// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 
var lastname = "456";

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// -------------------------------- Loading presenter showreels --------------------------------------

// make asynchronous HTTP request using the XMLHttpRequest object 
function menuprocess(talent_group, selectedval){
	//alert('menuprocess: '+talent_group);
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
	
	if(!talent_group){
		var selectBox = document.forms['search'].talent_group;
		var talent_group = selectBox.options[selectBox.selectedIndex].value;
		if(!talent_group){talent_group = 'any';}
	}
	url = "ajax/processor.php?talent_group=" + encodeURIComponent(talent_group);
	if(selectedval){
		url = url + '&selected='+encodeURIComponent(selectedval)
	}
	try{xmlHttp.open("GET", url, true);}catch(err){alert('xmlHttp.open() failed: '+err);}
	//alert(url);
	xmlHttp.onreadystatechange = handleServerResponseMenu;
    xmlHttp.send(null);
  }else{ 
    setTimeout('menuprocess()', 1000);
  }
}

// executed automatically when a message is received from the server
function handleServerResponseMenu() {

  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
		
      xmlResponse = xmlHttp.responseXML;
      xmlDocumentElement = xmlResponse.documentElement;
	  myhtmlcode = xmlDocumentElement.getElementsByTagName("htmlcode").item(0).firstChild.data;
      document.getElementById("professionlist").innerHTML = myhtmlcode;
    } else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}


// make asynchronous HTTP request using the XMLHttpRequest object 
function loadaudio(soundfile){
	//alert('menuprocess: '+talent_group);
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
	
	url = "ajax/processor.php?soundfile=" + encodeURIComponent(soundfile);

	try{xmlHttp.open("GET", url, true);}catch(err){alert('xmlHttp.open() failed: '+err);}
	//alert(url);
	xmlHttp.onreadystatechange = updateaudio;
    xmlHttp.send(null);
  }else{ 
    setTimeout('loadaudio(soundfile)', 1000);
  }
}

// executed automatically when a message is received from the server
function updateaudio() {

  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
		
      xmlResponse = xmlHttp.responseXML;
      xmlDocumentElement = xmlResponse.documentElement;
	  myhtmlcode = xmlDocumentElement.getElementsByTagName("htmlcode").item(0).firstChild.data;
      document.getElementById("audioplayer").innerHTML = myhtmlcode;
	  document.getElementById("showreelbutton").innerHTML = '<img src="images/b_showreel_off.gif" alt="" name="showreel" width="104" height="29" border="0" id="showreel" />';
	  
    } else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}