var actionmap=0;
var myCanvasclavo;
var canvaslayer=Array();
var myCanvaspredios;
var vg_showpopup; //indica que se esta mostrando un popup
var vg_showpopup=false; //para indicar que se esta mostrando un popup actualmente, luego borrarlo
var vg_overobject=false; //para indicar que el mouse se encuentra sobre un objeto dinamico y no desencadenar el evento mousedown en el theInsideLayer en el mapa

var enlacequerycalles = new XHConn();
if (!enlacequerycalles)    alert ("XMLHTTP no disponible");
var ct='';
var enlaceterminado=function(oXML){document.getElementById("queryresult").innerHTML=oXML.responseText;}
var enlacemispredios=function(oXML){document.getElementById("queryec").innerHTML=oXML.responseText;}
var enlacejunta=function(oXML){document.getElementById("queryjunta").innerHTML=oXML.responseText;}
var enlaceproblemas=function(oXML){document.getElementById("problemas").innerHTML=oXML.responseText;}
var vermarcador=false;
// imagen para indicar posición
var aqui = document.createElement( 'img' );
aqui.src = 'imagenessin/aqui.gif';
aqui.id='aqui';
aqui.style.zindex=1000;
aqui.xOffset=-14;
aqui.yOffset=-14;
//fin de imagen para marcar posición	 
function buscardireccion(){
   var cuadra=document.getElementById("txt_cuadra").value.toUpperCase()+"";
	var manzana=document.getElementById("txt_manzana").value.toUpperCase()+"";
	var lote=document.getElementById("txt_lote").value.toUpperCase()+"";	
	var calle= document.getElementById("txt_calle").value.toUpperCase()+"";	
   if ((manzana=="") && (lote=="")){  // si es una búsqueda de calles-cuadras
    if (calle.length>3){
      if (!(isNaN(parseInt(cuadra)))||(cuadra=="")) {
        divquery=getRawObject('queryresult');   
        divquery.innerHTML= "<img src='imagenes/cargando.gif'> Buscando...";                 
         var parametros="calle=" + calle + "&cuadra="+cuadra+"&manzana=&lote=";
			enlacequerycalles.connect("querycalles.php","POST",parametros,enlaceterminado);
      }else{
			document.getElementById("txt_cuadra").value="";
         alert ("Ingrese un número");
      };
    }
   }else{ // si es una búsqueda de manzana y lote   
      if (lote==""){
	    alert("Ingrese datos de lote")
	  } else {	  
        divquery=getRawObject('queryresult');   
        divquery.innerHTML= "<img src='imagenes/cargando.gif'> Buscando...";        
        var parametros="calle=" + calle +"&cuadra=&manzana=" + manzana + "&lote="+ lote;   
		  enlacequerycalles.connect("querycalles.php","POST",parametros,enlaceterminado);
	  }	
   }	  
}

function consultarmispredios(){
 var enlacepredios = new XHConn();
 if (!enlacepredios){ 
    alert ("XMLHTTP no disponible");
    return;    
 }
 var parametros="ct=" + ct;
 if (!(parametros=="ct=")){
 enlacepredios.connect("querymispredios.php","POST",parametros,enlacemispredios);
 }
}

function posicionarlote(cod_cat){
 var http_request = AJAXCrearObjeto();
	 var url = 'queryxylote.php?cod='+ cod_cat;
	 http_request.onreadystatechange = function handle_json() {
 								     if (http_request.readyState == 4) {
						  		       if (http_request.status == 200) {
									      var json_data = http_request.responseText; 
									      var the_object = eval("(" + json_data + ")");
										   myKaMap.zoomTo(the_object[0][0],the_object[0][1]);										  
									    } else {
										      alert("Ha habido un problema con la URL.");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
}

function myOnLoad()
{   
    initDHTMLAPI();
    myKaMap = new kaMap( 'viewport' );
    myKaMap.initialize('sanborja');
    var myKaScalebar = new kaScalebar( myKaMap, 'scalebar' );
    var myKaKeymap = new kaKeymap( myKaMap, 'keymap' );
    var myKaLegend = new kaLegend( myKaMap, 'legend', false );
    myKaMap.registerForEvent( KAMAP_MAP_INITIALIZED, null, myMapInitialized );
    myKaMap.registerForEvent( KAMAP_SCALE_CHANGED, null, myScaleChanged );
    myKaMap.registerForEvent( KAMAP_QUERY, null, myQuery );	    
    myKaNavigator = new kaNavigator( myKaMap );     
	 myKaNavigator.activate();  
	 myKaQuery = new kaQuery( myKaMap, KAMAP_POINT_QUERY ,'help');	
	 myKaAnotation = new kaQuery( myKaMap, KAMAP_RECT_QUERY, 'crosshair' );	 
    drawPage();   
    canvaslayer[0] = myKaMap.createDrawingCanvas(8000);
    myCanvaspredios = myKaMap.createDrawingCanvas(5000); 
	mybusqueda = new kaXmlOverlay( myKaMap, 250 );
    
}

/**
 * event handler for KAMAP_MAP_INITIALIZED
 *
 * the scales are put into a select ... this will be used for zooming
 */ 
function myMapInitialized( eventID, mapName ){ 	
    var objb=document.createElement( 'div' );
    var brig="<table border='0' cellpadding='0' cellspacing='0'>";
	brig=brig + "<tr><td width='2' height='15'> </td> <td width='14' height='14'><img src='iconos/ico_brigadista.gif' width='14' height='14'></td><td width='20' height='14'><input type=checkbox  onClick='cargarbrigadista(this.checked)'></td><td width='160' height='14'>Brigadista Defensa Civil</td></tr>";
	 brig=brig+ "<tr><td height='14'></td><td><img src='recursos/pozo.png'></td><td><input type=checkbox  onClick='pto_agua_load(this.checked)'></td><td>Puntos de Agua</td></tr><tr><td> </td><td >&nbsp;</td><td></td><td><img src='recursos/hidrante.png'>Hidrante <img src='recursos/tanque.png'>Tanque <img src='recursos/pozo.png'>Pozo</td></tr>";
	brig=brig+ "</table>";
	objb.innerHTML=brig;
	getRawObject('legend').appendChild(objb);
	ActivarTab(1);
}

function crearlotes(){
  var http_request = AJAXCrearObjeto();
	 var url = 'querypredio.php?ct='+ct;
	 http_request.onreadystatechange = function handle_json() {
 										 if (http_request.readyState == 4) {
							  		     if (http_request.status == 200) {
									     var json_data = http_request.responseText; 
									     var the_object = eval("(" + json_data + ")");
										  for (var i=0;i<the_object.length;i++){
										        crearfotopredio(the_object[i][0],the_object[i][1],'../fotoslotesmall/'+the_object[i][2]+'-1.jpg',i+1);
												adicionarsubsector(the_object[i][2],i);
									      }
										  
									    } else {
										      alert("Ha habido un problema con la URL.");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
}
function adicionarsubsector(predio,n){
var http_request = AJAXCrearObjeto();
	 var url = 'querysubsector.php?cod='+predio;
	 http_request.onreadystatechange = function handle_json() {
 										 if (http_request.readyState == 4) {
							  		     if (http_request.status == 200) {
									     var json_data = http_request.responseText; 
									     var sector = eval("(" + json_data + ")");
								         obj=getRawObject('subsector');
									     obj.options[n] = new Option(sector,sector,false,false);
									    } else {
										      alert("Ha habido un problema con la URL.");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
 

}



function f_vercom(id,numcobertura,vercomponentes){
//	var vercomponentes=true;
	if(vercomponentes){
	var http_request = AJAXCrearObjeto();
	canvaslayer[numcobertura] = myKaMap.createDrawingCanvas(15500+numcobertura);
	var url = "componentes.php?idcomp="+id;
	http_request.onreadystatechange = function handle_json(){
 										 if (http_request.readyState == 4){
							  		     if (http_request.status == 200){
									     var json_data = http_request.responseText;
									     var the_object = eval("(" + json_data + ")");
										 numobjetos=the_object.length;
										  for (var i=0;i<numobjetos;i++){
											createobjcomp(the_object[i][0],the_object[i][1],the_object[i][2],id,numcobertura);
											 
									      }
										  //dvload.innerHTML="";
									    }else{
										      alert("Ha habido un problema con la URL");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
	 }
	 else{
	if(!(canvaslayer[numerocobertura]==null)){
		myKaMap.removeDrawingCanvas(canvaslayer[numerocobertura]);
		canvaslayer[numerocobertura]=null;
	}else{
		//alert("isnull")
	}
	//
	 }
	 
	 
}



function createobjcomp(obj1,obj2,obj3,idtipo,numcobertura){


							var img = document.createElement('img');
											  img.src = 'imagenessin/comp_'+idtipo+'.png';
											  img.title=obj3;
											  //img.style.zindex=500+numero;
											  img.xOffset=-14;
											  img.yOffset=-14;


											img.style.cursor="pointer";
											img.onclick= function(){
											//vftolte=window.open("FLoteFoto.php?codcat="+title ,"vftolte","height=505,menubar=no,width=460,status=yes,scrollbars=no,toolbar=no,location=no,resizable=no");
												show_wininfocomponente(obj3);
												//vftolte.focus();
											  return false;
											  };
							  
											  
											  
											  myKaMap.addObjectGeo( canvaslayer[numcobertura],obj1, obj2, img );
											
											

}














function crearfotopredio(x,y,imagen,numero){
  imgp= document.createElement( 'img' );
  imgp.src = 'imagenes/predio.gif';
  imgp.id='predio'+numero;  
  imgp.name="<img width=150 height= 100 border=\'1\' src="+imagen+">"; 
  imgp.onmouseover= function(numero) { return overlib(this.name,WIDTH,150,HEIGHT,100);};
  imgp.onmouseout= function(numero) {if(!numero) numero=event; return nd(); };	 
  myKaMap.addObjectGeo( myCanvaspredios, x, y, imgp );  
}

function myQuery( eventID, queryType, coords ){
  if (actionmap==1){	 
	consultarfoto(coords[0],coords[1]);		
  } 
 if (actionmap==2){
      if (isNaN(coords[2])){
        myKaMap.zoomIn();
        myKaMap.zoomTo(coords[0],coords[1]);
      }else{
		  myKaMap.zoomToExtents(coords[0], coords[3], coords[2],coords[1])
		}	   
	}
  if (actionmap==3){
    if (isNaN(coords[2])){
        myKaMap.zoomOut();
        myKaMap.zoomTo(coords[0],coords[1]);
      }else{
	      c=myKaMap.getGeoExtents();	
	      myKaMap.zoomToExtents(2*c[0]- coords[0],2*c[1]-coords[1],2*c[2]-coords[2],2*c[3]-coords[3]);
	   }   
	}
	
  if (actionmap==4){	 
	consultarlote(coords[0],coords[1]);	
  } 	
	
}

function consultarlote(xg,yg){
	 var http_request = AJAXCrearObjeto();
	 var url = 'queryfoto.php?xg='+xg+'&yg='+yg;
	    http_request.onreadystatechange = function handle_json() 
		{
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {
					var json_data = http_request.responseText; 
					var lafoto = eval("(" + json_data + ")");
					certparam(lafoto[0][0]);
				}else{
					alert("Ha habido un problema con la URL.");
				}
				http_request = null;
				//document.getElementById("queryec").innerHTML=oXML.responseText;

			}
		};
		http_request.open("GET", url, true);
		http_request.send(null);	
}


function certparam(lote){

	AbrirVentana("divParametros", "DATOS DE PARAMETROS", 850, 450);
	innerHTML("divParametros","");
	
	var http_request = AJAXCrearObjeto();
	 var url = 'parametros/parametroslote.php?pLote='+lote;
	    http_request.onreadystatechange = function handle_json() 
		{
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {
					var json_data = http_request.responseText;
					innerHTML("divParametros", json_data );
				}else{
					alert("Ha habido un problema con la URL.");
				}
				http_request = null;
			}
		};
		http_request.open("GET", url, true);
		http_request.send(null);	
}

function AbrirVentana(capa, titulo, ancho, alto){
	if( jQuery("#Vent_"+capa).length == 0 ){
		jQuery("body").prepend("<div id='Vent_"+capa+"' title='"+titulo+"' class='flora' style='margin:0px;'><div id='"+capa+"' style='overflow:auto; overflow-x:hidden;'></div></div>");
		jQuery("#"+capa)
		.css("background-color","#E0EFF6")
		.css({ width:ancho, height:alto - 25 });
	}
	
	innerHTML(capa, "");
	
	jQuery("#Vent_"+capa)
	.dialog(
		{
			modal:true
			,overlay:{ opacity: 0.5, background: "gray" }
			,width:ancho
			,height:alto
			,resizable:false
		}
	);
}

function CerrarVentana(capa){
	jQuery("#Vent_"+capa).dialog("close");
}

function innerHTML(dom, html){
	document.getElementById(dom).innerHTML = "";
	document.getElementById(dom).innerHTML = html;
}

function consultarfoto(xg,yg){
 var http_request = AJAXCrearObjeto();
 var url = 'queryfoto.php?xg='+xg+'&yg='+yg;
 http_request.onreadystatechange = function handle_json() {
 										 if (http_request.readyState == 4) {
							  		     if (http_request.status == 200) {
									     var json_data = http_request.responseText; 
									     var lafoto = eval("(" + json_data + ")");
									       if (lafoto[0]==""){
											  lafoto[0][0]='<a>Foto no encontrada</a>'	
									       }else{
									        lafoto[0][0]="<img width=150 height= 100 border=\'1\' src=../fotoslotesmall/"+lafoto[0][0]+"-1.jpg>";
									       }
										    overlib(lafoto[0][0],STICKY,CLOSECLICK,CAPTION,'Foto',WIDTH,150,HEIGHT,100,CENTER);
									    } else {
										      alert("Ha habido un problema con la URL.");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
}
function moveMap(dir)
{

nStep = 40;

        switch(dir)
        {
          case 0://north
            myKaMap.moveBy(0,nStep);
            myKaMap.triggerEvent( KAMAP_EXTENTS_CHANGED, myKaMap.getGeoExtents() );
            break;
          case 3: //south
            myKaMap.moveBy(0,-nStep);
            myKaMap.triggerEvent( KAMAP_EXTENTS_CHANGED, myKaMap.getGeoExtents() );
            break;
          case 1: //east
            myKaMap.moveBy(nStep,0);
            myKaMap.triggerEvent( KAMAP_EXTENTS_CHANGED, myKaMap.getGeoExtents() );
            break;
          case 2: //west
            myKaMap.moveBy(-nStep,0);
            myKaMap.triggerEvent( KAMAP_EXTENTS_CHANGED, myKaMap.getGeoExtents() );
            break;
         }
}

function switchMode(id){
actionmap=id;
switch (id)
{
    case 0:
        myKaNavigator.activate();
        break;
    case 1:
		myKaQuery.activate();
      break;
	 case 2:
      myKaAnotation.activate();
		break;
	 case 3:
      myKaAnotation.activate();
		break;
	 case 4:
      	myKaQuery.activate();
		break;		
   }
}
function listarjunta(){
 var subsector=document.getElementById('subsector').value;  
 var elanio=document.getElementById('anio').value;   
 var enlacejuntav = new XHConn();
 if (!enlacejuntav){ 
    alert ("XMLHTTP no disponible");
    return;    
 }
   var parametros="jv=" + subsector+ "&an="+elanio;
      enlacejuntav.connect("queryjunta.php","POST",parametros,enlacejunta);
}

function listarproblema(){
 var elanio=document.getElementById('anio').value;
 var subsector=document.getElementById('subsector').value;
 var enlaceproblemaso = new XHConn();
  if (!enlaceproblemaso){ 
    alert ("XMLHTTP no disponible");
    return;    
  }
   var parametros="jv=" + subsector+"&an="+elanio; 
   enlaceproblemaso.connect("queryproblemas.php","POST",parametros,enlaceproblemas);  
}

function myScaleChanged( eventID, scale )
{
     var currentMap = myKaMap.getCurrentMap();
    var scales = currentMap.getScales();
    for(var i in scales){
        var imgString = 'img'+scales[i];
        var scaleString = 'img'+scale;
        if(getRawObject(imgString)) {
            if(imgString == scaleString) {
                  getRawObject(scaleString).className = 'escalaactiva'; 
            } else {
                getRawObject(imgString).className = 'escalainactiva';  
            }
        }
    }
}

// Function pour établir l'echelle
function mySetScale( scale )
{   
    myKaMap.zoomToScale( scale );
}

/** Aficher tout le map*/
function myZoomExtent()
{ 
  var exStr = myKaMap.getCurrentMap().defaultExtents.toString();
  var ex = myKaMap.getCurrentMap().defaultExtents;
  myKaMap.zoomToExtents(ex[0],ex[1],ex[2],ex[3]);
}

function myZoomIn()
{
    myKaMap.zoomIn();
}

function myZoomOut()
{
    myKaMap.zoomOut();
}


function drawPage()
{
    var browserWidth = getInsideWindowWidth();
    var browserHeight = getInsideWindowHeight()-95;    
    var eldiv = getRawObject('viewport');    
    eldiv.style.width = browserWidth -200 + "px";
    eldiv.style.height = browserHeight  + "px";   
    eldiv = getRawObject('reference');    
    eldiv.style.height = browserHeight  + "px";
    eldiv = getRawObject('mispredios');    
    eldiv.style.height = browserHeight  + "px";           
    eldiv = getRawObject('mijunta');    
    eldiv.style.height = browserHeight  + "px";           
    eldiv = getRawObject('queryec');    
    eldiv.style.height = parseInt((browserHeight-90)/2)  + "px";           
    eldiv = getRawObject('queryjunta');    
    eldiv.style.height = parseInt((browserHeight-90)/2)  + "px";               
    myKaMap.resize();
}

function posicionarg(cx,cy){
  myKaMap.zoomTo(cx,cy,1500);    
  borrarclavo
  marcar(cx,cy);
}
function marcar(x,y){
     myKaMap.addObjectGeo( canvaslayer[0], x, y, aqui );    
     vermarcador=true;	
}
function borrarclavo(){
  if (vermarcador)  myKaMap.removeObject(document.getElementById('aqui'));
}

function ColorFila() {
	var rows = document.getElementsByTagName("tr");
	for(var i in rows) {
		rows[i].onmouseover = function() {
			this.className = "resaltar";
		}
		rows[i].onmouseout = function() {
			this.className = null;
		}
	}
}
onload= ColorFila;

function cargarbrigadista( mostrar){
 if (mostrar){
  var http_request = AJAXCrearObjeto();
  var numcobertura=17
  canvaslayer[numcobertura] = myKaMap.createDrawingCanvas(500+numcobertura);
	 var url = 'querybrigadista.php';
	 http_request.onreadystatechange = function handle_json(){
 										 if (http_request.readyState == 4){
							  		     if (http_request.status == 200){
									     var json_data = http_request.responseText;
									     var the_object = eval("(" + json_data + ")");
										 numobjetos=the_object.length;
										  for (var i=0;i<numobjetos;i++){
									        crearobjeto(the_object[i][0],the_object[i][1],the_object[i][2],numcobertura,'iconos/ico_brigadista.gif',i+1);
									      }
									    } else {
										      alert("Ha habido un problema con la URL");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
 }else{
     quitarobjetos('brigadista',29);
 }
}

function cargarobjetos( numcobertura,icono,mostrar,numobjetos){
 if (mostrar){	 
	 var http_request = AJAXCrearObjeto();
	 canvaslayer[numcobertura] = myKaMap.createDrawingCanvas(500+numcobertura);
	 var url = 'queryobjeto.php?num='+numcobertura;
	 http_request.onreadystatechange = function handle_json() {
 										 if (http_request.readyState == 4) {
							  		     if (http_request.status == 200) {
									     var json_data = http_request.responseText; 
									     var the_object = eval("(" + json_data + ")");
										 numobjetos=the_object.length;
										  for (var i=0;i<numobjetos;i++){
											  if(numcobertura==12){
												crearobjeto_cabina(the_object[i][0],the_object[i][1],the_object[i][2],the_object[i][3],the_object[i][4],numcobertura,icono,i+1);
											  }else{
												crearobjeto(the_object[i][0],the_object[i][1],the_object[i][2],numcobertura,icono,i+1);
											  }

									      }
										
									    } else {
										      alert("Ha habido un problema con la URL.");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
 }else{
     quitarobjetos(numcobertura,numobjetos);
 }	
}

function AJAXCrearObjeto(){
  var obj;
  if(window.XMLHttpRequest) { // no es IE
    obj = new XMLHttpRequest();
  } else { // Es IE o no tiene el objeto
     try {
       obj = new ActiveXObject("Microsoft.XMLHTTP");
    }  catch (e) {
      alert('El navegador utilizado no es efectivo');
    }
  }
  return obj;
}

function crearobjeto_cabina(xl,yl,nombre,direcc,id,numcobertura,icono,numero){
  img=null;
  img = document.createElement( 'img' );
  img.src = icono;
  img.id='obj'+numcobertura;
  img.style.zindex=500+numero;
  img.xOffset=-7;
  img.yOffset=-7;
  //img.name=texto+"<br><center><img src=foto1.jpg></center>";
  img.name=nombre+"|"+id+"|"+direcc;
  img.style.cursor="pointer";
  
  img.onmouseover=function(){vg_overobject=true;}; //!!!para indicar en el global que se esta sobre objeto
  img.onmouseout=function(){vg_overobject=false;};//!!!para indicar en el global que se ha salido de objeto
  img.onclick= function(){popup_cabina(this.name,xl,yl);};
  myKaMap.addObjectGeo( canvaslayer[numcobertura], xl, yl, img );

}

function popup_cabina(p_nombre,x,y){
	 tar=p_nombre.split("|");
	 if(tar[0]=="null"){tar[0]="";}
	 if(tar[2]=="null"){tar[2]="";}
	 
	 vg_showpopup=true;
	 info="<table width='180' border='0' cellspacing='2' cellpadding='0'>";
     info=""+info+"<tr align=left><td valign=top class=negrita>Cabina:</td><td>"+tar[0]+"</td></tr>";
     info=""+info+"<tr align=left><td valign=top class=negrita>Dirección:</td><td>"+tar[2]+"</td></tr>";
	 info=""+info+"<tr><td></td><td align='right'><a class=linktooltip href='#' onclick=\"cabinas_loadfoto('"+tar[1]+"','"+tar[0]+"','"+tar[2]+"')\">Mostrar Fotos</a></td></tr>";
	 info=info+"</table>";
	 overlib(info,FGCOLOR, '#FFFFFF', BGCOLOR, '#80A0C1',WIDTH,180,HEIGHT,35, STICKY,CLOSECLICK,CAPTION,tar[1],CLOSECOLOR,'#F5C823');
	 //http_request.open("GET", url, true);
	 //http_request.send(null);
}

function cabinas_loadfoto(cd,nomb,dir){
ccppfc=window.open("CabinaFotos.php?c="+cd+"&nomb="+nomb+"&dir="+dir,"ccppfc","height=490,menubar=yes,width=470,status=no,scrollbars=no,toolbar=no,location=no,resizable=yes");
ccppfc.focus();
}

function crearobjeto(xl,yl,texto,numcobertura,icono,numero){
  img=null;
  img = document.createElement( 'img' );
  img.src = icono;
  img.id='obj'+numcobertura;
  img.style.zindex=500+numero;
  //img.name=texto+"<br><center><img src=foto1.jpg></center>";
  img.name=texto;
  img.xOffset=-7;
  img.yOffset=-7;
  img.style.cursor="pointer";
  img.onmouseover=function(){vg_overobject=true;}; //!!!para indicar en el global que se esta sobre objeto
  img.onmouseout=function(){vg_overobject=false;};//!!!para indicar en el global que se ha salido de objeto
  img.onclick= function(){popup_objeto(this.name,xl,yl);};
  myKaMap.addObjectGeo( canvaslayer[numcobertura], xl, yl, img );
  /*return;
  img.onmouseover=  function(a) {  if(!a) a=event; return overlib(this.name, CAPTION, 'Datos',FGCOLOR, '#FFFFFF', BGCOLOR, '#006633',WIDTH,200,HEIGHT,35, CAPICON,icono);};
  img.onmouseout= function(a) {  if(!a) a=event; return nd(); };
  myKaMap.addObjectGeo( canvaslayer[numcobertura], xl, yl, img );*/
}

function popup_objeto(p_nombre,x,y){
	 vg_showpopup=true;
	 info="<table width='180' border='0' cellspacing='2' cellpadding='0'>";
     info=""+info+"<tr align=left><td>"+p_nombre+"</td></tr>";
	 info=info+"</table>";
	 overlib(info,FGCOLOR, '#FFFFFF', BGCOLOR, '#80A0C1',WIDTH,180,HEIGHT,35, STICKY,CLOSECLICK,CAPTION,'objeto',CLOSECOLOR,'#F5C823');
}

function quitarobjetos(numerocobertura,numdeobjetos){
   for (var i=1; i<=numdeobjetos;i++){   
      myobjeto=document.getElementById('obj'+numerocobertura); 
      myKaMap.removeObject(myobjeto);
    }	
	myKaMap.removeDrawingCanvas(canvaslayer[numerocobertura]);
}

//// funciones para la creación dinámica de objetos y minifichas informativas//
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("No se pudo cargar el evento del objeto ");
  }
}

function ActivarTab(nombre) {
  var  i;
  if (nombre == null)  return;
	if (nombre==1){
  	  var divleyenda = getRawObject('legend'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('tabla'); 	
	  divleyenda.style.visibility="visible";
  	  divleyenda = getRawObject('mispredios'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('mijunta'); 	
	  divleyenda.style.visibility="hidden";		

  	  divleyenda = getRawObject('salud'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('seguridad'); 	
	  divleyenda.style.visibility="hidden";	  
	}
	if (nombre==2){
  	  var divleyenda = getRawObject('tabla'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('legend'); 	
	  divleyenda.style.visibility="visible";
  	  divleyenda = getRawObject('mispredios'); 	
	  divleyenda.style.visibility="hidden";	  
  	  divleyenda = getRawObject('mijunta'); 	
	  divleyenda.style.visibility="hidden";		

  	  divleyenda = getRawObject('salud'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('seguridad'); 	
	  divleyenda.style.visibility="hidden";	  
	}
	if (nombre==3){
    if (!(ct=='')){
  	  var divleyenda = getRawObject('tabla'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('legend'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('mispredios'); 	
	  divleyenda.style.visibility="visible";	
  	  divleyenda = getRawObject('mijunta'); 	
	  divleyenda.style.visibility="hidden";	

  	  divleyenda = getRawObject('salud'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('seguridad'); 	
	  divleyenda.style.visibility="hidden";	  
	  }else{
	    alert ("Ingrese su código de contribuyente y clave");
	  }
	}
  	if (nombre==4){
    if (!(ct=='')){  	
  	  var divleyenda = getRawObject('tabla'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('legend'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('mispredios'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('mijunta'); 	
	  divleyenda.style.visibility="visible";	

  	  divleyenda = getRawObject('salud'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('seguridad'); 	
	  divleyenda.style.visibility="hidden";
	  
	  }else{
	    alert ("Ingrese su código de contribuyente y clave");
	  }	  
	}	

  	if (nombre==5){
    if (!(ct=='')){  	
  	  var divleyenda = getRawObject('tabla'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('legend'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('mispredios'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('mijunta'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('salud'); 	
	  divleyenda.style.visibility="visible";	
  	  divleyenda = getRawObject('seguridad'); 	
	  divleyenda.style.visibility="hidden";		  
	  }else{
	    alert ("Ingrese su código de contribuyente y clave");
	  }	  
	}	


  	if (nombre==6){
    if (!(ct=='')){  	
  	  var divleyenda = getRawObject('tabla'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('legend'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('mispredios'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('mijunta'); 	
	  divleyenda.style.visibility="hidden";
  	  divleyenda = getRawObject('salud'); 	
	  divleyenda.style.visibility="hidden";	
  	  divleyenda = getRawObject('seguridad'); 	
	  divleyenda.style.visibility="visible";		  
	  }else{
	    alert ("Ingrese su código de contribuyente y clave");
	  }	  
	}	





	
}
function printpreview()
{
    window.print();
}
function createWindow(cUrl,cName,cFeatures) {
	var xWin = window.open(cUrl,cName,cFeatures);
	xWin.focus();
}

function vermicuenta(){
 document.frmEc.codigo.value=ct;
 document.frmEc.clave.value=document.getElementById('pwd').value;
 document.frmEc.submit();
return;
}

function validarusuario(){
	 var http_request = AJAXCrearObjeto();
	 var user=document.getElementById('ct');
	 var pwd=document.getElementById('pwd');	
	 if (isNaN(user.value)){
		alert ("Código incorrecto");
		document.getElementById('ct').value="";
		return;	
	 }
    
	 var url = 'queryusuario.php?usr='+user.value+'&pwd='+pwd.value;
	 http_request.onreadystatechange = function handle_json() {
 										 if (http_request.readyState == 4) {
							  		     if (http_request.status == 200) {
									     var json_data = http_request.responseText; 
									     entrar = eval("(" + json_data + ")");		
                                          if (entrar>0){	
											 document.getElementById('espacepwd').style.visibility="hidden";
											 document.getElementById('espaceentrar').innerHTML="";										  
										     document.getElementById('espacecodigo').innerHTML="Cargando sus datos ...";
											 ct=user.value;	
											 crearlotes();	
	 	                                     consultarmispredios();											 										 							   										
	 										 listarproblema();
											 listarjunta();										 
											 document.getElementById('espacecodigo').innerHTML=" ";
                                             }else{
                                               alert('Usuario y clave incorrecto');                                     
                                             }
									     } else {
										      alert("Ha habido un problema con la URL.");
									     }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
}

//--Puntos de Agua
function pto_agua_load( mostrar){
var numcobertura=23;
if(mostrar){
  var http_request = AJAXCrearObjeto();
  canvaslayer[numcobertura] = myKaMap.createDrawingCanvas(500+numcobertura);
	 var url = 'pto_agua_loadobjects.php';
	 http_request.onreadystatechange = function handle_json(){
 										 if (http_request.readyState == 4){
							  		     if (http_request.status == 200){
									     var json_data = http_request.responseText;
									     var the_object = eval("(" + json_data + ")");
										 numobjetos=the_object.length;
										  for (var i=0;i<numobjetos;i++){
									        pto_agua_crearobjeto(the_object[i][0],the_object[i][1],the_object[i][2],numcobertura,i+1);
									      }
									    } else {
										      alert("Ha habido un problema con la URL");
									    }
									    http_request = null;
									  }
									 };
	 http_request.open("GET", url, true);
	 http_request.send(null);
 }else{
     pto_agua_quitarobjeto(numcobertura);
 }
}

function pto_agua_crearobjeto(xl,yl,tipo,numcobertura,numero){
  var img = document.createElement( 'img' );
  if(tipo=="HIDRANTES"){
	  img.src = 'recursos/hidrante.png';
  }else if(tipo=="POZOS"){
	  img.src = 'recursos/pozo.png';
  }else if(tipo=="TANQUES"){
	  img.src = 'recursos/tanque.png';
  }else{
	return false;
  }
  img.title=tipo;
  //img.style.zindex=500+numcobertura; //numero;
  img.xOffset=-8;
  img.yOffset=-8;
  img.style.cursor="pointer";
  /*img.onclick=function(){
   	  vsmfro=window.open("Semaforo.php?codigo="+title ,"vsmfro","height=600,menubar=no,width=610,status=yes,scrollbars=yes,toolbar=no,location=no,resizable=yes");
	  vftolte.focus();
	  window.event.cancelBubble=true;
  };
  img.onmouseup=function(){window.event.cancelBubble=true;}
  img.onmousedown=function(){window.event.cancelBubble=true;}
  */
  myKaMap.addObjectGeo( canvaslayer[numcobertura], xl, yl, img );
}

function pto_agua_quitarobjeto(numerocobertura){
	myKaMap.removeDrawingCanvas(canvaslayer[numerocobertura]);
	canvaslayer[numerocobertura]=null;
}
