
function Rule_getProperty(numstyleSheet, numRule, CSSPropName) {
	if (browser.isNS) {var r = document.styleSheets[numstyleSheet].cssRules;}
	else {var r = document.styleSheets[numstyleSheet].rules;}
	var cad = eval("r[numRule].style."+CSSPropName);
	return cad;
}

function Rule_setProperty(numstyleSheet, numRule, CSSPropName, CSSPropValue) {
	if (browser.isNS) {var r = document.styleSheets[numstyleSheet].cssRules;}
	else {var r = document.styleSheets[numstyleSheet].rules;}
	if (CSSPropName == "filter") {r[numRule].style.filter = CSSPropValue;}
	else {eval("r[numRule].style."+CSSPropName+" = '"+CSSPropValue+"'");}
}

function Rule_getColor(numstyleSheet, numRule, CSSPropName) {
	if (browser.isNS) {var r = document.styleSheets[numstyleSheet].cssRules;}
	else {var r = document.styleSheets[numstyleSheet].rules;}
	var cad = eval("r[numRule].style."+CSSPropName);
	if (browser.isNS) cad = getColorFormatRGB2CSS(cad);
	return cad;
}

function Rule_setColor(numstyleSheet, numRule, CSSPropName, CadColor) {
	if (browser.isNS) {var r = document.styleSheets[numstyleSheet].cssRules;}
	else {var r = document.styleSheets[numstyleSheet].rules;}
	eval("r[numRule].style."+CSSPropName+" = '"+CadColor+"'");
}

function Rule_setMida(numstyleSheet, numRule, CSSPropName, CadMida) {
	if (browser.isNS) {var r = document.styleSheets[numstyleSheet].cssRules;}
	else {var r = document.styleSheets[numstyleSheet].rules;}
	eval("r[numRule].style."+CSSPropName+" = '"+CadMida+"px'");
}

Estil=function (Tag1, Tag2, Alertar) {
	
	if (!Alertar) {Alertar = false;}
	else {Alertar = true;}
	
	var i, j, k, r, cad;
	
	this.numstyleSheet = -1;
	this.numRule = -1;
	this.selectorText = '';
	this.Ok = false;
	
	if (browser.isIE) Tag1 = Tag1.toUpperCase();
	
	this.selectorText = Tag1 + Tag2;
	
	cercar:
	for (i = 0; i < document.styleSheets.length; i++) {
		if (browser.isIE) {r = document.styleSheets[i].rules;}
		else {r = document.styleSheets[i].cssRules;}
		if (r != null) {
			for (j = 0; j < r.length; j++) {
				if (r[j].selectorText == this.selectorText) {
					this.numstyleSheet = i;
					this.numRule = j;
					this.Ok = true;
					break cercar;
				}
			}
		}
	}
};

Estil.prototype={
	getProperty:function(CSSPropName){return Rule_getProperty(this.numstyleSheet, this.numRule, CSSPropName);}, 
	setProperty:function(CSSPropName, CSSPropValue){Rule_setProperty(this.numstyleSheet, this.numRule, CSSPropName, CSSPropValue);}, 
	getColor:function(CSSPropName){return Rule_getColor(this.numstyleSheet, this.numRule, CSSPropName);}, 
	setColor:function(CSSPropName, CadColor, factor){
		var cad = getFactorToColorCSS(CadColor, factor);
		if (cad != '') Rule_setColor(this.numstyleSheet, this.numRule, CSSPropName, cad);
	}, 
	setMida:function(CSSPropName, CadMida){Rule_setMida(this.numstyleSheet, this.numRule, CSSPropName, CadMida);}
};


function getColorFormatRGB2CSS(cadColorRGB) {
	var cadColorCSS = "";
	if ((cadColorRGB != 'transparent') && (cadColorRGB != '')) {
		cadColorCSS = cadColorRGB.substring(4, cadColorRGB.lastIndexOf(")"));
		var parts = cadColorCSS.split(", ");
		cadColorCSS = "#";
		for (var i = 0; i < parts.length; i++) {cadColorCSS += d2h(parseInt(parts[i], 10), 2);}
	}
	return cadColorCSS;
}

function getFactorToColorCSS(CadColor, factor) {
	var cad = CadColor;
	if (cad == 'transparent') cad == '';
	if (cad != '') {
		var colorsRGB = Array(-1,-1,-1);
		var f = (factor!=null)?parseFloat(factor):1;
		var opuesto = (f < 0);
		f = Math.abs(f);
		for (i = 0; i < 3; i++) {
			colorsRGB[i] = Math.min(Math.round(h2d(cad.substr((i*2)+1, 2)) * f), 255);
			if (opuesto) colorsRGB[i] = 255 - colorsRGB[i];
		}
		cad = "#";
		for (i = 0; i < 3; i++) {cad += d2h(colorsRGB[i], 2);}
	}
	return cad;
}

function getSumRGBToColorCSS(CadColor, SumR, SumG, SumB) {
	var cad = CadColor;
	if (cad == 'transparent') cad == '';
	if (cad != '') {
		var colorsRGB = Array(-1,-1,-1);
		var sumRGB = Array(0,0,0);
		if (SumR != null) sumRGB[0] = parseFloat(SumR);
		if (SumG != null) sumRGB[1] = parseFloat(SumG);
		if (SumB != null) sumRGB[2] = parseFloat(SumB);
		for (i = 0; i < 3; i++) {
			colorsRGB[i] = h2d(cad.substr((i*2)+1, 2)) + sumRGB[i];
			if (sumRGB[i] < 0) {colorsRGB[i] = Math.max(colorsRGB[i], 0);}
			else {colorsRGB[i] = Math.min(colorsRGB[i], 255);}
		}
		cad = "#";
		for (i = 0; i < 3; i++) {cad += d2h(colorsRGB[i], 2);}
	}
	return cad;
}

function d2h(d, minWidth) {
	// Decimal a hexadecimal
	var cad = d.toString(16);
	while (cad.length < minWidth) {cad = "0" + cad;}
	return cad;
}
function h2d(h) {return parseInt(h,16);} 	// Hexadecimal a decimal
