// shows new div when submit is clicked
function showProgressBar() {
    if (document.getElementById('displayInProgress') != null) {
       document.getElementById('displayInProgress').style.top = document.body.scrollTop + 150;
       document.getElementById('displayInProgress').style.visibility = 'visible';
    }
}

function disableButtons() {
    if (document.getElementById('submitform') != null) {
       document.getElementById('submitform').value = "Please Wait.....";
       document.getElementById('submitform').disabled = true;
    }

    if (document.getElementById('resetform') != null) {
       document.getElementById('resetform').disabled = true;
    }

    showProgressBar();
}

// focus on the first text element
function focus1() {
    var inputs = document.getElementsByTagName('input');
    for (var k=0; k<inputs.length; k++)
    {
        if ((inputs[k].type == 'text') && (inputs[k].disabled == 'false'))
        {
                inputs[k].focus();
                return true;
        }
    }
}
// Used on signup to show which template is selected
function select_tem(template)
{
	window.location.href="http://signup.esiteasp.com/ntpa/details.html?template=" + template
}

// Shows the instructions for putting a nxg template on a page
function select(id)
{
        window.location.href="http://signup.esiteasp.com/ntpa/latest_support/location.html?template=" + id
}

// validation code used on Lookup Account
function check_status(){
  if (document.forms[0].office_status.checked)
     document.forms[0].office_status.value = "ACTCLS";
}

function set_status(){
  document.forms[0].office_status.value = "ACTCLS";
}

function validate(){
  check_status();
  var m = /^\*/;
  if (document.forms[0].key_value.value.match(m) != null)
  {
    alert("Invalid Entry");
    document.forms[0].key_value.focus();
    return false;
  }
  else if (document.forms[0].key_value.value == "")
  {
    alert('You must enter a "Search For" value');
    document.forms[0].key_value.focus();
    return false;
  }
  else
  {
    for(var i = 0; i < document.forms[0].key_fld.length; i++) {
      if (document.forms[0].key_fld[i].checked)
        document.forms[0].key_fld.value = document.forms[0].key_fld[i].value;
    }
    for(var i = 0; i < 3; i++) {
      if (document.forms[0].sort_by[i].checked)
        document.forms[0].sort_by.value = document.forms[0].sort_by[i].value;
    }
    for(var i = 0; i < 2; i++) {
      if (document.forms[0].match_type[i].checked)
        document.forms[0].match_type.value = document.forms[0].match_type[i].value;
    }
    disableButtons();
    return true;
  }
}

// Validate Fields on History view page
function hist_validate() {
  // Account Name is mandatory
  if (document.getElementById('member_name').value == "") {
     alert("You must enter a value for Account Name");
     document.getElementById('member_name').focus();

     return false;
  }

  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
  
  // Start and End dates must be mm/dd/yy if entered.
  if (document.getElementById('start_date').value != "") {
     var matchArray = document.getElementById('start_date').value.match(datePat); // is the format ok?
     if (matchArray == null) {
        alert("Start Date is not in a valid format. It should be in the format MM/DD/YY")
        document.getElementById('start_date').value="";
        document.getElementById('start_date').focus();
        return false;
     }
  }

  if (document.getElementById('end_date').value != "") {
     var matchArray = document.getElementById('end_date').value.match(datePat); // is the format ok?
     if (matchArray == null) {
        alert("End Date is not in a valid format. It should be in the format MM/DD/YY")
        document.getElementById('end_date').value="";
        document.getElementById('end_date').focus();
        return false;
     }
  }

  disableButtons();
  return true;  // date is valid
}
 
// Used on update member record
function validate_memberupdate_step2(){

  var valid;
  var myForm = document.forms[0];

  valid = lengthValidater(myForm.email, "Email", 0);
  if (!(valid)) {
     return false;
  }
  valid = lengthValidater(myForm.first, "First Name", 0);
  if (!(valid)) {
     return false;
  }
  valid = lengthValidater(myForm.last, "Last Name", 0);
  if (!(valid)) {
     return false;
  }
  valid = lengthValidater(myForm.phone, "Phone", 9);
  if (!(valid)) {
     return false;
  }
  valid = lengthValidater(myForm.city, "City", 0);
  if (!(valid)) {
     return false;
  }
  valid = lengthValidater(myForm.state, "State/Province", 0);
  if (!(valid)) {
     return false;
  }
  valid = lengthValidater(myForm.zip, "Zip/Postal Code", 4);
  if (!(valid)) {
     return false;
  }
 
  myForm.submit();
  return true;
}

function lengthValidater(formElement, elementName, elLength)
{
   if (formElement.value.length <= elLength)
   {
      alert("The " + elementName + " must have at least " + (elLength + 1) + " character(s). Please fix the value.");
      formElement.focus();
      return false;
   }
   else
   {
      return true;
   }
}


function popup2() {

newwin=window.open('/vsell/new/service_agreement.html','newwin','height=250,width=575,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');
 
  }

function popup3() {

newwin=window.open('/vsell/new/store_service_agreement.html','newwin','height=250,width=575,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');

 }
 
 function SetCurrencyVars()
{

var EPCurrency = document.forms[0].NVO_PRIVATE_ECOM_Primary_Currency;
var ELocale = document.forms[0].NVO_PRIVATE_ECOM_Locale;
  EPCurrency.value = document.forms[0].Currency.options[document.forms[0].Currency.selectedIndex].value;
  ELocale.value = document.forms[0].Locale.options[document.forms[0].Locale.selectedIndex].value;
  
  //document.write("Currency: " + EPCurrency.value + "<BR>");
  //document.write("Locale: " + ELocale.value + "<BR>");

}

function SetCurrencyLists()
{

  var EPCurrency = document.forms[0].NVO_PRIVATE_ECOM_Primary_Currency;
  var ELocale = document.forms[0].NVO_PRIVATE_ECOM_Locale;
  //document.write("Currency: " + EPCurrency.value + "<BR>");
  //document.write("Locale: " + ELocale.value + "<BR>");

  for (i = 0; i < document.forms[0].Currency.length; i++) 
  {
     // verify that the form element exists before assigning to it
     if (document.forms[0].Currency.options[i].value == EPCurrency.value)
        {
        document.forms[0].Currency.options[i].selected = true;
        }
     else
        {
        document.forms[0].Currency.options[i].selected = false;
        }
  }

  for (i = 0; i < document.forms[0].Locale.length; i++) 
  {
     //verify that the form element exists before assigning to it
    if (document.forms[0].Locale.options[i].value == ELocale.value)
        {
        document.forms[0].Locale.options[i].selected = true;
        }
    else
        {
        document.forms[0].Locale.options[i].selected = false;
        }
  }    
}
