var servletName = 'client';

// Precarga de las imagenes del documento
var imgarray = new Array; 
var iptr = 0;

function PreLoadImg(isrc){
	imgarray[iptr] = new Image;
	imgarray[iptr].src = isrc;
	return 	iptr++;
}

function InitDoc(){

	var x;

	// zooms
	x = PreLoadImg("img/zoom_in_a.gif");
	x = PreLoadImg("img/zoom_out_a.gif");
	x = PreLoadImg("img/zoom_in_p.gif");
	x = PreLoadImg("img/zoom_out_p.gif");

	// pans
	x = PreLoadImg("img/botones/pans/pan_nw_a.gif");
	x = PreLoadImg("img/botones/pans/pan_n_a.gif");
	x = PreLoadImg("img/botones/pans/pan_ne_a.gif");
	x = PreLoadImg("img/botones/pans/pan_sw_a.gif");
	x = PreLoadImg("img/botones/pans/pan_s_a.gif");
	x = PreLoadImg("img/botones/pans/pan_se_a.gif");
	x = PreLoadImg("img/botones/pans/pan_e_a.gif");
	x = PreLoadImg("img/botones/pans/pan_w_a.gif");
	x = PreLoadImg("img/botones/pans/pan_corner_h_a.gif");
	x = PreLoadImg("img/botones/pans/pan_corner_v_a.gif");

	// botones
	x = PreLoadImg("img/botones/herramientas/zoom_in_lupa.gif");
	x = PreLoadImg("img/botones/herramientas/zoom_in_lupa_a.gif");
	x = PreLoadImg("img/botones/herramientas/zoom_in_lupa_p.gif");
	x = PreLoadImg("img/botones/herramientas/zoom_out_lupa.gif");
	x = PreLoadImg("img/botones/herramientas/zoom_out_lupa_a.gif");
	x = PreLoadImg("img/botones/herramientas/zoom_out_lupa_p.gif");
	x = PreLoadImg("img/botones/herramientas/pan.gif");
	x = PreLoadImg("img/botones/herramientas/pan_a.gif");
	x = PreLoadImg("img/botones/herramientas/pan_p.gif");
	x = PreLoadImg("img/botones/herramientas/info.gif");
	x = PreLoadImg("img/botones/herramientas/info_a.gif");
	x = PreLoadImg("img/botones/herramientas/info_p.gif");
	x = PreLoadImg("img/botones/herramientas/info_geo.gif");
	x = PreLoadImg("img/botones/herramientas/info_geo_a.gif");
	x = PreLoadImg("img/botones/herramientas/info_geo_p.gif");

}

function timeNow() {
	var i = indiceHora();

	for (j = 1; j < i; j++){
	   setTimeout("proxim()", 50);
	}

}

function indiceHora() {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var i = hours * 2;

	if (minutes < 30){
	   i++;
	} else {
	   i += 2;
	}
	return i;
}


function proxim(){
	if (posicions.recordset.AbsolutePosition != posicions.recordset.RecordCount){
	   posicions.recordset.MoveNext();
	}
}


// Obtener el valor del elemento seleccionado en un ListBox
function valorLB(lb) {   
   var i;

   for (i=0; i<lb.length; i++) {
      if (lb[i].selected) {
         break;
      }
   }

   if (i < lb.length) {
      return lb[i].value;
   } else {
      return null;
   }
}

// Selección de todas las categorias
/*function seleccionarTodo(frm,textSel,textDes) {

	count = frm.poicats.length;

	var selected = "false";
	if (frm.inputSel.value == textDes) {
		selected = "";
		frm.inputSel.value = textSel;
	} else frm.inputSel.value = textDes;

	for (i=0; i<count ;i++ ) {
		frm.poicats[i].checked=selected;
		try {
			eval("frm.poicats[" + i + "].checked='"+ selected +"'");
		}
		catch (e){}
	}

} */


// Función para limpiar los campos que no contengan información válida
function limpiarCampos_ca(frm){

	validarCampo(frm, 'stn_o', 'Adreça', '');
//	validarCampo(frm, 'stnum_o', 'Nº', '');
	validarCampo(frm, 'ctn_o', 'Localitat', '');
	validarCampo(frm, 'stn_d', 'Adreça', '');
//	validarCampo(frm, 'stnum_d', 'Nº', '');
	validarCampo(frm, 'ctn_d', 'Localitat', '');
	validarCampo(frm, 'ctn_1', 'Localitat', '');
	validarCampo(frm, 'ctn_2', 'Localitat', '');
	validarCampo(frm, 'ctn_3', 'Localitat', '');
	validarCampo(frm, 'ctn_4', 'Localitat', '');

}

// Función para limpiar los campos que no contengan información válida
function limpiarCampos_es(frm){

	validarCampo(frm, 'stn_o', 'Dirección', '');
	//validarCampo(frm, 'stnum_o', 'Nº', '');
	validarCampo(frm, 'ctn_o', 'Localidad', '');
	validarCampo(frm, 'stn_d', 'Dirección', '');
	//validarCampo(frm, 'stnum_d', 'Nº', '');
	validarCampo(frm, 'ctn_d', 'Localidad', '');
	validarCampo(frm, 'ctn_1', 'Localidad', '');
	validarCampo(frm, 'ctn_2', 'Localidad', '');
	validarCampo(frm, 'ctn_3', 'Localidad', '');
	validarCampo(frm, 'ctn_4', 'Localidad', '');

}


// Validación de un campo
function validarCampo(frm, nom, valor, nouValor){
	if (frm[nom].value == valor){
		frm[nom].value = nouValor;
	}
}

// Definición de la función trim()
String.prototype.trim = function() {
	// skip leading and trailing whitespace
	// and return everything in between
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}


// Hacer una peticion de ruta
function pedirRuta(frm, servlet, lang){

	var urlRuta = "visor.jsp?cmd=route";
	
	if (lang == 'es') {
		
		if (frm.stn_d.value.trim() != 'Dirección'){ 
			var dir=new Array(2);
					
			dir[0]="";
			dir[1]="";

			dir=separaDireccion(trimRight(trimLeft(frm.stn_o.value)));
			var stn_o = "";
			var stnum_o = "";

			if(dir[0]!=""){
				stn_o = dir[0];
				urlRuta += "&stn_o="+stn_o;
			}

			if(dir[1]!=""){
				stnum_o = dir[1];
				urlRuta += "&stnum_o="+stnum_o;
			}
		}

		/*if (frm.stnum_o.value.trim() != 'Nº'){ urlRuta += "&stnum_o=" + frm.stnum_o.value.trim(); }*/
		if (frm.ctn_o.value.trim() != 'Localidad'){ urlRuta += "&ctn_o=" + frm.ctn_o.value.trim(); } else { alert('El campo Localidad es obligatorio.'); return false; }
		if (frm.ctryc_o.selectedIndex != 0){ urlRuta += "&ctryc_o=" + frm.ctryc_o[frm.ctryc_o.selectedIndex].value; }

		if (frm.stn_d.value.trim() != 'Dirección'){ 

			var dir=new Array(2);
					
			dir[0]="";
			dir[1]="";

			dir=separaDireccion(trimRight(trimLeft(frm.stn_d.value)));
			var stn_d = "";
			var stnum_d = "";

			if(dir[0]!=""){
				stn_d = dir[0];
				urlRuta += "&stn_d="+stn_d;
			}

			if(dir[1]!=""){
				stnum_d = dir[1];
				urlRuta += "&stnum_d="+stnum_d;
			}
		}

		//if (frm.stnum_d.value.trim() != 'Nº'){ urlRuta += "&stnum_d=" + frm.stnum_d.value.trim(); }
		if (frm.ctn_d.value.trim() != 'Localidad'){ urlRuta += "&ctn_d=" + frm.ctn_d.value.trim(); } else { alert('El campo Localidad es obligatorio.'); return false; }
		if (frm.ctryc_d.selectedIndex != 0){ urlRuta += "&ctryc_d=" + frm.ctryc_d[frm.ctryc_d.selectedIndex].value; }

		// Validamos los valores de los campos obligatorios de cada una de las paradas
		//if (!validarPaisEtapas_es(frm)){ return false };

		// Añadimos los parámetros referentes a las diferentes paradas
		urlRuta += anadirParadas_es(frm);

		// Añadimos el parámetro WEIGHT para determinar el tipo de ruta (Time, Distance, Money)
		urlRuta += anadirTipoRuta(frm);

		// Eliminamos los valores que ponemos por defecto
		limpiarCampos_es(frm);

	} else {

		if (frm.stn_o.value.trim() != 'Adreça'){ 
			var dir=new Array(2);
					
			dir[0]="";
			dir[1]="";

			dir=separaDireccion(trimRight(trimLeft(frm.stn_o.value)));
			var stn_o = "";
			var stnum_o = "";

			if(dir[0]!=""){
				stn_o = dir[0];
				urlRuta += "&stn_o="+stn_o;
			}

			if(dir[1]!=""){
				stnum_o = dir[1];
				urlRuta += "&stnum_o="+stnum_o;
			}			
		}
		//if (frm.stnum_o.value.trim() != 'Nº'){ urlRuta += "&stnum_o=" + frm.stnum_o.value.trim(); }
		if (frm.ctn_o.value.trim() != 'Localitat'){ urlRuta += "&ctn_o=" + frm.ctn_o.value.trim(); } else { alert('El camp Localitat és obligatori.'); return false; }
		if (frm.ctryc_o.selectedIndex != 0){ urlRuta += "&ctryc_o=" + frm.ctryc_o[frm.ctryc_o.selectedIndex].value; }
		if (frm.stn_d.value.trim() != 'Adreça'){ 
			var dir=new Array(2);
					
			dir[0]="";
			dir[1]="";

			dir=separaDireccion(trimRight(trimLeft(frm.stn_d.value)));
			var stn_d = "";
			var stnum_d = "";

			if(dir[0]!=""){
				stn_d = dir[0];
				urlRuta += "&stn_d="+stn_d;
			}

			if(dir[1]!=""){
				stnum_d = dir[1];
				urlRuta += "&stnum_d="+stnum_d;
			}
		}
		//if (frm.stnum_d.value.trim() != 'Nº'){ urlRuta += "&stnum_d=" + frm.stnum_d.value.trim(); }
		if (frm.ctn_d.value.trim() != 'Localitat'){ urlRuta += "&ctn_d=" + frm.ctn_d.value.trim(); } else { alert('El camp Localitat és obligatori.'); return false; }
		if (frm.ctryc_d.selectedIndex != 0){ urlRuta += "&ctryc_d=" + frm.ctryc_d[frm.ctryc_d.selectedIndex].value; }

		// Validamos los valores de los campos obligatorios de cada una de las paradas
		//if (!validarPaisEtapas_ca(frm)){ return false };
		// Añadimos los parámetros referentes a las diferentes paradas
		urlRuta += anadirParadas_ca(frm);
		// Añadimos el parámetro WEIGHT para determinar el tipo de ruta (Time, Distance, Money)
		urlRuta += anadirTipoRuta(frm);
		// Eliminamos los valores que ponemos por defecto
		limpiarCampos_ca(frm);
	}

	urlRuta += "&domini=" + frm.domini.value;
	urlRuta += "&lang=" + lang;
	urlRuta += "&mindist=0";
	urlRuta += "&numcand_o=300";
	urlRuta += "&numcand_d=300";

	location.href = urlRuta;
	return false;

}



// Validamos los valores de los campos obligatorios de cada una de las paradas
function validarPaisEtapas_es(frm){
	if ( (frm.ctryc_1.selectedIndex == 0 && (frm.ctn_1.value.trim() != "Localidad" && frm.ctn_1.value.trim() != "")) ||
		 (frm.ctryc_2.selectedIndex == 0 && (frm.ctn_2.value.trim() != "Localidad" && frm.ctn_2.value.trim() != "")) ||
		 (frm.ctryc_3.selectedIndex == 0 && (frm.ctn_3.value.trim() != "Localidad" && frm.ctn_3.value.trim() != "")) ||
		 (frm.ctryc_4.selectedIndex == 0 && (frm.ctn_4.value.trim() != "Localidad" && frm.ctn_4.value.trim() != "")) ){
		alert('Debe escoger un país.');
		return false;
	}
	return true;
}

function validarPaisEtapas_ca(frm){
	if ( (frm.ctryc_1.selectedIndex == 0 && (frm.ctn_1.value.trim() != "Localitat" && frm.ctn_1.value.trim() != "")) ||
		 (frm.ctryc_2.selectedIndex == 0 && (frm.ctn_2.value.trim() != "Localitat" && frm.ctn_2.value.trim() != "")) ||
		 (frm.ctryc_3.selectedIndex == 0 && (frm.ctn_3.value.trim() != "Localitat" && frm.ctn_3.value.trim() != "")) ||
		 (frm.ctryc_4.selectedIndex == 0 && (frm.ctn_4.value.trim() != "Localitat" && frm.ctn_4.value.trim() != "")) ){
		alert("Ha d'escollir un país.");
		return false;
	}
	return true;
}


function anadirParadas_es(frm){
	var retorno = "";

	if (frm.ctn_1.value.trim() != 'Localidad' && frm.ctn_1.value.trim() != ''){ 
		retorno += "&ctn_1=" + frm.ctn_1.value.trim(); 
		retorno += "&ctryc_1=" + frm.ctryc_1[frm.ctryc_1.selectedIndex].value;
	}
	if (frm.ctn_2.value.trim() != 'Localidad' && frm.ctn_2.value.trim() != ''){ 
		retorno += "&ctn_2=" + frm.ctn_2.value.trim(); 
		retorno += "&ctryc_2=" + frm.ctryc_2[frm.ctryc_2.selectedIndex].value;
	}
	if (frm.ctn_3.value.trim() != 'Localidad' && frm.ctn_3.value.trim() != ''){ 
		retorno += "&ctn_3=" + frm.ctn_3.value.trim(); 
		retorno += "&ctryc_3=" + frm.ctryc_3[frm.ctryc_3.selectedIndex].value;
	}
	if (frm.ctn_4.value.trim() != 'Localidad' && frm.ctn_4.value.trim() != ''){ 
		retorno += "&ctn_4=" + frm.ctn_4.value.trim(); 
		retorno += "&ctryc_4=" + frm.ctryc_4[frm.ctryc_4.selectedIndex].value;
	}

	return retorno;
}

function anadirParadas_ca(frm){
	var retorno = "";

	if (frm.ctn_1.value.trim() != 'Localitat' && frm.ctn_1.value.trim() != ''){ 
		retorno += "&ctn_1=" + frm.ctn_1.value.trim(); 
		retorno += "&ctryc_1=" + frm.ctryc_1[frm.ctryc_1.selectedIndex].value;
	}
	if (frm.ctn_2.value.trim() != 'Localitat' && frm.ctn_2.value.trim() != ''){ 
		retorno += "&ctn_2=" + frm.ctn_2.value.trim(); 
		retorno += "&ctryc_2=" + frm.ctryc_2[frm.ctryc_2.selectedIndex].value;
	}
	if (frm.ctn_3.value.trim() != 'Localitat' && frm.ctn_3.value.trim() != ''){ 
		retorno += "&ctn_3=" + frm.ctn_3.value.trim(); 
		retorno += "&ctryc_3=" + frm.ctryc_3[frm.ctryc_3.selectedIndex].value;
	}
	if (frm.ctn_4.value.trim() != 'Localitat' && frm.ctn_4.value.trim() != ''){ 
		retorno += "&ctn_4=" + frm.ctn_4.value.trim(); 
		retorno += "&ctryc_4=" + frm.ctryc_4[frm.ctryc_4.selectedIndex].value;
	}

	return retorno;
}


// Añadimos el parámetro WEIGHT para determinar el tipo de ruta (Time, Distance, Money)
function anadirTipoRuta(frm){
	var retorno = "";

	if (frm.weight[0].checked) { retorno += "&weight=time"; }
	if (frm.weight[1].checked) { retorno += "&weight=distance"; }
	if (frm.weight[2].checked) { retorno += "&weight=money"; }

	return retorno;
}


// Función para mostrar/ocultar los mapas de cada etapa en la ruta detallada
function minimapa(capa, src, stringmostrar, stringamagar){
	if(document.getElementById(capa).innerHTML.indexOf("<img") < 0 && document.getElementById(capa).innerHTML.indexOf("<IMG") < 0){
		var codiHtml = "<IMG src='" + src + "' style='margin: 4px'/>";

		document.getElementById(capa).innerHTML = codiHtml;
		document.getElementById("link" + capa.substring(4)).innerHTML = "<IMG src=\"img/rutas/mapa_detall.gif\" border=\"0\"/>&#160;<A href=\"javascript:minimapa('" + capa + "', '" + src + "', '" + stringmostrar + "', '" + stringamagar + "')\" class=\"reportTextBlue\">" + stringamagar + "</A>";
	} else {
		var codiHtml = " ";

		document.getElementById(capa).innerHTML = codiHtml;
		document.getElementById("link" + capa.substring(4)).innerHTML = "<IMG src=\"img/rutas/mapa_detall.gif\" border=\"0\"/>&#160;<A href=\"javascript:minimapa('" + capa + "', '" + src + "', '" + stringmostrar + "', '" + stringamagar + "')\" class=\"reportTextBlue\">" + stringmostrar + "</A>";
	}
}

// Función para recargar el Frame PARENT con una URL
function botonTamano(par){
	parent.location.href = par;
}


// Situal el slider segun la escala del parametro. scale=[0..13]
function sliderMove2Scale(scale) {

  var theImg = document.getElementById("slider_bt");// valores [0..64]
  var pixLeft = parseInt(scale) * 64 / 13;
  theImg.style.left = pixLeft;

}

// declaramos variable
var sliderMouseDown = false;

function sliderButton_mouseDownEvent (e) {

  if (!e) e = window.event;

  if (!sliderMouseDown) sliderMouseDown = true;

  return false;
}


function sliderButton_mouseUpEvent (e) {

  if (!e) e = window.event;

  try {
	  var theImg = document.getElementById("slider_bt");// valores [0..64]
	  var sliderWidth = parseInt(document.getElementById("slider_bg").style.width);

      //theImg.style.left = e.x;

	  var valor = parseInt(theImg.style.left);
	  var numScales = 13; // [0..13]
	  var pixMax = sliderWidth - theImg.width ; // valor maximo posible de theImg
	  
	  if (valor > pixMax) valor = pixMax;
	  if (valor < 0) valor = 0;

	  var percent = valor / pixMax * 100;

	  var scale = percent * numScales / 100;
	  scale = Math.round(scale);

	  window.status = "scale: " + scale;

	  sliderScaleChange(scale);
  } catch(e) {}

  sliderMouseDown = false;  
  return false;
}


function sliderButton_mouseMoveEvent (evt) {

  var e = evt || window.event;
  if (!sliderMouseDown) return false;

  // targ: who received the event
  if (e.target) targ = e.target;
  else if (e.srcElement) targ = e.srcElement;
  if (targ.nodeType == 3) // defeat Safari bug
	targ = targ.parentNode;

  if (targ.id == "" || e.x < 0) return false;
  if (targ.id == "slider_bt") theImg = targ;
  else theImg = document.getElementById("slider_bt");


  offX = (theImg.width/2);
  var sliderWidth = parseInt(document.getElementById("slider_bg").style.width);
  var sliderHeight = parseInt(document.getElementById("slider_bg").style.height);
  var sliderTop = parseInt(document.getElementById("slider_bg").style.top);
  var sliderLeft = parseInt(document.getElementById("slider_bg").style.left);

  var newLeft = e.x - offX;
  if (newLeft < 0) newLeft = 0;
  if (newLeft > sliderWidth - theImg.width) newLeft = sliderWidth - theImg.width;


  theImg.style.left = newLeft;
  return false;  
}


// Añadir getpoicats para cada poicat seleccionado
/*function activarGetpoicats(frm, baseurl){

	var origen;
	if (parent.oculto.location.href.indexOf("oculto.html") >= 0){
		origen=document.forms[0];
	} else {
		origen=parent.oculto.document.forms[0];
	}

	var newurl = "oculto?cmd="+origen.cmd.value+"&labelop=0&label=&smap=1&lang=es&width=570&height=470";
	newurl += "&center="+origen.center.value+"&labelpt="+origen.center.value+"&scale="+origen.scale.value;

	frm = document.forms['categorias'];
	for (var i = 0; i < frm.elements.length; i++){
		if (frm.elements[i].name == 'poicats' && frm.elements[i].value != '' && frm.elements[i].checked){
			newurl += "&poicats=" + frm.elements[i].value;
		}
	}

	if(document.getElementById("EU1").checked){
		newurl += "&poicats=866" + document.getElementById("EU1").value;
	}
	if(document.getElementById("EU2").checked){
		newurl += "&poicats=866" + document.getElementById("EU2").value;
	}
	if(document.getElementById("EU3").checked){
		newurl += "&poicats=866" + document.getElementById("EU3").value;
	}
	if(document.getElementById("EU4").checked){
		newurl += "&poicats=866" + document.getElementById("EU4").value;
	}
	if(document.getElementById("EU5").checked){
		newurl += "&poicats=866" + document.getElementById("EU5").value;
	}


	var params = baseurl.split("&");
	//obtenemos los parametros de la baseurl pq se pasan los shapes y molists que debemos pintar
	for(var i = 0; i < params.length; i++){
		if(params[i].substring(0,5) == 'shape' || params[i].substring(0,5) == 'molis' || params[i].substring(0,5) == 'route'){
			newurl += "&" + params[i];
		}
	}


	ocultarInfoTooltip();
	parent.main.document.getElementById("wait").style.visibility= "visible";
	parent.oculto.location.href=newurl;
	return false;
}*/

// Muestra u oculta el layer con el nombre del parametro
/*function mostrarDiv(layerId) {
	var theDiv = document.getElementById(layerId);
	var theImg = document.getElementById("poisMenu");

	if (theDiv.style.visibility == "hidden") {
		theDiv.style.visibility = "visible";
		theImg.src = "img/botones/herramientas/pois_p.gif";
	}
	else {
		theDiv.style.visibility = "hidden";
		theImg.src = "img/botones/herramientas/pois.gif";
	}
}*/

// pone a invisible el tooltip
function ocultarInfoTooltip() {
	try {// por si no esta activo
		document.getElementById("infoTooltip").style.visibility="hidden";//caja
	} catch (e)	{}
	try {
		document.getElementById("spotTooltip").style.visibility="hidden";//xinxeta
	} catch (e)	{}
}

// recibe la accion de mouseover/out de las imagenenes de pan de los corners.
// propaga el evento a las imageners assiciadas.
function panButtonCornerMouse(panPattern,isOver) {
	var imgCorner = document.getElementById("img_"+panPattern);
	var imgCornerH = document.getElementById("img_"+panPattern+"_h");
	var imgCornerV = document.getElementById("img_"+panPattern+"_v");

	var overId = "";
	if (isOver == true) overId = "_a";
	imgCorner.src="img/botones/pans/"+panPattern+overId+".gif";
	imgCornerH.src="img/botones/pans/pan_corner_h"+overId+".gif";
	imgCornerV.src="img/botones/pans/pan_corner_v"+overId+".gif";
}

// recibe la accion de mouseover de las imagenenes de pan de los corners.
// propaga el evento a las imageners assiciadas.
function panButtonCornerMouseOver(panPattern) {
	var imgCorner = document.getElementById("img_"+panPattern);
	var imgCornerH = document.getElementById("img_"+panPattern+"_h");
	var imgCornerV = document.getElementById("img_"+panPattern+"_v");
	imgCorner.src="img/botones/pans/"+panPattern+"_a.gif";
	imgCornerH.src="img/botones/pans/"+panPattern+"_h_a.gif";
	imgCornerV.src="img/botones/pans/"+panPattern+"_h_a.gif";
}

// *************************** BOTONES DE HERRAMIENTAS ***************************

// Contol de los botones de herramientas al salir de uno de ellos
function botonMouseOut(boton){
	if (herramienta != boton.id){
		if (boton.id == "zoomin") boton.src="img/botones/herramientas/zoom_in_lupa.gif";
		if (boton.id == "zoomout") boton.src="img/botones/herramientas/zoom_out_lupa.gif";
		if (boton.id == "pan") boton.src="img/botones/herramientas/pan.gif";
		if (boton.id == "info") boton.src="img/botones/herramientas/info.gif";
		if (boton.id == "info_geo") boton.src="img/botones/herramientas/info_geo.gif";
	}
}

// Control de los botones de herramientas al pulsar uno de ellos
function botonMouseUp(boton){
	if (boton.id == "zoomin"){
		boton.src="img/botones/herramientas/zoom_in_lupa_p.gif"; canviarCursor('zoomin');
		document.getElementById('zoomout').src = "img/botones/herramientas/zoom_out_lupa.gif";
		document.getElementById('pan').src = "img/botones/herramientas/pan.gif";
		document.getElementById('info').src = "img/botones/herramientas/info.gif";
		document.getElementById('info_geo').src = "img/botones/herramientas/info_geo.gif";
	}
	if (boton.id == "zoomout"){
		document.getElementById('zoomin').src = "img/botones/herramientas/zoom_in_lupa.gif";
		boton.src="img/botones/herramientas/zoom_out_lupa_p.gif"; canviarCursor('zoomout');
		document.getElementById('pan').src = "img/botones/herramientas/pan.gif";
		document.getElementById('info').src = "img/botones/herramientas/info.gif";
		document.getElementById('info_geo').src = "img/botones/herramientas/info_geo.gif";
	}
	if (boton.id == "pan"){
		document.getElementById('zoomin').src = "img/botones/herramientas/zoom_in_lupa.gif";
		document.getElementById('zoomout').src = "img/botones/herramientas/zoom_out_lupa.gif";
		boton.src="img/botones/herramientas/pan_p.gif"; canviarCursor('pan');
		document.getElementById('info').src = "img/botones/herramientas/info.gif";
		document.getElementById('info_geo').src = "img/botones/herramientas/info_geo.gif";
	}
	if (boton.id == "info"){
		document.getElementById('zoomin').src = "img/botones/herramientas/zoom_in_lupa.gif";
		document.getElementById('zoomout').src = "img/botones/herramientas/zoom_out_lupa.gif";
		document.getElementById('pan').src = "img/botones/herramientas/pan.gif";
		boton.src="img/botones/herramientas/info_p.gif"; canviarCursor('info');
		document.getElementById('info_geo').src = "img/botones/herramientas/info_geo.gif";
	}
	if (boton.id == "info_geo"){
		document.getElementById('zoomin').src = "img/botones/herramientas/zoom_in_lupa.gif";
		document.getElementById('zoomout').src = "img/botones/herramientas/zoom_out_lupa.gif";
		document.getElementById('pan').src = "img/botones/herramientas/pan.gif";
		document.getElementById('info').src = "img/botones/herramientas/info.gif";
		boton.src="img/botones/herramientas/info_geo_p.gif"; canviarCursor('info_geo');
	}
}

// Control de los botones de herramientas al entrar en uno de ellos
function botonMouseOver(boton){
	if (herramienta != boton.id){
		if (boton.id == "zoomin") boton.src="img/botones/herramientas/zoom_in_lupa_a.gif";
		if (boton.id == "zoomout") boton.src="img/botones/herramientas/zoom_out_lupa_a.gif";
		if (boton.id == "pan") boton.src="img/botones/herramientas/pan_a.gif";
		if (boton.id == "info") boton.src="img/botones/herramientas/info_a.gif";
		if (boton.id == "info_geo") boton.src="img/botones/herramientas/info_geo_a.gif";
	}
}

// resize del iframe de
function rutasIframeResize(theIframe, smallWidth, smallHeight,bigWidth, bigHeight) {
	//var theIframe = parent.document.getElementById("main");
	if (theIframe == undefined) return false;// Si no estamos en rutas no hacemos nada.

	var newWidth=0;
	var newHeight=0;

	// comprovamos tamaño actual
	if (theIframe.width != bigWidth) {
		return false;
	} else {
		newWidth=bigWidth;  
		newHeight=bigHeight; 
	}
	//alert("before:" + theIframe.width);
	theIframe.width=newWidth + "px";
	theIframe.height=newHeight + "px";
	//alert("after:" + theIframe.width);

	return false;
}

// peticion de zoom a una de las paradas de la ruta
function rutasZoomToStage(urlIframe,zoomParams) {
	
	var theMainDocument = frames['main'].document;
	if (theMainDocument == undefined) return false; // si aun no se ha cargado el mapa
	
	// para obtener parametros actuales. Si es la primera peticion aun no tenemos el oculto y debemos mirar en en principal
	var theForm = frames['oculto'].document.forms['frmmapa'];
	if (theForm == undefined) theForm = theMainDocument.forms["frmmapa"];


	var theUrl = urlIframe + zoomParams +
		'&smap=1' +
		'&newWidth=' + theForm.width.value +
		'&newHeight=' + theForm.height.value;
	
	// si hay pois activado los mantenemos
	for (var i=0; i<theForm.length; i++) {
		if (theForm.elements[i].name == "poicats") {
			theUrl += "&poicats=" + theForm.elements[i].value;
		}
	}

	frames['main'].location.href=theUrl;
}


function tratarStyle(select){
	for(var i=0; i<select.options.length; i++){
		if(select.options[i].selected){
			select.options[i].className = "textFocused";
		}else{
			select.options[i].className = "text";
		}
	}
}
