function EnviarRepositorio()
{

   if ((document.repositorio.url.value!="")&&(document.repositorio.archivo.value!=""))   
   {
   
     alert("No se puede introducir una URL y un enlace a la vez para un mismo elemento del repositorio");
   }else
   { 
     if ((document.repositorio.url.value=="")&&(document.repositorio.archivo.value=="")&&(document.repositorio.url.type!="hidden"))   
        { // la tercera condicción es para poder editar un adjunto sin eliminar el archivo ya subido
		 alert("Debe describir la url o el archivo con los que el elemento del repositorio enlazar&aacute;");
        }
	 	else document.repositorio.submit();
			
   }
   		
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
function FormRecursos()
{
 if (document.formrecursos.titulo.value!="")   
	     {  
           document.formrecursos.submit();
		 } else alert("El campo Titulo es Obligatorio");
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
function abrirventana(documento)   //lanza una ventana pop-up
{
var ventana2=null;
var opciones="left=100,top=100,width=400,height=310, resizable=no ,scrollbars=np,menubar=no", i= 0; 
if (ventana2==null||(ventana.closed))   ventana2 = window.open(documento,"",opciones); 

ventana2.location = documento;
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function DameUrl()
{
return location.href;
}
function DameGET()
{
return location.search;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
function IraURL()
{

if (DameGET()=="") {}
else {window.location=DameUrl();}
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
var ventana=null;
function LanzaImagen(foto)
{
 var opciones="left=100,top=100,width=250,height=150, resizable=yes ,scrollbars=yes", i= 0; 
if (ventana==null||(ventana.closed))   ventana = window.open("","",opciones); 

//construimos la pagina que se habrira en la nueva ventana
ventana.document.open();
ventana.document.write("<html><head><title>"+foto+"</title>");
 ventana.document.write("<");
 ventana.document.write("script LANGUAGE='JavaScript'>");
 ventana.document.write("imagen=new Image();");
 ventana.document.write("function colocar() { ");
 ventana.document.write("if (screen.availWidth>window.document.imagen.width)  ");
 ventana.document.write("pantallax=((screen.availWidth-window.document.imagen.width)/2);   ");
 ventana.document.write("else (pantallax=0);   ");
 ventana.document.write("if (screen.availHeight>window.document.imagen.height)  ");
 ventana.document.write("pantallay=((screen.availHeight-window.document.imagen.height)/2);  ");
 ventana.document.write("else (pantallay=0); ");
 ventana.document.write("window.moveTo(pantallax,pantallay);  ");
 ventana.document.write(" if(screen.availWidth>window.document.imagen.width)    ");
 ventana.document.write("fotox=window.document.imagen.width; ");
 ventana.document.write("else fotox=screen.availWidth; ");
 ventana.document.write("if(screen.availHeight>window.document.imagen.height) ");
 ventana.document.write("fotoy=window.document.imagen.height; ");
 ventana.document.write("else fotoy=screen.availHeight; ");
 ventana.document.write("window.resizeTo(fotox,fotoy); ");
 ventana.document.write("window.focus(); ");
  ventana.document.write("}");
 ventana.document.write("<");
 ventana.document.write("/script>");

ventana.document.write("</head>");
ventana.document.write("<body style='word-spacing: 0; text-indent: 0; margin: 0'>")
ventana.document.write("<img name=imagen src='"+foto+"' Border=0>");
 ventana.document.write("<");
 ventana.document.write("script LANGUAGE='JavaScript'>");

//ventana.document.write("imagen.src='"+foto+"';");
//ventana.document.write("imagen.onload=colocar();");
ventana.document.write("setTimeout('colocar();',1500);");
ventana.document.write("setTimeout('colocar();',7000);");

//llama a  dar tamaño a la ventana desde la precarga de la imagen porque así
// da tamaño a la ventana antes de que se termine de cargar la imagen

 ventana.document.write("<");
 ventana.document.write("/script>");

ventana.document.write("</body></html>");
ventana.focus(); 
}

////////////////////////////////////////////
////////////////////////////

function LanzaCalendario(op)
{
opcion=op;
ventana=open("selector.htm", "fechas", " location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=250,height=180,top=100,left=250");
ventana.focus();
}
////////////////////////////////////////////
////////////////////////////
function PonerResultado(valor)
{
switch (opcion) {
     case 1:  document.form1.fecha_ini.value=valor;
         break;
     case 2:  document.form1.fecha_fin.value=valor;
         break; 
}
  ventana.close();
}
////////////////////////////////////////////
////////////////////////////
function enviarformfecha()
{

document.form1.fecha.disabled="";
//document.form1.fecha_fin.disabled="";
document.form1.submit();
}
////////////////////////////////////////////
////////////////////////////
function enviarform()
{
document.form1.fecha_ini.disabled="";
document.form1.fecha_fin.disabled="";
document.form1.submit();
}
///////////////////////////////////////
///////////////////////////////////////
function enviarformsecc()
{
 if (document.secciones.titulo.value!="")   
{  
   document.secciones.submit();
}else alert("La sección requiere un título");
}
/////////////////////////////////////////
///////////////////////////////////////
function BorrarCita(cual)
{
document.form1.borrar.value=cual;
document.form1.submit();

}

/////////////////////////////////////
/////////////////////////////////////
function Confirmar(url,mensaje)
{
if (confirm(mensaje)) 
  if (url!="") {window.location=url;}
}
////////////////////////////////////
/////////////////////////////////////
function Actualizar()
{
window.location=window.location;
}
//////////////////////////////////////////////////
/////////////////////////////////////////////////////
function MostrarCapaNueva(valor)
{
 if (valor=="1221t") Mostrar_Capa('nueva',1);
 else {
        Mostrar_Capa('nueva',0);
		document.getElementById('categorian').value="";
      }
}

////////////////////////////////
//////////////////////////////////////////////
/////////////////////////////////////////////////////////
function offsetLeft(el)
{
x = el.offsetLeft
for (e = el.offsetParent; e; e = e.offsetParent)
x += e.offsetLeft;
return x
} 
//////////////////////////////////////////////
/////////////////////////////////////////////////////////
function ColocarContacto()
{


valor=offsetLeft(document.getElementById("contacto_item"));
document.getElementById("contacto").style.left=((valor-358)+"px");
 
}
///////////////////////////////////
//////////////////////////////////
var numero=0;
var mensaje_abierto=0;

function ContactoPulsado()
{
if (mensaje_abierto==1)  // si se está mostrarndo el mensaje de envio lo cerramos
   {
    $(document.getElementById("contacto_mensaje")).fadeOut(1000);   //cierra
	mensaje_abierto=0;   
   }	
 //  ColocarContacto();
   //apertura y cierra de la capa de contacto
  if (numero==0)
       {
	    var ancho = 600; 
        var alto = 400;  	
		var wscr = $(window).width();
        var hscr = $(window).height();
        //La capa modal opcupara toda la pantalla
        $('#contactomodal').css("width", wscr+200);
        $('#contactomodal').css("height", hscr*3);                 
        // obtener posicion central
        var mleft = ( wscr - ancho ) / 2;
        var mtop = ( hscr - alto ) / 2;
		var ancho= document.getElementById("contacto").width;
		              
        // estableciendo ventana modal en el centro
        $('#contacto').css("left", mleft+'px');
        $('#contacto').css("top", mtop+'px');
		

        $(document.getElementById("contactomodal")).css("opacity", 0.6) 
		
		 
	    $(document.getElementById("contactomodal")).fadeIn(1000);   //abre
		$(document.getElementById("contacto")).fadeIn(1000);   //abre
	     numero=1;
	   }
  else {
         $(document.getElementById("contacto")).fadeOut(1000);   //cierra
		 $(document.getElementById("contactomodal")).fadeOut(1000);   //cierra
		 numero=0;
  }  
   
}
///////////////////////////////////////////
///////////////////////////////////////////

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
     if ((formData[0].value=="") || (formData[1].value=="") ||(formData[2].value==""))
	 {
	   alert("Debe completar los 3 campos");
	   return false;
	 }
	   document.getElementById("contacto_mensaje").innerHTML="<br><br><br>Enviando formulario ... ";
	   $(document.getElementById("contacto_mensaje")).fadeIn(100);
	   mensaje_abierto=1;
         
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
	
	// alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
   //     '\n\nThe output div should have already been updated with the responseText.'); 
   
    document.getElementById("contacto_mensaje").innerHTML="<br><br><br>"+responseText+" ... ";
    ContactoPulsado();

} 

//////////////////////////////////////////////////
//////////////////////////////////////////////////
function Mostrar_Capa(id,ver) {
	document.getElementById(id).style.display = ver ? "block" : "none";
}
///////////////////////////
///////////////////////////

function MostrarEntorno(cual,lang)
{
  if (cual==0)
   {
     Mostrar_Capa("entorno_entorno",1);
     Mostrar_Capa("entorno_villuercas",0);
	 Mostrar_Capa("entorno_ibores",0);
	 Mostrar_Capa("entorno_jara",0);
	document.getElementById("entorno_pestana").style.backgroundImage="url(images/entornop1"+lang+".jpg)";
   }
 if (cual==1)
   {
     Mostrar_Capa("entorno_entorno",0);
     Mostrar_Capa("entorno_villuercas",1);
	 Mostrar_Capa("entorno_ibores",0);
	 Mostrar_Capa("entorno_jara",0);
	 document.getElementById("entorno_pestana").style.backgroundImage="url(images/entornop2"+lang+".jpg)";
   }
 if (cual==2)
   {
     Mostrar_Capa("entorno_entorno",0);
     Mostrar_Capa("entorno_villuercas",0);
	 Mostrar_Capa("entorno_ibores",1);
	 Mostrar_Capa("entorno_jara",0);
	 document.getElementById("entorno_pestana").style.backgroundImage="url(images/entornop3"+lang+".jpg)";
   }
 if (cual==3)
   {
     Mostrar_Capa("entorno_entorno",0);
     Mostrar_Capa("entorno_villuercas",0);
	 Mostrar_Capa("entorno_ibores",0);
	 Mostrar_Capa("entorno_jara",1);
     document.getElementById("entorno_pestana").style.backgroundImage="url(images/entornop4"+lang+".jpg)";
   }         
}
//////////////////////////
///////////////////////////
function MostrarHoteles(cual,lang)
{
  if (cual==0)
   {
     Mostrar_Capa("hoteles_hoteles",1);
     Mostrar_Capa("hoteles_hostales",0);
	 Mostrar_Capa("hoteles_rurales",0);
	 Mostrar_Capa("hoteles_otros",0);
	document.getElementById("hoteles_pestana").style.backgroundImage="url(images/hotelesp1"+lang+".jpg)";
   }
 if (cual==1)
   {
     Mostrar_Capa("hoteles_hoteles",0);
     Mostrar_Capa("hoteles_hostales",1);
	 Mostrar_Capa("hoteles_rurales",0);
	 Mostrar_Capa("hoteles_otros",0);
	 document.getElementById("hoteles_pestana").style.backgroundImage="url(images/hotelesp2"+lang+".jpg)";
   }
 if (cual==2)
   {
     Mostrar_Capa("hoteles_hoteles",0);
     Mostrar_Capa("hoteles_hostales",0);
	 Mostrar_Capa("hoteles_rurales",1);
	 Mostrar_Capa("hoteles_otros",0);
	 document.getElementById("hoteles_pestana").style.backgroundImage="url(images/hotelesp3"+lang+".jpg)";
   }
 if (cual==3)
   {
     Mostrar_Capa("hoteles_hoteles",0);
     Mostrar_Capa("hoteles_hostales",0);
	 Mostrar_Capa("hoteles_rurales",0);
	 Mostrar_Capa("hoteles_otros",1);
     document.getElementById("hoteles_pestana").style.backgroundImage="url(images/hotelesp4"+lang+".jpg)";
   }         
}
//////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
function Callejero(cual)
{
$.ajax({
      type: "GET",
      url: "damecallejero.php",
	  data: "cual="+cual,
	  success:CallejeroCargar 	 
});
}

function CallejeroCargar(responseText, statusText)
 {
   document.getElementById("callejero_ficha").innerHTML=responseText;   
 }
//////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
function FichaMonasterio(cual)
{
if (cual==0)
{
  Mostrar_Capa("monasterio_edificio_ficha",0); 
   Mostrar_Capa("monasterio_edificio_principal",1); 
}
else
{
$.ajax({
      type: "GET",
      url: "dameficha.php",
	  data: "cual="+cual,
	  success:FichaMonasterioCargar 	 
});
}
}
//////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

function FichaMonasterioCargar(responseText, statusText)
 {
   document.getElementById("monasterio_edificio_ficha").innerHTML=responseText;  
   Mostrar_Capa("monasterio_edificio_ficha",1); 
   Mostrar_Capa("monasterio_edificio_principal",0); 
 }
//////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
function CerrarMonasterioHistoria()
{
  valor=document.getElementById("monasterio_historia_texto").style.display;
  if (valor=="none")
  {
    valor2="Cerrar";
  document.getElementById("monasterio_historia_texto").style.display ="block";
  document.getElementById("monasterio_historia_cerrar").innerHTML=valor2;
   
  }
  else
  {
   valor2="Abrir";
  document.getElementById("monasterio_historia_texto").style.display ="none";  
  document.getElementById("monasterio_historia_cerrar").innerHTML=valor2;
  }
  //document.getElementById("monasterio_historia_texto").style.display = (valor=="none") ? "block" : "none";

}
//////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
function Cerrarmonasterio_virgen()
{
  valor=document.getElementById("monasterio_virgen_texto").style.display;
  if (valor=="none")
  {
    valor2="Cerrar";
  document.getElementById("monasterio_virgen_texto").style.display ="block";
  document.getElementById("monasterio_virgen_cerrar").innerHTML=valor2;
   
  }
  else
  {
   valor2="Abrir";
  document.getElementById("monasterio_virgen_texto").style.display ="none";  
  document.getElementById("mmonasterio_virgen_cerrar").innerHTML=valor2;
  }
  //document.getElementById("monasterio_historia_texto").style.display = (valor=="none") ? "block" : "none";

}
