// Javascript for the Scriptome
d=document
SectCellID = "Cell" + Sect
Stan = (d.getElementById)
beige = "#ECD9BB"
//darkblue = "#5E7390"
darkblue = "#111111" // onLoad changes this to blue/green for Unix/Windows page

function startmenu() {
    x = 1;
    while (im = d.getElementById("unixtool" + x)) {
      opentool("unix", x);
      x++
    }
}

// New color for the navbar element we mouse over
// Also set some variables that the embedded navbar code can use
function NavBarOver(id) {
    if (Stan) {
	CellID = "Cell" + id
	TxtID = "Txt" + id
	oldTxtColor = d.getElementById(TxtID).style.color
	d.getElementById(TxtID).style.color = beige
	oldCellColor = d.getElementById(CellID).style.color
	d.getElementById(CellID).style.backgroundColor=darkblue
    }
}

function NavBarOut(id) {
    if (Stan) {
	CellID = "Cell" + id
	TxtID = "Txt" + id
	d.getElementById(TxtID).style.color = oldTxtColor
	if (id !== Sect) {
	    d.getElementById(CellID).style.backgroundColor=oldCellColor
	}
    }
}

// Toggle all the tool menus closed when loading a page

// Expand or contract tool menus
function menu_toggle(menu_num) {
    var imid = "img" + menu_num;
    var img = d.getElementById(imid);
    // TODO get img.src, use its path but change filename
    var menu1 = "menu" + menu_num;
    menu = d.getElementById(menu1);
    if (menu.style.display == "none") {
        menu.style.display = "block";
        img.src="../../images/triangle16_down.gif"
    } else {
        menu.style.display = "none";
        img.src="../../images/triangle16_right.gif"
    }
}

function toggle_code_format(button) {
    var f = button.form;
    if (f.style.whiteSpace == 'pre') {
	f.style.whiteSpace = 'normal';
	button.value  ='Expand code';
    }
    else {
        f.style.whiteSpace = 'pre';
	button.value = 'Shrink code';
    }
}

// Given a menu selection, go there
function go(my_selection) {
    var place = my_selection.value
    // IE: even after hopping, scroll bar selects & goes to a different tool!
    window.focus();
    // Ignore empty selection (default "pick a tool" choice)
    if (place) {
	location=place;
    }
}

// TODO reset all forms onLoad
function updateParameters(update) {
    var theform = update.form;
    var toolname = theform.name;
    for (x=0; x < theform.parameter.length; x++) {
	var input = theform.parameter[x];
	// TODO CHECK FOR EXISTENCE!
	updateOneParam(input);
    }
}

function updateOneParam(input) {
    var iid = input.id;
    var pid = iid.replace(/edit/, "param");
    var param = d.getElementById(pid);
    // TODO CHECK FOR EXISTENCE!
    //param.innerHTML = input.value;
    var newTxt = document.createTextNode(input.value);
    //var dbg = d.getElementById("debugger");
    param.replaceChild(newTxt, param.firstChild);
}

