// Funciones validación formularios
var whitespace = " \t\n\r";
var reWhitespace = /^\s+$/
var mail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
var movil = /^6[0-9]{8}$/;
var telef = /^[0-9]{8}$/;
var fijo = /^9[0-9]{8}$/;


// Verifica que no este vacio
function isEmpty(s){
	return ((s == null) || (s.length == 0)) 
}
 
// Verifica que no sean espacios en blanco o vacio
function isWhitespace (s){
    return (isEmpty(s) || reWhitespace.test(s));
}
 
 // Validar email
function isEmail(s){
	return (isWhitespace(s) || validarEmail(s));
}

function validarEmail(valor) {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
                return false;
        } else {
                return true;
        }
}


// Cambiar capas de lo mas comentado y lo más visto
function not_lomasvisto(){
	document.getElementById("capa1").style.display="";
	document.getElementById("capa2").style.display="none";
}

function not_lomascomentado(){
	document.getElementById("capa1").style.display="none";
	document.getElementById("capa2").style.display="";
}

// Cambiar capas de lo mas comentado y lo más visto
function art_lomasvisto(){
	document.getElementById("capa1").style.display="";
	document.getElementById("capa2").style.display="none";
}

function art_lomascomentado(){
	document.getElementById("capa1").style.display="none";
	document.getElementById("capa2").style.display="";
}



//desplegar y ocultar div de enviar a un amigo
function enviaramigo(){
	if(document.getElementById("enviaramigo").style.display=="none"){
		document.getElementById("enviaramigo").style.display="";
		if(document.getElementById("enviaramigo_respuesta")){
			document.getElementById("enviaramigo_respuesta").style.display="none";
		}

	}else{
		document.getElementById("enviaramigo").style.display="none";
		if(document.getElementById("enviaramigo_respuesta")){
			document.getElementById("enviaramigo_respuesta").style.display="none";
		}
	}
}



// Aumentar y reducir texto de la notícia
fuenteActual = 10;
fuenteMasPeq = 8;
fuenteMasGrande = 12;

function MasTxtNot() {
	
	fuenteActual = fuenteActual+2;
    if (fuenteActual > fuenteMasGrande) {
		fuenteActual = fuenteMasGrande
    }
	var divID = document.getElementById("not_completa");
	var divID2 = document.getElementById("noticia_principal_desc_corta_int");
	divID.style.fontSize = fuenteActual+"pt";
	divID2.style.fontSize = fuenteActual+"pt";
}

function MenosTxtNot(cuerpo,desc_corta) {
	fuenteActual = fuenteActual-2;
	if (fuenteActual < fuenteMasPeq) {
		fuenteActual = fuenteMasPeq
	}
	var divID = document.getElementById("not_completa");
	var divID2 = document.getElementById("noticia_principal_desc_corta_int");
	divID.style.fontSize = fuenteActual+"pt";
	divID2.style.fontSize = fuenteActual+"pt";
}


function MasTxtArt() {
	fuenteActual = fuenteActual+2;
    if (fuenteActual > fuenteMasGrande) {
		fuenteActual = fuenteMasGrande
    }
	//alert(fuenteActual);
	var divID = document.getElementById("marcpru");
	divID.style.fontSize = fuenteActual+"pt";
}

function MenosTxtArt(cuerpo,desc_corta) {
	fuenteActual = fuenteActual-2;
	if (fuenteActual < fuenteMasPeq) {
		fuenteActual = fuenteMasPeq
	}
	//alert(fuenteActual);
	var divID = document.getElementById("marcpru");
	divID.style.fontSize = fuenteActual+"pt";
}

// validar formulario enviar amigo
function validaform(frm) {
	if(document.getElementById("remi").value==""){
		alert("No has escrito el nombre del remitente.");
		frm.remi.focus();
		return false;
	}
	if(!mail.test(frm.mail_remi.value)) {
		alert("el e-mail del remitente no es correcto.");
		frm.mail_remi.focus();
		return false;
	}
	if(document.getElementById("dest").value==""){
		alert("No has escrito el nombre del destinatario.");
		frm.dest.focus();
		return false;
	}
	if(!mail.test(frm.mail_dest.value)) {
		alert("el e-mail del destinatario no es correcto.");
		frm.mail_dest.focus();
		return false;
	}
}

function validaform_contacto(frm) {
	if(document.getElementById("nombre").value==""){
		alert("No has escrito el nombre del remitente.");
		frm.remi.focus();
		return false;
	}
	if(!mail.test(frm.email.value)) {
		alert("el e-mail del remitente no es correcto.");
		frm.mail_remi.focus();
		return false;
	}
	if (isWhitespace(frm.telefono.value)){
		alert("Por favor, informe su telefono");
		frm.fijo.focus();
		return false;
	}
	if(!fijo.test(frm.telefono.value) || !movil.test(frm.telefono.value)) {
		alert("Por favor, informe correctamente su telefono. Debe comenzar por '9' o '6' y no contener puntos ni comas ni espacios en blanco");
		frm.fijo.focus();
		frm.fijo.select();
		return false;
	}

	if (isWhitespace(frm.comentario.value)){
		alert("Por favor, escriba el comentario");
		frm.movil.focus();
		return false;
	}
}


/******************************************** PORTADA ********************************************/

// apartado comparador...

function bordesDiv(div,check){
	var hiddenTmp="border_"+check;
	var hiddenObj=document.getElementById(hiddenTmp);
	//alert("check->"+check);
	if(hiddenObj.value == "0"){
		document.getElementById(div).style.border = '2px solid #DB2700';
		document.getElementById(check).checked=true;
		hiddenObj.value="1";
	}else{
		document.getElementById(div).style.border = '2px solid #cccccc';
		document.getElementById(check).checked=false;
		hiddenObj.value="0";
	}

}


function borderDivOnMouseOut(div, check){
	var hiddenTmp="border_"+check;
	var hiddenObj=document.getElementById(hiddenTmp);

	if(hiddenObj.value == "1"){
		document.getElementById(div).style.border = '2px solid #DB2700'
	}else{
		document.getElementById(div).style.border = '2px solid #f4f4f4'
	}

}

function borderDivOnMouseOver(div , check){
	var hiddenTmp="border_"+check;
	var hiddenObj=document.getElementById(hiddenTmp);
	
	if(hiddenObj.value == "0"){
		document.getElementById(div).style.border = '2px solid #cccccc';
	}
}


function verify2(frm){
	
	if (isWhitespace(frm.telefono.value)){
		alert("Por favor, informe su telefono");
		frm.telefono.focus();
		return false;
	}
	if(!fijo.test(frm.telefono.value) && !movil.test(frm.telefono.value)) {
		alert("Por favor, informe correctamente el teléfono. Debe comenzar por '6' o '9' y no contener puntos ni comas ni espacios en blanco");
		frm.telefono.focus();
		frm.telefono.select();
		return false;
	}

}


function verify(frm){
	
	if (isWhitespace(frm.nombre.value)){
		alert("Por favor, informe su nombre");
		frm.nombre.focus();
		return false;
	}

	if (isWhitespace(frm.fijo.value)){
		alert("Por favor, informe su telefono fijo");
		frm.fijo.focus();
		return false;
	}
	if(!fijo.test(frm.fijo.value)) {
		alert("Por favor, informe correctamente el telefono fijo. Debe comenzar por '9' y no contener puntos ni comas ni espacios en blanco");
		frm.fijo.focus();
		frm.fijo.select();
		return false;
	}

	if (isWhitespace(frm.movil.value)){
		alert("Por favor, informe su movil");
		frm.movil.focus();
		return false;
	}
	if(!movil.test(frm.movil.value)) {
		alert("Por favor, informe correctamente el tel?fono movil. Debe comenzar por '6' y no contener puntos ni comas ni espacios en blanco");
		frm.movil.focus();
		frm.movil.select();
		return false;
	}

	if (isWhitespace(frm.email.value)){
		alert("Por favor, informe su e-mail");
		frm.email.focus();
		return false;
	}
	if (isEmail(frm.email.value)){
		alert("Por favor, informe correctamente la direccion de e-mail");
		frm.email.focus();
		return false;
	}
	
	if (!frm.privacidad.checked){
		alert("Para completar el registro debe aceptar la declaracion de privacidad");
		return false;
	}
}



function valida_contac(frm){
	
	if (isWhitespace(frm.nombre.value)){
		alert("Por favor, informe su nombre.");
		frm.nombre.focus();
		return false;
	}
	
	if (isEmail(frm.email.value)){
		alert("Por favor, informe correctamente la dirección de e-mail");
		frm.email.focus();
		return false;
	}
	
	if (isWhitespace(frm.comentario.value)){
		alert("Por favor, escribe un comentario.");
		frm.nombre.focus();
		return false;
	}

	return true;
}
