function setAndExecute(divId, innerHTML)
{
   var div = document.getElementById(divId);
   div.innerHTML = '<!-- improvizacija za script execute --><div style="display: none; ">dopolnilo</div>'+innerHTML;
   var x = div.getElementsByTagName("script"); 
   for(var i=0;i<x.length;i++)
   {
       eval(x[i].text);
   }
}

function createRequestObject(){

	var req;
	
	if(window.XMLHttpRequest) {
		//For Firefox, Safari, Opera
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject){
		//For IE 5+
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		//Error for an old browser
		alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera'); 
	}
	
	return req;
	
}

//Make the XMLHttpRequest Object
var http=new Array()

function ustvariObject() {
	var i;
	
	i = http.length;
	
	http[i] = createRequestObject();
	
	return i;
}


function ajax(method, url, divID, pomoznoOknoNaslov, pomoznoOknoSirina, form) {
	
	var params = "";
	var i;
	
	i = ustvariObject();
	
	
	if(url == '') {
		url = location.href + "&ajax=1";
	}

	http[i].divID = divID;
	http[i].pomoznoOknoNaslov = pomoznoOknoNaslov;
	http[i].pomoznoOknoSirina = pomoznoOknoSirina;

	if(method == 'get' || method == 'GET' || method == 'post' || method == 'POST') {

		http[i].open(method,url,true);
		if(method == 'POST' || method == 'post') {

			params = miniajax.serialize(form);
			http[i].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http[i].setRequestHeader("Content-length", params.length);
			http[i].setRequestHeader("Connection", "close");
			
		} else {
			params = null;
		}

		http[i].onreadystatechange = handleResponse;
		http[i].send(params);
		if(document.getElementById('ajaxLoading')) {
			document.getElementById('ajaxLoading').style.display = 'block';
		}
	}
}




function handleResponse(){
	
	if(this.readyState == 4 && this.status == 200){
		var response = this.responseText;
		if(response){
			if(typeof(this.divID) != "undefined") {
				
				setAndExecute(this.divID, response);
				
				if(this.divID == 'pomoznoOkno') {
					if(typeof(this.pomoznoOknoNaslov) != "undefined") { 
						document.getElementById('awtlTitle').innerHTML = this.pomoznoOknoNaslov; 
					}
					if(typeof(this.pomoznoOknoSirina) != "undefined") { 
						getEleChil(document.getElementById("admWinLogin"))[2].style.width = this.pomoznoOknoSirina+'px';
					} else {
						getEleChil(document.getElementById("admWinLogin"))[2].style.width = '800px';
					}
					document.getElementById('admWinLogin').style.visibility = 'visible';
				}
				
				if(this.divID == 'pomoznoOkno' || this.divID == 'uporabnikInfo' || this.divID == 'uporabnikInfoZgodovina') {
					setTimeout("controlAdminObjects();", 100);
				}
				if(document.getElementById('ajaxLoading')) {
					document.getElementById('ajaxLoading').style.display = 'none';
				}
			}
		}
	}
}





function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};

miniajax={};
miniajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
miniajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
miniajax.send=function(u,f,m,a){var x=miniajax.x();x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)};
miniajax.get=function(url,func){miniajax.send(url,func,'GET')};
miniajax.gets=function(url){var x=miniajax.x();x.open('GET',url,false);x.send(null);return x.responseText};
miniajax.post=function(url,func,args){miniajax.send(url,func,'POST',args)};
miniajax.update=function(url,elm){var e=$(elm);var f=function(r){e.innerHTML=r};miniajax.get(url,f)};
miniajax.submit=function(url,elm,frm){var e=$(elm);var f=function(r){e.innerHTML=r};miniajax.post(url,f,miniajax.serialize(frm))};



