/*	API DE GENERACION DINAMICA DE LAYERS. POR CARLOS HURTADO
*	funciones:

*	ContentLayer(initial,i,type,content,width,height,link,align,FGCOLOR,BGCOLOR,opacity,left,top)
*	-------------------------------
*	utilidad: genera un Layer con contenido sobre el mapa.}
*	-----------------------------
*	-initial, indice -> genera un nombre de layer (ej: nombre="tt", indice=1 => layer de nombre "tt1")
*	-type		->define contenido: 'texto' 'imagen' 'flash'
*	-content	->si tipo='texto' contenido es texto (o HTML)
*				->si tipo='imagen' contenido es url de imagen
*				->si tipo='flash' contenido es url de flash
*	-width, height -> ancho y alto de contenido. (importante para centrar)
*	-link		->link a pagina web c/r empresa
*	-align		-> 'LT','CT','RT','LM','CM','RM','LB','CB','RB' (posiciones: left top, center top, right top, left middle, etc...)
*	-FGCOLOR	-> color texto de layer de texto
*	-BGCOLOR	-> color fondo de layer de texto
*	-opacity	-> numero de 0 a 1 (double) define la opacidad del layer
*	-left,top -> coordenadas de posicion del layer (c/r a Mapa) en pixeles
*
*    ToolTip2(initial,i,left,top,radio,content)
*	-------------------------------
*	utilidad: genera un area en el mapa con capacidad de generar un tooltip
*	-------------------------------
*	-initial	-> nombre del area
*	-i			-> no necesario
*	-left, top	-> coordenadas de posicion del area (c/r a Mapa) en pixeles
*	-radio		-> radio de circulo de area
*	-content	-> contenido del tooltip (  "  no son permitidas)
*
*	destroyAll()
*  ----------------------------------
*	destruye todos los elementos dinamicos (tooltips y contentlayers).
*	necesario al hacer cambios en el mapa (recarga, etc)
*	se podria optimizar el funcionamiento, no activandolo cuando se hagan cambios sobre el mapa
*	que no requiera cambio de posicion y escala (consultar punto, consultar calle)
*
*
**/
//variables para lockear cursores//
var lockcursor=0;
var oldcursor="";
var pub_array=new Array();
var ua = navigator.userAgent.toLowerCase();
function getNavegador()
{
	  if (ua.indexOf('opera')!=-1) { // Opera (check first in case of spoof)
		 return 'opera';
	  } else if (ua.indexOf('msie 7')!=-1) { // IE7
		 return 'ie7';
	  } else if (ua.indexOf('msie') !=-1) { // IE
		 return 'ie';
	  } else if (ua.indexOf('safari')!=-1) { // Safari (check before Gecko because it includes "like Gecko")
		 return 'safari';
	  } else if (ua.indexOf('gecko') != -1) { // Gecko
		 return 'gecko';
	  } else {
		 return false;
	  }
}
var navegador = getNavegador();
var manito = (navegador=='gecko')?'pointer':'hand';


/*permite compatibilizar con firefox la creacion dinamica de elementos*/
function prototipear()
{
	if( typeof HTMLElement!="undefined"
			&&
		  !HTMLElement.prototype.insertAdjacentElement
		)
	{
		//define funcion insertAdjacentElement
	   HTMLElement.prototype.insertAdjacentElement =
	   function(where,parsedNode)
		 {
				switch (where)
				{
					case 'beforeBegin':
						this.parentNode.insertBefore(parsedNode,this)
						break;
					case 'afterBegin':
						this.insertBefore(parsedNode,this.firstChild);
						break;
					case 'beforeEnd':
						this.appendChild(parsedNode);
						break;
					case 'afterEnd':
						if (this.nextSibling)
							this.parentNode.insertBefore(parsedNode,this.nextSibling);
						else
							this.parentNode.appendChild(parsedNode);
					break;
				}
	  }
	  //define funcion insertAdjacentHTML
		HTMLElement.prototype.insertAdjacentHTML =
		function(where,htmlStr)
	  {
			var r = this.ownerDocument.createRange();
			r.setStartBefore(this);
			var parsedHTML = r.createContextualFragment(htmlStr);
			this.insertAdjacentElement(where,parsedHTML)
		}
		//define funcion insertAdjacentText
		HTMLElement.prototype.insertAdjacentText =
		function(where,txtStr)
		{
			var parsedText = document.createTextNode(txtStr)
			this.insertAdjacentElement(where,parsedText)
		}
	}
}

prototipear();

//definicion de nombre de capa de publicidad//
//si se necesitan mas capas de otras cosas definir mas capas//
var pubLayer='dchild';
var maparea='main_area';


//cambia el cursor en mouseover (en tooltip)
function MostrarTooltip()
{
	lockcursor=1;
	oldcursor=cursorStyle;
	SetCursorAccion('3dohelp.ani');
}

//cambiar el cursor en mouseout al original
function OcultarTooltip(){
	if(lockcursor==1){
		SetCursorAccion(oldcursor);
	}
	lockcursor=0;
}

//crea un objeto area nuevo antes del final del objeto map de id son
function new_Area(name,left,top,radio,content,son,mclk)
{
	var html='<AREA id="'+name+'" ';
	html +='name="'+name+'" ';
	html +='alt="'+content+'" ';
	html +='title="'+content+'" ';
	html +='shape="circle" ';
	html +='onmouseover="javascript:MostrarTooltip();" ';
	html +='onMouseOut="javascript:OcultarTooltip();" ';
	html +='coords="'+left+','+top+','+radio+'" ';
	if(mclk!="")
	html +='onclick="'+mclk+'" ';
	html +='>';
	document.getElementById(son).insertAdjacentHTML('beforeEnd',html);

}


//crea un layer en la posicion dada, con contenido content, antes del final del objeto son
// si son es 'body' lo inserta al final del cuerpo
//movr, mout, mclk son posibilidades extras para el layer
//usar como parametro por ejemplo movr="onMouseOver='algo();'"
function new_Layer(name,left,top,content,movr,mout,mclk,z,son)
{

  var html='<DIV id="'+name+'" ';
  html += ' STYLE="position: absolute;';
  html += ' left: '+left+'px; top: '+top+'px;';
  html += ' z-index:'+z+';';
  html += ' visibility: visible;';
  html += '" ';
  html += movr;
  html += " ";
  html += mout;
  html += " ";
  html += mclk;
  html += ' >';
  html += content;
  html += '<\/DIV>';
  if(son=='body'){
		document.body.insertAdjacentHTML('beforeEnd',html);
  }
  else{
		document.getElementById(son).insertAdjacentHTML('beforeEnd',html);
  }

}


//funcion flash_content, genera el contenido necesario para insertar flashs transparentes

function flash_content(content,width,height)
{
	var html='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"';
	html += ' width="'+width+'" ';
	html += ' height="'+height+'" >';
	html += ' <param name="movie" value="'+content+'">';
	html += ' <param name="quality" value="high">';
	html +=	'<param name="wmode" value="transparent">';
	html += ' <embed src="'+content+'" ';
	html += ' quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
	html += ' width="'+width+'" ';
	html += ' height="'+height+'" wmode="transparent" >';
	html += '</embed></object>';
	return html;
}


/*estilo estandar para layers de texto*/
var style='tooltip_back';

/*****************************************************************************/
/*Modificado por Marcos Varela para la integración de tooltip a la publicidad*/
/*****************************************************************************/
var id_timeout;
function cerrar_tooltip(){
	if(document.getElementById('tooltip_publicidad')!=null){
		var div=document.getElementById('tooltip_publicidad');
		div.innerHTML = "";
		div.outerHTML = "";
		if(div.parentNode)
			div.parentNode.removeChild(div);	
	}
	clearTimeout(id_timeout);
}
function tooltip_publicidad(div,tooltip_left,tooltip_top,tooltip_titulo,tooltip_texto,tooltip_foto,tooltip_link){
	if(document.getElementById('tooltip_publicidad')!=null){
		var div=document.getElementById('tooltip_publicidad');
		div.innerHTML = "";
		div.outerHTML = "";
		if(div.parentNode)
			div.parentNode.removeChild(div);	
	}

	html='<div style="background=#FFFFFF;margin=0;padding=0;width=200px;">';
	html+='<table><tr><td align="right"><a href="javascript:return false;" onclick="cerrar_tooltip();">X</a></td></tr><tr><th>'+tooltip_titulo+'</th></tr><tr><td><img src="'+tooltip_foto+'"></td></tr><tr><td>'+tooltip_texto+'</td></tr><tr><td><a href="http://'+tooltip_link+'" target="_blank">'+tooltip_link+'</a></td></tr></table></div>';

	var ancho_pix=document.getElementById('ancho_pix').value;
	var alto_pix=document.getElementById('alto_pix').value;
	
	var pos_left;
	var pos_top;
	if (tooltip_left > (ancho_pix/2)){
		pos_left='0';
		pos_top='0';
	}else{
		pos_left=(ancho_pix - 200);
		pos_top='0';
	}
	oToolTip.innerHTML='';
	new_Layer('tooltip_publicidad',pos_left,pos_top,html,'','','',100,'oToolTip');
	oToolTip.style.display="block";
	id_timeout=setTimeout("cerrar_tooltip();",5000);
}
function ContentLayerPubLink(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo,tooltip,tooltip_titulo,tooltip_texto,tooltip_foto,tooltip_link)
{


	var name1=initial+""+i;
	var tt_content="";
	if(type.toLowerCase()=='imagen'){
		if(linker!='') tt_content	='<a href="'+linker+'">';
		tt_content				+='<img id="IMG_'+name1+'" src="'+content+'" border="0" title="'+titulo+'">';
		if(linker!='') tt_content	+='</a>';
	}

	if(type.toLowerCase()=='texto'){
		tt_content				='<table class="'+style+'"><tr>';
		tt_content				+='<td bgcolor="#'+BGCOLOR+'"><font color="#'+FGCOLOR+'">';
		tt_content				+= content;
		tt_content				+= '</font></td></tr></table>';
	}

	if(type.toLowerCase()=='flash'){
		tt_content				+=flash_content(content,width,height);
	}
	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));


	movr="";
	mout="";
	if(document.getElementById('tooltip_publicidad')!=null){
		var div=document.getElementById('tooltip_publicidad');
		div.innerHTML = "";
		div.outerHTML = "";
		if(div.parentNode)
			div.parentNode.removeChild(div);	
	}

	if(tooltip='SI'){
		mclk="onclick=\"tooltip_publicidad('"+name1+"','"+left2+"','"+top2+"','"+tooltip_titulo+"','"+tooltip_texto+"','"+tooltip_foto+"','"+tooltip_link+"');\"";
	}else{
		mclk="";
	}

	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,pubLayer);



	if(type.toLowerCase()!='flash'){
		ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
		dd.elements[name1].show();
		dd.elements[name1].setOpacity(opacity);
		dd.elements[name1].setZ(6);
		dd.elements[name1].moveBy(left2,top2);

	}
	else{
		pub_array[pub_array.length]=name1;
		document.getElementById(name1).style.left=left2+"px";
		document.getElementById(name1).style.top=top2+"px";
	}

	if(type.toLowerCase()=='imagen' && name1=='estrella1')
	{
		if(cursorStyle && cursorStyle.length>0)
			SetCursor(cursorStyle);
	}
}
/*****************************************************************************/
/***********************************Fin Modificación**************************/
/*****************************************************************************/



function ContentLayer(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo)
{

	var name1=initial+""+i;
	var tt_content="";
	if(type.toLowerCase()=='imagen'){
		if(linker!='') tt_content	='<a href="'+linker+'">';
		tt_content				+='<img id="IMG_'+name1+'" src="'+content+'" border="0" title="'+titulo+'">';
		if(linker!='') tt_content	+='</a>';
	}

	if(type.toLowerCase()=='texto'){
		tt_content				='<table class="'+style+'"><tr>';
		tt_content				+='<td bgcolor="#'+BGCOLOR+'"><font color="#'+FGCOLOR+'">';
		tt_content				+= content;
		tt_content				+= '</font></td></tr></table>';
	}

	if(type.toLowerCase()=='flash'){
		tt_content				+=flash_content(content,width,height);
	}

	movr="";
	mout="";
	mclk="";
	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,pubLayer);

	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));

	if(type.toLowerCase()!='flash'){
		ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
		dd.elements[name1].show();
		dd.elements[name1].setOpacity(opacity);
		dd.elements[name1].setZ(6);
		dd.elements[name1].moveBy(left2,top2);

	}
	else{
		pub_array[pub_array.length]=name1;
		document.getElementById(name1).style.left=left2+"px";
		document.getElementById(name1).style.top=top2+"px";
	}

	if(type.toLowerCase()=='imagen' && name1=='estrella1')
	{
		if(cursorStyle && cursorStyle.length>0)
			SetCursor(cursorStyle);
	}
}

function ContentLayerDialog(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo,visibilidad,posicion)
{
	var name1=initial+""+i;
	var tt_content="";
	if(type.toLowerCase()=='imagen'){
		if(linker!='') tt_content	='<a href="'+linker+'">';
		tt_content				+='<img src="'+content+'" border="0" title="'+titulo+'">';
		if(linker!='') tt_content	+='</a>';
	}
	if(type.toLowerCase()=='dialogo'){
		var wi = content.length*10;
		tt_content	=	'<table border="0" width="'+wi+'" align="center" cellpadding="0" cellspacing="0">';
		tt_content	+=	'<tr>';
		tt_content	+=	'<td width="17" valign="top"><img src="./images/api/izq_1.gif" width="17" height="8"></td>';
		tt_content	+=	'<td width="18" background="./images/api/centro_sup.gif"></td>';
		tt_content	+=	'<td width="18" background="./images/api/centro_sup.gif"></td>';
		tt_content	+=	'<td width="27" background="./images/api/centro_sup.gif"></td>';
		tt_content	+=	'<td valign="top"><img src="./images/api/der_1.gif" width="10" height="8"></td>';
		tt_content	+=	'</tr>';
		tt_content	+=	'<tr>';
		tt_content	+=	'<td valign="top"><img src="./images/api/izq_2.gif" width="17" height="15"></td>';
		tt_content	+=	'<td colspan="3" background="./images/api/fondo.gif"></td>';
		//tt_content	+= content;
		tt_content	+=	'<td><img src="./images/api/der_2.gif" width="10" height="15"></td>';
		tt_content	+=	'</tr>';
		tt_content	+=	'<tr>';
		tt_content	+=	'<td valign="top"><img src="./images/api/izq_3.gif" width="17" height="28"></td>';
		tt_content	+=	'<td valign="top" background="./images/api/centro_bajo.gif"><img src="./images/api/izq_33.gif" width="19" height="28"></td>';
		tt_content	+=	'<td valign="top" background="./images/api/centro_bajo.gif"></td>';
		tt_content	+=	'<td background="./images/api/centro_bajo.gif"></td>';
		tt_content	+=	'<td><img src="./images/api/der_3.gif" width="10" height="28"></td>';
		tt_content	+=	'</tr>';
		tt_content	+=	'</table>';
	}
	if(type.toLowerCase()=='texto'){
		tt_content				='<p>';
		tt_content				+='<font name="Verdana, Arial, Helvetica, sans-serif" size="1">';
		tt_content				+= content;
		tt_content				+= '</font>';
		tt_content				+= '</p>';
	}
	movr="";
	mout="";
	mclk="";
	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,pubLayer);

	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));
	if(type.toLowerCase()!='flash'){
		ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
		if (visibilidad)
			dd.elements[name1].show();
		else
			dd.elements[name1].hide();
		dd.elements[name1].setOpacity(opacity);
		dd.elements[name1].setZ(6);
		dd.elements[name1].moveBy(left2,top2);
	}
	else{
		pub_array[pub_array.length]=name1;
		document.getElementById(name1).style.left=left2+"px";
		document.getElementById(name1).style.top=top2+"px";
	}
}

/**
* Crea el layer 'foto'+i con el contenido
* de la primera imagen de la direccion indicada
**/
function LayerFoto(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo)
{
	//alert("LayerFoto="+initial);
	var name1=initial+""+i;
	var tt_content="";
	if(type.toLowerCase()=='imagen')
	{
		//alert('http://www.mapcity.com/leeimagen.asp?id=' + content + '&width=73&height=55');
		tt_content=''
		tt_content+='<table width="73" height="55" border="0" cellspacing="0" cellpadding="0">'
		tt_content+='<tr><td align="center" valign="middle">'
			tt_content+='<img name="SlideShow" border="0"'
				tt_content+=' src="http://maper2.mapcity.com/leeimagen.asp?id=' + content + '&width=73&height=55"'
				tt_content+=' onclick="javascript:VentanaFoto();"'
				tt_content+=' title="Ver Fotos de la direcci&oacute;n"'
				tt_content+=' style="cursor:'+manito+';">'
		tt_content+='</td></tr>'
		tt_content+='<tr><td height="8" align="right">'
			tt_content+='<a href="javascript:document.direcc.flagfoto.value=\'0\';LayerOcultarFoto(\''+initial+'\','+i+');LayerMostrarFoto(\'verfoto\',\'1\');">'
				tt_content+='<img src="images/boton_cerrar_foto.gif" border="0" height="8" width="8" align="absmiddle">'
			tt_content+='</a>'
		tt_content+='</td></tr></table>';
	}
	movr="";
	mout="";
	mclk="";
	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,pubLayer);

	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));

	if(type.toLowerCase()!='flash'){
		ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
		dd.elements[name1].show();
		dd.elements[name1].setOpacity(opacity);
		dd.elements[name1].setZ(10);
		dd.elements[name1].moveBy(left2,top2);

	}
}

/**
* Crea layer con imagen de camara
* onmousedown -->muestra foto y oculta camara
**/
function LayerVerFoto(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo)
{
	//alert("LayerVerFoto="+initial);
	var name1=initial+""+i;
	var tt_content="";
	if(type.toLowerCase()=='imagen')
	{
		tt_content='<img name="SlideShow" src="images/htm/verfoto.gif" border="0"'
		 tt_content+=' onclick="javascript:document.direcc.flagfoto.value=\'1\';'
		 tt_content+=' LayerMostrarFoto(\'foto\',\'1\');'
		 tt_content+=' LayerOcultarFoto(\'verfoto\',\'1\');"'
		 tt_content+=' title="Ver Fotos de la direcci&oacute;n"'
		 tt_content+=' style="cursor:'+manito+';"/>'
	}
	movr="";
	mout="";
	mclk="";
	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,pubLayer);

	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));

	if(type.toLowerCase()!='flash'){
		ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
		dd.elements[name1].show();
		dd.elements[name1].setOpacity(opacity);
		dd.elements[name1].setZ(10);
		dd.elements[name1].moveBy(left2,top2);

	}
}

function ShowLayer (initial,i){
	dd.elements[initial+""+i].show();
}

function HideLayer (initial,i){
	dd.elements[initial+""+i].hide();
}

function LayerOcultarFoto(initial,i){
	dd.elements[initial+""+i].hide();
	//dd.elements[name1].setZ(1);
}

function LayerMostrarFoto(initial,i){
	dd.elements[initial+""+i].show();
	//dd.elements[name1].setZ(6);
}

function LayerCamara(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo)
{
	var name1=initial+""+i;
	var tt_content="";
	if(type.toLowerCase()=='imagen')
	{
		tt_content='<a href="javascript:VentanaCamara();" title="Ver Fotos Cuadra">'
		tt_content+=' <img border=0 width=14 heigth=9 src=' + content + ' name="camaraimg">'
		tt_content+='</a>';
	}

	movr="";
	mout="";
	mclk="";
	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,pubLayer);
	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));
	if(type.toLowerCase()!='flash'){
	   ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
	   dd.elements[name1].show();
	   dd.elements[name1].setOpacity(opacity);
	   dd.elements[name1].setZ(10);
	   dd.elements[name1].moveBy(left2,top2);
	}
}

function MoverCamara(x,y)
{
      dd.elements["camara1"].moveBy( x,y );
}

function MoverLayer(name,x,y)
{
	dd.elements[name].moveBy( x,y );
}

function CambiaContenidoLayer(name,contenido)
{
	dd.elements[name].innerHTML = contenido;
}

function alignleft(align,width,height){
	var al=align.toUpperCase();
	var res;
	if(al=='LT' || al=='LM' || al=='LB') res= parseInt((-1) * parseInt(width));
	if(al=='CT' || al=='CM' || al=='CB') res= parseInt((-1) * parseInt(width)/2);
	if(al=='RT' || al=='RM' || al=='RB') res= 0;
	return res;
}

function aligntop(align,width,height){
	var al=align.toUpperCase();
	var res;
	if(al=='LT' || al=='CT' || al=='RT') res= parseInt((-1) * parseInt(height));
	if(al=='LM' || al=='CM' || al=='RM') res= parseInt((-1)* parseInt(height)/2);
	if(al=='LB' || al=='CB' || al=='RB') res= 0;
	return res;
}



//funcion ToolTip2
//parametros:	initial <- nombre de areas
//				i		<- indice (no necesario)
//				left	<- posicion en pixeles x
//				top		<- posicion en pixeles y
//				radio	<- radio de zona de tooltip
//				content <- contenido de tooltip (no incluir comillas dobles " en contenido)
//utilidad:
//genera un ToolTip en una posicion dada (informacion de un punto)
function ToolTip2(initial,i,left,top,radio,content,mclk){
	var name1=initial+i+"";
	new_Area(name1,left,top,radio,content,maparea,mclk);
}


//funcion destroyTooltips
//parametros:
//
//utilidad:
//destruye la lista de tooltips para refrescar la area del mapa
function destroyTooltips()
{
	var arr=document.getElementsByTagName('area');

	//alert('Largo arr  ==> '+arr.length);

	for (i=arr.length-1;i>=0;i--)
	{
		arr[i].outerHTML="";
	}
	if(oldcursor!="")
		SetCursorAccion(oldcursor);

}

function ocultarlayersantesimp()
{
	for(i=1;i<dd.elements.length;i++){
		dd.elements[i].hide();
	}
}

//funcion destroyLayers
//parametros:
//
//utilidad:
//destruye la lista de layers que tienen propiedades

function destroyLayers()
{

	//alert('Ttl : '+dd.elements.length);
	for(i=2;i<dd.elements.length;i++)
	{
		var tempname=dd.elements[i].name;

		//alert(i+' ==> ' +tempname);
		if (tempname != "slider4")
		{
			dd.elements[i].setZ(1);
			dd.elements[i].del();
			i--;
			var div=document.getElementById(tempname);
			div.innerHTML = "";
			div.outerHTML = "";
			if(div.parentNode)
				div.parentNode.removeChild(div);
		}
	}

	//alert('Largo pub_array '+pub_array.length);

	for(i=0;i<pub_array.length;i++){
		var div=document.getElementById(pub_array[i]);
		div.innerHTML ="";
		div.outerHTML= "";
		if(div.parentNode)
			div.parentNode.removeChild(div);
	}
	pub_array=new Array();
}

function destroyLayerId(nombre){
	for(i=0;i<dd.elements.length;i++){
		var tempname=dd.elements[i].name;
		if (tempname == nombre)
		{
			dd.elements[i].setZ(1);
			dd.elements[i].del();
			i--;
			var div=document.getElementById(tempname);
			div.innerHTML = "";
			div.outerHTML = "";
			if(div.parentNode)
				div.parentNode.removeChild(div);
		}
	}
	/*for(i=0;i<pub_array.length;i++){
		var div=document.getElementById(pub_array[i]);
		div.innerHTML ="";
		div.outerHTML= "";
	}
	pub_array=new Array();*/
}

//funcion destroyAll()
//destruye todo
function destroyAll(){
	destroyLayers();
	destroyTooltips();
}

function imprimir()
{
	var x=dd.elements.length
	for(i=2;i<x;i++)
		{
			dd.elements[i].hide();
		}

	for(i=0;i<pub_array.length;i++)
		{
			var div=document.getElementById(pub_array[i]);
			div.style.display="none";
		}
	//window.print();
	getObjIframe('ImprimeMapa', true).print();
	for(i=2;i<x;i++)
		{
			dd.elements[i].show();
		}
	for(i=0;i<pub_array.length;i++)
		{
		var div=document.getElementById(pub_array[i]);
		div.style.display="block";
		}
}

function loadFrameImprimeMapa(strFrameName){	
	var strURL = 'ImprimeMapa.asp'
	+ '?mapa='+document.getElementById('MainWindow').src
	+ '&GrillaPagina='+document.getElementById('GrillaPagina').value
	+ '&GrillaFila='+document.getElementById('GrillaFila').value
	+ '&GrillaColumna='+document.getElementById('GrillaColumna').value
	+ '&Str_Direccion='+document.getElementById('Str_Direccion').value
	+ '&comuna='+getObjFromForm('direcc', 'Comuna1',true).value;		
	
	document.getElementById(strFrameName).src = strURL;
}

function PrintThisFrame(strFrameName) 
{  
  getObjFromFrame('mapa_impresion',strFrameName,true).src=document.getElementById('MainWindow').src; 
  if ( document.getElementById('DescEntorno'))
  {
     getObjFromFrame('entorno_impresion',strFrameName,true).innerHTML = getObjFromFrame('id_entorno','DescEntorno',true).innerHTML;  
  }

  window.frames[strFrameName].focus(); 
  window.frames[strFrameName].print(); 	
} 

function ContentFoto(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo)
{
	var name1=initial+""+i;
	var tt_content="";
	if(type.toLowerCase()=='imagen'){
			tt_content	+='<img onclick="'+linker+'" src="'+content+'" border="0" title="'+titulo+'" style="cursor:'+manito+';">';
		}
	movr="";
	mout="";
	mclk="";
	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,pubLayer);
	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));
	if(type.toLowerCase()!='flash'){
		ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
		dd.elements[name1].show();
		dd.elements[name1].setOpacity(opacity);
		dd.elements[name1].setZ(6);
		dd.elements[name1].moveBy(left2,top2);
	}
	else{
		pub_array[pub_array.length]=name1;
		document.getElementById(name1).style.left=left2+"px";
		document.getElementById(name1).style.top=top2+"px";
	}
}

// Se agrego hasta aqui para SGE

function ContentLayer_estrella(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,titulo,censo,xcenso,ycenso,carga_solo_ploteo,ciudad)
{
	var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));
	var xcenso2=parseInt(parseInt(xcenso)+parseInt(alignleft(align,width,height)));
	var ycenso2=parseInt(parseInt(ycenso)+parseInt(aligntop(align,width,height)));
	var name1=initial+""+i;
	var tt_content="";
	var gse_on='on';
	var manza_on='on';
	if(type.toLowerCase()=='imagen'){
		if(linker!='') tt_content	='<a href="'+linker+'">';
		 if (ciudad=='SANTIAGO')
		{
		tt_content +='<img src="'+content+'" border="0"   title="'+titulo+'">';
		}
		else
		{
		tt_content +='<img src="'+content+'" border="0" onmouseover="" onmouseout="" title="'+titulo+'">';
		}
		if(linker!='') tt_content	+='</a>';
	}
	movr="";
	mout="";
	mclk="";
	new_Layer_estrella(name1,0,0,tt_content,movr,mout,mclk,55,pubLayer);

	pub_array[pub_array.length]=name1;
	document.getElementById(name1).style.left=left2+"px";
	document.getElementById(name1).style.top=top2+"px";
	if (ciudad=='SANTIAGO' && censo != '')
	{
		if (carga_solo_ploteo=='ploteo_gse')
		{
			showToolTip(censo,xcenso2,ycenso2,'on','on');
			setTimeout("hideToolTip()",3000);
			carga_solo_ploteo='';
		}
		//refresca posicion del div al mover mapa
		else
		{
			showToolTip(censo,xcenso2,ycenso2,'off','off');
		}
	}

}

function new_Layer_estrella(name,left,top,content,movr,mout,mclk,z,son)
{
  var html='<DIV id="'+name+'" ';
  html +=' STYLE="position: absolute;';
  html += ' left: '+left+'px; top: '+top+'px;';
  html += 'z-index:'+z+';';
  html += 'visibility: visible;';
  html += '" ';
  html += movr;
  html += " ";
  html += mout;
  html += " ";
  html += mclk;
  html += ' >';
  html += content;
  html += '<\/DIV>';
  if(son=='body'){
		document.body.insertAdjacentHTML('beforeEnd',html);
  }
  else{
		document.getElementById(son).insertAdjacentHTML('beforeEnd',html);
  }
}


function showToolTip(text,x,y,gse_on,manza_on){
	//if(document.all)e = event;
	if(nIE) return false;

	if (text=='') return false;
	if(parseInt(document.direcc.Escala.value) > '21000')return false;
	//if (manza_on=='on')draw_manzana();
	draw_manzana(manza_on);

	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	var obj3 = document.getElementById('ocultar_manzana');
	//Definir coordenadas div.
	var y1=95;
	var x1=100;
	if (y<90)
	{
		y1=-35;
		change_style('bubble_bottom','bubble_bottomy');
		if (x<100)
		{
			x1=-5;
			change_style('bubble_top','bubble_topx');
		}
		else
		{
			change_style('bubble_top','bubble_topy');
		}
	}
	else
	{
		if (x<100)
		{
			x1=-5;
			change_style('bubble_top','bubble_topx2');
			change_style('bubble_bottom','bubble_bottomx');
		}
		else
		{
			change_style('bubble_top','bubble_top');
			change_style('bubble_bottom','bubble_bottom');
		}
	}

	var leftPos = x-x1;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos+ 'px';
	obj.style.top = y-y1;
	obj3.style.left = leftPos+'px';
	obj3.style.top = y-y1;
	if (gse_on=='on')
	{
		obj.style.display = 'block';
		obj3.style.display = 'block';
	}
	else
	{
		obj.style.display = 'none';
		obj3.style.display = 'none';
	}
	var text_gse=text.split("-");
	var hogar=text_gse[0];
	var personas=text_gse[1];
	var gse_text=text_gse[2];
	var Hombres=text_gse[3];
	var Mujeres=text_gse[4];

	var table='<table width="85%" border="0" cellspacing="0" cellpadding="0">';
	table+='<tr align="center"><td colspan="3" width="120" class="gse_tr"> Informacion Censo</td></tr>'
	table+='<tr><td width="65" class="gse"> Nº Hogares</td><td width="6" class="gse">:</td><td width="43" class="gse"> '+hogar+'</td></tr>';
	table+='<tr><td class="gse"> Nº Personas</td><td class="gse">:</td><td class="gse"> '+personas+'</td></tr>';
	table+='<tr><td class="gse">  - Hombres</td><td class="gse">:</td><td class="gse"> '+Hombres+'</td></tr>';
	table+='<tr><td class="gse">  - Mujeres</td><td class="gse">:</td><td class="gse"> '+Mujeres+'</td></tr>';
	table+='<tr><td class="gse"> Gse</td><td class="gse">:</td><td class="gse"> '+gse_text+'</td></tr>';
	table+='<tr><td colspan="3"><a href="javascript:alert(\'www.infochile.cl\');">Mas Informaci&oacute;n</a></td></tr>';
	table+='</table>';
	obj2.innerHTML = table;
}

function hideToolTip()
{
	document.getElementById('ocultar_manzana').style.display = 'none';
	document.getElementById('bubble_tooltip').style.display = 'none';
	document.getElementById('capa_manzana').style.display='none';
}

function show_manzana()
{

	if(nIE) return false;
	if (document.getElementById('lista_puntox').value == "") return false;
	if(parseInt(document.direcc.Escala.value) > '21000')return false;

	if(direcc.AccionMouse[5].checked || direcc.AccionMouse[6].checked) return false;
	var obj_b=document.getElementById('bubble_tooltip');
	var obj_c=document.getElementById('capa_manzana');
	if(document.body.onload)
	{
		if (obj_b.style.display == 'block') return false;
		//dd.elements.dragger.setDraggable(false);
		document.getElementById('ocultar_manzana').style.display = 'block';
		obj_b.style.display = 'block';
		//jg.clear();
		obj_c.style.display='block';
	}
}

function link_on_gse()
{

	// revisa que no se utilizando medir distancia o area para no activar capa dragger
	if(direcc.AccionMouse[2].checked)
	{
		dd.elements.dragger.setDraggable(true);
	}
	hideToolTip();
}

function draw_manzana(manza_on)
{
	//genera tooltip con informacion e la manzana dependiendo de las coordenads
	//la lectura del gse lo realiza en el ploteo de mysql.

	if (manza_on=='off')document.getElementById('capa_manzana').style.display='none';
	else document.getElementById('capa_manzana').style.display='block';

	var offsetC='4';
	if(parseInt(document.direcc.Escala.value) > '10000')offsetC='1';;

	var list1=document.getElementById('lista_puntox').value.split(',');
	var list2=document.getElementById('lista_puntoy').value.split(',');
	var minx=parseInt(list1[0]);
	var max=parseInt(list1[0]);
	var miny=parseInt(list2[0]);
	var maxy=parseInt(list2[0]);

	for (i=0;i<list1.length;i++)
	{
		if (parseInt(list1[i]) <= minx)
			minx = parseInt(list1[i]);
		if (parseInt(list1[i]) > max)
			max = parseInt(list1[i]);
	}

	for (i=0;i<list2.length;i++)
	{
		if (list2[i] <= miny)
			miny = parseInt(list2[i]);
		if (list2[i] > maxy)
			maxy = parseInt(list2[i]);
	}

	var contx=parseInt(minx+(max-minx)/2);
	var conty=miny+(maxy-miny)/2;

	for (i=0;i<list1.length;i++)
	{
		if (parseInt(list1[i]) <= parseInt(contx))
		{
			list1[i]=parseInt(list1[i])+parseInt(offsetC);
		}
		else if ( parseInt(list1[i]) > parseInt(contx))
		{
			list1[i]=parseInt(list1[i])-parseInt(offsetC);
		}
		list1[i]=parseInt(list1[i]);

	}

	for (i=0;i<list2.length;i++)
	{
		if (parseInt(list2[i]) <= parseInt(conty))
		{
			list2[i]=parseInt(list2[i])+parseInt(offsetC);
		}
		else if (parseInt(list2[i]) > parseInt(conty))
		{
			list2[i]=parseInt(list2[i])-parseInt(offsetC);
		}
		list2[i]=parseInt(list2[i]);
	}

	//jge=new jsGraphics("capa_manzana");
	jge.setStroke('2');
	jge.setColor("#E59A08");
	//alert('jge.fillPolygon('+list1+':'+list2+')');
	jge.fillPolygon(list1,list2); //con relleno
	//jge.drawPolyline(list1,list2); //solo contorno
	jge.paint();

}

// Se agrego hasta aqui para SGE
//ajax

var peticion = false;
 try {
  peticion = new XMLHttpRequest();
  } catch (trymicrosoft) {
  try {
		peticion = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
  try {
		peticion = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (failed) {
		peticion = false;
}
}
}

if (!peticion)
  alert("ERROR AL INICIALIZAR!");

function cargarFragmento(fragment_url, element_id)
{
	var element = document.getElementById(element_id);
	peticion.open("GET", fragment_url);
	peticion.onreadystatechange = function() {
	if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
	}
	}
	peticion.send(null);
}

function showDivFoto(ttip,contenido,left,top)
{
	//var lefter = (parseInt(left)<parseInt(320))?332:1;
	//var lefter = (parseInt(left)<parseInt(sAncho_Pix/2))?((parseInt(sAncho_Pix/2))+parseInt(sAncho_Pix/2)/sFactorFotoMapa):1;
	var lefter = (parseInt(left)<parseInt(sAncho_Pix/2))? parseInt(sAncho_Pix)-parseInt(parent.sAnchoFotoMapa):1;
	var topper = 1;
	oToolTip.innerHTML ='<div align="right" style="position:absolute; left:'+lefter+'px; top:'+topper+'px width:'+sAnchoFotoMapa+'px; height:100%; z-index:90; visibility:visible; display:block;"><span class="textopopup">'+contenido+'</span></div>';
	oToolTip.style.display="block";
}

function hideDivFoto()
{
	oToolTip.style.display="none";
}

function hideshowFotos(sw)
{
	var swfoto = parent.getObjFromForm('direcc','flagcamara' , true).value;
	if (parseInt(sw)==1)
	{
		if (swfoto == 1)
		{
			for(i=0;i<pub_array.length;i++)
			{
				var div=document.getElementById(pub_array[i]);
				div.style.display="none";
			}
			for(i=0;i<dd.elements.length;i++)
			{
				var tempname=dd.elements[i].name;
				if (tempname.substring(0,5) == 'foto_'  || tempname.substring(0,4) == 'pub_')
					dd.elements[i].hide();
			}
			parent.getObjFromForm('direcc','flagcamara',true).value=0;
			parent.getObj('IMG_layercamara1',true).src= "./images/camaraOff.gif";
			var objLbl = returnObjById("lblCamara")
			objLbl.innerHTML = "&nbsp;Activar&nbsp;Puntos&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		else
		{
			for(i=0;i<pub_array.length;i++)
			{
				var div=document.getElementById(pub_array[i]);
				div.style.display="block";
			}
			for(i=0;i<dd.elements.length;i++)
			{
				var tempname=dd.elements[i].name;
				if (tempname.substring(0,5) == 'foto_' || tempname.substring(0,4) == 'pub_')
					dd.elements[i].show();
			}
			parent.getObjFromForm('direcc','flagcamara',true).value=1;
			parent.getObj('IMG_layercamara1',true).src= "./images/camaraOn.gif";
			var objLbl = returnObjById("lblCamara")
			objLbl.innerHTML = "&nbsp;Desactivar&nbsp;Puntos&nbsp;&nbsp;&nbsp;&nbsp;";
		}
	}
	else
	{
		//alert(swfoto);
		if (swfoto == 0)
		{
			for(i=0;i<pub_array.length;i++)
			{
				var div=document.getElementById(pub_array[i]);
				div.style.display="none";
			}
			for(i=0;i<dd.elements.length;i++)
			{
				var tempname=dd.elements[i].name;
				if (tempname.substring(0,5) == 'foto_' || tempname.substring(0,4) == 'pub_')
					dd.elements[i].hide();
			}
			parent.getObj('IMG_layercamara1',true).src= "./images/camaraOff.gif";
		}
	}

	//alert(sw+' ==> '+swfoto+' ==> '+parent.getObjFromForm('direcc','flagcamara',true).value);

}

function returnObjById( id ) 
{ 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
}

function ContentLayerFotos(initial,i,type,content,width,height,linker,align,FGCOLOR,BGCOLOR,opacity,left,top,alias,titulo,onmover,onmout,onclk,div){

	var name1=initial+""+i;
	var tt_content="";

	if(type.toLowerCase()=='imagen')
	{
		if(linker!='') tt_content	='<a href="'+linker+'">';
		tt_content				+='<img src="'+content+'" id="img_'+name1+'"';
		if (width > 0 )
			tt_content			+=' width="'+width+'" ';
		if (height > 0 )
			tt_content			+=' height="'+height+'" ';

		if (onclk.length > 0 )
		tt_content				+=' onclick="'+onclk+'" ';

		if (onmout.length > 0 )
		tt_content				+=' onmouseout="'+onmout+'" style="border: 1px Solid #c0c0c0;" ';

		var tt_content2="";
		if (onmover.length > 0 )
		{
			tt_content2				=' onmouseover="parent.showDivFoto(\'foto_'+onmover+'\',\'';
			tt_content2				+='<table width='+sAnchoFotoMapa+' heigth=300 bgcolor=#D2D8E3 border=0><tr><td align=center valign=middle>';
			tt_content2				+='<table width=90% heigth=95% bgcolor=#D2D8E3 border=0>';
			tt_content2				+='<tr>';
			tt_content2				+='<td align=center valign=middle>';
			tt_content2				+='<font family=Arial,Helvetica,sans-serif size=1px color=#2222FF><b>'+titulo+'</b></font>';
			tt_content2				+='</td>';
			tt_content2				+='</tr>';
			tt_content2				+='<tr>';
			tt_content2				+='<td align=center>';
			tt_content2				+='<font family=Arial,Helvetica,sans-serif size=1px color=#666666>Gentileza de '+alias+'</font>';
			tt_content2				+='</td>';
			tt_content2				+='</tr>';
			tt_content2				+='<tr>';
			tt_content2				+='<td align=center valign=middle>';
			tt_content2				+='<img src=http://fotos.mapcity.com/fachadas/'+onmover+'.jpg '+( (sAncho_Pix<600)?'width='+(sAnchoFotoMapa-10):'' ) +' name=Foto id=Foto align=center>';
			tt_content2				+='</td>';
			tt_content2				+='</tr>';
	//		tt_content2				+='<tr>';
	//		tt_content2				+='<td align=center valign=middle > <a href=www.nokia.cl/ahoratodoseune ><img  src=./images/nokia.gif border=0> </a></td>';
	//		tt_content2				+='</tr>';
			tt_content2				+='<tr>';
			tt_content2				+='<tr>';
			tt_content2				+='<td align=center valign=top>Suba sus propias fotos haciendo click en el ícono <img src=./images/CamaraSinFoto.gif border=0> bajo el recuadro inferior del mapa';
			tt_content2				+='</td>';
			tt_content2				+='</tr>';
			tt_content2				+='</table>';
			tt_content2				+='</td></tr></table>\'';
			tt_content2				+=','+left+','+top+');"';
		}

		tt_content				+=tt_content2;
		tt_content				+=' border="0" title="'+titulo+'" ';
		if (initial.toLowerCase() == 'layercamara')
			tt_content				+=' style="cursor:'+manito+';">';
		else
			tt_content				+='>';

		if(linker!='') tt_content	+='</a>';

	}

	if(type.toLowerCase()=='texto')
	{
		tt_content				='<table class="'+style+'"><tr>';
		tt_content				+='<td bgcolor="#'+BGCOLOR+'"><font color="#'+FGCOLOR+'">';
		tt_content				+= content;
		tt_content				+= '</font></td></tr></table>';
	}

	if(type.toLowerCase()=='flash'){
		tt_content				+=flash_content(content,width,height);
	}

	movr="";
	mout="";
	mclk="";
	new_Layer(name1,0,0,tt_content,movr,mout,mclk,4,div);

	//var left2=parseInt(parseInt(left)+parseInt(alignleft(align,width,height)));
	//var top2=parseInt(parseInt(top)+parseInt(aligntop(align,width,height)));
	var left2=parseInt(left-8);
	var top2=parseInt(top-8);

	if(type.toLowerCase()!='flash'){
		ADD_DHTML(name1+VERTICAL+HORIZONTAL+RESET_Z);
		dd.elements[name1].show();
		dd.elements[name1].setOpacity(opacity);
		dd.elements[name1].setZ(6);
		dd.elements[name1].moveBy(left2,top2);
	}
	else{
		pub_array[pub_array.length]=name1;
		document.getElementById(name1).style.left=left2+"px";
		document.getElementById(name1).style.top=top2+"px";
	}
	window.status = name1;
}
