// JavaScript Document

function onmouse_over(archivo, id){

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


function initValidation (id_form)
{
		
	var correcto = true;	
	
	
		// Aceptar condiciones	
	if($("#accept_cond").attr("value") != undefined && $("#accept_cond:checked").val() == null){		
		mark_field('accept_cond','required');
	   correcto = false;
	}else{
		unmark_field('accept_cond','required');
	}
	
	// campos requeridos
	  $("#"+id_form).find(".required:visible").each(function(i) {
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	   
	   if (valor==undefined){
	   	   mark_field(id,'required');
		   correcto = false;		
	   }else 
	   		unmark_field(id,'required');
     
	   });
	
	 
	// 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');
	   }
	   });
	   
	
	 
	 return correcto;
}

function mark_field (id, type)
{	
	$("#"+id).css("background-color", "#ffffcc");	
	$("#error_"+ id + "_" + type).show();	
}

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


function you_cant(){

	alert('Debe ser Afiliado e Identificado para poder descargar');
	
}

function you_cant2(){

	alert('Debe ser Afiliado e Identificado para poder acceder');
	
}

	function doSubmit(id_form, action){
		$("#"+id_form).attr('action', action);
		$("#"+id_form).submit();
	}
	
	
	
	
	function doValid(id_form, action){		
		if(initValidation(id_form)){
			$("#img_enviar").hide();
			doSubmit(id_form, action);
			
		}
	}
	
	
	
	function load_comunidad(){
	
		var id = document.getElementById("comunidades_autonomas").value;
	
		var url = "contactar.php?comunidad=" + id;
		window.location.href = url;
	}
	

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