
String.prototype.hexTOrgb = function() {
	for ( var hex, i = 0, colors = this.match( /\w\w/g ); ( hex = parseInt( "0x" + colors[i] ) ); i++ )
	colors[i] = hex;
	return colors.join( ',' );
}

String.prototype.rgbTOhex = function() {
	for ( var rgb, i = 0, colors = this.split(','); ( rgb = colors[i] ); i++ )
	colors[i] = parseInt( rgb ).toString( 16 ).toUpperCase().leadingZeros( 1, 2 );
	return "#" + colors.join( '' );
}

String.prototype.leadingZeros = function( qty, totalPlaces ) {
	var s = this;
	if ( this.length + qty > totalPlaces ) return s;
	for ( var i=0; i<qty; i++ )
	s = "0" + s;
	return s;
}

String.prototype.anyToHex = function() {
	if( this.length <= 7 ) {
		return this.toUpperCase();
	} else {
		result = this.substr(4);
		result = result.substr( 0, (result.length-1) );
		return result.rgbTOhex();
	}
}

String.prototype.getFileName = function() {
	var result = this.replace( /\//gi, "\\" );
	resultArr = result.split( '\\' );
	return( resultArr[ resultArr.length - 1 ] );
}


var IE = ( document.all ? true : false );

function flipImg( imageObj, fileName ) {
    imageObj = document.getElementById( imageObj );
    
	document.lastImage = imageObj.src;
	imageObj.src = fileName;
}

function restoreImg( imageObj ) {
    imageObj = document.getElementById( imageObj );
    
	if( document.lastImage ) imageObj.src = document.lastImage;
	document.lastImage = "";
}

function focusFirstInput( divId ) {
	if( divId ) {
		var obj = document.getElementById( divId );

		if( obj.getElementsByTagName( 'input' )[ 0 ] ) {
			obj.getElementsByTagName( 'input' )[ 0 ].focus();
			obj.getElementsByTagName( 'input' )[ 0 ].select();
		}
	}
}

function getX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function getY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getElementValueByName( elementName, obj ) {
	nameObj = obj.getElementsByTagName( elementName )[ 0 ];
	eleValue = nameObj.firstChild.nodeValue;

  return( eleValue );
}

function getElementsByTagNames(list,obj)
{
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++)
	{
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++)
		{
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (testNode.sourceIndex)
	{
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition)
	{
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}
