//xmlHttp


 
function uploadyoutube(exerciseid,title,desc,filename,tag1,tag2,tag3,tag4)
{
if (filename.length==0)
 { 
 document.getElementById("youtubestatus").
 innerHTML="";
 document.getElementById("youtubestatus").
 style.border="0px";
 return
 }  
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  }
document.getElementById("prog_youtubeupload").style.visibility="visible";  
var url="youtube_upload.php"
url=url+"?exerciseid="+exerciseid+"&title="+title+"&description="+desc+"&filename="+filename+"&tag1="+tag1+"&tag2="+tag2+"&tag3="+tag3+"&tag4="+tag4
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("youtubestatus").
 innerHTML=xmlHttp.responseText;
 document.getElementById("youtubestatus").
 style.display="block";  
 document.getElementById("youtubestatus").
 style.border="0px solid #000000";
 document.getElementById("prog_youtubeupload").style.visibility="hidden";
 } 
}



function checkyoutube(uploadedvidid, showdefaultmsg)
{
if (uploadedvidid.length==0)
 { 
 document.getElementById("youtubestatus").
 innerHTML="";
 document.getElementById("youtubestatus").
 style.border="0px";
 return
 }  
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  }
document.getElementById("youtubestatus").innerHTML="";  
document.getElementById("prog_youtubecheck").style.visibility="visible";   
var url="youtube_chkstatus.php"
url=url+"?uploadedvidid="+uploadedvidid+"&showdefaultmsg"+showdefaultmsg
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=checkstateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function checkstateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("youtubestatus").
 innerHTML=xmlHttp.responseText;
 document.getElementById("youtubestatus").
 style.display="block";  
 document.getElementById("youtubestatus").
 style.border="0px solid #000000";
 document.getElementById("prog_youtubecheck").style.visibility="hidden";
 } 
}



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;
}




/**
 * Functions to display a youtube video
 */

function sendRequest(filePath, params) {
  if (window.XMLHttpRequest) {
    var xmlhr = new XMLHttpRequest();
  } else {
    var xmlhr = new ActiveXObject('MSXML2.XMLHTTP.3.0');
  }
        
  xmlhr.open('POST', filePath, true);
  xmlhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 

  xmlhr.onreadystatechange = function() {
    var resultDiv = document.getElementById("videoPlayer");
    if (resultDiv == null) return;
    if (xmlhr == null) return;
    if (xmlhr.readyState == 1) {
      resultDiv.innerHTML = '<b>Loading...</b>'; 
    } else if (xmlhr.readyState == 4 && xmlhr.status == 200) {
      if (xmlhr.responseText) {
        resultDiv.innerHTML = xmlhr.responseText;
      }
    } else if (xmlhr.readyState == 4) {
      //alert('Invalid response received - Status: ' + xmlhr.status);
    }
  }
  xmlhr.send(params);
}


function presentVideo(videoId) {
  var params = 'queryType=show_video&videoId=' + videoId;
  var filePath = 'youtube_playmovie.php';
  if (videoId!="") {
  sendRequest(filePath, params);
  }
}

