	
var busquedaa=0;var opt=0;var spc=0;  
function utf8_encode ( string ) {
    // http://kevin.vanzonneveld.net
    string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net

    var tmp_arr = [], i = ac = c1 = c2 = c3 = 0;
 
    str_data += '';
 
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return tmp_arr.join('');
}
function inicializar(){
    busquedaa=0;
    opt=document.getElementById('opciones');
    spc=document.getElementById('espazos');   
    
    if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.indexOf('MSIE 4') < 0)){
        var busca=document.getElementById('busquedas');
        opt.style.overflow="hidden";
        opt.style.visibility="hidden";   
        opt.style.height="0px";  
        spc.style.visibility="visible";
        opt.style.background="#FFF6BF none repeat scroll 0 0";
        opt.style.border="2px solid #FFD324";
        opt.style.color="#817134";
        opt.style.width="414px";
        busca.style.width="414px"; 
        spc.style.height="30px";
        opt.style.width="412px";    
        opt.style.marginBottom = "0px";
    }
    else{   
        opt.style.overflow="hidden";
        opt.style.visibility="hidden";   
        opt.style.height="0px";  
        spc.style.visibility="visible";
        opt.style.background="#FFF6BF none repeat scroll 0 0";
        opt.style.border="2px solid #FFD324";
        opt.style.color="#817134";
        spc.style.height="30px";
        opt.style.width="417px";   
        opt.style.marginBottom = "0px";
    }
}
    
    
    
    function prueba(x){ //para  o tipo  e para amosar extras 
		document.getElementById("encoche").style.visibility = "hidden";
		document.getElementById("ape").style.visibility = "hidden";
		document.getElementById("pavo").style.visibility = "hidden";
		document.getElementById("coche").style.visibility = "hidden";
		document.getElementById("fotos").innerHTML = '';
		document.getElementById("extras").innerHTML = '';
		if (x==2) {
			document.getElementById("encoche").style.visibility="visible";
			document.getElementById("coche").style.visibility="visible";
		}else{
			document.getElementById("ape").style.visibility="visible";
			document.getElementById("pavo").style.visibility="visible";
		}
		if(x==2){
			document.getElementById("fotos").innerHTML='<h4>FOTOS:</h4><br><IFRAME src="http://farm4.static.flickr.com/3136/2627169901_4187458e9b.jpg?v=0">'
			document.getElementById("fotos").innerHTML='<h4>VIDEOS:</h4><BR><p id="player1"><embed width="350" height="263" flashvars="logo=http://www.culturagalega.org/imaxes/logoplayer.png&amp;file=http://www.culturagalega.org/avg/avg_imax/audiovisual/ami.flv&amp;image=miniatura_video_ami.jpg" allowfullscreen="true" quality="high" name="single" id="single" style="" src="http://www.culturagalega.org/TV/flvplayer.swf" type="application/x-shockwave-flash"/></p>';
			document.getElementById("extras").innerHTML='<h4>EXTRAS:</h4><BR><IFRAME src="http://farm1.static.flickr.com/84/234891446_4cef94a1c2.jpg?v=0">';
		}else{
			document.getElementById("fotos").innerHTML='<h4>FOTOS:</h4></h4><br><IFRAME src="http://farm1.static.flickr.com/142/356863057_67f0c6dba1.jpg?v=1189629620">';
			document.getElementById("extras").innerHTML='<h4>EXTRAS:</h4><BR><IFRAME src="http://farm3.static.flickr.com/2094/2087879492_4771871d28.jpg?v=0">';
		}
			
	}
	function eliminaDiv(){
			
			try{
			var el = document.getElementById("mono");
			var padre = el.parentNode;
			padre.removeChild(el);
			}catch(erro){
			}
			
	}
	
	function activaInfo(){

			document.getElementById("info").style.visibility = 'visible';

	}
	
	function salir(){

			document.getElementById("info").style.visibility = 'hidden';
	}
	
	function muestraContenido() {
		
		eliminaDiv();
		activaInfo();
		var nuevoDiv = document.createElement("div");
		nuevoDiv.setAttribute("id","mono");
		nuevoDiv.innerHTML = this.req.responseText;
		
		var info = window.parent.document.getElementById('info');
		info.appendChild(nuevoDiv);
	}
	
	function muestraContenidoTit() {
		
		eliminaDiv();
		salir();
		var info2 = window.parent.document.getElementById('txt_ttlo');
		info2.innerHTML = this.req.responseText;
	}
 
    function cargaContenidos(id) {
		var cargador = new net.CargadorContenidos("roteiro_datos.php?cod_rtro="+id, muestraContenido);
	}
	
	function cargaContenidosTit(id) {
		var cargador2 = new net.CargadorContenidos("roteiro_datosTit.php?cod_rtro="+id, muestraContenidoTit);
	}
 
    //window.onload = cargaContenidos(1);      //Si quisiera empezar la pagina cargando unos contenidos (aleatorios por ejemplo)

		var net = new Object();
 
		net.READY_STATE_UNINITIALIZED=0;
		net.READY_STATE_LOADING=1;
		net.READY_STATE_LOADED=2;
		net.READY_STATE_INTERACTIVE=3;
		net.READY_STATE_COMPLETE=4;
 
// Constructor
	net.CargadorContenidos = function(url, funcion, funcionError) {
    this.url = url;
	this.req = null;
	this.onload = funcion;
	this.onerror = (funcionError) ? funcionError : this.defaultError;
	this.cargaContenidoXML(url);
}
 
	net.CargadorContenidos.prototype = {
	cargaContenidoXML: function(url) {
    if(window.XMLHttpRequest) {
      this.req = new XMLHttpRequest();
    }
    else if(window.ActiveXObject) {
      this.req = new ActiveXObject("Microsoft.XMLHTTP");
    }
 
    if(this.req) {
      try {
        var loader = this;
        this.req.onreadystatechange = function() {
          loader.onReadyState.call(loader);
        }
        this.req.open('GET', url, true);
        this.req.send(null);
      } catch(err) {
        this.onerror.call(this);
      }
    }
  },
 
  onReadyState: function() {
    var req = this.req;
    var ready = req.readyState;
    if(ready == net.READY_STATE_COMPLETE) {
      var httpStatus = req.status;
      if(httpStatus == 200 || httpStatus == 0) {
        this.onload.call(this);
      }
      else {
        this.onerror.call(this);
      }
    }
  },
 
  defaultError: function() {
    alert("Se ha producido un error al obtener los datos"
      + "\n\nreadyState:" + this.req.readyState
      + "\nstatus: " + this.req.status 
      + "\nheaders: " + this.req.getAllResponseHeaders());
  }
}//fin constructor





function buscaenterI(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
    comprobar();
    return false;
}
else
return true;
}

function buscaenterI2(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
    comprobar2();
    return false;
}
else
return true;
}
    

    /*function vacio(){
        document.getElementById("busc").value="";
    }*/
//función de búsqueda 
function buscar(){
	var z = document.getElementById("busc").value;
	location.href = "buscador.php?b="+z;

}


function vacio(){
		document.getElementById("busc").value="";
}

function vacio2(){
        document.getElementById("busc2").value="";
}
    

function mostrarAvanzada()
{
    //var opt=document.getElementById('opciones'); */
   // spc=document.getElementById('espazos');
    busquedaa=1;  
    
    if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.indexOf('MSIE 4') < 0)){
        opt.style.width="414px";  
        opt.style.background="#FFF6BF none repeat scroll 0 0"; 
        opt.style.visibility="visible"; 
        opt.style.height="200px";
        opt.style.border="2px solid #FFD324"; 
        opt.style.color="#817134"; 
        spc.style.height="30px";      
        spc.style.visibility="hidden"; 
        document.getElementById('busquedaav').style.visibility="hidden";
        //opt.style.padding="10px"; 
		opt.style.paddingTop = "2px";
		opt.style.paddingBottom = "10px";
		opt.style.paddingRight = "10px";
		opt.style.paddingLeft = "10px";
		
        document.getElementById('busquedas').style.borderBottom="2px dotted #FFD324";
        opt.style.borderTop="2px dotted #FFD324";
        opt.style.marginTop= "-14px"; 
        opt.style.marginBottom = "20px";     
    }
    else{ 
        opt.style.width="417px";  
        opt.style.background="#FFF6BF none repeat scroll 0 0"; 
        opt.style.visibility="visible"; 
        opt.style.height="200px";
        opt.style.border="2px solid #FFD324"; 
        opt.style.color="#817134"; 
        spc.style.height="30px";      
        spc.style.visibility="hidden"; 
        document.getElementById('busquedaav').style.visibility="hidden";
        //opt.style.padding="10px"; 
		opt.style.paddingTop = "2px";
		opt.style.paddingBottom = "10px";
		opt.style.paddingRight = "10px";
		opt.style.paddingLeft = "10px";
		
		document.getElementById('busquedas').style.borderBottom="2px dotted #FFD324";
        opt.style.borderTop="2px dotted #FFD324";
        opt.style.marginTop= "-14px";  
        opt.style.marginBottom = "20px";    
    }
}

function ocultarAvanzada()
{                             
    //var opt=document.getElementById('opciones');
    //spc=document.getElementById('espazos');
    busquedaa=0;
    
    
    if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.indexOf('MSIE 4') < 0)){
        opt.style.width="414px"; 
        opt.style.visibility="hidden"; 
        opt.style.height="0px";     
        spc.style.height="30px";    
        spc.style.visibility="visible"; 
        document.getElementById('busquedaav').style.visibility="visible";
        document.getElementById('busquedas').style.borderBottom="solid"; 
        document.getElementById('busquedas').style.border="2px solid #FFD324";  
        opt.style.borderTop="2px solid #FFD324";  
        opt.style.marginBottom = "0px";
    }
    else{ 
        opt.style.width="417px";
        opt.style.visibility="hidden"; 
        opt.style.height="0px";     
        spc.style.height="30px";    
        spc.style.visibility="visible"; 
        document.getElementById('busquedaav').style.visibility="visible";
        document.getElementById('busquedas').style.borderBottom="solid"; 
        document.getElementById('busquedas').style.border="2px solid #FFD324";  
        opt.style.borderTop="2px solid #FFD324";  
        opt.style.marginBottom = "0px";  
    }
}

function engadirExtra(id){
    document.getElementById('extra'+id).style.height="300px";
    document.getElementById('extra'+id).style.visibility="visible";
    document.getElementById('obxectos'+id).style.height="0px";
    document.getElementById('obxectos'+id).style.visibility="hidden";
    document.getElementById('extra'+id).setAttribute("class","extravisible"); 
      
}

function empezarAdmin(id){

    /*document.getElementById('extra'+id).style.height="0px";
    document.getElementById('extra'+id).style.visibility="hidden";
    document.getElementById('obxectos'+id).style.height="200x";
      
    document.getElementById('obxectos'+id).style.height="460px";*/
    document.getElementById('oculto').value=0;  
 
}

function ocultarExtra(id){
    document.getElementById('extra'+id).style.height="0px";
    document.getElementById('extra'+id).style.visibility="hidden"; 
    document.getElementById('obxectos'+id).style.height="460px";
    document.getElementById('obxectos'+id).style.visibility="visible";
}

function cambiarFavorito(id){
    if(document.getElementById('favextrs'+id).checked=="checked"){
        document.getElementById('favextrs'+id).value="1";
    }
    else{
        document.getElementById('favextrs'+id).value="0"; 
    }
}

function mostrarObxecto(id){      
    for(var i=0;i<document.getElementById('oculto').value;i++){
        if(i==id){       
            document.getElementById('obxectos'+i).style.visibility="visible";
            document.getElementById('obxectos'+i).style.height="460px";
            document.getElementById('enlace'+i).setAttribute("class","enlacevisible");     
            document.getElementById('obxectos'+i).style.visibility="visible";
            document.getElementById('extra'+i).style.visibility="hidden";    
            document.getElementById('obxectos'+i).style.height="460px";
            document.getElementById('extra'+i).style.height="0px";
            document.getElementById('enlace'+i).setAttribute("class","enlacevisible");  
        }
        else{
            document.getElementById('obxectos'+i).style.visibility="hidden";
            document.getElementById('obxectos'+i).style.height="0px";
            document.getElementById('enlace'+i).setAttribute("class","enlacenovisible");               
            document.getElementById('extra'+i).style.height="0px";  
            document.getElementById('extra'+i).style.visibility="hidden";
            document.getElementById('obxectos'+i).style.visibility="hidden";
            document.getElementById('obxectos'+i).style.height="0px";
            document.getElementById('enlace'+i).setAttribute("class","enlacenovisible");   
        }
    }
}

function comprobar()
{
    var cad=document.getElementById('busc').value; 
    location.href="buscador.php?b="+cad+"&nt=-1&cod=-1";   
}

function comprobar2()
{
    var cad=document.getElementById('busc2').value; 
    location.href="buscador.php?b="+cad+"&nt=-1&cod=-1&tipoD=-1&pax=1";   
}

function limparExtras(id){
    document.getElementById("titextrs").value="";
    document.getElementById("fuenteextrs").value=""; 
    document.getElementById("desextrs").value=""; 
    document.getElementById("urlextrs").value=""; 
}
//call( u -> url, o -> object (can be null) to invoke function on, f -> callback function, p -> optional argument to specify POST)
/////////////////////////////////

function enviarDatosObxecto(id){
    var titobx=document.getElementById('titobx'+id).value;
    var desobx=document.getElementById('desobx'+id).value;  
    var endobx=document.getElementById('endobx'+id).value;  
    var horobx=document.getElementById('horobx'+id).value;  
    var preobx=document.getElementById('preobx'+id).value;  
    var geoobx=document.getElementById('geoobx'+id).value;
    var tipo=document.getElementById('tipo'+id).value;
    var codrot=document.getElementById('codrot').value; 
    document.getElementById('general').value=id;     
    call("insertarObxectos.php?titbox="+titobx+"&desobx="+desobx+"&endobx="+endobx+"&horobx="+horobx+"&preobx="+preobx+"&geoobx="+geoobx+"&tipo="+tipo+"&codrot=codrot",this,recogerDatos,"post");   
}
function vacio(){
		document.getElementById("busc").value="";
}
function enviarDatosExtra(id){
    var titextrs=document.getElementById('titextrs'+id).value;
    var desextrs=document.getElementById('desextrs'+id).value;   
    var tipoextrs=document.getElementById('tipoextrs'+id).value;
    var fuenteextrs=document.getElementById('fuenteextrs'+id).value;  
    var codobx=document.getElementById('codobx'+id).value; 
    var urlextrs=document.getElementById('urlextrs'+id).value;  
    var favextrs=document.getElementById('favextrs'+id).value;     
    call("insertarExtras.php?titextrs="+titextrs+"&desextrs="+desextrs+"&tipoextrs="+tipoextrs+"&fuenteextrs="+fuenteextrs+"&codobx="+codobx+"&urlextrs="+urlextrs+"&favextrs="+favextrs,this,recogerDatos,"post");   
}

function recogerDatos(html){
    var aux=document.getElementById('general').value; 
    document.getElementById('codobx'+aux).value=html;
}

function validarActivar(){
    if(document.getElementById('nombrerot')==""){
        alert("Debe poñer algun nome ao roteiro");
        return false;
    }

}