// To check if all the fields in the form are correctly filled.
// Validation - Reports if all the fields are filled out correctly

function checkaddrt()
{
 if (testformaddrt()) return true;
 else return false;	
}		

function testformaddrt()
{

 /* check for email field */
 if (document.addrt.username.value == "")
 {
  alert("The email field is blank.\n\nPlease enter the email address we have on record.");
  document.addrt.username.focus();      
  return false;       
 }   

 // Return false if e-mail field does not contain a '@' and '.' .

 if (document.addrt.username.value.indexOf ('@',0) == -1 || document.addrt.username.value.indexOf ('.',0) == -1)
 {      
  alert("The email address you have entered is invalid.\n\nPlease re-enter the correct email address we have on record.");      		
  document.addrt.username.focus();      
  document.addrt.username.select();      
  return false;      
 }  	

 /* check for password field */

 var password = document.addrt.password.value;
 if (password == "")
 {
  alert("The password field is blank.\n\nPlease enter the password we have on record.");
  document.addrt.password.focus();
  return false;
 }

 var password = document.addrt.password.value;
 for (var i = 0; i < password.length; i++)
 {
  var ch = password.substring(i,i+1);
  if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch != ' ') && (ch < "0" || "9" < ch))
  {         
   alert("The password you have entered is invalid.\n\nPlease re-enter the correct password we have on record.");         			
   document.addrt.password.focus();         
   document.addrt.password.select();         
   return false;         
  }      
 }

 var model = document.addrt.model.selectedIndex;
 if (document.addrt.model.options[model].value == '')
 {
  alert('Please select your vehicle make');       				
  document.addrt.model.focus();
  return false;
 }

 var capacity = document.addrt.capacity.value;
 if (((document.addrt.model.options[model].value == 'Mini Bus') || (document.addrt.model.options[model].value == 'Luxury Bus')) && (capacity == ""))
 {
  alert("Please enter the capacity of the vehicle");       				
  document.addrt.capacity.focus();
  return false;
 }

 // Return false if characters are not 0-9
 for (var i = 0; i < capacity.length; i++)
 {
  var ch = capacity.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The vehicle capacity has to be a whole number.\n\nPlease re-enter the capacity correctly.");         			
   document.addrt.capacity.focus();         
   document.addrt.capacity.select();         
   return false;         
  }      
 }

 var place = document.addrt.place.selectedIndex;
 if (document.addrt.place.options[place].value == '')
 {
  alert('Please select your city/town');       				
  document.addrt.place.focus();
  return false;
 }

 var minprice = document.addrt.minprice.value;
 if (minprice == "")
 {
  alert("Please enter the minimum charge below which you will not rent out the vehicle");       				
  document.addrt.minprice.focus();
  return false;
 }

 // Return false if characters are not 0-9
 for (var i = 0; i < minprice.length; i++)
 {
  var ch = minprice.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The minimum charge has to be a whole number.\n\nPlease re-enter the minimum charge correctly.");         			
   document.addrt.minprice.focus();         
   document.addrt.minprice.select();         
   return false;         
  }      
 }

 var hourslimit = document.addrt.hourslimit.value;
 if (hourslimit == "")
 {
  alert("Please enter the ceiling number of hours for the minimum charge");       				
  document.addrt.hourslimit.focus();
  return false;
 }

 // Return false if characters are not 0-9
 for (var i = 0; i < hourslimit.length; i++)
 {
  var ch = hourslimit.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The number of hours has to be a whole number.\n\nPlease re-enter the number of hours correctly.");         			
   document.addrt.hourslimit.focus();         
   document.addrt.hourslimit.select();         
   return false;         
  }      
 }

 var kmslimit = document.addrt.kmslimit.value;
 if (kmslimit == "")
 {
  alert("Please enter the ceiling number of kilometers for the minimum charge");       				
  document.addrt.kmslimit.focus();
  return false;
 }

 // Return false if characters are not 0-9
 for (var i = 0; i < kmslimit.length; i++)
 {
  var ch = kmslimit.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The number of kilometers has to be a whole number.\n\nPlease re-enter the number of kilometers correctly.");         			
   document.addrt.kmslimit.focus();         
   document.addrt.kmslimit.select();         
   return false;         
  }      
 }

 // Return false if characters are not 0-9
 var hourprice = document.addrt.hourprice.value;
 for (var i = 0; i < hourprice.length; i++)
 {
  var ch = hourprice.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The hourly charge has to be a whole number.\n\nPlease re-enter the hourly charge correctly.");         			
   document.addrt.hourprice.focus();         
   document.addrt.hourprice.select();         
   return false;         
  }      
 }

 // Return false if characters are not 0-9
 var kmprice = document.addrt.kmprice.value;
 for (var i = 0; i < kmprice.length; i++)
 {
  var ch = kmprice.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The distance charge has to be a whole number.\n\nPlease re-enter the distance charge (per kilometer) correctly.");         			
   document.addrt.kmprice.focus();         
   document.addrt.kmprice.select();         
   return false;         
  }      
 }

 if (document.addrt.outstation[0].checked)
 {
  var longkmprice = document.addrt.longkmprice.value;
  if (longkmprice == "")
  {
   alert("Please enter the distance charge (per kilometer) for long distance travel");       				
   document.addrt.longkmprice.focus();
   return false;
  }
 }

 // Return false if characters are not 0-9
 var longkmprice = document.addrt.longkmprice.value;
 for (var i = 0; i < longkmprice.length; i++)
 {
  var ch = longkmprice.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The distance charge has to be a whole number.\n\nPlease re-enter the distance charge (per kilometer) correctly.");         			
   document.addrt.longkmprice.focus();         
   document.addrt.longkmprice.select();         
   return false;         
  }      
 }

 // Return false if characters are not 0-9
 var longminprice = document.addrt.longminprice.value;
 for (var i = 0; i < longminprice.length; i++)
 {
  var ch = longminprice.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The minimum billing has to be a whole number.\n\nPlease re-enter the minimum billing (for long diatance) correctly.");         			
   document.addrt.longminprice.focus();         
   document.addrt.longminprice.select();         
   return false;         
  }      
 }

 // Return false if characters are not 0-9
 var longnightprice = document.addrt.longnightprice.value;
 for (var i = 0; i < longnightprice.length; i++)
 {
  var ch = longnightprice.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The overnight charge has to be a whole number.\n\nPlease re-enter the overnight charge correctly.");         			
   document.addrt.longnightprice.focus();         
   document.addrt.longnightprice.select();         
   return false;         
  }      
 }

 // Return false if characters are not 0-9
 var longchauffeurprice = document.addrt.longchauffeurprice.value;
 for (var i = 0; i < longchauffeurprice.length; i++)
 {
  var ch = longchauffeurprice.substring(i,i+1);
  if ((ch < "0") || ("9" < ch))
  {         
   alert("The chauffeur allowance has to be a whole number.\n\nPlease re-enter the chauffeur allowance correctly.");         			
   document.addrt.longchauffeurprice.focus();         
   document.addrt.longchauffeurprice.select();         
   return false;         
  }      
 }

 var particulars = document.addrt.particulars.value;
 for (var i = 0; i < particulars.length; i++)
 {
  var count = i;
  if (count > 254)
  {         
   alert("The description exceeds the permissible limit - please keep it brief.");         			
   document.addrt.particulars.focus();         
   document.addrt.particulars.select();         
   return false;         
  }      
 }


 return true;
}


