var xmlhttp;

function GetXmlHttpObject()
{
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject) {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}

function SimpleAjaxTask(url)
{
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

//  InnerHtmlAjaxTask
function InnerHtmlAjaxTask(html_id, url)
{
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; }
  
  xmlhttp.onreadystatechange= function(){InnerHtmlCallback(html_id);};
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}
function InnerHtmlCallback(html_id)
{
  if (xmlhttp.readyState==4) {
  
    var newdiv = document.createElement("div");
    newdiv.innerHTML = xmlhttp.responseText;
    var container = document.getElementById(html_id);
    if ( container.hasChildNodes() ) {
      while ( container.childNodes.length >= 1 )
      {
        container.removeChild( container.firstChild );       
      } 
    }   
    container.appendChild(newdiv);
  }
}

// Ajax Tasks
function ShowGroup(id) {  
  var url="/ajax_xmloperation.php";        
  url=url+"?id="+id+"&op=show_group";
  var value,xx,x,i;  
  var list = document.getElementById("group_list");
  list.innerHTML = value = '';
  
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {                             
      x=xmlhttp.responseXML.documentElement.getElementsByTagName("car");

      for (i=0;i<x.length;i++) {
        xx=x[i].getElementsByTagName("name");
        {
          try { value += xx[0].firstChild.nodeValue + '<br />'; }
          catch (er) { value += ''; }
        }
        
      }
      value = value.slice(0,value.length-2);
      list.innerHTML = value; 
    }
  }
  xmlhttp.open("GET",url,true);
  xmlhttp.send();
}

function PickCar(id) {  
  var url="/ajax_operation.php";
  url=url+"?id="+id+"&op=pick_car";  

  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("suspend").disabled=false;                 
      document.forms["rent_form"].submit();  
    }
  }

  xmlhttp.open("GET",url,true);
  xmlhttp.send();
}

function ulubione_script() {

    var tytul = '99 RENT';
    var adres = 'http://99rent.pl';

    //FireFox
    if (window.sidebar) { 

        window.sidebar.addPanel(tytul, adres, ""); 

    //IE
    } else if (window.external) {

        window.external.AddFavorite(adres, tytul); 

    //Opera
    } else if (window.opera && window.print) {

        var a = document.createElement('a');
        a.setAttribute('href', adres);
        a.setAttribute('title', tytul);
        a.setAttribute('rel','sidebar');
        a.click();
    }
}

function ulubione_link() { 
  if (window.external || window.sidebar || 
     (window.opera  && window.print) )
  {
    document.writeln('<a href="javascript:ulubione_script();" class="link_top" title="Dodaj do ulubionych"></a>');
  }
}
