var submitcount = 0;
function formCheck(form1) {
if (!ValidLength(form1.username.value,3)){
      alert("Please enter your name!");
      form1.username.focus();
      return false;
      }
if (!ValidEmail(form1.email.value)){
      alert("Please enter a valid email address!");
      form1.email.focus();
      return false;
      }
if (!ValidLength(form1.sitename.value,2)){
      alert("Please enter your site name!");
      form1.sitename.focus();
      return false;
      }
if (!ValidLength(form1.url.value,5)){
      alert("Please enter your URL!");
      form1.url.focus();
      return false;
      }
if(form1.url.value.indexOf("http://") < 0){
      alert("Please enter a valid url like the given example!");
      form1.url.focus();
      return false;
      }      
if (!ValidLength(form1.despt.value,2)){
      alert("Please enter a short description of your site!");
      form1.despt.focus();
      return false;
      }
if (!ValidLength(form1.cat.options[form1.cat.selectedIndex].value,2)){
      alert("Please select a category for your site.");
      form1.cat.focus();
      return false;
      }
if (!ValidLength(form1.link.value,1)){
      alert("Please enter a reciprocal link!");
      form1.link.focus();
      return false;
      }
if(form1.link.value.indexOf("http://") < 0){
      alert("Please enter a valid reciprocal link like the given example!");
      form1.link.focus();
      return false;
      }      
}	
//function to validate by length
function ValidLength(item, len) {
   return (item.length >= len);
}
//function to validate an email address
function ValidEmail(item) {
		emailcheck=item;
		//check for disallowed characters
		invalids=" /:;,";
		for(i=0; i<invalids.length; i++){
			characto=(invalids.charAt(i));
			if (emailcheck.indexOf(characto) != -1){
				return false; }
		}
		//check for @, skip first character
		atindex= emailcheck.indexOf("@",1)
		if (atindex == -1){
			return false; }
		//check for only one @
		if (emailcheck.indexOf("@",atindex+1) != -1){
			return false;; 		}
		//check for dot after @
		dotindex=emailcheck.indexOf(".",atindex+1)
		if (dotindex == -1){
			return false; }
		//check for at least 2 chars after dot
		if ((dotindex+3) > emailcheck.length) {
			return false;;}
   return true;
}
