//
// Popper
//

isIE4 = document.all? true : false;
isIE6 = document.getElementById && document.all ? true : false;
isNS4 = document.layers? true : false;
isNS6 = document.getElementById && !document.all ? true : false;
var POPPER_CONTAINER_PREFIX = "POPPER_CONTAINER";
var POPPER_CONTENTCONTAINER_PREFIX = "POPPER_CONTENTCONTAINER";
var Popper_idGenerator = new IDGenerator(0);
var PopperMap = new Object();
var PopperIDGenerator = null;

function IDGenerator(nextID){
	this.nextID = nextID;
	this.GenerateID = IDGeneratorGenerateID;
}
function IDGeneratorGenerateID(){
	return this.nextID++;
}
function Popper(contentContainer, positionReferenceObject, popperTitle, popperType, width, height){
	this.idGenerator = Popper_idGenerator;
	this.instantiated = false;
	this.width = 200;
	this.height = 200;
	this.top = 0;
	this.left=0;
	this.title = "Popup";
	this.popperType = 1;
	this.contentContainer = contentContainer;
	this.positionReferenceObject = positionReferenceObject;
	this.borderColour = "#0066CC";
	this.textCSS = "font: normal normal normal 11px verdana; color: #FFFFFF";
	this.backgroundColour = "#FFFFFF";
	this.contentString = "";
	if (popperTitle)this.title = popperTitle;
	if (width)this.width = width;
	if (height)this.height = height;
	if (popperType)this.popperType = popperType;
//Functions
	this.Instantiate = Popper_Intantiate;
	this.initContainerRefs = Popper_InitContainerRefs;
	this.initMouseEvents = Popper_InitMouseEvents;
	this.setCSSAtrribs = Popper_SetCSSAtrribs;
}
function Popper_SetCSSAtrribs(screenItem, cssValue){

}
function Popper_Intantiate(){
	if (this.instantiated) return;
	this.id = this.idGenerator.GenerateID();
	PopperMap[this.id] = this;
	PopperIDGenerator = this.idGenerator;
	this.initContainerRefs();
	var html = "";
	html += "<DIV ID='" + POPPER_CONTAINER_PREFIX + this.id +"' NAME='" + POPPER_CONTAINER_PREFIX + this.id +"' STYLE='position:absolute; border:1px solid " + this.borderColour + "; top: "+this.top+"px; left: "+this.left+"px; width:"+this.width+"px;  display:none; background-color:#FFFFFF;";
	if (this.popperType == 1 || this.popperType == 2){
		html += " overflow:visible;";
	}else{
		html += " height:"+this.height+"px; overflow:hidden;";
	}
	html += "'>";
	html += "<TABLE " + (this.popperType == 1 || this.popperType == 2 ? "" : "height='" + eval(this.height)) + "'  width='100%' cellpadding=0 cellspacing=0 border=0 style=''>";
//Barra del titulo
	if (this.popperType != 1){
		html += "<TR bgcolor='" + this.borderColour + "'><TD height='20' width='100%' style='"+this.textCSS+"'>" +this.title+ "</TD><TD width='20'>";
		if (this.popperType != 2){
			html += "<a href='javascript:Popper_HidePopper("+this.id+"); void(0);' style='"+this.textCSS+"; text-decoration:none'><b>X</b></a>";
		}
		html += "</TD></TR>";
	}
//Contenido de la celda
	html += "<TR><TD " + (this.popperType == 1 || this.popperType == 2 ? "" : "height='" + eval(this.height - 20)) + "' colspan=2 valign=top align=left><DIV ID='" + POPPER_CONTENTCONTAINER_PREFIX + this.id +"' NAME='" + POPPER_CONTENTCONTAINER_PREFIX + this.id +"' " ;
	if (this.popperType == 1 || this.popperType == 2){
		html += " STYLE='overflow:visible;";
	}else{
		html += " STYLE='overflow:auto;";
		html += " height:" +eval(this.height - 20)+ "px;";
	}
	html += " width:100%;'> " + this.contentString + "</DIV></TD></TR>";
	html += "</TABLE>";
	html += "</DIV>";
	document.write(html);
	this.instantiated = true;
}

function Popper_InitContainerRefs(){
	if (isIE4){
		this.contentString = String(document.all[this.contentContainer].innerHTML);
		document.all[this.contentContainer].style.display = 'none';
		this.initMouseEvents(document.all[this.positionReferenceObject]);
	}else if(isIE6){
		this.contentString = String(document.getElementById(this.contentContainer).innerHTML);
		document.getElementById(this.contentContainer).style.display = 'none';
		this.initMouseEvents(document.getElementById(this.positionReferenceObject));
	}else if (isNS4){
		this.contentString = String(document.layers[this.contentContainer].innerHTML);
		document.layers[this.contentContainer].style.display = 'none';
		this.initMouseEvents(document.layers[this.positionReferenceObject]);
	}else if (isNS6) {
		this.contentString = String(document.getElementById(this.contentContainer).innerHTML);
		document.getElementById(this.contentContainer).style.display = 'none';
		this.initMouseEvents(document.getElementById(this.positionReferenceObject));
	}
}
function Popper_InitMouseEvents(thisElement){
	var showString = "Popper_ShowPopper("+this.id+")";
	var hideString = "Popper_HidePopper("+this.id+")";
	try{
		switch (this.popperType){
			case 1: 
				thisElement.onmouseover =  function () {eval(showString);return true;};
				thisElement.onmouseout =  function () {eval(hideString);return true;};
				break;
			case 2: 
				thisElement.onmouseover =  function () {eval(showString);return true;};
				thisElement.onmouseout =  function () {eval(hideString);return true;};
				break;
			case 3: 
				thisElement.onmousedown =  function () {eval(showString);return true;};
				break;
			case 4: 
				thisElement.onclick =  function () {eval(showString);return true;};
				break;
			case 5: 
				thisElement.ondblclick =  function () {eval(showString);return true;};
				break;
			default:
				thisElement.onmouseover =  function () {eval(showString);return true;};
				thisElement.onmouseout =  function () {eval(hideString);return true;};
		}
	}
	catch (e){
		alert (thisElement);
		var thisNodeText = "<SPAN id='"+this.positionReferenceObject+"_NEW_POPPER_NODE' name='"+this.positionReferenceObject+"_NEW_POPPER_NODE'>";
		thisNodeText += thisElement.innerHTML;
		thisNodeText += "</SPAN>";
		thisElement.innerHTML = thisNodeText;
		this.positionReferenceObject += "_NEW_POPPER_NODE";
		if (isIE4){
			thisElement = document.all[this.positionReferenceObject];
		}else if(isIE6){
			thisElement = document.getElementById(this.positionReferenceObject);
		}else if (isNS4){
			thisElement = document.layers[this.positionReferenceObject];
		}else if (isNS6) {
			thisElement = document.getElementById(this.positionReferenceObject);
		}
		switch (this.popperType){
			case 1: 
				thisElement.onmouseover =  function () {eval(showString);return true;};
				thisElement.onmouseout =  function () {eval(hideString);return true;};
				break;
			case 2: 
				thisElement.onmouseover =  function () {eval(showString);return true;};
				thisElement.onmouseout =  function () {eval(hideString);return true;};
				break;
			case 3: 
				thisElement.onmousedown =  function () {eval(showString);return true;};
				break;
			case 4: 
				thisElement.onclick =  function () {eval(showString);return true;};
				break;
			case 5: 
				thisElement.ondblclick =  function () {eval(showString);return true;};
				break;
			default:
				thisElement.onmouseover =  function () {eval(showString);return true;};
				thisElement.onmouseout =  function () {eval(hideString);return true;};
		}
	}
}
function Popper_ShowPopper(id){
	if (!PopperMap[id].instantiated)return;
	Popper_HideAllPoppers();
	if (isIE4){
		PopperMap[id].left = Popper_retrieveTotalOffsetLeft(document.all[PopperMap[id].positionReferenceObject] )+ document.all[PopperMap[id].positionReferenceObject].offsetWidth;
		PopperMap[id].top = Popper_retrieveTotalOffsetTop(document.all[PopperMap[id].positionReferenceObject] );
		document.all[POPPER_CONTAINER_PREFIX + id].style.display = 'inline';
		document.all[POPPER_CONTAINER_PREFIX + id].style.top = PopperMap[id].top;
		document.all[POPPER_CONTAINER_PREFIX + id].style.left = PopperMap[id].left;
	}else if(isIE6){
		PopperMap[id].left = Popper_retrieveTotalOffsetLeft(document.getElementById(PopperMap[id].positionReferenceObject))+ document.getElementById(PopperMap[id].positionReferenceObject).offsetWidth;
		PopperMap[id].top = Popper_retrieveTotalOffsetTop(document.getElementById(PopperMap[id].positionReferenceObject));
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.display = 'inline';
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.top = PopperMap[id].top;
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.left = PopperMap[id].left;
	}else if (isNS4){
		PopperMap[id].left = Popper_retrieveTotalOffsetLeftNN(document.layers[PopperMap[id].positionReferenceObject])+ document.layers[PopperMap[id].positionReferenceObject].offsetWidth;
		PopperMap[id].top = Popper_retrieveTotalOffsetTopNN(document.layers[PopperMap[id].positionReferenceObject]);
		document.layers[POPPER_CONTAINER_PREFIX + id].style.display = 'inline';
		document.layers[POPPER_CONTAINER_PREFIX + id].style.top = PopperMap[id].top;
		document.layers[POPPER_CONTAINER_PREFIX + id].style.left = PopperMap[id].left;
	}else if (isNS6) {
		PopperMap[id].left = Popper_retrieveTotalOffsetLeftNN(document.getElementById(PopperMap[id].positionReferenceObject)) + document.getElementById(PopperMap[id].positionReferenceObject).offsetWidth;
		PopperMap[id].top = Popper_retrieveTotalOffsetTopNN(document.getElementById(PopperMap[id].positionReferenceObject));
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.display = 'inline';
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.top = PopperMap[id].top;
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.left = PopperMap[id].left;
	}
	
}
function Popper_HideAllPoppers(){
	if (PopperMap == null) return;
	for (var i in PopperMap){
		Popper_HidePopper(i);
	}
}
function Popper_HidePopper(id){
	if (!PopperMap[id].instantiated)return;
	if (isIE4){
		document.all[POPPER_CONTAINER_PREFIX + id].style.display = 'none';
	}else if(isIE6){
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.display = 'none';
	}else if (isNS4){
		document.layers[POPPER_CONTAINER_PREFIX + id].style.display = 'none';
	}else if (isNS6) {
		document.getElementById(POPPER_CONTAINER_PREFIX + id).style.display = 'none';
	}
}
function Popper_retrieveTotalOffsetLeft(thisElement){
	if (thisElement == null || thisElement == document.body)return 0;
	return thisElement.offsetLeft + Popper_retrieveTotalOffsetLeft(thisElement.offsetParent);
}
function Popper_retrieveTotalOffsetTop(thisElement){
	if (thisElement == null || thisElement == document.body)return 0;
	return thisElement.offsetTop + Popper_retrieveTotalOffsetTop(thisElement.offsetParent);
}
function Popper_retrieveTotalOffsetLeftNN(thisElement){
	if (isNS4) return thisElement.x;
	if (thisElement == null || thisElement == document.body)return 0;
	return thisElement.offsetLeft + Popper_retrieveTotalOffsetLeft(thisElement.offsetParent);
}
function Popper_retrieveTotalOffsetTopNN(thisElement){
	if (isNS4) return thisElement.y;
	if (thisElement == null || thisElement == document.body)return 0;
	return thisElement.offsetTop + Popper_retrieveTotalOffsetTop(thisElement.offsetParent);
}
