
	// #######################################
	// ##### VISIBILITY/RESIZE FUNCTIONS #####
	// #######################################

	// GLOBAL VARIABLES
	var availTopHeight = 150;
	var lastHeight = 150;
	var swapPos = 0;
	var zipClick = false;
	var availScreenWidth = 0;
	var availScreenHeight = 0;
	
	//UI pointer vars
	var m_divCobrandArea;
	var m_tblSessionInfo;
	var m_imgSpacer;
	var m_imgSpacer2;
	var m_txtChatArea;
	var m_txtSendChat;
	var m_imgSwapper;
	var m_divTools;
	var m_divAllToolsArea;
	
	// RESIZE TOP AND BOTTOM AREAS (following page or other resize)
	function IToolContainer_Resize()
	{	
			
		if (m_SessionState == SESSIONSTATE_UNCONNECTED && m_LastAvailScreenWidth != 0 && m_LastAvailScreenHeight != 0)
		{
			//use the width height we remembered at session end time (instead of recalc'ing because Safari has problems with that)
			availScreenWidth = m_LastAvailScreenWidth;
			availScreenHeight = m_LastAvailScreenHeight;
		}	
		else 
		{
			availScreenWidth = (window.innerWidth) ? window.innerWidth : (window.document.body.clientWidth) ? window.document.body.clientWidth : screen.availWidth;
			availScreenHeight = (window.innerHeight) ? window.innerHeight : (window.document.body.clientHeight) ? window.document.body.clientHeight : screen.availHeight;			
		}

		doChatResize();
		doToolsResize();
	}


	// RESIZE CHAT (TOP) AREA
	function doChatResize()
	{
		if (availTopHeight == 0)
		{
			height = 0;
			varCobrandHeight = 0;
		}
		else
		{
			height = (availTopHeight) - 32;
			if (height < 18)
				height = 18;

			varCobrandHeight = height + 26; // + 4; // - 28;
			if (varCobrandHeight < 38)
				varCobrandHeight = 38;
			
			varSessionInfoHeight = varCobrandHeight - 61;
			if (varSessionInfoHeight <= 0)
				varSessionInfoHeight = 1;
			
			m_tblSessionInfo.height = varSessionInfoHeight;
		}
		
		width = availScreenWidth;
		if (availScreenWidth < 750)
			width = 750;			
			
		m_divCobrandArea.style.left = width - 242;
		m_divCobrandArea.style.height = varCobrandHeight;		
		
		if (document.all)
			m_imgSpacer.height = height - 5; // + 7;	
		else
			m_imgSpacer.height = height + 9;
		
		m_txtChatArea.style.height = height;
		
		varWidth = (width) - 245;

		m_imgSpacer2.width = varWidth + 3;
		m_txtChatArea.style.width = varWidth;
		
		if (document.all)
			m_txtSendChat.style.width = varWidth - 48;
		else
			m_txtSendChat.style.width = varWidth - 53;
	}
	


	// RESIZE TOOLS (BOTTOM) AREA
	function doToolsResize()
	{
		height = availScreenHeight - availTopHeight - 43; 
		if(height < 0)		
			height = 0;
			
		width = availScreenWidth;
		if (width < 750)
			width = 750;
		
		m_divTools.style.height = height;
		m_divTools.style.width = width - 8;
		
		m_divAllToolsArea.style.top = availTopHeight + 30;
		
		//flip swapper if we just resized past the zip-point
		if (!zipClick && availTopHeight <= 57)
		{
			swapPos = 1;
			m_imgSwapper.src = 'Images/swapper_down.gif';
		}
		else if (!zipClick)
		{
			swapPos = 0;
			m_imgSwapper.src = 'Images/swapper_up.gif';
		}

		zipClick = false;
	}
	


	// #######################################
	// ##### INSTA-DRAG ARROW FUNCTION #######
	// #######################################

	// swapPos is the swapper status
	// swapPos (0) means it's currently pointed up
	// swapPos (1) means it's currently pointed down
	
	function swapperSwitch()
	{
		zipClick = true;
	
		if (swapPos == 0)
		{
			swapPos = 1;

			m_imgSwapper.src = 'Images/swapper_down.gif';

			lastHeight = availTopHeight;
			availTopHeight = 57;
			
		}
		else
		{
			swapPos = 0;

			m_imgSwapper.src = 'Images/swapper_up.gif';

			availTopHeight = lastHeight;
		}
		
		IToolContainer_Resize();
		
	}


	function swapperOver(direction) {
	
		// gradually construct the image path based on
		// the swapper direction (swapPos) and
		// the mouseover direction (direction)
		
		var imgPath			= "Images/swapper_";
		
		if (swapPos == 0) {
			imgPath += "up";
		} else {
			imgPath += "down";
		}
	
		if (direction == "over") {
			imgPath += "_over";
		}
		
		imgPath += ".gif";
		
		m_imgSwapper.src = imgPath;
	}


	

	// TOGGLE VISIBILITY OF CHAT/COBRAND AREA
	function IToolContainer_TopShowHide(type)
	{
		MM_showHideLayers('divAllChatArea', '', type);
		MM_showHideLayers('txtChatArea', '', type);
		MM_showHideLayers('txtInnerChatArea', '', type);
		MM_showHideLayers('divCobrandArea', '', type);
		MM_showHideLayers('divFrameSeparator', '', type);	


		if (type == 'hide')
		{
			m_imgSwapper.style.visibility = 'hidden';
			availTopHeight = 0;
			m_divAllToolsArea.style.top = 35;
		}
		else
		{
			m_imgSwapper.style.visibility = 'visible';
			availTopHeight = 163;
			m_divAllToolsArea.style.top = availTopHeight + 35;
		}

		IToolContainer_Resize();
	}
	

	function IToolContainer_TopResize(top)
	{
		availTopHeight = top;
		IToolContainer_Resize();
	}
	
	function IToolContainer_OnUnload()
	{	
		//set session-level cookie 'IsLoaded' to 0 since we might be about to unload (will be reset to 1 when startScroll() in IEnvironmentManager fires via timer)
		document.cookie = 'IsLoaded=0; path=/';
		
		if (IEnvironmentManager_GetSessionState() >= top.SESSIONSTATE_CONNECTING)
		{
			msg = "\n\nĦIMPORTANTE! ĦDebes hacer CLIC en CANCELAR!\n\nPara seguir conectado con tu bibliotecario, por favor haz clic en CANCELAR.\n\n";

			if (document.all)	
			{
				if(event != null)
					event.returnValue = msg;
				else 
					return msg;
			}
			else
				return msg;
		}
	}


	// #######################################
	// #### STARTER (BODY ONLOAD) FUNCTION ###
	// #######################################

	function IToolContainer_Init()
	{
		//set pointers to UI elements
		m_divCobrandArea = document.getElementById('divCobrandArea');
		m_tblSessionInfo = document.getElementById('tblSessionInfo');
		m_imgSpacer = document.getElementById('imgSpacer');
		m_imgSpacer2 = document.getElementById('imgSpacer2');
		m_txtChatArea = document.getElementById('txtChatArea');
		m_txtSendChat = document.getElementById('txtSendChat');
		m_imgSwapper = document.getElementById('imgSwapper');
		m_divTools = document.getElementById('divTools');
		m_divAllToolsArea = document.getElementById('divAllToolsArea');
	}


	// #######################################
	// ######### MENU ITEM FUNCTIONS #########
	// #######################################

	// RETRIEVE REFERENCE TO APPROPRIATE MENU ITEM
	function getMenuItemFromTag(tag)
	{
		var arr = new Array(2);
		var divider = "||";
		
		//parse the tag string		
		loc = 0;
		curPos = 0;
		
		while ((pos = tag.indexOf(divider, curPos)) != -1)
		{
			arr[loc] = tag.substring(curPos, pos);
			
			curPos = pos + 2;
			loc++;
		}
		
		this.type = arr[0];
		this.name = arr[1];
		this.URL = arr[2];
		
		return this;
	}
	
	// ULTRAWEB MENU ONCLICK HANDLER
	function UltraWebMenu1_ItemClick(menuId, itemId)
	{
		var item = igmenu_getItemById(itemId);
		var tag = item.getTag();
	
		if (!tag) return;

		var selItem = getMenuItemFromTag(tag);
		
		if (selItem.type == "tool") 
			IEnvironmentManager_AddTool(selItem.URL, selItem.name);
		else
		{
			switch (selItem.type)
			{
				case "signin":
					dialogueDisplay('login');
					break;					
				case "signout":
					IEnvironmentManager_UserLogoff();
					break;
				case "print":
					IEnvironmentManager_Print();
					break;
				case "endsession":
					IEnvironmentManager_EndSession();
					break;
			}
		}
	}

	// #######################################
	// ######### LOGIN BOX FUNCTIONS #########
	// #######################################

	// hide or display loginBox
	function dialogueDisplay(state, params, handlerFunction) {

		var oLoginFra = document.getElementById('fraLoginBox');
		oLoginFra.src = "/nGEN-es/Apps/SocWeb/Frames/blank.html";	
		dialogueResize(1, 1);

		if(handlerFunction) 
		{
			m_DialogueContinueFunction = handlerFunction;
		}
		
		setTimeout("dialogueDisplayAction('" + state + "','" + params + "')", 150);
	}

	function dialogueDisplayAction(state, params) {
		var oLoginDiv = document.getElementById('loginBox');
		var oLoginFra = document.getElementById('fraLoginBox');
		
		switch (state)
		{
			case "login":
				oLoginFra.src = "Frames/loginBox.aspx";
				dialogueResize(402, 275);
				oLoginDiv.style.visibility	= "visible";
				oLoginDiv.style.display		= "inline";
				break;

			case "create":
				oLoginFra.src = "Frames/loginCreate.aspx";
				dialogueResize(575, 290);
				oLoginDiv.style.visibility	= "visible";
				oLoginDiv.style.display		= "inline";
				break;

			case "forgot":
				oLoginFra.src = "Frames/loginForgot.aspx";
				dialogueResize(402, 275);
				oLoginDiv.style.visibility	= "visible";
				oLoginDiv.style.display		= "inline";
				break;

			case "survey":
				oLoginFra.src = "/nGEN-es/Tools/PostSessionSurvey/survey_prep.aspx";
				dialogueResize(647, 443);
				oLoginDiv.style.visibility	= "visible";
				oLoginDiv.style.display		= "inline";
				break;
			
			case "alert":
				oLoginFra.src = "Frames/alert.aspx" + params;
				dialogueResize(464, 182);
				oLoginDiv.style.visibility	= "visible";
				oLoginDiv.style.display		= "inline";
				break;
			
			case "none":
				dialogueResize(1, 1);
				oLoginDiv.style.visibility	= "hidden";
				oLoginDiv.style.display		= "none";
				break;
		}
				
		if (state != "survey" && state != "none")
			window.setTimeout("dialogueFocus()", 250);		
	}


	function dialogueResize(w, h) 
	{
		document.getElementById('fraLoginBox').style.width	= w;
		document.getElementById('fraLoginBox').style.height	= h;	
	}


	function dialogueFocus()
	{
		var s	= document.getElementById('fraLoginBox').contentWindow.document;
		
		if (s.getElementById('txtUsername'))
		{
			if (s.getElementById('txtUsername').value == '')
				s.getElementById('txtUsername').focus();
			else
				s.getElementById('butLogin').focus();
		}
		else if (s.getElementById('txtEmail')) 
		{
			s.getElementById('txtEmail').focus();
		}
	}

	//this function closes the dialog window and forward the call on to the handling function
	var m_DialogueContinueFunction;
	function dialogueContinue(result)
	{
		//hide dialog window
		dialogueDisplay('none');

		//forward to function that will handle the dialog result
		if (m_DialogueContinueFunction) 
		{
			m_DialogueContinueFunction(result);
		}
	}

	var focusCmd = null; // last focus command


	function forceTab(inputRef,evt) {
	
		evt = (evt) ? evt : ((event) ? event : null);
		
		// if they did not press Tab, leave the function
		if (evt.keyCode != 9) { 
			return; 
		} else {
			
			if (document.all) {
				evt.returnValue = false;
			} else { 
				evt.preventDefault();
				evt.stopPropagation();
			}
		}
		

		var thisTab			= inputRef.tabIndex;
		var thisForm		= inputRef.form;
		var bestTab			= null;
		var firstElement	= null;
		var lastElement		= null;

		focusCmd			= null;
		
		
		if (evt.shiftKey == false) {
		
			bestTab = 1000;
			
			for (i=0; i < thisForm.elements.length; i++) {
			
				if (thisForm.elements[i].tabIndex > thisTab && thisForm.elements[i].tabIndex < bestTab && 
					thisForm.elements[i].type != "hidden" && 
					thisForm.elements[i].disabled == false && 
					parentDisplay(thisForm.elements[i]) == true) {

					bestTab = thisForm.elements[i].tabIndex;

					focusCmd = "document.getElementById('fraLoginBox').contentWindow.document.forms[0].elements[" + i + "].focus();";
				}
			
				if (firstElement == null && 
					thisForm.elements[i].type != "hidden" && 
					thisForm.elements[i].disabled == false && 
					parentDisplay(thisForm.elements[i]) == true) {

						firstElement	= i;

				}
			
			}


		} else {	// evt.shiftKey == true
		
			bestTab = 0;
			
			for (i = thisForm.elements.length - 1; i > 0; i--) {
			
				if (thisForm.elements[i].tabIndex < thisTab && thisForm.elements[i].tabIndex > bestTab && 
					thisForm.elements[i].type != "hidden" && 
					thisForm.elements[i].disabled == false && 
					parentDisplay(thisForm.elements[i]) == true) {

					bestTab = thisForm.elements[i].tabIndex;

					focusCmd = "document.getElementById('fraLoginBox').contentWindow.document.forms[0].elements[" + i + "].focus();";
				}
			
				if (lastElement == null && 
					thisForm.elements[i].type != "hidden" && 
					thisForm.elements[i].disabled == false && 
					parentDisplay(thisForm.elements[i]) == true) {

						lastElement	= i;

				}
				
			}
			
		}

		
		if (focusCmd != null) {
			setTimeout("eval(focusCmd)", 20);
			return false;
		}

		
		// if we are still in the function at this point,
		// it means we didn't find a next or previous tab,
		// and we have to jump to the first or last visible element;

		var jumpTarget = (evt.shiftKey ? lastElement : firstElement);
		
		focusCmd = "document.getElementById('fraLoginBox').contentWindow.document.Form1.elements[" + jumpTarget + "].focus();";

		setTimeout("eval(focusCmd)", 20);
		return false;

	}



	function parentDisplay(obj) {
	
		while (obj) {
		
			if (obj.style && obj.style.display && obj.style.display == "none") {
				return false;
			}
		
			obj = obj.parentNode;
		}
	
		return true;
	}
	










