function submitComment()
{	
	
	var author=$F("author");

	if(author=="")
	{
		$("author").style.background = "#FFCCCC";
		alert("Please enter your name");
		$("author").focus();
		return false;
	}
	else
	{
		$("author").style.background = "#FFFFFF";
	}
	//EMAIL VALIDATION
	var goodEmail 	= $F("email").match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	apos		= $F("email").indexOf("@");
	dotpos		= $F("email").lastIndexOf(".");
	lastpos		= $F("email").length-1;
	var badEmail 	= (apos<1 || dotpos-apos<2 || lastpos-dotpos<2);

	if (($F("email") == "") || (!goodEmail && badEmail))		
	{
		$("email").style.background = "#FFCCCC";
		alert("Please enter a valid email");
		$("email").focus();
		return false;
	}
	else
	{
		$("email").style.background = "#FFFFFF";
	}

	var city=$F("city");

	var comment=trim($F("comment"));
	
	if(comment =="")
	{
		$("comment").style.background = "#FFCCCC";
		alert("Please enter a comment");
		$("comment").focus();
		return false;
	}
	else
	{
		$("comment").style.background = "#FFFFFF";
	}
	
	var cat_id=$F("cat_id");
	var news_id=$F("news_id");

	//YOU MAY WANT TO CHANGE THE URL IN THE LINE BELOW
	var url = "comments-post.php";
	var params='author='+$F("author")+'&email='+$F("email")+'&city='+$F("city")+'&comment='+$F("comment")+'&news_id='+$F("news_id")+"&cat_id="+$F("cat_id")+"&website="+$F("website");
	
	
	new Ajax.Request(url, {onComplete:showResponse, onException:showException, onFailure:showException, asynchronous:true, method:"post", evalScripts:false, postBody:params});
	$("submit").hide();
	$("loading").show();

	function showResponse(req)
	{	
		
		if (req.responseText=="1" || req.responseText=="0")	//1. added to contacts	//2.already in contacts
		{
			$("loading").hide();
			$("okmessage").show();
			$("submit").show();
			$("author").clear();
			$("email").clear();
			$("website").clear();
			$("city").clear();
			$("comment").clear();
		}
		if (req.responseText=="2" )	
		{
			$("loading").hide();
			$("okmessage2").show();
			$("submit").show();
			$("author").clear();
			$("email").clear();
			$("website").clear();
			$("city").clear();
			$("comment").clear();
		}
		if (req.responseText=="error")	
		{
			alert("An error has occured. Please try again.");
			$("loading").hide();
			$("okmessage").hide();
			$("submit").show();
		}
	}
	function showException()
	{
		alert("Error occured while talking to the server. Please try again.");
		$("loading").hide();
		$("okmessage").hide();
		$("submit").show();
		$("author").clear();
		$("email").clear();
		$("website").clear();
		$("city").clear();
		$("comment").clear();
	}
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}