if(this.val == undefined)
	this.val=1;

function vote(item,rate)
{
	var number=/^[0-9]+$/;
	if(item>0 && rate<=5 && rate>=1 && this.val==1)
	{
		var url="vote.php";
		var form_to_send="item="+item+"&rate="+rate;
	   xmlHttp=connect_to_ajax(return_value);
	   xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
	   xmlHttp.send(form_to_send);	
		this.val=0;
	}
	else
	{
		document.getElementById("show_info").innerHTML='Oddawałeś już przed chwilą głos na tą pozycję';
	}
}

function connect_to_ajax(handler)
{
  xmlHttp=false;
  if (window.XMLHttpRequest) //Mozilla, Opera
  {
      xmlHttp=new XMLHttpRequest();
      if(xmlHttp.overrideMimeType)
      {
          xmlHttp.overrideMimeType('text/xml');
      }
  }
  else if (window.ActiveXObject) //MS IE
  {
      try
      {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
        try
        {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
        
        }
      }
  }
  if(!xmlHttp)
  {
      alert('Nie można wywołać obiektu XMLHttpObject')
      return false;
  }
  xmlHttp.onreadystatechange=handler;
  return xmlHttp;
}
    
function check_response()
{
 if (xmlHttp.readyState == 4)
  {
      if (xmlHttp.status == 200)
      {
          return true;
      }
      else
      {
      	 alert("Wystąpił problem z wywołaniem AJAX:\n"+xmlHttp.statusText);
          return false;
      }
  }	    
}    

function return_value()
{
 if(check_response())
 {
  	document.getElementById("show_info").innerHTML="Dziękujemy za oddanie głosu. Będzie on uwzględniony przy następnym odświeżeniu strony";
 }
}