function handleKeyPress(e, form) {
	var key           = e.keyCode || e.which,
    currentValeur = (e.currentTarget) ? e.currentTarget : e.srcElement;
  
	if (key === 13) { // Si on presse sur la touche "ENTER"
    if (currentValeur !== '' && currentValeur.value.length > 1) {
      $('#rechercher').click();
    }
	}
}

function switchLangue(current) {
  var valeurs = ['Recherche', 'Search'];
  return (current === 'fr') ? valeurs[0] : valeurs[1];
}

function recherche() {
	var form = $('.formRecherche')[0],
    langue = form.id.split('_')[1],
    valeur = $("#ch_recherche").val(),
    formValid = false,
    lblLang;
  if (langue === "fr") {
    lblLang = "Recherche"; 
  } else {
    lblLang = "Search";
  }
	
  $(".recherche").delegate("#ch_recherche", "click", function () {
    this.classname = 'inputRecherche';
    if (this.value === 'Recherche' || this.value === 'Search') {
      this.value = '';
    }

  }).delegate("#ch_recherche", "blur", function () {
		this.classname = 'inputRecherche inactif';
    if (this.value === '') {
      this.value = switchLangue(langue);
    }
    
  }).delegate("#rechercher", "click", function (e) {
 
		var currentValeur = $("#ch_recherche").val();
		if (currentValeur !== lblLang) {
			document.forms[0].submit();
		}
		return false;
  });
}


$(document).ready(function() {
	$('.btnUpdate').click(function() {
		id = this.className.split(" ")[1].split("_")[1];
		$("#frmUpdateCart_"+id).submit();
	});
	$('.btnDelete').click(function() {
		id = this.className.split(" ")[1].split("_")[1];
		$("#frmDeleteCart_"+id).submit();
	});
		$('.deleteCommande').click(function() {
	});
	
	$('.ajouterAuPanier').click(function() {
		$("#frmAjouterAuPanier").submit();
	});
	
	
	$('.bouton .retour').click(function() {
		
		referer = document.referrer;
		if (referer.search("panier") != -1 || referer.search("cart") != -1) {
			
			if (referer.search("panier") != -1) {
				window.open('/accueil.html','_self');
			}
			else if (referer.search("cart") != -1) {
				window.open('/en/home.html','_self');
			}
		}
		else {
			history.go(-1);
		}
	});
});



$(document).ready(function() {
 $("#shipping_pays").change(function () {
	var value = $('select#shipping_pays option:selected').val();
		switch(value) {
			case 'CA':
				$('#champForm_province').show();
				$('#champForm_region').hide();
				break;
			default:
				$('#champForm_province').hide();
				$('#shipping_region').val("");
				$('#champForm_region').show();
		}
	});

 $("#billing_pays").change(function () {
	var value = $('select#billing_pays option:selected').val();
		switch(value) {
			case 'CA':
				$('#champForm_province').show();
				$('#champForm_region').hide();
				break;
			default:
				$('#champForm_province').hide();
				$('#billing_region').val("");
				$('#champForm_region').show();
		}
	});
});





window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});























