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

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

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


function check_opinion(){
	
	var campos= new Array('nombre', 'email', 'provincia', 'opinion');
	var error=false;
	
	for(var i=0;i<campos.length;i++){
		
		if(document.getElementById(campos[i]).value==""){
			document.getElementById(campos[i]+'-1').style.color='red';
			error=true;
		}else{
			document.getElementById(campos[i]+'-1').style.color='#333';
		}
	}
		
	
	//Validacion email
	var filter = /^(.+\@.+\..+)$/;
	
	if(!filter.test(document.getElementById('email').value)){
		document.getElementById('email').style.color='red';
		error=true;
	}else{
		document.getElementById('email').style.color='#333';
	}
	
	if(error) window.alert('Revise los campos marcados en rojo.');
	else{

	 		return true;
	 	
	}
	
	return false;
}

function check_contacto(){
	
	var campos= new Array('nombre', 'telefono', 'email', 'poblacion', 'provincia', 'descripcion');
	var error=false;
	
	for(var i=0;i<campos.length;i++){
		
		if(document.getElementById(campos[i]).value==""){
			document.getElementById(campos[i]+'-1').style.color='red';
			error=true;
		}else{
			document.getElementById(campos[i]+'-1').style.color='#333';
		}
	}
		
	
	//Validacion email
	var filter = /^(.+\@.+\..+)$/;
	
	if(!filter.test(document.getElementById('email').value)){
		document.getElementById('email').style.color='red';
		error=true;
	}else{
		document.getElementById('email').style.color='#333';
	}
	
	if(error) window.alert('Revise los campos marcados en rojo.');
	else{

	 		document.getElementById('form_contacto').submit();
	 	
	}
}

function check_presupuesto(){
	
	var campos2= new Array('nombre2', 'email2', 'telefono2','loc_origen','loc_destino','dir_origen','dir_destino','piso_origen','piso_destino');
	var campos3= new Array('ascensor','ascensor2','montaje','guardamuebles','elevador','embalaje', 'origen', 'destino','tipo1','tipo2');
	var error=false;
	
	for(var i=0;i<campos2.length;i++){
	
		if(document.getElementById(campos2[i]).value==""){
			document.getElementById(campos2[i]+'-1').style.color='red';
			error=true;
		}else{
			document.getElementById(campos2[i]+'-1').style.color='#333';
		}
	}
	
	for(var i=0;i<campos3.length;i++){
	
		if(document.getElementById(campos3[i]).value=="0"){
			document.getElementById(campos3[i]+'-1').style.color='red';
			error=true;
		}else{
			document.getElementById(campos3[i]+'-1').style.color='#333';
		}
	}
	
 
	//Validacion email
	var filter = /^(.+\@.+\..+)$/;
	
	if(!filter.test(document.getElementById('email2').value)){
		document.getElementById('email2').style.color='red';
		error=true;
	}else{
		document.getElementById('email2').style.color='#333';
	}
	
	if(error) window.alert('Revise los campos marcados en rojo.');
	else{
	
		if(document.getElementById('condiciones-presupuesto').checked==false){
	
			alert('Debe aceptar la politica de privacidad.');
	
		}else{
	 		document.getElementById('form_presupuesto').submit();
	 	}
	}
}


function check_sorteo(){

	var formOk = 1;

	var camposRek = new Array('nombre-sorteo','apellidos-sorteo','ciudad-sorteo','telefono-sorteo','email-sorteo','dni-sorteo');
	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";
		}
		
	}
	
	if (formOk == 0) alert('Asegurese de haber rellenado todos los campos');

	if (formOk==1) {

		if(document.getElementById('condiciones').checked==false){
			
			alert('Debe aceptar la politica de privacidad.');
			
		}else{
		
		//-- GUARDAR PARA EL SORTEO
		xajax_guardar_sorteo(
			document.getElementById('nombre-sorteo').value,
			document.getElementById('apellidos-sorteo').value,
			document.getElementById('dni-sorteo').value,
			document.getElementById('ciudad-sorteo').value,
			document.getElementById('email-sorteo').value, 
			document.getElementById('telefono-sorteo').value
			);
		}
		
		document.getElementById('boton-enviar').style.display="none";
	}
	
	return false;
}




