var ajax={
    query   : new Array(),
    http    : null,
    running : 1,  
    init    : function(){

              this.http = ( window.XMLHttpRequest ) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");               
              
              },             
    load    : function(url,onComplete){
               onComplete = onComplete?onComplete:function(){};
               ajax.query.push([url,onComplete]);
               if (ajax.running == 1){
                   ajax.next();
                 }
                 
              },
     next    : function(){
                ajax.running=2;	  
                if (ajax.query.length>0){
				
                ajax.http.open("get",ajax.query[0][0],true);
 
				ajax.http.onreadystatechange=function()
				  {
					  if(ajax.http.readyState==4)
					    {
                         ajax.query[0][1](ajax.http.responseText);
                         ajax.query=ajax.query.slice(1);
						 ajax.next();
						};
				  }
				 ajax.http.send(null); 
 
                }                            
                ajax.running=1; 
             }

                  
   }
   
ajax.init();



function refresh(txt){
  var tempArray=txt.split(",");
  var obj=document.getElementById(target); 

  obj.options.length = 0;
  var x=0;
  for(var i=0;i<tempArray.length;i+=2){
   
   obj.options[x++] = new Option(tempArray[i],tempArray[i+1],false,selectat[target]==tempArray[i+1]);
  }
	if ((target=="localitate")&&(document.getElementById("zona"))) 
	  {
	  obj=document.getElementById("zona"); 
      obj.options.length = 0;	  
	  obj.options[0]=new Option("alege localitatea intai","0");
	  }
  selectat[target]=0;	  
  working=0;
}

var working=0;
var target="";
function loadit(url,target_)
 {  
  if (!working) 
    {
	working=1;	
	target=target_;
	var temp=Math.round(Math.random()*999999);
	ajax.load(url+"&random="+temp,refresh);
	}
  else setTimeout("loadit('"+url+"','"+target_+"')",10)
 }

var selectat={judet:0,
			   localitate:0,
			   zona:0	
				}

function LoadFunction(judet_,localitate_,zona_)
  {
	   selectat["judet"]=judet_;
	   selectat["localitate"]=localitate_;
	   selectat["zona"]=zona_;
	   if (document.getElementById("localitate")) {loadit('included/show.php?jud='+judet_,'localitate');}
	   if (document.getElementById("zona")) {loadit("included/show.php?loc="+localitate_,"zona");}
  }


