var ToolBox_BuildNo							= "74";
var ToolBox_Debug							= mom.features['feature_development_build'];

var ToolBox_Debug_lastfunction				= new String;   
var ToolBox_Debug_papertrail				= new Array;
var ToolBox_Debug_searchExternal			= false;   
var ToolBox_Debug_temp_string				= new String;
var ToolBox_FileName						= "toolbox.js";
var ToolBox_Header_Search_CE				= "Search Clinical Evidence";
var ToolBox_Message_Admin_Confirm_Clear		= "Clear text \nAre you sure you want to clear this text?";
var ToolBox_Message_Admin_Prompt_url		= "Link address (URL):";
var ToolBox_Message_MaxPostMessage			= maxPostLengthMessage;
var ToolBox_Message_NoContent				= "No content was entered";
var ToolBox_Message_NoInfo					= "No further information has been provided for this node.";
var ToolBox_Message_SelectionNotSupported	= "Use the format [http:\/\/www.website.address link text]\nto insert a link manually.";
var ToolBox_Message_NoSelection				= "Please select the link text first.\n\n"+ ToolBox_Message_SelectionNotSupported;
var ToolBox_Message_Note_none				= "Please write your notes here.";
var ToolBox_Message_Note_Confirm_Clear		= ToolBox_Message_Admin_Confirm_Clear;
var ToolBox_Message_Revert					= "Are you sure you want to revert to the original version of this text?";
var ToolBox_Message_Search_none				= "Click in this box to enter additional search term(s), use commas to separate terms";
var ToolBox_Message_Search_none_cepop		= "No searches available";
var ToolBox_QuickSearch_numbers				= new String;
var ToolBox_QuickSearch_text				= new String;
var ToolBox_QuickSearch_types				= new String;
var ToolBox_QuickSearch_ilink               = new String;
var ToolBox_QuickSearch_pathway               = new String;
var ToolBox_QuickSearch_url					= "quickinfoSearchResults.html";
var ToolBox_RootElementId					= "divToolBox";
var logger									= new Object;
var currentNode								= {
												id:0,
												hasAdminInfo:false,
												hasLocalInfo:false,
												adminInfoCleared:false,
												body:new String,
												guidanceNote:new String,
												localinfo:new String,
												note:new String,
												title:new String
											}
var currentUser								= {adminViewer:false,adminEditor:false,notesEditor:false}
var gbl_IntCombinedHeight;
if (window.mom) {
	currentUser								= {
												adminViewer:(mom.features['feature_adminlocalisation'])?true:false,
												adminEditor:(mom.roles['role_admin_editor'])?true:false,
												notesEditor:(mom.features['feature_notes'])?true:false
											}
}
var ToolBox_ArraySnomed						= new Array;// smomed codes held in array, used to submit the NHL search
var ToolBox_ArrayDelimiter					= "_:_";
var ToolBox_ArraySnomedContainer			= "divSnomedSelectBox";
var ToolBox_AdditionalContainer             = "divAdditionalSelectBox"
ToolBox_ArraySnomed.getBoth					= function(id){var temp="";for(var i=0;i<this.length;i++){if(this[i].id==id){temp=this[i].both;break;}}return temp;};
ToolBox_ArraySnomed.getCodes				= function(id){var temp="";for(var i=0;i<this.length;i++){if(this[i].id==id){temp=this[i].codes.join(ToolBox_ArrayDelimiter);break;}}return temp;};
ToolBox_ArraySnomed.getIds					= function(){var temp="";for(var i=0;i<this.length;i++){temp+=this[i].id+", ";}return temp;};
ToolBox_ArraySnomed.getTexts				= function(id){var temp="";for(var i=0;i<this.length;i++){if(this[i].id==id){temp=this[i].texts.join(ToolBox_ArrayDelimiter);break;}}return temp;};
ToolBox_ArraySnomed.hasValue				= function(id){var temp=false;for(var i=0;i<this.length;i++){if(this[i].id==id){temp=true;break;}}return temp;};
ToolBox_ArraySnomed.getCodesSelected		= function(){
    var temp="";var cbs = document.getElementById(ToolBox_ArraySnomedContainer).getElementsByTagName("INPUT");
    try{
        for (i=0;i<cbs.length;i++){
            if (cbs[i].type=="checkbox" && cbs[i].checked)
            {temp+=cbs[i].value+ToolBox_ArrayDelimiter}
        }
    }catch(e){};
    return temp;
};
ToolBox_ArraySnomed.getTextsSelected		= function(){
    var temp="";var cbs = document.getElementById(ToolBox_ArraySnomedContainer).getElementsByTagName("INPUT");
    try{
        for (i=0;i<cbs.length;i++){
            if (cbs[i].type=="checkbox" && cbs[i].checked)
            {temp+=cbs[i].getAttribute("text")+ToolBox_ArrayDelimiter}
        }
    }catch(e){};
    return temp;
};
ToolBox_ArraySnomed.getAdditionalSelected		= function(){
    var temp="";var cbs = document.getElementById(ToolBox_AdditionalContainer).getElementsByTagName("INPUT");
    var added = false;
    try{
        for (i=0;i<cbs.length;i++){
            if (cbs[i].type=="checkbox" && cbs[i].checked)
            {temp+="'"+cbs[i].value+"'_:_"; added = true;}
        }
    }catch(e){};
    if(added) {temp = temp.substring(0,temp.length-3)};
    return temp;
};
String.prototype.anchorPatten               = str_AnchorPatten;
String.prototype.br                         = str_Br;
String.prototype.br_remove                  = str_Br_remove;
String.prototype.checkLength                = str_CheckLength;
String.prototype.isEmpty                    = str_IsEmpty;
String.prototype.isMaxPostLength            = str_IsMaxPostLength;
String.prototype.makeCEready                = str_MakeCEready;
String.prototype.makeGoogleReady            = str_MakeGoogleReady;
String.prototype.trim                       = str_Trim;
function ToolBox()
{
   
    this.admin            	= new ToolBoxAdmin;            
    this.adminEdit        	= AdminEdit;                   
    this.append         	= Append;                      
    this.close             	= Close;                       
    this.closeExternal     	= CloseExternal;               
    this.closeIfOpen    	= CloseIfOpen;                 
    this.currentToolboxSize	= 0;						
    this.currentView		= 0;						
    this.hide            	= Hide;                        
    this.info             	= Info;                        
    this.infoShow        	= InfoShow;                    
    this.keepHorizontal 	= glb_ToolBoxKeepHorizontal;   
    this.keepVertical     	= glb_ToolBoxKeepVertical;     
    this.open             	= Open;                        
    this.openAndLoad    	= OpenAndLoad;                 
    this.openAndLoadNotes  	= OpenAndLoadNotes;            
    this.openAndLoadLocalInfo = OpenAndLoadLocalInfo;	
    this.openAndLoadReferralInfo = OpenAndLoadReferralInfo;
    this.openLocalInfo    	= OpenLocalInfo;
    this.openLocalInfoForm	= OpenLocalInfoForm;		
    this.openNotes        	= OpenNotes;
    this.openQuickInfo    	= OpenQuickInfo;
    this.openReferralInfo   = OpenReferralInfo;
    this.override         	= UnitReplace;                 
    this.init             	= Init;                        
    this.isActive        	= false;                       
    this.toggle         	= Toggle;                      
    this.toggleTab        	= ToggleTab;                   
    this.localinfo        	= new ToolBoxLocalInfo;        
    this.notes             	= new ToolBoxNotes;            
    this.quickinfo        	= new ToolBoxQuickInfo;        
    this.referral           = new ToolBoxReferralCriteria;
    this.unknownTabSetState = UnknownTabSetState;		
    this.roll            	= glb_ImageRollOver;        
    this.rollOut        	= glb_ImageRollOut ;           
    this.setDisplaySize		= SetDisplaySize;			
    this.setHeaderState 	= new SetHeaderState;		
    this.setIsActive    	= SetIsActive;
    this.setCurrentNode		= new SetCurrentNode;		
    this.setQuickinfoSize	= SetQuickinfoSize;			
    this.submitSearch     	= SubmitSearch;				
    this.submitSearchBNF	= SubmitSearchBNF;			
    this.submitSearchCE 	= SubmitSearchCE;			
    this.submitSearchNLH	= SubmitSearchNLH;			
    this.submitSearchGoogle	= SubmitSearchGoogle;		
    this.submitGereralCE	= SubmitSearchGereralCE;
    this.search				= new ToolBoxSearch;
    this.showSearchBar    	= ShowSearchBar;			
    this.swap				= Swap;
    this.triggerWidths		= new Array(1024,0);		
    this.triggerHeights		= new Array(768,0);			
	this.heights			= new Array(400,400,567,567); 

    window.onscroll     	= this.keepVertical;		
    window.onresize			= this.setQuickinfoSize		

    this.popUp = new PopUp;

   
   
    this.isSet				= false;                           
    this.defaltEl			= "divDefaultPanel";                    
    this.externalIds		= new Array("referralNodeDiv","divPrintOptions")        
    this.id					= "divToolBox";                    

   
    this.units = new Array;
    this.units.getInt		= function(i)    {var temp="not found";if(this[i]){temp=document.getElementById(this[i].id);}return temp;};
    this.units.getId		= function(id)    {var temp="";for(var i=0;i<this.length;i++){if(this[i].id==id){temp=document.getElementById(this[i].id);break;}}return temp;}
    this.units.getIdStr		= function(i)    {var temp="not found";if(this[i]){if(this[i].id){temp=this[i].id}}return temp;}
    this.units.onerror		= function(e,l,p){alert("Array error, no object found")};
    this.units.showAll		= function()    {for (var i=0;i<arguments.length;i++){this.getId(arguments[i]).show();}};
    this.units.hideAll		= function()    {for (var i=0;i<this.length;i++){this.getInt(i).hide();}};
    this.units.hide			= function(id)    {this.getId(id).hide()};
    this.units.clean		= function()    {for (var i=(this.length-1);i>-1;i--){this[i]=null;}};
   
    function Init()
    {
        logger.log("toolbox.init()");
        document.getElementById(this.id).setIsActive = this.setIsActive;
        document.getElementById(this.id).isActive = false;       
        document.getElementById(this.id).getOffsetFromBody = GetOffsetFromBody;
		document.getElementById(this.id).getOffsetFromBody();

		gbl_IntCombinedHeight = document.getElementById(this.id).offsetHeight ;
        this.lastActiveUnit = document.getElementById(this.id).lastActiveUnit     = new Object;                       
        this.originaltop     = document.getElementById(this.id).originaltop     = parseInt(document.getElementById(this.id).offsetTop);
        this.getUnits 		= GetUnits;
        this.getUnits();    
        this.setQuickinfoSize();
        this.isSet = true;
        function GetUnits()
        {
            logger.log("toolbox.init.getUnits()");
            var us = document.getElementById(this.id).getElementsByTagName('DIV');
            var t = "";
            var xx = 0;
            for (i=0;i<us.length;i++)
            {
                if (us[i].className.indexOf('unit')==0)
                {
                    xx = this.units.length;
                    this.units[xx]         = new Object;
                    this.units[xx].id     = us[i].id;
                }
            }
            for (var i=0;i<this.units.length;i++)
            {
                document.getElementById(this.units[i].id).hasTab		= UnitHasTab;
                document.getElementById(this.units[i].id).show			= UnitShow;
                document.getElementById(this.units[i].id).hide			= UnitHide;
                document.getElementById(this.units[i].id).isActive		= false;
            }
        }
		function GetOffsetFromBody(){
			this.offsetFromBody = glb_GetOffsetTop(this,null);
		}
        return true;
    }
    function AdminEdit()
    {
    	if (window.demo && demo.active){demo.warn();return}
    	logger.log("toolbox.adminEdit()");
    	this.hide("divSearchPanel","divSearchPanelForm","divSearchPanelCE");
        this.openLocalInfoForm();
    }
    function Append()
    {
        for (var i=0;i<arguments.length;i++)
        {
            try {
                logger.log("toolbox.append('"+ arguments[i] +"')");
                this.units.getId(arguments[i]).show();
            }
            catch (e){glb_ErrorReporter(e,'problem with toolbox.append()');}
        }
    }
    function Close()
    {
        logger.log("toolbox.close()");
        document.getElementById(this.id).setIsActive(false);
        this.isActive = false;
        try {
	        this.unknownTabSetState(this.id);
        	this.admin.reset();           
        
        	this.search.close();       
        	this.units.hideAll();       
        	this.showSearchBar();
        } catch(e){glb_ErrorReporter(e,'problem with toolbox.close()');}
    }
    function CloseExternal()
    {
        for (var i=0;i<this.externalIds.length;i++)
        {
            if (document.getElementById(this.externalIds[i]))
            {
                document.getElementById(this.externalIds[i]).style.display = 'none';
            }
        }
    }
    function CloseIfOpen()
    {
        if (document.getElementById(this.id).isActive)
        {
            this.close();
        }
        return true;
    }
    function Hide()
    {
    	if (!arguments.length){return;}
        for (var i = 0;i<arguments.length;i++) {
	        try {
		        logger.log("toolbox.hide("+arguments[i]+")");
	            this.units.hide(arguments[i]);
	        } catch (e){glb_ErrorReporter(e,'no such element: '+arguments[i] );}
        }
    }
    function Info()
    {
        var m = "";
        m+= ToolBox_FileName +" build no: " + ToolBox_BuildNo;
        m+= "\n\nPage info"
        m+= "\ndomain:\t"+ location.protocol +"\/\/"+ location.host ;
        m+= "\npage: \t"+ location.pathname ;
        if ( location.search.toString() )
        {
            m+= "\nparams: \t"+ location.search.substring(1,location.search.length).replace(/&/g,"\n\t") ;
        }
        m+= "\n\nToolBox info";
        m+= "\ndebug = "+ ToolBox_Debug;
        m+= ",\tcurrentSize = "+ toolbox.currentToolboxSize;
        m+= ",\tisAcive = "+ document.getElementById(this.id).isActive;
        m+= "\nfunction history:\n"        + logger.getHistory(5);
        if (document.getElementById(this.id).isActive){
            m+=    "\ncurrent width = "+ document.getElementById(this.id).offsetWidth+ " height = "+ document.getElementById(this.id).offsetHeight +" size = "+ toolbox.currentToolboxSize;
        }
        m+= "\n\nUnits info";
        m+= "\nNo. of units = "+this.units.length;
        for (var i=0;i<this.units.length;i++)
        {
            m+= "\nUnit "+ (i+1) +": id="+this.units.getIdStr(i)+";\tisActive="+ document.getElementById(this.units[i].id).isActive +";\thas tab = "+ document.getElementById(this.units[i].id).hasTab() ;
        }
        m+= "\n\nUser info"
        m+= "\nis Admin viewer\t= "        + currentUser.adminViewer;
        m+= "\nis Admin editor\t= "        + currentUser.adminEditor;
        m+= "\nis Notes editor\t= "        + currentUser.notesEditor;
        m+= "\n\nAdmin info ";
        if (currentNode.id) {
            try{
                var form = document.forms["form_node_content_" + currentNode.id];
                m+= "\nis localized = "+     form.localized.value ;
                m+= "\ncanEdit = "+         form.canEdit.value ;
            } catch(e){}
        }
        m+= ""
        m+= "\n\nCurrent node info ";
        m+= "\ncurrentNode.id = "                    + currentNode.id;
        m+= "\ncurrentNode.hasNote = "             + currentNode.hasNote;
        m+= "\ncurrentNode.hasLocalInfo = "             + currentNode.hasLocalInfo;
        m+= "\ncurrentNode.hasAdminInfo (editable) = "             + currentNode.hasAdminInfo;
        m+= "\ncurrentNode.hasAdminInfoCleared = "     + currentNode.hasAdminInfoCleared;
        m+= "\n\nSearch info ";
        if (ToolBox_QuickSearch_text)
        {
            m+= "\nToolBox_QuickSearch_text = "        + ToolBox_QuickSearch_text;
        }
        if (ToolBox_QuickSearch_numbers)
        {
            m+= "\nToolBox_QuickSearch_numbers = "    + ToolBox_QuickSearch_numbers;
        }
        if (ToolBox_QuickSearch_types)
        {
            m+= "\nToolBox_QuickSearch_types = "    + ToolBox_QuickSearch_types;
        }
        if (ToolBox_QuickSearch_ilink)
        {
            m+= "\nToolBox_QuickSearch_ilink = "    + ToolBox_QuickSearch_ilink;
        }
        m+= "\n"+ ToolBox_ArraySnomed.length +" nodes have snomed text, ids: "     + ToolBox_ArraySnomed.getIds();
        return m;
    }
    function InfoShow()
    {
        alert(this.info());
    }
    function Open()
    {
    	var t = (arguments.length)? "toolbox.open("+arguments[0]+")" : "toolbox.open()";
        logger.log(t);
        var c = this.closeIfOpen();
        this.closeExternal();
        document.getElementById(this.id).setIsActive(true);
        this.isActive = true;
        if (arguments.length)
        {
            for (var i=0;i<arguments.length;i++)
            {
                try
                {
                    logger.log(" - toolbox.open('"+ arguments[i] +"')");
                    this.units.getId(arguments[i]).show();
                }
                catch(e){glb_ErrorReporter(e,"Couldn't open toolbox unit \n" + arguments[i])}
            }
        }
        else
        {
            this.units.getId(this.defaltEl).show(this);
        	this.swap("divQuickInfo");
        }
        this.unknownTabSetState(this.id);
        this.showSearchBar();
    }
    function OpenAndLoad()
    {
        logger.log("toolbox.openAndLoad("+ currentNode.id +")");
        var c = this.closeIfOpen();
        this.open();
        try{
        	this.setHeaderState.set(1);
            this.quickinfo.loadContent();
        } catch(e){glb_ErrorReporter(e,"Couldn't open the toolbox quickinfo "+ currentNode.id +" ");}
    }
    function OpenAndLoadNotes()
    {
        logger.log("toolbox.openAndLoadNotes()");
        var c = this.closeIfOpen();
        this.open();
        this.openNotes();
    }
    function OpenAndLoadLocalInfo()
    {
        logger.log("toolbox.openAndLoadLocalInfo()");
        var c = this.closeIfOpen();
        this.open();
        this.openLocalInfo();
    }
    function OpenAndLoadReferralInfo()
    {
        logger.log("toolbox.openAndLoadReferralInfo()");
        var c = this.closeIfOpen();
        this.open();
        this.openReferralInfo();
    }
    function OpenLocalInfo()
    {
    	if (window.demo && demo.active){demo.warn();return}
        logger.log("toolbox.openLocalInfo()");
        try
        {
            this.setHeaderState.set(3);
            this.swap("divLocalInfo");
            this.localinfo.loadContent();
            this.localinfo.setHeight();
        	this.hide("divGuidanceNoteContainer")
        }
        catch (e){glb_ErrorReporter(e,"Couldn't open the toolbox unit divLocalInfo");}
    }
     function OpenLocalInfoForm()
    {
    	if (window.demo && demo.active){demo.warn();return}
        logger.log("toolbox.openLocalInfoForm()");
        try
        {
            this.setHeaderState.set(3);
            this.swap("divAdminInfoForm");
           
           
           
            toolbox.admin.checkRevertInfo();
            this.localinfo.setHeight();
        	this.hide("divSearchPanelForm","divSearchPanel","divSearchPanelCE")
            this.append('divGuidanceNoteContainer');
           
            if(!oFCKeditor) {
                 this.admin.defaultAdminMessage = document.getElementById('h5QiSubHeadText_admininfo').innerHTML;
                 document.getElementById('h5QiSubHeadText_admininfo').innerHTML = 'Loading editor, please wait...';
                 setupFCK();
            }    
            else {
                 this.admin.loadContent();
                 this.localinfo.setHeight();
            }
        }
        catch (e){glb_ErrorReporter(e,"Couldn't open the toolbox unit divLocalInfo");}
    }
    function OpenNotes()
    {
        logger.log("toolbox.openNotes()");
        try
        {
            this.setHeaderState.set(2);
            this.swap("divNotes");
            this.notes.loadContent();
            this.notes.setView();
        	this.hide("divGuidanceNoteContainer");
        }
        catch (e){glb_ErrorReporter(e,"Couldn't open the toolbox unit");}
    }
    function OpenQuickInfo()
    {
        logger.log("toolbox.openQuickInfo()");
        try
        {
            this.setHeaderState.set(1);
        	this.swap("divQuickInfo");
            this.quickinfo.loadContent();
        	this.hide("divGuidanceNoteContainer");
        }
        catch (e){glb_ErrorReporter(e,"Couldn't open the toolbox unit");}
    }
    function OpenReferralInfo(){
        logger.log("toolbox.openReferralInfo()");
        try
        {
            this.setHeaderState.set(4);
            this.referral.loadContent();
            document.getElementById("divDefaultPanel").className = document.getElementById("divDefaultPanel").className.replace(/open/g,"closed")
            document.getElementById("divReferralPanel").className = document.getElementById("divReferralPanel").className.replace(/closed/g,"open")
            this.referral.setHeight();
        	this.hide("divSearchPanelForm","divSearchPanel","divSearchPanelCE")
        }
        catch (e){glb_ErrorReporter(e,"Couldn't open the toolbox unit divReferralInfo");}
    }
	function Swap(active)// swap will close all these views and open a new one without loading content or reseting
	{
		logger.log("toolbox.swap("+active+")\n\tClosing divs array[]");
		var list = new Array("divLocalInfo","divNotes","divQuickInfo","divAdminInfoForm", "divReferralPanel");
		var temp;
		for (var i=0;i<list.length;i++){
			if (document.getElementById(list[i])){
				document.getElementById(list[i]).className = document.getElementById(list[i]).className.replace(/open/g,"closed")
			}else{logger.log("\n\t[error] no sutch element "+ list[i]);}
		}
		if (document.getElementById(active)){
			document.getElementById(active).className = document.getElementById(active).className.replace(/closed/g,"open")
		}
	}
    function UnitHasTab()
    {
        return false;
    };
    function UnitHide()
    {
        this.className     = this.className.replace(/open/g,"closed");
        this.isActive     = false;
        toolbox.unknownTabSetState(this.id);
    };
    function UnitShow()
    {
        this.className = this.className.replace(/closed/g,"open");
        this.isActive     = true;
        if (this.hasTab())
        {
            toolBox.lastActiveUnit = this;
        }
        toolbox.unknownTabSetState(this.id);
    };
    function UnitReplace(unit)// replace the current unit with another
    {
        this.units.hideAll();
        this.unknownTabSetState(this.lastActiveUnit.id,true);
        this.units.getId(unit).show();
    };
    function UnknownTabSetState(id,forceAcvie)
    {
        if (document.getElementById(id))
        {
            if (document.getElementById(id.replace(/div/,"tab")))
            {
                var tab  = document.getElementById(id.replace(/div/,"tab"));
                var unit = document.getElementById(id);
                if (unit.isActive || forceAcvie)
                {
                    tab.src = tab.src.replace(/_off/g,"_on")
                    tab.alt = tab.alt.replace(/Open/g,"Close")
                }
                else
                {
                    tab.src = tab.src.replace(/_on/g,"_off")
                    tab.alt = tab.alt.replace(/Close/g,"Open")
                }
            }
        }
    }
    function SetCurrentNode()
    {
    	this.set			= Set; 		
    	this.hasUpdated 	= HasUpdated; 
    	this.loadData		= LoadData; 

    	function Set(id)
    	{
    		currentNode.id = id;
    		this.loadData();
    	}
    	function HasUpdated()
    	{
    		return true;
    	}
    	function LoadData()
    	{
    	
    		currentNode.title = currentNode.body = currentNode.note = currentNode.localinfo = currentNode.guidanceNote = null;
    		currentNode.hasNote = currentNode.hasAdminInfo = currentNode.hasLocalInfo = currentNode.hasAdminInfoCleared = false;
    		try {
	    		var form = document.forms["form_node_content_" + currentNode.id];
	    		currentNode.title 				= form.quickInfoTitle.value;
	    		currentNode.body 				= form.quickInfoBody.value;
	    		currentNode.note 				= (mom.features['feature_notes'])? form.quickInfoNote.value : "" ;
	    		currentNode.hasNote = (currentNode.note) ? true : false;
                currentNode.referral = form.referralCriteria.value;
				if (mom.features['feature_adminlocalisation']) {
		    		currentNode.localinfo 			= form.adminInfoTxt.value;
		    		currentNode.guidanceNote		= form.guidanceNote.value;
		            currentNode.hasAdminInfo        = ( form.adminInfoTxt.value.length ) ? true : false ;
		            currentNode.hasLocalInfo        = ( form.localized.value == "true" ) ? true : false ;
		            currentNode.hasAdminInfoCleared = ( form.adminInfoTxt.value == "" ) ? true : false ;
	            }
			} catch (e){glb_ErrorReporter(e,'no such element: '+ currentNode.id );}
    	}
    }
    function SetDisplaySize(size)
    {
    	if (toolbox.currentToolboxSize == size){return}
    	var stylesheets = document.getElementsByTagName("LINK");
    	for (var i=0;i<stylesheets.length;i++){
    		if (stylesheets[i].id.indexOf("linkToolboxSize") == 0) {
    			stylesheets[i].disabled = true;
    		}
    	}
    	if (document.getElementById("linkToolboxSize"+size)){
    	
    		gbl_IntCombinedHeight = toolbox.heights[size-1];
    		document.getElementById("linkToolboxSize"+size).disabled = false;
    		checkDisplayHeight()
    	
    		toolbox.currentToolboxSize = size;
    		if (toolbox.currentView==1){
    			toolbox.quickinfo.setHeight();
    		} else if (toolbox.currentView==2) {
    			toolbox.notes.setHeight();
    		} else if (toolbox.currentView==3) {
    			toolbox.localinfo.setHeight();
    		} else if (toolbox.currentView==4) {
    			toolbox.referral.setHeight();
    		}
		    toolbox.keepVertical();
    	}
    	function checkDisplayHeight(){
    		var height = gbl_IntCombinedHeight;
    		if (document.getElementById("divFlowChart").offsetHeight < height) {
    			document.getElementById("divFlowChart").style.height = height + "px";
    		}
    	}
    }
    function SetQuickinfoSize()
    {
    	var w,h;
 		if (document.documentElement) {w = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth ;}
 		if (document.documentElement) {h = (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight ;}
	    if (w < (toolbox.triggerWidths[0]+1) && h < (toolbox.triggerHeights[0]+1)){
	    	toolbox.setDisplaySize(1);
	    } else if (w > (toolbox.triggerWidths[0]+1) && h < (toolbox.triggerHeights[0]+1)){
	    	toolbox.setDisplaySize(2);
	    } else if (w < (toolbox.triggerWidths[0]+1) && h > (toolbox.triggerHeights[0]+1)){
	    	toolbox.setDisplaySize(3);
	    } else if (w > (toolbox.triggerWidths[0]+1) && h > (toolbox.triggerHeights[0]+1)){
	    	toolbox.setDisplaySize(4);
	    }
      
    }
    function SetHeaderState()
    {
    	this.idHeader 			= "spanQiGlobalHeadText";
    	this.idHeaderContainer	= "divQuickInfoGlobalHeader";
    	this.set				= Set;
    	this.setHeader			= SetHeader;
    	this.setLocalInfoLink	= SetLocalInfoLink;
    	this.setNotesTab		= SetNotesTab;
    	this.setQuickinfoTab	= SetQuickinfoTab;
    	this.tab_quickinfo		= "liQuickInfTab";
    	this.tab_notes			= "liNotesTab";
    	this.tab_localinfo		= "liAdminInfoTab";
    	function Set(state)
    	{
    		logger.log("toolbox.setHeaderState.set("+state+")");
    		toolbox.currentView = state;
    	
	    	if (!document.getElementById(this.idHeaderContainer).currentNodeId || document.getElementById(this.idHeaderContainer).currentNodeId != currentNode.id)
	    	{
	    		document.getElementById(this.idHeader).firstChild.nodeValue = currentNode.title;
	    		document.getElementById(this.idHeaderContainer).currentNodeId = currentNode.id
	    	}
	    	this.setHeader(state);
    	}
    	function SetHeader(state)
    	{
    		var admin 		= (state==3) ? true : false;
    		var notes		= (state==2) ? true : false;
    		var qi 			= (!admin && !notes); 

    		this.setLocalInfoLink(admin);
    		this.setNotesTab(notes);
    		this.setQuickinfoTab(qi);
    	}
    	function SetQuickinfoTab(state)
    	{
    		if (state){
    			document.getElementById(this.tab_quickinfo).className = "first selected";
    		} else {
    			document.getElementById(this.tab_quickinfo).className = "first";
    		}
    	}
    	function SetNotesTab(state)
    	{
    		if (!mom.features['feature_notes']){return;}
    		if (state){
    			document.getElementById(this.tab_notes).className = "selected";
    		} else {
    			document.getElementById(this.tab_notes).className = "";
    		}
    	}
    	function SetLocalInfoLink(state)
    	{
    		if (!mom.features['feature_adminlocalisation']){return;}
    		if (state && currentNode.hasAdminInfo){
   				document.getElementById(this.tab_localinfo).className = "selected";
   				document.getElementById(this.tab_localinfo).getElementsByTagName("A")[0].firstChild.nodeValue = "Local info";
   				document.getElementById(this.tab_localinfo).getElementsByTagName('A')[0].href = "javascript:toolbox.openLocalInfo();";
    		} else if (!state && currentNode.hasAdminInfo) {
    			document.getElementById(this.tab_localinfo).className = "";
    			document.getElementById(this.tab_localinfo).getElementsByTagName("A")[0].firstChild.nodeValue = "Local info";
    			document.getElementById(this.tab_localinfo).getElementsByTagName('A')[0].href = "javascript:toolbox.openLocalInfo();";
    		} else if (mom.roles["role_admin_editor"]) {
    			document.getElementById(this.tab_localinfo).className = "off";
    			document.getElementById(this.tab_localinfo).getElementsByTagName("A")[0].firstChild.nodeValue = "Add local info";
    			document.getElementById(this.tab_localinfo).getElementsByTagName('A')[0].href = "javascript:toolbox.openLocalInfoForm();";
    		} else {
    			document.getElementById(this.tab_localinfo).className = "off";
    			document.getElementById(this.tab_localinfo).getElementsByTagName("A")[0].firstChild.nodeValue = new String;
    			document.getElementById(this.tab_localinfo).getElementsByTagName('A')[0].href = "javascript:void(0);";
    		}
    	}
    }
    function SetIsActive(active)
    {
        if (active)
        {
            this.isActive =  true;
            this.className = "open";
        }
        else
        {
            this.isActive = false;
            this.className = "closed";
        }
    }
    function ShowSearchBar()
    {
        document.getElementById("divSearchBar").style.display = (document.getElementById(this.id).isActive) ? "block" : "none" ;
    }
    function SubmitSearch(page, pathway, node)
    {
        if (window.demo && demo.active){demo.warn();return}
        logger.log("toolbox.submitSearch()");
        this.search.closeNLH();
        this.append('divSearchPanel');
        this.search.submitSearch(page, pathway, node);
    }
    function SubmitSearchBNF(url, page, pathway, node)
    {
        logger.log("toolbox.submitSearchBNF()");
        this.search.submitSearchBnf(url, page, pathway, node);
    }
    function SubmitSearchCE()
    {
		if (window.demo && demo.active){demo.warn();return}
        logger.log("toolbox.submitSearchCE()");
        this.search.closeNLH();
        this.append('divSearchPanelCE');
        this.search.submitSearchSnowedCE();
    }
    function SubmitSearchNLH(page, pathway, node)
    {
		if (window.demo && demo.active){demo.warn();return}
        logger.log("toolbox.submitSearchNLH()");
        this.search.closeNLH();
        this.append('divSearchPanel');
        this.search.submitSearchSnowed(page, pathway, node);
    }
    function SubmitSearchGoogle(url, page, pathway, node)
    {
        logger.log("toolbox.submitSearchGoogle()");
        this.search.submitSearchGoogle(url,page, pathway, node);
    }
    function SubmitSearchGereralCE()
    {
        logger.log("toolbox.submitSearchGeneralCE() not implemented");
    }
    function Toggle()
    {
        if (document.getElementById(this.id).isActive)
        {
            this.close();
        }
        else
        {
            if (arguments.length)
            {
                this.open(arguments);
            }
            else
            {
                this.openAndLoad();
            }
        }
    }
    function ToggleTab(id)
    {
        if (document.getElementById(id).isActive)
        {
            this.close();
        }
        else
        {
            this.open(id);
        }
    }
    function TabOff(){this.src = this.src.replace(/_on/g,"_off")}
    function TabOn(){this.src = this.src.replace(/_off/g,"_on")}
    function TabSetState()
    {
        if (document.getElementById(this.id.replace(/tab/,"div")).isActive)
        {
            this.on();
        }
        else
        {
            this.off();
        }
    }
}
function ToolBoxAdmin()
{
    this.close				= Close;			
    this.checkRevertInfo	= CheckRevertInfo;
    this.editCancel			= Cancel;			
    this.editClear			= Clear;			
    this.editRevert			= EditRevert;		
    this.editRevertCancel	= EditRevertCancel;
    this.editRevertSave		= EditRevertSave;
    this.editSave			= EditSave;
    this.getRevertInfo		= GetRevertInfo;	
    this.getCurrentInfo		= GetCurrentInfo;
    this.getCurrentNodeAdminInfo = GetCurrentNodeAdminInfo;
    this.info				= Info;
    this.idAdminDispaly     = "divAdminExistingInfo_display";
    this.idAdminNote        = "pEditAdminInfo_note";
    this.idAdminData        = "pEditAdminInfo_data";
    this.nameLiLocalLink    = "liEditAdminInfo_link";
    this.idGuidanceNote     = "divGuidanceNote";
	this.idTagLineElement 	= "h5QiSubHeadText_admininfo";
    this.loadContent		= LoadContent;		
    this.loadRevertInfo		= LoadRevertInfo;	
    this.loadRevertDisplay	= LoadRevertDisplay;
    this.nodeHasRevert		= NodeHasRevert;	
    this.reset				= Reset;			
    this.revertHide			= RevertHide;		
    this.revertShow			= RevertShow;
    this.savedInfoGet		= null;
    this.savedInfoLoad		= null;
    this.getUrl				= GetURL;			
    this.compareSelection	= CompareSelection; 
    this.storeSelection		= StoreSelection;	
    this.putSelection 		= PutSelection;		

    this.getGuidanceNote        = GetGuidanceNote        
    this.guidanceSet            = false;
    this.setGuidanceNote        = SetGuidanceNote        

    this.idTextAdminInfo    = "textareaAdminInfo_edit";
    var inf = "";
    function Cancel()
    {
    	if (currentNode.hasAdminInfo)
    	{
    		toolbox.openLocalInfo();
    	}
    	else
    	{
    		toolbox.openQuickInfo();
    	}
    }
    function Close()
    {
      
    }
    function Clear()
    {
        logger.log("toolbox.admin.clear()");
        try
        {
            if (FCKeditorAPI.GetInstance('textareaAdminInfo_edit').GetHTML("").trim() && confirm(ToolBox_Message_Admin_Confirm_Clear))
            {
	            FCKeditorAPI.GetInstance('textareaAdminInfo_edit').SetHTML("");
            }
            document.getElementById(this.idTextAdminInfo).focus();
        }
        catch (e){glb_ErrorReporter(e,'error clearing admin info');}
    }
    function EditRevert()
    {
        this.revertShow();	
        this.loadRevertDisplay();
    }
    function EditRevertCancel()
    {
        this.revertHide();
    }
    function EditRevertSave()
    {
        logger.log("toolbox.admin.editRevertSave()");
        try
        {
            if (confirm(ToolBox_Message_Revert) && currentNode.id)
            {
                document.forms["revertForm"].nodeID.value = currentNode.id;
                document.forms["revertForm"].submit();
            }
        }
        catch (e){glb_ErrorReporter(e,'error sumbiting revert form');}
    }
    function EditSave()
    {
    	logger.log("toolbox.admin.editSave()");
		if (document.getElementById("laicon_"+ currentNode.id)){
			document.getElementById("laicon_"+ currentNode.id).style.display    = "block";
		}
        document.adminInfoEditorForm.submit();
    }
    function GetRevertInfo()
    {
        logger.log("toolbox.admin.getRevertInfo()");
        if (currentNode.hasLocalInfo)
        {
            var url = "ancestorAdminLocalisation.html?pageNodeId=" + currentNode.id + "&page-id=" + pageid;
            window.frames['iframeGetRevertInfo'].location.replace( url );
        }
    }
    function GetCurrentNodeAdminInfo()
    {
        try {
            var form = document.forms["form_node_content_" + currentNode.id];
            currentNode.hasAdminInfo         = ( form["adminInfoTxt"].value.length ) ? true : false ;
            currentNode.hasLocalInfo         = ( form["localized"].value == "true" ) ? true : false ;
            currentNode.hasAdminInfoCleared     = ( form["adminInfoTxt"].value == "" ) ? true : false ;
        } catch(e){glb_ErrorReporter(e,"error in admin.getCurrentNodeAdminInfo()");}
    }
    function Info()
    {
        var m         = new String;
        m+=         "currentNode.id = " + currentNode.id + "\n";
        m+=         "currentUser.adminEditor = "+ currentUser.adminEditor +"\n";
        m+=         "currentUser.adminViewer = "+ currentUser.adminViewer +"\n";
        m+=         "currentUser.notesEditor = "+ currentUser.notesEditor +"\n";
        m+= 		"currentNode.hasLocalInfo = "+ currentNode.hasLocalInfo +"\n";
        m+= 		"currentNode.hasAdminInfo = "+ currentNode.hasAdminInfo +"\n";
        m+= 		"currentNode.hasAdminInfoCleared = "+ currentNode.hasAdminInfoCleared +"\n";
        m+=         "NodeHasRevert = " + this.nodeHasRevert()  + "\n";
        alert(m);
    }
    function LoadContent()
    {
        logger.log("toolbox.admin.loadContent()");
        this.setGuidanceNote();
        this.getCurrentNodeAdminInfo();
       
       
        this.getCurrentInfo();
        try{
            document.forms["adminInfoEditorForm"].nodeID.value                     = currentNode.id;
            document.forms["adminInfoEditorForm"].nodeText.value                   = currentNode.title;
            document.forms["adminInfoEditorForm"].adminInfoText.value              = adminInfoTxt.trim();
            document.getElementById("pEditData").innerHTML                         = adminDisplayData;
            glb_HideIfEmpty("pEditData");
            FCKeditorAPI.GetInstance('textareaAdminInfo_edit').SetHTML(replaceUrlNoTitle(adminInfoTxt.trim()));            
        } catch(e){glb_ErrorReporter(e,"error in admin.loadContent()");}
        try {
            if (document.forms["adminInfoEditorForm"].adminInfoText.value){
                document.getElementById(this.idTagLineElement).innerHTML = document.getElementById(this.idTagLineElement).innerHTML.replace(/Add/,"Edit");
            } else {
                document.getElementById(this.idTagLineElement).innerHTML = document.getElementById(this.idTagLineElement).innerHTML.replace(/Edit/,"Add");
            }
        } catch(e){glb_ErrorReporter(e,"error in admin.loadContent()");}
        if ( this.nodeHasRevert() )
        {
            document.getElementById("spanAlowRevert").style.display = 'inline';
        }
        else
        {
            document.getElementById("spanAlowRevert").style.display = 'none';
        }
        logger.log("- has revert ? "+ this.nodeHasRevert());
    }
    function replaceUrlNoTitle(text){
        var replacement = "<a href='$1'>$2</a>"
        text = text.replace(/\n/g,"<br />");
        text = text.replace(/\[(mailto:[\S]*) ([\S ]*?)\]/g, replacement);
        text = text.replace(/\[(https?:\/\/[\S]*) ([\S ]*?)\]/g, replacement);
		return text;
	}
    function GetCurrentInfo()
    {
        logger.log("toolbox.admin.getCurrentInfo()");
        try {
            var form = document.forms["form_node_content_" + currentNode.id];
            window.adminInfoId                        = currentNode.id;
            window.adminInfoTxt                        = form.adminInfoTxt.value;
            window.adminLastAuthorName                = form.lastAuthorName.value;
            window.adminLastAuthorVariantName        = form.lastAuthorVariantName.value;
            window.adminLastModified                = form.lastEditDate.value;
            window.pageid                            = form.pageid.value;
            window.adminDisplayData                    = window.adminLastAuthorName +" | "+ window.adminLastModified;
            if (window.adminDisplayData == " | "){window.adminDisplayData = ""}
        } catch (e){glb_ErrorReporter(e,'error loading current info');}
    }
    function LoadRevertInfo(revertText,revertAuthor,revertDate)// used by the iframe content page ancestorAdminLocalisation.xsl
    {
        logger.log("toolbox.admin.loadRevertInfo()");
        window.revertInfoText         = revertText;
        window.revertAuthor         = revertAuthor;
        window.revertDate             = revertDate;
        window.revertDisplayData     = revertAuthor +" | "+ revertDate;
        window.revertDisplayData     =  (window.revertDisplayData==' | ') ? '' : window.revertDisplayData;
    }
    function LoadRevertDisplay()
    {
        logger.log("toolbox.admin.loadRevertDisplay()");
        var form = document.forms["revertForm"];
        try
        {
            document.getElementById("spanQiHeadText_admininfo_revert").innerHTML = window.currentNode.title
           
            document.getElementById("textareaAdminInfo_revert_current").innerHTML     = adminInfoTxt;
            document.getElementById("pFromData").innerHTML                         = adminDisplayData;
           
            document.getElementById("textareaAdminInfo_revert_archive").innerHTML   = revertInfoText;
            document.getElementById("textareaAdminInfo_revert_revertToText").value   = revertInfoText;
            form.nodeID.value                                                     = currentNode.id;
            document.getElementById("pToData").innerHTML                         = revertDisplayData;
        }
        catch (e){glb_ErrorReporter(e,'error loading admin revert display');}
        glb_HideIfEmpty("pToData");
    }
    function CheckRevertInfo()
    {
    	logger.log("toolbox.admin.checkRevertInfo()");
        if (currentUser.adminEditor)
        {
            if (currentNode.hasLocalInfo)
            {
                inf+= "loading admin display content (ie. item has saved info )...\n";
                try
                {
                   
                    toolbox.admin.getCurrentInfo();
                    window.revertInfoText                     = "";
                    window.revertDisplayData                 = "";   
                    toolbox.admin.getRevertInfo();
                    document.getElementById(this.idAdminNote).innerHTML = adminInfoTxt.br();
                }
                catch (e)
                {
                    glb_ErrorReporter(e,inf);
                }
            }
            else
            {
                window.adminInfoTxt         = " ";
                window.adminLastAuthorName    = " ";
                window.adminLastModified     = " ";
                window.adminDisplayData     = " ";
            }
        }
    }
    function NodeHasRevert()
    {
        var form = document.forms["form_node_content_" + currentNode.id];
        return ( !mom.variants["is-root-current"] && form.canEdit.value == "true" && currentNode.hasLocalInfo );
    }
    function Reset()// make sure we don't get any carry over from nodes, clear all field and close
    {
        logger.log("toolbox.admin.reset()");
        if (currentUser.adminEditor)
        {
            var inf = "Get revert info\n";
            try
            {
                var form = document.forms["revertForm"];
               
                document.getElementById("textareaAdminInfo_revert_current").value = "";
                document.getElementById("pFromData").innerHTML = "";
               
                document.getElementById("textareaAdminInfo_revert_archive").value = "";
                form.nodeID.value = "";
            }
            catch (e){glb_ErrorReporter(e,inf);};
            inf+= "Reset adminInfoEditorForm display\n";
            try
            {
                if (document.getElementById("divGuidanceNote").loadGuidanceNote) {
                    document.getElementById("divGuidanceNote").loadGuidanceNote("");
                }
                document.forms["adminInfoEditorForm"].nodeID.value                     = "";
                document.forms["adminInfoEditorForm"].adminInfoText.value             = "";
                document.getElementById("pEditData").innerHTML                           = "";
            }
            catch (e){glb_ErrorReporter(e,inf)};
        }
    }
    function RevertShow()
    {
    	logger.log("toolbox.admin.revertShow()");
    	try {
	        toolbox.open("divAdminInfoRevert");
	        if (document.getElementById("divSearchBar")){
	        	document.getElementById("divSearchBar").style.display="none";
	        }
	        toolbox.localinfo.setHeight();
        } catch (e){glb_ErrorReporter(e,"[error] admin.revertShow()")};
    }
    function RevertHide()
    {
    	try {
    		toolbox.open("divDefaultPanel")
	        toolbox.openLocalInfoForm();
        } catch (e){glb_ErrorReporter(e,"[error] admin.revertHide()")};
    }
    function GetURL()
    {
        if (!document.selection && !window.getSelection)
        {
            alert(ToolBox_Message_SelectionNotSupported)
        }
        else if (this.compareSelection())
        {
            this.putSelection( prompt( ToolBox_Message_Admin_Prompt_url, "http:/"+"/" ) );
        }
        else
        {
            alert(ToolBox_Message_NoSelection);
        }
    }
    function StoreSelection()
    {
        window.currentSelection = (document.selection) ? document.selection.createRange().text : (document.getSelection) ? document.getSelection() : "" ;
    }
    function CompareSelection()
    {
        var isOk = false;
        var temp = (document.selection) ? document.selection.createRange().text : (document.getSelection) ? document.getSelection() : "" ;
        if (window.currentSelection && window.currentSelection == temp)
        {
            isOk = true;
        }
        return isOk;
    }
    function PutSelection(href)
    {
        if (!href){return;}
        var label = window.currentSelection.trim();
        href = href.trim();
        if (document.selection){
            document.selection.createRange().text = "["+ href +" "+ label +"] ";
        }
        else if (window.getSelection){
            label = window.getSelection();
            window.getSelection() = "["+ href +" "+ label +"] ";
        }
        else if (document.getSelection){
            label = document.getSelection();
            document.getSelection() = "["+ href +" "+ label +"] ";
        }
    }
    function GetGuidanceNote(customNote)// attached to the Guidance Note div
    {
       
        if (customNote)
        {
            this.innerHTML = customNote;
        }
        else if (!customNote && this.innerHTML != this.defaultGuidanceNote)
        {
            this.innerHTML = this.defaultGuidanceNote
        }
    }
    function SetGuidanceNote()
    {
    	if (!this.guidanceSet){
	        document.getElementById(this.idGuidanceNote).defaultGuidanceNote  = document.getElementById(this.idGuidanceNote).innerHTML;
	        document.getElementById(this.idGuidanceNote).loadGuidanceNote     = this.getGuidanceNote;
            this.guidanceSet = true
	    } else {
			var inf = "";
	        inf+= "loading guidance content ("+ currentNode.id +")...\n";
	        try
	        {
	            document.getElementById(this.idGuidanceNote).loadGuidanceNote(currentNode.guidanceNote);
	            inf+= "normal content loaded\n";
	        }
	        catch (e){glb_ErrorReporter(e,inf);}
        }
    }
}
function ToolBoxLocalInfo()
{
    this.loadContent		= LoadContent;
    this.setHeight			= SetHeight;
    this.idBody				= "divLiBody";
    this.idEditTextarea		= "textareaAdminInfo_edit";
    this.idEditLink			= "pLocalInfo_editLink";
    this.idData				= "pLocalInfo_data";
    function LoadContent()
    {
        logger.log("toolbox.localinfo.loadContent()");
        try
        {
            toolbox.admin.getCurrentInfo();
        } catch (e){glb_ErrorReporter(e,'[error] getting current localinfo content');}
        try {
            document.getElementById("pLocalInfo_note").innerHTML = replaceUrl(currentNode.localinfo);
            document.getElementById("pLocalInfo_data").innerHTML = adminDisplayData;
        } catch(e){
            glb_ErrorReporter(e,"Couldn't load local info")
        }
       
        document.getElementById(this.idEditLink).className = (currentUser.adminEditor) ? "show pb" : "hidden" ;
    }
	function replaceUrl(text){
        var mailtoReplacement = "<a title='Opens e-mail application' class='externalLinkNoPic' target='_blank' href='$1'>$2</a>",
            httpReplacement = "<a title='Opens in a new window' class='externalLinkNoPic' href='$1' onclick='openExternalLink(\"$1\",\"admininfo\",currentNode.title, mom.pageName, mom.pathwayName); return false;'>$2<img src='../i/global/external.gif' alt='' /></a>";            
        text = text.replace(/\n/g,"<br />");
        text = text.replace(/\[(mailto:[\S]*) ([\S ]*?)\]/g, mailtoReplacement);
        text = text.replace(/\[(https?:\/\/[\S]*) ([\S ]*?)\]/g, httpReplacement);
		return text;
	}
    function SetHeight(){
        logger.log("toolbox.localinfo.setHeight()");
        var offset = 0;
        offset += document.getElementById(this.idData).offsetHeight;
        offset += document.getElementById(this.idEditLink).offsetHeight;
        toolbox.quickinfo.setHeight(document.getElementById(this.idBody), offset);
        offset += document.getElementById("h5QiSubHeadText_admininfo").offsetHeight;
        offset += document.getElementById("pEditData").offsetHeight;
        toolbox.quickinfo.setHeight(document.getElementById(this.idEditTextarea), offset);
        if (document.getElementById("textareaAdminInfo_revert_current")) {
            toolbox.quickinfo.setHeight(document.getElementById("textareaAdminInfo_revert_current"), 60);
            toolbox.quickinfo.setHeight(document.getElementById("textareaAdminInfo_revert_archive"), 60);
        }
        if (document.getElementById("textareaAdminInfo_edit___Frame")) {
            toolbox.quickinfo.setHeight(document.getElementById("textareaAdminInfo_edit___Frame"), 60);
        }
    }
}
function ToolBoxNotes()
{
    this.edit					= Edit;						
    this.editCancel				= EditCancel;				
    this.editClear				= EditClear;				
    this.editForm				= EditForm;					
    this.editReset				= EditReset;				
    this.editRevert				= EditRevert;				
    this.editSave				= EditSave;					
	this.editView				= false;					
	this.editViewEdit			= EditViewEdit;				
	this.editViewReset			= EditViewReset;			
    this.feedbackSave			= FeedbackSave;				
    this.id						= "divNotes";				
    this.idTextarea				= "textareaNotesEdit";		
    this.idViewarea				= "textareaNotesFeedback"; 	
    this.loadContent			= LoadContent;				
    this.setView				= EditSetView;				
    this.setHeight				= SetTextAreaHeight			

    function LoadContent(id)
    {
        var currentid		= glb_ToolBox_CurrentId(id);
        var inf				= new String;
        var form			= document.forms["form_node_content_" + currentNode.id];
        this.valid			= Valid;                   

        logger.log("toolbox.notes.loadContent()");
        try
        {
            toolbox.admin.getCurrentNodeAdminInfo();
            inf = "content aquired\n";
            if (!currentNode.note)
            {
                currentNode.note = ToolBox_Message_Note_none;
            }
            document.forms["noteEditorForm"].noteText.value = document.noteFeedbackForm.comment.value = currentNode.note.br_remove();
            document.noteFeedbackForm.nodeText.value = currentNode.title;
            inf+= "content values loaded\n";
            if (!document.getElementById(this.idTextarea).setClearText)
            {
                document.getElementById(this.idTextarea).onfocus             = glb_DefaultTextClear;
                document.getElementById(this.idTextarea).reset                 = glb_DefaultTextReset;
                document.getElementById(this.idTextarea).defaultText         = ToolBox_Message_Note_none;
                document.getElementById(this.idTextarea).valid                = this.valid;
                document.getElementById(this.idTextarea).setClearText         = true;
            }
            else
            {
                document.getElementById(this.idTextarea).reset();
            }
           
            inf+= "clear text set";
        }
        catch (e)
        {
            glb_ErrorReporter(e,inf);
        }
        function Valid()
        {
            var ok = false;
            if (this.value != this.defaultText)
            {
                ok = true;
            }
            return ok;
        }
    }
    function Edit()
    {
    	this.setView("edit");
    }
    function EditClear()
    {
        if (confirm(ToolBox_Message_Note_Confirm_Clear)) {
            document.getElementById(this.idTextarea).value = "";
        }
    }
    function EditCancel()
    {
    	if(currentNode.hasNote)
    	{
	        toolbox.openNotes();
    	}
    	else
    	{
         	toolbox.openQuickInfo();
    	}
    }
    function EditForm()
    {
    	logger.log("toolbox.notes.editForm()");
        var set = this.editViewEdit();
    }
    function EditRevert()
    {
        this.loadContent();
    }
    function EditReset()
    {
    	logger.log("toolbox.notes.editReset()");
        var set = this.editViewReset();
    }
    function EditViewReset()
    {
    	logger.log("toolbox.notes.editViewReset()");
        document.getElementById("formNoteEditorForm").style.display = "none";
        document.getElementById("formNoteFeedbackForm").style.display = "block";
        this.editView = false;
        return 0;
    }
    function EditViewEdit()
    {
    	logger.log("toolbox.notes.edit()");
        document.getElementById("formNoteEditorForm").style.display = "block";
        document.getElementById("formNoteFeedbackForm").style.display = "none";
        this.editView = true;
        return 0;
    }
    function EditSave()
    {
        logger.log("toolbox.notes.EditSave()");
        if (document.getElementById(this.idTextarea).valid())
        {
            window.txtQuickInfoNotes = document.noteEditorForm.noteText.value;
            if (window.txtQuickInfoNotes.checkLength())
            {
                try {
                    var form = document.forms["form_node_content_" + currentNode.id];
                    var formNotes = document.forms["noteEditorForm"];
                    form["quickInfoNote"].value = txtQuickInfoNotes;
                    document.getElementById("noteicon_"+ currentNode.id).style.display    = "block";
                    formNotes.nodeId.value = formNotes.nodeID.value = currentNode.id;
                    formNotes.nodeText.value = currentNode.title;
					formNotes.submit();
                }
                catch (e){glb_ErrorReporter(e,"Submitting the notes update form");}
            }
        }
    }
    function EditSetView(toggle)
    {
    	logger.log("toolbox.notes.setView()");
    	if ( toggle == "edit")
    	{
    		this.editForm();
    	}
        else if ( document.noteEditorForm.noteText.value == ToolBox_Message_Note_none )
        {
            this.editForm();
        }
        else
        {
            this.editReset();
        }
        this.setHeight();
    }
    function FeedbackSave()
    {
    	document.noteFeedbackForm.nodeId.value = document.noteFeedbackForm.nodeID.value = currentNode.id;
        document.noteFeedbackForm.submit();
    }
    function SetTextAreaHeight()
    {
        logger.log("toolbox.notes.setHeight()");
		var offset = 0;
        if (document.getElementById(this.idViewarea).style.overflowX)
        {
            try {
                document.getElementById(this.idViewarea).style.overflowX = "hidden";
            } catch (e){}
        }
        if (this.editView) {
        	offset = document.getElementById("pNoteLinks").offsetHeight + 5;
        	toolbox.quickinfo.setHeight(document.getElementById(this.idTextarea),offset);
        } else {
        	offset = document.getElementById("pFeedbackLinks").offsetHeight;
        	toolbox.quickinfo.setHeight(document.getElementById(this.idViewarea),offset);
        }
    }
}
function ToolBoxQuickInfo()
{
    this.loadContent            = LoadContent;            
    this.reset                  = Reset;               

   
    this.idBody                 = "spanQiBody";
    this.idScrollBody			= "divQiBody";
    this.i                      = 0;
    this.setHeight              = SetHeight;

    function SetHeight(element,offset)
    {
    	element = (element || document.getElementById("divQiBody"));
   		logger.log("toolbox.quickInfo.setHeight("+element.id+")");
   		var fallBackOffset = 24;
   		var padding = fallBackOffset;
   		if (element.currentStyle){
   			padding = (parseInt(element.currentStyle["paddingTop"]) + parseInt(element.currentStyle["paddingBottom"]) );
   		}
  		if (isNaN(padding)) {padding = fallBackOffset};
    	var height = (gbl_IntCombinedHeight-1);
    	offset = (offset || 0);
    	height = (height - glb_GetOffsetTop(element,document.getElementById(ToolBox_RootElementId))) - offset;
    	height = (mom.features['feature_nlh']) ? (height - document.getElementById("divSearchBar").offsetHeight) : height ;
    	element.style.height = (height-padding) +"px";
    }
    function LoadContent()
    {
        logger.log("toolbox.quickinfo.loadContent()");
        var inf = "";
        inf+= "loading normal content ("+ currentNode.id +")...\n";
        try
        {
            if (!currentNode.body || currentNode.body == "&nbsp;"){currentNode.body = ToolBox_Message_NoInfo};
            document.getElementById(this.idBody).innerHTML        = currentNode.body;
            document.getElementById(this.idScrollBody).scrollTop  = 0;
            inf+= "normal content loaded\n";
        }
        catch (e){glb_ErrorReporter(e,inf);}
		this.setHeight(document.getElementById(this.idScrollBody));
    }
    function Reset()
    {
        logger.log("toolbox.quickinfo.reset()");
        document.getElementById(this.idBody).innerHTML = "";
    }
}
function PopUp(){
    this.id = "divPopup";
    this.close = Close;
    this.idHeader = "h4fdbPopHeader";
    this.idText = "spanFdbPopUpText";
    this.idHTML = "spanFdbPopUpHTML";
    this.containerRef = "divToolBox";
    this.container = "divQiBody";
    this.title = "fdbHeaderSpan"
    this.popupLinks = "popUpLinks";
    this.show = Show;
    this.hide = Hide;
    this.getPostion = GetPosition;
    this.put = Put;
    this.showWithGraphic = ShowWithGraphic;
    this.getOffsetX = glb_GetOffsetLeft;// find position x, depricated set in css
    this.getOffsetY = glb_GetOffsetTop;
    this.img = "imgSpan"
    this.x = 0;
    this.y = 0;
    this.offsetY = 16;
    function Show(obj, title, popText, popLink, popDesc){
        var img = obj.getElementsByTagName('IMG')[0];
        this.getPostion(img);
        this.put();
        document.getElementById(this.id).style.display = "block";
        document.getElementById(this.container).attachEvent("onscroll", Close);
        document.getElementById(this.idText).innerHTML = popText;
        document.getElementById(this.title).innerHTML = title;
        document.getElementById(this.popupLinks).innerHTML = "";
        if (popLink.length > 0 && popDesc.length == popLink.length) {
            for (i = 0; i < popLink.length; i = i + 1) {
                var linkExist = document.getElementById(this.id).getElementsByTagName("A")[i];
                if (!linkExist) {
                    var linkParagraph = document.getElementById(this.popupLinks);
                    var firstLink = document.createElement('a');
                    linkParagraph.appendChild(firstLink);
                    firstLink.href = popLink[i];
                    firstLink.innerHTML = popDesc[i] + " ";
                }
                else {
                    linkExist.href = popLink[i];
                    linkExist.innerHTML = popDesc[i] + " ";
                }
            }
        }
        this.popActive = true;
        function Close(){
            this.detachEvent("onsrcoll", Close);
            toolbox.popUp.hide();
        }
    }
    function ShowWithGraphic(obj, title, popText, popLink, popDesc, img, styleName){
        var imgSpan = document.getElementById(this.img);
        var graphicExist = document.getElementById(this.id).getElementsByTagName("img")[1];
        if (!graphicExist) {
            var firstImg = document.createElement('img');
            imgSpan.appendChild(firstImg);
            firstImg.src = img;
            firstImg.className = styleName;
        }
        toolbox.popUp.show(obj, title, popText, popLink, popDesc);
    }
    function Close(){
        toolbox.popUp.hide();
    }
    function Hide(){
        document.getElementById(this.id).style.display = "none";
        this.popActive = false;
    }
    function GetPosition(obj){
        this.y = (this.getOffsetY(obj, document.getElementById(this.containerRef)) - document.getElementById(this.container).scrollTop);
    }
    function Put(){
        document.getElementById(this.id).style.top = (this.y + this.offsetY) + "px";
    }
}
function ToolBoxSearch()
{
    this.cePop                     = new CePop;            
    this.close                     = Close;               
    this.closeNLH                 = CloseNLH;               
    this.idIframe                 = "iframeSearchResults";
    this.idIframeCE                = "iframeSearchResultsCE";
    this.nlhSearch                 = new NlhSearch;       
    this.openNLH                 = OpenNLH;                
    this.submitSearch             = SubmitSearch;           
    this.submitSearchSnowed     = SubmitSearchSnowed;   
    this.submitSearchBnf          = SubmitSearchBnf;       
    this.submitSearchGoogle          = SubmitSearchGoogle;       
    this.submitSearchSnowedCE     = SubmitSearchSnowedCE;   
    this.submitSearchGeneralCE     = SubmitSearchGeneralCE;// node level search
    function CePop()
    {
        this.id             = "divCePop";
        this.container         = "divQiBody";
        this.containerRef     = "divToolBox";
        this.idSearchDisplay= "strongSearchTerm";
        this.idHeader        = "h4cePopHeader";
        this.idText            = "spanText";
       
        this.currentObj        = null;
        this.currentImg        = null;
        this.getOffsetX     = glb_GetOffsetLeft;// find position x, depricated set in css
        this.getOffsetY     = glb_GetOffsetTop;   
        this.getPostion     = GetPosition;
       
        this.hide             = Hide;
        this.mOut            = MouseOut;
       
        this.offsetY        = 16;                
        this.popActive         = false;
        this.put             = Put;
        this.show             = Show;
       
        this.toggle         = Toggle;            
        this.x                = 0;
        this.y                = 0;
        function GetPosition(obj)
        {
            this.y = ( this.getOffsetY(obj,document.getElementById(this.containerRef)) - document.getElementById(this.container).scrollTop );
        }
        function Hide()
        {
            document.getElementById(this.id).style.display = "none";
            document.getElementById(this.idSearchDisplay).firstChild.nodeValue = "search term";
            this.popActive = false;
        }
        function MouseOut()
        {
            if (this.image){this.image.out()};
        }
        function Put()
        {
            document.getElementById(this.id).style.top     = (this.y + this.offsetY)+"px";
        }
        function Show(obj)
        {
			var clone = obj.cloneNode(true);
			if (clone.getElementsByTagName("IMG")[0])
				clone.removeChild(clone.getElementsByTagName("IMG")[0]);
			document.getElementById(this.id).style.display = "block";
            document.getElementById(this.container).attachEvent("onscroll",Close);
			document.getElementById(this.idSearchDisplay).innerHTML = clone.innerHTML;
            var firstLink = document.getElementById(this.id).getElementsByTagName("A")[0];
            if (!firstLink)// all links are disabled so nothing to display. change message to reflect this
            {
                document.getElementById(this.idText).style.display = "none";
                document.getElementById(this.idHeader).getElementsByTagName("SPAN")[0].firstChild.nodeValue = ToolBox_Message_Search_none_cepop;
            }
            this.popActive = true;
            function Close()
            {
                this.detachEvent("onsrcoll",Close);
                toolbox.search.cePop.hide();
            }
        }
        function Toggle(obj,numbers,texts,types,ilinkName,pathwayName)
        {
            logger.log("toolbox.search.cePop.toggle()");
            ToolBox_QuickSearch_numbers            = numbers;
            ToolBox_QuickSearch_text            = ilinkName + ToolBox_ArrayDelimiter + pathwayName;
            ToolBox_QuickSearch_types            = types;
            ToolBox_QuickSearch_ilink           = ilinkName;
            ToolBox_QuickSearch_pathway           = pathwayName;
            obj = glb_GetParentTagName(obj,"A");
            var img = obj.getElementsByTagName('IMG')[0];           
            obj.onmouseout = this.mOut;                               
            if (this.popActive == true && this.currentObj == obj)    
            {
                img.over();
                this.hide();
            }
            else
            {
                if (this.currentImg)
                {
                    try {this.currentImg.off()}
                    catch(e){glb_ErrorReporter(e,'[error] swapping image src');}
                }
                try {
                    this.currentObj = obj;
                    this.currentImg = img;
                    this.getPostion(img);
                    this.put();
                    this.show(obj);
                }
                catch(e){glb_ErrorReporter(e,'[error] problem in ce toggle');}
            }
        }
    }
    function Close()
    {
        this.closeNLH();
    }
    function CloseNLH()
    {
        this.nlhSearch.close();           
        toolbox.hide("divSearchPanel","divSearchPanelCE");   
        this.cePop.hide();                
    }
    function NlhSearch()
    {
        this.ceLoad         = LoadCe;           
        this.close          = Close;
        this.id             = "divSearchPanelForm";
        this.idDisplay      = "divSnomedSelectBox";
        this.idTextarea     = "inputTermBox";
        this.open           = Open;
       
        function LoadCe(sid)
        {
           
            sid = glb_ToolBox_CurrentId(sid);
            if (document.getElementById("snomedCheckboxes_" + sid)) {
                document.getElementById(this.idDisplay).innerHTML = document.getElementById("snomedCheckboxes_" + sid).innerHTML;
            }
            else {
                document.getElementById(this.idDisplay).innerHTML = "";
            }
            if (document.getElementById("nodeName_" + sid)) {
                document.getElementById("divAdditionalSelectBox").innerHTML = document.getElementById("nodeName_" + sid).innerHTML;
            }
        }
        function Close()
        {
        	logger.log("toolbox.search.nlhSearch.close()");
        	toolbox.hide(this.id);
           
        }
        function Open()
        {
        	logger.log("toolbox.search.nlhSearch.open()");
        	toolbox.append(this.id);
           
        }
    }
    function OpenNLH(inputTerm)
    {
    	logger.log("toolbox.search.openNLH()");
    	if (window.demo && demo.active){demo.warn();return}
        glb_IframeReset(document.getElementById(this.idIframe));
        glb_IframeReset(document.getElementById(this.idIframeCE));
		toolbox.hide("divGuidanceNoteContainer","divSearchPanel","divSearchPanelCE");
        this.nlhSearch.ceLoad(window.currentNode.id);
        document.getElementById("inputTermBox").value = (inputTerm)? inputTerm : "";
        this.nlhSearch.open();
    }
    function SubmitSearch(page, pathway, node)
    {
        logger.log("toolbox.search.submitSearch()");
        sid = glb_ToolBox_CurrentId();
        glb_IframeReset(document.getElementById(this.idIframe));
        glb_IframeReset(document.getElementById(this.idIframeCE));
        var searchUrl = ToolBox_QuickSearch_url +"?page-nr=1&search-type=nlh&tab-id=0&search-state=searchNLH&nlh-checked=on";
        var additionalSearchTerms = ToolBox_ArraySnomed.getAdditionalSelected(); 
        var freeText ="";
        try
        {   
            freeText = document.getElementById(this.nlhSearch.idTextarea).value;
            searchUrl+=        "&freeText=" + freeText;
        }
        catch(e){searchUrl+="&freeText=";}
        if(document.getElementById(this.nlhSearch.idTextarea).value != '') searchUrl += " ";
        searchUrl += additionalSearchTerms.replace("_:_", " ");    
         try
        {
           
            searchUrl+=        "&snomedCodes=" + ToolBox_ArraySnomed.getCodesSelected();
            searchUrl+=        "&snomedTexts=" + ToolBox_ArraySnomed.getTextsSelected();
            searchUrl+=	"&page="+encodeURIComponent(page)+"&pathway="+encodeURIComponent(pathway)+"&node="+encodeURIComponent(node)+"&searchType=nodeNLH";
            searchUrl+= "&searchItems=" + ToolBox_ArraySnomed.getAdditionalSelected();            
            if(freeText.length > 0){
                if(additionalSearchTerms.length > 0) searchUrl+= "_:_";
                searchUrl += "'" + freeText + "'";
            }
            glb_SubmitSearch(this.idIframe,searchUrl);
        }
        catch(e){glb_ErrorReporter(e,"search url\n"+searchUrl)}
    }
    function SubmitSearchBnf(url,page, pathway, node)
    {
        logger.log("toolbox.search.submitSearchBnf()");
        var getSearch = ToolBox_QuickSearch_text.makeGoogleReady();
        var externalSearch = "externalSearch.html?href="+encodeURIComponent(url)+"&queryString="+encodeURIComponent(getSearch)+"&searchType=ctBNF&auditableId="+mom.pageid+"&useCase=Search+Bnf+Action&page="+encodeURIComponent(page)+"&pathway="+encodeURIComponent(pathway)+"&node="+encodeURIComponent(node);
        popup(externalSearch,"new");
    }
    function SubmitSearchGoogle(url,page, pathway, node)
    {
        logger.log("toolbox.search.submitSearchGoogle()");
        var getSearch = ToolBox_QuickSearch_text.makeGoogleReady();
        var externalSearch = "externalSearch.html?href="+encodeURIComponent(url)+"&queryString="+encodeURIComponent(getSearch)+"&searchType=ctGoogle&auditableId="+mom.pageid+"&useCase=Search+Google+Action&page="+encodeURIComponent(page)+"&pathway="+encodeURIComponent(pathway)+"&node="+encodeURIComponent(node);
        popup(externalSearch,"new");
    }
    function SubmitSearchSnowed(page, pathway, node)
    {
        logger.log("toolbox.search.submitSearchSnowed()");
        glb_IframeReset(document.getElementById(this.idIframe));
        glb_IframeReset(document.getElementById(this.idIframeCE));        try
        {
            var searchUrl = ToolBox_QuickSearch_url +"?page-nr=1&search-type=nlh&tab-id=0&search-state=searchNLH&nlh-checked=on";
            searchUrl+="&snomedTexts=&snomedCodes=";
            searchUrl+="&freeText=" + ToolBox_QuickSearch_ilink;
            searchUrl+="_:_" + ToolBox_QuickSearch_pathway;
			searchUrl+="&page=" + encodeURIComponent(page);
			searchUrl+="&pathway=" + encodeURIComponent(pathway);
			searchUrl+="&node=" + encodeURIComponent(node);
			searchUrl+="&searchType=ctNLH";
            glb_SubmitSearch(this.idIframe,searchUrl);
        }
        catch(e){glb_ErrorReporter(e,"search url\n"+searchUrl)}
    }
    function SubmitSearchSnowedCE()
    {
        logger.log("toolbox.search.submitSearchSnowedCE()");
        try
        {
            var searchUrl = "ceSearchSlider.action?page-nr=1&search-type=ce&tab-id=0";
            searchUrl+=        "&snomedCodes=&snomedTypes=" + ToolBox_QuickSearch_text.makeCEready();
            searchUrl+=     "&displayText=" + ToolBox_QuickSearch_text.makeCEready();
            searchUrl+=     "&nodeText=" + window.currentNode.title;
            glb_SubmitSearch(this.idIframeCE,searchUrl);
        }
        catch(e){glb_ErrorReporter(e,"search url\n"+searchUrl)}
    }
    function SubmitSearchGeneralCE(action,snomedCodes,snomedTypes,snomedTexts,displayText,nodeText)
    {
        logger.log("toolbox.search.submitSearchGeneralCE()");
        toolbox.append('divSearchPanel');
        try
        {
            var searchUrl = "ceSearchSlider.action?snomedCodes=" + snomedCodes + "&snomedTypes=" + snomedTypes +  "&displayText=" + displayText +"&nodeText=" + nodeText;
            glb_SubmitSearch(this.idIframeCE,searchUrl);
        }
        catch(e){glb_ErrorReporter(e,"search url\n"+searchUrl)}
    }
}
function ToolBoxReferralCriteria(){
    this.criteriaBlockId = "divReferralCriteria";
    this.criteriaTextId = "divReferralCriteriaText";
    this.criteriaHeaderId = "h4ReferTitle";
    this.setHeight = CriteriaSetHeight;
    this.loadContent = LoadContent;
    function CriteriaSetHeight(){
        logger.log("toolbox.referral.setHeight()");
      	toolbox.quickinfo.setHeight(document.getElementById(this.criteriaBlockId),0);        
    }
    function LoadContent()
    {
        logger.log("toolbox.referral.loadContent()");
        var inf = "";
        inf+= "loading normal content ("+ currentNode.id +")...\n";
        try
        {
            document.getElementById(this.criteriaHeaderId).innerHTML        = currentNode.title;
            if (!currentNode.referral || currentNode.referral == "&nbsp;") {currentNode.referral = "Referal criteria not defined."};
            document.getElementById(this.criteriaTextId).innerHTML        = currentNode.referral;
            document.getElementById(this.criteriaBlockId).scrollTop  = 0;
            inf+= "normal content loaded\n";
        }
        catch (e){glb_ErrorReporter(e,inf);}
    }
}
function glb_ImageInit(img){
    if (!img.set)
    {
        img.onmouseout  = img.out = glb_ImageRollOut;
        img.on             = glb_ImageOn;
        img.onActive    = false;
        img.onSrc        = img.src.replace(/_def/,"_on");
        img.off            = glb_ImageOff;
        img.offSrc        = img.src;
        img.over        = glb_ImageOver;
        img.overSrc        = img.src.replace(/_def/,"_over");
        img.set         = true;
    }
}
function glb_ImageRollOver(obj)
{
   
   
    var img;
    if (obj.tagName != "IMG")// e.g. if using rollover on A or LI tag
    {
        if (!obj.set)
        {
            obj.onmouseout = glb_ImageParentRollOut;
            obj.set = true;
            obj.image = obj.getElementsByTagName('IMG')[0];
        }
        img = obj.getElementsByTagName('IMG')[0];
    }
    else
    {
        img = obj;
    }
    if (!img.set)
    {
        glb_ImageInit(img);
    }
    if (!img.onActive)
    {
        img.src = img.overSrc;
    }
}
function glb_ImageParentRollOut()
{
    this.image.off();
}
function glb_ImageRollOut()
{
    if (!this.onActive)
    {
        this.src = this.offSrc;
    }
}
function glb_ImageOff()
{
    this.onActive = false;
    this.src = this.offSrc;
}
function glb_ImageOver()
{
    this.onActive = false;
    this.src = this.overSrc;
}
function glb_ImageOn()
{
    this.onActive = true;
    this.src = this.onSrc;
}
function glb_ToolBox_CurrentId(id)
{
    if (id){window.currentNode.id = id;};
    if (!window.currentNode.id){window.currentNode.id = 1;};
    return window.currentNode.id;
}
var feedbackDepth = 0;
function glb_ToolBoxKeepHorizontal(){}
function glb_ToolBoxKeepVertical()
{
    if (!document.getElementById("divToolBox")){return;}
    var t = 0;
    var x,y,z;
    var bufferTop         = 8;// buffer from top of page (where it starts scrolling)
    var bufferBottom     = 18;// buffer from bottom of container in px
    var tweak			= 8;// don't know why we need this, it's for the scrolling position
    if (document.body && document.body.scrollTop) {t = document.body.scrollTop}
    else if (document.documentElement && document.documentElement.scrollTop) {t = document.documentElement.scrollTop}
    if (t)// there is scrolling
    {
        x = ( document.getElementById("divToolBox").offsetFromBody - bufferTop );
        y = ( document.getElementById("divToolBox").offsetFromBody + document.getElementById("divFlowChart").offsetHeight - bufferBottom );// where to stop scroll
        z = ( document.getElementById("divToolBox").offsetHeight + document.getElementById("divToolBox").originaltop );
        if ( ( t > x ) && ( ( t + z )  <  y  ) ){
            document.getElementById("divToolBox").style.top = ( t - x )+(tweak) + "px";
		
        }
    }
    else
    {
        document.getElementById("divToolBox").style.top = (document.getElementById("divToolBox").originaltop) + "px";
    }
}
function str_AnchorPatten()
{
   return this.replace(/</g,"&lt;").replace(/\n/g,"<br/>").replace(/\[(http:\/\/[\S]*) ([\S ]*?)\]/g,"<a title='Opens in a new window' class='externalLinkNoPic' target='_blank' href=$1>$2<img src='../i/global/external.gif' alt='' /></a>");
}
function str_CheckLength()
{
    var ok = true;
    if (this.isMaxPostLength())    {alert(ToolBox_Message_MaxPostMessage);ok = false;}
    return ok;
}
function str_IsEmpty()
{
    return (this.trim().length == 0) ? true : false;
}
function str_IsMaxPostLength()
{
    return (this.length > maxPostLength)? true : false;
}
function str_Br()
{
   return this.replace(/\n/g,"<br/>");
}
function str_Br_remove()
{
   return this.replace(/&#13;/g,"");
}
function str_Trim()
{
   return this.replace(/^\s*|\s*$/g,"");
}
function str_MakeCEready()
{
    return this.replace(/_:_/g,",").replace(/,$/,"");
}
function str_MakeGoogleReady()
{
    var newSearch = this.replace(/,$/,"");
    newSearch = newSearch.split(/_:_/);
    for(i=0; i<newSearch.length; i++)
    {
        if(newSearch[i].match(" "))
        {
            newSearch[i] = "\"" + newSearch[i] + "\""
        }
    }
    newSearch = newSearch.toString();
    return newSearch.replace(/,/g, " ");
}
function ToolBox_SnomedItem(codes,texts,id)
{
    this.both        = new String;
    this.codes         = stringToArray(codes);
    this.id         = id;
    this.texts         = stringToArray(texts);
    this.both         = buildBoth(this.codes,this.texts);// possibility used on the results page
    function stringToArray(string)
    {
        var array = new Array;
        if (!string){string=""};
        array = string.split(ToolBox_ArrayDelimiter);
        return array;
    }
    function buildBoth(codes,texts)
    {
        var s = "";
        try {
            for (var i=0;i<codes.length;i++)
            {
                if (codes[i]) {s+="&snomedCode="+ codes[i] +"&text_"+ texts[i];}
            }
        }
        catch(e){glb_ErrorReporter(e,"Array error; "+ typeof(codes) +" - "+ typeof(texts) )}
        return s;
    }
}
function glb_GetValue()// so we don't submit the default text
{
    return (this.value != this.defaultText) ? this.value : "" ;
}
function glb_DefaultTextClear()// onfocus clear default text if necessary
{
    if (this.value == this.defaultText)
    {
        this.value = "";
    }
}
function glb_DefaultTextReset()// put back default text if empty
{
    if (this.value == "")
    {
        this.value = this.defaultText;
    }
}
function glb_DefaultTextResetOverride()// put back default text regardless
{
    if (this.value != this.defaultText)
    {
        this.value = this.defaultText;
    }
}
function glb_ErrorReporter(e,inf)
{
    if (ToolBox_Debug)
    {
        var m = "Error on "+ ToolBox_FileName +"\nLast function called "+ logger.getLast() +" \n  "+ e + "\n  "+ e.message;
        if (inf) m+="\n  "+ inf
        var v = confirm(m+"\n\nView history?");
        if (v) alert(logger.getHistory(20))
    }
    else
    {
        try {
            var message = escape("Error on toolbox.js\n\n"+ inf +"\n\n"+ e +"\n\n"+ e.message +"\n\n"+ toolbox.info() +"\n\n");
            gbl_sendError(message);
        } catch(e){}
    }
}
function glb_GetOffsetLeft(el,root)
{
    var x = 0;
    while (el != root){
        x += el.offsetLeft;
        el = el.offsetParent;
    }
    return x;
}
function glb_GetOffsetTop(el,root,test)
{
    var y = 0;
    if (!root){
        if (document.body){root = document.body ;}
        else if (document.documentElement){root = document.documentElement;}
    }
	do {
        y += el.offsetTop;
        el = el.offsetParent;
    } while (el && el != root)
	return y ;
}
function glb_Logger()
{
    this.getLast             = GetLast;
    this.getHistory         = GetHistory;
    this.last                = ShowLast;
    this.log                 = Log;
    this.reset                = Reset;
    this.review                = Review;
    function GetHistory(len)
    {
        var t = "";
        if (len)
        {
            for (i=ToolBox_Debug_papertrail.length;i>(ToolBox_Debug_papertrail.length - (len+1));i--)
            {
                if (ToolBox_Debug_papertrail[i]){t+="\t"+ToolBox_Debug_papertrail[i]+";\n"}
            }
            if (i>0){t+= "\t"+(i+1)+" more..."}
        }
        else
        {
            t = ToolBox_Debug_papertrail.reverse().join(";\n");
            ToolBox_Debug_papertrail.reverse();
        }
        return t;
    }
    function GetLast()
    {
        return ToolBox_Debug_papertrail[ToolBox_Debug_papertrail.length-1];
    }
    function Log(item)
    {
        ToolBox_Debug_papertrail.push(item);
    }
    function Reset()
    {
        ToolBox_Debug_papertrail = null;
        ToolBox_Debug_papertrail = new Array;
    }
    function Review()
    {
        alert(this.getHistory());
    }
    function ShowLast(i)
    {
        if (i)
        {
            alert(this.getHistory(i));
        }
        else {
            alert(this.getLast());
        }
    }
}
logger = new glb_Logger;
function glb_GetParentTagName(el,tagName)
{
    while (el.tagName != tagName){
        el = el.parentNode;
    }
    return el;
}
function glb_SubmitSearch(idIframe,searchUrl)
{
            searchUrl= encodeURI(searchUrl);
            if (ToolBox_Debug_searchExternal)
            {
                if (prompt("Continue",searchUrl))
                window.open(searchUrl,"","")
            }
            else
            {
                document.getElementById(idIframe).src = searchUrl;
            }
}
function glb_IframeReset(iframe)
{
    if (!iframe.set){
        iframe.originalUrl     = iframe.src;
        iframe.reset         = Reset;
        iframe.set             = true;
    } else {
        iframe.reset();
    }
    function Reset(){
        if (this.src != this.originalUrl) {
            this.src = this.originalUrl;
        }
    }
}
function glb_HideIfEmpty(htmlelement,showStyle)
{
    if (typeof(htmlelement) == "string"){htmlelement = document.getElementById(htmlelement);}
    if (!htmlelement){return;}
    if (!showStyle) {showStyle = "block"};// default is 'block', override to 'inline' etc...
    try {
        if ( htmlelement.innerHTML == "" )
        {
            htmlelement.style.display = "none";
        }
        else
        {
            htmlelement.style.display = showStyle;
        }
    } catch(e){}
}
function glb_DivToolBoxCleanUp()
{
    if (window.toolbox)
    {
        try {
            toolbox.units.clean();
            toolbox.units         = null;
            toolbox.search        = null;
            toolbox.quicknotes     = null;
            toolbox.notes        = null;
            toolbox.admin        = null;
            toolbox             = null;
            document.getElementById("textareaNotesEdit").onfocus = null;
            document.getElementById("textareaTermBox").onfocus = null;
        } catch (e){}
    }
}
try {
	HTMLElement.prototype.__defineGetter__("currentStyle", function() {
	return getComputedStyle(this, null);
	});
} catch (e){}
window.onunload = glb_DivToolBoxCleanUp;
var toolbox = new ToolBox;
var demo={active:false,message:"Sorry, action disabled in this prototype ",warn:function(){alert(this.message)},redirect:function(){alert("Sorry, this prototype only works in Inernet Explorer 6\nYou will be forwarded to the home page");location.href="index.html"}}
