
var currTimer = null;
var currEleID = null;
var defaultID = null;

function setDefault(eleID) {
  defaultID = eleID;
  showHide(defaultID, true, false);
  //alert(eleID);
}

function showHide(eleID, showEle, useDelay) {
  if(useDelay) {
    currTimer = setTimeout("showHide('"+eleID+"', "+showEle+", false)", 5000);
  } else {
    var ele = document.getElementById(eleID);
    if(ele) {
    if(showEle) {
      if(currTimer!=null) {
        clearTimeout(currTimer);
      }
      if(currEleID!=null) {
        var ele2 = document.getElementById(currEleID);
        ele2.style.display = 'none';
      }
      currEleID = eleID;
      //alert('showing: '+eleID);
      ele.style.display = 'block';
    } else {
      //alert('hiding: '+eleID);
      ele.style.display = 'none';
      if(currEleID==eleID) {
        currEleID = null;
        
        showHide(defaultID, true, false);
      }
    }
    }
  }
}

function setEnabled(isEnabled) {
  var address   = document.getElementById('billInfo_address');
  var city     = document.getElementById('billInfo_city');
  var state     = document.getElementById('billInfo_state');
  var zip     = document.getElementById('billInfo_zip');
  
  if(isEnabled) {
    address.style.backgroundColor   = '#fff';
    city.style.backgroundColor     = '#fff';
    state.style.backgroundColor   = '#fff';
    zip.style.backgroundColor     = '#fff';
  } else {
    address.style.backgroundColor   = '#ddd';
    city.style.backgroundColor     = '#ddd';
    state.style.backgroundColor   = '#ddd';
    zip.style.backgroundColor     = '#ddd';
  }
  
  address.disabled   = !isEnabled;
  city.disabled     = !isEnabled;
  state.disabled     = !isEnabled;
  zip.disabled     = !isEnabled;
}

function validateCardNo(input, inputDiv) {//'payInfo_cardNumber_input','payInfo_cardNumber') {
  var cardNo = document.getElementById(input).value;
  
  var xmlhttp = new XMLHttpRequest();
  var vars = 'cardNo='+cardNo;
  xmlhttp.open('POST','/~matistry/cardValidate_ajax.php?'+vars,true);
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", vars.length);
  xmlhttp.setRequestHeader("Connection", "close");
  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4) {
      var inputDivObj = document.getElementById(inputDiv);
      //alert(xmlhttp.responseText);
      var arr = xmlhttp.responseText.split('|');
      
      //document.getElementById('cardType_americanexpress').className   = '';
      document.getElementById('cardType_discover').className       = '';
      document.getElementById('cardType_mastercard').className     = '';
      document.getElementById('cardType_visa').className         = '';
      
      var typeEle = document.getElementById('cardType_'+arr[0].replace(' ',''));
      if(typeEle!=null) {
        typeEle.className = 'img_sel';
      }
      
      if(arr[1]=='1') {
        inputDivObj.className = 'chOutPage_row_cell';
      } else {
        inputDivObj.className = 'chOutPage_row_cell chOutPage_row_cellErr';  
      }
      
    }
  }
  xmlhttp.send(vars);
}

function retrieveShipQuote(shippingID, destZipID, qtyID, username, startZip, services) {
  
  var destZip = document.getElementById(destZipID);
  destZip = destZip.value;
  
  var qty = document.getElementById(qtyID);
  qty = qty.value;
  
  if(qty>0) {
  
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET','./js/ajax_getShipQuotes.php?username='+username+'&startZip='+startZip+'&destZip='+destZip+'&qty='+qty+'&services='+services,true);
    xmlhttp.onreadystatechange = function() {
      if(xmlhttp.readyState == 4) {
        var ele = document.getElementById(shippingID);
        ele.innerHTML = xmlhttp.responseText;
      }
    }
    xmlhttp.send(null);
  
  }
}

