
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 keyset(key, e) {

    if (e.keyCode == 13) {
        document.getElementById(key).focus();
    }
}

function got_focus(key) {
    document.getElementById(key).style.backgroundColor = "#000066";

}

function lost_focus(key) {
    document.getElementById(key).style.backgroundColor = "#000000";

}



function print_inv() {
  
//    var  recno=  document.getElementById("Received_No").value;
//    
//    sessionStorage.setItem("NO", recno);
//    
//   
//    window.location = "received_print.php";
//


    var url = "transfer_print.php";
    url = url + "?Transfer_No=" + document.getElementById('Transfer_No').value;


    window.open(url, '_blank');


}




function checked_item1(serialnumber) {

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

    var url = "transfer_data.php";
    url = url + "?Command=" + "checked1";
    url = url + "&serial=" + serialnumber;
    url = url + "&transfer=" + document.getElementById("Transfer_No").value;
    url = url + "&invdate=" + document.getElementById("invdate").value;
    url = url + "&Suppler=" + document.getElementById("Suppler").value;
    url = url + "&s_name=" + document.getElementById("s_name").value;
    url = url + "&con=" + document.getElementById("con").value;
    url = url + "&Remark=" + document.getElementById("Remark").value;

    if (document.getElementById(serialnumber).checked) {
        url = url + "&stat=1";

    } else {
        url = url + "&stat=0";
    }


    xmlHttp.onreadystatechange = dd;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);


}
function dd() {
    var XMLAddress1;

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

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("subtot");
        document.getElementById('subtot').value = XMLAddress1[0].childNodes[0].nodeValue;


        self.close();


    }
}

function showarmyresultdel() {
    var XMLAddress1;

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

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

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("subtot");
        document.getElementById('subtot').value = XMLAddress1[0].childNodes[0].nodeValue;



        document.getElementById('itemCode').value = "";
        document.getElementById('itemDesc').value = "";
        document.getElementById('brand').value = "";
        document.getElementById('itemPrice').value = "";
        document.getElementById('serialN').focus();
//     
        self.close();


    }
}




function save_inv() {


    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
     
    
    if (document.getElementById('Transfer_No').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Transfer Number Not Entered</span></div>";
        return false;
    }
    if (document.getElementById('invdate').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Date Not Entered</span></div>";
        return false;
    }
    if (document.getElementById('Suppler').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Suppler Code Not Entered</span></div>";
        return false;
    }
    if (document.getElementById('s_name').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Suppler Name Not Entered</span></div>";
        return false;
    }
    if (document.getElementById('con').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Contact Number Not Entered</span></div>";
        return false;
    }


    var url = "transfer_data.php";
    url = url + "?Command=" + "save_item";

    url = url + "&Transfer_No=" + document.getElementById('Transfer_No').value;
    url = url + "&invdate=" + document.getElementById('invdate').value;
    url = url + "&Suppler=" + document.getElementById('Suppler').value;
    url = url + "&s_name=" + escape(document.getElementById('s_name').value);
    url = url + "&con=" + escape(document.getElementById('con').value);
    url = url + "&Remark=" + escape(document.getElementById('Remark').value);
    url = url + "&invdate=" + document.getElementById('invdate').value;
    url = url + "&subtot=" + document.getElementById('subtot').value;


    xmlHttp.onreadystatechange = salessaveresult;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);



}

function salessaveresult() {
    var XMLAddress1;

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

        if (xmlHttp.responseText == "Saved") {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-success' role='alert'><span class='center-block'>Saved</span></div>";
            newent();
        } else {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>" + xmlHttp.responseText + "</span></div>";
        }
    }
}

function new_inv() {

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



    document.getElementById('Transfer_No').value = "";
    document.getElementById('Suppler').value = "";
    document.getElementById('s_name').value = "";
    document.getElementById('con').value = "";
    document.getElementById('Remark').value = "";
    document.getElementById('Remark').value = "";
    document.getElementById('msg_box').innerHTML = "";
    document.getElementById('Item').value = "";
    document.getElementById('Description').value = "";
    document.getElementById('Brand').value = "";
    document.getElementById('SerialN').value = "";
    document.getElementById('subtot').value = "";
    document.getElementById('itemdetails').innerHTML = "";

    getdt();
    view();
}

function getdt() {

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

    var url = "transfer_data.php";
    url = url + "?Command=" + "getdt";
    url = url + "&ls=" + "new";

    xmlHttp.onreadystatechange = assign_dt1;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

}


function assign_dt1() {
    var XMLAddress1;

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

function assign_invno() {



    var XMLAddress1;

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

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("invno");
        document.getElementById('txt_entno').value = XMLAddress1[0].childNodes[0].nodeValue;

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("tmpno");
        document.getElementById('tmpno').value = XMLAddress1[0].childNodes[0].nodeValue;

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("dt");
        document.getElementById('invdate').value = XMLAddress1[0].childNodes[0].nodeValue;



    }

}




function del_item(cdate) {

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

    var url = "po_data.php";
    url = url + "?Command=" + "setitem";
    url = url + "&Command1=" + "del_item";
    url = url + "&itemCode=" + cdate;
    url = url + "&invno=" + document.getElementById('txt_entno').value;
    url = url + "&tmpno=" + document.getElementById('tmpno').value;

    xmlHttp.onreadystatechange = showarmyresultdel;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

}




function update_list(stname) {

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

    var url = "po_data.php";
    url = url + "?Command=" + "update_list";
    url = url + "&refno=" + document.getElementById('cusno').value;
    url = url + "&cusname=" + document.getElementById('customername').value;
    url = url + "&stname=" + stname;

    xmlHttp.onreadystatechange = showitemresult;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

}


function showitemresult()
{
    var XMLAddress1;
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {
        document.getElementById('filt_table').innerHTML = xmlHttp.responseText;
    }
}


function cancel_inv() {
    $('#myModal_c').modal('hide');

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

    document.getElementById('msg_box').innerHTML = "";
    if (document.getElementById('c_name').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Select Entry</span></div>";
        return false;
    }
    if (document.getElementById('subtot').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Select Entry</span></div>";
        return false;
    }

    var url = "po_data.php";
    url = url + "?Command=" + "del_inv";
    url = url + "&crnno=" + document.getElementById('txt_entno').value;
    url = url + "&tmpno=" + document.getElementById('tmpno').value;
    xmlHttp.onreadystatechange = cancel_result;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function cancel_result() {
    var XMLAddress1;
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        if (xmlHttp.responseText == "ok") {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-success' role='alert'><span class='center-block'>Cancelled</span></div>";
        } else {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>" + xmlHttp.responseText + "</span></div>";
        }
    }
}

function view() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    var url = "transfer_data.php";
    url = url + "?Command=" + "view";
    url = url + "&Item=" + document.getElementById("Item").value;
    url = url + "&Description=" + document.getElementById("Description").value;
    url = url + "&Brand=" + document.getElementById("Brand").value;
    url = url + "&SerialN=" + document.getElementById("SerialN").value;
    url = url + "&Rate=" + document.getElementById("Rate").value;
    url = url + "&limit=" + document.getElementById("limit").value;




    xmlHttp.onreadystatechange = viewResult;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}


function viewResult() {
    var XMLAddress1;

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

