function loading(capa){
	document.getElementById(capa).innerHTML = '<img src="imgs/loading.gif" />';
}

function cargaDadesCapa(dades,capa){
	//$('#'+capa).hide();
	document.getElementById(capa).innerHTML = dades;
	//$('#'+capa).fadeIn('slow');
}

function ocultaFiltros(){
	if($('#descripcio_expo').is(':hidden')){
		$('#descripcio_expo').slideDown('slow');
		enviaVariableSession('muestra_filtro',1);
		document.getElementById('link_ocultar_filtros').innerHTML = "cerrar";
		$("#link_ocultar_filtros").removeClass('muestra_tancat');
		$("#link_ocultar_filtros").addClass('muestra_obert');
	}else{
		$('#descripcio_expo').slideUp('slow');
		//enviaVariableSession('muestra_filtro',2);
		document.getElementById('link_ocultar_filtros').innerHTML = "abrir";
		$("#link_ocultar_filtros").removeClass('muestra_obert');
		$("#link_ocultar_filtros").addClass('muestra_tancat');
	}
}

function enviaVariableSession(variable,valor){
	$.ajax({
			type: "POST",
			data: "variable="+variable+"&valor="+valor,
			url: "secciones/comunes/asignasession.php",

			success: function(msg){
			//alert(msg);
			}

		});
}

function envia_contacto(qui){

	estudio=document.getElementById("estudio").checked;
	disenyador=document.getElementById("disenyador").checked;
	var filter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

	if(qui == "estudio"){
		estudio = true;
	}else if(qui == "disenyador"){
		disenyador = true;
	}

	if (disenyador == true){

		algunBuid = 0;

		nom=document.getElementById('nom').value;
		if((nom == "")||(nom == "-1")){
			algunBuid = 1;
			$("#no_nom").fadeIn("slow");
		}else{
			$("#no_nom").fadeOut("slow");
		}

		fecha=document.getElementById('fecha').value;
		if((fecha == "")||(fecha == "-1")){
			algunBuid = 1;
			$("#no_fecha").fadeIn("slow");
		}else{
			$("#no_fecha").fadeOut("slow");
		}

		lugar_naci=document.getElementById('lugar_naci').value;
		if((lugar_naci == "")||(lugar_naci == "-1")){
			algunBuid = 1;
			$("#no_lugar_naci").fadeIn("slow");
		}else{
			$("#no_lugar_naci").fadeOut("slow");
		}

		lugar_resi=document.getElementById('lugar_resi').value;
		if((lugar_resi == "")||(lugar_resi == "-1")){
			algunBuid = 1;
			$("#no_lugar_resi").fadeIn("slow");
		}else{
			$("#no_lugar_resi").fadeOut("slow");
		}

		email=document.getElementById('email').value;
		if((email == "")||(email == "-1")){
			algunBuid = 1;
			$("#no_email").fadeIn("slow");
		}else{
			if(!filter.test(email)){
				algunBuid = 1;
				$("#wrong_mail").fadeIn("slow");
			}else{
				$("#no_email").fadeOut("slow");
				$("#wrong_mail").fadeOut("slow");
			}
		}

		web=document.getElementById('web').value;
		if((web == "")||(web == "-1")){
			algunBuid = 1;
			$("#no_web").fadeIn("slow");
		}else{
			$("#no_web").fadeOut("slow");
		}

		if(algunBuid == 0){
			document.forms.subscripcio.submit();
		}
	}else if (estudio == true){

		algunBuid = 0;

		nom_estudi=document.getElementById('nom_estudi').value;
		if((nom_estudi == "")||(nom_estudi == "-1")){
			algunBuid = 1;
			$("#no_nom_estudi").fadeIn("slow");
		}else{
			$("#no_nom_estudi").fadeOut("slow");
		}

		lugar_estudio=document.getElementById('lugar_estudio').value;
		if((lugar_estudio == "")||(lugar_estudio == "-1")){
			algunBuid = 1;
			$("#no_lugar_estudio").fadeIn("slow");
		}else{
			$("#no_lugar_estudio").fadeOut("slow");
		}

		email=document.getElementById('email').value;
		if((email == "")||(email == "-1")){
			algunBuid = 1;
			$("#no_email").fadeIn("slow");
		}else{
			if(!filter.test(email)){
				algunBuid = 1;
				$("#wrong_mail").fadeIn("slow");
			}else{
				$("#no_email").fadeOut("slow");
				$("#wrong_mail").fadeOut("slow");
			}
		}

		web=document.getElementById('web').value;
		if((web == "")||(web == "-1")){
			algunBuid = 1;
			$("#no_web").fadeIn("slow");
		}else{
			$("#no_web").fadeOut("slow");
		}

		miembro_1=document.getElementById('miembro_1').value;
		fecha_miembro_1=document.getElementById('fecha_miembro_1').value;
		lugar_miembro_1=document.getElementById('lugar_miembro_1').value;

		if((miembro_1 != "")||(fecha_miembro_1 != "")||(lugar_miembro_1 != "")){
			if(count_miembros == 0){
				count_miembros = 1;
			}
		}

		document.getElementById("countmiembr").value = count_miembros;

		if(algunBuid == 0){
			document.forms.subscripcio.submit();
		}

	}
}

function estudio_function(idioma){
	document.getElementById("disenyador").checked = false;

	loading('formulari_contact');
	$.ajax({
		type: "POST",
		url: "secciones/contacto/estudio.php",
		data: "ajax=1&idioma="+idioma,

		success: function(msg){
			cargaDadesCapa(msg,'formulari_contact');
			$('#formulari_contact').fadeIn("slow");
		}
 	});
}


function disenyador_function(idioma){
	document.getElementById("estudio").checked = false;

	loading('formulari_contact');
	$.ajax({
		type: "POST",
		url: "secciones/contacto/disenyador.php",
		data: "ajax=1&idioma="+idioma,

		success: function(msg){
			cargaDadesCapa(msg,'formulari_contact');
			$('#formulari_contact').fadeIn("slow");
		}
 	});
}

function obre_otro_miembro(idioma,countmiembros){

	if(count_miembros < 2){
		count_miembros = countmiembros;
	}else{
		count_miembros++;
	}

	loading('div_otro_miembro_'+count_miembros);
	$.ajax({
		type: "POST",
		url: "secciones/contacto/otro_miembro.php",
		data: "ajax=1&idioma="+idioma+"&countMiembros="+count_miembros,

		success: function(msg){
			cargaDadesCapa(msg,'div_otro_miembro_'+count_miembros);
			$('#div_otro_miembro_'+count_miembros).fadeIn("slow");
		}
 	});
}


/*function showMap(){
	if($('#google_maps').is(':hidden')){
		$('#google_maps').fadeIn('slow');
	}else{
		$('#google_maps').fadeOut('slow');
	}
}

function showSala1(){
	$('#sala2').hide();
	$('#sala3').hide();
	if($('#sala1').is(':hidden')){
		$('#sala1').fadeIn('slow');
	}else{
		$('#sala1').fadeOut('slow');
	}
}

function showSala2(){
	$('#sala1').hide();
	$('#sala3').hide();
	if($('#sala2').is(':hidden')){
		$('#sala2').fadeIn('slow');
	}else{
		$('#sala2').fadeOut('slow');
	}
}

function showSala3(){
	$('#sala1').hide();
	$('#sala2').hide();
	if($('#sala3').is(':hidden')){
		$('#sala3').fadeIn('slow');
	}else{
		$('#sala3').fadeOut('slow');
	}
}

function showAct1(){
	$('#act2').hide();
	$('#act3').hide();
	$('#act4').hide();
	if($('#act1').is(':hidden')){
		$('#act1').fadeIn('slow');
	}else{
		$('#act1').fadeOut('slow');
	}
}
function showAct2(){
	$('#act1').hide();
	$('#act3').hide();
	$('#act4').hide();
	if($('#act2').is(':hidden')){
		$('#act2').fadeIn('slow');
	}else{
		$('#act2').fadeOut('slow');
	}
}
function showAct3(){
	$('#act2').hide();
	$('#act1').hide();
	$('#act4').hide();
	if($('#act3').is(':hidden')){
		$('#act3').fadeIn('slow');
	}else{
		$('#act3').fadeOut('slow');
	}	
}
function showAct4(){
	$('#act2').hide();
	$('#act3').hide();
	$('#act1').hide();
	if($('#act4').is(':hidden')){
		$('#act4').fadeIn('slow');
	}else{
		$('#act4').fadeOut('slow');
	}
}
function abreMenu(){
	if($('#submenu0').is(':hidden')){
		$('#submenu0').slideDown('slow');
	}else{
		$('#submenu0').slideUp('slow');
	}
}
function abreEventos(){
	if($('#submenu1').is(':hidden')){
		$('#submenu1').slideDown('slow');
	}else{
		$('#submenu1').slideUp('slow');
	}
}*/
