function ajaxObj() {
	try {
		return new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e){
		try{
			return new ActiveXObject('Microsoft.XMLHTTP');
		} catch(e) {
			return new XMLHttpRequest();
		}
	}
};

function ajaxGet(url,funct) {
	var aObj = ajaxObj();
	aObj.open('GET',url,true);
	aObj.onreadystatechange = function(){
		if(aObj.readyState == 4) {
			funct(aObj.responseText);
		}
	};
	aObj.send(null);
};

var stDatotek = 1;
var fileID = 1;

var moznostiHTML;

function dodaj(el) {
	
	prostor = document.getElementById("datoteke");
	datotekeTable2 = document.getElementById("datotekeTable");
	
	extarr = el.value.split('.');
	ext = extarr[extarr.length-1].toLowerCase();
	dovoljeno = eval('(["jpg","jpg","png","png","gif","bmp","bmp","bmp","tiff","tiff","tga"])');
	veljavno = false;
	for (i = 0; i < dovoljeno.length; i++) {
		if (ext == dovoljeno[i]) {
			veljavno = true;
			break;
		}
	}
	if (!veljavno) {
		prostor.removeChild(el);
		dodajInputFile(prostor);
		alert('Ova vrsta fajla nije dozvoljena!');
		return;
	}

	// Safari fix:
	el.style.position = 'absolute';
	el.style.left = '-1000px';
	
	novTr = document.createElement("tr");
	novTr.setAttribute("id","tr-"+fileID);
	datotekeTable2.appendChild(novTr);
	
	novo = document.createElement("td");
	novo.className = "fileName";
	pot = el.value;
	if (pot.indexOf('/') != -1) {
		ime = pot.split('/');
	} else {
		ime = pot.split('\\');
	}
	tempIme = ime[ime.length-1];
	if (tempIme.length > 25) {
		tempIme = tempIme.substring(0,25) + '...';	
	}
	novo.innerHTML = tempIme;
	novTr.appendChild(novo);

	novo0 = document.createElement("td");
	novo0.className = "fileDesc";
	novo = document.createElement("input");
	novo.value = "Klikni i dodaj opis...";
	novo.className = "descEmpty";
	novo.onclick = function() { if (this.value == "Klikni i dodaj opis...") { this.value = ""; } this.className = "descActive"; }
	novo.onblur = function() { if (this.value == "" || this.value == "Klikni i dodaj opis...") { this.value="Klikni i dodaj opis..."; this.className = "descEmpty"; } else { this.className = "descText"; } }
	novo.setAttribute("name","opis[]");
	novo0.appendChild(novo);
	novTr.appendChild(novo0);
	
	novo = document.createElement("td");
	novo.className = "fileRemove";
	novo.innerHTML = "<a href='#'><img src='resources/images/sr_Latn/ico-del22.gif' alt='x'/></a>";
	novo.setAttribute("id","odstrani-"+fileID);
	novo.onclick = function() { odstrani(this.getAttribute("id")); return false; }
	novTr.appendChild(novo);
	
	if (document.getElementById("opisime") == null) {
		opisime = document.createElement("img");
		opisime.src = "resources/images/sr_Latn/opisime.png";
		opisime.style.position = "absolute";
		opisime.style.marginLeft = "-150px";
		opisime.style.marginTop = "20px";
		opisime.setAttribute("id","opisime");
		novTr.appendChild(opisime);
		setTimeout("hideBalloon();", 3000);
	}
	
	animiraj(novTr);
		
	stDatotek++;
	fileID++;

	if (stDatotek <= 50) {
		dodajInputFile(prostor); 
	}

}

function hideBalloon() {
	
	if (document.getElementById("opisime") != null) {
		document.getElementById("opisime").style.display = "none";
	}
}

function animiraj(el) {
	var r = 137;
	var g = 206;
	
	var ani = setInterval(function () {
		r = r-3;
		g = g-1.2;
		el.style.backgroundColor = 'rgb('+r+','+Math.round(g)+',255)';
		if (r == 17) {
			clearInterval(ani);
		}
	},30);
}

function odstrani(kaj) {

	idarr = kaj.split('-');
	id = idarr[1];
	prostor = document.getElementById("datoteke");
	prostor.removeChild(document.getElementById("datoteka-"+id));
	datotekeTable2 = document.getElementById("datotekeTable");
	datotekeTable2.removeChild(document.getElementById("tr-"+id));

	stDatotek--;
	
	if (stDatotek == 50) {
		dodajInputFile(prostor);
	}
}

function dodajInputFile(prostor) {
	novo = document.createElement("input");
	novo.setAttribute("type","file");
	novo.setAttribute("size","38");
	novo.setAttribute("name","datoteka[]");
	novo.className = "upload-input";
	novo.setAttribute("id","datoteka-"+fileID);
	novo.onchange = function() { dodaj(this); };
	prostor.appendChild(novo);
}

function moznosti(mode) {

	moznosti2 = document.getElementById("moznosti");
	linkDodatno2 = document.getElementById("linkDodatno");

	if (moznosti2.style.display == "none") {
		if (!moznostiHTML) {
			if (mode) {
				ajaxGet('options.php?prilepi=1',updateMoznosti);
			} else {
				ajaxGet('options.php',updateMoznosti);
			}
		}
		moznosti2.style.display = "block";
		linkDodatno2.innerHTML = 'Sakrij dodatne mogućnosti';		
	} else {
		moznosti2.style.display = "none";
		linkDodatno2.innerHTML = 'Dodatne mogućnosti';
	}
}

function updateMoznosti(source) {

	moznostiHTML = true;
	moznosti2 = document.getElementById("moznosti");
	moznosti2.innerHTML = source;
}

function getRandomNumber(range) {
	return Math.floor(Math.random() * range);
}
function getRandomChar() {
	var chars = "0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";
	return chars.substr( getRandomNumber(62), 1 );
}
function randomID(size) {
	var str = "";
	for(var i = 0; i < size; i++) {
		str += getRandomChar();
	}
	return str;
}

function poslji() {	
	gumbposlji2 = document.getElementById("gumbposlji");
	gumbposlji2.style.display = "none";
	showProgress();
	
	//var random = Math.random();
	var random = randomID(15);
	document.getElementById('upload').action = document.getElementById('upload').action + "?X-Progress-ID="+random;
	//alert( "action: "+document.getElementById('upload').action );
	//return false;
	
	var osvezevanje = setInterval('osveziProgress(\"'+random+'\")', 1000);
	
	obrazec2 = document.getElementById("upload");
	obrazec2.submit();
	
	els = getElementsByClass("descEmpty|descActive|descText");
	for (i = 0; i < els.length; i++) {
		els[i].readOnly = true;
		els[i].onclick = null;
		els[i].onblur = null;
	}
	els = getElementsByClass("fileRemove");
	for (i = 0; i < els.length; i++) {
		els[i].onclick = function() { return false; };
	}
	els = getElementsByClass("upload-input");
	for (i = 0; i < els.length; i++) {
		els[i].style.position = 'absolute';
		els[i].style.left = '-1000px';
	}
	
}

function osveziProgress( identifier ) {
	//id = document.getElementById("UPLOAD_IDENTIFIER").value;
	id = identifier;
	t=new Date();
	ajaxGet('progress.php?id='+id+'&random='+t.getTime(),progressCallback);
}

function progressCallback(info) {
	pocakaj2 = document.getElementById("progressFrame");
	if (info != "") {
		pocakaj2.innerHTML = info;
	}
}

// http://www.dustindiaz.com/getelementsbyclass/

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function posljiEmail() {
	gumbemail2 = document.getElementById("gumbemail");
	gumbemail2.onclick = function() { return false; };
	gumbemail2.innerHTML = '<img src="resources/images/sr_Latn/btn-posiljam.gif" alt=""/>';
	ajaxGet('sendlinks.php',emailCallback);
}

function emailCallback() {
	gumbemail2 = document.getElementById("gumbemail");
	gumbemail2.innerHTML = '<img src="resources/images/sr_Latn/btn-poslano.gif" alt=""/>';
}

function oznaci(polje) {
	polje.focus();
  	polje.select();
	kopiraj(polje.value);
}

function kopiraj(text) {
    flavor = "text/unicode";
    if (window.clipboardData)
    {
        window.clipboardData.setData("Text", text );
    }
    else if (window.netscape && navigator.userAgent.toLowerCase().indexOf('opera') == -1)
    {
        try
        {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch(e)
        {
            alert("Zbog visoke bezbednosti u Firefox-u pristup do Clipboard-a trenutno nije moguć. Idite na stranu 'about:config' i za vrednost 'signed.applets.codebase_principal_support' pritisnite na 'true'.");
            return false;
        }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor(flavor);
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext=text;
        str.data=copytext;
        trans.setTransferData(flavor,str,copytext.length*2);
        var clipid=Components.interfaces.nsIClipboard;
        if (!clip) return false;
        clip.setData(trans,null,clipid.kGlobalClipboard);
        return true;
    }
    else
    {
        alert("Vaš browser ne podržava automatsko kopiranje u Clipboard!");
    }
}

function opis(mode,el,id) {
	if (mode) {
		if (el.value == 'Klikni i dodaj opis...') {
			el.value = '';
		}
		el.className = 'descActive';
	} else {
		
		t=new Date();
		url = 'action.php?action=desc&id='+id+'&random='+t.getTime()+'&text=';
		
		if (el.value != '' && el.value != 'Klikni i dodaj opis...') {
			el.className = 'descText';	
			ajaxGet(url+encodeURIComponent(el.value),opisCallback);
		} else {
			el.className = 'descEmpty';
			el.value = 'Klikni i dodaj opis...';
			ajaxGet(url,opisCallback);
		}
	}
}

function opisCallback(niz) { }

var checkednum = 0;

function countcheck(el) {
	if (el.checked) {
		checkednum++;
	} else {
		checkednum--;	
	}
}

function oznaciVse(mode,inputname) {
	if (mode) {
		for (i = 0; i < document.getElementsByName(inputname).length; i++) {
			if (!document.getElementsByName(inputname)[i].checked && !document.getElementsByName(inputname)[i].disabled) {
				document.getElementsByName(inputname)[i].checked = true;
				checkednum++;
			}
		}
	} else {
		for (i = 0; i < document.getElementsByName(inputname).length; i++) {
			if (document.getElementsByName(inputname)[i].checked && !document.getElementsByName(inputname)[i].disabled) {
				document.getElementsByName(inputname)[i].checked = false;
				checkednum--;
			}
		}
	}
}

function action2(actionstr) {

	obrazec2 = document.getElementById("obrazec");
	obrazec2.setAttribute("action", obrazec2.action + "&action=" + actionstr);
	obrazec2.submit();
}

function povrni() {
	location.replace("action.php?action=unhide");
}

function mapa(st) {
	move2 = document.getElementById("selectFolder");
	if (move2.value == "Novi folder...") {
		prompt("Ime novog foldera (najviše 32 znaka):",mapaCallback,st);
	}
}

function mapaCallback(st,promptValue) {
	move2 = document.getElementById("selectFolder");
	if (promptValue != '') {
		move2.options[st+1] = new Option(promptValue,promptValue);
		move2.options[st+1].selected = true;
	} else {
		move2.options[0].selected = true;
	}
}

var glasoval = false;
var ocenaGlobal = 0;
var glasovGlobal = 0;
var viewsGlobal = 0;

function zeGlasoval() {
	glasoval = true;
}

function oznaciZ(stevilo) {
	if (!glasoval) {
		for (i = 1; i <= stevilo; i++) {
			zvezdica = document.getElementById("z"+i);
			zvezdica.src = "resources/images/sr_Latn/z2.gif";
		}
		for (i = stevilo+1; i <= 5; i++) {
			zvezdica = document.getElementById("z"+i);
			zvezdica.src = "resources/images/sr_Latn/z0.gif";
		}
	}
}

function naloziOceno(datoteka) {
		t=new Date();
		url = 'oceni.php?datoteka='+datoteka+'&random='+t.getTime();
		ajaxGet(url,updateOcenaParse);
}

function odznaci() {
	updateOcena(ocenaGlobal,glasovGlobal,viewsGlobal);
}

function oceni(ocena,datoteka) {
	if (!glasoval) {
		t=new Date();
		url = 'oceni.php?datoteka='+datoteka+'&ocena='+ocena+'&random='+t.getTime();
		ajaxGet(url,updateOcenaParse);
		glasoval = true;
		for (i = 1; i <= 5; i++) {
			document.getElementById("z"+i).style.cursor = "default";
		}
	}
}

function updateOcenaParse(podatki) {
	var temp = new Array();
	temp = podatki.split('!');
	updateOcena(temp[0],temp[1],temp[2]);
}

function updateOcena(ocena,glasov,views) {

	if (ocena != "napaka" && ocena != "nocookie") {

		for (i = 1; i <= 5; i++) {
			zvezdica = document.getElementById("z"+i);
			napis = ocena + ' (' + number_format(glasov) + ' glasova, pogledano ' + number_format(views) + 'x)';
			zvezdica.alt = napis;
			zvezdica.title = napis;
		}
		ocenaGlobal = ocena;
		glasovGlobal = glasov;
		viewsGlobal = views;
	}

	if (ocena == "napaka") {
		glasoval = true;
		for (i = 1; i <= 5; i++) {
			document.getElementById("z"+i).style.cursor = "default";
		}
	} else if (ocena == "nocookie") {
		alert("Ne možete glasati jer Vaš browser ne prihvata cookie-je");
	} else {
		if (ocena <= 0.4) {
			pobarvaj(0,false);
		} else if (ocena > 0.4 && ocena < 0.6) {
			pobarvaj(0,true);
		} else if (ocena >= 0.6 && ocena <= 1.4) {
			pobarvaj(1,false);
		} else if (ocena > 1.4 && ocena < 1.6) {
			pobarvaj(1,true);
		} else if (ocena >= 1.6 && ocena <= 2.4) {
			pobarvaj(2,false);
		} else if (ocena > 2.4 && ocena < 2.6) {
			pobarvaj(2,true);
		} else if (ocena >= 2.6 && ocena <= 3.4) {
			pobarvaj(3,false);
		} else if (ocena > 3.4 && ocena < 3.6) {
			pobarvaj(3,true);
		} else if (ocena >= 3.6 && ocena <= 4.4) {
			pobarvaj(4,false);
		} else if (ocena > 4.4 && ocena < 4.6) {
			pobarvaj(4,true);
		} else if (ocena >= 4.6) {
			pobarvaj(5,false);
		}
	}
}

function pobarvaj(zvezdic,polzvezdic) {
		if (zvezdic > 0) {
			for (i = 1; i <= zvezdic; i++) {
				zvezdica = document.getElementById("z"+i);
				zvezdica.src = "resources/images/sr_Latn/z1.gif";
			}
			for (i = zvezdic+1; i <= 5; i++) {
				zvezdica = document.getElementById("z"+i);
				zvezdica.src = "resources/images/sr_Latn/z0.gif";
			}
		} else {
			for (i = 1; i <= 5; i++) {
				zvezdica = document.getElementById("z"+i);
				zvezdica.src = "resources/images/sr_Latn/z0.gif";
			}
		}
		if (polzvezdic) {
				zvezdic = zvezdic + 1;
				zvezdica = document.getElementById("z"+zvezdic);
				zvezdica.src = "resources/images/sr_Latn/z05.gif";
				for (i = zvezdic+1; i <= 5; i++) {
					zvezdica = document.getElementById("z"+i);
					zvezdica.src = "resources/images/sr_Latn/z0.gif";
				}
		}
}

function checkuser(username) {
	ajaxGet('checkuser.php?user='+username,usernameStatus);
}

function usernameStatus(status) {
	if (status == 'taken') {
		document.getElementById('zasedeno').style.display = "block";
	} else {
		document.getElementById('zasedeno').style.display = "none";
	}
}

function showProgress() {
	var overlay=document.getElementById('overlay');
	var progressFrame=document.getElementById('progressFrame');
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	overlay.style.height = (arrayPageSize[1] + 'px');
	overlay.style.display = 'block';
	
	arVersion = navigator.appVersion.split("MSIE");
	version = parseFloat(arVersion[1]);
	if (version == 0 || isNaN(version) || version >= 7) {
		overlay.style.backgroundImage = 'url(resources/images/sr_Latn/flb_overlay.png)';
	} else {
		overlay.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="resources/images/sr_Latn/flb_overlay.png",sizingMethod="scale")';	
	}
	
	progressFrame.style.width='400px';
	progressFrame.style.background='#e2f0f9 url(resources/images/sr_Latn/logo-small.gif) no-repeat 95% 90%';
	
	var frameTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 150) / 2);
	var frameLeft = ((arrayPageSize[0] - 420) / 2);
	progressFrame.style.top = (frameTop < 0) ? "0px" : frameTop + "px";
	progressFrame.style.left = (frameLeft < 0) ? "0px" : frameLeft + "px";

}
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

window.alert = function(txt) { dialog(1,txt); }
window.confirm = function(txt,funct,arg) { dialog(2,txt,funct,arg); }
window.prompt = function(txt,funct,arg) { dialog(3,txt,funct,arg); }

function dialog(mode,txt,funct,arg) {
	if(document.getElementById("modalContainer")) return;
	mObj = document.getElementsByTagName("body")[0].appendChild(document.createElement("div"));
	mObj.id = 'modalContainer';
	mObj.style.display = 'block';
	arVersion = navigator.appVersion.split("MSIE");
	version = parseFloat(arVersion[1]);
	if (version == 0 || isNaN(version) || version >= 7) {
		mObj.style.backgroundImage = 'url(resources/images/sr_Latn/flb_overlay.png)';
	} else {
		mFilterObj = mObj.appendChild(document.createElement("div"));
		mFilterObj.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="resources/images/sr_Latn/flb_overlay.png",sizingMethod="scale")';
		mFilterObj.style.width = '100%';
		mFilterObj.style.height = '100%';
	}
	arrayPageSize = getPageSize();
	arrayPageScroll = getPageScroll();
	mObj.style.height = (arrayPageSize[1] + 'px');
	alertObj = mObj.appendChild(document.createElement("div"));
	alertObj.id = "dialogBox";
	frameTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 150) / 2);
	frameLeft = ((arrayPageSize[0] - 420) / 2);
	alertObj.style.top = (frameTop < 0) ? "0px" : frameTop + "px";
	alertObj.style.left = (frameLeft < 0) ? "0px" : frameLeft + "px";
	msg = alertObj.appendChild(document.createElement("p"));
	msg.appendChild(document.createTextNode(txt));
	if (mode == 3) {
		inpt = alertObj.appendChild(document.createElement("input"));
		inpt.type = 'text';
		inpt.style.display = 'block';
		inpt.style.margin = 'auto';
		inpt.setAttribute('maxLength','32');
		inpt.focus();
	}
	btn = alertObj.appendChild(document.createElement("img"));
	btn.src = 'resources/images/sr_Latn/btn-ok-b.gif';
	btn.style.cursor = 'pointer';
	btn.style.margin = '2px';
	if (mode == 1) {
		btn.onclick = function() { document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); return false; }
	} else if (mode == 2 || mode == 3) {
		if (mode == 2) {
			btn.onclick = function() { document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); funct(arg); }
		} else {
			btn.onclick = function() { document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); funct(arg,inpt.value); }
		}
		btn = alertObj.appendChild(document.createElement("img"));
		btn.src = 'resources/images/sr_Latn/btn-preklici.gif';
		btn.style.cursor = 'pointer';
		btn.style.margin = '2px';
		if (mode == 2) {
			btn.onclick = function() { document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); return false; }
		} else {
			btn.onclick = function() { document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); funct(arg,''); }
		}	
	}
}

var set = false;
function resize(image, normal) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
    	browserWidth = document.body.offsetWidth;
    }
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        browserWidth = document.documentElement.clientWidth;
    }
    if (image.width > (browserWidth - 50)) {
        if (!set) {
            realWidth = image.width;
            set = true;
        }
        image.width = (browserWidth - 50);
    } else if (image.width == (browserWidth - 50) || normal) {
        if (set) {
            image.width = realWidth;
        }
    }
}

function clean(obj) {
	if (obj.value == "Korisničko ime") {
		obj.value = "";	
	}	
	if (obj.value == "Lozinka") {
		obj.value = "";
		changeInputTypeToPassword(obj);
	}	
}

function changeInputTypeToPassword(prevObject) {
    var passInput = document.createElement('input');
    passInput.setAttribute('type', 'password');
    passInput.setAttribute('name', prevObject.getAttribute('name'));
    passInput.className = 'login-input';
    passInput.id = 'password';
    prevObject.parentNode.replaceChild(passInput, prevObject);
    setTimeout("focusInput('password');", 1);
} 

function focusInput(objectID) {
	document.getElementById(objectID).focus();
}

var hexcase = 0;
var chrsz = 8;
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}

function core_md5(x, len)
{
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

function md5() {
	document.getElementById('geslo').value = hex_md5(document.getElementById('geslo').value);
}

function number_format(number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands
    //
    // version: 906.1806
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +     input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +     improved by: davook
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Jay Klehr
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *     example 10: number_format('1.20', 2);
    // *     returns 10: '1.20'
    // *     example 11: number_format('1.20', 4);
    // *     returns 11: '1.2000'
    // *     example 12: number_format('1.2000', 3);
    // *     returns 12: '1.200'
    var n = number, prec = decimals;
 
    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);
        return (Math.round(n*k)/k).toString();
    };
 
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
 
    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = toFixedFix(Math.abs(n), prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    var decPos = s.indexOf(dec);
    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';
    }
    return s;
}


