var STREETADDRESS = "Street Address";
var ENTER_ZIP_POSTAL_CODE = "Enter ZIP / Postal Code";
var ZIP_POSTAL_CODE = "ZIP / Postal Code";
var CITY = "City";
var LASTNAME = "Agent's Last Name";

if (window.addEventListener) { //DOM method for binding an event
	//window.addEventListener("load", 	checkForMFOrAnnuities, false);
}
else if (window.attachEvent) { //IE exclusive method for binding an event
	//window.attachEvent("onload", 	checkForMFOrAnnuities);
}

function wasEnterKeyPressed(e) {
	var characterCode;

	//if (e && e.which) { //if which property of event object is supported (NN4)
	if (! window.event) {
		//e = e;
		//characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
		return true;
	} else {
		return false;
	}
}

function submitEnterOnSearchRequestFormLoc(e) {
	var wasEnterKey = wasEnterKeyPressed(e);
	if (wasEnterKey) {
		if(submitClickedOnCityStateForm()) {
			document.searchRequestFormLoc.submit();
		}
	}
}

function submitEnterOnSearchRequestFormName(e) {
	var wasEnterKey = wasEnterKeyPressed(e);
	if (wasEnterKey) {
		if(submitClickedOnNameForm()) {
			document.searchRequestFormName.submit();
		}
	}
}

function submitEnterOnSearchRequestFormLocResults(e) {
	var wasEnterKey = wasEnterKeyPressed(e);
	if (wasEnterKey) {
		if(submitClickedOnZipForm()) {
			document.searchRequestFormLoc.submit();
		}
	}
}

function submitEnterOnSearchRequestFormLoc2Results(e) {
	var wasEnterKey = wasEnterKeyPressed(e);
	if (wasEnterKey) {
		if(submitClickedOnCityStateForm()) {
			document.searchRequestFormLoc2.submit();
		}
	}
}

function submitClickedOnCityStateForm() {

	var whichZip = 1;
	var zip = "";
	
	var zipCodeObj
	//check zip code values...search criteria page has 1 zipCodeText, search results has 2 zipCodeText fields and we only care about the 2nd one
	//since the 2nd form calls submitClickedOnCityStateForm
	var zips=document.getElementsByName('zipCodeText');
	if (zips != null) {
		if (zips.length > 0) {
			if (zips.length == 1) {
				zipCodeObj = zips.item(0);
			} else {
				zipCodeObj = zips.item(1);
			}
			zip = zipCodeObj.value;
		}
	}
	
	//var zipCodeObj = myfield.zipCodeText;
    //if (zipCodeObj != null && zipCodeObj.value != ENTER_ZIP_POSTAL_CODE) {
    //	zip = zipCodeObj.value;
    //}
    
    zipCodeObj = document.getElementById("zipCodeText2");
	if (zipCodeObj != null && zipCodeObj.value != ZIP_POSTAL_CODE && zipCodeObj.value != '') {
    	zip = zipCodeObj.value;
    	whichZip = 2;
    }
                
    var street = "";
    var streetObj = document.getElementById("streetText");
    if (streetObj != null && streetObj.value != STREETADDRESS && streetObj.value != '') {
    	street = streetObj.value;
    }

	var city = "";
	var cityObj = document.getElementById("cityText");
	if (cityObj != null && cityObj.value != CITY && cityObj.value != '') {
		city = cityObj.value;
	}
	var stateProvince = "";
	var stateProvinceObj = document.getElementById("stateProvince");
	if (stateProvinceObj != null) {
		stateProvince = stateProvinceObj.value;
	}
	if (validateZipCityStateInput(zip, whichZip, street, city, stateProvince)) {
		return true;
	} else {
		return false;
	}
}

function submitClickedOnZipForm() {
	var zipCode = "";
	var zipCodeObj = document.getElementById("zipCodeText");
	
	var bank = document.getElementById("bank").checked;
	var mfunds = document.getElementById("mfunds").checked;
	var varlife = document.getElementById("varlife").checked;
	var language = document.getElementById("language").value;
	
	if (zipCodeObj != null) {
		zipCode = zipCodeObj.value;
	}
	
	var zipCode1 = zipCodeObj.value;
	var zipCode2 = document.getElementById("zipCodeText2").value;
	var state =  document.getElementById("stateProvince").value;
	
	var passProducts = true;
	
	var isStateCA = false;
	var isZip1CA = false;
	var isZip2CA = false;
	
	if( (state != "") && isCanadianState(state)) {
		isStateCA = true;
	}
	if(  ( (zipCode1 != "ZIP / Postal Code") || (zipCode1 != ""))  && isCanadianZip(zipCode1)){
		isZip1CA = true;
	}
	if( ( (zipCode2 != "ZIP / Postal Code") || (zipCode2 != ""))  && isCanadianZip(zipCode2)){
		isZip2CA = true;
	}
	
	if(isStateCA || isZip1CA || isZip2CA){
		passProducts = false;
	}
	
	if(passProducts){
		if(bank){document.getElementById("zipBank").value = "true";}
		if(varlife){document.getElementById("zipVarlife").value = "true";}
	}
	if(mfunds){document.getElementById("zipMfunds").value = "true";}
	if(language != ""){document.getElementById("zipLanguage").value = language;}	

	if (validateZipInput(zipCode)) {
		return true;
	} 
	else {
		return false;
	}
}


function isCanadianZip(zip){
	return zip.match("([a-zA-Z][0-9]){3}");
}

function isCanadianState(state){
	if( (state.toLowerCase() == "ab") || (state.toLowerCase() == "on") || (state.toLowerCase() == "nb")){
		return true;
	}
	return false;
}

function submitClickedOnNameForm() {
	if (validateNameInput(document.getElementById("lastName").value, document.getElementById("stateProvinceForName").value)) {
		return true;
	} else {
		return false;
	}
}


//validation
function validateZipInput(zipInput) {
	document.getElementById("errorFoundOnZip").style.display = "none";
	document.getElementById("zipErrorOnZip").style.display = "none";
	document.getElementById("errorSearchCriteriaOnZip").style.display = "none";
	document.getElementById("errorNoAgentsFoundOnZip").style.display = "none";
	if (zipInput.length > 0) {
		var zipCode = cleanUpZipCode(zipInput);
		var isZipValid = validateZipCode(zipCode);
		if (isZipValid) {
			return true;
		} else {
			document.getElementById("errorFoundOnZip").style.display = "block";
			document.getElementById("zipErrorOnZip").style.display = "block";
			return false;
		}
	} else {
		//document.getElementById("errorSearchCriteriaOnZip").style.display = "block";
		document.getElementById("errorFoundOnZip").style.display = "block";
		document.getElementById("zipErrorOnZip").style.display = "block";
		return false;
	}
}

function validateZipCityStateInput(zipInput, whichZip, streetInput, cityInput, stateInput) {

	if (document.getElementById("mainLocError-Zip") != null) {
    	document.getElementById("mainLocError-Zip").style.display = "none";
    }
    document.getElementById("errorFoundOnCityState").style.display = "none";
    document.getElementById("zipErrorOnCityState").style.display = "none";
    document.getElementById("streetErrorOnCityState").style.display = "none";
    document.getElementById("poBoxErrorOnCityState").style.display = "none";
    document.getElementById("cityErrorOnCityState").style.display = "none";
    document.getElementById("stateErrorOnCityState").style.display = "none";
    document.getElementById("zipErrorOnStreetSearch").style.display = "none";
    document.getElementById("errorSearchCriteriaOnCityState").style.display = "none";
    document.getElementById("errorNoAgentsFoundOnCityState").style.display = "none";
                
    var zipCode = cleanUpZipCode(zipInput);
    var isZipValid = validateZipCode(zipCode);
    var isStreetValid = validateStreet(streetInput);
    var isPOBox = validateForPOBox(streetInput);
    var isCityValid = validateCity(cityInput);
    var isStateValid = validateState(stateInput);
    // if a zip code is found...
    if ((zipInput.length > 0) && (ENTER_ZIP_POSTAL_CODE != zipInput) && (ZIP_POSTAL_CODE != zipInput)) {
    	// if a street is found... return true
        if (streetInput.length > 0 && (STREETADDRESS != streetInput)){
        	if (! isStreetValid) {
            	document.getElementById("streetErrorOnCityState").style.display = "block";
            }
            if (isPOBox) {
            	document.getElementById("poBoxErrorOnCityState").style.display = "block";
            }
            if (! isZipValid) {
            	document.getElementById("zipErrorOnStreetSearch").style.display = "block";
            }
            if (! isStreetValid || isPOBox || ! isZipValid) {
            	if (document.getElementById("mainLocError-Zip") != null) {
                	document.getElementById("mainLocError-Zip").style.display = "block";
                }
                document.getElementById("errorFoundOnCityState").style.display = "block";
                return false;
            } else {
                return true;
            }
        } else if (whichZip == 1) {  //from the top zip code?
        	if (isZipValid) {
        		return true;
        	} else {
	        	if (document.getElementById("mainLocError-Zip") != null) {
    	        	document.getElementById("mainLocError-Zip").style.display = "block";
        	    }
                                                
            	document.getElementById("errorFoundOnCityState").style.display = "block";
	            document.getElementById("zipErrorOnCityState").style.display = "block";

    	        return false;
        	}
        } else {  //from zip code search on bottom
        	//display error on street since it hasn't been entered
	        if (document.getElementById("mainLocError-Zip") != null) {
            	document.getElementById("mainLocError-Zip").style.display = "block";
       	    }
        	    
       	    document.getElementById("errorFoundOnCityState").style.display = "block";
       	    document.getElementById("streetErrorOnCityState").style.display = "block";
       	    
        	if (! isZipValid) {
        	    document.getElementById("zipErrorOnStreetSearch").style.display = "block";
        	}
        	return false;
       }
    } else if (streetInput.length > 0 && (STREETADDRESS != streetInput)){
        	if (! isStreetValid) {
            	document.getElementById("streetErrorOnCityState").style.display = "block";
            }
            if (isPOBox) {
            	document.getElementById("poBoxErrorOnCityState").style.display = "block";
            }
            if (! isZipValid) {
            	document.getElementById("zipErrorOnStreetSearch").style.display = "block";
            }
            if (! isStreetValid || isPOBox || ! isZipValid) {
            	if (document.getElementById("mainLocError-Zip") != null) {
                	document.getElementById("mainLocError-Zip").style.display = "block";
                }
                document.getElementById("errorFoundOnCityState").style.display = "block";
                return false;
            } else {
                return true;
            }
	} else if ((cityInput.length > 0 && CITY != cityInput) || stateInput != "") {
        	if (! isCityValid) {
            	document.getElementById("cityErrorOnCityState").style.display = "block";
            }
            if (! isStateValid) {
            	document.getElementById("stateErrorOnCityState").style.display = "block";
            }
            if (! isCityValid || ! isStateValid) {
            	if (document.getElementById("mainLocError-Zip") != null) {
                	document.getElementById("mainLocError-Zip").style.display = "block";
                }
                document.getElementById("errorFoundOnCityState").style.display = "block";
                return false;
            } else {
                return true;
            }
   } else {
		if (document.getElementById("mainLocError-Zip") != null) {
			document.getElementById("mainLocError-Zip").style.display = "block";
		}
		document.getElementById("errorFoundOnCityState").style.display = "block";
		document.getElementById("zipErrorOnCityState").style.display = "block";

        return false;
   }
}


function validateStreet(streetInput) {
	//valid if 1 to 30 alphabetic characters including single quote, dash, space, pound, parens, ampersand and period
    var isStreetValid = false;
                                
    if (streetInput != null) {
    	if (streetInput.length >= 1 && streetInput.length <= 30) {
        	var streetValid = streetInput.match("[a-zA-Z0-9., \043\047\050\051\057\046\-]{" + streetInput.length + "}");
            if (streetValid != null) { //match found
            	isStreetValid = true;
            }
        }
	}
    return isStreetValid;
}
function validateForPOBox(streetInput) {
	//valid if 1 to 30 alphabetic characters including single quote, dash, space and period
    var poBox = false;
                                
    if (streetInput != null) {
    	if (streetInput.length >= 1 && streetInput.length <= 30) {
        	//var isPOBox = streetInput.match(".*(box|Box|BOX|bOx|BoX|boX|BOx|bOX|bx|bo) *[0-9].+$");
        	var isPOBox = streetInput.match(".*([B|b][O|o|0][X|x]) *[0-9].*$");
            if (isPOBox != null) { //match found
            	poBox = true;
            }
        }
    }
	return poBox;
}

function validateNameInput(nameInput, stateInput) {
	if (document.getElementById("mainLocError-Name") != null) {
		document.getElementById("mainLocError-Name").style.display = "none";
	}
	document.getElementById("nameErrorOnName").style.display = "none";
	document.getElementById("stateErrorOnName").style.display = "none";
	document.getElementById("errorFoundOnName").style.display = "none";
	document.getElementById("errorSearchCriteriaOnName").style.display = "none";
	document.getElementById("errorNoAgentsFoundOnName").style.display = "none";
	//validate name/state input
	if ((nameInput.length > 0 && "Agent's Last Name" != nameInput) || stateInput != "") {
		var isNameValid = validateLastName(nameInput);
		var isStateValid = validateState(stateInput);
		if (! isNameValid || "Agent's Last Name" == nameInput) {
			document.getElementById("nameErrorOnName").style.display = "block";
		}
		if (! isStateValid) {
			document.getElementById("stateErrorOnName").style.display = "block";
		}
		if (! isNameValid || "Agent's Last Name" == nameInput || ! isStateValid) {
			document.getElementById("errorFoundOnName").style.display = "block";
			if (document.getElementById("mainLocError-Name") != null) {
				document.getElementById("mainLocError-Name").style.display = "block";
			}
			return false;
		} else {
			return true;
		}
	} else {
		if (document.getElementById("mainLocError-Name") != null) {
			document.getElementById("mainLocError-Name").style.display = "block";
		}
		document.getElementById("errorFoundOnName").style.display = "block";
		document.getElementById("nameErrorOnName").style.display = "block";
		document.getElementById("stateErrorOnName").style.display = "block";

		return false;
	}
}

function cleanUpZipCode(zipInput) {
	var zipCode = zipInput;
		
	//remove dash and all subsequent text
	var dashIndex = zipInput.indexOf("-");
	if (dashIndex >= 0) {
		zipCode = zipInput.substring(0, dashIndex);
	}
		
	//remove space if there
	var spaceIndex = zipCode.indexOf(" ");
	if (spaceIndex >= 0) {
		var tempZip = zipCode;
		zipCode = tempZip.substring(0,spaceIndex);
		zipCode = zipCode + tempZip.substring(spaceIndex+1);
	}
	return zipCode;
}

function validateZipCode(zipInput) {
	//valid if 5 characters all numeric or 6 characters alphanumeric
	var isZipValid = false;
	var zipValid = null;
		
	if (zipInput != null) {
		if (zipInput.length == 5) {
			zipValid = zipInput.match("[0-9]{5}");
		}
		if (zipInput.length == 6) {
			zipValid = zipInput.match("([a-zA-Z][0-9]){3}");
		}
		if (zipValid != null) { //match found
			isZipValid = true;
		}
	}
	return isZipValid;
}

function validateCity(cityInput) {
	//valid if 1 to 30 alphabetic characters including single quote, dash, space and period
	var isCityValid = false;
		
	if (cityInput != null) {
		if (cityInput.length >= 1 && cityInput.length <= 30) {
			//"\055" is octal for a dash
			var cityValid = cityInput.match("[a-zA-Z' .\055]{" + cityInput.length + "}");
			if (cityValid != null) { //match found
				isCityValid = true;
			}
		}
	}
	return isCityValid;
}

function validateState(stateInput) {
	//valid if 2 upper case alphabetic characters
	var isStateValid = false;
		
	if (stateInput != null) {
		var stateValid = stateInput.match("[A-Z]{2}");
		if (stateValid != null) { //match found 
			isStateValid = true;
		}
	}
	return isStateValid;
}

function validateLastName(lastNameInput) {
	//valid if 1 to 30 alphabetic characters including single quote, space, period, comma and dash
	var isLastNameValid = false;
	
	if (lastNameInput != null) {
		if (lastNameInput.length >= 1 && lastNameInput.length <= 30) {
			//"\055" is octal for a dash
			var lastNameValid = lastNameInput.match("[a-zA-Z' .,\055]{" + lastNameInput.length + "}");
			if (lastNameValid != null) { //match found
				isLastNameValid = true;
			}
		}
	}
	return isLastNameValid;
}
function resetShowDialog(id, country, destAddress, city, state, zip, stateCode, agentCode,latitude, longitude, root, ddUrl) {
	var dialogbox = document.getElementById("directionsIFrame");
	var lang = "";					 				
	if (dialogbox != null) {				
		var url = document.location.host; 
		//var url = "  convertlanguage"; 
		if(url.indexOf("convertlanguage") >= 0){
			lang = "&language=spanish";					 				
		}
		dialogbox.src = getOnline2Path()+""+ ddUrl + "?origAddress=&origCity=&origStateProvince=&origPostalCode=&destAddress=" + destAddress + "&destCity=" + city + "&destStateProvince=" + state + "&destPostalCode=" + zip + "&latitude=" + latitude + "&longitude=" + longitude + lang; //must be a relative path
	}
	showDialog(id);
}
function showEmailMeDialog(stateCode, agentCode) {	
	var elmt = dijit.byId("emailMe");
	if (elmt != null) {
		//var href = "http://wp95dc02.opr.test.statefarm.org:50420/b2c/AgentMicrositePortlets_Photo/servlet/EmailMe?st=" + stateCode + "&ofc=" + agentCode + "&modalID=emailMe";
		var href = "/b2c/AgentMicrositePortlets_Photo/servlet/EmailMe?st=" + stateCode + "&ofc=" + agentCode + "&modalID=emailMe";
		elmt.setHref(href);
		elmt.refresh();
	}
	showDialog("emailMe");
}

//allows us to enable/disable the product checkboxes and the images associated with the them
function checkBoxDisable(id, state, keepChecked){ 
  document.getElementById(id).disabled=state;
  if (!keepChecked) {document.getElementById(id).checked=false;}
  $(document).ready(function(){
		// check for what is/isn't already checked and match it on the fake ones
		$("input:checkbox").each( function() {
		  (this.checked && this.disabled) ? $("#fake"+this.id).addClass('fakedisabledchecked') : $("#fake"+this.id).removeClass('fakedisabledchecked');
			(this.checked && !this.disabled) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
			(!this.checked && this.disabled) ? $("#fake"+this.id).addClass('fakedisabled') : $("#fake"+this.id).removeClass('fakedisabled');
		});
	});
 }
 
 //allows us enable/disable the language radio buttons and the images associated with them
 function radioDisable(state,keepChecked) {
    var r=document.getElementsByName('language');
		for (var i=0;i<r.length;i++){
			 if (!keepChecked) {r.item(i).checked=false;}
		   r.item(i).disabled=state;
		}		    	

	$(document).ready(function(){
	// check for what is/isn't already selected and match it on the fake ones
		$("input:radio").each( function() {
				(this.checked && this.disabled) ? $("#fake"+this.id).addClass('fakeoptdisabledchecked') : $("#fake"+this.id).removeClass('fakeoptdisabledchecked');
				(this.checked && !this.disabled) ? $("#fake"+this.id).addClass('fakeoptchecked') : $("#fake"+this.id).removeClass('fakeoptchecked');
				(!this.checked && this.disabled) ? $("#fake"+this.id).addClass('fakeoptdisabled') : $("#fake"+this.id).removeClass('fakeoptdisabled');
		});
	});	
}



function topZipFocus(country) {
	clearTopZip();
	scrapeStreetAddressSearchSection(country);
	scrapeCityStateSearchSection(country);
}

function topZipChg(country) {
	//check to see if a Canadian province was selected/deselected
	checkForBankAnnuities(country);
}

function streetAddressFocus(country) {
	clearStreetAddress();
	scrapeTopZip(ENTER_ZIP_POSTAL_CODE, country);
}

function streetAddressFocusFromResults(country) {
	clearStreetAddress();
	scrapeTopZip("", country);
}

function streetAddressChg(country) {
	scrapeCityStateSearchSection(country);
}

function bottomZipFocus(country) {
	clearBottomZip();
	scrapeTopZip(ENTER_ZIP_POSTAL_CODE, country);
}

function bottomZipFocusFromResults(country) {
	clearBottomZip();
	scrapeTopZip("", country);
}

function bottomZipChg(country) {
	scrapeCityStateSearchSection(country);
}

function radiusChg(country) {
	scrapeTopZip(ENTER_ZIP_POSTAL_CODE, country);
	scrapeCityStateSearchSection(country);
}

function radiusChgFromResults(country) {
	scrapeTopZip("", country);
	scrapeCityStateSearchSection(country);
}

function cityFocus(country) {
	clearCity();
	scrapeTopZip(ENTER_ZIP_POSTAL_CODE, country);
}

function cityFocusFromResults(country) {
	clearCity();
	scrapeTopZip("", country);
}

function cityChg(country) {
	scrapeStreetAddressSearchSection(country);
}

function stateChg(country) {
	scrapeTopZip(ENTER_ZIP_POSTAL_CODE, country);
	scrapeStreetAddressSearchSection(country);
	
	//check to see if a Canadian province was selected/deselected
	checkForBankAnnuities(country);
}

function stateChgFromResults(country) {
	scrapeTopZip("", country);
	scrapeStreetAddressSearchSection(country);
	
	//check to see if a Canadian province was selected/deselected
	checkForBankAnnuities(country);
}

function mfOrAnnuitiesClk() {
	//checkForMFOrAnnuities();
}

function langChg() {
	var langObj = document.getElementById("language");
	if (langObj != null) {
		if (langObj.selectedIndex > 0) { //a language has been selected
			disableMFAnnuities();
		} else {
			enableMFAnnuities();
		}
	}
}

function lastNameFocus() {
	clearLastName();
}

function disableLanguages() {
	document.getElementById("language").disabled = true;
}

function enableLanguages() {
	document.getElementById("language").disabled = false;
}

function isCanadaChosen(country) { //check to see if the zip code is canadian or a province selected
	var isCanada = false;
	var isDefault = true;
	
	//check zip code values
	//var zipObj = document.getElementById("zipCodeText");
	//if (zipObj != null) {
	//	isCanada = isZipCanada(zipObj.value);
	//	if (zipObj.value != ENTER_ZIP_POSTAL_CODE && zipObj.value != ZIP_POSTAL_CODE && zipObj.value != "") {
	//		isDefault = false;
	//	}
	//}
	
	//check zip code values...search criteria page has 1 zipCodeText, search results has 2 zipCodeText fields and we only care about the 2nd one
	var zips=document.getElementsByName('zipCodeText');
	if (zips != null) {
		if (zips.length > 0) {
			if (zips.length == 1) {
				zipObj = zips.item(0);
			} else {
				zipObj = zips.item(1);
			}
			isCanada = isZipCanada(zipObj.value);
			if (zipObj.value != ENTER_ZIP_POSTAL_CODE && zipObj.value != ZIP_POSTAL_CODE && zipObj.value != "") {
				isDefault = false;
			}
		}
	}
	
	if (! isCanada) {
		zipObj = document.getElementById("zipCodeText2");
		if (zipObj != null) {
			isCanada = isZipCanada(zipObj.value);
			if (zipObj.value != ENTER_ZIP_POSTAL_CODE && zipObj.value != ZIP_POSTAL_CODE && zipObj.value != "") {
				isDefault = false;
			}	
		}
	}
	
	//check state drop down
	if (! isCanada) {
		stateObj = document.getElementById("stateProvince");
		if (stateObj != null) {
			if ((stateObj.value == 'AB') || (stateObj.value == 'NB') || (stateObj.value == 'ON')) {
				isCanada = true;
			} else {
				if (stateObj.value != "") {
					isDefault = false;
				}
			}
		}
	}
	
	//we are on the Canadian website and no zip code or state has been chosen
	if (! isCanada) {
		if (country == "CA" && isDefault) {
			isCanada = true;
		}
	}
	
	return isCanada;
}

function isZipCanada(zipValue) {
	if (zipValue.length > 0) {
		if (zipValue != ENTER_ZIP_POSTAL_CODE && zipValue != ZIP_POSTAL_CODE) {
			var zipFirstChar = zipValue.substring(0,1);
			var zipAlpha = zipFirstChar.match("[a-zA-Z]{1}");
			if (zipAlpha != null) {
				return true;
			}
		}
	}
	return false;
}

function isLanguageChosen() {
	var isLanguage = false;
	
	var langObj = document.getElementById("language");
	if (langObj != null) {
		if (langObj.selectedIndex > 0) {
			isLanguage = true;
		}
	}
	
	return isLanguage;
}

function isBankChosen() {
	var isBank = false;
	
	var bankObj = document.getElementById("bank");
	if (bankObj != null) {
		if (bankObj.checked) {
			isBank = true;
		}
	}
	
	return isBank;
}

function isAnnuitiesChosen() {
	var isAnnuities = false;
	
	var annuitiesObj = document.getElementById("varlife");
	if (annuitiesObj != null) {
		if (annuitiesObj.checked) {
			isAnnuities = true;
		}
	}
	
	return isAnnuities;
}

function isMFChosen() {
	var isMF = false;
	
	var mfObj = document.getElementById("mfunds");
	if (mfObj != null) {
		if (mfObj.checked) {
			isMF = true;
		}
	}
	
	return isMF;
}

function showBankAnnuities() {
	document.getElementById('hbank').style.visibility = "";
	document.getElementById('hbank').style.display = '';
	document.getElementById('hvarlife').style.visibility = "";
	document.getElementById('hvarlife').style.display = '';
}

function hideBankAnnuities() {
	document.getElementById('hbank').style.visibility = "hidden";
	document.getElementById('hbank').style.display = 'none';
	document.getElementById('hbank').checked = false;
	document.getElementById('hvarlife').style.visibility = "hidden";
	document.getElementById('hvarlife').style.display = 'none';
	document.getElementById('hvarlife').checked = false;
	document.getElementById('bank').checked = false;
	document.getElementById('varlife').checked = false;
	checkBoxDisable("bank", document.getElementById("bank").disabled, false);
	checkBoxDisable("varlife", document.getElementById("varlife").disabled, false);
	
	//checkForMFOrAnnuities();  //since we are unchecking the annuities, we need to see if we need to enable the languages if annuities is not clicked anymore
}

function disableMFAnnuities() {
	checkBoxDisable("mfunds", true, false);
	checkBoxDisable("varlife", true, false);
}

function enableMFAnnuities() {
	checkBoxDisable("mfunds", false, false);
	checkBoxDisable("varlife", false, false);
}

function scrapeTopZip(defaultTo, country) {
	//clear top zip
	var topZipObj = document.getElementsByName('zipCodeText');
	if (topZipObj != null) {
		for (var i=0; i < topZipObj.length; i++){
			if (topZipObj.item(i).value == ENTER_ZIP_POSTAL_CODE) {
			} else {
				topZipObj.item(i).value = defaultTo;
			}
		}
	}
	
	//check to see if a Canadian province was selected/deselected
	checkForBankAnnuities(country);
}

function scrapeStreetAddressSearchSection(country) {
	var streetObj = document.getElementById('streetText');
	if (streetObj != null) {
		if (streetObj.value != STREETADDRESS) {
			streetObj.value = STREETADDRESS;
		}
	}
	
	var zipObj = document.getElementById('zipCodeText2');
	if (zipObj != null) {
		if (zipObj.value != ZIP_POSTAL_CODE) {
			zipObj.value = ZIP_POSTAL_CODE;
		}
	}
	
	var radiusObj = document.getElementById('radius');
	if (radiusObj != null) {
		radiusObj.selectedIndex = 0;
	}
	
	//check to see if a Canadian province was selected/deselected
	checkForBankAnnuities(country);
}

function scrapeCityStateSearchSection(country) {
	var cityObj = document.getElementById('cityText');
	if (cityObj != null) {
		if (cityObj.value != CITY) {	
			cityObj.value = CITY;
		}
	}
	
	var stateObj = document.getElementById('stateProvince');
	if (stateObj != null) {
		stateObj.selectedIndex = 0;
	}
	
	//check to see if a Canadian province was selected/deselected
	checkForBankAnnuities(country);
}

//clears the top zip if it equals the default
function clearTopZip() {
	var zip2Obj = document.getElementById('zipCodeText');
	if (zip2Obj != null) {
	    if (zip2Obj.value == ENTER_ZIP_POSTAL_CODE) {
    		zip2Obj.value = "";
    	}
    }
}

//clears the street address if it equals the default
function clearStreetAddress() {
	var streetObj = document.getElementById('streetText');
	if (streetObj != null) {
	    if (streetObj.value == STREETADDRESS) {
    		streetObj.value = "";
    	}
    }
}

//clears the bottom zip if it equals the default
function clearBottomZip() {
	var zip2Obj = document.getElementById('zipCodeText2');
	if (zip2Obj != null) {
	    if (zip2Obj.value == ZIP_POSTAL_CODE) {
    		zip2Obj.value = "";
    	}
    }
}

//clears the city if it equals the default
function clearCity() {
	var cityObj = document.getElementById('cityText');
	if (cityObj != null) {
		if (cityObj.value == CITY) {
			cityObj.value = "";
		}
	}
}

//clears the last name if it equals the default
function clearLastName() {
	var lastNameObj = document.getElementById('lastName');
	if (lastNameObj != null) {
		if (lastNameObj.value == LASTNAME) {
			lastNameObj.value = "";
		}
	}
}

//checks to see if MF or Annuities has been selected...
//if so, it will disable the languages
//if not, it will enable the languages
function checkForMFOrAnnuities() {
	var m = document.getElementById('mfunds');
	var v = document.getElementById('varlife');
	
	if (m.checked || v.checked) {
		disableLanguages();
	} else {
		enableLanguages();
	}
}

//checks to see if a Canadian zip code or province has been selected...
//if so, it will hide the Bank and Annuities check boxes
//if not it will display the Bank and Annuities check boxes
function checkForBankAnnuities(country) {
	if (isCanadaChosen(country)) {
		hideBankAnnuities();
	} else {
		showBankAnnuities();
	}
}

function getOnline2Path(){
	var myHost = document.location.host;
	var host = "";
	
	if( (myHost.indexOf("tcidv") > 0) || (myHost.indexOf("localhost") >= 0)){
	    host = ".tcidv";
	}
	else if(myHost.indexOf("tcipf") > 0){
	    host = ".tcipf";
	}
	else if(myHost.indexOf("tcisp") > 0){
	    host = ".tcisp";
	}
	path = document.location.protocol+"//online2" + host+".statefarm.com";
	return path;
}
