var subNavIFrameTop=23;
var subNavIFrameHeightOffset=17;

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function startList() {
    try {
        //If the browser is internet explorer 6 or lower
        if (BrowserDetect.browser == "Explorer" && BrowserDetect.version <= 6 && document.getElementById) {
            //Get the naviagation list
            navRoot = document.getElementById("nav");
            //Iterate over the navigation children
            for (i = 0; i < navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                //If this child is a list item
                if (node.nodeName == "LI") {
                    //Set its mouse over and mouse out behaviour
                    node.onmouseover = function() {
                        this.className += " over";
                        //Need to place an iframe under the ul
                        //so select boxes don't show through
                        var uls = this.getElementsByTagName('ul');
                        for (j = 0; j < uls.length; j++) {
                            ul = uls[j];
                            if (ul.className == "sub-nav") {
                                var iframe = document.createElement('iframe');
                                iframe.src = "about:blank";
                                var iframeHeight = ul.offsetHeight - subNavIFrameHeightOffset;
                                iframe.style.top = subNavIFrameTop + 'px';
                                iframe.style.height = iframeHeight + 'px';
                                iframe.style.width = ul.offsetWidth + 'px';

                                this.insertBefore(iframe, ul);
                            }
                        }
                    }
                    node.onmouseout = function() {
                        //Ditch the iframe
                        var iframes = this.getElementsByTagName('iframe');
                        for (k = 0; k < iframes.length; k++) {
                            this.removeChild(iframes[k]);
                        }
                        //Change the class name
                        this.className = this.className.replace(" over", "");
                    }
                }
            }
        }
    }
    catch (e) {
        // Ignore error means menu made invisible
    }
}

window.onload=function() { startList(); externalLinks(); };

//this is the script for the tabs on the details page

     //var tabCount = 4;
        function setTab(ct, tabCount) {
            var i;
            for(i=1; i<=tabCount; i++) {
                var td = document.getElementById("tabdiv" + i);
				var tl = document.getElementById("tabli" + i);
                td.style.display = 'none';
				tl.className = '';
            }
            
            var std = document.getElementById("tabdiv" + ct);
			var sli = document.getElementById("tabli" + ct);
            std.style.display = 'block';
			sli.className = 'on';

}

function BuyNow(product, quantity, goafter){
    CallServer(product + "|" + quantity + "|0|" + goafter, "");
}

function UpdateProductQuantity(product, quantity) {
    CallServer(product + "|" + quantity + "|1|", "");
}

function RemoveProduct(product) {
    CallServer(product + "|0|1|", "");
}

function ReceiveServerData(arg, context) {

    if(arg=="ok")
    {
        document.location = "/ssl/checkout/Basket.aspx";
        return;
    }
    
    if(arg!="")
    {
        document.location = arg;
        return;
    }
    else
        document.location = "/Error.aspx";
}

function SendToGoogleCheckout(productguid, quantity) {
    CallServer(productguid + "|" + quantity + "|0|", "");
}

function cookieCheck() {
    var tmpcookie = new Date();
    chkcookie = (tmpcookie.getTime() + '');
    document.cookie = "chkcookie=" + chkcookie + "; path=/";
    if (document.cookie.indexOf(chkcookie, 0) < 0) {
        document.getElementById("ctl00_divCookiesDisabled").style.display = "block";
    }
    else {
        document.getElementById("ctl00_divCookiesDisabled").style.display = "none";
    }
}