
function unHighLightRequired(){
  var eArr = new Array("emailH", "planH", "companyH", "monthlyFeeH");
  for(var i = 0; i < eArr.length; i ++){
    var e = getElement(eArr[i]);
    if((e.style != null) && (e.style.fontWeight == "bold")){
      e.style.fontWeight = "bold";
      e.style.color = "black";
    }
  }
}


function isFormValidator(theForm){
  
  unHighLightRequired();
  
  var theMessage = "";
  var ckEmail = getIfEmailValueIsBogusMessage(theForm.requestorsEmailAddress, "your email address");
  if(ckEmail != ""){
    theMessage = ckEmail;
    var e = getElement("emailH");
    e.style.color = "red";
    e.style.fontWeight = "bold";
  }
  if (theForm.company.value == "")  {
    theMessage = theMessage + "Please provide Company Name\n";
    var e = getElement("companyH");
    e.style.color = "red";
    e.style.fontWeight = "bold";
  }
  if (theForm.plan.value == "") {
    theMessage = theMessage + "Please provide Plan Name\n";
    var e = getElement("planH");
    e.style.color = "red";
    e.style.fontWeight = "bold";
  }

  if(theForm.editType.value != "Delete_this_plan"){
    if(theForm.monthlyFee.value == ""){
      theMessage = theMessage + "Please provide Monthly Fee\n";
      var e = getElement("monthlyFeeH");
      e.style.color = "red";
      e.style.fontWeight = "bold";
    }
  }
  
  if(theMessage != "")
  {
    alert(theMessage);
    return false;
  }
  theForm.starttime.value = theForm.sMonth.value+"/"+theForm.sDay.value+"/"+theForm.sYear.value;
  theForm.endtime.value = theForm.eMonth.value+"/"+theForm.eDay.value+"/"+theForm.eYear.value;
  return true;
}



function isFormValidatorReseller(theForm){
  
  unHighLightRequired();
  
  var theMessage = "";
  var ckEmail = getIfEmailValueIsBogusMessage(theForm.requestorsEmailAddress, "your email address");
  if(ckEmail != ""){
    theMessage = ckEmail;
    var e = getElement("emailH");
    e.style.color = "red";
    e.style.fontWeight = "bold";
  }
  if (theForm.company.value == "")  {
    theMessage = theMessage + "Please provide Company Name\n";
    var e = getElement("companyH");
    e.style.color = "red";
    e.style.fontWeight = "bold";
  }
  if (theForm.plan.value == "") {
    theMessage = theMessage + "Please provide Plan Name\n";
    var e = getElement("planH");
    e.style.color = "red";
    e.style.fontWeight = "bold";
  }
  
  if(theMessage != "")
  {
    alert(theMessage);
    return false;
  }
  theForm.starttime.value = theForm.sMonth.value+"/"+theForm.sDay.value+"/"+theForm.sYear.value;
  theForm.endtime.value = theForm.eMonth.value+"/"+theForm.eDay.value+"/"+theForm.eYear.value;
  return true;
}






function getIfEmailValueIsBogusMessage(e, tit){
  var re = /^[a-z0-9]([a-z0-9_\.\-\+])*\@([a-z0-9]([a-z0-9\-])*\.)+([a-z0-9])+\s*$/ig;
    if(!(e.value.match(re))){
      return "\""+e.value+"\" for " + tit + " is not a valid email address.\n";
    }
    return "";
}

function getElement(e){
  var el = null;
    el = document.getElementById(e);
    if(el == null){
      var iEl = document.all.e;
        if (iEl != null){
          el = iEl;
        }
    }
    return el;
}

function modalReset(f){
  if(confirm("Reset the form?")){
    unHighLightRequired();
    return true;
  }
  return false;
}

