// FUNCTION
function changeClassId(i,c)
	{
		if(document.all) document.all(i).className=c;
		else if(document.getElementById) document.getElementById(i).className=c; 
	}
function changeClass(e,c)
	{
		e.className=c;
	}
function noPx(v)
	{
		return Math.round(v.substr(0, v.length-2));
	}
function freshStyle(p)
	{
		var elements = new Array ();
		var children = p.getElementsByTagName( "*" );

		for ( var i = 0; i < children.length; i++ )
			{
				children[i].className = children[i].className;
			}
	}
function getElHeight(el)
	{
		try{
			h = el.style.pixelHeight;
			if(!isDefined(h) || h < 1)
				h = el.offsetHeight;
			if(!isDefined(h) || h < 1)
				h = el.clientHeight;
		} catch(e) {
			h = el.offsetHeight;
		}
		return h;
	}
function getElWidth(el)
	{
		try{
			w = el.style.pixelWidth;
			if(!isDefined(w) || w < 1)
				w = el.offsetWidth;
			if(!isDefined(w) || w < 1)
				w = el.clientWidth;
		} catch(e) {
			w = el.offsetWidth;
		}
		return w;
	}

function getElY(obj) {
	var y = 0;
	while (obj) {
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return(y);
}

function getElX(obj) {
	var x = 0;
	while (obj) {
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return(x);
}

function getMouseXY(e)
	{
		if (!e)
			var e = window.event;
		x = e.clientX;
		y = e.clientY;

		return {'x':x,'y':y};
	}
// 3RD PARTY
// return [cssrule] on [element]
function getStyle( element, cssRule )
{
  if( document.defaultView && document.defaultView.getComputedStyle )
  {
    var value = document.defaultView.getComputedStyle( element, '' ).getPropertyValue( cssRule );
  }
  else if ( element.currentStyle ) var value = element.currentStyle[ cssRule ];
  else                             var value = false;
  return value;
}

// return elements with [classname]
document.getElementsByClassName = function ( className )
{
  var elements = new Array ();
  var children = document.getElementsByTagName( "*" );
  for ( var a = 0; a < children.length; a++ )
  {
    if ( children[a].hasClass ( className ) ) elements.push ( children[a] );
  }
  return elements;
}

// load css e js dinamicamente
function loadHead()
	{
		if (!document.getElementById)
			return
		for (i=0; i<arguments.length; i++)
			{
				var file = arguments[i];
				var fileref = "";
				if (file.indexOf(".js")!=-1)
					{
						fileref=document.createElement('script');
						fileref.setAttribute("type","text/javascript");
						fileref.setAttribute("src", file);
					}
				else if (file.indexOf(".css")!=-1)
					{
						fileref=document.createElement("link");
						fileref.setAttribute("rel", "stylesheet");
						fileref.setAttribute("type", "text/css");
						fileref.setAttribute("href", file);
					}
				if (fileref!="")
					{
						document.getElementsByTagName("head").item(0).appendChild(fileref);
					}
			}
	}
	
	
function cssRGB(color_string)
{
    this.ok = false;

    // strip any leading #
    if (color_string.charAt(0) == '#') { // remove # if any
        color_string = color_string.substr(1,6);
    }

    color_string = color_string.replace(/ /g,'');
    color_string = color_string.toLowerCase();

    // array of color definition objects
    var color_defs = [
        {
            re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
            example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'],
            process: function (bits){
                return [

                    parseInt(bits[1]),
                    parseInt(bits[2]),
                    parseInt(bits[3])
                ];
            }
        },
        {
            re: /^(\w{2})(\w{2})(\w{2})$/,
            example: ['#00ff00', '336699'],
            process: function (bits){
                return [
                    parseInt(bits[1], 16),
                    parseInt(bits[2], 16),
                    parseInt(bits[3], 16)
                ];
            }
        },
        {
            re: /^(\w{1})(\w{1})(\w{1})$/,
            example: ['#fb0', 'f0f'],
            process: function (bits){
                return [
                    parseInt(bits[1] + bits[1], 16),
                    parseInt(bits[2] + bits[2], 16),
                    parseInt(bits[3] + bits[3], 16)
                ];
            }
        }
    ];

    // search through the definitions to find a match
    for (var i = 0; i < color_defs.length; i++) {
        var re = color_defs[i].re;
        var processor = color_defs[i].process;
        var bits = re.exec(color_string);
        if (bits) {
            channels = processor(bits);
            this.r = channels[0];
            this.g = channels[1];
            this.b = channels[2];
            this.ok = true;
        }

    }

    // validate/cleanup values
    this.r = (this.r < 0 || isNaN(this.r)) ? 0 : ((this.r > 255) ? 255 : this.r);
    this.g = (this.g < 0 || isNaN(this.g)) ? 0 : ((this.g > 255) ? 255 : this.g);
    this.b = (this.b < 0 || isNaN(this.b)) ? 0 : ((this.b > 255) ? 255 : this.b);

    // some getters
    this.toRGB = function () {
        return 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')';
    }
    this.toHex = function () {
        var r = this.r.toString(16);
        var g = this.g.toString(16);
        var b = this.b.toString(16);
        if (r.length == 1) r = '0' + r;
        if (g.length == 1) g = '0' + g;
        if (b.length == 1) b = '0' + b;
        return '#' + r + g + b;
    }
}
