  function loadFile(url, target) {
	document.getElementById(target).innerHTML = "<table style=\"width:100%; height:100%;\"><tr><td style=\" text-align:center; vertical-align:middle;\"><img src=\"/bilder/bitte_warten.gif\" /></td></tr></table>";
	var ro = createRequestObject();
	ro.open("GET", url);
	ro.onreadystatechange = function() {
	  if(ro.readyState==4 && ro.status == 200) {
		document.getElementById(target).innerHTML = ro.responseText;
	  }
	}
	ro.send(null);
  }
  function loadFileEx(url, target) {
	target.innerHTML = "<table style=\"width:100%; height:100%;\"><tr><td style=\" text-align:center; vertical-align:middle;\"><img src=\"/bilder/bitte_warten.gif\" /></td></tr></table>";
	var ro = createRequestObject();
	ro.open("GET", url);
	ro.onreadystatechange = function() {
	  if(ro.readyState==4 && ro.status == 200) {
		target.innerHTML = ro.responseText;
	  }
	}
	ro.send(null);
  }
  function sendFile(url, target, text) {
	target.innerHTML = "<table style=\"width:100%; height:100%;\"><tr><td style=\" text-align:center; vertical-align:middle;\"><img src=\"/bilder/bitte_warten.gif\" /></td></tr></table>";
	var ro = createRequestObject();
	ro.open("POST", url);
	ro.onreadystatechange = function() {
	  if(ro.readyState==4 && ro.status == 200) {
		document.getElementById(target).innerHTML = ro.responseText;
	  }
	}
	ro.setRequestHeader("Pragma", "no-cache");
	ro.setRequestHeader("Cache-Control", "must-revalidate");
	ro.setRequestHeader("If-Modified-Since", document.lastModified);
	ro.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");  
	ro.send(text);
  }

  function createRequestObject() {
	if( window.XMLHttpRequest ) {
	  ro = new XMLHttpRequest();
	} else if( window.ActiveXObject ) {
	  ro = new ActiveXObject( "Microsoft.XMLHTTP" );
	}
	return ro;
  }




  function showInteraktiv() {
	document.getElementById("interaktiv").style.display = "block";
  }
  function hideInteraktiv() {
	document.getElementById("interaktiv").style.display = "none";
  }


  function sendRating(beg) {
	i=0;
	var query = Array();
	for (var rating in ratings) {
	  value = ratings[rating];
	  player = rating;
	  query[i++] = String(player) + "=" + String(value);
	}
	
	if (document.getElementsByTagName("map").length != i) {
	  alert("Sie haben noch nicht alle Spieler bewertet.");
	} else {
	  if (confirm("Möchten Sie diese Bewertung abschicken? Eine nachträgliche Änderung ist nicht mehr möglich.")) {
		sendFile("/module/bewertung_save.php?id=" + String(beg), "interaktiv", query.join("&"));
	  }
	}
	  
  }

  function showPic(name, width, height) {
	pic = window.open("/interaktiv/gallerie/pic_show.php?pic=" + name, "Bild", "width=" + width + ",height=" + height + ",scrollbars=yes");
	pic.focus();
  }


$(document).ready(function() {    
    var ratings = Array();
    
    function createBox(autoheight,hideclose) {$("body").append('<div id="layer"></div><div id="box_rahmen"><div id="box"><div id="box_text"></div></div><button id="box_close">schließen</button></div>');(autoheight==1)?$("#box_rahmen").css('height',''):$("#box_rahmen").css('height','80%');(hideclose==1)?$("#box_close").hide():$("#box_close").show();;$("#box_close").click(function(){closeBox();});}
    function showBox(url,post,autoheight,hideclose,callbackFnc) {
        if ($("#box_rahmen").length==0) createBox(autoheight,hideclose);
        if (url.substr(0,1)=="/") {
            $.post(url,post,function(data){
                $("#box_text").html(data); 
                $("#box_rahmen").center(); 
                if (callbackFnc != undefined) callbackFnc.call();
            });
        } else {
            $("#box_text").html(url);
            $("#box_rahmen").center();
            if (callbackFnc != undefined) callbackFnc.call();
        }
        
        $("#layer").fadeTo(500,0.9, function() {
            $("#box_rahmen").fadeTo(500,1);
        });
        
    }    
    function closeBox() {$("#layer").fadeTo(500,0, function() {$("#layer").remove();});$("#box_rahmen").fadeTo(500,0, function() {$("#box_rahmen").remove();});}

    function createTabs(id) {$("#"+id).tabs({load: function(event, ui) {$("#"+id+" > a", ui.panel).click(function() {$(ui.panel).get(this.href);return true;});}});}

    function showNews(id){showBox("/module/showNews.php",{id:id})}
    function showClubgame(id){showBox("/module/showClubgame.php",{clu:id},1,0);}
    function showVoteSelect(){showBox("/module/bewertung.php",0,1,0, function() { $("button.vote").click(function(){showVote($(this).attr('alt'))})})}
    function showVote(id){showBox("/module/bewertung.php",{id:id},1,0, function() {  $("#vote").click(function() { doVote(); });}); return false;}

    function doLogin(user, pass) {$.post('/module/doLogin.php', { name: user, pass: pass }, function(data){if (data !== "") { window.location.reload(); } else { $("#login_error").html("Benutzer unbekannt oder Passwort falsch"); } });}
    function doLogout() {$.post('/module/doLogin.php', { logout:1 }, function(data){ window.location.reload();});}    
    function doVote() {}

    function spieltag_einzeln(liga, spieltag) {$("#spieltag").load("/module/spieltag_einzeln.php", {liga:liga, spieltag:spieltag});}



    jQuery.fn.center = function(){this.css("position","fixed");this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");return this;}

    // Automatische Umwandler
    $("div[id$=_tabs]").each(function(index){createTabs($(this).attr("id"));});
    $(".clubgame_button").each(function(index){$(this).click(function() { showClubgame($(this).attr("alt"));});});
      
    $("a.news").live('click',function(){showNews($(this).attr("title"));});
    $("#spieltag_auswahl a").each(function(index){$(this).click(function() { spieltag_einzeln($(this).parent().attr("alt"),$(this).text());});});    
    $("#spieltag_auswahl").each(function(index){spieltag_einzeln($(this).attr("alt"),"0")});
    
    
    $('.gallery a').lightBox({fixedNavigation:true});

    $("a[id=login]").click(function(){showBox('<h1>Anmelden</h1>User:<br /><input id="login_user"><br />Passwort:<br /><input id="login_password" type="password"><br /><button id="login_submit">Anmelden</button><div id="login_error"></div>',0,1,0, function() { $("#login_submit").click(function() { doLogin($("#login_user").val(),$("#login_password").val()); }); }); return false;});
    $("a[id=logout]").click(function(){showBox('<h1>Abmelden</h1>M&ouml;chtest du dich wirklich abmelden?<br /><button id="logout_yes">Abmelden</button>',0,1,0,function() {$("#logout_yes").click(function() { doLogout();});}); return false;});
    $("a[id=bewerten]").click(function(){showVoteSelect()});       
    
                                                                                                                                                                                                     

    $("area[alt^=Note]").live('mouseenter',function(){
        $("img#"+$(this).parent().attr('name')).attr('src','/bilder/bewertung_'+$(this).attr('alt').substr(5,1)+'.png'); 
    }); 
    $("area[alt^=Note]").live('click',function(){
        ratings[$(this).parent().attr('name').substr(1)] = $(this).attr('alt').substr(5);
    });
    $("map[name^=w]").live('mouseleave',function(){
        number = (ratings[$(this).attr('name').substr(1)]) ? ratings[$(this).attr('name').substr(1)] : 0;
        $("img#"+$(this).attr('name')).attr('src','/bilder/bewertung_'+number+'.png'); 
    });
    
    function doVote() {
        query = "/module/bewertung_save.php?id="+$("#begid").html();
        $("map[name^=w]").each(function(index){
            player = $(this).attr('name').substr(1);
            note = $("img#"+$(this).attr('name')).attr('src').substr(18,1); 
            if (note == 0) { alert("Sie haben noch nicht alle Spieler bewertet."); return false; }
            query = query + "&" + player + "=" + note;
            
        })  

        if (confirm("Möchten Sie diese Bewertung abschicken? Eine nachträgliche Änderung ist nicht mehr möglich.")) {
            $.get(query,function(data){showBox(data,0,1,0)});
        }
    }

     

 

function sendRating(beg) {
    i=0;
    var query = Array();
    for (var rating in ratings) {
      value = ratings[rating];
      player = rating;
      query[i++] = String(player) + "=" + String(value);
    }
    
    if (document.getElementsByTagName("map").length != i) {
      alert("Sie haben noch nicht alle Spieler bewertet.");
    } else {
      if (confirm("Möchten Sie diese Bewertung abschicken? Eine nachträgliche Änderung ist nicht mehr möglich.")) {
        sendFile("/module/bewertung_save.php?id=" + String(beg), "interaktiv", query.join("&"));
      }
    }
      
  }


















});

