function isAnyStateSelected() {
	var stateProvince = document.getElementById("stateProvince").value;
	if (stateProvince == '') {
		return false;
	} else {
		return true;
	}
}

function isCanadaSelected() {
	var stateProvince = document.getElementById("stateProvince").value;
	if ((stateProvince == 'AB') || (stateProvince == 'NB') || (stateProvince == 'ON')) {
		return true;
	} else {
		return false;
	}
}

//-------------------------------------------------
//called by the Narrowing Form when a radio button
//is selected.  Determines if the MFunds and VLife
//check boxes should be deselected and disabled
//or enabled based on the selection.
//DISABLE MFUNDS & VLIFE WHEN ANY LANGUAGE IS SELECTED.
//@param: hasLanguage is the language radio is selected.
//		  [nation] optional/overloaded.
//+++++++++++++++++++++++++++++++++++++++++++++++++
// This method is overlaoded to allow the switch
// the narrowing section when the user entered
// a state or zip that is in CA and vice versa.
function langChk(hasLanguage, nation) {

	var setCanada = false;
	if (isAnyStateSelected()) { //first check to see if they have selected a state/province
		if (isCanadaSelected()) {
			setCanada = true;
		}
	} else {
		if (nation == 'CA') {
			setCanada = true;
		}
	}

	if (setCanada) {
		checkBoxDisable("bank", true, false);
		checkBoxDisable("varlife", true, false);
		if (hasLanguage == true) {
			checkBoxDisable("mfunds", true, false);
		} else {
			checkBoxDisable("mfunds", false, true);
		}
	} else {
		checkBoxDisable("bank", false, true);
		if (hasLanguage == true) {
			checkBoxDisable("mfunds", true, false);
			checkBoxDisable("varlife", true, false);
		} else {
			checkBoxDisable("mfunds", false, true);
			checkBoxDisable("varlife", false, true);
		}
	}
}

//--------------------------------------------------
//Called by the Narrowing Form when a check box is
//selected.  Determines if the language should be
//disabled and deselected or enabled based on the
//selection.
//DISABLE LANGUAGES WHEN MFUNDS OR VLIFE IS CHECKED.
//--------------------------------------------------
function narrowChk(value) {
	var m = document.getElementById('mfunds');
	var v = document.getElementById('varlife');
	var value;
	if (m.checked || v.checked) { value = true; }
	
	if (value == true) {
		radioDisable(true, false);
	} else {
		radioDisable(false, true);
	}
}

function stateChk(nation) {
	var stateProvince = document.getElementById('stateProvince').value;
	if ((stateProvince == "" && nation == 'CA') || isCanadaSelected()) {
	
		checkBoxDisable("bank", true, false);

		checkBoxDisable("varlife", true, false);
		if (document.getElementById('mfunds').checked || document.getElementById('varlife').checked) {
			radioDisable(true, false);
		} else {
			radioDisable(false, true);
		}

		hideBankAndVarLife();
	} else {
	
		checkBoxDisable("bank", false, true);
		if (! isLanguageChecked()) {
			checkBoxDisable("varlife", false, true);
		}
		restoreBankAndVarLife();
	}
}



function formReset(formID, nation) {
	var stateProvince = document.getElementById("stateProvince").value;
	if (formID === 'NarrowSearchForm') {
		if (isCanadaSelected() || (nation == 'CA' && stateProvince == "")) {
			checkBoxDisable("bank", true, false);
	
			checkBoxDisable("varlife", true, false);		
			hideBankAndVarLife();
		} else {
			checkBoxDisable("bank", false, true);
			checkBoxDisable("varlife", false, true);
			restoreBankAndVarLife();
		}

		checkBoxDisable("mfunds", false, true);
		if (document.getElementById('mfunds').checked || document.getElementById('varlife').checked) {
			radioDisable(true, false);
		} else {
			radioDisable(false, false);
		}
	}
}

function isLanguageChecked() {
	var checked = false;
	var x = document.getElementsByName('language');
	for (var i=0; i < x.length; i++) {
		if (x.item(i).checked) {
			checked = true;
		}
	}
	return checked;
}

function hideBankAndVarLife() {
	document.getElementById('hbank').style.visibility = "hidden";
	document.getElementById('hbank').style.display = 'none';
	document.getElementById('hvarlife').style.visibility = "hidden";
	document.getElementById('hvarlife').style.display = 'none';
}

function restoreBankAndVarLife() {
	document.getElementById('hbank').style.visibility = "";
	document.getElementById('hbank').style.display = '';
	document.getElementById('hvarlife').style.visibility = "";
	document.getElementById('hvarlife').style.display = '';
}

function processZip(zipValue, nation) {
	if (zipValue.length > 0) {
		var zipFirstChar = zipValue.substring(0,1);
		var zipAlpha = zipFirstChar.match("[a-zA-Z]{1}");
		if (zipAlpha != null) {
			document.getElementById('bank').checked = false;
			document.getElementById('varlife').checked = false;
			hideBankAndVarLife();
		} else {
			if (document.getElementById('hbank').style.visibility == "hidden") {
				restoreBankAndVarLife();
			}
		}			
	} else {
		if (nation == 'US') {
			restoreBankAndVarLife();
		} else {
			hideBankAndVarLife();
		}
	}
}

//ALLOWS USER TO PRESS THE ENTER KEY ON ANY PORTION OF THE FORM
//AND SUBMIT THE CURRENT INFORMATION.
/*
function submitenter(myfield, e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13) {
		myfield.form.submit();
		return false;
	} else {
		return true;
	}
}
*/

function submitClickedOnCityStateForm(myfield) {

	var whichZip = 1;
	var zip = "";
	
	//var zipCodeObj = document.getElementById("zipCodeText");
	var zipCodeObj = myfield.zipCodeText;
    if (zipCodeObj != null && zipCodeObj.value != 'Ingrese el código postal') {
    	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 != 'Address' && 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(myfield) {
	var zipCode = "";
	var zipCodeObj = document.getElementById("zipCodeText");
	if (zipCodeObj != null) {
		zipCode = zipCodeObj.value;
	}
	if (validateZipInput(zipCode)) {
		return true;
	} else {
		return false;
	}
}

function submitClickedOnNameForm(myfield) {

	if (validateNameInput(document.getElementById("lastName").value, document.getElementById("stateProvinceForName").value)) {
		return true;
	} else {
		return false;
	}
}

function clearZip() {
	var zipCode = document.getElementById('zipCodeText').value;
	if (zipCode == 'Ingrese el código postal') {
		document.getElementById('zipCodeText').value = "";
	}
	
	var street = document.getElementById('streetText').value;
	if (street != 'Address') {
		document.getElementById('streetText').value = "";
	}
	
	var street = document.getElementById('cityText').value;
	if (street != 'City') {
		document.getElementById('cityText').value = "";
	}
	
	var street = document.getElementById('zipCodeText2').value;
	if (street != 'ZIP / Postal Code') {
		document.getElementById('zipCodeText2').value = "";
	}
}

function clearZip2() {
	var zipCode2 = document.getElementById('zipCodeText2').value;
    if (zipCode2 == 'ZIP / Postal Code') {
    	document.getElementById('zipCodeText2').value = "";
    }
    
    var r=document.getElementsByName('zipCodeText');
    for (var i=0;i<r.length;i++){
    	if (r.item(i).value == 'Ingrese el código postal') {
        } else {
        	r.item(i).value="";
        }
    }
}

function clearStreet() {
	var street = document.getElementById('streetText').value;
    if (street == 'Address') {
    	document.getElementById('streetText').value = "";
    }
                
    var r=document.getElementsByName('zipCodeText');
    for (var i=0;i<r.length;i++){
    	if (r.item(i).value == 'Ingrese el código postal') {
        } else {
        	r.item(i).value="";
        }
    }
}

function clearCity() {
	var city = document.getElementById('cityText').value;
	if (city == 'Ciudad') {
		document.getElementById('cityText').value = "";
	}
	
	var r=document.getElementsByName('zipCodeText');
	for (var i=0;i<r.length;i++){
		if (r.item(i).value == 'Ingrese el código postal') {
		} else {
			r.item(i).value="";
		}
	}
	
}

function clearLastName() {
	var lastName = document.getElementById('lastName').value;
	if (lastName == "Apellido del agente") {
		document.getElementById('lastName').value = "";
	}
}

function unhideCityState() {
    dojo.style(dojo.byId("showMoreOpt"), "display", "none");
    dojo.style(dojo.byId("showFewerOpt"), "display", "block");
    dojo.style(dojo.byId("scbyModBtm"), "backgroundPosition", "0px -46px");
}


//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 && ("Address" != streetInput)){
        	if (! isStreetValid) {
            	document.getElementById("streetErrorOnCityState").style.display = "block";
            }
            if (isPOBox) {
            	document.getElementById("poBoxErrorOnCityState").style.display = "block";
            }
            if (! isCityValid) {
            	document.getElementById("cityErrorOnCityState").style.display = "block";
            }
            if (! isStateValid) {
            	document.getElementById("stateErrorOnCityState").style.display = "block";
            }
            if (! isZipValid) {
            	document.getElementById("zipErrorOnStreetSearch").style.display = "block";
            }
            if (! isCityValid || ! isStateValid || ! 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 (isZipValid) {
            return true;
        } else if (whichZip == 1) {
            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 { //must be doing a zip search from the city state area
        	if (document.getElementById("mainLocError-Zip") != null) {
            	document.getElementById("mainLocError-Zip").style.display = "block";
            }
                                                
            document.getElementById("errorFoundOnCityState").style.display = "block";
            document.getElementById("zipErrorOnStreetSearch").style.display = "block";

            return false;
        }
    } else if (streetInput.length > 0 && ("Address" != streetInput)){
        	if (! isStreetValid) {
            	document.getElementById("streetErrorOnCityState").style.display = "block";
            }
            if (isPOBox) {
            	document.getElementById("poBoxErrorOnCityState").style.display = "block";
            }
            if (! isCityValid) {
            	document.getElementById("cityErrorOnCityState").style.display = "block";
            }
            if (! isStateValid) {
            	document.getElementById("stateErrorOnCityState").style.display = "block";
            }
            if (! isZipValid) {
            	document.getElementById("zipErrorOnStreetSearch").style.display = "block";
            }
            if (! isCityValid || ! isStateValid || ! 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("errorSearchCriteriaOnCityState").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\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 && "Apellido del agente" != nameInput) || stateInput != "") {
		var isNameValid = validateLastName(nameInput);
		var isStateValid = validateState(stateInput);
		if (! isNameValid || "Apellido del agente" == nameInput) {
			document.getElementById("nameErrorOnName").style.display = "block";
		}
		if (! isStateValid) {
			document.getElementById("stateErrorOnName").style.display = "block";
		}
		if (! isNameValid || "Apellido del agente" == 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("errorSearchCriteriaOnName").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, root, ddUrl) {
	var dialogbox = document.getElementById("directionsIFrame");
	if (dialogbox != null) {
		//dialogbox.src = "http://statefarm.convertlanguage.com/statefarm/enes/24/_online2_statefarm_com/b2c/AgentLocatorPortlet-Portlet/jsps/html/modal/map.html"; //must be a relative path
		//dialogbox.src = "/b2c/AgentLocatorPortlet-Portlet/jsps/html/advantageCallback.jsp?origcountry=" + country + "&destcountry=" + country + "&pheight=340&pwidth=600&sheight=119&swidth=198&transaction=route&querytemplate=route&origaddress=&origcity=&origstateProvince=&origpostalCode=&destaddress=" + destAddress + "&destcity=" + city + "&deststateProvince=" + state + "&destpostalCode=" + zip + "&st=" + stateCode + "&ofc=" + agentCode + "&x=84&y=11"; //must be a relative path
		//dialogbox.src = root + "/advantageCallback.jsp?origcountry=" + country + "&destcountry=" + country + "&pheight=340&pwidth=600&sheight=119&swidth=198&transaction=route&querytemplate=route&origaddress=&origcity=&origstateProvince=&origpostalCode=&destaddress=" + destAddress + "&destcity=" + city + "&deststateProvince=" + state + "&destpostalCode=" + zip + "&st=" + stateCode + "&ofc=" + agentCode + "&x=84&y=11"; //must be a relative path
		//dialogbox.src = "http://10.35.126.41:9080/MicrosoftMapExample/DrivingDirections?origcountry=" + country + "&destcountry=" + country + "&pheight=340&pwidth=600&sheight=119&swidth=198&transaction=route&querytemplate=route&origaddress=&origcity=&origstateProvince=&origpostalCode=&destaddress=" + destAddress + "&destcity=" + city + "&deststateProvince=" + state + "&destpostalCode=" + zip + "&st=" + stateCode + "&ofc=" + agentCode + "&x=84&y=11"; //must be a relative path
		dialogbox.src = ddUrl + "?origAddress=&origCity=&origStateProvince=&origPostalCode=&destAddress=" + destAddress + "&destCity=" + city + "&destStateProvince=" + state + "&destPostalCode=" + zip; //must be a relative path
	}
	showDialog(id);
}

function showEmailMeDialog(stateCode, agentCode) {	
	var elmt = dijit.byId("emailMe");
	if (elmt != null) {
		//var href = "http://statefarm.convertlanguage.com/statefarm/enes/24/_wp95dc02_opr_test_statefarm_org__50420/b2c/AgentMicrositePortlets_Photo/servlet/EmailMe?st=" + stateCode + "&ofc=" + agentCode + "&modalID=emailMe";
		var href = "http://statefarm.convertlanguage.com/statefarm/enes/24/_online2_statefarm_com/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');
		});
	});	
}

//selects the radio button and the image associated with it
function radioSelect(id){
  $(document).ready(function(){
		$("input:radio").each( function() {
			if (!this.disabled){
				($(this).hasClass('fakeoptchecked')) ?  $("#fake"+this.id).removeClass('fakeoptchecked') :  $("#fake"+this.id).removeClass('fakeoptchecked'); 
				($(this).hasClass('fakeoptdisabled')) ? $("#fake"+this.id).removeClass('fakeoptdisabled') : $("#fake"+this.id).removeClass('fakeoptdisabled');
				($(this).hasClass('fakeoptdisabledchecked')) ? $("#fake"+this.id).removeClass('fakeoptdisabledchecked') : $("#fake"+this.id).removeClass('fakeoptdisabledchecked');
			}
		});
	});
}