/*
 * Funciones javascript para el formulario de inscripción al congreso y compra
 */


$(document).ready(function () {
		function formatCurrency(num) {
			num = num.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
				num = "0";
				sign = (num == (num = Math.abs(num)));
				num = Math.floor(num*100+0.50000000001);
				cents = num%100;
				num = Math.floor(num/100).toString();
				if(cents<10)
					cents = "0" + cents;
				for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
				    num = num.substring(0,num.length-(4*i+3))+','+
				num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + num + '.' + cents+' €');
		}
    	
    	$('.num_pax').click(function() {
        	/* Recálculo en funcion del número de paxes seleccionados */            
            var id_cuo = this.id.split('_')[1];            
            var num_paxes = (this.checked == undefined)?parseInt(this.value):(this.checked)?1:0;
            var precio = parseFloat($('#precio_'+id_cuo)[0].value);
            var total = num_paxes * precio;
            $('#d_total_'+id_cuo).html(formatCurrency(total));            	
    	});
        
        
         $(".btn_reservar").click(                
              function () {
                    $.blockUI({ css: { 
                        border: 'none', 
                        padding: '15px', 
                        backgroundColor: '#000', 
                        '-webkit-border-radius': '10px', 
                        '-moz-border-radius': '10px', 
                        opacity: '.5', 
                        color: '#fff' 
                    } }); 
                    document.body.style.cursor = 'wait';                    
                    var form = document.forms[0]
                    form.submit();
                    document.body.style.cursor = 'default';
              }
        );

        /* Inicialización de los importes */
        var paxes_cuotas = $('.num_pax');
        for (i=0; i< paxes_cuotas.length; i ++) {
            var cuota = paxes_cuotas[i];
            var id_cuo = cuota.id.split('_')[1];
            //var num_paxes = parseInt(cuota.value);            
            var num_paxes = (cuota.checked == undefined)?parseInt(cuota.value):(cuota.checked)?1:0;
            var precio = parseFloat($('#precio_'+id_cuo)[0].value);
            var total = num_paxes * precio;
            $('#d_total_'+id_cuo).html(formatCurrency(total));                                        
        }
    });   
