// JavaScript Document
    var countries = new Array();
    var statesArray = new Array();
    var countryElement = document.getElementById("country");
    var stateElement = document.getElementById("state_province");
    if (countryElement) {
        addCountry("USA", "AL;AK;AZ;AR;CA;CO;CT;DE;FL;GA;HI;ID;IL;IN;IA;KS;KY;LA;ME;MD;MA;MI;MN;MS;MO;MT;NE;NV;NH;NJ;NM;NY;NC;ND;OH;OK;OR;PA;RI;SC;SD;TN;TX;UT;VT;VA;WA;WV;WI;WY");
        addCountry("Canada", "AB;BC;MB;NB;NL;NS;NT;NU;ON;PE;QC;SK;YT");
        countryElement.onchange=changeCountry;
    }

    function addCountry(country, statesText) {
        countries[country] = country;
        statesArray[country] = statesText.split(";");
        var option = createOption(country, country);
        countryElement.options.add(option)
    }

    function changeCountry() {
        var currentCountry = countryElement.value;
        stateElement.options.length = 0;
        stateElement.options.add(createOption("Select One", ""));
        if (currentCountry) {
            var states = statesArray[currentCountry];
            for (var i = 0; i < states.length; i++) {
                stateElement.options.add(createOption(states[i], states[i]));
            }
        }
    }

    function createOption(text, value) {
        var option = new Option();
        option.value = value;
        option.text = text;
        return option;
    }

    function beforeSubmit() {
        var currentInput;
        currentInput = document.getElementsByName("email_address")[0];
        if(currentInput.value==""){
            alert("Email Address is required.");
            currentInput.focus();
            return false;
        }
            
            
			var emailaddress = currentInput.value;		
			var emailconfirm = document.getElementById("_for_validation_email_confirmation").value;
					
			  if (checkemail(emailaddress)==false){
		currentInput.value=""
		currentInput.focus()
		return false
     	} 
			
			if(emailaddress!=emailconfirm){
				alert("I'm sorry - the email address you've entered doesn't match the email confirmation. Please ensure your email matches to complete your signup.");
				return false;
			}  
            
            
            
            
            
            

        var checkboxes = document.getElementsByName("mappingListsCheckBox");
        var list_ids="";
        for(var i=0;i<checkboxes.length;i++){
            if(checkboxes[i].checked)
               list_ids+=","+checkboxes[i].value;
        }
        document.getElementById("list_ids_hidden").value=list_ids.substring(1);
        if(list_ids==""){
            alert("Please select a list to subscribe to!");
            return false;
        }
        
        return true;
    }
    

	function checkemail(str){
		var testresults
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
		testresults=true
		else{
		alert("Please input a valid email address!")
		testresults=false
		}
		return (testresults)
	}
