﻿function setOpacity(elem, value)
{
	elem.style.filter = "alpha(opacity=" + value + ")";
	elem.style.mozOpacity = value/100;
	elem.style.opacity = value / 100;
//	filter:alpha(opacity=25);-moz-opacity:.25;opacity:.25;
}






function getCSSRule(ruleName, deleteFlag) {           
   ruleName=ruleName.toLowerCase();                   
   if (document.styleSheets) {                          
      for (var i=0; i<document.styleSheets.length; i++) {
         var styleSheet=document.styleSheets[i];         
         var ii=0;                                       
         var cssRule=false;                              
         do {                                            
            if (styleSheet.cssRules) {                   
               cssRule = styleSheet.cssRules[ii];        
            } else {                                     
               cssRule = styleSheet.rules[ii];           
            }                                            
            if (cssRule)  {                              
               if (cssRule.selectorText.toLowerCase()==ruleName) { 
                  if (deleteFlag=='delete') {            
                     if (styleSheet.cssRules) {          
                        styleSheet.deleteRule(ii);        
                     } else {                             
                        styleSheet.removeRule(ii);        
                     }                                    
                     return true;                         
                  } else {                                
                     return cssRule;                      
                  }                                       
               }                                          
            }                                             
            ii++;                                         
         } while (cssRule)                                
      }                                                   
   }                                                      
   return false;                                          
}                                                         

function killCSSRule(ruleName) {                          
   return getCSSRule(ruleName,'delete');                  
}                                                         

function addCSSRule(ruleName) {                           
   if (document.styleSheets) {                            
      if (!getCSSRule(ruleName)) {                        
         if (document.styleSheets[0].addRule) {           
            document.styleSheets[0].addRule(ruleName, null,0);      
         } else {                                         
            document.styleSheets[0].insertRule(ruleName+' { }', 0); 
         }                                                
      }                                                   
   }                                                      
   return getCSSRule(ruleName);                           
} 





function getNumValueFromStyle(style)
{
	if(style == null)
		return 0;
	var styleText = new Array("px", "%", "em");
	for(var i = 0; i < styleText.length; ++i)
	{
		if(style.indexOf(styleText[i]) != -1)
		{
			var v = parseInt(style.substr(0, style.indexOf(styleText[i])));
			if(isNaN(v))
				return 0;
			else
				return v;
		}
	}
	return 0;
}






function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}
if(typeof(Element) != null)
{
	Element.prototype.setSelectionEnabled = Element.prototype.set_SelectionEnabled = document.set_SelectionEnabled = function(value)
	{
		if(value)
		{
			if(typeof(this.onselectstart) != "undefined")
				this.onselectstart = this._saveOnSelectStart;
			else if(this.style != null && typeof(this.style.MozUserSelect) != "undefined")
				this.style.MozUserSelect = "";
			else
				this.onmousedown = this._saveOnMouseDown;
		}
		else
		{
			if(typeof(this.onselectstart) != "undefined")
			{
				this._saveOnSelectStart = this.onselectstart;
				this.onselectstart = function() { return false; };
			}
			else if(typeof(this.style.MozUserSelect) != "undefined")
				this.style.MozUserSelect = "none";
			else
			{
				this._saveOnMouseDown = this.onmousedown;
				this.onmousedown = function() { return false; };
			}
		}
	}
	Element.prototype.GetComputedStyle = function()
	{
		if(window.getComputedStyle != null)
			return window.getComputedStyle(this, null);
		return this.currentStyle;
	}
	Element.prototype.set_WidthStyle = function(width)
	{
		width -= getNumValueFromStyle(this.GetComputedStyle().paddingRight)
			+ getNumValueFromStyle(this.GetComputedStyle().paddingLeft)
			+ getNumValueFromStyle(this.GetComputedStyle().borderRightWidth)
			+ getNumValueFromStyle(this.GetComputedStyle().borderLeftWidth);
		if(width < 0) width = 0;
		this.style.width = width + "px";
	}
	Element.prototype.set_HeightStyle = function(height)
	{
		height -= getNumValueFromStyle(this.GetComputedStyle().paddingTop)
			+ getNumValueFromStyle(this.GetComputedStyle().paddingBottom)
			+ getNumValueFromStyle(this.GetComputedStyle().borderTopWidth)
			+ getNumValueFromStyle(this.GetComputedStyle().borderBottomWidth);
		if(height < 0) height = 0;
		this.style.height = height + "px";
	}
}