// JavaScript Document
var W3CDOM = (document.getElementsByTagName && document.createElement);

window.onload = function () {
	document.forms[0].onsubmit = function () {
		return validate()
	}
}

function validate()
{
	validForm = true;
	firstError = null;
	errorstring = '';
	
	var x = document.forms[0].elements;
//-------------------------------name-------------------------//		
if (!x['state'].value)
{
writeError(x['state'],'*');
}

if (!x['zipcode'].value)
{
writeError(x['zipcode'],'*');
}

if(x['state'].value==''&&x['zipcode'].value==''){
writeError(x['display'],'* Required');}
else{

if (x['zipcode'].value.length==5)
{}
else{writeError(x['zipcode'],'*');

	writeError(x['display'],'* Check Zipcode');
}
}


			
	if (!W3CDOM)
		alert(errorstring);
	
	if (firstError)
		firstError.focus();
	
	if (validForm)
	{
		//confirm('Please check to see if all data entered in form is is valid!');
	}
	return validForm;
}

function writeError(obj,message)
{
	validForm = false;
	if (obj.hasError) return;
	if (W3CDOM)
	{
		//obj.className += ' errormessage';
		obj.onchange = removeError;
		var sp = document.createElement('span');
		sp.className = 'errormessage';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else
	{
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	if (!firstError)
		firstError = obj;
}

function removeError()
{
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}


function autoTab(element, nextElement) {
if (element.value.length == element.maxLength && nextElement != null) {
element.form.elements[nextElement].focus();
}
}

//The first line assigns the MatchIgnoreCase function as an equalsIgnoreCase method of the String object

String.prototype.equalsIgnoreCase=MatchIgnoreCase;

function MatchIgnoreCase(strTerm){
var strToSearch = this.toLowerCase();
strTerm = strTerm.toLowerCase();
if(strToSearch==strTerm){
return true;
}else
{
return false;
}
} 




