
var navigate = "";
var frmaction = "";
var strErr = "";
var strErrVal = "";

function required(theForm,varlid){
	if (navigate != "prv"){
		var complete = true;
		switch (varlid){
			case "FR":{
				strErr = "Veuillez accomplir les conditions suivantes de l'aperçu.\n";	
				var strErrM = "Toutes les options d'estimation de matrice de ";
				var strErrSM = "Tous les champs des boîtes multiples des textes de ";
				var strGridC = "Au moins une option par rangée de la grille de Matrix ";
				var strErrCheck1 = "Vous devez sélectionner un maximum de ";
				var strErrCheck2 = " options de réponses pour la ";
				var strErrTextN1 = "La somme de toutes vos réponses à la ";
				var strErrTextN2 = " devrait égaler à ";				
				break;
			}
			default:{
				strErr = "Please complete the following requirements of the survey.\n";	
				var strErrM = "All the answer options of Matrix/Grid ";
				var strErrSM = "All the Text Boxes of ";
				var strGridC = "At least one answer option per row of the Matrix/Grid ";
				var strErrCheck1 = "You must select only up to ";
				var strErrCheck2 = " answers options for ";
				var strErrTextN1 = "The total of all the answers of ";
				var strErrTextN2 = " should add up to ";				
				break;
			}
		}
		for (i = 0; i < theForm.length; i++){
			ctrlName = theForm[i].name;
			if (ctrlName.substr(0,1) == "r"){ 				
				if (trim(theForm[i].value) == ""){
					strErr += theForm[i].title + ".\n";
					complete = false;					
				}
				else{
					if (ctrlName.substr(0,2) == "rq"){
						vqtype = eval("theForm.hqt" + ctrlName + ".value");
						if ((vqtype == "TextSM" ) && (typeof(eval("theForm.hta" + ctrlName)) == "object")){
							vatl = eval("theForm.atl" + ctrlName + ".value");
							if (vatl != 1 ){
								vtota = eval("theForm.hta" + ctrlName + ".value");
								vans = 0
								var checkStr = theForm[i].value;					
								for (j=0; j < checkStr.length; j++)
								{
									ch = checkStr.charAt(j);
									if (ch == "~")
										vans++;						
								}				
								if (vans != vtota){								
									strErr += strErrSM + theForm[i].title + "\n";
									complete = false;
								}
							}						
						}
						if ((vqtype == "GridT" || vqtype == "GridS") && typeof(eval("theForm.hta" + ctrlName)) == "object"){
							vtota = eval("theForm.hta" + ctrlName + ".value");
							vans = 0
							var checkStr = theForm[i].value;					
							for (j=0; j < checkStr.length; j++)
							{
								ch = checkStr.charAt(j);
								if (ch == "~")
									vans++;						
							}				
							if (vans != vtota){								
								strErr += strErrM + theForm[i].title + "\n";
								complete = false;
							}						
						}
						if ((vqtype == "MatrixM" || vqtype == "GridR") && typeof(eval("theForm.hta" + ctrlName)) == "object"){
							vtota = eval("theForm.hta" + ctrlName + ".value");
							vans = 0
							var checkStr = theForm[i].value;					
							for (j=0; j < checkStr.length; j++)
							{
								ch = checkStr.charAt(j);
								if (ch == "~")
									vans++;						
							}				
							if (vans != vtota){								
								strErr += strGridC + theForm[i].title + "\n";
								complete = false;
							}						
						}
						if ((vqtype == "GridC") && typeof(eval("theForm.hta" + ctrlName)) == "object"){						
							vtota = eval("theForm.hta" + ctrlName + ".value");					
							vans = 0
							var checkStr = theForm[i].value;					
							for (j=1; j <= vtota; j++)
							{
								if (checkStr.indexOf("~" + j + "-") != -1)														
									vans++;						
							}																					
							if (vans != vtota){								
								strErr += strGridC + theForm[i].title + "\n";
								complete = false;
							}						
						}
						if (vqtype == "Radio" && theForm[i].value == "~0" && typeof(eval("theForm.hta" + ctrlName)) == "object"){						
							strErr += theForm[i].title + ".\n";
							complete = false;
						}
						if ((vqtype == "Check") && (typeof(eval("theForm.hma" + ctrlName)) == "object") && (theForm[i].value.indexOf("~n") == -1)){
							vtota = eval("theForm.hma" + ctrlName + ".value");
							vtotadisp = vtota;
							if (theForm[i].value.indexOf("~0") != -1){
								vtota++
							}
							vans = 0
							var checkStr = theForm[i].value;					
							for (j=0; j < checkStr.length; j++)
							{
								ch = checkStr.charAt(j);
								if (ch == "~")
									vans++;						
							}				
							if (vans > vtota){								
								strErr += strErrCheck1 + vtotadisp + strErrCheck2 + theForm[i].title + "\n";
								complete = false;
							}						
						}
						if (vqtype == "TextN" && typeof(eval("theForm.hta" + ctrlName)) == "object"){						
							vtota = eval("theForm.hta" + ctrlName + ".value");					
							var vans = 0; 
							var ctot = 0;
							var totval = 0;
							var cval=0;
							var checkStr = theForm[i].value;					
							for (j=0; j < checkStr.length; j++)
							{
								ch = checkStr.charAt(j);
								if (ch == "~")
									vans++;						
							}				
							if (vans != vtota){
								strErr += strErrSM + theForm[i].title + "\n";
								complete = false;
							}
							for (j=1; j <= vtota; j++)
							{
								cval = eval("theForm.val_" + j + ctrlName + ".value");								
								if (cval != "" && !(isNaN(cval))) 
									ctot += parseFloat(cval);					
							}							
							totval = eval("theForm.totval_" + ctrlName + ".value");
							if (totval != "")
								totval = parseFloat(totval);
							if (ctot != totval){
								strErrTot = strErrTextN1 + theForm[i].title + strErrTextN2 + totval;
								strErr += strErrTot + "\n";
								complete = false;
							}								
						}
						if ((vqtype == "Date") && (typeof(eval("theForm.hvl" + ctrlName)) == "object") && (theForm[i].value != "")){
								var dt=theForm[i];							
								if (isDateLang(dt.value,theForm[i].title,varlid)==false){								
									complete = false;
								}							
						}
						if ((vqtype == "TextS") && (typeof(eval("theForm.hvl" + ctrlName)) == "object") && (theForm[i].value != "")){
							vvalid = eval("theForm.hvl" + ctrlName + ".value");						
							vans = theForm[i].value;
							complete = ValidateTextLang(vvalid,vans,complete,theForm[i],varlid);											
						}
					}
					else{
						if (ctrlName.substr(0,4) == "rpin"){						
							if ((typeof(eval("theForm.hvl" + ctrlName)) == "object") && (theForm[i].value != "")){
								vvalid = eval("theForm.hvl" + ctrlName + ".value");						
								vans = theForm[i].value;							
								complete = ValidateTextLang(vvalid,vans,complete,theForm[i],varlid);											
							}						
						}					
					}				
				}
			}
			else{
				if (ctrlName.substr(0,3) == "qtn"){				
					vqtype = eval("theForm.hqt" + ctrlName + ".value");					
					if (vqtype == "TextN" && typeof(eval("theForm.hta" + ctrlName)) == "object"){						
						vtota = eval("theForm.hta" + ctrlName + ".value");					
						var vans = 0; 
						var ctot = 0;
						var totval = 0;
						var cval=0;						
						for (j=1; j <= vtota; j++)
						{
							cval = eval("theForm.val_" + j + ctrlName + ".value");								
							if (cval != "" && !(isNaN(cval))) 
								ctot += parseFloat(cval);					
						}
						if (ctot > 0) {							
							totval = eval("theForm.totval_" + ctrlName + ".value");
							if (totval != "")
								totval = parseFloat(totval);
							if (ctot != totval){
								strErrTot = strErrTextN1 + theForm[i].title + strErrTextN2 + totval;
								strErr += strErrTot + "\n";
								complete = false;
							}
						}								
					}
					if ((vqtype == "Check") && (typeof(eval("theForm.hma" + ctrlName)) == "object") && (theForm[i].value.indexOf("~n") == -1) && (theForm[i].value != "")){
						vtota = eval("theForm.hma" + ctrlName + ".value");
						vtotadisp = vtota;
						if (theForm[i].value.indexOf("~0") != -1){
							vtota++
						}
						vans = 0
						var checkStr = theForm[i].value;					
						for (j=0; j < checkStr.length; j++)
						{
							ch = checkStr.charAt(j);
							if (ch == "~")
								vans++;						
						}				
						if (vans > vtota){								
							strErr += strErrCheck1 + vtotadisp + strErrCheck2 + theForm[i].title + "\n";
							complete = false;
						}						
					}
					if ((vqtype == "Date") && (typeof(eval("theForm.hvl" + ctrlName)) == "object") && (theForm[i].value != "")){
							var dt=theForm[i];							
							if (isDateLang(dt.value,theForm[i].title,varlid)==false){								
								complete = false;
							}							
					}										
					if ((vqtype == "TextS") && (typeof(eval("theForm.hvl" + ctrlName)) == "object") && (theForm[i].value != "")){
						vvalid = eval("theForm.hvl" + ctrlName + ".value");						
						vans = theForm[i].value;
						complete = ValidateTextLang(vvalid,vans,complete,theForm[i],varlid);											
					}
				}				
				if (ctrlName.substr(0,3) == "pin"){						
					if ((typeof(eval("theForm.hvl" + ctrlName)) == "object") && (theForm[i].value != "")){
						vvalid = eval("theForm.hvl" + ctrlName + ".value");						
						vans = theForm[i].value;							
						complete = ValidateTextLang(vvalid,vans,complete,theForm[i],varlid);											
					}						
				}
				if (ctrlName.substr(0,3) == "tsm"){										
					ctrlTextBox = ctrlName.substring(3,ctrlName.length);					
					if ((typeof(eval("theForm.hvl" + ctrlTextBox)) == "object") && (theForm[i].value != "")){
						vvalid = eval("theForm.hvl" + ctrlTextBox + ".value");						
						vans = theForm[i].value;							
						complete = ValidateTextLang(vvalid,vans,complete,theForm[i],varlid);											
					}					
				}									
			}									
		}
		if (complete){
			theForm.action = frmaction;			
			return true;
		}
		else{			
			alert(strErr);
			return false;
		}	
	}
	else
		return true;
									
}

/*Code by Nadun - Minimum Comment Validation - Starts*/
function trimString(strInput)
{
	return strInput.replace(/(^\s*)|(\s*$)/g, "");
}

function valMinCom(theForm,minComms){
	var totComs = 0;
	for (i = 0 ; i < theForm.length; i++) {			
		if ((theForm.elements[i].name.substring(0,3) == "com" || theForm.elements[i].name.substring(0,4) == "rcom")){			
			if (trimString(theForm.elements[i].value)!="")
				totComs = totComs + 1;
		}
		/*if (theForm.elements[i].name.substring(0,4) == "ctxt"){			
			if (trimString(theForm.elements[i].value)!="")
				totComs = totComs + 1;
		}*/
	}

	if (minComms>totComs)
		return false;
	else
		return true;
}
/*Code by Nadun - Minimum Comment Validation - Ends*/

function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}
function trim ( s )
{
	return rtrim(ltrim(s));
}

function switchImgYN(currentNum, totalNum, imageName, fieldName, fieldValue, radioOnPath, radioOffPath) {	
	for (i = 0; i<=totalNum; i++) {
		if (i == currentNum) { switchImg('Image_' + imageName + '_' + i, 'button-on'); }
		else { switchImg('Image_' + imageName + '_' + i,  'button-off'); }
	}	
}

function switchImgRadio(currentNum, totalNum, imageName, fieldName, fieldValue, radioOnPath, radioOffPath) {	
	for (i = 0; i<=totalNum; i++) {
		if (i == currentNum) { switchImg('Image_' + imageName + '_' + i, 'radio-on'); }
		else { switchImg('Image_' + imageName + '_' + i,  'radio-off'); }
	}	
}

function switchImgCheck(currentNum, totalNum, imageName, fieldName, fieldValue, radioOnPath, radioOffPath) {	
	for (i = 1; i<=totalNum; i++) {
		if (i == currentNum) { 
			switchImg('Image_' + imageName + '_' + i, 'check-on'); 
		}
		else { 
			chdn = eval("document.frmSurvey.hdn_" + i + imageName);
			chdn.value = "";
			switchImg('Image_' + imageName + '_' + i, 'check-off'); 
		}
	}	
}

function switchRealCheck(currentNum, totalNum, imageName, fieldName, fieldValue, radioOnPath, radioOffPath) {	
	for (i = 1; i<=totalNum; i++) {
		if (i == currentNum) { 
			chdn = eval("document.frmSurvey.Image_" + imageName + '_' + i);
			chdn.value = "on";
		}
		else { 
			chdn = eval("document.frmSurvey.hdn_" + i + imageName);
			chdn.value = "";
			chdn2 = eval("document.frmSurvey.Image_" + imageName + '_' + i);
			chdn2.value = "off";
		}
	}	
}

function switchImgCheckSLG(currentNum, totalNum, imageName, fieldName, fieldValue, radioOnPath, radioOffPath,theForm) {	
	for (i = 1; i<=totalNum; i++) {
		if (i == currentNum) { 
			switchImg('Image_' + imageName + '_' + i, radioOnPath); 
		}
		else { 
			chdn = eval("document." + theForm + ".hdn_" + i + imageName);
			chdn.value = "";
			switchImg('Image_' + imageName + '_' + i, radioOffPath); 
		}
	}	
}

/*function switchImgMS(currentNum, totalNum, imageName, fieldName, fieldValue, radioOnPath, radioOffPath) {	
	for (i = 0; i<=totalNum; i++) {
		if (i == currentNum) { switchImg('Image_' + imageName + '_' + i, radioOnPath + 'button-'+ (i+1) + '-1.gif'); }
		else { switchImg('Image_' + imageName + '_' + i, radioOffPath + 'button-'+ (i+1) + '-0.gif'); }
	}
}*/

function switchImgMM(currentNum, totalNum, imageName, fieldName, beginPos, radioOnPath, radioOffPath) {	
	for (i = beginPos; i<=totalNum; i++) {
		if (i == currentNum) { switchImg('Image_' + imageName + '_' + i, 'button-on'); }
		else { switchImg('Image_' + imageName + '_' + i, 'button-off'); }
	}
}

function switchImgGR(currentNum, totalNum, imageName, fieldName, beginPos, radioOnPath, radioOffPath) {	
	for (i = beginPos; i<=totalNum; i++) {
		if (i == currentNum) { switchImg('Image_' + imageName + '_' + i, 'radio-on'); }
		else { switchImg('Image_' + imageName + '_' + i, 'radio-off'); }
	}
}

function switchImg(id, newSrc) {	
	 document.getElementById(id).className = newSrc;
	 window.focus();	 
}

function CheckNumeric(txtControl,bolzero,varlid){
	switch (varlid){
		case "FR":{			
			var strErrNumeric1 = "Cette réponse peut seulement être donnée en chiffres";
			var strErrNumeric2 = "La valeur de chaque réponse à cette question doit être plus que 0";				
			break;
		}
		default:{			
			var strErrNumeric1 = "This answer only accept numbers";
			var strErrNumeric2 = "All the answer values of this question shoud be greater than 0";
			break;
		}
	}
	txtControl = eval("document.frmSurvey." + txtControl.name);	
	if (isNaN(txtControl.value))
	{
		strErr = strErrNumeric1;
		alert(strErr);
		setTimeout(function(){txtControl.focus();txtControl.select();},10);
		return false;
	}
	else
		if (bolzero == 1) {			
			if (parseFloat(txtControl.value) <= 0){
				strErr = strErrNumeric2;
				alert(strErr);
				setTimeout(function(){txtControl.focus();txtControl.select();},50);
				return false;			
			}
			else
				return true;
		}
		else
			return true;
}

function CalcTextN(totans,varqtn){	
	var ctot = 0;	
	for (i = 1 ; i < totans+1; i++) {		
		cval = eval("document.frmSurvey.val_" + i + varqtn + ".value");				
		if (cval != "" && !(isNaN(cval))) 
			ctot += parseFloat(cval);	
	}
	totcontrol = eval("document.frmSurvey.totval_" + varqtn);
	totcontrol.value = ctot ;
}

//Email Validation
// BOI, followed by one or more characters, followed by @,
// followed by one or more characters, followed by ., 
// followed by one or more characters, followed by EOI.
var reEmail = /^.+\@.+\..+$/;

function isEmail (s){  	
	return reEmail.test(s)
}

//US zip code validation
var reUSZipCode = /(^\d{5}$)|(^\d{5}-\d{4}$)/

function isZIPCode (s){
   return reUSZipCode.test(s);
}

//CA Postal code validation
var reCAPostal = /([A-Za-z]\d[A-Za-z](| |-)\d[A-Za-z]\d)$/;

function isPostalCode (s){  	
	return reCAPostal.test(s)
}

// BOI, followed by one or more digits, followed by EOI.
var reInteger = /^\d+$/;

function isInteger (s){       
    return reInteger.test(s);
}

//Single decimal validation
var reFloatSD = /^\d*\.{1}\d{1}$/;

function isFloatSD (s){       
    return reFloatSD.test(s);
}

//Double decimal validation
var reFloatDD = /^\d*\.{1}\d{2}$/;

function isFloatDD (s){       
    return reFloatDD.test(s);
}

//US Phone number validation
// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;

function isUSPhoneNumber (s){   
	return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function ValidateText(varvalid,varans,complete,control){		
	switch (varvalid) {
		case "1" : {
			if (!isZIPCode(varans)){								
				strErrVal = "Invalid zip code format in " + control.title + "\n";
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "2" : {
			if (!isPostalCode(varans)){								
				strErrVal = "Invalid postal code format in " + control.title + "\n";
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "3" : {
			varDigits = "0123456789"
			varans = stripCharsNotInBag(varans,varDigits);
			if (!isUSPhoneNumber(varans)){								
				strErrVal = "Invalid phone number format in " + control.title + "\n";
				strErr += strErrVal;
				complete = false;
			}
			else
			{				
				valcontrol = eval("document.frmSurvey." + control.name);				
				if (control.name.substr(0,4) == "rpin"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(4,control.name.length);
					txtcontrol = eval("document.frmSurvey.rpin" + varqtnid);
					txtcontrol.value = varans ;					
				}
				if (control.name.substr(0,3) == "pin"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(3,control.name.length);
					txtcontrol = eval("document.frmSurvey.pin" + varqtnid);
					txtcontrol.value = varans ;
				}
				if (control.name.substr(0,4) == "rqtn"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(4,control.name.length);
					txtcontrol = eval("document.frmSurvey.txt" + varqtnid);
					txtcontrol.value = varans ;
				}
				if (control.name.substr(0,3) == "qtn"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(3,control.name.length);
					txtcontrol = eval("document.frmSurvey.txt" + varqtnid);
					txtcontrol.value = varans ;
				}
				if (control.name.substr(0,3) == "tsm"){										
					txtcontrol = valcontrol;
					var tsmundpos = txtcontrol.name.indexOf("_");
					var tsmqstart =  txtcontrol.name.indexOf("r");
					if (tsmqstart == -1) {
						tsmqstart =  txtcontrol.name.indexOf("q");
					}
					var tsmansno = txtcontrol.name.substring(tsmundpos+1,tsmqstart);
					var tsmqtnname = txtcontrol.name.substring(tsmqstart,txtcontrol.name.length);					
					s = varans; 
					s = s.replace( /^\s*/,'');
					s = s.replace( /\s*$/,'' );
					if ( s != '') {
						txtqtncontrol = eval("document.frmSurvey." + tsmqtnname);
						txtqtncontrol.value = txtqtncontrol.value.replace('~' + tsmansno + '-' + s,'');
						varans = reformat(varans,"",3, "-", 3, "-", 4);
						if (txtqtncontrol.value.indexOf('~' + tsmansno + '-' + varans) == -1){
							txtqtncontrol.value = txtqtncontrol.value + '~' + tsmansno + '-' + varans;
						}					
						txtcontrol.value = varans ;
					}										
				}																						
			}								
			break;
		}
		case "4" : {
			if (!isEmail(varans)){												
				strErrVal = "Invalid email address format in " + control.title + "\n";
				strErr += strErrVal;				
				complete = false;
			}
			break;
		}
		case "5" : {
			if (!isInteger(varans)){								
				strErrVal = "Invalid number format in " + control.title + ". The answer should be an integer.\n";
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "6" : {
			if (!isFloatSD(varans)){								
				strErrVal = "Invalid number format in " + control.title + ". The answer should be numeric with one decimal.\n";
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "7" : {
			if (!isFloatDD(varans)){								
				strErrVal = "Invalid number format in " + control.title + ". The answer should be numeric with two decimals.\n";
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "8" : {
			if (!isPostalCode(varans) && !isZIPCode(varans)){								
				strErrVal = "Invalid zip or postal code format in " + control.title + "\n";
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "9" : {
			if (!(isInteger(varans) || isFloatSD(varans) || isFloatDD(varans)))
			{
				strErrVal = "Invalid number format in " + control.title + ". The answer should be numeric with no more than two decimals.\n";
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "10" : {
			if (!(isInteger(varans) || isFloatSD(varans) || isFloatDD(varans)))
			{
				strErrVal = "Invalid number format in " + control.title + ". The answer should be numeric with no more than two decimals.\n";
				strErr += strErrVal;
				complete = false;
			}
		}
	}					
	return complete;
}


var dtCh= "/";
var minYear=1900;
var maxYear=2500;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,qtnStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){		
		strErr += "Invalid date format in " + qtnStr + ". The date format should be : mmm/dd/yyyy." + "\n";
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){		
		strErr += "Invalid date format in " + qtnStr + ". Please select a valid month." + "\n";
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){		
		strErr += "Invalid date format in " + qtnStr + ". Please select a valid day." + "\n";
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){		
		strErr += "Invalid date format in " + qtnStr + ". Please select a valid year." + "\n";
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){		
		strErr += "Invalid date format in " + qtnStr + ". Please select a valid date." + "\n";
		return false;
	}
	return true;
}

function keyPress(e){	
	var keynum
	if(window.event) // IE
	{
		if (e.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
		}
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		if (e.which == 13)
		{
		    e.cancelBubble = true;
		    return false;
		}
	}	
}










function ValidateTextLang(varvalid,varans,complete,control,varlid){		
	switch (varvalid) {
		case "1" : {
			if (!isZIPCode(varans)){
				switch (varlid){
					case "FR":{
						strErrVal = "Code postal incorrect format dans la '" + control.title + "'\n";
						break;}
					default:{
						strErrVal = "Invalid zip code format in " + control.title + "\n";
						break;}
				}
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "2" : {
			if (!isPostalCode(varans)){		
				switch (varlid){
					case "FR":{
						strErrVal = "Code postal incorrect format dans la '" + control.title + "'\n";
						break;}
					default:{
						strErrVal = "Invalid postal code format in " + control.title + "\n";
						break;}
				}
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "3" : {
			varDigits = "0123456789"
			varans = stripCharsNotInBag(varans,varDigits);
			if (!isUSPhoneNumber(varans)){	
				switch (varlid){
					case "FR":{
						strErrVal = "Numéro de téléphone non valide format dans la '" + control.title + "'\n";
						break;}
					default:{
						strErrVal = "Invalid phone number format in " + control.title + "\n";
						break;}
				}
				strErr += strErrVal;
				complete = false;
			}
			else
			{				
				valcontrol = eval("document.frmSurvey." + control.name);				
				if (control.name.substr(0,4) == "rpin"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(4,control.name.length);
					txtcontrol = eval("document.frmSurvey.rpin" + varqtnid);
					txtcontrol.value = varans ;					
				}
				if (control.name.substr(0,3) == "pin"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(3,control.name.length);
					txtcontrol = eval("document.frmSurvey.pin" + varqtnid);
					txtcontrol.value = varans ;
				}
				if (control.name.substr(0,4) == "rqtn"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(4,control.name.length);
					txtcontrol = eval("document.frmSurvey.txt" + varqtnid);
					txtcontrol.value = varans ;
				}
				if (control.name.substr(0,3) == "qtn"){
					varans = reformat(varans,"",3, "-", 3, "-", 4);
					valcontrol.value = varans ;
					varqtnid = control.name.substring(3,control.name.length);
					txtcontrol = eval("document.frmSurvey.txt" + varqtnid);
					txtcontrol.value = varans ;
				}
				if (control.name.substr(0,3) == "tsm"){										
					txtcontrol = valcontrol;
					var tsmundpos = txtcontrol.name.indexOf("_");
					var tsmqstart =  txtcontrol.name.indexOf("r");
					if (tsmqstart == -1) {
						tsmqstart =  txtcontrol.name.indexOf("q");
					}
					var tsmansno = txtcontrol.name.substring(tsmundpos+1,tsmqstart);
					var tsmqtnname = txtcontrol.name.substring(tsmqstart,txtcontrol.name.length);					
					s = varans; 
					s = s.replace( /^\s*/,'');
					s = s.replace( /\s*$/,'' );
					if ( s != '') {
						txtqtncontrol = eval("document.frmSurvey." + tsmqtnname);
						txtqtncontrol.value = txtqtncontrol.value.replace('~' + tsmansno + '-' + s,'');
						varans = reformat(varans,"",3, "-", 3, "-", 4);
						if (txtqtncontrol.value.indexOf('~' + tsmansno + '-' + varans) == -1){
							txtqtncontrol.value = txtqtncontrol.value + '~' + tsmansno + '-' + varans;
						}					
						txtcontrol.value = varans ;
					}										
				}																						
			}								
			break;
		}
		case "4" : {
			if (!isEmail(varans)){	
				switch (varlid){
					case "FR":{
						strErrVal = "Adresse e-mail incorrecte format dans la '" + control.title + "'\n";
						break;}
					default:{
						strErrVal = "Invalid email address format in " + control.title + "\n";
						break;}
				}
				strErr += strErrVal;				
				complete = false;
			}
			break;
		}
		case "5" : {
			if (!isInteger(varans)){	
				switch (varlid){
					case "FR":{
						strErrVal = "Nombre incorrect format dans la '" + control.title + "'. La réponse devrait être un entier.\n";
						break;}
					default:{
						strErrVal = "Invalid number format in " + control.title + ". The answer should be an integer.\n";
						break;}
				}
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "6" : {
			if (!isFloatSD(varans)){	
				switch (varlid){
					case "FR":{
						strErrVal = "Nombre incorrect format dans la '" + control.title + "'. La réponse devrait être numérique avec une décimale.\n";
						break;}
					default:{
						strErrVal = "Invalid number format in " + control.title + ". The answer should be numeric with one decimal.\n";
						break;}
				}
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "7" : {
			if (!isFloatDD(varans)){	
				switch (varlid){
					case "FR":{
						strErrVal = "Nombre incorrect format dans la '" + control.title + "'. La réponse devrait être numérique avec deux décimales.\n";	
						break;}
					default:{
						strErrVal = "Invalid number format in " + control.title + ". The answer should be numeric with two decimals.\n";
						break;}
				}
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "8" : {
			if (!isPostalCode(varans) && !isZIPCode(varans)){	
				switch (varlid){
					case "FR":{
						strErrVal = "Code postal incorrect format dans la '" + control.title + "'\n";
						break;}
					default:{
						strErrVal = "Invalid zip or postal code format in " + control.title + "\n";
						break;}
				}				
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "9" : {
			if (!(isInteger(varans) || isFloatSD(varans) || isFloatDD(varans)))
			{
				switch (varlid){
					case "FR":{
						strErrVal = "Nombre incorrect format dans la '" + control.title + "'. La réponse devrait être numérique avec pas plus de deux décimales.\n";
						break;}
					default:{
						strErrVal = "Invalid number format in '" + control.title + "'. The answer should be numeric with no more than two decimals.\n";
						break;}
				}				
				strErr += strErrVal;
				complete = false;
			}
			break;
		}
		case "10" : {
			if (!(isInteger(varans) || isFloatSD(varans) || isFloatDD(varans)))
			{
				switch (varlid){
					case "FR":{
						strErrVal = "Nombre incorrect format dans la '" + control.title + "'. La réponse devrait être numérique avec pas plus de deux décimales.\n";
						break;}
					default:{
						strErrVal = "Invalid number format in '" + control.title + "'. The answer should be numeric with no more than two decimals.\n";
						break;}
				}				
				strErr += strErrVal;
				complete = false;
			}
		}
	}					
	return complete;
}
function isDateLang(dtStr,qtnStr,varlid){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){		
		switch (varlid){
			case "FR":{
				strErr += "Format de date incorrecte à la '" + qtnStr + "'. Le format de date doit être: mmm/jj/aaaa" + "\n";
				break;}
			default:{
				strErr += "Invalid date format in " + qtnStr + ". The date format should be : mmm/dd/yyyy." + "\n";
				break;}
		}	
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){		
		switch (varlid){
			case "FR":{
				strErr += "Format de date incorrecte à la '" + qtnStr + "'. S'il vous plaît choisir valide mois." + "\n";
				break;}
			default:{
				strErr += "Invalid date format in " + qtnStr + ". Please select a valid month." + "\n";
				break;}
		}	
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){		
		switch (varlid){
			case "FR":{
				strErr += "Format de date incorrecte à la '" + qtnStr + "'. S'il vous plaît choisir valable jour." + "\n";
				break;}
			default:{
				strErr += "Invalid date format in " + qtnStr + ". Please select a valid day." + "\n";
				break;}
		}	
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){		
		switch (varlid){
			case "FR":{
				strErr += "Format de date incorrecte à la '" + qtnStr + "'. S'il vous plaît choisir valide année." + "\n";
				break;}
			default:{
				strErr += "Invalid date format in " + qtnStr + ". Please select a valid year." + "\n";
				break;}
		}	
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){		
		switch (varlid){
			case "FR":{
				strErr += "Format de date incorrecte à la '" + qtnStr + "'. S'il vous plaît choisir une période." + "\n";
				break;}
			default:{
				strErr += "Invalid date format in " + qtnStr + ". Please select a valid date." + "\n";
				break;}
		}	
		return false;
	}
	return true;
}
