// fonction pour calculer le prix Vs quantite
subtol = new Array();

function calcul()
	{
	calcul(-1);
	}

function calcul(langId)
	{
	var bigtotal = 0
	
	if (document.calc.qty.length != null) 
		{
		for (var j=0; j<document.calc.qty.length; j++)
			{
			quantite = document.calc.qty[j].value
			if (((quantite / quantite) != 1) && (quantite != 0)) {alert('S.V.P. entrer un chiffres dans cet espace');return;}
			subtol[j] = (quantite*prix[j]);
			subtol[j] = fixDecimal(subtol[j]);
			document.calc.price[j].value = format(subtol[j],langId);
			bigtotal = bigtotal + subtol[j]
			bigtotal = fixDecimal(bigtotal,langId);
			}
		}   
		else 
		{
		quantite = document.calc.qty.value
		if (((quantite / quantite) != 1) && (quantite != 0)) {alert('S.V.P. entrer un chiffres dans cet espace');return;}
		subtol = (quantite*prix[0]);
		subtol = fixDecimal(subtol);
		document.calc.price.value = format(subtol,langId);
		bigtotal = subtol
		}
	document.calc.total.value = format(bigtotal,langId); 
	}

function fixDecimal(value)
	{
	var valueChar = value + "";
	var chiffre = valueChar.split(".");
	// Si il y a une portion decimal
	if(chiffre.length > 1)
		{
		if(chiffre[1].length > 2)	// Si on a une portion decimal contenant plus de 2 chiffres, il faut arrondir
			{
			value *= 100;
			value = Math.round(value);
			value /= 100;
			}
		}	
	return value;	
	}

// fonction pour formater un chiffre 0.00$
function format(chiffre,langId)
	{

	chiffre = chiffre + "";
	chiffre = chiffre.split(".");
	if(!chiffre[0]) chiffre[0] = "0";
	if(!chiffre[1]) chiffre[1] = "00";
	if(chiffre[1].length==1) chiffre[1] += "0";

	var returnString = "";

	if(langId == -2)
		returnString = chiffre[0] + "," + chiffre[1] + " $";
	else
		returnString = "$ " + chiffre[0] + "." + chiffre[1];
	
	return returnString;
	}	

// fix pour empecher de cliquer dans les boites sur Netscape 
function bugNS() 
	{
	document.calc.qty[0].focus();
	}


function isEmailAddressValid(email)
	{
	var val_email = email.toLowerCase();
	var email_parts = val_email.split("@");
	
	// must be compose of two parts
	if(email_parts.length != 2)
		return false;
		
	// validate the first part (LOCAL NAME) of the email
	val_email = email_parts[0];
	
	if(val_email.length == 0 || val_email == "")
		return false;
		
	for(var i=0; i < val_email.length; i++)
	{
		var charToValidate = val_email.charAt(i);
		
		if(charToValidate > "~")		// Out of the ASCII caracteres bound ("~" = 126)
			return false;
			
		if(charToValidate == '(' || charToValidate == ')'
	   		|| charToValidate == '<' || charToValidate == '>' 
	   		|| charToValidate == ',' || charToValidate == ';' 
	   		|| charToValidate == ':' || charToValidate == '\\' 
	   		|| charToValidate == '"' || charToValidate == '[' 
	   		|| charToValidate == ']' || charToValidate == ' ' )
		{
			return false;
		}
	}

	// validate the second part (DOMAIN) of the email
	val_email = email_parts[1];

	if(val_email.length == 0 || val_email == "")
		return false;
	
	for(var i=0; i < val_email.length; i++)
	{
		var charToValidate = val_email.charAt(i);
		if(charToValidate < 'a' || charToValidate > 'z')
			if(charToValidate < '0' || charToValidate > '9')
				if(charToValidate != '.' && charToValidate != '-')
					return false;
	}	
	return true;
}	

// postal code verificator
function clearIt(pCodeField) {
	pCodeField.value = ""; 
	if(pCodeField.type != "hidden") { 
		pCodeField.focus(); 
	}
}

function validatePCode(pCodeField) {

	pCodeField.value = pCodeField.value.toUpperCase();
	var pCode = pCodeField.value;
	var pCodeLength = pCode.length;
	
	if(pCodeLength < 6 || pCodeLength > 7){ clearIt(pCodeField); return false;}
	
	if(pCodeLength == 6) {
		pCodeField.value = pCode.substring(0,3) + " " + pCode.substring(3,6);
		pCode = pCodeField.value;
	}

	// cloum
	if(pCodeField.value == "H0H 0H0") { 
		clearIt(pCodeField); 
		return false;
	}
	// /cloum
		
	cP = pCode.charAt(0);
	if(cP < "A" || cP > "Z"){ clearIt(pCodeField); return false;}

	cP2 = pCode.charAt(1);
	if(cP2 < "0" || cP2 > "9"){ clearIt(pCodeField); return false;}

	cP3 = pCode.charAt(2);
	if(cP3 < "A" || cP3 > "Z"){ clearIt(pCodeField); return false;}

	cP5 = pCode.charAt(4);
	if(cP5 < "0" || cP5 > "9"){ clearIt(pCodeField); return false;}

	cP6 = pCode.charAt(5);
	if(cP6 < "A" || cP6 > "Z"){ clearIt(pCodeField); return false;}

	cP7 = pCode.charAt(6);
	if(cP7 < "0" || cP7 > "9"){ clearIt(pCodeField); return false;}

	// cloum - 07/08/2002
	// If the middle (4th) character is not a blank space, 
	// replace the actual character with a blank space
	cP4 = pCode.charAt(3);
	if(cP4 != " ") { 
		pCodeField.value = pCode.substring(0,3) + " " + pCode.substring(4,7);
	}
	return true;	
}

// cloum
// Telephone number validation
function validateTel(pTelField)
{
	var pTel = pTelField.value;
	var pTelLength = pTel.length;

	for (i = 0; i < pTelLength; i++)
	{
		cP = pTel.charAt(i);
		if ((cP < "0" || cP > "9") && (cP != "(" && cP != ")" && cP != "-" && cP != " "))
		{
			clearIt(pTelField); 
			return false;
		}
	}

	return true;	
}
// /cloum

function redirectToURL(anObject)
	{
	// is a List (ex : <SELECT>)
	if(anObject.options != null && anObject.selectedIndex != null)
		{	
		if(anObject.options[anObject.selectedIndex].value != "") window.location = anObject.options[anObject.selectedIndex].value;
		}
	}