var catalogSelect = 0;

function radioSelected(e)
{
	var evalString = e + " = 1";
	eval (evalString);
}

function notZeroLength(e)
{
	return true;
}

function isIntegerNumber(s) 
{
	var i;
	for (i=0;i<s.length;i++)
	{
		var c = s.charAt(i);
		if ((c < "0") || (c > "9"))
		{
			return false;
		}
	}
	return true;
}

function isZipPostalCode(e)
{
	return true;	
}

function isPhoneNumber(e)
{
	var phoneNumberPattern = /^\d\d\d\-\d\d\d-\d\d\d\d$/;
	if (phoneNumberPattern.test(e))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validateSubmit(e)
{
	// check that a catalog has been selected
	if (catalogSelect == 0)
	{	
		e.button1.value='Submit';
		alert("You have not selected a catalog.");
		return false;
	}
	
	var done = 0;
	var errorString = "";
	var errorCondition = 0;
	// check required fields are filled
	while (done == 0)
	{
		if (e.email.value.length == 0)
		{
			errorString = "You have not entered an email address.";
			errorCondition = 1;
			focusField = "email";
			done = 1;
		}else if(e.email.value.length >40){
		    errorString = "Email address can not exceed 40 characters.";
			errorCondition = 1;
			focusField = "email";
			done = 1;		
		}
		
		if (e.zip.value.length == 0)
		{
			errorString = "You have not entered a zip/postal code.";
			errorCondition = 1;
			focusField = "zip";
			done = 1;
		}
		if (e.country.value == "--")
		{
			errorString = "You selected a state.";
			errorCondition = 1;
			focusField = "state";
			done = 1;
		}
		if (e.country.value == "--")
		{
			errorString = "You selected a country.";
			errorCondition = 1;
			focusField = "country";
			done = 1;
		}
		if (e.city.value.length == 0)
		{
			errorString = "You have not entered a city.";
			errorCondition = 1;
			focusField = "city";
			done = 1;
		}
		if (e.address1.value.length == 0)
		{
			errorString = "You have not entered an address.";
			errorCondition = 1;
			focusField = "address1";
			done = 1;
		}
		if (e.lastName.value.length == 0)
		{
			errorString = "You have not entered a last name.";
			errorCondition = 1;
			focusField = "lastName";
			done = 1;
		}
		if (e.firstName.value.length == 0)
		{
			errorString = "You have not entered a first name.";
			errorCondition = 1;
			focusField = "firstName";
			done = 1;
		}
		done = 1;
	}
	
	if (errorCondition == 1)
	{
		e.button1.value='Submit';
		alert(errorString);
		if (focusField != "")
		{
			eval("e." + focusField + ".focus()");
		}
		return false;
	}
	
	// check that fields are correctly formatted
	if ((!isPhoneNumber(e.phone.value))&&(e.phone.value.length > 0))
	{
		e.button1.value='Submit';
		alert("The phone number should be formatted as xxx-xxx-xxxx (i.e. 800-555-1212).");
		eval("e.phone.focus()");
		return false;
	}
	if (e.phone.value.length > 12)
	{
		e.button1.value='Submit';
		alert("The phone number should be formatted as xxx-xxx-xxxx (i.e. 800-555-1212).");
		eval("e.phone.focus()");
		return false;
	}	
	if ((!isPhoneNumber(e.fax.value))&&(e.fax.value.length > 0))
	{
		e.button1.value='Submit';
		alert("The fax number should be formatted as xxx-xxx-xxxx (i.e. 800-555-1212).");
		eval("e.fax.focus()");
		return false;
	}
	if (e.fax.value.length > 12)
	{
		e.button1.value='Submit';
		alert("The fax number should be formatted as xxx-xxx-xxxx (i.e. 800-555-1212).");
		eval("e.fax.focus()");
		return false;
	}
	

	var zip = e.zip.value;
	var result = "";
	if (e.country.value == "USA")
	{
		var pattern = /(^\d\d\d\d\d$)|(^\d\d\d\d\d-\d\d\d\d$)|(^\d\d\d\d\d \d\d\d\d$)/;
		var result = zip.match(pattern);
		if (result == null)
		{
			e.button1.value='Submit';
			alert("The zip code should be formatted as xxxxx or xxxxx-xxxx (i.e. 60061 or 54936-1939).");
			eval("e.zip.focus()");
			return false;
		}
	}
	else
	{
		var pattern = /^[a-zA-Z][0-9][a-zA-Z] [0-9][a-zA-Z][0-9]$/;
		result = zip.match(pattern);
		if (result == null)
		{
			e.button1.value='Submit';
			alert("The postal code should be formatted as LNL NLN (i.e. A1A 1A1).");
			eval("e.zip.focus()");
			return false;
		}
	}
	
	return true;
}


	USA = new Array(1);
	CAN = new Array(1);
	
	modelArrayPointer = new Array(1);
	modelArrayPointer[0] = USA;
	modelArrayPointer[1] = CAN;

		USA[0]="AL";
		USA[1]="AK";
		USA[2]="AR";
		USA[3]="AZ";
		USA[4]="CA";
		USA[5]="CO";
		USA[6]="CT";
		USA[7]="DC";
		USA[8]="DE";	
		USA[9]="FL";
		USA[10]="GA";
		USA[11]="HI";
		USA[12]="IA";
		USA[13]="ID";
		USA[14]="IL";
		USA[15]="IN";
		USA[16]="KS";
		USA[17]="KY";
		USA[18]="LA";
		USA[19]="MA";
		USA[20]="MD";
		USA[21]="ME";	
		USA[22]="MI";
		USA[23]="MN";
		USA[24]="MO";
		USA[25]="MS";
		USA[26]="MT";	
		USA[27]="NC";
		USA[28]="ND";
		USA[29]="NE";
		USA[30]="NH";
		USA[31]="NJ";
		USA[32]="NM";
		USA[33]="NV";
		USA[34]="NY";   
		USA[35]="OH";
		USA[36]="OK";
		USA[37]="OR";
		USA[38]="PA";
		USA[39]="RI";
		USA[40]="SC";
		USA[41]="SD";
		USA[42]="TN";
		USA[43]="TX";
		USA[44]="UT";
		USA[45]="VA";
		USA[46]="VT";	
		USA[47]="WA";
		USA[48]="WI";
		USA[49]="WV";	
		USA[50]="WY";
		USA[51]="AA";
		USA[52]="AE";
		USA[53]="AP";
		USA[54]="AS";
		USA[55]="FM";
		USA[56]="MH";
		USA[57]="MP";
		USA[58]="PE";
		USA[59]="PR";
		USA[60]="VI";		
	
		
		CAN[0]="AB";
		CAN[1]="BC";
		CAN[2]="MB";
		CAN[3]="NB";
		CAN[4]="NF";
		CAN[5]="NS";
		CAN[6]="NT";
		CAN[7]="NU";
		CAN[8]="ON";
		CAN[9]="PE";
		CAN[10]="PQ";
		CAN[11]="SK";
		CAN[12]="YT";
		
function changeCountry()
{
	var maxrow = 0;
	for(var g = 0; g < 61; g++)
	{
		document.catalogRequest.state.length = 0;
	}

	modelpointer = modelArrayPointer[document.catalogRequest.country.selectedIndex];
	if (document.catalogRequest.country.selectedIndex == 0)
	{  maxrow = 61}

	if (document.catalogRequest.country.selectedIndex == 1)
	{ maxrow = 13}

	var selIndex = 0;
	for (var g = 0; g < maxrow; g++) 
	{
		document.catalogRequest.state.options[g] = new Option(modelpointer[g]);
	}
	document.catalogRequest.state.selectedIndex = selIndex;
}
