var SubWinHeight;
var SubWinWidth;


function GetInformation( url,width,height,windowname,title ){
	var options;
	var sOut;

	if(!title)
	{
		title = windowname;
		windowname = 'SubWindow';
	}
	if(!windowname)
	{
		windowname = 'SubWindow';
	}
	l = width/2, t = height/2;

	sOut = '/LearningSystem/eView/Usage/UsageWrapper.asp?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
	 
	if(width == '*' || width == 0 || width == null )
	{
		if (window.screen) 
		{
    			width = Math.floor(screen.availWidth-((screen.availWidth/100)*20));
    			height = Math.floor(screen.availHeight-((screen.availHeight/100)*20));
    			l = Math.floor((screen.availWidth-width)/2);
    			t = 30;
		}
	}
	else
	{
		if (window.screen) 
		{
				l = Math.floor((screen.availWidth-width)/2);
				t = Math.floor((screen.availHeight-height)/2);	
		}
	}
	
	SubWinHeight=height;
	SubWinWidth=width;	
	options   = 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=' + width +',height=' + height+',top='+t+',left='+l ;
	win = window.open( sOut, windowname, options );	
	win.focus()    
	RegisterChildWindow( window, win, windowname );
}

function OpenContentFrames( url,width,height,windowname,title ){
	var options;
	var sOut;
	if(!title)
	{
		title = windowname;
		windowname = 'SubWind';
	}
	l = width/2, t = height/2;

	sOut = '/LearningSystem/eView/Usage/UsageWrapper.asp?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);

	if(width == '*')
	{
		if (window.screen) 
		{
    			width = Math.floor(screen.availWidth-((screen.availWidth/100)*20));
    			height = Math.floor(screen.availHeight-((screen.availHeight/100)*20));
    			l = Math.floor((screen.availWidth-width)/2);
    			t = 30;
		}
	}
	else
	{
		if (window.screen) 
		{
				l = Math.floor((screen.availWidth-width)/2);
				t = Math.floor((screen.availHeight-height)/2);	
		}
	}
	
	SubWinHeight=height;
	SubWinWidth=width;	
	options   = 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=' + width +',height=' + height+',top='+t+',left='+l ;
	top.parent.tkContentFrame = window.open( sOut, windowname, options );	
	top.parent.tkContentFrame.focus()    	
}

// **************************************************************************
// ** GetInformationNoUsage                                                **
// **                                                                      **
// ** 30/06/2006 Richard Robinson                                          **
// **                                                                      **
// ** Modification of pre-existing GetInformationNoUsage function          **
// ** following move of code to GetInformationNoUsagewithHandle            **
// **                                                                      **
// ** THIS FUNCTION DOES NOT RETURN A REFERENCE TO THE NEW WINDOW          **
// **                                                                      **
// ** url :        The URL to launch in the new window                     **
// ** width :      The width in pixels of the new window                   **
// ** height :     The height in pixels of the new window                  **
// ** windowname : The name for the window (for code references)           **
// ** title :      not used - kept in for backward compatability           **
// **              with existing code                                      **
// **                                                                      **
// ** Launches a new pop up browser window of the specifed dimensions      **
// ** and centres in the screen. All browser furniture is removed          **
// ** except the scrollbars.                                               **
// **************************************************************************
function GetInformationNoUsage( url,width,height,windowname,title )
{
	GetInformationNoUsageWithHandle( url,width,height,windowname,title ) 
}

// **************************************************************************
// ** GetInformationNoUsageWithHandle                                      **
// **                                                                      **
// ** 30/06/2006 Richard Robinson                                          **
// **                                                                      **
// ** Modification of pre-existing GetInformationNoUsage function          **
// ** to return a handle to the newly spawned window.                      **
// **                                                                      **
// ** url :        The URL to launch in the new window                     **
// ** width :      The width in pixels of the new window                   **
// ** height :     The height in pixels of the new window                  **
// ** windowname : The name for the window (for code references)           **
// ** title :      not used - kept in for backward compatability           **
// **              with existing code                                      **
// ** RETURNS :    A reference to the new window                           **
// **                                                                      **
// ** Launches a new pop up browser window of the specifed dimensions      **
// ** and centres in the screen. All browser furniture is removed          **
// ** except the scrollbars.                                               **
// **************************************************************************
function GetInformationNoUsageWithHandle( url,width,height,windowname,title )
{
	var options;
	var left, top;
	left = width/2, top = height/2;

	// if we can get the screen details, then position in the centre
	if (window.screen) {
    		left = Math.floor((screen.availWidth-width)/2);
    		top = Math.floor((screen.availHeight-height)/2);	
	}
	options = 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left;
	win = window.open( url, windowname, options );
	win.focus();
	RegisterChildWindow( window, win, windowname );
	return win;
}

function GetInformationNoUsageWithHandleWithOptions( url,width,height,windowname,title )
{
	var options;
	var left, top;
	left = width/2, top = height/2;

	// if we can get the screen details, then position in the centre
	if (window.screen) {
    		left = Math.floor((screen.availWidth-width)/2);
    		top = Math.floor((screen.availHeight-height)/2);	
	}
		
	options = 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left;	
		
	win = window.open( url, windowname, options );
	win.focus();
	RegisterChildWindow( window, win, windowname );
	return win;
}


function GetLocation( url){
	document.location=url
}

function ConfirmClose(){
	if(document.OurValues.save.value ==1 ){
		if (confirm('Do you want to save changes?')){
			ExecuteForm1(); 
			parent.opener.PageRefresh();
		}else{
			parent.opener.PageRefresh();
		}
	}
}

function RegisterChildWindow( parentWindow, childWindow, windowName )
{   
    RegisterDescendentWindow( parentWindow, childWindow, windowName, 1 )
}

function RegisterDescendentWindow( parentWindow, descendentWindow, windowName, generation )
{       
    try 
    {   
        if ( typeof( parentWindow._descendentWindows ) == 'object' && _descendentWindows.length != null )
        {        
            parentWindow._descendentWindows[ _descendentWindows.length ] = [ descendentWindow, windowName, generation ];
        }
    }
    catch(e)
    {
    }
    
    try 
    {        
        var nextGeneration = generation + 1;
        
        if ( parentWindow.top != parentWindow && parentWindow.parent != null && parentWindow != parentWindow.parent )
        {        
            RegisterDescendentWindow( parentWindow.parent, descendentWindow, windowName, nextGeneration );
        }
        if ( parentWindow.opener != null && parentWindow != parentWindow.opener )
        {
            RegisterDescendentWindow( parentWindow.opener, descendentWindow, windowName, nextGeneration );
        }
    }
    catch(e)
    {
    }
}

function CloseChildWindows( windowName )
{
    CloseDescendentWindows( 1 );
}

function CloseDescendentWindows( windowName, generation )
{
    if ( typeof( _descendentWindows ) == 'object' && _descendentWindows.length != null )
    {
        var i;
        var currentCell;
        var currentWindow;
        
        for ( i = 0; i < _descendentWindows.length; i++ )
        {
            currentCell = _descendentWindows[ i ];
            
            try
            {                    
                if ( currentCell != null && ( generation == null || generation == currentCell[ 2 ] ) && ( windowName == null || windowName == currentCell[ 1 ] ) )
                {
                    currentWindow = currentCell[ 0 ];
                    
                    if ( currentWindow != null && currentWindow.closed != null && ! currentWindow.closed && currentWindow.close )
                    {
                        currentWindow.close();                    
                        _descendentWindows[ i ] = null;
                    }
                }
            }               
            catch(e)
            {
            }         
        }
    }
}

function OpenScaledWindow( url, scalePercent, minWidth, minHeight, windowName )
{
    var w = 0, h = 0;

	if (window.screen) {
		w = Math.floor( scalePercent * screen.availWidth / 100 );
		h = Math.floor( scalePercent * screen.availHeight / 100 );		
	}
	
	if ( w < minWidth ) 
	{
	    w = minWidth;
	}
	
	if ( h < minHeight )
	{
	    h = minHeight;
	}
	
	GetInformationNoUsage(url ,w , h , windowName);
}

function OpenScaledWindowLogon( url, scalePercent, minWidth, minHeight, windowName )
{
    var w = 0, h = 0;    

	if (window.screen) {
		w = Math.floor( scalePercent * screen.availWidth / 100 );
		h = Math.floor( scalePercent * screen.availHeight / 100 );		
	}
	
	if ( w < minWidth ) 
	{
	    w = minWidth;
	}
	
	if ( h < minHeight )
	{
	    h = minHeight;
	}
	
	GetInformationNoUsageWithHandleWithOptions(url ,w , h , windowName);
}

function OpenLsManagerWindow()
{	
	OpenScaledWindow('/learningsystem/eview/learningspacemanager/LSM_Frames.asp', 85, 'LearningSpaceManager');	
}

function OpenEportfolioSignOnWindow()
{	
	OpenScaledWindowLogon('/LearningSystem/eView/MicroApps/SignOnLaunch/Login.aspx?Product=eportfolio', 85, 'ePortfolio');	
}

function Open2SimpleWindow()
{	
	var dateNow = new Date();
	var baseline = new Date( 2000, 0, 1);
	OpenScaledWindowLogon('/LearningSystem/2Simple/', 85, 600, 400, '2Simple' + ( dateNow - baseline ) );	
}

function GetInformationNoUsageWithHandleEmail( url,width,height,windowname,title )
{
	var options;
	var left, top;
	left = width/2, top = height/2;

	// if we can get the screen details, then position in the centre
	if (window.screen) {
    		left = Math.floor((screen.availWidth-width)/2);
    		top = Math.floor((screen.availHeight-height)/2);	
	}
	options = 'location=yes,toolbar=yes,directories=no,status=yes,scrollbars=yes,resizable=yes,menubar=yes,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left;
	win = window.open( url, windowname, options );
	win.focus();
	RegisterChildWindow( window, win, windowname );
	return win;
}


function GetInformationNoUsageEmail( url,width,height,windowname,title )
{
	GetInformationNoUsageWithHandleEmail( url,width,height,windowname,title ) 
}

function OpenScaledWindowEmail( url, scalePercent, minWidth, minHeight, windowName )
{
    var w = 0, h = 0;

	if (window.screen) {
		w = Math.floor( scalePercent * screen.availWidth / 100 );
		h = Math.floor( scalePercent * screen.availHeight / 100 );		
	}
	
	if ( w < minWidth ) 
	{
	    w = minWidth;
	}
	
	if ( h < minHeight )
	{
	    h = minHeight;
	}
	
	GetInformationNoUsageEmail(url ,w , h , windowName);
}

/******************************************************************************
 * Overview
 ******************************************************************************
 *
 * The library contains functions for decoding and encoding strings in various
 * formats, i.e. HTML, JavaScript, SQL and XML.
 *
 ******************************************************************************
 * Design Notes
 ******************************************************************************
 *
 * This library has a direct dependency on the following libraries:
 *
 * /LearningSystem/Libraries/LS_General_Utility_Library.js
 *
 * However, due to the method used to avoid multiple includes, this library
 * does not include its dependencies, hence it is the responsibility of the
 * includer to ensure that the appropriate library dependencies are handled.
 *
 ******************************************************************************/

/**
 * Decodes a component used in HTML.
 *
 * @param String i_Component  The component to be decoded.
 *
 * @return String  The decoded component.
 */
 function HTMLDecode(i_Component)
 {
     var decodedComponent;

     decodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         decodedComponent = decodedComponent.replace(/&quot;/g, "\"");
         decodedComponent = decodedComponent.replace(/&#34;/g, "\"");
         decodedComponent = decodedComponent.replace(/&apos;/g, "'");
         decodedComponent = decodedComponent.replace(/&#39;/g, "'");
         decodedComponent = decodedComponent.replace(/&gt;/g, ">");
         decodedComponent = decodedComponent.replace(/&#62;/g, ">");
         decodedComponent = decodedComponent.replace(/&lt;/g, "<");
         decodedComponent = decodedComponent.replace(/&#60;/g, "<");
         decodedComponent = decodedComponent.replace(/&amp;/g, "&");
         decodedComponent = decodedComponent.replace(/&#38;/g, "&");
     }

     return decodedComponent;
 }

/**
 * Encodes a component for use in HTML.
 *
 * @param String i_Component  The component to be encoded.
 *
 * @return String  The encoded component.
 */
 function HTMLEncode(i_Component)
 {
     var encodedComponent;

     encodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         encodedComponent = encodedComponent.replace(/&/g, "&amp;");
         encodedComponent = encodedComponent.replace(/</g, "&lt;");
         encodedComponent = encodedComponent.replace(/>/g, "&gt;");
         encodedComponent = encodedComponent.replace(/'/g, "&#39;");
         encodedComponent = encodedComponent.replace(/"/g, "&quot;");
     }

     return encodedComponent;
 }

/**
 * Decodes a component used in JavaScript.
 *
 * @param String i_Component  The component to be decoded.
 *
 * @return String  The decoded component.
 */
 function JavaScriptDecode(i_Component)
 {
     var decodedComponent;

     decodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         decodedComponent = decodedComponent.replace(/\\"/g, "\"");
         decodedComponent = decodedComponent.replace(/\\'/g, "'");
         decodedComponent = decodedComponent.replace(/\\n/g, "\n");
         decodedComponent = decodedComponent.replace(/\\r/g, "\r");
         decodedComponent = decodedComponent.replace(/\\t/g, "\t");
         decodedComponent = decodedComponent.replace(/\\\\/g, "\\");
     }

     return decodedComponent;
 }

/**
 * Encodes a component for use in JavaScript.
 *
 * @param String i_Component  The component to be encoded.
 *
 * @return String  The encoded component.
 */
 function JavaScriptEncode(i_Component)
 {
     var encodedComponent;

     encodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         encodedComponent = encodedComponent.replace(/\\/g, "\\\\");
         encodedComponent = encodedComponent.replace(/\t/g, "\\t");
         encodedComponent = encodedComponent.replace(/\r/g, "\\r");
         encodedComponent = encodedComponent.replace(/\n/g, "\\n");
         encodedComponent = encodedComponent.replace(/'/g, "\\'");
         encodedComponent = encodedComponent.replace(/"/g, "\\\"");
     }

     return encodedComponent;
 }

/**
 * Decodes a component used in SQL.
 *
 * @param String i_Component  The component to be decoded.
 *
 * @return String  The decoded component.
 */
 function SQLDecode(i_Component)
 {
     var decodedComponent;

     decodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         decodedComponent = decodedComponent.replace(/''/g, "'");
     }

     return decodedComponent;
 }

/**
 * Encodes a component for use in SQL.
 *
 * @param String i_Component  The component to be encoded.
 *
 * @return String  The encoded component.
 */
 function SQLEncode(i_Component)
 {
     var encodedComponent;

     encodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         encodedComponent = encodedComponent.replace(/'/g, "''");
     }

     return encodedComponent;
 }

/**
 * Decodes a component used in XML.
 *
 * @param String i_Component  The component to be decoded.
 *
 * @return String  The decoded component.
 */
 function XMLDecode(i_Component)
 {
     var decodedComponent;

     decodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         decodedComponent = decodedComponent.replace(/&quot;/g, "\"");
         decodedComponent = decodedComponent.replace(/&#34;/g, "\"");
         decodedComponent = decodedComponent.replace(/&apos;/g, "'");
         decodedComponent = decodedComponent.replace(/&#39;/g, "'");
         decodedComponent = decodedComponent.replace(/&gt;/g, ">");
         decodedComponent = decodedComponent.replace(/&#62;/g, ">");
         decodedComponent = decodedComponent.replace(/&lt;/g, "<");
         decodedComponent = decodedComponent.replace(/&#60;/g, "<");
         decodedComponent = decodedComponent.replace(/&amp;/g, "&");
         decodedComponent = decodedComponent.replace(/&#38;/g, "&");
     }

     return decodedComponent;
 }

/**
 * Encodes a component for use in XML.
 *
 * @param String i_Component  The component to be encoded.
 *
 * @return String  The encoded component.
 */
 function XMLEncode(i_Component)
 {
     var encodedComponent;

     encodedComponent = i_Component;

     if (IsSet(i_Component))
     {
         encodedComponent = encodedComponent.replace(/&/g, "&amp;");
         encodedComponent = encodedComponent.replace(/</g, "&lt;");
         encodedComponent = encodedComponent.replace(/>/g, "&gt;");
         encodedComponent = encodedComponent.replace(/"/g, "&quot;");
         encodedComponent = encodedComponent.replace(/'/g, "&apos;");
     }

     return encodedComponent;
 }

/******************************************************************************
 * Overview
 ******************************************************************************
 *
 * The library contains general utility functions.
 *
 ******************************************************************************
 * Design Notes
 ******************************************************************************
 *
 * This library has no dependencies on any other libraries.
 *
 ******************************************************************************/

/**
 * Determines whether a value is set.
 *
 * @param Variant i_Value  The value to be checked.
 *
 * @return Boolean  Indicates whether the value is set.
 */
 function IsSet(i_Value)
 {
     return ((i_Value != undefined) && (i_Value != null));
 }

// This is a reference to the frame used to run content.
// (it is used to destroy the content frame upon logout)
var tkContentFrame = null;

var blnPortalLogin = true;

var menuSize        = 0;
var menuTitle       = 30;
var NetscapeToolbar = 0;

var MenuMode     = 0;
var MenuStem     = '';
var MenuShortcut = '';
var MenuUrl      = '';
var MenuUrlIntro = '';

var win       = null;
var win2      = null;
var winStatus = 0;

var _descendentWindows = new Array();

function CloseWin()
{
    if (self.win != null)
    {
        if (!self.win.closed)
        {
            self.win.close();
            self.win = null;
        }
    }
}

function CloseWin2()
{
    if (self.win2 != null)
    {
        if (!self.win2.closed)
        {
            self.win2.close();
            self.win2 = null;
        }
    }
}

function AppsEngineWindowClose(AppsEngine_Path)
{
    today = new Date();
    timeinseconds = today.getSeconds() + 60 * today.getMinutes() + 3600 * today.getHours();
    top.PortalRelease.location = AppsEngine_Path + 'WindowCloseAction.asp?TimeNow=' + timeinseconds;
}

function keepAlive()
{
    var timedelay;
    var timeinseconds;
    var today;

    // Keep the session alive by calling ToolBar_Refresh_EView.asp.
    try
    {
        today = new Date();
        timeinseconds = today / 1000;

        self.PortalRefresh.location = '/LearningSystem/Toolbar_Refresh_EView.asp?timeinseconds=' + timeinseconds;

        timedelay = 180000;
    }
    catch (e)
    {
        self.PortalRelease.location = '/LearningSystem/Toolbar_Refresh_EView_errors.asp?error=' + e;

        timedelay = 1000;
    }

    // Set the timer ready for the next time.
    try
    {
        setTimeout('keepAlive();', timedelay);
    }
    catch (e)
    {
        self.PortalRelease.location = '/LearningSystem/Toolbar_Refresh_EView_errors.asp?error=' + e;

        setTimeout('keepAlive();', timedelay);
    }
}

function SetInitialFocus()
{
    try
    {
        PortalBottom.setFocusCounted();
    }
    catch (e)
    {
        setTimeout('SetInitialFocus();', 100);
    }
}

function OnUnloadFunction()
{
    CloseDescendentWindows('Upload');
}
