﻿
first = 1;
last = 4;
current = 1;

function ObjectByID(ID) {
    if (typeof ID != 'string') return null;
    if (typeof document.getElementById != 'undefined') return document.getElementById(ID);
    if (typeof document.all != 'undefined') return document.all[ID];
    if (typeof document.layers != 'undefined') return document.layers[ID];
    return null;
}

function toggleSubMenu(ParentID) {
    var subMenu = ObjectByID(ParentID + "_submenu");
    if (!subMenu) return;
    subMenu.style.display = subMenu.style.display.toLowerCase() == "block" ? "none" : "block";
}

function ImageSwitcher() {
    $(".mpv_multiimg ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
    $(".mpv_multiimg ul li").click(function () {
        var imgAlt = $(this).find('img').attr("alt");
        var imgTitle = $(this).find('a').attr("href");  // Get Main Image Title
        var imgDesc = $(this).find('.block').html();
        var imgDescHeight = $(".mpv_mainimg").find('.block').height();
        var ZoomSrc = imgTitle.replace("Med", "Lrg");
        var NoZoom = $(this).find('a').attr("NoZoom");

        if ($(this).is(".active")) {
            return false;
        }
        else {
            if (!NoZoom) {
                $(".mpv_mainimg .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 50, function () {
                    $(".mpv_mainimg .block").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 50);
                    $(".mpv_mainimg img").attr({ src: imgTitle, alt: imgAlt, "data-zoomsrc": ZoomSrc });
                    MojoZoom.init();
                });
            }
        }

        if (!NoZoom) {
            $(".mpv_multiimg ul li").removeClass('active'); //Remove class of 'active' on all list-items
            $(this).addClass('active');  //Add class of 'active' on the selected list
        }
        return false;
    });
}

function bookmark_us() {
    if (window.sidebar) {
        window.sidebar.addPanel(document.title, this.location, "");
    }
    else {
        window.external.AddFavorite(this.location, document.title);
    }
}

function decQty() {
    var Qty;
    Qty = document.getElementById('ctl00_MainContent_txtQty').value;
    Qty--;

    if (Qty < 1)
        Qty = 1;

    document.getElementById('ctl00_MainContent_txtQty').value = Qty;
}

function incQty() {

    var Qty;
    Qty = document.getElementById('ctl00_MainContent_txtQty').value;
    Qty++;

    if (Qty < 1)
        Qty = 1;

    document.getElementById('ctl00_MainContent_txtQty').value = Qty;
}

function nextSlide() {
    // Hide current picture

    object.style.display = 'none';
    // Show next picture, if last, loop back to front
    if (current == last) { current = 1; }
    else { current++ }
    object = document.getElementById('slide' + current);
    object.style.display = 'block';
    DoSlide();
}

function First() {
    // Set Up Initial Checkbox
    if (document.getElementById("txtDynamicMasterLineCode")) {
        var Selected = (document.getElementById("txtDynamicMasterLineCode")).value

        document.getElementById('chkSizeCol' + Selected).checked = true;

        var thisBox = 'chkSizeCol' + Selected;

        if (document.getElementById('OrigPrice' + Selected)) {
            document.getElementById('OrigPrice' + Selected).style.display = 'block';
            document.getElementById('NewPrice' + Selected).style.display = 'block';
            document.getElementById('OfferText' + Selected).style.display = 'block';
        }

        ChangeProdCheckbox(Selected, thisBox)
    }

    // To Do - Set Up DualDD

}

// Switch Product Dual DD View

function ChangeProdDualDD() {

    var selCol = document.getElementById('cmbColourDD').value;
    var selSize = document.getElementById('cmbSizeDD').value;

    var ColAmount = document.getElementById("cmbColourDD").length
    var SizeAmount = document.getElementById("cmbSizeDD").length

    // Switch Stock, offers and price


    for (i = 0; i < ColAmount; i++) {
        var thisCol = document.getElementById('cmbColourDD').options[i].value;

        for (j = 0; j < SizeAmount; j++) {
            var thisSize = document.getElementById('cmbSizeDD').options[j].value;
            if (document.getElementById('stock_' + thisCol + "_" + thisSize)) {
                // Debug Code
                //alert("Size =" + thisSize + " Colour=" + thisCol)
                document.getElementById('stock_' + thisCol + "_" + thisSize).style.display = 'none';
                document.getElementById('prc_' + thisCol + "_" + thisSize).style.display = 'none';
                if (document.getElementById('OrigPrice' + thisCol + thisSize)) {
                    document.getElementById('OrigPrice' + thisCol + thisSize).style.display = 'none';
                    document.getElementById('NewPrice' + thisCol + thisSize).style.display = 'none';
                    document.getElementById('OfferText' + thisCol + thisSize).style.display = 'none';
                }
            }
        }
    }

    object = document.getElementById('stock_' + selCol + "_" + selSize);
    price = document.getElementById('prc_' + selCol + "_" + selSize);
    if (document.getElementById('OrigPrice' + selCol + selSize)) {
        document.getElementById('OrigPrice' + selCol + selSize).style.display = 'block';
        document.getElementById('NewPrice' + selCol + selSize).style.display = 'block';
        document.getElementById('OfferText' + selCol + selSize).style.display = 'block';
    }
    object.style.display = 'block';
    price.style.display = 'block';

    // Switch Image
    var MyImage = 'MainContent_myimage';

    var newsrc = document.getElementById("main_" + selCol + "_" + selSize).value;
    var nwZoomsrc = document.getElementById("zoom_" + selCol + "_" + selSize).value;

    document.getElementById(MyImage).src = newsrc;
    document.getElementById(MyImage).setAttribute("data-zoomsrc", nwZoomsrc);

    MojoZoom.init();
}

// Switch Product in chart view 
function ChangeProdCheckbox(linecode, boxid) {
    var box = document.getElementById(boxid).checked;
    var count = 0;
    if (box) {
        var sel = linecode;
        var MyImage = 'MainContent_myimage';

        // Change the Images
        var newsrc = document.getElementById("main" + sel).value;
        var nwZoomsrc = document.getElementById("zoom" + sel).value;

        document.getElementById(MyImage).src = newsrc;
        document.getElementById(MyImage).setAttribute("data-zoomsrc", nwZoomsrc);

        // Change the stock

        object = document.getElementById('stock' + sel);
        object.style.display = 'block';

        // Change The Offer
        if (document.getElementById('OrigPrice' + sel)) {
            document.getElementById('OrigPrice' + sel).style.display = 'block';
            document.getElementById('NewPrice' + sel).style.display = 'block';
            document.getElementById('OfferText' + sel).style.display = 'block';
        }
        // Ensure Only 1 box is ticked at a time
        var inputs = document.getElementsByTagName('*');
        var checkboxes = [];
        for (var i = 0; i < inputs.length; i++) {

            if (inputs[i].type == 'checkbox') {
                var thisItem = inputs[i].id;

                if (thisItem != boxid) {
                    var chkid = inputs[i].id;
                    var thisId = (chkid.substring(10));

                    document.getElementById('stock' + thisId).style.display = 'none';
                    if (document.getElementById('OrigPrice' + thisId)) {
                        document.getElementById('OrigPrice' + thisId).style.display = 'none';
                        document.getElementById('NewPrice' + thisId).style.display = 'none';
                        document.getElementById('OfferText' + thisId).style.display = 'none';
                    }
                    count++;
                }

                inputs[i].checked = false;

            }
        }


        document.getElementById(boxid).checked = true;


        if (count == 0) {
            var thisId = document.getElementById("txtDynamicMasterLineCode").value;
            if (thisId != linecode) {
                document.getElementById('stock' + thisId).style.display = 'none';
                if (document.getElementById("OrigPrice")) {
                    document.getElementById('OrigPrice' + thisId).style.display = 'none';
                    document.getElementById('NewPrice' + thisId).style.display = 'none';
                    document.getElementById('OfferText' + thisId).style.display = 'none';
                }
            }
            else {
                if (document.getElementById("OrigPrice" + thisId)) {
                    document.getElementById('OrigPrice' + thisId).style.display = 'block';
                    document.getElementById('NewPrice' + thisId).style.display = 'block';
                    document.getElementById('OfferText' + thisId).style.display = 'block';
                }
            }
        }

        MojoZoom.init();
    }
}

// Swithc Product using Dropdowns

function SwitchProduct() {
    var sel = document.getElementById('cmbSizeColDD').value;
    var Amount = document.getElementById("cmbSizeColDD").length

    // Switch Stock

    object = document.getElementById('stock' + sel);
    object.style.display = 'block';


    for (i = 0; i < Amount; i++) {
        thisSel = document.getElementById('cmbSizeColDD').options[i].value;

        if (thisSel == sel) {
            // Do Nothing
        }
        else {
            document.getElementById('stock' + thisSel).style.display = 'none';
        }
    }

    // Switch Offers
    for (i = 0; i < Amount; i++) {
        thisOffer = document.getElementById('cmbSizeColDD').options[i].value;

        if (thisOffer == sel) {
            if (document.getElementById('OrigPrice' + sel)) {
                document.getElementById('OrigPrice' + sel).style.display = 'block';
                document.getElementById('NewPrice' + sel).style.display = 'block';
                document.getElementById('OfferText' + sel).style.display = 'block';
            }
        }
        else {

            if (document.getElementById('OrigPrice' + thisOffer)) {
                document.getElementById('OrigPrice' + thisOffer).style.display = 'none';
                document.getElementById('NewPrice' + thisOffer).style.display = 'none';
                document.getElementById('OfferText' + thisOffer).style.display = 'none';
            }
        }
    }

    // Switch Image
    var MyImage = 'MainContent_myimage';

    var newsrc = document.getElementById("main" + sel).value;
    var nwZoomsrc = document.getElementById("zoom" + sel).value;

    document.getElementById(MyImage).src = newsrc;
    document.getElementById(MyImage).setAttribute("data-zoomsrc", nwZoomsrc);

    MojoZoom.init();
}



/*
* MojoZoom 0.1.4 - JavaScript Image Zoom
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
* Licensed under the MPL License [http://www.nihilogic.dk/licenses/mpl-license.txt]
*/
/*
var MojoZoom = (function () {

var $ = function (id) { return document.getElementById(id); };
var dc = function (tag) { return document.createElement(tag); };

var defaultWidth = 256;
var defaultHeight = 256;

function addEvent(element, ev, handler) {
var doHandler = function (e) {
return handler(e || window.event);
}
if (element.addEventListener) {
element.addEventListener(ev, doHandler, false);
} else if (element.attachEvent) {
element.attachEvent("on" + ev, doHandler);
}
}

function getElementPos(element) {
var x = element.offsetLeft;
var y = element.offsetTop;
var parent = element.offsetParent;
while (parent) {
x += parent.offsetLeft;
y += parent.offsetTop;
parent = parent.offsetParent;
}
return {
x: x,
y: y
}
}

function getEventMousePos(element, e) {
var scrollX = document.body.scrollLeft || document.documentElement.scrollLeft;
var scrollY = document.body.scrollTop || document.documentElement.scrollTop;

if (e.currentTarget) {
var pos = getElementPos(element);
return {
x: e.clientX - pos.x + scrollX,
y: e.clientY - pos.y + scrollY
}
}
return {
x: e.offsetX,
y: e.offsetY
}
}

function makeZoomable(img, zoomSrc, zoomImgCtr, zoomWidth, zoomHeight, alwaysShow) {
// make sure the image is loaded, if not then add an onload event and return
if (!img.complete && !img.__mojoZoomQueued) {
addEvent(img, "load", function () {
img.__mojoZoomQueued = true;
setTimeout(function () {
makeZoomable(img, zoomSrc, zoomImgCtr, zoomWidth, zoomHeight, alwaysShow);
}, 1);
});
return;
}

img.__mojoZoomQueued = false;

// Wrap everything in a timeout.
// this fixes a problem where, if makeZoomable is called a second time after changing the src,
// FF would not have figured out the new offsetHeight of the image yet. A small timeout helps though it's rather hackish.
setTimeout(function () {

// sorry
var isIE = !!document.all && !!window.attachEvent && !window.opera;

var w = img.offsetWidth;
var h = img.offsetHeight;

var oldParent = img.parentNode;
if (oldParent.nodeName != "A") {
var linkParent = dc("a");
linkParent.setAttribute("href", zoomSrc);
linkParent.setAttribute("target", "_blank");
oldParent.replaceChild(linkParent, img);
linkParent.appendChild(img);
} else {
var linkParent = oldParent;
}

linkParent.style.position = "relative";
linkParent.style.display = "block";
linkParent.style.width = w + "px";
linkParent.style.height = h + "px";

var imgLeft = img.offsetLeft;
var imgTop = img.offsetTop;

var zoom = dc("div");
zoom.className = "mojozoom_marker";

var zoomImg = dc("img");
zoomImg.className = "mojozoom_img";

zoomImg.style.position = "absolute";
zoomImg.style.left = "-9999px";
zoomImg.style.top = "-9999px";

document.body.appendChild(zoomImg);

var parent = img.parentNode;

var ctr = dc("div");
with (ctr.style) {
position = "absolute";
left = imgLeft + "px";
top = imgTop + "px";
width = w + "px";
height = h + "px";
overflow = "hidden";
display = "none";
}

ctr.appendChild(zoom);
parent.appendChild(ctr);

var zoomInput = parent;

// clear old overlay
if (img.__mojoZoomOverlay)
parent.removeChild(img.__mojoZoomOverlay);
img.__mojoZoomOverlay = ctr;

// clear old high-res image
if (img.__mojoZoomImage && img.__mojoZoomImage.parentNode)
img.__mojoZoomImage.parentNode.removeChild(img.__mojoZoomImage);
img.__mojoZoomImage = zoomImg;

var useDefaultCtr = false;
if (!zoomImgCtr) {
zoomImgCtr = dc("div");
zoomImgCtr.className = "mojozoom_imgctr";

var imgPos = getElementPos(img);
zoomImgCtr.style.left = w + imgPos.x + "px";
zoomImgCtr.style.top = imgPos.y + "px";

zoomImgCtr.style.width = (zoomWidth ? zoomWidth : defaultWidth) + "px";
zoomImgCtr.style.height = (zoomHeight ? zoomHeight : defaultHeight) + "px";

document.body.appendChild(zoomImgCtr);
useDefaultCtr = true;
}
zoomImgCtr.style.overflow = "hidden";

if (!alwaysShow) {
zoomImgCtr.style.visibility = "hidden";
}

addEvent(zoomImg, "load", function () {

// bail out if img has been removed from dom
if (!zoomImg.parentNode) return;

var zoomWidth = zoomImg.offsetWidth;
var zoomHeight = zoomImg.offsetHeight;

var ctrWidth = zoomImgCtr.offsetWidth;
var ctrHeight = zoomImgCtr.offsetHeight;

var ratioW = zoomWidth / w;
var ratioH = zoomHeight / h;

var markerWidth = Math.round(ctrWidth / ratioW);
var markerHeight = Math.round(ctrHeight / ratioH);

document.body.removeChild(zoomImg);
zoomImgCtr.appendChild(zoomImg);

var zoomFill = dc("div");
zoomFill.className = "mojozoom_fill";
zoom.appendChild(zoomFill);

var zoomBorder = dc("div");
zoomBorder.className = "mojozoom_border";
zoom.appendChild(zoomBorder);

zoom.style.width = markerWidth + "px";
zoom.style.height = markerHeight + "px";


if (alwaysShow) {
zoom.style.left = "0px";
zoom.style.top = "0px";

zoomImg.style.left = "0px";
zoomImg.style.top = "0px";
}

var isInImage = false;

if (!alwaysShow) {
addEvent(zoomInput, "mouseout",
function (e) {
var target = e.target || e.srcElement;
if (!target) return;
if (target.nodeName != "DIV") return;
var relTarget = e.relatedTarget || e.toElement;
if (!relTarget) return;
while (relTarget != target && relTarget.nodeName != "BODY" && relTarget.parentNode) {
relTarget = relTarget.parentNode;
}
if (relTarget != target) {
isInImage = false;
ctr.style.display = "none";
zoomImgCtr.style.visibility = "hidden";
}
}
);
// a bit of a hack, mouseout is sometimes not caught if moving mouse really fast
addEvent(document.body, "mouseover",
function (e) {
if (isInImage && !(e.toElement == zoomBorder || e.target == zoomBorder)) {
ctr.style.display = "none";
zoomImgCtr.style.visibility = "hidden";
isInImage = false;
}
}
);
}

addEvent(zoomInput, "mousemove",
function (e) {
isInImage = true;

var imgPos = getElementPos(img);

if (useDefaultCtr) {
zoomImgCtr.style.left = w + imgPos.x + "px";
zoomImgCtr.style.top = imgPos.y + "px";
}
ctr.style.display = "block";
zoomImgCtr.style.visibility = "visible";

var pos = getEventMousePos(zoomInput, e);
if (e.srcElement && isIE) {
if (e.srcElement == zoom) return;
if (e.srcElement != zoomInput) {
var zoomImgPos = getElementPos(e.srcElement);
pos.x -= (imgPos.x - zoomImgPos.x);
pos.y -= (imgPos.y - zoomImgPos.y);
}
}
var x = markerWidth / 2;
var y = markerHeight / 2;

if (!isIE) {
pos.x -= imgLeft;
pos.y -= imgTop;
}

if (pos.x < x) pos.x = x;
if (pos.x > w - x) pos.x = w - x;
if (pos.y < y) pos.y = y;
if (pos.y > h - y) pos.y = h - y;

var left = ((pos.x - x) | 0);
var top = ((pos.y - y) | 0);

zoom.style.left = left + "px";
zoom.style.top = top + "px";

zoomImg.style.left = -((pos.x * ratioW - ctrWidth / 2) | 0) + "px";
zoomImg.style.top = -((pos.y * ratioH - ctrHeight / 2) | 0) + "px";
}
);
});

// I've no idea. Simply setting the src will make IE screw it self into a 100% CPU fest. In a timeout, it's ok.
setTimeout(function () {
zoomImg.src = zoomSrc;
}, 1);

}, 1);
}

function init() {
var images = document.getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
var img = images[i];
var zoomSrc = img.getAttribute("data-zoomsrc");
if (zoomSrc) {
makeZoomable(img, zoomSrc, document.getElementById(img.getAttribute("id") + "_zoom"), null, null, img.getAttribute("data-zoomalwaysshow") == "true");
}
}
}

return {
addEvent: addEvent,
init: init,
makeZoomable: makeZoomable
};

})();

MojoZoom.addEvent(window, "load", MojoZoom.init);
*/
function clickclear(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}
function clickrecall(thisfield, defaulttext) {
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}

function clickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

function stopRKey(evt) {
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type == "text")) { return false; }
}

function dotimer(thisbutton) {
    thisbutton.value = "Searching";
    thisbutton.style.textDecoration = 'blink';
}

function checkentry(textbox, brandbox, thisbutton)  // HELEN & PHIL 010211 - note original copy of function below
{
    var text = document.getElementById(textbox).value;

    var brand = 0;
    if (brandbox != null)
        brand = document.getElementById(brandbox).selectedIndex;

    if ((text == "Enter Keyword(s)" || text == "" || text == null) && brand == 0) {
        alert("Search Error - You have not entered any search criteria  \n\n Search using a single Keyword: \n If you want to Search for a product description or content contained in a page enter all or part of a keyword and click \"Search\". \n\n Search using multiple Keywords: \n If you want to Search for a product description or content contained in a page enter both keywords seperated by a space and click \"Search\". \n\n Search using specific keywords: \n If you want to Search for two specific keywords enter the keywords wrapped in \"\" and click \"Search\".");
        return false;
    }
    else {
        dotimer(thisbutton);
        return true;
    }
}

/* Craig's original checkentry function below:
function checkentry(textbox, thisbutton)
{

var text = document.getElementById(textbox).value;

alert(text);

if (text == "Enter Keyword(s)" || text == "" || text == null) {
alert("Search Error - You have not entered any search criteria  \n\n Search using a single Keyword: \n If you want to Search for a product description or content contained in a page enter all or part of a keyword and click \"Search\". \n\n Search using multiple Keywords: \n If you want to Search for a product description or content contained in a page enter both keywords seperated by a space and click \"Search\". \n\n Search using specific keywords: \n If you want to Search for two specific keywords enter the keywords wrapped in \"\" and click \"Search\".");
return false;
}
else {
dotimer(thisbutton);
return true;
}

}*/

var imgHeight;
var imgWidth;

function findHHandWW() {

    imgWidth = this.width;
    imgHeight = this.height;

    //alert("1 " + imgHeight);

    return true;
}

function showImage(imgPath) {
    var myImage = new Image();
    myImage.name = imgPath;
    myImage.onload = findHHandWW;
    myImage.src = imgPath;
}


function switchMultiImage(var1, var2) {

    var Img1 = document.getElementById('ctl00_MainContent_' + var1);
    var MainImg = document.getElementById('ctl00_MainContent_' + var2);

    var Img1Src = Img1.src;
    var MainImgSrc = MainImg.src;


    var NewMainImgSrc = Img1Src.replace("Sml", "Med");
    var NewImg1Src = MainImgSrc.replace("Med", "Sml");
    var NewZoomSrc = Img1Src.replace("Sml", "Lrg");

    MainImg.src = NewMainImgSrc;
    Img1.src = NewImg1Src;

    document.getElementById('ctl00_MainContent_' + var2).setAttribute("data-zoomsrc", NewZoomSrc);

    // Measure new thumbnail
    showImage(NewImg1Src);
    showImage(NewImg1Src);

    // Adjust Padding For New Thumbnail

    var paddingV = (120 - imgHeight) / 2;
    var paddingH = (120 - imgWidth) / 2;

    document.getElementById('ctl00_MainContent_' + var1).style.paddingRight = paddingH + "px";
    document.getElementById('ctl00_MainContent_' + var1).style.paddingLeft = paddingH + "px";
    document.getElementById('ctl00_MainContent_' + var1).style.paddingTop = paddingV + "px";
    document.getElementById('ctl00_MainContent_' + var1).style.paddingBottom = paddingV + "px";

    MojoZoom.init();
}

/*
* MojoZoom 0.1.6 - JavaScript Image Zoom
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
* Licensed under the MPL License [http://www.nihilogic.dk/licenses/mpl-license.txt]
*/

var MojoZoom = (function () {

    var $ = function (id) { return document.getElementById(id); };
    var dc = function (tag) { return document.createElement(tag); };

    var defaultWidth = 256;
    var defaultHeight = 256;

    function addEvent(element, ev, handler) {
        var doHandler = function (e) {
            return handler(e || window.event);
        }
        if (element.addEventListener) {
            element.addEventListener(ev, doHandler, false);
        } else if (element.attachEvent) {
            element.attachEvent("on" + ev, doHandler);
        }
    }

    function getElementPos(element) {
        var x = element.offsetLeft;
        var y = element.offsetTop;
        var parent = element.offsetParent;
        while (parent) {
            x += parent.offsetLeft - parent.scrollLeft;
            y += parent.offsetTop - parent.scrollTop;
            parent = parent.offsetParent;
        }
        return {
            x: x,
            y: y
        }
    }

    function getEventMousePos(element, e) {
        var scrollX = document.body.scrollLeft || document.documentElement.scrollLeft;
        var scrollY = document.body.scrollTop || document.documentElement.scrollTop;

        if (e.currentTarget) {
            var pos = getElementPos(element);
            return {
                x: e.clientX - pos.x + scrollX,
                y: e.clientY - pos.y + scrollY
            }
        }
        return {
            x: e.offsetX,
            y: e.offsetY
        }
    }

    function makeZoomable(img, zoomSrc, zoomImgCtr, zoomWidth, zoomHeight, alwaysShow) {
        // get the shadow div
        var divZoomShadow = $("divZoomShadow");

        // make sure the image is loaded, if not then add an onload event and return
        if (!img.complete && !img.__mojoZoomQueued) {
            addEvent(img, "load", function () {
                img.__mojoZoomQueued = true;
                setTimeout(function () {
                    makeZoomable(img, zoomSrc, zoomImgCtr, zoomWidth, zoomHeight, alwaysShow);
                }, 1);
            });
            return;
        }

        img.__mojoZoomQueued = false;

        // Wrap everything in a timeout.
        // this fixes a problem where, if makeZoomable is called a second time after changing the src,
        // FF would not have figured out the new offsetHeight of the image yet. A small timeout helps though it's rather hackish.
        setTimeout(function () {

            // sorry
            var isIE = !!document.all && !!window.attachEvent && !window.opera;

            var w = img.offsetWidth;
            var h = img.offsetHeight;

            var oldParent = img.parentNode;
            if (oldParent.nodeName != "A") {
                var linkParent = dc("a");
                linkParent.setAttribute("href", zoomSrc);
                linkParent.setAttribute("target", "_blank");
                oldParent.replaceChild(linkParent, img);
                linkParent.appendChild(img);
            } else {
                var linkParent = oldParent;
                linkParent.setAttribute("href", zoomSrc);
            }

            linkParent.style.position = "relative";
            linkParent.style.display = "block";
            linkParent.style.width = w + "px";
            linkParent.style.height = h + "px";

            var imgLeft = img.offsetLeft;
            var imgTop = img.offsetTop;

            var zoom = dc("div");
            zoom.className = "mojozoom_marker";

            var zoomImg = dc("img");
            zoomImg.className = "mojozoom_img";

            zoomImg.style.position = "absolute";
            zoomImg.style.left = "-9999px";
            zoomImg.style.top = "-9999px";

            zoomImg.style.maxWidth = "none";
            zoomImg.style.maxHeight = "none";
            zoomImg.style.zIndex = 10000001;


            document.body.appendChild(zoomImg);

            var parent = img.parentNode;

            var ctr = dc("div");
            ctr.style.position = "absolute";
            ctr.style.left = imgLeft + "px";
            ctr.style.top = imgTop + "px";
            ctr.style.width = w + "px";
            ctr.style.height = h + "px";
            ctr.style.overflow = "hidden";
            ctr.style.display = "none";

            ctr.appendChild(zoom);
            parent.appendChild(ctr);

            var zoomInput = parent;

            // clear old overlay
            if (img.__mojoZoomOverlay)
                parent.removeChild(img.__mojoZoomOverlay);
            img.__mojoZoomOverlay = ctr;

            // clear old high-res image
            if (img.__mojoZoomImage && img.__mojoZoomImage.parentNode)
                img.__mojoZoomImage.parentNode.removeChild(img.__mojoZoomImage);
            img.__mojoZoomImage = zoomImg;

            var useDefaultCtr = false;
            if (!zoomImgCtr) {
                zoomImgCtr = dc("div");
                zoomImgCtr.className = "mojozoom_imgctr";

                var imgPos = getElementPos(img);
                zoomImgCtr.style.left = w + imgPos.x + "px";
                zoomImgCtr.style.top = imgPos.y + "px";

                zoomImgCtr.style.width = (zoomWidth ? zoomWidth : defaultWidth) + "px";
                zoomImgCtr.style.height = (zoomHeight ? zoomHeight : defaultHeight) + "px";

                document.body.appendChild(zoomImgCtr);
                useDefaultCtr = true;
            }
            zoomImgCtr.style.overflow = "hidden";

            if (!alwaysShow) {
                zoomImgCtr.style.visibility = "hidden";
                if (divZoomShadow) divZoomShadow.style.visibility = "hidden";
            }

            addEvent(zoomImg, "load", function () {

                // bail out if img has been removed from dom
                if (!zoomImg.parentNode) return;

                var zoomWidth = zoomImg.offsetWidth ? zoomImg.offsetWidth : zoomImg.naturalWidth;
                var zoomHeight = zoomImg.offsetHeight ? zoomImg.offsetHeight : zoomImg.naturalHeight;

                var ctrWidth = zoomImgCtr.offsetWidth;
                var ctrHeight = zoomImgCtr.offsetHeight;

                var ratioW = zoomWidth / w;
                var ratioH = zoomHeight / h;

                var markerWidth = Math.round(ctrWidth / ratioW);
                var markerHeight = Math.round(ctrHeight / ratioH);

                document.body.removeChild(zoomImg);
                zoomImgCtr.appendChild(zoomImg);

                var zoomFill = dc("div");
                zoomFill.className = "mojozoom_fill";
                zoom.appendChild(zoomFill);

                var zoomBorder = dc("div");
                zoomBorder.className = "mojozoom_border";
                zoom.appendChild(zoomBorder);

                zoom.style.width = markerWidth + "px";
                zoom.style.height = markerHeight + "px";


                if (alwaysShow) {
                    zoom.style.left = "0px";
                    zoom.style.top = "0px";

                    zoomImg.style.left = "0px";
                    zoomImg.style.top = "0px";
                }

                var isInImage = false;

                if (!alwaysShow) {
                    addEvent(zoomInput, "mouseout",
					function (e) {
					    var target = e.target || e.srcElement;
					    if (!target) return;
					    if (target.nodeName != "DIV") return;
					    var relTarget = e.relatedTarget || e.toElement;
					    if (!relTarget) return;
					    while (relTarget != target && relTarget.nodeName != "BODY" && relTarget.parentNode) {
					        relTarget = relTarget.parentNode;
					    }
					    if (relTarget != target) {
					        isInImage = false;
					        ctr.style.display = "none";
					        zoomImgCtr.style.visibility = "hidden";
					        if (divZoomShadow) divZoomShadow.style.visibility = "hidden";
					    }
					}
				);
                    // a bit of a hack, mouseout is sometimes not caught if moving mouse really fast
                    addEvent(document.body, "mouseover",
					function (e) {
					    if (isInImage && !(e.toElement == zoomBorder || e.target == zoomBorder)) {
					        ctr.style.display = "none";
					        zoomImgCtr.style.visibility = "hidden";
					        if (divZoomShadow) divZoomShadow.style.visibility = "hidden";
					        isInImage = false;
					    }
					}
				);
                }

                addEvent(zoomInput, "mousemove",
				function (e) {
				    isInImage = true;

				    var imgPos = getElementPos(img);

				    if (useDefaultCtr) {
				        zoomImgCtr.style.left = w + imgPos.x + "px";
				        zoomImgCtr.style.top = imgPos.y + "px";
				    }
				    ctr.style.display = "block";
				    zoomImgCtr.style.visibility = "visible";

				    if (divZoomShadow) divZoomShadow.style.visibility = "visible";

				    var pos = getEventMousePos(zoomInput, e);
				    if (e.srcElement && isIE) {
				        if (e.srcElement == zoom) return;
				        if (e.srcElement != zoomInput) {
				            var zoomImgPos = getElementPos(e.srcElement);
				            pos.x -= (imgPos.x - zoomImgPos.x);
				            pos.y -= (imgPos.y - zoomImgPos.y);
				        }
				    }
				    var x = markerWidth / 2;
				    var y = markerHeight / 2;

				    if (!isIE) {
				        pos.x -= imgLeft;
				        pos.y -= imgTop;
				    }

				    if (pos.x < x) pos.x = x;
				    if (pos.x > w - x - 2) pos.x = w - x - 2;
				    if (pos.y < y) pos.y = y;
				    if (pos.y > h - y - 2) pos.y = h - y - 2;

				    var left = ((pos.x - x) | 0);
				    var top = ((pos.y - y) | 0);

				    zoom.style.left = left + "px";
				    zoom.style.top = top + "px";

				    zoomImg.style.left = -((pos.x * ratioW - ctrWidth / 2) | 0) + "px";
				    zoomImg.style.top = -((pos.y * ratioH - ctrHeight / 2) | 0) + "px";
				}
			);
            });

            // I've no idea. Simply setting the src will make IE screw it self into a 100% CPU fest. In a timeout, it's ok.
            setTimeout(function () {
                zoomImg.src = zoomSrc;
            }, 1);

        }, 1);
    }

    function init() {
        var images = document.getElementsByTagName("img");
        for (var i = 0; i < images.length; i++) {
            var img = images[i];
            var zoomSrc = img.getAttribute("data-zoomsrc");
            if (zoomSrc) {
                makeZoomable(img, zoomSrc, document.getElementById(img.getAttribute("id") + "_zoom"), null, null, img.getAttribute("data-zoomalwaysshow") == "true");
            }
        }
    }

    return {
        addEvent: addEvent,
        init: init,
        makeZoomable: makeZoomable
    };

})();

MojoZoom.addEvent(window, "load", MojoZoom.init);

function validateEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test(email);
}

function forgottenPassword(EmailID) {
    var email = $("#" + EmailID).val();

    if (!validateEmail(email)) {
        alert("Please enter a valid email address.");
        return;
    }

    location.href = "ForgottenPassword.aspx?email=" + email;
}

var panels = new Array('t1', 't2', 't3', 't4', 't5', 't6', 't7');
var selectedTab = null;

function showPanel(tab, name) {
    initialiseTabs();
    var ID = "#" + name.replace("t", "ctl00_MainContent_txtlnk");
    $(ID).removeClass("panel_tab");
    $(ID).addClass("panel_tab_active");

    for (i = 0; i < panels.length; i++) {
        if (document.getElementById(panels[i])) {
            document.getElementById(panels[i]).style.display = (name == panels[i]) ? 'block' : 'none';
        }
    }
    return false;
}

function initialiseTabs(selectFirst) {
    for (var i = 0; i < panels.length; i++) {
        var ID = "#" + panels[i].replace("t", "ctl00_MainContent_txtlnk")
        if ($(ID)) {
            $(ID).removeAttr("style");
            $(ID).removeClass("tab");
            $(ID).removeClass("panel_tab_active");
            if (i == 0 && selectFirst) {
                $(ID).addClass("panel_tab_active");
            } else {
                $(ID).addClass("panel_tab");
            }
        }
    }
}

$(document).ready(function () {
    initialiseTabs(true);
});
