var swear_words_arr=new Array("viagra","http","a href","www",".com","prescription","drugs","cunt","pussy","penis","fuck","prick","refinance","sex","horny","mortgage");
var swear_alert_arr=new Array;
var swear_alert_count=0;

function Submit_onclick() {
	//check for client side (form) validation
	
	if (Form_Validate() == true) {							
		return true;
	} else {
		return false;
	}	

}

function reset_alert_count()
{
 swear_alert_count=0;
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
	}

function Form_Validate() {

	if (document.postForm.author_nameStr.value==""){
		alert("Name cannot be blank");
		document.postForm.author_nameStr.focus = true;
		return false;
	}
	
	//if (document.postForm.author_emailStr.value==""){
		//alert("Email cannot be blank");
		//document.postForm.author_emailStr.focus = true;
		//return false;
	//}
	
	if (document.postForm.author_emailStr.value != "" && document.postForm.author_emailStr.value.indexOf('@') == -1)
	{
		alert("Please enter a valid Email.");
        document.postForm.author_emailStr.focus(true);
        return false;
	}
	
	if (document.postForm.author_emailStr.value != "" && document.postForm.author_emailStr.value.indexOf('.') == -1)
	{
		alert("Please enter a valid Email.");
        document.postForm.author_emailStr.focus(true);
        return false;
    }
	if (document.postForm.author_emailStr.value != "" && isEmail(postForm.author_emailStr.value) == false) 
	{
		alert("Please enter a valid Email.");
		document.postForm.author_emailStr.focus(true);
		return false;
	}
	if (document.postForm.detailStr.value==""){
		alert("Message cannot be blank");
		document.postForm.detailStr.focus = true;
		return false;
	}
	
	if (document.postForm.detailStr.value != "" && document.postForm.detailStr.value.indexOf('a href') == 1)
	{
		alert("Please enter a valid Guestbook message.");
        document.postForm.detailStr.focus(true);
        return false;
    }
	if (document.postForm.detailStr.value != "" && document.postForm.detailStr.value.indexOf('http') == 1)
	{
		alert("Please enter a valid Guestbook message.");
        document.postForm.detailStr.focus(true);
        return false;
    }
	if (document.postForm.detailStr.value != "" && document.postForm.detailStr.value.indexOf('www') == 1)
	{
		alert("Please enter a valid Guestbook message.");
        document.postForm.detailStr.focus(true);
        return false;
    }
	
	 reset_alert_count();
	 var compare_text=document.postForm.detailStr.value;
	 for(var i=0; i<swear_words_arr.length; i++)
	 {
	  for(var j=0; j<(compare_text.length); j++)
	  {
	   if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
	   {
		swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
		swear_alert_count++;
	   }
	  }
	 }
	 var alert_text="";
	 for(var k=1; k<=swear_alert_count; k++)
	 {
	  alert_text+="\n" + "(" + k + ")  " + swear_alert_arr[k-1];
	 }
	 if(swear_alert_count>0)
	 {
	  alert("Please enter a valid Guestbook message.");
	  document.postForm.detailStr.focus(true);
	  return false;
	 }
	
	return true;
}	