
var onSubmit = function()
{
	var ret = false;
	
	var StateEle, CountryEle, zipEle, organizationEle, occupationEle;
	
	if (document.getElementById("action").value == "unsubscribe")
	{
		if (FormValidation.requiredValidator([  {elementId:"Email", label:"Email Address"}]))
		{
			ret = FormValidation.validateEmailByEleId("Email");
		}
	}
	else
	{
		if (FormValidation.requiredValidator([  {elementId:"Email", label:"Email Address"}, 
												{elementId:"Country", label:"Country"}]))
		{
			if (FormValidation.validateEmailByEleId("Email")) {
				StateEle = document.getElementById("State");
				CountryEle = document.getElementById("Country");
				zipEle = document.getElementById("Zip");
		    organizationEle = document.getElementById("Organization");
        occupationEle = document.getElementById("Occupation");
        if (StateEle.selectedIndex == 0 && (CountryEle.value == "Canada" || CountryEle.value == "United States")) {
					FormValidation.selectElement(StateEle);
		      window.alert("State cannot be blank, it is required for the selected Country.");
				} else if (zipEle.value.length == 0 && (CountryEle.value == "United States")) {
					FormValidation.selectElement(zipEle);
		      window.alert("Zip Code cannot be blank, it is required for the United States");
        } else if (occupationEle.value.length == 0) {
          FormValidation.selectElement(occupationEle);
          window.alert("Occupation cannot be blank");
        } else if (organizationEle.value.length == 0) {
          FormValidation.selectElement(organizationEle);
          window.alert("Organization cannot be blank");
        } else {
					if (CountryEle.value != "United States" && CountryEle.value !="Canada")
					{
						StateEle.selectedIndex = 0;
					}
					if (CountryEle.value != "United States" )
					{
						zipEle.value = "";
					}
					ret = true;
				}
			}
		}
	}
  return ret;
}

var startList = function() 
{
	var i;
	var node;
	var navRoot = document.getElementById("nav");
	
	for (i = 0; i < navRoot.childNodes.length; i++) 
	{
		node = navRoot.childNodes[i]; 
		if (node.nodeName=="LI") 
		{ 
			node.onmouseover = function() { 
				this.className+=" over"; 
			};
			node.onmouseout = function() { 
				this.className=this.className.replace(" over", ""); 
			}; 
		} 
	}
};

var initDropDowns = function()
{
	document.getElementById("Country").onchange = function()
	{
		if (this.value != "United States" && this.value !="Canada")
		{
			document.getElementById("State").selectedIndex = 0;
		}
	};
	
	document.getElementById("action").onchange = function()
	{
		if (this.value == "unsubscribe")
		{
			document.getElementById("arch_unsubscribe_form").style.display = "";
			document.getElementById("arch_subscribe_form").style.display = "none";
		}
		else
		{
			document.getElementById("arch_subscribe_form").style.display = "";
			document.getElementById("arch_unsubscribe_form").style.display = "none";
		}		
	};
};

window.onload = function() { initDropDowns();  startList(); };
