var result;
var windex = 0;
var org_cmd;

function SetResult(buf) {
    result = buf;
//    alert(result);
    return result;
}

function mopen(buf) {
    main.location.href = buf;
}

function openx(arg) {
    window.location=arg;
    alert("Function openx done");
}

function btnHover(btn) {
    btn.style.border = "1px solid #0A246A";
    btn.style.background = "#B6BDD2";
}

function btnUnHover(btn) {
	btn.style.border = "1px solid #DBD8D1";
    btn.style.background = "#DBD8D1";
    window.status = "";
}

function Update(buf) {
    result = "Result: "+buf;
    try {
        window.main.update();
    } catch(e) {
//       alert("nav.js: Update() window.main.update() " + e);
    }
    return result;
}

function noframes() {
    var x = main.location.href;
    location.href = x;
}

function extwin() {
    var x = window.frames[1].location.href;
    windex++;
    var y = "NAT32_"+windex;
    window.open(x, y, 'width=900 height=600 resizable=yes scrollbars=yes');
    return false;
}

function edit() {
   var x = window.frames[1].location.pathname;
   var u = "shell?cmd=edit+htm"+x;
   bottom.location.href = u;
}

function myHelpSubmit(cmd) {
    org_cmd = cmd.value;
    if (cmd.value.substr(0, 5) != 'help ')
         cmd.value = 'help ' + cmd.value;
    setTimeout('document.myHelp.cmd.value=org_cmd',100);
    return 1;
}

function myHelpGet(cmd) {
    org_cmd = cmd.value;
    if (cmd.value.substr(0, 4) != 'cat ')
         cmd.value = 'cat ' + 'htm/' + cmd.value + '.htm';
    setTimeout('document.myHelp.cmd.value=org_cmd',100);
    return 1;
}

function myCmdSubmit() {
    setTimeout('document.myCmd.reset()',100);
    return true;
}

function resize() {
    var w = document.getElementById("toolbar").scrollWidth;
    var x = ((w-498)/3)/8;  // Empirical
    var y = document.getElementById("toolbar").scrollHeight;

    GetHeights();

    if (navigator.userAgent.indexOf("Firefox") != -1)
        x = x-8;

    if (x <= 0)
        x = 1;
    x = Math.floor(x);

    resizeInputs(x);

    resizeIframe('main');
    resizeIframe('tree');
}

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

var tbh;    // Toolbar height
var sbh;    // Statusbar height
var vph;    // Viewport height
var vphx;   // Special viewport height
var vpht;   // Test viewport height

function GetHeights() {

    var tbx = document.getElementById("toolbar");
    tbh = tbx.scrollHeight;
//    alert("tbh "+tbh);
    var sbx = document.getElementById("bottom");
    sbh = sbx.scrollHeight;
//    alert("sbh "+sbh);
    vph = document.documentElement.clientHeight;
//    alert("vph "+vph);
    vphx = document.body.scrollHeight;
//    alert("vphx "+vphx);
    vpht = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
//    alert("vpht "+vpht);

}

function GetTbh() {
    var tbx = document.getElementById("toolbar");
    tbh = tbx.scrollHeight;
    return tbh;
}

function GetSbh() {
    var sbx = document.getElementById("bottom");
    sbh = sbx.scrollHeight;
    return sbh;
}

function GetVph() {
    vph = document.documentElement.clientHeight;
    return vph;
}

function GetVphx() {
    vphx = document.body.scrollHeight;
    return vphx;
}

function resizeIframe(frameid) {
    var currentfr=document.getElementById(frameid)

    currentfr.style.display="block"
    if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
//        currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
        currentfr.height = vpht - tbh - sbh - 2;// + FFextraHeight;
    }
    else

    if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
//        currentfr.height = currentfr.Document.body.scrollHeight;
        currentfr.height = vph - tbh - sbh - 2; // for borders
    }
    else {
        currentfr.height = vpht - tbh - sbh - 2;
    }
}
function resizeInputs(s) {
    var i1=document.getElementById("input1");
    var i2=document.getElementById("input2");
    var i3=document.getElementById("input3");

    i1.size=s;
    i2.size=s;
    i3.size=s;
}


