Object.prototype.inheritFrom = function( objType, args ) {
	eval( "var obj = new "+objType+"();" );
	this.inheritInstance( obj, args );
}

Object.prototype.inheritInstance = function( obj, args ) {
	for( var p in obj ) {
		this[p] = obj[p];
	}
	for ( a in args ) {
		this[a] = args[a];
	}
}
Object.prototype.inherit = function( obj, args ) {
	if ( typeof obj == "object" ) {
		this.prototype = new obj();
	}
	else {
		this.prototype = new obj();
	}
	for ( a in args ) {
		this[a] = args[a];
	}
}

Object.prototype.toInt = function() {
	var i = parseInt( this );
	if ( i == "undefined" || isNaN( i ) || i === null ) {
		return 0;
	}
	return i;
}

Array.prototype.last = function() {
	return this[this.length-1];
}

function CrossEvent( e ) {
	this.e = 		e;
	this.type = 	e.type;
	this.target = 	(e.target) ? e.target : e.srcElement;
	this.key = 		( e.keyCode ) ? e.keyCode : e.which
	//this.e.dump = Object.prototype.dump;
	//this.target.dump = Object.prototype.dump;

	this.stopPropagation = function() {
		if ( CrossDom.isFireFox ) {
			this.e.stopPropagation();
		}
		if ( CrossDom.idIE ) {
			this.e.cancelBubble = true;
		}
	}
}

function _CrossDOM() {
	this.isExternal = false;
	if ( arguments[0] ) {
		this.document = arguments[0];
		this.isExternal = true;
	}
	else {
		this.document = window.document;
	}
	
	this.nav = navigator.userAgent.toLowerCase();
	this.isIE = (this.nav.indexOf("msie") != -1 && this.document.all);
	this.isFireFox = this.nav.indexOf("firefox") != -1
	
	this.getElementById = function( id ) {
		return this.document.getElementById( id );
	}
	
	this.createElement = function( type ) {
		var el = this.document.createElement( type );
		if ( arguments.length > 1 ) {
			var properties = arguments[1];
			for ( p in properties ) {
				el[p] = properties[p];
			}
		}
		return el;
	}
	
	this.appendChild = function( parent, child ) {
		parent.appendChild( child );
	}
	
	this.appendChildToBody = function( child ) {
		this.document.body.appendChild( child );
	}
	
	this.insertAtIndex = function( parent, child, index ) {
		var sibling = parent.childNodes[index];
		if ( ! sibling ) {
			this.appendChild( parent, child );
		}
		else {
			parent.insertBefore( child, sibling );
		}
	}
	
	this.removeChild = function( parent, child ) {
		parent.removeChild( child );
	}
	
	this.removeNode = function( node ) {
		this.removeChild( node.parentElement, node );
	}
	
	this.getEvent = function ( e ) {
		var win = window;
		if ( this.isExternal ) {
			win = win.parent;
		}
		var evt = ( win.event ) ? win.event : e;
		return new CrossEvent( evt );
	}
	
	this.absX = function(obj) {
		var curleft = 0;
		if ( obj && obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}

	this.absY = function( 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;
	}
}
var CrossDom = new _CrossDOM();
var CrossDom2 = new _CrossDOM();

function _Debugger() {
	var self = this;
	this._debugMode = false;
	this._debugWin = null;
	
	this.debugMode = function() {
		if ( this._debugMode ) return;
		window.moveTo( 0, 0 );
		window.resizeTo( screen.width-400, 845 );
		this._debugWin = window.open("","debugCanvas", "scrollbars=yes;toolbar=no,menubar=no,width=390,height=800,resizable=yes,left="+(screen.width-400)+",top=0");
		this._debugWin.document.open();
		this._debugMode = true; 
	}
	
	this.closeDebugger = function() {
		if ( self._debugWin ) {
			self._debugWin.close();
		}
	}
	
	this.write = function( str ) {
		if ( ! this._debugWin ) { return }
		this._debugWin.document.write( str + "<br>" );
		this._debugWin.document.scrollTop = 10000;
	}
	
	this.alert = function( msg ) {
		if ( ! confirm( msg ) ) {
			__STOP__;
		}
	}
	
	this.dump = function ( obj ) {
		if ( obj ) {
			var post_str = "";
			var w = window.open();
			w.document.open();
			for( var p in obj ) {
				if ( obj[p] ) {
					w.document.write( "this."+p+" = "+obj[p]+"<br>" );
				}
				else {
					post_str += "this."+p+" = "+obj[p]+"<br>";
				}
			}
			w.document.write( "<hr>"+post_str );
			w.document.close();
		}
		else {
			alert( "Cannot dump obj: "+obj );
		}
	}
}
Debugger = new _Debugger();
	
	
//window.onbeforeunload = this.closeDebugger;
var Debugger = new _Debugger();




var _loadedScripts = new Array();
function is_loaded( scriptsrc ) {
	var scripts = document.getElementsByTagName( "SCRIPT" );
	for( var i=0; i < scripts.length; i++ ) {
		if ( scripts[i].src == scriptsrc ) {
			return true;
		}
	}
	return false;
}

function include( scriptsrc ) {
	if ( ! is_loaded( scriptsrc ) ) {
		var script = document.createElement( "SCRIPT" );
		script.src = scriptsrc;
		var head = document.getElementsByTagName( "HEAD" );
		if( head.length > 0 ) {
			head[0].appendChild( script );
		}
	}	
}

// Encodes special characters
function myxml_fix(data) {
	data = data.replace( /&/g, "&amp;" );
	data = data.replace( />/g, "&gt;" );
	data = data.replace( /</g, "&lt;" );
	data = data.replace( /"/g, "&quot;" );
	return data;
}

// Decodes special characters
function myxml_defix(data) {
	data = data.replace( "&quot;","\"" );
	data = data.replace( "&gt;", "<" );
	data = data.replace( "&lt;", ">" );
	data = data.replace( "&amp;", "&" );
	return data;
}