
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(!(exists(document.signup.name.value))) {
    
    	  	fixThis += "Please enter your name.\n";
    	}
    	
    	if(!(exists(document.signup.address1.value))) {
	    
	    	fixThis += "Please enter your postal address.\n";
    	}
    	
   	
    	if(!(exists(document.signup.postcode.value))) {
	    
	    	fixThis += "Please enter your postcode.\n";
    	}
    	
    	if(!(exists(document.signup.email.value))) {
	    
	    	fixThis += "Please enter your email address.\n";
    	}

    	if(!(isChecked(document.signup.tandc))) {
	    
	    	fixThis += "You must accept the terms and conditions to subscribe. If you don't wish to continue then please follow the home link or press the back button on your browser.\n";
    	}

    	if (fixThis !="") {
    	  alert(fixThis);
    	  
    	} else {
    	   
    	   document.signup.submit();
    	}
  }

  function validateTopUp() {
    
    	var fixThis = "";
    
 

    	if(document.topup.tandc.value == "") {
	    
	    	fixThis += "You must accept the terms and conditions. If you don't wish to continue then please follow the home link or press the back button on your browser.\n";
    	}

    	if (fixThis !="") {
    	  alert(fixThis);
    	  
    	} else {
    	   
    	   document.topup.submit();
    	}
  }
  

  function validateLogonForm() {
    
    	var fixThis = "";
    
    	if(!(exists(document.logon.email.value))) {
	  	fixThis += "Please enter your email address.\n"
  	}
    	
    	if(!(exists(document.logon.password.value))) {
    
    	  	fixThis += "Please enter your password.\n";
    	}
    	
    	if (fixThis !="") {
    	  alert(fixThis);
    	  
    	} else {
    	   
    	   document.logon.submit();
    	}
  }
  
  function validateUpload() {
      
      	var fixThis = "";
      
      	if(!(exists(document.upload.refno.value))) {
  	  	fixThis += "Please input a reference number.\n"
    	}
      	
      	if(!(exists(document.upload.title.value))) {
	  	fixThis += "Please input a job title.\n"
    	}
    	
    	if(!(exists(document.upload.description.value))) {
	  	fixThis += "Please enter a job description.\n"
    	}

    	if(!(ischecked(document.upload.uk))) {
	  	fixThis += "You must be an EU resident or have a valid work permit to apply for this job.\n"
    	}
   	
      	if (fixThis !="") {
      	  alert(fixThis);
      	  
      	} else {
      	   
      	   document.upload.submit();
      	}
  }
  
    function validatePasswdForm() {
        
        	var fixThis = "";
        
        	if(!(exists(document.changepass.password.value))) {
    	  	fixThis += "Please enter your old password.\n"
      	}
        	
        	if(!(exists(document.changepass.newpassword.value))) {
  	  	fixThis += "Please enter your new password.\n"
      	}
 
         	if(!(exists(document.changepass.confirmpassword.value))) {
   	  	fixThis += "Please confirm your new password.\n"
      	}

         	if(!(document.changepass.newpassword.value == document.changepass.confirmpassword.value)) {
   	  	fixThis += "The passwords you entered did not match.\n"
      	}
        	
        	if (fixThis !="") {
        	  alert(fixThis);
        	  
        	} else {
        	   
        	   document.changepass.submit();
        	}
  }
  
  function validateApply() {
    
    	var fixThis = "";
    
   	
    	if(!(exists(document.apply.name.value))) {
    
    	  	fixThis += "Please enter your name.\n";
    	}
 
    	
    	if(!(exists(document.apply.email.value))) {
	    
	    	fixThis += "Please enter your email address.\n";
    	}

    	if(!(exists(document.apply.file.value))) {
	    
	    	fixThis += "You must attach your CV.\n";
    	}
    	
    	if(!(isChecked(document.apply.permit))) {
	    
	    	fixThis += "Please confirm that you are able to work in the UK.\n";
    	}    	

    	if (fixThis !="") {
    	  alert(fixThis);
    	  
    	} else {
    	   
    	   document.apply.submit();
    	}
  }
  
  function validateListAgency() {
     
     	var fixThis = "";
            
      	if(!(exists(document.onlineapp.company.value))) {
  		    
  		    	fixThis += "Please enter your Company name.\n";
      	}
      	
      	if(!(exists(document.onlineapp.contact.value))) {
      
      	  	fixThis += "Please enter your name.\n";
      	}
   
      	
      	if(!(exists(document.onlineapp.email.value))) {
  	    
  	    	fixThis += "Please enter your email address.\n";
      	}
   	
  
      	if (fixThis !="") {
      	  alert(fixThis);
      	  
      	} else {
      	   
      	   document.onlineapp.submit();
      	}
  }    
  
  
  
  function validateSendFriend() {
       
       	var fixThis = "";
              
        if(!(exists(document.sendfriendform.recipient.value))) {
    		    
    		fixThis += "Please enter your friend or colleagues name.\n";
        }
        	
        if(!(exists(document.sendfriendform.name.value))) {
        
          	fixThis += "Please enter your name.\n";
        }
     
        	
        if(!(exists(document.sendfriendform.emailfrom.value))) {
    	    
    		fixThis += "Please enter your email address.\n";
        }
     	
     	if(!(exists(document.sendfriendform.emailto.value))) {
	    	    
	    	fixThis += "Please enter your friend or colleagues email address.\n";
        }
    
        if (fixThis !="") {
          alert(fixThis);
        	  
        } else {
        	   
          document.sendfriendform.submit();
        }
  }  
  
  
  
  function validateFeedBack() {
         
         	var fixThis = "";
                
          if(!(exists(document.feedback.name.value))) {
      		    
      		fixThis += "Please enter your name.\n";
          }
          	
          if(!(exists(document.feedback.email.value))) {
          
            	fixThis += "Please enter your email address.\n";
          }
       
          	
          if(!(exists(document.feedback.comments.value))) {
      	    
      		fixThis += "Please enter your comments.\n";
          }
       	
            
          if (fixThis !="") {
            alert(fixThis);
          	  
          } else {
          	   
            document.feedback.submit();
          }
  }    
