﻿// JScript File

	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 == "")
		{
		    //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)
	{
	    argsIsValid = true;
	    
	    if((state != null) && (stateOther != null) && (country != null))
        {        
            if((country.options[country.selectedIndex].value == ""))
            {
                argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text.toLowerCase() == "other")
            {
                if (stateOther.value.length == 0)
                    argsIsValid = false;
            }
            else if(country.options[country.selectedIndex].text.toLowerCase() == "united states")
            {
                if(state.options[state.selectedIndex].value == "")
                    argsIsValid = false;
                else if(state.options[state.selectedIndex].value != "")
                    argsIsValid = true;
            }
            else
            {
                if (stateOther.value.length == 0)
                    argsIsValid = false;
            }
        }
        else
            argsIsValid = false;
        
        return argsIsValid;
	}
	
	
	function ValidateCountrySelection(country, countryOther)
	{
	    argsIsValid = true;
	    
	    if((country != null) && (countryOther != null))
        {
            if((country.options[country.selectedIndex].value == ""))
                argsIsValid = false;
            else if(country.options[country.selectedIndex].text.toLowerCase() == "other")
                if (countryOther.value.length == 0)
                    argsIsValid = false;
        }
        else
            argsIsValid = false;
        
        return argsIsValid;
	}