var blTermino    = false;
var http_request = false;
var TotRow       = 0;
var PosCursor    = 0;
var objCalle     ;
var objNum		 ;
var objDep		 ;

var expl = 0;

/***********************************************************
FUNCIONES PUBLICAS
***********************************************************/

function findPosX(obj)
		  {
			var curleft = 0;
			if(obj.offsetParent)
				while(1) 
				{
				  curleft += obj.offsetLeft;
				  if(!obj.offsetParent)
					break;
				  obj = obj.offsetParent;
				}
			else if(obj.x)
				curleft += obj.x;
			return curleft;
			
}
function findPosY(obj)
		  {
			var curtop = 0;
			if(obj.offsetParent)
				while(1)
				{
				  curtop += obj.offsetTop;
				  if(!obj.offsetParent)
					break;
				  obj = obj.offsetParent;
				}
			else if(obj.y)
				curtop += obj.y;
			return curtop;
}

/***********************************************************
FUNCIONES PUBLICAS
***********************************************************/
function do_xml(paramObj, szComuna, top, left, e) {
	/*Validar Tecla Presionada */
	objCalle = paramObj
	szValor  = objCalle.value.toUpperCase();
	
	//alert(szValor + ' - ' +szComuna+' - '+top + ' - '+left+' - '+e)
	
    //var ieKey = nav4 ? event.which : event.keyCode;
	//alert(window.event.which + " - " + e.keyCode)
	var ieKey;
	if (e.which){
		//alert("which")
		ieKey = e.which;
		expl = 1;
	}else{
		//alert("keyCode")
		ieKey = e.keyCode;
	}
	//var ieKey = nav4 ? e.which : e.keyCode;

	//var ieKey = event.keyCode;

	//alert(ieKey)
	
	if (ieKey == 8)
	{
		document.getElementById("divNumCalles").style.visibility = "hidden";
	}

	var nKey  =0;
	var strin = "Codice tecla in Explorer: " + ieKey;
	var blEntrar = false;

	if ((ieKey > 95 ) && (ieKey < 106)) {blEntrar = true;}
	if ((ieKey == 8 )) {blEntrar = true;}
	if (((ieKey > 64 ) && (ieKey < 91))) {blEntrar = true;}
	if (ieKey == 49) {blEntrar=false; }
	
	//alert(szValor + ' -- ' + blEntrar)
	if (szValor != '' && blEntrar) {
			blTermino = false;
			//window.divCarga.style.visibility = "visible";
			document.getElementById("divCalles").style.visibility = "visible";
			//window.divCalles.style.visibility = "visible";
			
			document.getElementById("divCalles").style.top = top+"px";
			document.getElementById("divCalles").style.left = left+"px";
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szValor;	
			//alert(szParametros);
			makeRequest('xml/xmlListaCalle.asp', szParametros, '2');
		}else{
			if (szValor == '') {document.getElementById("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 (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";
				}
			}
		}
	}


//**********************************
function do_xml_num(paramObj, szComuna, top, left, e) {
	/*Validar Tecla Presionada */
	objCalle = paramObj
	szValor  = objCalle.value.toUpperCase();
	
	//alert(szValor + ' - ' +szComuna+' - '+top + ' - '+left+' - '+e)
	
    //var ieKey = nav4 ? event.which : event.keyCode;
	//alert(window.event.which + " - " + e.keyCode)
	var ieKey;
	if (e.which){
		//alert("which")
		ieKey = e.which;
		expl = 1;
	}else{
		//alert("keyCode")
		ieKey = e.keyCode;
	}
	//var ieKey = nav4 ? e.which : e.keyCode;

	//var ieKey = event.keyCode;

	//alert(ieKey)
	
	var nKey  =0;
	var strin = "Codice tecla in Explorer: " + ieKey;
	var blEntrar = false;
	//alert(ieKey)
	if ((ieKey > 95 ) && (ieKey < 106)) {blEntrar = true;}
	if ((ieKey == 8 )) {blEntrar = true;}
	if (((ieKey > 64 ) && (ieKey < 91))) {blEntrar = true;}
	if (ieKey == 49) {blEntrar=False; }
	
	//alert(szValor + ' -- ' + blEntrar)
	if (szValor != '' && blEntrar) {
			blTermino = false;
			//window.divCarga.style.visibility = "visible";
			document.getElementById("divCalles").style.visibility = "visible";
			//window.divCalles.style.visibility = "visible";
			
			document.getElementById("divCalles").style.top = top+"px";
			document.getElementById("divCalles").style.left = left+"px";
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szValor;	
			//alert(szParametros);
			makeRequest('xml/xmlListaCalle.asp', szParametros, '2');
		}else{
			if (szValor == '') {document.getElementById("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 (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";
				}
			}
		}
	}

//********************************************************************















	/* para las regiones */
function do_xml_Comunas(paramNum) {

	if (paramNum != '') {
		blTermino = false;
		makeRequestDir('xml/xmlregiones.asp', "region="+paramNum, '2');
	}
	else if (paramNum==""){
		var oForm = document.oForm; 
			
		var ocomuna = oForm.comuna;
		for (var i=ocomuna.options.length-1;i>=0;i--) {
			ocomuna.options[i]=null;
		}
			ocomuna.options[0] = new Option('Seleccione Comuna...', '');
			ocomuna.disabled = true;
	}
}

function makeRequestDir(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;
	//window.alert(url);
	//url = "../xml/xmlListaCalle.asp?szNombreCalle=EDUARDO&szComuna=PROVIDENCIA";
	http_request.onreadystatechange = alertContentsDir;
    http_request.open('GET', url, true);
    http_request.send(null);
}

function alertContentsDir() {
	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++;
						}
					}
					fntShowComuna(arr,i);
				}
			}
			blTermino = true;
			} else {
            alert('Se presento algun problema en la carga.');
         }
	}
}

function fntShowComuna(arr,indice) {
	var oForm = document.oForm; 
	var ocomuna = oForm.comuna;

	//Limpiar Combo Comuna
	if (indice==0){
		for (var i=ocomuna.options.length-1;i>=0;i--) {
		ocomuna.options[i]=null;
		}
	}

	//Llenar Datos para Regiones
	arr = arr.toString();
	var arreglo;
	arreglo = arr.split(",");
	if (indice==0){
		ocomuna.disabled = false;
		ocomuna.options[0] = new Option('Seleccione Comuna...', '');
		ocomuna.options[1] = new Option(arreglo[1], arreglo[1]);
	}
	else
	{
		ocomuna.options[ocomuna.options.length] = new Option(arreglo[1], arreglo[1]);
	}
}



/***********************************************************
FUNCIONES PRIVADAS
***********************************************************/
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;
	}
  
	url = url + parameters;
	//url = "../xml/xmlListaCalle.asp?szNombreCalle=EDUARDO&szComuna=PROVIDENCIA";
	http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
    http_request.send(null);
}


function alertContents() {
	LimpiaTabla("TablaEncabezado");
//alert (http_request.readyState)
	if (http_request.readyState == 4) {
//alert (http_request.status == 200)
		if (http_request.status == 200) {
			var xmldoc = http_request.responseXML;
            var root = xmldoc.getElementsByTagName('root').item(0);
			//alert(root.childNodes.length)
			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++;
						}
					}
					
					addrow("TablaEncabezado", arr);
				}
			}
			blTermino = true;
			//window.divCarga.style.visibility = "hidden";
         } else {
            alert('Se presento algun problema en la carga.');
         }
	}
}


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: #ffffff; 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');

			//var nav4 = window.event.keyCode ? true : false;

			if (expl == 1){
				cell.addEventListener("click", function(){ FncLlenaText(lastRow); },false );
			}else{
				cell.attachEvent("onclick", function(){ FncLlenaText(lastRow); } );
			}
		
		} else {
			nmCell = 0;
			cell.setAttribute('align', 'right');
		}
		cell.innerHTML = arr[r];
	}
}


function FncLlenaText(lpRow) {
	var x = document.getElementById('TablaEncabezado').rows[lpRow].cells;
	objCalle.value = x[0].innerHTML;
	//window.divCalles.style.visibility = "hidden";
	document.getElementById('divCalles').style.visibility = "hidden";
}

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);
	}
}


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
    }
}


//*************************************************************************************************************//

/***********************************************************
FUNCIONES PUBLICAS
***********************************************************/
function do_xml_num(paramObj, szComuna, szCalle, top, left, e) {
	/*Validar Tecla Presionada */
	objNum = paramObj
	szValor = 0;
	szValor  = objNum.value.toUpperCase();

	//var nav4 = window.Event ? true : false;
	//var ieKey = event.keyCode;
    //var ieKey = nav4 ? e.which : e.keyCode;
	
	var ieKey;
	if (e.which){
		//alert("which")
		ieKey = e.which;
		expl = 1;
	}else{
		//alert("keyCode")
		ieKey = e.keyCode;
	}
	
	var nKey  =0;
	var strin = "Codice tecla in Explorer: " + ieKey;
	var blEntrar = true;
	              if (48 <= ieKey && ieKey <= 57) {blEntrar = true;}
				  if ((ieKey == 8 )) {blEntrar = true;}
                //permitir acceso de numeros "numpad"
				 if (96 <= ieKey && ieKey <= 105) {blEntrar = true;}


	if (isNaN(parseInt(szValor))) {	
		//alert('aka vs1');
		//return;
	}
	
		if (szValor != '' && blEntrar) {
	//alert('aka')
			blTermino = false;
			document.getElementById('divNumCalles').style.visibility = "visible";
			//window.divNumCalles.style.visibility = "visible";
			
			document.getElementById('divNumCalles').style.top = top+"px";
			document.getElementById('divNumCalles').style.left = left+"px";
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szCalle+'&szNumCalle='+szValor;		
			//alert(szParametros);
			makeRequestNum('xml/xmlListaNumCalle.asp', szParametros, '2');
			//alert('22323')
			}
		else {
			//alert(szValor);
			if (szValor == '') {document.getElementById('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 (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";
				}
			}
		}
	}


/***********************************************************
FUNCIONES PRIVADAS
***********************************************************/
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() {
	LimpiaTabla("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++;
						}
					}
					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: #ffffff; 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');
			
			//var nav4 = window.Event ? true : false;
			if (expl == 1){
				cell.addEventListener("click", function(){ FncLlenaTextNum(lastRow); },false );
			}else{
				cell.attachEvent("onclick", function(){ FncLlenaTextNum(lastRow); } );
			}

			/*if (nav4){
				cell.addEventListener("click", function(){ FncLlenaTextNum(lastRow); },false );
			}else{
				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)
		}
		cell.innerHTML =  arr[r];

	}
}


function FncLlenaTextNum(lpRow) {
	var x = document.getElementById('TablaEncabezadoNum').rows[lpRow].cells;
	objNum.value = x[0].innerHTML;
	document.getElementById('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);
	}
}


//*************************************************************************************************************//

/***********************************************************
FUNCIONES PUBLICAS
***********************************************************/
function do_xml_dep(paramObj, szComuna, szCalle, lpNum, top, left) {
	//alert(szComuna + "  " + szCalle + " " +  lpNum)
	objDep = paramObj
	szValor  = objDep.value.toUpperCase();
	var ieKey = event.keyCode; 
	var nKey  =0;
	var strin = "Codice tecla in Explorer: " + ieKey;
	var blEntrar = false;

	if ((ieKey > 95 ) && (ieKey < 106)) {blEntrar = true;}
	if ((ieKey == 8 )) {blEntrar = true;}
	if (((ieKey > 64 ) && (ieKey < 91))) {blEntrar = true;}

	if (szValor != '' && blEntrar) {
			blTermino = false;
			/*window.divCarga.style.visibility = "visible";*/
			window.divDep.style.visibility = "visible";
			window.divDep.style.top = top;
			window.divDep.style.left = left;
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szCalle+'&szNumCalle='+lpNum+'&lpNumEd='+szValor;		
			makeRequestDep('../xml/xmlListaEd.asp', szParametros, '2');
			}
		else {
			if (szValor == '') {window.divDep.style.visibility = "hidden";}
			
			if (ieKey == 40) {
				var tbl = document.getElementById("TablaEncabezadoDep");
				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("TablaEncabezadoDep");
				var rows = tbl.getElementsByTagName("tr");
				var lpRow = 0;
				for(i = 0; i < rows.length; i++){           
					if (rows[i].className == "rover")
						lpRow = i; 
				   } 
				if (lpRow != 0)
					FncLlenaTextDep(lpRow);
			}

			if (ieKey == 38) {
				var tbl = document.getElementById("TablaEncabezadoDep");
				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";
				}
			}
		}
	}


/***********************************************************
FUNCIONES PRIVADAS
***********************************************************/
function makeRequestDep(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;
	http_request.onreadystatechange = alertContentsDep;
    http_request.open('GET', url, true);
    http_request.send(null);
}

function alertContentsDep(){
	LimpiaTabla("TablaEncabezadoDep");

	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++;
						}
					}
					addrowDep("TablaEncabezadoDep", arr);
				}
			}
			blTermino = true;
			//window.divCarga.style.visibility = "hidden";
         } else {
            alert('Se presento algun problema en la carga.');
         }
	}
}


function addrowDep(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: #ffffff; 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(){ FncLlenaTextDep(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)
		}
		cell.innerHTML =  arr[r];

	}
}

function FncLlenaTextDep(lpRow) {
	var x = document.getElementById('TablaEncabezadoDep').rows[lpRow].cells;
	objNum.value = x[0].innerHTML;
	window.divDep.style.visibility = "hidden";
}

function LimpiaTablaDep(tablename) {
	var tbl = document.getElementById(tablename);
	for (var i=tbl.rows.length; tbl.rows.length > 1; i--) {
		tbl.deleteRow(tbl.rows.length - 1);
	}
}

/***********************************************************
FUNCIONES PUBLICAS
***********************************************************/
function do_xml_dos(paramObj, szComuna, top, left) {
	/*Validar Tecla Presionada */
	objCalle = paramObj
	szValor  = objCalle.value.toUpperCase();
	var ieKey = event.keyCode; 
	var nKey  =0;
	var strin = "Codice tecla in Explorer: " + ieKey;
	var blEntrar = false;

	if ((ieKey > 95 ) && (ieKey < 106)) {blEntrar = true;}
	if ((ieKey == 8 )) {blEntrar = true;}
	if (((ieKey > 64 ) && (ieKey < 91))) {blEntrar = true;}

	if (szValor != '' && blEntrar) {
			blTermino = false;
			/*window.divCarga.style.visibility = "visible";*/
			window.divCalles.style.visibility = "visible";
			window.divCalles.style.top = top;
			window.divCalles.style.left = left;
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szValor;		
			makeRequest2('xml/xmlListaCalle.asp', szParametros, '2');
			}
		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 (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";
				}
			}
		}
	}


/***********************************************************
FUNCIONES PRIVADAS
***********************************************************/
function makeRequest2(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 = alertContents2;
    http_request.open('GET', url, true);
    http_request.send(null);
}


function alertContents2() {
	LimpiaTabla2("TablaEncabezado");

	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++;
						}
					}
					
					addrow2("TablaEncabezado", arr);
				}
			}
			blTermino = true;
			//window.divCarga.style.visibility = "hidden";
         } else {
            alert('Se presento algun problema en la carga.');
         }
	}
}


function addrow2(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: #ffffff; 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(){ FncLlenaText(lastRow); } );
		} else {
			nmCell = 0;
			cell.setAttribute('align', 'right');
		}					
		cell.innerHTML = arr[r];
	}
}


function FncLlenaText2(lpRow) {
	var x = document.getElementById('TablaEncabezado').rows[lpRow].cells;
	objCalle.value = x[0].innerHTML;
	window.divCalles.style.visibility = "hidden";
}

function LimpiaTabla2(tablename) {
	var tbl = document.getElementById(tablename);
	for (var i=tbl.rows.length; tbl.rows.length > 1; i--) {
		tbl.deleteRow(tbl.rows.length - 1);
	}
}


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
    }
}


//*************************************************************************************************************//
//*************************************************************************************************************//


function do_xml_robo(paramObj, szComuna, top, left) {
	/*Validar Tecla Presionada */
	objCalle = paramObj
	szValor  = objCalle.value.toUpperCase();
	var ieKey = event.keyCode; 
	var nKey  =0;
	var strin = "Codice tecla in Explorer: " + ieKey;
	var blEntrar = false;

	if ((ieKey > 95 ) && (ieKey < 106)) {blEntrar = true;}
	if ((ieKey == 8 )) {blEntrar = true;}
	if (((ieKey > 64 ) && (ieKey < 91))) {blEntrar = true;}

	if (szValor != '' && blEntrar) {
			blTermino = false;
			/*window.divCarga.style.visibility = "visible";*/
			window.divCalles.style.visibility = "visible";
			window.divCalles.style.top = top;
			window.divCalles.style.left = left;
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szValor;		
			makeRequest_robo('../xml/xmlListaCalle.asp', szParametros, '2');
			}
		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 (lpRow != 0)
					FncLlenaText_robo(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";
				}
			}
		}
	}


/***********************************************************
FUNCIONES PRIVADAS
***********************************************************/
function makeRequest_robo(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 = alertContents_robo;
    http_request.open('GET', url, true);
    http_request.send(null);
}


function alertContents_robo() {
	LimpiaTabla_robo("TablaEncabezado");

	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++;
						}
					}
					
					addrow_robo("TablaEncabezado", arr);
				}
			}
			blTermino = true;
			//window.divCarga.style.visibility = "hidden";
         } else {
            alert('Se presento algun problema en la carga.');
         }
	}
}


function addrow_robo(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: #ffffff; 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(){ FncLlenaText_robo(lastRow); } );
		} else {
			nmCell = 0;
			cell.setAttribute('align', 'right');
		}					
		cell.innerHTML = arr[r];
	}
}


function FncLlenaText_robo(lpRow) {
	var x = document.getElementById('TablaEncabezado').rows[lpRow].cells;
	objCalle.value = x[0].innerHTML;
	window.divCalles.style.visibility = "hidden";
}

function LimpiaTabla_robo(tablename) {
	var tbl = document.getElementById(tablename);
	for (var i=tbl.rows.length; tbl.rows.length > 1; i--) {
		tbl.deleteRow(tbl.rows.length - 1);
	}
}


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
    }
}


//*************************************************************************************************************//

/***********************************************************
FUNCIONES PUBLICAS
***********************************************************/
function do_xml_num_robo(paramObj, szComuna, szCalle, top, left) {
	/*Validar Tecla Presionada */
	objNum = paramObj
	szValor  = objNum.value;
	var ieKey = event.keyCode; 
	var nKey  = 0;
	var strin = "Codice tecla in Explorer: " + ieKey;
	var blEntrar = true;
	
//	alert(ieKey);
	if ((ieKey > 47 ) && (ieKey < 57)) {blEntrar = true;}
	if ((ieKey == 8 )) {blEntrar = true;}

	if (szValor != '' && blEntrar) {
			blTermino = false;
			/*window.divCarga.style.visibility = "visible";*/
			window.divNumCalles.style.visibility = "visible";
			window.divNumCalles.style.top = top;
			window.divNumCalles.style.left = left;
			var szParametros = '?szComuna='+encodeURI(szComuna)+'&szNombreCalle='+szCalle+'&szNumCalle='+szValor;		
			makeRequestNum_robo('../xml/xmlListaNumCalle.asp', szParametros, '2');
			}
		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 (lpRow != 0)
					FncLlenaTextNum_robo(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";
				}
			}
		}
	}


/***********************************************************
FUNCIONES PRIVADAS
***********************************************************/
function makeRequestNum_robo(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_robo;
    http_request.open('GET', url, true);
    http_request.send(null);
}


function alertContentsNum_robo() {
	LimpiaTabla_robo("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++;
						}
					}

					addrowNum_robo("TablaEncabezadoNum", arr);
				}
			}
			blTermino = true;
			//window.divCarga.style.visibility = "hidden";
         } else {
            alert('Se presento algun problema en la carga.');
         }
	}
}


function addrowNum_robo(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: #ffffff; 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)
		}
		cell.innerHTML =  arr[r];

	}
}


function FncLlenaTextNum_robo(lpRow) {
	var x = document.getElementById('TablaEncabezadoNum').rows[lpRow].cells;
	objNum.value = x[0].innerHTML;
	window.divNumCalles.style.visibility = "hidden";
}

function LimpiaTablaNum_robo(tablename) {
	var tbl = document.getElementById(tablename);
	for (var i=tbl.rows.length; tbl.rows.length > 1; i--) {
		tbl.deleteRow(tbl.rows.length - 1);
	}
}


//*************************************************************************************************************//


