window.addEvent('domready', function(){
	var temporal=0;
	var tiempo=0;
	$('convertir').addEvent("click", function(e) {
		e = new Event(e).stop();
		tiempo=(parseInt($('minutos').value)*6000)+(parseInt($('segundos').value)*100)+(parseInt($('centesimas').value));
		if ($('crono').value=="E" && $('piscina').value=="25"){	
			$('tempe25').value = traducir(tiempo);
			temporal = tiempo-man_ele($('prueba').value);
			$('tempm25').value = traducir(temporal);
			temporal = temporal+de25a50($('prueba').value,$('sexo').value);
			$('tempm50').value = traducir(temporal);
			temporal = temporal+man_ele($('prueba').value);
			$('tempe50').value = traducir(temporal);
		}else if($('crono').value=="M" && $('piscina').value=="25"){
			$('tempm25').value = traducir(tiempo);
			temporal = tiempo+man_ele($('prueba').value);
			$('tempe25').value = traducir(temporal);
			temporal = temporal+de25a50($('prueba').value,$('sexo').value);
			$('tempe50').value = traducir(temporal);
			temporal = temporal-man_ele($('prueba').value);
			$('tempm50').value = traducir(temporal);
		}else if($('crono').value=="E" && $('piscina').value=="50"){
			$('tempe50').value = traducir(tiempo);
			temporal = tiempo-man_ele($('prueba').value);
			$('tempm50').value = traducir(temporal);
			temporal = temporal-de25a50($('prueba').value,$('sexo').value);
			$('tempm25').value = traducir(temporal);
			temporal = temporal+man_ele($('prueba').value);
			$('tempe25').value = traducir(temporal);
		}else if($('crono').value=="M" && $('piscina').value=="50"){
			$('tempm50').value = traducir(tiempo);
			temporal = tiempo+man_ele($('prueba').value);
			$('tempe50').value = traducir(temporal);
			temporal = temporal-de25a50($('prueba').value,$('sexo').value);
			$('tempe25').value = traducir(temporal);
			temporal = temporal-man_ele($('prueba').value);
			$('tempm25').value = traducir(temporal);
		}
	});
});

function de25a50(prueba,sexo){	
	switch (prueba) {
		case "50l":
			if (sexo=="M") {return(70)}
			else return(40);
			break;
		case "100l":
			if (sexo=="M") {return(160)}
			else return(100);
			break;
		case "200l":
			if (sexo=="M") {return(340)}
			else return(240);
			break;
		case "400l":
			if (sexo=="M") {return(720)}
			else {return(520)};
			break;
		case "800l":
			if (sexo=="M") {return(1570)}
			else {return(1190)};
			break;
		case "1500l":
			if (sexo=="M") {return(2950)}
			else {return(2230)};
			break;
		case "50m":
			return(30);
			break;
		case "100m":
			if (sexo=="M") {return(130)}
			else {return(80)};
			break;
		case "200m":
			if (sexo=="M") {return(310)}
			else {return(240)};
			break;
		case "50e":
			if (sexo=="M") {return(110)}
			else {return(100)};
			break;
		case "100e":
			if (sexo=="M") {return(250)}
			else {return(220)};
			break;
		case "200e":
			if (sexo=="M") {return(570)}
			else {return(570)};
			break;
		case "50b":
			if (sexo=="M") {return(80)}
			else {return(60)};
			break;
		case "100b":
			if (sexo=="M") {return(230)}
			else {return(200)};
			break;
		case "200b":
			if (sexo=="M") {return(600)}
			else {return(450)};
			break;
		case "200x":
			if (sexo=="M") {return(490)}
			else {return(310)};
			break;
		case "400x":
			if (sexo=="M") {return(1000)}
			else {return(750)};
			break;
	}
}

function man_ele (prueba){	
	switch (prueba) {
		case "50m":
		case "50e":
		case "50b":
		case "50l":
			return(29);
			break;
		default:
			return(19);
			break;
	}
}

function con_cero(temp){	
	switch (temp){ 	
		case 0:
			return("00");
			break;
		case 1:
			return("01");
			break;
	 	case 2:
			return("02");
			break;
	 	case 3:
			return("03");
			break;
	 	case 4:
			return("04");
			break;
	 	case 5:
			return("05");
			break;
	 	case 6:
			return("06");
			break;
	 	case 7:
			return("07");
			break;
	 	case 8:
			return("08");
			break;
	 	case 9:
			return("09");
			break;
		default:
			return(temp);
	}
}

function traducir(temporal){
	var m;
	var s;
	var c;
	m=Math.floor(temporal/6000);
	s=Math.floor((temporal-(m*6000))/100);
	c=temporal-(m*6000)-(s*100);
	return con_cero(m)+":"+con_cero(s)+"."+con_cero(c);
}
