var currPopup = null;
var currFocus = null;
var lastFocus = null;
var currSubMenu = null;
var currButton = null;

/**********************************************************************************/
//		Open Menus Section
/**********************************************************************************/
// Hide sub menus after pressing
function HideSubMenu (btnObj, simpleBtnMode)
{
	OnMouseOutOnMenu(btnObj);
	
	if (currPopup != null && simpleBtnMode == 1) {
		currPopup.hide();
	}
}
// Hide menus after pressing
function HideMenu ()
{
	if (currPopup != null) 	{
		currPopup.hide();
	}
}
// Used to open first level menus from the buttons
function OpenMenu (btnObj,id,subMenu)
{
	var oPopup = window.createPopup();
	if (!document.all[id])
		return;
		
	btnObj.className = "ButtonOpenMenu";
	var oPopupBody = oPopup.document.body;

	oPopup.document.write (document.all[id].innerHTML);
	oPopup.document.body.className = "PopUp";
	menuObj = document.all[id];
	currPopup = oPopup;
	oPopup.document.window = oPopup;
	currFocus = oPopup.document.body;
	btnObj.setActive ();
	mainWin = oPopup.parent;
	OnMouseOverOnBtn (btnObj);
	if (subMenu == 1) {
		OpenSubMenu (btnObj,id,oPopup);
	}
	else {
			oPopup.show (0,							//Left
						btnObj.offsetHeight - 3,	//Top
						(document.all[id].offsetWidth)*2, // Width
						(document.all[id].offsetHeight)*1.25, // Height
						btnObj); // Relative Object
			if (currButton != null) {
				FireOnMouseOutEvent (currButton);
				currButton = null;
			}
	}
	btnObj.axis = "1";
	event.keyCode = 0 ;
	event.cancelBubble = true;
	event.returnValue = false;
}
// Opens all of the sub menus
function OpenSubMenu (btnObj,id,oPopup)
{
	if (!document.all[id])
		return;
	
	btnObj.className = "ButtonOpenMenu";
	var oPopupBody = oPopup.document.body;
	oPopup.document.write (document.all[id].innerHTML);

	oPopup.document.body.className = "PopUp";
	menuObj = document.all[id];
	// use parentNode - in order to get the tr object, where the btn is located 
	var parentObj = GetBrowserParentWindow (btnObj.document).event.srcElement;
	if(parentObj.tagName != 'TR')
		parentObj = parentObj.parentNode;
	if(parentObj.tagName != 'TR')
		parentObj = parentObj.parentNode;
	if ((window.screenLeft + btnObj.clientWidth + ((document.all[id].offsetWidth)*2)) > screen.availWidth) {
		// Will pass the edge of the screen, so open to the left
		oPopup.show((((document.all[id].offsetWidth)*2) * -1), // left
						btnObj.clientTop, //top
						(document.all[id].offsetWidth)*2, // Width
						(document.all[id].clientHeight)*1.25, // Height
						parentObj); // Relative Object
	}
	else
		oPopup.show(btnObj.clientWidth, // left
						btnObj.clientTop, //top
						(document.all[id].offsetWidth)*2, // Width
						(document.all[id].clientHeight)*1.25, // Height
						parentObj); // Relative Object
	try {
		btnObj.all['PDSubHotKeyDiv'].className = "MenuMouseOver";
		btnObj.all['PDSubCapDiv'].className = "MenuMouseOver";
	}
	catch (e) {
	}
	var coll = GetBrowserElementsByTagName (oPopup.document.body, "input")
	var level = 0;
	if (coll!=null && (coll.length > 0)) 
		level = coll[0].getAttribute ("Level");
	
	var parentWindow = GetBrowserParentWindow (oPopup.document.parentWindow);
	var win = FindParent(parentWindow, 0,level);
	win.lastFocus = win.currFocus;
	win.currFocus = oPopup.document.body;
	currPopup = oPopup;
}
// Finds the parent window of the sub menu
function FindParent (win, currLvl, wantedLvl)
{
	var wanted = parseInt(wantedLvl)
	winParent = null;
	if ((currLvl >= wanted))
		return win;
	else 
		winParent = FindParent (win.parent, currLvl + 1, wantedLvl);
	
	return winParent;
}
/**********************************************************************************/
//		Event Handlers Section
/**********************************************************************************/
// Event handler for clicks on a Button, not that this does not launch the defined event (key up does)
function OnBtnPressed (btnObj)
{
	if (btnObj == null || btnObj.Event == null || btnObj.Event == "") {
		alert ("OnBtnPressed Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true)
		return;
	// Need to be replaced with CSS!!
	btnObj.className		= "ButtonPressed";
	btnObj.axis				= "1"
}
// Event handler for clicking on a menu button
function OnMenuBtnPressed (btnObj)
{
	if (btnObj == null || btnObj.Event == null || btnObj.Event == "") {
		alert ("OnMenuBtnPressed Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true)
		return;
	currFocus = null;
	lastFocus = null;
	try {
		parent.currFocus = null;
		parent.location.href	= btnObj.Event;
		if ((window.parent.document.activeElement != null) &&
			(window.parent.document.activeElement.axis == "1"))
			document.window.hide ();
		window.parent.document.activeElement.axis = "0";
		OnMouseOutOnBtn(window.parent.document.activeElement);
	}
	catch (e) {
		try {
			window.parent.parent.document.activeElement.axis = "0";
			OnMouseOutOnBtn(window.parent.parent.document.activeElement);
			parent.parent.location.href	= btnObj.Event;
			document.window.hide ();
			parent.document.window.hide ();
		}
		catch (e) {
			try {
				window.parent.parent.parent.document.activeElement.axis = "0";
				OnMouseOutOnBtn(window.parent.parent.parent.document.activeElement);
				parent.parent.parent.location.href	= btnObj.Event;
				document.window.hide ();
			}
			catch (e) {
				try {
					parent.parent.parent.parent.location.href	= btnObj.Event;
					document.window.hide ();
				}
				catch (e) {
					alert("OnMenuBtnPressed Error! " + e.message);
				}
			}
		}
	}
}
// Event handler for Focus out of the buttons, after pressing
function OnBtnLeave (btnObj)
{
	if (btnObj == null) {
		alert ("OnBtnLeave Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true)
		return;
	//btnObj.className		= "BorderStandard";
	btnObj.axis				= "0"
	try {
		window.location.href	= btnObj.Event;
		OnMouseOutOnBtn(btnObj);
	}
	catch (e) {
		alert("OnBtnLeave " + e.message);
	}
}
// Event Handler for Mouse over of the Buttons
function OnMouseOverOnBtn(btnObj)
{
	if (btnObj == null) {
		alert ("OnMouseOverOnBtn Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true)
		return;
	if (document.activeElement == null)
		return;
		
	if (btnObj.axis != "1") {
		btnObj.className = "ButtonMouseOver";
	}
}
// Event Handler of the mouse over of the menus
function OnMouseOverOnMenu(btnObj)
{
	OnMouseOverMenu (btnObj);
}
// Fucntion for Event Handler of the mouse over of the menus
function OnMouseOverMenu(btnObj)
{
	if (currFocus != null)
		FireOnMouseOutEvent (currFocus);
	currFocus = btnObj;
	var coll = GetBrowserElementsByTagName (currFocus,"input");
	if (coll!=null && (coll.length > 0)) {
		currFocus = coll[0];
	}
	if (btnObj == null) {
		alert ("OnMouseOverMenu Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true)
		return;
	btnObj.className = "MenuMouseOver";
	try {
		btnObj.all['PDHotKeyDiv'].className = "MenuMouseOver";
		btnObj.all['PDCapDiv'].className = "MenuMouseOver";
	}
	catch (e) {
	}
	try {
		btnObj.all['PDSubHotKeyDiv'].className = "MenuMouseOver";
		btnObj.all['PDSubCapDiv'].className = "MenuMouseOver";
	}
	catch (e) {
	}
	try {
		btnObj.all['PDMenuHotKeyDiv'].className = "MenuMouseOver";
		btnObj.all['PDMenuCapDiv'].className = "MenuMouseOver";
	}
	catch (e) {
	}
}
// Event handler for focus out of the menus, after pressing
function OnMouseOutMenu(btnObj)
{
	if (btnObj == null) {
		alert ("OnMouseOutMenu Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true)
		return;
	if (btnObj.all['PDCapDiv'] != null) {
		btnObj.all['PDCapDiv'].className = "";
	}
	if (btnObj.all['PDHotKeyDiv'] != null) {
		btnObj.all['PDHotKeyDiv'].className = "";
	}
	try {
		btnObj.all['PDSubHotKeyDiv'].className = "";
		btnObj.all['PDSubCapDiv'].className = "";
	}
	catch (e) {
	}
	try {
		btnObj.all['PDMenuHotKeyDiv'].className = "";
		btnObj.all['PDMenuCapDiv'].className = "";
	}
	catch (e) {
	}
}
// Event Handler for Mouse over of the Buttons, after pressing
function OnMouseOutOnBtn(btnObj)
{
	if (btnObj == null) {
		alert ("OnMouseOutOnBtn Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true) {
		alert ("OnMouseOutOnBtn Button is disabled");
		return;
	}
	if (btnObj.axis != "1")
		btnObj.className = "BorderStandard";
}
// Event Handler for Mouse over of the Menus, after pressing
function OnMouseOutOnMenu(btnObj)
{
	if (btnObj == null) {
		alert ("OnMouseOutOnMenu Error in XML-XSL merge please call Lab IT!");
		return;
	}
	if (btnObj.disabled == true) {
		alert ("OnMouseOutOnMenu Button is disabled");
		return;
	}
	btnObj.className = "Menu";
}

/**********************************************************************************/
//		Keys Section
/**********************************************************************************/
// Key Down event
function getKeyDown(keyStroke) {
	if (((event.keyCode <= 40) && (event.keyCode >= 37)) || (event.keyCode == 13)) {
		ArrowKeys (event.keyCode);
		return;
	}
	if (SpecialKey ())
		return getKey(event.keyCode);
	return false ;
}
// Key Press Event
function getKeyPress(keyStroke) {
	if (!SpecialKey ())
		return getKey(event.keyCode); 
	return false ;
}
// Some keys are captured on the key press and some on the key down, this function makes sure that
// all of them are handled
function SpecialKey () {
	// Esc
	if ((event.keyCode == 27) && (currButton != null)) 
		FireOnMouseOut (currButton);
		
	// a-z + alt
	if (((event.keyCode) >= 65) && ((event.keyCode) <= 90) && (event.altKey)) 
		return true;
		
	// a-z + ctrl
	if (((event.keyCode) >= 65) && ((event.keyCode) <= 90) && (event.ctrlKey)) 
		return true;
		
	// function keys
	if (((event.keyCode) >= 112) && ((event.keyCode) <= 123)) 
		return true;
	
	switch (event.keyCode) {
		case (70):
			if (event.ctrlKey)
				return true; break;
		case (8):
		case (27):
		case (32):
		case (35):
		case (43):
		case (46):
			return true;
	}
	return false;
}
// Arrow keys director
function ArrowKeys(keyStroke)
{
	if (currFocus == null)
		return;
	switch (keyStroke) {
		case (40) : //down
			SelectNextSiblingMenu (); break;
		case (38) : //up
			SelectPrevSiblingMenu (); break;
		case (13) : // enter
				SelectMenu (); 
			break;
		case (39) : // left
			SelectSubMenu (); break;
		case (37) : // up
			SelectParentMenu (); break;
	}
	event.keyCode = 0 ;
	event.cancelBubble = true;
	event.returnValue = false;
}
// Used to find the first child menu after opening a sub menu
function SelectNextChildMenu()
{
	if (currFocus == null)
		return;
	var coll = GetBrowserElementsByTagName (currFocus, "input");
	if (coll!=null && (coll.length > 0)) {
		FireOnMouseOverEvent (coll[0]);
		currFocus = coll[0];
	}
	
}
// Enter after navigating with the arrow keys
function SelectMenu()
{
	if (currFocus == null)
		return;
	var tag = currFocus.getAttribute ("ButtonId");
	var parentWindow = GetBrowserParentWindow (currFocus.document);
	var menu = parentWindow.document.getElementById(tag);
	if (menu==null)
		return;
	currFocus = null;
	FireOnMouseDownEvent (menu);
}
// Up key from a menu
function SelectParentMenu ()
{
	if (currFocus == null)
		return;
	var parentObj = document.all[currFocus.getAttribute ("ButtonId")];
	var level = currFocus.getAttribute ("level");
	if ((parentObj != null) && ((level == "1") || (level == "0")))
		FireOnMouseOutEvent (parentObj);
	currFocus.document.parentWindow.parent.currPopup.hide (); 
	currFocus = lastFocus;
}
// left key from a menu
function SelectSubMenu()
{
	if (currFocus == null)
		return;
	var tag = currFocus.getAttribute ("ButtonId");
	var level = currFocus.getAttribute ("Level");
	var parentWindow = GetBrowserParentWindow (currFocus.document);
	var menu = parentWindow.document.getElementById(tag);
	if (menu==null)
		return;
	if ((level == "-1") || (level == "-2") || (level == "0")) {
		FireOnClickEvent (menu);
	}
	else {
		menu.fireEvent ("onmouseenter");
		FireOnMouseOverEvent (menu);
		SelectNextChildMenu ();
	}
}
// down key from a menu
function SelectNextSiblingMenu()
{
	if (currFocus==null)
		return;
	var tag = currFocus.getAttribute ("ButtonId");
	var level = currFocus.getAttribute ("Level");
	var parentWindow = GetBrowserParentWindow (currFocus.document);
	var coll = GetBrowserElementsByTagName (parentWindow.document, "input");
	if (coll==null)
		return;
	var i = 0;
	var next = 0;
	var found = false;
	for (var btn in coll) {
		if (coll[i] != null){
			var currTag = coll[i].getAttribute ("ButtonId");
			var currLevel = coll[i].getAttribute ("Level");
			if ((found) && (currLevel == level)) {
				next = i;
				found = false;
			}
			if (currTag == tag)
				found = true;
		}
		i = i + 1;
	}	
	if ((next >= coll.length) || (next < 0))
		return;
	FireOnMouseOverEvent (coll[next]);
	currFocus = coll[next];
}
// Right key from a menu
function SelectPrevSiblingMenu()
{
	if (currFocus==null)
		return;
	var tag = currFocus.getAttribute ("ButtonId");
	var level = currFocus.getAttribute ("Level");
	var parentDocument = GetBrowserParentWindow (currFocus.document);
	var coll = GetBrowserElementsByTagName (parentWindow.document, "input");
	if (coll==null)
		return;
	var i = coll.length - 1;
	var next = 0;
	var found = false;
	var lastLevel = -1;
	for (var btn in coll) {
		if (coll[i] != null){
			var currTag = coll[i].getAttribute ("ButtonId");
			var currLevel = coll[i].getAttribute ("Level");
			if ((currLevel == level) && (lastLevel == -1)) 
				lastLevel = i;
			if ((found) && (currLevel == level)) {
				next = i;
				found = false;
			}
			if (currTag == tag)
				found = true;
		}
		i = i - 1;
	}	
	if (found)
		next = lastLevel;
	if ((next >= coll.length) || (next < 0))
		return;
	FireOnMouseOverEvent (coll[next]);
	currFocus = coll[next];
}
//Function to handle all keystrokes, except for arrow keys
function getKey(keyStroke) {
	var coll = GetBrowserElementsByTagName (document, "input"); // input controls house the connection between the key and the td with the event
	if (coll!=null){
		i = 0
		var found = false;
		for (var btn in coll) { // Find the correct input control in all of the possible inputs
			if (coll[i] != null){
				if (!found) {
					found = CheckHotKey (coll[i], event); // Check the current input against the keys pressed
					if (found) {
						var extraMenu = coll[i].getAttribute ("MainMenuId");
						var extraMenus = document.getElementById(extraMenu);
						if (extraMenu != null) { // Extra Menu at the end of the toolbar
							var subMenu = coll[i].getAttribute ("SubMenuId");
							if (document.getElementById(subMenu)) {
								OpenMenu(extraMenus,subMenu,0);
								// To make the menu disappear after pressed
								if ((window.parent.document.activeElement != null) &&
									(coll[i].getAttribute ("IfMenuButton") != "1"))
									window.parent.document.activeElement.axis = "1";

								FireOnMouseOutEvent (document.getElementById(extraMenu));
								document.getElementById(extraMenu).visible = true;
								SelectNextChildMenu ();
							}
							currButton = extraMenus;
						}
						else if ( // Open a button menu
							(document.all[coll[i].getAttribute ("MenuId")] != null ) &&
							event.ctrlKey
						) {
							FireOnClickEvent(document.all[coll[i].getAttribute ("MenuId")]);
							SelectNextChildMenu ();
							currButton = document.all[coll[i].getAttribute ("MenuId")];
						}
						else { // Button event
							FireOnMouseDownEvent (coll[i]);
							//alert ("fired");
							// On the menu buttons, the event is run on the mousedown. 
							// On regular buttons, on the mouseup
							if (coll[i].getAttribute ("IfMenuButton") != "1") {
							
								var runMe = "FireOnMouseUpEvent(document.all['" + coll[i].getAttribute ("ButtonId") + "'])";
								setTimeout (runMe, 500);
							}
						}
						// report key was used
						//window.status = "key : "+coll[i].getAttribute ("ButtonId")+coll[i].getAttribute ("MenuId");
						event.keyCode = 0 ;
						event.cancelBubble = true;
						event.returnValue = false;
						//alert ("Function Event!");
						return true;
					}
				}
			}
			i++;
		}
	}
	// Return that the key was not used
	event.keyCode = 0 ;
	event.cancelBubble = true;
	event.returnValue = true;
	return false ;
}
// Function to check the keys pressed against a specific input control
function CheckHotKey (obj, eventObj)
{
	if (CheckFunctionKeys(obj, eventObj)) { // Non-alpha-numeric keys
		return true;
	}
	//alert (event.keyCode);
	if (!IsAlphaNumeric (event.keyCode))
		return false;
		
	// alpha-numeric keys	
	var keyCode = event.keyCode;
	var hotKey = obj.getAttribute ("Hotkey");
	if (hotKey == null)
		return false;
	var which = "";
	which += ControlKeyString (eventObj);
	which += String.fromCharCode(keyCode).toUpperCase();
	//alert (which);
	return (hotKey == which) // if found
}
function IsAlphaNumeric(keycode)
{				// 0 - 9							A - Z
	return ((keycode >= 48 && keycode <= 57) || (keycode >= 65 && keycode <= 90)); 
}
// Check string for control keys to be added to the key pressed
function ControlKeyString (eventObj)
{
	var which = "";
	if (eventObj.altKey && !eventObj.ctrlKey && !eventObj.shiftKey)
		which += "A|";
	else if (eventObj.altKey && !eventObj.ctrlKey && eventObj.shiftKey)
		which += "AS|";
	else if (eventObj.ctrlKey && !eventObj.altKey && !eventObj.shiftKey)
		which += "C|";
	else if (eventObj.ctrlKey && !eventObj.altKey && eventObj.shiftKey)
		which += "CS|";
	else if (eventObj.shiftKey && !eventObj.ctrlKey && !eventObj.altKey)
		which += "S|";
	else
		which += "N|";
	return which;
}
// checks the input string to the string of the keys pressed for those that do not
// have a alpha-numeric representation
function CheckFunctionKeys (obj, eventObj)
{
	var hotKey = obj.getAttribute ("Hotkey");
	if (hotKey == null)
		return false;
		
	var addKey = hotKey.substring (0, hotKey.indexOf ('|'));
	if (addKey == null)
		addKey = "";
	var checkString = hotKey.substring (hotKey.indexOf ('|') + 1).toUpperCase  ();
	if (checkString == null)
		checkString = "";
	var boolVal = false;
	var sendEvent = true;
	// Switch is for special keys that do not have a alpha-numeric representation
	switch (eventObj.keyCode) {
		case 8:
			boolVal = (checkString == "BACKSPACE"); sendEvent = false; break;
		case 27:
			if (currButton != null) {
				FireOnMouseOutEvent(currButton);
			}
			boolVal = (checkString == "ESC"); sendEvent = false; break;
		case 32:
			boolVal = (checkString == "SPACEBAR"); sendEvent = false; break;
		case 35:
			boolVal = (checkString == "END"); sendEvent = false; break;
		case 36:
			boolVal = (checkString == "HOME"); sendEvent = false; break;
		case 43:
			boolVal = (checkString == "+"); sendEvent = false; break;
		case 46:
			boolVal = (checkString == "DEL"); sendEvent = false; break;
		case 112:
			boolVal = (checkString == "F1"); break;
		case 113:
			boolVal = (checkString == "F2"); break;
		case 114:
			boolVal = (checkString == "F3"); break;
		case 115:
			boolVal = (checkString == "F4"); break;
		case 116:
			boolVal = (checkString == "F5"); break;
		case 117:
			boolVal = (checkString == "F6"); break;
		case 118:
			boolVal = (checkString == "F7"); break;
		case 119:
			boolVal = (checkString == "F8"); break;
		case 120:
			boolVal = (checkString == "F9"); break;
		case 121:
			boolVal = (checkString == "F10"); break;
		case 122:
			boolVal = (checkString == "F11"); break;
		case 123:
			boolVal = (checkString == "F12"); break;
	}
	if (boolVal) {
		var which = ControlKeyString (eventObj);
		if (eventObj.ctrlKey && !eventObj.altKey && !eventObj.shiftKey){
			if( document.all[obj.getAttribute ("MenuId")] != null )
				return true ;
		}
		var chkString = (addKey + "|") == which; // returns if the keystring matches the keystring of the input
		return chkString;
	}
	return false;
}

/**********************************************************************************/
//		Fade Section
/**********************************************************************************/

nereidFadeObjects = new Object();
nereidFadeTimers = new Object();

/*
* object - image to be faded (actual object, not name);
* destop - destination transparency level (ie 80, for mostly solid)
* rate   - time in milliseconds between trasparency changes (best under 100)
* delta  - amount of change each time (ie 5, for 5% change in transparency)
*/
function nereidFade(object, destOp, rate, delta)
{
	if (!document.all)
		return
	if (object != "[object]")
	{
		//do this so I can take a string too
		setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
		return;
	}
	clearTimeout(nereidFadeTimers[object.sourceIndex]);
	diff = destOp-object.filters.alpha.opacity;
	direction = 1;
	if (object.filters.alpha.opacity > destOp)
	{
		direction = -1;
	}
	delta=Math.min(direction*diff,delta);
	object.filters.alpha.opacity+=direction*delta;
	if (object.filters.alpha.opacity != destOp)
	{
		nereidFadeObjects[object.sourceIndex]=object;
		nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
	}
}

function CheckEnabled (button)
{
	if (button == null)
		return;
	if (button.all == null)
		return;
	if (button.all.length == 0)
		return;
	for (i = 0; i < button.all.length; i++)
		button.all(i).disabled = button.disabled;
}

//code that disables the section capability
function disableselect(e){
	return false
}
function reEnable(){
	return true
}
//if IE4+
//document.onselectstart=new Function ("return false")
//if NS6
/*if (window.sidebar)
{
	document.onmousedown=disableselect
	document.onclick=reEnable
}*/

/****************************************/
/*			scrolling yes/no (New)		*/
/****************************************/
var TAG = "IFRAME";
var setIframeHeightActivated	= false;
var setScrollActivated			= false;
var onResizeHandler				= null;
var CusHeightExt				= 25;
var CusWidthExt				    = 10;

function SetScroll ()
{
	setScrollActivated = true;
	setTimeout ("SettingScrollAfterDelay ();", 100);	
}


var CURR_BODY_CLASS = "";
function SettingScrollAfterDelay ()
{
	
	if (CURR_BODY_CLASS == "" && document.body.className != "")
		CURR_BODY_CLASS = " " + document.body.className + " ";
	
	if (document.body.scrollWidth > document.body.clientWidth &&
		document.body.scrollHeight > document.body.clientHeight && 
		document.body.scrollWidth - document.body.clientWidth > CusWidthExt &&
		document.body.scrollHeight - document.body.clientHeight > CusHeightExt) {			
		document.body.className =  "OverFlowHidden OverFlowXscroll OverFlowYscroll" + CURR_BODY_CLASS;		
	}			
	else if (document.body.scrollWidth > document.body.clientWidth && document.body.scrollWidth - document.body.clientWidth > CusWidthExt) {					
			document.body.className =  "OverFlowHidden OverFlowXscroll OverFlowYhidden" + CURR_BODY_CLASS;		
	}
	else if (document.body.scrollHeight > document.body.clientHeight && document.body.scrollHeight - document.body.clientHeight > CusHeightExt){			
		document.body.className =  "OverFlowHidden OverFlowXhidden OverFlowYscroll" + CURR_BODY_CLASS;
	 }
	 else
		document.body.className =  "OverFlowHidden OverFlowXhidden OverFlowYhidden" + CURR_BODY_CLASS;
	
	
	if (document.getElementById && !(document.all)) { //FF
		document.body.className =  "OverFlowAuto " + CURR_BODY_CLASS;		
	}
}
function CalcNodesHeight ()
{
	var nodesHeight = 0;
	var childList = document.body.childNodes;
	for(var i=0; i<childList.length; i++)	
	{
		if (childList.item(i).tagName != TAG && parseInt (childList.item (i).offsetHeight) > 0)
			nodesHeight+= parseInt (childList.item(i).offsetHeight);
	}	
	return nodesHeight;	
}

// Parameter extraHeight can be (+extraHeight) or (-extraHeight)
function SetIframeHeight (oIframe, extraHeight) 
{
	if (oIframe == null)
		return;
	
	if (oIframe.onresize != null)
		onResizeHandler = oIframe.onresize;

	oIframe.onresize			= null;
	setIframeHeightActivated	        = true;	
	SetReportIframeWidth (oIframe);
	setTimeout ("SetIframeHeightAfterDelay ('" + oIframe.id + "', " + extraHeight + ")", 100);
}

function SetReportIframeWidth (oIframe)
{
	// set width to the result report frame	
	try	{
		var w = screen.width - 260;	
		if (w < 700)
			oIframe.document.getElementById("m_resultFrame").width = "700";
		else {		
			if (document.getElementById && !(document.all))
				oIframe.width = w			
			else {
				var obj = oIframe.document.getElementById("m_resultFrame")
				obj.width = w; //IE							
			}
		}
	}catch(err){}
}

function SetOnResizeEvent (frameID)
{
	var frameDocument = GetFrameDocument (frameID);
	if (frameDocument == null)
		return;
	if (frameDocument.body == null || frameDocument.body.childNodes == null)		
		return;
	
	eval ("document.getElementById('" + frameID + "').onresize = " + onResizeHandler);
}

function SetIframeHeightAfterDelay (frameID, extraHeight)
{
	var frameDocument = GetFrameDocument(frameID);
	if (frameDocument == null)
		return;
		
	if (frameDocument.body == null || frameDocument.body.childNodes == null)
		return;
	
	try	{	
		var isNUll = 0;
		eval ("if (document.getElementById('" + frameID + "') == null) isNUll = 1;");
		if (isNUll) return;
	}catch (exp){return;}
	
	var ifrHeight = 0;
	var childList = frameDocument.body.childNodes;
	for(var i = 0; i < childList.length; i++) {
		if (childList.item (i).tagName != TAG && parseInt (childList.item (i).offsetHeight) > 0)
			ifrHeight += parseInt (childList.item (i).offsetHeight);
	}
	var finalHeight = ifrHeight + parseInt (extraHeight);	
	if (finalHeight <= document.body.clientHeight)
		finalHeight = document.body.clientHeight;
	
	var somethingChanged = false;
	try {
		eval ("if (document.getElementById('" + frameID + "').height != " + finalHeight + ") {document.getElementById('" + frameID + "').height = " + finalHeight + "; somethingChanged = true;}");
	}catch (exp){return;}
	
	// The timeouts are ensuring that (1) setting the parent's Iframe Height will occur first
	// (2) Then the scroll (if needed)
	// And finally (3) the resize event back to his place
	// It is very important to keep that order
	if (somethingChanged) {
		// 1:
		try {
			if (parent.setIframeHeightActivated == true)
				setTimeout ("parent.SetParentsIframeHeight ();", 100);
		}
		catch (exp){}
		// 2:
		try {
			if (setScrollActivated == true)
				setTimeout ("SetScroll ();", 110);
		}
		catch (exp){}
	}
	// 3:
	setTimeout ("SetOnResizeEvent ('" + frameID + "');", 500);
}

function SetParentsIframeHeight (objID)
{
	try {
		var iframes = GetBrowserElementsByTagName (document,TAG);
		for (var i = 0 ; i < iframes.length ; i++) {
			try {
				SetIframeHeight (iframes [i], 0);
			}
			catch (exp) {}
		}
	}
	catch (exp) {}
}
function FindObject (objId)
{
	var founded = false;
	if (opener != undefined) {	
		var op = opener.parent.frames;
		for (var i=0; i< op.length; i++) {										
			try {
				if (op[i].document.getElementById(objId));
					return op[i].document.getElementById(objId);
			}catch(err){}
		}
		op = opener.parent.parent.frames;
		if (op && !founded) {
			for (var i=0; i< op.length; i++) {										
				try {
					if (op[i].document.getElementById(objId))
						return op[i].document.getElementById(objId);
				}catch (err){}
			}			
		}			
	}
	else {		
		var oFrames = parent.frames;		
		while (oFrames && !founded) { 		
			for (i=0; i< oFrames.length; i++) {															
				try {
					if(oFrames[i].document.getElementById(objId))
						return oFrames[i].document.getElementById(objId);
				} catch(err){}
			}
			oFrames = parent.oFrames;		
		}
		if (!founded) {			
			oFrames = parent.window.parent.frames			
			while (oFrames && !founded) {
				for (i=0; i< oFrames.length; i++) {						
					try {
						if (oFrames[i].document.getElementById(objId))
							return oFrames[i].document.getElementById(objId);
					} catch(err){}
				}
				oFrames = parent.oFrames;
			} 
		}		
	}	
	return null;
}
function InitSessionTimoeout (milliseconds)
{
	var founded = false;
	if (opener != undefined) {
		var op = opener.parent.frames;
		for (var i=0; i< op.length; i++) {
			try {
				var trace = "before InitSessionTimoeout (" + milliseconds + ") : m_sessionTimeOut = " +  op[i].document.getElementById("m_sessionTimeOut").value;
				op[i].JSTrace       (trace, window.location.pathname);
				op[i].ClientJSTrace (trace, window.location.pathname);
				op[i].document.getElementById("m_sessionTimeOut").value = milliseconds;founded=true;
				trace    = "After InitSessionTimoeout  (" + milliseconds + ") : m_sessionTimeOut = " +  op[i].document.getElementById("m_sessionTimeOut").value;
				op[i].JSTrace (trace, window.location.pathname);
				op[i].ClientJSTrace (trace, window.location.pathname);
			} catch(err){}
		}
		op = opener.parent.parent.frames;
		if (op && !founded) {
			for (var i=0; i< op.length; i++) {
				try {
					var trace = "before InitSessionTimoeout (" + milliseconds + ") : m_sessionTimeOut = " +  op[i].document.getElementById("m_sessionTimeOut").value;
					op[i].JSTrace       (trace, window.location.pathname);
					op[i].ClientJSTrace (trace, window.location.pathname);
					op[i].document.getElementById("m_sessionTimeOut").value = milliseconds;founded=true;
					trace     = "After InitSessionTimoeout  (" + milliseconds + ") : m_sessionTimeOut = " +  op[i].document.getElementById("m_sessionTimeOut").value;
					op[i].JSTrace       (trace, window.location.pathname);
					op[i].ClientJSTrace (trace, window.location.pathname);
				} catch(err){}
			}
		}
	}
	else {		
		var oFrames = parent.frames;		
		while (oFrames && !founded) { 		
			for (i=0; i< oFrames.length; i++) {															
				try {
					var trace = "before InitSessionTimoeout (" + milliseconds + ") : m_sessionTimeOut = " +  oFrames[i].document.getElementById("m_sessionTimeOut").value;
					oFrames[i].JSTrace       (trace, window.location.pathname);
					oFrames[i].ClientJSTrace (trace, window.location.pathname);
					oFrames[i].document.getElementById("m_sessionTimeOut").value = milliseconds;founded=true;
					trace     = "After InitSessionTimoeout  (" + milliseconds + ") : m_sessionTimeOut = " +  oFrames[i].document.getElementById("m_sessionTimeOut").value;
					oFrames[i].JSTrace       (trace, window.location.pathname);
					oFrames[i].ClientJSTrace (trace, window.location.pathname);
				} catch(err){}
			}
			oFrames = parent.oFrames;		
		}
		if (!founded) {			
			oFrames = parent.window.parent.frames			
			while (oFrames && !founded) {
				for (i=0; i< oFrames.length; i++) {						
					try {
						var trace = "before InitSessionTimoeout (" + milliseconds + ") : m_sessionTimeOut = " +  oFrames[i].document.getElementById("m_sessionTimeOut").value;
						oFrames[i].JSTrace (trace, window.location.pathname);
						oFrames[i].document.getElementById("m_sessionTimeOut").value = milliseconds;founded=true;
						trace     = "After InitSessionTimoeout  (" + milliseconds + ") : m_sessionTimeOut = " +  oFrames[i].document.getElementById("m_sessionTimeOut").value;
						oFrames[i].JSTrace (trace, window.location.pathname);
						oFrames[i].ClientJSTrace (trace, window.location.pathname);
					} catch(err){}
				}
				oFrames = parent.oFrames;
			} 
		}		
	}
}

function GetIframe (name)
{
	var founded = false;
	if (opener != undefined) {
		var op = opener.parent.frames;
		for (var i=0; i< op.length; i++) {
			try {
				if (op[i].name == name)
					return op[i];
			}catch(err){}
		}
		op = opener.parent.parent.frames;
		if (op && !founded) {
			for (var i=0; i< op.length; i++) {
				try {
					if (op[i].name == name)
						return op[i];
				} catch(err){}
			}
		}
	}
	else {		
		var oFrames = parent.frames;		
		while (oFrames && !founded) { 		
			for (i=0; i< oFrames.length; i++) {															
				try {
					if (oFrames[i].name == name)
						return oFrames[i];
				} catch(err){}
			}
			oFrames = parent.oFrames;		
		}
		if (!founded) {			
			oFrames = parent.window.parent.frames			
			while (oFrames && !founded) {
				for (i=0; i< oFrames.length; i++) {						
					try {
						if (oFrames[i].name == name)
							return oFrames[i];}
					catch(err){}
				}
				oFrames = parent.oFrames;
			} 
		}		
	}	
	return null;
}
function CTrace (msg)
{
	GetIframe ('Up').ClientJSTrace (msg, window.location.pathname);
}
