//------------------------------------------------------------------------
// HippoBase/EventInfo Common JavaScript Routines
// copyright Andreas Steidle, 2004
//------------------------------------------------------------------------

// add/change a property in a CSS rule of a stylesheet
function styleSheetSetProperty(styleSheetIndex,selectorText,cssProperty,value) {
	//alert("cssRuleSetProperty(selectorText="+selectorText+",property="+cssProperty+",value="+value+")");
	if (!document.styleSheets) return;
	var styleSheet = document.styleSheets[styleSheetIndex];
	
	var rules = new Array();
	if (styleSheet.cssRules)	 rules = styleSheet.cssRules;	// W3C DOM standard
	else if (styleSheet.rules) rules = styleSheet.rules;		// MS IE on win
	else return;
	for(var i=rules.length-1; i>=0; i--) {
		var rule = rules[i];
		//alert(rules+" "+rule+" "+rule.cssRules+" "+rule.cssRules[0]+" "+rule.cssRules[0].selectorText);
		if(rule.selectorText && rule.selectorText.toLowerCase()==selectorText.toLowerCase()) {
			//alert("Changing property in CSS rule:\n"+rule.selectorText+" { "+cssProperty+": ["+rule.style.display+"] to ["+value+"] }");
			rule.style[cssProperty] = value;
			break;
		}
	}
}

function styleSheetDisplayRule(styleSheetIndex,selectorText,showCondition,displayOnValue) {
	styleSheetDisplayRuleVal(styleSheetIndex,selectorText,showCondition,displayOnValue,'none');
}

function styleSheetDisplayRuleVal(styleSheetIndex,selectorText,condition,displayValue1,displayValue2) {
	//alert("styleSheetDisplayRule(selectorText="+selectorText+", condition="+condition+", displayValue1="+displayValue1+", displayValue2="+displayValue2+")");
	var newDisplayValue = condition ? ieTableCssDisplayAttr(displayValue1) : ieTableCssDisplayAttr(displayValue2);
	styleSheetSetProperty(styleSheetIndex,selectorText,'display',newDisplayValue);
}

// work around for MSIEs sloppy CSS display implemantation
function ieTableCssDisplayAttr(displayValue) {
	if(navigator.appName.indexOf("Microsoft")==-1) return displayValue;
	if(displayValue=='table-cell') return 'block';
	if(displayValue=='table-row') return 'block';
	if(displayValue=='table-row-group') return 'block';
	return displayValue;
}
