// Fonction pour valider l'adresse courriel
function checkEmailAddress(field){
	var goodEmail = field.value.search(/^[^\.]*[A-Za-z0-9_\-\.]*[^\.]\@[^\.][A-Za-z0-9_\-\.]+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.biz)|(\.us)|(\.bizz)|(\.coop)|(\..{2,2}))[ ]*$/gi);
	if (goodEmail!=-1){
    return true;
	}else{
		alert("Le courriel saisi comporte une erreur");
	 	return false;
  }
}

function IsEmpty(aTextField) {
   if ((aTextField.value.length < 1) ||
   (aTextField.value==null)) {
      return true;
   }
   else {
   	return false; 
   }
}	
function looping_and_validate(){
	var c = 0;
	var field_empty = "";
	for(i=0; i < document.myform.length; i++){
		//if (IsEmpty(document.myform.elements[i])){
		if (IsEmpty(document.myform.elements[i])){
			if(document.myform.elements[i].id != "Courriel"){
				field_empty = field_empty + "\n - " +  document.myform.elements[i].id;
				c++;
			}
		}
	}
	if (c == 0){
			if(!IsEmpty(document.myform.Courriel)){
				return checkEmailAddress(document.myform.Courriel)
			}else{
				return true;
			}
		}else{
			alert("Veuillez remplir ce ou ces champs: " + field_empty);
			return false;
		}
}
//maxlenght of textarea
function limite(zone,max){
	if(zone.value.length>=max){
		zone.value=zone.value.substring(0,max);
	}
}
function verifTxtBoxDecimal(control)
{
	if(/[^0-9.]/.test(control.value))
		control.value = control.value.toLowerCase().replace(/([^0-9.])/g,"");
		
	if(/^\.|^0[0-9]/.test(control.value))
		control.value = control.value.toLowerCase().replace(/(^\.|^0[0-9])/,""); //control.value = "0.";
	
	if(control.name.substr(0,6) == "rabais")
		verifTxtBoxDecimalRabais(control);
	
	if(/\.$/.test(control.value))
	{
		avant_le_point = control.value.substr(0, control.value.length-1);
		if(avant_le_point.indexOf(".") > 0)
			control.value = avant_le_point;
	}		
	
	if(/[\d+(\.\d\d)?$]/.test(control.value))
	{
		concat_value = control.value;
		pos = control.value.indexOf(".");
		if(pos > 0)
		{
			avant_le_point = control.value.substr(0,pos+1);
			apres_le_point = control.value.substr(pos+1);
			if(apres_le_point.indexOf(".") >= 0)
			{
				apres_le_point = apres_le_point.replace(".","");
				concat_value = avant_le_point + apres_le_point;
				//concat_value = Math.round(concat_value*100)/100;
				control.value = concat_value;
			}
			
			longueur = control.value.substr(pos)
			if(longueur.length > 3)
				control.value = control.value.substr(0,pos+3);
		}
	}
}

function formatePrix(field)
{
	var value = eval('document.product_save.'+field).value;
	if(value != "")
	{
		value = parseFloat(value);
		value = formatNumber(value);
		eval('document.product_save.'+field).value = value;
	}
	else
		eval('document.product_save.'+field).value = "0.00";
}
function check_quote(str_quote){
	
	if(str_quote.value.indexOf('\'') != -1){
		alert("Veuillez éviter l'apostrophe dans le champ: " + str_quote.id);
		str_quote.value = "";
		str_quote.focus();
		
	}	
}