﻿<!--
//extrait les variables de l'url
function getVar (nomVariable){
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
	if (infos.indexOf("#")!=-1)
	infos = infos.substring(0,infos.indexOf("#"))+"&"
	var variable=0
	{
		nomVariable = nomVariable + "="
		var taille = nomVariable.length
		if (infos.indexOf(nomVariable)!=-1)
		variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
	}
	return variable
} 

//on récupère la variable langue
langue = getVar('langue');
if(langue == 0){
	langue = "fr";
}	


function validQteCaddy(champ, qte, enstock, initQte, nonrecom){

	var erreurs = "";
	
	if(isNaN(qte)){
		erreurs = "La quantité doit être un nombre";
		champ.value = initQte;
	}else{
		qte = Number(qte);
		if(qte <= 0){
			erreurs = "La quantité doit être supérieure à zéro";
			champ.value = initQte;
		}else{
			if(nonrecom && qte > enstock){
				erreurs = "Ce produit n\'est pas recommandable, vous ne pouvez commander que " + enstock + " article(s)";
				champ.value = enstock;
			}
		}
	}
	
	if(erreurs!=""){
		alert(erreurs);
	}else{
		document.caddyform.action = "caddy.asp?langue=" + langue;
		document.caddyform.submit();
	}
}

function validQtePanier(champ, qte, enstock, initQte, id_Panier, id_Produit, nonrecom){

	var erreurs = "";

	if(isNaN(qte)){
		erreurs = "La quantité doit être un nombre";
		champ.value = initQte;
	}else{
		qte = Number(qte);
		if(qte <= 0){
			erreurs = "La quantité doit être supérieure à zéro";
			champ.value = initQte;
		}else{
			if(nonrecom && qte > enstock){
				erreurs = "Ce produit n\'est pas recommandable, vous ne pouvez commander que " + enstock + " article(s)";
				champ.value = enstock;
			}
		}
	}
	
	
	
	if(erreurs!=""){
		alert(erreurs);
	}else{
		document.panierform.action = "compte_paniers.asp?langue=" + langue + "&produit=" + id_Produit + "&panier=" + id_Panier + "&qte=" + qte;
		document.panierform.submit();
	}
}

function ajoutPanier(id){
	id.trigger('click');
}


document.onkeydown = checkKeycode

function checkKeycode(e) {
	
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	
	if(keycode == 13 && elementFocus == 'recherche'){
		validRechercheMenu();
	}
	if(keycode == 13 && elementFocus == 'rechercheRef'){
		validRechercheRefMenu();
	}
	if(keycode == 13 && elementFocus == 'qte' && champ != undefined){
		validQteCaddy(champ, champ.value, enstock, initQte, nonrecommandable);
	}
	if(keycode == 13 && elementFocus == 'qtePaniers' && champ != undefined){
		validQtePanier(champ, champ.value, enstock, initQte, id_Panier, id_Produit, nonrecommandable);
	}
	if(keycode == 13 && elementFocus == 'identifie'){
		validationIdentifie();
	}
	if(keycode == 13 && elementFocus == 'compte_password'){
		validationComptePassword();
	}
	if(keycode == 13 && elementFocus == 'ajoutAdresse'){
		ajoutAdresse();
	}
	if(keycode == 13 && elementFocus == 'newsletter'){
		validNewsletterInscrire();
	}
	if(keycode == 13 && elementFocus == 'enteteConnexion'){
		validationEnteteConnexion();
	}
	if(keycode == 13 && elementFocus == 'panier'){
		ajoutPanier(id);
	}
	if(keycode == 13 && elementFocus == 'mespaniers'){
		validationPanierAjout();
	}
	if(keycode == 13 && elementFocus == 'newsletterCompteAjout'){
		ajoutNew(true);
	}
	if(keycode == 13 && elementFocus == 'newsletterCompteAjout2'){
		ajoutNew();
	}
}

function toggleFocus(tag){
	elementFocus = tag;
}

function toggleFocusField(champ){
	champQte = champ;
}

function toggleFocusAjoutPanier(field){
	id = $("#_" + field);
}

function toggleFocusCaddyQte(field, stock, initQty, nonrecom){
	champ = field;
	enstock = Number(stock);
	initQte = initQty;
	nonrecommandable = nonrecom;
}

function toggleFocusPanierQte(field, stock, initQty, idPanier, idProduit, nonrecom){
	champ = field;
	enstock = Number(stock);
	initQte = initQty;
	id_Panier = idPanier;
	id_Produit = idProduit
	nonrecommandable = nonrecom;
}
//-->
