﻿window.onload = load;
window.onbeforeunload = unload;
var coords;
var currPos;
var touchScreen;
var minPrice,maxPrice;

var fpSliders=[];
var aStore;


function load()
{
    if($('reference1')){var newZoom;prodInfoZoom();}     
    if($('scrollContain')){
        (function(){
            var scrollTrack=$('scrollTrack');		
		    var scrUp=$('scrollLeft'),scrDown=$('scrollRight');
		    var scroll=new scroller(
		        $('scrollContain'),
		        $('scrollHandle'),
		        $('scrollTrack'),
		        $('fpScroll'), //plistT
		        $('mainScroll'),   //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();}                  
        })()
    }
    
    var dropDownClass=$$(document,"div","dropdown");     
    var baseClass=$$(document,"div","wrapDropdown");   
    var displayClass=$$(document,"div","dropdownCon");
    for(var i=0;i<dropDownClass.length;i++){
        makeDropDown(
            dropDownArray,
            dropDownClass[i],
            baseClass[i],
            displayClass[i],
            '',
            '',
            '',
            '',
            doDropDown
        );     
    }		
    
    /* FRONTPAGE SLIDERS */
    var getContainer=$$(document,"ul","frontpage");  
    var getAllContent=$$(document,"li","fpl2");      
    var getTopControls=$$(document,"div","verticalT");
    var getBottomControls=$$(document,"div","verticalB");      
    for(var i=0;i<getContainer.length;i++){        
        generateSliders({
            get:'offsetHeight',
            set:'height',
            style:'top',
            container:getContainer[i],
            content:getContainer[i].getElementsByTagName('li'),
            ctrl:({left:getTopControls[i],right:getBottomControls[i]})  
        }); /*** vertical sliders */
    };      
    if($('ulFp2')){
        generateSliders({ 
            get:'offsetWidth',
            set:'width',
            style:'left',
            container:$('ulFp2'),
            content:$$(document,"li","fpl"),
            ctrl:({left:$('ctrlL'),right:$('ctrlR')}),
            option:'updateDisplay',
            display:$('slideTitle')
        });
    };/*** horizontal slider */            
    /* END SLIDERS */    
        
    aStore=new fpLinkStore();
    
    if($('fpSearch')){$('fpSearch').onclick=function(){aStore.buildURL();}}   
    
    
    //fpLink();
    var fpLinks=$$(document,'a','fpLinks');
    for(var i=0;i<fpLinks.length;i++){fpLinks[i].onclick=fpLink;}
    
    if(document.getElementById('thisContent'))
    {
        doProdList();
        document.ondragstart=null;
		document.onselectstart=null;
    }

    var currButtons = $$(document, "p", "hCurr"); //MSIE Fix
    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'; }
            }
        }
    }
    if($('dPrice1')){$('dPrice1').innerHTML=currency.getRate(getCookie("currCookie")).currSet.currSymbol+(currency.getRate(getCookie("currCookie")).currSet.currRate*minPrice).toFixed(0);}
    if($('dPrice2')){$('dPrice2').innerHTML=currency.getRate(getCookie("currCookie")).currSet.currSymbol+(currency.getRate(getCookie("currCookie")).currSet.currRate*maxPrice).toFixed(0);}
}

function unload(){resetDropDown();}

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 faqtog(conid, linkid) {
    try {
        var container = document.getElementById(conid);
        var link = document.getElementById(linkid);

        if (container.style.display == 'none') {
            container.style.display = 'block';
        } else {
            container.style.display = 'none';
        }
    } catch (e) { }
}

function readtog(conid, linkid, maxh) {
    //alert(conid+"____"+linkid+"____"+maxh);
   // try {
        var container = document.getElementById(conid);
        var link = document.getElementById(linkid);
        var height = container.scrollHeight;
        var cheight = container.offsetHeight;

        if (maxh == 'check') {
            if (cheight >= height) {
                link.style.display = 'none';
            } else {
                link.style.display = 'block';
            }
        } else {
                
            if (height > cheight) {
                container.style.height = height + 'px';
                link.innerHTML = 'Read Less';
            } else {
                container.style.height = maxh + 'px';
                link.innerHTML = '...Read More';
            }
        }
    //} catch (e) { }
}

function Highlight(id) {
    var storediv = document.getElementById('st-' + id)
    if (storediv) {
        storediv.className = 'storeinfo_on';
    }
    var marker = document.getElementById('mark-' + id)
    if (marker) {
        marker.src = '/images/storelocator/marker_on.png';
    }
}

function UnHighlight(id, num) {
    var storediv = document.getElementById('st-' + id)
    if (storediv) {
        storediv.className = 'storeinfo';
    }
    var marker = document.getElementById('mark-' + id)
    if (marker) {
        marker.src = '/images/storelocator/marker' + num + '.png';
    }
}



function displaySizeFit(units) {
    var xmlHttp = null;
    var response;
    var container = document.getElementById("tabContent1");

    if (units == '' || units == 'undefinded') {
        units = '';
    }
    
    try {
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
            alert("Your browser does not support XMLHTTP!");
            return;
        }
    }
    var url = "/websizes.asp";
    url = url + "?pcode=" + escape(pCode);
    url = url + "&units=" + escape(units);
    //alert(url);
    //try set to true for async
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
    xmlHttp.responseText;
    response = xmlHttp.responseText;
    container.innerHTML = response;
}

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 showPass(str) {
    c = document.getElementById("password_con");
    //alert("str: "+str)
    if (str == "1") {
        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 check(formRef,obj){
    var dropDown=document[formRef].address1;
    if(dropDown.value==''){dropDown.className='errSelect';obj.style.display='block';return false;}
    else{                  dropDown.className='';obj.style.display='none';return true;}        
}
function link_encode(string){        
	string = string.toLowerCase();
    string = string.replace(/-/g, "~");
    string = string.replace(/ /g, "-");
	string = string.replace(/£/g, "-pound-");
    string = string.replace(/%/g, "%25");
    string = string.replace(/\+/g, "%2b");
	string = string.replace(/&/g, "_and_");
    return string;    
}  
function liveChat(url){newwindow=window.open(url,'name','height=475,width=420');if(window.focus){newwindow.focus();}return false;}
function openZoom(image,name) 
{
    var newWindow = window.open('','','scrollbars=yes,menubar=no,height=850,width=850,resizable=yes,toolbar=no,location=no,status=no');
    //newWindow.document.write("<html><head><title>"+name+" Large Image</title></head><body><div align='center'><img src='../aspecto/resize.asp?image=/aspecto/store/stock/"+image+"&dim=1000'></div></body></html>");
    newWindow.document.write("<html><head><title>"+name+" Large Image</title></head><body><div align='center'><img src='../isize.asp?image=/store/stock/"+image+"&h=800&w=800&fit=0'></div></body></html>");
    newWindow.document.close;
}
