// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 

function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
 
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
} 

function must_login_items()
{
	fav_link = document.getElementById("favorit_link");
	fav_link.innerHTML="You have to login to do this! ";
}

function must_login_users()
{
	fav_auth = document.getElementById("favorit_auth");
	fav_auth.innerHTML="You have to login to do this! ";
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function add_to_favorite(item_id)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    var now = new Date();
    xmlHttp.open("GET", "../index.php?module=favorit_item&item_id="+item_id+"&time="+now );  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = added_to_favorite;
    // make the server request
    xmlHttp.send(null);
  }
  else
  {
     // if the connection is busy, try again after one second  
     alert('The server is busy. Try again');
  }
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function add_to_fav_auth(item_id)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    var now = new Date();
    xmlHttp.open("GET", "../index.php?module=users&user_id="+item_id+"&status=ok&time="+now );  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = added_to_fav_auth;
    // make the server request
    xmlHttp.send(null);
  }
  else
  {
     // if the connection is busy, try again after one second  
     alert('The server is busy. Try again');
  }
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function voting(item_id,vot)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    var now = new Date();
    xmlHttp.open("GET", "../voting.php?item_id="+item_id+"&vot="+vot+"&time="+now );  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = voting_responce;
    // make the server request
    xmlHttp.send(null);
  }
  else
  {
     // if the connection is busy, try again after one second  
     setTimeout("voting('"+item_id+"','"+vot+"');",1000);
  }
}

