//function DynEl(window, id, body, left, top, width, height, zIndex, visibility, bgcolor) {
function DynEl(window, id, body, left, top, width, height, zIndex, visibility, bgcolor){
	this.window = window;
	this.id = id;
	this.body = body;
	
	var d = window.document;
	d.writeln('<STYLE TYPE="text/css">');
	d.write('#' + id + '{position:absolute;');
	if(left) 	d.write('left:' + left + ';');
	if(top)  	d.write('top:' + top + ';');
	if(width) 	d.write('width:' + width + ';');
	if(height) 	d.write('height:' + height + ';');
	if(zIndex) 	d.write('z-index:' + zIndex +';');
	if(visibility)  d.write('visibility:' + visibility + ';');
	if(bgcolor){
		d.write('background-color:'+ bgcolor + ';');
		d.write('layer-background-color:'+ bgcolor + ';');
		d.write ('border: 1px none #000000;');
	}
/*	if(f-family) d.write('font-family:'+ f-family + ';');
	if(f-weight) d.write('font-weight:'+ f-weight + ';');
	if(f-size)	 d.write('font-size:'+ f-size + ';');
	if(t-align)	 d.write('text-align:'+ text-align + ';');
	if(t-color)  d.write('color:' + t-color + ';');
*/

	d.writeln('}');
	d.writeln('</STYLE>');
}

if(navigator.appName.indexOf("Netscape") != -1){

	DynEl.prototype.output = function(){
		var d = this.window.document;

		d.writeln('<DIV ID="' + this.id +'">');
		d.writeln(this.body);
		d.writeln("</DIV>");

		this.layer = d[this.id];
	}
	
	DynEl.prototype.moveTo = function(x,y) {
//		alert("llegue"); 
		this.layer.left = x;
		this.layer.top = y;
//		alert("salgo");
	}
	DynEl.prototype.moveBy = 	function(x,y) {this.layer.moveBy(x,y);}
	DynEl.prototype.show =   	function() {this.layer.visibility = "show";}
	DynEl.prototype.hide =   	function() {this.layer.visibility = "hide";}
	DynEl.prototype.setZIndex =    	function(z) {this.layer.zIndex = z;}
	DynEl.prototype.setBgColor =  	function(color) {this.layer.bgColor = color;}
	DynEl.prototype.setBgImage = 	function(image) {this.layer.background.src = image;}
	DynEl.prototype.setSrc = 	function(dir) {this.layer.src = dir;}

	DynEl.prototype.getX = 		function() {return this.layer.left;}
	DynEl.prototype.getY = 		function() {return this.layer.top;}
	DynEl.prototype.getWidth =   	function() {return this.layer.width;}
	DynEl.prototype.getHeight =   	function() {return this.layer.height;}
	DynEl.prototype.getZIndex =    	function() {return this.layer.zIndex;}
	DynEl.prototype.isVisible =  	function() {this.layer.visibility == "show";}

	DynEl.prototype.setBody = function(){
		this.layer.document.open();
		for (var i=0; i<arguments.length; i++){
			this.layer.document.writeln(arguments[i]);
		}
		this.layer.document.close();
	}

	DynEl.prototype.addEventHandler = function(eventname, handler){
		this.layer.captureEvents(DynEl._eventmasks[eventname]);
		var dynel = this;
		this.layer[eventname] = function(event){
			return handler(dynel, event.type, event.x, event.y, event.which, event.which,
				((event.modifiers & Event.SHIFT_MASK) !=0),
				((event.modifiers & Event.CTRL_MASK) !=0),
				((event.modifiers & Event.CTRL_MASK) !=0));
		}
	}

	DynEl.prototype.removeEventHandler = function(eventname){
		this.layer.releaseEvents(DynEl._eventmasks[eventname]);
		delete this.layer[eventname];
	}

	DynEl._eventmasks = {
			onabort:Event.ABORT, onblur:Event.BLUR, onchange:Event.CHANGE, onclick:Event.CLICK,
			ondblclick:Event.DBLCLICK, ondragdrop:Event.DRAGDROP, onerror:Event.ERROR,
			onfocus:Event.FOCUS, onkeydown:Event.KEYDOWN, onkeypress:Event.KEYPRESS, onkeyup:Event.KEYUP,
			onload:Event.LOAD, onmousedown:Event.MOUSEDOWN, onmousemove:Event.MOUSEMOVE,
			onmouseout:Event.MOUSEOUT, onmouseover:Event.MOUSEOVER, onmouseup:Event.ONMOUSEUP,
			onmove:Event.MOVE, onreset:Event.RESET, onresize:Event.RESIZE, onselect:Event.SELECT,
			onsubmit:Event.SUBMIT, onunload:Event.UNLOAD
	};
	
}


if(navigator.appName.indexOf("Microsoft") != -1){

	DynEl.prototype.output = function(){
		var d = this.window.document;

		d.writeln('<DIV ID="' + this.id +'">');
		d.writeln(this.body);
		d.writeln("</DIV>");

		this.element = d.all[this.id];
		this.style = this.element.style;
	}
	
	DynEl.prototype.moveTo = function(x,y) {
		this.style.left = x;
		this.style.top  = y;
	}
	DynEl.prototype.moveBy = function(x,y) {
		this.style.left += x;
		this.style.top += y;
	}
	DynEl.prototype.show =   	function() {this.style.visibility = "visible";}
	DynEl.prototype.hide =   	function() {this.style.visibility = "hidden";}
	DynEl.prototype.setZIndex =    	function(z) {this.style.zIndex = z;}
	DynEl.prototype.setBgColor =  	function(color) {this.style.backgroundColor = color;}
	DynEl.prototype.setBgImage = 	function(image) {this.style.backgroundImage = image;}
	DynEl.prototype.setSrc = 	function(dir) {this.style.document.location = dir;}

	DynEl.prototype.getX = 		function() {return this.style.pageX;}
	DynEl.prototype.getY = 		function() {return this.style.pageY;}
	DynEl.prototype.getWidth =   	function() {return this.style.width;}
	DynEl.prototype.getHeight =   	function() {return this.style.height;}
	DynEl.prototype.getZIndex =    	function() {return this.style.zIndex;}
	DynEl.prototype.isVisible =  	function() {this.style.visibility == "visible";}

	DynEl.prototype.setBody = function(){
		var body = "";
		for (var i=0; i<arguments.length; i++){
			body += arguments[i] + "\n"
		}
		this.element.innerHTML = body;
	}

	DynEl.prototype.addEventHandler = function(eventname, handler){
		var dynel = this;
		this.element[eventname] = function(){
			var e = dynel.window.event;
			e.cancelBubble = true;
			return handler(dynel, e.type, e.x, e.y, e.button, e.keyCode,
					e.shiftKey, e.cttrlKey, e.altKey);
		}
	}

	DynEl.prototype.removeEventHandler = function(eventname){
		delete this.element[eventname];
	}
}
