$(document).ready(function(){
		$(document).pngFix();
});

function calcular(){
	var numero = $("#personas").val();
	var strep  = $(".streeper:checked").val();
	var humor  = $(".humorista:checked").val();
	
	//calculamos precio autocar
	if(numero <= 20){
		var autocar = 350.00;
	} else if(numero > 20 && numero <= 30){
		var autocar = 400.00;
	} else if(numero > 30 && numero <=40){
		var autocar = 500.00
	} else {
		var autocares = Math.round(numero / 20);
		var autocar = autocares * 400.00;
	}
	
	//Calculo streeper
	if(strep == 1 || strep == 2){
		var streeper = 210.00;
	} else{
		var streeper = 0;
	}
	
	//Humorista
	if(humor == 1){
		var humorista = 275.00;		
	} else {
		var humorista = 0;
	}
	
	//Calculo del menu
	var men = numero * 50;
	
	//total
	var total = autocar + streeper + humorista + men;
	$("#total").text(total+"\u20AC");
	$("#unitario").text(format_number(total/numero,2)+"\u20AC");	
	
}

function validar(){
	var nombre  = $("#nombre").val();
	var tlf  = $("#tlf").val();
	var email  = $("#email").val();
	var comentario  = $("#comentario").val();
	var error=0;

	if(tlf.length < 6 && email.length < 5){
		var error=1;		
	}
	if(comentario.length < 5){
		var error=1;

	}
	if(error==1){
		alert("Debes especificar almenos una forma de contacto y un mensaje");
		return false;
	}
}

function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf(',');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}