<!--

function resetTheForm() {
	lookingForPhysician();
	lookingInStateCity();
    document.getElementById("looking_for_physician_id").checked = true;
    document.getElementById("network_id").value="";
    document.getElementById("state").value="";
}

// Activates and deactivates appropriate fields when looking for a Physician...
function lookingForPhysician() {
	document.forms.ipf_form.specialty.disabled = false;
	document.forms.ipf_form.specialty.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.specialty.selectedIndex = 0;
	
	document.forms.ipf_form.name.disabled = false;
	document.forms.ipf_form.name.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.name.value = "";
	
	document.forms.ipf_form.gender.disabled = false;
	document.forms.ipf_form.gender.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.gender.selectedIndex = 0;
	
	document.forms.ipf_form.group.disabled = false;
	document.forms.ipf_form.group.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.group.value = "";
	document.forms.ipf_form.hospital.disabled = false;
	document.forms.ipf_form.hospital.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.hospital.value = "";
		
	document.forms.ipf_form.ancillary_type.disabled = true;
	document.forms.ipf_form.ancillary_type.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.ancillary_type.selectedIndex = 0;
}

// Activates and deactivates appropriate fields when looking for a Group of Physicians...
function lookingForGroup() {
	document.forms.ipf_form.specialty.disabled = true;
	document.forms.ipf_form.specialty.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.specialty.selectedIndex = 0;
	
	document.forms.ipf_form.name.disabled = false;
	document.forms.ipf_form.name.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.name.value = "";
	
	document.forms.ipf_form.gender.disabled = true;
	document.forms.ipf_form.gender.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.gender.selectedIndex = 0;
	
	document.forms.ipf_form.group.disabled = true;
	document.forms.ipf_form.group.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.group.value = "";
	document.forms.ipf_form.hospital.disabled = true;
	document.forms.ipf_form.hospital.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.hospital.value = "";
		
	document.forms.ipf_form.ancillary_type.disabled = true;
	document.forms.ipf_form.ancillary_type.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.ancillary_type.selectedIndex = 0;
}

// Activates and deactivates appropriate fields when looking for a Group of Physicians...
function lookingForHospital() {
	document.forms.ipf_form.specialty.disabled = true;
	document.forms.ipf_form.specialty.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.specialty.selectedIndex = 0;
	
	document.forms.ipf_form.name.disabled = false;
	document.forms.ipf_form.name.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.name.value = "";
	
	document.forms.ipf_form.gender.disabled = true;
	document.forms.ipf_form.gender.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.gender.selectedIndex = 0;
	
	document.forms.ipf_form.group.disabled = true;
	document.forms.ipf_form.group.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.group.value = "";
	document.forms.ipf_form.hospital.disabled = true;
	document.forms.ipf_form.hospital.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.hospital.value = "";
		
	document.forms.ipf_form.ancillary_type.disabled = true;
	document.forms.ipf_form.ancillary_type.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.ancillary_type.selectedIndex = 0;
}

// Activates and deactivates appropriate fields when looking for an Ancillary...
function lookingForAncillary() {
	document.forms.ipf_form.specialty.disabled = true;
	document.forms.ipf_form.specialty.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.specialty.selectedIndex = 0;
	
	document.forms.ipf_form.name.disabled = true;
	document.forms.ipf_form.name.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.name.value = "";
	
	document.forms.ipf_form.gender.disabled = true;
	document.forms.ipf_form.gender.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.gender.selectedIndex = 0;
	
	document.forms.ipf_form.group.disabled = true;
	document.forms.ipf_form.group.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.group.value = "";
	document.forms.ipf_form.hospital.disabled = true;
	document.forms.ipf_form.hospital.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.hospital.value = "";
		
	document.forms.ipf_form.ancillary_type.disabled = false;
	document.forms.ipf_form.ancillary_type.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.ancillary_type.selectedIndex = 0;
}

// Activates and deactivates appropriate fields when looking for all physicians, hospitals, and ancillaries...
function lookingForAll() {
	document.forms.ipf_form.specialty.disabled = true;
	document.forms.ipf_form.specialty.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.specialty.selectedIndex = 0;
	
	document.forms.ipf_form.name.disabled = true;
	document.forms.ipf_form.name.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.name.value = "";
	
	document.forms.ipf_form.gender.disabled = true;
	document.forms.ipf_form.gender.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.gender.selectedIndex = 0;
	
	document.forms.ipf_form.group.disabled = true;
	document.forms.ipf_form.group.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.group.value = "";
	document.forms.ipf_form.hospital.disabled = true;
	document.forms.ipf_form.hospital.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.hospital.value = "";
		
	document.forms.ipf_form.ancillary_type.disabled = true;
	document.forms.ipf_form.ancillary_type.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.ancillary_type.selectedIndex = 0;
}

// Activates and deactivates appropriate fields when looking in a State and County...
function lookingInStateCounty() {
	document.forms.ipf_form.state.disabled = false;
	document.forms.ipf_form.state.style.backgroundColor = "#FFFFFF";
	//document.forms.ipf_form.state.selectedIndex = 0;
	
	document.forms.ipf_form.county.disabled = false;
	document.forms.ipf_form.county.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.county.value = "";
	
	document.forms.ipf_form.city.disabled = true;
	document.forms.ipf_form.city.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.city.value = "";
	
	document.forms.ipf_form.zip_code.disabled = true;
	document.forms.ipf_form.zip_code.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.zip_code.value = "";
	document.forms.ipf_form.zip_radius.disabled = true;
	document.forms.ipf_form.zip_radius.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.zip_radius.value = "";
}

// Activates and deactivates appropriate fields when looking in a State and City...
function lookingInStateCity() {
	document.forms.ipf_form.state.disabled = false;
	document.forms.ipf_form.state.style.backgroundColor = "#FFFFFF";
	
	document.forms.ipf_form.county.disabled = true;
	document.forms.ipf_form.county.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.county.value = "";
	
	document.forms.ipf_form.city.disabled = false;
	document.forms.ipf_form.city.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.city.value = "";
	
	document.forms.ipf_form.zip_code.disabled = true;
	document.forms.ipf_form.zip_code.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.zip_code.value = "";
	document.forms.ipf_form.zip_radius.disabled = true;
	document.forms.ipf_form.zip_radius.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.zip_radius.value = "";
}

// Activates and deactivates appropriate fields when looking in a Zip Code and Radius...
function lookingInZipRadius() {
	document.forms.ipf_form.state.disabled = true;
	document.forms.ipf_form.state.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.state.selectedIndex = 0;
	
	document.forms.ipf_form.county.disabled = true;
	document.forms.ipf_form.county.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.county.value = "";
	
	document.forms.ipf_form.city.disabled = true;
	document.forms.ipf_form.city.style.backgroundColor = "#DDDDDD";
	document.forms.ipf_form.city.value = "";
	
	document.forms.ipf_form.zip_code.disabled = false;
	document.forms.ipf_form.zip_code.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.zip_code.value = "";
	document.forms.ipf_form.zip_radius.disabled = false;
	document.forms.ipf_form.zip_radius.style.backgroundColor = "#FFFFFF";
	document.forms.ipf_form.zip_radius.value = "10";
}

// This function is for compatability with other search forms.   The main form
// doesn't use this function.
function validateDocHospSearchForm() {
    var validFormData = validateFormData();
    if (validFormData == true) {
    	document.ipf_form.submit();
    }
    return validFormData;
}

function validateFormData() {
    // Check for all required PHCS search elements
    if ((document.getElementById("health_plan_id") != null) && (document.getElementById("health_plan_id").value == "PHCS")) {
        if (document.getElementById("hl_front_id").checked == true) {
            // Verify that a network program was specified
            var networkProgram = "";
            var networkProgramSelect = document.getElementById("hl_network_program_front_id");
            for (var pos = 0 ; pos < networkProgramSelect.options.length ; pos++) {
                if (networkProgramSelect.options[pos].selected == true) {
                    networkProgram = networkProgramSelect.options[pos].value;
                    break;
                }
            }
            if (networkProgram == "") {
                alert("Please select the network program that appears\non the front of your card.");
                window.scrollTo(0,300);
                document.location.href = "#step1";
                return false;
            } else {
                // verify that a logo was selected from the back of the card
                if (document.getElementById("phcs_ppo_back_id").checked == false) {
		            alert("Please specify all logos that appears on the back of your card.");
                    displayCardTab("back");
                    window.scrollTo(0,300);
                    document.location.href = "#step1";
                    return false;
                }
            }
        } else if (document.getElementById("phcs_front_id").checked == true) {

            if (document.getElementById("hl_back_id").checked == true) {
                // Verify that a network program was specified
                var networkProgram = "";
                var networkProgramSelect = document.getElementById("hl_network_program_back_id");
                for (var pos = 0 ; pos < networkProgramSelect.options.length ; pos++) {
                    if (networkProgramSelect.options[pos].selected == true) {
                        networkProgram = networkProgramSelect.options[pos].value;
                        break;
                    }
                }
                if (networkProgram == "") {
                    alert("Please select the network program that appears\non the back of your card.");
                    window.scrollTo(0,300);
                    document.location.href = "#step1";
                    return false;
                }
            }

        } else {
		    alert("Please specify the logo that appears on the front of your card.");
            window.scrollTo(0,300);
            document.location.href = "#step1";
            return false;
        }

    } else {

	    // This checks to be sure the user selected a network...
	    if (document.ipf_form.network[0].selected) {
	    	alert("Please select the NETWORK that you belong to.");
	        document.ipf_form.network.focus();
		    return false;
	    }
    }
	
	// This checks to be sure only one name was entered into the name field...
	//if (document.ipf_form.looking_for[0].checked && 
	//document.ipf_form.name.value.indexOf(" ") >= 0) {
	//alert("Please enter only the LAST NAME of the physician you are searching for.");
	//document.ipf_form.name.focus();
	//return false;
	//}
	
	// This has been commented out becasue of the enhanced apostrophe 
	// checking ASP code that was added on 12/17/04 by MCL
	
	// This checks to be sure no apostrophes were entered into the name field...
	//if (document.ipf_form.looking_for[0].checked && 
	//document.ipf_form.name.value.indexOf("'") >= 0) {
	//	alert("Please do not enter apostrophes in the Physicisn's NAME.");
	//	document.ipf_form.name.focus();
	//	return false;
	//}
	
	// This checks to be sure no apostrophes were entered into the group field...
	if (document.ipf_form.looking_for[0].checked && 
	document.ipf_form.group.value.indexOf("'") >= 0) {
		alert("Please do not enter apostrophes in the Group's NAME.");
		document.ipf_form.group.focus();
		return false;
	}
	
	// This checks to be sure no apostrophes were entered into the hospital field...
	if (document.ipf_form.looking_for[0].checked && 
	document.ipf_form.hospital.value.indexOf("'") >= 0) {
		alert("Please do not enter apostrophes in the Hospital's NAME.");
		document.ipf_form.hospital.focus();
		return false;
	}
	
	// This checks to be sure the name field is not left empty when searching for a group...
	if (document.ipf_form.looking_for[1].checked && 
	document.ipf_form.name.value == "") {
		alert("Please enter a NAME when performing a search for a Group of Physicians.");
		document.ipf_form.name.focus();
		return false;
	}
	
	// This checks to be sure no apostrophes were entered into the name field...
	if (document.ipf_form.looking_for[1].checked && 
	document.ipf_form.name.value.indexOf("'") >= 0) {
		alert("Please do not enter apostrophes in the Group's NAME.");
		document.ipf_form.name.focus();
		return false;
	}

	// This checks to be sure no apostrophes were entered into the name field...
	if (document.ipf_form.looking_for[2].checked && 
	document.ipf_form.name.value.indexOf("'") >= 0) {
		alert("Please do not enter apostrophes in the Hospital's NAME.");
		document.ipf_form.name.focus();
		return false;
	}

	// This checks to be sure the user has selected a state...
	if ((document.ipf_form.location[0].checked || document.ipf_form.location[1].checked) && 
	document.ipf_form.state[0].selected) {
		alert("Please select the STATE that you would like to search within.");
		document.ipf_form.state.focus();
		return false;
	}

	// Require a city when searching by state and city for PHCS
    if ((document.getElementById("health_plan_id") != null) && (document.getElementById("health_plan_id").value == "PHCS")) {
	    if (document.ipf_form.location[0].checked && document.ipf_form.city.value == "") {
		    alert("Please enter a City name when searching by State and City.");
		    document.ipf_form.city.focus();
		    return false;
        }
	}

	// This checks to be sure no apostrophes were entered into the city field...
	if (document.ipf_form.location[0].checked && 
	document.ipf_form.city.value.indexOf("'") >= 0) {
		alert("Please do not enter apostrophes in the City's NAME.");
		document.ipf_form.city.focus();
		return false;
	}
	
    // Require a county when searching by state and county for PHCS
    if ((document.getElementById("health_plan_id") != null) && (document.getElementById("health_plan_id").value == "PHCS")) {
        if (document.ipf_form.location[1].checked && document.ipf_form.county.value == "") {
            alert("Please enter a County name when searching by State and County.")
		    document.ipf_form.county.focus();
		    return false;
        }
    }

	// This checks to be sure no apostrophes were entered into the county field...
	if (document.ipf_form.location[1].checked && 
	document.ipf_form.county.value.indexOf("'") >= 0) {
		alert("Please do not enter apostrophes in the County's NAME.");
		document.ipf_form.county.focus();
		return false;
	}

	// This checks to be sure the zip code field is not left empty...
	if (document.ipf_form.location[2].checked && 
	document.ipf_form.zip_code.value == "") {
		alert("Please enter a ZIP CODE when performing a search using the Zip Code and Mile Radius option.");
		document.ipf_form.zip_code.focus();
		return false;
	}
	
	// This checks to be sure the zip code is five digits in length...
	if (document.ipf_form.location[2].checked && 
	document.ipf_form.zip_code.value.length < 5) {
		alert("Please enter a valid ZIP CODE that is five digits in length.");
		document.ipf_form.zip_code.focus();
		return false;
	}
	
	// This checks to be sure only numbers were entered into the zip code field...
	if (document.ipf_form.location[2].checked && 
	isNaN(document.ipf_form.zip_code.value)) {
		alert("Please enter a valid ZIP CODE that contains only numbers.");
		document.ipf_form.zip_code.focus();
		return false;
	}
	
	// This checks to be sure only numbers were entered into the zip code radius field...
	if (document.ipf_form.location[2].checked && 
	document.ipf_form.zip_radius.value.length > 0 &&
	isNaN(document.ipf_form.zip_radius.value)) {
		alert("Please enter a valid RADIUS that contains only numbers.");
		document.ipf_form.zip_radius.focus();
		return false;
	}
	
	// This checks to be sure a postive number greater that zero was entered into the zip code radius field...
	if (document.ipf_form.location[2].checked && 
	document.ipf_form.zip_radius.value.length > 0 &&
	document.ipf_form.zip_radius.value < 1) {
		alert("Please enter a RADIUS of one mile or more.");
		document.ipf_form.zip_radius.focus();
		return false;
	}
	
	//This code sets up the query string in the URL based on what search options have been selected
	
	//Define variables
	var strURL
    strURL = "ipf_tu.asp?"

	//if (document.getElementById("health_plan_id").value == "FirstHealth") {
	//	strURL = "ipf_ccn_tu.asp?"
	//} else {
    //    strURL = "ipf_tu.asp?"
	//}
	
	//This is when searching for a physician
	if (document.ipf_form.looking_for[0].checked) {		
		strURL = strURL + "page=" + document.ipf_form.page.value + "&items=" + document.ipf_form.items.value + "&customize=" + document.ipf_form.customize.value + "&network=" + document.ipf_form.network.value + "&lookingfor=Physician&specialty=" + document.ipf_form.specialty.value + "&name=" + document.ipf_form.name.value + "&gender=" + document.ipf_form.gender.value + "&group=" + document.ipf_form.group.value + "&hospital=" + document.ipf_form.hospital.value + "&ancillary=" +  document.ipf_form.ancillary_type.value;
	}
	
	//This is when searching for a group
	if (document.ipf_form.looking_for[1].checked) {
		strURL = strURL + "page=" + document.ipf_form.page.value + "&items=" + document.ipf_form.items.value + "&customize=" + document.ipf_form.customize.value + "&network=" + document.ipf_form.network.value + "&lookingfor=Group&specialty=" + document.ipf_form.specialty.value + "&name=" + document.ipf_form.name.value + "&gender=" + document.ipf_form.gender.value + "&group=" + document.ipf_form.group.value + "&hospital=" + document.ipf_form.hospital.value + "&ancillary=" +  document.ipf_form.ancillary_type.value;
	}
	
	//This is when searching for a hospital
	if (document.ipf_form.looking_for[2].checked) {
		strURL = strURL + "page=" + document.ipf_form.page.value + "&items=" + document.ipf_form.items.value + "&customize=" + document.ipf_form.customize.value + "&network=" + document.ipf_form.network.value + "&lookingfor=Hospital&specialty=" + document.ipf_form.specialty.value + "&name=" + document.ipf_form.name.value + "&gender=" + document.ipf_form.gender.value + "&group=" + document.ipf_form.group.value + "&hospital=" + document.ipf_form.hospital.value + "&ancillary=" +  document.ipf_form.ancillary_type.value;
	}
	
	//This is when searching for a ancillary
	if (document.ipf_form.looking_for[3].checked) {
		strURL = strURL + "page=" + document.ipf_form.page.value + "&items=" + document.ipf_form.items.value + "&customize=" + document.ipf_form.customize.value + "&network=" + document.ipf_form.network.value + "&lookingfor=Ancillary&specialty=" + document.ipf_form.specialty.value + "&name=" + document.ipf_form.name.value + "&gender=" + document.ipf_form.gender.value + "&group=" + document.ipf_form.group.value + "&hospital=" + document.ipf_form.hospital.value + "&ancillary=" +  document.ipf_form.ancillary_type.value;
	}
	
	//This is when searching for all physicians, hospitals, and an ancillaries
	if (document.ipf_form.looking_for[4].checked) {
		strURL = strURL + "page=" + document.ipf_form.page.value + "&items=" + document.ipf_form.items.value + "&customize=" + document.ipf_form.customize.value + "&network=" + document.ipf_form.network.value + "&lookingfor=All&specialty=" + document.ipf_form.specialty.value + "&name=" + document.ipf_form.name.value + "&gender=" + document.ipf_form.gender.value + "&group=" + document.ipf_form.group.value + "&hospital=" + document.ipf_form.hospital.value + "&ancillary=" +  document.ipf_form.ancillary_type.value;
	}
	
	//This is when searching in a state and city
	if (document.ipf_form.location[0].checked) {
		strURL = strURL + "&lookingin=StateCity&state=" + document.ipf_form.state.value + "&county=" + document.ipf_form.county.value + "&city=" + document.ipf_form.city.value + "&zipcode=" + document.ipf_form.zip_code.value + "&radius=" + document.ipf_form.zip_radius.value + "&searchengine=" + document.ipf_form.searchengine.value;
	}
	
	//This is when searching in a state and county
	if (document.ipf_form.location[1].checked) {
		strURL = strURL + "&lookingin=StateCounty&state=" + document.ipf_form.state.value + "&county=" + document.ipf_form.county.value + "&city=" + document.ipf_form.city.value + "&zipcode=" + document.ipf_form.zip_code.value + "&radius=" + document.ipf_form.zip_radius.value + "&searchengine=" + document.ipf_form.searchengine.value;
	}
	
	//This is when searching in a zip code
	if (document.ipf_form.location[2].checked) {
		strURL = strURL + "&lookingin=ZipCode&state=" + document.ipf_form.state.value + "&county=" + document.ipf_form.county.value + "&city=" + document.ipf_form.city.value + "&zipcode=" + document.ipf_form.zip_code.value + "&radius=" + document.ipf_form.zip_radius.value + "&searchengine=" + document.ipf_form.searchengine.value;
	}
	
	//This submits the form if the function returns true
	document.ipf_form.action = strURL
    return true;
}

function processPagePopUpMenu() {
	document.page_popup_menu.action = "ipf_tu.asp?page=" + document.page_popup_menu.page.value + document.page_popup_menu.url.value;
	document.page_popup_menu.submit();
}

function checkForNetworkSelection() {
	var networkSelectList = document.getElementById("networkId");
	var selectedPos = networkSelectList.selectedIndex;
    selectedValue = networkSelectList.options[selectedPos].value;
	if ((selectedValue.length > 4) && (selectedValue.substr((selectedValue.length - 4), 4) == ".asp")) {
		window.location.assign(selectedValue);
	}
}

/*
 *  Global Cookie Variables
 */
var cookieFieldNames;
var cookieFieldValues;

/*
 *  Save form values so they can be restored when the user clicks the back button
 */ 
function saveSelections(engine) {

    var form = document.getElementById("ipf");
	var cookieString = "engine=" + engine;

	for (var fPos = 0 ; fPos < form.length ; fPos++) {

        var field = form[fPos];
		var fieldName = field.name;
		var fieldValue = field.value;
		var fieldType = field.type;

		if (fieldType == "radio") {
			if (field.checked == true) {
				cookieString = (cookieString  + "\|" +  fieldName + ":" + fieldValue);
			}
		}

        if (fieldType == "checkbox") {
            if (field.checked == true) {
                cookieString = (cookieString  + "\|" +  fieldName + ":checked");
            }
        }

		if ((fieldType == "text") || (fieldType == "textarea") || (fieldType == "select-one") || (fieldType == "hidden")) {
		    cookieString = (cookieString + "\|" + fieldName + ":" + fieldValue);
		}

	}

    setCookie(engine, cookieString); 
}

/*
 *  Build a cross reference of values from the cookie string
 */
function buildCookieXref(cookieString) {
    cookieFieldNames = new Array();
	cookieFieldValues = new Array();

	var fieldArray;
	var oneFieldArray;
	var fieldName;
	var fieldValue;

    var fieldArray = cookieString.split("\|");
	for (var fPos = 0 ; fPos < fieldArray.length ; fPos++) {
		oneFieldArray = fieldArray[fPos].split(":");
		fieldName = oneFieldArray[0];
		fieldValue = oneFieldArray[1];
		cookieFieldNames[fPos] = fieldName;
		cookieFieldValues[fPos] = fieldValue;
	}
}

/*
 *  Get one value from the cookie cross reference
 */
function getFieldValue(fieldName) {
	var fieldValue = "";
	
    if (cookieFieldNames != null) {
        for (var fPos = 0 ; fPos < cookieFieldNames.length ; fPos++) {
            if (cookieFieldNames[fPos] == fieldName) {
                fieldValue = cookieFieldValues[fPos];
                break;
            }
        }
    }
	
	return fieldValue;
}

/*
 *  Restore previous form values
 */ 
function restoreSelections(engine) {

    var form = document.getElementById("ipf");

    var cookieString;
    var fieldArray;
    var fieldName;
    var fieldValue;

    cookieString = getCookie(engine);
	if ((cookieString != null) && (cookieString != "")) {
        buildCookieXref(cookieString);

        // Cycle through all of the form fields
		for (var fPos = 0 ; fPos < form.length ; fPos++) {

            var field = form[fPos];
		    var fieldName = field.name;
		    var fieldValue = field.value;
		    var fieldType = field.type;

		    if (fieldType == "radio") {
				if (getFieldValue(fieldName) == fieldValue) {
			        field.checked = true;
					
					if (fieldName == "looking_for") {
						if (fieldValue == "physician") {
							lookingForPhysician();
						} else if (fieldValue == "group") {
							lookingForHospital();
						} else if (fieldValue == "hospital") {
							lookingForHospital();
						} else if (fieldValue == "ancillary") {
							lookingForAncillary();
						} else {
							lookingForAll();
						}
					} else if (fieldName == "location") {
						if (fieldValue == "state_county") {
							lookingInStateCounty();
						} else if (fieldValue == "zip_radius") {
							lookingInZipRadius();
						} else {
							lookingInStateCity();
						}
					}
				}
			}

            if (fieldType == "checkbox") {
                if (getFieldValue(fieldName) == "checked") {
                    field.checked = true;
                }
            }

		    if ((fieldType == "text") || (fieldType == "textarea") || (fieldType == "select-one") || (fieldType == "hidden")) {
				field.value = getFieldValue(fieldName);
			}
		}
	}
}


/*
 * COOKIE FUNCTIONS
 */

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

/**********
 * Function to update the network drop-down list based on the specified health plan
 */
function updateNetworkList(healthPlan) {
    var networkSelect = document.getElementById("network_id");
    var pos;

    //Remove existing options
    for (pos = (networkSelect.options.length - 1) ; pos >= 0 ; pos--) {
        if (networkSelect.options.remove) {
            networkSelect.options.remove(pos)
        } else {
            networkSelect.options[pos] = null;
        }
    }

    //Add instruction option
    networkSelect.options.add(new Option(), 0);
    networkSelect.options[0].text = "Please select the network you belong to...";
    networkSelect.options[0].value = "";
    //Add health plan network options
    var insPos = 1;
    for (pos = 0 ; pos < networkArray.length ; pos++) {
        if (networkArray[pos][0] == healthPlan) {
            networkSelect.options.add(new Option(), insPos);
            networkSelect.options[insPos].text = networkArray[pos][1];
            networkSelect.options[insPos].value = networkArray[pos][2];
            insPos++;
        }
    } 
    //If only one network exists, then select it
    //Count will be 2 when only 1 exists because of the message line
    if (networkSelect.options.length == 2) {
        networkSelect.options[1].selected = true;
    }
}

/**********
 * Function to update the logo based on the specified health plan
 * Ajax methodology is used to update the logo
 */
function updateHealthPlanLogo(healthPlan) { 
    var logoDiv = document.getElementById("health_plan_logos_id");
    logoDiv.innerHTML = "";
    var pos;
    for (pos = 0 ; pos < logoArray.length ; pos++) {
        if (logoArray[pos][0] == healthPlan) {
            var fileName = logoArray[pos][1];
            var oXmlHttp = zXmlHttp.createRequest();
            oXmlHttp.open("GET", fileName , false);
            oXmlHttp.send(null);
            if ((oXmlHttp.readyState == 4) && (oXmlHttp.status == 200)) {
                logoDiv.innerHTML = oXmlHttp.responseText;
            }          
        }
    }  
}

/**********
 * Function to update the specialty drop-down list based on the specified health plan
 */
function updateSpecialtyList(healthPlan) {
    // clear the list
    var specialtyList = document.getElementById("specialty");
    for (pos = (specialtyList.options.length - 1) ; pos >= 0 ; pos--) {
        if (specialtyList.options.remove) {
            specialtyList.options.remove(pos)
        } else {
            specialtyList.options[pos] = null;
        }
    }

    var matchPlan = "default";
    if (healthPlan == "FirstHealth") {
        matchPlan = healthPlan;
    }

    var insPos = 0;
    for (pos = 0 ; pos < specialtyArray.length ; pos++) {
        if (specialtyArray[pos][0] == matchPlan) {
            specialtyList.options.add(new Option(), insPos);
            specialtyList.options[insPos].text = specialtyArray[pos][1];
            specialtyList.options[insPos].value = specialtyArray[pos][2];
            insPos++;
        }
    } 
}

/**********
 * Function to update the network drop-down list based on the specified health plan
 * EHC is currently the only health plan that differs from the default
 */
function updateStateList(healthPlan) {
    var stateSelect = document.getElementById("state");
    var selectedPos = stateSelect.selectedIndex;
    var selectedState = "";
    if (selectedPos > 0) {
        selectedState = stateSelect.options[selectedPos].value;
    }
    var matchPlan;
    var pos;

    matchPlan = "default";
    if (healthPlan == "EHC") {
        matchPlan = healthPlan;
    }

    //Remove existing options
    for (pos = (stateSelect.options.length - 1) ; pos >= 0 ; pos--) {
        if (stateSelect.options.remove) {
            stateSelect.options.remove(pos)
        } else {
            stateSelect.options[pos] = null;
        }
    }

    //Add instruction option
    stateSelect.options.add(new Option(), 0);
    stateSelect.options[0].text = "Please select a state to search within...";
    stateSelect.options[0].value = "";
    //Add health plan network options
    var insPos = 1;
    for (pos = 0 ; pos < stateArray.length ; pos++) {
        if (stateArray[pos][0] == matchPlan) {
            stateSelect.options.add(new Option(), insPos);
            stateSelect.options[insPos].text = stateArray[pos][2];
            stateSelect.options[insPos].value = stateArray[pos][1];
            insPos++;
        }
    } 
    stateSelect.value = selectedState;

}

/**********
 * Function to update the ancillary drop-down list based on the specified health plan
 */
function updateAncillaryList(healthPlan) {
    // clear the list
    var ancillaryList = document.getElementById("ancillary_type");
    for (pos = (ancillaryList.options.length - 1) ; pos >= 0 ; pos--) {
        if (ancillaryList.options.remove) {
            ancillaryList.options.remove(pos)
        } else {
            ancillaryList.options[pos] = null;
        }
    }

    var matchPlan = "default";
    if (healthPlan == "FirstHealth") {
        matchPlan = healthPlan;
    }

    var insPos = 0;
    for (pos = 0 ; pos < ancillaryArray.length ; pos++) {
        if (ancillaryArray[pos][0] == matchPlan) {
            ancillaryList.options.add(new Option(), insPos);
            ancillaryList.options[insPos].text = ancillaryArray[pos][1];
            ancillaryList.options[insPos].value = ancillaryArray[pos][2];
            insPos++;
        }
    } 
}

/**********
 * Function invoked when the health plan is changed.   This function calls
 * several other functions to change the contents of the screen based 
 * on the specified health plan.
 */
function selectHealthPlan(healthPlan) {
    var hp_img_id = (healthPlan + "_img_id");
    var hp_link_id = (healthPlan + "_link_id");
    var previousHealthPlan = document.getElementById("health_plan_id").value;
    if (previousHealthPlan != "") {
        var prev_img_id = (document.getElementById("health_plan_id").value + "_img_id");
        var prev_link_id = (document.getElementById("health_plan_id").value + "_link_id");
        document.getElementById(prev_img_id).src="/assets/images/one_pixel_transparent.gif";
    }
    document.getElementById(hp_img_id).src="/assets/images/red_arrow_right.gif";
    document.getElementById("health_plan_id").value = healthPlan;
    updateNetworkList(healthPlan);
    updateStateList(healthPlan);
    updateSpecialtyList(healthPlan);
    updateAncillaryList(healthPlan);
    updateHealthPlanLogo(healthPlan);
    if (healthPlan == "PHCS") {
        hideNetworkDropDown();
        displayCardTab("front");
        document.getElementById("city_optional").innerHTML = "";
        document.getElementById("county_optional").innerHTML = "";
    } else {
        hideCardTab();
        displayNetworkDropDown();
        document.getElementById("city_optional").innerHTML = "<font class=\"hl-12px-bold-blue-text\">(Optional)</font>";
        document.getElementById("county_optional").innerHTML = "<font class=\"hl-12px-bold-blue-text\">(Optional)</font>";
    }
}

/**********
 * Function called when the network is changed.   This function allows
 * special/miscellaneous handling to take place based on the network selected.
 */
function processNetworkSelection() {
    var networkSelect = document.getElementById("network_id");
    var selectedOption = networkSelect.options[networkSelect.selectedIndex].value;
    if (selectedOption == "HPO") {
	    openExternalWindowII("The HPO network is a travel network outside of the EHC and HealthLink network service areas.","http://www.hpoltd.com/","Health Payors Organization (HPO, Ltd)","hpoltd");
	    networkSelect.selectedIndex = 1;
    }
}

function displayHelpPopup(sourceObject, sourceEvent, title, content) {
    try {
        document.getElementById("help_title_id").innerHTML = title;
        document.getElementById("help_content_id").innerHTML = content;
        domTT_activate(sourceObject, sourceEvent, "content", document.getElementById("help_content_div_id"));
    } catch (err) {
    }
}

/**********
 *  Zip code radius disclaimer text
 */
var zipRadiusDisclaimerText = "<br/><font class='hl-12px-bold-red-text'><i><b>Please note:</b></font> <font color='#A90533'>The mile radius from a given zip code is not an indicator of the drive time to a provider's office or medical facility. Please use the &quot;Map It&quot; function to determine the actual distance and estimated time traveled.</i></font>";
function displayOrHideZipRadiusDisclaimer() {
    if (document.getElementById("location_zip_id").checked == true) {
        document.getElementById("zip_radius_disclaimer_div_id").innerHTML = zipRadiusDisclaimerText;
    } else {
        document.getElementById("zip_radius_disclaimer_div_id").innerHTML = "";
    }                        
}

/**
 *  This method is no longer used
 */
function validateFormAndDisplayProgressIndicator() {
    var validData;
    var buttonDiv = document.getElementById("button_div");
    var progressDiv = document.getElementById("progress_indicator_div");
    validData = validateFormData();
    if (validData == true) {
        buttonDiv.style.visibility = "hidden";
        buttonDiv.style.display = "none";
        progressDiv.style.visibility = "visible";
        progressDiv.style.display = "block";
        setTimeout("resetProgressImage()",100);
    }
    return validData;
}

/**
 *  This method is no longer used
 */
function displayPageChangeProgressIndicator() {
    var buttonDiv = document.getElementById("button_div");
    var progressDiv = document.getElementById("progress_indicator_div");
    buttonDiv.style.visibility = "hidden";
    buttonDiv.style.display = "none";
    progressDiv.style.visibility = "visible";
    progressDiv.style.display = "block";
    setTimeout("resetProgressImage()",100);
}

// Internet Explorer halts annimated gif images when the form
// is submitted.   This function (used with setTimeout) restarts the annimation.
function resetProgressImage() {
    var progressImage = document.getElementById("progress_image_id");
    progressImage.src = progressImage.src;
}


/**********
 *   PHCS specific scripts (only when the health plan is PHCS)
 */

function hideNetworkDropDown() {
    var ddDiv = document.getElementById("network_dropdown_div");
    ddDiv.style.visibility = "hidden";
    ddDiv.style.display = "none";
}

function displayNetworkDropDown() {
    var ddDiv = document.getElementById("network_dropdown_div");
    ddDiv.style.visibility = "visible";
    ddDiv.style.display = "block";
}

function displayCardTab(side) {
    var frontLogo = "";
    var networkProgram = "";
    if (document.getElementById("hl_front_id").checked == true) {
        frontLogo = "hl";
        var networkProgramSelect = document.getElementById("hl_network_program_front_id");
        for (var pos = 0 ; pos < networkProgramSelect.options.length ; pos++) {
            if (networkProgramSelect.options[pos].selected == true) {
                networkProgram = networkProgramSelect.options[pos].value;
                break;
            }
        }
    } else if (document.getElementById("phcs_front_id").checked == true) {
        frontLogo = "phcs";
    }

    if (side == "back") {
        if (frontLogo == "") {
            alert("Please select the logo that appears on the\nfront of your card.");
            document.location.href = "#step1";
            return;
        } else if ((frontLogo == "hl") && (networkProgram == "")) {
            alert("Please select the network program that appears\non the front of your card.");
            document.location.href = "#step1";
            return;
        }
    }

    var tabDiv = null;
    hideCardTab();
    if (side == "back") {
       tabDiv = document.getElementById("back_card_icon_div");
    } else if (side == "front") {
       tabDiv = document.getElementById("front_card_icon_div");
    }
    tabDiv.style.visibility = "visible";
    tabDiv.style.display = "block";

    cardDiv = document.getElementById("card_div");
    cardDiv.style.visibility = "visible";
    cardDiv.style.display = "block";

    var phcsInnerBackDiv = document.getElementById("phcs_on_front_inner_div");
    var hlInnerBackDiv = document.getElementById("hl_on_front_inner_div");
    if (frontLogo == "phcs") {
        hlInnerBackDiv.style.visibility = "hidden";
        hlInnerBackDiv.style.display = "none";
        phcsInnerBackDiv = document.getElementById("phcs_on_front_inner_div");
        phcsInnerBackDiv.style.visibility = "visible";
        phcsInnerBackDiv.style.display = "block";
    } else {
        phcsInnerBackDiv.style.visibility = "hidden";
        phcsInnerBackDiv.style.display = "none";
        hlInnerBackDiv = document.getElementById("hl_on_front_inner_div");
        hlInnerBackDiv.style.visibility = "visible";
        hlInnerBackDiv.style.display = "block";
    }
    updateCard();
}

function resetCard() {
    document.getElementById("phcs_ppo_back_id").checked = false;
    document.getElementById("hl_multiplan_back_id").checked = false;
    document.getElementById("hl_back_id").checked = false;
    document.getElementById("phcs_multiplan_back_id").checked = false;
    updateCard();
}

/**********
 * This function is invoked any time a change is made that impacts the PHCS network selection
 */
function updateCard() {
    // Update the front of the card
    var showFrontNetworkPrograms = false;
    var showBackNetworkPrograms = false;
    var showPHCSLink = false;
    var frontImage = document.getElementById("card_front_logo_id");
    frontImage.src = "/assets/images/one_pixel_transparent.gif";
    if (document.getElementById("hl_front_id").checked == true) {
        frontImage.src = "/assets/images/icon_healthlink.gif";
        showFrontNetworkPrograms = true;
    } else if (document.getElementById("phcs_front_id").checked == true) {
        frontImage.src = "/assets/images/icon_phcs.gif";
        showPHCSLink = true;
        if (document.getElementById("hl_back_id").checked == true) {
            showBackNetworkPrograms = true;
        }
    } else {
        frontImage.src = "/assets/images/one_pixel_transparent.gif";
    }
  
    var hlFrontNetworkDiv = document.getElementById("hl_network_program_front_inner_div");
    if (showFrontNetworkPrograms == true) {
        hlFrontNetworkDiv.style.visibility = "visible";
        hlFrontNetworkDiv.style.display = "block";
    } else {
        hlFrontNetworkDiv.style.visibility = "hidden";
        hlFrontNetworkDiv.style.display = "none";
    }

    var phcsPrimaryDiv = document.getElementById("phcs_primary_div");
    if (showPHCSLink == true) {
        phcsPrimaryDiv.style.visibility = "visible";
        phcsPrimaryDiv.style.display = "block";
    } else {
        phcsPrimaryDiv.style.visibility = "hidden";
        phcsPrimaryDiv.style.display = "none";
    }

    // hide MultiPlan disclaimer
    var hlMultiplanDisclaimerDiv = document.getElementById("hl_multiplan_disclaimer_div");
    hlMultiplanDisclaimerDiv.style.visibility = "hidden";
    hlMultiplanDisclaimerDiv.style.display = "none";
    var phcsMultiplanDisclaimerDiv = document.getElementById("phcs_multiplan_disclaimer_div");
    phcsMultiplanDisclaimerDiv.style.visibility = "hidden";
    phcsMultiplanDisclaimerDiv.style.display = "none";
    
    // Update the back of the card
    var backMiddleImage = document.getElementById("card_back_middle_logo_id");
    if (document.getElementById("phcs_ppo_back_id").checked == true) {
        backMiddleImage.src = "/assets/images/icon_phcs_ppo.gif";
    } else if (document.getElementById("hl_back_id").checked == true) {
        backMiddleImage.src = "/assets/images/icon_healthlink.gif";
        showBackNetworkPrograms = true;
    } else {
        backMiddleImage.src = "/assets/images/one_pixel_transparent.gif";
    }

    var hlBackNetworkDiv = document.getElementById("hl_network_program_back_inner_div");
    if (showBackNetworkPrograms == true) {
        hlBackNetworkDiv.style.visibility = "visible";
        hlBackNetworkDiv.style.display = "block";
    } else {
        hlBackNetworkDiv.style.visibility = "hidden";
        hlBackNetworkDiv.style.display = "none";
    }

    var backBottomImage = document.getElementById("card_back_bottom_logo_id");
    if (document.getElementById("phcs_multiplan_back_id").checked == true) {
        backBottomImage.src = "/assets/images/icon_multiplan.gif";
        phcsMultiplanDisclaimerDiv.style.visibility = "visible";
        phcsMultiplanDisclaimerDiv.style.display = "block";        
    } else if (document.getElementById("hl_multiplan_back_id").checked == true) {
        backBottomImage.src = "/assets/images/icon_multiplan.gif";
        hlMultiplanDisclaimerDiv.style.visibility = "visible";
        hlMultiplanDisclaimerDiv.style.display = "block";
    } else {
        backBottomImage.src = "/assets/images/one_pixel_transparent.gif";
    }

    //Set the appropriate network
    var hlFrontNetworkDropdown = document.getElementById("hl_network_program_front_id");
    var hlBackNetworkDropdown = document.getElementById("hl_network_program_back_id");
    var selectedNetwork = "";
    if (document.getElementById("hl_front_id").checked == true) {
        if (hlFrontNetworkDropdown.selectedIndex >= 0) {
            if (hlFrontNetworkDropdown.options[hlFrontNetworkDropdown.selectedIndex].value == "PPO") {
                selectedNetwork = "PHCS_E_PPO";
            } else if (hlFrontNetworkDropdown.options[hlFrontNetworkDropdown.selectedIndex].value == "OA1") {
                selectedNetwork = "PHCS_E_OA1";
            } else if (hlFrontNetworkDropdown.options[hlFrontNetworkDropdown.selectedIndex].value == "OA2") {
                selectedNetwork = "PHCS_E_OA2";
            } else if (hlFrontNetworkDropdown.options[hlFrontNetworkDropdown.selectedIndex].value == "OA3") {
                selectedNetwork = "PHCS_E_OA3";
            }
        } else {
            selectedNetwork = "PHCS_E_PPO";
        }
    } else if (document.getElementById("phcs_front_id").checked == true) {
        if (document.getElementById("hl_back_id").checked == true) {
            if (hlBackNetworkDropdown.selectedIndex >= 0) {
                if (hlBackNetworkDropdown.options[hlBackNetworkDropdown.selectedIndex].value == "PPO") {
                    selectedNetwork = "PHCS_P_PPO";
                } else if (hlBackNetworkDropdown.options[hlBackNetworkDropdown.selectedIndex].value == "OA1") {
                    selectedNetwork = "PHCS_P_OA1";
                } else if (hlBackNetworkDropdown.options[hlBackNetworkDropdown.selectedIndex].value == "OA2") {
                    selectedNetwork = "PHCS_P_OA2";
                } else if (hlBackNetworkDropdown.options[hlBackNetworkDropdown.selectedIndex].value == "OA3") {
                    selectedNetwork = "PHCS_P_OA3";
                }
            } else {
                selectedNetwork = "PHCS_P_PPO";
            }
        } else {
            selectedNetwork = "PHCS_PRIMARY";
        }
    }
    // Now set the selected option
    var networkDropdown = document.getElementById("network_id");
    networkDropdown.options[0].selected = true;
    for (var pos = 0 ; pos < networkDropdown.options.length ; pos++) {
        if (networkDropdown.options[pos].value == selectedNetwork) {
            networkDropdown.options[pos].selected = true;
            break;
        }
    }

}

function hideCardTab() {
    var tabDiv = document.getElementById("front_card_icon_div");
    tabDiv.style.visibility = "hidden";
    tabDiv.style.display = "none";
    tabDiv = document.getElementById("back_card_icon_div");
    tabDiv.style.visibility = "hidden";
    tabDiv.style.display = "none";
    var cardDiv = document.getElementById("card_div");
    cardDiv.style.visibility = "hidden";
    cardDiv.style.display = "none";
}


//-->
