function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}


function load_cus_inv(cdata) {
 
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    } 
     
    var url = 'cus_register_data.php';
    var params = 'Command=' + 'load_cus_inv';  
    params = params + '&cus_name=' + document.getElementById('cus_name').value; 
    params = params + '&cus_type=' + document.getElementById('cus_type').value;
    // alert("ok");
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.onreadystatechange = re_load_cus_inv;

    xmlHttp.send(params);

}

function re_load_cus_inv() {
     
  var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("sales_table");
        document.getElementById('cus_detail').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;
 
    }
}


function pass_cus_inv(custno){
    
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert("Browser does not support HTTP Request");
        return;
    }

    var url = "cus_register_data.php";

    url = url + "?Command=" + "pass_cus_inv";
    url = url + "&custno=" + custno;
    
    xmlHttp.onreadystatechange = re_pass_cus_inv;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

}

function re_pass_cus_inv() {
     
  var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        
        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("cus_code");
        document.getElementById('cus_code').value = XMLAddress1[0].childNodes[0].nodeValue;
        
        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("cus_name");
        document.getElementById('selected_cus').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;
        
        pass_data();
    }
}

function pass_data(){
    
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert("Browser does not support HTTP Request");
        return;
    }
 
    var url = "cus_register_data.php";
    var params = 'Command=' + 'pass_data';  
    params = params + "&type=" + document.getElementById('type').value; 
    params = params + "&custno=" + document.getElementById('cus_code').value; 
    params = params + "&dtfrom=" + document.getElementById('dtfrom').value;
    params = params + "&dtto=" + document.getElementById('dtto').value;
    params = params + "&dep=" + document.getElementById('dep').value;
    params = params + "&salerep=" + document.getElementById('salerep').value;
    params = params + "&cus_code=" + document.getElementById('cus_code').value;
    var datecheck='False';
    if(document.getElementById('selected_data').checked){
        var datecheck='True';
    }
     params = params + "&datecheck=" + datecheck; 
       
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.onreadystatechange = re_pass_data;
    xmlHttp.send(params);
     

}

function re_pass_data() {
     
  var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        
        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("item_details");
        document.getElementById('item_details').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;
 
    }
}









