function validateForm(theForm)
{
       if ((theForm.firstname.value) == ""){alert("No first name entered. Please enter your first name."); return false;}
	   else
	   if ((theForm.familyname.value) == ""){alert("No family name entered. Please enter your family name."); return false;}
	   else
       if (!isURL(theForm.url.value)){alert("The URL of the site you wish to be listed is invalid. Please re-enter"); return false;}
	   else
	   if ((theForm.title.value) == ""){alert("Please enter the title of the site you wish to be listed"); return false;}
	   else
	   if ((theForm.desc.value) == ""){alert("Please enter a description of the site you wish to be listed"); return false;}
	   else
	    if ((theForm.category.value)== ""){alert("Please enter the category which you would like your site listed. If a relevant category does not already exist, please suggest a new one"); return false;}
	   else
	   if (echeck(theForm.emailaddress.value)==false){
		 return false;}
		else 
		if (!isURL(theForm.ourlink.value)){alert("The URL of the page on your site where our link appears is invalid. Please re-enter"); return false;}

		 if (searchengine(theForm)==false){
		 return false;}
		else 
		return true;
}

// ------------------------------------------

function searchengine(theForm)
{
 
  if ((theForm.sereport.checked) && (theForm.search1.value == "") && (theForm.search2.value == "") && (theForm.search1.value == ""))
   {alert("You have requested a FREE search engine report but you haven't supplied any search terms you would like us to report on. Please enter at least one search term"); return false;}  
  
    if ((theForm.sereport.checked == false) && !((theForm.search1.value == "") && (theForm.search2.value == "") && (theForm.search1.value == "")))
   {alert("You have not requested a FREE search engine report but have supplied search terms. Please check the request search engine report checkbox"); return false;}
   else
   return true
   
}

// ------------------------------------------

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 isURL (url) {
  var urlPattern = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/;
  return urlPattern.test(url.toLowerCase());
}
