function getXMLHTTP() { 
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
function getKlas(ucilistaId) {

	var strURL = "findKlas.php?uciliste=" + ucilistaId;
	var req = getXMLHTTP();

	if (req) {

		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {
					document.getElementById('klasdiv').innerHTML = req.responseText;
				} else {
					alert("There was a problem while using XMLHTTP:\n"
							+ req.statusText);
				}
			}
		}
		req.open("GET", strURL, true);
		req.send(null);
	}
}


function getKlas1(ucilista) {

	var strURL = "findKlas1.php?uciliste_id=" + ucilista;
	var req = getXMLHTTP();

	if (req) {

		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {
					document.getElementById('klas1div').innerHTML = req.responseText;
				} else {
					alert("There was a problem while using XMLHTTP:\n"
							+ req.statusText);
				}
			}
		}
		req.open("GET", strURL, true);
		req.send(null);
	}
}
	function napisi(klas){
			$("#uplodot").html("<div id=\"fileQueue\"></div><input type=\"file\" name=\"uploadify\" id=\"uploadify\" /><p><a href=\"javascript:jQuery('#uploadify').uploadifyClearQueue()\">Откажи</a></p>");
			$("#uploadify").uploadify({
				'uploader'       : 'scripts/uploadify.swf',
				'script'         : 'scripts/uploadify.php',
				'cancelImg'      : 'cancel.png',
				'folder'         : 'images/'+$("#ucilista").val()+"/"+klas,
				'queueID'        : 'fileQueue',
				'auto'           : true,
				'multi'          : true
			});
		};
//Script Source: CodeLifter.com
//Copyright 2003

//SETUPS:
//===============================

//Set the horizontal and vertical position for the popup

PositionX = 450;
PositionY = 300;

//Set these value approximately 20 pixels greater than the
//size of the largest image to be used (needed for Netscape)

defaultWidth  = 250;
defaultHeight = 250;

//Set autoclose true to have the window close automatically
//Set autoclose false to allow multiple popup windows

var AutoClose = false;

//================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=yes,width=600,height=300,left='+PositionX+',top='+PositionY;
function popImageTires(ime,prezime,grad,adresa,email,telefon){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Персонални информации</title></head><body ><table><tr style="background-color:#CCCCCC"><td>ИМЕ: </td><td>'+ime+'</td></tr><tr style="background-color:#999999"><td>ПРЕЗИМЕ: </td><td>'+prezime+'</td></tr><tr style="background-color:#CCCCCC"><td>ГРАД: </td><td>'+grad+'</td></tr><tr style="background-color:#999999"><td>АДРЕСА: </td><td>'+adresa+'</td></tr><tr style="background-color:#CCCCCC"><td>E-MAIL: </td><td>'+email+'</td></tr><tr style="background-color:#999999"><td>ТЕЛЕФОН: </td><td>'+telefon+'</td></tr></table><p><small>**За печатење Ctrl+P</small></p></body></html>');
	
close();		
	}}

var i = 1;

function add_file(file) {
	var j = i - 1;

	var box = document.getElementById('file_list');
	var num = box.length;
	var file_exists = 0;

	for (x = 0; x < num; x++) {
		if (box.options[x].text == file) {
			alert('This file has already been added to the Upload List.');
			document.getElementById('file_' + j).value = "";
			file_exists = 1;
			break;
		}
	}

	if (file_exists == 0) {
		// For Internet Explorer
		try {
			el = document.createElement('<input type="file" name="userfile[]" id="file_' + i + '" size="30" onChange="javascript:add_file(this.value);">');
		}
		// For other browsers
		catch (e) {
			el = document.createElement('input');
			el.setAttribute('type', 'file');
			el.setAttribute('name', 'userfile[]');
			el.setAttribute('id', 'file_' + i);
			el.setAttribute('size', '30');
			el.setAttribute('onChange', 'javascript:add_file(this.value);');
		}

		document.getElementById('file_' + j).style.display = 'none';

		if (document.getElementById('list_div').style.display == 'none') {
			document.getElementById('list_div').style.display = 'block';
		}

		document.getElementById('files_div').appendChild(el);
		box.options[num] = new Option(file, 'file_' + j);

		i++;
	}
}

function remove_file() {
	var box = document.getElementById('file_list');

	if (box.selectedIndex != -1) {
		var value = box.options[box.selectedIndex].value;
		var child = document.getElementById(value);
	
		box.options[box.selectedIndex] = null;
		document.getElementById('files_div').removeChild(child);
	
		if (box.length == 0) {
			document.getElementById('list_div').style.display = 'none';
		}
	}
	else {
		alert('You must first select a file from the list.');
	}
}

function do_submit() {
// Uncomment this block for the real onSubmit code

	var box = document.getElementById('file_list');
	var max_files = 50;
	
	if (box.length <= max_files) {	
		var child = document.getElementById('file_' + (i - 1));

		div = document.getElementById('files_div');
		div.removeChild(child);
		div.style.display = 'none';

		return true;
	}
	else
	{
		alert('You have more files listed than the maximum allowed.\nPlease limit your upload files to no more than <? echo $upload_max_files; ?> at a time.');
		return false;
	}

// Just for test page
	alert('Files uploaded successfully');
	return false;
}

