var M_BCOOKIE = true;
var M_EXP_DAYS = 0;
var M_EXP_HOURS = 0;

var _BCOOKIE = false;
var _EXP_DAYS = 0;
var _EXP_HOURS = 0;
var _KEY = "cssman";

function makeGMTDate(duration_day, duration_hour)
{
	exp_day = new Date;
	exp_day.setHours(exp_day.getHours()+duration_day*24+duration_hour);
	exp_day = exp_day.toGMTString();
	return exp_day;
}


function getCookie(key)
{
	if(!key) return("");
	cData = document.cookie + ";";
	indexKey  = cData.indexOf(key, 0);
	if (indexKey != -1){
		indexV = cData.indexOf("=", indexKey) +1;
		indexVend = cData.indexOf(";", indexV);
		if(indexVend > indexV) return(unescape(cData.substring(indexV, indexVend))); 
	}
	else{
		return("");
	}
}

function setCookie(key, value, expday, exphour)
{
	if(!key) return;
	if(!value) return;
	
	cData = key + "=" + escape(value) + "; ";

	if((expday+exphour)>0){ 
		cData += "expires=" + makeGMTDate(expday, exphour) + "; ";
	}
	document.cookie = cData;
}

function initCssMan(expday, exphour)
{
	_BCOOKIE = true;
	_EXP_DAYS = expday;
	_EXP_HOURS = exphour;

	previousCss = getCookie(_KEY);
	if (!previousCss) previousCss = "hpb_cssman_std";
	setCss(previousCss);

}

function setCss(strTitle)
{
	var pStyle = document.styleSheets;
	
	if(pStyle){
		for(i=0; i<document.styleSheets.length;i++){
			obj =pStyle[i];
			if(obj.title == strTitle){
				if(_BCOOKIE) setCookie(_KEY, strTitle, _EXP_DAYS, _EXP_HOURS);
				obj.disabled=false;
			}
			else{
				obj.disabled=true;
			}
		}
	}
}

function showBot(){
		document.getElementById("HPB_CSSMAN_OUTER").style.visibility  ="visible";
}

function hideBot(){
		document.getElementById("HPB_CSSMAN_OUTER").style.visibility  ="hidden";
}

if (M_BCOOKIE == true)
	window.onLoad = initCssMan(M_EXP_DAYS, M_EXP_HOURS);
