//single
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

//check
function validate_requiredcheck(field,alerttxt)
{
with (field)
  {
  if (field.checked)
    {
    return true;
    }
  else
    {
     alert(alerttxt);return false;
    }
  }
}
//multiple
function validate_requiredm(field1,field2,alerttxt)
{
with (field1,field2)
  {
  if ((field1.value==null||field1.value=="") && (field2.value==0||field2.value==""))
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
//email
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;}
  }
}
//date of birth
function validate_dob(field,alerttxt)
{
with (field)
  {
  if (field.value>=2004)
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}


//market buy validation
function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(description,"There is no description of the product wanted!")==false)
  {description.focus();return false;}
  
   if (validate_required(quantity,"You must specify a quantity!")==false)
  {quantity.focus();return false;}  
  
    if (validate_required(dep,"You must specify a date! Dates are of the the form dd/mm/yyyy")==false)
  {dep.focus();return false;}  
    
  }
}

//market sell verification
function validate_formsg(thisform)
{
with (thisform)
  {
  if (validate_required(description,"There is no description of the product wanted!")==false)
  {description.focus();return false;}
  
   if (validate_required(quantity,"You must specify a quantity!")==false)
  {quantity.focus();return false;}  
  
    if (validate_required(dep,"You must specify a date from! Dates are of the the form dd/mm/yyyy")==false)
  {dep.focus();return false;}  
    if (validate_required(arr,"You must specify a date to! Dates are of the the form dd/mm/yyyy")==false)
  {arr.focus();return false;} 
  }
}

//createj
function validate_formcj(thisform)
{
with (thisform)
  {
    if (validate_required(veh,"You must specify your transport type")==false)
  {veh.focus();return false;}   
    if (validate_requiredm(space,person,"You must specify the number of people or the size of object you can transport")==false)
  {person.focus();return false;}
    if (validate_required(jdate,"You must specify a date from! Dates are of the the form dd/mm/yyyy")==false)
  {jdate.focus();return false;}
     if (validate_required(lieu,"Please specify your leaving location")==false)
  {lieu.focus();return false;}
   if (validate_required(lieu2,"Please specify your arrival location")==false)
  {lieu2.focus();return false;}
  }
}


//findt
function validate_formfj(thisform)
{
with (thisform)
  {  
    
    if (validate_required(title,"You must give your posting a title!")==false)
  {title.focus();return false;}
    if (validate_required(date,"You must specify a date from! Dates are of the the form dd/mm/yyyy")==false)
  {date.focus();return false;}
     if (validate_required(mess,"You must add a message!")==false)
  {message.focus();return false;}
     if (validate_required(lieu,"Please specify your leaving location")==false)
  {lieu.focus();return false;}
   if (validate_required(lieu2,"Please specify your arrival location")==false)
  {lieu2.focus();return false;} 
  }
}

//registration personal
function validate_formregp(thisform)
{
with (thisform)
  { 
   if (validate_requiredcheck(tandc,"You must accept the terms and conditions before registering")==false)
  {tandc.focus();return false;}
  if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;}
  if (validate_required(fname,"Please specify a first name!")==false)
  {fname.focus();return false;}
  if (validate_required(sname,"Please specify a surname!")==false)
  {sname.focus();return false;}
  if (validate_dob(year,"date of birth not valid, please confirm that you are old enough to read and write!")==false)
  {year.focus();return false;}
  if (validate_required(display,"Please choose a display name")==false)
  {display.focus();return false;}  
 
  }
  
}

//registration company
function validate_formregc(thisform)
{
with (thisform)
  {
   if (validate_required(fname,"Please specify a company name")==false)
  {fname.focus();return false;}
   if (validate_required(addr,"Please specify an address for the company")==false)
  {addr.focus();return false;}
   if (validate_required(postc,"Please specify the postcode for the address")==false)
  {postc.focus();return false;}
  if (validate_required(workn,"Please specify a company telephone number")==false)
  {workn.focus();return false;}
  if (validate_required(vat,"Please specify the company\'s registration number. If unsure type n/a")==false)
  {vat.focus();return false;}
  if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;}
    if (validate_requiredcheck(tandc,"You must accept the terms and conditions before registering")==false)
  {tandc.focus();return false;}
}  
  }
//password reminder
function validate_formps(thisform)
{
with (thisform)
  {
  if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;}
}  
  }
  function validate_formcont(thisform)
{
with (thisform)
  {
   if (validate_required(name,"Please specify a name")==false)
  {name.focus();return false;}
   if (validate_required(query,"Please specify the nature of your query")==false)
  {query.focus();return false;}
  if (validate_required(title,"Please specify a title for your query")==false)
  {title.focus();return false;}
  if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;}
       if (validate_required(message,"Please include a message")==false)
  {mess.focus();return false;}
}  
  }
  
//transport search  
  function validate_formsrch(thisform)
{
with (thisform)
  {
   if (validate_required(lieu,"Please specify your leaving location")==false)
  {lieu.focus();return false;}
   if (validate_required(lieu2,"Please specify your arrival location")==false)
  {lieu2.focus();return false;}
 }  
  }
  
//findj
function validate_formfj(thisform)
{
with (thisform)
  { 
  if (validate_required(lieu,"Please specify your leaving location")==false)
  {lieu.focus();return false;}
   if (validate_required(lieu2,"Please specify your arrival location")==false)
  {lieu2.focus();return false;}
    if (validate_requiredm(space,person,"You must specify the number of people or the size of object that needs to be transported")==false)
  {space.focus();return false;}
  if (validate_required(jdate,"You must specify a date from! Dates are of the the form dd/mm/yyyy")==false)
  {jdate.focus();return false;}
  }
}  
   