// FONCTIONS JAVASCRIPT ---------------------------------------------------------------------------------------------------------


/* Fonction Popup */
function window_open(URL){
window.open(URL, 'Envoyer', 'width=766,height=432,scrollbars=no,toolbar=no,menubar=no,left=20,top=20');
}

/* Fonction JumpMenu (OnChange) */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* test les champs du formulaire */
function test(prenom, nom, email, adresse, codpost, ville, province, pays, tel, mdp, confmdp, sondage1, email2) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (prenom.value == null || prenom.value == "") { alert('Entrez un pr&eacute;nom - Enter a first name'); return false; }
	if (nom.value == null || nom.value == "") { alert('Entrez un nom - Enter a name'); return false; }
	if (email.value == null || email.value == "" || (!filter.test(email.value))) { alert('Entrez une adresse email valide - Enter a valid email'); return false; }
	if (adresse.value == null || adresse.value == "") { alert('Entrez une adresse - Enter an address'); return false; }
	if (codpost.value == null || codpost.value == "") { alert('Entrez un code postal - Enter a postal code'); return false; }
	if (ville.value == null || ville.value == "") { alert('Entrez une ville - Enter a city'); return false; }
	if (province.value == null || province.value == "") { alert('Entrez une province - Enter a province'); return false; }
	if (pays.value == null || pays.value == "") { alert('Entrez un pays - Enter a country'); return false; }
	if (tel.value == null || tel.value == "") { alert('Entrez un telephone - Enter a phone'); return false; }
	if (mdp.value == null || mdp.value == "") { alert('Entrez un mot de passe - Enter a password'); return false; }
	if (confmdp.value == null || confmdp.value == "") { alert('Confirmez mot de passe - Confirm password'); return false; }
	if (mdp.value != confmdp.value) { alert('Les mots de passe ne correspondent pas ! - Passwords doesn\'t match'); return false; }
	//if (sondage1.value == "") { alert('O&ugrave; avez-vous entendu parlé de nous ? - Where did you learn about us ?'); return false; }
	if (email2.value == null || email2.value == "" || (!filter.test(email2.value))) { alert('Entrez une adresse email valide - Enter a valid email'); return false; }
	if (email2.value != email.value) { alert('Les emails ne correspondent pas ! - Emails doesn\'t match !'); return false; }
	return true
}
/* test form PM */
function testpm(pricematch, comp_name, comp_ad) {
	if (pricematch.value == null || pricematch.value == "") { alert('Indiquer un prix Price Match - Enter a Price Match price '); return false; }
	if (comp_name.value == null || comp_name.value == "") { alert('Indiquer le nom du competiteur - Enter the competitor name '); return false; }
	if (comp_ad.value == null || comp_ad.value == "") { alert('Indiquer l\'adresse du competiteur - Enter the competitor address '); return false; }			
	return true
}


/* test form ProdReq */
function testrequest(emaila, emailb, prodreq) {
	if (prodreq.value == null || prodreq.value == "") { alert('Indiquer un nom de produit - Enter a product name '); return false; }
	if (emaila.value == null || emaila.value == "") { alert('Entrez un email - Enter an email'); return false; }
	if (emailb.value == null || emailb.value == "") { alert('Entrez un email de confirmation - Enter a confirmation email'); return false; }
	if (emailb.value != emaila.value) { alert('les 2 emails ne correspondent pas - Emails are not matching'); return false; }
	
	return true
}
/* PC Configurable FONCTIONS -------------------------------------------------------------------------------- */
/* Affiche le prix en direct */
function display_price(row)
{
	var itemqty = parseInt(eval("document.pcc.qty_" + row + ".value"));
	if (eval("document.pcc.item_" + row + ".value") != "" || eval("document.pcc.item_" + row + ".value").length > 0)
	{
		var itemstring1 = eval("document.pcc.item_" + row + ".value");
		var itemid = itemstring1.substring(0 ,itemstring1.indexOf(":"));
		var itemstring2 = itemstring1.substring(itemid.length+1 ,itemstring1.length);
		var itemprice = itemstring2.substring(0 ,itemstring2.indexOf(":"));

		itemqty = parseInt(itemqty);
		itemid = parseFloat(itemid);
		itemprice = parseFloat(itemprice);

		eval("document.pcc.price_" + row + ".value=" + itemprice*itemqty);
		
	}
	else
	{
		eval("document.pcc.price_" + row + ".value=0");
	}
	
	document.pcc.total_haut.value=display_total();
	document.pcc.total_bas.value=display_total();
	parseelement(eval("document.pcc.price_" + row));
	parseelement(document.pcc.total_haut);
	parseelement(document.pcc.total_bas);
}

/* Affiche le total en direct */
function display_total()
{
	var total = 0;

	for (var i=0; i<parseInt(document.pcc.linecount.value); i++) {
		sstotal = eval("document.pcc.price_" + i + ".value");
		total = total + parseFloat(sstotal);
	}
	return total;
}

/* Affiche le lien + infos */
function moreinfo(row, message)
{
	var itemstring = eval("document.pcc.item_" + row + ".value");
	var itemid = itemstring.substring(0 ,itemstring.indexOf(":"));
	if (isNaN(itemid) || itemid.length==0 || itemid==null)
		alert(message);
	else	
		window.open("produit.asp?num="+itemid+"#noheader", "DETAIL", "toolbar=no,location=no,directories=no," + "status=no,menubar=no,scrollbars=yes,resizable,width=760,height=600");
}

/* Parse number to currency format */
	var prefix=""
	var wd
	
	function parseelement(thisone){
	if (thisone.value.charAt(0)=="$")
	return
	wd="w"
	var tempnum=thisone.value
	for (i=0;i<tempnum.length;i++){
	if (tempnum.charAt(i)=="."){
	wd="d"
	break
	}
	}
	if (wd=="w")
	thisone.value=prefix+tempnum+".00"
	else{
	if (tempnum.charAt(tempnum.length-2)=="."){
	thisone.value=prefix+tempnum+"0"
	}
	else{
	tempnum=Math.round(tempnum*100)/100
	thisone.value=prefix+tempnum
	}
	}
	}