﻿// JScript File

var objConverter= function( arr )
{
	var o = { } ;
	for ( var i = 0 ; i < arr.length ; i++ )
	{
		o[ a[ i ] ] = "" ;
	}
	return o ;
}

var WorkspaceStyleSheetClass = function ( )
{
	var self = this ; 
	
	self.base = baseClass ;
	self.base( ) ;

	var baseInitalise = self.initalise ;
	self.name = "WorkspaceStyleSheetClass" ;
	self.base.name = "WorkspaceStyleSheetClass" ;

	var sheetUrlBranch = "/EmbeddedResource/Simplicity/Web/UI;Simplicity/Web/" ;
	var colourSheetName = new Array( "SimplicityBlue.css" , "SimplicityGreen.css" ) ;
	var colourSheet = null ;
	
	self.inspectCurrentStyleSheets = function ( ) 
	{
		var currentSheetName = "" ;
		var urlBranchStartingPoint = -1 ;
		var iSheetLoopCount ;
		for ( iSheetLoopCount = 0 ; iSheetLoopCount < document.styleSheets.length ; iSheetLoopCount++ )
		{
			urlBranchStartingPoint = document.styleSheets[ iSheetLoopCount ].href.indexOf( sheetUrlBranch ) ; 
			if ( urlBranchStartingPoint > -1 )
			{
				urlBranchStartingPoint = urlBranchStartingPoint + sheetUrlBranch.length ;
				currentSheetName = document.styleSheets[ iSheetLoopCount ].href.substr( urlBranchStartingPoint ) ;
				switch ( currentSheetName )
				{
					case "SimplicityBlue.css" :
					case "SimplicityGreen.css" :
					case "SimplicitySlime.css" :
						self.colourSheet = document.styleSheets[ iSheetLoopCount ] ;
						break;

					/* Templates */
					case "WebConfig_Template_1.css" :
						self.buildWebConfig_Template_1( document.styleSheets[ iSheetLoopCount ] )
						break;

					/* Workspaces */
					case "WebConfig_Login.css" :
						// self.buildWebConfig_Login( document.styleSheets[ iSheetLoopCount ] )
						break;
					case "WebConfig_MainMenu.css" :
						// self.buildWebConfig_MainMenu( document.styleSheets[ iSheetLoopCount ] )
						break;

					/* Explorers */
					case "WebConfig_LoginExplorer.css" :
						break;
					case "WebConfig_PersonExplorer.css" :
					case "WebConfig_OrganisationExplorer.css" :
						self.buildWebConfig_Explorer( document.styleSheets[ iSheetLoopCount ] )
						break;

					default :
						document.writeln( "<!-- " + currentSheetName + " <br /> -->" ) ;
						break;
				}
			}
		}
	} ;

	self.buildWebConfig_Template_1 = function ( sheet ) 
	{
		var ruleName = "" ;
		var cssRules = sheet.cssRules || sheet.rules
		var iRuleLoopCount ;
		var importRule = null ;
		for ( iRuleLoopCount = 0 ; iRuleLoopCount < cssRules.length ; iRuleLoopCount++ )
		{
			ruleName = cssRules[ iRuleLoopCount ].selectorText ;
			importRule = null ;
			switch ( ruleName )
			{
				case "BODY" :
				case "body" :
					// cssRules[ iRuleLoopCount ].style.backgroundColor = self.obtainColoursheetRule( ".BackgroundColour_L7" ).backgroundColor ;
					break;
				case ".PageCell" :
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L7" )
					cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					importRule = self.obtainColoursheetRule( ".TextColour_L7" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					break;
				case ".PageCell .Header .Bar" :
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L5" )
					cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					importRule = self.obtainColoursheetRule( ".TextColour_L5" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					break;
				case ".PageCell .Header .Buttons .Home .HyperLink" :
					//cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					//cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".BackgroundImage_HeaderButtonsHomeHyperLink" )
					cssRules[ iRuleLoopCount ].style.backgroundImage	= importRule.backgroundImage ;
					break;
				case ".PageCell .Header .Buttons .Search .HyperLink" :
					//cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					//cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".BackgroundImage_HeaderButtonsSearchHyperLink" )
					cssRules[ iRuleLoopCount ].style.backgroundImage	= importRule.backgroundImage ;
					break;
				case ".PageCell .Header .Buttons .ContactUs .HyperLink" :
					//cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					//cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".BackgroundImage_HeaderButtonsContactUsHyperLink" )
					cssRules[ iRuleLoopCount ].style.backgroundImage	= importRule.backgroundImage ;
					break;
				case ".PageCell .Header .Banner" :
					//cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					//cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".BackgroundImage_HeaderButtonsBannerHyperLink" )
					cssRules[ iRuleLoopCount ].style.backgroundImage	= importRule.backgroundImage ;
					break;
				case ".PageCell .Header .Menu" :
					//cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					//cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".BackgroundImage_HeaderButtonsMenuHyperLink" )
					cssRules[ iRuleLoopCount ].style.backgroundImage	= importRule.backgroundImage ;
					break;
				case ".PageCell .Header .Menu A" :
				case ".PageCell .Header .Menu a" :
					//cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					//cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".TextColour_L3" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					break;
				case ".PageCell .Header .Menu .MenuLink1, .PageCell .Header .Menu .MenuLink2, .PageCell .Header .Menu .MenuLink3, .PageCell .Header .Menu .MenuLink4" :
				/* IE HACKs */
				case ".PageCell .Header .Menu .MenuLink1" :
				case ".PageCell .Header .Menu .MenuLink2" :
				case ".PageCell .Header .Menu .MenuLink3" :
				case ".PageCell .Header .Menu .MenuLink4" :
				/* IE HACKs */
					//cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					//cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".TextColour_L3" )
					cssRules[ iRuleLoopCount ].style.borderColor		= importRule.color ;
					break;
				case ".PageCell .PanelMain" :
				case ".PageCell .PanelFull .ExplorerTitle" :
				case ".PageCell .PanelFull .ExplorerTitle, .PageCell .PanelFull .ExplorerForm" :
				case ".PageCell .PanelFull .ExplorerForm" : // IE HACK
				case ".PageCell .ListTitle" :
				case ".PageCell .ListTitle, .PageCell .ListSortForm" :
				case ".PageCell .ListSortForm" : // IE HACK
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L9" )
					cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					importRule = self.obtainColoursheetRule( ".TextColour_L9" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					break;
				case ".PageCell .MainContent" :
				case ".PageCell .PanelLogin" :
				case ".PageCell .ListSearchForm" :
				case ".PageCell .PanelFull .ExplorerForm .ExplorerDiv .Relationships" :
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L6" )
					cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					importRule = self.obtainColoursheetRule( ".TextColour_L6" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					break;
				case ".PageCell .LowerDividor" :
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L8" )
					cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					importRule = self.obtainColoursheetRule( ".TextColour_L8" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L1" )
					cssRules[ iRuleLoopCount ].style.borderColor		= importRule.backgroundColor ;
					break;
				case ".PageCell .Footer" :
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L1" )
					cssRules[ iRuleLoopCount ].style.backgroundColor	= importRule.backgroundColor ;
					cssRules[ iRuleLoopCount ].style.borderColor		= importRule.backgroundColor ;
					importRule = self.obtainColoursheetRule( ".TextColour_L1" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.color ;
					break;
			}
		}
		if ( cssRules!= null && cssRules.length > 0 )
		{
			document.writeln( "<!-- " + ( cssRules[ 2 ].cssText || cssRules[ 2 ].style.cssText ) + " <br /> -->" ) ;
		}
		else
		{
			document.writeln( "Dynamic Css is not supported by your browser. <br />" ) ;
		}
	} ;

	self.buildWebConfig_Explorer = function ( sheet ) 
	{
		var ruleName = "" ;
		var cssRules = sheet.cssRules || sheet.rules
		var iRuleLoopCount ;
		var importRule = null ;
		for ( iRuleLoopCount = 0 ; iRuleLoopCount < cssRules.length ; iRuleLoopCount++ )
		{
			ruleName = cssRules[ iRuleLoopCount ].selectorText ;
			importRule = null ;
			switch ( ruleName )
			{
				case "A.Organisation_Add, A.Organisation_Delete" :
				/* IE HACKs */
				case "A.Organisation_Add" :
				case "A.Organisation_Delete" :
				/* IE HACKs */
				case "a.Organisation_Add, a.Organisation_Delete" :
					importRule = self.obtainColoursheetRule( ".BackgroundColour_L6" )
					cssRules[ iRuleLoopCount ].style.color				= importRule.backgroundColor ;
					break;
			}
		}
	} ;

	self.obtainColoursheetRule = function ( propertyName ) 
	{
		var returnValue = null ;
		if ( self.colourSheet == null )
		{
			return returnValue ;
		}
		var ruleName = "" ;
		var cssRules = self.colourSheet.cssRules || self.colourSheet.rules
		var iRuleLoopCount ;
		for ( iRuleLoopCount = 0 ; iRuleLoopCount < cssRules.length ; iRuleLoopCount++ )
		{
			ruleName = cssRules[ iRuleLoopCount ].selectorText  ;
			switch ( ruleName )
			{
				case propertyName :
					returnValue = cssRules[ iRuleLoopCount ].style ;
					break ;
			}
			if ( returnValue != null )
			{
				break ;
			}
		}
		return returnValue ;
	} ;
} ;
//document.styleSheets[ 0 ].cssRules[ 0 ].style ;

var thisWorkspaceStyleSheetClass = new WorkspaceStyleSheetClass( ) ;
thisWorkspaceStyleSheetClass.inspectCurrentStyleSheets( ) ;