//////////////////////////////////////
// Objeto __Cross (browser) 0.09b	//
//////////////////////////////////////
//(c) Jorge Lopez Monterrubio, 2002 //
//  jlopezmonterrubio@hotmail.com   //
//////////////////////////////////////


function __Cross_Class() {
	this.__Cross_=true;
	// check for browser
	this.isDOM=(document.getElementById)?true:false;
	this.isIE=document.all?true:false;
	this.isIE4=this.isIE && !this.isDOM;
	this.isIE5=this.isIE&&this.isDOM&&navigator.appVersion.indexOf("MSIE 5")>-1;
	this.isIE6=this.isIE&&this.isDOM&&navigator.appVersion.indexOf("MSIE 6")>-1;
	this.isNS=!this.isIE && (navigator.appName.indexOf("Netscape")!=-1);
	this.isNS4=this.isNS && !this.isDOM && (parseFloat(navigator.appVersion)>=4)
									   && (parseFloat(navigator.appVersion)<6);
	this.isGecko=navigator.product == ("Gecko");
	this.isNS6=this.isGecko || (this.isNS && this.isDOM );
	this.isMac=navigator.userAgent.indexOf("Mac")>-1;

	this.getMethod=__Cross_getMethod;
	this.getTag=__Cross_getTag;
	this.setStyle=__Cross_setStyle;
	this.addEventListener=__Cross_addEventListener;
	this.removeEventListener=__Cross_removeEventListener;
	this.alertObject=__Cross_alertObject; // debug
	this.alertForm=__Cross_alertForm; // debug
	this.setInnerHTML=__Cross_setInnerHTML;
	this.checkCreateLayer=__Cross_checkCreateLayer; // si se puede crear capas
													// en un momento dado
	// metodos según browser (mayor velocidad)
	this.setPosicion=this.getMethod("setPosicion");
	this.getX=this.getMethod("getX");
	this.getY=this.getMethod("getY");
	this.getZ=this.getMethod("getZ");
	//
	this.setSize=this.getMethod("setSize");
	this.getWidth=this.getMethod("getWidth");
	this.getHeight=this.getMethod("getHeight");
	//
	this.setVisibility=this.getMethod("setVisibility");
	this.setBgColor=this.getMethod("setBgColor");
	// screen
	this.setPageX=this.getMethod("setPageX");
	this.setPageY=this.getMethod("setPageY");
	this.getPageX=this.getMethod("getPageX");
	this.getPageY=this.getMethod("getPageY");
	this.getPageWidth=this.getMethod("getPageWidth");
	this.getPageHeight=this.getMethod("getPageHeight");
	//
	this.onDocument=new __Cross_document_Class(this);
}
function __Cross_getMethod(name) {
 var m=null;
 	if(this.isDOM) m=eval("window.__Cross_"+name+"_DOM");
	if(!m) {
		var sufix;
		if(this.isIE
			|| (this.isNS6 && !name.indexOf('etPage')==0) ) sufix="_IE";
		else
		if(this.isNS) sufix="_NS";
		m=eval("window.__Cross_"+name+sufix);
		if(!m) m=eval("window.__Cross_"+name); 	
		if(!m) m=new Function('return false;');
	}
	return m;	
}
// copia propiedades y metodos de un objeto
function __Cross_acquire(obj) {
	if(obj!=null)
		for(var i in obj) this[i]=obj[i];
}
function __Cross_getTag(name) {
 var tag;
	if(this.isDOM) {
		tag=document.getElementById(name);
	}
	else
	if(this.isIE) {
		tag=document.all(name);
	}
	else
	if(this.isNS) {		
		tag=eval("document."+name);
	}
	return tag;				
}
function __Cross_setStyle(tag,cssStr) {
 	if(tag && tag.style) {
		if(!this.isIE && this.isDOM && tag.setAttribute) {
			tag.setAttribute("style",cssStr);
		}else tag.style.cssText=cssStr;
	}
}
function __Cross_addEventListener(tag,eventName,func,capture) {
	if(tag) {
		eventName=eventName.toLowerCase();
		if(this.isDOM) {
			 if(this.isIE) {
				if(tag.attachEvent) {
					tag.attachEvent("on"+eventName,func);
					return true;
				}
			 }
			 else
			 if(tag.addEventListener) {
				tag.addEventListener(eventName,func,capture);
				return true;
			 }
		}
		if(!eval("tag.on"+eventName)) {
			if(this.isNS4 && capture) {
				tag.captureEvents(eval("Event."+eventName.toUpperCase()));
			}
			eval("tag.on"+eventName+"=func");
			return true;		
		}
	}
	return false;
}
function __Cross_removeEventListener(tag,eventName,func,capture) {
	if(tag) {
		eventName=eventName.toLowerCase();
		if(this.isDOM) {
			 if(this.isIE) {
				if(tag.detachEvent) {
					tag.detachEvent("on"+eventName,func);
					return true;
				}
			 }
			 else
			 if(tag.removeEventListener) {
				tag.removeEventListener(eventName,func,capture);
				return true;
			 }
		}
		if(this.isNS4 && capture) {
			tag.releaseEvents(eval("Event."+eventName.toUpperCase()));
		}
		eval("tag.on"+eventName+"=null");
		return true;		
	}
	return false;
}
function __Cross_alertObject(obj,newWindow,functions,maxLines) {
	if(obj) {
		var s="";
		var line=0;
		for(var x in obj) {
			var iS=null;
			if(functions==true || typeof(obj[x])!="function") {
				iS=obj[x]+"";	
			}
			else {
				if(functions!=false && functions==null)
					iS="function() {}";
			}
			if(iS) {
				s+="["+x+"]: "+iS+"\n";
				// paginacion
				line++;
				if(!newWindow && line>maxLines) {
					line=0;
					alert(s);
					s="";
				}
			}
		}
		if(s!="") {
			if(newWindow) {
				window.open().document.write(s);
			}
			else {
				alert(s);
			}
		}
	}
	else alert(obj);
}
function __Cross_alertForm(frm,newWindow,maxLines) {
	if(frm && frm.elements && frm.elements.length) {
		var s="";
		var line=0;
		for(var i=0;i<frm.elements.length;i++) {
			s+="["+frm.elements[i].name+"]: "+frm.elements[i].value+"\n";
			// paginacion
			line++;
			if(!newWindow && line>maxLines) {
				line=0;
				alert(s);
				s="";
			}
		}
		if(s!="") {
			if(newWindow) {
				window.open().document.write(s);
			}
			else {
				alert(s);
			}
		}
	}
	else alert(frm);
}
function __Cross_setInnerHTML(tag,content) {
	if(tag) {
		if(this.isDOM || this.isIE4) {
			if(this.isIE || this.isGecko || tag.innerHTML!=null) {
				tag.innerHTML=content;
			}
			else {// pure DOM by Rey Nunez
				var rng=document.createRange();
				var html=rng.createContextualFragment(content);
				while (tag.hasChildNodes()) {
					tag.removeChild(tag.lastChild);
				}
				tag.appendChild(html);				
			}
			return true;
		}
		else if(this.isNS4) {
			tag.document.write(content);
			tag.document.close();
		}
	}	
	return false;
}
function __Cross_checkCreateLayer() {
	if(this.isDOM || this.isIE4 || this.isGecko) return true;
	if(this.isNS4) { // en NS4 no existe new Layer hasta onload
		
		return true; // FIX ME
	}
	return false;
}

////////////////
function __Cross_setPosicion_IE(tag,x,y,z) {
	if(tag) {
		var s=tag.style;
		if(s) {
			if(x!=null && !isNaN(x)) s.left=x+'px';
			if(y!=null && !isNaN(y)) s.top=y+'px';
			if(z!=null && !isNaN(z)) s.zIndex=z;	
			return true;
		}
	}
	return false;
}
function __Cross_setPosicion_NS(tag,x,y,z) {
	if(tag) {
		if(!isNaN(z)) tag.zIndex=z;	
		if(tag.moveTo && (!isNaN(x) || !isNaN(y))) {
			tag.moveTo( (!isNaN(x))?x:this.getX(tag),
					(!isNaN(y))?y:this.getY(tag));
			return true;
		}
	}
	return false;
}
////////////////
function __Cross_getX_DOM(tag) {
	if(tag && tag.style) {
		var p=parseInt(tag.style.left);
		return p!=''?p:null;
	}
	return null;
}	
function __Cross_getX_IE(tag) {
	if(tag && tag.style) return tag.style.pixelLeft;
	return null;
}	
function __Cross_getX_NS(tag) {
	if(tag && tag.left) return tag.left;
	return null;
}	
////////////////
function __Cross_getY_DOM(tag) {
	if(tag && tag.style) {
		var p=parseInt(tag.style.top);
		return p!=''?p:null;
	}
	return null;
}	
function __Cross_getY_IE(tag) {
	if(tag && tag.style) return tag.style.pixelTop;
	return null;
}	
function __Cross_getY_NS(tag) {
	if(tag && tag.top) return tag.top;
	return null;
}	
////////////////
function __Cross_getZ_IE(tag) {
	if(tag && tag.style) return tag.style.zIndex;
	return null;
}	
function __Cross_getZ_NS(tag) {
	if(tag && tag.zIndex) return tag.zIndex;
	return null;
}	
////////////////
function __Cross_setSize_DOM(tag,w,h) {
	if(tag && tag.style) {
		if(w!=null && !isNaN(w)) tag.style.width=w+"px";
		if(h!=null && !isNaN(h)) tag.style.height=h+"px";
		return true;
	}
	return false;
}
function __Cross_setSize_IE(tag,w,h) {
	if(tag && tag.style) {
		if(w!=null && !isNaN(w)) tag.style.pixelWidth=w;
		if(h!=null && !isNaN(h)) tag.style.pixelHeight=h;
		return true;
	}
	return false;
}
function __Cross_setSize_NS(tag,w,h) {
	if(tag && tag.resizeTo) {
		tag.resizeTo(!(isNaN(w))?w:this.getWidth(tag),
					 (!isNaN(h))?h:this.getHeight(tag));
		return true;
	}
	return false;
}
////////////////
function __Cross_getWidth_DOM(tag) {
	if(tag && tag.style) {
		var p=parseInt(tag.style.width);
		return p!=''?p:null;
	}
	return null;
}	
function __Cross_getWidth_IE(tag) {
	if(tag && tag.style) return tag.style.pixelWidth;
	return null;
}	
function __Cross_getWidth_NS(tag) {
	if(tag && tag.clip) return tag.clip.width;
	return null;
}	
////////////////
function __Cross_getHeight_DOM(tag) {
	if(tag && tag.style) {
		var p=parseInt(tag.style.height);
		return p!=''?p:null;
	}
	return null;
}	
function __Cross_getHeight_IE(tag) {
	if(tag && tag.style) return tag.style.pixelHeight;
	return null;
}	
function __Cross_getHeight_NS(tag) {
	if(tag && tag.clip) return tag.clip.height;
	return null;
}	
////////////////
function __Cross_setVisibility_IE(tag,visible) {
	if(tag) {
		var s=tag.style;
		if(s) {
			s.visibility=(visible)?"visible":"hidden";	
			return true;
		}
	}
	return false;
}	
function __Cross_setVisibility_NS(tag,visible) {
	if(tag && tag.visibility) {
		tag.visibility=(visible)?"show":"hide";	
		return true;
	}
	return false;
}	
////////////////
function __Cross_setBgColor_IE(tag,bgColor) {
	if(tag && tag.style) {
		tag.style.background=bgColor
		return true;
	}
	return false;
}	
function __Cross_setBgColor_NS(tag,bgColor) {
	if(tag) {
		tag.bgColor=bgColor;
		return true;
	}
	return false;
}	
////////////////
function __Cross_setPageX_IE(x) {
	if(document.body) document.body.scrollLeft=x;
}	
function __Cross_setPageX_NS(x) {
	if(window) window.pageXOffset=x;
}	
////////////////
function __Cross_setPageY_IE(y) {
	if(document.body) document.body.scrollTop=y;
}	
function __Cross_setPageY_NS(y) {
	if(window) window.pageYOffset=y;
}	
////////////////
function __Cross_getPageX_IE() {
	if(document.body) return document.body.scrollLeft;
	return null;
}	
function __Cross_getPageX_NS() {
	if(window) return window.pageXOffset
	return null;
}	
////////////////
function __Cross_getPageY_IE() {
	if(document.body) return document.body.scrollTop;
	return null;
}	
function __Cross_getPageY_NS() {
	if(window) return window.pageYOffset
	return null;
}	
////////////////
function __Cross_getPageWidth_IE() {
	if(document.body) return document.body.clientWidth;
	return null;
}	
function __Cross_getPageWidth_NS() {
	if(window) return window.innerWidth
	return null;
}	
////////////////
function __Cross_getPageHeight_IE() {
	if(document.body) return document.body.clientHeight;
	return null;
}	
function __Cross_getPageHeight_NS() {
	if(window) return window.innerHeight
	return null;
}		
	



//////////
function __Cross_document_Class(c) { // private and static
	this.X=0;
	this.Y=0;
	this.clickX=0;
	this.clickY=0;
	this.keyCode=0;
	this.handleDocumentEvent=__Cross_HandleDocumentEvent;
	this.handleDocumentEvent(c,"mousedown");
	this.handleDocumentEvent(c,"mousemove");
	this.handleDocumentEvent(c,"keydown");
}

function __Cross_HandleDocumentEvent(c,eventName) {
	if(!eventName) return;
	eventName=eventName.toLowerCase();
	eval("this.on"+eventName+"Handlers=new Array()");
	var f;
	f=new Function(
			"for(var i=0;i<this.on"+eventName+"Handlers.length;i++) {\n"+
			"	if(this.on"+eventName+"Handlers[i])\n"+
			"		this.on"+eventName+"Handlers[i](this);\n"+
			"}\n"
	);
	eval("this.on"+eventName+"Handler=f");
	f=new Function(
			"var func=arguments[0];\n"+
			"var i=0;\n"+
			"var done=false;\n"+
			"while(i<this.on"+eventName+"Handlers.length && !done) {\n"+
			"	if(!this.on"+eventName+"Handlers[i]) {\n"+
			"		done=true;\n"+
			"	}else i++;\n"+
			"}\n"+
			"this.on"+eventName+"Handlers[i]=func;\n"+
			"return(i);"
	);
	eval("this.on"+eventName+"Set=f");
	f=new Function(
			"var i=arguments[0];"+
			"if(i!=null && this.on"+eventName+"Handlers[i])"+
			"	this.on"+eventName+"Handlers[i]=null;"
	);
	eval("this.on"+eventName+"Clear=f");

	var sufix="";
	if(c.isNS) {
		sufix="_NS";
	}else {
		sufix="_IE";
	}
	c.addEventListener(document,eventName,
							eval("__Cross_on"+eventName+sufix),true);
}


function __Cross_onmousedown_IE() {
 var t=__Cross.onDocument;
	t.clickX=document.body.scrollLeft+window.event.clientX;
	t.clickY=document.body.scrollTop+window.event.clientY;
	t.onmousedownHandler();
}
function __Cross_onmousedown_NS(eventNS) {
 var t=__Cross.onDocument;
	t.clickX=eventNS.pageX;
	t.clickY=eventNS.pageY;
	t.onmousedownHandler();
	routeEvent(eventNS);
}
function __Cross_onmousemove_IE() {
 var t=__Cross.onDocument;
	t.X=document.body.scrollLeft+window.event.clientX;
	t.Y=document.body.scrollTop+window.event.clientY;
	t.onmousemoveHandler();
}
function __Cross_onmousemove_NS(eventNS) {
 var t=__Cross.onDocument;
 	t.X=eventNS.pageX;
	t.Y=eventNS.pageY;
	t.onmousemoveHandler();
	routeEvent(eventNS);
}
function __Cross_onkeydown_IE() {
 var t=__Cross.onDocument;
	t.keyCode=window.event.keyCode;
	t.onmousemoveHandler();
}
function __Cross_onkeydown_NS(eventNS) {
 var t=__Cross.onDocument;
	t.keyCode=eventNS.which;
	t.onmousemoveHandler();
	routeEvent(eventNS);
}

if(!window.__Cross) {
	var __Cross=new __Cross_Class(); // unico objeto please :p
}
