﻿// JScript File

var ASPprefix = 'ctl00_ContentPlaceHolder1_';


function preloadAndSetup()
{              
    String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
    picLoading = new Image();
    picLoading.src =  '/Images/loading.gif';
    picLoadingBig = new Image();
    picLoadingBig.src =  '/Images/loadingBig.gif';


}

function initializePages()
{
    getHostAdress();

    if (checkLocation("checkout.aspx"))
    {
        document.getElementById('btnGoToCheckout').style.visibility = 'hidden';

    
        showBas = (showBas == 1 ? 0 : 1); showBasket();
        
        setInnerText('basketCaption', 'Shopping Basket');
        
        document.getElementById('basketCaption').onclick = function() {  return;  };
        document.getElementById('basketArrow').style.display = 'none';


        if (window.external && (typeof window.XMLHttpRequest == "undefined")) // test for IE 6
        {
            document.getElementById(ASPprefix + 'txtBillPostCode').style.width = '34px';   
            document.getElementById(ASPprefix + 'txtDeliveryPostCode').style.width = '34px';   
        }
        else if (isFirefox())
        {
            document.getElementById(ASPprefix + 'txtCC1').style.width = 
            document.getElementById(ASPprefix + 'txtCC4').style.width = '35px';   
            document.getElementById(ASPprefix + 'txtCC2').style.width = 
            document.getElementById(ASPprefix + 'txtCC3').style.width = '34px';   
            document.getElementById('lblExpYear').style.width = '48px';
        }
        else if (isSafari())
        {

            if (getSafariVersion() < 520)
            {
                document.getElementById(ASPprefix + 'txtCardHolder').style.width = '150px';   
                document.getElementById('lblExpYear').style.width = '40px';   

                document.getElementById(ASPprefix + 'txtCC1').style.width = 
                document.getElementById(ASPprefix + 'txtCC4').style.width = '35px';   
                document.getElementById(ASPprefix + 'txtCC2').style.width = 
                document.getElementById(ASPprefix + 'txtCC3').style.width = '34px';   
            }
        }
    }
}




function checkLocation(page)
{
    var l = window.location.toString().toLowerCase().replace(/\\/g,"/");
    if (l.indexOf(page.toLowerCase()) > -1)
        return true;
    else
        return false;
}



function removeFirstChild(control)
{
    var xx = document.getElementById(control);
    var old = xx.firstChild;
    
    if (old != null)
        xx.removeChild(old);

    return xx;
}

function setInnerText(id, text)
{
    if (document.all || isSafari())
        document.getElementById(id).innerText = text;
    else            
        document.getElementById(id).textContent = text;
}

function getInnerText(id)
{
    if (document.all)
        return document.getElementById(id).innerText;
    else            
        return document.getElementById(id).textContent;
        
}


function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) 
{

    $.cookie(sName, sValue, { expires: 7, path: '/' });
    
}
                    
function getCookie(sName) 
{
    
    return $.cookie(sName);

}                

function deleteCookie(sName, sPath, sDomain) 
{
    
    $.cookie('the_cookie', null);
    
}


   
function getQuerystringParameterValue(p)
{
    var query_vars = readQueryStr(); 
    var myparam = query_vars[p]; 

    return myparam;
}   


/******
* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
* Modified here to exclude form tags properly, cross browser by jscheuer1
*******/

//form tags to omit:
var omitformtags=["input", "textarea", "select"]

function disableselect(e)
{
    for (i = 0; i < omitformtags.length; i++)
    if (omitformtags[i]==(e.target.tagName.toLowerCase()))
        return;
    return false
}

function reEnable()
{
    return true
}



function checkOrCreateTempContent(control)
{
    var tempCM = control.firstChild;

    if (!tempCM)
        tempCM = document.createElement("div");
        
    return tempCM;     
}




function isIE()
{
    return(document.all);
}

function isSafari()
{
    var sUserAgent = navigator.userAgent;
    return sUserAgent.indexOf("AppleWebKit") > -1;
}

function getSafariVersion()
{
    var sUserAgent = navigator.userAgent;
    var reAppleWebKit = new RegExp("AppleWebKit\\/(\\d+(?:\\.\\d*)?)");
    reAppleWebKit.test(sUserAgent);
    return parseFloat(RegExp["$1"]);
}

function isFirefox()
{
    var agt=navigator.userAgent.toLowerCase();
    if (agt.indexOf("firefox") != -1)
        return true;
    else
        return false;
}



function showDetails(id)
{

    var d = document.getElementById('feat_' + id);
    d.style.display = d.style.display == 'none' ? 'block' : 'none';
        
}


function returnKey(ev)
{
    if (window.event)
       return window.event.keyCode;
    else if (e)
       return e.which;
    else
       return true;
    
}
function allowNbOfChars(id, idToSkipTo, NbOfChars, e)
{

    var key;
    var keychar;

    key = returnKey(e);
    
    if (key >= 96 && key <=105) {
        key = key - 48;
    }
       
    keychar = String.fromCharCode(key);
    
    
	var a = document.getElementById(id);
    if ((("0123456789").indexOf(keychar) > -1))
    {
	    if ((NbOfChars - a.value.length) <= 0)
	    {
		    document.getElementById(idToSkipTo).focus();
	    }	
    }
    return true;
}

function numbersonly(myfield, e)
{
    var key;
    var keychar;

    key = returnKey(e);

    keychar = String.fromCharCode(key);

    // control keys
    if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) )
       return true;

    // numbers
    else if ((("0123456789").indexOf(keychar) > -1))
       return true;
    else
        return false;       

}


var _updatePanel;
var _imgLoading;
function pageLoad(sender, args){    
    //  register for our events
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);    
    
    //  get the updateprogressdiv
    _updatePanel = $get(ASPprefix +'upDefaultContent');
    _imgLoading = $get('divLoading');
} 
function beginRequest(sender, args){
    // make it visible
    _updatePanel.style.display = 'none';             
    _imgLoading.style.visibility = 'visible';
}
function endRequest(sender, args) {
    // make it invisible
    _imgLoading.style.visibility = 'hidden';
    _updatePanel.style.display = 'block';
}


function highlightProductLink(id)
{
    document.getElementById(id).style.textDecoration = "underline";
}

function unHighlightProductLink(id)
{
    document.getElementById(id).style.textDecoration = "none";
}

function getShipmentPrice()
{

    var region = document.getElementById( ASPprefix + "ddlShipmentRegion");
    
    if (region)
    {
         var param;
            param = encodeURIComponent("regionColumn") + "=" + encodeURIComponent( region.value ) + "&";
            param += encodeURIComponent("productList") + '=' + encodeURIComponent( itemsInCartIds );
        

        setCookie("shipmentRegion", region.value );
        
        var paramToSend = param;
        sendXHRreturnJSON(paramToSend, "GetShipmentCost", displayShipmentPrice);
        
    }
}

function displayShipmentPrice(JSON)
{

    var a = convertJSONtoArray(JSON);
    var b = new Array();
    b = a.shipment;
    
    updateTotal( b.price.replace("$", "") );
    
    
    
    var lbl = document.getElementById( ASPprefix + "lblFreight");
    
    
    
    if (lbl)
    {
        var txtPrice = document.createTextNode(b.price);
        
        if (lbl.firstChild != null)
           lbl.removeChild(lbl.firstChild);
                
        lbl.appendChild(txtPrice);
    
    }
}

function updateTotal( shipmentPrice )
{
    setCookie("Freight", shipmentPrice);

    var total = getInnerText( ASPprefix + 'lblSubtotal' ).replace("$", "");
        
    total = parseFloat(total) + parseFloat( shipmentPrice );
        
    setInnerText(ASPprefix + 'lblTotal', '$' + to2DecimalPlaces(total));  

    setInnerText(ASPprefix + 'lblGSTIncluded', '$' + to2DecimalPlaces(total/11));  
    
}

function convertJSONtoArray(JSON)
{
    try
    {
        if(JSON != '')
        {
            var x = eval("(" + JSON + ")");
            var z = new Array(x);
            var a = z[0];
            
            return a;
        }
        else
            return '';
    }
    catch(e)
    {
        alert ('Error in convertJSONtoArray \n' + e.message);
    }
     
}

function setReturnedItemsCount(value)
{
    setCookie('returnedItemsCount', value); 
    
}
function getReturnedItemsCount()
{
    var result;
    result = getCookie('returnedItemsCount'); 
    
    if (result == undefined)
        result = 0;
            
    return parseInt(result); 
}



function loadMap( )
{
    var width = "517";
    var height = "517";
    
    window.open("Map.htm","Map","left=300,top=300,width=" + width + ",height=" + height + ",resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");    
    

}




//////////////////////////////
//////////////////////////////
//////////////////////////////
///////////////////////////////

// EFFECTS


function bold(id, isBold)
{
    var a = document.getElementById(id);
    if (a)
    {
        if (isBold == 1)
            a.style.fontWeight = 'bold';
        else
            a.style.fontWeight = 'normal';
    }
}



    var currentLeftMenuID;

//   Left Menu Mouse oVer
    function LMMV(c) 
    {
        if(currentLeftMenuID != c.id && 'pmi_' + currentLeftMenuID != c.id )
            c.className = 'menuElement_Over';
        
        c.style.cursor = 'pointer';
    }
//   Left Menu Mouse ouT
    function LMMT(c)
    {
        if(currentLeftMenuID != c.id && 'pmi_' + currentLeftMenuID != c.id )
            c.className = 'menuElement';
    }

   function lOvr(c)
    {
        c.style.color='#bfbfbf'; 
        c.style.cursor='pointer';
    }
    function lOut(c)
    {
        c.style.color='purple'; 
    }

  function expandImage(id, makeBigger, changeLeftMargin)
    {
        var size;
        var object = document.getElementById(id);
        
        if (makeBigger)
            size = 10;
        else        
            size = -10;

        var w = object.style.width;
        var x = size + parseInt(w.replace('px', ''));

        var h = object.style.height;

        if(h != "")
        {
            var y = size + parseInt(h.replace('px', ''));


            object.style.width = x.toString() + 'px';
            object.style.height = y.toString() + 'px';
            
            if (makeBigger)
                object.style.marginTop = (size/-2) + 'px';
            else
                object.style.marginTop = '0px';

            if (changeLeftMargin)
            {
                if (makeBigger)
                    object.style.marginLeft = (size/-2) + 'px';
                else
                    object.style.marginLeft = '0px';
            }
        }
    }



  function opacity(id, opacStart, opacEnd, millisec) 
    {
        errorFlag = false;
        var speed = Math.round(millisec / 100); //speed for each frame
        var timer = 0;

        if(opacStart > opacEnd)  //determine the direction for the blending, if start and end are the same nothing happens
        {
            for(i = opacStart; i >= opacEnd; i--) 
            {
                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        } 
        else if(opacStart < opacEnd) 
        {
            for(i = opacStart; i <= opacEnd; i++)
            {
                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        }
    }
    
    function changeOpac(opacity, id)    //change the opacity for different browsers
    {
        var object = document.getElementById(id);
        if (object)
        {
            object.style.opacity = (opacity / 100);
            object.style.MozOpacity = (opacity / 100);
            object.style.KhtmlOpacity = (opacity / 100);
            object.style.filter = "alpha(opacity=" + opacity + ")";
            
            errorFlag = false;
        }
        else
        {
            errorFlag = true;
            return false;
            
        }
    } 
   

// end EFFECTS



// Menu Vertical scripts

    var currentTopMenuID;
   function MouseOver(c)
    {
        if(currentTopMenuID != c.id)
            c.className = 'menuElementHorizontal_Over';
        c.style.backgroundImage= "url('Images/Bckg/bg_green_roll.gif')"; 
        c.style.cursor = 'pointer';           
    }
    function MouseOut(c)
    {
        if(currentTopMenuID != c.id)
            c.className = 'menuElementHorizontal';
        c.style.backgroundImage = "url('Images/Bckg/bg_green.gif')";            
    }
    
// END Menu Vertical scripts
    
    
// Basket slide scripts

   function slideOpenCloseControlTrigger(id, px, expandDown)
    {
        var s = document.getElementById(id);
        
        errorFlag = false;
        var speed = Math.round(slideMillisec / 100); //speed for each frame
        var timer = 0;
        
        if(px > 0)  
        {
            for(i = 0; i < px; i++) 
            {
                setTimeout("slideOpenCloseControl(1,'" + id + "', " + expandDown + ")",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        } 
        else 
        {
            for(i = 0; i > px; i--)
            {
                setTimeout("slideOpenCloseControl(-1,'" + id + "', " + expandDown + ")",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        }
    }
    
     function slideOpenCloseControl(pixels, id, expandDown)    
    {
        var object = document.getElementById(id);
        var pix = parseInt(pixels);
        var t = parseInt((object.style.top).replace('px', ''));
        var h = parseInt((object.style.height).replace('px', ''));
        
        var nt = (t - pix).toString() + 'px';
        var nh = (h + pix).toString() + 'px';
        if (nh == '-1px')
            nh = '0px';
        
        if (object)
        {
            if (!expandDown)
                object.style.top = nt;
            object.style.height = nh;
        }
        else
        {
            errorFlag = true;
            return false;
        }
    } 

//  END Basket slide scripts



