var radioid;
var radiostatus = "play";
var radioidFF;
var showsubmenu;
var xmlreqs=new Array();
var currenttime = 'March 10, 2010 22:49:52'; //PHP method of getting server date

function CXMLReq(freed) {
    this.freed = freed;
    this.xmlhttp = false;

    try
    { //Javascript > 5.
        this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }

    catch (e)
    { //Gebruik anders active X.
        try { //Voor IE dus.
            this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) { //Anders andere browser.
            this.xmlhttp = false;
        }
    }

    if (!this.xmlhttp && typeof xmlhttpRequest != 'undefined')
    {  //Geen IE maak dan javascript object.
        this.xmlhttp = new XMLHttpRequest();
    }
}

function doRequest(serverPage, div, title)
{ //AJAX AJAX AJAX AJAX!!!
    if (ol=="ja")
    {
        return oldoRequest(serverPage, div);
    }

    var newid = -1;
    for (var i=0; i<xmlreqs.length; i++) {
        if (xmlreqs[i].freed == 1) { newid = i; break; }
    }
    if (newid == -1) { newid = xmlreqs.length; xmlreqs[newid] = new CXMLReq(1); }

    xmlreqs[newid] = new CXMLReq();
    xmlreqs[newid]['div'] = div;
    xmlreqs[newid]['title'] = title;
//alert(xmlreqs.length);
if (xmlreqs[newid].xmlhttp) {
  showLoading();
  xmlreqs[newid].xmlhttp.open("POST", serverPage);
  document.getElementById(xmlreqs[newid]['div']).innerHTML = 'Laden...';
  xmlreqs[newid].xmlhttp.onreadystatechange = function()
        { //hij verandert van status
          if (xmlreqs[newid].xmlhttp.readyState == 4 && xmlreqs[newid].xmlhttp.status == 200)
          { //klaar
            if (xmlreqs[newid].xmlhttp.responseText != null && xmlreqs[newid].xmlhttp.responseText.length>0)
            { //controleer of er uberhaupt wat in staat
               document.getElementById(xmlreqs[newid]['div']).innerHTML = xmlreqs[newid].xmlhttp.responseText;
               document.title='SoeGiJoMa';
            }
            xmlreqs[newid].freed = 1;
            hideLoading();
          }
        }
  xmlreqs[newid].xmlhttp.send(null);
  return false;
}}

function oldoRequest(serverPage, div)
{ //AJAX AJAX AJAX AJAX!!!
//Maak een boolean variable voor het controleren op geldige IE instantie.
var xmlhttp = false;
var serverPagearray=new Array();
var loadedobjects = "";

try
{ //Javascript > 5.
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}

catch (e)
{ //Gebruik anders active X.
    try { //Voor IE dus.
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) { //Anders andere browser.
        xmlhttp = false;
    }
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{  //Geen IE maak dan javascript object.
    xmlhttp = new XMLHttpRequest();
}

  serverPagearray[serverPage] = true;
  xmlhttp.open("POST", serverPage);
  objID = document.getElementById(div);
  objID.innerHTML = 'Laden...';
  showLoading();
  xmlhttp.onreadystatechange = function()
        { //hij verandert van status
          if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
          { //klaar
            serverPagearray[serverPage] = false;
            if (xmlhttp.responseText == null || xmlhttp.responseText.length==0)
            { //controleer of er uberhaupt wat in staat
                //objID.style.display = "none";
            } else {
                //objID.style.display = "block";
                objID.innerHTML = xmlhttp.responseText;
            }
            hideLoading();
          }
        }
  xmlhttp.send(null);
  return false;
}

function loadjs(file,objID)
{ //laad externe javascript functies
  var head = document.getElementsByTagName('head').item(0);
  var old  = document.getElementById(objID);
  if (old)
  {
    try
    { //The first child of the div is the bold element.
        head.removeChild(old);
    }
    catch(e)
    {
    }
  }
  script = document.createElement('script');
  script.src = file;
  script.type = 'text/javascript';
  script.defer = true;
  script.id = objID;
  void(head.appendChild(script));
//  head.appendChild(script)
  return false;
}

/*
function radiotimer()
{
    loadjs('DJORadio/radiocheck.php', 'radiocheck');
    setTimeout("radiotimer()",10000);
}
*/

function stopError() {
    return true;
}

function shsm(did) {
    if (document.getElementById(showsubmenu))
    { document.getElementById(showsubmenu).style.display = 'none'; }
    if (document.getElementById(did))
    { document.getElementById(did).style.display = 'block'; }
    showsubmenu = did;
}

///////////Stop editting here/////////////////////////////////

var montharray=new Array("Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","October","November","December");
var serverdate=new Date(currenttime);

function padlength(what){
var output=(what.toString().length==1)? "0"+what : what;
return output;
}

function displaytime(){
serverdate.setSeconds(serverdate.getSeconds()+1);
var minsec = ":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds());
var hourned=padlength(serverdate.getHours());
var hoursr=padlength(serverdate.getHours()-4);
var dayback=0;
if (hoursr<0) { dayback=1; hoursr=24+hoursr; }

if (document.getElementById("servertime")) {document.getElementById("servertime").innerHTML=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()+" - "+hourned+minsec;}
if (document.getElementById("servertime_sr")) {document.getElementById("servertime_sr").innerHTML=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate()-dayback)+", "+serverdate.getFullYear()+" - "+hoursr+minsec;}
}

//window.onerror = stopError;

function loadonbody()
{   //laad alle scripts
	hideLoading();

    if (ol=="ja")
    {
        //oldoRequest('weer.php', 'righter_column');
        setTimeout("oldoRequest('berichten.php?forumid=1', 'contents')", 1000);
        setTimeout("oldoRequest('DJORadio/djoradio.php', 'radiodiv')", 2500);
    }
    else
    {
        doRequest('berichten.php?forumid=1', 'contents');
        //doRequest('weer.php', 'righter_column');
        doRequest('DJORadio/djoradio.php', 'radiodiv');
        loadjs('DJORadio/radiocheck.php', 'radiocheck');
        document.getElementById('browserMsg').style.display = 'none';
    }
    radioid = document.getElementById('DJO_Radio');
    radioidFF = document.getElementById('DJO_Radio_FF');
    setInterval("displaytime()", 1000);
    setInterval("loadjs('DJORadio/radiocheck.php', 'radiocheck')", 30000);
}

function playRadio() {
	radiostatus = "play";
    document.getElementById('DJO_Radio').controls.play();
    return false;
}

function stopRadio() {
	radiostatus = "stop";
    if (typeof DJO_Radio != 'undefined') {
    	document.getElementById('DJO_Radio').controls.stop();
    }
    if (typeof DJO_Radio_FF != 'undefined') {
        document.getElementById('DJO_Radio_FF').controls.stop();
    }
    document.getElementById('radioStatus').innerHTML = '<img src="/layout/play.jpg" alt="" /><br />Afspelen';
    return false;
}

function playRadio() {
	radiostatus = "play";
	if (typeof DJO_Radio != 'undefined') {
	    document.getElementById('DJO_Radio').controls.play();
	}
    if (typeof DJO_Radio_FF != 'undefined') {
	    document.getElementById('DJO_Radio_FF').controls.play();
    }
    document.getElementById('radioStatus').innerHTML = '<img src="/layout/stop.jpg" alt="" /><br />Stoppen';
    return false;
}

function playPauseRadio() {
	if (radiostatus == "stop") {
    	playRadio();
    }
    else {
    	stopRadio();
    }
    return false;
}

function showLoading() {
		document.getElementById("loadingMsg").style.display = "";
	loadingBuffer = loadingBuffer + 1;
	return;
}

function hideLoading() {
	loadingBuffer = loadingBuffer - 1;

	if (loadingBuffer < 1) {
		document.getElementById("loadingMsg").style.display = "none";
		loadingBuffer = 0;
	}
	return;
}

