/* VALIDACIONES */

function check_password(){
	var psw1=document.getElementById('psw1').value;
	var psw2=document.getElementById('psw2').value;
	
	if(psw1!=psw2){
		document.getElementById('psw1').style.color="red";
		document.getElementById('psw2').style.color="red";
 		return true;
	}
	
	document.getElementById('psw1').style.color="black";
	document.getElementById('psw2').style.color="black";
	
	return false;
}

function check_telefono(){
	var telefono=document.getElementById('telefono').value;
	telefono=quitar_caracteres(telefono);
	
	if( !(/^\d{9}$/.test(telefono)) && telefono!="") {
 		 document.getElementById('telefono').style.color="red";
 		 return true;
 		 
	}
	
	document.getElementById('telefono').style.color="black";
	return false;
	
}

function check_cp(){
	var cp=document.getElementById('cp').value;
	cp=quitar_caracteres(cp);
	
	if( !(/^\d{5}$/.test(cp)) && cp!="") {
 		 document.getElementById('cp').style.color="red";
 		 return true;
	}
	
	document.getElementById('cp').style.color="black";
	
	return false;
}


function check_email(comprobar_usuario, nombre_email, inf_ampliada){
	
	var email=document.getElementById(nombre_email).value;

	var filter = /^(.+\@.+\..+)$/;
	
	if( !filter.test(email) && email!="" ) {
 		 document.getElementById(nombre_email).style.color="red";
 		 return true;
	}
	
	document.getElementById(nombre_email).style.color="black";
		
	return existe;
}

function quitar_caracteres(cadena){
	cadena=cadena.replace(/ /gi, "");
	cadena=cadena.replace(/-/gi, "");
	cadena=cadena.replace(/_/gi, "");
	cadena=cadena.replace(/\./gi, "");
	return cadena;
}

function quitar_espacios(cadena){ return cadena.replace(/ /gi, "");}
/* Cambiamos de block a none y viceversa de un div */
function display_on_off(div){
	
	if(document.getElementById(div).style.display=="none") document.getElementById(div).style.display="block";
	else document.getElementById(div).style.display="none";
}

function display_on_display_off(div_on, div_off){
	
	display_on(div_on);
	display_off(div_off);
}

/* Ponemos block a on */
function display_on(div){ document.getElementById(div).style.display="block"; }

/* Ponemos block a off */
function display_off(div){ document.getElementById(div).style.display="none"; }

/* Alert con confirmacion */
function alerta(item, ruta){
	borrar=window.confirm('Seguro que desea eliminar '+item+'?');
	if(borrar)	document.location.href=ruta;
}

//Quitar contenido del input
function updateInput(txtLabel, thisInput, opcion) {
	if (opcion == 1) {
		if (thisInput.value == txtLabel) thisInput.value = '';
	}
	else {
		if (thisInput.value == '') thisInput.value = txtLabel;
	}
}


