
// funciones front

/* FUNCIONES VALIDACIÓN FORMULARIOS */

var whitespace = " \t\n\r";
var reWhitespace = /^\s+$/

/** 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));
}

/*** corta espacios en blanco al principio y al final de una variable ***/
function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	};
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

/*** Valida un email mediante expresiones regulares ***/
function validarEmail(valor) {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
                return false;
        } else {
                return true;
        }
}
function isEmail(s){
	return (isWhitespace(s) || validarEmail(s));
}


function validar_es(form){ 

  if(isWhitespace(form.nombre.value)){ alert('Introduce tu nombre.'); form.email.focus(); return false; }

  if(isEmail(form.email.value)){ alert('Introduce tu email.'); form.email.focus(); return false; }
  
  if(isWhitespace(form.poblacion.value)){ alert('Introduce tu poblacion.'); form.poblacion.focus(); return false; }
  
  if(isWhitespace(form.codigo_postal.value)){ alert('Introduce tu codigo postal.'); form.codigo_postal.focus(); return false; }
  
  return true; 
} 

function validar_cat(form){ 

  if(isWhitespace(form.nombre.value)){ alert('Introdueix el teu nom.'); form.email.focus(); return false; }

  if(isEmail(form.email.value)){ alert('Introdueix el teu email.'); form.email.focus(); return false; }
  
  if(isWhitespace(form.poblacion.value)){ alert('Introdueix la teva poblacio.'); form.poblacion.focus(); return false; }
  
  if(isWhitespace(form.codigo_postal.value)){ alert('Introduce el teu codi postal.'); form.codigo_postal.focus(); return false; }
  
  return true; 
} 

function validar_en(form){ 

  if(isWhitespace(form.nombre.value)){ alert('Insert your name.'); form.email.focus(); return false; }

  if(isEmail(form.email.value)){ alert('Insert your email.'); form.email.focus(); return false; }
  
  if(isWhitespace(form.poblacion.value)){ alert('Insert your city.'); form.poblacion.focus(); return false; }
  
  if(isWhitespace(form.codigo_postal.value)){ alert('Insert your country.'); form.codigo_postal.focus(); return false; }
 
  return true; 
} 




// muestra u oculta pestañas	
function showTab(id_1, id_2){
	tab_1 = document.getElementById(id_1);
	td_1 = document.getElementById(id_1+'_td');
	
	tab_2 = document.getElementById(id_2);
	td_2 = document.getElementById(id_2+'_td');
	
	tab_1.style.display='';
	td_1.className='activo';
	
	tab_2.style.display='none';
	td_2.className=false;
}

// muestra u oculta noticias
function showNew(id, total, cerrar, leermas){
	// ocultamos el resto de noticias
	for ( var i=0; i<total; i++){
		if(i != id){
			var noticia = document.getElementById('new_'+i);
			if(noticia.style.display!='none'){
				noticia.style.display='none';
				var a = document.getElementById('anew_'+i);
				a.innerHTML = leermas;
			}
		}
	}
	// mostramos o ocultamos la noticia
	var noticia = document.getElementById('new_'+id);
	var a = document.getElementById('anew_'+id);
	
	if(noticia.style.display!='none'){
		a.innerHTML = leermas;
		noticia.style.display='none';
	}else{
		a.innerHTML = cerrar;
		noticia.style.display='';
	}
}
