var jg;
var datosAero;
var puntoRosa;

var listaFrecs;
var listaVelos;
var radio;
var escalaFrecuencia;
var escalaVelocidad;
var listaDatosGrafica;
var aeroProduccion;
var aeroHoras;
var latitud;
var longitud;
var clickLoginX;
var clickLoginY;

var tempImg;

function buscarCoordenada(){
	//Limpiar graficos del mapa
  	var map = EsriControls.maps['map1'];
    var formId = map.formId;
    var url = EsriUtils.getServerUrl(formId);
	
	var x = document.getElementById("coordenadaX");
	var y = document.getElementById("coordenadaY");	
	var radio = document.getElementById('radioCoordenada');
	var huso =document.getElementById("huso");

	setMensaje('errorCoordenadas', '');


	if (x.value!=null && x.value!="" &&
		y.value!=null && y.value!="" &&
		huso.value!=null && huso.value!="" && !isNaN(x.value) && !isNaN(y.value) && !isNaN(huso.value)
		&&
		radio.value!=null && radio.value!="" && !isNaN(radio.value)){
		
	    var params = "parametro=buscarCoordenadas&formId=" + formId +"&huso="+huso.value+"&radio="+radio.value+"&x="+x.value+"&y="+y.value+ "&mapId=" + map.id + "&" + EsriUtils.buildRequestParams(formId);
	    //send AJAX request to server and pass callback function
	    var xh = EsriUtils.sendAjaxRequest(url, params, true, function() {buscarCoordenadaResponse(xh); });
	}
	else{
		setMensaje('errorCoordenadas', Res.getString('errorCoordenadas'));
	}
	
}



function buscarCoordenadaResponse(xh){
	if (xh != null && xh.readyState == 4 && xh.status == 200) {
		//alert('fin');
		var map = EsriControls.maps['map1'];
		//Refrescar el mapa y los graficos
		for (var i=0;i<map.mapSourceNames.length;i++) {
			map.mapSources[map.mapSourceNames[i]].update(map);
			map.mapSources[map.mapSourceNames[i]].updateImages(map.viewBounds);
		}
		map.updateWebGraphics();
		map.resize(map.bounds.width,map.bounds.height);
		//buscarCoordenada();
		actualizarMapa();
	}
}


function zoomCoordenada(){
	//Limpiar graficos del mapa
  	var map = EsriControls.maps['map1'];
    var formId = map.formId;
    var url = EsriUtils.getServerUrl(formId);

	var x = document.getElementById("coordenadaX");
	var y = document.getElementById("coordenadaY");		
	var radio= document.getElementById('radioCoordenada');
	var huso= document.getElementById('huso');
	
	if (x.value!=null && x.value!="" &&
		y.value!=null && y.value!="" &&
		huso.value!=null && huso.value!="" && !isNaN(x.value) && !isNaN(y.value) && !isNaN(huso.value)
		&&
		radio.value!=null && radio.value!="" && !isNaN(radio.value)){
		
	    var params = "parametro=zoomCoordenadas&formId=" + formId +"&radio="+radio.value+"&huso="+huso.value+"&x="+x.value+"&y="+y.value+ "&mapId=" + map.id + "&" + EsriUtils.buildRequestParams(formId);
	    //send AJAX request to server and pass callback function
	    var xh = EsriUtils.sendAjaxRequest(url, params, true, function() {zoomCoordenadaResponse(xh);});
    }
}


function zoomCoordenadaResponse(xh){
	if (xh != null && xh.readyState == 4 && xh.status == 200) {
		var map = EsriControls.maps['map1'];
		//Refrescar el mapa y los graficos
		for (var i=0;i<map.mapSourceNames.length;i++) {
			map.mapSources[map.mapSourceNames[i]].update(map);
			map.mapSources[map.mapSourceNames[i]].updateImages(map.viewBounds);
		}
		map.updateWebGraphics();
		map.resize(map.bounds.width,map.bounds.height);
		//buscarCoordenada();
		actualizarMapa();
	}
}


function fechaDeHoy(){		
	var fecha = new Date(); 
	var dd = fecha.getDate();
	if (dd<10){
		dd="0"+dd;
	}
	var mm=(fecha.getMonth() + 1); 
	if (mm<10){
		mm="0"+mm;
	}
	var yyyy=fecha.getFullYear() ;
	return dd+"/"+mm+"/"+yyyy;
}

	function actualizarImagenDeallocate(toolName){
		var img=document.getElementById('button_mapToolsTask_action_energia');
		if (-1!=img.src.search("D.png") && (-1!=toolName.toLowerCase().search("energia") || -1!=toolName.search("esri"))){//si es -1, no encontro nada en el search
			
			img.src=img.src.replace("D.png",".png");
			
		}	
		img=document.getElementById('button_mapToolsTask_action_rosa');
		if (-1!=img.src.search("D.png") && (-1!=toolName.toLowerCase().search("rosa") || -1!=toolName.search("esri"))){//si es -1, no encontro nada en el search
			
			img.src=img.src.replace("D.png",".png");

		}
		img=document.getElementById('button_mapToolsTask_tool_descarga');
		if (img!=null){
			if (-1!=img.src.search("D.png") && (-1!=toolName.toLowerCase().search("descarga") || -1!=toolName.search("esri"))){//si es -1, no encontro nada en el search
				
				img.src=img.src.replace("D.png",".png");
			}
		}
		img=document.getElementById('button_mapToolsTask_action_buscarCoordenadas');
		if (img!=null){
			if (-1!=img.src.search("D.png") && (-1!=toolName.toLowerCase().search("obtener") || -1!=toolName.search("esri"))){//si es -1, no encontro nada en el search
				img.src=img.src.replace("D.png",".png");
			}
		}
		
//		if(EsriUtils.isIE6){
//			EsriUtils.setImageSrc(img, img.src);
//		}
		
	}
	function actualizarImagenClick(img, src){
		tempImg=src;
		if(EsriUtils.isIE6){
			EsriUtils.setImageSrc(img, src);
		}
		else{
			img.src=src;
		}
		
	}
	function actualizarImagenOut(img){
		if (-1==img.src.search("D.png") && -1==img.src.search("D.gif")){
			if(EsriUtils.isIE6){
				EsriUtils.setImageSrc(img, tempImg);
			}
			else{
				img.src = tempImg;
			}
			
		}
	}
	function actualizarImagenIn(img,src){
		if (-1==img.src.search("D.png") && -1==img.src.search("D.gif")){
			tempImg=img.src;
			if(EsriUtils.isIE6){
				EsriUtils.setImageSrc(img, src);
			}
			else{
				img.src = src;
			}
		}
	}


  function mostrarAyuda(toolId){
  		var contentId="ayudaPanelContent";
  		
  		if(taskBox != null){
    		var toggle = document.getElementById(taskBox.getPanelHeaderToggleId(contentId));
      		toggle.src = taskBox.collapseImg;
      	}
  
  
		var iframeAyuda = document.getElementById('ayudaIframe');
		//iframeAyuda.src = "help/help.html";

		if(EsriUtils.isIE){
		  	if(ayudaIframe.window.document.getElementById('divAyuda_general') != null)
  				ayudaIframe.window.document.getElementById('divAyuda_general').style.display = "none";
		}
		else{
		  	if(iframeAyuda.contentWindow.document.getElementById('divAyuda_general') != null)
  				iframeAyuda.contentWindow.document.getElementById('divAyuda_general').style.display = "none";
		}
  		
  		if (toolId == "mapToolsTask_tool_zoomIn"){
  			ocultarTodaAyuda('divAyuda_zoomIn');
  		}
  		else if (toolId == "mapToolsTask_tool_zoomOut"){
  			ocultarTodaAyuda('divAyuda_zoomOut');
		}
		else if (toolId == "mapToolsTask_tool_pan"){
  			ocultarTodaAyuda('divAyuda_pan');
		}
		else if (toolId == "mapToolsTask_action_previous"){
  			ocultarTodaAyuda('divAyuda_previous');
		}
		else if (toolId == "mapToolsTask_action_next"){
  			ocultarTodaAyuda('divAyuda_next');
		}
		else if (toolId == "mapToolsTask_action_zoomFullExtent"){
  			ocultarTodaAyuda('divAyuda_zoomFullExtent');
		}
		else if (toolId == "identify_Custom"){
  			ocultarTodaAyuda('divAyuda_identify');
		}
		else if (toolId == "Mostrar Rosa"){
  			ocultarTodaAyuda('divAyuda_rosa');
		}
		else if (toolId == "Calcular Energia"){
  			ocultarTodaAyuda('divAyuda_calcularEnergia');
		}
		else if (toolId == "Descargar Datos"){
  			ocultarTodaAyuda('divAyuda_descargaDatos');
		}
		else if (toolId == "Obtener Punto"){
  			ocultarTodaAyuda('divAyuda_buscarCoordenada');
		}
		else if ((toolId == "mapToolsTask_tool_getLocation") || (toolId == "mapToolsTask_tool_getDistance") || (toolId == "mapToolsTask_tool_getArea")){
  			ocultarTodaAyuda('divAyuda_measure');
		}
		else{
  			ocultarTodaAyuda('');
			//iframeAyuda.src = "blank.html";
		}
	  
	  	EsriUtils.showElement(document.getElementById('ayudaPanelContent'));
  	
  }
  
  function mostrarAyudaMedicion(){
  
	  	ocultarTodaAyuda('divAyuda_measure');

		var iframeAyuda = document.getElementById('ayudaIframe');

		if(EsriUtils.isIE){
		  	if(ayudaIframe.window.document.getElementById('divAyuda_general') != null)
  				ayudaIframe.window.document.getElementById('divAyuda_general').style.display = "none";
		}
		else{
		  	if(iframeAyuda.contentWindow.document.getElementById('divAyuda_general') != null)
  				iframeAyuda.contentWindow.document.getElementById('divAyuda_general').style.display = "none";
		}
		
	
	  	EsriUtils.showElement(document.getElementById('ayudaPanelContent'));
  
  }
  

  function mostrarAyudaMapaReferencia(){
  
	  	ocultarTodaAyuda('divAyuda_overview');

		var iframeAyuda = document.getElementById('ayudaIframe');

		if(EsriUtils.isIE){
		  	if(ayudaIframe.window.document.getElementById('divAyuda_general') != null)
  				ayudaIframe.window.document.getElementById('divAyuda_general').style.display = "none";
		}
		else{
		  	if(iframeAyuda.contentWindow.document.getElementById('divAyuda_general') != null)
  				iframeAyuda.contentWindow.document.getElementById('divAyuda_general').style.display = "none";
		}
		
	
	  	EsriUtils.showElement(document.getElementById('ayudaPanelContent'));
  
  }
  
  
  function ocultarTodaAyuda(divNombre){

	var iframeAyuda = document.getElementById('ayudaIframe');

  	if(EsriUtils.isIE){

	  	if((divNombre != "") && ayudaIframe.window.document.getElementById(divNombre) != null){
	  		ayudaIframe.window.document.getElementById(divNombre).style.display = "block";
		 	if(ayudaIframe.window.document.getElementById('divAyuda_general') != null)
		  		ayudaIframe.window.document.getElementById('divAyuda_general').style.display = "none"; 
	  	 }
	  	 else{
	 		if(ayudaIframe.window.document.getElementById('divAyuda_general') != null)
	  			ayudaIframe.window.document.getElementById('divAyuda_general').style.display = "block"; 
	  	 }

	  	
	  	if((divNombre != "divAyuda_zoomIn") && ayudaIframe.window.document.getElementById('divAyuda_zoomIn') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_zoomIn').style.display = "none";
	
	  	if((divNombre != "divAyuda_zoomOut") && ayudaIframe.window.document.getElementById('divAyuda_zoomOut') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_zoomOut').style.display = "none";
	
	  	if((divNombre != "divAyuda_pan") && ayudaIframe.window.document.getElementById('divAyuda_pan') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_pan').style.display = "none"; 
	
	  	if((divNombre != "divAyuda_previous") && ayudaIframe.window.document.getElementById('divAyuda_previous') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_previous').style.display = "none";
	
	  	if((divNombre != "divAyuda_next") && ayudaIframe.window.document.getElementById('divAyuda_next') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_next').style.display = "none";
	
	  	if((divNombre != "divAyuda_zoomFullExtent") && ayudaIframe.window.document.getElementById('divAyuda_zoomFullExtent') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_zoomFullExtent').style.display = "none";
	
	  	if((divNombre != "divAyuda_identify") && ayudaIframe.window.document.getElementById('divAyuda_identify') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_identify').style.display = "none";
	
	  	if((divNombre != "divAyuda_measure") && ayudaIframe.window.document.getElementById('divAyuda_measure') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_measure').style.display = "none";
	
	  	if((divNombre != "divAyuda_overview") && ayudaIframe.window.document.getElementById('divAyuda_overview') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_overview').style.display = "none";
	
	  	if((divNombre != "divAyuda_rosa") && ayudaIframe.window.document.getElementById('divAyuda_rosa') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_rosa').style.display = "none";
	
	  	if((divNombre != "divAyuda_calcularEnergia") && ayudaIframe.window.document.getElementById('divAyuda_calcularEnergia') != null)
	  		ayudaIframe.window.document.getElementById('divAyuda_calcularEnergia').style.display = "none";
	
	  	if((divNombre != "divAyuda_descargaDatos") && ayudaIframe.window.document.getElementById('divAyuda_descargaDatos') != null)
		  	ayudaIframe.window.document.getElementById('divAyuda_descargaDatos').style.display = "none";
  	
	  	if((divNombre != "divAyuda_buscarCoordenada") && ayudaIframe.window.document.getElementById('divAyuda_buscarCoordenada') != null)
		  	ayudaIframe.window.document.getElementById('divAyuda_buscarCoordenada').style.display = "none";
  	
  	}
  	else{
 	 	
	  	if((divNombre != "") && iframeAyuda.contentWindow.document.getElementById(divNombre) != null){
	  		iframeAyuda.contentWindow.document.getElementById(divNombre).style.display = "block";
		  	if(iframeAyuda.contentWindow.document.getElementById('divAyuda_general') != null)
		  		iframeAyuda.contentWindow.document.getElementById('divAyuda_general').style.display = "none"; 
	  	}
	  	else{
		  	if(iframeAyuda.contentWindow.document.getElementById('divAyuda_general') != null)
		  		iframeAyuda.contentWindow.document.getElementById('divAyuda_general').style.display = "block"; 
	  	}

	  	
	  	if((divNombre != "divAyuda_zoomIn") && iframeAyuda.contentWindow.document.getElementById('divAyuda_zoomIn') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_zoomIn').style.display = "none";
	
	  	if((divNombre != "divAyuda_zoomOut") && iframeAyuda.contentWindow.document.getElementById('divAyuda_zoomOut') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_zoomOut').style.display = "none";
	
	  	if((divNombre != "divAyuda_pan") && iframeAyuda.contentWindow.document.getElementById('divAyuda_pan') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_pan').style.display = "none"; 
	
	  	if((divNombre != "divAyuda_previous") && iframeAyuda.contentWindow.document.getElementById('divAyuda_previous') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_previous').style.display = "none";
	
	  	if((divNombre != "divAyuda_next") && iframeAyuda.contentWindow.document.getElementById('divAyuda_next') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_next').style.display = "none";
	
	  	if((divNombre != "divAyuda_zoomFullExtent") && iframeAyuda.contentWindow.document.getElementById('divAyuda_zoomFullExtent') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_zoomFullExtent').style.display = "none";
	
	  	if((divNombre != "divAyuda_identify") && iframeAyuda.contentWindow.document.getElementById('divAyuda_identify') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_identify').style.display = "none";
	
	  	if((divNombre != "divAyuda_measure") && iframeAyuda.contentWindow.document.getElementById('divAyuda_measure') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_measure').style.display = "none";
	
	  	if((divNombre != "divAyuda_overview") && iframeAyuda.contentWindow.document.getElementById('divAyuda_overview') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_overview').style.display = "none";
	
	  	if((divNombre != "divAyuda_rosa") && iframeAyuda.contentWindow.document.getElementById('divAyuda_rosa') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_rosa').style.display = "none";
	
	  	if((divNombre != "divAyuda_calcularEnergia") && iframeAyuda.contentWindow.document.getElementById('divAyuda_calcularEnergia') != null)
	  		iframeAyuda.contentWindow.document.getElementById('divAyuda_calcularEnergia').style.display = "none";
	
	  	if((divNombre != "divAyuda_descargaDatos") && iframeAyuda.contentWindow.document.getElementById('divAyuda_descargaDatos') != null)
		  	iframeAyuda.contentWindow.document.getElementById('divAyuda_descargaDatos').style.display = "none";
  	
	  	if((divNombre != "divAyuda_buscarCoordenada") && iframeAyuda.contentWindow.document.getElementById('divAyuda_buscarCoordenada') != null)
		  	iframeAyuda.contentWindow.document.getElementById('divAyuda_buscarCoordenada').style.display = "none";
  	
  	}
  
  }
  
  

function limpiarGraficos(){ 
	//Limpiar graficos del mapa
  	var map = EsriControls.maps['map1'];
    var formId = map.formId;
    var url = EsriUtils.getServerUrl(formId);
	
    var params = "parametro=limpiarGraficos&formId=" + formId + "&mapId=" + map.id + "&" + EsriUtils.buildRequestParams(formId);
    //send AJAX request to server and pass callback function
    var xh = EsriUtils.sendAjaxRequest(url, params, true, function() {actualizarMapa(); });
}

function actualizarMapa(){
	var map = EsriControls.maps['map1'];
   	for (var i=0;i<map.mapSourceNames.length;i++) {
		map.mapSources[map.mapSourceNames[i]].update(map);
		map.mapSources[map.mapSourceNames[i]].updateImages(map.viewBounds);
	}
	
	map.updateWebGraphics();
}

function getMouseXY(e) {
	//Toma las coordenas del evento.
	var IE = document.all?true:false
	if (IE) {
	  clickLoginX= event.clientX + document.body.scrollLeft
	  clickLoginY= event.clientY + document.body.scrollTop
	} else {
	  clickLoginX= e.pageX
	  clickLoginY= e.pageY
	}  
	if (clickLoginX< 0){
		clickLoginX= 0;
	}
	if (clickLoginY< 0){
		clickLoginY= 0;
	}
	return true
  }


  function Autenticar(){
   	var usuario = document.getElementById('mapForm:loginL').value;
   	var password = document.getElementById('mapForm:passwordL').value;
   	
    if((usuario == null) || (password == null) || (usuario == "") || (password == "")){
 		advertenciaBalloon.showTooltipOutEventAbsolut(clickLoginX,clickLoginY-10, Res.getString("errorLogin") );
    }
    else {
 	 	var map = EsriControls.maps['map1'];
    	var formId = map.formId;
    	var url = EsriUtils.getServerUrl(formId);
 		
	    var params = "parametro=autenticar&formId=" + formId + "&mapId=" + map.id + "&user=" + usuario+ "&pass=" + password+ "&" + EsriUtils.buildRequestParams(formId);
	    //send AJAX request to server and pass callback function
	    var xh = EsriUtils.sendAjaxRequest(url, params, true, function() { loguearUsuarioResponse(xh);});
	}
  }


    function Desloguear(){
    	var form = document.forms['formLogout'];
    	form.submit();
    }
    

  function loguearUsuarioResponse(xh){
  
	if (xh != null && xh.readyState == 4 && xh.status == 200) {
		//Arma los arrays con los datos recibidos
		var xmlTemp = xh.responseXML;
		var resultTags = xmlTemp.getElementsByTagName("result");
		if (resultTags.length > 0) {
			var resultTag = resultTags.item(0);
	        var details = resultTag.getElementsByTagName("detail");
			var detail = details.item(0);
			
			var usuario = detail.getAttribute("usuario");
			var contrasena = detail.getAttribute("contrasena");
			var nombre = detail.getAttribute("nombre");
			
			var error = detail.getAttribute("error");
			if (usuario!=null){
				var form = document.forms['formLogin'];
				var form = document.forms['formLogin'];
		    	form.login.value = usuario;
		    	form.password.value = contrasena;
		    	form.nombre.value = nombre;
		    	form.submit();
			}else{
				advertenciaBalloon.showTooltipOutEventAbsolut(clickLoginX,clickLoginY-10, Res.getString("errorLogin") );
			}
			
		}
	}
}

function borrarHistograma(div){
	var myDivWin=taskWindowManager.windows['win_divRosa'];
	if (myDivWin!=null){
		var temp=document.getElementById(div);
		temp.innerHTML="";
	
		document.getElementById('chart').style.display = "none";
		var pb = EsriUtils.getPageBounds();
		var left = pb.width - 400;
		var top = pb.height-myDivWin.bounds.height;
		myDivWin.moveTo(left,top);
		myDivWin.resize(400,myDivWin.bounds.height);

		document.getElementById('histograma').checked=false;
	}
}


function graficar(div){

		var temp = document.getElementById(div);
		if(temp != null){
			temp.innerHTML="";
			var max=parseInt(listaDatosGrafica[0]);
			for (var i=1;i<listaDatosGrafica.length;i++) {
				if (parseInt(listaDatosGrafica[i])>max){
					max=parseInt(listaDatosGrafica[i]);
				}
		    }
		    if (max != 0){
				var c = new Chart(document.getElementById(div));	
				c.setDefaultType(CHART_BAR);
				c.setGridDensity(27, 5);
				c.setShowLegend(false);
				c.setVerticalRange(0, max);
				c.setBarDistance(1);
				c.setBarWidth(15);
				c.setHorizontalLabels(['','0,5','','2,5','','4,5','','6,5','','8,5','','10,5','','12,5','','14,5','','16,5','','18,5','','20,5','','22,5','','24,5','','>25,5']);
				c.add('Spam','#FF9900', listaDatosGrafica);
				c.draw();
			}
		} 
}

window.onload = function() {
	ieCanvasInit('includes/iecanvas.htc');
	draw(); 
};

function mostrarTextoAero() {
	//Escribe el texto dentro de la ventana con los datos del aero seleccionado
	var aeroSelect = document.getElementById("aeros");
	var aero = document.getElementById("divAero");
	var textoAero;
	textoAero=Res.getString("textAero");
	var aeroSelected=parseInt(aeroSelect.selectedIndex);
	
	//aero.innerHTML=textoAero.replace("#valor#",aeroProduccion[aeroSelected]).replace("#aero#","Aero "+(aeroSelected+1)).replace("#horas#",aeroHoras[aeroSelected]).replace("#longitud#",this.longitud).replace("#latitud#",this.latitud);
			
		
	if(document.all){//IE
		aero.innerHTML = textoAero.replace("#valor#",aeroProduccion[aeroSelected]).replace("#aero#","Aero "+(aeroSelected+1)).replace("#horas#",aeroHoras[aeroSelected]).replace("#longitud#",this.longitud).replace("#latitud#",this.latitud);
	}
	else{
		if (document.getElementById){ 
			//aero.textContent = textoAero.replace("#valor#",aeroProduccion[aeroSelected]).replace("#aero#","Aero "+(aeroSelected+1)).replace("#horas#",aeroHoras[aeroSelected]).replace("#longitud#",this.longitud).replace("#latitud#",this.latitud);
			aero.innerHTML= new String (textoAero.replace("#valor#",aeroProduccion[aeroSelected]).replace("#aero#","Aero "+(aeroSelected+1)).replace("#horas#",aeroHoras[aeroSelected]).replace("#longitud#",this.longitud).replace("#latitud#",this.latitud).replace("&oacute","\u00f3"));
		}
		else
			alert(Res.getString("ErrorBrowserSupport"));
	}
}

function mostrarAero(xh,x,y){
	if (xh != null && xh.readyState == 4 && xh.status == 200) {
		//Arma los arrays con los datos recibidos
		var xmlTemp = xh.responseXML;
		var resultTags = xmlTemp.getElementsByTagName("result");
		if (resultTags.length > 0) {
			var resultTag = resultTags.item(0);
	        var aeros= resultTag.getElementsByTagName("aero");
	        
	        var details = resultTag.getElementsByTagName("detail");
			var detail = details.item(0);
			mensaje = detail.getAttribute("mensaje");
	        
	        longitud=detail.getAttribute("coordenada_X");
			longitud = Math.round(parseFloat(longitud)*100)/100;
			latitud=detail.getAttribute("coordenada_Y");		
			latitud= Math.round(parseFloat(latitud)*100)/100;
	        
	        
	        if (mensaje==null){	        
		        aeroProduccion=new Array();
		        aeroHoras=new Array();
		        for (var i=0;i<aeros.length;i++) {
					var aero= aeros.item(i);
		        	aeroProduccion[i]=aero.getAttribute("produccion");
		        	aeroHoras[i]=aero.getAttribute("horas");
		        }
		        //Muestra los datos de los aeros	
				var map = EsriControls.maps["map1"];
				var mc=map.callOut;
				
				var select="<select onchange=mostrarTextoAero(); id='aeros' name='aeros' style='width: 90%'>";
				for(var i=1;i<=6;i++){
					select+="<option>Aero "+i+"</option>";
				}
				select+="</select>";
				
				var testoAero=Res.getString("textAero");
				mc.setContent({header: select, content: "<div id='divAero'></div>",footer:""});
				mostrarTextoAero();
				mc.moveTo(x,y);
				mc.expand();
			    mc.show();
		    }else{
		    	advertenciaBalloon.showTooltipOutEvent(parseInt(x),parseInt(y), Res.getString("errorInformacion"));
		    }
		}
	}
}

function initRosa(){
	listaDatosGrafica=new Array(16);
	document.getElementById('velocidad').checked=true;
	document.getElementById('frecuencia').checked=true;
	jg = new jsGraphics('frec');
	jg.setStroke(2);
	jg.setColor(Res.getString("colorFrecuencia"));
	jg.drawLine(20,10,40,10);
	jg.paint();
	jg = new jsGraphics('velo');
	jg.setStroke(2);
	jg.setColor(Res.getString("colorVelocidad"));
	jg.drawLine(20,10,40,10);
	jg.paint();
	jg = new jsGraphics('divRosaImg')
}
function mostrarRosa(v,f,div){
	jg.clear();
	mostrarFrecuencia(f.checked);
	mostrarVelocidad(v.checked);
}
function mostrarVelocidad(mostrar){
	if (mostrar){
		//muestra escalas
		jg.setColor(Res.getString("colorVelocidad"));		
		jg.setFont(Res.getString("fontEscalaRosa"), Res.getString("tamanoEscalaRosa"), Font.PLAIN);
		radio=Res.getString("radioRosa");
		for (var i=1;i<5;i++){
			var temp=(escalaVelocidad/4)*i;
			jg.drawString(temp, parseInt(Res.getString("xCentroRosa"))+8, parseInt(Res.getString("yCentroRosa"))-i*(radio/4), 500, "1");
			jg.paint();
		}
		//dibuja rosa
		jg.setStroke(2);
		jg.setColor(Res.getString("colorVelocidad"));
		for (var i=0;i<listaVelos.length;i++) {
			var a=listaVelos[i];
			var b;
			if (i==listaVelos.length-1){
				b=listaVelos[0];
			}else{
				b=listaVelos[i+1];
			}
			jg.drawLine(parseInt(a[0]),parseInt(a[1]),parseInt(b[0]),parseInt(b[1]));
			jg.paint();
		}	
	}
}
function mostrarFrecuencia(mostrar){
	if (mostrar){
		//muestra escalas
		jg.setColor(Res.getString("colorFrecuencia"));		
		jg.setFont(Res.getString("fontEscalaRosa"), Res.getString("tamanoEscalaRosa"), Font.PLAIN);
		radio=Res.getString("radioRosa");
		for (var i=1;i<5;i++){
			var temp=(escalaFrecuencia/4)*i;
			jg.drawString(temp, parseInt(Res.getString("xCentroRosa"))+8, parseInt(Res.getString("yCentroRosa"))+(i-1)*(radio/4)-5, 500, "1");
			jg.paint();
		}
		//dibuja rosa
		jg.setStroke(2);
		jg.setColor(Res.getString("colorFrecuencia"));
		for (var i=0;i<listaFrecs.length;i++) {
			var a=listaFrecs[i];
			var b;
			if (i==listaFrecs.length-1){
				b=listaFrecs[0];
			}else{
				b=listaFrecs[i+1];
			}
			jg.drawLine(parseInt(a[0]),parseInt(a[1]),parseInt(b[0]),parseInt(b[1]));
			jg.paint();
		}
	}
}

function dibujarRosa(xh,div){
	if (xh != null && xh.readyState == 4 && xh.status == 200) {
		jg.clear();
		var xmlTemp = xh.responseXML;
		var resultTags = xmlTemp.getElementsByTagName("result");
		var resultTag = resultTags.item(0);
		var escalasTag= resultTag.getElementsByTagName("escalas");
		
		var details = resultTag.getElementsByTagName("detail");
		var detail = details.item(0);
		mensaje = detail.getAttribute("mensaje");
		
		var longitud=detail.getAttribute("coordenada_X");
		longitud = Math.round(parseFloat(longitud)*100)/100;
		var latitud=detail.getAttribute("coordenada_Y");		
		latitud= Math.round(parseFloat(latitud)*100)/100;					
		var myDivWin=taskWindowManager.windows['win_divRosa'];
		myDivWin.setTitulo(Res.getString("Longitud")+" "+longitud +" "+ Res.getString("Latitud")+" "+latitud);
				
		if(mensaje==null){
			listaFrecs=new Array(16);
			if (resultTags.length > 0) {
				var resultTag = resultTags.item(0);
		        var frecs= resultTag.getElementsByTagName("frecs");
		        for (var i=0;i<frecs.length;i++) {
					var frec= frecs.item(i);
					
		        	var coord= new Array(2);
		        	coord[0]=frec.getAttribute("x");
		        	coord[1]=frec.getAttribute("y");
		        	listaFrecs[i]=coord;
		        }
			}
			listaVelos=new Array(16);
			if (resultTags.length > 0) {
				var resultTag = resultTags.item(0);
		        var velos= resultTag.getElementsByTagName("velos");
		        	        	        
		        for (var i=0;i<velos.length;i++) {
					var vel= velos.item(i);
					
		        	var coord= new Array(2);
		        	coord[0]=vel.getAttribute("x");
		        	coord[1]=vel.getAttribute("y");
		        	listaVelos[i]=coord;
		        }
			}
			
			if(mostrarVelocidad || mostrarFrecuencia){
				var esc= resultTag.getElementsByTagName("escalas");
				var escTemp=esc.item(0);
				escalaFrecuencia=escTemp.getAttribute("frecuencia");
				escalaVelocidad=escTemp.getAttribute("velocidad");
			}
			mostrarVelocidad(document.getElementById('velocidad').checked);
			mostrarFrecuencia(document.getElementById('frecuencia').checked);
			
			var max=0;
	        var datosGrafica = resultTag.getElementsByTagName("grafica"); 	        
	        for (var i=0;i<datosGrafica.length;i++) {
				var dato = datosGrafica.item(i);
	        	listaDatosGrafica[i]=dato.getAttribute("x");
	        	if (max<listaDatosGrafica[i]){
	        		max=listaDatosGrafica[i];
	        	}
	        }
	        if (max==0){
	        	document.getElementById('histograma').disabled="disabled";
	        	document.getElementById('histograma').checked=false;
	        	mostrarHistograma(document.getElementById('histograma'));
	        }else{
	        	document.getElementById('histograma').disabled=null;
	        }
			
			taskWindowManager.windows['win_divRosa'].show();
			graficar('chart');
			
		}else{
			taskWindowManager.windows['win_divRosa'].hide();
			var puntoCoord = resultTag.getElementsByTagName("punto");
			var punto = puntoCoord.item(0);
			var x = punto.getAttribute("x");
			var y = punto.getAttribute("y");
			// No se encontraron datos
			//No ha indicado un punto contenedor de información. Por favor intente nuevamente...
			advertenciaBalloon.showTooltipOutEvent(parseInt(x),parseInt(y), Res.getString("errorInformacion"));
		}
	}
	
	
}
