

function mark_field (id, type)
{	
	$("#"+id).css("background-color", "#FFE400");	
	//document.getElementById(id).style.backgroundColor="#ffffcc";
	//$("#"+id).addClass('fondo');

	$("#error_all_" + type).show();	
}

function unmark_field (id, type)
{	
	$("#"+id).css("background-color", "#FFFFFF");
	$("#error_"+ id + "_" + type).hide();
	//$("../",id).remove("span");
}


function add_class(id, class2){

	$("#"+id).addClass(class2);

	
}

function remove_class(id, class2){

	$("#"+id).removeClass(class2);

	
}


function toggle_me(id){
	

		 $("#"+id).toggle();

}
						
function change_img(img, url){


document.getElementById(img).src=url;
	
}

function update_provincia(){
	
	$("#registrate_p3").attr('action', 'registrate_p3.php');
	$("#registrate_p3").submit();
		
}


function show_whatever(id){

	$("#"+id).show();
	

}

function hide_whatever(id){

	//$("#"+id).hide();
	document.getElementById(id).style.visibility="hidden";


}






function change_sex_man(){

	document.getElementById('estado_civil').disabled="disabled";
	$("#estado_civil").hide();
	
	document.getElementById('estado_civil2').disabled="";
	$("#estado_civil2").show();
	
}

function change_sex_woman(){

	document.getElementById('estado_civil2').disabled="disabled";
	$("#estado_civil2").hide();
	
	document.getElementById('estado_civil').disabled="";
	$("#estado_civil").show();
	
}



function initValidation (id_form)
{
	
	
		
	var correcto = true;	
	// campos requeridos
	  $("#"+id_form).find(".required:visible").each(function(i) {
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	   
	   if (valor==undefined || valor=="0" || valor=="void"){
	   	   mark_field(id,'required');
		   correcto = false;		
	   }else 
	   		unmark_field(id,'required');
     
	   });
	  
	  
	    
	   // checkbox ----------------------------------------------
	var	k=0;	 
	var	numero_total=false;
	var checbox_validar = false;
	
	// buscamos todos los checkbox que tengan la clase required_check
	   $("#"+id_form).find(".required_check:visible").each(function(i) {
		id = $(this).attr("id");
		 
	  	// cogemos el id de cada uno y buscamos la longitud
	    var checked = $("input[@id="+id+"]:checked").length; 
        if (checked == 0) { k++; } // sumamos uno al contador si encontramos vacío
		
		numero_total++;
		checbox_validar = true;

	   });

	
		
	   if(true == checbox_validar && k==numero_total){ // comprobamos si hay como mínimo 1 seleccionado, de no ser así mostramos error
		correcto = false;
		 mark_field(id,'required');
	 	$("#interested").show();
	   }else{

		   $("#interested").hide();
	   }
	   // FIN checkbox ----------------------------------------------
	  

     
	  
	// Aceptar condiciones	
	if($("#accept_cond:visible").attr("value") != undefined && $("#accept_cond:checked").val() == null){		
		mark_field('accept_cond','required');
	   correcto = false;
	}else{
		unmark_field('accept_cond','required');
	}
	  
	// campos password iguales	  
	pasw = $("#password").attr("value");		
	repasw = $("#repassword").attr("value");		
	if(pasw != undefined && pasw != ''){
		if (pasw == repasw){
   			unmark_field('password','match_password');  		
	   }else{ 
   		   mark_field('password','match_password');
		   correcto = false;
	   }  	
	}
	
	
	
	
	
	 
	// campos email
	$("#"+id_form).find(".valid_email:visible").each(function(i) {	
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	  
	   if (valor!=undefined) {
	  if (!valor.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i)){
	  	mark_field(id,'valid_email');
		correcto = false;
	  }else unmark_field(id,'valid_email');
	   }
	   });
	 
	 // min length
	 $("#"+id_form).find(".min_length:visible").each(function(i) {		
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	  if (valor!=undefined) {
	  if (valor.length<6){
	  	mark_field(id,'min_length');
		correcto = false;
	  }
	   else unmark_field(id,'min_length');
	  }
	   });

	 $("#"+id_form).find(".minimum:visible").each(function(i) {			 
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	  if (valor!=undefined) {
	  	id = $(this).attr("id");
	  	fieldcomp = id.substring(0, id.indexOf('_') );
	  	
	  	valor2=$("#"+fieldcomp).attr("value");
	  
	  	if (parseInt(valor)>parseInt(valor2)){
	  	correcto = false;
	  	mark_field(id,'minimum');
		}
	   else unmark_field(id,'minimum');
	  }
	   }); 	  
	 

	 // campos email iguales	  
	pasw = $("#email").attr("value");		
	repasw = $("#reemail").attr("value");		
	if(pasw != undefined && pasw != ''){
		if (pasw == repasw){
   			unmark_field('email','match_email');  		
	   }else{ 
   		   mark_field('reemail','match_email');
		   correcto = false;
	   }  	
	}
	   
	 return correcto;
}






// JavaScript Document

function onmouse_over(archivo, id, idioma){

eval("document."+id+".src='img/"+idioma+"/"+archivo+"'");
	
}

function onmouse_out(archivo, id, idioma){

eval("document."+id+".src='img/"+idioma+"/"+archivo+"'");
}


function b_alojamientos (){

document.getElementById('alojamientos_div').style.display="block";
document.getElementById('coches_div').style.display="none";
document.getElementById('actividades_div').style.display="none";

}

function b_coches (){

document.getElementById('alojamientos_div').style.display="none";
document.getElementById('coches_div').style.display="block";
document.getElementById('actividades_div').style.display="none";

}

function b_actividades (){

document.getElementById('alojamientos_div').style.display="none";
document.getElementById('coches_div').style.display="none";
document.getElementById('actividades_div').style.display="block";

}




function submitform(form)
{

var myform=document.getElementById(form);
myform.submit();
}



function valida_alojamientos(message, id, form){

var test=document.getElementById(id).value;
	if (test=="void"){
	
		alert(message);
	
	}else{

	var myform=document.getElementById(form);
	myform.submit();
	}


}




function mostrar_ficha (mostrar, ocultar1, ocultar2){

document.getElementById(mostrar).style.display="block";
document.getElementById(ocultar1).style.display="none";
document.getElementById(ocultar2).style.display="none";

}

function consultar_opciones(variable){								
	/*	
		if(document.myform.salida.value<document.myform.f_date_c22.value){
		
			alert(variable);
		}else{*/
					$("#myform").submit();
					
//		}
		}
			
			
	
						
						
function borrar_opcion(text){
	if(confirm(text)){
		return true;
	}else return false;
}

function popup(page, title, width, height) {	
	window.open(page, title, "width=" + width + ",height="+height+",menubar=no,scrollbars=yes");
}
