function submitForm(){
	if(validateForm()){
		document.frm.action = "send.php";
		document.frm.submit();
	}
}

function validateForm(){
	
	if(document.frm.nProduct == null || document.frm.nProduct.value == "")
	{
		alert("Please enter name of product or service.");
		cument.frm.nProduct.focus();
		return false;
	}
	if(document.frm.discount == null || document.frm.discount.value == "")
	{
		alert("Please enter discount offer.");
		cument.frm.discount.focus();
		return false;
	}
	if(document.frm.zipcode == null || document.frm.zipcode.value == "")
	{
		alert("Please enter zipcode of location.");
		cument.frm.zipcode.focus();
		return false;
	}
	if(document.frm.phone == null || document.frm.phone.value == "")
	{
		alert("Please enter contact telephone number.");
		cument.frm.phone.focus();
		return false;
	}
	if(document.frm.email == null || document.frm.email.value == "")
	{
		alert("Please enter E-mail.");
		cument.frm.email.focus();
		return false;
	}
	if(document.frm.email != null || document.frm.email.value != "")
	{
		var toMail = document.frm.email.value;
		if (!validateEmail(toMail))
		{
			alert ('Please enter a valid email.');
			document.frm.email.focus();
			return false;
	 	}
	}
	if(document.frm.category == null || document.frm.category.value == "")
	{
		alert("Please select listing category.");
		cument.frm.category.focus();
		return false;
	}
	if(document.frm.name == null || document.frm.name.value == "")
	{
		alert("Please enter your name.");
		cument.frm.name.focus();
		return false;
	}
	if(document.frm.contact == null || document.frm.contact.value == "")
	{
		alert("Please enter your contact number.");
		cument.frm.contact.focus();
		return false;
	}
	if(document.frm.comments == null || document.frm.comments.value == "")
	{
		alert("Please enter business or service description.");
		cument.frm.comments.focus();
		return false;
	}
	return true;
}
function validateEmail(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	if (str.indexOf(at) == -1) {
	   //alert("Invalid E-mail ID")
		return false;
	}
	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
	   //alert("Invalid E-mail ID")
		return false;
	}
	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
	    //alert("Invalid E-mail ID")
		return false;
	}
	if (str.indexOf(at, (lat + 1)) != -1) {
	    //alert("Invalid E-mail ID")
		return false;
	}
	if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
	    //alert("Invalid E-mail ID")
		return false;
	}
	if (str.indexOf(dot, (lat + 2)) == -1) {
	    //alert("Invalid E-mail ID")
		return false;
	}
	if (str.indexOf(" ") != -1) {
	    //alert("Invalid E-mail ID")
		return false;
	}
	return true;
}
