/********************************************/
/*   Handcode Toolkit v1.1                  */
/*   Copyright 2004 Incus Web Works         */
/********************************************/


//SMUSA-specific function to add variable onto url
 function reloadParentPageJS(rec){
  loc = new String((parent.window.location+"?"));
  parent.window.location = loc.slice(0, (loc.indexOf("?")))+"?rec="+rec;
  
 }

/* Menu Functions */
// Uses some functions from "Layout Functions"

function _B (text, Link, Frame) {
 _button (text, Link, Frame, 'B', '', '', '');
}

//created for special use...
function _B2 (text, Link, Frame) {
 _button2 (text, Link, Frame, 'B2', '', '', '');
}

function _SM (text, subID) {
 _subMenuButton (text, subID, 'B', '', '', '');
}
function _S (text, Link, Frame, subID) {
 _subMenuLink (text, Link, Frame, subID, 'S', '');
}

//writes div
function _D (ID, C, S){ document.write("<div id="+ID+" class=\""+C+"\" style=\""+S+"\">"); }
//closes div
function _C (){ document.write("</div>"); }
//writes menu button 
function _button (text, Link, Frame, Class, Style, Over, Out){ document.write("<div class=\""+Class+"\" style=\""+Style+"\" onMouseOver=\"_BOver(this, '"+Over+"')\" onMouseOut=\"_BOut(this, '"+Out+"')\" onMouseDown=\"_go('"+Link+"', '"+Frame+"')\">"+text+"</div>"); }

//created for special use...
function _button2 (text, Link, Frame, Class, Style, Over, Out){ document.write("<div class=\""+Class+"\" style=\""+Style+"\" onMouseOver=\"_B2Over(this, '"+Over+"')\" onMouseOut=\"_B2Out(this, '"+Out+"')\" onMouseDown=\"_go('"+Link+"', '"+Frame+"')\">"+text+"</div>"); }

function _subMenuButton (text, subID, Class, Style, Over, Out){ document.write("<div class=\""+Class+"\" style=\""+Style+"\" onMouseOut=\"_hideWait('"+subID+"'); _SMOut(this, '"+Out+"')\" onMouseOver=\"_show('"+subID+"'); _SMOver(this, '"+Over+"')\">"+text+"</div>"); }
function _subMenuLink (text, Link, Frame, parentID, Class, Style){ document.write("<div class=\""+Class+"\" style=\""+Style+"\" onMouseOut=\"_hideWait('"+parentID+"'); _SOut(this)\" onMouseOver=\"_show('"+parentID+"'); _SOver(this)\" onMouseDown=\"_go('"+Link+"', '"+Frame+"')\">"+text+"</div>"); }
//goes to a locaiton
function _go(Link, Frame){
 if (Frame) _getRef(Frame).src=Link;
 else window.location = Link; }
//shows object
tID=0;
OpenID=0;
function _show(ID){
	if (tID || OpenID) _clearHide();
	_getSty(ID).display="block";
	OpenID=ID;
}
//hides object after T milliseconds
T=700;
function _hideWait(ID){
	tID = setTimeout('_hide("'+ID+'")', T);
}
function _hide(ID){
	_getSty(ID).display="none";
	OpenID=0;
}
function _clearHide(){
	if (tID) clearTimeout (tID);
	if (OpenID) _hide(OpenID);
}


/* Layout Functions */

//These variables define the minimum size of the browser window
MinWidth = 800;
MinHeight = 600;
//compatability code
var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;
var isIE4=isIE&&!isDOM?1:0;
var isOp=window.opera?1:0;
var isWin=navigator.platform.indexOf('Win')!=-1?1:0;
var isDyn=isDOM||isIE||isNS4;
var px=isNS4||isOp?0:"px"; 
var CSSmode=document.compatMode;
CSSmode=(CSSmode&&CSSmode.indexOf('CSS')!=-1)||isDOM&&!isIE||isOp?1:0;
function _getRef(id, par) {
 par=!par?document:(par.navigator?par.document:par);
 return isIE ? par.all[id] :
  (isDOM ? (par.getElementById?par:par.ownerDocument).getElementById(id) :
  (isNS4 ? par.layers[id] : null));
}
function _getSty(id, par){
 var r=_getRef(id, par);
 return r?(isNS4?r:r.style):(isNS4?id:id.style);
}
//object positioning, width & height functions
function _top(id, value, par){
 var sty=_getSty(id, par);
 sty.top=(value?value:0)+px;
}
function _left(id, value, par){
 var sty=_getSty(id, par);
 sty.left=(value?value:0)+px;
}
function _width(id, value, par){
 var sty=_getSty(id, par);
 sty.width=(value?value:0)+px;
}
function _height(id, value, par){
 var sty=_getSty(id, par);
 sty.height=(value?value:0)+px;
}
//page object constructor
if (!window.page) var page = { win: window, minW: MinWidth, minH: MinHeight, MS: isIE&&!isOp, db: CSSmode?'documentElement':'body' }
//function returns window width
page.winW=function() { with (this) return Math.max(minW, MS?win.document[db].clientWidth:win.innerWidth-15) }
//function returns window height
page.winH=function() { with (this) return Math.max(minH, MS?win.document[db].clientHeight:win.innerHeight) }
//onLoad and onResize functions
window.onload = function() {
 _position();
 if (Print) window.print();
 if (Dev) _updateDev();
}
window.onresize = function() { _position(); }
//array to hold all div objects
var divs = Array();
//div object constructor
function div (id, x, y, w, h){ this.id = id; this.x = x; this.y = y; this.w = w; this.h = h; }
//function creates div object
divCount = 0;
function _locate (id, x, y, w, h){
 divs[divCount] = new div(id, x, y, w, h);
 //this line allows reference to div properties directly via id: e.g. div.{divID}.x
 eval ('div.'+id+' = new div(id, x, y, w, h)');
 ++divCount;
}
//function creates div object
function _build (id, x, y, w, h, c, s, t){
 _D(id, c, s);
 document.write(t);
 _C();
 _locate (id, x, y, w, h);
}
//function positions div objects
function _position() {
//only run these functions once
 winW = page.winW();    //no max width
 //widthMax = 1000;  winW = page.winW()<widthMax ? page.winW() : widthMax;   //set max width as "widthMax" 
 winH = page.winH();    //no max height
 //heightMax = 800;  winH = page.winH()<heightMax ? page.winH() : heightMax;   //set max height as "heightMax"
 //calculates center
 xCenter = winW/2;
 yCenter = winH/2;
 //claculates left margin for a center-associated object
 xZero = winW/2-MinWidth/2;
 yZero = winH/2-MinHeight/2;
 for (var i = 0; i < divs.length; i++) {
  //'if statement' prevents error if div does not exist in page
  if (_getRef(divs[i].id)) {
   _left(divs[i].id, eval(divs[i].x)); 
   _top(divs[i].id, eval(divs[i].y)); 
   // Don't let the width and height get below 0.    
   if (divs[i].w) _width(divs[i].id, Math.max(0,eval(divs[i].w)));
   if (divs[i].h) _height(divs[i].id, Math.max(0,eval(divs[i].h)));
   _getSty(divs[i].id).visibility="visible";
  }
 }
}
//set Print to "true" on pages that you want to have auto-print
var Print = false;

//Developer Assistance Functions - call initDev() on pages that you want to run developer assistance
var Dev = false;
var mouseX = 0;
var mouseY = 0;
if (isNS4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = _getMousePosition;

function _getMousePosition(e) {
 if (isNS4){
  mouseX = e.pageX;
  mouseY = e.pageY;
 }
 if (isIE){
  mouseX = event.clientX + document.body.scrollLeft;
  mouseY = event.clientY + document.body.scrollTop;
 }
 return true;
}
function initDev(){
 statsWindow = window.open("","statsWindowLink", "toolbar=0, menubar=0, width=150, height=150, top=10, left=10");
 statsWindow.document.write('<div id="info_" style="font-family: arial; font-size: 12px; color: #000000;">X: <input style="border: none; font-family: arial; font-size: 12px; width: 35px" id="Xpositon_" value="0"><br>Y: <input style="border: none; font-family: arial; font-size: 12px; width: 35px" id="Ypositon_" value="0"><br>X-Center-Offset: <input style="border: none; font-family: arial; font-size: 12px; width: 35px" id="XCenterOffset_" value="0"><br>Y-Center-Offset: <input style="border: none; font-family: arial; font-size: 12px; width: 35px" id="YCenterOffset_" value="0"><br>Window Width: <input style="border: none; font-family: arial; font-size: 12px; width: 35px" id="WindowWidth_" value="0"><br>Window Height: <input style="border: none; font-family: arial; font-size: 12px; width: 35px" id="WindowHeight_" value="0"></div>');
 statsWindow.document.close();
 Dev = true;
}
function _updateDev(){
 statsWindow.Xpositon_.value = mouseX;
 statsWindow.Ypositon_.value = mouseY;
 statsWindow.XCenterOffset_.value = mouseX-xCenter;
 statsWindow.YCenterOffset_.value = mouseY-yCenter;
 statsWindow.WindowWidth_.value = winW;
 statsWindow.WindowHeight_.value = winH;
 setTimeout('_updateDev()', 50);
 return;
}
