
var ProductImages = {
    Show : function() {
        var nodes = document.getElementsByTagName('IMG');
        var lth = nodes.length;
        for (var i = 0; i < lth; ++i) {
            var o = nodes[i].getAttribute('path');
            if (o != null) {
                nodes[i].src = o;
                nodes[i].style.display = 'block';
                nodes[i].style.filter = 'alpha(opacity=100)';
            }
        }
    },
    Hide : function() {
        var nodes = document.getElementsByTagName('IMG');
        var lth = nodes.length;
        for (var i = 0; i < lth; ++i) {
            var o = nodes[i].getAttribute('path');
            if (o != null) nodes[i].style.display = 'none';
        }
    },
    Check : function() {
      var o = document.getElementById('chkShowImages');
      if (!!!o) alert('chkShowImages Element not found');
     
      var url = '/Catalog/ProductView.aspx?ShowImages='
      if (o.checked) {
        url += 'true';
        ProductImages.Show();
      }
      else {
        url += 'false';
        ProductImages.Hide();
      }
      top.neotekText(url, null); 
    }
};

function ShowLoadingImage() {
    var oo = document.getElementById('ItemPanel');
    oo.innerHTML = '';
    var div = document.createElement('div');
    div.style.textAlign = 'center';
    div.innerHTML = '<img src="/Owner/Skin/images/progress.gif" />';
    oo.appendChild(div);
}

function ChangeProductView()
{
    var o = document.getElementById('ListStyle');
    var url = '/Catalog/ProductView.aspx?ChangeView=';
    var view = o.options[o.selectedIndex];
    view = view.getAttribute('ViewID');
    url = url + view;
 
    ShowLoadingImage();    
    top.neotekText(url, ProductViewCallback);
}
function ChangePage(PageNum) {
    var url = '/Catalog/ProductView.aspx?PageNo=' + PageNum;
    ShowLoadingImage();
    top.neotekText(url, ProductViewCallback);
}
function PageQuery(q) {
    var url = window.location.search;
    if (url.length > 1) url = url.substring(1);
    else return null;
    var keyValuePairs = url.split("&");
    for (var i = 0; i < keyValuePairs.length; ++i) {
        var key = keyValuePairs[i].split('=')[0];
        if (key.toLowerCase() == q.toLowerCase())
            return keyValuePairs[i];
    }
    return null;    
}

function UpdatePageSize(e, catID) {
    e = e || window.event;
    var o = e.target || e.srcElement;
    var tempView = PageQuery("TempView") || '';
    if (tempView) tempView = '&' + tempView;
    var url = '/Catalog/ProductView.aspx?Id=' + catID + '&PageSize=' + o.value + tempView;
    window.location = url; // Need to update page Numbers so full page refresh is preferred
}
function ProductViewCallback(retVal) {
    var o = document.getElementById('ItemPanel');
    if (o) { 
        o.innerHTML = retVal;
        var scriptNodes = o.getElementsByTagName('script'); // script tags won't run if ajax call (in html)
        var lth = scriptNodes.length;
        for (var i = 0; i < lth; ++i) {
            if (scriptNodes[i].src != '') {
                var script = document.createElement('script');
                script.src = scriptNodes[i].src.toString();
                o.appendChild(script); // Creates another tag but the original won't load and removing it causes other issues
            }
            else 
                eval(scriptNodes[i].innerHTML);
        }
    }
}
function ShowInventoryPopup(e, id)
{
    var settings = {
        URL:'/Catalog/InventoryPopup.aspx?Ajax=1&ProductId=' + id,
        Title:'Inventory',
        ShowClose:true,
        Position:e,
        ShowTriangle:['left',''],
        Width:400,
        DoFade:false,
        CloseOnLoseFocus:false
    };
    top.NeotekPopup.Show(settings);
}
function ShowTab(num)
{
    var stock = document.getElementById('invStockTbl');
    var eta = document.getElementById('invETATbl');
    if (num == 0) {
        stock.style.display = 'block';
        eta.style.display = 'none';
    } else {
        stock.style.display = 'none';
        eta.style.display = 'block';
    }
}

function OnUnloadCheck() {
    var hasItems = false;
    var df = document.forms['OrderPad'];
    if (df) {
        if (df.Qty) {
            if (df.Qty.length) {
                for (var i = 0; i < df.Qty.length; i++) {
                    if (df.Qty[i].value != '') {
                        hasItems = true;
                        break
                    }
                }
            } else {
                hasItems = (df.Qty.value != '');
            }
        }
    }
    if (hasItems) {
        if (confirm('You have items not yet submitted to your basket.\n Would you like to add these to your basket now?')) {
            var vals = top.getFormValues(df);
            top.neotekscript(df.action, vals);
        }
    }
}
window.onbeforeunload = OnUnloadCheck; // IE "can't run from freed script" error if onunload tried. (IE7,Vista)
