var httpReq;
var idObj;
var msgsObj;

function createRequestObject() {
   var ro;

   if (window.XMLHttpRequest) {
      ro = new XMLHttpRequest();
   } else {
      if (window.ActiveXObject) {
         ro = new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return ro;
}

function getData(t, c) {
   targetObjID = c;
   if(c >= 0) {
      idObj = document.getElementById('ids'+c);
      h = document.getElementById('sHeight'+c).value;
      w = document.getElementById('sWidth'+c)[document.getElementById('sWidth'+c).selectedIndex].value;
      msgsObj = document.getElementById('msgBox');
   }

   if(t == 'cw_8200_sps_w_cus' && parseInt(w) == 120 && (document.getElementById('wType').value == 'IMPACT' || document.getElementById('wType').value == 'Secure Plus')) {
      alert('Maximum available width is 108');
      document.getElementById('sWidth'+c).selectedIndex = 0;
      return;
   }

   if(t == 'cw_8200_hr_w_cus' && parseInt(h) == 63)
      h = 60;

   if(t == 'cw8100sh_w_cus' && h == '74 3/4')
      h = 78;
   httpReq = createRequestObject();
   var aParams = new Array();
   var sParam = encodeURIComponent("t");
   sParam += "=";
   sParam += encodeURIComponent(t);
   aParams.push(sParam);

   sParam = encodeURIComponent("w");
   sParam += "=";
   sParam += encodeURIComponent(w);
   aParams.push(sParam);

   sParam = encodeURIComponent("h");
   sParam += "=";
   sParam += encodeURIComponent(h);
   aParams.push(sParam);

   sBody = aParams.join("&");
   url = "get_cw_form_cus_props.php";
   httpReq.open("POST", url, true);
   httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   httpReq.onreadystatechange = handleResponse;
   httpReq.send(sBody);
}

function checkReadyState() {
   if(httpReq.readyState < 4) {
      msgsObj.style.display = "block";
   } else if(httpReq.readyState == 4) {
      return (httpReq.status == 200);
   }
}

function handleResponse() {
   if(checkReadyState()) {
      if(httpReq.responseText) {
         msgsObj.style.display = "none";
         idObj.value = httpReq.responseText;
      }
   }
}

function validate() {

   if(document.getElementById('wType')) {
      if(document.getElementById('wType')[document.getElementById('wType').selectedIndex].value.length == 0) {
         alert('Please select Window Type!');
         document.getElementById('wType').focus();
         return false;
      }
   }

   document.getElementById('confirmOK').value = 1;
   return true;
}

function form8200Cus(wt) {
   if(wt == 'IMPACT' || wt == 'Secure Plus') {
      document.getElementById('sHeight6').value = 63;
      document.getElementById('row7').style.display = 'none';
      document.getElementById('row8').style.display = 'none';
   }

   if(wt == 'Standard' || wt == '') {
      document.getElementById('sHeight6').value = 60;
      document.getElementById('row7').style.display = '';
      document.getElementById('row8').style.display = '';
   }
}