var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
if (!IE) document.captureEvents(Event.keyCode)
var e;
function guardaTexto(texto){

	texto=texto.replace(/…/gi, '...');
	texto=texto.replace(/—/gi, '-');
	texto=texto.replace(/“/gi,'"');
	texto=texto.replace(/”/gi,'"');
	texto=texto.replace(/‘/gi, "'");
	texto=texto.replace(/’/gi, "'");
	texto=texto.replace(/´/gi, "'");
	texto=texto.replace(/•/gi, "-");
	texto=texto.replace(/&euro;/gi, '#euro;');
	texto=texto.replace(/\u20ac/g, '#euro;');
	texto=texto.replace(/&/gi, '#y#');

	return texto;
}
function muevePanel(e){
	if (IE) { 
		posX = event.clientX;
		posY = event.clientY;
	}else{ 
		posX = e.pageX;
		posY = e.pageY;
	}

	var elemento = document.getElementById('subcabeceraIzquierda');
	var posCapa = getAbsoluteElementPosition(elemento)

	posX=posX-posCapa.left+20;
	posY=posY-posCapa.top+20;

	document.getElementById('panel').style.left=posX+"px";
	document.getElementById('panel').style.top=posY+"px";

}

function getAbsoluteElementPosition(element) {
	if (typeof element == "string") element = document.getElementById(element)
	if (!element) return { top:0,left:0 };
	var y = 0;
	var x = 0;
	while (element.offsetParent) {
		x += element.offsetLeft;
		y += element.offsetTop;
		element = element.offsetParent;
	}
	return {top:y,left:x};
}

function panel(texto, e){
	muevePanel(e);
	document.getElementById('panel').style.display='block';
	document.getElementById('panel').innerHTML=texto+'&nbsp;&nbsp;<img style=\'vertical-align:middle;\' src=\'http://www.ruralvive.com/imagenes/simbolo.jpg\'>';	
}

function panelPlaya(texto, e){
	muevePanel(e);
	document.getElementById('panel').style.display='block';
	document.getElementById('panel').innerHTML=texto;	
}

function cambiaCapa(capa){
	if (document.getElementById(capa).style.display=='block') document.getElementById(capa).style.display='none';
	else if (document.getElementById(capa).style.display='none') document.getElementById(capa).style.display='block';
}

function cambiaCheck(id, nombre, contador){
	if (document.getElementById('localizacion'+contador).checked) anadeLocalizacion(id, nombre, contador);
	else quitaLocalizacion(id, nombre, contador);
}
function anadeLocalizacion(id, nombre, contador){
	apunte=', <span class="localizacion">'+nombre+'<a href="javascript:quitaLocalizacion(\''+id+'\', \''+nombre+'\', \''+contador+'\')">[x]</a></span> ';
	if (!document.getElementById(nombre+id)) document.getElementById('localizacionSeleccionada').innerHTML=document.getElementById('localizacionSeleccionada').innerHTML+' <span id="'+nombre+id+'">'+apunte+'</span> ';
	else document.getElementById(nombre+id).innerHTML=apunte;
}
function quitaLocalizacion(id, nombre, contador){
	document.getElementById(nombre+id).innerHTML='';
	if (document.getElementById('localizacion'+contador).checked) document.getElementById('localizacion'+contador).click();
}


function cambiaCheckActivo(id, nombre, contador){
	if (document.getElementById('localizacionActivo'+contador).checked) anadeLocalizacionActivo(id, nombre, contador);
	else quitaLocalizacionActivo(id, nombre, contador);
}
function anadeLocalizacionActivo(id, nombre, contador){
	apunte=', <span class="localizacionActivo">'+nombre+'<a href="javascript:quitaLocalizacionActivo(\''+id+'\', \''+nombre+'\', \''+contador+'\')">[x]</a></span> ';
	if (!document.getElementById(nombre+id+'activo')) document.getElementById('localizacionActivoSeleccionada').innerHTML=document.getElementById('localizacionActivoSeleccionada').innerHTML+' <span id="'+nombre+id+'activo'+'">'+apunte+'</span> ';
	else document.getElementById(nombre+id+'activo').innerHTML=apunte;
}
function quitaLocalizacionActivo(id, nombre, contador){
	document.getElementById(nombre+id+'activo').innerHTML='';
	if (document.getElementById('localizacionActivo'+contador).checked) document.getElementById('localizacionActivo'+contador).click();
}
function cambiaCheckServicios(id, nombre, contador){
	if (document.getElementById('servicio'+contador).checked) anadeServicio(id, nombre, contador);
	else quitaServicio(id, nombre, contador);
}
function anadeServicio(id, nombre, contador){
	apunte=', <span class="localizacion">'+nombre.replace('servicio', '')+'<a href="javascript:quitaServicio(\''+id+'\', \''+nombre+'\', \''+contador+'\')">[x]</a></span>';
	if (!document.getElementById(nombre+id)) document.getElementById('serviciosSeleccionados').innerHTML=document.getElementById('serviciosSeleccionados').innerHTML+'<span id="'+nombre+id+'">'+apunte+'</span> ';
	else document.getElementById(nombre+id).innerHTML=apunte;
}
function quitaServicio(id, nombre, contador){
	document.getElementById(nombre+id).innerHTML='';
	if (document.getElementById('servicio'+contador).checked) document.getElementById('servicio'+contador).click();
}

function onTecla(e)	{	
	var tecla = String.fromCharCode(e?e.keyCode:event.keyCode);		
} 	
document.onkeydown = onTecla;	
if (!IE) if(document.all)document.captureEvents(Event.KEYDOWN);

function validaTecla(e){
  tecla = (document.all) ? e.keyCode : e.which;
  return tecla;
}
function alineaPie(){
	if (document.getElementById("tabla1")) anchura1=document.getElementById("tabla1").offsetWidth;
	else anchura1=0;
	if (document.getElementById("tabla2")) anchura2=document.getElementById("tabla2").offsetWidth;
	else anchura2=0;
	if (document.getElementById("tabla3")) anchura3=document.getElementById("tabla3").offsetWidth;
	else anchura3=0;
	if (document.getElementById("tabla4")) anchura4=document.getElementById("tabla4").offsetWidth;
	else anchura4=0;
	if (document.getElementById("tabla5")) anchura5=document.getElementById("tabla5").offsetWidth;
	else anchura5=0;

	var maxAnchura=0;
	if (anchura1>maxAnchura) maxAnchura=anchura1;
	if (anchura2>maxAnchura) maxAnchura=anchura2;
	if (anchura3>maxAnchura) maxAnchura=anchura3;
	if (anchura4>maxAnchura) maxAnchura=anchura4;
	if (anchura5>maxAnchura) maxAnchura=anchura5;

	if (document.getElementById('tabla1')) document.getElementById('tabla1').style.width=maxAnchura+"px";
	if (document.getElementById('tabla2')) document.getElementById('tabla2').style.width=maxAnchura+"px";
	if (document.getElementById('tabla3')) document.getElementById('tabla3').style.width=maxAnchura+"px";
	if (document.getElementById('tabla4')) document.getElementById('tabla4').style.width=maxAnchura+"px";
	if (document.getElementById('tabla5')) document.getElementById('tabla5').style.width=maxAnchura+"px";
	if (document.getElementById("textoLugares")) document.getElementById('textoLugares').style.width=maxAnchura+"px";
}
function asignaVariable(nombre, valor){
	eval(nombre+'='+valor+';');
}
