
var co_nombre = new Array(100);
var co_lon = new Array(100);
var co_lat = new Array(100);

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


var rowHighlight = true // turn on row highlights
var colHighlight = true // turn off row highlights

	function getElement(el) 
	{
		var tagList = new Object
		for (var i = 1; i < arguments.length; i++)
		  tagList[arguments[i]] = true
		while ((el!=null) && (tagList[el.tagName]==null))
		  el = el.parentElement
		return el
	}

function checkHighlight(which)
	{
		
		var el = getElement(event.srcElement,"TH","TD");
		if (el==null) return
		if ((el.tagName=="TH") && (colHighlight))
		 {
		  var idx = el.cellIndex
		  var table = getElement(el, "TABLE")
		  var column = table.all.tags("COL")[idx]
		  if (which)
			column.className="cover"
		  else
			column.className=""
		}      

		if ((el.tagName=="TD") && (rowHighlight)) 
		{
		  var row = getElement(el, "TR") 
		  var table = getElement(row, "TABLE")
		  if (which) 
			row.className = "rover"
		  else
			row.className = ""
		  cache = row
		}
	}






  var rowHighlight2 = true // turn on row highlights
  var colHighlight2 = true // turn off row highlights
  function getElement2(el) {
    var tagList = new Object
    for (var i = 1; i < arguments.length; i++)
      tagList[arguments[i]] = true
    while ((el!=null) && (tagList[el.tagName]==null))
      el = el.parentElement
    return el
  }
  
  
  
  function checkHighlight2(which) {
    var el = getElement2(event.srcElement,"TH","TD")
    if (el==null) return
    if ((el.tagName=="TH") && (colHighlight)) {
      var idx = el.cellIndex
      var table = getElement2(el, "TABLE")
      var column = table.all.tags("COL")[idx]
      if (which)
        column.className="cover2"
      else
        column.className=""
    }      
    if ((el.tagName=="TD") && (rowHighlight)) {
      var row = getElement2(el, "TR") 
      var table = getElement2(row, "TABLE")
      if (which) 
        row.className = "rover2"
      else
        row.className = ""
      cache = row
    }
  }


/*******************************************/
function do_xml_num(paramObj, szComuna, szCalle, szRegion) {
		szValor  = paramObj;	
		var ieKey = event.keyCode; var nKey=0;
		var strin = "Codice tecla in Explorer: " + ieKey;
		var blEntrar = false;
		if ((ieKey == 27 ) )
		 {
			blEntrar = false;
			window.divNumCalles.style.visibility = "hidden";
		 }

		if ((ieKey > 95 ) && (ieKey < 106))
		 {
			blEntrar = true;
		 }

		if ((ieKey == 8 )) 
		{
			blEntrar = true;
		}

		if (((ieKey > 64 ) && (ieKey < 91))) 
		{
			blEntrar = true;
		}
		if ((szValor != '') && (blEntrar)) 
		{
			blTermino = false;
			posText = Position.get(document.frmConsulta.szNumero);
			window.divNumCalles.style.left		= posText.left-5;
			window.divNumCalles.style.top		= posText.top - 45;
			window.divNumCalles.style.visibility = "visible";
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szCalle+'&szNumCalle='+szValor+'&szRegion='+szRegion;		
			//alert(szParametros);
			makeRequestNum('../emol_web/pgns_ajax/xmlListaNumCalle.php', szParametros, '2');
			PosCursor = 0;
			}
		else 
		{
				if ((szValor == ''))
				window.divNumCalles.style.visibility = "hidden";
		}
			
			if (ieKey == 40) 
			{
				var tbl = document.getElementById("TablaEncabezadoNum");
				var rows = tbl.getElementsByTagName("tr");
				var TotRow = rows.length;
				for(i = 0; i < rows.length; i++)
				{           
					   rows[i].className = ""; 
				} 
		   		if (PosCursor < TotRow ) 
				{
					PosCursor = PosCursor + 1;
				}
				if (PosCursor == rows.length)
				{
					PosCursor = rows.length - 1;
				}
				rows[PosCursor].className = "rover";
			}
			if (ieKey == 13) 
			{
				var tbl = document.getElementById("TablaEncabezadoNum");
				var rows = tbl.getElementsByTagName("tr");
				var lpRow = 0;
				for(i = 0; i < rows.length; i++)
				{           
					  if (rows[i].className == "rover")
					  	 lpRow = i; 
  					  if (rows.length==2)
					  { lpRow = i; FncEnviarConsulta(); }
				} 
				 if (lpRow != 0)
					FncLlenaTextNum(lpRow);
			}
			if (ieKey == 38) 
			{
				var tbl = document.getElementById("TablaEncabezadoNum");
				var rows = tbl.getElementsByTagName("tr");
				var TotRow = tbl.rows.length;
				if (PosCursor > 1) 
				{
					PosCursor = PosCursor - 1;
				}
				for(i = 0; i < rows.length; i++)
				{           
					   rows[i].className = ""; 
				} 
				if ((PosCursor == (TotRow - 1)))
					rows[TotRow].className = "rover";
				else 
				{
					rows[PosCursor + 1].className = "";
					rows[PosCursor].className = "rover";
				}
			}

//			40 tcla abajo
//			38 tcla arriba
}

function makeRequestNum(url, parameters, lpTipoAux) {
	http_request = false;
	lpTipo = lpTipoAux;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
		}
	}
	if (!http_request) {
		alert('No se puede crear instance XMLHTTP');
	return false;
	}
  
	url = url + parameters;
	//url = "../xml/xmlListaCalle.asp?szNombreCalle=EDUARDO&szComuna=PROVIDENCIA";
	http_request.onreadystatechange = alertContentsNum;
    http_request.open('GET', url, true);
    http_request.send(null);
}


function alertContentsNum() {
	LimpiaTablaNum("TablaEncabezadoNum");

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc = http_request.responseXML;
            var root = xmldoc.getElementsByTagName('root').item(0);
			
			for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
				var node = root.childNodes.item(iNode);
				for (i = 0; i < node.childNodes.length; i++) {
					var sibl = node.childNodes.item(i);
					var len = parseInt(sibl.childNodes.length / 2);
					var arr = new Array(len);
					var cnt = 0;
				  
					for (x = 0; x < sibl.childNodes.length; x++) {
						var sibl2 = sibl.childNodes.item(x);
						var sibl3;
						if (sibl2.childNodes.length > 0) {
							sibl3 = sibl2.childNodes.item(0);
							arr[cnt] = sibl3.data;   
							cnt++;
						}
					}
					window.divNumCalles.style.visibility = "hidden";
					//alert(arr[0]);
					addrowNum("TablaEncabezadoNum", arr);
				}
			}
			blTermino = true;
			//window.divCarga.style.visibility = "hidden";
         } else {
            alert('Se presento algun problema en la carga.');
         }
	}
}


function addrowNum(tablename, arr) {
	var tbl = document.getElementById(tablename);
	var lastRow = tbl.rows.length;
	var row = tbl.insertRow(lastRow);
	
	row.setAttribute('bgcolor', 'black');
	row.setAttribute('align', 'left');
	row.setAttribute('style', 'background-color: #567062; color: #e8eeeb; font-weight: bold; font-size: 8pt;');
	
	var nmCell = 0;
	for (r = 0; r < arr.length; r++) {   
		var cell = row.insertCell(r);
		if (nmCell == 0) {
			nmCell = 1;
			cell.setAttribute('align', 'left');
			cell.attachEvent("onclick", function(){ FncLlenaTextNum(lastRow); } );
		} else {
			nmCell = 0;
			cell.setAttribute('align', 'right');
		}				

		arr[r]=arr[r].replace(/^\s*|\s*$/g,"");
		if ( arr[r].substr(arr[r].length-1) =="-"){
			arr[r]=arr[r].substr(0,arr[r].length-1)
		}
		window.divNumCalles.style.visibility = "visible";
		cell.innerHTML =  arr[r];

	}
}


function FncLlenaTextNum(lpRow) {
	var x = document.getElementById('TablaEncabezadoNum').rows[lpRow].cells;
	document.frmConsulta.szNumero.value = x[0].innerHTML;
	window.divNumCalles.style.visibility = "hidden";
}

function LimpiaTablaNum(tablename) {
	var tbl = document.getElementById(tablename);
	for (var i=tbl.rows.length; tbl.rows.length > 1; i--) {
		tbl.deleteRow(tbl.rows.length - 1);
	}
}
/*******************************************/

function do_xml_comunas(szValor)
 {
 
		if (szValor != '')
			{
				blTermino = false;
				makeRequest('../emol_web/pgns_ajax/xmlListaComuna.php', '?szRegion='+ encodeURI(szValor), '1');
			}
		else
			{
			if (szValor == "")
			window.divCalles.style.visibility = "hidden";
			LimpiaComboComuna();
			}
	}

	var http_request = false;
	var blTermino = false;
	var lpTipo = '';
   
   function makeRequest(url, parameters, lpTipoAux)
    {
     
	  http_request = false;
	  lpTipo = lpTipoAux;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
	  if (!http_request) {
         alert('No se puede crear instance XMLHTTP');
         return false;
      }
	  
		  if (lpTipoAux=='3')
		  {
		  //alert('servicios');
		  http_request.onreadystatechange = alertContents2;
		  }
		  else
		  {
		  //alert('otros');
		  http_request.onreadystatechange = alertContents;
		  }
	  
     http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

   function alertContents() {
		if (lpTipo == '1') {
			LimpiaComboComuna();
			}
		else {
			  LimpiaTabla("TablaEncabezado");
		}

      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            var xmldoc = http_request.responseXML;
            var root = xmldoc.getElementsByTagName('root').item(0);
			window.divCalles.style.visibility = "hidden";
            for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
               var node = root.childNodes.item(iNode);
               for (i = 0; i < node.childNodes.length; i++) {
                  var sibl = node.childNodes.item(i);
                  var len = parseInt(sibl.childNodes.length / 2);
				  var arr = new Array(len);
                  var cnt = 0;
						// mostrar div con resultados mayores a uno			
/*
					  if (node.childNodes.length<=1 && lpTipo==2)
					  {
						window.divCalles.style.visibility = "hidden";
					  }
					  else if (node.childNodes.length >= 2 && lpTipo==2)
					  {
					  window.divCalles.style.visibility = "visible";
					  }
*/
/*
					  if (node.childNodes.length>0 && lpTipo==2)
					  {
					  	  alert("OK");
					  	  window.divCalles.style.visibility = "visible";				  	  
					  }
*/
                  for (x = 0; x < sibl.childNodes.length; x++) {
                     var sibl2 = sibl.childNodes.item(x);
                     var sibl3;
                     if (sibl2.childNodes.length > 0) {
                        sibl3 = sibl2.childNodes.item(0);
						arr[cnt] = sibl3.data;   
                        cnt++;
                     }
                  }
			
					if (lpTipo == '1')
					 {
						co_nombre[i] = arr[0];
						co_lon[i] = arr[2];
						co_lat[i] = arr[3];
					 	//alert(i+"\n0="+arr[0]+"\n1="+arr[1]+"\n2="+arr[2]+"\n3="+arr[3]);
						addListaComuna(arr[0], arr[0]);
					 }
					else 
					{
						addrow("TablaEncabezado", arr);
						//alert("OK");
					}
               }
            }
            
            setTimeout("do_xml_serv2();",200);
            
			blTermino = true;
         } else {
            alert('Se presento algun problema en la carga.');
         }
      }
   }

//*comuna
 function LimpiaComboComuna() {
 		var objComunas = document.getElementById('szListaComuna');
		for (var i = objComunas.options.length-1; i >= 0; i--)
			 objComunas.options[i]=null;

		var idxCmn = 0;
		objComunas.options[idxCmn] = new Option("Todas", "0");
	}

   function addListaComuna(szValueComuna, szTxtComuna)
    {
		var objComunas = document.getElementById('szListaComuna');
		var idxCmn = objComunas.options.length;
		objComunas.options[idxCmn] = new Option(szTxtComuna, szValueComuna);
	}


//*

//CALLE*
 function LimpiaTabla(tablename) 
 {
	var tbl = document.getElementById(tablename);
		for (var i=tbl.rows.length; tbl.rows.length > 1; i--) 
		{
			tbl.deleteRow(tbl.rows.length - 1);
		}
   }
  
 function addrow(tablename, arr)
  {
		
		var tbl = document.getElementById(tablename);
		var lastRow = tbl.rows.length;
		var row = tbl.insertRow(lastRow);
		row.setAttribute('bgcolor', 'black');
		row.setAttribute('align', 'left');
		row.setAttribute('style', 'background-color: #567062; color: #e8eeeb; font-weight: bold; font-size: 8pt;');
		var nmCell = 0;
		for (r = 0; r < arr.length - 1; r++) 
		{   
			var cell = row.insertCell(r);
				if (nmCell == 0) {
					nmCell = 1;
					cell.setAttribute('align', 'left');
					cell.attachEvent("onclick", function(){ FncLlenaText(lastRow); } );
					}
				else {
					nmCell = 0;
					cell.setAttribute('align', 'right');
					}
//			alert("ok");
            window.divCalles.style.visibility = "visible";				  	  
			//alert(arr[r]);//aaaaaaa
			cell.innerHTML = arr[r];
		}
		//alert("final");
	} 
	
	function FncLlenaText(lpRow) 
	{
		var x = document.getElementById('TablaEncabezado').rows[lpRow].cells;
		document.frmConsulta.szNombreCalle.value = x[0].innerHTML;
		window.divCalles.style.visibility = "hidden";
	}
   
//*

//nombre calle 

	var	tmr2 = 0;
	var TotRow = 0;
	var PosCursor = 0;
	
	function do_xml(szValor,Xobject)
	 {
		var ieKey = event.keyCode; var nKey=0;
		var strin = "Codice tecla in Explorer: " + ieKey;
		var blEntrar = false;
		if ((ieKey == 27 ) )
		 {
			blEntrar = false;
			window.divCalles.style.visibility = "hidden";
		 }

		if ((ieKey > 95 ) && (ieKey < 106))
		 {
			blEntrar = true;
		 }

		if ((ieKey == 8 )) 
		{
			blEntrar = true;
		}

		if (((ieKey > 64 ) && (ieKey < 91))) 
		{
			blEntrar = true;
		}
		if ((szValor != '') && (blEntrar)) 
		{
			blTermino = false;
			var val_input='nombreCalle';
			var oForm = document.frmConsulta;
			oForm.szNombreCalle.value = (document.frmConsulta.szNombreCalle.value).toUpperCase()
			szValor = oForm.szNombreCalle.value;
			//posicion del div de resultado
			posText = Position.get(Xobject);
			window.divCalles.style.left		= posText.left-5;
			window.divCalles.style.top		= posText.top - 45;
			window.divCalles.style.visibility = "visible";
			var szParametros = '?szNombreCalle='+encodeURIComponent(szValor);
			if (oForm.szRegion.value != '0')
			{
				szParametros = szParametros + '&szRegion=' + encodeURIComponent(oForm.szRegion.value);
			}

			if (oForm.szComuna.value != '0')
			{
				szParametros = szParametros + '&szComuna=' + encodeURIComponent(oForm.szComuna.value);
			}
			//path='../emol_web/pgns_ajax/xmlListaCalle.php'+szParametros;
			//document.getElementById('url_path').value=path;
			makeRequest('../emol_web/pgns_ajax/xmlListaCalle.php', szParametros, '2');
			PosCursor = 0;
			}
		else 
		{
				if ((szValor == ''))
				window.divCalles.style.visibility = "hidden";
		}
			
			if (ieKey == 40) 
			{
				var tbl = document.getElementById("TablaEncabezado");
				var rows = tbl.getElementsByTagName("tr");
				var TotRow = rows.length;
				for(i = 0; i < rows.length; i++)
				{           
					   rows[i].className = ""; 
				} 
		   		if (PosCursor < TotRow ) 
				{
					PosCursor = PosCursor + 1;
				}
				if (PosCursor == rows.length)
				{
					PosCursor = rows.length - 1;
				}
				rows[PosCursor].className = "rover";
			}
			if (ieKey == 13) 
			{
				var tbl = document.getElementById("TablaEncabezado");
				var rows = tbl.getElementsByTagName("tr");
				var lpRow = 0;
				for(i = 0; i < rows.length; i++)
				{           
					  if (rows[i].className == "rover")
					  	 lpRow = i; 
					  if (rows.length==2)
					  { lpRow = i; document.frmConsulta.szNumero.focus(); }
				} 
				 if (lpRow != 0)
					FncLlenaText(lpRow);
			}
			if (ieKey == 38) 
			{
				var tbl = document.getElementById("TablaEncabezado");
				var rows = tbl.getElementsByTagName("tr");
				var TotRow = tbl.rows.length;
				if (PosCursor > 1) 
				{
					PosCursor = PosCursor - 1;
				}
				for(i = 0; i < rows.length; i++)
				{           
					   rows[i].className = ""; 
				} 
				if ((PosCursor == (TotRow - 1)))
					rows[TotRow].className = "rover";
				else 
				{
					rows[PosCursor + 1].className = "";
					rows[PosCursor].className = "rover";
				}
			}

//			40 tcla abajo
//			38 tcla arriba
	}
	
//BUSCADOR 	
function FncBuscarDirEnter() 
{
		var ieKey = event.keyCode; var nKey=0;
		var strin = "Codice tecla in Explorer: " + ieKey;
		var blEntrar = false;
		estado_div = window.divNumCalles.style.visibility;
		if ((ieKey == 13 )&&(estado_div=="hidden"))
		 {
			blEntrar = true;
		}
		if (blEntrar)
			FncEnviarConsulta();
		else
		{
			xcomuna = document.frmConsulta.szComuna.value;
			xnombre_calle = document.frmConsulta.szNombreCalle.value;
			xnumero = document.frmConsulta.szNumero.value;
			xregion = document.frmConsulta.szRegion.value;
			do_xml_num(xnumero,xcomuna,xnombre_calle,xregion);
		}
	}
	
function FncEnviarConsulta()
 {
		var oFormMuestra = document.frmConsulta; 
		var oFormEnvia = document.dataForm; 
		if (oFormMuestra.szRegion.value == '0') 
		{
			oFormEnvia.region.value = ''; 
		}
		else
		{
			oFormEnvia.region.value = oFormMuestra.szRegion.value;
		}
		if (oFormMuestra.szComuna.value == '0') 
		{
			oFormEnvia.comuna.value = ''; 
		}
		else
		{
			oFormEnvia.comuna.value = oFormMuestra.szComuna.value;
		}

		oFormEnvia.calle.value = oFormMuestra.szNombreCalle.value;
		oFormEnvia.numero.value = oFormMuestra.szNumero.value;
		window.divCalles.style.visibility = "hidden";

		//window.MuestraDireccion.style.visibility = "visible";

		/*var objDirMuestra = document.getElementById('txDireccion');
		objDirMuestra.setAttribute('class', 'TBuscaDir');
		var szDirMuestra = "Direccion Buscada : " + oFormMuestra.szNombreCalle.value;
		alert(szDirMuestra);
		return false;
		if (oFormMuestra.szNumero.value == '')
			szDirMuestra = szDirMuestra + " [SIN NUMERO] ";
		else
			szDirMuestra = szDirMuestra + " #" + oFormMuestra.szNumero.value;
		
		if (oFormMuestra.szComuna.value == '0')
			szDirMuestra = szDirMuestra + ", [SIN COMUNA] ";
		else
			szDirMuestra = szDirMuestra + ", " + oFormMuestra.szComuna.value;
		var szValor = oFormMuestra.szRegion.value;
		var szEtqRegion = "";
		if (szValor == "R1 ") { szEtqRegion= "Region I ";} 
		if (szValor == "R2 ") { szEtqRegion= "Region II ";} 
		if (szValor == "R3 ") { szEtqRegion= "Region III ";} 
		if (szValor == "R4 ") { szEtqRegion= "Region IV ";} 
		if (szValor == "R5 ") { szEtqRegion= "Region V ";} 
		if (szValor == "R6 ") { szEtqRegion= "Region VI ";} 
		if (szValor == "R7 ") { szEtqRegion= "Region VII ";} 
		if (szValor == "R8 ") { szEtqRegion= "Region VIII ";} 
		if (szValor == "R9 ") { szEtqRegion= "Region IX ";} 
		if (szValor == "R10") { szEtqRegion= "Region X ";} 
		if (szValor == "R12") { szEtqRegion= "Region XII ";} 
		if (szValor == "RM ") { szEtqRegion= "Region RM";} 

		szDirMuestra = szDirMuestra + ", " + szEtqRegion;
		alert(szDirMuestra);
		//objDirMuestra.innerHTML = szDirMuestra;
		*/	
		//alert('ter');
		findDirection();
	}



function findDirection() 
{
		var oForm     = document.dataForm
		var reg       = oForm.region.value;
		var nom       = oForm.calle.value;
		var num       = oForm.numero.value;
		var com       = oForm.comuna.value;
		//alert("reg ="+reg+" nom="+nom+" num="+num+" com="+com);
	
		if (reg != "")
		 {
				if (nom != "")
				{
				if (num == "") num = 0;	
					var url = "../emol_web/buscadores/getDireccion.php?region="+reg+"&comuna="+com+"&calle="+nom+"&numero="+num; 	
					//document.getElementById('url_path').value=url;		
										
					//alert(url);
					checkName(url, '');
				} 
				
				
		} 
		else
		{
			alert("Informacion: Debe Seleccionar una Region");
		}
			
	
}


function checkName(url, response) {
		if (response!="") { 
			alert(response);
		}
		else {
			loadXMLDoc(url);
		}
	}

var req;

	function loadXMLDoc(url) {
		// branch for native XMLHttpRequest object
		
		if (window.XMLHttpRequest)
		{
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open("GET",url,true);
			req.send(null);
		}
		// branch for IE/Windows ActiveX version
		else if (window.ActiveXObject) 
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) 
			{
				req.onreadystatechange = processReqChange;
				req.open("GET",url,true);
//				alert ('2' + url); //o_O
				req.send();
			}
		}
	}
var dir_print='undefined';
function processReqChange() {

		if (req.readyState==4) {
			if (req.status==200) {
				response = req.responseXML.documentElement;
				var sta = response.getElementsByTagName('sta')[0].firstChild.data;


			var oForm = document.dataForm
			var reg = oForm.region.value;
			var nom = oForm.calle.value;
			var num = oForm.numero.value;
			var com = oForm.comuna.value;
			var params = "region="+reg+"&comuna="+com+"&calle="+nom+"&numero="+num;

			if (sta == 1) 
				{
					//alert('simple');
					lat      = response.getElementsByTagName('lat')[0].firstChild.data;
					lon      = response.getElementsByTagName('lon')[0].firstChild.data;
					txt      = response.getElementsByTagName('txt')[0].firstChild.data;

					lat = new Number(lat) 
					lon = new Number(lon) 
					
					
					Glon = "";
					Glat = "";
					Gtxt = "";
					//gotoXY(lat, lon, 10000, txt, mapaBase);
					//alert("lon="+lon+"\nlat="+lat);
					pos_emol(lon, lat); //ubica centro direccion 
					
					convert_geo_pix(lon,lat,txt);
						
					dir_print = txt;
//					var params = "region="+reg+"&comuna="+com+"&calle="+nom+"&numero="+num;
					//var params = "lat="+lat+"&lon="+lon+"&txt="+txt;
					//var Iframe = window.IFOptions;
					//Iframe.location.href = "../emol_web/buscadores/getDireccionOpcionesExacta.php?" + params;
//					var path_url_bsu="../emol_web/buscadores/getDireccionOpcionesExacta.php?" + params;
					var path_url_bsu="../emol_web/buscadores/getDireccionOpciones.php?" + params;

//					http://149.0.0.55/emol_web/buscadores/getDireccionopciones.php?region=RM&comuna=&calle=pasaje%20uno&numero=10

					cargar(path_url_bsu, 'result_dir') ;
				
					//alert(servicio_activo);
					

					document.getElementById('resultadoBusqueda').style.display = "block";
					/*
					document.getElementById('BannerLeft').style.display = "none";
					document.getElementById('listado_servicios').style.visibility = "visible";
					*/
					//AQUI APAGAR LAYERS
					//FncApagaCapas();
				} 
				else
				 {
													
					var Iframe = window.IFOptions;
					//Iframe.location.href = "../emol_web/buscadores/getDireccionOpciones.php?" + params;
					var path_url_bsu="../emol_web/buscadores/getDireccionOpciones.php?" + params;							
					cargar(path_url_bsu, 'result_dir') ;
					//document.getElementById('url_path').value="../emol_web/buscadores/getDireccionOpciones.php?" + params;;		
					document.getElementById('resultadoBusqueda').style.display = "block";
					/*
					document.getElementById('BannerLeft').style.display = "none";
					document.getElementById('listado_servicios').style.visibility = "visible";
					*/
				}
				/*
				if (servicio_activo!='')
					{
						document.getElementById(servicio_activo).style.border=0;
						document.getElementById(servicio_activo).style.backgroundColor="";
						servicio_activo='';
					}
					*/
			}
			else
				alert("Se produjo un error recibiendo los datos XML:\n" + req.statusText);
		}
		
	}





var tmpimgAct 	= "";
function fntShowPosition(lat, lon , txt,imgAct,tipo_resu) 
{
Glon = "";
Glat = "";
Gtxt = "";
txt=txt.replace('-','');
dir_print = txt;

	if (tipo_resu=='exacta')
	{
	 pos_emol(lon, lat);
	 convert_geo_pix(lon,lat,txt);
	 
	}
	 else
	{
	
		if (tmpimgAct != "") 
		{
		
		var TDtbl = document.getElementById(tmpimgAct);
		TDtbl.src = "../imagenes/iconos_servicios/globo_resultado_off.gif";
		tmpimgAct = imgAct;
		
		}
		
		var TDtbl = document.getElementById(imgAct);
		
		TDtbl.src = "../imagenes/iconos_servicios/icon_resultado_busqueda.gif";
	
		//mapFrame.arr_Localizaciones.length = 0;
		//mapFrame.arr_Localizaciones[0] = [lat, lon, txt];	
		//evita que recarga pagna al presionar nuevamente misma direccion
		
		
	  	pos_emol(lon, lat);
		convert_geo_pix(lon,lat,txt);
		tmpimgAct = imgAct
		do_xml_serv2();
	}
}

//cierra tabla resultado de busqueda
function CerrarResultado() {
		document.getElementById('resultadoBusqueda').style.display = "none";
		/*
		document.getElementById('BannerLeft').style.display = "block";
		document.getElementById('listado_servicios').style.visibility = "hidden";
		*/
	}

function LimpiarResultado() {
		document.getElementById('resultadoBusqueda').style.display = "none";
		/*
		document.getElementById('BannerLeft').style.display = "block";
		document.getElementById('listado_servicios').style.visibility = "hidden";
		*/
		document.frmConsulta.szRegion.value = "RM ";
		document.frmConsulta.szComuna.value = "0";
		document.frmConsulta.szNombreCalle.value = "";
		document.frmConsulta.szNumero.value = "";
		do_xml_comunas(document.frmConsulta.szRegion.value);
//		cambia_region();
//		if (tpServ!="")	do_xml_serv(tpServ);
//		i_serv = 0;
		document.all.dire.innerHTML = "";
		Glon = "";
		Glat = "";
		Gtxt = "";
}

//*** ccortes
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 cargar(fragment_url, element_id) 
{ 	var element = document.getElementById(element_id); 
	//alert(element)
	element.innerHTML = '<table width="240" height="100" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td align="center">&nbsp;</td></tr><tr><td height="20" align="center"><table width="100" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><img src="../imagenes/cargando.gif" width="16" height="16"/></td></tr><tr><td align="center" class="textos">cargando</td></tr></table></td></tr><tr><td align="center">&nbsp;</td></tr></table>'; 
	peticion.open("GET", fragment_url); 
	peticion.onreadystatechange = function() { 
		if (peticion.readyState == 4) { 
			//if(peticion.status==200) { 
				element.innerHTML = peticion.responseText;
			//} 				
		} 
	} 
	peticion.send(null); 
}

//****



//************* SERVICIOS *****************//

var servicio_activo='';
var tpServ	= "";
var	tmr_serv = 0;
var TotRow_serv = 0;
var PosCursor_serv = 0;
	function do_xml_serv (szValor) {
		servicio_activo=szValor;
		var szParametros = '?szNombreServicio=' + szValor;
		var oForm =  document.frmConsulta;
		if ((tpServ == szValor)) 
		 {
			/*document.getElementById('listado_servicios').style.visibility = "hidden";*/
		 	
			//o_O sacar frame
//			window["listado_servicios"].document.body.innerHTML = '';
			document.getElementById('listado_servicios').innerHTML = '';	
			
			color_servicios = 0;
			i_serv = 0;
			remove_servicios('serv');
			var TDtbl = document.getElementById("img" + tpServ);
			TDtbl.src = "../imagenes/iconos_servicios/icono_" + tpServ + "_up.gif";
			document.getElementById(szValor).style.border=0;
			document.getElementById(szValor).style.backgroundColor="";
			
			//fncElimarServicios();
			//arr_LocalizacionesServicios.length = 0;
			//arr_CapaLocalizacionesServicios.length = 0;
			tpServ = "";
			return 0;
			}
		else {	
					/*
					alert("b");
					document.getElementById('BannerLeft').style.display = "none";
					document.getElementById('listado_servicios').style.visibility = "visible";
					*/

				if (tpServ != "") {
					i_serv = 0;
					var TDtbl = document.getElementById("img" + tpServ);
					TDtbl.src = "../imagenes/iconos_servicios/icono_" + tpServ + "_up.gif";
					var TDtbl = document.getElementById(tpServ);
					TDtbl.style.backgroundColor = "";
					TDtbl.style.border = "0";
					remove_servicios('serv');	
					}
							
				var TDtbl = document.getElementById("img" + szValor);
				TDtbl.src = "../imagenes/iconos_servicios/icono_" + szValor + "_down.gif";

				var TDtbl = document.getElementById(szValor);
				TDtbl.style.backgroundColor = "#DFEAF5";
				TDtbl.style.border = "#2982D6 solid 1px";
				tpServ	= szValor;
		}
		
		if (oForm.szRegion.value != '0'){
			szParametros = szParametros + '&szRegion=' + encodeURI(oForm.szRegion.value);
		}

		var extents = myKaMap.getGeoExtents();
		var cx1 = extents[0];
		var cx2 = extents[2];
		var cy1 = extents[1];
		var cy2 = extents[3];
		//		agregamos parametros de la extension del mapa
		var urlEXT = '&X1=' + cx1 + '&X2='  + cx2  + '&Y1=' + cy1 +'&Y2=' +	cy2;
		
		szParametros=szParametros+urlEXT;
			//document.frmConsulta.sql.value = szParametros;
//			return;
		//alert(szParametros);
		//document.getElementById('url_path').value='../emol_web/pgns_ajax/xmlListaServicios.php'+szParametros;
		makeRequest('../emol_web/pgns_ajax/xmlListaServicios.php', szParametros, '3');
	
	PosCursor_serv = 0;
	}


function do_xml_serv2 () {
		if (tpServ!='')
		{	
			var szValor='';
			szValor = tpServ;
			
			remove_servicios('serv');
			var TDtbl = document.getElementById("img" + tpServ);
			TDtbl.src = "../imagenes/iconos_servicios/icono_" + tpServ + "_up.gif";
			document.getElementById(szValor).style.border=0;
			document.getElementById(szValor).style.backgroundColor="";			

			servicio_activo=szValor;
			var szParametros = '?szNombreServicio=' + szValor;
			var oForm =  document.frmConsulta;

					if (tpServ != "") {
						/*
						alert("aa");
						document.getElementById('BannerLeft').style.display = "none";
						document.getElementById('listado_servicios').style.visibility = "visible";
						*/

						var TDtbl = document.getElementById("img" + tpServ);
						TDtbl.src = "../imagenes/iconos_servicios/icono_" + tpServ + "_up.gif";
						var TDtbl = document.getElementById(tpServ);
						TDtbl.style.backgroundColor = "";
						TDtbl.style.border = "0";
						remove_servicios('serv');	
						}
						
					
					var TDtbl = document.getElementById("img" + szValor);
					TDtbl.src = "../imagenes/iconos_servicios/icono_" + szValor + "_down.gif";

					var TDtbl = document.getElementById(szValor);
					TDtbl.style.backgroundColor = "#DFEAF5";
					TDtbl.style.border = "#2982D6 solid 1px";
					tpServ	= szValor;

			var extents = myKaMap.getGeoExtents();
			var cx1 = extents[0];
			var cx2 = extents[2];
			var cy1 = extents[1];
			var cy2 = extents[3];
			//		agregamos parametros de la extension del mapa
			var urlEXT = '&X1=' + cx1 + '&X2='  + cx2  + '&Y1=' + cy1 +'&Y2=' +	cy2;
			//alert(urlEXT);
			szParametros=szParametros+urlEXT;		
//			document.frmConsulta.sql.value = szParametros;
//			return;
			//document.getElementById('url_path').value='../emol_web/pgns_ajax/xmlListaServicios.php'+szParametros;
			makeRequest('../emol_web/pgns_ajax/xmlListaServicios.php', szParametros, '3');
		
			PosCursor_serv = 0;
		}
	}


var arr_LocalizacionesServicios = new Array();

function alertContents2() 
{
	arr_LocalizacionesServicios.length=0;
		var szGifServ = "globo_";
		if (tpServ == 'CARGA_BIP_METRO') 	szGifServ = "globo_metro";
		if (tpServ == 'CARGA_BIP_LOCAL')	szGifServ = "globo_bip";
		if (tpServ == 'CAJEROS')			szGifServ = "globo_redbank";
		if (tpServ == 'MUSEO')				szGifServ = "globo_MUSEO";
		if (tpServ == 'SUPERMERCADO')		szGifServ = "globo_supermercado";
		if (tpServ == 'CINES') 				szGifServ = "globo_cines";			
		if (tpServ == 'BAR Y PUB S') 		szGifServ = "globo_pubs";						
		if (tpServ == 'RESTAURANTES')		szGifServ = "globo_restaurant";			
		if (tpServ == 'HOTELES')			szGifServ = "globo_hoteles";
		if (tpServ == 'MOTELES')			szGifServ = "globo_Moteles";						
		if (tpServ == 'BANCOS')				szGifServ = "globo_banco";			
		if (tpServ == 'CARABINEROS')		szGifServ = "globo_carabineros";	
		if (tpServ == 'IGLESIAS')			szGifServ = "globo_iglesias";					
		if (tpServ == 'CENTRO COMERCIAL')	szGifServ = "globo_centrocomercial";	
		if (tpServ == 'MUNICIPALIDAD')		szGifServ = "globo_municipalidad";								
		if (tpServ == 'FARMACIAS')			szGifServ = "globo_farmacias";						
		if (tpServ == 'MALL')					szGifServ = "globo_mall";	
		if (tpServ == 'SERVICIO DE URGENCIA')	szGifServ = "globo_SERVICIOURGENCIA";	
		if (tpServ == 'TEATRO')				szGifServ = "globo_TEATRO";					
					
			
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            var xmldoc = http_request.responseXML;
            var root = xmldoc.getElementsByTagName('root').item(0);
            for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
               var node = root.childNodes.item(iNode);
               for (i = 0; i < node.childNodes.length; i++) 
			   {
					
                  var sibl = node.childNodes.item(i);
                  var len = parseInt(sibl.childNodes.length / 2);
                  var arr = new Array(len);
                  var cnt = 0;
				  
                  for (x = 0; x < sibl.childNodes.length; x++) 
				  {
                     var sibl2 = sibl.childNodes.item(x);
                     var sibl3;
                     if (sibl2.childNodes.length > 0) {
                        sibl3 = sibl2.childNodes.item(0);
						//alert(sibl3.data);
                        arr[cnt] = sibl3.data;   
						cnt++;
                     }
					
                  }
				if (arr[0] != 'VACIO' )
					{
					arr_LocalizacionesServicios[arr_LocalizacionesServicios.length] = [arr[0], arr[1], arr[2], szGifServ, arr[3]];	
//					alert(arr_LocalizacionesServicios.length);
			}
					
               }
            }
			blTermino = true;
					 pub_servicios(szGifServ);
         } else {
            alert('Se presento algun problema en la carga.');
         }
      }
	  
   }
	
	
	function pub_servicios() {
//alert(arr_LocalizacionesServicios.length );
		noCargaMinimap=true;
		var idx = 0;
		for (idx = 0; idx < arr_LocalizacionesServicios.length ; idx++) {
				servicios( idx,arr_LocalizacionesServicios[idx][1],arr_LocalizacionesServicios[idx][0], arr_LocalizacionesServicios[idx][2],arr_LocalizacionesServicios[idx][3],arr_LocalizacionesServicios[idx][4]);
			}
		
		itexto_servicios = itexto_servicios + "</table>";
		
		//apaga el resultado de las direcciones y coloca el resultado de los servicios o_O
		//document.getElementById('resultadoBusqueda').style.display = 'none';
		document.getElementById('resultadoServicios').style.display = 'block';
		document.getElementById('listado_servicios').innerHTML = itexto_servicios;
		//o_O prueba
		//itexto_servicios = "<html><body><table border='0' cellpadding='0' cellspacing='0' align='left' width='243'>";
		itexto_servicios = "<table border='0' cellpadding='2' cellspacing='0' align='left' width='100%'>";
		noCargaMinimap=false;
		color_servicios = 0;
}














/**

 * Copyright (c)2005-2007 Matt Kruse (javascripttoolbox.com)

 * 

 * Dual licensed under the MIT and GPL licenses. 

 * This basically means you can use this code however you want for

 * free, but don't claim to have written it yourself!

 * Donations always accepted: http://www.JavascriptToolbox.com/donate/

 * 

 * Please do not link to the .js files on javascripttoolbox.com from

 * your site. Copy the files locally to your server instead.

 * 

 */

var Position = (function() {

  // Resolve a string identifier to an object

  // ========================================

  function resolveObject(s) {

    if (document.getElementById && document.getElementById(s)!=null) {

      return document.getElementById(s);

    }

    else if (document.all && document.all[s]!=null) {

      return document.all[s];

    }

    else if (document.anchors && document.anchors.length && document.anchors.length>0 && document.anchors[0].x) {

      for (var i=0; i<document.anchors.length; i++) {

        if (document.anchors[i].name==s) { 

          return document.anchors[i]

        }

      }

    }

  }

  

  var pos = {};

  pos.$VERSION = 1.0;

  

  // Set the position of an object

  // =============================

  pos.set = function(o,left,top) {

    if (typeof(o)=="string") {

      o = resolveObject(o);

    }

    if (o==null || !o.style) {

      return false;

    }

    

    // If the second parameter is an object, it is assumed to be the result of getPosition()

    if (typeof(left)=="object") {

      var pos = left;

      left = pos.left;

      top = pos.top;

    }

    

    o.style.left = left + "px";

    o.style.top = top + "px";

    return true;

  };

  

  // Retrieve the position and size of an object

  // ===========================================

  pos.get = function(o) {

    var fixBrowserQuirks = true;

      // If a string is passed in instead of an object ref, resolve it

    if (typeof(o)=="string") {

      o = resolveObject(o);

    }

    

    if (o==null) {

      return null;

    }

    

    var left = 0;

    var top = 0;

    var width = 0;

    var height = 0;

    var parentNode = null;

    var offsetParent = null;

  

    

    offsetParent = o.offsetParent;

    var originalObject = o;

    var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references

    while (el.parentNode!=null) {

      el = el.parentNode;

      if (el.offsetParent==null) {

      }

      else {

        var considerScroll = true;

        /*

        In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 

        take its scroll position into account. If elements further up the chain are scrollable, their 

        scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value

        which must be ignored.

        */

        if (fixBrowserQuirks && window.opera) {

          if (el==originalObject.parentNode || el.nodeName=="TR") {

            considerScroll = false;

          }

        }

        if (considerScroll) {

          if (el.scrollTop && el.scrollTop>0) {

            top -= el.scrollTop;

          }

          if (el.scrollLeft && el.scrollLeft>0) {

            left -= el.scrollLeft;

          }

        }

      }

      // If this node is also the offsetParent, add on the offsets and reset to the new offsetParent

      if (el == offsetParent) {

        left += o.offsetLeft;

        if (el.clientLeft && el.nodeName!="TABLE") { 

          left += el.clientLeft;

        }

        top += o.offsetTop;

        if (el.clientTop && el.nodeName!="TABLE") {

          top += el.clientTop;

        }

        o = el;

        if (o.offsetParent==null) {

          if (o.offsetLeft) {

            left += o.offsetLeft;

          }


          if (o.offsetTop) {

            top += o.offsetTop;

          }

        }

        offsetParent = o.offsetParent;

      }

    }

    

  

    if (originalObject.offsetWidth) {

      width = originalObject.offsetWidth;

    }

    if (originalObject.offsetHeight) {

      height = originalObject.offsetHeight;

    }

    

    return {'left':left, 'top':top, 'width':width, 'height':height

        };

  };

  

  // Retrieve the position of an object's center point

  // =================================================

  pos.getCenter = function(o) {

    var c = this.get(o);

    if (c==null) { return null; }

    c.left = c.left + (c.width/2);

    c.top = c.top + (c.height/2);

    return c;

  };

  

  return pos;

})();

