var httpReq;
var scObj;
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) {
      scObj = document.getElementById('sCode'+c);
      idObj = document.getElementById('ids'+c);
      w = document.getElementById('wdths'+c).value;
      h = document.getElementById('hghts'+c)[document.getElementById('hghts'+c).selectedIndex].value;
      msgsObj = document.getElementById('msgBox');
   }
   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_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";
         valsArr = httpReq.responseText.split(",");
         idObj.value = valsArr[0];
         scObj.value = valsArr[1];
      }
   }
}

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;
}