// To check if all the fields in the form are correctly filled.
// Validation - Reports if all the fields are filled out correctly

function checkaddcp()
{
 if (testformaddcp()) return true;
 else return false;	
}		

function testformaddcp()
{

 /* check for email field */
 if (document.addcp.username.value == "")
 {
  alert("The email field is blank.\n\nPlease enter the email address we have on record.");
  document.addcp.username.focus();      
  return false;       
 }   

 // Return false if e-mail field does not contain a '@' and '.' .

 if (document.addcp.username.value.indexOf ('@',0) == -1 || document.addcp.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.addcp.username.focus();      
  document.addcp.username.select();      
  return false;      
 }  	

 /* check for password field */

 var password = document.addcp.password.value;
 if (password == "")
 {
  alert("The password field is blank.\n\nPlease enter the password we have on record.");
  document.addcp.password.focus();
  return false;
 }

 var password = document.addcp.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.addcp.password.focus();         
   document.addcp.password.select();         
   return false;         
  }      
 }

 var oplace = document.addcp.oplace.selectedIndex;
 if (document.addcp.oplace.options[oplace].value == '')
 {
  alert('Please select the locality from where you start off');       				
  document.addcp.oplace.focus();
  return false;
 }

 var dplace = document.addcp.dplace.selectedIndex;
 if (document.addcp.dplace.options[dplace].value == '')
 {
  alert('Please select the locality to which you travel to');       				
  document.addcp.dplace.focus();
  return false;
 }

 if (document.addcp.oplace.options[oplace].value == document.addcp.dplace.options[dplace].value)
 {
  alert('Your origin and destination localities are the same. Please check.');       				
  document.addcp.dplace.focus();
  return false;
 }


 var hour = document.addcp.hour.selectedIndex;
 if (document.addcp.hour.options[hour].value == '')
 {
  alert('Please select your start hour');       				
  document.addcp.hour.focus();
  return false;
 }

 var minute = document.addcp.minute.selectedIndex;
 if (document.addcp.minute.options[minute].value == '')
 {
  alert('Please select your start hour');       				
  document.addcp.minute.focus();
  return false;
 }

 var tolerance = document.addcp.tolerance.selectedIndex;
 if (document.addcp.tolerance.options[tolerance].value == '')
 {
  alert('Please select your start time flexibility (in minutes)');       				
  document.addcp.tolerance.focus();
  return false;
 }

 if (document.addcp.category[0].checked)

 {

  var model = document.addcp.model.selectedIndex;
  if (document.addcp.model.options[model].value == '')
  {
   alert('Please select your vehicle make');
   document.addcp.model.focus();
   return false;
  }

  var regnum1 = document.addcp.regnum1.value;

  if (regnum1 == "")
  {
   alert("The state code is blank.\n\nPlease enter the state code displayed on your car registration plate.");
   document.addcp.regnum1.focus();
   return false;
  }
 
  for (var i = 0; i < regnum1.length; i++)
  {
   var ch = regnum1.substring(i,i+1);
   if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))
   {         
    alert("The state code you have entered is invalid.\n\nPlease re-enter the state code displayed on your car registration plate.");
    document.addcp.regnum1.focus();         
    document.addcp.regnum1.select();         
    return false;         
   }      
  }

  var regnum2 = document.addcp.regnum2.value;

  if (regnum2 == "")
  {
   alert("The RTO code is blank.\n\nPlease enter the RTO code displayed on your car registration plate.");
   document.addcp.regnum2.focus();
   return false;
  }

  for (var i = 0; i < regnum2.length; i++)
  {
   var ch = regnum2.substring(i,i+1);
   if ((ch < "0" || "9" < ch))
   {         
    alert("The RTO code you have entered is invalid.\n\nPlease re-enter the RTO code displayed on your car registration plate.");
    document.addcp.regnum2.focus();         
    document.addcp.regnum2.select();         
    return false;         
   }      
  }

  var regnum3 = document.addcp.regnum3.value;

  if (regnum3 == "")
  {
   alert("The third code is blank.\n\nPlease enter the third code displayed on your car registration plate.");
   document.addcp.regnum3.focus();
   return false;
  }

  for (var i = 0; i < regnum3.length; i++)
  {
   var ch = regnum3.substring(i,i+1);
   if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))
   {         
    alert("The third code you have entered is invalid.\n\nPlease re-enter the third code displayed on your car registration plate.");
    document.addcp.regnum3.focus();         
    document.addcp.regnum3.select();         
    return false;         
   }      
  }

  var regnum4 = document.addcp.regnum4.value;

  if (regnum4 == "")
  {
   alert("The registration number is blank.\n\nPlease enter the number displayed on your car registration plate.");
   document.addcp.regnum4.focus();
   return false;
  }

  for (var i = 0; i < regnum4.length; i++)
  {
   var ch = regnum4.substring(i,i+1);
   if ((ch < "0" || "9" < ch))
   {         
    alert("The registration number you have entered is invalid.\n\nPlease re-enter the correct number displayed on your car registration plate.");
    document.addcp.regnum4.focus();         
    document.addcp.regnum4.select();         
    return false;         
   }      
  }
 
 }


 if (((document.addcp.gender[0].checked) == 0) && ((document.addcp.gender[1].checked) == 0))
 {
  alert('Please identify your gender - male or female');
  return false;
 }
 
 var age = document.addcp.age.selectedIndex;
 if (document.addcp.age.options[age].value == '')
 {
  alert('Please select your age-group');       				
  document.addcp.age.focus();
  return false;
 }

 var occupation = document.addcp.occupation.selectedIndex;
 if (document.addcp.occupation.options[occupation].value == '')
 {
  alert('Please let us know your occupation');
  document.addcp.occupation.focus();
  return false;
 }

 var education = document.addcp.education.selectedIndex;
 if (document.addcp.education.options[education].value == '')
 {
  alert('Please indicate your level of education');
  document.addcp.education.focus();
  return false;
 }

 var language = document.addcp.language.selectedIndex;
 if (document.addcp.language.options[language].value == '')
 {
  alert('Please let us know your ethnic background');
  document.addcp.language.focus();
  return false;
 }

 var description = document.addcp.description.value;
 for (var i = 0; i < description.length; i++)
 {
  var count = i;
  if (count > 100)
  {         
   alert("Your description is a bit lengthy - please keep it brief.");
   document.addcp.description.focus();         
   document.addcp.description.select();         
   return false;         
  }      
 }

 var particulars = document.addcp.particulars.value;
 for (var i = 0; i < particulars.length; i++)
 {
  var count = i;
  if (count > 254)
  {         
   alert("Your particulars are a bit lengthy - please keep it brief.");
   document.addcp.particulars.focus();         
   document.addcp.particulars.select();         
   return false;         
  }      
 }


 return true;
}


