
$(window).ready(function(){ 
	$('a#eml').each(function(){ var head = 'in' + 'fo' + '\x40'; this.href = 'mailto:' + head + 'contespelmon' + '.org'; this.innerHTML =  head + 'contespelmon' + '&#46;org'; });
	$('a#opcioa').click(function(){ var uri = "formularis/fes-te-amic.php"; $.get(uri, {}, function(data){ obrirFinestra(uri, data); }, 'html'); });
	$('a#opciob').click(function(){ var uri = "formularis/fes-un-donatiu.php"; $.get(uri, {}, function(data){ obrirFinestra(uri, data); }, 'html'); });	
});

function obrirFinestra(uri, data){
	$('#formulari div.contenidor').html(data);
	$('#formulari').css('width', $(window).width() + 'px').css('height', $(document).height() + 'px').slideDown(1400);
	$('#formulari .contenidor #altreimport').focus(function(){ $('#aimport').attr('checked', 'checked'); this.readonly = false; }).blur(function(){ if(!$('#aimport').attr('checked')) this.value = ''; });
	$('#formulari .contenidor input.tancar').click(function(){ tancarFinestra(); });	
	$('#formulari .contenidor input.enviar').click(function(){ 
		if(confirm("Heu revisat les dades del formulari i el voleu enviar? No oblideu omplir tots els camps si us plau. Per enviar accepteu. Moltes Gràcies.")){
		var dades = Object();
		$("form input, form select").each(function() {	
			if(this.type != 'hidden' && !this.disabled && !this.readonly){
				switch(this.type){
					case 'radio':
						if(this.checked && this.value)
							dades[this.name] = this.title + '|' + this.value;
						break;
					case 'checkbox':
							dades[this.name] = this.title + (this.checked ? '|sí' : '|no');
						break;
					default:
						dades[this.name] = this.title + '|' + this.value;					
				}				
			}
		})	
		dades['sub'] = 1;
		$.post(uri, dades, function(data){ scroll(0, 0); $('#formulari div.contenidor').html(data); $('#formulari .contenidor input.tancar').click(function(){ tancarFinestra(); }); }, 'html'); 
		}
	});	
	
}

function tipusEntitat(persona){
	$('input#cognoms, div#mesdades input, input#professio').each(function(){ $(this).attr('disabled', persona); });
	$('.amaga').each(function(){ $(this).css('display', persona ? 'none' : 'block'); });
}

function deshabilita(valor, bloc, un){
	$((un ? "#" + bloc : "#" + bloc + " input[@type='text']")).each(function(){ $(this).attr('readonly', valor).attr('value', ''); });
}

function tancarFinestra(){
	$('#formulari').slideUp(1400, function(){ $('#formulari div.contenidor').html(''); });
}
