/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(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					
	}

function ValidateEmail(){
	var emailID=document.classified.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

 
 /**********************************************************
  **********************************************************/

function CheckHeaderSearchFields() {

missinginfo = "You must select either a Category, County or enter a Keyword to search";

if ( (document.searchresults.county.value == "") && (document.searchresults.category.value == "") && (document.searchresults.keywords.value == "") ) 
{
alert(missinginfo);
return false;
}
else return false;
}
//  End -->

 
 /**********************************************************
  **********************************************************/
function ValidateAdvert(){
	var textID=document.classified.adverttext
	
	if ((textID.value==null)||(textID.value=="")){
		alert("Please Enter your Advert Text")
		textID.focus()
		return false
	}
	return true
 }
  
 /**********************************************************
  **********************************************************/
function ValidateName(){
	var textID=document.classified.name
	
	if ((textID.value==null)||(textID.value=="")){
		alert("Please Enter your Name")
		textID.focus()
		return false
	}
	return true
 }
  
 /**********************************************************
  **********************************************************/
function ValidateAddress(){
	var textID=document.classified.address
	
	if ((textID.value==null)||(textID.value=="")){
		alert("Please Enter your Address")
		textID.focus()
		return false
	}
	return true
 }
  
 /**********************************************************
  **********************************************************/
function ValidateTelephone(){
	var textID=document.classified.telephone
	
	if ((textID.value==null)||(textID.value=="")){
		alert("Please Enter your Telephone Number")
		textID.focus()
		return false
	}
	return true
 }
  
 /**********************************************************
  **********************************************************/
  
 function checkbox_checker()
{

// set var checkbox_choices to zero

var checkbox_choices = 0;

if (classified.monday.checked)
{ checkbox_choices = checkbox_choices + 1; }
if (classified.tuesday.checked)
{ checkbox_choices = checkbox_choices + 1; }
if (classified.wednesday.checked)
{ checkbox_choices = checkbox_choices + 1; }
if (classified.weekend.checked)
{ checkbox_choices = checkbox_choices + 1; }
if (classified.all.checked)
{ checkbox_choices = checkbox_choices + 1; 
  if(checkbox_choices > 1)
    {
      alert("Please specify publication dates OR select \"all\".\nYou cannot do both.")
      return (false);
    } 
}

if (checkbox_choices < 1 )
{
// If there were less then selections made display an alert box 
alert("Please make at least one publication selection.")
return (false);
}

/* If three were selected then display an alert box stating input was OK */
return (true);
}


/*********************************************************
 *********************************************************/
 
 function check_class_form()
   {
      if(!checkbox_checker())
       {
        return (false);
        }
      if(!ValidateAdvert())
       {
        return (false);
        }
      if(!ValidateName())
       {
        return (false);
        }
      if(!ValidateAddress())
       {
        return (false);
        }
      if(!ValidateTelephone())
       {
        return (false);
        }
      if(!ValidateEmail())
       {
        return (false);
        }
        
   return (true);
   }   
   
   
   
 /************************************************************/
 /************************************************************/
 
 function CountWords (this_field, show_word_count, show_char_count, numwords, baseprice, extraprice, wendprice) {
if (show_word_count == null) {
show_word_count = true;
}
if (show_char_count == null) {
show_char_count = false;
}
var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}

  if(numwords >= word_count)
    {
alert ("Word Count:  " + word_count + wordOrWords);    
    }
   else
     {
     var leftover = 0;
     var extra = 0;
     var totalcost = 0;
     leftover = word_count - numwords;
     alert ("Word Count:  " + word_count + wordOrWords);   
     }

return word_count;
}

 /************************************************************/
 /************************************************************/

function histback() {
    history.back();
}

/**************************************************/
/**************************************************/
function ValidateRecEmail(){
	var emailID=document.emailform.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
function ValidateRecFriendEmail(){
	var emailID=document.emailform.friendemail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Friends Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
function ValidateRecName(){
	var emailID=document.emailform.name
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Name")
		emailID.focus()
		return false
	}
	return true
 }
function ValidateRecFriendName(){
	var emailID=document.emailform.friendname
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Friends Name")
		emailID.focus()
		return false
	}
	return true
 }
 /////////////////////
 function check_rec_form()
   {
      if(!ValidateRecName())
       {
        return (false);
        }
      if(!ValidateRecEmail())
       {
        return (false);
        }
      if(!ValidateRecFriendName())
       {
        return (false);
        }
      if(!ValidateRecFriendEmail())
       {
        return (false);
        }
        
   return (true);
   }   

