﻿window.onload = load;
var aSrch;
var coords;
var currPos;
var version1;
var browser = navigator.appName;
var version=navigator.appVersion;
function getBrowser(){if(browser=="Microsoft Internet Explorer"){version1=version.substring(22,25);}}
getBrowser();
function load()
{
    if($('zoomWindow')){var newZoom;prodInfoZoom();}         
    if($('reference1')){try{getBrowser();
        spanI0=$('spanI0');
        spanI1=$('spanI1');
        spanI2=$('spanI2');
        spanI3=$('spanI3');
        spanI4=$('spanI4');}catch(e){}              
        getImgSrc(bCode,pColour,imgNo,thumbDim,img1,img2,img3,imgFit,'true');
    }    
    if(document.getElementById('thisContent'))
    {
        var scrollTrack=$('scrollTrack');		
		var scrUp=$('scrollLeft'),scrDown=$('scrollRight');
		scroll=new scroller($('scrollContain'),$('scrollHandle'),$('scrollTrack'),$('plistT'),$('plist_wrap'),'styleLeft');		
		scroll.init();			
		scrollTrack.onmousedown=function(event){scroll.mouseMove();}		
		scrUp.onmousedown=
		scrDown.onmousedown=function(){scroll.startClickMove(this);}
		scrUp.onmouseout=
		scrUp.onmouseup=
		scrDown.onmouseout=
		scrDown.onmouseup=function(){scroll.stopClickMove();}     
        doProdList();          
    }
    if(document.getElementById('basketWrap')){
        var scrollTrack=$('scrollTrack');		
		var scrUp=$('scrollUp'),scrDown=$('scrollDown');
		scroll=new scroller(
		    $('scrollContain'),
		    $('scrollHandle'),
		    $('scrollTrack'),
		    $('basketTable'),
		    $('basketWrap'),
		    'styleTop'
		);		
		scroll.init();			
		scrollTrack.onmousedown=function(event){scroll.mouseMove();}		
		scrUp.onmousedown=
		scrDown.onmousedown=function(){scroll.startClickMove(this);}
		scrUp.onmouseout=
		scrUp.onmouseup=
		scrDown.onmouseout=
		scrDown.onmouseup=function(){scroll.stopClickMove();}                  
    }
    if($('conDesc')){
        var scrollTrack=$('scrollTrack');
        var scrUp=$('scrollUp'),scrDown=$('scrollDown');
        scroll=new scroller(
		    $('scrollContain'),
		    $('scrollHandle'),
		    $('scrollTrack'),
		    $('wrapDesc'),
		    $('conDesc'),
		    'styleTop'       
        );
    	scroll.init();			
		scrollTrack.onmousedown=function(event){scroll.mouseMove();}		
		scrUp.onmousedown=
		scrDown.onmousedown=function(){scroll.startClickMove(this);}
		scrUp.onmouseout=
		scrUp.onmouseup=
		scrDown.onmouseout=
		scrDown.onmouseup=function(){scroll.stopClickMove();}   
    }
    if($('scrollContainMain')){
        var scrollTrack=$('scrollTrack');
        var scrUp=$('scrollUp'),scrDown=$('scrollDown');
        scroll=new scroller(
		    $('scrollContainMain'),
		    $('scrollHandle'),
		    $('scrollTrack'),
		    $('mainScroll'),
		    $('mainScrollWrap'),		    
		    'styleTop'       
        );
    	scroll.init();			
		scrollTrack.onmousedown=function(event){scroll.mouseMove();}		
		scrUp.onmousedown=
		scrDown.onmousedown=function(){scroll.startClickMove(this);}
		scrUp.onmouseout=
		scrUp.onmouseup=
		scrDown.onmouseout=
		scrDown.onmouseup=function(){scroll.stopClickMove();}   
    }
    /** sizeGuide Scroller */
    if($('sizeGuideWrap')){
        var scrollTracks=$('scrollTrackSize');
        var scrUps=$('scrollUpSize'),scrDowns=$('scrollDownSize');
        scrolls=new scroller(
		    $('scrollContainSize'),
		    $('scrollHandleSize'),
		    $('scrollTrackSize'),
		    $('sizeGuideContent'),
		    $('sizeGuideIWrap'),		    
		    'styleTop'       
        );
    	scrolls.init();			
		scrollTracks.onmousedown=function(event){scrolls.mouseMove();}		
		scrUps.onmousedown=
		scrDowns.onmousedown=function(){scrolls.startClickMove(this);}
		scrUps.onmouseout=
		scrUps.onmouseup=
		scrDowns.onmouseout=
		scrDowns.onmouseup=function(){scrolls.stopClickMove();}   
    }
    var currButtons = $$(document, "p", "hCurr"); //MSIE Fix
    //alert(currency.getRate(getCookie("currCookie")).currSet.currRate + " #" + currency.store.active)
    if (currency.getRate(getCookie("currCookie")).currSet.currRate != currency.store.active) {
        var prices = $$(document, "span", "currTag");
        currency.setCurrency(getCookie("currCookie"), prices);
        setClicks(currButtons, document.getElementById(currency.getRate(getCookie("currCookie")).currSet.cCode));
    }
    for(i in currButtons){
        currButtons[i].onclick = function () {
            var prices = $$(document, "span", "currTag");
            currency.setCurrency(this.id, prices);
            setClicks(currButtons,this);
            if (document.getElementById('currPrompt')) {//ugly checkout prompt box
                var checkPrompt = document.getElementById('currPrompt');
                if (this.innerHTML != site_currency) { checkPrompt.style.display = 'block'; }
                else { checkPrompt.style.display = 'none'; }
            }
        }
    }
    /** ~~~~~~~~~~~~~~~~~~~~~ Newsletter signup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */    
    $('sUpLink').onclick=function(){return false;}
    var nContent=$('signUpContent');     
    isNaN(parseInt(version1))?
    nContent.fade=new opacity(nContent,0,20,100,0,5,10):
    nContent.fade=new opacity(nContent,0,0,100,0,25,10);//IE        
    var signUp=$('tagLink');

    signUp.onclick=function(){
        var nreq=createxmlHttp();  
        nreq.onreadystatechange=function(){
            if(nreq.readyState==4&&nreq.status==200){            
                doPopOut(nreq,'newsClose',nContent);            
            }
        }
        var URL="/initForm.asp?dir=sNewsletter";
        nreq.open("GET",URL,true);
        nreq.send(null); 
    }  
    
    if($('sizeGuideWrap')){
        var sGuide=$('sGuide');
        var nContent2=$('sizeGuideWrap');  
        var nContent2a=$('sizeGuideContent'); 
        isNaN(parseInt(version1))?
        nContent2.fade=new opacity(nContent2,0,0,100,0,10,10):
        nContent2.fade=new opacity(nContent2,0,0,100,0,25,10);//IE      
        sGuide.onclick=function(){
            var nreq=createxmlHttp();  
            nreq.onreadystatechange=function(){
                if(nreq.readyState==4&&nreq.status==200){        
                    nContent2a.innerHTML=nreq.responseText;
                    nContent2.fade.iFadeIn(1);                    
                    scrolls.timer.timer(
                        function(){
                            scrolls.initStuff();
                        },500
                    );
                    $('sizeClose').onclick=function(){
                        nContent2.fade.iFadeOut(1);     
                        return false;  
                    }                          	
                }
            }
            var URL="/sSizeGuide.asp";
            nreq.open("GET",URL,true);
            nreq.send(null);  
        }    
    }   
}

function $(id){return document.getElementById(id);}
function c$(a,b){
	return(
		function(e){
			return a[b](e,this);
		}
	)
}
function makeScroller(){} //not in use yet
    makeScroller.prototype={
        addScroller:function(scrContain,scrHandle,scrTrack,toScroll,wrapToScroll,dirRef){
            this.s.push(
                new scroller(
		            $(scrContain),
		            $(scrHandle),
		            $(scrTrack),
		            $(toScroll),
		            $(wrapToScroll),		    
		            dirRef       
                )
            );
            this.s[this.s.length-1].init();   
            scrTrack.onmousedown=$c(this.s[this.s.length-1],'mouseMove');//function(event){scroll.mouseMove();}		
		    scrUp.onmousedown
		    scrDown.onmousedown=c$(this.s[this.s.length-1],'s');
		scrUp.onmousedown=
		scrDown.onmousedown=function(){scroll.startClickMove(this);}
		scrUp.onmouseout=
		scrUp.onmouseup=
		scrDown.onmouseout=
		scrDown.onmouseup=function(){scroll.stopClickMove();}        
    }
}
function createxmlHttp(){var request=false;
    try{request=new XMLHttpRequest();}catch(e){try{
    request=new ActiveXObject("Msxml2.XMLHTTP");}
    catch(e){try{request=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(e){alert("Your browser does not support AJAX!");request=false;}}}return request;}
function doPopOut(obj,closeObj,contentObj,sizeGuideWrap){
    contentObj.innerHTML=obj.responseText;
    contentObj.fade.iFadeIn(1);
    $(closeObj).onclick=function(){
        contentObj.fade.iFadeOut(1);     
        return false;  
    }
}
function setClicks(els, active) { for (j in els) { els[j].className = "hCurr"; } active.className = "hCurr hcOn"; }
function currency(a){this.store={prev:a,active:a};this.array=new Array();}
    currency.prototype.addCurrency=function(cC,cS,cR){this.array.push(new this.initCurrency(cC,cS,cR));}
    currency.prototype.initCurrency=function(cC,cS,cR){this.currSet={cCode:cC,currSymbol:cS,currRate:cR};}
    currency.prototype.getRate=function(cCode){for(i in this.array){if(this.array[i].currSet.cCode==cCode){return this.array[i];break;}}}
    currency.prototype.clean=function(num){num=num.replace(",","");return num;}
    currency.prototype.format=function(num,dp){       
        var x=num.split('.');var x1=x[0];
        var x2=x.length>1&&dp>0?'.'+x[1]:'';
        var rgx=/(\d+)(\d{3})/;
        while(rgx.test(x1)){x1 =x1.replace(rgx,'$1'+','+'$2');}            
        return x1+x2; 
    }
    currency.prototype.setCurrency=function(el,els){
        this.store.active=this.getRate(el);var dp;	
        for(i in els){
            var dp=(els[i].innerHTML.substr(1).split('.').length>1)?els[i].innerHTML.substr(1).split('.').length:0;                
            els[i].innerHTML=
            this.store.active.currSet.currSymbol+this.format(((this.clean(els[i].innerHTML.substr(1))/this.store.prev).toFixed(2)*this.store.active.currSet.currRate).toFixed(2),dp);                
        }
        this.store.prev=this.store.active.currSet.currRate;
        setCookie("currCookie",el,1);
    }
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString() + "; path=/");
}

function $$(oElm, strTagName, strClassName) {
    var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for (var i = 0; i < arrElements.length; i++) {
        oElement = arrElements[i];
        if (oRegExp.test(oElement.className)) {
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}
var Dom = { get: function(el) { if (typeof el === 'string') { return document.getElementById(el); } else { return el; } },
    add: function(el, dest) { var el = this.get(el); var dest = this.get(dest); dest.appendChild(el); },
    remove: function(el) { var el = this.get(el); el.parentNode.removeChild(el); } 
};
var Event = { add: function() {
    if (window.addEventListener) { return function(el, type, fn) { el.addEventListener(type, fn, false); }; }
    else if (window.attachEvent) { return function(el, type, fn) { var f = function() { fn.call(el, window.event); }; el.attachEvent('on' + type, f); }; } 
} ()
};

function clearDefault(el) 
{
    if (el.defaultValue==el.value) el.value = "";
}

function showOther(str)
{
    c = document.getElementById("title_other");
    if(str =="Other")
    {
        c.style.display="block";
    }
    else
    {
        c.style.display="none";
    }
}
function bskremove(product)
{
    document.getElementById(product).checked=true;
    document.basket.submit();
}

function wishremove(product)
{
    document.getElementById(product).checked=true;
    document.wishlist.submit();
}
  
function getAbsPos(element) {
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) { var tmp = getAbsPos(element.offsetParent); r.x += tmp.x; r.y += tmp.y; } return r;
}

function getRelPos(event, reference) {
    var x, y; event = event || window.event; var el = event.target || event.srcElement;
    if (!window.opera && typeof event.offsetX != 'undefined') {
        var pos = { x: event.offsetX, y: event.offsetY }; var e = el;
        while (e) {
            e.mouseX = pos.x; e.mouseY = pos.y;
            pos.x += e.offsetLeft; pos.y += e.offsetTop; e = e.offsetParent;
        }
        var e = reference; var offset = { x: 0, y: 0 }
        while (e) {
            if (typeof e.mouseX != 'undefined') {
                x = e.mouseX - offset.x; y = e.mouseY - offset.y; break;
            }
            offset.x += e.offsetLeft; offset.y += e.offsetTop; e = e.offsetParent;
        } e = el;
        while (e) { e.mouseX = undefined; e.mouseY = undefined; e = e.offsetParent; } 
    }
    else { var pos = getAbsPos(reference); x = event.pageX - pos.x; y = event.pageY - pos.y; }
    return { x: x, y: y };
} 	