
	var Themes = new Array();
	var oHtmlLink;
	var DEFAULT_THEME = 'CensusMainTheme6';
	var StrDirTree = '';
	var SELECTION_IMAGE = 0;
	var CSS_FILE = 1;
	var EXT = 2;
	
	// 0 = Name of the image file on the selector
	// 1 = Name of the css file

	Themes[0] = new Array('abstractblue','CensusMainTheme6', 'jpg');	
	//Themes[1] = new Array('nurse','CensusMainTheme4', 'jpg');	
	//Themes[2] = new Array('business','CensusMainTheme5', 'jpg');
	//Themes[3] = new Array('tree','CensusMainTheme3', 'gif');

	
	function ApplyTheme(theme){	
		openThemeSelector();
		ChangeCss(theme);
	}
	
	function openThemeSelector(){
		var oSelector = document.getElementById('Selector');
		
		if(oSelector){
			oSelector.style.display = oSelector.style.display == '' ? 'none' : '';
		}
	}
	
	function CreateLinkStyleSheet(StrCssFile){
		var HtmlHead = document.getElementsByTagName("head")[0];         
		var HtmlLink = document.createElement('link');
		
		HtmlLink.type = 'text/css';
		HtmlLink.rel = 'stylesheet';
		HtmlLink.href = StrCssFile;
		HtmlLink.alt = 'theme';
		HtmlHead.appendChild(HtmlLink);
		
		return HtmlLink;
	}
	
	function ChangeCss(cssFileName, themeLoad){
		var directoryCssFile = '';
		var linkElement = document.getElementsByTagName('link');		
		var oContainerBackgroundIE = '';
		var strDirectory = '';
		var StrContainer;
		var container;
		
		function GetThemeLink(){
			var linkElement = document.getElementsByTagName('link');
			var Result = false;
			
			for(c=0;c<linkElement.length;c++){
				if(linkElement[c].rel == 'stylesheet'){
					if(linkElement[c].alt == 'theme'){
						Result = linkElement[c];
						break;
					}
				}
			}
			
			return Result;
		}
				
		function FindArrayByCssFileName(StrCss){
			for(c=0;c<Themes.length;c++){
				if(Themes[c][CSS_FILE] == StrCss){
					return Themes[c];
					break;
				}
			}
		}
		
		
		for(c=0;c<document.location.href.split('/').length - 5;c++){
			directoryCssFile += '../';
		}
		
		StrDirTree = directoryCssFile;
		
		var StrPathCssFile = directoryCssFile+'theme/css/' + cssFileName + '.css'
		
		oThemeImageBackgroundIE = document.getElementById('ThemeImageBackground');

		var arrCssFile=FindArrayByCssFileName(cssFileName);
		
		if(arrCssFile){
			if(oThemeImageBackgroundIE){
				oThemeImageBackgroundIE.src = 'Theme/images/backgrounds/'+arrCssFile[SELECTION_IMAGE]+'.'+arrCssFile[EXT];
			}else{
				var obrowser = CMqBrowserDetector();
				
				if(obrowser){ 
					if(obrowser.ie && (obrowser.minor == 7 || obrowser.minor == 8)){
						if(!parent.document.ifrWindow){ // Not a popup window
							var strImg = 'Theme/images/backgrounds/'+arrCssFile[SELECTION_IMAGE]+'.'+arrCssFile[EXT];

							strImg = strImg.replace('\'','').replace('\'','');
							strImg = strImg.replace('\"','').replace('\"','');
									
							StrContainer = '<DIV id="ThemeContainerBackground" style="Z-INDEX: -20; LEFT: 0px; WIDTH: 100%; POSITION: fixed; TOP: 0px; HEIGHT: 100%"><IMG id="ThemeImageBackground" style="WIDTH: 100%; HEIGHT: 100%" height=819 src="'+StrDirTree + strImg +'" width=1024></DIV>'
							
							container = document.createElement('div');						
							container.id = 'imgBckgrndContainer';
							
							setTimeout(function(){							
								document.appendChild(container)							
								document.getElementById('imgBckgrndContainer').innerHTML = StrContainer
							},2000);
						}
					}
				}
			}
		}
		
		if(oHtmlLink){
			oHtmlLink.setAttribute('href', StrPathCssFile);				
		}else{
			if(!GetThemeLink()){
				oHtmlLink = CreateLinkStyleSheet(StrPathCssFile)
			}
		}

		if(themeLoad && cssFileName == ''){			
			ChangeCss(DEFAULT_THEME);	// Use default
		}
		
		if(!themeLoad){
			SaveTheme(cssFileName);
		}
	}
	
	function SaveTheme(cssFileName){
		
		var expireDate = new Date();		
		expireDate.setTime(expireDate.getTime()+(1000*24*60*60*1000));				
		document.cookie = 'MqTheme='+cssFileName+'; expires='+expireDate.toGMTString()+'; path=/';	
	}
	
	function ReadThemeCookie(){
		
		var StrCookies = document.cookie.split(';');
		var StrTheme = '';
		
		for(c=0;c<StrCookies.length;c++){
			if(StrCookies[c].substring(0, StrCookies[c].indexOf('=')).replace(' ','') == 'MqTheme'){				
				StrTheme = StrCookies[c].substring(StrCookies[c].indexOf('=')+1, StrCookies[c].length)
			}				
		}
		return StrTheme;	
	}

	function ListThemes(){		
		var StrHTML = '<table width=\"100%\" cellspacing=\"0\" height=\"90%\" border=\"0\">';				  
		var oSelector = document.getElementById('Selector');
		
		for(c=0;c<Themes.length;c++){
			StrHTML += '<tr height=\"90\"><td align=\"center\" style=\"cursor: hand; background-color: #000000;\" onClick=\"ApplyTheme(\'' + Themes[c][CSS_FILE] + '\')\" onMouseOver=\"this.style.backgroundColor=\'#cccccc\'\" onMouseOut=\"this.style.backgroundColor=\'#000000\'\"><img src=\"Theme/images/backgrounds/'+Themes[c][SELECTION_IMAGE]+'.'+Themes[c][EXT]+'\" class=\"SelectorImage\"></td></tr>';
		}
		
		StrHTML += '</table>';
		
		if(oSelector){
			oSelector.innerHTML = StrHTML;		
		}
	}