﻿function TechHelpValidator(theForm)


{
  var checkStr = theForm.TechHelpName.value;
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    if (ch == "'")
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("SVP, veuillez mettre votre nom au lieu de ' dans le champ  Nom.");
    theForm.TechHelpName.focus();
    return (false);
  }


  if (theForm.TechHelpName.value == "")
  {
    alert("SVP, veuillez mettre votre nom dans le champ Nom.");
    theForm.TechHelpName.focus();
    return (false);
  }

  if (theForm.TechHelpName.value.length < 2)
  {
    alert("SVP, veuillez mettre au moins 2 caractères dans le champ Nom.");
    theForm.TechHelpName.focus();
    return (false);
  }

  if (theForm.TechHelpName.value.length > 75)
  {
    alert("SVP, veuillez mettre au maximum 75 caractères dans le champ Nom.");
    theForm.TechHelpName.focus();
    return (false);
  }


  
/* Was COMMENTED OUT */

 if (theForm.TechHelpOrganization.value == "")
  {
    alert("SVP, veuillez mettre le nom de votre organisation dans le champ Organisation.");
    theForm.TechHelpOrganization.focus();
    return (false);
  }
/*  was COMMENTED OUT */ 
  if (theForm.TechHelpOrganization.value.length < 2)
  {
    alert("SVP, veuillez mettre au moins 2 caractères dans le champ Organisation.");
    theForm.TechHelpOrganization.focus();
    return (false);
  }

  if (theForm.TechHelpOrganization.value.length > 100)
  {
    alert("SVP, veuillez mettre un maximum de 100 caractères dans le champ Organisation.");
    theForm.TechHelpOrganization.focus();
    return (false);
  }


 
  

  



  if (theForm.TechHelpEmail.value == "")
  {
    alert("SVP, veuillez mettre votre courriel dans le champ Courriel.");
    theForm.TechHelpEmail.focus();
    return (false);
  }

/* TEST:  COMMENTed OUT  for now

  if (theForm.TechHelpEmail.value.length < 8)
  {
    alert("SVP, veuillez mettre au moins 8 caractères dans le champ Courriel.");
    theForm.TechHelpEmail.focus();
    return (false);
  }

  if (theForm.TechHelpEmail.value.length > 100)
  {
    alert("SVP, veuillez mettre au maximum 100 caractères dans le champ Courriel.");
    theForm.TechHelpEmail.focus();
    return (false);
  }

  var checkStr = theForm.TechHelpEmail.value;
  
  if (checkStr.charAt(0) == " ")
  {
    alert("SVP, ne mettez pas d'espace devant votre courriel.");
    theForm.TechHelpEmail.focus();
    return (false);
  }

******/





  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz??????????????????????????????????????????????????????????????????????0123456789-@_.";
  var checkStr = theForm.TechHelpEmail.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("SVP, veuillez mettre que des lettres, des chiffres et les caractères @._-  dans le champ Courriel.");
    theForm.TechHelpEmail.focus();
    return (false);
  }

  var checkStr = theForm.TechHelpEmail.value;
  var emailValid1 = false;
  var emailValid2 = false;

  for (i = 0;  i < checkStr.length;  i++)
  { 
 	ch = checkStr.charAt(i);
 	if (ch == "@")
 	  {
 	   emailValid1 = true;
  	   break;
  	  }
  }

  for (i = 0;  i < checkStr.length;  i++)
  { 
 	ch = checkStr.charAt(i);
 	if (ch == ".")
     {
	   emailValid2 = true;
 	   break;
 	  }
  }
  if (emailValid1 == false || emailValid2 == false)
  {
	alert("SVP, veuillez mettre votre courriel comme il faut.");
   theForm.TechHelpEmail.focus();
   return (false);
  }
 
 
 
 
 
  
 /*  TEST: AREA CODE VARIABLES PLACED HERE  */
  
   var checkOK = "0123456789-";
  var checkStr = theForm.TechHelpAreaCode.value;
  var allValid = true;
  var validGroups = 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("SVP, veuillez mettre que des chiffres dans le champ Indicatif régional.");
    theForm.TechHelpAreaCode.focus();
    return (false);
  }
   
  
  
 
 if (theForm.TechHelpAreaCode.value == "")
  {
    alert("SVP, veuillez mettre votre indicatif régional dans le champ Indicatif régional.");
    theForm.TechHelpAreaCode.focus();
    return (false);
  }

  if (theForm.TechHelpAreaCode.value.length < 3)
  {
    alert("SVP, veuillez mettre au moins 3 chiffres dans le champ Indicatif régional.");
    theForm.TechHelpAreaCode.focus();
    return (false);
  }

  if (theForm.TechHelpAreaCode.value.length > 3)
  {
    alert("SVP, veuillez mettre au maximum 3 chiffres dans le champ Indicatif régional.");
    theForm.TechHelpAreaCode.focus();
    return (false);
  }
  
  
 
   /*  TEST: PHONE NUMBER VARIABLES PLACED HERE  */
   
     var checkOK = "0123456789--";
  var checkStr = theForm.TechHelpPhone.value;
  var allValid = true;
  var validGroups = 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("SVP, veuillez mettre que des chiffres et  -  dans le champ Téléphone.");
    theForm.TechHelpPhone.focus();
    return (false);
  }
  
  
  

  if (theForm.TechHelpPhone.value == "")
  {
    alert("SVP, veuillez mettre votre numéro de téléphone dans le champ Téléphone.");
    theForm.TechHelpPhone.focus();
    return (false);
  }

  if (theForm.TechHelpPhone.value.length < 7)
  {
    alert("SVP, veuillez mettre au moins 7 chiffres dans le champ Téléphone .");
    theForm.TechHelpPhone.focus();
    return (false);
  }

  if (theForm.TechHelpPhone.value.length > 8)
  {
    alert("SVP, veuillez mettre un maximum de 8 chiffres dans le champ Téléphone.");
    theForm.TechHelpPhone.focus();
    return (false);
  }
  
  
  
  
    /*  TEST: COMMENTS VARIABLES ADDED HERE  
	
	

{
  var checkStr = theForm.TechHelpComments.value;
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    if (ch == "'")
    {
      allValid = false;
      break;
    }
  }
  
  
  */ 
  
  

  if (theForm.TechHelpComments.value == "")
  {
    alert("SVP, veuillez décrire le problème dans le champ Description du problème.");
    theForm.TechHelpComments.focus();
    return (false);
  }
  
	
/* TEST: COMMENTING OUT THIS PART - When I commented out the last lines, it didn't work anymore */


  return (true);
}


