﻿// JScript File
var separatorCharacter = "----";
	function State_Change(SelectField, OtherField, textVisibleStyle, textHiddenStyle) 
	{
	    var indexNum = SelectField.selectedIndex;
		if (SelectField[indexNum].text == 'APO/FPO')
		{
			MM_findObj(OtherField).className = textVisibleStyle;
		}
		else 
		{
			MM_findObj(OtherField).className = textHiddenStyle;
			MM_findObj(OtherField).value = "";
		}
	}
	
	function Country_Change(CountrySelectField, CountryOtherField, StateSelectField, StateOtherField, textVisibleStyle, textHiddenStyle, selectVisibleStyle, selectHiddenStyle) 
	{
		/*
		if (CountrySelectField.options[CountrySelectField.selectedIndex].text.toLowerCase() == "other")
		{
			//Other
			MM_findObj(CountryOtherField).className = textVisibleStyle;
			MM_findObj(StateOtherField).className = textVisibleStyle;
			//MM_findObj(StateSelectField).selectedIndex = MM_findObj(StateSelectField).length-1;
			MM_findObj(StateSelectField).selectedIndex = 0;
			MM_findObj(StateSelectField).className = selectHiddenStyle;
		}
		else 
		*/
		if (CountrySelectField.options[CountrySelectField.selectedIndex].text.toLowerCase() == "united states")
		{
			//United States
			MM_findObj(CountryOtherField).className = textHiddenStyle;
			MM_findObj(StateOtherField).className = textHiddenStyle;
			MM_findObj(CountryOtherField).value = "";
			MM_findObj(StateOtherField).value = "";
			
			//if (MM_findObj(StateSelectField).selectedIndex == MM_findObj(StateSelectField).length-1) 
			//{
				MM_findObj(StateSelectField).selectedIndex = 0;
			//}
			MM_findObj(StateSelectField).className = selectVisibleStyle;
		
		}
		else if ((CountrySelectField.options[CountrySelectField.selectedIndex].value == "") ||
		    (CountrySelectField.options[CountrySelectField.selectedIndex].text == separatorCharacter))
		{
		    //no country selected
		    MM_findObj(CountryOtherField).className = textHiddenStyle;
			MM_findObj(StateOtherField).className = textHiddenStyle;
			MM_findObj(StateSelectField).selectedIndex = MM_findObj(StateSelectField).length-1;
			MM_findObj(StateSelectField).className = selectHiddenStyle;
		}
		else 
		{
			//International
			MM_findObj(CountryOtherField).className = textHiddenStyle;
			MM_findObj(StateOtherField).className = textVisibleStyle;
			MM_findObj(StateSelectField).selectedIndex = MM_findObj(StateSelectField).length-1;
			MM_findObj(StateSelectField).className = selectHiddenStyle;
			
		}
	}
	
	function ValidateStateSelection(state, stateOther, country, ddlRequired, otherRequired)
	{
	    argsIsValid = true;
	    
	    if((state != null) && (stateOther != null) && (country != null) && (ddlRequired != null) && (otherRequired != null))
        {
            if(country.options[country.selectedIndex].value == null)
            {
                if (ddlRequired)
                    argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text == separatorCharacter)
            {
                if (ddlRequired)
                    argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text.toLowerCase() == "other")
            {
                if (stateOther.value.length == 0 && otherRequired)
                    argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text.toLowerCase() == "united states")
            {
                if(state.options[state.selectedIndex].value == "")
                {
                    if (ddlRequired)
                        argsIsValid = false;
                }
                else if(state.options[state.selectedIndex].value != "")
                {
                    argsIsValid = true;
                }
            }
            else if((country.options[country.selectedIndex].value == ""))
            {
                if (ddlRequired)
                    argsIsValid = false;
            }
            else
            {
                if (stateOther.value.length == 0 && otherRequired)
                    argsIsValid = false;
            }
        }
        else
            argsIsValid = false;
        
        return argsIsValid;
	}
	
	
	function ValidateCountrySelection(country, countryOther, ddlRequired, otherRequired)
	{
	    argsIsValid = true;
	    
	    if((country != null) && (countryOther != null) && (ddlRequired != null) && (otherRequired != null))
        {
            if(country.options[country.selectedIndex].value == null)
            {
                if (ddlRequired)
                    argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text == null)
            {
                if (ddlRequired)
                    argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text == separatorCharacter)
            {
                if (ddlRequired)
                    argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text.toLowerCase() == "other")
            {
                if (countryOther.value.length == 0 && otherRequired)
                {
                    argsIsValid = false;
                }
            }
            else if(country.options[country.selectedIndex].value == "")
            {
                if (ddlRequired)
                    argsIsValid = false;
            }
        }
        else
            argsIsValid = false;
        
        return argsIsValid;
	}