jQuery.noConflict();

//SearchBox global vars
var searchBoxes = jQuery(".text");
var searchBox1 = jQuery("#search1");
var searchBox2 = jQuery("#recherche_rapide");
var searchBox2Default = "Recherche rapide";

function getDataForQuery(form_id){
	data = jQuery(form_id).serialize() || "";
	data += (data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
	return data;
}


jQuery(document).ready(function(){

   /* JQuery SearchBox */
	//Effects for both searchbox
	searchBoxes.focus(function(e){
		jQuery(this).addClass("active");
	});
	searchBoxes.blur(function(e){
		jQuery(this).removeClass("active");
	});
	
	//Searchbox1, set focus when document is ready
	searchBox2.focus();
	
	//Searchbox2 show/hide default text if needed
	searchBox2.focus(function(){
		if(jQuery(this).attr("value") == searchBox2Default) {
          jQuery(this).attr("value", "");
        }
	});
	searchBox2.blur(function(){
		if(jQuery(this).attr("value") == "") {
          jQuery(this).attr("value", searchBox2Default);
        }
	});
});

var currencyFormat = function(valeur,locale)
{
 split = ",";
 if(locale == 'fr')
   split = " ";
 nStr = valeur
 nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + split + '$2');
  }
  return x1 + x2 + "$"; 
}

var kilometerFormat = function (valeur,locale) 
{
  split = ","
  if(locale == 'fr')
    split = " "
   nStr = valeur
 nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + split + '$2');
  }
  return x1 + x2 + "km"; 
}
jQuery(document).ready(function(){
    jQuery('a.popup-window').click(function(){
        window.open(this.href,'','toolbar=no,directories=no,status=no,menubar=no');
        return false;
    });
});

