<!--

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}
function isPhone(s) {
   	for (var i = 0; i < s.length; i++) {
   		c = s.charAt(i);
      	if ((!isDigit(c)) && (c!=" ") && (c!="-") && (c!="(") && (c!=")")) return false; }
    return true; 
}
function isValidCodeChar(s)
{
	for (var i=0; i<s.length; i++) { 
   		if (!isDigitOrLetter(s.charAt(i)) && ! s.charAt(i)=="_") return false; }
   	return true; 
}
function LTrim(s) {
   	while (s.substring(0,1)==" ") { s=s.substring(1); }
   	return s;
}
function RTrim(s) {
   	while (s.substring(s.length-1,s.length)==" ") { s=s.substring(0,s.length-1); }
   	return s;
}
function Trim(s) {
   	return LTrim(RTrim(s));
}

function TrimPhone(s) {
   	var sOut = "";
   	for (var i=0; i<s.length; i++) {
   		if (isDigit(s.charAt(i))) sOut+= s.charAt(i); }
   	return sOut;
}
function FormatPhone(s) {
	var sOut = "";
	if (s.length==10)
		sOut = s.substr(0,3) + "-" + s.substr(3,3) + "-" + s.substr(6);
	else if (s.length==7)
		sOut = s.substr(0,3) + "-" + s.substr(3);
	else
		sOut = s;
	return sOut;
}

function isValidPhone(item,req,inter,lang) {
	var isGood = 1;
	var str = Trim(item.value);
	item.value = str;
	if (str.length==0 && req==0) return true;
	if (str.length==0 && req==1) { isGood = 0; }
	else if (!isPhone(str)) { isGood = 0; }
	else {
		str = TrimPhone(str);
	  	if (str.length==11) {
	  		if (inter==1) { if (str.charCodeAt(0)!=49) isGood = 0; else if (str.charCodeAt(1) <50) isGood = 0; }
	  		else { isGood = 0; } }
	  	else if ((str.length==10)||(str.length==7)) {
	  		if (str.charCodeAt(0) <50) { isGood = 0; } }
		else { isGood = 0; } }
	if (isGood==0) {
		item.focus(); item.select();
		if (lang=="FR") alert("Numéro invalide");
		else alert("Invalid number");
		return false; }
	else { item.value=str; return true; }
}
function isValidPhoneWithAreaCode(item,req,inter,lang) {
	var isGood = 1;
	var str = Trim(item.value);
	item.value = str;
	if (str.length==0 && req==0) return true;
	if (str.length==0 && req==1) { isGood = 0; }
	else if (!isPhone(str)) { isGood = 0; }
	else {
		str = TrimPhone(str);
	  	if (str.length==11) {
	  		if (inter==1) { if (str.charCodeAt(0)!=49) isGood = 0; else if (str.charCodeAt(1) <50) isGood = 0; }
	  		else { isGood = 0; } }
	  	else if ((str.length==10)) {
	  		if (str.charCodeAt(0) <50) { isGood = 0; } }
		else { isGood = 0; } }
	if (isGood==0) {
		item.focus(); item.select();
		if (lang=="FR") alert("Numéro invalide\nVeuillez entrer un numéro avec un code régional.");
		else alert("Invalid number\nPlease fill with a number with an area code.");
		return false; }
	else { item.value=str; return true; }
}
function isValidEmail (item,req,lang) {
		//checkEmail est plus complet.
	var isGood=1;
	var str=Trim(item.value);
	str=str.toLowerCase();
	item.value=str;
	if (str.length==0 && req==0) return true;
	if (str.length==0 && req==1) isGood=0;
	else if (str.indexOf("@")<2) isGood=0;
	else {
		if (str.search(/[\s!;,çàäâéèêëöôòüûùî'^¨}{#$^&*]/) > -1) { isGood=0; }
		else {
			var t1=str.substr(0,str.indexOf("@"));
			var t2=str.substr(str.indexOf("@")+1);
			if (t2.search(/\.com$|\.ca$|\.qc\.ca$|\.org$|\.net$|\.ws$|\.cl$|\.fr$/i)<2) { isGood=0; }}}
	if (isGood==0) {
		item.focus();
		item.select();
		if (lang=="FR") alert("Adresse de courriel invalide");
		else alert("Invalid e-mail address");
		return false; }
	else { return true; }
}
function isValidCourriel (item,req,lang) {
	//checkEmail est plus complet.
	var isGood=1;
	var str=Trim(item.value);
	str=str.toLowerCase();
	item.value=str;
	if (str.length==0 && req==0) return true;
	if (str.length==0 && req==1) isGood=0;
	else if (str.indexOf("@")<2) isGood=0;
	else {
		if (str.search(/[\s!;,çàäâéèêëöôòüûùî'^¨}{#$^&*]/) > -1) { isGood=0; }
		else {
			var t1=str.substr(0,str.indexOf("@"));
			var t2=str.substr(str.indexOf("@")+1);
			if (t2.search(/\.com$|\.ca$|\.qc\.ca$|\.org$|\.net$|\.ws$|\.cl$|\.fr$/i)<2) { isGood=0; }}}
	if (isGood==0) {
		item.focus();
		item.select();
		if (lang=="FR") alert("Adresse de courriel invalide");
		else alert("Invalid e-mail address");
		return false; }
	else { return true; }
}
function checkEmail2(item, req, strLang) {
	var blnGood=true;
	var myEmail= Trim(item.value);
	var reg = new RegExp("/^\w+([/&\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/");
	item.value = myEmail;
	if (myEmail.length==0 && req==0)
		return true;
	if (myEmail.length==0 && req==1)
		blnGood = false;
	else
		{
			if (!(myEmail.match(reg)))
				blnGood = false;
		}
	if (!blnGood)
	{
		item.focus();
		item.select();
		if(strLang=="FR")
			alert("Adresse de courriel invalide!");
		else
			alert("Invalid e-mail address!");
		return false;
	}
	else
		return true;
}
function checkEmail(item, req, strLang) {
	var blnGood=true;
	var myEmail= Trim(item.value);
	item.value = myEmail;
	if (myEmail.length==0 && req==0)
		return true;
	if (myEmail.length==0 && req==1)
		blnGood = false;
	else
		{
			if (!(/^\w+([&\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myEmail)))
				blnGood = false;
		}
	if (!blnGood)
	{
		item.focus();
		item.select();
		if(strLang=="FR")
			alert("Adresse de courriel invalide!");
		else
			alert("Invalid e-mail address!");
		return false;
	}
	else
		return true;
}

function goodchars(e, goods)
{
	var key, keychar;
	key = getkey(e);
	if (key == null) 
		return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	if (goods.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   	return true;
	return false;
}
function goodlenght(e,longmax, item){
	var key, keychar;
	key = getkey(e);
	if (key == null) 
		return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	if (item.value.length<longmax)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   	return true;
	return false;
}
function getkey(e){
	if (window.event)
   	return window.event.keyCode;
	else 
		if(e)
   		return e.which;
		else
   		return null;
}
function fctValidate(f)
{
   if (f.txtusername.value.length==0)
   {
   	alert("Vous devez entrer un code d'usager!");
      f.txtusername.focus();
      return false;
    }
    if(f.txtpassword.value.length<4 ||f.txtpassword.value.length>6)
    {
    	alert("Vous devez entrer un mot de passe de 4 à 6 chiffres!");
      f.txtpassword.focus();
      return false;
    }
    return true;
}
function isValidPassCode (item,req,mini,maxi,langue) {
	var isGood=1;
	var str=item.value;
	if (str.length==0 && req==0) return true;
	if (str.length==0 && req==1) isGood=0;
	else {
		if (!isValidCodeChar(str)) isGood=0;
		else {
			if ((mini != -1) && (str.length<mini)) isGood=0;
			if ((maxi != -1) && (str.length>maxi)) isGood=0; } }
	if (isGood==0) {
		var err=""; item.focus(); item.select();
		if (langue=="FR") {
			err="Veuillez entrer un code alphanumérique, sans accents ou espaces";
			if (req==1) err+=" (requise)";
			if ((mini != -1) && (mini != -1) && (mini == maxi)) err+=" ayant "+mini+" caractères.";
			else if ((mini != -1) && (mini != -1)) err+=" ayant entre "+mini+" et "+maxi+" caractères.";
			else if (mini != -1) err+=" ayant "+smin+" caractères et plus.";
			else if (maxi != -1) err+=" ayant "+smax+" caractères ou moins.";
			else err+="."; }
		else {
			err="Please enter an alphanumeric code, without accents or spaces";
			if (req==1) err+=" (required)";
			if ((mini != -1) && (mini != -1) && (mini == maxi)) err+=" having "+mini+" characters.";
			else if ((mini != -1) && (mini != -1)) err+=" having between "+mini+" and "+maxi+" characters.";
			else if (mini != -1) err+=" having "+smin+" or more characters.";
			else if (maxi != -1) err+=" having "+smax+" or less characters.";	
			else err+="."; }
		alert(err);
		return false; }
	else { return true; }
}
function isValidString(item,req,min,max,lang) {
	var isGood = 1, err = "";
	item.value = TrimCrLf(item.value);
	var str = item.value;
	if ((str.length==0) && (req==0)) return true;
	if (((min>0) && (max>0)) && ((str.length<min) || (str.length>max))) {
		if (min==max) {
			if (lang=="FR") { err="Ce champ ";err+=(req==1)?"(obligatoire)":"(facultatif)";err+=" doit comporter "+min+" caractères. Votre entrée en contient: "+str.length;}
			else { err="This field ";err+=(req==1)?"(required)":"(optional)";err+=" may have "+min+" characters. Your entry: "+str.length;}}
		else {
			if (lang=="FR") { err="Ce champ ";err+=(req==1)?"(obligatoire)":"(facultatif)";err+=" doit comporter entre "+min+" et "+max+" caractères. Votre entrée en contient: "+str.length;}
			else { err="This field ";err+=(req==1)?"(required)":"(optional)";err+=" may have betweem "+min+" and "+max+" characters. Your entry: "+str.length;}}
		isGood = 0;}
	else if ((min!=-1) && (str.length<min)) {
		if (lang=="FR") { err="Ce champ ";err+=(req==1)?"(obligatoire)":"(facultatif)";err+=" doit comporter un minimum de "+min+" caractères. Votre entrée en contient: "+str.length;}
		else { err="This field ";err+=(req==1)?"(required)":"(optional)";err+=" may have at least "+min+" characters. Your entry: "+str.length;}
		isGood = 0;}
	else if ((max!=-1) && (str.length>max)) {
		if (lang=="FR") { err="Ce champ ";err+=(req==1)?"(obligatoire)":"(facultatif)";err+=" doit comporter un maximum de "+max+" caractères. Votre entrée en contient: "+str.length;}
		else { err="This field ";err+=(req==1)?"(required)":"(optional)";err+=" may have a maximum of "+max+" characters. Your entry: "+str.length;}
		isGood = 0;}
	if (isGood == 0) { item.focus(); item.select(); }
	if (err.length>0) alert(err);
	return (isGood==1);
}
function TextPrep(item){
	var s = Trim(item.value);
	s=s.charAt(0).toUpperCase() + s.substring(1, s.length);
	for(var i=0;i<s.length;i++){
		if (s.charAt(i)==" " || s.charAt(i)=="-" || s.charAt(i)=="," || s.charAt(i)=="'")
			s=s.substring(0, i+1)+ s.charAt(i+1).toUpperCase()+ s.substring(i+2, s.length);
		else
			s=s.substring(0, i+1)+ s.charAt(i+1).toLowerCase()+ s.substring(i+2, s.length);}
	item.value = s;
}
function isValidPostalCode(item, req, lang){
	var isGood=1;
	str=Trim(item.value).toUpperCase();
	item.value=str;
	if (str.length==0 && req==0) return true;
	if (str.length==0 && req==1) isGood = 0;
	if (str.length==6){	
		var temp;
		str = str + " ";
		for (var i=6;i>3;i--){	
			temp = str.charAt(i);
			str=str.substr(0,i-1) + temp + str.charAt(i-1) + str.substr(i+1, 6-i);
			item.value=str;}}
	if (!str.length ==7) {isGood=0;}
	else if (!(isLetter(str.charAt(0)) && isDigit(str.charAt(1)) && isLetter(str.charAt(2)) && str.charAt(3)==' ' && isDigit(str.charAt(4)) && isLetter(str.charAt(5)) && isDigit(str.charAt(6)) ))
		{isGood=0;}
	if (isGood==0) {
		if (lang=="FR")
			alert("Code Postal invalide");
		else 
			alert("Invalid Postal Code");
		item.select();
		item.focus();
		return false; }
	else  
		return true; 
}
function TrimCrLf(s) {
	while (s.length>0) { if (s.charCodeAt(0)<33) s=s.substr(1,s.length-1); else break;}
	while (s.length>0) { if (s.charCodeAt(s.length-1)<33)s=s.substr(0,s.length-1); else break; }
	return s;
}
function LTrim(s) {
   	while (s.substring(0,1)==" ") { s=s.substring(1); }
   	return s; 
}
function RTrim(s) {
   	while (s.substring(s.length-1,s.length)==" ") { s=s.substring(0,s.length-1); }
   	return s; 
}
function Trim(s) {
   	return LTrim(RTrim(s)); 
}
function isLetter (c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))) 
}
function isDigit (c) {
	return ((c >= "0") && (c <= "9")) 
}
function isInteger (s) {
   	for (var i=0; i<s.length; i++) { 
   		if (!isDigit(s.charAt(i))) return false; }
   	return true; 
}

function isDigitOrLetter (c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || ((c >= "0") && (c <= "9"))) 
}
function isAlphaNumeric (s) {
   	for (var i=0; i<s.length; i++) { 
   		if (!isDigitOrLetter(s.charAt(i))) return false; }
   	return true; 
}

function isPhoneChar (s) {
   	var x=0;
   	for (var i=0; i<s.length; i++) {
   		x=s.charCodeAt(i); if (!((x>=48 && x<=57) || x==87 || x==119)) return false; }
   	return true; 
}
function isValidEmailField (item,req,lang,longueur) {
	var isGood=1;
	var str=Trim(item.value);
	if(item.value.length>longueur)
	{
		item.focus();
		item.select();
		if (lang=="FR") 
			alert("Adresse de courriel trop longue!");
		else 
			alert("Too long e-mail address!");
		return false; 
	}
	else
	{
		str=str.toLowerCase();
		item.value=str;
		if (str.length==0 && req==0) return true;
		if (str.length==0 && req==1) isGood=0;
		else if (str.indexOf("@")<2) isGood=0;
		else {
			if (str.search(/[\s!;,]/) > -1) { isGood=0; }
			else {
				var t1=str.substr(0,str.indexOf("@"));
				var t2=str.substr(str.indexOf("@")+1);
				if (t2.search(/\.com$|\.ca$|\.cc$|\.fr$|\.ch|\.qc\.ca$|\.org$|\.net$|\.ws$/i)<2) { isGood=0; } } }
	}
	if (isGood==0) {
		item.focus();
		item.select();
		if (lang=="FR") alert("Adresse de courriel invalide");
		else alert("Invalid e-mail address");
		return false; }
	else { return true; }
}
function getAllSelectInfo(cbo, quoted)
{
	var tmp="";
	for(var i=0;i<cbo.length;i++)
	{
		if(quoted)
			tmp+="'"+cbo.options[i].value+"'";
		else
			tmp+=cbo.options[i].value;
		if(i<(cbo.length-1))
			tmp+=","
	}
	return tmp;
}
function getAllChkInfo(cbo, quoted)
{
	var tmp="";
	for(var i=0;i<cbo.length;i++)
	{
		if(cbo[i].checked)
		{
			if(quoted)
				tmp+="'"+cbo[i].value+"',";
			else
				tmp+=cbo[i].value+",";
		}
	}
	if (tmp.length > 0)
		tmp=tmp.substr(0,tmp.length-1);
	return tmp;
}
function isValidDate (a, m, j, lang) {
	var isValid=1;
	if (m==4 || m==6 || m==9 || m==11) if(j>30) isValid=0;
	if (m==2) isValid=((a%4==0) && (a%100 !=0 || a%400==0) ? ((j>29)?0:1):(j>28)?0:1);
	if (isValid==0) {
		if (lang=="FR") alert("Date invalide");
		else alert("Invalid date");
		return false; }
	else { return true; }
}
function getRadioValue(item)
{
	var sel = false;
	var val = null;
	var i=0;
	while (!sel && i<item.length)
	{
		if(item[i].checked)
		{
			sel = true;
			val = item[i].value;
		}
		i++;	
	}
	return val;
}
-->
