$(document).ready(function() {



  $("#searchForm #q").click(function(){
    $(this).val("");
});

$("#searchForm").submit(function(){
    if ($(this).find("#q").val() == 'Búsqueda de productos' || $(this).find("#q").val() == 'Product Search')
    { $(this).find("#q").val("").focus();  return false;  }
});


$(".buttonDetails").click(function(){
 $.cookie('urlBack', document.URL, { path: '/', expires: 0.005 });
});

var provCookie = $.cookie('provSelected');
if (provCookie != null)
   {
   var isDetailsFlores = "";
if ($("#floresDetallesCont").html() != null) isDetailsFlores = "yes";
else isDetailsFlores ="no";

    var URLnow = document.URL;
    if (URLnow.indexOf('ramos-de-flores')!= -1 || URLnow.indexOf('comprar-flores-online/envio-de-flores-a')!= -1 || URLnow.indexOf('flower-bouquets')!= -1 || URLnow.indexOf('purchase-flowers-online/send-flowers-to')!= -1  || isDetailsFlores == "yes")
          { 
            $("option[value='"+provCookie+"']").attr("selected","selected");
          }
         else
          {
            $.cookie('provSelected', null);
          }
   }






var paginatorContent = $("#paginator").html();
$("#paginator_bottom").html(paginatorContent);



var basketCont = $("#shoppingBasket table").html();
if (basketCont != null)
{

 $(".banner > *:not(#shoppingBasket,#basketImage)").remove(); 
}
var options = { path: '/', expires: 10 }; 
$("form.myForm").jqTransform();

$(".jqTransformSelectWrapper ul:eq(0) li a").click(function(){

var theLink = $(this).attr("title");
if (theLink != null && theLink!= "")
     {
          if (theMicrosite == 'Español')
          {
          theLink = theSiteUrl + "/floristeria-online/comprar-flores-online/envio-de-flores-a-"+theLink+"/";
          $.cookie('provSelected', $(this).attr('title'), options);
          }
          else
          {
theLink = theSiteUrl + "/flower-shop/purchase-flowers-online/send-flowers-to-"+theLink+"/";
          $.cookie('provSelected', $(this).attr('title'), options);
         
          }
          window.location.href = theLink;
     }
});



$(".jqTransformSelectWrapper ul:eq(1) li a").click(function(){

var theLink = $(this).attr("title");
if (theMicrosite == 'Español')
{
theLink = theSiteUrl + "/floristeria-online/comprar-flores-online/"+theLink+"/";
$.cookie('eventoSelected', $(this).attr('title'), options);
}
else
{
theLink = theSiteUrl + "/flower-shop/purchase-flowers-online/"+theLink+"/";
$.cookie('eventoSelected', $(this).attr('title'), options);
}
window.location.href = theLink;

});

});


function isFilled(searchWord)
{

if (document.getElementById('search_id').value == '' || document.getElementById('search_id').value == searchWord)
{
document.getElementById('search_id').value='';
document.getElementById('search_id').focus();
return false;
}
else
{
 if (theMicrosite = "floristeria-online")
location = theSiteUrl + "/" + theMicrosite + "/site-info/resultados-de-busqueda/?free_text_search=" + encodeURIComponent( document.getElementById("search_id").value );
else  if (theMicrosite = "flower-shop")
location = theSiteUrl + "/" + theMicrosite + "/site-info/search-results/?free_text_search=" + encodeURIComponent( document.getElementById("search_id").value );

    return false;

}

}

(function($){

	$.fn.shuffle = function() {
		return this.each(function(){
			var items = $(this).children();
			return (items.length) ? $(this).html($.shuffle(items)) : this;
		});
	}
	
	$.shuffle = function(arr) {
		for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
		return arr;
	}
	
})(jQuery);



/** This function replaces the funny characters to build an url from a name. Exactly as the translate function in our XSL ***/

function translateToURL(name)
{

name = name.toLowerCase();

/*** Replacing these chars: /.()&amp;,:+ÆßØø?¿!¡ with dashes  ***/

name = name.replace(/\"/g,'-').replace(/\'/g,'-').replace(/ /g,'-').replace(/\+/g,'-').replace(/\//g,'-').replace(/\./g,'-').replace(/\(/g,'-').replace(/\)/g,'-').replace(/&amp;/g,'-').replace(/\;/g,'-').replace(/,/g,'-').replace(/:/g,'-').replace(/\?/g,'-').replace(/!/g,'-').replace(/¿/g,'-').replace(/¡/g,'-').replace(/ß/g,'-').replace(/ø/g,'-').replace(/Ø/g,'-').replace(/æ/g,'-').replace(/®/g,'-').replace(/™/g,'-').replace(/©/g,'-');  


/*** Replacing these chars:  àáâãäåçèéêëìíîïðñòóôõöùúûüýÿğišıąćęłńóśźż with  aaaaaaceeeeiiiidnooooouuuyygisiacelnoszz  ***/

name = name.replace(/à/g,'a').replace(/á/g,'a').replace(/â/g,'a').replace(/ã/g,'a').replace(/ä/g,'a').replace(/å/g,'a').replace(/ç/g,'c').replace(/è/g,'e').replace(/é/g,'e').replace(/ê/g,'e').replace(/ë/g,'e').replace(/ì/g,'i').replace(/í/g,'i').replace(/î/g,'i').replace(/ï/g,'i').replace(/ı/g,'i').replace(/ð/g,'d').replace(/ñ/g,'n').replace(/ò/g,'o').replace(/ó/g,'o').replace(/ô/g,'o').replace(/õ/g,'o').replace(/ö/g,'o').replace(/ù/g,'u').replace(/ú/g,'u').replace(/û/g,'').replace(/ü/g,'u').replace(/ý/g,'y').replace(/ÿ/g,'y').replace(/ğ/g,'g').replace(/š/g,'s').replace(/ą/g,'a').replace(/ć/g,'c').replace(/ę/g,'e').replace(/ł/g,'l').replace(/ń/g,'n').replace(/ó/g,'o').replace(/ś/g,'s').replace(/ź/g,'z').replace(/ż/g,'z');

return(name);

}