﻿function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        } 
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL, winName, features) {
    window.open(theURL, winName, features);
}


function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_validateForm() {
    if (form.btnContinueOrder == true) {
        var i, p, q, nm, test, num, min, max, errors = '', args = MM_validateForm.arguments;
        for (i = 0; i < (args.length - 2); i += 3) {
            test = args[i + 2]; val = MM_findObj(args[i]);
            if (val) {
                nm = val.name; if ((val = val.value) != "") {
                    if (test.indexOf('isEmail') != -1) {
                        p = val.indexOf('@');
                        if (p < 1 || p == (val.length - 1)) errors += '- ' + nm + ' must contain an e-mail address.\n';
                    } else if (test != 'R') {
                        num = parseFloat(val);
                        if (isNaN(val)) errors += '- ' + nm + ' must contain a number.\n';
                        if (test.indexOf('inRange') != -1) {
                            p = test.indexOf(':');
                            min = test.substring(8, p); max = test.substring(p + 1);
                            if (num < min || max < num) errors += '- ' + nm + ' must contain a number between ' + min + ' and ' + max + '.\n';
                        } 
                    } 
                } else if (test.charAt(0) == 'R') errors += '- ' + nm + ' is required.\n';
            }
        } if (errors) alert('The following error(s) occurred:\n' + errors);
        document.MM_returnValue = (errors == '');
    }
}

function getEl(id) {
    // Helper to reduce typing
    return document.getElementById(id);
}

function checkPromotionCode(src, arg) {
    var i = getEl("txtPromotionCode").value.length;
    if (i != 0) {
        arg.IsValid = (i >= 10 && i <= 15);
    } else {
        arg.IsValid = true;
    }
}

function checkHouseNumberOrName(src, arg) {
    arg.IsValid = (getEl("txtHouseNumber").value.length != 0 || getEl("txtHouseName").value.length != 0);
}

function checkClubcardNumber(src, arg) {
    arg.IsValid = (getEl("txtClubcardNumber").value.length >= 16 || getEl("txtClubcardNumber").value.length == 0);
}

function checkCreditCard(src, arg) {
    arg.IsValid = (getEl("txtCardNumber").value.length == 16 || getEl("txtCardNumber").value.length == 18 || getEl("txtCardNumber").value.length == 19);
}

function checkSortCode(src, arg) {
    var sSortCode = getEl("txtSortCode1").value + getEl("txtSortCode2").value + getEl("txtSortCode3").value;
    arg.IsValid = (sSortCode.length == 6);
}

function checkSecurityCode(src, arg) {
    var sSortCode = getEl("Checkout:CardPaymentDetailsTemplate_SecurityCode").value;
    arg.IsValid = (sSortCode.length > 2);
}

function checkEmails(src, arg) {
    if (getEl("txtEmail").value.length != 0 && getEl("txtEmailConfirm").value.length != 0) {
        arg.IsValid = getEl("txtEmail").value == getEl("txtEmailConfirm").value;
    } else {
        arg.IsValid = true;
    }
}

function popup(url, windowName, width, height, top, left) {
    remote = window.open(url, windowName, "resizable=yes,toolbar=0,location=0,directories=0,status=no,menubar=0,scrollbars=1,copyhistory=0,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",screeny=" + top + ",screenx=" + left);
    return false;
}

function checkTandC(src, arg) {
    arg.IsValid = getEl("chkTerms").checked;
}

function checkEnter(evt) {
    var evt = (evt) ? evt : ((event) ? event : null);
    var src = evt ? (evt.target ? evt.target : evt.srcElement) : event.srcElement;

    if (evt) {
        var kc = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
        if (kc == 13) {
            switch (src.id.toLowerCase()) {
                case "quicksearch_quicksearchaccessoriesid_txttextsearch":
                    getEl("QuickSearch_quicksearchAccessoriesID_btnTextSearch").click();
                    break;
                case "quicksearch_quicksearchreconid_txttextsearch":
                    getEl('QuickSearch_quicksearchReconID_btnTextSearch').click();
                    break;
                case "quicksearch_quicksearchathomeid_txttextsearch":
                    getEl('QuickSearch_quicksearchAtHomeID_btnTextSearch').click();
                    break;
            }
        }
    }
    if (window.event.keyCode == 13) {
        return false;
    }
    return true;
}

function cleartextbox(textbox) {
    textbox.value = '';
}

function changeclass1() {
    var NAME = document.getElementById("itemDescHeader")
    NAME.className = "selected"
}

function clickButton(e) {
    var intKey = (window.Event) ? e.which : e.keyCode;

    if (intKey == 13) {
        document.getElementById('searchBar_searchButton').click();
        return false;
    }

    return true;
}

function clickButton(e, button) {
    var intKey = (window.Event) ? e.which : e.keyCode;

    if (intKey == 13) {
        document.getElementById(button).click();
        return false;
    }

    return true;
}

function changeImage(e, imageUrl) {
    if (document.images) {
        document.getElementById(e).src = imageUrl;
    }
}

function changeHRef(e, url) {
    document.getElementById(e).href = url;
}

var addthis_config = {
    ui_click: true
}
