/* Get the parent element/node of the child control
*/
function getParentElement(child) {
    if (child.parentElement != undefined)
        return child.parentElement;
    if (child.parentNode != undefined)
        return child.parentNode;
    return null;
}

/* Allow only numbers to be entered into a field
*/
function numbersOnly(e) {
    var keynum;
    var keychar;
    var numcheck;

    if (window.event) // IE
        keynum = e.keyCode;
    else if (e.which) // Netscape/Firefox/Opera
        keynum = e.which;

    if (keynum == 8 || keynum == undefined)
        return true;

    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;

    return numcheck.test(keychar);
}

/* Allow only numbers and decimal to be entered into a field
*/
function numbersAndDecimalOnly(e) {
    var keynum;
    var keychar;
    var numcheck;

    if (window.event) {// IE
        keynum = e.keyCode;
    }
    else if (e.which) {// Netscape/Firefox/Opera
        keynum = e.which;
    }

    if (keynum == 8 || keynum == undefined)
        return true;

    keychar = String.fromCharCode(keynum);
    numcheck = /\d|\./;
    return numcheck.test(keychar);
}

function selectMainItem(productID, recordID, listID) {
    var list = document.getElementById(listID);
    var record = document.getElementById(recordID);
    var elements = null;

    if (list == null) {
        elements = document.body.getElementsByTagName('TR');
    }
    else {
        elements = list.getElementsByTagName('TR');
    }

    for (var i = 0; i < elements.length; i++) {
        if (elements[i].id.indexOf('_MainProductID_', 0) > 0) {
            if (elements[i].id.endsWith(productID)) {
                elements[i].className = 'wizardStep2Selected';

                if (recordID.endsWith('S2')) {
                    var cb = elements[i].getElementsByTagName('INPUT');
                    cb[0].checked = true;
                }
            }
            else
                elements[i].className = 'wizardStep2NotSelected';
        }
    }
    if (record != null)
        record.value = productID;

    __doPostBack(recordID.replace('_', '$'), '');
}

function markItemComplete(productID, checked) {
    var elements = null;

    if (document.all)
        elements = document.all;
    else
        elements = document.body.getElementsByTagName('TR');

    for (var i = 0; i < elements.length; i++) {
        if (elements[i].id.indexOf('_MainProductID_', 0) > 0) {
            if (elements[i].id.endsWith(productID)) {
                for (var x = 0; x < elements[i].getElementsByTagName('INPUT').length; x++) {
                    if (elements[i].getElementsByTagName('INPUT')[x].type == 'checkbox') {
                        elements[i].getElementsByTagName('INPUT')[x].checked = (checked == 1);
                    }
                }
            }
        }
    }
}

function checkItem(ctrlID, state) {
    var element = document.getElementById(ctrlID);

    if (element == null) {
        alert("Unable to find element");
        return;
    }

    element.checked = (state == 1);
}

function editSubItemInformation(ctrl, mainProductID, subProductID) {
    var feedback = document.getElementById('ctl00_contentFrame_orderWizard_subProductOption');
    var val = '';

    if (feedback == null) {
        alert('Unable to pass back information');
        return;
    }

    if (ctrl.value != null)
        val = ctrl.value + ':' + mainProductID + ':' + subProductID;
    else
        val = ctrl.checked ? '1' : '0' + ':' + mainProductID + ':' + subProductID;

    if (val != feedback.value) {
        feedback.value = val;
        __doPostBack('ctl00$contentFrame$orderWizard$subProductOption', '');
    }
}

function submittedImages() {
    window.location = "uploaded.aspx";
}

function setValue(ctrlID, value) {
    if (document.getElementById(ctrlID) == null) {
        return;
    }

    if (document.getElementById(ctrlID).value != undefined)
        document.getElementById(ctrlID).value = value;
    else if (document.getElementById(ctrlID).innerHTML != undefined)
        document.getElementById(ctrlID).innerHTML = value;
}

function linkTemplate(currentSelID, templateID, templateDescription, feedbackControlID, linkSuffixText, pageNumber, multiPage) {
    var currentSel = document.getElementById(currentSelID).value;
    var feedback = document.getElementById(feedbackControlID);
    var links = document.getElementsByName('linkInfoFor' + currentSel + linkSuffixText);
    var link = null;

    if (links[0] != null)
        link = links[0];
    else {
        links = document.getElementsByTagName('DIV');

        for (var x = 0; x < links.length && link == null; x++) {
            if (links[x].getAttribute('name') == 'linkInfoFor' + currentSel + linkSuffixText) {
                link = links[x];
            }
        }
    }

    if (link != null) {
        /*if (pageNumber == 0) {
        link.innerHTML = templateDescription;
        link.className = 'pageTemplate';
        feedback.value = currentSel + ':' + templateID + ":" + pageNumber;
        }
        else*/
        if (pageNumber >= 0) {
            link.innerHTML = templateDescription + ' - p' + (pageNumber + 1);
            link.className = 'pageTemplate';
            feedback.value = currentSel + ':' + templateID + ":" + (pageNumber + 1);
        }
        else {
            if (multiPage == 1 && pageNumber < 0) {
                if (!confirm("You are about to link multiple pages to the configurable content\r\nThis will mean Page 1 will link to the selected content, Page 2 to the next configurable content for this order item and so on.\r\nIs this what you want?"))
                    return false;
            }

            var row = link.parentNode;
            while (row != null && row.tagName != 'TR')
                row = row.parentNode;

            var tbl = row.parentNode;
            while (tbl != null && tbl.tagName != 'TABLE' && tbl.tagName != 'TBODY')
                tbl = tbl.parentNode;

            var found = false;
            var pages = 0;
            var feedbackIDs = "m:" + templateID;
            for (var child = 0; child < tbl.childNodes.length && -pageNumber > pages; child++) {
                if (!found && tbl.childNodes[child] == row) {
                    found = true;
                }

                if (found) {
                    var currentRow = null;

                    for (; child < tbl.childNodes.length && currentRow == null; child++) {

                        if (tbl.childNodes[child].tagName != undefined && tbl.childNodes[child].tagName == 'TR') {
                            currentRow = tbl.childNodes[child];
                        }
                    }
                    if (currentRow != null)
                        child--;
                    else
                        break;

                    var currentCell = null;

                    for (var childCell = 0; childCell < currentRow.childNodes.length && currentCell == null; childCell++) {

                        if (currentRow.childNodes[childCell].tagName != undefined && currentRow.childNodes[childCell].tagName == 'TD') {
                            currentCell = currentRow.childNodes[childCell];
                        }
                    }

                    if (currentCell == null)
                        break;

                    var d = null;

                    for (var childDiv = 0; childDiv < currentCell.childNodes.length && d == null; childDiv++) {
                        if (currentCell.childNodes[childDiv].tagName != undefined && currentCell.childNodes[childDiv].tagName == 'DIV') {
                            d = currentCell.childNodes[childDiv];
                        }
                    }

                    if (d == null)
                        break;

                    d.innerHTML = templateDescription + ' - p' + (++pages);
                    d.className = 'pageTemplate';

                    feedbackIDs += ':linkForItem' + currentCell.id + ':' + pages;
                }
            }
            //            alert('Feedback: ' + feedbackIDs);
            feedback.value = feedbackIDs;
        }
        __doPostBack(feedbackControlID.replace('_', '$'), '');
        __doPostBack('ctl00$leftInformationContainer$orderSummaryPanel', '');
    }
    else
        alert('Unable to link the template\r\nPlease select a page to link the template to.');
    return false;
}

/* Display the correct page
*/
function displayStep(newStep) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById('ctl00_contentFrame_step1') != null) document.getElementById('ctl00_contentFrame_step1').className = newStep == 1 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step2') != null) document.getElementById('ctl00_contentFrame_step2').className = newStep == 2 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step3') != null) document.getElementById('ctl00_contentFrame_step3').className = newStep == 3 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step4') != null) document.getElementById('ctl00_contentFrame_step4').className = newStep == 4 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step5') != null) document.getElementById('ctl00_contentFrame_step5').className = newStep == 5 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step6') != null) document.getElementById('ctl00_contentFrame_step6').className = newStep == 6 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step7') != null) document.getElementById('ctl00_contentFrame_step7').className = newStep == 7 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step8') != null) document.getElementById('ctl00_contentFrame_step8').className = newStep == 8 ? 'stepVisible' : 'stepHidden';
        if (document.getElementById('ctl00_contentFrame_step9') != null) document.getElementById('ctl00_contentFrame_step9').className = newStep == 9 ? 'stepVisible' : 'stepHidden';

        if (document.getElementById('ctl00_contentFrame_pleaseWaitPanel') != null) document.getElementById('ctl00_contentFrame_pleaseWaitPanel').className = 'stepHidden';
    }
    /*else {
    if (document.layers) { // Netscape 4 
    document.ctl00_contentFrame_step1.visibility = newStep == 1 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step2.visibility = newStep == 2 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step3.visibility = newStep == 3 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step4.visibility = newStep == 4 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step5.visibility = newStep == 5 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step6.visibility = newStep == 6 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step7.visibility = newStep == 7 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step8.visibility = newStep == 8 ? 'visible' : 'hidden';
    document.ctl00_contentFrame_step9.visibility = newStep == 9 ? 'visible' : 'hidden';
    }
    else { // IE 4 
    document.all.ctl00_contentFrame_step1.style.visibility = newStep == 1 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step2.style.visibility = newStep == 2 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step3.style.visibility = newStep == 3 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step4.style.visibility = newStep == 4 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step5.style.visibility = newStep == 5 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step6.style.visibility = newStep == 6 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step7.style.visibility = newStep == 7 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step8.style.visibility = newStep == 8 ? 'visible' : 'hidden';
    document.all.ctl00_contentFrame_step9.style.visibility = newStep == 9 ? 'visible' : 'hidden';
    }
    }*/
}

function orderMainItem(productLinkButton) {
    var repeaterPanel = getParentElement(productLinkButton);
    var inputs = repeaterPanel.getElementsByTagName('INPUT');
    var hiddenControl = document.getElementById('ctl00_contentFrame_itemToOrder');

    if (hiddenControl == null) {
        alert('Unable to add item to order');
        return false;
    }

    hiddenControl.value = inputs[0].value;
    __doPostBack('ctl00$contentFrame$itemToOrder', '');
    return false;
}

/*----------------------------------------------
Function: changeMainItem()
Purpose: The customer description or quantity has
been changed so feed the information back to the server
----------------------------------------------*/
function changeMainItem(valueChanged) {
    var repeaterPanel = valueChanged.o_Ih;

    while (repeaterPanel != null && repeaterPanel.tagName != 'TABLE') {
        repeaterPanel = getParentElement(repeaterPanel);
    }

    if (repeaterPanel == null) {
        alert('Unable to modify order');
        return false;
    }

    repeaterPanel = getParentElement(repeaterPanel);

    var inputs = repeaterPanel.getElementsByTagName('INPUT');

    var hiddenControl = document.getElementById('ctl00_contentFrame_itemToModify');

    if (hiddenControl == null) {
        alert('Unable to modify order');
        return false;
    }

    var newValue = inputs[0].value + ':' + valueChanged.ID + ':' + valueChanged.value();

    if (hiddenControl.value != newValue) {
        hiddenControl.value = newValue;
        __doPostBack('ctl00$contentFrame$itemToModify', '');
    }

    __doPostBack('ctl00$leftInformationContainer$orderSummaryPanel', '');

    return false;
}

/*----------------------------------------------
Function: watermarkFocus()
Purpose: Remove a watermark image from a 
text field when focussed
----------------------------------------------*/
function watermarkFocus(element, defaultText) {
    if (element.value == defaultText) {
        element.className = "normal";
        element.value = "";
    }
}

/*----------------------------------------------
Function: watermarkBlur()
Purpose: Restore a watermark image to a 
text field when focus is lost and the
text is in it's default state
----------------------------------------------*/
function watermarkBlur(element, defaultText, watermarkStyle) {
    var textValue = element.value;

    if (textValue == defaultText || textValue.length == 0) {
        element.className = watermarkStyle;
        element.value = defaultText;
    }
    else
        element.className = "normal";

    changeMainItem(element);
}

/*
* Take input from new text field to pass to original function to process qty change on new order page
*/
function changeSupportItemQty(sender) {
    var repeaterPanel;

    if (sender.o_Ih != null)
        repeaterPanel = document.getElementById(sender.o_Ih.id);
    else
        repeaterPanel = document.getElementById(sender.ID);

    while (repeaterPanel != null && repeaterPanel.tagName != 'TR')
        repeaterPanel = getParentElement(repeaterPanel);

    if (repeaterPanel == null) {
        alert("Unable to update order");
        return;
    }

    var inputs = repeaterPanel.getElementsByTagName('INPUT');
    var vals = inputs[0].value.split('|');

    changeSupportItem(inputs[1], vals[0], vals[1], vals[2], vals[3]);
}

/*
* Process a qty change against a support product on the new order page
*/
function changeSupportItem(valueChanged, productID, mainProductID, imageID, labelID) {
    // hide the price label
    document.getElementById(labelID).style.visibility = 'hidden';
    document.getElementById(labelID).style.width = '0px';
    // show the animated waiting 
    document.getElementById(imageID).style.visibility = 'visible';
    document.getElementById(imageID).style.width = 'auto';

    //get the details for the change
    var qty = 0;

    if (valueChanged.value) {
        if (valueChanged.value > 0)
            qty = valueChanged.value;
        else if (valueChanged.checked != undefined)
            qty = valueChanged.checked ? 1 : 0;
    }

    // pass the information to the web service to be processed
    services.pageServices.EditSubItem(mainProductID, productID, qty, imageID, labelID, editSubItemSuccess, editSubItemFailure);
}

/*
* Changed the qty of the support product so display the new price
*/
function editSubItemSuccess(e) {
    var img = document.getElementById(e.ImageID);
    var lbl = document.getElementById(e.PanelID);

    // Hide the animated graphic
    img.style.visibility = 'hidden';
    img.style.width = '0px';

    // show the price label
    lbl.style.visibility = 'visible';
    lbl.style.width = '100%';
    lbl.innerHTML = e.Price;

    __doPostBack('ctl00$leftInformationContainer$orderSummaryPanel', '');
}

function editSubItemFailure(e) {
    alert("An error has occurred while trying to update the product configuration\r\n" + e.get_message());
}

function selectListItem(listItem, recordToID, productID, elementName, checkBox, tagName, nonSelStyle, selStyle, forceStyle) {
    if (document.getElementById(recordToID) == null)
        return;

    var recordTo = document.getElementById(recordToID);

    if (recordTo.value == productID && forceStyle != true)
        return;

    var selectedStyle = selStyle;
    var nonSelectedStyle = nonSelStyle;

    if (selectedStyle == null || selectedStyle == undefined) {
        selectedStyle = 'accordionHeaderSel';
    }
    if (nonSelectedStyle == null || nonSelectedStyle == undefined) {
        nonSelectedStyle = 'accordionHeaderNonSel';
    }

    if (listItem != null) {
        if (checkBox) {
            var cb = listItem.getElementsByTagName('INPUT');
            if (cb[1] != null) {
                if (cb[1].type == 'checkbox')
                    cb[1].checked = true;
            }
        }

        var lookForTag = tagName;

        if (lookForTag == null || lookForTag == undefined)
            lookForTag = 'TR';

        var containers = document.getElementsByTagName(lookForTag);

        for (var container = 0; container < containers.length; container++) {
            // Could use getElementsByName, but this is bug ridden in IE8 - this method works.
            if (containers[container].getAttribute('name') == elementName)
                containers[container].className = nonSelectedStyle;
        }

        listItem.className = selectedStyle;
    }
    recordTo.value = productID;
    //    alert(recordToID.replace('_', '$'), '');
    __doPostBack(recordToID.replace('_', '$'), '');
}

function selectSubListItem(listItem, recordToID, productID, elementName, parentControl, nonSelStyle, selStyle) {
    var recordTo = document.getElementById(recordToID);
    var parent = document.getElementById(parentControl);

    if (recordTo.value == productID)
        return;

    var containers = document.getElementsByTagName('TR');

    for (var container = 0; container < containers.length; container++) {
        if (containers[container].getAttribute('name') == elementName)
            containers[container].className = nonSelStyle;
    }

    if (listItem != null)
        listItem.className = selStyle;

    recordTo.value = productID;

    __doPostBack(recordToID.replace('_', '$'), '');
}

function selectSchool() {
    var school = document.getElementById('ctl00_contentFrame_billingName').value;
    var summaryField = document.getElementById('ctl00_contentFrame_summaryBillingName');

    if (school.length <= 0) {
        alert('Please enter a billing name');
        return false;
    }

    summaryField.innerText = school;
    $find('schoolDialog').hide();

    return false;
}

//function showAddressDialog(billingAddress) {

//    var billingDialog = addressDialog;

//    if (billingDialog == null) {
//        billingDialog = $find('addressDialog');
//    }

//    if (billingDialog == null) {
//        alert('failed to find dialog');
//        return;
//    }

//    document.getElementById('ctl00_contentFrame_addressDialog_addressType').value = billingAddress ? 'billing' : 'delivery';

//    var addressInfo = null;

//    if (billingAddress)
//        addressInfo = document.getElementById('ctl00_contentFrame_billingAddressInfo');
//    else
//        addressInfo = document.getElementById('ctl00_contentFrame_deliveryAddressInfo');

//    if (addressInfo == null)
//        return;

//    if (addressInfo.value == null || addressInfo.value.length == 0) {
//        document.getElementById('ctl00_contentFrame_addressDialog_billingAddress1').value = "";
//        document.getElementById('ctl00_contentFrame_addressDialog_billingAddress2').value = "";
//        document.getElementById('ctl00_contentFrame_addressDialog_billingTown').value = "";
//        document.getElementById('ctl00_contentFrame_addressDialog_billingCounty').value = "";
//        document.getElementById('ctl00_contentFrame_addressDialog_billingPostcode').value = "";
//    }
//    else {
//        var addressLines = addressInfo.value.split('|', 999);

//        document.getElementById('ctl00_contentFrame_addressDialog_billingAddress1').value = addressLines[0];
//        document.getElementById('ctl00_contentFrame_addressDialog_billingAddress2').value = addressLines[1];
//        document.getElementById('ctl00_contentFrame_addressDialog_billingTown').value = addressLines[2];
//        document.getElementById('ctl00_contentFrame_addressDialog_billingCounty').value = addressLines[3];
//        document.getElementById('ctl00_contentFrame_addressDialog_billingPostcode').value = addressLines[4];
//    }

//    billingDialog.Open();
//}

//function cancelAddress() {
//    var billingDialog = addressDialog;

//    if (billingDialog == null) {
//        billingDialog = $find('addressDialog');
//    }

//    if (billingDialog == null) {
//        alert('failed to find dialog');
//        return;
//    }
//    billingDialog.Close();
//}
//function selectAddress() {
//    var address1 = document.getElementById('ctl00_contentFrame_addressDialog_billingAddress1').value;
//    var address2 = document.getElementById('ctl00_contentFrame_addressDialog_billingAddress2').value;
//    var town = document.getElementById('ctl00_contentFrame_addressDialog_billingTown').value;
//    var county = document.getElementById('ctl00_contentFrame_addressDialog_billingCounty').value;
//    var postcode = document.getElementById('ctl00_contentFrame_addressDialog_billingPostcode').value;

//    if (address1 == null || address1.length == 0) {
//        alert('Please enter an address');
//        return false;
//    }

//    if (town == null || town.length == 0) {
//        alert('Please enter a town');
//        return false;
//    }

//    if (county == null || county.length == 0) {
//        alert('Please enter a county');
//        return false;
//    }

//    if (postcode == null || postcode.length < 6) {
//        alert('Please enter a postcode');
//        return false;
//    }

//    var billingAddress = (document.getElementById('ctl00_contentFrame_addressDialog_addressType').value == 'billing');
//    var addressInfo = null;
//    var summaryInfo = null;

//    if (billingAddress) {
//        addressInfo = document.getElementById('ctl00_contentFrame_billingAddressInfo');
//        summaryInfo = document.getElementById('ctl00_contentFrame_summaryBillingAddress');
//    }
//    else {
//        addressInfo = document.getElementById('ctl00_contentFrame_deliveryAddressInfo');
//        summaryInfo = document.getElementById('ctl00_contentFrame_summaryDeliveryAddress');
//    }

//    if (addressInfo == null)
//        return;

//    addressInfo.value = address1 + '|' + address2 + '|' + town + '|' + county + '|' + postcode.toUpperCase();
//    summaryInfo.innerHTML = address1 + '<br />' + (address2.length > 0 ? (address2 + '<br />') : '') + town + '<br />' + county + '<br />' + postcode.toUpperCase();

//    var billingDialog = addressDialog;

//    if (billingDialog == null) {
//        billingDialog = $find('addressDialog');
//    }

//    if (billingDialog == null) {
//        alert('failed to find dialog');
//        return;
//    }
//    billingDialog.Close();
//}


function OnAsyncFailure(result) {
    alert('Failure: ' + result.get_message());
}

function refreshCrest(imageClientID) {
    var img = document.getElementById(imageClientID);
    if (img != null) {
        if (img.src != document.URL) {
            img.click();
        }
    }
}


function AppLoad() {
    if (Sys != null && Sys != undefined) {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
    }
}

function EndRequest(sender, args) {
    // Check to see if there's an error on this request.
    if (args.get_error != undefined) {
        if (args.get_error() != null) {
            alert("An error has occurred: " + args.get_error());
            //            args.set_errorHandled(true);
        }
    }
}

function dragEnd() {
    // get the 'before diary' list
    var ul = document.getElementById('pageSortList');
    var sequenceInfo = '';
    var sendFeedback = false;

    var lis = ul.getElementsByTagName('LI');
    var pos = 0;

    for (pos = 0; pos < lis.length; pos++) {
        // Get the inputs - the first element is the page information to be passed back to the server
        var inputs = lis[pos].getElementsByTagName('INPUT');

        if (inputs != null && inputs.length > 0) {
            // seperate the pages with a :
            if (sequenceInfo.length > 0)
                sequenceInfo += ':';

            sequenceInfo += lis[pos].getElementsByTagName('INPUT')[0].value;
        }
    }

    // check if the second list is present
    if (document.getElementById('pageSortList2') != null) {

        // this is the new order page - build the information for the After Diary section
        // add D to the list to seperate the before and after list
        if (sequenceInfo.length > 0)
            sequenceInfo += ':D';
        else
            sequenceInfo += 'D';

        // get the 'after diary'
        ul = document.getElementById('pageSortList2');
        lis = ul.getElementsByTagName('LI');
        pos = 0;

        for (pos = 0; pos < lis.length; pos++) {

            var inputs = lis[pos].getElementsByTagName('INPUT');

            if (inputs != null && inputs.length > 0) {
                if (sequenceInfo.length > 0)
                    sequenceInfo += ':';
                sequenceInfo += lis[pos].getElementsByTagName('INPUT')[0].value;
            }
        }
    }

    // get the feedback control
    var feedback = document.getElementById('ctl00_contentFrame_sequenceInformation');

    // look for an alternative feedback control (admin page)
    if (feedback == null) {
        feedback = document.getElementById('ctl00_ctl00_contentFrame_content_sequenceInformation');
        sendFeedback = true;
    }

    if (feedback != null) {
        feedback.value = sequenceInfo;
        if (sendFeedback)
            __doPostBack(feedback.name, '');
    }
    else
        alert('Unable to record sequence information');
}

function dragStart() {
}

function moveItemPastDiary(sender) {
    var li = sender.parentNode;
    var afterDiary = document.getElementById('pageSortList2');

    while (li != null && li.tagName != 'LI')
        li = li.parentNode;

    if (li == null || afterDiary == null) {
        return false;
    }

    var ul = li.parentNode;

    ul.removeChild(li);
    afterDiary.insertBefore(li, afterDiary.firstChild);

    dragEnd();

    sender.style.visibility = "hidden";
    sender.style.height = "0px";
    document.getElementById(sender.id.replace('movePastDiary', 'moveBeforeDiary')).style.visibility = "visible";
    document.getElementById(sender.id.replace('movePastDiary', 'moveBeforeDiary')).style.height = "16px";

    return false;
}

function moveItemBeforeDiary(sender) {
    var li = sender.parentNode;
    var beforeDiary = document.getElementById('pageSortList');

    while (li != null && li.tagName != 'LI')
        li = li.parentNode;

    if (li == null || beforeDiary == null) {
        return false;
    }

    var ul = li.parentNode;

    ul.removeChild(li);
    beforeDiary.appendChild(li);

    dragEnd();

    sender.style.visibility = "hidden";
    sender.style.height = "0px";
    document.getElementById(sender.id.replace('moveBeforeDiary', 'movePastDiary')).style.visibility = "visible";
    document.getElementById(sender.id.replace('moveBeforeDiary', 'movePastDiary')).style.height = "16px";

    return false;
}

function moveItemToStart(sender) {
    var li = sender.parentNode;

    while (li != null && li.tagName != 'LI')
        li = li.parentNode;

    if (li == null) {
        return;
    }

    var ul = li.parentNode;
    ul.removeChild(li);
    ul.insertBefore(li, ul.firstChild);

    dragEnd();
}

function moveItemUp(sender) {
    var li = sender.parentNode;

    while (li != null && li.tagName != 'LI')
        li = li.parentNode;

    if (li == null) {
        return;
    }

    var ul = li.parentNode;
    var previous = li.previousSibling;

    while (previous != null && previous.tagName != 'LI')
        previous = previous.previousSibling;

    if (previous == null) {
        return;
    }

    ul.removeChild(li);
    ul.insertBefore(li, previous);

    dragEnd();
}

function moveItemDown(sender) {
    var li = sender.parentNode;

    while (li != null && li.tagName != 'LI')
        li = li.parentNode;

    if (li == null) {
        return;
    }

    var ul = li.parentNode;
    var next = li.nextSibling;

    while (next != null && next.tagName != 'LI')
        next = next.nextSibling;

    if (next == null) {
        return;
    }

    next = next.nextSibling;

    while (next != null && next.tagName != 'LI')
        next = next.nextSibling;

    if (next == null) {
        return;
    }

    ul.removeChild(li);
    ul.insertBefore(li, next);

    dragEnd();
}

function moveItemToEnd(sender) {
    var li = sender.parentNode;

    while (li != null && li.tagName != 'LI')
        li = li.parentNode;

    if (li == null) {
        return;
    }

    var ul = li.parentNode;
    ul.removeChild(li);
    ul.insertBefore(li, null);

    dragEnd();
}

function uploadCloseButton() {
    __doPostBack('ctl00$contentFrame$uploadContent', '');
}

/*
* Settings screen function - Sets the correct selection to appear highlighted as well as displaying the correct panel
*/
function settingsSelectSection(setting) {
    document.getElementById('ctl00_contentFrame_loginSettings').className = setting == 'loginSettings' ? 'settingsSelected' : 'settingsNotSelected';
    document.getElementById('loginSettingsInfo').style.visibility = setting == 'loginSettings' ? 'visible' : 'hidden';

    document.getElementById('ctl00_contentFrame_schoolSettings').className = setting == 'schoolSettings' ? 'settingsSelected' : 'settingsNotSelected';
    document.getElementById('schoolSettingsInfo').style.visibility = setting == 'schoolSettings' ? 'visible' : 'hidden';

    document.getElementById('ctl00_contentFrame_billingSettings').className = setting == 'billingSettings' ? 'settingsSelected' : 'settingsNotSelected';
    document.getElementById('billingSettingsInfo').style.visibility = setting == 'billingSettings' ? 'visible' : 'hidden';

    document.getElementById('ctl00_contentFrame_userAccounts').className = setting == 'userAccounts' ? 'settingsSelected' : 'settingsNotSelected';
    document.getElementById('userAccountsInfo').style.visibility = setting == 'userAccounts' ? 'visible' : 'hidden';
}

/*
* Settings screen function - passes back information to the server regarding a description change of a template
*/
function changeTemplateDescription(sender) {
    var repeaterPanel = document.getElementById(sender.o_Ih.id);

    while (repeaterPanel != null && repeaterPanel.tagName != 'TR')
        repeaterPanel = getParentElement(repeaterPanel);

    if (repeaterPanel == null) {
        alert('Unable to modify order');
        return false;
    }

    var inputs = repeaterPanel.getElementsByTagName('INPUT');
    var newInfo = inputs[0].value + ':' + sender.value();

    var reportTo = document.getElementById('ctl00_contentFrame_templateChanged');

    if (reportTo == null) {
        alert('Unable to update information');
    }
    else {
        reportTo.value = newInfo;
        __doPostBack(reportTo.id.replace('_', '$'), '');
    }
}

/*
* Settings screen function - passes back information to the server regarding a template deletion after 
*  first prompting the user to make sure they actaully want to remove the template
*/
function deleteTemplate(templateID, control) {

    var reportTo = document.getElementById('ctl00_contentFrame_deleteTemplate');

    if (reportTo == null) {
        alert('Unable to update information');
    }
    else {
        reportTo.value = templateID;

        while (control != null && control.tagName != 'TR')
            control = getParentElement(control);

        if (control != null) {
            if (confirm("Are you sure you wish to remove this template from your list?")) {
                control.style.visibility = "hidden";
                __doPostBack(reportTo.id.replace('_', '$'), '');
            }
        }
        else {
            alert("Unable to remove item from list");
        }
    }
}

/* content page - open file upload dialog
*/
function openUploadDialog() {
    dialogUpload.Open();
}

/* content page - Open the online editor dialog
*/
function openEditorDialog(templateID) {
    var dlg = document.getElementById('dialogFrame');
    if (templateID != null)
        dlg.src = 'components/display/HTMLPage.aspx?templateID=' + templateID + '&TitleReadOnly=1';
    else
        dlg.src = 'components/display/HTMLPage.aspx';
    dialog.Open();
}
/* content page - open file upload dialog
*/
function closedUploadDialog() {
    var feedbackCtrl = document.getElementById("ctl00_contentFrame_feedback");
    feedbackCtrl.value = "done" + feedbackCtrl.value;
    __doPostBack(feedbackCtrl.id.replace('_', '$'), '');
}
/* Hide Please Wait - Order panel
*/
function hidePleaseWaitPanel() {
    document.getElementById('ctl00_contentFrame_step9').className = 'stepVisible';
    document.getElementById('ctl00_contentFrame_pleaseWaitPanel').className = 'stepHidden';
}
/* Show Please Wait - Order panel
*/
function showPleaseWaitPanel() {
    if (typeof (Page_ClientValidate) == 'function')
        Page_ClientValidate();

    if (Page_IsValid != null && Page_IsValid == true) {
        document.getElementById('ctl00_contentFrame_step9').className = 'stepHidden';
        document.getElementById('ctl00_contentFrame_pleaseWaitPanel').className = 'stepVisible';
        return true;
    }
    else
        return false;

}
/* Validate the Discounts panel
*/
function validateDiscountsPanel(source, clientside_arguments) {
    var allowControl = document.getElementById('ctl00_ctl00_contentFrame_content_allowDiscounts');

    if (allowControl == null || allowControl == undefined) {
        alert('Unable to validate discount information');
    }

    if (allowControl.checked == false) {
        clientside_arguments.IsValid = true;
        return;
    }

    var discountValue = document.getElementById('ctl00_ctl00_contentFrame_content_discount');
    var discountModePercentage = document.getElementById('ctl00_ctl00_contentFrame_content_discountMode_0');
    var discountModePrice = document.getElementById('ctl00_ctl00_contentFrame_content_discountMode_1');
    var discountStartsAt = document.getElementById('ctl00_ctl00_contentFrame_content_discountStartsAt');
    var discountStartsAtValue = document.getElementById('ctl00_ctl00_contentFrame_content_discountStartsAtValue');

    if (discountValue.value.length == 0) {
        allowControl.checked = false;
        clientside_arguments.IsValid = true;
        return;
    }

    if (discountValue.value <= 0) {
        allowControl.checked = false;
        clientside_arguments.IsValid = true;
        return;
    }

    if (discountValue.value >= 90 && discountModePercentage.checked) {
        clientside_arguments.IsValid = false;
        return;
    }

    if (discountValue.value >= 50 && discountModePercentage.checked) {
        if (!confirm("You are attempting to give more than 50% discount\r\nAre you sure this is what you want?")) {
            clientside_arguments.IsValid = false;
            return;
        }
    }

    if (!discountModePercentage.checked && !discountModePrice.checked) {
        clientside_arguments.IsValid = false;
        return;
    }

}

/* Checks the user wants to remove all product in the current section
*/
function checkRemoveSection(accordionID) {

    var extender = $find(accordionID);

    if (extender == null || extender == undefined)
        return false;

    if (extender.get_Pane(extender.get_SelectedIndex()) == null)
        return false;

    var pane = extender.get_Pane(extender.get_SelectedIndex()).header;

    if (pane.innerText)
        pane = pane.innerText;
    else
        pane = pane.getElementsByTagName('DIV')[0].innerHTML;

    if (pane.indexOf('\n') == 0) {
        pane = pane.substr(1, pane.length - 2);
    }

    if (pane.trim)
        pane = pane.trim();

    return confirm("Are you sure you wish to remove the '" + pane + "' section?\r\n\r\nIf you choose to remove the '" + pane + "' section, then all products in the section will also be deleted");
}

/* Checks the user wants to remove all product in the current section
*/
function checkRemoveProduct(accordionID, productIDControlID) {

    var extender = $find(accordionID);
    var productRecorder = document.getElementById(productIDControlID);

    if (extender == null || extender == undefined || productRecorder == null || productRecorder == undefined)
        return false;

    if (extender.get_Pane(extender.get_SelectedIndex()) == null)
        return false;

    var pane = extender.get_Pane(extender.get_SelectedIndex()).header;

    if (pane.innerText)
        pane = pane.innerText;
    else
        pane = pane.getElementsByTagName('DIV')[0].innerHTML;

    if (pane.indexOf('\n') == 0) {
        pane = pane.substr(1, pane.length - 2);
    }

    if (pane.trim)
        pane = pane.trim();

    var productID = productRecorder.value;

    if (productID == null || productID.length == 0) {
        alert("Please select a product to remove");
        return false;
    }

    var productDiv = document.getElementById('productID_' + productID);
    var trElements = productDiv.getElementsByTagName('TD');
    var productName = null;

    for (pos = 0; pos < trElements.length && productName == null; pos++) {
        if (trElements[pos].id == 'productID') {
            productName = trElements[pos].innerText;
        }
    }

    if (productName == null) {
        alert('Unable to find product information');
        return false;
    }

    return confirm("Are you sure you wish to remove the '" + productName + "' product from the '" + pane + "' section?");
}

/* New product button pressed on the mainProducts page
*/
function newProduct() {
    var mainProductID = document.getElementById('ctl00_ctl00_contentFrame_content_selectedMainProduct');
    var temp = "";

    if (mainProductID != null) {
        selectListItem(temp, 'ctl00_ctl00_contentFrame_content_selectedMainProduct', '-' + ("" + (Math.random() * 100000)).substr(0, 4), 'accountEntry', false, 'DIV', 'smallAccordionHeaderNonSelNoSize', 'smallAccordionHeaderSelNoSize');
    }
}

/* Copy the category combo box to a hidden control as the validator does not seem to accurately track the changes
*/
function copyCategory() {
    document.getElementById('ctl00_ctl00_contentFrame_content_mainProductsPane_content_productCategoryInfo').value = productCategory.text;
    ValidatorValidate(document.getElementById('ctl00_ctl00_contentFrame_content_mainProductsPane_content_productCategoryInfoValidator'));
}

/* Set the sub product links to edit mode
*/
var checkUpdating = false;

function editProductRow(subProductID, rowNum, clientID, varIncluded, varMin, varMax, varInc, varFrontCover, varRearCover, varMovable, varBeforeDiary, varAfterDiary, varCustomRearCover) {
    var rowToEdit = document.getElementById('ctl00_ctl00_contentFrame_content_supportProductsPane_content_rowToEdit');

    if (rowToEdit == null || rowToEdit == undefined) {
        alert('Unable to edit row');
        return;
    }
    else {
        rowToEdit.value = subProductID;
        //        __doPostBack(rowToEdit.id.replace('_', '$'), '');

        clearInterval(timerLostFocus);
    }

    document.getElementById('ctl00_ctl00_contentFrame_content_editorFlyout_selectedIndex').value = rowNum;

    checkUpdating = true;

    numberIncluded.value(varIncluded);
    minimum.value(varMin);
    maximum.value(varMax);
    increment.value(varInc);

    insideFrontCover.checked(varFrontCover == 1);
    insideRearCover.checked(varRearCover == 1);
    movable.checked(varMovable == 1);
    beforeMainProduct.checked(varBeforeDiary == 1);
    afterMainProduct.checked(varAfterDiary == 1);
    rearCover.checked(varCustomRearCover == 1);
    setCheckBoxes();

    editorFlyout.Open();
    editorFlyout.screenCenter();

    checkUpdating = false;

    return;

}

function CloseEditorWindow() {
    editorFlyout.Close();
}

/* Editor loose focus - set a timer going before stopping the editor
*/
var timerLostFocus = null;

function editProductRowBlur() {
    timerLostFocus = setTimeout("editProductRowClear();", 250);
}

/* Editor loose focus timer - clear the edit mode
*/
function editProductRowClear() {
    clearInterval(timerLostFocus);
    var rowToEdit = document.getElementById('ctl00_ctl00_contentFrame_content_supportProductsPane_content_rowToEdit');
    if (rowToEdit == null || rowToEdit == undefined) {
        alert('Unable to edit row');
    }
    else {
        rowToEdit.value = -1;
        __doPostBack(rowToEdit.id.replace('_', '$'), '');
    }
}

/* Editor control has focus - Cancel timer
*/
function editProductRowFocus() {
    clearTimeout(timerLostFocus);
}

/* previous orders list option changed - add or duplicate order
*/
var previousOrderID = -1;

function previousOrderFunctions(e) {
    var repeaterPanel = e;

    while (repeaterPanel != null && repeaterPanel.tagName != 'TR')
        repeaterPanel = getParentElement(repeaterPanel);

    if (repeaterPanel == null) {
        alert('Unable to perform request at present');
        return false;
    }

    var inputs = repeaterPanel.getElementsByTagName('INPUT');

    if (inputs == null)
        alert('not found');

    previousOrderID = inputs[0].value;

    optionsWindow.Open();

    return false;
}

/* Duplicate an order and redirect to the order page
*/
function duplicateOrder() {
    optionsWindow.Close();

    // pass the information to the web service to be processed
    services.pageServices.set_timeout(10000);
    services.pageServices.DuplicateOrder(previousOrderID, duplicateOrderSuccess, duplicateOrderFailure);
}

/* Redirect to the newOrder page if the duplication was a success
*/
function duplicateOrderSuccess(e) {
    if (e < 0) {
        alert("An error occurred duplicating the order");
        return false;
    }
    newUrl = "newOrder.aspx?resumeOrder=" + e;
    window.location = newUrl;
}

function duplicateOrderFailure(e) {
    alert("An error occurred duplicating the order: " + e.get_message());
}

/* Main Products screen - Link Updated
*/
function refreshLink(clientID) {
    var feedback = document.getElementById(clientID);

    feedback.value = Math.random();
    __doPostBack(clientID.replace('_', '$'), '');
}
/* Finishing Options Category changed
*/
function categoryChanged(sender, e) {
    var parent = null;

    if (sender.checked) // obout text box
        parent = sender.o_c;
    if (sender.value) // obout check box
        parent = sender.o_Ih;

    while (parent != null && parent.tagName != 'TR')
        parent = getParentElement(parent);

    if (parent == null) {
        alert('Unable to perform request at present');
        return false;
    }

    var inputs = parent.getElementsByTagName('INPUT');
    var itemID = null;
    var itemName = null;
    var itemRequired = null;

    for (var x = 0; x < inputs.length; x++) {

        var id = inputs[x].id.substring(inputs[0].id.lastIndexOf('_') + 1);

        if (id == 'id')
            itemID = inputs[x].value;
        else if (id == 'categoryName')
            itemName = inputs[x].value;
        else if (id == 'categoryRequired')
            itemRequired = inputs[x].checked;
    }

    if (itemID == null || itemName == null || itemRequired == null) {
        alert('Unable to perform request at present');
        return false;
    }

    var feedback = '' + itemID + '|' + itemName + '|' + itemRequired;
    var feedbackControl = document.getElementById('ctl00_ctl00_contentFrame_content_categoryChange');

    if (feedbackControl == null) {
        alert('Unable to perform request at present');
        return false;
    }

    feedbackControl.value = feedback;
    __doPostBack(feedbackControl.id.replace('_', '$'), '');
}
/* Finishing Options item changed
*/
function optionChanged(sender, e) {
    var parent = null;

    if (sender.value)
        parent = sender.o_Ih;

    while (parent != null && parent.tagName != 'TR')
        parent = getParentElement(parent);

    if (parent == null) {
        alert('Unable to perform request at present');
        return false;
    }

    var inputs = parent.getElementsByTagName('INPUT');
    var itemID = null;
    var itemName = null;
    var itemPrice = null;

    for (var x = 0; x < inputs.length; x++) {

        var id = inputs[x].id.substring(inputs[0].id.lastIndexOf('_') + 1);

        if (id == 'id')
            itemID = inputs[x].value;
        else if (id == 'optionName')
            itemName = inputs[x].value;
        else if (id == 'optionPrice')
            itemPrice = inputs[x].value;
    }

    if (itemID == null || itemName == null || itemPrice == null) {
        alert('Unable to perform request at present');
        return false;
    }

    var feedback = '' + itemID + '|' + itemName + '|' + itemPrice;
    var feedbackControl = document.getElementById('ctl00_ctl00_contentFrame_content_optionChange');

    if (feedbackControl == null) {
        alert('Unable to perform request at present');
        return false;
    }

    feedbackControl.value = feedback;
    __doPostBack(feedbackControl.id.replace('_', '$'), '');
}

/* Delivery charges - standard charge change
*/
function standardChargeChanged(sender, e) {
    var feedbackControl = document.getElementById('ctl00_ctl00_contentFrame_content_standardChargeFeedback');

    if (feedbackControl == null)
        return;

    //Obout: feedbackControl.value = sender.value();
    feedbackControl.value = sender.value;
    __doPostBack(feedbackControl.id.replace('_', '$'), '');
}

/* Admin Orders screen - feedback changed
*/
function feedbackChanged(sender, e) {
    // Obout list: var value = sender.options[e].value;
    var value = sender.value;

    if (value == -1) {
        return false;
    }

    // -2 = Complete Order
    if (value == -2) {
        if (!confirm("This will move the order to the complete phase and will send an email to the user\r\nIs this correct?")) {
            sender.value = "-1";
            return false;
        }
    }

    // Obout: var parent = sender.o_Ih;
    var parent = getParentElement(sender);

    while (parent != null && parent.tagName != 'TR')
        parent = getParentElement(parent);

    if (parent == null) {
        alert('Unable to perform request at present');
        return false;
    }

    var inputs = parent.getElementsByTagName('INPUT');
    var itemID = null;

    for (var x = 0; x < inputs.length; x++) {
        var id = inputs[x].id.substring(inputs[0].id.lastIndexOf('_') + 1);

        if (id == 'id')
            itemID = inputs[x].value;
    }

    var feedbackControl = document.getElementById('ctl00_ctl00_contentFrame_content_feedbackChanged');
    if (feedbackControl == null) {
        alert("Unable to update feedback");
        sender.value("-1");
        return false;
    }

    feedbackControl.value = itemID + ':' + value;
    __doPostBack(feedbackControl.id.replace('_', '$'), '');
    return false;
}

/* Main Product Page - set the checkbox options correctly
*/
function setCheckBoxes() {

    if (rearCover.checked()) {
        insideFrontCover.checked(false);
        insideRearCover.checked(false);
        movable.checked(false);
        beforeMainProduct.checked(false);
        afterMainProduct.checked(false);

        insideFrontCover.disable();
        insideRearCover.disable();
        movable.disable();
        beforeMainProduct.disable();
        afterMainProduct.disable();

        rearCover.enable();

        return;
    }

    if (insideFrontCover.checked()) {
        insideRearCover.checked(false);
        movable.checked(false);
        beforeMainProduct.checked(false);
        afterMainProduct.checked(false);
        rearCover.checked(false);

        rearCover.disable();
        insideRearCover.disable();
        movable.disable();
        beforeMainProduct.disable();
        afterMainProduct.disable();

        insideFrontCover.enable();

        return;
    }

    if (insideRearCover.checked()) {
        insideFrontCover.checked(false);
        movable.checked(false);
        beforeMainProduct.checked(false);
        afterMainProduct.checked(false);
        rearCover.checked(false);

        rearCover.disable();
        insideFrontCover.disable();
        movable.disable();
        beforeMainProduct.disable();
        afterMainProduct.disable();

        insideRearCover.enable();

        return;
    }

    if (movable.checked()) {
        insideFrontCover.checked(false);
        insideRearCover.checked(false);
        rearCover.checked(false);

        rearCover.disable();
        insideFrontCover.disable();
        insideRearCover.disable();

        beforeMainProduct.enable();
        afterMainProduct.enable();
        movable.enable();

        return;
    }

    if (beforeMainProduct.checked()) {
        afterMainProduct.checked(false);
        afterMainProduct.disable();
        beforeMainProduct.enable();
    }
    else if (afterMainProduct.checked()) {
        beforeMainProduct.checked(false);
        beforeMainProduct.disable();
        afterMainProduct.enable();
    }
    rearCover.enable();
    insideFrontCover.enable();
    insideRearCover.enable();
    movable.enable();
}

/* Main Product page - Front Cover Options
*/
function insideFrontCoverOption(sender, e) {
    if (checkUpdating)
        return;

    checkUpdating = true;

    setCheckBoxes();

    checkUpdating = false;
}

/* Main Product page - Rear Cover Options
*/
function insideRearCoverOption(sender, e) {
    if (checkUpdating)
        return;

    checkUpdating = true;

    setCheckBoxes();

    checkUpdating = false;
}

/* Main Product page - Movable Option
*/
function movableOption(sender, e) {
    if (checkUpdating)
        return;

    checkUpdating = true;

    setCheckBoxes();

    checkUpdating = false;
}

/* Main Product page - Before Option
*/
function beforeDiaryOption(sender, e) {
    if (checkUpdating)
        return;

    checkUpdating = true;

    setCheckBoxes();

    checkUpdating = false;
}

/* Main Product page - After Option
*/
function afterDiaryOption(sender, e) {
    if (checkUpdating)
        return;

    checkUpdating = true;

    setCheckBoxes();

    checkUpdating = false;
}

/* Main Product page - Rear Cover Option
*/
function rearCoverOption(sender, e) {
    if (checkUpdating)
        return;

    checkUpdating = true;

    setCheckBoxes();

    checkUpdating = false;
}


/* New Order - Preview Main Product
*/
function previewMainProduct(productID) {
    var tableRow = getParentElement(productID);

    while (tableRow != null && tableRow.tagName != 'TR') {
        tableRow = getParentElement(tableRow);
    }

    var inputs = tableRow.getElementsByTagName('INPUT');

    window.open('components/webPreview/previewPage.aspx?orderID=-1&orderItemID=m' + inputs[0].value, 'productPreview',
        'width=800,height=500,scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,menubar=no,copyhistory=no,status=no,screenX=2,screenY=2,left=2,top=2');

    return false;
}

/* Account screen - product pricing details changed
*/
function productAccountPriceChanged(sender, e) {
    var parent = sender.o_Ih;

    while (parent != null && parent.tagName != 'TR')
        parent = getParentElement(parent);

    if (parent == null) {
        alert('Unable to perform request at present');
        return false;
    }

    var inputs = parent.getElementsByTagName('INPUT');
    var feedback = '' + inputs[0].value + '|' + e;
    var feedbackControl = document.getElementById('ctl00_ctl00_contentFrame_content_productPriceInfo');

    if (feedbackControl == null) {
        alert('Unable to perform request at present');
        return false;
    }

    feedbackControl.value = feedback;
    __doPostBack(feedbackControl.id.replace('_', '$'), '');
}

/* New order page - custom cover page load event
*/
function coverPageLoadEvent() {
    var mainItem = document.getElementById('ctl00_contentFrame_step3MainItem');
    var frame = document.getElementById('coverUploadFrame');
    if (mainItem == null) {
        alert('main item not found');
        return false;
    }
    if (frame == null) {
        alert('frame item not found');
        return false;
    }

    var loc = '' + window.frames['coverUploadFrame'].document.location;

    if (loc.indexOf('filesUploaded') > 0) {
        document.getElementById('coverUploadFrame').src = "components/contentUpload.aspx?files=1&templateType=1&orderProductID=" + mainItem.value;
        document.getElementById('ctl00_contentFrame_frontCoverPane_content_customCoverLoaded').value = Math.random();
        __doPostBack('ctl00$contentFrame$frontCoverPane$content$customCoverLoaded', '');
    }
}

/* New order page - School name feedback
*/
function schoolNameChanged() {
    var nameFeedback = document.getElementById("ctl00_contentFrame_frontCoverPane_content_schoolNameFeedback");

    if (nameFeedback == null) {
        alert('Unable to find feedback details');
        return;
    }

    nameFeedback.value = Math.random();
    __doPostBack(nameFeedback.id.replace('_', '$'), '');
}

/* New order page - footer text feedback
*/
function footerChanged() {
    var footerFeedback = document.getElementById("ctl00_contentFrame_pageBorderPane_content_footerTextFeedback");

    if (footerFeedback == null) {
        alert('Unable to find feedback details');
        return;
    }

    footerFeedback.value = Math.random();
    __doPostBack(footerFeedback.id.replace('_', '$'), '');
}

/* New Order - page sequence feedback
*/
function displayStep6Error() {
    if (document.getElementById('ctl00_contentFrame_errorDialogMessage') != null) {
        alert(document.getElementById('ctl00_contentFrame_errorDialogMessage').value);
        document.getElementById('ctl00_contentFrame_errorDialogMessage').value = "";
    }
}

/* Progress bar waiting images
*/
var nextButton;
var prevButton;
var waitImage;
var descriptiveText;
var TimeToFade = 200.0;
var clickedButton;

function progressPreviousClick() {
    nextButton = document.getElementById('ctl00_topMenu_progress_wizardNext');
    prevButton = document.getElementById('ctl00_topMenu_progress_wizardBack');
    waitImage = document.getElementById('ctl00_topMenu_progress_progressWaitImage');
    descriptiveText = document.getElementById('ctl00_topMenu_progress_description');

    if (nextButton == null || prevButton == null || waitImage == null || descriptiveText == null)
        return true;

    clickedButton = prevButton.name;

    descriptiveText.style.visibility = 'hidden';
    descriptiveText.style.width = '0px';
    descriptiveText.style.height = '0px';
    descriptiveText.innerText = '';
    waitImage.style.float = 'right';
    waitImage.style.visibility = 'visible';
    waitImage.style.width = 'auto';
    waitImage.style.height = 'auto';
    waitImage.style.float = 'left';

    setTimeout("fade()", 33);
    return false;
}


function progressNextClick() {
    nextButton = document.getElementById('ctl00_topMenu_progress_wizardNext');
    prevButton = document.getElementById('ctl00_topMenu_progress_wizardBack');
    waitImage = document.getElementById('ctl00_topMenu_progress_progressWaitImage');
    descriptiveText = document.getElementById('ctl00_topMenu_progress_description');

    if (nextButton == null || prevButton == null || waitImage == null || descriptiveText == null)
        return true;
    
    clickedButton = nextButton.name;
    
    descriptiveText.style.visibility = 'hidden';
    descriptiveText.style.width = '0px';
    descriptiveText.style.height = '0px';
    descriptiveText.innerText = '';
    waitImage.style.float = 'right';
    waitImage.style.visibility = 'visible';
    waitImage.style.width = 'auto';
    waitImage.style.height = 'auto';
    waitImage.style.float = 'left';

    setTimeout("fade()", 33);
    return false;

    nextButton.style.visibility = 'hidden';
    prevButton.style.visibility = 'hidden';
    nextButton.style.width = '0px';
    prevButton.style.width = '0px';
    descriptiveText.style.visibility = 'hidden';
    descriptiveText.style.width = '0px';

    waitImage.style.visibility = 'visible';
    waitImage.style.width = 'auto';
    waitImage.style.height = 'auto';
    return false;
}

function fade() {

    if (nextButton.FadeState == null) {
        if (nextButton.style.opacity == null
        || nextButton.style.opacity == ''
        || nextButton.style.opacity == '1') {
            nextButton.FadeState = 2;
        }
        else {
            nextButton.FadeState = -2;
        }
    }

    if (nextButton.FadeState == 1 || nextButton.FadeState == -1) {
        nextButton.FadeState = nextButton.FadeState == 1 ? -1 : 1;
        nextButton.FadeTimeLeft = TimeToFade - nextButton.FadeTimeLeft;
    }
    else {
        nextButton.FadeState = nextButton.FadeState == 2 ? -1 : 1;
        nextButton.FadeTimeLeft = TimeToFade;
        setTimeout("animateFade(" + new Date().getTime() + ")", 33);
    }
}

function animateFade(lastTick) {
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    if (nextButton.FadeTimeLeft <= elapsedTicks) {
        nextButton.style.opacity = nextButton.FadeState == 1 ? '1' : '0';
        prevButton.style.opacity = nextButton.FadeState == 1 ? '1' : '0';
        waitImage.style.opacity = nextButton.FadeState == 1 ? '0' : '1';

        nextButton.style.filter = 'alpha(opacity = ' + (nextButton.FadeState == 1 ? '100' : '0') + ')';
        prevButton.style.filter = 'alpha(opacity = ' + (nextButton.FadeState == 1 ? '100' : '0') + ')';
        waitImage.style.filter = 'alpha(opacity = ' + (nextButton.FadeState == 1 ? '0' : '100') + ')';

        __doPostBack(clickedButton, '');        
        return;
    }

    nextButton.FadeTimeLeft -= elapsedTicks;
    var newOpVal = nextButton.FadeTimeLeft / TimeToFade;
    if (nextButton.FadeState == 1)
        newOpVal = 1 - newOpVal;

    nextButton.style.opacity = newOpVal;
    prevButton.style.opacity = newOpVal;
    waitImage.style.opacity = 1 - newOpVal;

    nextButton.style.filter = 'alpha(opacity = ' + (newOpVal * 100) + ')';
    prevButton.style.filter = 'alpha(opacity = ' + (newOpVal * 100) + ')';
    waitImage.style.filter = 'alpha(opacity = ' + (100 - (newOpVal * 100)) + ')';

    setTimeout("animateFade(" + curTick + ")", 33);
}

function postcodeChanged(s, e) {
    s.value(e.toUpperCase());
    document.getElementById('ctl00_contentFrame_postcodeChangedFeedback').value = Math.random();
    __doPostBack('ctl00$contentFrame$postcodeChangedFeedback', '');
}

function reverseSubmission(orderID) {
    if (!confirm("Are you sure you want to reverse the order submission for order " + orderID + "?")) {
        return false;
    }

    var hf = document.getElementById('ctl00_ctl00_contentFrame_content_submitted_content_reverseOrder');
    if (hf == null) {
        alert('Unable to reverse order - unable to find elements');
        return false;
    }

    hf.value = orderID;
    __doPostBack(hf.name, '');    
}
