//
function numericCheck(val, type, msg){
	var nr1 = val;
	var typeCheck = type;
	var flag = 0;
	var numberErrorMsg = msg;
	if(val == "") return false;
	if (numberErrorMsg == null) numberErrorMsg = "Cette entrée doit être un nombre. Veuillez enlever tous les lettres, caractères spéciaux, et espaces.";
	switch(typeCheck){
		case 0: //int
			cmp = "-0123456789"; break;
		case 1: //int + commas
			cmp="0123456789,"; break;
		case 2: //float
			cmp = "0123456789.,"; break;
		case 3: //currency
			cmp = "0123456789.,$-"; break;
		case 4: //int + point
			cmp = "0123456789."; break;
		case 5: //for zip codes  
			cmp = "0123456789-"; break;
		default:
			cmp = "0123456789"; break;
	}
	for (var i=0; i<nr1.length; i++){
		tst = nr1.substring(i,i+1);
		if ((cmp.indexOf(tst)<0) || (cmp.indexOf(" ") != -1)) flag++;
	}
	if (flag != 0){
		if(numberErrorMsg != "nomsg") alert(numberErrorMsg);
		return false;
	}
	return true;
}
function validEmail(str, msg){
	var emailErrorMsg = msg;
	if(emailErrorMsg == null) emailErrorMsg = "Veuillez entrer une adresse électronique valide. Les adresses électroniques doivent contenir le symbole @ et au moins un point (nomdevotreami@abc.com).";
	if (!isValidEmail(str)){
		if(emailErrorMsg != "nomsg") alert(emailErrorMsg);
		return false;
	}
	return true;
}

function validAspDate(asp_year, asp_month, asp_day, val, textBox, type, msg1, msg2){
	var dateErrorMsg = msg1;
	var spaceErrorMsg = msg2;
	var indate = val;
	var flag = 0;
	if(indate == "") return false;
	if(dateErrorMsg == null)
    	dateErrorMsg = "La date ou le format de la date entrée n'est pas valide. Suivez le format MM/JJ/AAAA sans espace.";
  	if(spaceErrorMsg == null)
    	spaceErrorMsg = "S.V.P. veuillez entrer de nouveau la date sous le format suivant JJ/MM/AAAA sans espaces."; //en
  	if(indate.indexOf(" ")!=-1){
    	if(dateErrorMsg != "nomsg"){
	  		alert(spaceErrorMsg);
	  		textBox.value = "";
      		textBox.focus();
		}  
    	return false;
  	}	
  	if (indate.indexOf("-")!=-1) var delimeter = "-";
  	else if (indate.indexOf("/")!=-1) var delimeter = "/";
  	else if (indate.indexOf(".")!=-1) var delimeter = ".";
  	else flag++;
  	var dateArray = indate.split(delimeter);
  	if((dateArray.length != 3) || ((dateArray[2].length != 2) && (dateArray[2].length != 4)) ||
    (dateArray[0].length < 1) || (dateArray[0].length > 2) || (dateArray[1].length < 1) ||
    (dateArray[1].length > 2)) {
    	flag++;
  	}
  	else if((numericCheck(dateArray[0], 0, dateErrorMsg)==false) || (numericCheck(dateArray[1], 0, dateErrorMsg)==false) || (numericCheck(dateArray[2], 0, dateErrorMsg)==false)) {  
		return false;
  	}
  	var intYear = parseInt(dateArray[2], 10);
  	if ((intYear >= 0) & (intYear <= 29)) dateArray[2] = 2000 + intYear;
  	else if ((intYear >= 30) & (intYear <= 99)) dateArray[2] = 1900 + intYear;
  	if (isDate(dateArray[2], dateArray[0], dateArray[1])==false) flag++;
  	if(flag != 0){
    	if(dateErrorMsg != "nomsg"){
      		alert(dateErrorMsg);
	  		textBox.value = "";
      		textBox.focus();
    	}
		return false;
  	}
	if ((dateArray[2] > 99) & (dateArray[2] < 1753)){
    	if(dateErrorMsg != "nomsg"){
      		alert("Nous n'acceptons  pas de date avant 1753.  S.V.P. choisir une année ultérieure. "); //en
	  		textBox.value = "";
      		textBox.focus();
    	}
		return false;
  	}
  	if ( type=='before' && ( (dateArray[2] > asp_year)	
	|| (dateArray[2] == asp_year && dateArray[0] > asp_month) 
	|| (dateArray[2] == asp_year && dateArray[0] == asp_month && dateArray[1] > asp_day) ) ) {
    	if(dateErrorMsg != "nomsg") {
      		alert("Nous n'acceptons pas une date ultérieure.  S.V.P. essayez de nouveau"); //en
	  		textBox.value = "";
      		textBox.focus();
    	}
		return false;
  	}
  	if ( type=='after' && ( (dateArray[2] < asp_year)	
	|| (dateArray[2] == asp_year && dateArray[0] < asp_month) 
	|| (dateArray[2] == asp_year && dateArray[0] == asp_month && dateArray[1] < asp_day) ) ) {
    	if(dateErrorMsg != "nomsg") {
      		alert("Nous n'acceptons pas une date ultérieure.  S.V.P. essayez de nouveau"); //en
	  		textBox.value = "";
      		textBox.focus();
    	}
		return false;
  	}
  	indate = dateArray[0] + "/" + dateArray[1] + "/" + dateArray[2];
  	textBox.value = indate;  // Set the date in the form to the modified date.
  	return true;
}
function checkLength(ptr, maxlength){
	if(ptr.value.length > maxlength){		
    	alert("Votre message doit contenir  "+maxlength+" caractères ou moins"); //en
		ptr.focus();
    	return false;
  	}
}
function checkNumber(ptr, msg){
	ptr.value = jsDV_strTrim(ptr.value);
	if(ptr.value != "")
    	if(!numericCheck(ptr.value,0,'nomsg')){ 
        	alertText(msg, "Veuillez entrer un numéro valide");
			ptr.select();
        	ptr.focus();
        	return false;
		}
}
function checkFloat(ptr, msg){
	ptr.value = jsDV_strTrim(ptr.value);
	if(ptr.value != "")	
    	if(!numericCheck(ptr.value,2,'nomsg')){
			alertText(msg, "Veuillez entrer un numéro valide");
			ptr.select();
			ptr.focus();
			return false;
		}
}
function checkPointNumber(ptr, msg){
	ptr.value = jsDV_strTrim(ptr.value);
	if(ptr.value != "")
    	if(!numericCheck(ptr.value,4,'nomsg')){ 
			alertText(msg, "Veuillez entrer un numéro valide");
			ptr.select();
			ptr.focus();
			return false;
		}
}
function checkCurrency(ptr, msg){
	var amountValue = jsDV_strTrim(ptr.value.replace(/,|\$/g,""));
	var returnValue = "";
	if(amountValue != "")
		returnValue = jsDV_isValidMoney(amountValue)
		if(returnValue == "-1"){
			alertText(msg, "Veuillez entrer une devise valide");
			ptr.value = "";
        	ptr.focus();
        	return false;
		} 
		else
			ptr.value = returnValue;
}
function checkPercentage(ptr, msg){
	ptr.value = jsDV_strTrim(ptr.value);
	if(ptr.value != "")
    	if(!numericCheck(ptr.value,6,'nomsg')){ 
			alertText(msg, "S.V.P veuillez entrer un pourcentage valide."); //en
			ptr.select();
        	ptr.focus();
        	return false;
		}
}
function checkAge(ptr, msg){
	ptr.value = jsDV_strTrim(ptr.value);
	if(ptr.value != "")
		if(!numericCheck(ptr.value,0,'nomsg')){ 
        	alertText(msg, "Veuillez entrer un âge valide.");
			ptr.value = "";
			ptr.focus();
			return false; 
		}   
}
function checkZip(ptr, msg){
	ptr.value = jsDV_strTrim(ptr.value);
	if(ptr.value != ""){
		var flag = 0;
		strchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -";
		for(var i=0; i<ptr.value.length; i++){
			tst = ptr.value.substring(i,i+1);
    		if (strchar.indexOf(tst)<0)	flag++;
		}
		if(flag != 0){
        	alertText(msg, "S.V.P veuillez entrer un code postal valide."); //en
			ptr.select();
        	ptr.focus();
        	return false; 
		}
	}
}
function checkCountryZip(zipptr, ctrptr, msg){
	var zip = "";
	var formatzip = "";
	var country = "";
	var flag = 0;
	var i;
	var err;
	zip = zipptr.value;
	for (i=0; i<ctrptr.length; i++)
		if (ctrptr[i].selected == true) country = ctrptr[i].value;
	if((zip != "") && (country == "CA")){
		var strchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var strint = "0123456789";
		for(i=0; i<zip.length; i++){
			tst = zip.substring(i,i+1);
			switch(i) {
				case 0:
				case 2:
				case 5:
					if (strchar.indexOf(tst)<0) flag++;
					break;
				case 1:
				case 4:
				case 6:
					if (strint.indexOf(tst)<0) flag++;	
					break;
				case 3:
					if(tst == "-") tst = " ";
					if(tst != " ") flag++;
					break;
				default:
					if(i>6) flag++;
					break;
			}
			formatzip = formatzip + tst;
			err = "Le format canadien des codes postaux est incorrrecte. Veuillez corriger le format LCL CLC  L=lettre et C=chiffre"; //en
		}
	}
	else {
		formatzip = zip;
		if (msg != null && msg != "") err = msg;
		else err = "S.V.P veuillez entrer un code postal valide."; //en
	}
	if(flag != 0){
        alert(err);
        return false; 
	}
	else{
		zipptr.value = formatzip.toUpperCase();
		return true;
	}
}
function checkFormLoginName(thisform, msg1, msg2, msg3){
	if(thisform.LoginName != null && thisform.Password != null && thisform.VerifyPassword != null) {
		if(thisform.Password.value.length < 5){
			alertText(msg1, "Le mot de passe doit contenir au moins 5 caractères veuillez essayer de nouveau");
			return false;
		}
		if(thisform.Password.value != thisform.VerifyPassword.value){
			alertText(msg2, "Vos mots de passe ne concordent pas veuillez essayer de nouveau");
			return false;
		}
		if(thisform.Password.value == thisform.LoginName.value){
			alertText(msg3, "Votre mot de passe ne peut pas être identique à votre nom d'utilisateur");
			return false;
		}
	}
	return true;
}

