/**
 * Initialisiert ein neues AjaxBase-Objekt
 * @return
 */
function AjaxCaller()
{
	///////////////////////////////////////////////////////////////////////////
	// Fields
	
	this._request;
	var _callbackFunction;
	this._url;
	this._urlParams;

	
	///////////////////////////////////////////////////////////////////////////
	//Public Methods
	
	/**
	 * Asynchroner Aufruf der Provider-Seite
	 */
	this.callAsync = function(url, urlParams, callbackFunction) 
	{	
		//fields
		this._url = url;
		this._urlParams = urlParams;
		_callbackFunction = callbackFunction;
		
		//create request object
		if(this._request == null)
	    {
			this._createXmlRequestObj();
	    }
		
		//set state change function
		this._request.onreadystatechange = this._onStateChange;
		
		//call
		this._call(url, urlParams);
	};
	
	
	///////////////////////////////////////////////////////////////////////////
	// Private Methods
	
	/**
	 * Erzeugt ein neues Request-Objekt und gibt es zurück.
	 * @return XMLHttpRequest-Objekt
	 */
	this._createXmlRequestObj = function()
	{
		
	    try
	    {	// mozilla
	    	this._request = new XMLHttpRequest();
	    }
	    catch (e)
	    {
	    	try
	    	{	// ie 5
	    		this._request = new ActiveXObject("Msxml2.XMLHTTP");
	        } 
	        catch (e)
	        {
	        	try
	        	{	// ie > 5
	        		this._request = new ActiveXObject("Microsoft.XMLHTTP");
	            } 
	            catch (e)
	            {
	            	this._request = null;
	            }
	        }  
	    }
	};
	
	/**
	 * Wird aufgerufen bei einem statechange
	 * @param callBackFunction callback Function
	 */
	this._onStateChange = function()
	{       
	    if(this.readyState == 4)
	    {
	    	if(this.status == 200) 
	       	{    
	    		_callbackFunction(this.responseText);
	     	}      
	    }
	};

	/**
	 * Führt die Kommunikation mit dem Server durch
	 */
	this._call = function()
	{
		this._request.open("GET", this._url + this._urlParams, true);
		this._request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this._request.send(null);
	};
}


function requestRemainingTime()
{   
	var caller = new AjaxCaller();
	caller.callAsync("shared/time_service.php", "", writeRemaingTime);	
}  

function writeRemaingTime(response)
{
	document.getElementById("countdown").innerHTML = response;
}

