// Copyright Vcast 2006 
// By Felix Li

function AJAX(me,owner)
{
	this.me = me;
	this.divOwner = owner;
	this.xmlDoc = null;
	


	this.playVideo = function(url)
	{
		if (window.ActiveXObject)
		{
			this.xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
			this.xmlDoc.onreadystatechange = function () {
				if (window[me].xmlDoc.readyState == 4) window[me].playVideoReady();
			};
 		}
		else
		{
			alert('Your browser can\'t handle this script');
			return;
		}
		this.xmlDoc.open("GET",url,true)
  		this.xmlDoc.send(null)
		//this.xmlDoc.load(url);
		
	}
	
	this.playVideoReady= function()
	{
		//var x = window[me].xmlDoc.getElementsByTagName("body");
	    //content = x[0].firstChild.nodeValue;

		if (window[me].xmlDoc.status == 200)
		{
			var temp = new Array();
			var text = window[me].xmlDoc.responseText;
			temp = text.split('|');
			if (temp[0] == "1")
			{
			    document.getElementById("MediaPlayer").URL = temp[1];
				document.getElementById("MediaPlayer").Controls.CurrentPosition = temp[3];
				document.getElementById("videoID").innerHTML = temp[2];	
			}			    
			else
			{
				alert('The time you entered does not return any video. Please validate the value.  ' + text);
			}
		    
			//document.MediaPlayer.controls.Play();
			
		}
		else
			document.getElementById(window[me].divOwner).innerHTML = 'Cant play video';
	
	}
	
	this.updateTarget = function(url)
	{
		
		if (window.ActiveXObject)
		{
			this.xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
			this.xmlDoc.onreadystatechange = function () {
				if (window[me].xmlDoc.readyState == 4) window[me].xmlready();
			};
 		}
		else
		{
			alert('Your browser can\'t handle this script');
			return;
		}
		this.xmlDoc.open("GET",url,true)
  		this.xmlDoc.send(null)
		//this.xmlDoc.load(url);
		
		
	}
	
	this.xmlready = function()
	{
		//var x = window[me].xmlDoc.getElementsByTagName("body");
	    //content = x[0].firstChild.nodeValue;

		if (window[me].xmlDoc.status == 200)
		{
			document.getElementById(window[me].divOwner).innerHTML = window[me].xmlDoc.responseText;
			
		}
		else
			document.getElementById(window[me].divOwner).innerHTML = 'Fail retreiving content';
	
	}
	
	

}


