﻿var popupwin;

function verticalCentre() {
    if (window.innerHeight) {
        var frameheight = window.innerHeight;
    } else if (document.documentElement.clientHeight) {
        var frameheight = document.documentElement.clientHeight;
    } else {
        var frameheight = document.body.clientHeight;
    }
    var rem = (frameheight / 2) - 270;
    if (rem > 0) {
        setY('outer1', rem);
    }
    show('outer1');
}

function showPopup(page) {
    if (popupwin) { popupwin.close() }

    if (self.screen) {
        var posx = (screen.availWidth - 600) / 2;
        var posy = (screen.availHeight - 500) / 2;
    } else {
        var posx = 250;
        var posy = 200;
    }

    popupwin = window.open(page+".html", page, "width=600,height=500,left="+posx+",top="+posy+",screenx="+posx+",screeny="+posy+",status=yes,menubar=yes,titlebar=yes,toolbar=yes,scrollbars=yes,location=no");
}

function showInvoice(invoiceno, pickingList) {
    if (popupwin) { popupwin.close() }

    if (screen.availHeight) {
        var winy = screen.availHeight - 90;
        var winx = screen.availWidth - 24;
    } else {
        var winy = 660;
        var winx = 1000;
    }
    popupwin = window.open("/showinvoice.aspx?invoiceno=" + invoiceno+ "&pickinglist=" + pickingList + "&winx=" + winx + "&winy=" + winy, "Invoice", "fullscreen=yes");
}

function showReport(startdate, enddate) {
    if (popupwin) { popupwin.close() }

    if (screen.availHeight) {
        var winy = screen.availHeight - 90;
        var winx = screen.availWidth - 24;
    } else {
        var winy = 660;
        var winx = 1000;
    }
    popupwin = window.open("/showreport.aspx?startdate=" + startdate + "&enddate=" + enddate + "&winx=" + winx + "&winy=" + winy, "PurchaseReport", "fullscreen=yes");
}

function showPDF(filename) {
    if (popupwin) { popupwin.close() }

    if (screen.availHeight) {
        var winy = screen.availHeight - 90;
        var winx = screen.availWidth - 24;
    } else {
        var winy = 660;
        var winx = 1000;
    }
    popupwin = window.open("/showPDF.aspx?filename=" + filename + "&winx=" + winx + "&winy=" + winy, "Invoice", "fullscreen=yes");
}

function filterkeys(field, type, event) {
    var key;
    if (window.event) {
        key = window.event.keyCode;
    } else if (event) {
        key = event.which;
    } else {
        return true;
    }

    if (key == 0 || key == 8) {
        window.status = "";
        return true;
    } else {
        if (type == 'int') {
            if ((key > 47) && (key < 58)) {
                window.status = "";
                return true;
            } else {
                window.status = "Invalid Number";
                return false;
            }
        } else if (type == 'float') {
            if ((key > 47 && key < 58) || key == 46) {
                window.status = "";
                return true;
            } else {
                window.status = "Invalid Number";
                return false;
            }
        } else if (type == 'date') {
            if (key > 46 && key < 58) {
                window.status = "";
                return true;
            } else {
                window.status = "Invalid Date Character";
                return false;
            }
        } else if (type == 'time') {
            if (key > 47 && key < 59) {
                window.status = "";
                return true;
            } else {
                window.status = "Invalid Time Character";
                return false;
            }
        } else if (type == 'pcode') {
            if ((key > 47 && key < 58) || (key > 64 && key < 91) || (key > 96 && key < 123) || key == 32) {
                window.status = "";
                return true;
            } else {
                window.status = "Invalid Character";
                return false;
            }
        }
    }
}

function checkout() {
    document.form2.action = "https://secure.wp3.rbsworldpay.com/wcc/purchase";
    document.form2.submit();
}

function checkDeactivate() {
    if (confirm("Are you sure you want to disable this user account?\n\nThe user will not be able to log in or place any new orders until their account is enabled again.")) {
        return true;
    } else {
        return false;
    }
}

function checkDelete() {
    if (confirm("Are you sure you want to remove this product?")) {
        return true;
    } else {
        return false;
    }
}

function checkEmailForm() {
	if (document.getElementById('ctl00_maincontent_name').value == null || document.getElementById('ctl00_maincontent_name').value == '' || document.getElementById('ctl00_maincontent_email').value == null || document.getElementById('ctl00_maincontent_email').value == '') {
	    alert("You have not entered your name and email address");
	    document.getElementById('ctl00_maincontent_name').focus();
	    return false;
	}
	return true;
}

function loadProduct(divid) {
    divid = divid.replace(/_/g, '$');
    __doPostBack(divid+'name', '');
}

