
function eObj(id,attribute,value){
	if (document.all){
		lb = "[";rb = "]";idType = "document.all";
	}
	else{
		lb = "(";rb = ")";idType = "document.getElementById";
	}
	var object = idType+lb+"'"+id+"'"+rb+"."+attribute+"\=\""+value+"\"";
	eval(object);
}

function eObjVal(id,attribute){
	if (document.all){
		lb = "[";rb = "]";idType = "document.all";
	}
	else{
		lb = "(";rb = ")";idType = "document.getElementById";
	}
	var object = idType+lb+"'"+id+"'"+rb+"."+attribute;
	return eval(object);
}

<!-- Added by Yogaesh for form validation -->

<!-- Controller function -->

function doValidations(){
	var frmSearch = document.forms[0];
	var sArAlphabeticFields = new Array();
	// Changed on 07th March for removing alphanumeric validations on company name, street and city.
	var sArAlphaNumericFields = new Array("txtzip");
	var sArAlphaNumericFieldLabels = new Array("Zip Code");
	
	var sArUsFields = new Array("usname","usstate");
	var sArCaFields = new Array("caname","castate");
	var sArNonUsFields = new Array("intlname");
	var sArUsFieldNames = new Array("Business Name","State");
	var sArCaFieldNames = new Array("Business Name","Region");
	var sArNonUsFieldNames = new Array("Business Name");
	var bResult = false;
	var iSelectIndex = document.forms[0].selcountry.selectedIndex;
	var sSelectName = document.forms[0].selcountry[iSelectIndex].value;
			
	remove_XS_whitespace(frmSearch);
	bResult = testEmpty(sArUsFields,sArCaFields,sArNonUsFields,sArUsFieldNames,sArCaFieldNames,sArNonUsFieldNames,sSelectName);
	if(!bResult)
		return false;
	bResult = checkAlphaNumeric(sArAlphaNumericFields,sArAlphaNumericFieldLabels);
	if(!bResult)
		return false;
	bResult = checkPhoneFormat("txttelephone");
	if(!bResult){
		return false;
	}
	bResult = preventTollFreePhoneNumber("txttelephone", "search");
	if(bResult != "success"){
		alert(bResult);
		return false;
	}
	if(sSelectName == "CA" || sSelectName == "US"){
		if(sSelectName == "US")
			bResult = validateStateCode("txtstate","1");
		else
			bResult = validateStateCode("txtstate_ca","2");
		if(!bResult)
			return false;
	}
	return true;
	
}

<!-- To show text only on selecting a country. 7th March -->
function showOrHideText(selection){
	var information_div = document.getElementById("information1");
	if(!selection){
		information_div.style.display='none';
	}
	else{
		information_div.style.display='inline';
	}
}



<!-- Testing for empty values -->
function testEmpty(fieldid1,fieldid2,fieldid3,fieldname1,fieldname2,fieldname3,countryselected){
	
	var outerindex = 0;
	var minlength;
	var maxlength;
	var medlength;
	var sCountrySelected = countryselected;
	
	var alertarray;
	var alertindex =0;
	var shortarray;
	var mediumarray;
	var longarray;
	var shortarraynames;
	var mediumarraynames;
	var longarraynames;
	var message;
	var iIterateFully = 0;
	
	if(sCountrySelected == "US"){
		iIterateFully = 1;
	}
	else if(sCountrySelected == "CA"){
		iIterateFully = 2;
	}
	
	
	if(fieldid1.length > fieldid2.length){
		if(fieldid1.length > fieldid3.length){
			maxlength = fieldid1.length;
			longarray = fieldid1;
			longarraynames = fieldname1;
		}
		else{
			maxlength = fieldid3.length;
			longarray = fieldid3;
			longarraynames = fieldname3;			
		}
		if(fieldid2.length > fieldid3.length){
			medlength = fieldid2.length;
			mediumarray = fieldid2;
			mediumarraynames = fieldname2;
			minlength = fieldid3.length;
			shortarray = fieldid3;
			shortarraynames = fieldname3;
		}
		else{
			medlength = fieldid3.length;
			mediumarraynames = fieldname3;
			mediumarray = fieldid3;
			minlength = fieldid2.length;
			shortarray = fieldid2;
			shortarraynames = fieldname2;
		}
	}
	else{
		if(fieldid2.length > fieldid3.length){
			maxlength = fieldid2.length;
			longarraynames = fieldname2;
			longarray = fieldid2;
		}
		else{
			maxlength = fieldid3.length;
			longarraynames = fieldname3;
			longarray = fieldid3;
		}
		if(fieldid1.length > fieldid3.length){
			medlength = fieldid1.length;
			mediumarray = fieldid1;
			mediumarraynames = fieldname1;
			minlength = fieldid3.length;
			shortarray = fieldid3;
			shortarraynames = fieldname3;
		}
		else{
			medlength = fieldid3.length;
			mediumarray = fieldid3;
			mediumarraynames = fieldname3;
			minlength = fieldid1.length;
			shortarraynames = fieldname1;
			shortarray = fieldid1;
		}
	}
	
	alertarray = new Array(maxlength);
	
	while(outerindex < maxlength){
		if(outerindex < minlength && outerindex < medlength){
			if(!document.getElementById(shortarray[outerindex]).value && !document.getElementById(mediumarray[outerindex]).value && !document.getElementById(longarray[outerindex]).value){
				alertarray[alertindex] = longarraynames[outerindex];
				alertindex++;
			}
		}
		else if(outerindex < medlength && iIterateFully){
				if(!document.getElementById(mediumarray[outerindex]).value && !document.getElementById(longarray[outerindex]).value){
					if(iIterateFully == "2"){
						alertarray[alertindex] = longarraynames[outerindex];
					}
					else{
						alertarray[alertindex] = mediumarraynames[outerindex];
					}
					alertindex++;
				}
		}
		else if(iIterateFully){
				if(!document.getElementById(longarray[outerindex]).value){
					alertarray[alertindex] = longarraynames[outerindex];
					alertindex++;
				}
		}
		else{
			break;
		}
		outerindex++;
	}
	
	/*Web Sec Enhancement March 2008 Changes Start*/
	if(document.forms[0].captcha_input_us.value == "" && document.forms[0].captcha_input_ca.value == "" && document.forms[0].captcha_input_nus.value == ""){
				alertarray[alertindex] = "Verification Code";
				alertindex++;
	}
	/*Web Sec Enhancement March 2008 Changes End*/
	
	if(alertindex){

		if(alertindex > 1){
			message = "The following fields are empty.\nPlease fill them up and submit.\n-------------------------------------------------\n" ;
		}
		else{
			message = "The following field is empty.\nPlease fill it up and submit.\n-------------------------------------------------\n" ;			
		}
		for(i=0;i<alertindex;i++){
			message = message + alertarray[i] + "\n";
		}
		alert(message);
		return false;
	}
	return true;
}


<!-- To test whether a given field is strictly alphanumeric or not -->
function checkAlphaNumeric(sArray,sNameArray){
	var i;
	var sFieldName;
	var charpos;
	var regexp = /[[+;?*^$@!<>%\]~\#%&\(\)\{\}\,\.\\\/\-\_`=\|]/;//The list of special characters. Can be modified if necessary to accomodate certain characters.
	var alertarray = new Array(sArray.length);
	var alertindex = 0;
	var 		message = "The following fields need to be Alpha Numeric\n---------------------------------------------\n";
	
	for(i=0;i<sArray.length;i++){
		sFieldName = eval("document.forms[0]." + sArray[i] + ".value");//Replace RHS by the field to be tested.
		charpos = sFieldName.search(regexp);//returns -1 if string doesnt contain the special characters, else returns index of first occurrence
		if(charpos>=0){
			alertarray[alertindex]=sNameArray[i];
			alertindex++;
			message = message + sNameArray[i] + "\n";
		}
	}
	if(alertindex){
		alert(message);
		return false;
	}
	return true;
}

<!-- To test whether a given field is strictly numeric -->
function checkNumeric(sFieldName){
	var regexp = /[[+;?*^$@!<>%\]~\#%&\(\)\{\}\,\.\\\/\-\_`=\|]|[a-z]/i;//The list of special characters. Can be modified if necessary to accomodate certain characters.
	var charpos = sFieldName.search(regexp);//returns -1 if string doesnt contain alphabets and special characters, else returns index of first occurrence
	if(charpos>=0)
		return false;
	else if(sFieldName.length>0)
		return true;
}

<!-- To test the format of phone number -->
function checkPhoneFormat(sFieldName){
	sFieldName = eval("document.forms[0]." + sFieldName + ".value");//Replace RHS by the field to be tested.
	var regexp = /[[;?*^$@!<>%\]~\#%&\(\)\{\}\,\.\\\/\-\_`=\|]|[a-z]/i;//The list of special characters. Can be modified if necessary to accomodate certain characters.
	var charpos = sFieldName.search(regexp);//returns -1 if string doesnt contain alphabets and special characters, else returns index of first occurrence
	if(charpos>=0){
		alert("Phone number must be numeric. \(A \"+\" may be present in the beginning\)");
		return false;
	}
	else if(sFieldName.indexOf("+") > 0){
		alert("The + sign cannot occur in any position other than the first!");
		return false;
		
	}
	else
		return true;
}


<!-- To test whether a given field is strictly alphabetic -->
function checkNumeric(sFieldName){
	var regexp = /[[+;?*^$@!<>%\]~\#%&\(\)\{\}\,\.\\\/\-\_`=\|]|[0-9]/i;//The list of special characters. Can be modified if necessary to accomodate certain characters.
	var charpos = sFieldName.search(regexp);//returns -1 if string doesnt contain numbers and special characters, else returns index of first occurrence
	if(charpos>=0)
		return false;
	else if(sFieldName.length>0)
		return true;
}

<!-- Validate the state code entered -->

function validateStateCode(sStateFieldName, iUsOrCanada){
	
	var sStateList; 
	var msg;
	var sStateValue = eval("document.forms[0]." + sStateFieldName + ".value");

	
	if(iUsOrCanada == "1"){
		sStateList = "AK,AL,AZ,AR,CA,CO,CT,DE,DC,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VT,VA,VI,WA,WV,WI,WY";
		msg = "Please enter a valid state code!";
	}
	else{	
		sStateList = "AB,BC,MB,NA,NB,NF,NT,NS,ON,PE,PQ,QC,SK,YT";
		msg = "Please enter a valid region code";
	}
	
	if(sStateList.indexOf(sStateValue.toUpperCase()) >= 0){
		return true;
	}
	else{
		alert(msg);
		return false;
	}
}

<!-- Trim -->

function remove_XS_whitespace(frm)
{
	var i;
	var item;
	var index_front;
	var index_behind
	for(i=0;i<frm.elements.length;i++){
	item = frm.elements[i];
	if(item.type=="text" || item.type=="textarea" || item.type=="hidden"){
	  	var tmp = "";
		var item_length = item.value.length;
		var item_length_minus_1 = item.value.length - 1;
		var front_flag = 0;
		var rev_flag = 0;
		var front_spaces = 0;
		var back_spaces = 0;

		if(item.value.length==1 && item.value.charAt(0)==' '){
			item.value = "";
		}
		else if(item.value.length ==1){
			return true;
		}

		  index_front = 0;
		  index_behind = item_length_minus_1;
		  
		  while(index_front <= index_behind)
		  {
		    if(item.value.charAt(index_front) == ' ')
		    {
				front_spaces++;
				index_front++;
		    }
		    else
		    {
				front_flag = 1;
		   	}
		   	if(item.value.charAt(index_behind) == ' ')
			{
					back_spaces++;
					index_behind--;
			}
			else
			{
					rev_flag = 1;
		   	}
		   	if(front_flag ==1 && rev_flag ==1)
		   		break;

		  }


		  item.value = item.value.substring(front_spaces,item.value.length);
		  item.value = item.value.substring(0,(item.value.length - back_spaces));

		  front_flag=0;
		  rev_flag=0;

		  front_spaces = 0;
		  back_spaces =0;
		}

	 }
}
<!-- To prevent toll free phone numbers -->
function preventTollFreePhoneNumber(phoneNumberField, flagForRequestType){
	var MessageToDisplay = "success";
//	tollFreePhoneNumberList = "800,888,866,877,855";
	tollFreePhoneNumberList = ["800","888","866","877","855"];
	if(flagForRequestType == "search"){
		phoneNumberBeginsWith = eval("document.forms[0]." + phoneNumberField + ".value");
	}
	else if(flagForRequestType == "ModifyOrNew"){
		phoneNumberBeginsWith = phoneNumberField;
	}
	
	if(phoneNumberBeginsWith != "")
		phoneNumberBeginsWith = phoneNumberBeginsWith.substring(0,3);
		
	//if(phoneNumberBeginsWith != "" && tollFreePhoneNumberList.indexOf(phoneNumberBeginsWith) >= 0){
	//	MessageToDisplay = "The phone number you have entered is Toll-free";
	//}
	if(phoneNumberBeginsWith != ""){
		for(var i=0; i < tollFreePhoneNumberList.length;i++){
			if(tollFreePhoneNumberList[i] == phoneNumberBeginsWith){
				MessageToDisplay = "The phone number you have entered is Toll-free";
			}
		}
	}
		return MessageToDisplay;
}
<!-- End of changes made by Yogaesh -->
