function check_registro(){
	
	var formOk = 1;

	var camposRek = new Array('nombre','apellidos','direccion','poblacion', 'cp','telefono','nif','email','psw','psw2');

	var formOk = 1;


	for(i=0; i<camposRek.length;i++) {
	
		thisCampo = document.getElementById(camposRek[i]);

		if (thisCampo.value=='') {
			formOk = 0;
			thisCampo.style.border="1px solid #C40001";
			thisCampo.style.color="#C40001";
		
		}else{
			thisCampo.style.border="1px solid #FFF";
			thisCampo.style.color="#000";
		}
		
	}
	if (formOk == 0) alert('Asegurese de rellenar los campos marcados en rojo');

	if (formOk==1) {
		
		if(!document.getElementById('condiciones').checked){
			
			alert("Debe aceptar la politica de privacidad");
			
		}else{
			
			document.getElementById('form-login').submit();
			return true;
		}
	}
	
	return false;
}

function check_presupuesto(){
	
	var formOk = 1;

	var camposRek = new Array('nombre','direccion','cp','localidad','provincia','telefono','email','consulta');

	var formOk = 1;

	

	for(i=0; i<camposRek.length;i++) {
	
		thisCampo = document.getElementById(camposRek[i]);

		if (thisCampo.value=='') {
			formOk = 0;
			thisCampo.style.border="1px solid #C40001";
			thisCampo.style.color="#C40001";
		
		}else{
			thisCampo.style.border="1px solid #FFF";
			thisCampo.style.color="#000";
		}
		
	}
	
	if (formOk == 0) alert('Asegurese de rellenar los campos marcados en rojo');

	if (formOk==1) {
		
		if(!document.getElementById('condiciones').checked){
			
			alert("Debe aceptar la politica de privacidad");
			
		}else{
			
			document.getElementById('form-presupuesto').submit();
		}
	}
}



/* 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, "");}
function visible_on(div){
	
	document.getElementById(div).style.visibility="visible";
}


function quitar_favorito(usuario, articulo){
	
	if(usuario==''){
	
		alert('Debe Registrarse para poder quitar articulos a favoritos.')
	
	}else{
		
		if(confirm("Desea eliminar el producto de sus favoritos?")){
			xajax_eliminar_favorito(usuario, articulo)
		}
	}
}

function insertar_favorito(usuario, articulo){
	
	if(usuario==''){
	
		alert('Debe Registrarse para poder agregarse articulos a favoritos.')
	
	}else{
		
		xajax_inserta_favorito(usuario, articulo)

	}
}

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


