var canada = ["Alberta","British Columbia", "Manitoba", "New Brunswick",
              "Newfoundland", "Northwest Territories", "Nova Scotia", "Nunavut",
              "Ontario", "Prince Edward Island", "Quebec", "Saskatchewan", "Yukon"];
var USA = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
            "Connecticut", "Delaware", "District of Columbia", "Florida",
            "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
            "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts",
            "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana",
            "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", 
            "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",
            "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
             "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington",
             "West Virginia", "Wisconsin", "Wyoming"];
             


Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) { 
			return true;
		}
	}
	return false;
}

function checkState(hdl){
    if(hdl.value != ""){
        if(document.getElementById("UserState")){ 
            var val = document.getElementById("UserState").options[document.getElementById("UserState").selectedIndex].text;        
            if(hdl.value == "USA"){
                if((val == 'Other') || canada.in_array(val)){
                    document.getElementById("UserState").value = '';
               }
            } else if(hdl.value == "Canada"){
                if((val == 'Other') || USA.in_array(val)){
                    document.getElementById("UserState").value = '';
               }
            } else {
               document.getElementById("UserState").value = 'Other';
            }
        }   
    }
}

function checkCountry(hdl){
    if(hdl.value != ""){
        if(document.getElementById("UserCountry")){ 
            var val = hdl.options[hdl.selectedIndex].text;
            if(USA.in_array(val)){
               document.getElementById("UserCountry").value = 'USA';
            } else if(canada.in_array(val)){
               document.getElementById("UserCountry").value = 'Canada';
            } else {
               document.getElementById("UserCountry").value = '';
            }
        }   
    }
}


