//**********************************************************************************
function validateSearch()
{
  searchForm = document.forms['Search'];
  if ( 
       isTextEmpty( searchForm.Art_No.value )      &&
       !isDropDownSelected('Category', 'Search')   &&
       isTextEmpty( searchForm.Description.value ) &&
       !searchForm.Stock_Available.checked         &&
       !searchForm.New_Tag.checked                 &&
       !searchForm.Hot_Tag.checked 
       
   )
  {
    alert("Please enter a valid search criteria.");
    return false;
  }
}

//**********************************************************************************
function validateEmailToFriend()
{ 
  MailForm = document.forms['EmailForm'];
  if ( isTextEmpty( MailForm.Your_Name.value )  )
  {
    alert("Please enter your name.");
    return false;
  }
  if ( ! isValidEmail( MailForm.Your_Email.value ) )
  {
    alert("Please enter your email address correctly");
    return false;
  }

  if ( isTextEmpty( MailForm.Your_Friends_Name.value )  )
  {
    alert("Please enter your friend's name.");
    return false;
  }
  if ( ! isValidEmail( MailForm.Your_Friends_Email.value ) )
  {
    alert("Please enter your friend's email address correctly");
    return false;
  }
}

//**********************************************************************************

function validateJoin(FormName)
{
  FormName1 = FormName;
  FormName  = document.forms[FormName];


// email

         if (!isValidEmail(FormName.email.value))
         {
           alert('Please enter a valid email address!');
           FormName.email.select();
           return false;
         }

// first_name
         if (isTextEmpty(FormName.first_name.value))
         {
           alert('Please enter your first name!');
           FormName.first_name.select();
           return false;
         }
        
// last_name
         if (isTextEmpty(FormName.last_name.value))
         {
           alert('Please enter your last name!');
           FormName.last_name.select();
           return false;
         }

// country
         if (!isDropDownSelected('country', 'Enquiry' ))
         {
           alert('Please select your country!');
           FormName.country.focus();
           return false;
         }


// pass_word
         if (isTextEmpty(FormName.pass_word.value))
         {
           alert('Please enter your password!');
           FormName.pass_word.focus();
           return false;
         }

// cpass_word
         if (isTextEmpty(FormName.cpass_word.value))
         {
           alert('Please confirm your password!');
           FormName.cpass_word.focus();
           return false;
         }

// cpass_word
         if (FormName.pass_word.value != FormName.cpass_word.value)
         {
           alert('The password and confirm password are not the same!');
           FormName.cpass_word.focus();
           return false;
         }

} 
//**********************************************************************************
function validateModify(FormName)
{
  FormName1 = FormName;
  FormName  = document.forms[FormName];


// first_name
         if (isTextEmpty(FormName.first_name.value))
         {
           alert('Please enter your first name!');
           FormName.first_name.select();
           return false;
         }
        
// last_name
         if (isTextEmpty(FormName.last_name.value))
         {
           alert('Please enter your last name!');
           FormName.last_name.select();
           return false;
         }

// country
         if (isTextEmpty(FormName.country.value))
         {
           alert('Please enter your country!');
           FormName.country.focus();
           return false;
         }

// email

         if (!isValidEmail(FormName.email.value))
         {
           alert('Please enter a valid email address!');
           FormName.email.select();
           return false;
         }

} 

//**********************************************************************************
function changePassword(FormName)
{
  FormName = document.forms[FormName];

  if (isTextEmpty(FormName.old_password.value)|| isTextEmpty(FormName.new_password1.value) || isTextEmpty(FormName.new_password2.value) )
         {
           alert('Please enter proper values!');
           FormName.old_password.select();
          return false;
          }

  if ( FormName.new_password1.value != FormName.new_password2.value )
         {
           alert('Your new password and confirm password are not the same!');
           FormName.new_password1.select();
          return false;
          }


        
 if (confirm('Are you sure you want to modify this entry?'))
  {
    FormName.submit();
  }

} //confirmModify()

//**********************************************************************************

function validateEnquiry(FormName)
{
  FormName1 = FormName;
  FormName  = document.forms[FormName];

// email

         if (!isValidEmail(FormName.email.value))
         {
           alert('Please enter a valid email address!');
           FormName.email.select();
           return false;
         }

// first_name
         if (isTextEmpty(FormName.first_name.value))
         {
           alert('Please enter your first name!');
           FormName.first_name.select();
           return false;
         }


// last_name
         if (isTextEmpty(FormName.last_name.value))
         {
           alert('Please enter your last name!');
           FormName.last_name.select();
           return false;
         }

// country
         if (!isDropDownSelected('country', 'Enquiry' ))
         {
           alert('Please select your country!');
           FormName.country.focus();
           return false;
         }

// comments
         if (isTextEmpty(FormName.comments.value))
         {
           alert('Please enter your comments!');
           FormName.comments.select();
           return false;
         }

} 
//**********************************************************************************
function validateLogin() {
  loginForm = document.forms['Login'];
  if ( isTextEmpty( loginForm.user_name.value ) ) {
    alert("Please enter your member id");
    loginForm.user_name.focus();
    return false;
  }

  if ( isTextEmpty( loginForm.pass_word.value ) ) {
    alert("Please enter your password");
    loginForm.pass_word.focus();
    return false;
  }
 
 
}

//**********************************************************************************

function validatePrescription(theForm)
{

  if (theForm.First_Name.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.First_Name.focus();
    return (false);
  }

  if (theForm.First_Name.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"First Name\" field.");
    theForm.First_Name.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.= \t\r\n\f";
  var checkStr = theForm.First_Name.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=\" characters in the \"First Name\" field.");
    theForm.First_Name.focus();
    return (false);
  }

  if (theForm.Last_Name.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Last_Name.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"Last Name\" field.");
    theForm.Last_Name.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.= \t\r\n\f";
  var checkStr = theForm.Last_Name.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=\" characters in the \"Last Name\" field.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address1.value == "")
  {
    alert("Please enter a value for the \"Street\" field.");
    theForm.Address1.focus();
    return (false);
  }

  //if (theForm.Address1.value.length > 18)
  //{
  //  alert("Please enter at most 18 characters in the \"Street\" field.");
  //  theForm.Address1.focus();
  //  return (false);
  //}

  //var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.= \t\r\n\f";
  //var checkStr = theForm.Address1.value;
  //var allValid = true;
  //for (i = 0;  i < checkStr.length;  i++)
  //{
  //  ch = checkStr.charAt(i);
  //  for (j = 0;  j < checkOK.length;  j++)
  //    if (ch == checkOK.charAt(j))
  //      break;
  //  if (j == checkOK.length)
  //  {
  //    allValid = false;
  //    break;
  //  }
  //}
  //if (!allValid)
  //{
  //  alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=\" characters in the \"Street\" field.");
  //  theForm.Address1.focus();
  //  return (false);
  //}

  if (theForm.Suburb_Town.value == "")
  {
    alert("Please enter a value for the \"Town/City\" field.");
    theForm.Suburb_Town.focus();
    return (false);
  }

  //if (theForm.Suburb_Town.value.length > 18)
  //{
  //  alert("Please enter at most 18 characters in the \"Town/City\" field.");
  //  theForm.Suburb_Town.focus();
  //  return (false);
  //}
  //
  //var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.= \t\r\n\f";
  //var checkStr = theForm.Suburb_Town.value;
  //var allValid = true;
  //for (i = 0;  i < checkStr.length;  i++)
  //{
  //  ch = checkStr.charAt(i);
  //  for (j = 0;  j < checkOK.length;  j++)
  //    if (ch == checkOK.charAt(j))
  //      break;
  //  if (j == checkOK.length)
  //  {
  //    allValid = false;
  //    break;
  //  }
  //}
  //if (!allValid)
  //{
  //  alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=\" characters in the \"Town/City\" field.");
  //  theForm.Suburb_Town.focus();
  //  return (false);
  //}

  if (theForm.Post_Code.value.length > 9)
  {
    alert("Please enter at most 9 characters in the \"Post Code\" field.");
    theForm.Post_Code.focus();
    return (false);
  }

  if (theForm.Post_Code.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Post Code\" field.");
    theForm.Post_Code.focus();
    return (false);
  }

  //var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.= \t\r\n\f";
  //var checkStr = theForm.Post_Code.value;
  //var allValid = true;
  //for (i = 0;  i < checkStr.length;  i++)
  //{
  //  ch = checkStr.charAt(i);
  //  for (j = 0;  j < checkOK.length;  j++)
  //    if (ch == checkOK.charAt(j))
  //      break;
  //  if (j == checkOK.length)
  //  {
  //    allValid = false;
  //    break;
  //  }
  //}
  //if (!allValid)
  //{
  //  alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=\" characters in the \"Post Code\" field.");
  //  theForm.Post_Code.focus();
  //  return (false);
  //}

  if (theForm.Make.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Make\" field.");
    theForm.Make.focus();
    return (false);
  }

  //var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.= \t\r\n\f";
  //var checkStr = theForm.Make.value;
  //var allValid = true;
  //for (i = 0;  i < checkStr.length;  i++)
  //{
  //  ch = checkStr.charAt(i);
  //  for (j = 0;  j < checkOK.length;  j++)
  //    if (ch == checkOK.charAt(j))
  //      break;
  //  if (j == checkOK.length)
  //  {
  //    allValid = false;
  //    break;
  //  }
  //}
  //if (!allValid)
  //{
  //  alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=\" characters in the \"Make\" field.");
  //  theForm.Make.focus();
  //  return (false);
  //}

  if (theForm.Model.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Model\" field.");
    theForm.Model.focus();
    return (false);
  }

  //var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.= \t\r\n\f";
  //var checkStr = theForm.Model.value;
  //var allValid = true;
  //for (i = 0;  i < checkStr.length;  i++)
  //{
  //  ch = checkStr.charAt(i);
  //  for (j = 0;  j < checkOK.length;  j++)
  //    if (ch == checkOK.charAt(j))
  //      break;
  //  if (j == checkOK.length)
  //  {
  //    allValid = false;
  //    break;
  //  }
  //}
  //if (!allValid)
  //{
  //  alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=\" characters in the \"Model\" field.");
  //  theForm.Model.focus();
  //  return (false);
  //}

  var checkOK = "0123456789-";
  var checkStr = theForm.Year.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Year\" field.");
    theForm.Year.focus();
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q1.length;  i++)
  {
    if (theForm.Q1[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 1\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q2.length;  i++)
  {
    if (theForm.Q2[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 2\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q4.length;  i++)
  {
    if (theForm.Q4[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 3\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q5.length;  i++)
  {
    if (theForm.Q5[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 4\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q6.length;  i++)
  {
    if (theForm.Q6[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 5\" options.");
    return (false);
  }

  if (theForm.Q6[1].checked)
  {
    var radioSelected = false;
    for (i = 0;  i < theForm.Q6_2.length;  i++)
    {
      if (theForm.Q6_2[i].checked)
          radioSelected = true;
    }
    if (!radioSelected)
    {
      alert("Please select one of the options from the second section of \"Question 5\".");
      return (false);
    }
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q7.length;  i++)
  {
    if (theForm.Q7[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 6\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q8.length;  i++)
  {
    if (theForm.Q8[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 7\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q10.length;  i++)
  {
    if (theForm.Q10[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 8\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q14.length;  i++)
  {
    if (theForm.Q14[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 11\" options.");
    return (false);
  }

  if (theForm.Q14[0].checked)
  {
    if (theForm.Email.value == "")
    {
      alert("Please enter a value for the \"Email\" field.");
      theForm.Email.focus();
      return (false);
    }

    //if (theForm.Email.value.length > 35)
    //{
    //  alert("Please enter at most 35 characters in the \"Email\" field.");
    //  theForm.Email.focus();
    //  return (false);
    //}
    //
    //var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒþŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-()/\\+'[]&,.=<>_#-@ \t\r\n\f";
    //var checkStr = theForm.Email.value;
    //var allValid = true;
    //for (i = 0;  i < checkStr.length;  i++)
    //{
    //  ch = checkStr.charAt(i);
    //  for (j = 0;  j < checkOK.length;  j++)
    //    if (ch == checkOK.charAt(j))
    //      break;
    //  if (j == checkOK.length)
    //  {
    //    allValid = false;
    //    break;
    //  }
    //}
    //if (!allValid)
    //{
    //  alert("Please enter only letter, digit, whitespace and \"()/\\+'[]&,.=<>_#-@\" characters in the \"Email\" field.");
    //  theForm.Email.focus();
    //  return (false);
    //}
  }
  return (true);
}