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 newent() {
    document.getElementById("txt_aircode").value = "";
    document.getElementById("txt_airname").value = "";
    document.getElementById("txt_country").value = "";
    document.getElementById("txt_town").value = "";
   
    document.getElementById('msg_box').innerHTML = "";

    getdt();
}

function getdt() {

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

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

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

}


function assign_dt() {
    document.getElementById('itemdetails').innerHTML = xmlHttp.responseText;
}


function getbycode(cdata) {

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

    var url = "point_sch_data.php";
    url = url + "?Command=" + "getdt";

    url = url + "&ls=" + cdata;

    url = url + "&txt_aircode=" + document.getElementById('txt_aircode').value;

    url = url + "&txt_airname=" + document.getElementById('txt_airname').value;
    url = url + "&txt_country=" + document.getElementById('txt_country').value;
    url = url + "&txt_town=" + document.getElementById('txt_town').value;
   

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

}

function getbyname() {

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

    var url = "point_sch_data.php";
    url = url + "?Command=" + "getdt";
    url = url + "&ls=" + "name";

    url = url + "&txt_aircode=" + document.getElementById('txt_aircode').value;
    url = url + "&txt_airname=" + document.getElementById('txt_airname').value;
    url = url + "&txt_country=" + document.getElementById('txt_country').value;
    url = url + "&txt_town=" + document.getElementById('txt_town').value;
  
    xmlHttp.onreadystatechange = assign_dt;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

}


function getcode(cdata, cdata1, cdata2, cdata3) {


    document.getElementById('txt_aircode').value = cdata;
    document.getElementById('txt_airname').value = cdata1;
    document.getElementById('txt_country').value = cdata2;
    document.getElementById('txt_town').value = cdata3;
   

    window.scrollTo(0,0);
}

function save_inv() {

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

    if (document.getElementById('txt_aircode').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Airport Code Not Enterd</span></div>";
        return false;
    }
    if (document.getElementById('txt_airname').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Airport Name Not Enterd</span></div>";
        return false;
    }
    if (document.getElementById('txt_country').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Country Not Enterd</span></div>";
        return false;
    }



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

    url = url + "&txt_aircode=" + document.getElementById('txt_aircode').value;
    url = url + "&txt_airname=" + document.getElementById('txt_airname').value;
    url = url + "&txt_country=" + document.getElementById('txt_country').value;
    url = url + "&txt_town=" + document.getElementById('txt_town').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>";
            setTimeout(function () {
                window.location.reload(1);
            }, 3000);
//            newent();
        } else {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>" + xmlHttp.responseText + "</span></div>";
        }
    }
}