//FORMULARFUNKTIONEN

//ADD ACTION - ACTION SPEICHERN
function sendActiondata() {
	document.forms['action_data'].insert(new Element('input',
            {name: 'submit_actiondata', value: 'true', type: 'hidden'}));
	document.forms['action_data'].submit();
}
//ADD ACTION - ACTION LOESCHEN
function deleteActiondata() {
	document.forms['action_data'].insert(new Element('input',
            {name: 'delete_actiondata', value: 'true', type: 'hidden'}));
	document.forms['action_data'].submit();
}
//REGISTRIERUNG
function sendUserdata() {
	document.forms['user_data'].insert(new Element('input',
            {name: 'submit_userdata', value: 'true', type: 'hidden'}));
	document.forms['user_data'].submit();
}
//TEAMGRUENDUNG
function sendTeamdata() {
	document.forms['team_data'].insert(new Element('input',
            {name: 'submit_teamdata', value: 'true', type: 'hidden'}));
	document.forms['team_data'].submit();
}
//ALLGEMEIN UPLOAD EINES BILDES
function uploadLogo() {
	document.forms['upload_logo'].insert(new Element('input',
            {name: 'upload_logo', value: 'true', type: 'hidden'}));
	document.forms['upload_logo'].submit();
}
//ALLGEMEIN FILEUPLOAD
function uploadTrailer() {
	document.forms['upload_trailer'].insert(new Element('input',
            {name: 'upload_trailer', value: 'true', type: 'hidden'}));
	document.forms['upload_trailer'].submit();
}
function uploadLogo() {
	document.forms['upload_logo'].insert(new Element('input',
            {name: 'upload_logo', value: 'true', type: 'hidden'}));
	document.forms['upload_logo'].submit();
}
//TEAMANMELDUNG
function bookAction() {
	document.forms['action_booking'].insert(new Element('input',
            {name: 'book_action', value: 'true', type: 'hidden'}));
	document.forms['action_booking'].submit();
}
//HAUPTSEITE - LOGIN
function sendLogin() {
	document.forms['user_login'].insert(new Element('input',
            {name: 'login', value: 'true', type: 'hidden'}));
	document.forms['user_login'].submit();
}
//KASSE - BOOKCODE SCAN
function sendBookcode() {
	document.forms['scan_bookcode'].insert(new Element('input',
            {name: 'submit_bookcode', value: 'true', type: 'hidden'}));
	document.forms['scan_bookcode'].submit();
}
//KASSE - PAYMENT STATUS
function sendPaymentStatus() {
	document.forms['payment_status'].insert(new Element('input',
            {name: 'submit_paymentstatus', value: 'true', type: 'hidden'}));
	document.forms['payment_status'].submit();	
}
//STATION - STATION LOESCHEN
function sendDeleteActionpoint() {
	document.forms['action_data'].insert(new Element('input',
            {name: 'submit_delete', value: 'true', type: 'hidden'}));
	document.forms['action_data'].submit();
}
//STATION - STATION SPEICHERN
function sendActionpoint() {
	document.forms['action_data'].insert(new Element('input',
            {name: 'submit_actionpoint', value: 'true', type: 'hidden'}));
	document.forms['action_data'].submit();
}
//STATION - STATION BEARBEITEN
function changeActionpoint() {
	document.forms['action_data'].insert(new Element('input',
            {name: 'change_actionpoint', value: 'true', type: 'hidden'}));
	document.forms['action_data'].submit();
}
//STATION - TEAMCODE
function sendTeamcode() {
	document.forms['scan_teamcode'].insert(new Element('input',
            {name: 'submit_teamcode', value: 'true', type: 'hidden'}));
	document.forms['scan_teamcode'].submit();		
}
//PUNKTE VERGEBEN
function sendChooseteam() {
	document.forms['choose_team'].insert(new Element('input',
            {name: 'submit_chooseteam', value: 'true', type: 'hidden'}));
	document.forms['choose_team'].submit();		
}
//USERMANAGEMENT - SAVE STATIONUSERACCOUNT
function sendUseraccount() {
	document.forms['user_account'].insert(new Element('input',
            {name: 'submit_useraccount', value: 'true', type: 'hidden'}));
	document.forms['user_account'].submit();
}
//USERMANAGEMENT - HELPER RECHTE
function sendUsermgmt (userid) {
	document.forms['usermgmt_'+userid].insert(new Element('input',
            {name: 'submit_usermgmt', value: 'true', type: 'hidden'}));
	document.forms['usermgmt_'+userid].submit();
}
//USERMANAGEMENT - KICK HELPER
function kickStationuser (userid) {
	document.forms['delstationuser_'+userid].insert(new Element('input',
            {name: 'submit_delstationuser', value: 'true', type: 'hidden'}));
	document.forms['delstationuser_'+userid].submit();
}
//RÄTSEL - RÄTSEL SPEICHERN
function sendRiddle() {
	document.forms['riddle_data'].insert(new Element('input',
            {name: 'submit_riddle', value: 'true', type: 'hidden'}));
	document.forms['riddle_data'].submit();
}
//RÄTSEL - RÄTSEL BEARBEITEN
function changeRiddle() {
	document.forms['riddle_data'].insert(new Element('input',
            {name: 'change_riddle', value: 'true', type: 'hidden'}));
	document.forms['riddle_data'].submit();
}
//ACTIONTEAM ÜBERSICHT - ACTIONTEAM LÖSCHEN
function deleteActionteam (actionteamid) {
	document.forms['delactionteam'].insert(new Element('input',
            {name: 'submit_delactionteam', value: actionteamid, type: 'hidden'}));
	document.forms['delactionteam'].submit();
}
//ADMIN - NEUE ACTION - UMSCHALTEN DER TEXTEINGABE FÜR ACTION AKTIV UND BEENDET
function showActiveText() {
	document.getElementById('action_text_active').style.display = "";
	document.getElementById('action_text_finished').style.display = "none";
}
function showFinishedText() {
	document.getElementById('action_text_active').style.display = "none";
	document.getElementById('action_text_finished').style.display = "";
}
//ADMIN - NEUE ACTION - HINZUFÜGEN UND ENTFERNEN VON PLÄTZEN IM RENKING
var ranking_count = 1;
function changeRanking(option) {

	if(option == "add"){
		ranking_count += 1;
		
		document.getElementById('ranking').insert(new Element('input', {name: 'place_' + ranking_count, id: 'place_' + ranking_count, type: 'text', class: 'form_input_short', style: 'margin-left:10px'}));
		document.getElementById('ranking').insert(new Element('input', {name: 'teamname_' + ranking_count, id: 'teamname_' + ranking_count, type: 'text', class: 'form_input_short'}));
		document.getElementById('ranking').insert(new Element('input', {name: 'score_' + ranking_count, id: 'score_' + ranking_count, type: 'text', class: 'form_input_short'}));
	
	}else if(option == "delete" && ranking_count > 1) {
		var oldscore = document.getElementById('score_' + ranking_count);
		document.getElementById('ranking').removeChild(oldscore);
		
		var oldplace = document.getElementById('place_' + ranking_count);
		document.getElementById('ranking').removeChild(oldplace);
		
		var oldteamname = document.getElementById('teamname_' + ranking_count);
		document.getElementById('ranking').removeChild(oldteamname);
		
		ranking_count -= 1;
	}
}

function checkSelectedTeammember (elementID) {
    var formID = document.forms["action_booking"];
    var count = 0;
    var maxNumber = 5;

    for (i=0; i<formID.length; i++) {
    	if (formID.elements[i].type=="checkbox" && formID.elements[i].checked==true && count<=maxNumber) {
      		count++;
     	}
    }

    if (count>maxNumber) {
    	elementID.checked = false;
     	alert ("Es dürfen nur maximal "+maxNumber+" Mitglieder pro Team angemeldet werden!");
    }
}

function calcTotalPrice(){
	
	for(i=0; i<document.anmeldung.teamsize.length; i++){
    	if(document.anmeldung.teamsize[i].checked == true){
        	var members = document.anmeldung.teamsize[i].value;
		}
	}
	  
	var pricebig = Number(document.anmeldung.pricebig.value);
	var pricesmall = Number(document.anmeldung.pricesmall.value);
	
	if(members == 3 || members == 4){
		var price = pricesmall.toFixed(2);
	}
	if(members == 5 || members == 6){
		var price = pricebig.toFixed(2);
	}
	
	var sum1  = price * members;
	var total = sum1.toFixed(2);
	
	var sum3 = total /1.19;
	var subtotal = sum3.toFixed(2);
	
	var sum2 = total - (total /1.19);
	var tax = sum2.toFixed(2);
	
	document.anmeldung.subtotal.value = subtotal;
	document.anmeldung.totalprice.value = total;
	document.anmeldung.tax.value = tax;
	document.anmeldung.numofmembers.value = members;
	document.getElementById("perperson").innerHTML = members + " Pers. a " + price + " Eur";
}
	


jQuery(document).ready(function(){
    
    // Using ++++ multiple unit types within one animation.
	
	//ANIAMTION - ANMELDUNG MISSIONSBESCHREIBUNG
	
	jQuery("#nav_briefing").click(function(){
     	 if (jQuery("#nav_briefing").html() == "mehr") {
			jQuery("#additionalInfo").stop().slideDown('slow');
			jQuery("#nav_briefing").html("schlie&szlig;en");
          }else{
			jQuery("#additionalInfo").stop().slideUp('slow');
			jQuery("#nav_briefing").html("mehr");
		  }
     });
	
	jQuery("#nav_location").click(function(){
     	 if (jQuery("#nav_location").html() == "Infos zur Location") {
			jQuery("#locationInfo").stop().slideDown('slow');
			jQuery("#nav_location").html("schlie&szlig;en");
          }else{
			jQuery("#locationInfo").stop().slideUp('slow');
			jQuery("#nav_location").html("Infos zur Location");
		  }
     });
	
	//ANIAMTION - LAST ACTION - ZUSAMMENFASSUNG
	
	jQuery("#nav_summary").click(function(){
     	 if (jQuery("#nav_summary").html() == "weitere Platzierungen") {
			jQuery("#moreSummary").stop().slideDown('slow');
			jQuery("#nav_summary").html("schlie&szlig;en");
          }else{
			jQuery("#moreSummary").stop().slideUp('slow');
			jQuery("#nav_summary").html("weitere Platzierungen");
		  }
     });
	
	jQuery("#nav_location").click(function(){
     	 if (jQuery("#nav_location").html() == "Infos zur Location") {
			jQuery("#locationInfo").stop().slideDown('slow');
			jQuery("#nav_location").html("schlie&szlig;en");
          }else{
			jQuery("#locationInfo").stop().slideUp('slow');
			jQuery("#nav_location").html("Infos zur Location");
		  }
     });
	
	jQuery("#nav_sponsors").click(function(){
     	 if (jQuery("#nav_sponsors").html() == "Sponsoren!") {
			jQuery("#moreSponsors").stop().slideDown('slow');
			jQuery("#nav_sponsors").html("Sponsoren schlie&szlig;en");
          }else{
			jQuery("#moreSponsors").stop().slideUp('slow');
			jQuery("#nav_sponsors").html("Sponsoren!");
		  }
     });
	
	//ANIMATION - ANMELDUNG USERACCOUNT
	
    jQuery("#member").click(function(){
     	 if (jQuery("#memberReg").css("display") == "none") {
			jQuery("#memberReg").stop().slideDown('slow');
          }else{
			jQuery("#memberReg").stop().slideUp('slow');
		  }
     });
	
	jQuery("#pAmiando").click(function(){
     	 if (jQuery("#pAmiando:checked").val() == "amiando") {
				jQuery("#vorkasse").stop().slideUp(500, function() {
					jQuery("#amiando").stop().slideDown(1000);
				});
		  }
     });
	
		jQuery("#pVorkasse").click(function(){
     	 if (jQuery("#pVorkasse:checked").val() == "vorkasse") {
				jQuery("#amiando").stop().slideUp(500, function() {
					jQuery("#vorkasse").stop().slideDown(1000);
				});
		  }
     });
/*	
	jQuery("#pAbendkasse").click(function(){
     	 if (jQuery("#pAbendkasse:checked").val() == "abendkasse") {
			jQuery("#amiando").stop().slideUp(500, function() {
				jQuery("#vorkasse").stop().slideUp(500, function() {
					jQuery("#abendkasse").stop().slideDown(1000);
				});
			});
		  }
     });
*/

	//ANMELDUNG - COMMANDERNAME SOFORT AUCH ALS USERNAME EINTRAGEN
	
	jQuery("#commander").change(function(){
			var commander = jQuery("#commander").val();
			jQuery("#username").val(commander)
	});
	
	//LOGIN
	
	jQuery("#login_btn").click(function(){
     	 if (jQuery("#login_body").css("height") == "0px") {
			jQuery("#login_btn").stop().animate({
        			height: '150px',
					opacity: '1.00'
            	}, 1 );
			jQuery("#login_body").stop().animate({
        			width: '165px',
					opacity: '1.00'
            	}, 1000 );
			jQuery("#login_navbtn").css('backgroundImage','url(/images/log_nav_btn_in.png)');
          }
     	if (jQuery("#login_body").css("width") == "165px") {
     		jQuery("#login_btn").stop().animate({
        			width: '0px',
					opacity: '0.00'
            	}, 1 );
			jQuery("#login_body").stop().animate({
     			 	width: '0px',
     			 	opacity: '0.00'
     		 	}, 1000 );
			jQuery("#login_navbtn").css('backgroundImage','url(/images/log_nav_btn_out.png)');
     	}
     })
	
	jQuery("#logout_btn").mouseover(function() {
		jQuery("#user_wrap").css('background','url(/images/user_bg_logout_sprite.png) no-repeat 0px -85px');
	});
	
	jQuery("#logout_btn").mouseout(function() {
		jQuery("#user_wrap").css('background','url(/images/user_bg_logout_sprite.png) no-repeat 0px 0px');
	});
	
	jQuery("#login_btn").mouseover(function() {
		jQuery("#log_wrap").css('background','url(/images/user_bg_login_sprite.png) no-repeat 0px -85px');
	});
	
	jQuery("#login_btn").mouseout(function() {
		jQuery("#log_wrap").css('background','url(/images/user_bg_login_sprite.png) no-repeat 0px 0px');
	});
	
	
    jQuery("#login_button_wrap").click(function(){
     	 if (jQuery("#login_body_wrap").css("width") == "0px") {
			jQuery("#login_body_wrap").stop().animate({
        			width: '140px',
        			marginLeft: '0px'
            	}, 1000 );
     		jQuery("#login_form_wrap").stop().animate({
 				width: '120px',
 				opacity: '1.00',
 				marginLeft: '10px'
     		}, 1000 );
			jQuery("#login_button_wrap").css('backgroundImage','url(/images/login_but_in.png)');

          }
     	if (jQuery("#login_body_wrap").css("width") == "140px") {
     		jQuery("#login_body_wrap").stop().animate({
     			 	width: '0px',
     			 	marginLeft: '-5px'
     		 	}, 1000 );
     		jQuery("#login_form_wrap").stop().animate({ 
   				width: '120px',
   				opacity: '0.00',
   				marginLeft: '-135px'
       		}, 1000 );
			jQuery("#login_button_wrap").css('backgroundImage','url(/images/login_but_out.png)');
     	}
     });

    jQuery("#newsletter_button_wrap").click(function(){
   	 if (jQuery("#newsletter_wrap").css("marginLeft") == "-145px") {
   	 
    		jQuery("#newsletter_wrap").stop().animate({ 
        		marginLeft: "0px"
      		}, 500 );
      		jQuery("#newsletter_body_wrap").stop().animate({
          		opacity: "1.00"
          	}, 500 ); 
        }
   	 else{
   		 jQuery("#newsletter_wrap").stop().animate({ 
          		marginLeft: "-145px"
        	}, 500 );
    		jQuery("#newsletter_body_wrap").stop().animate({ 
         	 	opacity: "0.00"
        	}, 500 );
        }
   });

    jQuery("#bookmarks_button_wrap").click(function(){
      	 if (jQuery("#bookmarks_body_wrap").css("width") == "0px") {
      		jQuery("#bookmarks_body_wrap").stop().animate({
         			width: '140px',
         			marginLeft: '0px'
             	}, 1000 ); 
     			jQuery("#bookmarks_icon_wrap").stop().animate({
     				width: '120px',
     				opacity: '1.00',
     				filter: 'alpha(opacity = 100)',
     				marginLeft: '10px'
         		}, 1000);
           }
      	if (jQuery("#bookmarks_body_wrap").css("width") == "140px") {
      		 jQuery("#bookmarks_body_wrap").stop().animate({
      			 	width: '0px',
      			 	marginLeft: '-5px'
      		 	}, 1000 ); 
       		jQuery("#bookmarks_icon_wrap").stop().animate({ 
       				width: '120px',
       				opacity: '0.00',
       				filter: 'alpha(opacity = 0)',
       				marginLeft: '-135px'
           		}, 1000 );
      	}
      });
        
    jQuery("#menue_field_wrap_1").click(function(){
   		if (jQuery("#sub_txt_wrap_1").is(":hidden")) {
   	 
     		jQuery("#sub_txt_wrap_1").slideDown("slow");
     		jQuery("#sub_txt_wrap_2").slideUp("slow");
     		jQuery("#sub_txt_wrap_3").slideUp("slow");
     		jQuery("#sub_txt_wrap_4").slideUp("slow");
     		jQuery("#sub_txt_wrap_5").slideUp("slow");
        }
   	 	else{
     		jQuery("#sub_txt_wrap_1").slideUp("slow");
     	} 
    });

    jQuery("#menue_field_wrap_2").click(function(){
      	 if (jQuery("#sub_txt_wrap_2").is(":hidden")) {
      		 
      		jQuery("#sub_txt_wrap_1").slideUp("slow");
        	jQuery("#sub_txt_wrap_2").slideDown("slow");
        	jQuery("#sub_txt_wrap_3").slideUp("slow");
     		jQuery("#sub_txt_wrap_4").slideUp("slow");
     		jQuery("#sub_txt_wrap_5").slideUp("slow");
           }
      	 else{
        	jQuery("#sub_txt_wrap_2").slideUp("slow");
        } 
 	});

    jQuery("#menue_field_wrap_3").click(function(){
     	 if (jQuery("#sub_txt_wrap_3").is(":hidden")) {
     		 
     	jQuery("#sub_txt_wrap_1").slideUp("slow");
     	jQuery("#sub_txt_wrap_2").slideUp("slow");
       	jQuery("#sub_txt_wrap_3").slideDown("slow");
       	jQuery("#sub_txt_wrap_4").slideUp("slow");	
       	jQuery("#sub_txt_wrap_5").slideUp("slow");
        }
     	else{
       	jQuery("#sub_txt_wrap_3").slideUp("slow");
       } 
	});

    jQuery("#menue_field_wrap_4").click(function(){
    	 if (jQuery("#sub_txt_wrap_4").is(":hidden")) {
    	
    	jQuery("#sub_txt_wrap_1").slideUp("slow");
    	jQuery("#sub_txt_wrap_2").slideUp("slow");
    	jQuery("#sub_txt_wrap_3").slideUp("slow");
      	jQuery("#sub_txt_wrap_4").slideDown("slow");
      	jQuery("#sub_txt_wrap_5").slideUp("slow");
         }
    	 else{
      	jQuery("#sub_txt_wrap_4").slideUp("slow");
      } 
	});
    
    jQuery("#menue_field_wrap_5").click(function(){
   	 if (jQuery("#sub_txt_wrap_5").is(":hidden")) {
   	
   	jQuery("#sub_txt_wrap_1").slideUp("slow");
   	jQuery("#sub_txt_wrap_2").slideUp("slow");
   	jQuery("#sub_txt_wrap_3").slideUp("slow");
   	jQuery("#sub_txt_wrap_4").slideUp("slow");
     	jQuery("#sub_txt_wrap_5").slideDown("slow"); 
        }
   	 else{
     	jQuery("#sub_txt_wrap_5").slideUp("slow");
     } 
	});
	  
  });
