﻿function hideDiv(divid) {
    document.getElementById(divid).style.visibility = 'hidden';
}
function disassociateBev(CurrentPageIndex, posid, plu, title) {
    var sMessage = "Do you really want to disassociate '" + plu + "' with the Beverage '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Recipe.aspx?disa=1&posid=" + posid + "&CurrentPageIndex=" + CurrentPageIndex;
    }
}
function deleBottleBeverage(upc) {
    var sMessage = "Do you really want to delete the Bottle '" + upc + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Bottles.aspx?upc=" + upc + "&del=1";
    }
}
function FreezeScreen(msg) {
    scroll(0, 0);
    var outerPane = document.getElementById('FreezePane');
    var innerPane = document.getElementById('InnerFreezePane');
    if (outerPane) outerPane.className = 'FreezePaneOn';
    if (innerPane) innerPane.innerHTML = msg;
}
function UnFreezeScreen() {
    scroll(0, 0);
    var outerPane = document.getElementById('FreezePane');
    var innerPane = document.getElementById('InnerFreezePane');
    if (outerPane) outerPane.className = 'FreezePaneOff';
    if (innerPane) innerPane.innerHTML = '';
}

function openWindow(url, features) {
    window.open(url, 'win1', features);
}

function unplug(SerialNo, bid) {
    var sMessage = "Do you really want to unplug the spout '" + SerialNo + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Spouts.aspx?SerialNo=" + SerialNo + "&unplug=1&bid=" + bid;
    }
}
function deleTeamlogAttachment(id, title) {
    var sMessage = "Do you really want to delete the file '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Edit_Teamlog.aspx?TeamLogID=" + id + "&del=1&file=" + escape(title);
    }
}
function deleTeamlog(id, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this log?";
    else
        sMessage = "Do you really want to delete the log '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_TeamLog.aspx?del=1&id=" + id;
    }
}
function deleTap(id, bid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this tap?";
    else
        sMessage = "Do you really want to delete the tap '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "TapSettings.aspx?del=1&tapid=" + id + "&bid=" + bid;
    }
}
function deleFlowAppInfo(cid, bid) {
    var sMessage = "Do you really want to delete the Flow Application information?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Survey.aspx?rdoMenu=1&delflowinfo=1&cid=" + cid + "&bid=" + bid;
    }
}
function delePOSAppInfo(cid, bid) {
    var sMessage = "Do you really want to delete the POS Application information?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Survey.aspx?rdoMenu=1&delposinfo=1&cid=" + cid + "&bid=" + bid;
    }
}
function changeVolume(size, kegs2addName, volumeName) {
    var kegs2add = trimAll(document.getElementById(kegs2addName).value);
    if (kegs2add != "") {
        if (isNaN(parseFloat(kegs2add))) {
            alert("Containers to Add must be a number.");
            document.getElementById(kegs2addName).value = "";
            document.getElementById(kegs2addName).focus();
        }
        else {
            var oldValue = parseFloat(document.getElementById(volumeName).value);
            var addValue = parseFloat(size) * parseFloat(kegs2add);
            document.getElementById(volumeName).value = Math.round((oldValue + addValue) * 100) / 100;
        }
    }
}
function deleFavouriteShift(id, title, isFromFront) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this Favourite Shift?";
    else
        sMessage = "Do you really want to delete the Favourite Shift '" + title + "'?";
    if (confirm(sMessage)) {
        var url = "Settings_FavouriteShifts.aspx?del=1&id=" + id;
        if (isFromFront == 1) {
            url += "&fromfront=1";
        }
        document.location.href = url;
    }
}
function deleVariance(url, logdate, plu, delbarid) {
    var sMessage = "Do you really want to delete this ";
    if (plu == "")
        sMessage += "FLOW";
    else
        sMessage += "SALES";
    sMessage += " record?";
    if (confirm(sMessage)) {
        document.location.href = url + "&del=1&logdate=" + logdate + "&plu=" + plu + "&delbarid=" + delbarid;
    }
}
function deleSpillage(id, LogDate) {
    var sMessage;
    if (LogDate == "")
        sMessage = "Do you really want to delete this Spillage?";
    else
        sMessage = "Do you really want to delete the Spillage at '" + LogDate + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Spillages.aspx?del=1&id=" + id;
    }
}
function deleRegion(id, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this Region?";
    else
        sMessage = "Do you really want to delete the Region '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Region.aspx?del=1&id=" + id;
    }
}
function deleSupplier(id, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this Supplier?";
    else
        sMessage = "Do you really want to delete the Supplier '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Supplier.aspx?del=1&id=" + id;
    }
}
function deleBar(id, cid, bid, title) {
    var sMessage;
//    if (title == "")
//        sMessage = "Do you really want to delete this bar?";
//    else
//        sMessage = "Do you really want to delete the bar '" + title + "'?";
    sMessage = "Deletion of a bar will remove existing taps assigned to it. Are you sure you want to delete?";
    if (confirm(sMessage)) {
        if (cid == "")
            document.location.href = "Settings_Branch.aspx?delbar=1&id=" + id;
        else
            document.location.href = "Settings_Bar.aspx?del=1&id=" + id + "&cid=" + cid + "&bid=" + bid;
    }
}
function deleUser(id, cid, bid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this user?";
    else
        sMessage = "Do you really want to delete the user '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_User.aspx?del=1&id=" + id + "&cid=" + cid + "&bid=" + bid;
    }
}
function deleTerminal(mid, cid, bid, id) {
    var sMessage;
    sMessage = "Do you really want to delete the Terminal '" + id + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Survey.aspx?del=1&id=" + escape(id) + "&cid=" + cid + "&bid=" + bid + "&mid=" + escape(mid);
    }
}
function deleTerminalName(tid, title, baredit) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this terminal?";
    else
        sMessage = "Do you really want to delete the terminal '" + title + "'?";

    if (confirm(sMessage)) {
        if (baredit == 1)
            document.location.href = "Settings_Bar.aspx?delterminal=1&id=" + tid;
        else
            document.location.href = "Settings_Terminal.aspx?del=1&id=" + tid;
    }
}
function deleBox(id, cid, bid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this BOX?";
    else
        sMessage = "Do you really want to delete the BOX '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Line.aspx?del=1&id=" + id + "&cid=" + cid + "&bid=" + bid;
    }
}
function delePOSSize(id, cid, bid, tid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this POS Size?";
    else
        sMessage = "Do you really want to delete the POS Size '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "POSSizes.aspx?del=1&id=" + id + "&cid=" + cid + "&bid=" + bid + "&tid=" + tid;
    }
}
function deleMissingPLU(id, plu) {
    var sMessage = "Do you really want to delete the missing PLU '" + plu + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_MissingPLUs.aspx?del=1&id=" + id;
    }
}
function delePOS(CurrentPageIndex, id, cid, bid, tid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this PLU?";
    else
        sMessage = "Do you really want to delete the PLU '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Recipe.aspx?del=1&id=" + id + "&cid=" + cid + "&bid=" + bid + "&tid=" + tid + "&CurrentPageIndex=" + CurrentPageIndex;
    }
}
function deleBeverage(id, cid, bid, tid, title, bevType) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this beverage?";
    else
        sMessage = "Do you really want to delete the beverage '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Beverage.aspx?del=1&id=" + id + "&cid=" + cid + "&bid=" + bid + "&bevType=" + bevType;
    }
}
function deleMasterBeverage(id, tid, cid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this beverage?";
    else
        sMessage = "Do you really want to delete the beverage '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_MasterBeverage.aspx?del=1&id=" + id + "&cid=" + cid + "&tid=" + tid;
    }
}

function ClientValidator_ValidDegree(ctl, args) {
    // even number?
    var sText = args.Value;
    args.IsValid = true;

    var ValidChars = "0123456789.-";
    var Char;

    for (i = 0; i < sText.length && args.IsValid == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            args.IsValid = false;
        }
    }
}

function ClientValidator_ValidPureNumber(ctl, args) {
    // even number?
    var sText = args.Value;
    args.IsValid = true;

    var ValidChars = "0123456789";
    var Char;

    for (i = 0; i < sText.length && args.IsValid == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            args.IsValid = false;
        }
    }
}

function trimAll(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}
function changeCssHelp(id) {
    var view = document.getElementById("helplink" + id);
    var block = document.getElementById("help" + id);
    var viewPos = new positionInfo(view);
    var blockPos = new positionInfo(block);
    var x = viewPos.getElementLeft() + 42;
    var y = viewPos.getElementBottom() + 2;
    var blockStyle = block.style;
    blockStyle["left"] = x + "px";
    blockStyle["top"] = y + "px";

    if (block.className == 'hideHelp') {
        block.className = 'showHelp';
    }
    else {
        block.className = 'hideHelp';
    }
}

function deleUnit(id, cid, bid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this unit?";
    else
        sMessage = "Do you really want to delete the unit '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Unit.aspx?del=1&id=" + id + "&cid=" + cid + "&bid=" + bid;
    }
}
function deleGroup(id, uid, cid, bid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this group?";
    else
        sMessage = "Do you really want to delete the group '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Groups.aspx?del=1&id=" + id + "&uid=" + uid + "&cid=" + cid + "&bid=" + bid;
    }
}
function deleProbe(id, gid, uid, cid, bid, title) {
    var sMessage;
    if (title == "")
        sMessage = "Do you really want to delete this probe?";
    else
        sMessage = "Do you really want to delete the probe '" + title + "'?";
    if (confirm(sMessage)) {
        document.location.href = "Settings_Probe.aspx?del=1&id=" + id + "&gid=" + gid + "&uid=" + uid + "&cid=" + cid + "&bid=" + bid;
    }
}

