// Form Submission by button

function doReset(sFldId)
{
  var oForm = document.getElementById("theForm");
  if (oForm != null) oForm.reset();

  var oFld = document.getElementById(sFldId);
  if (oFld != null) oFld.focus();
}
function doSubmitSpptReg()
{
   if (!TestNotNull("custno", "customer number")) return;
   if (!TestNotNull("cntct", "contact")) return;
   if (!TestNotNull("cmpny", "company")) return;
   if (!TestNotNull("cty", "city")) return;
   if (!TestNotNull("stt", "state")) return;
   if (!TestNotNull("cntry", "country")) return;
   if (!TestNotNull("tlphn", "telephone")) return;
   if (!TestNotNull("eml", "email address")) return;
   if (document.theForm.signup.selectedIndex == 0) {
     window.alert("Please select a support option");
     document.theForm.signup.focus();
     return;
   }
   if (document.theForm.signup.selectedIndex > 0) {
     var sMail = document.theForm.eml.value;
     var iFndAt = sMail.indexOf("@");
     var iFndDot = sMail.indexOf(".");
     if (iFndAt <= 0 || iFndDot <=0) {
       window.alert("Please enter a valid email address");
       document.theForm.eml.focus();
       return;
     }
    
   }
   var oForm = document.getElementById("theForm");
   if (oForm != null) oForm.submit();
}
function doSubmitGetPwd()
{
   if (!TestNotNull("email", "email address")) return;
   if (!TestNotNull("phone", "phone number")) return;
   var oForm = document.getElementById("theForm");
   if (oForm != null) oForm.submit();
}

function doSubmitRequest()
{
  if (!TestNotNull("name", "name")) return;
  if (!TestNotNull("title", "job title")) return;
  if (!TestNotNull("company", "company's name")) return;
  if (!TestNotNull("address", "address")) return;
  if (!TestNotNull("city", "city")) return;
  if (!TestNotNull("state", "state")) return;
  if (!TestNotNull("zipcode", "zip code")) return;
  if (!TestNotNull("country", "country")) return;
  if (!TestNotNull("phone", "telephone number")) return;
  if (!TestNotNull("email", "email address")) return;
  if (!TestIsValid("email", "email address")) return;
  if (!TestNotSelected("orgtype", "organization type")) return;
  if (!TestNotSelected("envtype", "environment type")) return;
  if (!TestNotSelected("apptype", "application type")) return;
  if (!TestNotSelected("hwtype", "existing hardware type")) return;
  if (!TestNotSelected("timeframe", "solution time frame")) return;
  if (!TestNotNull("wherefrom", "source where you heard about RFGen")) return;
  
  var oForm = document.getElementById("theForm");
  if (oForm != null) oForm.submit();
}

function TestIsNumeric(sId, sDesc)
{
  var oFld = document.getElementById(sId);
  if (oFld == null) {
    window.alert(sId + " element not found!");
    return false;
  }

  var ValidChars = "0123456789.";
  var sChar;

  for (i=0; i < oFld.value.length; i++) { 
    sChar = oFld.value.charAt(i); 
    if (ValidChars.indexOf(sChar) == -1) {
      window.alert("Please enter a valid " + sDesc);
      oFld.focus();
      return false;
    }
  }    
  return true;
}

function TestIsValid(sId, sDesc)
{
  var oFld = document.getElementById(sId);
  if (oFld == null) {
    window.alert(sId + " element not found!");
    return false;
  }
  
  var iFndAt = oFld.value.indexOf("@");
  var iFndDot = oFld.value.indexOf(".");
  if (iFndAt <= 0 || iFndDot <=0) {
    window.alert("Please enter a valid " + sDesc);
    oFld.focus();
    return false;
  }
  return true;
}

function TestNotNull(sId, sDesc)
{
  var oFld = document.getElementById(sId);
  if (oFld == null) {
    window.alert(sId + " element not found!");
    return false;
  }
  
  if (oFld.value.length < 2) {
    if (sDesc != "") window.alert("Please enter your " + sDesc);
    oFld.focus();
    return false;
  }
  return true;
}
  
function TestNotSelected(sId, sDesc)
{
  var oFld = document.getElementById(sId);
  if (oFld == null) {
    window.alert(sId + " element not found!");
    return false;
  }
  
  if (oFld.selectedIndex < 1) {
    if (sDesc != "") window.alert("Please identify your " + sDesc);
    oFld.focus();
    return false;
  }
  return true;
}

function TestEquals(sId1, sId2, sDesc)
{
  var oFld1 = document.getElementById(sId1);
  if (oFld1 == null) {
    window.alert(sId1 + " element not found!");
    return false;
  }
  
  var oFld2 = document.getElementById(sId2);
  if (oFld2 == null) {
    window.alert(sId2 + " element not found!");
    return false;
  }
  
  if (oFld1.value != oFld2.value) {
    if (sDesc != "") window.alert("Please enter your " + sDesc);
    oFld1.focus();
    return false;
  }
  return true;
}
  
