function deleteProd(obj) {
    if (obj.checked) {
        getResponseAJAX("updatedb.asp?sql=update t_Prod set b_Deleted=1 where s_ItemNo='" + obj.getAttribute("itemno") + "'");
    } else {
        getResponseAJAX("updatedb.asp?sql=update t_Prod set b_Deleted=0 where s_ItemNo='" + obj.getAttribute("itemno") + "'");
    }
}

function deleteCat(obj) {
    if (obj.checked) {
        getResponseAJAX("updatedb.asp?sql=update t_Cat set b_Deleted=1 where s_Cat='" + obj.getAttribute("cat") + "'");
    } else {
        getResponseAJAX("updatedb.asp?sql=update t_Cat set b_Deleted=0 where s_Cat='" + obj.getAttribute("cat") + "'");
    }
}

function updateCat(obj) {   
    switch (obj.getAttribute("field")) {
    case "s_Cat":
        getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateCat '" + obj.getAttribute("cat") + "','" + obj.value + "',null,null");
        document.getElementById("s_Display").setAttribute("cat",obj.value);
        document.getElementById("s_Parent").setAttribute("cat",obj.value);
        document.getElementById("btnReload").setAttribute("cat",obj.value);
        document.getElementById("chkDelete").setAttribute("cat",obj.value);
        break;
    case "s_Display":
        getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateCat '" + obj.getAttribute("cat") + "','" + obj.getAttribute("cat") + "',null,'" + obj.value + "'");
        break;
    case "s_Parent":
        getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateCat '" + obj.getAttribute("cat") + "','" + obj.getAttribute("cat") + "','" + obj.value + "',null");
        break;
    }
}

function updateCatImg(obj) {
    var X;
    if (obj.checked) {X=1} else {X=0};
    getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateCatImg '" + obj.getAttribute("cat") + "','" + obj.value + "'," + X);
}

function updateProdImg(obj) {
    var X;
    if (obj.checked) {X=1} else {X=0};
    getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateProdImg '" + obj.getAttribute("itemno") + "','" + obj.value + "'," + X);
}

function updateProdCat(obj) {
    var X;
    if (obj.checked) {X=1} else {X=0};
    getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateProdCat '" + obj.getAttribute("itemno") + "','" + obj.value + "'," + X);
}

function updateProdSize(obj) {
    var X;
    if (obj.checked) {X=1} else {X=0};
    getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateProdSize '" + obj.getAttribute("itemno") + "','" + obj.value + "'," + obj.getAttribute("prodPrice") + "," + X);
}

function updateProdColor(obj) {
    var X;
    if (obj.checked) {X=1} else {X=0};
    getResponseAJAX("updatedb.asp?sql=exec dbo.sp_updateProdColor '" + obj.getAttribute("itemno") + "','" + obj.value + "'," + X);
}

function updateProd(obj) {
    getResponseAJAX( "updatedb.asp?sql=update " + obj.getAttribute('table') + 
           " SET " + obj.getAttribute('field') + 
           "='" + obj.value + 
           "' WHERE s_ItemNo='" + obj.getAttribute('itemno') + "'");

    if (obj.id=='s_ItemNo') {
        window.location="product.asp?item=" + obj.value;
    }
           
}

function noResponseAJAX(url) {
    var xml;
    xml=GetXmlHttpObject()
    if (xml==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    } 
    if (url.indexOf('?')==-1) {
        url+='?ran=' + Math.round(999999*Math.random());
    } else {
        url+='&ran=' + Math.round(999999*Math.random());
    }  
    
    //xmlHttp.onreadystatechange=stateChanged_AJAX
    
    xml.open("GET",url,true)
    xml.send(null)
}

function getResponseAJAX(url) {
    var xml;
    xml=GetXmlHttpObject()
    if (xml==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    } 
    if (url.indexOf('?')==-1) {
        url+='?ran=' + Math.round(999999*Math.random());
    } else {
        url+='&ran=' + Math.round(999999*Math.random());
    }  
    
    //xmlHttp.onreadystatechange=stateChanged_AJAX
    
    xml.open("GET",url,false)
    xml.send(null)
    return xml.responseText;
}


function GetXmlHttpObject() { 
    var objXMLHttp=null;
    if (window.XMLHttpRequest) {
        objXMLHttp=new XMLHttpRequest();
    } else {
        if (window.ActiveXObject) {
            objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return objXMLHttp;
} 
