// JavaScript Document

var xmlHttp = createXmlHttpRequestObject(); 
var DHTML = document.getElementById;
var detalhePage = "";
var divId = ""
var divId2 = ""
var browser = "IE"
if(-1 != navigator.userAgent.indexOf("MSIE"))
	browser = "IE"
else 
	browser = "OT"

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;
}


// MENU
function openMenuVideo(bnt,video)
{
  // proceed only if the xmlHttp object isn't busy
  videoTemp = video;
  bntTemp = bnt;
  
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
  		// execute the .php page from the server
		url = "?video=" + video + "&bntPlay=" + bnt;
		page = "templates/menuDireita.php"+url
		divId = 'list_item';
		
		xmlHttp.open("GET", page , true);  
		// define the method to handle server responses		
		xmlHttp.onreadystatechange = handleServerResponse;		 
		// make the server request
		xmlHttp.send(null);
  }
  else
    setTimeout('openMenuVideo(videoTemp,bntTemp)', 1000);     // if the connection is busy, try again after one second   
}

function videoPlay(bnt,valorPesquisar)
{
  // proceed only if the xmlHttp object isn't busy
  valorPesquisarTemp = valorPesquisar;
  bntTemp = bnt;
 
  if(bnt == 1){document.getElementById("menuControl").style.display = 'none';}
  else {document.getElementById("menuControl").style.display = 'block';}
  
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
  		// execute the .php page from the server
		url = "?videoValue=" + valorPesquisar + "&tipoBrowser=" + browser;
		page = "templates/videoPlay.php"+url;
		divId2 = 'video';
				
		xmlHttp.open("GET", page , true);  
		// define the method to handle server responses		
		xmlHttp.onreadystatechange = handleServerResponsePlay;		 
		// make the server request
		xmlHttp.send(null);
  }
  else
    setTimeout('videoPlay(bntTemp,valorPesquisarTemp)', 1000);     // if the connection is busy, try again after one second   
}


function handleServerResponse() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState==1)
  {
	document.getElementById(divId).innerHTML="Carregando Dados..."				
  }
   
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      xmlResponse = xmlHttp.responseText;
  	  document.getElementById(divId).innerHTML = xmlResponse;
	} 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function handleServerResponsePlay() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState==1)
  {
	document.getElementById(divId2).innerHTML="Loading Video..."				
  }
   
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      xmlResponse = xmlHttp.responseText;
  	  document.getElementById(divId2).innerHTML = xmlResponse;
	} 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function titulo_Menu(titulo)
{
    document.getElementById('list_top_txt').innerHTML = titulo;
}

function titulo_video(titulo)
{
    document.getElementById('vid_txt').innerHTML = titulo;
}
