// Gift Certificate Form verification// Copyright © 2004 by gregerb.com, All rights reserved//// dependencies : none////regular expression variablesvar phoneRE= /\(?\d{3}\)?([-\s\.]?)\d{3}([-\s\.]?)\d{4}/var emailRE= /.*\@.*\..*/var zipRE=/[0-9]{5}/var nameRE=/[A-Z]+\s+[A-Z]+/function validate(){	with (document.forms.myform){		// convert input to upper or lower case		NAME.value=NAME.value.toUpperCase();		ADDRESS.value=ADDRESS.value.toUpperCase();		// remove punctuation		ADDRESS.value=ADDRESS.value.replace(/\./g,"");		CITY.value=CITY.value.toUpperCase();		NAMETOSHIP.value=NAME.value;		ADDRESSTOSHIP.value=ADDRESS.value;		CITYTOSHIP.value=CITY.value;		STATETOSHIP.value=STATE.value		ZIPTOSHIP.value=ZIP.value;		EMAIL.value=EMAIL.value.toLowerCase();			// check for name, both first and last		if (NAME.value.length<1){			window.alert("**NOTE: You must enter your FIRST and LAST NAME before continuing.");			NAME.focus();			return;		}		else {			OK=nameRE.exec(NAME.value)			if (!OK){				window.alert("**NOTE: You must enter your FIRST and LAST NAME before continuing.");				NAME.focus();				return;			}		}				// check for address		if (ADDRESS.value.length<1){			window.alert("**NOTE: You must enter your STREET ADDRESS before continuing.");			ADDRESS.focus();			return;		};				// check for city		if (CITY.value.length<1){			window.alert("**NOTE: You must enter your CITY before continuing.");			CITY.focus();			return;		};				if (STATE.selectedIndex == 0){			window.alert("**NOTE: You must select the STATE before continuing.");			STATE.focus();			return;		};			// check for city		if (ZIP.value.length<1){			window.alert("**NOTE: You must enter your ZIP CODE before continuing.");			ZIP.focus();			return;		}		else {			OK=zipRE.exec(ZIP.value);			if (!OK){				window.alert("**NOTE: "+ZIP.value+" is not a properly formatted ZIP CODE.");				ZIP.focus();				return;			}		}			//check for valid phone number		if (PHONE.value.length>1){			OK=phoneRE.exec(PHONE.value);			if (!OK){				window.alert(PHONE.value+" isn't a proper phone number [ddd-ddd-dddd].");				PHONE.focus();				return;			}			else {				// pretty format phnone number				PHONE.value=PHONE.value.replace(/[\s()-.]/g,"");				PHONE.value=PHONE.value.substring(0,3)+"-"+PHONE.value.substring(3,6)+"-"+PHONE.value.substring(6,10)			}		}		else {			window.alert("**NOTE: You must enter your PHONE NUMBER before continuing.");			PHONE.focus();			return;		}			//check for valid email addr		if (EMAIL.value.length<1) {			window.alert("**NOTE: You must enter your EMAIL address before continuing.");			EMAIL.focus();			return;		}		else {			OK=emailRE.exec(EMAIL.value)			if (!OK) {				window.alert(EMAIL.value+" isn't a properly formatted email address.");				EMAIL.focus();				return;			};		};	};	document.forms.myform.submit();};	function calculate() {	with (document.forms.myform){		quantity.value= parseInt(quantity.value);		if (quantity.value==0) quantity.value=1;		total.value = 5 * (	quantity.value)+".00";		AMOUNT.value=	total.value;		DESCRIPTION.value=	quantity.value+" Gift Certificate(s)";	};};