﻿function submitForm(EmailFieldName, optionalArg)
{
  var msg;

  var strEmail  = string_trim(document.frmForm.Email.value);
  var strPWD    = string_trim(document.frmForm.PWD.value);
  //var strVal    = /^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*(.[a-zA-Z]{2,3})$/
  var flagEmail = false;
  
  //if(!strVal.exec(strEmail)){ flagEmail = false } else { flagEmail = true }
  flagEmail = true;
  
  if (strEmail == "" || flagEmail == false)
  {
    msg = "Please enter a value for the \"Email\" field.";
    msg = msg.replace(/Email/, EmailFieldName);

    alert(msg);

    document.frmForm.Email.value = "";
    document.frmForm.Email.focus();

    if (!optionalArg)
    {
      return false;
    }
  }
  else if (strPWD == "" && optionalArg != "forgot")
  {
    alert("Please enter a value for the \"Password\" field.");

    document.frmForm.PWD.value = "";
    document.frmForm.PWD.focus();

    if (!optionalArg)
    {
      return false;
    }
  }
  else
  {
    if(optionalArg == "forgot"){
      document.frmForm.nlnk.value = "forgot";
      document.frmForm.PWD.value = "";
    } else {
      document.frmForm.nlnk.value = "enter";
    }
    document.frmForm.submit();
  }
}
function check_PromotionCode(xcode){
  xmlHttp = GetXmlHttpObject();
  if( xmlHttp == null ){
//    No podemos cotejar que el codigo de descuento sea valido, que hacemos?
    alert("Your browser does not support AJAX!");
    return;
  }
  
  url = "../register/validDiscountCode.asp?dc=" + xcode + "&sid=" + Math.random();

  xmlHttp.onreadystatechange = XmlHttpStateChanged;
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);

}

function XmlHttpStateChanged()
{
  if (xmlHttp.readyState == 4){                 // the request is complete
    var strRText = xmlHttp.responseText;
    if( strRText == "Yes" ){
      document.frmRegister.submit();
    } else {
      alert(strWrongDiscountCode);
      document.frmRegister.DiscountCode.focus();
    }
    return false;
  }
}


