// Validate Numeric input
// general purpose functions to see if an input value has been entered.
function isEmpty(inputStr) {
	if (inputStr == null || inputStr == "") {
		return true
	}
	return false
}

// general functions that validate numbers
function isPosInteger(inputVal){
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++){
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar > "9"){
			return false		
		}
	}
	return true
}
function isInteger(inputVal){
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++){
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-"){
			continue		
		}
		if (oneChar < "0" || oneChar > "9"){
			return false		
		}
	}
	return true
}
function isNumber(inputVal){
	oneDecimal = false
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++){
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-"){
			continue		
		}
		if (oneChar == "." && !oneDecimal){
			oneDecimal = true
			continue
		}
		if (oneChar < "0" || oneChar > "9"){
			return false		
		}
	}
	return true
}

var chkDot = true;
var usEmail = true;
   
function validEmail(eAddr) { 
	var lenSuffix = (usEmail) ? 4 : 3;
    var goodAddr = false;
    var ndxAt = ndxDot =  0;
    var exclude = /[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
          
    ndxAt  = eAddr.indexOf("@");
    ndxDot = eAddr.indexOf(".") ;
    ndxDot2 = eAddr.lastIndexOf(".") ;
          
	if ( (ndxDot < 0) || (ndxAt < 0) )
		alert("Il manque un '.' ou le '@'.\n\nà votre adresse de courriel. Le format est 'votrenom@domaine.suf'");  
	else if ( (ndxDot2 - 3) <= ndxAt)
		alert("Il manque peut-être le nom du domaine.\n\nLe format est 'votrenom@domaine.suf'");
	else if (eAddr.search(exclude) != -1)
		alert("Votre adresse de courriel contient des  caractères invalides.\n\nLe format est 'votrenom@domaine.suf'") 
	else
		goodAddr = true;
   
	return (goodAddr); 
} 

function isPostalCode(fPC1, fPC2){
	sPC1 = fPC1.value.toString()
	sPC2 = fPC2.value.toString()
	var checkPostal1 = /([A-Za-z]\d[A-Za-z])/
	var checkPostal2 = /(\d[A-Za-z]\d)/
	
	// Check first three.
	if (sPC1.search(checkPostal1) == -1){
			alert("Les trois premiers caractères de votre code postal sont invalides")
			fPC1.focus()
			return false
	}	

	// Check Last three.
	if (sPC2.search(checkPostal2) == -1){
			alert("Les trois derniers caractères de votre code postal sont invalides")
			fPC2.focus()
			return false
	}		
	return true;
}

function placeFocus() {

if (document.forms.length > 0) {
	var field = document.forms[0];
	for (i = 0; i < field.length; i++) {
		if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
		document.forms[0].elements[i].focus();
		break;
        }
    }
}
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
		}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
		index++;
		return found;
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}

function isNumber1(strInput){
	for (var i = 0; i < strInput.length; i++) {
		var oneChar = strInput.substring(i, 1 + i);
		if (oneChar < "0" || oneChar > "9") {
			alert("Assurez-vous d'utiliser seulement des chiffres pour indiquer les âges des enfants");
			return false;
			}
		}
		return true;
}

function checkIt(formfield) {
	strInput = formfield.value;
	if (isNumber1(strInput)) {
		// statement is true
		} else {
		formfield.value = "";
		formfield.focus();
		}
}
function isExistingMemberChecked(rdExistingMember) {
	var bExistingMember = false
	for (var counter = 0; counter < rdExistingMember.length; counter++){
		if (rdExistingMember[counter].checked == true){
			bExistingMember = true;	
		}
	}
	if (!bExistingMember){
		window.alert ("Veuillez indiquer si vous avez déjà un REÉÉ Heritage.\n");
	}
	return bExistingMember;
}

function isContestRefChecked(oForm) {
	var bRefChecked = false
	if (oForm.cbCanada.checked == true){
			bRefChecked = true;	
	}
	else if (oForm.cbFamilyCom.checked == true){
			bRefChecked = true;	
	}
	else if (oForm.cbeKids.checked == true){
			bRefChecked = true;
	}
	else if (oForm.cbYikes.checked == true){
			bRefChecked = true;	
	}
	else if (oForm.cbCCD.checked == true){
			bRefChecked = true;	
	}
	else if (oForm.cbGrowingFamily.checked == true){
			bRefChecked = true;	
	}	
	else if (oForm.cbOther.checked == true){
			if (oForm.txtOther.value != ""){
				bRefChecked = true;
			}
			else {
				window.alert ("Comment avez-vous entendu parler du concours ?\n");
				oForm.txtOther.focus();
				return bRefChecked
			}	
	}
	if (!bRefChecked){
		window.alert ("Comment avez-vous entendu parler du concours ?\n");
		oForm.cbCanada.focus();
	}
	return bRefChecked;
}

function VerifyOneChild( sForm ) {

	if ( !isEmpty(sForm.txtCName1.value) && (!isNumber(sForm.txtCAge1.value) || isEmpty(sForm.txtCAge1.value))) {
					window.alert ("SVP entrez un âge valide " + sForm.txtCName1.value + ".\n");
					sForm.txtCAge1.focus();
					return false;
	}
						
	if ( !isEmpty(sForm.txtCName1.value) && sForm.txtCAge1.value >= 15 ) {
					window.alert ("Seuls les enfants de moins de 15 ans \n peuvent souscrire à un REÉÉ Héritage.\n" );
					sForm.txtCAge1.focus();
					return false;
	}
	if ( !isEmpty(sForm.txtCAge1.value) && isEmpty(sForm.txtCName1.value)){
			window.alert ("Entrez le nom d'un enfant.\n");
			sForm.txtCName1.focus();
			return false;
	}
// Check all children for entries		
	if ( isEmpty(sForm.txtCName1.value) && isEmpty(sForm.txtCAge1.value)) {
					window.alert ("Aucun enfant n'a été entré.\n");
					sForm.txtCName1.focus();
					return false;
		}
	return true
}
function Verify( sForm ) {

	if ( !isEmpty(sForm.txtCName1.value) && (!isNumber(sForm.txtCAge1.value) || isEmpty(sForm.txtCAge1.value))) {
		window.alert ("SVP entrez un âge valide " + sForm.txtCName1.value + ".\n");
		sForm.txtCAge1.focus();
		return false;
	}
						
	if ( !isEmpty(sForm.txtCName1.value) && sForm.txtCAge1.value >= 15 ) {
					window.alert ("Seuls les enfants de moins de 15 ans \n peuvent souscrire à un REÉÉ Héritage.\n" );
					sForm.txtCAge1.focus();
					return false;
	}
	if ( !isEmpty(sForm.txtCAge1.value) && isEmpty(sForm.txtCName1.value)){
			window.alert ("Entrez le nom d'un enfant.\n");
			sForm.txtCName1.focus();
			return false;
	}
	if ( !isEmpty(sForm.txtCName2.value) && (!isNumber(sForm.txtCAge2.value) || isEmpty(sForm.txtCAge2.value))) {
					window.alert ("SVP entrez un âge valide " + sForm.txtCName2.value + ".\n");
					sForm.txtCAge2.focus();
					return false;
	}
	if ( !isEmpty(sForm.txtCName2.value) && sForm.txtCAge2.value >= 15 ) {
					window.alert ("Seuls les enfants de moins de 15 ans \n peuvent souscrire à un REÉÉ Héritage.\n" );
					sForm.txtCAge2.focus();
					return false;
	}
					
	if ( !isEmpty(sForm.txtCAge2.value) && isEmpty(sForm.txtCName2.value)){
			window.alert ("Entrez le nom d'un enfant.\n");
			sForm.txtCName2.focus();
			return false;
	}
	if ( !isEmpty(sForm.txtCName3.value) && (!isNumber(sForm.txtCAge3.value) || isEmpty(sForm.txtCAge3.value))) {
					window.alert ("SVP entrez un âge valide " + sForm.txtCName3.value + ".\n");
					sForm.txtCAge3.focus();
					return false;
	}
	if ( !isEmpty(sForm.txtCName3.value) && sForm.txtCAge3.value >= 15 ) {
					window.alert ("Seuls les enfants de moins de 15 ans \n peuvent souscrire à un REÉÉ Héritage.\n" );
					sForm.txtCAge3.focus();
					return false;
	}
					
	if ( !isEmpty(sForm.txtCAge3.value) && isEmpty(sForm.txtCName3.value)){
			window.alert ("Entrez le nom d'un enfant.\n");
			sForm.txtCName3.focus();
			return false;
	}

	if ( !isEmpty(sForm.txtCName4.value) && (!isNumber(sForm.txtCAge4.value) || isEmpty(sForm.txtCAge4.value))) {
					window.alert ("SVP entrez un âge valide " + sForm.txtCName4.value + ".\n");
					sForm.txtCAge4.focus();
					return false;
	}
	if ( !isEmpty(sForm.txtCName4.value) && sForm.txtCAge4.value >= 15 ) {
					window.alert ("Seuls les enfants de moins de 15 ans \n peuvent souscrire à un REÉÉ Héritage.\n" );
					sForm.txtCAge4.focus();
					return false;
	}
					
	if ( !isEmpty(sForm.txtCAge4.value) && isEmpty(sForm.txtCName4.value)){
			window.alert ("Entrez le nom d'un enfant.\n");
			sForm.txtCName4.focus();
			return false;
	}			
// Check all children for entries		
	if ( isEmpty(sForm.txtCName1.value) && isEmpty(sForm.txtCAge1.value) && isEmpty(sForm.txtCName2.value) && isEmpty(sForm.txtCAge2.value) && isEmpty(sForm.txtCName3.value) && isEmpty(sForm.txtCAge3.value) && isEmpty(sForm.txtCName4.value) && isEmpty(sForm.txtCAge4.value)) {
					window.alert ("Aucun enfant n'a été entré.\n");
					sForm.txtCName1.focus();
					return false;
		}
	return true
}


function VerifyRequestInfo(sForm){

	if (isEmpty(sForm.txtOrgName.value)) {
			window.alert ("Entrez une entreprise/un organisme.\n");
			sForm.txtOrgName.focus();
			return false;
	}
	if (isEmpty(sForm.txtFName.value)) {
			window.alert ("Entrez votre prénom.\n");
			sForm.txtFName.focus();
			return false;
	}
	if (isEmpty(sForm.txtLName.value)) {
			window.alert ("Entrez votre nom.\n");
			sForm.txtLName.focus();
			return false;
	}
	if (isEmpty(sForm.txtAddress1.value)) {
			window.alert ("Entrez votre adresse.\n");
			sForm.txtAddress1.focus();
			return false;
	}
	if (isEmpty(sForm.txtCity.value)) {
			window.alert ("Entrez une ville.\n");
			sForm.txtCity.focus();
			return false;
	}
	if (isEmpty(sForm.txtProvince.options[sForm.txtProvince.selectedIndex].value)) {
			window.alert ("Sélectionnez une province.\n");
			sForm.txtProvince.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode1.value) || sForm.txtPostalCode1.value.length != 3) {
			window.alert ("Entrez les trois premiers caractères de votre code postal.\n");
			sForm.txtPostalCode1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode2.value) || sForm.txtPostalCode2.value.length != 3) {
			window.alert ("Entrez les trois derniers caractères de votre code postal.\n");
			sForm.txtPostalCode2.focus();
			return false;
	}
	if (!isPostalCode(sForm.txtPostalCode1, sForm.txtPostalCode2)){
			return false;
	}
	if (isEmpty(sForm.txtPhoneArea.value)) {
			window.alert ("Entrez un code régional.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (!isNumber(sForm.txtPhoneArea.value) || (sForm.txtPhoneArea.value.length < 3)) {
			window.alert ("Entrez un code régional valide.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone1.value) || !isNumber(sForm.txtPhone1.value) || (sForm.txtPhone1.value.length < 3)) {
			window.alert ("Entrez un numéro de téléphone valide.\n");
			sForm.txtPhone1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone2.value) || !isNumber(sForm.txtPhone2.value) || (sForm.txtPhone2.value.length < 4)) {
			window.alert ("Entrez un numéro de téléphone valide.\n");
			sForm.txtPhone2.focus();
			return false;
	}
	if (!isEmpty(sForm.txtEmailAddress.value)){
			if (!validEmail(sForm.txtEmailAddress.value)){
			sForm.txtEmailAddress.focus();
			return false;}
	}
//	window.alert (sForm.cbPrivacyAgreement.value);
//	if (sForm.cbPrivacyAgreement.value != "TRUE"){
//			window.alert ("Vous devez lire et accepter notre politique de protection de la vie privée avant de soumettre une demande.\n");
//			sForm.cbPrivacyAgreement.focus();
//			return false;
//	}
		
	return true;
}

function VerifyContest(sForm){

	if (!isExistingMemberChecked(sForm.rdHeritageRESP)){
			return false;
	}
	if (isEmpty(sForm.txtFName.value)) {
			window.alert ("Entrez votre prénom.\n");
			sForm.txtFName.focus();
			return false;
	}
	if (isEmpty(sForm.txtLName.value)) {
			window.alert ("Entrez votre nom.\n");
			sForm.txtLName.focus();
			return false;
	}
	if (isEmpty(sForm.txtAddress1.value)) {
			window.alert ("Entrez votre adresse.\n");
			sForm.txtAddress1.focus();
			return false;
	}
	if (isEmpty(sForm.txtCity.value)) {
			window.alert ("Entrez une ville.\n");
			sForm.txtCity.focus();
			return false;
	}
	if (isEmpty(sForm.txtProvince.options[sForm.txtProvince.selectedIndex].value)) {
			window.alert ("Sélectionnez une province.\n");
			sForm.txtProvince.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode1.value) || sForm.txtPostalCode1.value.length != 3) {
			window.alert ("Entrez les trois premiers caractères de votre code postal.\n");
			sForm.txtPostalCode1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode2.value) || sForm.txtPostalCode2.value.length != 3) {
			window.alert ("Entrez les trois derniers caractères de votre code postal.\n");
			sForm.txtPostalCode2.focus();
			return false;
	}
	if (!isPostalCode(sForm.txtPostalCode1, sForm.txtPostalCode2)){
			return false;
	}
	if (isEmpty(sForm.txtPhoneArea.value)) {
			window.alert ("Entrez un code régional.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (!isNumber(sForm.txtPhoneArea.value) || (sForm.txtPhoneArea.value.length < 3)) {
			window.alert ("Entrez un code régional valide.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone1.value) || !isNumber(sForm.txtPhone1.value) || (sForm.txtPhone1.value.length < 3)) {
			window.alert ("Entrez un numéro de téléphone valide.\n");
			sForm.txtPhone1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone2.value) || !isNumber(sForm.txtPhone2.value) || (sForm.txtPhone2.value.length < 4)) {
			window.alert ("Entrez un numéro de téléphone valide.\n");
			sForm.txtPhone2.focus();
			return false;
	}
	if (!isEmpty(sForm.txtEmailAddress.value)){
			if (!validEmail(sForm.txtEmailAddress.value)){
			sForm.txtEmailAddress.focus();
			return false;}
	}
	if (isEmpty(sForm.txtCName.value)) {
			window.alert ("Entrez le nom de votre enfant.\n");
			sForm.txtCName.focus();
			return false;
	}
	if (isEmpty(sForm.txtCBDayMonth.value) || !isNumber(sForm.txtCBDayMonth.value)) {
			window.alert ("Entrez le mois de naissance de votre enfant.\n(chiffres seulement)\n");
			sForm.txtCBDayMonth.focus();
			return false;
	}
	if (isEmpty(sForm.txtCBDayDay.value) || !isNumber(sForm.txtCBDayDay.value)) {
			window.alert ("Entrez le jour de naissance de votre enfant.\\n(chiffres seulement)\n");
			sForm.txtCBDayDay.focus();
			return false;
	}
	if (isEmpty(sForm.txtCBDayYear.value) || !isNumber(sForm.txtCBDayYear.value)) {
			window.alert ("Entrez l'année de naissance de votre enfant.\n(chiffres seulement)\n");
			sForm.txtCBDayYear.focus();
			return false;
	}
	if (!sForm.cbRulesAndRegulation.checked){
			window.alert ("Vous devez lire et accepter les règles avant de soumettre votre formulaire.\n");
			sForm.cbRulesAndRegulation.focus();
			return false;
	}
	if (!isContestRefChecked(sForm)){
			return false;
	}
	return true;
}

function VerifyContactUs(sForm){
	
	if (!isExistingMemberChecked(sForm.rdHeritageRESP)){
			return false;
	}
	
//	if (bIsGroup == "True"){
//		if (isEmpty(sForm.txtOrgName.value)) {
//				window.alert ("Entrez une entreprise un organisme.\n");
//				sForm.txtOrgName.focus();
//				return false;
//		}
//	}
	if (isEmpty(sForm.txtFName.value)) {
			window.alert ("Entrez votre prénom.\n");
			sForm.txtFName.focus();
			return false;
	}
	if (isEmpty(sForm.txtLName.value)) {
			window.alert ("Entrez votre nom.\n");
			sForm.txtLName.focus();
			return false;
	}
	if (isEmpty(sForm.txtAddress1.value)) {
			window.alert ("Entrez votre adresse.\n");
			sForm.txtAddress1.focus();
			return false;
	}
	if (isEmpty(sForm.txtCity.value)) {
			window.alert ("Entrez une ville.\n");
			sForm.txtCity.focus();
			return false;
	}
	if (isEmpty(sForm.txtProvince.options[sForm.txtProvince.selectedIndex].value)) {
			window.alert ("Sélectionnez une province.\n");
			sForm.txtProvince.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode1.value) || sForm.txtPostalCode1.value.length != 3) {
			window.alert ("Entrez les trois premiers caractères de votre code postal.\n");
			sForm.txtPostalCode1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode2.value) || sForm.txtPostalCode2.value.length != 3) {
			window.alert ("Entrez les trois derniers caractères de votre code postal.\n");
			sForm.txtPostalCode2.focus();
			return false;
	}
	if (!isPostalCode(sForm.txtPostalCode1, sForm.txtPostalCode2)){
			return false;
	}
	if (isEmpty(sForm.txtPhoneArea.value)) {
			window.alert ("Entrez un code régional.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (!isNumber(sForm.txtPhoneArea.value) || (sForm.txtPhoneArea.value.length < 3)) {
			window.alert ("Entrez un code régional valide.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone1.value) || !isNumber(sForm.txtPhone1.value) || (sForm.txtPhone1.value.length < 3)) {
			window.alert ("Entrez un numéro de téléphone valide.\n");
			sForm.txtPhone1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone2.value) || !isNumber(sForm.txtPhone2.value) || (sForm.txtPhone2.value.length < 4)) {
			window.alert ("Entrez un numéro de téléphone valide.\n");
			sForm.txtPhone2.focus();
			return false;
	}
	if (!isEmpty(sForm.txtEmailAddress.value)){
			if (!validEmail(sForm.txtEmailAddress.value)){
			sForm.txtEmailAddress.focus();
			return false;}
	}
	return true;
}

function VerifyPostalCode(sForm){
	
	if (!isPostalCode(sForm.txtPostalCode1, sForm.txtPostalCode2)){
			return false;
	}
	return true;
}

function VerifyCareer(sForm){

	if (isEmpty(sForm.txtFName.value)) {
			window.alert ("Entrez votre prénom.\n");
			sForm.txtFName.focus();
			return false;
	}
	if (isEmpty(sForm.txtLName.value)) {
			window.alert ("Entrez votre nom.\n");
			sForm.txtLName.focus();
			return false;
	}
	if (isEmpty(sForm.txtAddress1.value)) {
			window.alert ("Entrez votre adresse.\n");
			sForm.txtAddress1.focus();
			return false;
	}
	if (isEmpty(sForm.txtCity.value)) {
			window.alert ("Entrez une ville.\n");
			sForm.txtCity.focus();
			return false;
	}
	if (isEmpty(sForm.txtProvince.options[sForm.txtProvince.selectedIndex].value)) {
			window.alert ("Sélectionnez une province.\n");
			sForm.txtProvince.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode1.value) || sForm.txtPostalCode1.value.length != 3) {
			window.alert ("Entrez les trois premiers caractères de votre code postal.\n");
			sForm.txtPostalCode1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPostalCode2.value) || sForm.txtPostalCode2.value.length != 3) {
			window.alert ("Entrez les trois derniers caractères de votre code postal.\n");
			sForm.txtPostalCode2.focus();
			return false;
	}
	if (!isPostalCode(sForm.txtPostalCode1, sForm.txtPostalCode2)){
			return false;
	}
	if (isEmpty(sForm.txtPhoneArea.value)) {
			window.alert ("Entrez un code régional.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (!isNumber(sForm.txtPhoneArea.value) || (sForm.txtPhoneArea.value.length < 3)) {
			window.alert ("Entrez un code régional valide.\n");
			sForm.txtPhoneArea.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone1.value) || !isNumber(sForm.txtPhone1.value) || (sForm.txtPhone1.value.length < 3)) {
			window.alert ("Entrez un numéro de téléphone valide.\n");
			sForm.txtPhone1.focus();
			return false;
	}
	if (isEmpty(sForm.txtPhone2.value) || !isNumber(sForm.txtPhone2.value) || (sForm.txtPhone2.value.length < 4)) {
			window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
			sForm.txtPhone2.focus();
			return false;
	}
	if (!isNumber(sForm.txtBusPhoneArea.value)) {
			window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
			sForm.txtBusPhoneArea.focus();
			return false;
	}
	if (!isNumber(sForm.txtBusPhone1.value)) {
			window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
			sForm.txtBusPhoneArea.focus();
			return false;
	}
	if (!isNumber(sForm.txtBusPhone1.value)) {
			window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
			sForm.txtBusPhoneArea.focus();
			return false;
	}

	if (!isEmpty(sForm.txtEmailAddress.value)){
			if (!validEmail(sForm.txtEmailAddress.value)){
			sForm.txtEmailAddress.focus();
			return false;}
	}
	return true;
}
// ****************************************************************************
// ** Validate New Password
// **
// ****************************************************************************
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function IsAlphaNumeric(sCheckme){
    
    var bHasDigit = false
    var bHasCharacter = false
    var i 
    for (i = 0; i < sCheckme.length; i++)
    {   
        // Check that current character is number.
        var c = sCheckme.charAt(i);

        if (isDigit(c)) bHasDigit = true;
        if (isLetter(c)) bHasCharacter = true;
    }
    if (bHasDigit && bHasCharacter) {
		return true
    }
    else {
		return false;
    }
}

function VerifyChangePassword(oUserIDField, oNewPwdField, oConfirmPwdField, oOldPwdField){

	if (isEmpty(oUserIDField.value)){
		alert('Entrez un ID utilisateur.');
		oUserIDField.focus();
		return false;
	}
	else if (isEmpty(oNewPwdField.value)){
		alert('Entrez un nouveau mot de passe.');
		oNewPwdField.focus();
		return false;	
	}
	else if (isEmpty(oConfirmPwdField.value)){
		alert('Confirmez votre mot de passé.');
		oConfirmPwdField.focus();
		return false;
	}
	else if (isEmpty(oOldPwdField.value)){
		alert('Entrez votre ancien mot de passe.');
		oOldPwdField.focus();
		return false;	
	}
	// Password length must be at least 5 characters long
	else if (oNewPwdField.value.length < 5){
		alert('Votre nouveau mot de passe doit comporter au moins 5 caractères.');
		oNewPwdField.value = '';
		oConfirmPwdField.value = '';
		oNewPwdField.focus();
		return false;	
	}
	// Check for both numeric and character values.
	else if (!IsAlphaNumeric(oNewPwdField.value)){
		alert('Votre nouveau mot de passe doit comporter des chiffres et des lettres.');
		oNewPwdField.value = '';
		oConfirmPwdField.value = '';
		oNewPwdField.focus();
		return false;	
	}
	else {
		if (oNewPwdField.value == oConfirmPwdField.value){
			return confirm('Voulez-vous vraiment changer votre mot de passe ?');
		}
		else {
			alert('Confirmez de nouveau votre nouveau mot de passe.');
			oConfirmPwdField.value = '';
			oConfirmPwdField.focus();
			return false;			
		}
	
	}
}
// ****************************************************************************
// ** Validate New Security Question and Answer
// **
// ****************************************************************************
function VerifyUpdateSecurityQA(oForm){
		
	if (isEmpty(oForm.txtUserID.value)){
		alert('Entrez votre ID utilisateur actuel.');
		oForm.txtUserID.focus();
		return false;		
	}
	else if (isEmpty(oForm.txtUserPwd.value)){
		alert('Entrez votre mot de passe pour fins de sécurité.');
		oForm.txtUserPwd.focus();
		return false;		
	}
	else if (isEmpty(oForm.txtSecurityQ.value)){
		alert('Entrez votre question de sécurité.');
		oForm.txtSecurityQ.focus();
		return false;		
	}
	else if (isEmpty(oForm.txtSecurityA.value)){
		alert("Entrez la réponse de sécurité constituée d'un seul mot.");
		oForm.txtSecurityA.focus();
		return false;		
	}
	else {
		return confirm('Voulez-vous vraiment mettre vos question et réponse de sécurité à jour ?')
	}
}
// ****************************************************************************
// ** Validate New UserID
// **
// ****************************************************************************
function VerifyUpdateUserID(oForm){

	if (isEmpty(oForm.txtUserID.value)){
		alert('Entrez votre ID utilisateur actuel.');
		oForm.txtUserID.focus();
		return false;		
	}
	else if (isEmpty(oForm.txtUserPwd.value)){
		alert('Entrez votre mot de passe pour fins de sécurité.');
		oForm.txtUserPwd.focus();
		return false;		
	}
	else if (isEmpty(oForm.txtNewUserID.value)){
		alert('Entrez votre nouveau ID utilisateur.');
		oForm.txtNewUserID.focus();
		return false;		
	}
	// New User ID length must be at least 6 characters long
	else if (oForm.txtNewUserID.value.length < 6){
		alert('Votre nouveau ID utilisateur doit comporter au moins 6 caractères.');
		oForm.txtNewUserID.value = '';
		oForm.txtNewUserID.focus();
		return false;	
	}
	// Check for both numeric and character values.
	else if (!IsAlphaNumeric(oForm.txtNewUserID.value)){
		alert('Votre nouveau mot de passe doit comporter des chiffres et des lettres.');
		oForm.txtNewUserID.value = '';
		oForm.txtNewUserID.focus();
		return false;	
	}
	else {
		return confirm('Voulez-vous vraiment mettre votre ID utilisateur à jour ?')
	}
}
// ****************************************************************************
// ** Validate Statement of Account
// **
// ****************************************************************************

function VerifyStatement(oSelectBox){

	if (oSelectBox.selectedIndex < 0){
				window.alert ("Sélectionnez un no de contrat ou le nom d' un bénéficiaire");
				oSelectBox.focus();
				return false;	
		}
	else if (isEmpty(oSelectBox.options[oSelectBox.selectedIndex].value)) {
				window.alert ("Sélectionnez un no de contrat ou le nom d'un bénéficiaire");
				oSelectBox.focus();
				return false;
		}
	else {
		return true
	}
}

// ****************************************************************************
// ** Validate SIN
// **
// ****************************************************************************
function VerifySIN(oForm){

	if (isEmpty(oForm.txtNewSIN1.value) || !isNumber(oForm.txtNewSIN1.value)){
		oForm.txtNewSIN1.focus();
		return false;		
	}
	else if (isEmpty(oForm.txtNewSIN2.value) || !isNumber(oForm.txtNewSIN2.value)){
		oForm.txtNewSIN2.focus();
		return false;		
	}
	else if (isEmpty(oForm.txtNewSIN3.value) || !isNumber(oForm.txtNewSIN3.value)){
		oForm.txtNewSIN3.focus();
		return false;		
	}
	else {
		return true;
	}
}
function StripNonDigits(number) {
var Re = /\d+/g;
if(Re.lastIndex > 1) { Re.lastIndex = 0; }
var Array = Re.exec(number);
if(Re.lastIndex < 1) { return 'X'; }
var ss = Array.join();
while(Re.lastIndex > 0 && Re.lastIndex < number.length) {
	Array = Re.exec(number);
	if(Array) { ss += Array.join(); }
	}
return ss;
} // StripNonDigits()

function Reverse(number) {
var n = '';
for(i = number.length; i >= 0; i--) { n += number.substr(i,1); }
return n;
} // Reverse()


function AddedTogether(number) {
var n = 0;
for(i = 0; i < number.length; i++) {
	var s = number.substr(i,1);
	var si = parseInt(s,10);
	if(i % 2 > 0) {
		var ii = si * 2;
		if(ii < 10) { n += ii; }
		else {
			var ss = ' ' + ii;
			for(xi = 1; xi < ss.length; xi++) {
				var xs = ss.substr(xi,1);
				var xsi = parseInt(xs,10);
				n += xsi;
				} // for
			} // else
		} // if
	else { n += si; }
	} // for
return n;
} // AddedTogether()


function Mod10(n) {
var reversed = Reverse(n);
var total = AddedTogether(reversed);
if(total % 10 > 0) { return false; }
return true;
} // Mod10()


function ValidateSIN(oForm) {

if (oForm.cboContractNo.selectedIndex < 0){
	window.alert ("Sélectionnez un contrat ou un bénéficiaire.");
	oForm.cboContractNo.focus();
	return false;	
	}
else if (isEmpty(oForm.cboContractNo.options[oForm.cboContractNo.selectedIndex].value)) {
	window.alert ("Sélectionnez un contrat ou un bénéficiaire.");
	oForm.cboContractNo.focus();
	return false;
	}
// Check for empty 3-digit boxes.
else if (!VerifySIN(oForm)){
	alert('Chaque case de saisie doit contenir 3 caractères, des chiffres seulement.');
	return false; 
}
var nSIN = StripNonDigits(oForm.txtNewSIN1.value + oForm.txtNewSIN2.value + oForm.txtNewSIN3.value);
if (Mod10(nSIN)){
	return confirm("Voulez-vous vraiment ajouter ce numéro d'assurance sociale pour cet enfant ?");
}
else {
	alert("NAS invalide");
	oForm.txtNewSIN1.focus();
	return false;
}	
} // Validate()

// ****************************************************************************
// **
// **					Validate Change of Address
// **
// ****************************************************************************

function VerifyChangeAddress(oForm, sUpdate){
	
	switch (sUpdate){
		case "CAN":
			if (isEmpty(oForm.txtNewAddress1.value)){
					window.alert ("Entrez votre adresse.\n");
					oForm.txtNewAddress1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewCity.value)){
					window.alert ("Entrez une ville.\n");
					oForm.txtNewCity.focus();
					return false;
			}
			else if (isEmpty(oForm.txtProvince.options[oForm.txtProvince.selectedIndex].value)) {
					window.alert ("Sélectionnez une province.\n");
					oForm.txtProvince.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPostalCode1.value) || oForm.txtPostalCode1.value.length != 3) {
					window.alert ("Entrez les trois premiers caractères de votre code postal.\n");
					oForm.txtPostalCode1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPostalCode2.value) || oForm.txtPostalCode2.value.length != 3) {
					window.alert ("Entrez les trois derniers caractères de votre code postal.\n");
					oForm.txtPostalCode2.focus();
					return false;
			}
			else if (!isPostalCode(oForm.txtPostalCode1, oForm.txtPostalCode2)){
					return false;
			}
			else if (isEmpty(oForm.txtNewPhoneArea.value)) {
					window.alert ("Entrez un code régional.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewPhoneArea.value) || (oForm.txtNewPhoneArea.value.length < 3)) {
					window.alert ("Entrez un code régional valide.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewPhone1.value) || !isNumber(oForm.txtNewPhone1.value) || (oForm.txtNewPhone1.value.length < 3)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtNewPhone1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewPhone2.value) || !isNumber(oForm.txtNewPhone2.value) || (oForm.txtNewPhone2.value.length < 4)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtNewPhone2.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhoneArea.value)) {
					window.alert ("Entrez un code régional valide de numéro de téléphone d'affaires.\n");
					oForm.txtNewBPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhone1.value)) {
					window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
					oForm.txtNewBPhone1.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhone2.value)) {
					window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
					oForm.txtNewBPhone2.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBExtension.value)) {
					window.alert ("Entrez un poste téléphonique d'affaires  valide.\n");
					oForm.txtNewBExtension.focus();
					return false;
			}
			else if (!isEmpty(oForm.txtNewEmail.value)){
					if (!validEmail(oForm.txtNewEmail.value)){
					oForm.txtNewEmail.focus();
					return false;}
			}
			return confirm("Voulez-vous vraiment mettre l'nformation personne-ressource à jour ?")
			break;
		case "USA":
			var digitsInZIPCode1 = 5
			var digitsInZIPCode2 = 9
			var zipcode
			zipcode = oForm.txtPostalCode1.value
			if (isEmpty(oForm.txtNewAddress1.value)){
					window.alert ("Entrez votre adresse.\n");
					oForm.txtNewAddress1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewCity.value)){
					window.alert ("Entrez une ville.\n");
					oForm.txtNewCity.focus();
					return false;
			}
			else if (isEmpty(oForm.txtProvince.options[oForm.txtProvince.selectedIndex].value)) {
					window.alert ("Sélectionnez une province.\n");
					oForm.txtProvince.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPostalCode1.value)) {
					window.alert ("Entrez votre code postal.\n");
					oForm.txtPostalCode1.focus();
					return false;
			}
			else if (!isNumber(oForm.txtPostalCode1.value)){
					window.alert ("Entrez un code postal2 valide.\n");
					oForm.txtPostalCode1.focus();					
					return false;
			}
			else if (!((zipcode.length == digitsInZIPCode1) || (zipcode.length == digitsInZIPCode2))){
					window.alert ("Entrez un code postal3 valide.\n");
					oForm.txtPostalCode1.focus();					
					return false;
			}
			else if (isEmpty(oForm.txtNewPhoneArea.value)) {
					window.alert ("Entrez un code régional.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewPhoneArea.value) || (oForm.txtNewPhoneArea.value.length < 3)) {
					window.alert ("Entrez un code régional valide.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewPhone1.value) || !isNumber(oForm.txtNewPhone1.value) || (oForm.txtNewPhone1.value.length < 3)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtNewPhone1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewPhone2.value) || !isNumber(oForm.txtNewPhone2.value) || (oForm.txtNewPhone2.value.length < 4)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtNewPhone2.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhoneArea.value)) {
					window.alert ("Entrez un code régional valide de numéro de téléphone d'affaires.\n");
					oForm.txtNewBPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhone1.value)) {
					window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
					oForm.txtNewBPhone1.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhone2.value)) {
					window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
					oForm.txtNewBPhone2.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBExtension.value)) {
					window.alert ("Entrez un poste téléphonique d'affaires  valide.\n");
					oForm.txtNewBExtension.focus();
					return false;
			}
			else if (!isEmpty(oForm.txtNewEmail.value)){
					if (!validEmail(oForm.txtNewEmail.value)){
					oForm.txtNewEmail.focus();
					return false;}
			}
			return confirm("Voulez-vous vraiment mettre l'nformation personne-ressource à jour ?")
			break;
		default:
			if (isEmpty(oForm.txtNewAddress1.value)){
					window.alert ("Entrez votre adresse.\n");
					oForm.txtNewAddress1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewCity.value)){
					window.alert ("Entrez une ville.\n");
					oForm.txtNewCity.focus();
					return false;
			}
			else if (isEmpty(oForm.txtCountryCode.options[oForm.txtCountryCode.selectedIndex].value)) {
					window.alert ("Sélectionnez un pays.\n");
					oForm.txtCountryCode.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewPhoneArea.value)) {
					window.alert ("Entrez un code régional.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewPhoneArea.value)) {
					window.alert ("Entrez un code régional.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (isEmpty(oForm.txtNewPhone1.value) || !isNumber(oForm.txtNewPhone1.value)) {
					window.alert ("Entrez un code régional valide.\n");
					oForm.txtNewPhone1.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhoneArea.value)) {
					window.alert ("Entrez un code régional valide de numéro de téléphone d'affaires.\n");
					oForm.txtNewBPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBPhone1.value)) {
					window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
					oForm.txtNewBPhone1.focus();
					return false;
			}
			else if (!isNumber(oForm.txtNewBExtension.value)) {
					window.alert ("Entrez un numéro de téléphone d'affaires valide.\n");
					oForm.txtNewBExtension.focus();
					return false;
			}
			else if (!isEmpty(oForm.txtNewEmail.value)){
					if (!validEmail(oForm.txtNewEmail.value)){
					oForm.txtNewEmail.focus();
					return false;}
			}
			return confirm("Voulez-vous vraiment mettre l'nformation personne-ressource à jour ?")		
			break;
	}
}	
// ****************************************************************************
// **
// **					Validate Bank Information
// **
// ****************************************************************************

function VerifyBankInfo(oForm){

	if (oForm.cboContractNo.selectedIndex < 0){
		window.alert ("Sélectionnez un contrat ou un bénéficiaire.");
		oForm.cboContractNo.focus();
		return false;	
	}
	else if (isEmpty(oForm.cboContractNo.options[oForm.cboContractNo.selectedIndex].value)) {
		window.alert ("Sélectionnez un contrat ou un bénéficiaire.");
		oForm.cboContractNo.focus();
		return false;
	}
	else if (oForm.cboBankNo.selectedIndex < 0){
		window.alert ("Sélectionnez une institution financière.");
		oForm.cboBankNo.focus();
		return false;	
	}
	else if (isEmpty(oForm.cboBankNo.options[oForm.cboBankNo.selectedIndex].value)) {
		window.alert ("Sélectionnez une institution financière.");
		oForm.cboBankNo.focus();
		return false;
	}	
	else if (isEmpty(oForm.txtBranchNo.value) || !isNumber(oForm.txtBranchNo.value)) {
		window.alert ("Entrez un numéro de succursale valide(chiffres seulement).\n");
		oForm.txtBranchNo.focus();
		return false;
	}
	else if (isEmpty(oForm.txtAccountNo.value) || !isNumber(oForm.txtAccountNo.value)) {
		window.alert ("Entrez un numéro de compte valide (chiffres seulement).\n");
		oForm.txtBranchNo.focus();
		return false;
	}
	else if (isEmpty(oForm.txtDepLastName.value)) {
		window.alert ("Entrez le nom de famille du dépositaire.\n");
		oForm.txtDepLastName.focus();
		return false;
	}
	else {
		return confirm("Voulez-vous vraiment mettre à jour les renseignements bancaires concernant ce contrat comme suit :\n\nBanque : " + oForm.cboBankNo.options[oForm.cboBankNo.selectedIndex].text + "\nNuméro de succursale : " + oForm.txtBranchNo.value + "\nNuméro de compte : " + oForm.txtAccountNo.value + "\nNom de famille du dépositaire : " + oForm.txtDepLastName.value + "\n\nEn cliquant sur OK, j autorise les transferts automatiques du compte susmentionné,\net j autorise l établissement bancaire susmentionné à accepter ces débits.");
	}
}

// ****************************************************************************
// **
// **		Validate Member Submission
// **
// **		This validation is called from the member 
// **		area for Add Units, Add Insurance, etc.. Submissions
// ****************************************************************************

function VerifyMemberSubmission(oForm, sUpdate){
	
	switch (sUpdate){
		case "CAN":
			if (isEmpty(oForm.txtFName.value)) {
					window.alert ("Entrez votre prénom.\n");
					oForm.txtFName.focus();
					return false;
			}
			else if (isEmpty(oForm.txtLName.value)) {
					window.alert ("Entrez votre nom.\n");
					oForm.txtLName.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhoneArea.value)) {
					window.alert ("Entrez un code régional.\n");
					oForm.txtPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtPhoneArea.value) || (sForm.txtPhoneArea.value.length < 3)) {
					window.alert ("Entrez un code régional valide.\n");
					oForm.txtPhoneArea.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhone1.value) || !isNumber(oForm.txtPhone1.value) || (oForm.txtPhone1.value.length < 3)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtPhone1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhone2.value) || !isNumber(oForm.txtPhone2.value) || (oForm.txtPhone2.value.length < 4)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtPhone2.focus();
					return false;
			}
			else if (!isEmpty(oForm.txtEmailAddress.value)){
					if (!validEmail(oForm.txtEmailAddress.value)){
					oForm.txtEmailAddress.focus();
					return false;}
			}
			break;
		case "USA":
			if (isEmpty(oForm.txtFName.value)) {
					window.alert ("Entrez votre prénom.\n");
					oForm.txtFName.focus();
					return false;
			}
			else if (isEmpty(oForm.txtLName.value)) {
					window.alert ("Entrez votre nom.\n");
					oForm.txtLName.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhoneArea.value)) {
					window.alert ("Entrez un code régional.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtPhoneArea.value) || (oForm.txtPhoneArea.value.length < 3)) {
					window.alert ("Entrez un code régional valide.\n");
					oForm.txtNewPhoneArea.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhone1.value) || !isNumber(oForm.txtPhone1.value) || (oForm.txtPhone1.value.length < 3)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtPhone1.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhone2.value) || !isNumber(oForm.txtPhone2.value) || (oForm.txtPhone2.value.length < 4)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtPhone2.focus();
					return false;
			}
			else if (!isEmpty(oForm.txtEmailAddress.value)){
					if (!validEmail(oForm.txtEmailAddress.value)){
					oForm.txtEmailAddress.focus();
					return false;}
			}
		default:
			if (isEmpty(oForm.txtFName.value)) {
					window.alert ("Entrez votre prénom.\n");
					oForm.txtFName.focus();
					return false;
			}
			else if (isEmpty(oForm.txtLName.value)) {
					window.alert ("Entrez votre nom.\n");
					oForm.txtLName.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhoneArea.value)) {
					window.alert ("Entrez un code régional.\n");
					oForm.txtPhoneArea.focus();
					return false;
			}
			else if (!isNumber(oForm.txtPhoneArea.value)) {
					window.alert ("Entrez un code régional valide.\n");
					oForm.txtPhoneArea.focus();
					return false;
			}
			else if (isEmpty(oForm.txtPhone1.value) || !isNumber(oForm.txtPhone1.value)) {
					window.alert ("Entrez un numéro de téléphone valide.\n");
					oForm.txtPhone1.focus();
					return false;
			}
		
			break;
		}
		return true;
}	