//#####################//
//This script references two <span> tags (themecolor-example, logo-example) to pick up the theme color and logo set in web logic portal
//#####################//

function toRGBHex(num){ // convert RGB colour value to HEX
	var decToHex="";
	var arr = new Array();
	var numStr = new String();
	numStr = num;
	arr = numStr.split(",");
	for(var i=0;i<3;i++){
		var hexArray = new Array( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" );
		var code1 = Math.floor(arr[i] / 16);
		var code2 = arr[i] - code1 * 16;
		decToHex += hexArray[code1];
		decToHex += hexArray[code2];
	}
	return (decToHex);
}

function getStyle(oElm, strCssRule){ //return  a css value
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){return p1.toUpperCase();});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function applyTheme(){/* Replacement calls. Please see documentation for more information.*/
	var oElement = document.getElementById('themecolor-example'), oColor;
	if( window.getComputedStyle ) {
		oColor = window.getComputedStyle(oElement,null).color;
		oColor = toRGBHex(oColor.slice(4,-1));
		oColor = "#"+oColor;
	}else if( oElement.currentStyle ) {
		oColor = oElement.currentStyle.color;
	}
	fullLogoUrl = getStyle(document.getElementById("logo-example"), "background-image");
	var fullLogoUrlTrim = fullLogoUrl.replace(/['"]/g,'');
	var logoimage = fullLogoUrlTrim.slice(4,-1);
	var logoImageEle = document.getElementById('logoimage');
	if (logoimage.length!=0 && logoImageEle != null) {
		eval("logoImageEle.src='"+logoimage+"'");
	}
	if(typeof sIFR == "function"){
		// This is the preferred "named argument" syntax
		sIFR.replaceElement("span", "/static/flash/modena.swf",named({sSelector:".page_heading",sBgColor:"#ffffff",sWmode:"transparent", sColor:"#000000"}));
		eval('sIFR.replaceElement("span", "/static/flash/modena.swf",named({sSelector:".area_heading",sBgColor:"#ffffff",sWmode:"transparent", sColor:"'+oColor+'"}));');
	};
	//debug
	//alert("Debug info: ThemeStyleSetting \nLogo Ref : "+logoimage+"\nTheme Colour : "+oColor);
}



				