/******************************************
*	
*	SYSTEM
*	
*******************************************/

var javascriptFolder = '?script=';
var requiredFiles = new Array();
var mouse;
var IE = document.all?true:false;
var startTime;
var pasteboard;
var onloadProcessesLoaded = false;

setTimeout('processOnLoad();', 4000);

function processOnLoad()
{
	if (onloadProcessesLoaded)
		return;
		
	onloadProcessesLoaded = true;
	for (var i =0; i < onloadfunctions.length; i++)
	{
		var onloadfunction = onloadfunctions[i];
		onloadfunction();
	}
	
}

function require(file)
{
	var script 	= document.createElement('script');
	script.src 	= javascriptFolder + file;
	script.type	= 'text/javascript';
	
 	if (document.getElementsByTagName('head').length > 0)
	{
		var parent = document.getElementsByTagName('head')[0];
		parent.appendChild(script);
	}
	else
	{
		var parent = document.getElementsByTagName('body')[0];
		parent.insertBefore(script, parent.firstChild);
	}
}

function initSystem()
{
	mouse = new Object();
	mouse.x = 0;
	mouse.y = 0;
	mouse.up = true;
	mouse.down = false;
	
	var time = new Date();
	
	startTime = time.getTime();
	
	if (!IE) 
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEDOWN);
		document.captureEvents(Event.MOUSEUP);
	}

	document.onmousemove 	= mouseMove;	
	document.onmouseup 		= mouseUp;
	document.onmousedown 	= mouseDown;
	
}

function dialogbox(callback, content, buttons, functions, data)
{
	
}


function mouseMove(e)
{
	if (IE) 
	{
		mouse.x = event.clientX + getScrollWidth();
		mouse.y = event.clientY + getScrollHeight();
	}
	else
	{
		mouse.x = e.pageX;
		mouse.y = e.pageY;
	}
}

function mouseUp()
{
	mouse.down = false;
	mouse.up = true;
}

function mouseDown()
{
	mouse.down = true;
	mouse.up = false;
}

function addEventListener(obj,event,fct, capture){
	return xb.addEvent(obj, event, fct, capture);
     /*if(obj.attachEvent)
        obj.attachEvent('on' + event, fct);
     else
	 if (obj.addEventListener)
        obj.addEventListener(event,fct,true);*/
}

var xb =
{
   evtHash: [],

   ieGetUniqueID: function(_elem)
   {
      if (_elem === window) { return 'theWindow'; }
      else if (_elem === document) { return 'theDocument'; }
      else { return _elem.uniqueID; }
   },

   addEvent: function(_elem, _evtName, _fn, _useCapture)
   {
      if (typeof _elem.addEventListener != 'undefined')
      { _elem.addEventListener(_evtName, _fn, _useCapture); }
      else if (typeof _elem.attachEvent != 'undefined')
      {
         var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) +
               '::evt_' + _evtName + '::fn_' + _fn + '}';
         var f = xb.evtHash[key];
         if (typeof f != 'undefined')
            { return; }

         f = function()
         {
            _fn.call(_elem);
         };

         xb.evtHash[key] = f;
         _elem.attachEvent('on' + _evtName, f);

         // attach unload event to the window to clean up possibly IE memory leaks
         window.attachEvent('onunload', function()
         {
            _elem.detachEvent('on' + _evtName, f);
         });

         key = null;
         //f = null;   /* DON'T null this out, or we won't be able to detach it */
      }
      else
         { _elem['on' + _evtName] = _fn; }
   },

   removeEvent: function(_elem, _evtName, _fn, _useCapture)
   {
      if (typeof _elem.removeEventListener != 'undefined')
         { _elem.removeEventListener(_evtName, _fn, _useCapture); }
      else if (typeof _elem.detachEvent != 'undefined')
      {
         var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) +
               '::evt' + _evtName + '::fn_' + _fn + '}';
         var f = xb.evtHash[key];
         if (typeof f != 'undefined')
         {
            _elem.detachEvent('on' + _evtName, f);
            delete xb.evtHash[key];
         }

         key = null;
         //f = null;   /* DON'T null this out, or we won't be able to detach it */
      }
   }
};

function getElapsedTime(userTime)
{
	var time = new Date();
	var elapsedTime = (time.getTime() - startTime) / 1000;
	
	if (userTime)
	{
		return (elapsedTime - userTime);
	}
	else
	{
		return elapsedTime;
	}
}

function moveWithMouse(object, offset)
{
	object.style.left = mouse.x + offset.x +'px';
	object.style.top = mouse.y + offset.y +'px';
}

function getMouseOffset(object)
{ 
    var objectPos    = getBounds(object); 
    return {x:objectPos.left - mouse.x, y:objectPos.top - mouse.y}; 
}

function mouseHasMoved(prevmouse, offset)
{
	if (!offset)
		offset = 1;
	
	if (prevmouse && (Math.abs(prevmouse.x - mouse.x) >= offset || Math.abs(prevmouse.y - mouse.y) >= offset))
	{
		return true;
	}
	else
	{
		return false;
	}
}


function mouseInBounds(dim)
{
	if (mouse.x >= dim.left && mouse.y >= dim.top && mouse.x <= dim.left + dim.width && mouse.y <= dim.top + dim.height)
		return true;
	else
		return false;
		
}

function inherit(object, from, param)
{
	for (var prop in from.prototype) {
        if (typeof from.prototype[prop] == "function")
		{
			object[prop]  = from.prototype[prop];
		}
	}
	
	if (from.prototype.constructor)
	{
		object.construct = from.prototype.constructor;
		object.construct(param);
	}
	return object;
}

function findNode(list, node) {
	for (var i = 0; i < list.length; i++) {
		if (list[i] == node) {
			return i;
		}
	}
	return -1;
}

var findCaretPosition = function(obj){
	var startpos = 0;
	var endpos = 0;
	
	if(document.getSelection){
		var sel = window.getSelection().getRangeAt(0);
		startpos = sel.startOffset;
		endpos = sel.endOffset;
	} else {
		var range = document.selection.createRange();
		var rangeCopy = range.duplicate();
		rangeCopy.moveToElementText(obj);
		rangeCopy.setEndPoint( 'EndToEnd', range );
		startpos = rangeCopy.text.length - range.text.length;
		endpos = startpos + range.text.length;
	}
	return [startpos, endpos];
}

function load_xml_content_string(xmlData) {
	if (window.ActiveXObject) {
		//for IE
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(xmlData);
		return xmlDoc;
	} else if (document.implementation && document.implementation.createDocument) {
		//for Mozila
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xmlData,"text/xml");
		return xmlDoc;
	}
	return xmlData;
}

function appendChildren(to, children)
{
	if (children)
	{
		for (var i = 0; i < children.length; i++)
			to.appendChild(children[i]);
	}
}

function generateElements(xml, tagname, container)
{
	//try
	if (!tagname)
		tagname = 'display';
		
	{
		var display = xml.getElementsByTagName(tagname)[0];
		var customStyle	= xml.getElementsByTagName('style')[0];
		var scripts = xml.getElementsByTagName('script')[0];
		
		var display = convertToHtml(display, false);
		
		initElements(display.getElementsByTagName('*'), container);
		
		var elements = new Array();
		
		for (var i = 0; i < display.childNodes.length; i++)
		{
			var element = display.childNodes[i];
			elements[elements.length] = element;
		}
		
		if (customStyle && customStyle.firstChild)
		{
			var head 	= document.getElementsByTagName('head')[0];
			var style 	= head.getElementsByTagName('style')[0];
			
			if (!style || !style.appendChild)
			{
				style = document.createElement('style');
				style.type='text/css';
				head.appendChild(style);
			}
			
			if (style.styleSheet)  // IE
				style.styleSheet.cssText += customStyle.firstChild.nodeValue;else
				style.appendChild(document.createTextNode(customStyle.firstChild.nodeValue));
		}
		
		if (scripts && scripts.firstChild)
		{
			
		}
		return elements;
	}
}

function convertToHtml(nodexml, returnChildren, parent)
{
	var node = null;
	
	if (returnChildren)
	{
		$children = new Array();
		
		for (var i = 0; i < nodexml.childNodes.length; i++)
			if (nodexml.childNodes[i].nodeType == 1)
			{
				$children[$children.length] = convertToHtml(nodexml.childNodes[i]);
			}
		
		if ($children.length)
			return $children;else
			return false;
	}
	
	if (nodexml.nodeType == 3)
	{
		node = document.createTextNode(nodexml.nodeValue);
	}
	else if (nodexml.nodeType == 1)
	{
		node = document.createElement(nodexml.tagName);
		
		if (nodexml.getAttribute("id"))
			node.id 		= nodexml.getAttribute("id");
		
		if (nodexml.getAttribute("class"))
			node.className 	= nodexml.getAttribute("class");
		
		for (var i = 0; i < nodexml.attributes.length; i++)
		{
			var attribute = nodexml.attributes[i];
			node.setAttribute(attribute.name, attribute.value);
		}
		
		if (nodexml.childNodes)
		for (var i = 0; i < nodexml.childNodes.length; i++)
		{
			convertToHtml(nodexml.childNodes[i], false, node);
		}
	}
	
	if (parent)
	{
		parent.appendChild(node);
	}
	
	return node;
}

function strtok (str, tokens) {
    // Tokenize a string  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strtok    // +   original by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: Use tab and newline as tokenizing characters as well
    // *     example 1: $string = "\t\t\t\nThis is\tan example\nstring\n";
    // *     example 1: $tok = strtok($string, " \n\t");
    // *     example 1: $b = '';    // *     example 1: while ($tok !== false) {$b += "Word="+$tok+"\n"; $tok = strtok(" \n\t");}
    // *     example 1: $b
    // *     returns 1: "Word=This\nWord=is\nWord=an\nWord=example\nWord=string\n"
    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};    // END REDUNDANT
	
    if (tokens === undefined && str) {
        tokens = str;
        str = this.php_js.strtokleftOver;
	}
	
    if (!str || str.length === 0)
	{
        return false;
    }
	
    if (tokens.indexOf(str.charAt(0)) !== -1) 
	{
		return this.strtok(str.substr(1), tokens);
    }
	
    for (var i=0; i < str.length; i++)
	{
        if (tokens.indexOf(str.charAt(i)) !== -1) 
		{
            break;
		}
    }
	
    this.php_js.strtokleftOver = str.substr(i+1);
    return str.substring(0, i);
}


function getDocumentWidth(){
	return (document.all)?document.body.offsetWidth:(window.innerWidth - 17);
}

function getDocumentHeight()
{
	var documentHeight 	= (document.all)?document.body.offsetHeight:window.innerHeight;
	var bodyHeight 		= document.getElementsByTagName('body')[0].offsetHeight;
	
	if (bodyHeight > documentHeight)
	{
		return bodyHeight;
	}
	else
	{
		return documentHeight;
	}
}

function getScrollWidth()
{
	try
	{
		var w = window.pageXOffset ||
		document.body.scrollLeft ||
		document.documentElement.scrollLeft;

		return w ? w : 0;
	}
	catch (ex)
	{
		return 0;
	}
}

function getScrollHeight()
{
	try
	{
		var h = window.pageYOffset ||
		document.body.scrollTop ||
		document.documentElement.scrollTop;

		return h ? h : 0;
	}
	catch (ex)
	{
		return 0;
	}
}

function cloneObject(object) {
	var clone = new Object();
	
	for (i in object) 
	{
		clone[i] = object[i];
	}
	
	return clone;
}

function hasElementClass(el, className)
{
	if (!el || !el.className)
		return false;
	
	var classList 	= el.className.split(' ');
	var newClass	= new Array();
	
	for (i = 0; i < classList.length; i++)
	{
		if (classList[i] == className)
		{
			return true;
		}
	}
	
	return false;
}

function addElementClass(el, className)
{
	if (!el)
		return false;
		
	if (!el.className)
		el.className = '';
	
	var classList = el.className.split(' ');
	
	for (i = 0; i < classList.length; i++)
	{
		if (classList[i] == className) return;
	}
	if (className && className != ' ')
		classList.push(className.replace(' ', ''));
	
	el.className = classList.join(' ');
}


function removeElementClass(el, className)
{
	if (!el || !el.className)
		return;
	
	var classList 	= el.className.split(' ');
	var newClass	= new Array();
	
	for (i = 0; i < classList.length; i++)
	{
		if (classList[i] && classList[i] != className)
		{
			newClass.push(classList[i].replace(' ', ''));
		}
	}
	
	el.className = newClass.join(' ');
}

function objectAddClass(className)
{
	addElementClass(this, className);
}

function objectRemoveClass(className)
{
	removeElementClass(this, className);
}

function objectHasClass(className)
{
	return elementHasClass(this, className);
}

function objectSetOpacity(amount)
{
	amount = (amount == 100)?99.999:amount;
  
	// IE
	this.style.filter = "alpha(opacity:"+amount+")";
	
	// Safari<1.2, Konqueror
	this.style.KHTMLOpacity = amount/100;
  
	// Mozilla and Firefox
	this.style.MozOpacity = amount/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	this.style.opacity = amount/100;
}

function objectAt(x, y, topObject)
{
	if (!topObject)
	{
		return false;
	}
	
	if (topObject.childNodes)
	{
		for (i in topObject.childNodes)
		{
			var objectUnder = objectAt(x, y, topObject.childNodes[i]);
			
			if (objectUnder)
			{
				return objectUnder;
			}
		}
	}
	
	var dim = getDimensions(topObject);
	if (x >= dim.x && y >= dim.y && x <= dim.x + dim.width && y <= dim.y + dim.height)
	{
		return  topObject;
	}
	
	return false;
}

function getBounds(object, message){ 
    var left = 0; 
    var top  = 0; 
	var firstObject = object;
	
    while (object.offsetParent){ 
        left += object.offsetLeft; 
        top  += object.offsetTop; 
        object = object.offsetParent;
    }

    return {left:left, top:top, width:firstObject.offsetWidth, height:firstObject.offsetHeight}; 
}


function setBounds(object, bounds){
	object.style.position 	= 'absolute';
	if (bounds.left)
	object.style.left 		= bounds.left + 'px';
	if (bounds.top)
	object.style.top		= bounds.top + 'px';
	if (bounds.width)
	object.style.width		= bounds.width + 'px';
	if (bounds.height)
	object.style.height		= bounds.height + 'px';
}

function getDimensions(object){ 
	return getBounds(object);
}

function setBox(object, x1, y1, x2, y2){
	object.style.position 	= 'absolute';
	object.style.left 		= x1 + 'px';
	object.style.top		= y1 + 'px';
	object.style.width		= (x2 - x1) + 'px';
	object.style.height		= (y2 - y1) + 'px';
} 

function setDimensions(object, left, top, width, height){
	/*object.style.position 	= 'absolute';
	object.style.left 		= left + 'px';
	object.style.top		= top + 'px';
	object.style.width		= width + 'px';
	object.style.height		= height + 'px';*/
	setBounds(object, {left:left, top:top, width:width, height:height});
} 


function getNodeText(node)
{
	if (document.all)
	{
		return node.innerText;
	}
	else if (node.text)
	{
		return node.textContent;
	}
	else
	{
		return node.innerHTML;
	}
}

function isChildOf(object, parent)
{
	while (object && object.parentNode){
        if (object.parentNode == parent)
		{
			return true;
		}
		object = object.parentNode; 
    } 
	return false;
}

Array.prototype.remove = function(from, to) {
	var rest = this.slice((to || from) + 1 || this.length);
	this.length = from < 0 ? this.length + from : from;
	return this.push.apply(this, rest);
};

function inArray (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}

function stripTags(oldString)
{
	return oldString.replace(/<&#91;^>&#93;*>/g, "");
}


function getSelectedText(){
    if (window.getSelection){
       var str = window.getSelection();
    }else if (document.getSelection){
       var str = document.getSelection();
    }else {
       var str = document.selection.createRange().text;
    }
    return str;
}


function documentWidth() {
	var width;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		width = window.innerWidth;
	} else 
	
	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		width = document.documentElement.clientWidth;
	} else 
	
	if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		width = document.body.clientWidth;
	}
	
	return width;
}

function doGetCaretPosition (oField) {

 // Initialize
 var iCaretPos = 0;

 // IE Support
 if (document.selection) { 

   // Set focus on the element
   oField.focus ();

   // To get cursor position, get empty selection range
   var oSel = document.selection.createRange ();

   // Move selection start to 0 position
   oSel.moveStart ('character', -oField.value.length);

   // The caret position is selection length
   iCaretPos = oSel.text.length;
 }

 // Firefox support
 else if (oField.selectionStart || oField.selectionStart == '0')
   iCaretPos = oField.selectionStart;

 // Return results
 return (iCaretPos);
}


/*
**  Sets the caret (cursor) position of the specified text field.
**  Valid positions are 0-oField.length.
*/
function doSetCaretPosition (oField, iCaretPos) {

 // IE Support
 if (document.selection) { 

   // Set focus on the element
   oField.focus ();

   // Create empty selection range
   var oSel = document.selection.createRange ();

   // Move selection start and end to 0 position
   oSel.moveStart ('character', -oField.value.length);

   // Move selection start and end to desired position
   oSel.moveStart ('character', iCaretPos);
   oSel.moveEnd ('character', 0);
   oSel.select ();
 }

 // Firefox support
 else if (oField.selectionStart || oField.selectionStart == '0') {
   oField.selectionStart = iCaretPos;
   oField.selectionEnd = iCaretPos;
   oField.focus ();
 }
}

   
function documentHeight() {
	var height;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		height = window.innerHeight;
	} else 
	
	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		height = document.documentElement.clientHeight;
	} else 
	
	if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		height = document.body.clientHeight;
	}
	
	return height;
}


function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}


function RGBColor(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();

    // before getting into regexps, try simple matches
    // and overwrite the input
    var simple_colors = {
        aliceblue: 'f0f8ff',
        antiquewhite: 'faebd7',
        aqua: '00ffff',
        aquamarine: '7fffd4',
        azure: 'f0ffff',
        beige: 'f5f5dc',
        bisque: 'ffe4c4',
        black: '000000',
        blanchedalmond: 'ffebcd',
        blue: '0000ff',
        blueviolet: '8a2be2',
        brown: 'a52a2a',
        burlywood: 'deb887',
        cadetblue: '5f9ea0',
        chartreuse: '7fff00',
        chocolate: 'd2691e',
        coral: 'ff7f50',
        cornflowerblue: '6495ed',
        cornsilk: 'fff8dc',
        crimson: 'dc143c',
        cyan: '00ffff',
        darkblue: '00008b',
        darkcyan: '008b8b',
        darkgoldenrod: 'b8860b',
        darkgray: 'a9a9a9',
        darkgreen: '006400',
        darkkhaki: 'bdb76b',
        darkmagenta: '8b008b',
        darkolivegreen: '556b2f',
        darkorange: 'ff8c00',
        darkorchid: '9932cc',
        darkred: '8b0000',
        darksalmon: 'e9967a',
        darkseagreen: '8fbc8f',
        darkslateblue: '483d8b',
        darkslategray: '2f4f4f',
        darkturquoise: '00ced1',
        darkviolet: '9400d3',
        deeppink: 'ff1493',
        deepskyblue: '00bfff',
        dimgray: '696969',
        dodgerblue: '1e90ff',
        feldspar: 'd19275',
        firebrick: 'b22222',
        floralwhite: 'fffaf0',
        forestgreen: '228b22',
        fuchsia: 'ff00ff',
        gainsboro: 'dcdcdc',
        ghostwhite: 'f8f8ff',
        gold: 'ffd700',
        goldenrod: 'daa520',
        gray: '808080',
        green: '008000',
        greenyellow: 'adff2f',
        honeydew: 'f0fff0',
        hotpink: 'ff69b4',
        indianred : 'cd5c5c',
        indigo : '4b0082',
        ivory: 'fffff0',
        khaki: 'f0e68c',
        lavender: 'e6e6fa',
        lavenderblush: 'fff0f5',
        lawngreen: '7cfc00',
        lemonchiffon: 'fffacd',
        lightblue: 'add8e6',
        lightcoral: 'f08080',
        lightcyan: 'e0ffff',
        lightgoldenrodyellow: 'fafad2',
        lightgrey: 'd3d3d3',
        lightgreen: '90ee90',
        lightpink: 'ffb6c1',
        lightsalmon: 'ffa07a',
        lightseagreen: '20b2aa',
        lightskyblue: '87cefa',
        lightslateblue: '8470ff',
        lightslategray: '778899',
        lightsteelblue: 'b0c4de',
        lightyellow: 'ffffe0',
        lime: '00ff00',
        limegreen: '32cd32',
        linen: 'faf0e6',
        magenta: 'ff00ff',
        maroon: '800000',
        mediumaquamarine: '66cdaa',
        mediumblue: '0000cd',
        mediumorchid: 'ba55d3',
        mediumpurple: '9370d8',
        mediumseagreen: '3cb371',
        mediumslateblue: '7b68ee',
        mediumspringgreen: '00fa9a',
        mediumturquoise: '48d1cc',
        mediumvioletred: 'c71585',
        midnightblue: '191970',
        mintcream: 'f5fffa',
        mistyrose: 'ffe4e1',
        moccasin: 'ffe4b5',
        navajowhite: 'ffdead',
        navy: '000080',
        oldlace: 'fdf5e6',
        olive: '808000',
        olivedrab: '6b8e23',
        orange: 'ffa500',
        orangered: 'ff4500',
        orchid: 'da70d6',
        palegoldenrod: 'eee8aa',
        palegreen: '98fb98',
        paleturquoise: 'afeeee',
        palevioletred: 'd87093',
        papayawhip: 'ffefd5',
        peachpuff: 'ffdab9',
        peru: 'cd853f',
        pink: 'ffc0cb',
        plum: 'dda0dd',
        powderblue: 'b0e0e6',
        purple: '800080',
        red: 'ff0000',
        rosybrown: 'bc8f8f',
        royalblue: '4169e1',
        saddlebrown: '8b4513',
        salmon: 'fa8072',
        sandybrown: 'f4a460',
        seagreen: '2e8b57',
        seashell: 'fff5ee',
        sienna: 'a0522d',
        silver: 'c0c0c0',
        skyblue: '87ceeb',
        slateblue: '6a5acd',
        slategray: '708090',
        snow: 'fffafa',
        springgreen: '00ff7f',
        steelblue: '4682b4',
        tan: 'd2b48c',
        teal: '008080',
        thistle: 'd8bfd8',
        tomato: 'ff6347',
        turquoise: '40e0d0',
        violet: 'ee82ee',
        violetred: 'd02090',
        wheat: 'f5deb3',
        white: 'ffffff',
        whitesmoke: 'f5f5f5',
        yellow: 'ffff00',
        yellowgreen: '9acd32'
    };
    for (var key in simple_colors) {
        if (color_string == key) {
            color_string = simple_colors[key];
        }
    }
    // emd of simple type-in colors

    // 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;
    }

    // help
    this.getHelpXML = function () {

        var examples = new Array();
        // add regexps
        for (var i = 0; i < color_defs.length; i++) {
            var example = color_defs[i].example;
            for (var j = 0; j < example.length; j++) {
                examples[examples.length] = example[j];
            }
        }
        // add type-in colors
        for (var sc in simple_colors) {
            examples[examples.length] = sc;
        }

        var xml = document.createElement('ul');
        xml.setAttribute('id', 'rgbcolor-examples');
        for (var i = 0; i < examples.length; i++) {
            try {
                var list_item = document.createElement('li');
                var list_color = new RGBColor(examples[i]);
                var example_div = document.createElement('div');
                example_div.style.cssText =
                        'margin: 3px; '
                        + 'border: 1px solid black; '
                        + 'background:' + list_color.toHex() + '; '
                        + 'color:' + list_color.toHex()
                ;
                example_div.appendChild(document.createTextNode('test'));
                var list_item_value = document.createTextNode(
                    ' ' + examples[i] + ' -> ' + list_color.toRGB() + ' -> ' + list_color.toHex()
                );
                list_item.appendChild(example_div);
                list_item.appendChild(list_item_value);
                xml.appendChild(list_item);

            } catch(e){}
        }
        return xml;

    }

}


initSystem();