// apra leer png respetando la transparencia
// filter:	progid:DXImageTransform.Microsoft.AlphaImageLoader(src="button.png",sizingMethod="crop");
//


function addEvent(objObject, strEventName, fnHandler) {
	// DOM-compliant way to add an event listener
	if (objObject.addEventListener)
		objObject.addEventListener(strEventName, fnHandler, false);
	// IE/windows way to add an event listener
	else if (objObject.attachEvent)
		objObject.attachEvent("on" + strEventName, fnHandler);
}

var detect = navigator.userAgent.toLowerCase();
function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


var iexplorer=checkIt('msie');



function include(fichero){
	var head = document.getElementsByTagName("head")[0];
	var script = document.createElement("script");
	script.src = fichero;
	head.appendChild(script);
}


function includeScript(fichero) {
	document.write("<script type='text/javascript' src='" + fichero + "'></script>");
}




//*********************************************************
// Parche para cargar png transparentes en IE
//

// (c) dynarch.com 2003
// Author: Mihai Bazon, http://dynarch.com/mishoo/

if (/MSIE [56].*Windows/.test(navigator.userAgent)) (function() {
	// fucked-up browser (Internet Explorer for Windows)
	var blank = new Image;
	//blank.src = '/mishoo/images/blank.gif';
	var imgs = document.getElementsByTagName("img");
	for (var i = imgs.length; --i >= 0;) {
		var img = imgs[i];
		var src = img.src;
		if (!/\.png$/.test(src))
			continue;
		var s = img.runtimeStyle;
		s.width = img.offsetWidth + "px";
		s.height = img.offsetHeight + "px";
		s.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
		img.src = blank.src;
	}
})();




/***************************************************************************************************/
//

function STARTUP_Array()
	{
		this.cache= new Array();
		
		STARTUP_Array.prototype.count = function ()
		{
			return this.cache.length;
		}

		STARTUP_Array.prototype.add = function (item)
		{
			if (!item) return;
			if (!this.exist(item)) this.cache[this.count()] = item;
			
		}

		STARTUP_Array.prototype.del = function (nombreItem)
		{
			var lng=this.count;
			var a=0;
			if (lng==0) return false;
			for (a=0;a<lng;a++)   
			    {
			     if (this.cache[a]==nombreItem);
			        {
			        for(b=a;b<lng;b++)
			            {
			            this.cache[b]=this.cache[b+1];
			            }
			        this.cache.length--;
			        return true;
			        }
			    }
			return false;
		}

		STARTUP_Array.prototype.exist = function (nombreItem)
		{
			var a=0;
			for (a=0;a<this.count();a++)   
			  {
			  if (this.cache[a]==nombreItem) return this.cache[a];
			  }
			return false;   
		}

		STARTUP_Array.prototype.processx = function ()
		{
			var a=0;
			for (a=0;a<this.count();a++)   
			  {
			  eval (this.cache[a] + '()');
			  }
		}

		STARTUP_Array.prototype.process = function ()
		{
			var a=0;
			for (a=0;a<this.count();a++)   
			  {
			  	var f;
			  	eval ('f=function(){' + this.cache[a] + '()};');
			  	f();
			  }
		}
	}




var startupArray=new STARTUP_Array();



/***************************************************************************************************/
//

var autoNAME=0;

function autoGenerated()
	{
		return 'autoGenerated_' + (autoNAME++)
	}



function webObjectArray()
	{
		this.cache= new Array();
		
		webObjectArray.prototype.count = function ()
		{
			return this.cache.length;
		}

		webObjectArray.prototype.add = function (item)
		{
			if (!item) return;
			if (!item.nombre) return;
			if (!this.exist(item.nombre)) this.cache[this.count()] = item;
			
		}

		webObjectArray.prototype.del = function (nombreItem)
		{
			var lng=this.count;
			var a=0;
			if (lng==0) return false;
			for (a=0;a<lng;a++)   
			    {
			     if (this.cache[a].nombre==nombreItem);
			        {
			        for(b=a;b<lng;b++)
			            {
			            this.cache[b]=this.cache[b+1];
			            }
			        this.cache.length--;
			        return true;
			        }
			    }
			return false;
		}

		webObjectArray.prototype.exist = function (nombreItem)
		{
			var a=0;
			for (a=0;a<this.count();a++)   
			  {
			  if (this.cache[a].nombre==nombreItem) return this.cache[a];
			  }
			return false;   
		}

		webObjectArray.prototype.update = function (Item)
		{
			if (!Item) return false;
			if (!Item.nombre) return false;
			
			var a=0;
			for (a=0;a<this.count();a++)   
			{
				if (this.cache[a].nombre==Item.nombre) {
					this.cache[a]=Item;
					return this.cache[a];
				}
			}
			this.add(Item);
			return Item;   
		}


	}






var WEBOBJECTS=new webObjectArray();




/***********************************************************************************************************************/
/// Aņade herencia a los objetos
Object.prototype.extend = function (oSuper) 
{ 
       for (sProperty in oSuper) this[sProperty] = oSuper[sProperty]; 
}



/***********************************************************************************************************************/
/// Tamaņo del body




function BODY()
{
	if (iexplorer)
	{
		BODY.prototype.anchoVentana= function()		{
			if (!document.body) return 0;
			return document.body.clientWidth-1;			}

		BODY.prototype.altoVentana= function()		{
			if (!document.body) return 0;
			return document.body.clientHeight-1;		}

		BODY.prototype.anchoDocumento= function()	{
			if (!document.body) return 0;
			return document.body.scrollWidth;			}

		BODY.prototype.altoDocumento= function()		{
			if (!document.body) return 0;
			return document.body.scrollHeight;			}
		
		BODY.prototype.arriba= function()			{
			if (!document.body) return 0;
			return document.body.scrollTop;				}
		
		BODY.prototype.izquierda= function()			{
			if (!document.body) return 0;
			return document.body.scrollLeft;			}
	}
	else
	{
		BODY.prototype.anchoVentana= function()		{
			r=window.innerWidth-1; 
		    if(this.altoDocumento() >= window.innerHeight-16) r=r-17;
			return r;									}

		BODY.prototype.altoVentana= function()		{
			r=window.innerHeight-2;
			if(this.anchoDocumento() >= window.innerWidth-16) r=r-16;
			return r;									}

		BODY.prototype.anchoDocumento= function()	{
			if (!document.body) return 0;
			return document.documentElement.scrollWidth;}

		BODY.prototype.altoDocumento= function()		{
			if (!document.body) return 0;
			return document.documentElement.scrollHeight;}
		
		BODY.prototype.arriba= function()			{
			if (!document.body) return 0;
			return window.pageYOffset;					}
		
		BODY.prototype.izquierda= function()			{
			if (!document.body) return 0;
			return window.pageXOffset;					}
	}
	
	BODY.prototype.background= function (imagen)	{
		document.body.background=imagen;
	}
	
	BODY.prototype.element= function () {return document.body};
}

var body=new BODY();







/***********************************************************************************************************************/
/// funciones de uso general


function props(x){var T='';for(var p in eval(x)) T+=(p + "=" + eval("x." + p)+'\n');return T;}

function trimZero(n)
{
	var n=parseInt(n);
	return (n>=0) ? n:0;
}

function numero(x)
{
		if (isNaN(x)) x=parseInt(x.replace('px',''));
		return x;
}


/**************************************************/

function webObject(nombre)
{
	var r=WEBOBJECTS.exist(nombre);
	if (r) 	{
		this.extend(r);
		return;
	}

	this.tipo='WEBELEMENT';
	this.elemento=document.getElementById(nombre);
  	if (this.elemento) {this.style=this.elemento.style;} else this.style=0;
	this.nombre=nombre;
	this.objeto=eval('this');
	this.comportamiento=function(){};
	this.behaviourTimer=null;


	webObject.prototype.top=function(t)
	{
		if (!this.style) return 0;
		if (arguments.length) this.style.top=t + 'px';
		return numero(this.style.top);
	}
	
	webObject.prototype.left=function(t)
	{
		if (!this.style) return 0;
		if (arguments.length) this.style.left=t + 'px';
		return numero(this.style.left);
	}
	
	webObject.prototype.height=function(t)
	{
		if (!this.style) return 0;
		if (arguments.length) this.style.height=t; //else this.style.height='auto';
		var r=numero(this.elemento.offsetHeight)
//		if (!arguments.length) this.style.height=r;
		return r;
	}
	
	
	webObject.prototype.width=function(t)
	{
		if (!this.style) return 0;
		if (arguments.length) this.style.width=t; //else this.style.width='auto';
		var r=numero(this.elemento.offsetWidth);
//		if (!arguments.length) this.style.width=r;
		return r;
	}

	webObject.prototype.hide=function()
	{
		if (!this.style) return 0;
		this.style.display='none';
	}

	webObject.prototype.show=function()
	{
		if (!this.style) return 0;
		this.style.display='';
		alert ('hola');
	}

	
	webObject.prototype.opacity=function(t)
	{
		if (!this.style) return 0;
		if (iexplorer)
		{
			if (arguments.length) this.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=" + t + ")";
		}
		else
		{
			if (arguments.length) this.style.MozOpacity=t/100;
		}
		return false;
		
	}
	
	
	webObject.prototype.iniciar=function(tiempo)
	{
		if (this.behaviourTimer) window.clearInterval(this.behaviourTimer);
		if (tiempo&&this.comportamiento) 
		   {
		   	  WEBOBJECTS.update(eval('this'));
		   	  this.behaviourTimer=window.setInterval('WEBOBJECTS.exist("' + this.nombre + '").comportamiento()', tiempo);
		   }	  
	}

	webObject.prototype.evento=function(Evento,Funcion)
	{
		if ((this.elemento)&&(Evento)&&(Funcion)) 
		{
			var Evento=Evento.toLowerCase();
			addEvent(this.elemento, Evento, Funcion);
		   	WEBOBJECTS.update(eval('this'));
		}
	}
	
	
	WEBOBJECTS.add(this.objeto);
}

function DIV(nombre)
{
	this.extend(new webObject(nombre));
	this.tipo='DIV';
	DIV.prototype.adoptar=function(objeto) {
		if (!this.elemento)	return false;
		if (!objeto.elemento) return false;
		if (!objeto.nombre) return false;
		if (objeto.nombre==this.nombre) return false;
		return eval("this.elemento.appendChild(objeto.elemento);")!=false;
	}

	DIV.prototype.background=function(imagen) {
		if (this.style)	this.style.background="url('" + imagen + "');";
		return eval('this');
	}

	DIV.prototype.bgColor=function(color) {
		if (this.style) this.style.backgroundColor=color;
		return eval('this');
	}

	DIV.prototype.absolute=function() {
		if (this.style) this.style.position='absolute';
		return eval('this');
	}

	DIV.prototype.relative=function() {
		if (this.style) this.style.position='relativee';
		return eval('this');
	}

	DIV.prototype.fixed=function() {
		if (this.style) this.style.position='static';
		return eval('this');
	}
	
	DIV.prototype.overflow=function(ovr) {
		if (this.style) 
		{
			if (!ovr) var ovr='';
			if (!isNaN(ovr)) var ovr=String(ovr);
			overf='';
			switch(ovr){

				case '0':
				case 'hidden':
				          overf='hidden';break;
				case '1':
				case 'visible':
				          overf='visible';break;
				case '2':
				case 'inherit':
				          overf='inherit';break;
				case '3':
				case 'scroll':
				          overf='scroll';break;
				case '4':
				case 'auto':
				          overf='auto';break;
			 
			}
			this.style.overflow=overf;
			return eval('this');
		}
	}
	
	DIV.prototype.clip=function() {
		if (this.style) {
			var r="rect(0," + this.width() + "," + this.height() + ",0)";
			this.style.clip=r;
		}
	}
	
}



function crearDiv(nombre,x,y,ancho,alto,contenido)
{
	x=x||0;
	y=y||0;
	ancho=ancho||0;
	alto=alto||0;
	if (!nombre) nombre=autoGenerated();
	if (!contenido) contenido='';
	document.write ("<div id='" + nombre + "' style='position:absolute; overflow:hidden; top: " + x + ";left: " + y + ";width: " + ancho + ";height: " + alto + ";'>" + contenido + "</div>");
	return new DIV(nombre);
}