﻿<!-- Hide from old browsers

// (c) Copyright 2007 - 2011 Roy Henderson(henderson.roy@gmail.com)

// Global Vars
var booAProductHasBeenAddedToComparator = false;

// iPad/iPhone/iPod detection
var strComparatorClientName = navigator.userAgent;
var booComparatorFoundiPadiPhoneiPod = false;
if (strComparatorClientName.indexOf('iPhone') != -1) { booComparatorFoundiPadiPhoneiPod = true }
if (strComparatorClientName.indexOf('iPad') != -1) { booComparatorFoundiPadiPhoneiPod = true }
if (strComparatorClientName.indexOf('iPod') != -1) { booComparatorFoundiPadiPhoneiPod = true }

// * * * Cookie Handler * * *
function CookieHandler() {
    this.setCookie = function (name, value, seconds) {

        if (typeof (seconds) != 'undefined') {
            var date = new Date();
            date.setTime(date.getTime() + (seconds * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else {
            var expires = "";
        }

        document.cookie = name + "=" + value + expires + "; path=/";
    }   // End of setCookie

    this.getCookie = function (name) {

        name = name + "=";
        var carray = document.cookie.split(';');

        for (var i = 0; i < carray.length; i++) {
            var c = carray[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
        return null;
    }   // End of getCookie

    this.deleteCookie = function (name) {
        this.setCookie(name, "", -1);
    }   // End of deleteCookie


    // Slot Management
    this.slotSet = function (strSlotNumber, strObjName, strProductCode, strProductCode360) {
        this.setCookie('SlotObjName' + strSlotNumber, strObjName, 10000);
        this.setCookie('SlotProductCode' + strSlotNumber, strProductCode, 10000);
        this.setCookie('SlotProductCode360' + strSlotNumber, strProductCode360, 10000);
        this.setCookie('SlotInitialRotate' + strSlotNumber, 'yes', 10000);
    }   // End of slotSet

    this.slotGetObjName = function (strSlotNumber) {
        return this.getCookie('SlotObjName' + strSlotNumber);
    }   // End of slotGetObjName

    this.slotGetInitialRotate = function (strSlotNumber) {
        return this.getCookie('SlotInitialRotate' + strSlotNumber);
    }   // End of slotGetInitialRotate

    this.slotSetInitialRotate = function (strSlotNumber, strNewSetting) {
        this.setCookie('SlotInitialRotate' + strSlotNumber, strNewSetting, 10000);
    }   // End of slotSetInitialRotate

    this.slotGetProductCode = function (strSlotNumber) {
        return this.getCookie('SlotProductCode' + strSlotNumber);
    }   // End of slotGetProductCode

    this.slotGetProductCode360 = function (strSlotNumber) {
        return this.getCookie('SlotProductCode360' + strSlotNumber);
    }   // End of slotGetProductCode360

    this.slotGetSlot = function (strProductCode) {
        if (this.slotGetProductCode('1') == strProductCode) { return '1' }
        if (this.slotGetProductCode('2') == strProductCode) { return '2' }
        if (this.slotGetProductCode('3') == strProductCode) { return '3' }
        if (this.slotGetProductCode('4') == strProductCode) { return '4' }
        if (this.slotGetProductCode('5') == strProductCode) { return '5' }
        if (this.slotGetProductCode('6') == strProductCode) { return '6' }
        return '0';
    }   // End of slotGetSlot

    this.slotGetFirstAvailable = function () {
        if ('[' + this.slotGetProductCode('1') + ']' == '[null]') { return '1' }
        if ('[' + this.slotGetProductCode('2') + ']' == '[null]') { return '2' }
        if ('[' + this.slotGetProductCode('3') + ']' == '[null]') { return '3' }
        if ('[' + this.slotGetProductCode('4') + ']' == '[null]') { return '4' }
        if ('[' + this.slotGetProductCode('5') + ']' == '[null]') { return '5' }
        if ('[' + this.slotGetProductCode('6') + ']' == '[null]') { return '6' }
        return '0';
    }   // End of slotGetFirstAvailable

    this.slotMoveSlotsOneLeft = function () {
        var strIni = '';

        strIni = this.slotGetInitialRotate('2');
        this.slotSet('1', this.slotGetObjName('2'), this.slotGetProductCode('2'), this.slotGetProductCode360('2'));
        this.slotSetInitialRotate('1', strIni);

        strIni = this.slotGetInitialRotate('3');
        this.slotSet('2', this.slotGetObjName('3'), this.slotGetProductCode('3'), this.slotGetProductCode360('3'));
        this.slotSetInitialRotate('2', strIni);

        strIni = this.slotGetInitialRotate('4');
        this.slotSet('3', this.slotGetObjName('4'), this.slotGetProductCode('4'), this.slotGetProductCode360('4'));
        this.slotSetInitialRotate('3', strIni);

        strIni = this.slotGetInitialRotate('5');
        this.slotSet('4', this.slotGetObjName('5'), this.slotGetProductCode('5'), this.slotGetProductCode360('5'));
        this.slotSetInitialRotate('4', strIni);

        strIni = this.slotGetInitialRotate('6');
        this.slotSet('5', this.slotGetObjName('6'), this.slotGetProductCode('6'), this.slotGetProductCode360('6'));
        this.slotSetInitialRotate('5', strIni);

        strIni = this.slotGetInitialRotate('2');
        this.slotSet('6', null, null, null);
    }

    this.slotAddProduct = function (strObjName, strProductCode, strProductCode360) {
        if (this.slotGetSlot(strProductCode) != '0') { return false };    // Already in a slot
        var strSlot = this.slotGetFirstAvailable();
        if (strSlot == '0') { this.slotMoveSlotsOneLeft(); strSlot = '6' };
        this.slotSet(strSlot, strObjName, strProductCode, strProductCode360);
        return true;
    }   // End of slotAddProduct

    this.slotRemoveProduct = function (strProductCode) {
        var strSlot = this.slotGetSlot(strProductCode);
        if (strSlot == '0') { return false }
        this.slotSet(strSlot, null, null, null);
        return true;
    }   // slotRemoveProduct



}   // End of CookieHandler


// * * *  360 Rotation  * * *
function image360Handler() {
    // * * * General functions * * *
    this.browserDetect = function () {
        var browsername = navigator.appName;
        if (browsername.search(/netscape/i) == 0) {
            return 'NS';
        }
        else if (browsername.search(/microsoft/i) == 0) {
            return 'IE';
        }
        else {
            return 'other';
        }
    }   // End of browserDetect

    this.ojbName = function () {
        if (typeof obj != "object" || obj === null) return false;
        else return /(\w+)\(/.exec(obj.constructor.toString())[1];
    }

    this.onPageDisplaySlotExists = function () {
        var strOut = '';

        try {
            document.getElementById('Comparator360SlotFrontPage').innerHTML = '';
            strOut = 'Comparator360SlotFrontPage'
            return strOut
        } catch (e) {
        }

        return strOut
    }      // End of onPageDisplaySlotExists

    // * * * 360 Bar Functions * * *
    var strBrowser = this.browserDetect();
    imgSlctGif1 = new Image;
    imgSlctGif1.src = '../purelyimages/verticallow360-1.gif';
    imgSlctGif2 = new Image;
    imgSlctGif2.src = '../purelyimages/verticallow360-2.gif';
    imgRotationClick = new Image;
    imgRotationClick.src = '../purelyimages/comparator360loading.gif';
    imgRotationClickX = new Image;
    imgRotationClickX.src = '../purelyimages/comparatorrotationlow360.gif';


    this.barItemState = function (intItem, intSelected) {
        var strImageName = str360ObjName + 'imgslct' + intItem;

        if (intSelected == 1) {
            try {
                document[strImageName].src = imgSlctGif1.src;
            }
            catch (err) {
                // Do Nothing
            }
        }
        else {
            try {
                document[strImageName].src = imgSlctGif2.src;
            }
            catch (err) {
                // Do Nothing
            }
        }   // End If
    }   // End of barUpdateItem

    this.barClearAll = function () {
        var i = 0;
        for (i = 1; i <= 20; i++) {
            this.barItemState(i, 0);
        }
    }   // End of barClearAll

    this.barSelectItem = function (intItem) {
        this.barClearAll();
        this.barItemState(intItem, 1);

    }   // End of barSelectItem

    this.barSelectItems = function (intNumberOfItems) {
        this.barClearAll();
        if (intNumberOfItems >= 1) {
            var i = 0;
            for (i = 1; i <= intNumberOfItems; i++) {
                this.barItemState(i, 1);
            }

        }

    }   // End of barSelectItems

    // * * * 360 Central Image Functions * * *
    var strProductCodeImg1 = '';
    var strProductCodeImg360 = '';
    var str360ObjName = '';
    var str360ObjHandlerName = '';
    var intRotateStep = 0;
    var intComparator360Active = 1;
    var intRotationMode = 1;
    var intAutoResetTimer = 0;
    var intLoadingTimeout = 0;
    var intPauseTimer = 0;
    var intSkipInitialRotate = 0;
    var intSkipInitialRotateForceAutoRotate = 0;

    var imgDisplay0 = new Image;    // default image
    var imgDisplay1 = new Image;
    var imgDisplay2 = new Image;
    var imgDisplay3 = new Image;
    var imgDisplay4 = new Image;
    var imgDisplay5 = new Image;
    var imgDisplay6 = new Image;
    var imgDisplay7 = new Image;
    var imgDisplay8 = new Image;
    var imgDisplay9 = new Image;
    var imgDisplay10 = new Image;
    var imgDisplay11 = new Image;
    var imgDisplay12 = new Image;
    var imgDisplay13 = new Image;
    var imgDisplay14 = new Image;
    var imgDisplay15 = new Image;
    var imgDisplay16 = new Image;
    var imgDisplay17 = new Image;
    var imgDisplay18 = new Image;
    var imgDisplay19 = new Image;
    var imgDisplay20 = new Image;


    this.deleteClick = function () {
        intRotationMode = 0;
    }   // End of deleteClick            

    this.productcodeImg1Set = function (strProductCode) {
        strProductCodeImg1 = strProductCode;

    }   // End of productcodeSet

    this.productcodeImg1Get = function () {
        return strProductCodeImg1;

    }   // End of productcodeGet

    this.productcodeImg360Set = function (strProductCode360) {
        strProductCodeImg360 = strProductCode360;
        intRotationMode = 1;    // Load images mode

    }   // End of productcodeSet

    this.productcodeImg360Get = function () {
        return strProductCodeImg360;

    }   // End of productcodeGet

    this.imageLoad = function (intImageNumber, strAddress) {
        var strImageName = 'imgDisplay' + intImageNumber + '.src = strAddress';
        eval(strImageName);

    }   // End of imageLoadImage

    this.imageDownload20 = function (strProductCode, strProductCode360) {
        this.imageLoad(0, '../PublicImages/productimages/lowres/Image' + strProductCode + '-1.jpg');     // default
        this.imageLoad(1, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-1.jpg');
        this.imageLoad(2, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-3.jpg');
        this.imageLoad(3, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-5.jpg');
        this.imageLoad(4, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-7.jpg');
        this.imageLoad(5, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-9.jpg');
        this.imageLoad(6, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-11.jpg');
        this.imageLoad(7, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-13.jpg');
        this.imageLoad(8, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-15.jpg');
        this.imageLoad(9, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-17.jpg');
        this.imageLoad(10, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-19.jpg');
        this.imageLoad(11, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-21.jpg');
        this.imageLoad(12, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-23.jpg');
        this.imageLoad(13, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-25.jpg');
        this.imageLoad(14, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-27.jpg');
        this.imageLoad(15, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-29.jpg');
        this.imageLoad(16, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-31.jpg');
        this.imageLoad(17, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-33.jpg');
        this.imageLoad(18, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-35.jpg');
        this.imageLoad(19, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-37.jpg');
        this.imageLoad(20, '../PublicImages/productimages360/' + strProductCode360 + '/ImageLow-39.jpg');

    }

    this.imageIsLoaded = function (imgName) {
        var strEval = imgName + '.complete';
        if (!eval(strEval)) {
            return false;
        }
        if (strBrowser != 'IE') {
            var strEval = 'typeof ' + imgName + '.naturalWidth !=' + ' "undefined"' + ' && ' + imgName + '.naturalWidth';
            if (eval(strEval) == 0) {
                return false;
            }
        }
        return true;

    }   // End of imageIsLoaded

    this.imageLoadCount = function () {
        var i = 0;
        var intCounter = 0;
        for (i = 1; i <= 20; i++) {
            var imgName = 'imgDisplay' + i;
            if (this.imageIsLoaded(imgName) == true) { intCounter++ };
        }
        return intCounter;

    }   // End of imageLoadCount

    this.imageDisplay = function (intImageNumber) {
        var strImageName = 'imgDisplay' + intImageNumber + '.src';
        document[str360ObjName + 'imgDisplay'].src = eval(strImageName);

    }   // End of imageDisplay


    // * * * 360 Rotation * * *

    this.pauseOn = function () {
        intPauseTimer = 1;
    }   // End of pauseOn

    this.pauseOff = function () {
        intPauseTimer = 0;
    }   // End of pauseOff

    this.intSkipInitialRotateYes = function () {
        intSkipInitialRotate = 1;
    }   // End of intSkipInitialRotateYes 

    this.intSkipInitialRotateNo = function () {
        intSkipInitialRotate = 0;
    }   // End of intSkipInitialRotateNo

    this.intSkipInitialRotateForceAutoRotateYes = function () {
        intSkipInitialRotateForceAutoRotate = 1;
    }   // End of intSkipInitialRotateForceAutoRotateYes 

    this.intSkipInitialRotateForceAutoRotateNo = function () {
        intSkipInitialRotateForceAutoRotate = 0;
    }   // End of intSkipInitialRotateForceAutoRotateNo

    this.autoResetTimerClear = function () {
        intAutoResetTimer = 50;

    }   // End of autoResetTimerClear

    this.autoResetTimerTick = function () {
        if (intAutoResetTimer == 0) {
            return true;
        }

        intAutoResetTimer--;
        if (intAutoResetTimer == 0) {
            // Completed
            this.imageDisplay(0);
            intRotateStep = 9;
            this.barClearAll();
        }

    }   // End of autoResetTimerTick

    this.loadingTimeoutClear = function () {
        intLoadingTimeout = 0;
    }   // End of loadingTimeoutClear

    this.loadingTimeoutTick = function () {
        intLoadingTimeout++;
        if (intLoadingTimeout >= 250) {
            // Timedout
            alert('Timedout');
            intRotationMode = 0;    // Deleted
        }

    }   // End of loadingTimeoutTick

    this.rotateNextStep = function () {
        // Move to next step
        intRotateStep++;
        if (intRotateStep >= 21) {
            intRotateStep = 1;
        }
        // Change image
        this.imageDisplay(intRotateStep);

    }   // rotateNextStep

    this.rotateGetRotationMode = function () {
        return intRotationMode;
    }   //rotateGetRotationMode

    this.rotateOnOffSwitch = function () {
        if (intRotationMode == 4) {
            // Change to On
            intRotationMode = 5;
            return true;
        }

        if (intRotationMode == 5) {
            // Change to Off
            this.autoResetTimerClear();
            intRotationMode = 4;
            return false;
        }

    }   // End of rotateOnOffSwitch

    this.rotateOnSwitch = function () {
        // Change to On
        intRotationMode = 5;

        return true;

    }   // End of rotateOnSwitch

    this.rotateRollover = function (intImageNumber) {
        if (intRotationMode == 4) {
            if (intImageNumber >= 1) {
                this.imageDisplay(intImageNumber);
                this.barSelectItem(intImageNumber);
                this.autoResetTimerClear();
            }
        }
    }   // End of imageDisplayRollover

    this.rotateClick = function (intImageNumber) {
        if (intRotationMode == 3) {
            intRotationMode = 4;
            this.imageDisplay(intImageNumber);
            this.barSelectItem(intImageNumber);
            this.autoResetTimerClear();
            return true;
        }

        if (intRotationMode == 5) {
            intRotationMode = 4;
            this.imageDisplay(intImageNumber);
            this.barSelectItem(intImageNumber);
            this.autoResetTimerClear();
            return true;
        }

        return false;
    }   // End of rotateClick

    this.rotateTimerProcedure = function () {
        // Pause
        if (intPauseTimer == 1) { return true }

        // Modes        0 = Deleted
        //              1 = Startup Loading - place images into imgDisplay vars
        //              2 = Show Loading bar
        //              3 = Initial Rotation - From image 11 to image 10 via 20
        //              4 = Normal running - Waiting for auto reset
        //              5 = Auto rotate

        if (intComparator360Active == 1) {
            switch (intRotationMode) {
                case 0: // Do nothing
                    break;
                case 1: // Startup
                    if (this.productcodeImg360Get() == '0') { intRotationMode = 6; break; }
                    this.imageDownload20(this.productcodeImg1Get(), this.productcodeImg360Get());
                    this.loadingTimeoutClear();
                    intRotationMode = 2;
                    this.pauseOff();
                    break;

                case 2: // Loading bar
                    this.loadingTimeoutTick();
                    var imgCount = this.imageLoadCount();

                    if (imgCount == 20) {
                        // Completed
                        this.barClearAll();
                        intRotationMode = 3;
                        intRotateStep = 10;
                        document[str360ObjName + 'img360pauseplay'].src = imgRotationClickX.src;
                    }
                    else {
                        // Update bar
                        this.barSelectItems(imgCount);
                    }
                    break;

                case 3:
                    // Skip Inital rotate
                    if (intSkipInitialRotate == 1) {
                        // Skip
                        intRotationMode = 4;
                        intAutoResetTimer = 1;
                        intSkipInitialRotate = 0;

                        if (intSkipInitialRotateForceAutoRotate == 1) {
                            intSkipInitialRotateForceAutoRotate = 0;
                            intRotationMode = 5;
                        }
                    }
                    else {
                        // Initial rotation  - From image 11 to image 10 via 20
                        this.rotateNextStep();
                        this.barSelectItem(intRotateStep);
                        if (intRotateStep == 10) {
                            // Completed
                            intRotationMode = 4;
                            intAutoResetTimer = 50;
                            intSkipInitialRotate = 0;
                        }
                    }
                    break;
                case 4:
                    // Normal running
                    this.autoResetTimerTick();
                    break;

                case 5:
                    // Auto rotate
                    this.rotateNextStep();
                    this.barSelectItem(intRotateStep);
                    break;
                case 6:
                    // No 360 to rotate


                default: // Delete 360
                    break;

            }   // End of switch


        }   // End of if Comparator Active

        // Re run Timeout
        if (intRotationMode == 0) {
            return false;   // delete mode don't continue running code
        }
        else {
            return true;    // Continue code
        }

    }      // End of rotateTimerProcedure

    this.rotateTimerHandler = function () {
        if (this.rotateTimerProcedure() == true) {
            // Continue running code
            setTimeout(str360ObjHandlerName, 100);       // Must be set to a code object
        }

    }   // End of rotateTimerHandler

    this.rotateTimerHandlerStartup = function (strObjName, strObjHandlerName, strProductCode, strProductCode360) {
        str360ObjName = strObjName;
        str360ObjHandlerName = strObjHandlerName;
        this.productcodeImg1Set(strProductCode);
        this.productcodeImg360Set(strProductCode360);
        this.rotateTimerHandler();     // Launch timer

    }   // End of rotateTimerHandlerStartup

}   // End of ComparatorHander


// * * * XML Transfer * * * 
function xmlHandler() {
    var xmlhttp;
    // * * * Load XML documents from server * * *
    this.loadXMLdoc = function (url, strProcedure) {
        xmlhttp = null;

        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (xmlhttp != null) {
            eval('xmlhttp.onreadystatechange=' + strProcedure + ';');
            xmlhttp.open("GET", url, true);
            xmlhttp.send(null);
        }
        else {
            alert("Your browser does not support XMLHTTP.");
        }

    }   // End of loadXML

    this.stateChangeloadXMLDoc = function () {
        if (xmlhttp.readyState == 4) {
            // 4 = loaded
            if (xmlhttp.status == 200) {
                // 200 = OK
                // ...our code here...
                alert(xmlhttp.status);
                alert(xmlhttp.statusText);
                alert("[" + xmlhttp.responseText + "]");
            }
            else {
                //alert("Problem retrieving XML data");
            }
        }
    }   // End of stateChangeloadXMLDoc

    this.stateChangeloadXMLintoSlot = function () {
        if (xmlhttp.readyState == 4) {
            // 4 = loaded
            if (xmlhttp.status == 200) {
                // 200 OK
                var strHTML = xmlhttp.responseText;
                var strEval = strHTML.substring(0, strHTML.indexOf(':'));
                var strHTMLSpan = strHTML.substring(strHTML.indexOf(':') + 1, strHTML.length);
                //document.getElementById('Comparator360Slot1').innerHTML = strHTMLSpan;

                try {
                    eval(strEval);
                    if (booAProductHasBeenAddedToComparator == true) { PublicFunctionComparatorAutoOpenUpdateInitiate() };    // Force open / autoclose
                }
                catch (err) {
                    // Do Nothing
                }
                //document.getElementById('Comparator360Slot1').innerHTML = xmlhttp.responseText;
                //objSlot1.rotateTimerHandlerStartup('objSlot1','objSlot1.rotateTimerHandler()','6066');
            }
            else {
                //alert("Problem retrieving XML data");
            }
        }
    }   // End of stateChangeloadXMLintoSlot

    this.stateChangeloadXMLintoSlotOnPage = function () {
        if (xmlhttp.readyState == 4) {
            // 4 = loaded
            if (xmlhttp.status == 200) {
                // 200 OK
                var strHTML = xmlhttp.responseText;
                var strEval = strHTML.substring(0, strHTML.indexOf(':'));
                var strHTMLSpan = strHTML.substring(strHTML.indexOf(':') + 1, strHTML.length);
                //document.getElementById('Comparator360Slot1').innerHTML = strHTMLSpan;

                try {
                    eval(strEval);
                }
                catch (err) {
                    // Do Nothing
                }
                //document.getElementById('Comparator360Slot1').innerHTML = xmlhttp.responseText;
                //objSlot1.rotateTimerHandlerStartup('objSlot1','objSlot1.rotateTimerHandler()','6066');
            }
            else {
                //alert("Problem retrieving XML data");
            }
        }
    }    // End of stateChangeloadXMLintoSlot



}   // End of xmlHandler       


// * * *  Public Functions to initialise the comparator * * *
function LoadProductIntoSlotOnPage(strSlotName, strSlotObjName, strSlotObjXMLHandlerName, strProductCode, strRunInitialRotate, strProductCode360) {

    eval(strSlotObjName + '.intSkipInitialRotateYes()');
    eval(strSlotObjName + '.intSkipInitialRotateForceAutoRotateYes()');

    document.getElementById(strSlotName).innerHTML = '<img src="../purelyimages/comparatorloading.gif" />';
    var strRandom = '&postrandomizer=' + Math.random();
    var strEval = strSlotObjXMLHandlerName + '.loadXMLdoc("../HTML_Components_Includes/Comparator360xmlReceiver.aspx?fn=1&productcodeimg1=' + strProductCode + '&productcodeimg360=' + strProductCode360 + '&objname=' + strSlotObjName + '&spanname=' + strSlotName + '&displaydeletebutton=no' + strRandom + '","' + strSlotObjXMLHandlerName + '.stateChangeloadXMLintoSlotOnPage' + '");';
    eval(strEval);
}

function LoadProductIntoSlot(strSlot, strProductCode, strRunInitialRotate, strProductCode360) {
    if (strRunInitialRotate == 'no') {
        eval('objSlot' + strSlot + '.intSkipInitialRotateYes()');
    }
    else {
        var objCookie = new CookieHandler();
        objCookie.slotSetInitialRotate(strSlot, 'no');
        objCookie = null;
    }
    document.getElementById('Comparator360Slot' + strSlot).innerHTML = '<img src="../purelyimages/comparatorloading.gif" />';
    var strRandom = '&postrandomizer=' + Math.random();
    var strEval = 'objXMLdocSlot' + strSlot + '.loadXMLdoc("../HTML_Components_Includes/Comparator360xmlReceiver.aspx?fn=1&productcodeimg1=' + strProductCode + '&productcodeimg360=' + strProductCode360 + '&objname=objSlot' + strSlot + '&spanname=Comparator360Slot' + strSlot + strRandom + '","objXMLdocSlot' + strSlot + '.stateChangeloadXMLintoSlot' + '");';
    eval(strEval);
}

function PublicFunctionInitiateComparatorFromCookie() {
    var objCookie = new CookieHandler();

    if ('[' + objCookie.slotGetProductCode('1') + ']' != '[null]') { LoadProductIntoSlot('1', objCookie.slotGetProductCode('1'), objCookie.slotGetInitialRotate('1'), objCookie.slotGetProductCode360('1')) }
    if ('[' + objCookie.slotGetProductCode('2') + ']' != '[null]') { LoadProductIntoSlot('2', objCookie.slotGetProductCode('2'), objCookie.slotGetInitialRotate('2'), objCookie.slotGetProductCode360('2')) }
    if ('[' + objCookie.slotGetProductCode('3') + ']' != '[null]') { LoadProductIntoSlot('3', objCookie.slotGetProductCode('3'), objCookie.slotGetInitialRotate('3'), objCookie.slotGetProductCode360('3')) }
    if ('[' + objCookie.slotGetProductCode('4') + ']' != '[null]') { LoadProductIntoSlot('4', objCookie.slotGetProductCode('4'), objCookie.slotGetInitialRotate('4'), objCookie.slotGetProductCode360('4')) }
    if ('[' + objCookie.slotGetProductCode('5') + ']' != '[null]') { LoadProductIntoSlot('5', objCookie.slotGetProductCode('5'), objCookie.slotGetInitialRotate('5'), objCookie.slotGetProductCode360('5')) }
    if ('[' + objCookie.slotGetProductCode('6') + ']' != '[null]') { LoadProductIntoSlot('6', objCookie.slotGetProductCode('6'), objCookie.slotGetInitialRotate('6'), objCookie.slotGetProductCode360('6')) }

}   // End of PublicFunctionInitiateComparatorFromCookie

function PublicFunctionDeleteFromSlot(strProductCode) {
    var objCookie = new CookieHandler();
    var strProductSlot = objCookie.slotGetSlot(strProductCode);
    if (strProductSlot != '0') {
        eval('objSlot' + strProductSlot + '.deleteClick()');
        objCookie.slotRemoveProduct(strProductCode);
        document.getElementById('Comparator360Slot' + strProductSlot).innerHTML = '';
    }
}   // End of PublicFunctionDeleteFromSlot

function PublicFunctionAddProductToSlot(strProductCode, strProductCode360) {
    var objCookie = new CookieHandler();
    var strNextSlot = objCookie.slotGetFirstAvailable();
    var strFullReload = 'no';
    if (strNextSlot == '0') { strNextSlot = '6'; strFullReload = 'yes'; }
    if (objCookie.slotAddProduct('objSlot' + strNextSlot, strProductCode, strProductCode360) == true) {
        if (strFullReload == 'yes') {
            objSlot1.deleteClick();
            objSlot2.deleteClick();
            objSlot3.deleteClick();
            objSlot4.deleteClick();
            objSlot5.deleteClick();
            objSlot6.deleteClick();
            PublicFunctionInitiateComparatorFromCookie();
        }
        else {
            var strProductSlot = objCookie.slotGetSlot(strProductCode);
            if (strProductSlot != '0') {
                eval('objSlot' + strProductSlot + '.deleteClick()');
                LoadProductIntoSlot(strProductSlot, strProductCode, 'yes', strProductCode360);
            }
        }   // End of FullReload

        //PublicFunctionComparatorAutoOpenUpdateInitiate();    // Force open / autoclose  * * * RUN IN XML RECEIVER * * *
        booAProductHasBeenAddedToComparator = true;   // Force open / autoclose in XML receiver
        document.getElementById('fixme').style.visibility = 'visible';   //hidden / visible
        document.getElementById('DIVComparator').style.visibility = 'visible';   //hidden / visible 
        document.getElementById('DIVComparatorWideMode').style.visibility = strComparatorWideMode;   //hidden / visible
        RedDotComparatorStartFlight();  // Force Red Dot to fly
    }
}   // End of PublicFunctionAddProductToSlot

function PublicFunctionAddProductToSlotNoRedDot(strProductCode, strProductCode360) {
    var objCookie = new CookieHandler();
    var strNextSlot = objCookie.slotGetFirstAvailable();
    var strFullReload = 'no';
    if (strNextSlot == '0') { strNextSlot = '6'; strFullReload = 'yes'; }
    if (objCookie.slotAddProduct('objSlot' + strNextSlot, strProductCode, strProductCode360) == true) {
        if (strFullReload == 'yes') {
            objSlot1.deleteClick();
            objSlot2.deleteClick();
            objSlot3.deleteClick();
            objSlot4.deleteClick();
            objSlot5.deleteClick();
            objSlot6.deleteClick();
            PublicFunctionInitiateComparatorFromCookie();
        }
        else {
            var strProductSlot = objCookie.slotGetSlot(strProductCode);
            if (strProductSlot != '0') {
                eval('objSlot' + strProductSlot + '.deleteClick()');
                LoadProductIntoSlot(strProductSlot, strProductCode, 'no', strProductCode360);
            }
        }   // End of FullReload

        //PublicFunctionComparatorAutoOpenUpdateInitiate();    // Force open / autoclose  * * * RUN IN XML RECEIVER * * *
        booAProductHasBeenAddedToComparator = true;   // Force open / autoclose in XML receiver
        document.getElementById('fixme').style.visibility = 'visible';   //hidden / visible
        document.getElementById('DIVComparator').style.visibility = 'visible';   //hidden / visible 
        document.getElementById('DIVComparatorWideMode').style.visibility = strComparatorWideMode;   //hidden / visible
    }
}   // End of PublicFunctionAddProductToSlotNoRedDot        


// * * * Manage DIV footer section * * *
var intDivPercentageTarget = 0;
var intDivPercentageSizeOfSteps = 10;
var intDivPerventageYaxis = 0;

var booComparatorTitleClickState = false;

var booComparatorStopPopUpMode = false;

var strComparatorWideMode = 'collapse';
var lngComparatorPlacedAtEndOfPageY = 0;

var imgComparatorDown = new Image;
var imgComparatorDownClose = new Image;
var imgComparatorUp = new Image;
var imgComparatorUpHidden = new Image;

imgComparatorDown.src = '../purelyimages/comparatordown.gif';
imgComparatorDownClose.src = '../purelyimages/comparatordownclose.gif';
imgComparatorUp.src = '../purelyimages/comparatorup.gif';
imgComparatorUpHidden.src = '../purelyimages/1x1white.gif';

var intComparatorAutoOpenMode = 0;

function DivYaxis(intOffsetValuePercent) {
    // Fully displayed at a height 0px was -45px
    // Fully Hidden at a height of 355 was -310px
    var intHeight = -(intOffsetValuePercent * 2.65);
    document.getElementById('DIVComparator').style.marginTop = intHeight + 'px';
}   //DivYaxis

function DivTimerHandler() {
    if (booComparatorStopPopUpMode == true) { return true; } // Function disabled
    if (intDivPerventageYaxis == intDivPercentageTarget) { return true; }
    if (intDivPerventageYaxis > intDivPercentageTarget) { intDivPerventageYaxis -= intDivPercentageSizeOfSteps; DivYaxis(intDivPerventageYaxis); }
    if (intDivPerventageYaxis < intDivPercentageTarget) { intDivPerventageYaxis += intDivPercentageSizeOfSteps; DivYaxis(intDivPerventageYaxis); }

    // Continue running code
    setTimeout('DivTimerHandler()', 25);
    return false;
}   //DivTimerHandler

function PublicFunctionInitiateDivMotion(resetcounters) {
    if (resetcounters == true) {
        intDivPercentageTarget = 0;
        intDivPerventageYaxis = 0;
    }
    // Start timer
    setTimeout('DivTimerHandler()', 25);
}   //PublicFunctionDivStartup

function PublicFunctionDivYaxis(intOffsetValuePercent) {
    if (intDivPercentageTarget == 100) {
        ComparatorTitleCloseImage(1);
        ComparatorTitleCloseImage(4);
    }
    else {
        ComparatorTitleCloseImage(2);
        ComparatorTitleCloseImage(3);
    }

    intDivPercentageTarget = intOffsetValuePercent;
    PublicFunctionInitiateDivMotion(false)
}   //PublicFunctionDivYaxis

function PublicFunctionComparatorTitleClicked() {
    if (booComparatorTitleClickState == true) {
        PublicFunctionDivYaxis(0);
        booComparatorTitleClickState = false;
        intComparatorAutoOpenMode = 1;    // Force autoclose to end
    }
    else {
        PublicFunctionDivYaxis(100);
        booComparatorTitleClickState = true;
    }
}   //PublicFunctionComparatorTitleClicked

function PublicFunctionComparatorTitleRollover() {
    if (intDivPerventageYaxis == 0 && booComparatorTitleClickState == false) {
        PublicFunctionComparatorTitleClicked();
    }
}   //PublicFunctionComparatorTitleRollover

function ComparatorTitleCloseImage(intImageNumber) {
    switch (intImageNumber) {
        case 1:
            document.imgComparatorCloseBTN.src = imgComparatorDownClose.src;
            break;
        case 2:
            document.imgComparatorCloseBTN.src = imgComparatorDown.src;
            break;
        case 3:
            document.imgComparatorUpBTN.src = imgComparatorUpHidden.src;
            break;
        case 4:
            document.imgComparatorUpBTN.src = imgComparatorUp.src;
            break;
        default:
            document.imgComparatorCloseBTN.src = imgComparatorDownClose.src;
    }   //switch
    return true;
}   //ComparatorTitleCloseImage

function PublicFunctionComparatorShowInWideMode(booWide) {
    var strComparatorWide = '';
    if (booWide == true) {
        strComparatorWideMode = 'visible';
        strComparatorWide = '80%';
    }
    else {
        strComparatorWideMode = 'collapse';
        strComparatorWide = '100%';
    }
    document.getElementById('DIVComparatorWideMode').style.visibility = strComparatorWideMode;   //hidden / visible / collapse
    document.getElementById('DIVComparatorWideMode').style.width = strComparatorWide;
}   // PublicFunctionComparatorShowInWideMode

function PublicFunctionComparatorFindXoffset(TargetObjectName) {
    var intX = 0;
    var objTarget = document.getElementById(TargetObjectName);

    while (objTarget.offsetParent != null) {
        intX += objTarget.offsetLeft;
        objTarget = objTarget.offsetParent;
    }
    return intX;
}   //PublicFunctionComparatorFindXoffset

function PublicFunctionComparatorFindYoffset(TargetObjectName) {
    var intY = 0;
    var objTarget = document.getElementById(TargetObjectName);

    while (objTarget.offsetParent != null) {
        intY += objTarget.offsetTop;
        objTarget = objTarget.offsetParent;
    }
    return intY;
}   //PublicFunctionComparatorFindYoffset

function PublicFunctionComparatorFindDocumentHeight() {
    return Math.max(
                Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
                Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
                Math.max(document.body.clientHeight, document.documentElement.clientHeight)
            )
} //PublicFunctionComparatorFindDocumentHeight

function PublicFunctionComparatorPlaceAtEndOfDocument(booMakeSpaceAtEnd) {
    // iPod/iPad/iPhone
    // Place comparator at end of footer
    var lngOffsetFromEndOfPage = 320;    // Allow for <br />'s
    var lngEndOfDocument = PublicFunctionComparatorFindDocumentHeight();

    // Make Space at end of Document
    if (booMakeSpaceAtEnd == true) {
        try {
            document.getElementById('ComparatorLocateHereAtEndOfDocument').innerHTML = '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';
            document.imgComparatorUpBTN.src = imgComparatorUpHidden.src;
            booComparatorStopPopUpMode = true;    // Disable Popup Function
        }
        catch (err) {
            // Error continue
        }
    }

    lngComparatorPlacedAtEndOfPageY = lngEndOfDocument

    if (document.all) {
        document.getElementById('fixme').style.top = lngEndOfDocument - lngOffsetFromEndOfPage;
        document.getElementById('fixme').style.left = 0;
    }
    else {
        document.getElementById('fixme').style.top = (lngEndOfDocument - lngOffsetFromEndOfPage) + 'px';
        document.getElementById('fixme').style.left = 0 + 'px';
    }

    // Re-Run to see if the Document has grown after load.
    // Run from - PublicFunctionComparatorPlaceAtEndOfDocumentTimeout() 

}   //PublicFunctionComparatorPlaceAtEndOfDocument

function PublicFunctionComparatorPlaceAtEndOfDocumentTimeout() {
    var lngEndOfDocument = PublicFunctionComparatorFindDocumentHeight();

    if (lngComparatorPlacedAtEndOfPageY != lngEndOfDocument) {
        PublicFunctionComparatorPlaceAtEndOfDocument(false);
    }

    // Re-run every 2.5 seconds
    setTimeout('PublicFunctionComparatorPlaceAtEndOfDocumentTimeout()', 2500)
}   //PublicFunctionComparatorPlaceAtEndOfDocumentTimeout

function PublicFunctionComparatorTitleCloseClicked() {
    if (intDivPercentageTarget == 0) {
        document.getElementById('fixme').style.visibility = 'hidden';   //hidden / visible
        document.getElementById('DIVComparator').style.visibility = 'hidden';   //hidden / visible
        document.getElementById('DIVComparatorWideMode').style.visibility = 'collapse';   // retain existing state, but collapse.  will return in wxisting mode
    }
    else {
        PublicFunctionComparatorTitleClicked();
    }
}   //PublicFunctionComparatorTitleCloseClicked

function PublicFunctionComparatorTitleUpClicked() {
    PublicFunctionComparatorTitleClicked();
}   //PublicFunctionComparatorTitleCloseClicked

function ComparatorAutoOpenUpdate() {
    var booComparatorAutoOpenTrueFalse = false;

    switch (intComparatorAutoOpenMode) {
        case 0:
            // Open Mode
            // Do Nothing
            break;
        case 1:
            // Normal Running Mode
            // Do Nothing
            break;
        case 2:
            // Just Added New Product Mode
            // Apply to all six slots - Open Comparator, Once full rotation completed and image1 displayed close
            //intRotationMode
            try {
                // Normal running mode
                // Keep Open
                if (intDivPerventageYaxis == 0 && booComparatorTitleClickState == false) {
                    PublicFunctionComparatorTitleClicked();
                }
                // Comparator fully opened
                if (intDivPerventageYaxis != 100) { setTimeout('ComparatorAutoOpenUpdate()', 1000); return false; }
                // Comparator Open
                if (objSlot1.rotateGetRotationMode() == 3 || objSlot1.rotateGetRotationMode() == 2) { booComparatorAutoOpenTrueFalse = true; }
                if (objSlot2.rotateGetRotationMode() == 3 || objSlot2.rotateGetRotationMode() == 2) { booComparatorAutoOpenTrueFalse = true; }
                if (objSlot3.rotateGetRotationMode() == 3 || objSlot3.rotateGetRotationMode() == 2) { booComparatorAutoOpenTrueFalse = true; }
                if (objSlot4.rotateGetRotationMode() == 3 || objSlot4.rotateGetRotationMode() == 2) { booComparatorAutoOpenTrueFalse = true; }
                if (objSlot5.rotateGetRotationMode() == 3 || objSlot5.rotateGetRotationMode() == 2) { booComparatorAutoOpenTrueFalse = true; }
                if (objSlot6.rotateGetRotationMode() == 3 || objSlot6.rotateGetRotationMode() == 2) { booComparatorAutoOpenTrueFalse = true; }

                if (booComparatorAutoOpenTrueFalse == true) {
                    setTimeout('ComparatorAutoOpenUpdate()', 1000);
                }
                else {
                    // Close
                    PublicFunctionComparatorTitleClicked();
                    intComparatorAutoOpenMode = 1;
                }
            }
            catch (err) {
                // Do Nothing
            }
            break;
        default:

    }   //switch



}   //ComparatorAutoOpen

function PublicFunctionComparatorAutoOpenUpdateInitiate() {
    // Is it already open
    if (booComparatorTitleClickState == true) { return false; }

    if (intComparatorAutoOpenMode != 2) {
        intComparatorAutoOpenMode = 2;
        ComparatorAutoOpenUpdate();
    }

    return true;
}   //ComparatorAutoOpenUpdateInitalise

// * * * Manage DIV Arcing Red Dot * * *
var intPositionX = 0;
var intPositionY = 0;
var intCurrentStep = 0;
var intCurrentx = 0;
var intCurrenty = 0;
var intCompletedx = 0;
var intCompletedy = 0;
var dblVelocityy = 0;
var intFlightElipsxSteps = 1;
var booInFlight = false;

document.onmousemove = function (MouseEvent) {
    if (typeof MouseEvent == 'undefined') {
        theEvent = window.event;
    }
    else {
        theEvent = MouseEvent;
    }
    intPositionX = theEvent.clientX;
    intPositionY = theEvent.clientY;
}   //document.onmousemove

function RedDotSetXYinDoc(intxAxisDoc, intyAxisDoc) {
    if (document.all) {
        document.getElementById('DIVreddot').style.top = intyAxisDoc;
        document.getElementById('DIVreddot').style.left = intxAxisDoc;
    }
    else {
        document.getElementById('DIVreddot').style.top = intyAxisDoc + 'px';
        document.getElementById('DIVreddot').style.left = intxAxisDoc + 'px';
    }
}   //RedDotSetXY

function RedDotGetPageScrollOffsety() {
    if (document.all) {
        return document.documentElement.scrollTop;
    }
    else {
        return window.pageYOffset;
    }
}   //RedDotGetPageScrollOffset

function RedDotGetPageScrollOffsetx() {
    if (document.all) {
        return document.documentElement.scrollLeft;
    }
    else {
        return window.pageXOffset;
    }
}   //RedDotGetPageScrollOffsetx

function RedDotXYinWindow(intxAxisWindow, intyAxisWindow) {
    var xOffset = RedDotGetPageScrollOffsetx();
    var yOffset = RedDotGetPageScrollOffsety();
    RedDotSetXYinDoc(intxAxisWindow + xOffset, intyAxisWindow + yOffset);
}   //RedDotXYinWindow

function RedDotComparatorDIVx() {
    return document.documentElement.clientWidth;
}   //RedDotComparatorDIVx

function RedDotComparatorDIVy() {
    return document.documentElement.clientHeight;
}   //RedDotComparatorDIVy

function RedDotComparatorSlotx(intSlot) {
    var x = RedDotComparatorDIVx() / 2;
    var slotx = ((intSlot * 153) - 77) + (x - 480);
    return slotx;
}   //RedDotComparatorSlotx

function RedDotComparatorSloty(intSlot) {
    return RedDotComparatorDIVy() - 45;
}   //RedDotComparatorSloty        

function RedDotComparatorMousexinWindow() {
    return intPositionX;
}   //RedDotComparatorMousex

function RedDotComparatorMouseyinWindow() {
    return intPositionY;
}   //RedDotComparatorMousex        

function RedDotComparatorStartFlight() {
    var slotCookie = new CookieHandler();
    var strSlot = '0';
    try {
        strSlot = slotCookie.slotGetFirstAvailable();
    }
    catch (err) {
        // Do Nothing
    }
    if (strSlot == '0') { strSlot = '6' };
    var intSlot = parseInt(strSlot);
    var startx = RedDotComparatorMousexinWindow();
    var starty = RedDotComparatorMouseyinWindow();
    var endx = RedDotComparatorSlotx(intSlot);
    var endy = RedDotComparatorSloty(intSlot);
    slotCookie = null;

    // Has the Comparator been placed at the bottom of the page
    if (lngComparatorPlacedAtEndOfPageY > 0) {
        //alert('Added to Product Comparasons');
        self.scrollTo(0, PublicFunctionComparatorFindDocumentHeight());
        return true;
    }

    // start values
    intCurrentStep = 0;
    intCurrentx = startx;
    intCurrenty = starty;
    intFlightElipsxSteps = (endx - startx) / (55);
    intCompletedy = endy + 25;
    dblVelocityy = -10;

    RedDotComparatorVisibleDot();
    if (booInFlight != true) {
        RedDotCompatorFlightHandler();
    }

}   //RedDotComparatorStartFlight

function RedDotComparatorPathx(intDegrees, ingMultiplyer) {
    var dblResult = Math.sin(intDegrees / 57.295) * ingMultiplyer;
    return dblResult;
}   //RedDotComparatorPathx

function RedDotComparatorPathy(intDegrees, ingMultiplyer) {
    var dblResult = Math.cos(intDegrees / 57.295) * ingMultiplyer;
    return dblResult;
}   //RedDotComparatorPathy

function RedDotCompatorFlightHandler() {
    RedDotXYinWindow(intCurrentx, intCurrenty);

    intCurrenty += dblVelocityy;
    dblVelocityy += 1;
    intCurrentx += intFlightElipsxSteps;


    intCurrentStep++;
    if (intCurrentStep >= 100 || intCurrenty >= intCompletedy) {
        booInFlight = false;
        RedDotComparatorHideDot();
        return true;
    }
    else {
        booInFlight = true;
        setTimeout('RedDotCompatorFlightHandler()', 25);
        return false;
    }
}   //RedDotCompatorFlightHandler

function RedDotComparatorHideDot() {
    document.getElementById('DIVreddot').style.visibility = 'hidden';   //hidden / visible
}   //ReDotComparatorHideDot

function RedDotComparatorVisibleDot() {
    document.getElementById('DIVreddot').style.visibility = 'visible';   //hidden / visible
}   //ReDotComparatorVisibleDot        

// End hiding from old broswers -->

