/*
 * StreamMonitor - Tuning hours monitor
 *
 * Copyright (c) 2006 Fabrizio Fiandanese (creativepattern.com)
 *
 * $Date: 2009/10/07 14:22:42 $
 * $Rev: 110 $
 */

/**
 * Create a new StreamMonitor Object
 * @constructor
 */

function StreamMonitor(sUTSLocation)
{
	//Properties
	this.sUTSLocation=sUTSLocation;
	this.tuneSecs=0;
	this.isRunning=0;
	this.timerID;
		
	//Init
	this.init();
}

/**
* Inits StreamMonitor Object
* @method
*/
StreamMonitor.prototype.init = function()
{
	this.startTimer();

}

StreamMonitor.prototype.stopTimer = function()
{
	if(this.isRunning)
		clearTimeout(this.timerID);
		
	this.isRunning=false;
}
 
StreamMonitor.prototype.startTimer = function()
{
	
	this.isRunning=true;

	var self = this;
	this.timerID = setTimeout(function(){self.startTimer();}, 1000);

	this.tuneSecs++;
}

StreamMonitor.prototype.getTime = function()
{
	return this.tuneSecs;
}

function getFile(url) {
  if (window.XMLHttpRequest) {              
    AJAX=new XMLHttpRequest();              
  } else {                                  
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
     AJAX.open("GET", url, false);                             
     AJAX.send(null);
     return AJAX.responseText;                                         
  } else {
     return false;
  }                                             
}

StreamMonitor.prototype.sendTime = function()
{
	var tm = this.getTime();
	var endpoint = this.sUTSLocation + tm + "/add";

	if (tm>0)
	{
		getFile(endpoint); 
         	}  	

}


