/* -------------------------- Event Handling Code ----------------------------------*/

function showBubbleHelp(e) {
    var el;
    if (window.event && window.event.srcElement) {
        el = window.event.srcElement;
    } else if (e && e.target) {
        el = e.target;
    } else return false;
    if (el.id=='cardsizebtn1linesonetwo' ||
        el.id=='cardsizebtn1linesthree' ||
        el.id=='cardsizebtn1linesfour') {
        document.getElementById('cardsizebtn1bubble').style.display='block';
    } else if (el.id=='cardsizebtn2linesonetwo' ||
        el.id=='cardsizebtn2linesthree' ||
        el.id=='cardsizebtn2linesfour') {
        document.getElementById('cardsizebtn2bubble').style.display='block';
    } else if (el.id=='cardsizebtn3linesonetwo' ||
        el.id=='cardsizebtn3linesthree' ||
        el.id=='cardsizebtn3linesfour') {
        document.getElementById('cardsizebtn3bubble').style.display='block';
    } else {
        document.getElementById(el.id+'bubble').style.display='block';
    }
}
function hideBubbleHelp(e) {
    var el;

    if (window.event && window.event.srcElement) {
        el = window.event.srcElement;
    } else if (e && e.target) {
        el = e.target;
    } else return false;
    if (el.id=='cardsizebtn1linesonetwo' ||
        el.id=='cardsizebtn1linesthree' ||
        el.id=='cardsizebtn1linesfour') {
        document.getElementById('cardsizebtn1bubble').style.display='none';
    } else if (el.id=='cardsizebtn2linesonetwo' ||
        el.id=='cardsizebtn2linesthree' ||
        el.id=='cardsizebtn2linesfour') {
        document.getElementById('cardsizebtn2bubble').style.display='none';
    } else if (el.id=='cardsizebtn3linesonetwo' ||
        el.id=='cardsizebtn3linesthree' ||
        el.id=='cardsizebtn3linesfour') {
        document.getElementById('cardsizebtn3bubble').style.display='none';
    } else {
        document.getElementById(el.id+'bubble').style.display='none';
    }
}

/*
    Note Developers: we need one function for each button because we cannot (at this stage) reliably get the
    elementId of the event element object... and we cannot pass in a variable into the
    addEvent function because that would actually call the function, not reference it.
    Drop me a line at dcodotto@mindwire.com.au for more info if needed.
*/

var cardSizeBtnSelected;
function setButtonSml() {
    document.getElementById('cardsizebtn1').className = 'btncardsizesmlselected';
    document.getElementById('cardsizebtn2').className = 'btncardsizemed';
    document.getElementById('cardsizebtn3').className = 'btncardsizelrg';
    cardSizeBtnSelected = 'cardsizebtn1';
    //alert('Backend Boys: Clicking this button sets\nthe JavaScript variable cardSizeBtnSelected to "'+cardSizeBtnSelected+'".\nPlease remove this alert box once you have completed coding.');
}
function setButtonMed() {
    document.getElementById('cardsizebtn1').className = 'btncardsizesml';
    document.getElementById('cardsizebtn2').className = 'btncardsizemedselected';
    document.getElementById('cardsizebtn3').className = 'btncardsizelrg';
    cardSizeBtnSelected = 'cardsizebtn2';
    //alert('Backend Boys: Clicking this button sets\nthe JavaScript variable cardSizeBtnSelected to "'+cardSizeBtnSelected+'".\nPlease remove this alert box once you have completed coding.');
}
function setButtonLrg() {
    document.getElementById('cardsizebtn1').className = 'btncardsizesml';
    document.getElementById('cardsizebtn2').className = 'btncardsizemed';
    document.getElementById('cardsizebtn3').className = 'btncardsizelrgselected';
    cardSizeBtnSelected = 'cardsizebtn3';
    //alert('Backend Boys: Clicking this button sets\nthe JavaScript variable cardSizeBtnSelected to "'+cardSizeBtnSelected+'".\nPlease remove this alert box once you have completed coding.');
}
function mouseOverCardSizeBtn(e) {
    var el;
    //Cross browser code to get target object.
    if (window.event && window.event.srcElement) {
        el = window.event.srcElement;
    } else if (e && e.target) {
        el = e.target;
    } else return false;
    el.style.backgroundPosition = '0px -121px';
}
function mouseOutCardSizeBtn(e) {
    var el;
    //Cross browser code to get target object.
    if (window.event && window.event.srcElement) {
        el = window.event.srcElement;
    } else if (e && e.target) {
        el = e.target;
    } else return false;
    if (el.id != cardSizeBtnSelected) { //Do not un-highlight the button if it is the button the user has clicked on (i.e. user has selected it).
        el.style.backgroundPosition = '0px 0px';
    }
}


function addEvent(elm, evType, fn, useCapture)
//Cross Browser Add-Event function.
{
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    } else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    } else {
        elm['on' + evType] = fn;
    }
}

/* --------------------------- End of Event Handling Code ---------------------------- */



function incrementQty(e) {
    if (e.value!='99999') e.value++;
}
function decrementQty(e) {
    if (e.value!='0') {
        e.value--;
    }
}




function getPageHeight() {
    var x,y;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    {
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
    }
    else // Explorer Mac;
         //would also work in Explorer 6 Strict, Mozilla and Safari
    {
        x = document.body.offsetWidth;
        y = document.body.offsetHeight;
    }
    return y;
}


function getOffsetLeft (el) {
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null)
        ol += el.offsetLeft;
    return ol;
}
function getOffsetTop (el) {
    var ot = el.offsetTop;
    while((el = el.offsetParent) != null)
        ot += el.offsetTop;
    return ot;
}

function adjustLayout(pageKey) {
    var bottomRightCornerId = "br";
    //Set this function up based on the page we are adjsuting the layout for.
    if (pageKey == "p1.1") {
        bottomRightCornerId="brd";
    }

    //Get the crucial values.
    var topBorderPosition = getOffsetTop(document.getElementById("scrollpane"));
    var leftBorderPosition = getOffsetLeft(document.getElementById("scrollpane"));
    var bottomBorderPosition = getOffsetTop(document.getElementById("scrollpane")) + document.getElementById("fixedareatd").offsetHeight - 15;
    var rightBorderPosition = document.getElementById("fixedareatd").offsetWidth + getOffsetLeft(document.getElementById("fixedareatd")) - 17;
    var pageHeight = getPageHeight();

    //Set the position of the scroll panes top rounded corner.
    document.getElementById("tl").style.top = topBorderPosition+"px";
    document.getElementById("tl").style.left = leftBorderPosition+"px";

    //Set the position of the scroll panes bottom rounded corner.
    document.getElementById("bl").style.top = bottomBorderPosition+"px";
    document.getElementById("bl").style.left = leftBorderPosition+"px";

    //Set the position of the fixed area bottom rounded corner.
    document.getElementById(bottomRightCornerId).style.top = bottomBorderPosition+"px";
    document.getElementById(bottomRightCornerId).style.left = rightBorderPosition+"px";

    //Set the position of the fixed area top corner.
    document.getElementById("tr").style.top = topBorderPosition+"px";
    document.getElementById("tr").style.left = rightBorderPosition+"px";

    //Set the height of the scroll pane to equal that of the fixed pane (which no doubt will grow vertically).
    document.getElementById("scrollpane").style.height=document.getElementById("fixedareatd").offsetHeight+"px";
}

var g_clicked = false;

function protectedClick( theButton, theForm )
{
    theButton.disabled = true;
    if (g_clicked) {
        return;
    }
    g_clicked = true;

    theForm.submit();
}
