var ajax = new Array();

function webFillGradSelect(sel, prikazi_sve_text)
{
	
	var id_selecta = sel.options[sel.selectedIndex].value;
	document.getElementById('id_grad').options.length = 0;	// Empty next select box
	var y=document.createElement('option');
	y.text = prikazi_sve_text;
	try{
    	document.getElementById('id_grad').add(y,null); // standards compliant
    }
  	catch(ex){
    	document.getElementById('id_grad').add(y); // IE only
    }
	if(id_selecta.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'fillNextSelect.php?table=id_grad&id='+id_selecta;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createSelect(index, 'id_grad') };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function webFillLokacijaSelect(sel, prikazi_sve_text)
{
	var id_selecta = sel.options[sel.selectedIndex].value;
	document.getElementById('id_lokacija').options.length = 0;	// Empty next select box
	var y=document.createElement('option');
	y.text = prikazi_sve_text;
	try{
    	document.getElementById('id_lokacija').add(y,null); // standards compliant
    }
  	catch(ex){
    	document.getElementById('id_lokacija').add(y); // IE only
    }
	if(id_selecta.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'fillNextSelect.php?table=id_lokacija&id='+id_selecta;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createSelect(index, 'id_lokacija') };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createSelect(index, nextSelect)
{
	var obj = document.getElementById(nextSelect);
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}
