
if (document.images) {
    preload_image_object = new Image(); image_url = new Array(); //image_url[0] = "http://www.glwholesale.com/images/checkout.gif"; image_url[1] = "http://www.glwholesale.com/images/deletecart.gif"; image_url[2] = "http://www.glwholesale.com/images/emptycart.gif"; image_url[3] = "http://www.glwholesale.com/images/newcart.gif"; image_url[4] = "http://www.glwholesale.com/images/viewcart.gif"; image_url[5] = "http://www.glwholesale.com/images/loading.gif"; 
   // var i = 0; for (i = 0; i <= 5; i++)
  //      preload_image_object.src = image_url[i];
}
var IsIE; var IsIE7; var parentid; var arrWaitingParentIds = new Array(); var arrWaitingParentIdsSetTimeOutIds = new Array(); var arrWaitingParentIdsFirstRequestOldQty = new Array(); IsIE7 = function() {
    if (window.XMLHttpRequest) {
        if (document.epando)
        { IsIE7 = true; }
    }
};


function GetData(act, prodid, quant, itemindex, addtocartid) {
    var parentElementAddToCart = ''; if (addtocartid != null && addtocartid != '') {
        HideElement(addtocartid, true); if (addtocartid.lastIndexOf('_') > 0)
        { parentElementAddToCart = addtocartid.substring(0, (addtocartid.lastIndexOf('_'))); }
        else
        { parentElementAddToCart = addtocartid; }
    }
    
    var urlP = "ProductsListService.aspx"; switch (act) {
case "addtocart":

    urlP = urlP + "?action=" + act;
    urlP = urlP + "&ProductId=" + prodid;
    urlP = urlP + "&Quantity=" + quant;
    urlP = urlP + "&parentElementAddToCart=" + parentElementAddToCart;
    urlP = urlP + "&time=" + new Date().getTime();
  
    $("ctl00_ContentPlaceHolder1_hiddenLastClickedProductId").value = prodid;
    ShowIndicator(prodid, true);
    parentid = parentElementAddToCart + '_';

    break;
case "deletecart":
    var deleteButtonId = prodid;
    var answer = window.confirm('Remove all items from this cart?');
    if (answer) {
        $('trDeleting').style.display = "";
        urlP = urlP + "?action=" + act;
        urlP = urlP + "&time=" + new Date().getTime();
        
    }
    else {
        return false;
    }
    break;  
     case "newcart": urlP = urlP + "?action=" + act; urlP = urlP + "&time=" + new Date().getTime(); break; case "updatequantityincart": var updateBtnId = quant; var updateBtnParentId = updateBtnId.substring(0, (updateBtnId.lastIndexOf('_'))); var QuantityTextBoxInCart = updateBtnParentId + '_Qty'; var OldQuantityTextBox = updateBtnParentId + '_OldQty'; var NewQty = $(QuantityTextBoxInCart).value; var OldQty = $(OldQuantityTextBox).value; if (OldQty == NewQty || OldQty == null || OldQty == '' || NewQty == null || NewQty == '')
            { return false; }
            if ($('ctl00_ContentPlaceHolder1_hiddenLastClickedUpdateProductId') != null)
            { $('ctl00_ContentPlaceHolder1_hiddenLastClickedUpdateProductId').value = prodid; }
            $('imgUpdating').style.display = ""; urlP = urlP + "?action=" + act; urlP = urlP + "&ProductId=" + prodid; urlP = urlP + "&OldQty=" + OldQty; urlP = urlP + "&NewQty=" + NewQty; urlP = urlP + "&time=" + new Date().getTime(); break; case "loadcart": urlP = urlP + "?action=" + act; urlP = urlP + "&time=" + new Date().getTime(); break;
             case "quantitychangedingrid": var qtyTextBoxId = itemindex; parentid = qtyTextBoxId.substring(0, qtyTextBoxId.lastIndexOf('_') + 1); var qtyLabelId = parentid + 'Qty'; var oldqty = getInnerText(qtyLabelId); if (oldqty == quant || quant == '' || quant == null)
            { return false; }
            else
            { urlP = urlP + "?action=" + act; urlP = urlP + "&productid=" + prodid; urlP = urlP + "&oldqty=" + oldqty; urlP = urlP + "&newqty=" + quant; urlP = urlP + "&time=" + new Date().getTime(); ShowIndicator(prodid, true); }
            break; case "quantitychangedingridthroughclickbutton": firstrequest_OldQty = ''; var callSetTimeout = true; parentid = itemindex.substring(0, itemindex.lastIndexOf('_') + 1); var oldqty = quant; var newqty = $(itemindex).value; act = 'quantitychangedingridthroughclickbutton'; urlP = urlP + "?action=" + act; urlP = urlP + "&productid=" + prodid; urlP = urlP + "&newqty=" + newqty; urlP = urlP + "&time=" + new Date().getTime(); ShowIndicator(prodid, true); if (itemindex.lastIndexOf('_') != -1) {
                for (var i = 0; i < arrWaitingParentIds.length; i++) {
                    if (arrWaitingParentIds[i] == parentid)
                    { clearTimeout(arrWaitingParentIdsSetTimeOutIds[i]); arrWaitingParentIdsSetTimeOutIds[i] = setTimeout("WaitAndSendRequest('" + urlP + "','" + act + "','" + parentid + "'," + arrWaitingParentIdsFirstRequestOldQty[i] + "," + newqty + ");", 2000); return false; }
                }
                arrWaitingParentIds.push(parentid); arrWaitingParentIdsSetTimeOutIds.push(setTimeout("WaitAndSendRequest('" + urlP + "','" + act + "','" + parentid + "'," + oldqty + "," + newqty + ");", 2000)); arrWaitingParentIdsFirstRequestOldQty.push(oldqty);
            }
            else
            { LoadData(urlP + "&oldqty=" + oldqty, act, parentid, oldqty); }
            return false; break; case "selectedindexchangedcartid": var productid; if (prodid == 'New Cart...')
            { productid = 'NewCart'; }
            else
            { productid = prodid; }
            ShowLoading(); urlP = urlP + "?action=" + act; urlP = urlP + "&cartid=" + productid; urlP = urlP + "&time=" + new Date().getTime(); break;
        case "createcookieifnotexists":
            urlP = urlP + "?action=" + act;
            urlP = urlP + "&time=" + new Date().getTime(); 
              break;
    }
    if (urlP != "")
    { LoadData(urlP, act, parentid, quant); }
    return false;
}
function WaitAndSendRequest(ClickUrlP, ClickAction, ClickParentid, ClickOldQuant, ClickNewQuant) {
    for (var i = 0; i < arrWaitingParentIds.length; i++) {
        if (arrWaitingParentIds[i] == ClickParentid) {
            if (ClickUrlP != "")
            { ClickUrlP = ClickUrlP + "&oldqty=" + ClickOldQuant; LoadData(ClickUrlP, ClickAction, ClickParentid, ClickOldQuant); }
            arrWaitingParentIds[i] = ''; arrWaitingParentIdsSetTimeOutIds[i] = ''; arrWaitingParentIdsFirstRequestOldQty[i] = '';
        }
    }
}
function LoadData(url, action, parentid, newquant)
{ var ai = new AJAXInteraction(url, action, parentid, newquant); ai.doGet(); }
function ShowQuantity(ResultingParentElementAddToCart, result)
{ }
function HideElement(id, bln) {
    switch (bln)
    { case true: $(id).style.display = 'none'; break; case false: $(id).style.display = ''; break; }
}
function ShowIndicator(id, bln) {
    if (bln)
        $('imgindicator' + id).style.display = ""; else
        $('imgindicator' + id).style.display = "none";
}
function checkCookie() {
    var name = 'sopec_CartID'; var nameEQ = name + "="; var ca = document.cookie.split(';'); alert(ca.join(',')); for (var i = 0; i < ca.length; i++) {
        var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0)
            alert(c.substring(nameEQ.length, c.length)); return false;
    }
    alert('null'); return false;
}
function LoadCart()
{ GetData('loadcart'); GetData('createcookieifnotexists'); }
function hideAllQuantityTextBoxesInGrid() {
    var arrInputBoxes = document.getElementsByTagName('input'); alert(arrInputBoxes.length); for (var i = 0; i < arrInputBoxes.length; i++) {
        if (arrInputBoxes[i].type.toLowerCase() == 'text' && arrInputBoxes[i].getAttribute('id').substring(arrInputBoxes[i].getAttribute('id').lastIndexOf('_') + 1) == 'txtQty')
        { arrInputBoxes[i].style.display = "none"; }
    }
    return false;
}
function CheckValidCharaters_Old() {
    var arrKeyCodesAllowed = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; for (var i = 0; i < arrKeyCodesAllowed.length; i++) {
        if (event.keyCode) {
            if (event.keyCode == arrKeyCodesAllowed[i])
            { event.returnValue = true; return; }
        }
        else if (event.which)
        { alert(""); event.returnValue = true; return; }
    }
    event.returnValue = false;
}
function CheckValidCharaters(evt) {
    evt = (evt) ? evt : ((event) ? event : null); if (evt) {
        var charCode; if (evt && evt.which)
        { charCode = evt.which; }
        if (evt.keyCode)
        { charCode = evt.keyCode; }
        if (evt.charCode)
        { charCode = evt.charCode; }
        if (charCode > 12 && (charCode < 48 || charCode > 57)) {
            if (evt.returnValue)
            { evt.returnValue = false; return false; }
            else if (evt.preventDefault)
            { evt.preventDefault(); }
            else if (IsIE7)
            { evt.returnValue = false; }
            else
            { return false; }
        }
    }
}
function DecreaseQty(imgid, pid) {
    var imgid_parentId = imgid.substring(0, imgid.lastIndexOf('_'));
    var txtQtyId = imgid_parentId + '_txtQty';
    var divCasesId = imgid_parentId + '_divCases'
    var addToCart = imgid_parentId + '_Add';
    var imgUp = imgid_parentId + '_imgup';
    var imgDown = imgid_parentId + '_imgdown';
    var lblOldQtyId = imgid_parentId + '_Qty';
    if ($(txtQtyId) == null) {
        txtQtyId = 'txtQty';
        addToCart = 'Add';
        imgUp = 'imgup'; imgDown = 'imgdown';
        lblOldQtyId = 'Qty';
        divCasesId = 'divCases';
    }
    var Old_Qty = getInnerText(lblOldQtyId);
    if ($(txtQtyId).value != null && $(txtQtyId).value != "" && parseInt($(txtQtyId).value) - 1 >= 0) {
        $(txtQtyId).value = eval($(txtQtyId).value) - 1;
        setInnerText(lblOldQtyId, $(txtQtyId).value);
        GetData('quantitychangedingridthroughclickbutton', pid, Old_Qty, txtQtyId);
        if (parseInt($(txtQtyId).value) == 0) {

            $(txtQtyId).style.display = "none";
            if ($(divCasesId) != null)
            { $(divCasesId).style.display = "none"; }
            $(imgUp).style.display = "none";
            $(imgDown).style.display = "none";
        }
        else {
            $(addToCart).style.display = "none"; $(txtQtyId).style.display = ""; if ($(divCasesId) != null)
            { $(divCasesId).style.display = ""; }
            $(imgUp).style.display = ""; $(imgDown).style.display = "";
        }
    }

    //Start:Added By Pankaj Mahajan
    try {
        var IndicatorCellId = $('imgindicator' + pid).parentNode.getAttribute('id');
        var refElem = IndicatorCellId.substring(0, IndicatorCellId.lastIndexOf('_') + 1)
        var QtyTextBoxId = refElem + 'txtQty';
        var QtyTextBoxId = refElem + 'txtQty';
        var DivpCasesId = refElem + 'divCases'
        var AddToCartId = refElem + 'Add';
        var ImgUpId = refElem + 'imgup';
        var imgDownId = refElem + 'imgdown';
        var lblQty = refElem + 'Qty';
        if (parseInt($(txtQtyId).value) == 0) {

            $(QtyTextBoxId).style.display = "none";
            if ($(DivpCasesId) != null) {
                $(DivpCasesId).style.display = "none";
            }
            $(ImgUpId).style.display = "none";
            $(imgDownId).style.display = "none";
        }

    } catch (e) { }
    //End:Added By Pankaj Mahajan



    return false;
}
function IncreaseQty(imgid, pid) {
    var imgid_parentId = imgid.substring(0, imgid.lastIndexOf('_')); var txtQtyId = imgid_parentId + '_txtQty'; var lblOldQtyId = imgid_parentId + '_Qty'; var divCasesId = imgid_parentId + '_divCases'
    if ($(txtQtyId) == null)
    { txtQtyId = 'txtQty'; lblOldQtyId = 'Qty'; divCasesId = 'divCases'; }
    var Old_Qty = getInnerText(lblOldQtyId); if ($(txtQtyId).value != null && $(txtQtyId).value != "" && (parseInt($(txtQtyId).value) + 1).toString().length <= 3)
    { $(txtQtyId).value = eval($(txtQtyId).value) + 1; setInnerText(lblOldQtyId, $(txtQtyId).value); GetData('quantitychangedingridthroughclickbutton', pid, Old_Qty, txtQtyId); }
    return false;
}
function ChangeQuantity(Qtyid, Qtyvalue, pid)
{ GetData('quantitychangedingrid', pid, Qtyvalue, Qtyid); }
function $(id)
{ return document.getElementById(id); }
function getInnerText(lblOldQtyId) {
    if ($(lblOldQtyId) != null) {
        if (document.all) {
           // return $(lblOldQtyId).innerText;
            var str = $(lblOldQtyId).innerText;
            if (str.length > 0)
            {return  '1' }
            else {return str }
        }
        else {
            if ($(lblOldQtyId).textContent)
            { return $(lblOldQtyId).textContent; }
            else
            { alert("Error: This application till now does not support your browser.  Try again using IE ,Firefox or Opera."); }
        }
    }
}
function setInnerText(lblOldQtyId, val) {
    if ($(lblOldQtyId) != null) {
        if (document.all)
        { $(lblOldQtyId).innerText = val; }
        else {
            if ($(lblOldQtyId).textContent)
            { $(lblOldQtyId).textContent = val; }
            else
            { alert("Error: This application till now does not support your browser.  Try again using IE ,Firefox or Opera"); }
        }
    }
}
function ShowLoading()
{ $("ctl00_ContentPlaceHolder1_divShoppingCart").innerHTML = "<div align='center'><img src='images/loading.gif' alt='loading' /></div>"; }
if (document.implementation.hasFeature("XPath", "3.0")) {
    XMLDocument.prototype.selectNodes = function(cXPathString, xNode) {
        if (!xNode)
        { xNode = this; }
        var oNSResolver = this.createNSResolver(this.documentElement)
        var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
        var aResult = []; for (var i = 0; i < aItems.snapshotLength; i++)
        { aResult[i] = aItems.snapshotItem(i); }
        return aResult;
    }
    Element.prototype.selectNodes = function(cXPathString) {
        if (this.ownerDocument.selectNodes)
        { return this.ownerDocument.selectNodes(cXPathString, this); }
        else
        { throw "For XML Elements Only"; }
    }
}
if (document.implementation.hasFeature("XPath", "3.0")) {
    XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode) {
        if (!xNode)
        { xNode = this; }
        var xItems = this.selectNodes(cXPathString, xNode); if (xItems.length > 0)
        { return xItems[0]; }
        else
        { return null; }
    }
    Element.prototype.selectSingleNode = function(cXPathString) {
        if (this.ownerDocument.selectSingleNode)
        { return this.ownerDocument.selectSingleNode(cXPathString, this); }
        else
        { throw "For XML Elements Only"; }
    }
}

function showH(idval) {
    
    var idval1 = document.getElementById(idval).id;
    idval1 = idval1.replace('child_', 'child1_');
    
    document.getElementById(idval).style.display = 'block';
    document.getElementById(idval1).style.display = 'block';
}
function sHide(idval) {
    var idval1 = document.getElementById(idval).id;
    idval1 = idval1.replace('child_', 'child1_');
    document.getElementById(idval).style.display = 'none';
    document.getElementById(idval1).style.display = 'none';
}

