function validate_required(field,alerttxt) {
  with (field) {
    if (value==null||value=="") { alert(alerttxt);return false }
    else {return true}
  }
}
function validate_checkbox(field) {
  with (field) {
    if (checked==null||checked=="") { return false }
    else { return true }
  }
}
function validate_select(field,alerttxt) {
  with (field) {
    if (value=="-") { alert(alerttxt);return false }
    else { return true }
  }
}

function validate_email(field,alerttxt) {
  with (field) {
    apos=value.indexOf("@")
    dotpos=value.lastIndexOf(".")
    if (apos<1||dotpos-apos<2) 
      {alert(alerttxt);return false}
    else {return true}
  }
}


function validate_contactsform(thisform) {
  with (thisform) {
    if (validate_required(name,"You haven't entered your name")==false) { return false }
    else if (validate_required(email,"You haven't entered your email")==false) { return false }
    else if (validate_email(email,"Your email address is incorrect")==false) { return false }    
    else if (validate_required(message,"You haven't entered any text into the message")==false) { return false }
    else if ((validate_checkbox(methodphone)==false) && (validate_checkbox(methodemail)==false)) { alert("You haven't selected your preferred way of contacting you");return false }
  }
}

function validate_clientloginform(thisform) {
  with(thisform) {
    if(validate_required(clientuser,"Please enter a username")==false) { return false }
    else if(validate_required(clientpass,"Please enter a password")==false) { return false }
  }
}


function validate_jobsform(thisform) {
  with (thisform) {
    if (validate_required(name,"You haven't entered your name")==false) { return false }
    else if (validate_required(email,"You haven't entered your email")==false) { return false }
    else if (validate_email(email,"Your email address is incorrect")==false) { return false }
    else if (validate_select(area,"You haven't specified your area of interest")==false) { return false }
    else if (validate_required(cvfile,"You haven't attached your CV file")==false) { return false }
    else if (validate_required(message,"You haven't entered any text into the message")==false) { return false }
  }
}

