switch ($_POST["key"]) {
        case "confirm":
            $OUTPUT = confirm($_POST);
            break;
        case "write":
            $OUTPUT = write($_POST);
            break;
        default:
            $OUTPUT = editAccnt($_GET['bankid']);
    }
} else {
    # Display default output
    if (isset($_GET['bankid'])) {
        $OUTPUT = editAccnt($_GET['bankid']);
    } else {
        $OUTPUT = editAccnt('none');
    }
}
# get templete
require "../template.php";
function editAccnt($bankid)
{
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($bankid, "num", 1, 4, "Invalid Bank Account ID.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
function write($_POST)
{
    # Connect to cubit
    db_connect();
    # Get vars
    extract($_POST);
    if (isset($back)) {
        return editAccnt($bankid);
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($bankid, "num", 1, 4, "Invalid Bank Account ID.");
    $v->isOk($acctype, "string", 1, 30, "Invalid Account Type.");
    $v->isOk($bankname, "string", 1, 50, "Invalid Bank name.");
    $v->isOk($fcid, "num", 1, 30, "Invalid Currency.");
    $v->isOk($branchname, "string", 1, 50, "Invalid Branch Name.");
    $v->isOk($branchcode, "string", 1, 15, "Invalid Branch Code.");
    $v->isOk($accname, "string", 1, 50, "Invalid Account Name.");
    $v->isOk($accnum, "num", 1, 20, "Invalid Account Number.");
    $v->isOk($glacc, "num", 1, 20, "Invalid Ledger account.");
    $v->isOk($details, "string", 1, 255, "Invalid Details.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    $curr = getSymbol($fcid);
    db_connect();
    $sql = "UPDATE bankacct SET acctype = '{$acctype}', bankname = '{$bankname}', btype = '{$loc}', fcid = '{$fcid}', currency = '{$curr['name']}', branchname='{$branchname}', branchcode='{$branchcode}', accname='{$accname}', accnum='{$accnum}', details='{$details}' WHERE bankid='{$bankid}' AND div = '" . USER_DIV . "'";
    $nwUsrRslt = db_exec($sql) or errDie("Unable to edit bank account.");
    # ReCreate hook
    core_connect();
    $hook = "UPDATE bankacc SET accnum = '{$glacc}' WHERE accid = '{$bankid}'";
    $Rlst = db_exec($hook) or errDie("Unable to add hook for for bank account", SELF);
    # Status report
    $write = "\n\t\t<table " . TMPL_tblDflts . " width='50%'>\n\t\t\t<tr>\n\t\t\t\t<th>Bank Account Edited</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td>Bank Account <b>{$accname}</b>, was successfully edited.</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='bankacct-view.php'>View Bank Accounts</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='../main.php'>Main Menu</a></td>\n\t\t\t</tr>\n\t\t</table>";
    return $write;
}