function commentFormValidator(theForm)
{
  if (document.getElementById('sName').value == "")
  {
    alert("Please enter your name.");
    document.getElementById('sName').focus();
    return (false);
  }
  if (document.getElementById('sLocation').value == "")
  {
    alert("Please enter your location.");
    document.getElementById('sLocation').focus();
    return (false);
  }
  var compare_text=document.getElementById('sComment').value; 
  if (compare_text == "dummy text" || compare_text == "") 
 {
    //do nothing
    alert("Please enter a comment.");
    return (false);
 }
  if (document.getElementById('chkRules').checked == false)
  {
    alert("Please tick the box to agree to our house rules.");
    document.getElementById('chkRules').focus();
    return (false);
  }
  if (document.getElementById('sCaptcha').value == "")
  {
    alert("Please enter the number in the green image into the box.");
    document.getElementById('sCaptcha').focus();
    return (false);
  }
   
  //validate_user_text()
  //return (true);
    document.getElementById('frmComments').submit();
}

//var swear_alert_arr=new Array;
var swear_alert_count=0;

function reset_alert_count()
{
 swear_alert_count=0;
}

function validate_user_text()
{
 reset_alert_count();
 //var compare_text=document.frmComments.sComment.value;
 var compare_text=document.getElementById('sComment').value; 
 
 if (compare_text == "dummy text" || compare_text == "") {
    //do nothing
    alert("Please enter a comment.");
    //document.getElementById('sComment').focus();
 }
 else 
{ 
 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("Your comment cannot be submitted.\nThe following illegal words were found:\n_______________________________\n" + alert_text + "\n_______________________________");
 }
 else
 {    
    //alert("HERE");  
    //document.frmComment.submit();
    document.getElementById('frmComments').submit();
 }
}
}

function select_area()
{
 //document.frmComments.sComment.select();
}

function submitSearch()
{
    if (document.getElementById('sSearch').value == "") {
        alert("NO SEARCH");
    }
    else {
        document.getElementById('frmSearch').submit();
    }
}

window.onload=reset_alert_count;

	$(document).ready(function() {
	    $('textarea').growfield();

		$('textarea').addClass("textarea");
   		$('textarea').focus(function() {
   			$(this).removeClass("textarea").addClass("focusField");
		    if (this.value == this.defaultValue){ 
		    	this.value = '';
			}
			if(this.value != this.defaultValue){
    			this.select();
    		}
		});
		$('input[type="text"]').addClass("input");
   		$('input[type="text"]').focus(function() {
   			$(this).removeClass("input").addClass("focusField");
		    if (this.value == this.defaultValue){ 
		    	this.value = '';
			}
			if(this.value != this.defaultValue){
    			this.select();
    		}
		});
		$('textarea').blur(function() {
			$(this).removeClass("focusField").addClass("textarea");
		    if ($.trim(this.value) == ''){
		    	this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});
		$('input[type="text"]').blur(function() {
			$(this).removeClass("focusField").addClass("input");
		    if ($.trim(this.value) == ''){
		    	this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});    		
	});				
		
