var xmlHttp;
var xmlHttpReq;
var xmlHttpPoll;
var setRefT;

function getElementIDFix(layerId)
{
	var elem;
	if( document.getElementById ){ // this is the way the standards work
		elem = document.getElementById(layerId);
	}else if( document.all ){ // this is the way old msie versions work
		elem = document.all[layerId];
	}else if( document.layers ){ // this is the way nn4 works
		elem = document.layers[layerId];
	}
	return elem;
}


function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}


function vidStateChanged() 
{ 
	var loadstat='<br/><br/><center><img src="scripts/ajax_loading.gif" alt="Loading..." title="Loading..."><br/><b>Loading.....</b></center>';
	if (xmlHttpPoll.readyState==4 && xmlHttpPoll.status == 200){ 
		document.getElementById("flash_player").innerHTML=xmlHttpPoll.responseText;
		evalAjaxContent(xmlHttpPoll.responseText);
	} else if (xmlHttpPoll.readyState==1 || xmlHttpPoll.readyState==2 || xmlHttpPoll.readyState==3){ 
		document.getElementById("flash_player").innerHTML=loadstat;
	}
}

function evalAjaxContent(content) { 
  while(true) {
    var sindex = content.indexOf('<script type="text/javascript">');
    if(sindex < 0) break;
	content = content.substring(sindex);
    var eindex = content.indexOf("</script>");
    eval(content.substring(content.indexOf('>')+1,eindex));
    content = content.substring(eindex+9, content.length);
  }     
}



function getVid(vidID)
{
	if(setRefT){clearTimeout(setRefT);}

	xmlHttpPoll=GetXmlHttpObject();
	if (xmlHttpPoll==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 

	xmlHttpPoll.onreadystatechange=vidStateChanged;
	xmlHttpPoll.open("GET",'videos.php?op=getVid&vid='+vidID+'&sessiontimestamp=' + new Date().getTime(),true);
	xmlHttpPoll.setRequestHeader("If-Modified-Since", "Sun, 1 Jun 2008 00:00:00 GMT");
	xmlHttpPoll.setRequestHeader("Cache-Control", "no-cache"); 
	xmlHttpPoll.send(null);
} 

