// JavaScript Document

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
var navegador=BrowserDetect.browser;
//alert(navegador)


function calcularinicial(){
var ancho = window.innerWidth? window.innerWidth : document.body.clientWidth
var alto = window.innerHeight? window.innerHeight : document.body.clientHeight

//alert('ancho:'+ancho+'\nalto'+alto);

alto=alto-160

if(alto<500){
	alto=500	
}


mengua=500;

if(navegador=='Explorer'){
	ancho=ancho;
}else{
	ancho=ancho-17;	
}

//alert('ancho:'+ancho+'\nalto'+alto);
if(alto<610){document.getElementById('items_posibles').value='3';
}else if(alto>=610 && alto<720){document.getElementById('items_posibles').value='4';
}else if(alto>=720 && alto<830){document.getElementById('items_posibles').value='5';
}else if(alto>=830){document.getElementById('items_posibles').value='6';
}


document.getElementById('var_ancho').value=ancho;
document.getElementById('var_alto').value=alto;
if (document.getElementById('chivato_cat').value=='0'){
	mengua=mengua-210
}
if (document.getElementById('chivato_util').value=='0'){
	mengua=mengua-290
}

document.getElementById('map').style.width=ancho-mengua+'px';
//alert('alto:'+alto);
document.getElementById('map').style.height=alto+'px';
document.getElementById('categorias').style.height=alto+'px';
document.getElementById('marco_utilidades').style.height=alto+'px';

document.getElementById('hist').style.height=alto-65+'px';
document.getElementById('acti').style.height=alto-65+'px';
document.getElementById('favo').style.height=alto-65+'px';

cargar_favoritos();
}




function mostrar_ayuda(mensaje){
	document.getElementById('ayuda').innerHTML=mensaje;
}

function mostrar_aviso(mensaje){
	document.getElementById('texto_aviso').innerHTML=mensaje;
	$( '#dialog' ).dialog( "option", "title", 'FAVORITOS' );
	$( '#dialog' ).dialog( 'open' )
		setTimeout("$( '#dialog' ).dialog( 'close' )", 3500);

}




function buscar_1(){
	var	quebuscas=document.getElementById('quebuscas').value
	var	dondebuscas=document.getElementById('dondebuscas').value
	
	if(quebuscas=='Actividad, empresa, servicio...'){
			quebuscas='';
	}
	if(dondebuscas=='Provincia, localidad...'){
			dondebuscas='';
	}

	alert(quebuscas+'+'+dondebuscas)
	
	GDownloadUrl("puntos-txt.asp?tipo=b&q="+quebuscas+"&d="+dondebuscas, process_it);
}


function borrar_campo(campo){
	document.getElementById(campo).value='';
	cargar_predeterminado(campo);
}

function borrar_predeterminado(campo){
var valordelcampo=document.getElementById(campo).value
	if(campo=='quebuscas'){
		if(valordelcampo=='Actividad, empresa, servicio...'){
			document.getElementById(campo).value='';
			document.getElementById(campo).style.color='#000000';
		}
	}else if(campo='dondebuscas'){
		if(valordelcampo=='Provincia, localidad...'){
			document.getElementById(campo).value='';
			document.getElementById(campo).style.color='#000000';
		}
	}

}

function cargar_predeterminado(campo){
var valordelcampo=document.getElementById(campo).value
	if(campo=='quebuscas'){
		if(valordelcampo==''){
			document.getElementById(campo).value='Actividad, empresa, servicio...';
			document.getElementById(campo).style.color='#999999';
		}
	}else if(campo='dondebuscas'){
		if(valordelcampo==''){
			document.getElementById(campo).value='Provincia, localidad...';
			document.getElementById(campo).style.color='#999999';
		}
	}

}

function ocultar_cat(){
	document.getElementById('categorias').style.display='none'
	document.getElementById('celda_cat2').style.display='block'
	document.getElementById('chivato_cat').value='0'
	calcularinicial();
}
function mostrar_cat(){
	document.getElementById('categorias').style.display='block'
	document.getElementById('celda_cat2').style.display='none'
	document.getElementById('chivato_cat').value='1'
	calcularinicial();
}

function ocultar_util(){
	document.getElementById('marco_utilidades').style.display='none';
	document.getElementById('celda_util2').style.display='block';
	document.getElementById('chivato_util').value='0'
	calcularinicial();


}
function mostrar_util(){
	document.getElementById('marco_utilidades').style.display='block'
	document.getElementById('celda_util2').style.display='none'
	document.getElementById('chivato_util').value='1'
	calcularinicial();
}


function multiconsulta(ids){
	//alert(ids);
	document.getElementById('superiframe2').href="multiconsulta.asp?ids="+ids
	$('a.superiframe2').trigger('click');

}

function marcar_todo(formulario){ 

if (document.getElementById('marcartodo').checked==true){
	  for (i=0;i<document.getElementById(formulario).elements.length;i++) 
      if(document.getElementById(formulario).elements[i].type == "checkbox") 
         document.getElementById(formulario).elements[i].checked=1
        // document.getElementById(campo).value=document.getElementById(campovalores).value
  	}else{
  	   for (i=0;i<document.getElementById(formulario).elements.length;i++) 
      if(document.getElementById(formulario).elements[i].type == "checkbox") 
         document.getElementById(formulario).elements[i].checked=0 
         //document.getElementById(campo).value=''
  	}

}


function ver_coordenadas(){
	if(document.getElementById('span_coordenadas').style.display=='none'){	
		document.getElementById('span_coordenadas').style.display='block';
		document.getElementById('bt_coordenadas').src='imagenes/mapa/brujula_p.png';
	}else{
		document.getElementById('span_coordenadas').style.display='none';
		document.getElementById('bt_coordenadas').src='imagenes/mapa/brujula.png';
	}
}




function pestanas_lateral(capa){
	if(document.getElementById('capa_activa')){
	document.getElementById('activos').style.display='none';
	document.getElementById('favoritos').style.display='none';
	document.getElementById('historial').style.display='none';
	document.getElementById('pes_activos').className='';
	document.getElementById('pes_favoritos').className='';
	document.getElementById('pes_historial').className='';
	
	
	//document.getElementById('lat').focus();
	
	document.getElementById('pes_'+capa).className='actual';
	document.getElementById(capa).style.display='block';
	document.getElementById('capa_activa').value=capa;
	}
}


function cargar_activos(){
	
    if (!enProceso && http) {
	   var items=document.getElementById('items_posibles').value;
	   var ids=document.getElementById('ids_activos').value;
	   var alto=document.getElementById('var_alto').value-185
   	   var ordenar=""
	   if(document.getElementById('ordenarpor_activos')){
		   ordenar=document.getElementById('ordenarpor_activos').value;
	   }

       var url = "listado-breve.asp?tipo=activos&ids="+ ids +'&items='+ items +'&alto='+ alto +'&ordenarpor='+ ordenar;
	   //alert(url);
       http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponse_activos;
       enProceso = true;
       http.send(null);
    }
	
}

function handleHttpResponse_activos() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 //results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
			 //pestanas_lateral('favoritos');
             document.getElementById('acti').innerHTML = results;
             enProceso = false;
          }
       }
    }
}

function cargar_historial(){
	
    if (!enProceso && http) {
	   var items=document.getElementById('items_posibles').value;
	   var ids=document.getElementById('ids_historial').value;
	   var ordenar=""
	   if(document.getElementById('ordenarpor_historial')){
		   ordenar=document.getElementById('ordenarpor_historial').value;
	   }
       var url = "listado-breve.asp?tipo=historial&ids="+ ids +'&items='+ items +'&ordenarpor='+ ordenar;
       //alert(url);
	   http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponse_historial;
       enProceso = true;
       http.send(null);
    }
	
}

function handleHttpResponse_historial() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 //results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
			 //pestanas_lateral('favoritos');
             document.getElementById('hist').innerHTML = results;
             enProceso = false;
          }
       }
    }
}

function cargar_favoritos(){
	pestanas_lateral('favoritos');
    if (!enProceso && http) {
	   var items=document.getElementById('items_posibles').value;
	   var ordenar=""
	   var ids="0,"
	   
	   if(document.getElementById('ids_favoritos')){
			ids=document.getElementById('ids_favoritos').value;
		}

	   if(document.getElementById('ordenarpor_favoritos')){
		   ordenar=document.getElementById('ordenarpor_favoritos').value;
	   }
       var url = "listado-breve.asp?tipo=favoritos&ids="+ ids +'&items='+ items +'&ordenarpor='+ ordenar;
       //alert(url);
	   http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponse_favoritos;
       enProceso = true;
       http.send(null);
    }
	
}

function handleHttpResponse_favoritos() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 //results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
			 //pestanas_lateral('favoritos');
             document.getElementById('favo').innerHTML = results;
             enProceso = false;
          }
       }
    }
}



function cargarfoto(idfoto,archivo){
	var pie=document.getElementById('pie_'+idfoto).value
	document.getElementById('fotogrande').innerHTML='<img src="imagenes/empresas/media/'+archivo+'" title="'+pie+'">';
	document.getElementById('piefoto').innerHTML=pie;
}

function cargarvideo(video){
	document.getElementById('fotogrande').innerHTML='<object width="435" height="290"><param name="movie" value="http://www.youtube.com/v/'+video+'&autoplay=1&hl=es_ES&fs=1&rel=0&color1=0x234900&color2=0x4e9e00"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+video+'&autoplay=1&hl=es_ES&fs=1&rel=0&color1=0x234900&color2=0x4e9e00" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="435" height="290"></embed></object>';
}

function contactar_anunciante(idempresa){
	//alert("va a contactar con la empresa "+ idempresa);
	document.getElementById('iframe_grande').href="contactar_anunciante.asp?idempresa="+idempresa
	$('a.iframe').trigger('click');
}

function handleHttpResponseotras() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 //results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
			 //pestanas_lateral('favoritos');
             //document.getElementById('favoritos').innerHTML = results[0];
			 if(results.length>5){
				document.getElementById('infoover').innerHTML=results;
          		document.getElementById('infoover').style.display ='';
				 }
             enProceso = false;
          }
       }
    }
}

function ordenar(tipo){
	if(tipo=='activos'){
		cargar_activos();
	}else if(tipo=='historial'){
		cargar_historial();
	}else if(tipo=='favoritos'){
		cargar_favoritos();
	}
}

function otras_actividades(idempresa){
	document.getElementById('infoover').innerHTML='holads fque fadklf adsf';
    document.getElementById('infoover').style.display ='';

	/*
    if (!enProceso && http) {
       var url = "otrascategorias.asp?idempresa="+ idempresa;
       http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponseotras;
       enProceso = true;
       http.send(null);
    }*/
}

function grabar_stadisticas() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 //alert(results);
			 //results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
			 //pestanas_lateral('historial');
             //document.getElementById('hist').innerHTML = results[0];
			 //if(results[1].length>5){alert(results[1])}
             enProceso = false;
          }
       }
    }
}

function track(idempresa,accion) {
    if (!enProceso && http) {
       var url = "track.asp?idempresa="+ idempresa +'&accion='+ accion;
	   //alert(url);
       http.open("GET", url, true);
       http.onreadystatechange = grabar_stadisticas;
       enProceso = true;
       http.send(null);
    }
}



function enviar_amigo(idempresa){
	document.getElementById('iframe_grande').href="enviar_a_un_amigo.asp?idempresa="+idempresa
	$('a.iframe').trigger('click');

}


function coordenadas_gps(idempresa){
	document.getElementById('iframe_mini').href="coordenadas_gps.asp?idempresa="+idempresa
	$('a.miniiframe').trigger('click');
}

function como_llegar_o(idempresa){
	document.getElementById('iframe_mini').href="como_llegar.asp?idempresa="+idempresa
	$('a.miniiframe').trigger('click');
}

function como_llegar(idempresa,lat,lon,empresa){
	document.getElementById('li_ruta').style.display='block';
	document.getElementById('destino').value=lat+','+lon
	document.getElementById('txt_previo_ruta').innerHTML='C&oacute;mo llegar a "'+empresa+'" desde';
	pestanas_lateral('ruta')
}

function ocultar_ruta(){
	document.getElementById('li_ruta').style.display='none';
	document.getElementById('ruta_instrucciones').innerHTML='';
	document.getElementById('ruta').style.display='block';
	document.getElementById('ruta').style.display='none';
	pestanas_lateral('favoritos')
}

function ver_web(idempresa){
	var web_ok= document.getElementById('web_ok').innerHTML
	document.getElementById('web').innerHTML='Web: '+ web_ok;
	//document.getElementById('f_web').style.display='none';
	track(idempresa,5);
}

function ver_telefono(idempresa){
	track(idempresa,4);
	var web_ok= document.getElementById('telefono_ok').innerHTML
	document.getElementById('telefono_empresa').innerHTML='Tel&eacute;fono: '+ web_ok;
	//alert(document.getElementById('f_telefono'));
	//document.getElementById('f_telefono').style.display='none';
}


function leer_correo(idmensaje){
	document.getElementById('mensaje_detalle_'+idmensaje).style.display='block';
	document.getElementById('sobre_'+idmensaje).src='../imagenes/web/mail_1_trans.png';
    if (!enProceso && http) {
       var url = "../leer_correo.asp?idmensaje="+ idmensaje +'&accion=leer';
	   //alert(url);
       http.open("GET", url, true);
       http.onreadystatechange = grabar_correo;
       enProceso = true;
       http.send(null);
    }
}

function grabar_correo() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 //alert(results)
			 //results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
             enProceso = false;
          }
       }
    }
}




function handleHttpResponse() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
			 pestanas_lateral('favoritos');
             document.getElementById('favo').innerHTML = results[0];
             document.getElementById('ids_favoritos').value = results[2];
			 if(results[1].length>5){mostrar_aviso(results[1])}
             enProceso = false;
          }
       }
    }
}


function handleHttpResponse2() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText; 
			 results = results.split("|")
             //document.getElementById("favoritos"). = results[0];
			 //pestanas_lateral('favoritos');
             //document.getElementById('favoritos').innerHTML = results[0];
			 if(results[1].length>5){mostrar_ayuda(results[1])}
             enProceso = false;
          }
       }
    }
}



function agregar_favoritos2(idempresa) {
    if (!enProceso && http) {
	   var items=document.getElementById('items_posibles').value
       var url = "agregarafavoritos.asp?tipo=favoritos&idempresa="+ idempresa +'&items='+ items;
       http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponse2;
       enProceso = true;
       http.send(null);
    }
}




function agregar_favoritos(idempresa) {	
	marcar_id(idempresa,'ids_favoritos');
	cargar_favoritos();
}





function eliminar_favoritos(idempresa) {
	desmarcar_id(idempresa,'ids_favoritos');
	cargar_favoritos();
}



function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}

var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest

function showAddress(address) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  //alert(address + " not found");
		} else {
		  map.setCenter(point);
		  //map.moveTo(point);
		 // var marker = new GMarker(point);
		  // map.addOverlay(marker);
		 // marker.openInfoWindowHtml(address);
		}
	  }
	);
  }
}


function ver_en_mapa(){
	var muni='';
	var prov='';
	if (document.form_mapa.idprovincia.selectedIndex>0){
	//alert('pro' + document.form_mapa.idprovincia.options[document.form_mapa.idprovincia.selectedIndex].text);
	prov = document.form_mapa.idprovincia.options[document.form_mapa.idprovincia.selectedIndex].text;
	//alert(document.form_mapa.idprovincia.options[document.form_mapa.idprovincia.selectedIndex].text);
	if (prov.indexOf('-')==-1) {
		var zoom=7;
		//alert('com')
	}else{
		var zoom=9;
		//alert('prov')
		prov=prov.replace('-','')
	}
	}
	
	if (document.form_mapa.idmunicipio.selectedIndex>0){
	//alert('muni' + document.form_mapa.idmunicipio.options[document.form_mapa.idmunicipio.selectedIndex].text);
	muni = document.form_mapa.idmunicipio.options[document.form_mapa.idmunicipio.selectedIndex].text;
	var zoom=11;
	}
	
	pais = document.form_mapa.idpais.options[document.form_mapa.idpais.selectedIndex].text
	map.setZoom(zoom);
	
	document.getElementById('direccionmapa').value = muni + ", " + prov + ", " + pais;
		showAddress(document.getElementById('direccionmapa').value);
}

function marcar_mu(idmunicipio,idprovincia,idpais){
	carga_pais(idpais,idprovincia,idmunicipio);
}

function marcar_pr(idprovincia,idpais){
	carga_pais(idpais,idprovincia,'');
}

function marcar_re(idregion,idpais){
	carga_pais_region(idpais,idregion,'');
}


function carga_pais(idpais,idprovincia,idmunicipio){
	document.getElementById('idpais').value = idpais;
	$('#idpais').change();
 	timer_pais=setInterval("carga_provincia(idprovincia,idmunicipio)",1000)
}

function carga_pais_region(idpais,idregion,idmunicipio){
	document.getElementById('idpais').value = idpais;
	$('#idpais').change();
 	timer_pais=setInterval("carga_region(idregion,idmunicipio)",1000)
}

function carga_region(idregion,idmunicipio){

	if(document.getElementById('idprovincia').length>1){
		document.getElementById('idprovincia').value = idregion;
		$('#idprovincia').change();
		clearInterval(timer_pais);
		if(idmunicipio!=''){
			timer_provincia=setInterval("carga_municipio(idmunicipio)",1000)
		}
	}

}

function carga_provincia(idprovincia,idmunicipio){

	if(document.getElementById('idprovincia').length>1){
		document.getElementById('idprovincia').value = idprovincia;
		$('#idprovincia').change();
		clearInterval(timer_pais);
		if(idmunicipio!=''){
			timer_provincia=setInterval("carga_municipio(idmunicipio)",1000)
		}
	}

}

function carga_municipio(idmunicipio){

	if(document.getElementById('idmunicipio').length>1){
		document.getElementById('idmunicipio').value = idmunicipio;
		clearInterval(timer_provincia);
	}

}

function borrar_buscador_libre(){
	if(document.getElementById('desactivar_encadenado').value == 'no'){
		document.getElementById('quebuscas').value='Actividad, empresa, servicio...';
		document.getElementById('quebuscas').style.color='#999999';
		document.getElementById('dondebuscas').value='Provincia, localidad...';
		document.getElementById('dondebuscas').style.color='#999999';
	}
}

function borrar_filtros(){
	array_check="1,15,36,50,70,79,89,97"
	array_check=array_check.split(",")

    for (var i=0; i<array_check.length; i++) {
		if(document.getElementById('check'+array_check[i]).checked == 1){
			GDownloadUrl("puntos-txt.asp?cat="+array_check[i], remove_it);
			document.getElementById('check'+array_check[i]).checked = false;
		}
	}
	
  campo = document.getElementById('idmunicipio')
  for (i=0; i<campo.options.length; i+1){
	  campo.options[i]=null;
  }
  
  campo = document.getElementById('idprovincia')
  for (i=0; i<campo.options.length; i+1){
	  campo.options[i]=null;
  }
  document.getElementById('idpais').value = 'elija';

}

function mostrar_pagina(tipo,pagina){

	for(i=1;i<100;i=i+1){
		if(document.getElementById('pag_'+i+'_'+tipo)){
			document.getElementById('pag_'+i+'_'+tipo).style.display='none';
			document.getElementById('bt_'+i+'_'+tipo).style.backgroundColor='#ffffff';
		}else{i=101}
	}
	
	document.getElementById('pag_'+pagina+'_'+tipo).style.display='block';
	document.getElementById('bt_'+pagina+'_'+tipo).style.backgroundColor='#BED600';

}

function marcar_id(valor,campo)
{
	
	valores=document.getElementById(campo).value;
	var array_valores = valores.split(',');
	//alert("Longitud del array: " + secciones.length)
	var agregar=true
	for (i=0;i<array_valores.length;i++){
		
		if (array_valores[i]==valor){
			//alert("te pille"+secciones[i]);
			agregar=false;
			indice=i
			break;
			}
		else
			{
			//alert("no esta"+secciones[i])
			}
	} 
	if(agregar){
		array_valores.splice(array_valores.length-1,0,valor);
	}
	document.getElementById(campo).value=array_valores.join();
}

function desmarcar_id(valor,campo)
{
	
	valores=document.getElementById(campo).value;
	var array_valores = valores.split(',');
	//alert("Longitud del array: " + secciones.length)
	var eliminar=false
	for (i=0;i<array_valores.length;i++){
		
		if (array_valores[i]==valor){
			//alert("te pille"+secciones[i]);
			eliminar=true;
			indice=i
			break;
			}
		else
			{
			//alert("no esta"+secciones[i])
			}
	} 
	if(eliminar){
		array_valores.splice(indice,1);
	}else{
		//array_valores.splice(array_valores.length-1,0,valor);
	}
	document.getElementById(campo).value=array_valores.join();
}


function findPos(obj) {
	//alert(obj);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
	while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
	}
	//alert(curleft+" \n"+curtop);
	return [curleft,curtop];
}

var capa1=0
var capa15=0
var capa36=0
var capa50=0
var capa70=0
var capa79=0
var capa89=0
var capa97=0
var capaareas=0
var caparutas=0
var capapuntos=0

function abrir_submenu(capa){
	//coordenadas_submenu = findPos(document.getElementById(capa));
	//alert(coordenadas_submenu[0]+' x '+coordenadas_submenu[1]);
	//document.getElementById('submenu_'+capa).style.display='block';
	if(capa=='1'){
		capa1=1;
	}else if(capa=='15'){
		capa15=1;
	}else if(capa=='36'){
		capa36=1;
	}else if(capa=='50'){
		capa50=1;
	}else if(capa=='70'){
		capa70=1;
	}else if(capa=='79'){
		capa79=1;
	}else if(capa=='89'){
		capa89=1;
	}else if(capa=='97'){
		capa97=1;
	}else if(capa=='areas'){
		capaareas=1;
	}else if(capa=='rutas'){
		caparutas=1;
	}else if(capa=='puntos'){
		capapuntos=1;
	}
	
	setTimeout("abrir_capa('"+capa+"')",600);

}


function cerrar_submenu(capa){
	//coordenadas_submenu = findPos(document.getElementById(capa));
	//alert(coordenadas_submenu[0]+' x '+coordenadas_submenu[1]);
	//alert(capa);
	
	if(capa=='1'){
		capa1=0;
	}else if(capa=='15'){
		capa15=0;
	}else if(capa=='36'){
		capa36=0;
	}else if(capa=='50'){
		capa50=0;
	}else if(capa=='70'){
		capa70=0;
	}else if(capa=='79'){
		capa79=0;
	}else if(capa=='89'){
		capa89=0;
	}else if(capa=='97'){
		capa97=0;
	}else if(capa=='areas'){
		capaareas=0;
	}else if(capa=='rutas'){
		caparutas=0;
	}else if(capa=='puntos'){
		capapuntos=0;
	}

	setTimeout("cerrar_capa('"+capa+"')",500);
}

function abrir_capa(capa){
	
	if(capa=='1'){
		capa_seleccionada=capa1
	}else if(capa=='15'){
		capa_seleccionada=capa15
	}else if(capa=='36'){
		capa_seleccionada=capa36
	}else if(capa=='50'){
		capa_seleccionada=capa50
	}else if(capa=='70'){
		capa_seleccionada=capa70
	}else if(capa=='79'){
		capa_seleccionada=capa79
	}else if(capa=='89'){
		capa_seleccionada=capa89
	}else if(capa=='97'){
		capa_seleccionada=capa97
	}else if(capa=='areas'){
		capa_seleccionada=capaareas
	}else if(capa=='rutas'){
		capa_seleccionada=caparutas
	}else if(capa=='puntos'){
		capa_seleccionada=capapuntos
	}
	
if(capa_seleccionada==1){
document.getElementById('submenu_'+capa).style.display='block';	
}
}


function cerrar_capa(capa){
	
	if(capa=='1'){
		capa_seleccionada=capa1
	}else if(capa=='15'){
		capa_seleccionada=capa15
	}else if(capa=='36'){
		capa_seleccionada=capa36
	}else if(capa=='50'){
		capa_seleccionada=capa50
	}else if(capa=='70'){
		capa_seleccionada=capa70
	}else if(capa=='79'){
		capa_seleccionada=capa79
	}else if(capa=='89'){
		capa_seleccionada=capa89
	}else if(capa=='97'){
		capa_seleccionada=capa97
	}else if(capa=='areas'){
		capa_seleccionada=capaareas
	}else if(capa=='rutas'){
		capa_seleccionada=caparutas
	}else if(capa=='puntos'){
		capa_seleccionada=capapuntos
	}
	
if(capa_seleccionada!=1){
document.getElementById('submenu_'+capa).style.display='none';	
}
}