//Previsualizar noticias en la home
function previsualizar_home(titular,foto_home){
  if(foto_home.value=="" || foto_home.value=="/url/img/dot.gif"){
	foto_home.value="/corps/chguadiana/url/img/noticias_default.jpg";
  }  
  HTML = "<html><title>Vista Previa</title><style>body{margin: 5px 0px 5px 0px;}</style><body><table cellpadding='0' cellspacing='0' border='0' align='center' width='240' height='240' style='border:1px solid black;'><tr><td valign='top'><img src='"+ foto_home.value +"' name=load_image border=0 width=240 ></td></tr><tr><td style='padding:5px;vertical-align:top;height:100%;'>"+titular.value+"</td></tr></table></body></html>";
  popupVer = window.open('','_blank','toolbar=no,scrollbars=no,width=260,height=260,left=700,top=260');
  popupVer.document.open();
  popupVer.document.write(HTML);
  popupVer.document.close();
}

//EXPROPIACIONES
// Si dejamos el campo fecha de vencimiento del documento vacio, lo incrementa en 3 meses
function comprobar(fecha,enlace){
 if (enlace.value=='') {
	alert ("Debe introducir un documento");
	return false;
 }	
 else if(fecha.value==''){
	todaysDate = new Date();
	todaysYear = todaysDate.getYear();
	if (todaysYear < 1900) {todaysYear = todaysYear + 1900}
	todaysMonth = todaysDate.getMonth() + 1;
	todaysDay = todaysDate.getDate();
	currentMonth = todaysMonth;
	currentYear = todaysYear;

	// Mes Siguiente
	if ( currentMonth == 12 ) {
		nextMonth = 3;
		nextYear = parseInt(currentYear,10) + 1;
	}
	else if ( currentMonth == 10 ) {
		nextMonth = 1;
		nextYear = parseInt(currentYear,10) + 1;
	}
	else {
		nextMonth = parseInt(currentMonth,10) + 3;
		nextYear = currentYear
	}
	var new_fecha = dos_digitos(todaysDay)+"/"+dos_digitos(nextMonth)+"/"+nextYear;
	//var new_fecha = nextYear+"-"+dos_digitos(nextMonth)+"-"+dos_digitos(todaysDay);
	fecha.value=new_fecha;
	return true;
 }	
return true;

}

function dos_digitos (cifra) {
  str_cifra = new String (cifra)
  if (str_cifra.length == 1) { str_cifra = "0" + str_cifra; }
  return str_cifra;
}

//BUSCADORES
//Fecha de fin mayor que fecha de inicio
function verificar_fechas(inicio,fin) {
	if (inicio.value!='' && fin.value!=''){
		var fecha_inicio	= inicio.value;
		var fecha_fin		= fin.value;
		var actual 		= new Date();;
 	
		var fecha_1=fecha_inicio.substr(6,4)+"-"+fecha_inicio.substr(3,2)+"-"+fecha_inicio.substr(0,2);//2007-07-24
		var fecha_2=fecha_fin.substr(6,4)+"-"+fecha_fin.substr(3,2)+"-"+fecha_fin.substr(0,2);

		if(fecha_1 > fecha_2){
			alert("La fecha de fin debe ser superior a la fecha de inicio \n"); 
			return false;
		}
	}
    return true;	
}

//Extraer todos los datos del nombre del recorte de prensa
function obtener_datos(fecha,titular,medio,recorte){
 if (recorte.value!=""){
	var cadena = recorte.value;
	var comienzo=cadena.lastIndexOf("/")+1;
	var fin = cadena.length;
	cadena=cadena.substr(comienzo,fin);
	cadena=cadena.split("-");
	//FECHA
	//if(fecha.value==""){
		fecha_new=cadena[0]+"/"+cadena[1]+"/"+cadena[2];
		fecha.value=fecha_new;
	//}
	//MEDIO
	//if(medio.value==""){
		medio_new=cadena[3];
		medio.value=medio_new;
	//}
	//TITULAR
	//if(titular.value==""){
		titular_new=cadena[4];
		longitud_titular=titular_new.length-4;
		titular_new=titular_new.substring(0,longitud_titular);
		titular.value=titular_new;
	//}	
 }else{
	alert("Es necesario añadir un recorte de prensa");
	//return false;
 }	
 //return true;
 
}

//Para recorte de prensa, una vez que borrar el recorte de prensa se borrar tambien los datos de ese recorte
function borrar_datos(fecha,titular,medio,recorte){
	if (recorte.value==""){
		fecha.value="";
		titular.value="";
		medio.value="";
	}
}

//Comprobar si se han cargado los datos del recorte de prensa
function datos_ok(lista,recorte1,recorte2,mensaje){
  for (i=0;i<lista.length;i++) {
    if (lista[i].value == "") {
      alert(mensaje);
      return false;
	}  
  }
  
  if(recorte1.value=="" && recorte2.value==""){
      alert("Debe añadir un recorte de prensa");
	  return false;
  }	  
  
  return true;
}

//Validar el formulario de contactar

function validar_contactar() {
	var vError = ""; 	//Recoge los errores acumulados en el formulario
	var vfoco = "";		//Recoge el primer campo donde ha ocurrido un error

	//Nombre
	if (document.solicitar_informacion.nombre.value == ""){
		vError += "- Debe cumplimentar el campo Nombre.\n";
		(vfoco == "") ? vfoco = "nombre" : vfoco = vfoco;
	}
	//E-mail
	EMAIL=document.solicitar_informacion.email.value+"";
	X=0;
	for (Y=0; Y<= EMAIL.length; Y++){
		if (EMAIL.charAt(Y)+"" == "@" && Y > 0 && Y+1 < EMAIL.length) {X=1}
	}
	if (X == 0){
		vError += "- Por favor, indique una dirección de correo electrónico válida.\n";
		(vfoco == "") ? vfoco = "email" : vfoco = vfoco;
	}
	//Consulta
	if (document.solicitar_informacion.consulta.value == ""){
		vError += "- Debe cumplimentar el campo Consulta.\n";
		(vfoco == "") ? vfoco = "consulta" : vfoco = vfoco;
	}
	//-----------
	if (vError!=""){//Conpolamos posibles errores
		alert(vError);
		eval("document.solicitar_informacion."+vfoco+".focus();");
		return(false);
	}else
		return(true);
}

//Mostrar la capa de contenido de las noticias
function muestraCapa(capa) {
  var num_capas = 1;
  for (i=1;i<=num_capas;i++) {
    var tmp_tabla = "tabla_"+i;
	
    if (document.layers) {
	  document.layers[tmp_tabla].display 				= 'none';
    } else if (document.getElementById) {
	  document.getElementById(tmp_tabla).style.display	= 'none';
    }
  }
  tmp_tabla = "tabla_"+capa;
  if (document.layers) {
    document.layers[tmp_tabla].display 					= 'block';
  } else if (document.getElementById) {
    document.getElementById(tmp_tabla).style.display	= 'block';
  } 
}
