

var pickControl = null;
var idControl = null;

function showBox(objID, width, height, url) 
{
	  /* soporte para lightbox */
	  var overlay = document.getElementById('_overlay');
	  if (overlay==null) {
	  	overlay = document.createElement("div");
	  	overlay.className = "overlay";
	  	//si altura del scroll no es 900 asumir el 100%
	  	if(document.body.scrollHeight < 900)
	  		overlay.style.height = '100%';
	  	else
	  		overlay.style.height = document.body.scrollHeight + 'px';
	  	overlay.setAttribute("id", "_overlay");
	  	document.body.appendChild(overlay);
	  } else {
		//si altura del scroll no es 900 asumir el 100%
		if(document.body.scrollHeight < 900)
			overlay.style.height = '100%';
		else
			overlay.style.height = document.body.scrollHeight + 'px';
	  }
	  /* ---- */


	/* 
	NOTE:
	Original author: JTricks.com :: http://www.jtricks.com/ 
	*/

	var obj = document.getElementById(objID);        
	var newID = objID + "_popup";        
	var borderStyle = "#9d9d9d 1px solid"
	var boxdiv = document.getElementById(newID);
	
	  if (boxdiv != null) {
	  
		  /* soporte para lightbox */
		  overlay.style.display='block'
		  boxdiv.style.zIndex = 1002;
		  /* ---- */
	  
	    if (boxdiv.style.display=='none') {
	    	if (url!=null) 
	    	{
	    		var f = window.frames[objID + "_iframe"];
	    		f.document.open();
    			f.document.write("<center>");
    			f.document.write("<br><br>");
    			f.document.write("<img src='${def:context}/imagenes/anim.gif'>");
	    		f.document.write("<span style='padding-left:10px;font-family:Arial;font-size:9pt;font-weight:normal'>Cargando...</span>");
    			f.document.write("</center>");
	    		f.document.close();
	      		f.location = url;
	      	}
	      moveBox(obj, boxdiv);
	      boxdiv.style.display='block';
	    } else
	      boxdiv.style.display='none';
	    return false;
	  }
	
	  boxdiv = document.createElement('div');
	  boxdiv.setAttribute('id', newID);
	  boxdiv.style.display = 'none';
	  boxdiv.style.position = 'absolute';
	  boxdiv.style.width = width + 'px';
	  boxdiv.style.height = height + 'px';
	  boxdiv.style.border = borderStyle;
	  boxdiv.style.backgroundColor = '#F7F7F7';
	  boxdiv.style.padding = "0px";
	
	  var contents = document.createElement('iframe');
	  contents.scrolling = 'auto';
	  contents.frameBorder = '0';
	  contents.style.width = width + 'px';
	  contents.style.height = height + 'px';
	  contents.marginHeight = 0;
	  contents.marginWidth = 0;
	  contents.setAttribute('id', objID + "_iframe");
	  contents.setAttribute('name', objID + "_iframe");
	  
	  boxdiv.appendChild(contents);
	  document.body.appendChild(boxdiv);

	  if (url!=null) {
	  		var f = window.frames[objID + "_iframe"];
			f.document.open();
			f.document.write("<center>");
			f.document.write("<br><br>");
                        f.document.write("<img src='./imagenes/anim.gif' alt=''>");
			f.document.write("<span style='padding-left:10px;font-family:Arial;font-size:9pt;font-weight:bold'>Cargando...</span>");
			f.document.write("</center>");
			f.document.close();
			f.location = url;
	  }

	  /* soporte para lightbox */
	  overlay.style.display='block'
	  boxdiv.style.zIndex = 1002;
	  /* ---- */
	  
	  moveBox(obj, boxdiv);
	  boxdiv.style.display = 'block';
	  
	  return false;
	  
}	

function moveBox(element, box) 
{

	/* 
	NOTE:
	Original author: JTricks.com :: http://www.jtricks.com/ 
	*/

	var offset = 3;
    var cleft = 0;
	var ctop = 0;
	var obj = element;
	  while (obj.offsetParent) {
	    cleft += obj.offsetLeft/2;
	    ctop += obj.offsetTop/2-200;
	    obj = obj.offsetParent;
	  }
	  box.style.left = cleft + 'px';
	  ctop += element.offsetHeight + offset;
	  if (document.body.currentStyle &&
	    document.body.currentStyle['marginTop']) {
	    ctop += parseInt(
	      document.body.currentStyle['marginTop']);
	  }
	  box.style.top = ctop + 'px';

}

/**
* Esconde un DIV + IFRAME abierto con la
* funci?n showBox()
*/

function closeBox(objID)
{
	var obj = document.getElementById(objID);
	if (!obj.readonly)
		obj.focus();
		
	var strDiv = objID + "_popup";        
        document.getElementById(objID + "_popup").style.display = "none";
	
	/* soporte para lightbox */
	var overlay = document.getElementById('_overlay')
	if (overlay!=null)
		overlay.style.display='none';
	
}


function pickOpen(id, idCtl, url, ancho, altura)
{	
	if (pickControl!=null) pickClose();
			
	//verifica si existe el textbox
	var obj = document.getElementById(id);
	if (obj==null) {
		alert("ERROR (pickOpen): no existe un elemento con ID: " + id);
		return;			
	}

	pickControl = id;
	idControl = idCtl;
	
	//mostrar popup dhtml
	showBox(pickControl, ancho, altura, url);
}			

function pickClose()
{
	closeBox(pickControl);
	idControl = null;
	pickControl = null;
}

function alternarHelp(){

    var div = document.getElementById('btn_verAyuda');

    if (div.value == "Click para cerrar"){
        cerrarHelp();
    }else{
        mostrarHelp();
    }
}

function mostrarHelp() {
    var div = document.getElementById('flotante');
    div.style.display = '';
    div = document.getElementById('btn_verAyuda');
    div.value = "Click para cerrar"

}

function cerrarHelp() {
    var div = document.getElementById('flotante');
    div.style.display='none';
    div = document.getElementById('btn_verAyuda');
    div.value = "Ver mapa"
}


