//****************************************************************
//****************************************************************
//	COPYRIGHT 1998-99, Vertex Software
//****************************************************************
//****************************************************************

var gImageList = "";

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// PreloadImages
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
function PreloadImages( imageDirectory, imageList ) {
	if (!imageList) imageList = gImageList;
	var imageName = imageList.split( "," );
	var index = 0;
	for (index=0; index<imageName.length; index++) {
		document.preloads = new Array();
		document.preloads[index] = new Image();
		document.preloads[index].src = imageDirectory + imageName[index] + "b.gif";
		}
	}


//****************************************************************
// SetSelectedImage
//****************************************************************
function SetSelectedImage(name) {
	if (!name) return; 
	var pictureObj = eval( "document." + name );
	if (pictureObj) {
		// HACK!!! Need to defer the execution for Netscape. Calling before the page is loaded results in teh image not being assigned.
		window.setTimeout( "document." + name + ".src = document." + name + ".src.substring( 0, document." + name + ".src.length - 'c.gif'.length ) + 'c.gif'", 200 );
		}
	}


//===========================================================
// SetSelectedLink
//===========================================================
function SetSelectedLink( name ) {
	try {
		var link = document.getElementById( name );
		if (link) link.className += " Selected"; 
		}
	catch( error ) {
		window.status = ( "SetSelectedLink: " + error.description );
		}
	}



//****************************************************************
// rollover
//****************************************************************
function rollover(name) {
	try {
		var pictureObj = document.images[name];
		if (pictureObj) {
			var mouseOutSuffix = "a.gif";
			var mouseInSuffix = "b.gif";
			var sideImgSuffix = "c.gif";
			var openedImgSuffix = "d.gif";
			var defaultSideImg = "/img/default";
			var pictureSource = pictureObj.src || "";
			if (pictureSource.toLowerCase().indexOf( sideImgSuffix ) != -1 || pictureSource.toLowerCase().indexOf(openedImgSuffix) != -1) return;
			if (pictureSource.toLowerCase().indexOf( mouseOutSuffix ) != -1) {
				// ON MOUSEIN
				if (typeof pre != "undefined" && pre[name]) {
					pictureObj.src = pre[name].src;
					}
				else {
					pictureObj.src = pictureSource.substring( 0, pictureSource.length - mouseOutSuffix.length ) + mouseInSuffix;
					}
				if (document.centerimage){
					document.centerimage.src = "img/" + name + sideImgSuffix;
					}
				} 
			else {
				// ON MOUSEOUT
				pictureObj.src = pictureSource.substring( 0, pictureSource.length - mouseInSuffix.length ) + mouseOutSuffix;
				if (document.centerimage){
					document.centerimage.src = defaultSideImg + sideImgSuffix;
					}
				}
			}
		}
	catch (error) {
		window.status = ( "rollover: " + error.description );
		}
	}




//****************************************************************
//      CreateUniqueID
//****************************************************************
function CreateUniqueID( label ) {
        var todaydate = new Date();
        var ID = "";
        ID = ID + todaydate.getHours();
        ID = ID + todaydate.getMinutes();
        ID = ID + todaydate.getSeconds();
        // this function may be used in form elements
        if ( (label) && (label != "") ) {
                return label + "=" + escape(ID);
                }
        else {
                return escape(ID);
                }
        }




//****************************************************************
// PopupWindow
//****************************************************************
function PopupWindow( URL, name, height, width, resizeable, scrollbars, windowTop, windowLeft, menubars, toolbar, location) {
	resizeable = (resizeable ? ",resizable=yes" : ",resizable=no" );
	scrollbars = (scrollbars ? ",scrollbars=yes" : ",scrollbars=no" );
	menubars = (menubars ? ",menubars=yes" : ",menubars=no" );
	toolbar = (toolbar ? ",toolbar=yes" : ",toolbar=no" );
	location = (location ? ",location=yes" : ",location=no" );
	var windowprops = "height=" + height + ",width=" + width + resizeable + scrollbars + menubars + toolbar + location;	
	// only works on IE
	if (window.screenTop) {
		windowTop = (windowTop ? window.screenTop + windowTop :  window.screenTop + 10 );
		windowLeft = (windowLeft ?  window.screenLeft + windowLeft : window.screenLeft + 50 );
		windowprops = windowprops + ",top=" + windowTop + ",left=" + windowLeft;
		}
	var newWin = window.open(URL, name, windowprops);
	newWin.focus()
	}



//****************************************************************
// CenterWindow
//****************************************************************
function CenterWindow(width,height) {
	if (height > screen.availHeight) height = screen.availHeight - 100;
	if (width > screen.availWidth) width = screen.availWidth - 100;
	var top = (screen.availHeight - height)/2;
	var left = (screen.availWidth - width)/2;
	window.resizeTo( width, height );
	window.moveTo( left, top );
	}


// ===========================================================
// ResizeIFrameParent
// ===========================================================
function ResizeIFrameParent() {
	try {
		if (document.defaultView ) {
			document.parentWindow = document.defaultView;
			document.parentWindow.window.document.readyState = "complete"
			}
		if (document.parentWindow && document.parentWindow.window.document.readyState == "complete") {
			var parentFrame = document.parentWindow.window.frameElement;
			var kScrollBarWidth = 20;
			if (!parentFrame || document.body.scrollHeight == 0) return; 
			var frameHeight = document.body.scrollHeight;//Math.max(document.body.offsetHeight, document.body.scrollHeight);
			if (parentFrame.parentNode && !parentFrame.parentElement) parentFrame.parentElement = parentFrame.parentNode;
			parentFrame.parentElement.style.height = frameHeight;
			parentFrame.style.height = frameHeight;
			if (Math.abs( (parentFrame.style.pixelWidth ||parentFrame.clientWidth) - document.body.scrollWidth) > kScrollBarWidth) {
				var frameWidth = document.body.scrollWidth;
				parentFrame.parentElement.style.width = frameWidth;
				parentFrame.style.width = frameWidth;
				}
			if (parentFrame.ownerDocument && typeof parentFrame.ownerDocument.parentWindow.ResizeIFrameParent == "function") {
				parentFrame.ownerDocument.parentWindow.ResizeIFrameParent();
				}
			}
		}
	catch( error ) {
		window.status = ( "ResizeIFrameParent: " + error.description );
		}	
	}


//===========================================================
// ClearDefaultText
//===========================================================
function ClearDefaultText( element ) {
	try {
		if (!element || element.cleared) return;
		element.cleared = 1;
		element.value = ""; 
		element.style.color = "";
		}
	catch (error) {
		window.status =( "ClearDefaultText: " + error.description  );
		}
	}



//===========================================================
// SetWindowOnLoad
//===========================================================
function SetWindowOnLoad( handlerFunction ) {
	try {
		var currentHandler = window.onload;
		if (currentHandler) {
			window.onload = function () {
				handlerFunction();
				currentHandler();
				}
			}
		else {
			window.onload = handlerFunction;
			}
		}
	catch (error) {
		window.status = ( "SetWindowOnLoad: " + error.description  );
		}
	}



//===========================================================
// DisablePageOnNavigate
// Provides feedback for user by disabling document on nav change
// and setting cursor to wait.
//===========================================================
function DisablePageOnNavigate( ) {
	try {
		if (document.body.onbeforeunload || document.body.onfocus) return;
		document.body.onbeforeunload  = function() { 
			document.body.style.cursor = "wait";
			// 10JAN2009 RFM - if run immediately, block clicks on links w/ submits!
			//document.body.disabled = true;		
			window.setTimeout("document.body.disabled = true",100);
			}
		document.body.onfocus = function() {
			document.body.style.cursor = "default"; 
			document.body.disabled = false; 
			}
		}
	catch (error) {
		window.status = ( "DisablePageOnNavigate: " + error.description  );
		}
	}
