// JavaScript Document
function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Nemáte pohlí¾eè podporující XML request!.");
 }
}

//Our XmlHttpRequest object
var receiveReq = getXmlHttpRequestObject();

//Initiate the AJAX request
function makeRequest(url,param,onReady) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   receiveReq.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq.onreadystatechange = eval(onReady); 
   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");
   
   //Make the request
   receiveReq.send(param);
    
 }
  
}

var ajax = new Array();


function getSub(identifikator,object,script,doplnek)
{	
	var category = identifikator.options[identifikator.selectedIndex].value;
	var obj = document.getElementById(object);
	obj.innerHTML = "";	// Empty city select box
	obj.innerHTML = "<option>Načítám data, prosím čekejte...</option>";
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = './ajax/'+script+'.php?select='+category+'&next='+doplnek;		// Specifying which file to get
		ajax[index].onCompletion = function(){ insertHTML(index,object) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
}
function insertHTML(index,object){
	var obj = document.getElementById(object);
	obj.blur();
	obj.innerHTML = "";
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}
function newLocation(newurl){
	window.location.href=newurl;
}
