// JavaScript Document

//<![CDATA[
var http_request=false;
var gselkrajnr;
function getkrajName(selnr) {
	gselkrajnr=selnr
	frm=document.forms[0]
	
	
	
	load_getkrajName("/ssi/getkrajName.asp?data=get",selnr);
	//document.write(query);
}



//var http_request = false;
   function load_getkrajName(url,selnr) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = StateChangekrajname;
      http_request.open('GET', url, true);
	  
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //  http_request.setRequestHeader("Content-length", 4);
      http_request.setRequestHeader("Connection", "close");
	  http_request.send(null);

   }



function StateChangekrajname() {
		//alert(http_request.readyState);
	/*if (http_request.readyState == 1)
     {
           alert ('Ładowanie');
     } else if(http_request.readyState == 2)
     {
           alert ('Załadowano');
     }
      else if(http_request.readyState == 3)
     {
           alert ('Odebrano');
     } else if(http_request.readyState == 4)
     {
           alert ('Otworzono');
     }*/
	if(http_request.readyState == 1)
		{
	 		//document.getElementById('loader-icon').style.display= "block";
			//document.getElementById('hurtoponpowiatid').value= "";	
			//document.getElementById('link1Box').innerHTML="";
			//document.getElementById('link2Box').innerHTML="";
		}		
  		
	if (http_request.readyState == 4) { // Complete
			//document.getElementById('loader-icon').style.display= "none";
	
	if (http_request.status == 200) { // OK response
		
		// instrukcje...
		http_content = http_request.responseText;	
		
		// budowanie pola select
		results = http_content.split(",");
		
		theSelect = document.getElementById("hurtoponkrajid"+gselkrajnr);
		//theSelect.name="miasto"
		//theSelect.id="miasto"
		//theSelect.setAttribute = ("name","select1")
		//theSelect.setAttribute = ("id","select1")
		while (theSelect.firstChild) {
		     theSelect.removeChild(theSelect.firstChild);
		}
		
		theOption=document.createElement("option");
		theText=document.createTextNode("(wybierz z listy)");
		theOption.value="";
		theOption.appendChild(theText);
		theSelect.appendChild(theOption);
		theSelect.style.width="200px";
		
		for ( i = 0; i < results.length-1; i++ ) {
		theOption=document.createElement("option");
		aresposp=results[i].split('|');
		tkp=aresposp[1];
		vlp=aresposp[0];
		theText=document.createTextNode(tkp);
		theOption.appendChild(theText);
		
		theOption.setAttribute("value",vlp);
		theSelect.appendChild(theOption);
		}	
		
		
		
		} 
		
		else {
		// obsługa błędów
		http_content = http_request.statusText;
		//document.getElementById("urlContent").innerHTML = http_content;
       	}
    }
  }
 //]]>