var req;
var div_id;

function startAjax(params) {
      try {
        if( window.XMLHttpRequest ) req = new XMLHttpRequest();
        else if( window.ActiveXObject ) req = new ActiveXObject( "Microsoft.XMLHTTP" );
        else alert( "Ihr Webbrowser unterstuetzt leider kein Ajax!" );

        req.open( "GET", "ajax.php?" + params, true );
        req.onreadystatechange = cbFunc;
        req.send( null );
      } catch( e ) {
        alert( "Fehler: " + e );
      }
}
function cbFunc() {
      if( 4 == req.readyState ) {
        if( 200 != req.status ) {
          alert( "Fehler " + req.status + ": " + req.statusText );
        } else {
          document.getElementById(div_id).innerHTML = req.responseText;
        }
      }
}

function countdown() {
  var monate = 0, tage = 0, stunden = 0, minuten = 0, sekunden = 0;
  var zielDatum   = new Date(2010, 9-1, 11, 14, 0,0);
  var startDatum  = new Date();

  //document.getElementById('countdown').innerHTML = "Noch kein neuer Termin";
  //exit;

  if(startDatum < zielDatum)  {
    while(startDatum<zielDatum) {
      monate++;
      startDatum.setMonth(startDatum.getMonth()+1);
    }
    startDatum.setMonth(startDatum.getMonth()-1);
    monate--;

    while(startDatum.getTime()+(24*60*60*1000)<zielDatum) {
      tage++;
      startDatum.setTime(startDatum.getTime()+(24*60*60*1000));
    }

    stunden  = Math.floor((zielDatum-startDatum)/(60*60*1000));
    startDatum.setTime(startDatum.getTime()+stunden*60*60*1000);
    minuten  = Math.floor((zielDatum-startDatum)/(60*1000));
    startDatum.setTime(startDatum.getTime()+minuten*60*1000);
    sekunden = Math.floor((zielDatum-startDatum)/1000);

    (monate != 1)?    monate  = monate + " Monate,  " : monate = monate + " Monat,  ";
    (tage != 1)?      tage    = tage + " Tage<br>" : tage = tage + " Tag<br>";
    stunden = stunden + " Std, ";
    minuten = minuten + " Min und ";
    sekunden= sekunden + " Sek";

    document.getElementById('countdown').innerHTML = "Noch<br><b>" + monate + tage + stunden + minuten + sekunden + "</b><br>bis zum n&auml;chsten Lauf";
    setTimeout('countdown()', 1000);
  }
  else {
    document.getElementById('countdown').innerHTML = "Lauf gestartet";
  }
}

function vote() {
  div_id = "poll_result";
  iVotedNr = document.getElementById("voting").value;
  startAjax("action=vote&subscriber=" + iVotedNr);
}

function show_voting() {
  div_id = "poll_result";
  startAjax("action=show_voting");
}

function popup(imgid, location, w, h) {
  // Java-Script-Code für JS-Popup-Fenster (Gallery)
  window.open('new.php?location=' + location + '&imgid=' + imgid + '', '_blank', 'width=' + w + ', height=' + h + ', scrollbars=yes, resizable=yes, status=no, toolbar=no, left=200, top=50');
}
