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 update_item_list()
{


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


    var url = "search_delivery_item_data.php";
    url = url + "?Command=" + "search_item";
    url = url + "&itno=" + document.getElementById('itno').value;
    url = url + "&itemname=" + document.getElementById('itemname').value;
    url = url + "&brand1=" + document.getElementById('brand1').value;
    url = url + "&jobno=" + document.getElementById('jobno').value;
    url = url + "&checkbox=" + document.getElementById('checkbox').checked;

    if (document.getElementById('itno').value != "") {
        url = url + "&mstatus=itno";
    } else if (document.getElementById('itemname').value != "") {
        url = url + "&mstatus=itemname";
    }else if (document.getElementById('brand1').value != "") {
        url = url + "&mstatus=brand1";
    }
    else if (document.getElementById('jobno').value != "") {
        url = url + "&mstatus=jobno";
    }
    url = url + "&mstatus2=grn_item";
    //alert(url);		
    xmlHttp.onreadystatechange = showitemresult;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);


}


function showitemresult()
{
    var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {
        //alert(xmlHttp.responseText);
        //setTimeout("location.reload(true);",500);
        //if (xmlHttp.responseText=="exist"){
        //	alert("Already Exists");	
        //}

        //XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("inv_table");	
        //document.getElementById('filt_table').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;

        document.getElementById('filt_table').innerHTML = xmlHttp.responseText;
    }
}



function itno_quot(itno)
{


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


    var url = "search_delivery_item_data.php";
    url = url + "?Command=" + "pass_itno_quot";
    url = url + "&itno=" + itno;
    // url = url + "&brand=" + opener.document.form1.brand.value;
    url = url + "&department=" + opener.document.form1.department.value;

    var vatmethod = "";
    if (opener.document.form1.vatgroup_0.checked == true) {
        vatmethod = "vat";
    } else if (opener.document.form1.vatgroup_1.checked == true) {
        vatmethod = "non";
    } else if (opener.document.form1.vatgroup_2.checked == true) {
        vatmethod = "svat";
    } else if (opener.document.form1.vatgroup_3.checked == true) {
        vatmethod = "evat";
    }

    url = url + "&vatmethod=" + vatmethod;

    //alert(url);
    xmlHttp.onreadystatechange = passitresult_itno_quot;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);



}

function passitresult_itno_quot()
{
    var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {
        //alert(xmlHttp.responseText);

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("str_code");
        opener.document.form1.itemd_hidden.value = XMLAddress1[0].childNodes[0].nodeValue;

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("str_description");
        opener.document.form1.itemd.value = XMLAddress1[0].childNodes[0].nodeValue;
        
        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("str_Flagdesc");
        var str_Flagdesc = XMLAddress1[0].childNodes[0].nodeValue;
		//alert (str_Flagdesc);
        if (str_Flagdesc == "yess") {
            
            XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("str_description");
            opener.document.form1.itemd.value = XMLAddress1[0].childNodes[0].nodeValue;
            opener.document.form1.itemd.disabled = false;

        } else if (str_Flagdesc == "Noo") {
            
            XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("str_description");
            opener.document.form1.itemd.value = XMLAddress1[0].childNodes[0].nodeValue;
            opener.document.form1.itemd.disabled = true;
        }

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("str_selpri");
        opener.document.form1.rate.value = XMLAddress1[0].childNodes[0].nodeValue;

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("qtyinhand");
        opener.document.form1.stklevel.value = XMLAddress1[0].childNodes[0].nodeValue;


        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("str_partno");
        opener.document.form1.part_no.value = XMLAddress1[0].childNodes[0].nodeValue;

        //	XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("dis");	
        //	opener.document.form1.discount.value = XMLAddress1[0].childNodes[0].nodeValue;


        self.close();
        opener.document.form1.qty.focus();



    }
}





