function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    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_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function GoLE() {
    var theform;
    if (isIE) {
        theform = document.forms[0];
        theform.submit();
    }
    else {
        document.forms[0].submit();
    }
}

function Go() {
    var theform;
    if (isIE) {
        theform = document.forms[1];
        theform.submit();
    }
    else {
        document.forms[1].submit();
        //theform = document.PostBack;
        //PostBack.submit();
    }
}

function PrintWordDoc(file, text) {
    do {
        text = text.replace(",", "\n");
    } while (text.indexOf(",") > 0)

    var w = new ActiveXObject('Word.Application');
    if (w != null) {
        w.Visible = false;
        var docText;
        var obj;

        w.Visible = true;
        obj = w.Documents.Open(file);
        docText = obj.Content;
        w.Selection.TypeText(text);
        w.Options.PrintBackground = true;
        w.PrintOut();
        //w.Documents.Save("c:\\doc_From_javaScript.doc");
        w.quit(0);
        w.Visible = false;
    }
}

function openNewWindow(file, width, height) {
    var newwindow = open(file, "", "width=" + width + ",height=" + height + ",taskbar=no, scrollbars=yes, menubar=no,left=200,top=200,screenX=0,screenY=0", "");
    if (!newwindow) {
        alert("Sorry, this window failed to open, make sure you haven't a pop-up blocker installed, and your Javascript settings are set correctly.");
    }
    newwindow.document.close();
}

var xmlhttp

function loadXMLDoc(url) {
    // code for Mozilla, etc.
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest()
        xmlhttp.onreadystatechange = xmlhttpChange
        xmlhttp.open("GET", url, true)
        xmlhttp.send(null)
    }
    // code for IE
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
        if (xmlhttp) {
            xmlhttp.onreadystatechange = xmlhttpChange
            xmlhttp.open("GET", url, true)
            xmlhttp.send()
        }
    }
}

function xmlhttpChange() {
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState == 4) {
        // if "OK"
        if (xmlhttp.status == 200) {
            document.write(xmlhttp.responseText)
        }
        else {
            // alert("Problem retrieving XML data")
        }
    }
}

function Show(ToShow) {
    var O1 = document.getElementById(ToShow);
    O1.style.display = '';

    O1.style.left = mouseX + 10;
    O1.style.top = mouseY - (O1.offsetHeight / 2);
}

function ShowNew(ToShow) {
    var O1 = document.getElementById(ToShow);
    O1.style.display = '';

  
}

function ShowBelow(ToShow) {
    var O1 = document.getElementById(ToShow);
    O1.style.display = '';

    O1.style.left = 50 + "px";
    O1.style.top = mouseY + 10 + "px";
}

function ShowTop(ToShow) {
    var O1 = document.getElementById(ToShow);
    O1.style.display = '';
    O1.style.left = 80 + "px";
    O1.style.top = (document.body.scrollTop + 10) + "px";
}


function EnlargeProductImage(ToShow) {

    var O1 = document.getElementById("ImagePopUp");

    if (O1.style.display == "none") {

        O1.style.display = '';
        O1.style.left = 80 + "px";
        O1.style.top = (document.documentElement.scrollTop + 10) + "px";

        var start = ToShow.innerHTML.indexOf("/Images/Larger/");
        var end = ToShow.innerHTML.indexOf(".jpg");

        var justSrc = ToShow.innerHTML.substring(start, end);

        var imageHTML = justSrc.replace("/Images/Larger/", "");
        imageHTML = imageHTML + ".jpg";
        O1.innerHTML = "<div><a href=\"javascript:HideBigImage()\" style=\"text-align:center\">close</a></div><div><img src=\"http://www.bargainboards.co.uk/admin/images/" + imageHTML + "\" /></div>";
    }
    else {

        O1.style.display = "none";
    }
}

function HideBigImage() {

    document.getElementById("ImagePopUp").style.display = "none";
}

function ShowLeft(ToShow) {
    var O1 = document.getElementById(ToShow);
    O1.style.display = '';
    if (isIE) {
        O1.style.left = (event.clientX - 800);
        O1.style.top = document.body.scrollTop + (event.clientY - 110);
    }
    else {
        O1.style.left = 478;
        O1.style.top = 320;
    }
}

function Hide(ToShow) {
    var O1 = document.getElementById(ToShow);
    O1.style.display = 'none';
}

function UnHide(ToShow) {
    var O1 = document.getElementById(ToShow);
    O1.style.display = '';
}


function AJAXTextCommand(linkDiv, hiddenDiv, Command, Argument, GUID) {
    UnHide(hiddenDiv);
    Hide(linkDiv);
    SendCommand(GUID, Command, Argument);
}

function SendCommand(GUID, Command, Argument) {
    var URL = "/Admin/AJAX/AjaxCommand.aspx?GUID=" + GUID + "&Command=" + Command + "&Argument=" + Argument;
    AJAXSend(URL);
}

function CheckSelect(obj) {
    //alert(obj.value); return false;
    var select = document.getElementById(obj);

    if (select.value == "-1") {

        alert("Please select a product variation");
        return false;
    }
    else
        return true;

}

function CheckEnquireForm() {

    var warning = "";

    if (document.getElementById("txtFirstName").value == "")
        warning += "<br />Please enter your first name";
    if (document.getElementById("txtLastName").value == "")
        warning += "<br />Please enter your last name";
    if (document.getElementById("txtEmail").value == "")
        warning += "<br />Please enter your email";
    if (document.getElementById("txtEmail").value != document.getElementById("txtConfirmEmail").value)
        warning += "<br />your email does not match";
    if (document.getElementById("txtQuestion").value == "")
        warning += "<br />please enter a question";

    document.getElementById("EnquireValidation").innerHTML = warning;


    
    if (warning == "")
        return true;
    else
        return false;


}