/**
 * marx_eib.js
 */ 

//97, 123, 44, 71, 169, 146,  - errors in ASP?
//If the page is wide, write the image with the following parameters into the page source:
//s => the src, t => the alt text, c => classname (if any), m=> whatever usemap is (if any)

/* This function is not called anywhere else in the code as of 8/16/06 - Neil
function writeImage(s,t,c,m) {
	if (isWide)
		document.write("<img src='"+s+"' alt='"+t+"'"+
					   (c!=""?" class='"+c+"'":"")+
					   (m!=""?" usemap='"+m+"'":"")+">");
}
*/

var tb_array=null;  //String[] - stores the .innerHTML for each tab
var tb_count=-1;	//int - stores 2 less than the number of tables (doesn't count tabtop or rwph)
var currentTab=-1; 		//int - stores the index of the "Chosen tab"
var tblMaxHeight=0; //int - stores the height of the largest tab
var timp=null; 		//boolean[]

function selectTab(i) {
	var cPh;
	if (tb_array != null) {
		if (currentTab>-1) {
			//makes previous tab selection "Normal" again
			cPh = element('tbh_' + currentTab);
			cPh.className = 'Normal';
		}
		//selects the "i"th tab:
		//    - loads its corresponding content pane
		//    - make the tab "Hilited"
		cPh = element('tbc_0');
		cPh.innerHTML = tb_array[i];
		cPh = element('tbh_' + i);
		cPh.className = 'Hilite';
		currentTab = i;
	}
}

//initialize tabs and content arrays
function tabInit() {
	doTrace("tab_init");
	var tabTable = element('tbt'); //table top - not null
	if (tabTable != null) {
		var node;
		var tmp = 0;
		element('rwph').style.visibility='visible'; // in default.asp, this is only a &nbsp; (an empty space)
		tb_array = new Array();
		timp = new Array();
		tb_count = tabTable.rows.length-2;
		for(var x = 0; x < tb_count; x++) {
			/**
			 * 1) copies the innerHTML (content) of each content td into tb_array
			 * 2) "hides" each content td (and removes the content)
			 * 3) makes every tab "Normal"
			 */
			node = element('tbh_' + x);
			node.className='Normal';
			node = element('tbc_' + x);
			tb_array[x] = node.innerHTML;
			timp[x] = false;
			node.className = "HideTab";
			node.innerHTML = "";
		}
		node = element('tbc_0');
		node.rowSpan = tabTable.rows.length-1;
		node.className = 'Content';
		selectTab(0); //selects the first row (probably not necessary, since repeated later)
		try {
			for(var x = 0; x < tb_count; x++){
				//goes through each content td to find the max height for the table
				selectTab(x);
				node = element('tbc_0');
				tblMaxHeight = ((node.offsetHeight > tblMaxHeight) ?
								 node.offsetHeight : tblMaxHeight);
			}
		} catch (someError) { } //in case there was some error, catch it and do nothing with it
		selectTab(0); //re-select tab 0

		//subtract the tab height (25px) from the content pane's max height
		var n = tblMaxHeight - (tb_count * 25);
		//make up the difference between the combined size of each tab and the content pane's max height
		//by adding height to the footer (cell "tbph" in row "rwph")
		element('tbph').style.height =  ( (n > 0) ? n + 10 : 10) + 'px';
	}
	doTrace(" tb_count = " + tb_count);
	doTrace(" tblMaxHeight = " + tblMaxHeight);
	doTrace(" finished.");
}

var ctb = 0;
//processes some keyboard event and if the keyCode == 13 or 32 (I can only assume what those are)
//then, selects tab corresponding to ctb
function keyProcess(object) {
	var keyCode;
	keyCode=(window.event != null && window.event.keyCode != null)
	   ? window.event.keyCode : e.which;
	if (keyCode==null && object !=null && object.keyCode !=null)
		keyCode=object.keyCode1;
	if (keyCode==13||keyCode==32) { //<enter> and <tab>
		SelectTab(ctb);
		setTimeout("element('mrq_'+ctb).focus()",1); //focuses on the marquis in about 1ms.
		return false;
	}
	return keyCode;
}

