function Ajax(name)
{
	var http_request = null;
	var nazwa = name;
	var time=null;
	var responeText='';
	var URL=null;
	var parameters=null;
	var type=0;
	
	function cancel()
	{
		http_request=null;
	}
	
	
	function makeRequest(url, params, newType)
	{
		type=newType;
		if(!type) { document.getElementById('glosujText').innerHTML='Wysyłanie...'; }
		else if(type==1) { document.getElementById('komentarzText').innerHTML='<p style="text-align:center;font-weight:bold;margin:0;padding:30px 0;">Wysyłanie...</p>'; }
		else if(type==2) { document.getElementById('komentarzLoading').innerHTML='<p style="text-align:center;font-weight:bold;margin:0;padding:30px 0;">Ładowanie...</p>'; }
		
		URL = url;
		parameters = params;
		http_request = false;		
		
		if (window.XMLHttpRequest) { 
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/plain');
			}
		}
		else if (window.ActiveXObject) {
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}

		if (!http_request) {
			return false;
		}
	//	http_request.setRequestHeader("Cache-Control", "no-cache");
  //  http_request.setRequestHeader("Pragma", "no-cache");
			http_request.onreadystatechange = function() { change(http_request); };
		
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		http_request.send(params);
	}
	this.makeRequest = makeRequest;
	
	function change(http)
	{
		if (http.readyState == 4) {
			if (http.status == 200)
			{
				responeText = http.responseText;
				if(!type) { document.getElementById('glosujText').innerHTML='Głos dodany'; }
				else if(type==1)
				{
					data=responeText.split('###KOMENTARZE###');
					document.getElementById('komentarzText').innerHTML=data[0];
					document.getElementById('komentarzLoading').innerHTML=data[1];
				}
				else if(type==2)
				{
					data=responeText.split('###KOMENTARZE###');
					document.getElementById('komentarzLoading').innerHTML=data[1];
				}
				
				cancel();
				proba=0;
			}
			else {
				responeText='';
				cancel();
				proba=0;
			}
		}
	}
	
	function reset()
	{
		responeText='';
		cancel();
	}
	this.reset = reset;

}

var Url = {

	encode : function (string)
	{
		text = escape(this._utf8_encode(string));
		text = text.replace(/\+/g,"%2B");
		return text;
	},

	decode : function (string)
	{
		return this._utf8_decode(unescape(string));
	},

	_utf8_encode : function (string)
	{
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++)
		{
			var c = string.charCodeAt(n);
			if (c < 128)
			{
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048))
			{
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else
			{
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}

		return utftext;
	},

	_utf8_decode : function (utftext)
	{
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		
		while ( i < utftext.length )
		{
			
			c = utftext.charCodeAt(i);
			if (c < 128)
			{
				string += String.fromCharCode(c);
				i++;
			}
				else if((c > 191) && (c < 224))
				{
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else
			{
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}

	return string;
	}

}

ajax = new Ajax('ajax');