function SNSAjax()
{
	this.xmlhttp         = null;
	this.loading_message = null;

	this.xml_init = function()
	{
		try
		{
			this.xmlhttp = new XMLHttpRequest();
			return true;
		}
		catch(e)
		{
			try
			{
				this.xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
				return true;
			}
			catch(e)
			{
				return false;
			}
		}
	};

	this.process = function( url, type, post )
	{		
		type = type == "POST" ? "POST" : "GET";
		

		if( type == 'GET' )
		{
			url = url + ( url.indexOf('?') > -1 ? '&' : '?' ) + 'ajax=1';
		}
		else
		{
			if( typeof post != 'object' )
			{
				post = {};
			}
			
			post.ajax = 1;
		}		

		if( ! this.xmlhttp )
		{
			this.xml_init();
		}

		if( ! this.readystate_not_ready() )
		{
			this.xmlhttp.open( type, url, true );

			if( type == "GET" )
			{
				this.xmlhttp.send(null);
			}
			else
			{
				if( typeof(this.xmlhttp.setRequestHeader) != "undefined" )
				{
					this.xmlhttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
				}
				
				this.xmlhttp.send(this.format_for_post(post));
			}

			if( this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200 )
			{
				return true;
			}
		}

		return false;
	};

	this.format_for_post = function(arrayfields)
	{		
		var str = '';

		try
		{
			for( var x in arrayfields )
			{
				str += x + '=' + this.encodeurl(arrayfields[x]) + '&';
			}
		}
		catch(e) {}

		return str;
	};

	this.encodeurl = function(url)
	{
		url = (url + '').toString();

		var regcheck = url.match(/[\x90-\xFF]/g);

		if(regcheck)
		{
			for( var i = 0; i < i.length; i ++ )
			{
				url = url.replace( regcheck[i], '%u00' + ( regcheck[i].charCodeAt(0) & 0xFF ).toString(16).toUpperCase() );
			}
		}

		return escape(url).replace( /\+/g, "%2B" );
	};

	this.readystate_not_ready = function()
	{
		return ( this.xmlhttp.readyState && ( this.xmlhttp.readyState < 4 ) );
	};

	this.readystate_ready_and_ok = function()
	{
		return ( this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200 ) ? true : false;
	};

	this.onreadystatechange = function(event)
	{
		if( ! this.xmlhttp )
		{
			this.xml_init();
		}

		if( typeof(event) == 'function' )
		{
			this.xmlhttp.onreadystatechange = event;
		}
	};

	this.show_loading = function(skipDisable)
	{
		sns.displayLoadingForm(this.loading_message, skipDisable );
	};

	this.hide_loading = function(skipAvailable)
	{
		sns.hideLoadingForm(skipAvailable);
	};
}
