
function validate(field) {
var valid = "0123456789-() "
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
  return 1;
   }
if (!(exists(field.value))) {
  return 1;
   }
}

function exists(userEntry) {

  var aCharExists = 0;
  var entry=userEntry;

  if(entry) {
     for (var i=0; i<entry.length; i++) {
       if (entry.charAt(i) !="") {
         aCharExists=1;
       }
     }
  }

  if(!aCharExists) {
  return 0;
  }

  return 1;
}

function isLongerThan11(field) {
	if (field.substr(0,7) == 'http://') {
		if (field.length < 11) {
			return 0;
		}
	}
	else {
		if (field.length < 4) {
			return 0;
		}
	}
	return 1;
}

function isChecked(field) {
	if (field.checked) {
		return 1;
	}
	return 0;
}

function multiSelectCheck(field) {
	var selectCount = 0;
	
	for (var i = 0; i < field.length; i++) {
	      if (field.options[i].selected == true) {
	         selectCount++;
	      }
   	}
		
	if (selectCount > 6) {
		return 0;
	}
	return 1;
}


//////////////////////////////////////////////////////////////////////
// validateForm() function:
// Validates input of entire form.
//////////////////////////////////////////////////////////////////////

 
  function validateAppForm() {
  
  	var fixThis = "";
  
  	if(!(isLongerThan11(document.frmApp.u.value))) {
		fixThis += "Please enter the full URL (eg. http://www.uk250.co.uk).\n"
	}
  	
  	if(!(exists(document.frmApp.c.value))) {
  
  	  fixThis += "Please enter a contact name.\n";
  	}
  
  	if((validate(document.frmApp.tel))) {
  	
  		  fixThis += "Please enter a valid telephone number.\n";
  	}
  	
  	
  	if (fixThis !="") {
  	  alert(fixThis);
  	  
  	} else {
  	   
  	   document.frmApp.submit();
  	}
  }
  
  function validateAppForm1() {
    
    	var fixThis = "";
    
    	if(!(isLongerThan11(document.frmApp1.url.value))) {
  		fixThis += "Please enter the full URL (eg. http://www.uk250.co.uk).\n"
  	}
    	
    	if(!(exists(document.frmApp1.contact.value))) {
    
    	  	fixThis += "Please enter a contact name.\n";
    	}
    	
    	if(!(exists(document.frmApp1.street1.value))) {
	    
	    	fixThis += "Please enter your postal address.\n";
    	}
    	
    	if(!(exists(document.frmApp1.town.value))) {
	    
	    	fixThis += "Please enter your postal town.\n";
    	}
    	
    	if(!(exists(document.frmApp1.county.value))) {
	    
	    	fixThis += "Please enter your county.\n";
    	}
    	
    	if(!(exists(document.frmApp1.email.value))) {
	    
	    	fixThis += "Please enter a contact email address.\n";
    	}
    	
    	if(!(exists(document.frmApp1.name.value))) {
		    
		fixThis += "Please enter a name for your site.\n";
    	}
    	
    	if(!(multiSelectCheck(document.frmApp1.categories))) {
    	
    		fixThis += "You may only select a maximum of 6 categories.\n";
    		
    	}
    	
    	if(!(exists(document.frmApp1.description.value))) {
		    
		fixThis += "Please enter a description for your site.\n";
    	}
    	    
    	if (fixThis !="") {
    	  alert(fixThis);
    	  
    	} else {
    	   
    	   document.frmApp1.submit();
    	}
  }
  
  function validateEmailForm() {
    
    	var fixThis = "";
    
    	if(!(exists(document.form1.buddyname.value))) {
	  	fixThis += "Please enter your friends name.\n"
  	}
    	
    	if(!(exists(document.form1.buddyemail.value))) {
    
    	  	fixThis += "Please enter your friends email address.\n";
    	}
    	    	
    	if(!(exists(document.form1.myname.value))) {
	  	fixThis += "Please enter your name.\n"
	}
	  	
	if(!(exists(document.form1.myemail.value))) {
		fixThis += "Please enter your email address.\n"
  	}
    	
    	if (fixThis !="") {
    	  alert(fixThis);
    	  
    	} else {
    	   
    	   document.form1.submit();
    	}
  }
  
  function validateAppForm2() {
      
      	var fixThis = "";
      
      	if(!(isChecked(document.frmApp2.terms))) {
  	  	fixThis += "Please accept the terms.\n"
    	}
      	
      	if(!(isChecked(document.frmApp2.listing))) {
	  	fixThis += "Please confirm that your site abides by the listing guidelines.\n"
    	}
    	
    	if(!(isChecked(document.frmApp2.refund))) {
	  	fixThis += "Please accept understanding of the administration charge for rejected applications.\n"
    	}
      	
      	if (fixThis !="") {
      	  alert(fixThis);
      	  
      	} else {
      	   
      	   document.frmApp2.submit();
      	}
  }