function getObjByName(objForm,objName)
{
	for (i = 0; i < objForm.length; i++) {
	
		if(objForm.elements[i].name!=null) {  
			if ( objForm.elements[i].name.indexOf(objName)!=-1 && objForm.elements[i].name.indexOf("OldValue")==-1) {
	               return objForm.elements[i];
			}
		}
	}
}

function getCheckedObjByName(objForm,objName)
{
	for (i = 0; i < objForm.length; i++) {

	    if(objForm.elements[i].name!=null) {    
			if ( objForm.elements[i].name.indexOf(objName)!=-1 && objForm.elements[i].name.indexOf("OldValue")==-1) {
  
		        if(objForm.elements[i].checked) {
		              return objForm.elements[i]; 
		        }            
			}
		}	
	}
}

/**
 *	Check whether the inputed mail address is right in format.
 *	value - Should be a string, which contains a mail address.
 */
function mailCheck(value){
   return value == null ? false : value.match(/\b[A-Za-z0-9._%-]+@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,4}\b/);
}

/**
 *	Check whether the inputed postal code is right in format(Match any case M1H 2J2 or without space).
 *	value - Should be a string, which contains a mail address.
 */
function postalCodeCheck(value){
   return value == null ? false : value.match(/\b[A-Za-z][0-9][A-Za-z]\s{0,1}[0-9][A-Za-z][0-9]\b/);
}

/**
 * Trim all the spaces in the string.
 */
function trimSpaces(value){
    x = value.replace(/\s+/g, '');
    return x;
}

/**
 * Trim the spaces at the begin and end in the string.
 */
function trim(value){
    return value == null ? null : value.replace(/^ +/, '').replace(/ +$/, '');
}

/**
 * Trim the left spaces in the string.
 */
function lTrim(value){
    return value == null ? null : value.replace(/^ +/, '');
}

/**
 * Trim the right spaces in the string.
 */
function rTrim(value){
    return value == null ? null : value.replace(/ +$/, '');
}


function postcodevalidate(ctry,zip){
	zip = trimSpaces(zip).toUpperCase(); 
	provinveInitial="ABCEGHJKLMNPRSTVXY";
	if(ctry=="ca"&&provinveInitial.indexOf(zip.substring(0,1))==-1){
		return false;
	}else{
	var tmp ="";
	switch(trim(ctry)){
		case "ca":{
			if(zip.length!=6)
				return false;
			tmp= new RegExp("^[a-zA-Z][0-9][a-zA-Z][\\s]{0,1}[0-9][a-zA-Z][0-9]");
			break;
		}
		case "us":{
			tmp = new RegExp("^[0-9]{5}");
			break;
		}
		default:
			tmp= new RegExp("^[a-zA-Z][0-9][a-zA-Z][[:space:]][0-9][a-zA-Z][0-9]");
	}
	return tmp.test(zip);
	}
}
 



/*function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}*/

function getCompareString(string){
		
		string=string.toUpperCase(); 
		string=trimSpaces(string);
		return string;
	
	}	

function getProvinceAbbre(pc){
	province="";
	pc=getCompareString(pc);
	initial=pc.substring(0,1)
	
	switch (initial){
			case 'A':
				province = "NL";
				break;
			case 'B':
				province = "NS";
				break;
			case 'C':
				province = "PE";
				break;
			case 'E':
				province = "NB";
				break;
			case 'G':
				province = "QC";
				break;
			case 'H':
				province = "QC";
				break;
			case 'J':
				province = "QC";
				break;
			case 'K':
				province = "ON";
				break;
			case 'L':
				province = "ON";
				break;
			case 'M':
				province = "ON";
				break;
			case 'N':
				province = "ON";
				break;
			case 'P':
				province = "ON";
				break;
			case 'R':
				province = "MB";
				break;
			case 'S':
				province = "SK";
				break;
			case 'T':
				province = "AB";
				break;
			case 'V':
				province = "BC";
				break;
			case 'X':
				initial3=pc.substring(0,3)
			
				if (initial3=="X0A"||initial3== "X0B"||initial3=="X0C"){ 
					province = "NU";
				}else{
					province = "NT";
				}
				break;
			case 'Y':
				province = "YT";
				break;
	
	}
	return province;

}

function provinceEqual(sessionProvince,pc){
		
	inputProvince=getProvinceAbbre(pc)
	if(sessionProvince == "PQ")
	{
	sessionProvince="QC"
	}
	if(sessionProvince==inputProvince){
	    return true;
	}else{
		return false;
	}

}

	/**
	* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
	* IE has a problem with wanted select form tags to always be the topmost z-index or layer
	*/
	function hideSelectBoxes() {
		for(var i = 0; i < document.forms.length; i++) {
			for(var e = 0; e < document.forms[i].length; e++){
				if(document.forms[i].elements[e].tagName == "SELECT") {
					 document.forms[i].elements[e].style.visibility="hidden";
				}
			}
		}
	}
	
	/**
	* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
	* IE has a problem with wanted select form tags to always be the topmost z-index or layer
	*/
	function displaySelectBoxes() {
		for(var i = 0; i < document.forms.length; i++) {
			for(var e = 0; e < document.forms[i].length; e++){
				if(document.forms[i].elements[e].tagName == "SELECT") {
					 document.forms[i].elements[e].style.visibility="visible";
				}
			}
		}
	}

	function textCounter(obj, maxlimit) {
	    var spaceLength = 0 ;
		/**
		for (var i = 0; i < obj.value.length ; i++) {
		    var filterChar = obj.value.substring(i, i + 1) ;
			if (filterChar==" " || filterChar=="\n" || filterChar=="\r") {
				spaceLength ++ ;	
			}					
		}
	
	    var trimValue =  obj.value.replace(/ /g, "");   //trim space
	    */ 
		if (obj.value.length > maxlimit) {
			obj.value = obj.value.substring(0, maxlimit + spaceLength);
		}
	}

