  var g_runWithinTab=false;//for tpane processes that run from tabs that want to runWithin when they end.


		function frameworkInit()
                {getStealthSocket("StealthSocketFlash");}
		
		function frameworkInitAdmin()
		{
			 getStealthSocket("StealthSocketFlash");
			 if ( !g_mainframe ) 
				{
					  setTimeout("frameworkInit()", 40);
							return;
				}	
				//DEBUG SHIT for deactivating shield, remove from production
				g_mainframe.importScript(g_root+'scripts/GlobalEventHandler.js', top.document);
/*				
				try
				{
 			  addToGlobalEventHandler( "onkeydown", document.body, "shieldTest("+evtTxt()+")", false );
						addToGlobalEventHandler( "ondblclick", document.body, "startRemoteControl()", false );
				}catch(e)
				{  //catch needed to solve IE's importScript failing when browser cache settings are 'Every visit';
				   //this is a test case that could be carried to all occurances of this flaw.
					  setTimeout("frameworkInit()", 40);
							return;
				}		
*/				
				//END DEBUG SHIT
			 var dontShowAdmin = getParameter( document.cookie, "dontShowAdmin", ";" );
				if ( dontShowAdmin == "true" ) return;
		  adminConsole();				
		}		
		
  function cleanNavigationTo( dl ) 
		{
	  drillLevel=dl;
	  var lb = "";
	  var c = document.all["locationBar"].childNodes;
	  for ( i = 1; i < c.length; i++ ) 
   {
     if ( getOuterHTML(c[i]).indexOf("<A") == 0) break;
     if ( getOuterHTML(c[i]).indexOf("<a") == 0) break;
     lb += getOuterHTML(c[i]);
	  }	  
	  document.getElementById("locationBar").innerHTML = lb;
	  if ( c.length > 0 )
	    c[c.length-1].className = "navSelLink";										
	  return true;
  }
		
		function updateLocationBar( data )
		{
			 document.getElementById("locationBar").innerHTML = "<span class='locblurb'>You are here: &nbsp; </span>" + data; 
				var c = document.getElementById("locationBar").childNodes;
				for ( i=1; i<c.length; i++ )
				{
					  if ( c[i].nodeName != '#text' )
  					  c[i].className='navLink';
				}
				c[c.length-1].className='navSelLink';
		}
		
		function stripNavTo(e)
		{
			  var o = e.srcElement;
					if ( o.nodeName.toLowerCase() != "a" ) return;
			  var c = document.getElementById("locationBar").childNodes;
					var newLocation="";
			  for ( i=0; i<c.length;i++)
					{
						  newLocation += c[i].outerHTML;
						  if ( c[i] == o )
								{
											break;
								}
					}
					document.getElementById("locationBar").innerHTML=newLocation;
					c=document.getElementById("locationBar").childNodes;
					c[c.length-1].className='navSelLink';
		}
  
  
  var waitTimer = false;  
  function openWaitScreenWithDelay(delay) 
		{
	   waitTimer = setTimeout('openWaitScreen()', delay);
  }
  
  function openWaitScreen() 
		{
    if (!document.all.waitscreendiv)
      insertAdjacentHTML(document.body, "BeforeEnd","<div id=waitscreendiv class=tab style='font-family:arial; font-size:10pt; font-weight:bold; color:#000000; background-color:#ffffff; border:thin solid black;' align=center><img src='"+g_imageLocation+"Relatis/wait.gif' class=waitImg><br>Please wait...</div>");
	   document.all.waitscreendiv.style.left="400px";
	   document.all.waitscreendiv.style.top="250px";
	   document.all.waitscreendiv.style.visibility="visible";
  }
  
  function closeWaitScreen() 
		{	  
    clearTimeout(waitTimer);
	   if (!document.all.waitscreendiv) return;
    document.all.waitscreendiv.style.visibility="hidden";
  }
  
    
  ////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////extra code for new relatis//////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////
  var currentTreeNode = null;

		function delayBranchToggle(pk, dis)
		{//require a delay to fix IE's never ending download progress bar problem!
			 document.getElementById("loadedPk"+pk).style.display=dis;
		}
  function toggleMenuNodeReply(data)
  {
			 var nodeTable = g_mainframe.getParentWithTag(currentTreeNode,'TABLE');
	   setOuterHTML( nodeTable, data );
  }
		
		function RemoveFakeNode( o, usrMenuPk )
		{
    StealthDownload( 'LeftMenuTree_Form', 'RemoveFakeNode', "/servlet/com.isa.balmoral.admin.process.MatFrameworkServlet", null,"usrMenuPk="+usrMenuPk, getMenuNodeReply );			
				event.cancelBubble=true;
		}
	
  function requestMenuLinkScreen( pk, newWindow, realPk )
  {			 
		  var tabPk=getParameter( document.cookie, g_frameworkName+'seltabpk', ';' );
				var oldMenuPk=getParameter( document.cookie, g_frameworkName+'selmenupk_'+tabPk, ';' );
				if ( document.getElementById('m'+oldMenuPk) ) document.getElementById('m'+oldMenuPk).className=document.getElementById('m'+oldMenuPk).className.replace(/Still/g,'');
				if ( document.getElementById('m'+realPk) && document.getElementById('m'+realPk).className.indexOf('Still') < 0 ) document.getElementById('m'+realPk).className=document.getElementById('m'+realPk).className+"Still";
				setCookie( g_frameworkName+'selmenupk_'+tabPk,realPk ); 
			 if ( newWindow )
				  window.open(pk + "&linkSelected=true&topMenuPk=" + top.document.getElementById('LeftMenuTree_Form').topMenuPk.value,'RelatisPopup', 'left='+((screen.width/2)-300)+',top='+((screen.height/2)-280)+',directories=no,width=600,height=400,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no');
		  else
	     g_mainframe.document.location=pk + "&linkSelected=true&topMenuPk=" + top.document.getElementById('LeftMenuTree_Form').topMenuPk.value; 
    //StealthDownload( "LeftMenuTree_Form", "", "/servlet/com.isa.balmoral.admin.process.MatServlet", "mainframe","usrMenuLinkPk="+pk, null );	  
  }  
		var wijsp_link;

  function selectTab(nodePk,nodeLink)
  {
			 var oldpk=getParameter( document.cookie, g_frameworkName+'seltabpk', ';' );
			 setCookie( g_frameworkName+'seltabpk', nodePk );
			 if ( oldpk != nodePk ) tempSwitch(nodePk, oldpk);//bag of bollocks.....I hate demo's...     
    if (nodeLink.indexOf("com.isa.balmoral.admin.template.Main") > -1 )
	     g_mainframe.document.location="/servlet/com.isa.balmoral.admin.process.MatServlet?&subTask=blankPage&session="+document.getElementById("TabMenu_Form").elements.session.value + "&UsrTreePk="+nodePk+"&topMenuPk="+nodePk;  
	   else if ( nodeLink.indexOf("wijsp") > -1 )
				{
					 wijsp_link = nodeLink;
			   StealthDownload( "LeftMenuTree_Form", "GetLeftMenu", "/servlet/com.isa.balmoral.admin.process.MatFrameworkServlet", null,"&UsrTreePk="+nodePk, wijspMenuNodeReply );
				}
				else
	     g_mainframe.document.location=nodeLink + "&subTask=GetLeftMenu&UsrTreePk="+nodePk+"&topMenuPk="+nodePk+"&checkNode=true"; 		  	
  }
		function scrollMenuTreeIntoView()
		{
    var tabPk=getParameter( document.cookie, g_frameworkName+'seltabpk', ';' );
		  var oldMenuPk=getParameter( document.cookie, g_frameworkName+'selmenupk_'+tabPk, ';' );
    try { scrollIntoVView( document.getElementById("LeftMenuTree"), document.all["m"+oldMenuPk], true ); }catch(e){}
  }
		
  function getMenuNodeReply(data) 
  {
			//mmm this is shit, basically redraws the whole tree all the time.
    document.getElementById("menuTreeLoc").innerHTML=data;
    findAndExecuteScripts(data);
    ReloadRecentlyVisited();//needs to be here however it fucks up generic stuff.
  }
    
  function ReloadRecentlyVisited()
  {			
		  if ( !document.getElementById('RecentlyVisited') ) return;
    StealthDownload( "LeftMenuTree_Form", "ReloadRecentlyVisited", "/servlet/com.isa.balmoral.admin.process.MatFrameworkServlet", null,"", ReloadRecentlyVisitedReply );	  
  }
  function ReloadRecentlyVisitedReply( data )
  {
			document.getElementById('RecentlyVisited').innerHTML = data;
  }
  function publishRecentlyVisited(inNextScreenPk,inSelectedPk,inLastSelectedPk,inFieldName, inMenuLinkPk, inExtraParam, inLink) 
  {
			 top.document.all.locationBar.innerHTML = "<span class='locblurb'>You are here: </span>"+inLink.replace(/¬/g, '"');
    StealthDownload( "", "", "/servlet/com.isa.balmoral.admin.process.MatServlet", "mainframe","genFormPk="+inNextScreenPk+"&selectedPk="+inSelectedPk+"&lastSelectedPk="+inLastSelectedPk+"&sortField=&menuLinkPk="+inMenuLinkPk+"&topMenuPk="+top.document.LeftMenuTree_Form.topMenuPk.value + "&extraParameter="+inExtraParam, null );	  
  }
		
  function ReloadMyProcesses()
  {
			 if ( !document.getElementById('QuickProcesses') ) return;
    StealthDownload( "LeftMenuTree_Form", "ReloadMyProcesses", "/servlet/com.isa.balmoral.admin.process.MatFrameworkServlet", null,"", ReloadMyProcessesReply );	  
  }
  function ReloadMyProcessesReply( data )
  {
	   setOuterHTML( document.getElementById('QuickProcesses'), data );
  }
		
		function getFormHelp( sessionId )
		{
			 var HelpFormPk = document.all.formHelp.HelpFormPk;
    window.open('/servlet/com.isa.balmoral.admin.process.MatFrameworkServlet?session='+sessionId+'&subAction=getFormHelp&HelpFormPk='+HelpFormPk,'RelatisHelp', 'left=100,top=100,directories=no,width=600,height=400,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no');
		}

  function PosWin( x, y )
		{
			  var newX = x-4;
					var newY = y-116;
					window.moveTo(newX,newY);
					var diffX = x-window.screenLeft;
					var diffY = y-window.screenTop;
					window.moveBy(diffX, diffY);
		}
		
  function CentreWin( w, h )
  {
     if ( !document.body ) { setTimeout("CentreWin("+w+","+h+")",40); return; }
     window.moveTo( (screen.width/2)-(w/2), ((screen.height/2)-(h/2))-50 );	  
  }
		
  function SizeWin( w, h )
		{
			  var newW = w+4;
					var newH = h+116;
					window.resizeTo(newW,newH);
					var diffW = w-document.body.offsetWidth;
					var diffH = h-document.body.offsetHeight;
					window.resizeBy(diffW, diffH);
		}		
		
  function adminConsole( root, debug )
		{
			  g_mainframe.importScript(g_root+'scripts/GlobalTools.js', document);
					g_mainframe.importScript(g_root+'scripts/GlobalEventHandler.js', document);
			  g_mainframe.importScript(g_root+'scripts/tPane.js', document);			  					
			  g_mainframe.importScript(g_root+'scripts/genericScroller.js', document);
			  g_mainframe.importScript(g_root+'scripts/SkinMaker/cssAddRemoveProperty.js', document);
					g_mainframe.importScript(g_root+'scripts/UltimateSelect.js', document);
//			  g_mainframe.StealthDownload( null, "viewAdminConsole", "/servlet/com.isa.balmoral.admin.setup.GuiServlet", null,"", adminConsoleReply, true, true );//g_mainframe.findAndExecuteScripts );
					g_d=document;
					StealthDownload( 'LeftMenuTree_Form', "viewAdminConsole", "/servlet/com.isa.balmoral.admin.setup.GuiServlet", null,"", adminConsoleReply, true, true );
		}
		function adminConsoleReply( data )
		{
      var tpane = new TPane("AdminConsole");	
						tpane.modal=false;
						tpane.bgImage = "tpaneBack2.jpg";
						tpane.opacity = 78;
				  tpane.innerBorder = "3px double #adadad";
				  tpane.outerBorder = "1px solid black";	
						tpane.xAlign='right';
						tpane.showTPane( data, document.body, 150, 0, document.body );			      						
		}
		function AdminConsole_Div_startPaneMove()
		{
			  try { rn(document.all.invisShield); } catch(ex) {}
			  insertAdjacentHTML(document.body, "BeforeEnd", "<div id=invisShield style='display:block;left:"+getElementPosX(document.all.mainframe)+"px;top:"+getElementPosY(document.all.mainframe)+"px;width:"+document.all.mainframe.offsetWidth+"px;height:"+document.all.mainframe.offsetHeight+"px;'>&nbsp;</div>");
		}
		function AdminConsole_Div_stopPaneMove()
		{
			  rn(document.all.invisShield);
		}				
		function getZoomPosParms()
		{
    var x = (""+window.screenX) == "undefined" ? window.screenLeft : window.screenX;
    var y = (""+window.screenX) == "undefined" ? window.screenTop : window.screenY;	
				return 'pos=' +x+','+y+ '&atSave='+document.body.offsetWidth+','+document.body.offsetHeight;				
		}		
		
		//used to stop IE's bug when running script in the same document thats being replaced.
  function replaceMainframe()
		{				
		  if ( !g_body || g_body.length < 1 ) return;//fixes running process from calendar. 
			 var parts = g_body.split('<body');
				var nobody = parts[0]+"<body id=body onload=\"init(); document.body.insertAdjacentHTML('BeforeEnd',top.g_body); findAndExecuteScripts(top.g_body);top.g_body=null;try{resetGenericScroller('body', 'genericScroller', 'genericScroller', 1.0, 1.0, 0, 0);}catch(e){} \" class=whiteBack style='margin:0;padding:0;'><\/body><\/html>";	
				g_body=parts[1].substring(parts[1].indexOf('>')+1,parts[1].indexOf('<\/body'));
				var oNewDoc = g_mainframe.document.open("text/html", "replace");																								
 	  oNewDoc.write(nobody);												
				oNewDoc.close();	
				try
				{
				  if ( g_mainframe.document.view.genFormPk.value==top.g_scrollGenFormPk )
				    g_mainframe.document.all.genericScroller.scrollTop=top.g_scrollTopMem;
						top.g_scrollGenFormPk=false;
						top.g_scrollTopMem=false;
				} catch(e){}
		}
		
		function replaceTabSummary()
		{
			 var parts = g_body.split('<body');
				var nobody = parts[0]+"<body id=body onload=\"init(); document.body.insertAdjacentHTML('BeforeEnd',top.g_body); findAndExecuteScripts(top.g_body);top.g_body=null;try{resetGenericScroller('body', 'genericScroller', 'genericScroller', 1.0, 1.0, 0, 0);}catch(e){} \" class=whiteBack style='margin:0;padding:0;'><\/body><\/html>";	
				g_body=parts[1].substring(parts[1].indexOf('>')+1,parts[1].indexOf('<\/body'));
				var oNewDoc = g_runWithinTab.contentWindow.document.open("text/html", "replace");																								
 	  oNewDoc.write(nobody);												
				oNewDoc.close();
				g_runWithinTab=false;
		}
					
  function collapse( dontSetCookie ) 
		{ 
		  if ( document.getElementById('left').style.display=='none' ) 
				{ 
				  if ( !dontSetCookie ) setCookie("leftcollapse", "0");
				  document.getElementById('left').style.display='block'; 
						document.getElementById('footer_left').style.display='block';
						document.getElementById('footer_left_bot').style.display='block';
						document.getElementById('footer_mid').style.display='block';
						if ( document.getElementById('footer_overlap') )
  						document.getElementById('footer_overlap').style.display='block'; 
				} else 
				{ 
				  if ( !dontSetCookie ) setCookie("leftcollapse", "1");				
				  document.getElementById('left').style.display='none'; 
						document.getElementById('footer_left').style.display='none';
						document.getElementById('footer_left_bot').style.display='none';
						document.getElementById('footer_mid').style.display='none';
						if ( document.getElementById('footer_overlap') )
  						document.getElementById('footer_overlap').style.display='none'; 
				} 
		}		
		
  function cancelBubble(evt) 
  {
			 try 
				{
      if (typeof evt == 'undefined') evt=event;
      evt.returnValue = false; 
      evt.cancelBubble = true; 
				} catch(e) {}
    return false; 	 
  }	
		


  function setExecution(inGenExecutionPk)
  { 
    myInterval = setInterval('drawPopup(' + inGenExecutionPk + ')',3000);			
  }
	
  function drawPopup(inGenExecutionPk)
		{
	   try
    {
					 var fname = "view";
						if ( !g_mainframe.document.getElementById("view") ) fname = document.forms[0].name;
	     g_mainframe.StealthDownload( fname, 'changeStatus', '/servlet/com.isa.balmoral.admin.process.MatServlet',null,'GenExecutionPk=' + inGenExecutionPk + '&processStart=true&processType=true', g_mainframe.validateProcessReply );
      clear();
    } catch (e) {}
  }

  function clear()
	 {
	   clearInterval(myInterval);
  }
  
  var myInterval;
			
		function shieldFocus()
		{
			 try { g_mainframe.focusFirst(g_mainframe.document.all.Mat_Pain_Form); }catch(e){}
		}
			
  function activateShield( bShowWait )
		{    
    if ( bShowWait ) { try { rn( g_mainframe.document.all.spwait ); } catch(e){} specialWait(); }		
		  if ( document.getElementById('mfShield') ) 
				{
					return;						
				}
				//mini frameworks dont have left or top....
				try { document.all.leftShield.style.display='block'; }catch(e){}					
				try { document.all.topShield.style.display='block';		}catch(e){}
    g_mainframe.insertAdjacentHTML( g_mainframe.document.body, "BeforeBegin", "<div id=mfShield onmouseup='parent.shieldFocus();'>&nbsp;</div>" );												
		}
		
		
  function deactivateShield( bHideWait )
		{ 
		  try 
				{
      if ( bHideWait ) try { rn( g_mainframe.document.all.spwait ); }catch(ee){}					
//		    if ( !document.getElementById('mfShield') )
//						{
//							 return;				
//						}						
				  try{ document.all.leftShield.style.display='none'; }catch(e){}
				  try{ document.all.topShield.style.display='none'; }catch(e){}
				  rn(g_mainframe.document.getElementById('mfShield'));				  
				} catch (e) {}
		}
		
		function specialWait()
		{
			  insertAdjacentHTML( g_mainframe.document.body, "AfterBegin", "<div class='spwait' id='spwait' align=center><img src='"+top.g_imageLocation+"Relatis/wait.gif' border=0 /><br><span class=heading>Please wait...</span><br></div>" );
		}

var g_requestStamp=0;
var g_waitDelayTimer=false;
  function submitShieldUp()
		{
			 if ( document.all.submitShield.style.display=='block' ) return;
			 document.all.submitShield.style.display='block'; 
			 //document.all.submitShieldWait.style.display='block'; 
				//taking focus causes problems, is there another way I could do this???
				//perhaps catching all events and cancelling them!
//				document.all.submitShieldFocus.focus();
//				g_requestStamp=new Date().valueOf();
				g_waitDelayTimer = setTimeout("displayWaitDelay()",1000);
		}
		function displayWaitDelay()
		{
			 if ( document.all.submitShield.style.display=='block' ) 
  			 document.all.submitShieldWait.style.display='block'; 
		}
		function submitShieldDown()
		{			 
		  try { clearTimeout(g_waitDelayTimer); } catch(e){}
		  if ( !document.all.submitShield || document.all.submitShield.style.display!='block' ) return;
    document.all.submitShield.style.display='none';
    document.all.submitShieldWait.style.display='none';							
		}

		function shieldTest(e)
		{
			  e= !e ? event : e;
			  switch (e.keyCode)
					{
						 case 65 : activateShield( e.shiftKey ); break;
							case 68 : deactivateShield( e.shiftKey ); break;
					}						
		}
		
		function ViewInFormBuilder( genFormPk )
		{
    StealthDownload( null, 'formDesignerStart', '/servlet/com.isa.balmoral.admin.process.utils.guitemplates.FormDesigner', g_mainframe.document, 'selectedPk='+genFormPk, noReply);
		}
		
		function gotoProcessBuilder( o )
		{
					StealthDownload( null, 'processDesignerStart', '/servlet/com.isa.balmoral.admin.process.utils.guitemplates.ProcessDesigner', top.g_mainframe.document, 'session='+top.g_session+'&selectedPk='+o.getAttribute("gePk"), noReply);
		}
		
		function updateMainImg( src )
		{
			 if ( document.all.center.firstChild.src == src ) return;
  	 document.all.center.firstChild.src=src;
		}
		
		var g_goingToLogin=false;
		function logout( bWindowClosed )
		{			
		  if ( g_isFrameworkRedraw ) { isFrameworkRedraw=false; return; }
				cleanCookies();
		  if ( g_goingToLogin ) return;
    if ( !bWindowClosed )
				{
				  g_goingToLogin=true;
						StealthDownload( 'LeftMenuTree_Form', 'Logout', '/servlet/com.isa.balmoral.admin.process.'+top.g_frameworkName, '_self','windowClosed='+bWindowClosed, noReply, true, true );			
				} else
				{
      StealthDownload( 'LeftMenuTree_Form', 'Logout', '/servlet/com.isa.balmoral.admin.process.'+top.g_frameworkName, null,'windowClosed='+bWindowClosed, noReply, true, true );			
				}				
		}

		function noReply(){}	
		
		function showSearchRestricted()
		{
			  g_mainframe.document.all.searchRestricted.style.display='inline';
		}

function updateLogoImg( src )
{
  if ( document.all['logoImg'].src == src ) return;
  document.all['logoImg'].src = src;
}