// User-side JavaScript Functions
function vNews(f) {
	x=cleanVar(f.email.value);
	if (!validEmail(x)) {
		alert("Please enter a valid email address.");
		f.email.select();
		return false;
	}
}
function vMovies(f) {
	x=cleanVar(f.txtCityZip.value);
	if (x=='') {
		what = (f.searchby.options[f.searchby.selectedIndex].value==1) ? 'Movie Title' : 'Zip Code/City';
		alert("Please enter a "+what+".");
		f.txtCityZip.select();
		return false;
	}
}

//SUBFUNCTIONS
function cleanVar(cleaned) {
	cleaned=cleaned.replace(/^[ ]+([^ ]*)/, "$1"); //remove beginning spaces
	cleaned=cleaned.replace(/([^ ]*)[ ]+$/, "$1"); //remove ending spaces
	cleaned=cleaned.replace(/\s*/, ""); //remove white space characters
	return cleaned;
}

function validEmail(email) {
	invalidChars = " /:,;'";
	if (email == "" ) {
		return false;
	}
	for ( i = 0; i<invalidChars.length;  i++) {
		badChar=invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			//alert("Bad character["+ badChar +"]")
			return false
		}
	}
	atPos=email.indexOf("@",1)
	if (atPos== -1 ) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1 ) {
		return false
	}
	periodPos=email.indexOf(".",atPos)
	if (periodPos== -1 ) {
		return false
	}
	if (periodPos+3 > email.length ) {
		return false
	}
	return true
}