﻿var xmlHttp1 = createXmlHttpRequestObject();
var xmlHttp2 = createXmlHttpRequestObject();
var xmlHttp3 = createXmlHttpRequestObject();
var xmlHttp4 = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
    var xmlHttp;
    try
    {
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
        // try every prog id until one works !
        for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++)
        {
            try
            {
                xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
            }
            catch (e) { }
        }
    }
    if (!xmlHttp) alert("Error creating the XMLHttpRequest object.");
    else return xmlHttp;
}

function handleRequestStateChange1()
{
    if (xmlHttp1.readyState == 4)
    {
        if (xmlHttp1.status == 200)
        {
            var Resp = xmlHttp1.responseText;

            var IDName = new String(Resp.substring(4)); //<!--
            var ID = IDName.substring(0, IDName.indexOf("-->", 0));

            try
            {
                if (ID != '')
                {
                    if (ID == 'COMMAND')
                    {
                        xmlHttp1.onreadystatechange = function() { }
                        try { xmlHttp1.abort(); } catch (e) { }

                        document.location.href = Resp.substring(7 + ID.length);
                    }
                    else
                    {
                        if (ID == 'FUNCTION')
                        {
                            xmlHttp1.onreadystatechange = function() { }
                            try { xmlHttp1.abort(); } catch (e) { }

                            ShowCart(Resp.substring(7 + ID.length));
                        }
                        else
                        {
                            var lbControl = document.getElementById(ID);
                            lbControl.innerHTML = Resp;

                            xmlHttp1.onreadystatechange = function() { }
                            try { xmlHttp1.abort(); } catch (e) { }
                        }
                        setupRollovers();
                    }
                }
            }
            catch (e)
            {
                alert("handleRequestStateChange1:" + e.toString());
            }
        }
        else
        {
            alert(xmlHttp1.statusText);
        }
    }
}

function handleRequestStateChange2()
{
    if (xmlHttp2.readyState == 4)
    {
        if (xmlHttp2.status == 200)
        {
            var Resp = xmlHttp2.responseText;

            var IDName = new String(Resp.substring(4)); //<!--
            var ID = IDName.substring(0, IDName.indexOf("-->", 0));

            try
            {
                if (ID != '')
                {
                    if (ID == 'COMMAND')
                    {
                        xmlHttp2.onreadystatechange = function() { }
                        try { xmlHttp2.abort(); } catch (e) { }

                        document.location.href = Resp.substring(7 + ID.length);
                    }
                    else
                    {
                        var lbControl = document.getElementById(ID);
                        lbControl.innerHTML = Resp;

                        xmlHttp2.onreadystatechange = function() { }
                        try { xmlHttp2.abort(); } catch (e) { }

                        setupRollovers();
                    }
                }
            }
            catch (e)
            {
                alert("handleRequestStateChange2:" + e.toString());
            }
        }
        else
        {
            alert(xmlHttp2.statusText);
        }
    }
}
function handleRequestStateChange3()
{
    if (xmlHttp3.readyState == 4)
    {
        if (xmlHttp3.status == 200)
        {
            var Resp = xmlHttp3.responseText;

            var IDName = new String(Resp.substring(4)); //<!--
            var ID = IDName.substring(0, IDName.indexOf("-->", 0));

            try
            {
                if (ID != '')
                {
                    if (ID == 'COMMAND')
                    {
                        xmlHttp3.onreadystatechange = function() { }
                        try { xmlHttp3.abort(); } catch (e) { }

                        document.location.href = Resp.substring(7 + ID.length);
                    }
                    else
                    {
                        var lbControl = document.getElementById(ID);
                        lbControl.innerHTML = Resp;

                        xmlHttp3.onreadystatechange = function() { }
                        try { xmlHttp3.abort(); } catch (e) { }

                        setupRollovers();
                    }
                }
            }
            catch (e)
            {
                alert("handleRequestStateChange3:" + e.toString());
            }
        }
        else
        {
            alert(xmlHttp3.statusText);
        }
    }
}
function handleRequestStateChange4()
{
    if (xmlHttp4.readyState == 4)
    {
        if (xmlHttp4.status == 200)
        {
            var Resp = xmlHttp4.responseText;

            var IDName = new String(Resp.substring(4)); //<!--
            var ID = IDName.substring(0, IDName.indexOf("-->", 0));

            try
            {
                if (ID != '')
                {
                    if (ID == 'COMMAND')
                    {
                        xmlHttp4.onreadystatechange = function() { }
                        try { xmlHttp4.abort(); } catch (e) { }

                        document.location.href = Resp.substring(7 + ID.length);
                    }
                    else
                    {
                        var lbControl = document.getElementById(ID);
                        lbControl.innerHTML = Resp;

                        xmlHttp4.onreadystatechange = function() { }
                        try { xmlHttp4.abort(); } catch (e) { }

                        setupRollovers();
                    }
                }
            }
            catch (e)
            {
                alert("handleRequestStateChange4:" + e.toString());
            }
        }
        else
        {
            alert(xmlHttp4.statusText);
        }
    }
}


function process1(acontrol, action, ItemType, ItemID, CompID, ItemQty, APage)
{
    if (xmlHttp1)
    {
        try
        {
            if (xmlHttp1.readyState == 4 || xmlHttp1.readyState == 0)
            {
                var ADate = new Date(); //Gets rid of Caching Issues
                xmlHttp1.open("GET", "AjaxCart.aspx?AControl=" + acontrol + "&Action=" + action + "&Type=" + ItemType + "&ID=" + ItemID + "&CID=" + CompID + "&Qty=" + ItemQty + "&Pg=" + APage + "&TID=" + ADate.getTime(), true);
                xmlHttp1.onreadystatechange = handleRequestStateChange1;
                xmlHttp1.send(null);
            }
        }
        catch (e)
        {
            alert("Can't connect to server:\n" + e.toString());
        }
    }
}
function process2(acontrol, action, ItemType, ItemID, CompID, ItemQty, APage)
{
    if (xmlHttp2)
    {
        try
        {
            if (xmlHttp2.readyState == 4 || xmlHttp2.readyState == 0)
            {
                var ADate = new Date(); //Gets rid of Caching Issues
                xmlHttp2.open("GET", "AjaxCart.aspx?AControl=" + acontrol + "&Action=" + action + "&Type=" + ItemType + "&ID=" + ItemID + "&CID=" + CompID + "&Qty=" + ItemQty + "&Pg=" + APage + "&TID=" + ADate.getTime(), true);
                xmlHttp2.onreadystatechange = handleRequestStateChange2;
                xmlHttp2.send(null);
            }
        }
        catch (e)
        {
            alert("Can't connect to server:\n" + e.toString());
        }
    }
}
function process3(acontrol, action, ItemType, ItemID, CompID, ItemQty, APage)
{
    if (xmlHttp3)
    {
        try
        {
            if (xmlHttp3.readyState == 4 || xmlHttp3.readyState == 0)
            {
                var ADate = new Date(); //Gets rid of Caching Issues
                xmlHttp3.open("GET", "AjaxCart.aspx?AControl=" + acontrol + "&Action=" + action + "&Type=" + ItemType + "&ID=" + ItemID + "&CID=" + CompID + "&Qty=" + ItemQty + "&Pg=" + APage + "&TID=" + ADate.getTime(), true);
                xmlHttp3.onreadystatechange = handleRequestStateChange3;
                xmlHttp3.send(null);
            }
        }
        catch (e)
        {
            alert("Can't connect to server:\n" + e.toString());
        }
    }
}
function process4(acontrol, action, ItemType, ItemID, CompID, ItemQty, APage)
{
    if (xmlHttp4)
    {
        try
        {
            if (xmlHttp4.readyState == 4 || xmlHttp4.readyState == 0)
            {
                var ADate = new Date(); //Gets rid of Caching Issues
                xmlHttp4.open("GET", "AjaxCart.aspx?AControl=" + acontrol + "&Action=" + action + "&Type=" + ItemType + "&ID=" + ItemID + "&CID=" + CompID + "&Qty=" + ItemQty + "&Pg=" + APage + "&TID=" + ADate.getTime(), true);
                xmlHttp4.onreadystatechange = handleRequestStateChange4;
                xmlHttp4.send(null);
            }
        }
        catch (e)
        {
            alert("Can't connect to server:\n" + e.toString());
        }
    }
}
/////////////////////////////////////////////////////////////////////////////////
function ShowAddrEdit() {
    if ($("#AddrEdit").is(':hidden')) {
        $("#AddrEdit").slideDown("slow");
        $("#AEID").html("(Close Details)");
    }
    else {
        $("#AddrEdit").animate({ opacity: 'hide', height: 'hide' }, 'slow');
        $("#AEID").html("(Edit Details)");
    }
}
function HeaderSearch(ID)
{
    var SS = $("#" + ID).attr("value");
    location.href = "Searching.aspx?S=" + SS;
}
function ClearText(ID) 
{    
    $("#" + ID).attr("value") = "";    
}
function HeaderOffer(ID)
{
    var SS = $("#" + ID).attr("value");
    location.href = "eMailOffers.aspx?S=" + SS;
}

function CheckSearch(ID,e)
{    
    var key;

    if (window.event) key = window.event.keyCode;     //IE
    else key = e.which;     //firefox

    if (key == 13)
    {
        var SS = $("#" + ID).attr("value");
        location.href = "Searching.aspx?S=" + SS;
        event.keyCode = 0        
    }
}
function SelectPostCode(Addr,p,w) {

    var URL = "../SelectPostCode.aspx";
    if (w == true) URL = "SelectPostCode.aspx";
    var PC = "";
    
    if (p != '') p = p + "_";
    else p = '';
    
    PC = $("#" + p + Addr + "PostCode").attr("value");    
            
    window.open( URL + '?P=' + p + '&T=' + Addr + '&PC=' + PC, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=455,height=300,screenX=250,screenY=250,top=250,left=250');
}
function SelectPostCode2(Addr, p, w) {

    var URL = "../SelectPostCode2.aspx";
    if (w == true) URL = "SelectPostCode2.aspx";
    var PC = "";
    if (p != '') p = p + "_";
    
    PC = $("#" + p + Addr + "PostCode").attr("value");

    window.open(URL + '?P=' + p + '&T=' + Addr + '&PC=' + PC, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=455,height=340,screenX=250,screenY=250,top=250,left=250');
}
function SelectPC(ID, e, Addr, p, w)
{
    var key;

    if (window.event) key = window.event.keyCode;     //IE
    else key = e.which;     //firefox

    if (p != '') p = p + "_";

    var URL = "../SelectPostCode.aspx";
    if (w == true) URL = "SelectPostCode.aspx";
            
    if (key == 13) {
        var PC = $("#" + p + ID).attr("value");       
        
        window.open( URL + '?P=' + p + '&T=' + Addr + '&PC=' + PC, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=455,height=300,screenX=250,screenY=250,top=250,left=250');
        event.keyCode = 0
    }
}

function SetProdColour(PID)
{
	var CID = $("#ddCols" + PID + " option:selected").val();
	var Colour = $("#ddCols" + PID + " option:selected").text();

	//alert( Colour + ' ' + CID );
    
	
    $("#cd" + PID).attr("value", CID);
	
    //Do some Ajax to get the new Size List
    var str = CID;

    if ($("#ddSizes" + PID).length > 0)
    {
        $("#ddSizes" + PID).html("<span class=\"ColourBox\">Please Wait...</span>");
        $.ajax({
            url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
            data: "AControl=ddSizes" + PID + "&Action=Sizes&Type=" + Colour + "&ID=" + PID + "&CID=0&Qty=0",
            success: function(html)
			{ 
				$("#ddSizes" + PID).html(html); 

				//Not null
				if ($("#ddSizes" + PID).length > 0)
				{
					str = $("#ddSizes" + PID + " option:selected").val();
				}
            
				$("#CompID").attr("value", str);

				ReCalcColPrice(PID);
			}
        });
    }
}

function UpdateComp(PID)
{
    var str = $("#ddSizes" + PID + " option:selected").val();

    $("#CompID").attr("value", str);

	ReCalcColPrice(PID);
}

function ReCalcColPrice( PID )
{
	CompID = $("#CompID").attr("value");
    var AQty = $("#CartQtyEdit" + PID).attr("value");

	$.ajax({
		url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
        data: "AControl=NewPrice&Action=GetColPrice&Type=&ID=" + PID + "&CID=" + CompID + "&Qty=" + AQty,
        success: function(html) { $("#NewPrice").html(html); }
    });
}

function SetColour(PID, CID, Colour, ColID)
{
    $("#ColourName" + ColID).html(Colour);
    $("#cl" + ColID).attr("value", CID);
}

function GetColour(PID, CID, Colour, ColID)
{
    $("#ColourName" + ColID).html(Colour);    
}

function ReCalcPrice(ID)
{
    //Only called from Product Page
    var layers = document.getElementsByTagName('div');

    for (var i = 0, len = layers.length; i < len; i++)
    {
        if ((layers[i].id != '') && (layers[i].id == 'Accessories')) {
            var Str = '1,' + ID + '|';
            var selects = layers[i].getElementsByTagName('select');
            var inputs = layers[i].getElementsByTagName('input');

            for (var j = 0; j < selects.length; j++) {
                if (selects[j].value != 0) {
                    if (selects[j].name.substr(0, 2) == 'dd') {
                        Str = Str + '1,' + selects[j].value + '|';
                    }
                    if (selects[j].name.substr(0, 2) == 'dq') {
                        var AQty = document.getElementById("aq" + selects[j].name.substr(2, selects[j].name.length - 2));

                        if (AQty) Str = Str + AQty.value + ',' + selects[j].value + '|';
                    }
                }
            }
            for (var j = 0; j < inputs.length; j++) {
                if (inputs[j].name.substr(0, 2) == 'aa') {
                    Str = Str + inputs[j].value + ',' + inputs[j].name.substr(2, inputs[j].name.length - 2) + '|';
                }
                if (inputs[j].name.substr(0, 2) == 'cd') {
                    //-1 indicates a Locked Qty Item					
                    Str = Str + '-1,' + inputs[j].value + '|';
                }
                if (inputs[j].name.substr(0, 2) == 'cl') {
                    var AQty = document.getElementById("cq" + inputs[j].name.substr(2, inputs[j].name.length - 2));

                    if (AQty) Str = Str + AQty.value + ',' + inputs[j].value + '|';
                }
            }   

			alert( Str );
      
            //process1("NewPrice", "GetPrice", Str, "0", "0", "0");
            $.ajax({
                url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
                data: "AControl=NewPrice&Action=GetPrice&Type=" + Str + "&ID=0&CID=0&Qty=0",
                success: function(html) { $("#NewPrice").html(html); }
            });
        }
    }
}

function BuyCalcPrice(ID) {
    //Only called from Product Page
    var layers = document.getElementsByTagName('div');

    for (var i = 0, len = layers.length; i < len; i++) {
        if ((layers[i].id != '') && (layers[i].id == 'Accessories')) {
            var Str = '1,' + ID + '|';
            var selects = layers[i].getElementsByTagName('select');
            var inputs = layers[i].getElementsByTagName('input');

            for (var j = 0; j < selects.length; j++) {
                if (selects[j].value != 0) {
                    if (selects[j].name.substr(0, 2) == 'dd') {
                        //-1 indicates a Locked Qty Item					
                        Str = Str + '-1,' + selects[j].value + '|';
                    }
                    if (selects[j].name.substr(0, 2) == 'dq') {
                        var AQty = document.getElementById("aq" + selects[j].name.substr(2, selects[j].name.length - 2));

                        if (AQty) Str = Str + AQty.value + ',' + selects[j].value + '|';
                    }
                }
            }
            for (var j = 0; j < inputs.length; j++) {
                if (inputs[j].name.substr(0, 2) == 'aa') {
                    Str = Str + inputs[j].value + ',' + inputs[j].name.substr(2, inputs[j].name.length - 2) + '|';
                }
                if (inputs[j].name.substr(0, 2) == 'cd') {
                    //-1 indicates a Locked Qty Item					
                    Str = Str + '-1,' + inputs[j].value + '|';
                }
                if (inputs[j].name.substr(0, 2) == 'cl') {
                    var AQty = document.getElementById("cq" + inputs[j].name.substr(2, inputs[j].name.length - 2));

                    if (AQty) Str = Str + AQty.value + ',' + inputs[j].value + '|';
                }
            }
            $.ajax({
                url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
                data: "AControl=lbCart&Action=AddAAP&Type=" + Str + "&ID=0&CID=0&Qty=0",
                success: function(html) { location.href = "EditCart.aspx"; }
            });
        }
    }
}

function Fix(A, ID)
{   
    window.open(A + "&ID=" + ID, 'PDpopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=760,screenX=50,screenY=50,top=50,left=50');
}

function CopyAddress(from, to)
{
    var V = $("#" + from + "PostCode").attr("value");
    $("#" + to + "PostCode").attr("value", V);

    V = $("#" + from + "Firstname").attr("value");
    $("#" + to + "Firstname").attr("value", V);

    V = $("#" + from + "Lastname").attr("value");
    $("#" + to + "Lastname").attr("value", V);

    V = $("#" + from + "Tel").attr("value");
    $("#" + to + "Tel").attr("value", V);

    V = $("#" + from + "Company").attr("value");
    $("#" + to + "Company").attr("value", V);
    
    V = $("#" + from + "Address1").attr("value");
    $("#" + to + "Address1").attr("value", V);

    V = $("#" + from + "Address2").attr("value");
    $("#" + to + "Address2").attr("value", V);

    V = $("#" + from + "Address3").attr("value");
    $("#" + to + "Address3").attr("value", V);

    V = $("#" + from + "Town").attr("value");
    $("#" + to + "Town").attr("value", V);

    V = $("#dd" + from + "County").val();
    $("#dd" + to + "County").val(V);

    V = $("#dd" + from + "Country").val();
    $("#dd" + to + "Country").val(V);

    V = $("#dd" + from + "Title").val();
    $("#dd" + to + "Title").val(V);
}

function UpdateCartMode() {

    var V = $("#dddCountry").val();
    process1("lbFooter", "SetDeliveryCountry", "17", V, "", "");           
}

function HistoryBtnClick(w, ID) {
    var URL = "./History.aspx?ID=" + ID;
    if (w == true) URL = "./Agents/History.aspx?ID=" + ID;
    window.open( URL, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=600,screenX=50,screenY=50,top=50,left=50');
}
function StatsBtnClick(w) {
    var URL = "../ShopMgr/Stats.aspx";
    if (w == true) URL = "./ShopMgr/Stats.aspx";
    window.open( URL, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=700,screenX=50,screenY=50,top=50,left=50');
}
function CoopsBtnClick(w) {
    var URL = "./Coupons.aspx";
    if (w == true) URL = "./Agents/Coupons.aspx";
    window.open( URL, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=345,height=405,screenX=50,screenY=50,top=50,left=500');
}
function ShowCallBacks(w) {
    var URL = "./CallBacks.aspx";
    if (w == true) URL = "./Agents/CallBacks.aspx";
    window.open(URL, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=600,screenX=50,screenY=50,top=50,left=50');
}
function IncompleteBtnClick(w) {
    var URL = "./Incomplete.aspx";
    if (w == true) URL = "./Agents/Incomplete.aspx";
    window.open( URL, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=600,screenX=50,screenY=50,top=50,left=50');
}
function DoAgentHome(w) {
    var URL = "./Home.aspx";
    if (w == true) URL = "./Agents/Home.aspx";
    location.href = URL;
}
function AgentLogoff(w) {
    URL = "./AgentLogoff.aspx"; 
    if (w == true) URL = "./Agents/AgentLogoff.aspx";
    location.href = URL;
}
function CustomerCallBack(w) {
    var URL = "./Callbacks.aspx";
    if (w == true) URL = "./Agents/Callbacks.aspx";
    window.open(URL, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=600,screenX=50,screenY=50,top=50,left=50');
}

function AddReview(ID) { window.open('AddReview.aspx?ID=' + ID, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=630,height=520,screenX=50,screenY=50,top=50,left=50'); }
function Goto(ID) { location.href = "Product.aspx?ID=" + ID; }
function TellAFriend(ID) { location.href = "TellAFriend.aspx?ID=" + ID; }
function Continue() { location.href = "Default.aspx"; }
function EditCart() { location.href = "EditCart.aspx"; }
function CheckOut() { location.href = "Register.aspx"; }

function DrawCart() { process1("lbCart", "Render", "0", "0", "0", "0"); }
function MergeCart() { process1("lbCart", "Merge", "0", "0", "0", "0"); }
function ClearCart()
{
    //process1("", "Clear", "0", "0", "0", "0");
    $.ajax( {
                url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
                data: "AControl=&Action=Clear&Type=0&ID=0&CID=0&Qty=0"
            }
    );
}

function setupRollovers()
{
    if (!document.getElementsByTagName) return;

    var all_links = document.getElementsByTagName('a');
    for (var i = 0; i < all_links.length; i++)
    {
        var link = all_links[i];
        if (link.className && (' ' + link.className + ' ').indexOf(' rollover ') != -1)
        {
            if (link.childNodes && link.childNodes.length == 1 && link.childNodes[0].nodeName.toLowerCase() == 'img')
            {
                link.onmouseover = mouseover;
                link.onmouseout = mouseout;
                link.onmousedown = mousedown;
            }
        }

        if (link.className && (' ' + link.className + ' ').indexOf(' addimageover ') != -1)
        {
            if (link.childNodes && link.childNodes.length == 1 && link.childNodes[0].nodeName.toLowerCase() == 'img')
            {
                link.onmouseover = Imagemouseover;
                link.onmouseout = Imagemouseout;
                link.onmousedown = Imagemousedown;
            }
        }
    }
}
function findTarget(e)
{
    var target;

    if (window.event && window.event.srcElement) target = window.event.srcElement;
    else
        if (e && e.target) target = e.target;

    if (!target) return null;

    while (target != document.body && target.nodeName.toLowerCase() != 'a') target = target.parentNode;

    if (target.nodeName.toLowerCase() != 'a') return null;

    return target;
}

function mousedown(e)
{

    var target = findTarget(e);
    if (!target) return;

    var img_tag = target.childNodes[0];
    var BtnType = new String(img_tag.name.substring(0, 3));

    if (BtnType == 'CHK')
    {
        location.href = "Register.aspx";
    }

    var IDName = new String(img_tag.name.substring(3));
    var ID = IDName.substring(0, IDName.indexOf(":", 0));
    var CompID = IDName.substring(IDName.indexOf(":", 0) + 1);

    if (BtnType == 'BNX')
    {
        var P = "P" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/BagAdd.gif";
        BuySetTimeOut(ID);

        process1("lbCart", "AddExtra", "1", ID, CompID, "1");

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //Used on the Product Detail Page
    if (BtnType == 'ADD')
    {
        var P = "CM" + CompID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/wait.gif";
        BuySetCMTimeOut(CompID);

        var QtyEdit = "CartQtyEdit" + CompID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        process1("lbCart", "Add", "1", ID, CompID, AQty);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //Used on the Product Detail Page for an extra button at the bottom
    if (BtnType == 'AXB')
    {
        var P = "XB" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/wait.gif";
        BuySetXBTimeOut(ID);

        var QtyEdit = "CartQtyEditX" + ID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        process1("lbCart", "Add", "1", ID, CompID, AQty);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //Used on the Product Detail Page (Dual Buttons Bit)
    if (BtnType == 'ADU')
    {
        var P = "CD" + CompID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/wait.gif";
        BuySetCDTimeOut(CompID);

        var QtyEdit = "CartQtyEditD" + CompID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        process1("lbCart", "Add", "1", ID, CompID, AQty);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //Used on the Product Detail Page
    if (BtnType == 'APD')
    {
        var OrgImage = "./images/large/" + ID + ".jpg";

        CompID = $("#CompID").attr("value");

		if($("#Size" + ID).length )
		{
			var AS = $("#Size" + ID).attr("value");			
			if (AS != null) CompID = AS;
		}		

        function APDImage() { $("#PD" + ID).attr("src", OrgImage); }
        window.setTimeout(APDImage, 1800);

        $("#PD" + ID).attr("src", ("./images/waiting.gif"));

        var AQty = $("#CartQtyEdit" + ID).attr("value");
        $("#CartQtyEdit" + ID).attr("value", 1);

        $.ajax({
            url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
            data: "AControl=lbCart&Action=Add&Type=1&ID=" + ID + "&CID=" + CompID + "&Qty=" + AQty,
            success: function(html) { $("#lbCart").html(html); }
        });
        $.ajax({
            url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
            data: "AControl=CartSlider&Action=RenderCS&Type=1&ID=" + ID + "&CID=" + CompID + "&Qty=" + AQty,
            success: function(html) { $("#CartSlider").html(html); }
        });
        $.ajax({
            url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
            data: "AControl=ShowCS&Action=ShowCS&Type=1&ID=" + ID + "&CID=" + CompID + "&Qty=" + AQty,
            success: function(html)
            {
                var x = parseInt(html) * 66;
                x = x + 80;
                $("#CartSlider").height(x);
                $("#CartSlider").slideDown("slow");
            }
        });

        function APDSlideUp() { $("#CartSlider").animate({ opacity: 'hide', height: 'hide' }, 'slow'); }
        window.setTimeout(APDSlideUp, 10000);
    }

    //Used on the Product Detail Page
    if (BtnType == 'AAP')
    {
        var OrgImage = "./images/large/" + ID + ".jpg";

        CompID = $("#CompID").attr("value");

        function AAPImage() { $("#PD" + ID).attr("src", OrgImage); }
        window.setTimeout(AAPImage, 1800);

        $("#PD" + ID).attr("src", ("./images/waiting.gif"));

        var AQty = $("#CartQtyEdit" + ID).attr("value");
        $("#CartQtyEdit" + ID).attr("value", 1);

        BuyCalcPrice(ID);

        function AAPSlideUp() { $("#CartSlider").animate({ opacity: 'hide', height: 'hide' }, 'slow'); }
        window.setTimeout(AAPSlideUp, 10000);
    }

    //Used on the Product Listing Page
    if (BtnType == 'BNB')
    {
        var OrgImage = "./images/large/" + ID + ".jpg";

        function BNBImage() { $("#P" + ID).attr("src", OrgImage); }
        window.setTimeout(BNBImage, 1800);

        $("#P" + ID).attr("src", ("./images/waiting.gif"));

        var AQty = 1;

        $.ajax({
            url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
            data: "AControl=lbCart&Action=Add&Type=1&ID=" + ID + "&CID=" + CompID + "&Qty=" + AQty,
            success: function(html) { $("#lbCart").html(html); }
        });
        $.ajax({
            url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
            data: "AControl=CartSlider&Action=RenderCS&Type=1&ID=" + ID + "&CID=" + CompID + "&Qty=" + AQty,
            success: function(html) { $("#CartSlider").html(html); }
        });
        $.ajax({
            url: "AjaxCart.aspx", type: "GET", dataType: "html", cache: false,
            data: "AControl=ShowCS&Action=ShowCS&Type=1&ID=" + ID + "&CID=" + CompID + "&Qty=" + AQty,
            success: function(html) {
                var x = parseInt(html) * 66;
                x = x + 80;
                $("#CartSlider").height(x);
                $("#CartSlider").slideDown("slow");
            }
        });

        function APDSlideUp() { $("#CartSlider").animate({ opacity: 'hide', height: 'hide' }, 'slow'); }
        window.setTimeout(APDSlideUp, 10000);
    }

    //Used on the BUDDY Product Detail Page (Main Product)
    if (BtnType == 'APY')
    {

        var P = "PD" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/BigBagAdd.gif";
        BuySetPDTimeOut(ID);


        var QtyEdit = "CartQtyEdit" + ID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        process1("lbCart", "AddBuddy", "1", ID, CompID, AQty);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //When A Product is a component of a product
    if (BtnType == 'APM')
    {
        var P = "PM" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/wait.gif";
        BuySetPMTimeOut(ID);

        var QtyEdit = "CartQtyEdit" + ID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        process1("lbCart", "Add", "1", ID, CompID, AQty);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //When A Product is a component of a product
    if (BtnType == 'APU')
    {
        var P = "PU" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/wait.gif";
        BuySetPUTimeOut(ID);

        var QtyEdit = "CartQtyEditD" + ID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        process1("lbCart", "Add", "1", ID, CompID, AQty);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //Used for the Buy Now Button on the FrontPage
    if (BtnType == 'FPG')
    {
        var P = "P" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/BagAdd.gif";
        BuySetTimeOut(ID);

        process1("lbCart", "AddFP", "1", ID, CompID, "1");

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    //Used for the Buy Now Button on the FrontPage
    if (BtnType == 'MRI')
    {
        var ADate = new Date();
        location.href = "Product.aspx?ID=" + ID + "&TID=" + ADate.getTime();
    }

    if (BtnType == 'ENL')
    {
        ShowBig(ID);
    }

    //Clothing Top
    if (BtnType == 'CLT')
    {
        var P = "PD" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/BigBagAdd.gif";
        BuySetPDTimeOut(ID);

        var QtyEdit = "CartQtyEdit" + ID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        var CMID = "Size" + ID;
        var ASize = document.getElementById(CMID);

        var Logo = "";
        var LogoSel = document.getElementById("ddPerson");

        if (LogoSel)
        {
            for (var i = 0; i < LogoSel.options.length; i++)
            {
                if (LogoSel.options[i].selected)
                {
                    Logo = LogoSel.options[i].value;
                    break;
                }
            }
            if (Logo == "") Logo = LogoSel.options[0].value;
        }
        process1("lbCart", "Add", "1", ID, ASize.value, AQty);
        process2("lbCart", "AddNote", "1", ID, ASize.value, Logo);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

    if (BtnType == 'CLL')
    {
        var P = "CL" + ID;
        var PWait = document.getElementById(P);
        PWait.src = "./images/BigBagAdd.gif";
        BuySetCLTimeOut(ID);

        var QtyEdit = "CartQtyEdit" + ID;
        var AQty = document.getElementById(QtyEdit).value;
        document.getElementById(QtyEdit).value = "1";

        var CMID = "Size" + ID;
        var ASize = document.getElementById(CMID);

        process1("lbCart", "Add", "1", ID, ASize.value, AQty);

        img_tag.src = img_tag.src.replace(/_down(\.[^.]+)$/, '$1');
    }

}

function mouseout(e)
{
    var target = findTarget(e);
    if (!target) return;

    var img_tag = target.childNodes[0];
    img_tag.src = img_tag.src.replace(/_over(\.[^.]+)$/, '$1');
}

function mouseover(e)
{
    var target = findTarget(e);
    if (!target) return;

    var img_tag = target.childNodes[0];
    img_tag.src = img_tag.src.replace(/(\.[^.]+)$/, '_over$1');
}

function Imagemouseover(e)
{
    var target = findTarget(e);
    if (!target) return;

    var img_tag = target.childNodes[0];

    var IDName = new String(img_tag.name.substring(1));
    var ID = IDName.substring(0, IDName.indexOf("P", 0));
    var ProdID = IDName.substring(IDName.indexOf("P", 0) + 1);

    var P = "PD" + ProdID;

    var PWait = document.getElementById(P);

    PWait.src = "./images/AddLarge/" + ID + ".jpg";
}

function Imagemousedown(e)
{
    var target = findTarget(e);
    if (!target) return;

    var img_tag = target.childNodes[0];

    var IDName = new String(img_tag.name.substring(1));
    var ID = IDName.substring(0, IDName.indexOf("P", 0));

    ShowBigAdd(ID);
}

function Imagemouseout(e)
{
    var target = findTarget(e);
    if (!target) return;

    var img_tag = target.childNodes[0];

    var IDName = new String(img_tag.name.substring(1));
    var ID = IDName.substring(0, IDName.indexOf("P", 0));
    var ProdID = IDName.substring(IDName.indexOf("P", 0) + 1);

    var P = "PD" + ProdID;

    var PWait = document.getElementById(P);

    PWait.src = "./images/Large/" + ProdID + ".jpg";
}

function doClick(buttonName, e)
{
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    var key;

    if (window.event) key = window.event.keyCode;     //IE
    else key = e.which;     //firefox

    if (key == 13)
    {
        var btn = document.getElementById(buttonName);
        if (btn != null)
        {
            btn.click();
            event.keyCode = 0
        }
    }
}

function NewList(Filter, Var, Page)
{
    process4("ListDisp", "NewList", Filter, Var, "0", "0", Page);
}

function NewList2(Filter, ListID, Page)
{
    var ddSelect = document.getElementById("ddSelect");
    var SelID = "0";

    if (ddSelect)
    {
        for (var i = 0; i < ddSelect.options.length; i++)
        {
            if (ddSelect.options[i].selected)
            {
                SelID = ddSelect.options[i].value;
                break;
            }
        }
    }

    var ddFilter = document.getElementById("ddFilter");
    var FilID = "0";

    if (ddFilter)
    {
        for (var i = 0; i < ddFilter.options.length; i++)
        {
            if (ddFilter.options[i].selected)
            {
                FilID = ddFilter.options[i].value;
                break;
            }
        }
    }
    var tbID = document.getElementById("ListID");
    var ID = tbID.value;

    //alert( Filter + ' - ' + FilID  + ' - ' +  SelID  + ' - ' +  ID  + ' - ' + Page );

    process4("ListDisp", "NewList2", Filter, FilID, SelID, ID, Page);
}

function ListSelect(ID)
{
    var ddSelect = document.getElementById("ddSelect");
    var SelID = "1";
    for (var i = 0; i < ddSelect.options.length; i++)
    {
        if (ddSelect.options[i].selected)
        {
            SelID = ddSelect.options[i].value;
            break;
        }
    }

    var ddFilter = document.getElementById("ddFilter");
    var FilID = "1";
    for (var i = 0; i < ddFilter.options.length; i++)
    {
        if (ddFilter.options[i].selected)
        {
            FilID = ddFilter.options[i].value;
            break;
        }
    }

    var ListPage = document.getElementById("ListPage");
    var PageNo = ListPage.value;

    var MainCat = document.getElementById("tbCat");
    var Filter = MainCat.value;

    //alert( Filter + ' - ' + FilID  + ' - ' +  SelID  + ' - ' +  ID  + ' - ' + PageNo );

    process4("ListDisp", "NewList2", Filter, FilID, SelID, ID, PageNo);
}

function RemoveLine(ItemType, ItemID, CompID)
{
    process1("lbEditCart", "RemoveLine", ItemType, ItemID, CompID, "0");
}

function UpdateLine(ItemType, ItemID, CompID, Control)
{
    var AQty = document.getElementById(Control).value;
    process1("lbEditCart", "UpdateLine", ItemType, ItemID, CompID, AQty);
}

function RemoveLine2(ItemType, ItemID, CompID)
{
    process1("lbEditCart", "RemoveLine2", ItemType, ItemID, CompID, "0");
    UpdateShipping();
}

function UpdateLine2(ItemType, ItemID, CompID, Control)
{
    var AQty = document.getElementById(Control).value;
    process1("lbEditCart", "UpdateLine2", ItemType, ItemID, CompID, AQty);
    UpdateShipping();
}

function UpdateShipping()
{
    //alert('UpdateShipping' );
    var ddShip = document.getElementById("ddShipping");
    var SID = "1";
    for (var i = 0; i < ddShip.options.length; i++)
    {
        if (ddShip.options[i].selected)
        {
            SID = ddShip.options[i].value;
            break;
        }
    }
    process2("lbFooter", "GetFooter", "", SID, "", "");
}

function BuyNow(ID, CompID)
{
    var TheQty = 1;
    
    try
    {
        var AQty = igedit_getById("tbQty");
        TheQty = AQty.getValue();
    }
    catch(oError)
    {
    
    }

    process1("lbCart", "Add", "1", ID, CompID, TheQty);

    try
    {
        AQty.setValue(1);
    }
    catch( oError)
    {
    
    }
}

//Used on the Special Offer Image on the Front Page		
function BuyNow4(ID)
{
    var CompID = "0";

    var ADate = new Date();
    location.href = "AjaxCart.aspx?Action=ECAdd&Type=1&ID=" + ID + "&CID=" + CompID + "&Qty=1&TID=" + ADate.getTime();
}

//Used in Golden Ads Box
function BuyNow_Ads(ID, CompID)
{
    process1("lbCart", "AddExtra", "1", ID, CompID, "1");
}

function ShowBig(ID)
{
    popupWindow('BigImage.aspx?ID=' + ID)
}
function ShowBigAdd(ID)
{
    popupWindow('BigAddImage.aspx?ID=' + ID)
}

function Shipping(ID, Item, A, B)
{
    process1("lbCart", "Ship", "0", ID, "0", "0");

    var RBL = "";
    for (var i = A; i <= B; i++)
    {
        RBL = "rbShip" + i;
        document.getElementById(RBL).checked = false;
    }

    var RB = document.getElementById(Item);
    RB.checked = true;

    var TB = document.getElementById('tbShip');
    TB.value = ID;
}
function Insurance()
{
    var Ins = document.getElementById('cbInsure');

    if (Ins.checked) process1("lbCart", "Insure", "0", "1", "0", "0");
    else process1("lbCart", "Insure", "0", "0", "0", "0");
}

function GetZip(ZIP)
{
    process1("", "GetZip", ZIP, "", "", "");
}

function InsuranceCart()
{
    var Ins = document.getElementById('cbInsure');

    if (Ins.checked)
    {
        process1("", "InsureCart", "0", "1", "0", "0");
    }
    else
    {
        process1("", "InsureCart", "0", "0", "0", "0");

    }
    UpdateShipping();
}
function Payment(ID, Item, A, B)
{
    var RBL = "";
    for (var i = A; i <= B; i++)
    {
        RBL = "rbPay" + i;
        document.getElementById(RBL).checked = false;
    }

    var RB = document.getElementById(Item);
    RB.checked = true;

    var TB = document.getElementById('tbPay');
    TB.value = ID;
}

function ClearShipping() { process1("lbCart", "Ship", "0", "0", "0", "0"); }
function ClearInsurance() { process1("lbCart", "Insure", "0", "0", "0", "0"); }

function popupWindow(url)
{
    window.open(url, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=120,height=120,screenX=150,screenY=150,top=150,left=150');
}

function SelectImage(ID)
{
    location.href = "Product.aspx?ID=" + ID;
}

function RollOverGoldenAds()
{
    var Tbl = document.getElementById("TableAds");
    Tbl.style.backgroundColor = "#A0F4F6";
}

function RollOutGoldenAds()
{
    var Tbl = document.getElementById("TableAds");
    Tbl.style.backgroundColor = "#ffffff";
}

function CoopsBtn_Click(oButton, oEvent)
{
    window.open("./Coops.aspx", 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=345,height=405,screenX=50,screenY=50,top=50,left=500');
}
function StatsBtn_Click(oButton, oEvent)
{
    window.open("./ShopMgr/Stats.aspx", 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=700,screenX=50,screenY=50,top=50,left=50');
}
function AdminStatsBtn_Click(oButton, oEvent)
{
    window.open("./ShopMgr/Stats.aspx", 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=700,screenX=50,screenY=50,top=50,left=50');
}
function HistBtn_Click(oButton, oEvent)
{
    window.open("./History.aspx", 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=600,screenX=50,screenY=50,top=50,left=50');
}
function AdminHistBtn_Click(oButton, oEvent)
{
    window.open("./History.aspx", 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=960,height=600,screenX=50,screenY=50,top=50,left=50');
}

function BuySetTimeOut(ImageID)
{
    var A = "./images/small/" + ImageID + ".jpg";
    var P = "P" + ImageID;

    function bar() { document.getElementById(P).src = A; }
    window.setTimeout(bar, 1800);
}

function BuySetPMTimeOut(ImageID)
{
    var A = "./images/small/" + ImageID + ".jpg";
    var P = "PM" + ImageID;

    function bar() { document.getElementById(P).src = A; }
    window.setTimeout(bar, 1800);
}

function BuySetCLTimeOut(ImageID)
{
    var A = "./images/small/" + ImageID + ".jpg";
    var P = "CL" + ImageID;

    function bar() { document.getElementById(P).src = A; }
    window.setTimeout(bar, 1800);
}

function BuySetPUTimeOut(ImageID)
{
    var A = "./images/small/" + ImageID + ".jpg";
    var P = "PU" + ImageID;

    function bar() { document.getElementById(P).src = A; }
    window.setTimeout(bar, 1800);
}

function BuySetCMTimeOut(ImageID)
{
    var A = "./images/Comps/" + ImageID + ".jpg";
    var P = "CM" + ImageID;

    function bar() { document.getElementById(P).src = A; }
    window.setTimeout(bar, 1800);
}

function BuySetCDTimeOut(ImageID)
{
    var A = "./images/Comps/" + ImageID + ".jpg";
    var P = "CD" + ImageID;

    function bar() { document.getElementById(P).src = A; }
    window.setTimeout(bar, 1800);
}

function BuySetPDTimeOut(ImageID)
{
    var A = "./images/large/" + ImageID + ".jpg";
    var P = "PD" + ImageID;

    function bar() { document.getElementById(P).src = A; }
    window.setTimeout(bar, 1800);
}

function ClearText(e)
{
    var tb = document.getElementById(e);
    tb.value = "";
}

function ShowCart(CartItems)
{
    var x = parseInt(CartItems) * 66;
    x = x + 80;

    $("#CartSlider").height(x);

    $("#CartSlider").slideDown("slow");
}

function HideCart()
{
    $("#CartSlider").animate({ opacity: 'hide', height: 'hide' }, 'slow');
}
