// JavaScript Document
//Cross-browser cross-frame element retrieval
function Get( oName, oFrame, oDoc ) {
	if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
	for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
	for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = Get( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
	if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = Get( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	return null;
}

// Numeric test
function isNumeric(num, fieldPrompt, fieldName) {
	var regTest=/(^\d+$)|(^\d+\.\d+$)/
	if (regTest.test(num))
		return true;
	else {
		if (fieldPrompt) { 
			alert(fieldPrompt + " Must be a valid number");
			Get(fieldName).focus();
			Get(fieldName).select();
		}
		return false;
	}
}

//Iterate thru table rows
function loopTable(tbl, fnCallback, data)
{
	
  var r, c;
  if (!tbl || !fnCallback)  
	return; 
	
  for (r = 0; r < tbl.rows.length; ++r) {
    if (false == fnCallback(tbl.rows[r], true, r, c, data)) { 
		return; 
	}
/*
    for (c = 0; c < obj.rows[r].cells.length; ++c) {
      if (false == fnCallback(obj.rows[r].cells[c], false, r, c, data)) { 
		return; 
	  }
    }*/
  }
}

/* xTableCursor - mouseover highlight on rows and cells.
   id  - table id.
   inh - inherit style.
   def - default style.
   hov - row hover style.
   sel - cell selected style.
*/
function TableObject(id, inh, def, hov, sel, alt) // object prototype
{
  var tbl = Get(id);
  if (tbl) {
    loopTable(tbl, doHover);
  }
  function doHover(obj, isRow)
  {
    if (isRow) {
	  
	  if (obj.className == alt) {
	  	//debug("got alt");
	  		obj.onmouseout = trOutAlt;
	  } else {
	  	obj.onmouseout = trOut;
	  }
      //obj.className = def;
      obj.onmouseover = trOver;
      
    }
    else {
      obj.className = inh;
      obj.onmouseover = tdOver;
      obj.onmouseout = tdOut;
    }
  }
  this.unload = function() { loopTable(tbl, clearEvents); }
  function clearEvents(o) { o.onmouseover = o.onmouseout = null; }
  function trOver() { this.className = hov; }
  function trOut() {this.className = def;}
  function trOutAlt() {this.className = alt;}
  function tdOver() { this.className = sel; }
  function tdOut() { this.className = inh; }
}

// Show the debug window
function showDebug() {
  window.top.debugWindow =
      window.open("",
                  "Debug",
                  "left=0,top=0,width=300,height=700,scrollbars=yes,"
                  +"status=yes,resizable=yes");
  window.top.debugWindow.opener = self;
  // open the document for writing
  window.top.debugWindow.document.open();
  window.top.debugWindow.document.write(
      "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE>\n");
}

// If the debug window exists, then write to it
function debug(text) {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.document.write(text+"\n");
  }
}