// JavaScript Document
function getAjaxRequest() {
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
 
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

var ajaxRequest = getAjaxRequest();
var musical_list_file = "http://www.musical.nl/plugins/musical/musicals_list.inc.php";
function showPlayingMusicals() {
	ajaxRequest = getAjaxRequest();

	var ajaxDisplay = document.getElementById('musicals_list');	

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			try {
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			} catch (e)  {alert(e.toString())}
		}			
	}

	var params = "";
	ajaxRequest.open("POST", musical_list_file+'?act=musical_list_ajax_now_playing', true);
	ajaxDisplay.innerHTML = "<div style=\"text-align:center\"><img src=\"plugins/musical/images/loading.gif\" alt=\"Loading ...\" /></div>";
	ajaxRequest.send(null); 
}

function showToComeMusicals() {
		ajaxRequest = getAjaxRequest();

	var ajaxDisplay = document.getElementById('musicals_list');	

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			try {
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			} catch (e)  {alert(e.toString())}
		}			
	}

	var params = "";
	ajaxRequest.open("POST", musical_list_file+'?type=tocome', true);
	ajaxDisplay.innerHTML = "<div style=\"text-align:center\"><img src=\"plugins/musical/images/loading.gif\" alt=\"Loading ...\" /></div>";
	ajaxRequest.send(null); 

}

function searchMusical(sVal) {
	ajaxRequest = getAjaxRequest();

	var ajaxDisplay = document.getElementById('musicals_list');	

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			try {
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			} catch (e)  {alert(e.toString())}
		}			
	}

	var params = "";
	//ajaxRequest.setRequestHeader("Cache-Control", "no-cache");
	//ajaxRequest.setRequestHeader("Cookie", "");
	ajaxRequest.open("GET", musical_list_file+'?type=search&'+'sphrase='+sVal, true);
	ajaxRequest.send(null);
	ajaxDisplay.innerHTML = "<div style=\"text-align:center\"><img src=\"plugins/musical/images/loading.gif\" alt=\"Loading ...\" /></div>";
}

function showOld() {
	ajaxRequest = getAjaxRequest();

	var ajaxDisplay = document.getElementById('musicals_list');	

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			try {
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			} catch (e)  {alert(e.toString())}
		}			
	}

	var params = "";
	ajaxRequest.open("GET", musical_list_file+'?type=archive', true);
	ajaxRequest.send(params);
	ajaxDisplay.innerHTML = "<div style=\"text-align:center\"><img src=\"plugins/musical/images/loading.gif\" alt=\"Loading ...\" /></div>";
	
}

function musicalDetails(musicalID) {
	ajaxRequest = getAjaxRequest();
	//document.title = 'Changed to other musical';
	var ajaxDisplay = document.getElementById('mainwindow');	

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			try {
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			} catch (e)  {alert(e.toString())}
		}			
	}

	var params = "";
	ajaxRequest.open("GET", 'plugins/musical/musical_detail.inc.php?id='+musicalID, true);
	ajaxRequest.send(params);
	ajaxDisplay.innerHTML = "<div style=\"text-align:center\">Loading ... </div>";
	
}

function resetRandomImage() {
	$img = document.getElementById('randImage').innerHTML;
}

function unsubscribeMe(email,name) {
try {
	ajaxRequest = getAjaxRequest();
	//document.title = 'Changed to other musical';
	var ajaxDisplay = document.getElementById('sign_me_out');	

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			try {
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			} catch (e)  {alert(e.toString())}
		}			
	}

	var params = "email=" + email + "&naam=" + name;
	ajaxRequest.open("POST", 'plugins/mailing/mailing_signout.php', true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(params);
	ajaxDisplay.innerHTML = "<div style=\"text-align:center\">Loading ... </div>";
} catch (e)  {alert(e.toString())}
}

function rssLoad() {
	try {
		ajaxRequest = getAjaxRequest();
		//document.title = 'Changed to other musical';
		var ajaxDisplay = document.getElementById('googleNews');	
	
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function() {
			if(ajaxRequest.readyState == 4) {
				try {
					ajaxDisplay.innerHTML = ajaxRequest.responseText;
				} catch (e)  {alert(e.toString())}
			}			
		}
	
		var params = null;
		ajaxRequest.open("GET", 'http://www.musical.nl/plugins/musical/rssnews.php', true);
		ajaxRequest.send(params);
	} catch (e)  {alert(e.toString())}
}
