function validateForm(form)
{
	var zipPattern=/(^\d{5}$)|(^\D{1}\d{1}\D{1}\s\d{1}\D{1}\d{1}$)/;
	var emailPattern=/^[A-Za-z0-9][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	
	if (!emailPattern.test(form.email.value) || empty(strip(form.email.value)))
	{
		alert("Please enter a valid email address.");
		form.email.focus();
		return false;
	}
	if ( form.passwd.value == "" )
	{
		alert("Please enter a Password.");
		form.passwd.focus();
		return false;
	}
	if ( form.fname.value == "" )
	{
		alert("Please enter a contact name.");
		form.fname.focus();
		return false;
	}
	if ( form.fname.value.indexOf("|") != -1 )
	{
		alert("The contact name field cannot contain the pipe '|' character.");
		form.fname.focus();
		return false;
	}
	if ( form.businessname.value == "" )
	{
		alert("Please enter a business name.");
		form.businessname.focus();
		return false;
	}
	if ( form.businessname.value.indexOf("|") != -1 )
	{
		alert("The business name field cannot contain the pipe '|' character.");
		form.businessname.focus();
		return false;
	}
	if ( form.businesstype.value == "" )
	{
		alert("Please enter a business type.");
		form.businesstype.focus();
		return false;
	}
	if ( form.address.value == "" )
	{
		alert("Please enter an address.");
		form.address.focus();
		return false;
	}
	if ( form.address.value.indexOf("|") != -1 )
	{
		alert("The address field cannot contain the pipe '|' character.");
		form.address.focus();
		return false;
	}
	if ( form.city.value == "" )
	{
		alert("Please select a city.");
		form.city.focus();
		return false;
	}
	if ( form.city.value.indexOf("|") != -1 )
	{
		alert("The city field cannot contain the pipe '|' character.");
		form.city.focus();
		return false;
	}
	if ( form.state.value == "" )
	{
		alert("Please select a state or province.");
		form.state.focus();
		return false;
	}
	if ( form.state.value.indexOf("|") != -1 )
	{
		alert("The state/province field cannot contain the pipe '|' character.");
		form.state.focus();
		return false;
	}
	if (!zipPattern.test(form.zip.value) || empty(strip(form.zip.value)))
	{
		alert("Please enter a valid zip or postal code.");
		form.zip.focus();
		return false;
	}
	if (empty(strip(form.phone.value)))
	{
		alert("Please enter a phone.");
		form.phone.focus();
		return false;
	} else if (!validatePhone(form.phone.value)) {
		alert("Please enter a valid phone.  Format 111-111-1111.");
		form.phone.focus();
		return false;
	}
	if (!empty(strip(form.fax.value)))
	{
		if (!validatePhone(form.fax.value)) {
			alert("Please enter a valid fax.  Format 111-111-1111.");
			form.fax.focus();
			return false;
		}
	}
	if ( form.contactTime.value.indexOf("|") != -1 )
	{
		alert("The fax field cannot contain the pipe '|' character.");
		form.contactTime.focus();
		return false;
	}
	
	if ( form.comments.length > 255 )
	{
		alert("The maximum length of the comments field is 255 characters.");
		form.comments.focus();
		return false;
	}
	if ( form.comments.value.indexOf("|") != -1 )
	{
		alert("The comments field cannot contain the pipe '|' character.");
		form.comments.focus();
		return false;
	}
	if ( form.agree.checked == false )
	{
		alert("You have to agree to our terms and conditions.");
		form.agree.focus();
		return false;
	}
	
}

function twoFiftyChar()
{
	document.request.commentsCount.value = 255 - document.request.comments.value.length
	if( document.request.commentsCount.value < 0 )
	{
		tooLong = document.request.comments.value.length
		cutOff = tooLong - 255
		alert("The comments entry has a maximum length of 255 characters, your entry has been trimmed to fit that length.")
		document.request.comments.value = document.request.comments.value.slice(0, -cutOff)
		document.request.commentsCount.value = 255 - document.request.comments.value.length
	}
}


function empty(x) { 
    if (x.length > 0) {
		return false; 
    }
    return true;    
}
function strip(x) {
    if (x.length < 1) { 
		return x;
    } 
    return x.replace(/^\s+|\s+$/g,'');
}

function validatePhone(phone) {
	var filter = /^[1-9]\d{2}-\d{3}-\d{4}$/;
	if (!filter.test(strip(phone))) {
		return false;
	}
	return true;
}


function validateCoupon(formcp) {
	if ( formcp.cplbl.value == "" )
	{
		alert("Please enter a Coupon Label.");
		formcp.cplbl.focus();
		return false;
	}
	
	if ( formcp.coupons.length > 100 )
	{
		alert("The maximum length of the Coupons field is 100 characters.");
		formcp.coupons.focus();
		return false;
	}
	if ( formcp.coupons.value.indexOf("|") != -1 )
	{
		alert("The coupons field cannot contain the pipe '|' character.");
		formcp.coupons.focus();
		return false;
	}
	if ( formcp.coupons.value == "" )
	{
		alert("Please enter Coupon Description.");
		formcp.coupons.focus();
		return false;
	}

	if ( formcp.category.value == "null" )
	{
		alert("Please Select a Category.");
		formcp.category.focus();
		return false;
	}

}

function validateOCoupon(formcp) {
		
	if ( formcp.cptype.value == "null" )
	{
		alert("Please Select a Coupon type.");
		formcp.cptype.focus();
		return false;
	}
	
	if ( formcp.cplbl.value == "" )
	{
		alert("Please enter a Coupon Label.");
		formcp.cplbl.focus();
		return false;
	}
	
	if ( formcp.coupons.length > 100 )
	{
		alert("The maximum length of the Coupons field is 100 characters.");
		formcp.coupons.focus();
		return false;
	}
	if ( formcp.coupons.value.indexOf("|") != -1 )
	{
		alert("The coupons field cannot contain the pipe '|' character.");
		formcp.coupons.focus();
		return false;
	}
	
	if ( formcp.category.value == "null" )
	{
		alert("Please Select a Category.");
		formcp.category.focus();
		return false;
	}

}

function ThreeHundredChar()
{
	document.request.couponsCount.value = 300 - document.request.coupons.value.length
	if( document.request.couponsCount.value < 0 )
	{
		tooLong = document.request.coupons.value.length
		cutOff = tooLong - 300
		alert("The comments entry has a maximum length of 255 characters, your entry has been trimmed to fit that length.")
		document.request.coupons.value = document.request.coupons.value.slice(0, -cutOff)
		document.request.couponsCount.value = 300 - document.request.coupons.value.length
	}
}
function validateDetail(formcp) {
	
	if ( formcp.about.length > 500 )
	{
		alert("The maximum length of the Coupons field is 500 characters.");
		formcp.coupons.focus();
		return false;
	}
	if ( formcp.about.value.indexOf("|") != -1 )
	{
		alert("The coupons field cannot contain the pipe '|' character.");
		formcp.about.focus();
		return false;
	}
		if ( formcp.about.value == "" )
	{
		alert("Please enter about your business.");
		formcp.about.focus();
		return false;
	}
}
function fiveHundredChar()
{
	document.request.aboutCount.value = 500 - document.request.about.value.length
	if( document.request.aboutCount.value < 0 )
	{
		tooLong = document.request.about.value.length
		cutOff = tooLong - 500
		alert("The comments entry has a maximum length of 255 characters, your entry has been trimmed to fit that length.")
		document.request.about.value = document.request.about.value.slice(0, -cutOff)
		document.request.aboutCount.value = 500 - document.request.about.value.length
	}
}

function adminregValidate(admform)
{
	if ( admform.reguname.value == "" )
	{
		alert("Please enter a Username.");
		admform.reguname.focus();
		return false;
	}
	if ( admform.regpass.value == "" )
	{
		alert("Please enter Password.");
		admform.regpass.focus();
		return false;
	}
	if ( admform.regpass.value != admform.passconf.value )
	{
		alert("Your passwords does not match.");
		admform.regpass.focus();
		return false;
	}
}

function adminloginValidate(admform)
{
	if ( admform.uname.value == "" )
	{
		alert("Please enter a Username.");
		admform.uname.focus();
		return false;
	}
	if ( admform.passwd.value == "" )
	{
		alert("Please enter Password.");
		admform.passwd.focus();
		return false;
	}
}

function validateLocation(locform)
{
	if ( locform.address.value == "" )
	{
		alert("Please enter an address.");
		locform.address.focus();
		return false;
	}
	if ( locform.address.value.indexOf("|") != -1 )
	{
		alert("The address field cannot contain the pipe '|' character.");
		locform.address.focus();
		return false;
	}
	if ( locform.city.value == "" )
	{
		alert("Please select a city.");
		locform.city.focus();
		return false;
	}
	if ( locform.city.value.indexOf("|") != -1 )
	{
		alert("The city field cannot contain the pipe '|' character.");
		locform.city.focus();
		return false;
	}
	if ( locform.state.value == "" )
	{
		alert("Please select a state or province.");
		locform.state.focus();
		return false;
	}
	if ( locform.state.value.indexOf("|") != -1 )
	{
		alert("The state/province field cannot contain the pipe '|' character.");
		locform.state.focus();
		return false;
	}
	if (!zipPattern.test(locform.zip.value) || empty(strip(locform.zip.value)))
	{
		alert("Please enter a valid zip or postal code.");
		locform.zip.focus();
		return false;
	}
	if (empty(strip(locform.phone.value)))
	{
		alert("Please enter a phone.");
		locform.phone.focus();
		return false;
	} else if (!validatePhone(locform.phone.value)) {
		alert("Please enter a valid phone.  Format 111-111-1111.");
		locform.phone.focus();
		return false;
	}
	if (!empty(strip(locform.fax.value)))
	{
		if (!validatePhone(locform.fax.value)) {
			alert("Please enter a valid fax.  Format 111-111-1111.");
			locform.fax.focus();
			return false;
		}
	}
}


function validateFogotpass(formf)
{
	var zipPattern=/(^\d{5}$)|(^\D{1}\d{1}\D{1}\s\d{1}\D{1}\d{1}$)/;
	var emailPattern=/^[A-Za-z0-9][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	
	if (!emailPattern.test(formf.femail.value) || empty(strip(formf.femail.value)))
	{
		alert("Please enter a valid email address.");
		formf.femail.focus();
		return false;
	}
	
	if (!zipPattern.test(formf.fzip.value) || empty(strip(formf.fzip.value)))
	{
		alert("Please enter a valid zip or postal code.");
		formf.fzip.focus();
		return false;
	}
	
}
