var IS_RGBA_SUPPORTED = (function(){
	var value = 'rgba(1,1,1,0.5)',
	el = document.createElement('p'),
	result = false;
	try {
	el.style.color = value;
	result = /^rgba/.test(el.style.color);
	} catch(e) { }
	el = null;
	return result;
	})();

function getComputedCSS(_elem, _style) {

	var computedStyle;
	if (typeof _elem.currentStyle != 'undefined') {
		var camelStyle=_style.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');});
		computedStyle = _elem.currentStyle[camelStyle];
		//alert('Old currentStyle access. CamelStyle: '+camelStyle);
	}
	else {
		//alert('getComputedStyle is supported. Getting it');
		computedStyle = window.getComputedStyle(_elem, null).getPropertyValue(_style);
	}

	return computedStyle;
}



function getRGBValue() {
	var theElement=document.getElementById("standard");
	var rgbVal=getComputedCSS(theElement,'background-color');
	var color=new RGBColor(rgbVal);
	
	if (color.ok) {
		return color.toRGB();
	}
	
	else {
		//alert("Can't process color");
	}
}


function HexToAHex(hexcolor, alpha) {
	//alpha=parseFloat(alpha);
	////alert('Alpha is: '+alpha);
	if (hexcolor.charAt(0) == '#') { // remove # if any
		hexcolor = hexcolor.substr(1,6);
	}
	//alpha=1;
	
	var hexAlpha= Math.round((alpha*255)).toString(16);
	var aHexColor="#"+hexAlpha+hexcolor;
	return aHexColor;
}

function RGBAToAHex(rgba) {
	rgba=rgba.replace(/\s/g,"");
	rgb=rgba.replace(/rgba/,"rgb");
	rgbArray=rgb.split(',');
	rgb=rgbArray[0]+","+rgbArray[1]+","+rgbArray[2]+")";
	var alphaVal=rgbArray[3];
	alphaVal=alphaVal.replace(")","");
	var color=new RGBColor(rgb);
	var theHex=color.toHex();
	var theAHex=HexToAHex(theHex,alphaVal);
	return theAHex;
}

function fixIEAlpha(element,bgcolor) {
	if (!element.style.backgroundImage) {
		element.style.backgroundColor='transparent';
		element.style.zoom='1';
		element.style.filter= 'progid:DXImageTransform.Microsoft.gradient(startColorstr='+bgcolor+',endColorstr='+bgcolor+')';
		}
}

function addBGAlpha(element,alpha) {
	var theElement=document.getElementById(element);
	
	var rgbVal=getComputedCSS(theElement, 'background-color');
	//alert('Computed Value: '+rgbVal);
	var color=new RGBColor(rgbVal);
	if (color.ok) {	
		var rgbVal=color.toRGB();
	rgbVal=rgbVal.replace(/\s/g, "");
	var rgbaVal=rgbVal.substring(0,rgbVal.length-1)+','+alpha+')';
	rgbaVal=rgbaVal.replace('rgb', 'rgba');
		if(IS_RGBA_SUPPORTED) {
				theElement.style.backgroundColor=rgbaVal;
			}
		else {
			fixIEAlpha(theElement,RGBAToAHex(rgbaVal));
		}
	}
	
}

