/**---------------------------------------------------------------------------------------------------
 *
 * File:		advert.js
 * Date:		25.07.2007
 * Description:	Dynamic Adverts
 *
 * Usage:
 *
 *--------------------------------------------------------------------------------------------------*/


/**---------------------------------------------------------------------------------------------------
 *
 * Network wrapper
 *
 */
function send( recv, obj, url, data, flag )
{
	net = new Network( recv, obj, flag );
	
	net.send( url, data );
}


/**---------------------------------------------------------------------------------------------------
 *
 *
 */
function Network( recv, obj, flag )
{
	this.obj			= obj;
	this.synchronous	= ! flag;
	this.xmlHttpReq		= window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject( "Microsoft.XMLHTTP" );
	
	
	/**
	 * Sends a string of data to a URL
	 *
	 * @param string url	URL to send data to
	 * @param string data	data to send
	 */
	this.send = function( url, data )
	{
		var	self = this;
		
		try
		{
			self.xmlHttpReq.open( "POST", url, self.synchronous );
			self.xmlHttpReq.setRequestHeader(	"Content-Type",
												"application/x-www-form-urlencoded" );
			self.xmlHttpReq.onreadystatechange = function()
			{
				if ( self.xmlHttpReq.readyState == 4 && self.recv )
					self.recv( self.xmlHttpReq.responseText, self.obj );
			}
	
			this.xmlHttpReq.send( data );
		}
		catch( e )
		{
			alert( "Cannot access remote domain." );
		}
	}

	this.recv = recv;
}


/*--------------------------------------------------------------------------------------------------*/
