// Use for RichFx product display.
function enlargeDisplay(storeId, catalogId, langId, prodId)
{
	
	var url = "EnlargeProductDisplay?storeId="+storeId+"&catalogId="+catalogId+"&langId="+langId+"&productId=" + prodId;
	window.open(url,'Enlarged','width=620,height=550,toolbar=no,status=no,menubar=no,resizable=yes');
}

// Use for BOGO display.
function BOGO()
{ 
	var url = "/www/b/TCP/content/bogo.html";
	window.open(url,'BOGO','height=285,width=320,toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no');
}

// Use for product size chart display.
function sizingDisplay(storeId, catalogId, langId)
{
	var url = "SizingView?storeId="+storeId+"&catalogId="+catalogId+"&langId="+langId;
	window.open(url,'Sizing','height=400,width=600,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes')
}

// Use for product size chart display.
//Shoe size chart Display
function shoeSizingDisplay(url)
{ 

   window.open(url,'sizing','height=500,width=600,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
}

// End of shoe size chart Display
function shippingInfoDisplay(url)
{
	window.open(url,'ShippingInfo','height=600,width=750,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes')
}

// Use for privacy display.
function privacyDisplay(url)
{
	if(url==null)
	{
		url ="PrivacyView?storeId=10001&langId=-1&catalogId=10001";
	}
	window.open(url,'Privacy','height=600,width=750,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes')
}

function checnNumeric(val){

	var rc = true;
	var isNum = true;
	
	// Check for non-numeric, greater than 0 val.
	for (var y = 0; y < val.length; y++){
		
		if ((!parseInt(val.charAt(y))) && !(val.charAt(y) == '0')){
			isNum = false
			break;
		}
	}

	if ((!isNum) || (val < 1)){
		rc = false;
	}
	
	return rc;
}

function checkLogonSubmit(errUserName, errorPassword){

	var rc = true;
	var errMsg = "";
	var className = "error";
	var labelName = "";
	var inputName = "";
	var inputClassName = "input-error";
	
	labelName = "label.errorLogonId";
	inputName = "input.errorLogonId";

	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(document.LogonForm)){
		return false;
	}
		
	if (document.LogonForm.logonId.value < 1){
	
		errMsg += (errUserName) + '\n';
		$(labelName).addClass(className);
		$(inputName).addClass(inputClassName);	
		rc = false;
		
	}else{
		$(labelName).removeClass(className);
		$(inputName).removeClass(inputClassName);	
	}
	
	labelName = "label.errorLogonPassword";
	inputName = "input.errorLogonPassword";
	
	if (document.LogonForm.logonPassword.value < 1){
	
		errMsg += (errorPassword) + '\n';
		$(labelName).addClass(className);
		$(inputName).addClass(inputClassName);	
		rc = false;
		
	}else{
		$(labelName).removeClass(className);
		$(inputName).removeClass(inputClassName);	
	}
	
	if(rc == false){
		alert(errMsg);
	}
	
	return rc;
}

// Use on add billing or shipping address form to turn off existiong address radion selection 
// when user input non-empty value in the new address form.
function resetExistingAddressSelection(fm, val)
{
	if(!isEmpty(val)){
	
		// If only have a radio button, browser does not treat it as array but single entity.
		if(fm.existingAddressId.length != null){
		
			var radioLength = fm.existingAddressId.length;
			for(var i = 0; i < radioLength; i++) {
				if(fm.existingAddressId[i].checked) {
					fm.existingAddressId[i].checked = false;
				}
			}
		}else{
		
			// Only one radio.
			if(fm.existingAddressId.value != null){
				fm.existingAddressId.checked = false;
			}
		}
		
		resetShipmodeSelection(fm);
	}
}

function isPOBoxAddress(addressLines){

		// This P.O.Box strings logic copied from the backend.
		var vctPOBoxCompare = new Array();
		/*
		vctPOBoxCompare[0] = "p.o. box";
		vctPOBoxCompare[1] = "p. o. box";
		vctPOBoxCompare[2] = "po box";
		vctPOBoxCompare[3] = "p o box";
		vctPOBoxCompare[4] = "pobox";
		vctPOBoxCompare[5] = "p.o.box";
		vctPOBoxCompare[6] = "p.o box";
		vctPOBoxCompare[7] = "p o. box";
		vctPOBoxCompare[8] = "p o.box";
		vctPOBoxCompare[9] = "p.obox";
		vctPOBoxCompare[10] = "p obox";
		vctPOBoxCompare[11] = "post office box";
		*/
		
		//List given by Vicki on 9/16/08
		/*
		vctPOBoxCompare[0] = "P . O. BOX";
		vctPOBoxCompare[1] = "P . O . BOX";
		vctPOBoxCompare[2] = "P .O. BOX";
		vctPOBoxCompare[3] = "P BOX";
		vctPOBoxCompare[4] = "P  O  BOX";
		vctPOBoxCompare[5] = "P O BOX";
		vctPOBoxCompare[6] = "P O 205";
		vctPOBoxCompare[7] = "P OBOX";
		vctPOBoxCompare[8] = "P. O. BOX";
		vctPOBoxCompare[9] = "P. O . BOX";
		vctPOBoxCompare[10] = "P. O BOX";
		vctPOBoxCompare[11] = "P. O.  BOX";
		vctPOBoxCompare[12] = "P. O. BOX";
		vctPOBoxCompare[13] = "P. O.BOX";
		vctPOBoxCompare[14] = "P. O, BOX";
		vctPOBoxCompare[15] = "P..O. BOX";
		vctPOBoxCompare[16] = "P.O  BOX";
		vctPOBoxCompare[17] = "P.O BOX";
		vctPOBoxCompare[18] = "P.O. BOX";
		vctPOBoxCompare[19] = "P.O. B.";
		vctPOBoxCompare[20] = "P.O. BOX";
		vctPOBoxCompare[21] = "P.O.BOX";
		vctPOBoxCompare[22] = "P.O, BOX";
		vctPOBoxCompare[23] = "P.O, BOX";
		vctPOBoxCompare[24] = "P.O,  BOX";
		vctPOBoxCompare[25] = "P.O,BOX";
		vctPOBoxCompare[26] = "P.OBOX";
		vctPOBoxCompare[27] = "P.0 BOX";
		vctPOBoxCompare[28] = "P.0.BOX";
		vctPOBoxCompare[29] = "P, O. BOX";
		vctPOBoxCompare[30] = "P,O. BOX";
		vctPOBoxCompare[31] = "P,O, BOX";
		vctPOBoxCompare[32] = "P,O, BOX";
		vctPOBoxCompare[33] = "PO  BOX";
		vctPOBoxCompare[34] = "PO BOX";
		vctPOBoxCompare[35] = "PO. BOX";
		vctPOBoxCompare[36] = "PO.BOX";
		vctPOBoxCompare[37] = "POB";
		vctPOBoxCompare[38] = "POBOX";
		vctPOBoxCompare[39] = "POST BOX";
		vctPOBoxCompare[40] = "POST OFFICE BOX";
		vctPOBoxCompare[41] = "POSTAL BOX";
		vctPOBoxCompare[42] = "P0 BOX";
		vctPOBoxCompare[43] = "P  O BOX";
		vctPOBoxCompare[44] = "P O  BOX";
		*/
		
		// Below are P.O.Box strings with out spaces.
		vctPOBoxCompare[0] = "P.O.BOX";
		vctPOBoxCompare[1] = "POBOX";
		vctPOBoxCompare[2] = "PBOX";
		vctPOBoxCompare[3] = "P.OBOX";
		vctPOBoxCompare[4] = "PO.BOX";
		vctPOBoxCompare[5] = "P.BOX";
		vctPOBoxCompare[6] = "PO205";
		vctPOBoxCompare[7] = "P.O,BOX";
		vctPOBoxCompare[8] = "P,O.BOX";
		vctPOBoxCompare[9] = "P,O,BOX";
		vctPOBoxCompare[10] = "P..O.BOX";
		vctPOBoxCompare[11] = "P..O..BOX";
		vctPOBoxCompare[12] = "P.O..BOX";
		vctPOBoxCompare[13] = "P,O,,BOX";
		vctPOBoxCompare[14] = "P,,O,,BOX";
		vctPOBoxCompare[15] = "P,,O,BOX";
		vctPOBoxCompare[16] = "P.O.B.";
		vctPOBoxCompare[17] = "P0BOX";
		vctPOBoxCompare[18] = "P.0BOX";
		vctPOBoxCompare[19] = "P0.BOX";
		vctPOBoxCompare[20] = "P.0.BOX";
		vctPOBoxCompare[21] = "P0,BOX";
		vctPOBoxCompare[22] = "P,0BOX";
		vctPOBoxCompare[23] = "P,0,BOX";
		vctPOBoxCompare[24] = "POB";
		vctPOBoxCompare[25] = "P0B";
		vctPOBoxCompare[26] = "POSTBOX";
		vctPOBoxCompare[27] = "POSTOFFICEBOX";
		vctPOBoxCompare[28] = "POSTALBOX";
		vctPOBoxCompare[29] = "P,BOX";
		vctPOBoxCompare[30] = "P,O,B,";
		vctPOBoxCompare[31] = "P,OBOX";
		vctPOBoxCompare[32] = "PO,BOX";
		vctPOBoxCompare[33] = "P.O.B";
		vctPOBoxCompare[34] = "P,O,B";
		vctPOBoxCompare[35] = "P.O,B";
		vctPOBoxCompare[36] = "P,O.B";
		vctPOBoxCompare[37] = "P.0.B";
		vctPOBoxCompare[38] = "P,0,B";
		vctPOBoxCompare[39] = "P.0,B";
		vctPOBoxCompare[40] = "P,0.B";
		vctPOBoxCompare[41] = "BOX";
		vctPOBoxCompare[42] = "B0X";
		
		
		var foundPoBox = false;
		
		//var lineLowerCase = addressLines.toLowerCase();
		var lineUpperCase = addressLines.toUpperCase();
		//Trim the all spaces
		lineUpperCase = trimSpace(lineUpperCase);
		
		for(var i = 0; i < vctPOBoxCompare.length; i++) 
		{
			// Found.
			if (lineUpperCase.indexOf(vctPOBoxCompare[i]) > -1){
				foundPoBox = true;				
				break;
			}
		}
		return foundPoBox;
}

function setSelectAddressDefaultShipMode(fm){

	var addressId = "";
	
	if(fm.existingAddressId.length != null){
	
		for(var i = 0; i < fm.existingAddressId.length; i++) {
			if(fm.existingAddressId[i].checked) {
				addressId = fm.existingAddressId[i].value;
				
				break;
			}
		}
		
	}else{
		
		// Only one radio.
		if(fm.existingAddressId.value != null){
			if(fm.existingAddressId.checked) {
				addressId = fm.existingAddressId.value;
			}
		}
	
	}
	
	if(addressId != ""){
		resetShippingMethodFieldValues(fm, addressId);
	}

}


function resetShipmodeSelection(fm){
	
	if (fm.requireShipMethodCheck.value == 'Y') {	
		// Pre-select the first available shipmode.
	    for (i=0;i<fm.shipModeId.length;i++) {
	    
	    	var styleDisplay = fm.shipModeId[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display;
	    	var blockNoteId = fm.shipModeId[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
	    	
	    	if(styleDisplay == 'block'){
	    		fm.shipModeId[i].checked = true;
	    		break;
	    	}
		}  
	}
	
	/*
	if(fm.shipModeId.length != null){
		
		for(var k = 0; k < fm.shipModeId.length; k++) {
		
			fm.shipModeId[k].checked = false;
		}
		
	}else{
	
		// Only one radio.
		if(fm.shipModeId.value != null){
		
			fm.shipModeId.checked = false;
		}
	}
	*/
}


function resetNewAddressFormFieldValues(fm){

	fm.firstName.value = "";
	fm.lastName.value = "";
	fm.address1.value = "";
	fm.address2.value = "";
	fm.city.value = "";
	fm.state.selectedIndex = 0;
	fm.zipCode.value = "";
	fm.phone_1[0].value = "";
	fm.phone_1[1].value = ""; 
	fm.phone_1[2].value = ""; 
	fm.phone_1[3].value = "";
	fm.phone1.value="";
	
	resetShipmodeSelection(fm);
}

function isExistingAddressChecked(fm){

	var rc = false;
	
	//alert("Existing addresses value is " + fm.existingAddressId.value);
	//alert("Existing addresses length is " + fm.existingAddressId.length);
	
	// If only have a radio button, browser does not treat it as array but single entity.
	if(fm.existingAddressId.length != null){
	
		for(var i = 0; i < fm.existingAddressId.length; i++) {
			if(fm.existingAddressId[i].checked) {
				//alert("Checked address id " + fm.existingAddressId[i].value);
				rc = true;
				break;
			}
		}
		
	}else{
		
		// Only one radio.
		if(fm.existingAddressId.value != null){
			if(fm.existingAddressId.checked) {
				rc = true;
			}
		}
	
	}
	
	return rc;
}

function isShipmodeChecked(fm){

	var rc = true;
	
	if(fm.shipModeId != null){
	
		if(fm.shipModeId.length != null){
		
			var shipmodeNotChecked = true;
					
			// Check for at least one radio button being check.
			
			// If only have a radio button, browser does not treat it as array but single entity.
			if(fm.shipModeId.length != null){
					
				var radioLength = fm.shipModeId.length;
				for(var i = 0; i < radioLength; i++) {
				
					if(fm.shipModeId[i].checked) {
					
						shipmodeNotChecked = false;
						break;
					}
				}
				
				if(shipmodeNotChecked){
					rc = false;
				}
			}
		}
		
	}
	return rc;

}

function checkNewAddressSubmit(fm){

	var rc = true;
	var errMsg = "";
	var className = "error";
	var labelName = "";
	var inputName = "";
	var inputClassName = "input-error";
	var formValue = "";
	var continueCheckCity = true;

	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(fm)){
		return false;
	}	
	
	msg = "Please select Preexisting Address or..." + "\n";
	
	if(isExistingAddressChecked(fm)){
		//return true;
		
		msg = "Please select a shipping method" + "\n";
		if(isShipmodeChecked(fm)){
			fm.requireShipMethodCheck.value = "N";
			//alert("requireShipMethodCheck value="+fm.requireShipMethodCheck.value);
			return true;
		}else{
			errMsg += msg;
			alert(errMsg);
			return false;
		}
	}else{
		errMsg += msg;
	}	
		
	
	labelName = "label.errorRegFirstName";
	inputName = "input.errorRegFirstName";
	msg = "Please enter a first name." + "\n";
	formValue = fm.firstName.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}
	
	labelName = "label.errorRegLastName";
	inputName = "input.errorRegLastName";
	msg = "Please enter a last name." + "\n";
	formValue = fm.lastName.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}

	labelName = "label.errorRegAddress1";
	inputName = "input.errorRegAddress1";
	msg = "Please enter an address." + "\n";
	formValue = fm.address1.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}	

	labelName = "label.errorRegCity";
	inputName = "input.errorRegCity";
	msg = "Please enter a city." + "\n";
	formValue = fm.city.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
		continueCheckCity = false;
	}

	if (continueCheckCity == true){
		msg = "Please enter a valid city." + "\n";
		if (checkFormFieldCity(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}	
	}
	
	labelName = "label.errorRegState";
	inputName = "input.errorRegState";
	msg = "Please enter a state." + "\n";
	formValue = fm.state.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}

	labelName = "label.errorRegZipCode";
	inputName = "input.errorRegZipCode";
	msg = "Please enter a ZIP code." + "\n";
	formValue = fm.zipCode.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}else{
	
		msg = "Please enter a correct ZIP code." + "\n";
		if(checkZipCode(formValue, labelName, className, inputName, inputClassName) == false){
	
			errMsg += msg;
			rc = false;	
		}
	}

	msg = "Invalid phone. Please try again." + "\n";
		
	// Chcke none-char phone.
	var phoneCheck = true;
	
    if(( fm.phone_1[0].value != "") 
    	|| (fm.phone_1[1].value != "") 
    	|| (fm.phone_1[2].value != "") 
    	|| (fm.phone_1[3].value != "")){
    
    	var isIntCheck = true;
    	
   	    if( fm.phone_1[0].value != "") {
   	    	
			if(!isInteger(fm.phone_1[0].value)){
				isIntCheck = false;
			}
   	    }

   	    if( fm.phone_1[1].value != "") {
   	    	
			if(!isInteger(fm.phone_1[1].value)){
				isIntCheck = false;
			}
   	    }  
   	    
   	    if( fm.phone_1[2].value != "") {
   	    	
			if(!isInteger(fm.phone_1[2].value)){
				isIntCheck = false;
			}
   	    }

   	    if( fm.phone_1[3].value != "") {
   	    	
			if(!isInteger(fm.phone_1[3].value)){
				isIntCheck = false;
			}
   	    } 
   	    
   	   if(!isIntCheck) {
    		
    		$("label.errorRegPhone1").addClass(className);
    		$("input.errorRegPhone1").addClass(inputClassName);
    		errMsg += msg;
    		
    		rc = false;
    		phoneCheck = false;
  		
    	}else{
    	
    		$("label.errorRegPhone1").removeClass(className);
    		$("input.errorRegPhone1").removeClass(inputClassName);
    	}   
    	 
    }
    
    // Chcke for partial fill up phone.
    // Skip phone check if above already check and result with false which warning already set.
    if(phoneCheck){
	    if(( fm.phone_1[0].value == "") 
	    	|| (fm.phone_1[1].value == "") 
	    	|| (fm.phone_1[2].value == "") 
	    	|| (fm.phone_1[3].value != "")){
	    
	   	    if(( fm.phone_1[0].value == "") 
	    		|| (fm.phone_1[1].value == "") 
	    		|| (fm.phone_1[2].value == "")) {
	    		
	    		
	    		$("label.errorRegPhone1").addClass(className);
	    		$("input.errorRegPhone1").addClass(inputClassName);
	    		errMsg += msg;
	    		
	    		rc = false;
	  		
	    	}else{
	    	
	    		$("label.errorRegPhone1").removeClass(className);
	    		$("input.errorRegPhone1").removeClass(inputClassName);
	    	}        		
	    } else{
	    	
	    		$("label.errorRegPhone1").removeClass(className);
	    		$("input.errorRegPhone1").removeClass(inputClassName);
	    }
    }

	labelName = "label.errorRegEmail1";
	inputName = "input.errorRegEmail1";
	msg = "Please enter your email address." + "\n";
	formValue = fm.email1.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}

	msg = "Invalid email address. Please try again." + "\n";

	if (isEmpty(formValue) == false){	
		if (checkFormFieldEmail(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}
    
    if(rc == true)
    {
    	errMsg = "";
    }
    
    msg = "Please select a shipping method" + "\n";
	if(!isShipmodeChecked(fm)){
		
		errMsg += msg;
		rc = false;
	}
	
    if(rc == false){
		alert(errMsg);
	}else{
		
		fm.phone1.value = formatPhoneNo(fm.phone_1);
		fm.requireShipMethodCheck.value = "N";
		//alert("requireShipMethodCheck value="+fm.requireShipMethodCheck.value);
	}
	
	return rc;
}


function checkRegistrationSubmit(fm){

	
	var rc = true;
	var errMsg = "";
	var className = "error";
	var labelName = "";
	var inputName = "";
	var inputClassName = "input-error";
	var formValue = "";
	var continueCheckCity = true;

	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(fm)){
		return false;
	}
			
	labelName = "label.errorRegFirstName";
	inputName = "input.errorRegFirstName";
	msg = "Please enter a first name." + "\n";
	formValue = fm.firstName.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}

	labelName = "label.errorRegLastName";
	inputName = "input.errorRegLastName";
	msg = "Please enter a last name." + "\n";
	formValue = fm.lastName.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}	

	labelName = "label.errorRegAddress1";
	inputName = "input.errorRegAddress1";
	msg = "Please enter an address." + "\n";
	formValue = fm.address1.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}	

	labelName = "label.errorRegCity";
	inputName = "input.errorRegCity";
	msg = "Please enter a city." + "\n";
	formValue = fm.city.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
		continueCheckCity = false;
	}

	if (continueCheckCity == true){
		msg = "Please enter a valid city." + "\n";
		if (checkFormFieldCity(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}	
	}
	
	labelName = "label.errorRegState";
	inputName = "input.errorRegState";
	msg = "Please enter a state." + "\n";
	formValue = fm.state.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}

	labelName = "label.errorRegZipCode";
	inputName = "input.errorRegZipCode";
	msg = "Please enter a ZIP code." + "\n";
	formValue = fm.zipCode.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}
	
	msg = "Please enter a correct ZIP code." + "\n";
	if(checkZipCode(formValue, labelName, className, inputName, inputClassName) == false){

		errMsg += msg;
		rc = false;	
	}

	labelName = "label.errorRegEmail1";
	inputName = "input.errorRegEmail1";
	msg = "Please enter your email address." + "\n";
	formValue = fm.email1.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}

	msg = "Invalid email address. Please try again." + "\n";

	if (isEmpty(formValue) == false){	
		if (checkFormFieldEmail(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}

	labelName = "label.errorRegCemail1";
	inputName = "input.errorRegCemail1";
	msg = "Please enter your email address." + "\n";
	formValue = fm.cemail1.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}
	
	msg = "Invalid email address. Please try again." + "\n";

	if (isEmpty(formValue) == false){	
		if (checkFormFieldEmail(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}	
	
	msg = "Email address and confirm email address do not match. Please try again." + "\n";
	
	if (isEmpty(fm.email1.value) == false && isEmpty(fm.cemail1.value) == false){
		if (compareValues(fm.email1.value, fm.cemail1.value) == false){
			errMsg += msg;
			rc = false;
		}
	}

	msg = "Invalid phone. Please try again." + "\n";
		
	// Chcke none-char phone.
	var phoneCheck = true;
	
    if(( fm.phone_1[0].value != "") 
    	|| (fm.phone_1[1].value != "") 
    	|| (fm.phone_1[2].value != "") 
    	|| (fm.phone_1[3].value != "")){
    
    	var isIntCheck = true;
    	
   	    if( fm.phone_1[0].value != "") {
   	    	
			if(!isInteger(fm.phone_1[0].value)){
				isIntCheck = false;
			}
   	    }

   	    if( fm.phone_1[1].value != "") {
   	    	
			if(!isInteger(fm.phone_1[1].value)){
				isIntCheck = false;
			}
   	    }  
   	    
   	    if( fm.phone_1[2].value != "") {
   	    	
			if(!isInteger(fm.phone_1[2].value)){
				isIntCheck = false;
			}
   	    }

   	    if( fm.phone_1[3].value != "") {
   	    	
			if(!isInteger(fm.phone_1[3].value)){
				isIntCheck = false;
			}
   	    } 
   	    
   	   if(!isIntCheck) {
    		
    		$("label.errorRegPhone1").addClass(className);
    		$("input.errorRegPhone1").addClass(inputClassName);
    		errMsg += msg;
    		
    		rc = false;
    		phoneCheck = false;
  		
    	}else{
    	
    		$("label.errorRegPhone1").removeClass(className);
    		$("input.errorRegPhone1").removeClass(inputClassName);
    	}   
    	 
    }
    
    // Chcke for partial fill up phone.
    // Skip phone check if above already check and result with false which warning already set.
    if(phoneCheck){
	    if(( fm.phone_1[0].value == "") 
	    	|| (fm.phone_1[1].value == "") 
	    	|| (fm.phone_1[2].value == "") 
	    	|| (fm.phone_1[3].value != "")){
	    
	   	    if(( fm.phone_1[0].value == "") 
	    		|| (fm.phone_1[1].value == "") 
	    		|| (fm.phone_1[2].value == "")) {
	    		
	    		
	    		$("label.errorRegPhone1").addClass(className);
	    		$("input.errorRegPhone1").addClass(inputClassName);
	    		errMsg += msg;
	    		
	    		rc = false;
	  		
	    	}else{
	    	
	    		$("label.errorRegPhone1").removeClass(className);
	    		$("input.errorRegPhone1").removeClass(inputClassName);
	    	}        		
	    } else{
	    	
	    		$("label.errorRegPhone1").removeClass(className);
	    		$("input.errorRegPhone1").removeClass(inputClassName);
	    }
    }
	
		
    		
	msg = "" + "\n";
	
	// Handle create account option fields.
	// This is all or nothing for optional fields.
	// Check for match passwords
	// Check for password input value per business rule.
	if (isEmpty(fm.remail.value) == false || isEmpty(fm.logonPassword.value) == false || isEmpty(fm.logonPasswordVerify.value) == false
		|| isEmpty(fm.challengeQuestion.value) == false
		|| isEmpty(fm.challengeAnswer.value) == false
	){

		labelName = "label.errorRegRemail";
		inputName = "input.errorRegRemail";
		msg = "Please enter your email address." + "\n";
		formValue = fm.remail.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}

	if(fm.logonPassword != null){

		labelName = "label.errorRegLogonPassword";
		inputName = "input.errorRegLogonPassword";
		msg = "Please enter a password." + "\n";
		formValue = fm.logonPassword.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}

	if(fm.logonPasswordVerify != null){
	
		labelName = "label.errorRegLogonPasswordVerify";
		inputName = "input.errorRegLogonPasswordVerify";
		msg = "Please confirm your password." + "\n";
		formValue = fm.logonPasswordVerify.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}

	if(fm.challengeQuestion != null){
	
		labelName = "label.errorRegChallengeQuestion";
		inputName = "input.errorRegChallengeQuestion";
		msg = "Please select a challenge question." + "\n";
		formValue = fm.challengeQuestion.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}

	}
	
	if(fm.challengeAnswer != null){
	
		labelName = "label.errorRegChallengeAnswer";
		inputName = "input.errorRegChallengeAnswer";
		msg = "Please enter a challenge question answer." + "\n";
		formValue = fm.challengeAnswer.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}
			
	if(fm.logonPassword != null && fm.logonPasswordVerify !== null ){	
					
		msg = "Password and confirm password do not match. Please try again." + "\n";
	
		if (isEmpty(fm.logonPassword.value) == false && isEmpty(fm.logonPasswordVerify.value) == false){
			
			var samePasswords = true;
			
			if (compareValues(fm.logonPassword.value, fm.logonPasswordVerify.value) == false){
				errMsg += msg;
				samePasswords = false;
			}
			
			if (samePasswords){
				
				// Check number of alphnumic characters count of password.
				var maxCharsCount = 12;
				var minCharsCount = 8;
				
				if (!checkPassword(fm.logonPassword.value, maxCharsCount, minCharsCount)){
					msg = "Password must be alphanumeric and with minimum " + minCharsCount + " characters" + "\n";
					errMsg += msg;
					$("label.errorRegLogonPassword").addClass(className);
					$("label.errorRegLogonPasswordVerify").addClass(className);

					$("input.errorRegLogonPassword").addClass(inputClassName);
					$("input.errorRegLogonPasswordVerify").addClass(inputClassName);						
				
					rc = false;
				}
			
			}else{
			
				$("label.errorRegLogonPassword").addClass(className);
				$("label.errorRegLogonPasswordVerify").addClass(className);

				$("input.errorRegLogonPassword").addClass(inputClassName);
				$("input.errorRegLogonPasswordVerify").addClass(inputClassName);				
				rc = false;
				
			}
		}	
	}
		
	}else{
	
		// Remove error display.
		$("label.errorRegRemail").removeClass(className);
		$("label.errorRegLogonPassword").removeClass(className);
		$("label.errorRegLogonPasswordVerify").removeClass(className);
		$("label.errorRegChallengeQuestion").removeClass(className);
		$("label.errorRegChallengeAnswer").removeClass(className);
		
		$("input.errorRegRemail").removeClass(inputClassName);
		$("input.errorRegLogonPassword").removeClass(inputClassName);
		$("input.errorRegLogonPasswordVerify").removeClass(inputClassName);
		$("input.errorRegChallengeQuestion").removeClass(inputClassName);
		$("input.errorRegChallengeAnswer").removeClass(inputClassName);		
	
	}
		
		
	if(rc == false){
		alert(errMsg);
	}else{
		
		if (fm.logonId != null){
			// Assign email as logon Id for registration.
			fm.logonId.value = fm.email1.value;
		}
		
		// Assign phone value from phone fragments
		fm.phone1.value = formatPhoneNo(fm.phone_1);
		
		
		if(fm.demographicField1 != null){
		
			if(fm.demographicField1.checked == true){
				fm.demographicField1.value = 1;
			}
		}

		if(fm.demographicField2 != null){
		
			if(fm.demographicField2.checked == true){
				fm.demographicField2.value = 1;
			}
		}		
	}
	
	return rc;
}

function updateEmployeeId(fm){

	if(fm.tcpemployee.checked == false){
		fm.employeeId.value = "";
	}
	
}

function checkFindUsernameForm(fm){

	var rc = true;
	
	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(fm)){
		return false;
	}
	
	if(isEmpty(fm.emailAddress.value)){
	
	    $("label.errorEmailAddress").addClass("error");
    	$("input.errorEmailAddress").addClass("input-error");
    		
		alert("Please enter your email address");
		
		rc = false;
	}else{
	
		$("label.errorEmailAddress").removeClass("error");
    	$("input.errorEmailAddress").removeClass("input-error");
	}
	
	return rc;
}

function checkUserNameForm(fm){

	var rc = true;
	
	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(fm)){
		return false;
	}
		
	if(isEmpty(fm.logonId.value)){
	
	    $("label.errorLogonId").addClass("error");
    	$("input.errorLogonId").addClass("input-error");
    		
		alert("Please enter your User Name");
		
		rc = false;
	}else{
	
		$("label.errorLogonId").removeClass("error");
    	$("input.errorLogonId").removeClass("input-error");
	}
	
	return rc;

}

function checkResetPasswordForm(fm){

	var rc = true;

	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(fm)){
		return false;
	}
		
	if(isEmpty(fm.challengeAnswer.value)){
	
	    $("label.errorChallengeAnswer").addClass("error");
    	$("input.errorChallengeAnswer").addClass("input-error");
    		
		alert("Please enter a Challenge Answer");
		
		rc = false;
	}else{
	
		$("label.errorChallengeAnswer").removeClass("error");
    	$("input.errorChallengeAnswer").removeClass("input-error");
	}
	
	return rc;

}

function checkChangePasswordForm(fm){

	var rc = true;
	var errMsg = "";
	var className = "error";
	var labelName = "";
	var inputName = "";
	var inputClassName = "input-error";
	var formValue = "";

	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(fm)){
		return false;
	}
	
	if(fm.logonPasswordOld != null){

		labelName = "label.errorRegLogonPasswordOld";
		inputName = "input.errorRegLogonPasswordOld";
		msg = "Please enter an old password." + "\n";
		formValue = fm.logonPasswordOld.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}
	
	if(fm.logonPassword != null){

		labelName = "label.errorRegLogonPassword";
		inputName = "input.errorRegLogonPassword";
		msg = "Please enter a new password." + "\n";
		formValue = fm.logonPassword.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}

	if(fm.logonPasswordVerify != null){
	
		labelName = "label.errorRegLogonPasswordVerify";
		inputName = "input.errorRegLogonPasswordVerify";
		msg = "Please confirm your password." + "\n";
		formValue = fm.logonPasswordVerify.value;
		
		if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}
	
	if(fm.logonPassword != null && fm.logonPasswordVerify !== null ){	
					
		msg = "Password and confirm password do not match. Please try again." + "\n";
	
		if (isEmpty(fm.logonPassword.value) == false && isEmpty(fm.logonPasswordVerify.value) == false){
			
			var samePasswords = true;
			
			if (compareValues(fm.logonPassword.value, fm.logonPasswordVerify.value) == false){
				errMsg += msg;
				samePasswords = false;
			}
			
			if (samePasswords){
				
				// Check number of alphnumic characters count of password.
				var maxCharsCount = 12;
				var minCharsCount = 8;
				
				if (!checkPassword(fm.logonPassword.value, maxCharsCount, minCharsCount)){
					msg = "Password must be alphanumeric and with minimum " + minCharsCount + " characters" + "\n";
					errMsg += msg;
					$("label.errorRegLogonPassword").addClass(className);
					$("label.errorRegLogonPasswordVerify").addClass(className);

					$("input.errorRegLogonPassword").addClass(inputClassName);
					$("input.errorRegLogonPasswordVerify").addClass(inputClassName);						
				
					rc = false;
				}
			
			}else{
			
				$("label.errorRegLogonPassword").addClass(className);
				$("label.errorRegLogonPasswordVerify").addClass(className);

				$("input.errorRegLogonPassword").addClass(inputClassName);
				$("input.errorRegLogonPasswordVerify").addClass(inputClassName);				
				rc = false;
				
			}
		}	
	}	

	if(rc == false){
		alert(errMsg);
	}
	return rc;
}

function checkFormInputValue(fm)
{
	var rc = true;
	var className = "error";
	var inputClassName = "input-error";
	
	var errMsg = "Please enter valid character";
	var elem = fm.elements;
	
	
	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].type == "text"){
    		
    		var val = elem[i].value;
	    			    		
			if(val != ""){
			
				if(!isValidCharStr(val)){
					
					// Base on current input type text element, look up it class name and add error class into it.
					// Since the lable name is same as input name we can enable it.
					$("label."+elem[i].className).addClass(className);
	    			$("input."+elem[i].className).addClass(inputClassName);
	    			
	    			rc = false;
	    			
    			}else{
    			
    				// It seme like we can not use the same technique as above to remove inner class element
    				// except located the class element we need and then take out the other.
 					
    				var index   = elem[i].className.indexOf(inputClassName);
       				var errClassName = elem[i].className;
       				errClassName = errClassName.substring(0, index);
       				
					$("label."+errClassName).removeClass(className);
	    			$("input."+errClassName).removeClass(inputClassName);    			
    			}
			}
		}
	}
	
	if(!rc){
		alert(errMsg);
	}
	return rc;
}

function checkPassword(pwd, maxLength, minLength){

	var rc = true;
	
	if ((pwd.length > maxLength)|| (pwd.length < minLength) || (pwd == null)) {
	
		rc = false;
	}

	if (!alphaNumericCheck(pwd)){
		rc = false;
	}
	
	return rc;
}

function alphaNumericCheck(val){

	var rc = true;
	
	// No space.
	var regex=/(\s)/; //^[a-zA-z]+$/
	
	if(regex.test(val)){
		rc = false;
	}
	
	// Can not be only number.
	regex=/^[0-9]+$/;

	if(regex.test(val)){
		rc = false;
	}	

	// Can not be only characters.
	regex=/^[a-zA-Z]+$/;

	if(regex.test(val)){
		rc = false;
	}	
	 
	return rc;
}

function checkZipCode(f, labelName, labelClassName, inputName, inputClassName){
	
	var rc = true;
	
	if(isZipCode(f) == false){

		$(labelName).addClass(labelClassName);
		$(inputName).addClass(inputClassName);		
		rc = false;
		
	}else{
		$(labelName).removeClass(labelClassName);
		$(inputName).removeClass(inputClassName);		
	}
	
	return rc;
}

function checkFormFieldEmail(f, labelName, labelClassName, inputName, inputClassName){

	var rc = true;
	
	if (isEMailAddr(f) == false){

		$(labelName).addClass(labelClassName);
		$(inputName).addClass(inputClassName);		
		rc = false;
		
	}else{
		$(labelName).removeClass(labelClassName);
		$(inputName).removeClass(inputClassName);		
	}
	
	return rc;
}

function checkFormFieldCity(f, labelName, labelClassName, inputName, inputClassName){

	var rc = true;
	
	if (isCity(f) == false){

		$(labelName).addClass(labelClassName);
		$(inputName).addClass(inputClassName);		
		rc = false;
		
	}else{
		$(labelName).removeClass(labelClassName);
		$(inputName).removeClass(inputClassName);		
	}
	
	return rc;
}

function compareValues(a, b){

	var rc = false;
	
	if (a == b){
		rc = true;
	}
	
	return rc;
}

function checkFormField(f, labelName, labelClassName, inputName, inputClassName){

	var rc = true;
	
	if (isEmpty(f)){

		$(labelName).addClass(labelClassName);
		$(inputName).addClass(inputClassName);	
		rc = false;
		
	}else{
		$(labelName).removeClass(labelClassName);
		$(inputName).removeClass(inputClassName);		
	}
	
	return rc;
}

function updateRegRemail(fm){

	var valBemail = fm.email1.value;
	var valEmail = fm.remail.value;
	
	// Update email value as soon as user click on it.
	// Condition is if and only if the email field is blank.
	if(isEmpty(valBemail) == false){
	
		if(isEMailAddr(valBemail)){		
			if(isEmpty(valEmail)){
				fm.remail.value = valBemail
				fm.remail.disabled = true;
			}
		}
	}
}


function checkEmailRegistration(fm){

	var rc = true;
	var errMsg = "";
	var className = "error";
	var labelName = "";
	var inputName = "";
	var inputClassName = "input-error";
	var formValue = "";

	// This logic add on as per business required to check for special character.
	// Instead of add validate to each form, call the function and let it does all the checking and return first if not satified.
	if (!checkFormInputValue(fm)){
		return false;
	}

	labelName = "label.errorRegEmail1";
	inputName = "input.errorRegEmail1";
	msg = "Please enter an e-mail address." + "\n";
	formValue = fm.emailaddr.value;
	
	if (checkFormField(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}

	msg = "Please enter a valid email address." + "\n";

	if (isEmpty(formValue) == false){	
		if (checkFormFieldEmail(formValue, labelName, className, inputName, inputClassName) == false){
			errMsg += msg;
			rc = false;
		}
	}

	msg = "Please make sure the email addresses match." + "\n";

	if(fm.emailaddr.value != fm.emailaddr2.value){
		errMsg += msg;
		
		$("label.errorRegEmail1").addClass(className);
    	$("input.errorRegEmail1").addClass(inputClassName);
		$("label.errorRegCemail1").addClass(className);
    	$("input.errorRegCemail1").addClass(inputClassName);    	
		rc = false;
	}
	
	labelName = "label.errorRegCity";
	inputName = "input.errorRegCity";
	formValue = fm.city.value;

	msg = "Please enter a valid city." + "\n";
	if (checkFormFieldCity(formValue, labelName, className, inputName, inputClassName) == false){
		errMsg += msg;
		rc = false;
	}
	
	msg = "Invalid phone. Please try again." + "\n";
		
	// Chcke none-char phone.
	var phoneCheck = true;
	
    if(( fm.phone_1[0].value != "") 
    	|| (fm.phone_1[1].value != "") 
    	|| (fm.phone_1[2].value != "") 
    	|| (fm.phone_1[3].value != "")){
    
    	var isIntCheck = true;
    	
   	    if( fm.phone_1[0].value != "") {
   	    	
			if(!isInteger(fm.phone_1[0].value)){
				isIntCheck = false;
			}
   	    }

   	    if( fm.phone_1[1].value != "") {
   	    	
			if(!isInteger(fm.phone_1[1].value)){
				isIntCheck = false;
			}
   	    }  
   	    
   	    if( fm.phone_1[2].value != "") {
   	    	
			if(!isInteger(fm.phone_1[2].value)){
				isIntCheck = false;
			}
   	    }

   	    if( fm.phone_1[3].value != "") {
   	    	
			if(!isInteger(fm.phone_1[3].value)){
				isIntCheck = false;
			}
   	    } 
   	    
   	   if(!isIntCheck) {
    		
    		$("label.errorRegPhone1").addClass(className);
    		$("input.errorRegPhone1").addClass(inputClassName);
    		errMsg += msg;
    		
    		rc = false;
    		phoneCheck = false;
  		
    	}else{
    	
    		$("label.errorRegPhone1").removeClass(className);
    		$("input.errorRegPhone1").removeClass(inputClassName);
    	}   
    	 
    }else{
    
    	$("label.errorRegPhone1").removeClass(className);
    	$("input.errorRegPhone1").removeClass(inputClassName);
    
    }
    
    // Chcke for partial fill up phone.
    // Skip phone check if above already check and result with false which warning already set.
    if(phoneCheck){
	    if(( fm.phone_1[0].value != "") 
	    	|| (fm.phone_1[1].value != "") 
	    	|| (fm.phone_1[2].value != "") 
	    	|| (fm.phone_1[3].value != "")){
	    
	   	    if(( fm.phone_1[0].value == "") 
	    		|| (fm.phone_1[1].value == "") 
	    		|| (fm.phone_1[2].value == "")) {
	    		
	    		
	    		$("label.errorRegPhone1").addClass(className);
	    		$("input.errorRegPhone1").addClass(inputClassName);
	    		errMsg += msg;
	    		
	    		rc = false;
	  		
	    	}else{
	    	
	    		$("label.errorRegPhone1").removeClass(className);
	    		$("input.errorRegPhone1").removeClass(inputClassName);
	    	}        		
	    } else{
	    	
	    		$("label.errorRegPhone1").removeClass(className);
	    		$("input.errorRegPhone1").removeClass(inputClassName);
	    }
    }    
    	
	if(rc == false){
	
		alert(errMsg);
		
	}else{
	
		phone1 = fm.phone_1[0].value + "." + 
	
		fm.phone_1[1].value + "." + 
	
	    fm.phone_1[2].value + "." + 
	
	    fm.phone_1[3].value;   
		
		fm.phone1.value = phone1; 
		
		fm.emailaddr.value=fm.emailaddr.value.toLowerCase();
		fm.emailaddr2.value=fm.emailaddr2.value.toLowerCase();
	}
	
	return rc;

}

function isEmpty(s){
	
	var rc = false;
	
	s = trimAll(s);
	
	if ((s.length == 0) || (s == null)) {
		rc = true;
	}
   
	return rc;
}

function trimAll(str){

	while (str.substring(0,1) == ' '){
		str = str.substring(1, str.length);
	}
	while (str.substring(str.length-1, str.length) == ' '){
		str = str.substring(0,str.length-1);
	}
	return str;
}

function isEMailAddr(str) {
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}

/**
This function formats the 4 phone fields into the following format XXX.XXX.XXX.XXX
A string is returned containing the formatted number.
*/
function formatPhoneNo(phoneArray)
{
	var phoneNo = "";
	phoneNo = phoneArray[0].value + "." + 
	          phoneArray[1].value + "." + 
	          phoneArray[2].value + "." +
	          phoneArray[3].value;      
	          
	if(phoneNo == "..."){
		phoneNo = "";
	}

	return phoneNo;
}

/**
This function selects the appropriate option value.  The parameters are the field, 
a counter equal to the number of options, and the value to be selected.
*/
function selectOption(x, count, value) 
{
  if ((value != null) && (value!= "")) 
  {
      for (idx=0; idx<count; idx++) 
      {
      	if (x.options[idx].value == value)
      	  x.options[idx].selected = true;
      }
  }
}

/**
This function parses the following format XXX.XXX.XXX.XXX into 4 phone fields.
The parameters are an array of the 4 phone fields and the formatted phone number.
*/
function parsePhoneNo(phoneArray, phoneNo) 
{
  var index = 0;
  var value1 = "";
  var value2 = "";
  var value3 = "";
  var value4 = "";
  
  if (phoneNo!=null && phoneNo!="" && phoneNo!="...")
  {
       index   = phoneNo.indexOf(".");
       value1  = phoneNo.substring(0, index);
       phoneNo = phoneNo.substring(index+1, phoneNo.length);

       index   = phoneNo.indexOf(".");
       value2  = phoneNo.substring(0, index);
       phoneNo = phoneNo.substring(index+1, phoneNo.length);      

       index    = phoneNo.indexOf(".");
       value3   = phoneNo.substring(0, index);
       phoneNo  = phoneNo.substring(index+1, phoneNo.length);
     
       value4 = phoneNo;

       phoneArray[0].value = value1;
       phoneArray[1].value = value2;
       phoneArray[2].value = value3;
       phoneArray[3].value = value4;
  }
}

function isZipCode(zip) 
{

	// Check for correct USA nnnnn-nnnn zip code format

	var validateZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!validateZip.test(zip)) {
          return false;
     }

	return true;
}

/**
This function checks the radio button and selects the appropriate value.  The parameters 
are the field, and the value to be selected.
*/
function selectCheckbox (x, value) 
{
  if (value != null) 
  {
    x.checked = true;
  } 
  else 
  {
    x.checked = false;
  }
}

/**
This function checks the radio button and selects the appropriate value.  The parameters 
are the field, a counter equal to the number of options, and the value to be selected.
*/
function selectRadio (x, count, value) 
{
  if ((value!=null) && (value!="")) 
  {
    for (i=0; i<count; i++) 
    {
      if (x[i].value == value)
    	  x[i].checked = true;
    }
  }
} 

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function isInteger( iValue ) {

  var iValidate  = new RegExp(/(^-?\d\d*$)/);

  return iValidate.test(iValue);
}

function isCity( iValue ) {
  
  // Search for:
  // All char A-Z
  // . sign
  // Space, tab and return
  // ' sign
  // - sign
  //Lax - 10/2/08 -Commented City validation check for numbers as city field also used for APO# input.
  //var iValidate = new RegExp(/^[a-z.\'\-\s]*$/i);
  
  //return iValidate.test(iValue);
  return true;
}

function isValidCharStr( iValue ) {
  
  // Search for:
  // All char A-Z
  // @ sign
  // . sign
  // Space, tab and return
  // # sign
  // ' sign
  // - sign
  // _ sign
    
  var iValidate = new RegExp(/^[a-z@.#_\'\-\s\d]*$/i);
  
  return iValidate.test(iValue);
}

function autoTabOver(element, nextElementField) {
    if (element.value.length == element.maxLength && nextElementField != null) {
        element.form.elements[nextElementField].focus();
    }
}

function trimSpace(arg)
{
	//alert("In trimSpace arg value before trim="+arg );
	var trimmedArg ="";
	if (arg.indexOf(' ') !=-1)
	{
		var temp = new Array();
		temp = arg.split(' ');
		for(var i=0;i<temp.length;i++)
		{
			trimmedArg = trimmedArg + temp[i];
		}
	}
	else
	{
		trimmedArg= arg;
	}
	//alert("In trimSpace arg value after trim="+trimmedArg );
	return trimmedArg;
}

function trimPrice(dollarValue){
    var decimalPos = dollarValue.indexOf(".");
    if (dollarValue.substr(decimalPos, dollarValue.length - decimalPos - 1).length > 2) {
        dollarValue = dollarValue.substr(0, decimalPos + 3);
    }
    return dollarValue.replace("$", "");
}

// Use for debug.
function debug(str){
	//alert(str);
}