
// <![CDATA[
function display(obj,id1,id2, id3) {
txt = obj.options[obj.selectedIndex].value;
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
document.getElementById(id3).style.display = 'none';
if ( txt.match(id1) ) {
document.getElementById(id1).style.display = 'block';
}
if ( txt.match(id2) ) {
document.getElementById(id2).style.display = 'block';
}
if ( txt.match(id3) ) {
document.getElementById(id3).style.display = 'block';
}
}

function displayOtherBox(obj,id4) {
txt = obj.options[obj.selectedIndex].value;
document.getElementById(id4).style.display = 'none';
if ( txt.match(id4) ) {
document.getElementById(id4).style.display = 'block';
}

}
// ]]>

function checkWholeForm(theForm) {
	var error = "";
    var why = "";
    why += checkName(theForm.Name.value);
	why += checkAddress(theForm.Address.value);
	why += checkCity(theForm.City.value);
	why += checkState(theForm.State.value);
	why += checkZip(theForm.Zip.value);
    why += checkEmail(theForm.email.value);
	why += checkPhone(theForm.Phone.value);

	
	var re = /\S/;
    if (re.test(why)) {
       alert(why);
	   why = "";
	   error = "";
       return false;
    }
	return true;
}

function checkName(strval) {
	var error = "";
	var lnameFilter=/[a-zA-Z]{3,}/;
	if (!(lnameFilter.test(strval))) { 
		error = "Please enter a valid name.\n";
	}

	return error;
}

function checkAddress(strval) {
	var error = "";
	var AddressFilter=/[a-zA-Z]{5,}/;
	if (!(AddressFilter.test(strval))) { 
		error = "Please enter a valid Address.\n";
	}
	return error;
}

function checkCity(strval) {
	var error = "";
	var CityFilter=/[a-zA-Z]{3,}/;
	if (!(CityFilter.test(strval))) { 
		error = "Please enter a valid City.\n";
	}
	return error;
}
function checkState(strval) {
	var error = "";
	var StateFilter=/[a-zA-Z]{2,}/;
	if (!(StateFilter.test(strval))) { 
		error = "Please choose a state.\n";
	}
	return error;
}

function checkZip(strval) {
	var error = "";
	var ZipFilter=/^\d{5}([\-]\d{4})?$/;
	if (!(ZipFilter.test(strval))) { 
		error = "Please enter a valid zip code.\n";
	}
	return error;
}



function checkEmail(strval) {
	var error = "";
	var emailFilter=/^[A-Z0-9._%-]+\@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (!(emailFilter.test(strval))) { 
		   error = "Please enter a valid email address.\n";
	}

	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strval.match(illegalChars)) {
	   error = "The email address contains illegal characters.\n";
	}
	return error;
}

function checkPhone(strval_d) {
	var error = "";
	var stripped_d = strval_d.replace(/[\(\)\.\-\ ]/g, '');
    //strip out acceptable non-numeric characters
	
	if ((stripped_d.length == 10)) 
		{ 		
	    }
		else {
			error = "Please provide a valid phone number. Make sure you included an area code.\n";
		}
	return error;
}