
function Sport(name, mannschaft, einzel, paar, spiel, keinspiel, nature, music, fight, holiday, health, result) {
	this.name = name;
	this.mannschaft = mannschaft;
	this.einzel = einzel;
	this.paar = paar;
	this.spiel = spiel;
	this.keinspiel = keinspiel;
	this.nature = nature;
	this.music = music;	
	this.fight = fight;
	this.holiday = holiday;
	this.health = health;
	
	this.match = 0;		
	
	
	var insert = function (Sport, result) {
		if(result.length == 0) {
			result.push(Sport);
			return;
		}
		
		for(var i = 0; i < result.length - 1; i++) {
			if(result[i].match < Sport.match) {
				result.splice(i, 0, Sport);
				return;
			}
		}	
		
		result.push(Sport);
	}

	var doMatch = function(Sport, result) {
		if(document.Formular.group.checked == true)
			Sport.match = Sport.match + Sport.mannschaft;		
			
		if(document.Formular.pair.checked == true)
			Sport.match = Sport.match + Sport.paar;
			
		if(document.Formular.flex.checked == true)
			Sport.match = Sport.match + Sport.einzel;	
			
		if(document.Formular.nature.checked == true)
			Sport.match = Sport.match + Sport.nature;
			
		if(document.Formular.game.checked == true)
			Sport.match = Sport.match + Sport.spiel;		
			
		if(document.Formular.music.checked == true)
			Sport.match = Sport.match + Sport.music;
			
		if(document.Formular.fight.checked == true)
			Sport.match = Sport.match + Sport.fight;		
			
		if(document.Formular.holiday.checked == true)
			Sport.match = Sport.match + Sport.holiday;
			
		if(document.Formular.health.checked == true)
			Sport.match = Sport.match + Sport.health;
					
			
		insert(Sport, result);		
	}
	
	doMatch(this, result);
}



function calcSport() {
	var result = new Array();	

	//	  name, mannschaft, einzel, paar, spiel, keinspiel, nature, music, fight, holiday, health,result)
	new Sport("Badminton", 	0, 	0, 	10, 	10, 	0, 	0, 	0, 	0, 	0, 	0, result);
	new Sport("Tennis", 	0, 	0, 	10, 	10, 	0, 	3, 	0, 	0, 	0, 	0, result);
	new Sport("Squash", 	0, 	0, 	10, 	10, 	0, 	0, 	0, 	3, 	0,	0, result);
	new Sport("Tischtennis", 0, 	0, 	10, 	10, 	0, 	0, 	0, 	0, 	0, 	0, result);	
	
	new Sport("Joggen", 	0, 	10, 	0, 	0, 	10, 	10, 	0, 	0, 	0,	10,	result);
	new Sport("Spinning", 	0, 	10, 	0, 	0, 	10, 	0, 	5, 	0, 	0,	10,	result);
	new Sport("Walking", 	0, 	10, 	0, 	0, 	10, 	10, 	0, 	0, 	0,	10,	result);
	new Sport("Schwimmen", 	0, 	10, 	0, 	0, 	10, 	0, 	0, 	0, 	0,	10,	result);
	new Sport("Radfahren", 	0, 	10, 	0, 	0, 	10, 	10, 	0, 	0, 	0,	10,	result);
	new Sport("Heimtrainer", 0, 	10, 	0, 	0, 	10, 	0, 	0, 	0, 	0,	10,	result);
	new Sport("Inline-Skaten", 0, 	10, 	0, 	0, 	10, 	10, 	0, 	0, 	0,	10,	 result);
	new Sport("Mountain-Biking", 0,	10, 	0, 	0, 	10, 	10, 	0, 	0, 	10,	0,	 result);
	new Sport("Snowboarden", 0, 	10, 	0, 	0, 	10, 	10, 	0, 	0, 	10,	0,	 result);
	new Sport("Ski", 	0, 	10, 	0, 	0, 	10, 	10, 	0, 	0, 	10,	0,	 result);	
	
	new Sport("Basketball", 10, 	0, 	0, 	10, 	0, 	0, 	0, 	0, 	0, 	0,	result);
	new Sport("Volleyball", 10,	0, 	0, 	10, 	0, 	0, 	0, 	0, 	0, 	0,	result);
	new Sport("Fussball", 	10, 	0, 	0, 	10, 	0, 	3, 	0, 	3, 	0, 	0,	result);
	new Sport("Handball", 	10, 	0, 	0, 	10, 	0, 	0, 	0, 	3, 	0, 	0,	result);		
	
	new Sport("Jiu Jitsu", 	0, 	10, 	5, 	0, 	10, 	0, 	0, 	20, 	0, 	0,	result);
	new Sport("Karate", 	0, 	10, 	5, 	0, 	10, 	0, 	0, 	20, 	0, 	0,	result);
	new Sport("Kung Fu", 	0, 	10, 	5, 	0, 	10, 	0, 	0, 	20, 	0, 	0,	result);
	new Sport("Judo", 	0, 	10, 	5, 	0, 	10, 	0, 	0, 	15, 	0, 	0,	result);
	
	new Sport("Gruppentanz", 10, 	0, 	0, 	0, 	10, 	0, 	10, 	0,	0, 	0,	result);	
	new Sport("Tanzen", 0, 		0, 	10, 	10, 	0, 	0, 	10, 	0, 	0, 	0, result);
	new Sport("Aerobic", 0, 	10, 	5, 	10, 	0, 	0, 	10, 	0, 	0, 	5, result);
	new Sport("Jazz-Gymnastik", 0, 	10, 	5, 	10, 	0, 	0, 	10, 	0, 	0, 	10, result);

	new Sport("Fitness-Studio", 0, 	10, 	0, 	0, 	10, 	0, 	0, 	0,	0, 	10,	result);

	new Sport("Yoga", 	0, 	10, 	0, 	0, 	10, 	0, 	0, 	0, 	0, 	0,	result);

	new Sport("Windsurfen", 0, 	10, 	0, 	0, 	10, 	10, 	0, 	0, 	10,	0,	 result);
	new Sport("Bergsteigen", 0, 	10, 	5, 	0, 	10, 	20, 	0, 	0, 	10, 	0,	result);
	new Sport("Tauchen", 	0, 	10, 	5, 	0, 	10, 	30, 	0, 	0, 	10, 	0,	result);
	new Sport("Golf", 	0, 	10, 	5, 	0, 	0, 	10,	0, 	0, 	10, 	0,	result);
	new Sport("Reiten", 	0, 	10, 	5, 	0, 	10, 	10, 	0,	0, 	10, 	0,	result);
		
	window.location.href="../../tools/result.html?one=" + result[0].name +"&two=" + result[1].name + "&thr=" + result[2].name + "&fou=" + result[3].name + "&fiv=" + result[4].name;
}


function calcBMI() {
	
	var gewicht = document.Formular.weight.value;
	var groesse = document.Formular.size.value;		
	groesse = eval (groesse / 100);
	groesse = eval(groesse * groesse);
	var bmi = eval( gewicht / groesse );
	if(bmi > 38)
		window.location.href="dont.html?bmi=" + bmi;
	else 
		window.location.href="default.html?bmi=" + bmi;
}


function showParameter(parameterName) {
	var search = parameterName + "=";
	var iPos = window.location.href.indexOf(search);
	if(iPos > 0) {
		var iDiff = search.length;		
		var strvalue = window.location.href.substring(iPos + iDiff);

		iPos = strvalue.indexOf("&");		
		if(iPos > -1) {		
			strvalue = strvalue.substring(0, iPos);
		}
		
		document.write(decodeURI(strvalue));
	}
}
