var badInputColor="#FF0505";
var goodInputColor="#FFFFFF";
//dont specify the email input name its being taken care of ;)
var arrofInputNames = new Array('name', 'company', 'phone'); 
var arrLen = arrofInputNames.length;


//regexp verification of the validity of the e-mail address
function isValidEmail(sMail)
{
  var re=/^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi;
  return (sMail.match(re)==sMail)&&(sMail.substr(sMail.lastIndexOf("@")).length<=256);
}
// regexp verification of the validation of the TLD
function bDomainTLD(sMail)
{
 var re=/^(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|aero|arpa|biz|com|coop|edu|eu|gov|info|int|mil|museum|name|net|org|pro|jobs|travel)$/gi;
 return sMail.substr(sMail.lastIndexOf(".") + 1).match(re)!=null;
}

// Reset the background color of the corrected field if necessary
function validField(o)
{
 if (o.style.backgroundColor) o.style.backgroundColor="#FFFFFF";
}
// Change the background color 
function invalidField(o)
{
 o.style.backgroundColor=badInputColor;
} 
function checkAnswer(formid)
{
  var valid = true;
  var formobj = document.getElementById(formid);
  //alert(formobj);
  //alert(formobj.name.value);
  for (var i = 0; i < arrLen; i++)
  {
    var curInput = eval("document.forms[formid]." + arrofInputNames[i]);
    if (curInput.value.length < 1)
    {
      if (valid) curInput.focus(); //focus on the first failed field
      invalidField(curInput);
      valid = false;    
    }
  }
  // Check of email syntax
  if (formobj.email.value.length > 8) // example: a@aaa.cc
  {
    var val = formobj.email.value.toLowerCase();
    if (!isValidEmail(val) || !bDomainTLD(formobj.email.value))
    {
      invalidField(formobj.email);
      valid = false;
    }
    else
    {
      validField(formobj.email);
    }
  }
  else 
  {
      invalidField(formobj.email);
      valid = false;
  }
  return valid;
}

function sendAnswer()
{
  if (checkAnswer('contact')) document.forms['contact'].submit();
  else 
  {
    alert('invalid input has been turned to a different color' +
    ' please change them before trying to send them again');
  }
  return false;
}

function doThanks(lan)
{
  lan = (lan=undefined) ? en : lan;
  switch (lan)
  {
    case 'es':
    window.alert() 
    break;
    default:
    window.alert('Thank you for entering this sensitive information we will' +
    'contact you as soon as possible with a comprehensive solution for your' + 
    ' needs');
  }
}
