var leftAngleQuote = String.fromCharCode(171);
var rightAngleQuote = String.fromCharCode(187);

var caga = String.fromCharCode(192);
var caaa = String.fromCharCode(193);
var caca = String.fromCharCode(194);
var cat = String.fromCharCode(195);

var cega = String.fromCharCode(200);
var ceaa = String.fromCharCode(201);
var ceca = String.fromCharCode(202);

var ciga = String.fromCharCode(204);
var ciac = String.fromCharCode(205);
var cica = String.fromCharCode(206);

var coga = String.fromCharCode(210);
var coaa = String.fromCharCode(211);
var coca = String.fromCharCode(212);
var cot = String.fromCharCode(213);

var cuga = String.fromCharCode(217);
var cuaa = String.fromCharCode(218);
var cuca = String.fromCharCode(219);

var saga = String.fromCharCode(224);
var saaa = String.fromCharCode(225);
var saca = String.fromCharCode(226);
var sat = String.fromCharCode(227);

var sega = String.fromCharCode(232);
var seaa = String.fromCharCode(233);
var seca = String.fromCharCode(234);

var siga = String.fromCharCode(236);
var siaa = String.fromCharCode(237);
var sica = String.fromCharCode(238);

var soga = String.fromCharCode(242);
var soaa = String.fromCharCode(243);
var soca = String.fromCharCode(244);
var sot = String.fromCharCode(245);

var suga = String.fromCharCode(249);
var suaa = String.fromCharCode(250);
var suca = String.fromCharCode(251);

var ACCEPT_NUMBERS = "0123456789";
var ACCEPT_ACCENTS = "àÀèÈìÌòÒùÙâÂêÊîÎôÔûÛáÁéÉíÍóÓúÚ" + "üÜëËïÏöÖäÄÿŸçÇ";
var ACCEPT_ALPHANUMERICSYMBOLS = "abcdefghijklmnopqrstuvwwyzABCDEFGHIJKLMNOPQRSTUVWWYZ.,/;:<>'[{]}|-=_+1234567890!@#$%^&*()";
var ACCEPT_ALPHANUMERICSYMBOLSACCENTS = "abcdefghijklmnopqrstuvwwyzABCDEFGHIJKLMNOPQRSTUVWWYZ.,/;:<>'[{]}|-=_+1234567890!@#$%^&*()" + ACCEPT_ACCENTS;

i18nUpdateLanguageIndex();

function MM_findObj(n, d) { //v4.0
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n);
	return x;
}

function Basic_Check() {
	if (!this.required){return true;}
	var r = true;
	for(var i=0; i < this.requiredFields.length; i++) {
		//alert(this.name+": "+this.requiredFields[i]);
		if (!checkElement(this.requiredFields[i])){ r=false; }
	}
	return r;
}

function do_Submit(url) {
	if (document.forms.length != 0) {
		if (do_Submit.arguments.length != 0)
			document.forms[0].nexturl.value = url;
        // The following is a fix for IE sucking. It is for P6.
        if(document.forms[0].saveProgress)
            document.forms[0].saveProgress.value = "";

		document.forms[0].submit();
	}
	else
		top.location.replace(url);
	return true;
}

function isKeyDown_ctrlForPC_optForMac(evt) {
	var returnStr = false;
	var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
	var isMAC = (navigator.appVersion.indexOf('Mac') != -1);
	if (isMAC) {	// alt(option) 
		if (isIE)
			returnStr = window.event.altKey;
		else
			returnStr = evt.modifiers & Event.ALT_MASK;
	}
	else {		// control 
		if (isIE)
			returnStr = window.event.ctrlKey;
		else {
			returnStr = evt.modifiers & Event.CONTROL_MASK;	
		}
	}
	return returnStr;
}


function dropDownVal(theStr) {
	var fm  = document.forms[0];
	var elm = fm.elements[theStr];
	if (! elm) {
		return '';
	}
	else {
		var t = elm.type;
		if (t == "select-one") {
			return elm.options[elm.selectedIndex].value;
		}
		else if (elm[0] && elm[0].type == "radio") {
			return radioVal(theStr);
		}
	}
}


function checkElement(fieldName) { // only red arrows
	var filledOut = true;
	var fm = document.forms[0];
	var img = eval("document."+fieldName+"_r");
	var isRadio = false;
	var elm = fm.elements[fieldName];
	
	if (elm) {
		var t = elm.type;
		if (t == "text" || t == "hidden")
			filledOut = checkText(fieldName);
		else if (t == "select-one"){
			filledOut = checkDrop(fieldName);
		}
		else if (elm[0] && elm[0].type == "radio"){ 
			filledOut = checkRadio(fieldName);
//			alert("checkRadio["+fieldName+"] = "+filledOut);
			isRadio = true;
		}
	}
	else if (fm.elements[fieldName+"y"] && fm.elements[fieldName+"m"]) {
		if (fm.elements[fieldName+"d"])
			filledOut = (checkDrop(fieldName+"m") && checkText(fieldName+"d") && checkText(fieldName+"y"));
		else
			filledOut = (checkDrop(fieldName+"y") && checkDrop(fieldName+"m"))
	}
	else if (fm.elements[fieldName+"phAC"] && fm.elements[fieldName+"phNum"]) {
		filledOut = checkPhone(fm.elements[fieldName+"phAC"], fm.elements[fieldName+"phNum"], false);
	}
	
	if (showRequiredFields) {
		if (img) {
//            alert("hi: filledOut=" + filledOut);
            img.src = ((filledOut) ? empty.src : required.src);
//            alert("Field [" + fieldName + "] has its img.src set to [" + img.src + "].");
        }
	else if (isRadio){
			for (var i=0; true; i++) {
				var anImg = eval("document."+fieldName+i+"_r");
				if (!anImg) { break; }
//				alert("about to flip img "+anImg.name+" to filledOut:"+filledOut);
				anImg.src = ((filledOut) ? empty.src : required.src);
			}
		}
	}

	return filledOut;
}

function radioVal(radioName) {
	var rgrp = document.forms[0].elements[radioName];
	for (var i=0; i < rgrp.length; i++) {
		if (rgrp[i].checked) { return rgrp[i].value; }
	}
	return "";
}

function checkRadio(radioName) {
	var rgrp = document.forms[0].elements[radioName];
	for (var i=0; i < rgrp.length; i++) {
		if (rgrp[i].checked) { return true; }
	}
	return false;
}

function checkDrop(dropNameStr) {
	var thisDrop = dropDownVal(dropNameStr)+"";
	if (thisDrop=="" || thisDrop=="WONoSelectionString" || thisDrop=="undefined")
		return false;
	else 
		return true;
}

function checkText(objNameStr) {
	var thisTextObj = document.forms[0].elements[objNameStr];
	if (!(thisTextObj))
		return alert("csjs alert: checkText('"+objNameStr+"') doesn't appear to exist on this form.");
	else {
		var thisTextVal = "";
		if (thisTextObj.value.length > 0)
			thisTextVal = stripinFun(thisTextObj.value, ACCEPT_ALPHANUMERICSYMBOLSACCENTS ) + "";
		if (thisTextVal == "") {
			//thisTextObj.focus();
			//thisTextObj.select();
			return false;
		}
		else 
			return true;
	}
}
function checkPhone(areaObject, numberObject, warn) {
	var results = true;
	var msg = "";
	if (areaObject && numberObject) {
		results = false;
		var areaOk = false;
		var numberOk = false;
		
		if (numberObject.value.length > 0) {
			var strippedNum = stripinFun(numberObject.value, ACCEPT_NUMBERS);
			if (strippedNum.length > 7) {
				results = false;
				numberObject.value = strippedNum;
				msg = "there appear to be more than seven digits in the number";
			} else if (strippedNum.length == 7) {
				numberObject.value = strippedNum.substring(0,3)+"-"+strippedNum.substring(3,7);
				numberOk = true;
			} else {
				results = false;
				numberObject.value = strippedNum;
				msg = "there appear to be less than seven digits in the number";
			}
		}
		
		if (areaObject.value.length > 0) {
			var strippedAC = stripinFun(areaObject.value, ACCEPT_NUMBERS);
			if (strippedAC.length != 3) {
				results = false;
				if (msg=="")
					msg = "the area code is not exactly three digits";
				else
					msg += ", and the area code is not exactly three digits";
			}
			else
				areaOk = true;
			areaObject.value = strippedAC;
		}
		if (warn && msg != ""){
            alert(i18nK("InvalidPhoneNumberEntered"));
		}else
			results = (areaOk && numberOk);
	}
	return results;
}

function checkPhoneSingleText(textObject) {
    var success = false;
	if (textObject != null && textObject.value.length > 0) { 
		var stripped = stripinFun(textObject.value,"0123456789");
		if (stripped == "")
			;	// allowed to clear
		else if (stripped.length < 10) {
			alert("Invalid phone number: Please use the full ten digits");
			textObject.value = "";
			textObject.focus();
			textObject.select();
		}
		else {
			if (stripped.length == 11 && stripped.substring(0,1) == "1")
				stripped = stripped.substring(1,stripped.length);
			textObject.value = stripped;
			success = true;
		}
	}
    return success;
}

function setStatus(theMsg) {
	window.status = theMsg;
	return true;
}

function threePartDateToNumber(dayEle, monEle, yearEle) {
        dayEle.value = stripinFun(dayEle.value, ACCEPT_NUMBERS);
        var monthVal = "";
        if (monEle.type == "text") {
                monEle.value = stripinFun(monEle.value, ACCEPT_NUMBERS);
                monthVal = monEle.value;
        }
        else if (monEle.type == "select-one")
                monthVal = monEle.options[monEle.selectedIndex].value;
        else
                alert("csjs alert: checkThreePartDate passed a month element that is not a text field nor a dropdown!");
        yearEle.value = stripinFun(yearEle.value, ACCEPT_NUMBERS);

        if (monthVal.length > 0 && dayEle.value.length > 0 && yearEle.value.length > 0) {
                var monVal = parseInt(monthVal,10);
                var dayVal = parseInt(dayEle.value,10);
                var yearVal = parseInt(yearEle.value,10);
	}else
		return(0);
	
	var tot;

	tot = dayVal + (monVal * 31) + (yearVal * 372);

	return tot;
}

function checkThreePartDateForRootNamed(rootName, yearMin, yearMax){
	var fm = document.forms[0];

	var dayEle = fm.elements[rootName+'d'];
	var monEle = fm.elements[rootName+'m'];
	var yearEle = fm.elements[rootName+'y'];

    return checkThreePartDate(dayEle, monEle, yearEle, yearMin, yearMax);
}

function checkThreePartDate(dayEle,monEle,yearEle,yearMin,yearMax,donotwarn) {

	if (((monEle.type == "select-one" && monEle.selectedIndex > 0) ||
         (monEle.type == "text" && monEle.value.length > 0)) &&
        dayEle.value.length > 0 && yearEle.value.length > 0)
	{
		dayEle.value = stripinFun(dayEle.value, ACCEPT_NUMBERS);
		var monthVal = "";
		if (monEle.type == "text") {
			monEle.value = stripinFun(monEle.value, ACCEPT_NUMBERS);
			monthVal = monEle.value;
		}
		else if (monEle.type == "select-one"){
			monthVal = monEle.options[monEle.selectedIndex].value;
		}
		else{
			if (donotwarn != true){
				alert("csjs alert: checkThreePartDate passed a month element that is not a text field nor a dropdown!");
			}
		}
		yearEle.value = stripinFun(yearEle.value, ACCEPT_NUMBERS);
	
		if (monthVal.length > 0 && dayEle.value.length > 0 && yearEle.value.length > 0) {
			var monVal = parseInt(monthVal,10);
			var dayVal = parseInt(dayEle.value,10);
			var yearVal = parseInt(yearEle.value,10);
			if(validYear(yearEle,yearMin,yearMax)) {
				if(!validDate(dayVal,monVal,yearVal)) {
					if (donotwarn != true){
						alert(i18nK("InvalidDate2"));
					}
					dayEle.value = '';
					yearEle.value = '';
					if (monEle.type == "text") {
						monEle.value = '';
					}
					monEle.focus();
				}
				else
					return true;
			}
			else {
				if (donotwarn != true){
					alert(i18nK("InvalidYearPleaseCorrect"));
				}
				yearEle.value = '';
				yearEle.focus();
			}
		}
		else{

			return false;
        }
	}
    return false;
}


function checkClosingDate(dayCurrent,monthCurrent,yearCurrent,rootName,yearMax){
	var fm = document.forms[0];
	var dayPassed = fm.elements[rootName+'d'];
	var monthPassed = fm.elements[rootName+'m'];
	var yearPassed = fm.elements[rootName+'y'];
	
	var monthVal = "";
	var dayVal = "";
	monthVal = monthPassed.options[monthPassed.selectedIndex].value;
	dayVal = parseInt(dayPassed.value,10);
	
	var yearEntered = parseInt(yearPassed.value);

	if(checkThreePartDateForRootNamed(rootName, yearCurrent, yearMax)) {
		if(yearEntered == yearCurrent && monthVal < monthCurrent){
			alert(i18nK("InvalidDate2"));
			monthPassed.selectedIndex = 0;
			return false;
		}
		if(yearEntered == yearCurrent && monthVal == monthCurrent && dayVal < dayCurrent){
			alert(i18nK("InvalidDate2"));
			dayPassed.value = '';
			return false;
		}
	}
	return true;
}

// Returns true if valid, false otherwise.
function validDate(ddInt,mmInt,yyInt) {
	var m30Str = "|4|6|9|11|";
	var febInt = 28;
	var tempVar = 0;
	
	if(isNaN(yyInt))
		return false;
	else{
		if ((0+yyInt) < 30)
			tempVar = 2000 + yyInt;	// Handle all 2 digit dates, force to 4 digits //
		else if (yyInt < 1800)  		
			tempVar = 1900 + yyInt;
		else
			tempVar = yyInt;
	}

	if ((tempVar % 4) == 0) {		// 29 days in February calc //
		if ((tempVar % 100) == 0) {
			if ((tempVar % 400) == 0)
				febInt = 29;
		} 
		else 
			febInt = 29;
	}

    if(ddInt == "" || mmInt == "")
        return false;

    if(ddInt <= 0 || mmInt <= 0)
        return false;

	if(mmInt > 12){
		return false;
    }else if(mmInt == 2){
		if(ddInt > febInt)
			return false;
	}else if(m30Str.indexOf("|" + mmInt + "|") != -1){
		if(ddInt > 30)
			return false;
	}else{
		if(ddInt > 31)
			return false;
	}

	if(mmInt == 2 && ddInt == 29 && yyInt == 2002)
	      return false;

	return true;
}

function validYear(yEle,minInt,maxInt) {
	var userStr = stripinFun(yEle.value, ACCEPT_NUMBERS);
	var todayDte = new Date();
	var centryStr;
	if (userStr.length==0)
		return true;
	if (userStr.length==1||userStr.length==3||userStr.length>4) {
//		alert("Not right size");
		return false;
	}

	if(userStr.length==2) {
	    var yy = parseInt(userStr,10);
	    var y = parseInt(todayDte.getFullYear(), 10);
	    var centry = 100*Math.floor(y/100);
	    centryStr =  ((y+25) > (centry+yy)) ? centry : centry-100
	    userStr = centryStr + yy;
	}

	userStr = parseInt(userStr, 10);
	if (!isNaN(userStr) && userStr >= minInt && userStr <= maxInt) {
		yEle.value = userStr;
		return true;
	}
	return false;
}

function filterNum(theNum) {
	var hasDecimal = false;
	var minusStr = "";
	var result = "";
	var theChar = "";
	var i;
	for(i=0;i<=theNum.length;i++) {
		theChar = theNum.charAt(i);
		if(theChar==".") {
			if (hasDecimal) {
				return minusStr + result;
			} else {
				hasDecimal = true;
				result = result + theChar;
			}
		}
		else if(theChar=="-") {
			minusStr = "-";
		}
		else if(theChar>="0" && theChar<="9") {
 			result = result + theChar;
		}
	}
	return minusStr + result;
}

// Return a string with only the chars found in accept.
function stripinFun (s, accept) {
    var i;
    var returnString = "";
    if (s){
    	for (i = 0; i < s.length ; i++) {   
       	 var c = s.charAt(i);
        	if (accept.indexOf(c) != -1) returnString += c;
    	}
    }
    return returnString;
}

// Return a string stripped of chars found in reject.
function stripFun (s, reject) {
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (reject.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function upFirstChar(instr) {

	var i = 0;
	var j = "";
	var newstr = "";
	var new_word = false;
	
	for ( i=0 ; i < instr.length ; i++ ) {
		j = instr.charAt(i);
		
		if ((i == 0) || (new_word == true))
			j = j.toUpperCase();
		else
			j = j.toLowerCase();
			
		if (j == " ")
			new_word = true;
		else
			new_word = false;
		
		newstr = newstr + j;
	}
	return newstr;
}

function upFirstCharOnly(instr) {
	var i = 0;
	var j = "";
	var newstr = "";
	var new_word = false;
	
	for ( i=0 ; i < instr.length ; i++ ) {
		j = instr.charAt(i);
		
		if ((i == 0) || (new_word == true))
			j = j.toUpperCase();

		if (j == " ")
			new_word = true;
		else
			new_word = false;
		
		newstr = newstr + j;
	}
	return newstr;
}

function capitalizeFirst(ele) {
	var myStr = upFirstCharOnly(ele.value);
	ele.value = myStr;
}

function titleCase(ele) {
	var myStr = upFirstChar(ele.value);
	ele.value = myStr;
}

function stripGremlins(str) {
	var i = 0;
	var j = "";
	var newstr = "";
	var LF = unescape("%0A");
	var CR = unescape("%0D");

	for ( i=0 ; i < str.length ; i++ ) {
		j = str.charAt(i);
		if((j == LF) || (j == CR ) || ((j >= " ") && (j <= "~")) ||
                ACCEPT_ACCENTS.indexOf(j) != -1)
			newstr = newstr + j;
	}
	return newstr;
}

function filterString(in_string,keep_Alpha,keep_Num,exceptions) {
	var i = 0; 
	var j = ""; 
	var newstr = "";	
	
	if (exceptions + "" == 'undefined')
		exceptions = "";

    // Allow accent characters to be added!
//    if(sessionLanguage != "English")
        exceptions += ACCEPT_ACCENTS;
	
	var is_alpha = false;
	var is_num = false;
	var is_except = false;
	
	in_string = stripGremlins(in_string);

	for ( i=0 ; i < in_string.length ; i++ ) {
		is_alpha = false;
		is_num = false;
		is_except = false;

		j = in_string.charAt(i);
		
		if (exceptions.indexOf(j) != -1) 
			is_except = true;
		else if ( ((j >= "A") && (j <= "Z")) || ((j >= "a") && (j <= "z")) ) 
			is_alpha = true;
		else if ((j >= "0") && (j <= "9"))
			is_num = true;
		 
		if (is_except)
			newstr = newstr + j;
		else if ((keep_Alpha == true) && (is_alpha == true)) 
			newstr = newstr + j;
		else if ((keep_Num == true) && (is_num))
			newstr = newstr + j;
	}

	return newstr;
}

function properField(textElement,keepNumbers,exceptions,doNotUpperCase) {
	var myStr = textElement.value;
	if (myStr == '')
		return true;

	if (exceptions+"" == 'undefined')
		exceptions = '';
	exceptions += " '.";
		
	myStr = filterString(myStr,true,keepNumbers,exceptions);
	if (!doNotUpperCase){
		myStr = upFirstChar(myStr);
	}
	textElement.value = myStr;
	return true;
}

function capitalizeField(textElement,keepNumbers,exceptions,doNotUpperCase) {
	var myStr = textElement.value;
	if (myStr == '')
		return true;

	if (exceptions+"" == 'undefined')
		exceptions = '';
	exceptions += " '.";
		
	myStr = filterString(myStr,true,keepNumbers,exceptions);
	if (!doNotUpperCase){
		myStr = upFirstCharOnly(myStr);
	}
	textElement.value = myStr;
	return true;
}

function isNum(inString)  {
	if(inString.length!=1) 
		return false;
	var refString="1234567890";
	if (refString.indexOf(inString,0) == -1) 
		return false;
	return true;
}

function isChar(inString)  {
	if(inString.length!=1) 
		return false;
	var refString="abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ";
	if (refString.indexOf(inString,0) == -1) 
		return false;
	return true;
}

function isPostal(theObject) {
	if (theObject){
		var a = theObject.value;
		var b = "";
		var u = "";
		var failed = false;
	
		if(a.length < 1)
			return true;
	
		a = filterString(a,true,true,"");
		if (a.length < 1)
			return false;
	
		for(var i=0;i<=5;i++) {
			u = a.charAt(i);
	
			if (i==1||i==3||i==5) {
				if (!isNum(u)) 
					failed=true;
			} 
			else {
				if (isChar(u)) 
					u=u.toUpperCase();
				else 
					failed=true;
			}
			b = b + u;
		}
	
		b = b.substring(0,3)+" "+b.substring(3,6);
	
		theObject.value = b;
	
		return !(failed);
	}
}


function isPostalFirstHalf(obj1){
	var a = obj1.value;
	var b = "";
	var u = "";
	var failed = false;

    if(a.length < 1){
        return true;
        
    } 

	a = filterString(a,true,true,"");
	
	if (a.length < 1){
		return false;
	}	

	for(var i=0;i<3;i++) {
		u = a.charAt(i);

		if (i==1) {
			if (!isNum(u)) 
				failed=true;
		} 
		else {
			if (isChar(u)) 
				u=u.toUpperCase();
			else 
				failed=true;
		}
		b = b + u;
	}
	obj1.value = b.substring(0,3);
	
	if (failed == true){
		obj1.value = '';
		obj1.focus();
	}	

	return !(failed);
}


function isPostalSecondHalf(obj2){
	var a = obj2.value;
	var b = "";
	var u = "";
	var failed = false;

    if(a.length < 1)
        return true;

	a = filterString(a,true,true,"");
	
	if (a.length < 1)
		return false;

	for(var i=0;i<3;i++) {
		u = a.charAt(i);

		if (i==0 || i==2) {
			if (!isNum(u)) 
				failed=true;
		} 
		else {
			if (isChar(u)) 
				u=u.toUpperCase();
			else 
				failed=true;
		}
		b = b + u;
	}
	obj2.value = b.substring(0,3);
		
	if (failed == true){
		obj2.value = '';
		obj2.focus();
	}

	return !(failed);
}
	

function validateAndAlertForPostalCode(theObject, shouldLeave) {
	if (theObject){
		if(!isPostal(theObject)) {
		if(!shouldLeave) {
			theObject.value='';
		}
		theObject.focus();
		alert('Invalid Postal Code.');
		}
    }
}

function monthsFromYM(yearObject,monthObject) {
	var totmInt = 0;
	if (yearObject.selectedIndex != 0 && monthObject.selectedIndex != 0) {
		totmInt = (parseInt(monthObject.options[monthObject.selectedIndex].text,10)+(12*parseInt(yearObject.options[yearObject.selectedIndex].text,10)));
		if(!isNaN(totmInt)) 
			return totmInt;
   } 
   
   return null;
}


function isSin(textObject) {
	var tempStr = "";
	var tempInt = 0;
	var returnBol = false;
	var sumInt = 0;
	var sumStr = "";
	
	textObject.value = filterString(textObject.value,false,true,"");
	tempStr = textObject.value;

	if (tempStr.length == 9) {
		for (var indexInt=1;indexInt<9;indexInt++) {
			tempInt = parseInt(tempStr.charAt(indexInt-1),10);
			if ((indexInt % 2) == 0) {
				tempInt *= 2;
				if (tempInt > 9) {
					tempInt -= 9;
				}
			}
			sumInt += tempInt;
		}
		
		sumStr = ""+sumInt;
		tempInt = 10-parseInt(tempStr.charAt(tempStr.length-1),10);
		tempStr = ""+tempInt;


		if (sumStr.charAt(sumStr.length-1) == tempStr.charAt(tempStr.length-1))
			returnBol = true;
	}
	else if (tempStr.length < 1) 
		return true;

	return returnBol;

}
function do_Other(objref,optionsIdx,promptText,maxLen) {
	if (objref.selectedIndex == optionsIdx) {
		//Prompt for a value
		var otherValue = '';
		otherValue = prompt(promptText,"");
		if (otherValue == '' || otherValue+"" == 'null' || otherValue+"" == 'undefined') {
			objref.options[(optionsIdx)].selected = true;
			return false;
		}
		if (otherValue.length >= maxLen)
			otherValue = otherValue.substring(0,maxLen);
			
		/*
			Edited by Liban Gaashaan on Friday, May 23, 2003
			Added the followin two lines to create new option.
		*/
		var myNewOption = new Option ("TheText", "TheValue");
		objref.options[optionsIdx+1] = myNewOption;
		
		objref.options[(optionsIdx+1)].value = otherValue;
		objref.options[(optionsIdx+1)].text = otherValue;
		objref.options[(optionsIdx+1)].selected = true;
		return true;
	} else
		return false;
}

function validateNum(theNum,decplaces,min,max,addcommas,acceptNoneStr) {
	validateNumWithError(theNum,decplaces,min,max,addcommas,acceptNoneStr);
}

function validateNumWithError(theNum,decplaces,min,max,addcommas,acceptNoneStr,errorMsg,donotwarn) {
	var str = ""+theNum.value;
	if ((str == "") || (str == "null")) {
		theNum.value = "";
		return false;
	}
	if (acceptNoneStr) {
		var str2 = stripinFun(str,".0123456789noneNONE");
		if (str2.toUpperCase() == 'NONE')
			theNum.value = "0";
	}
	var tmpFloat = parseFloat(filterNum(theNum.value));
	if (isNaN(tmpFloat)) {	// OTHERWISE, FIELD DISPLAYS NaN //
		theNum.value = "";
		return false;
	}
	if (tmpFloat < min || tmpFloat > max) {
		if (donotwarn != true){
			if ((""+errorMsg) == "undefined") {
   	           	eval(i18nK("ValidateNumEval"));
			}
			else {
				alert(errorMsg);
			}
		}
		theNum.value = "";
		theNum.focus();
		return false;
	}
	var fmtdnum;
	var checkNum;
	if (decplaces == 0) {
		fmtdnum = formatInteger(theNum,decplaces);
		checkNum = parseInt(fmtdnum,10);
	} else {
		fmtdnum = formatRealNum(theNum,decplaces);
		checkNum = parseFloat(fmtdnum);
	}
	if (checkNum > max)
		fmtdnum = checkNum - 1;

	if (addcommas) {
		fmtdnum = commaFmt(fmtdnum);
	}
	theNum.value = fmtdnum;
	return true
}


function formatRealNum(theNum,decplaces) {
	var str = Math.round(parseFloat(filterNum(theNum.value)) * Math.pow(10,decplaces));
	str = ""+str;
	while (str.length <= decplaces) {
		str = "0" + str;
	}
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function formatInteger(theNum) {
	if (theNum){
		var str = Math.round(parseFloat(filterNum(theNum.value)));
		str = ""+str;
		return str;
	}
	return 0;
}

function commaFmt(numEle) {
	var tempStr = ""+numEle;
	
	// already has commas
	var charCheck = tempStr.indexOf(",");
	if ((charCheck+0) >= 0) {
		return numEle;
	}

	// separate the decimal from the whole number
	var decStr = "";
	var decInt = tempStr.indexOf(".");
	if (decInt!=-1) {
		decStr = tempStr.substring(decInt,tempStr.length);
		tempStr = tempStr.substring(0,decInt);
	}

	// if negative - save sign
	var isNeg = false;
	if (tempStr.indexOf("-")!=-1) {
		isNeg=true;
        tempStr=tempStr.substring(1,tempStr.length);
	}

	// short - no commas needed
	if (tempStr.length<=3) { 
		return numEle;
	}

	// add commas
	var newStr = "";
	var jInt = 0;
	for (var iInt=tempStr.length-1;iInt>=0;iInt--) {
		jInt++;
		newStr = tempStr.charAt(iInt) + newStr;
		if (jInt%3==0) {
			if (iInt-1>=0) {
				newStr = ","+newStr;
			}
		}
	}

	// re-assemble the parts
	if (decInt!=-1)
		newStr = newStr + decStr;
	if (isNeg)
		newStr = "-"+newStr;

	return newStr;
}

function tally(args) {
	var sumNum = 0;
	var tempNum = 0;
	var tempStr = "";
	var subBol = false;
	var doFloats = false;
	var startIndex = 0;
	if (tally.arguments[0] == "float") {
		doFloats = true;
		startIndex = 1;
	}

    for (var i=startIndex; i<(tally.arguments.length - 1); i++) {
		if (tally.arguments[i] == "-") {
			subBol = true;
		} 
		else {
		  if(tally.arguments[i]){
			tempStr = tally.arguments[i].value +"";
			tempStr = stripFun(tempStr,",");
			if (tempStr != "" && tempStr != null) {
				if (doFloats)
					tempNum = parseFloat(tempStr);
				else
					tempNum = parseInt(tempStr,10);
				if (tempNum>0) {
					if (subBol) {
						sumNum -= tempNum;
						subBol = false;
					} 
					else 
						sumNum += tempNum;
				}
			}
		  }
		}
	}
	if (doFloats && (sumNum+"").indexOf(".") == -1)
		sumNum += ".00";

	tally.arguments[i].value = sumNum;
}

function trim(string) {
    var i=0;
	string = ""+string;
	var returnString="";
    var whitespace = " \t\n\r";
	var just_white_space = true
	var ch = "";

	for (i = 0; i < string.length; i++){
		ch = string.substring(i, i+1);
        if (whitespace.indexOf(ch) == -1) {
			string=string.substring(i,string.length);
			just_white_space = false;
			break;
		}
    }
	if (just_white_space) {
		string = "";
	} else {
		i=string.length
		for (i = string.length; i>=0; i--){
			ch = string.substring(i, i+1);
			if (whitespace.lastIndexOf(ch) == -1) {
				string=string.substring(0,i+1);
				break
			}
		}
	}

	return string;
}

function setDropDownIndexByValue (formField, dropDownValue){
	for (var i = 0; i < formField.options.length; i++){
		if (formField.options[i].value == dropDownValue){
			formField.selectedIndex = i;
			break;
		}
	}
}

function setDropDownIndexByTextValue (formField, dropDownValue){
	for (var i = 0; i < formField.options.length; i++){
		if (formField.options[i].text == dropDownValue){
			formField.selectedIndex = i;
			break;
		}
	}
}

function Email_Check(element, warn) {
	var emailStr = element.value;
	if (emailStr == "none" || emailStr == "")
		return true;
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		if (warn)
			alert(i18nK("BadEmailAddressEntered"));
			//alert("Email address seems incorrect (check @ and .'s).  Please try again.")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
		if (warn)
			alert(i18nK("BadEmailAddressEntered"))
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
			if (warn)
				alert(i18nK("BadEmailAddressEntered"))
		        	//alert("Destination IP address is invalid!  Please try again.")
			return false
		    }
		   }
		   return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		if (warn)
			alert(i18nK("BadEmailAddressEntered"))
			//alert("The domain name doesn't seem to be valid.  Please try again.")
	    return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
		if (warn)
			alert(i18nK("BadEmailAddressEntered"))
		   	//alert("The address must end in a three-letter domain, or two letter country.  Please try again.")
		   return false
	}

	if (len<2) {
		if (warn)
			alert(i18nK("BadEmailAddressEntered"))
		   	//alert("This address is missing a hostname!  Please try again.");
		return false
	}
	return true;
}

/////////////////////////// TRANSLATION STUFF ///////////////////////
var languageIndex;

var i18nLanguageArray = new Array();

// This function just takes the value stored in the sessionLanguage and gets the
// 'index' for that language that is later used in i18n(). This is faster then
// resolving the strings each time i18n is called. You shouldn't have to call
// this ever (it is called at the top of js file that defines it and i18n.
function i18nUpdateLanguageIndex() {
    if(sessionLanguage == "English")
        languageIndex = 0;
    else if(sessionLanguage == "French")
        languageIndex = 1;
    else
        languageIndex = -1;
}

function i18nAddTextArrayForKey(array, key) {
    var str = 'i18nLanguageArray["' + key + '"] = array';
    eval(str);
}

var I18N_CMD_KEY = 10;
var I18N_CMD_ARRAY = 20;

function i18nK(key) {
    return i18n(I18N_CMD_KEY, key);
}

function i18n(cmd, obj1) {
    switch(cmd){
        case I18N_CMD_KEY: // Single Key.
            // obj1 is the key, return translated text.
            return eval('i18nLanguageArray["' + obj1 + '"][' + languageIndex + '];');
        case I18N_CMD_ARRAY: // Array of Keys
            // obj1 is an array of strings which are keys, return the
            // translated text.
            var newarray;

            for(var i = 0; i < obj1.length; i++){
                newarray[i] = eval('i18nLanguageArray["' + obj1[i] + '"][' + languageIndex + '];');
            }

            return newarray;
        default:
            alert("i18n(): Error in parameters: " + cmd + " is not a valid command."); 
            return "{i18n():ERROR}";
    }
}
//////////////////////// END TRANSLATION STUFF //////////////////////

// Translations for this class (can be overriden! See above!) //
i18nAddTextArrayForKey(new Array(
            'The year you have entered is invalid. Please try again. Select "OK" to return to the application.',
            'L\'année que vous avez entrée est invalide. Veuillez réessayer. Sélectionnez OK pour retourner à la demande.'
            ),
        "InvalidYearPleaseCorrect");
i18nAddTextArrayForKey(new Array(
            'The e-mail address you have entered is not in a valid format (e.g. yourname@server.com). Please try again. Select "OK" to return to the application.',
            'Le format de l\'adresse électronique entrée n\'est pas valide (p. ex., votrenom@serveur.com). Veuillez réessayer. Sélectionnez «OK» pour retourner à la demande.'
            ),
        "BadEmailAddressEntered");
i18nAddTextArrayForKey(new Array(
	    'The date you have entered is invalid. Please try again. Select "OK" to return to the application.',
	    'La date que vous avez entrée est invalide. Veuillez réessayer. Sélectionnez «OK» pour retourner à la demande.'),
	"InvalidDate2");
i18nAddTextArrayForKey(new Array(
            'Your phone number should have a 3-digit area code and a 7-digit local number. Please confirm the number and try again. Select "OK" to return to the application.',
            'Votre numéro de téléphone doit se composer de l\'indicatif régional à 3 chiffres et du numéro local à 7 chiffres. Veuillez confirmer le numéro et réessayer. Sélectionnez «OK» pour retourner à la demande.'
            ),
        "InvalidPhoneNumberEntered");
i18nAddTextArrayForKey(new Array(
            'The fields marked with red arrows are incomplete.\n\nTo return to this page and complete the information now, select "Cancel".\n\nTo proceed to the next page and complete them later, select "OK".',
            'Les champs marqués de flèches rouges sont incomplets.\n\nPour retourner à cette page et compléter les renseignements maintenant, sélectionnez  «Annuler».\n\nPour aller à la page suivante et les compléter plus tard, sélectionnez «OK».'
            ),
        "RequiredFieldSentence");
i18nAddTextArrayForKey(new Array(
            'Before starting your application, you must fill in the Qualifier information where required. Select "OK" to return to the application.',
            'Avant de commencer à remplir votre demande, vous devez entrer les renseignements sur l\'admissibilité dans l\'espace prévu à cet effet. Sélectionnez OK pour retourner à la demande.'
            ),
        "RequiredQualifierSentence");
i18nAddTextArrayForKey(new Array(
            'Before your results can be calculated, you must fill in the Qualifier information where required. Select "OK" to return to the application.',
            'Pour que vos résultats puissent être calculés, vous devez entrer les renseignements sur l\'admissibilité dans l\'espace prévu à cet effet. Sélectionnez OK pour retourner à la demande.'
            ),
        "RequiredQualifierResultsSentence");
i18nAddTextArrayForKey(new Array(
            'The postal code you have entered is not in a valid format (e.g. N9N 9N9). Please try again. Select "OK" to return to the application.',
            'Le format du code postal entré n\'est pas valide (p. ex., N9N 9N9). Veuillez réessayer. Sélectionnez «OK» pour retourner à la demande.'
            ),
        "InvalidPostalCodeEntered");
i18nAddTextArrayForKey(new Array(
            'The link you have selected is not available from this page.  Select "OK" to return to the application.',
            'Le lien que vous avez sélectionné n\'est pas disponible à partir de cet écran. Choisissez "OK" pour continuer.'
            ),
        "PageCannotBeAccessed");
i18nAddTextArrayForKey(new Array(
            'The page you have selected can\'t be accessed using this method. Select "OK" to return to the application.',
            'Vous ne pouvez pas accéder à la page que vous avez sélectionnée en vous servant de cette méthode. Sélectionnez OK pour retourner à la demande.'
            ),
        "ThePageYouHaveSelectedCannotBeAccessedUsingThisMethod");
i18nAddTextArrayForKey(new Array(
            'alert("Please enter a number between " + min + " and " + max + ". Select \\"OK\\" to return to the application.");',
            'alert("Veuillez inscrire un numéro entre " + min + " et " + max + ". Sélectionnez «OK» pour retourner à la demande.");'
            ),
        "ValidateNumEval");

// END Translations //
