	
	function brisanje_stolova(){
		if(confirm('Jeste li sigurni kako zelite isprazniti stolove?')){
			xmlhttp.open('GET', '<?=$g_path_sl?>iso/res/aj/brisanje_stolova.php');
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
					la_data = JSON.parse(xmlhttp.responseText);
					
					if(la_data['result'] == 1){
						document.getElementById('report-message').innerHTML = '<span style="color:blue">Stolovi su ispraznjeni</span>';
					}else{
						document.getElementById('report-message').innerHTML = '<p style="color:red">Došlo je do pogreške.</p><p>&nbsp;</p>' +
							'<p>Molimo pokušajte ponovo.</p><p>&nbsp;</p><p>U slučaju ponovljenih grešaka, molimo javite se administratoru.</p>';
					}
				}
			}
			xmlhttp.send(null);
		}
	}
	
	
	
	var g_submit_type = 0;
	
	function submit_report(rbr){
	
		if(rbr == 9){
			if(!document.getElementById('FilterVrsta').value){
				alert('Obavezno je odabrati polje "Vrsta"');
				return;
			}
		}
		if(rbr == 16){
			if(!document.getElementById('FilterPovratIliNe').value){
				alert('Obavezno je odabrati polje "Vrsta - Prikazi samo:"');
				return;
			}
		}
	
		
		document.getElementById('report-after').innerHTML = '';
		document.getElementById('report-message').innerHTML =
			'<img src="<?=$g_path_sl?>iso/res/images/spinner.gif" border="0" align="left" style="margin:5px 15px 0 0"> ' +
			'<span style="color:#444488">Izrada izvještaja u tijeku... Molimo pričekajte...</span>';
		
		var l_ime;
		
		var p1 = '';
		var p2 = '';
		var p3 = '';
		var p4 = '';
		var p5 = '';
		
		switch(rbr){
			case 1:
			case 8:
				l_ime = 'dnevni_promet';
				p1 = document.getElementById('FilterDatum').value;
				p2 = document.getElementById('FilterVrstaIzvjesca').value;
				p3 = document.getElementById('FilterUser').value;
				break;
				
			case 2:
				l_ime = 'pregled_prodaje_po_normativu';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				p3 = document.getElementById('FilterUser').value;
				break;
				
			case 3:
				l_ime = 'pregled_prodaje_po_nacinu_placanja';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				p3 = document.getElementById('FilterUser').value;
				break;
				
			case 4:
			case 11:
				l_ime = 'rekapitulacija_prometa';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				break;
				
			case 5:
				l_ime = 'pregled_prodaje_po_artiklu';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				p3 = document.getElementById('FilterGrupaPrikaza').value;
				p4 = document.getElementById('FilterSupplier').value;
				break;
				
			case 6:
				l_ime = 'porez_na_potrosnju';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				break;
				
			case 7:
			case 10:
				l_ime = 'stanje_skladista';
				p1 = document.getElementById('FilterDate').value;
				p2 = document.getElementById('FilterTime').value;
				p3 = document.getElementById('FilterGroup').value;
				break;
				
			case 12:
			case 13:
				l_ime = 'kartica_artikla';
				p1 = document.getElementById('FilterArticlesId').value;
				if(document.getElementById('FilterPordF2') && document.getElementById('FilterPordF2').checked){
					p2 = 1;
				}else{
					p2 = 0;
				}
				break;
				
			case 9:
				l_ime = 'prodani_artikli';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				p3 = document.getElementById('FilterVrsta').value;
				p4 = document.getElementById('FilterGroup').value;
				p5 = document.getElementById('FilterSupplier').value;
				break;
				
			case 14:
				l_ime = 'kolicina_materijala_po_stolovima';
				p1 = '';
				p2 = '';
				break;
				
			case 15:
				l_ime = 'keub';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				break;
				
			case 16:
				l_ime = 'rekapitproizvmedjus';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				if(document.getElementById('FilterKeubOrAll').checked){
					p3 = 1;
				}else{
					p3 = 0;
				}
				p4 = document.getElementById('FilterPovratIliNe').value;
				break;
				
			case 17:
				l_ime = 'rekapitreceivings';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				if(document.getElementById('FilterGrupirajDobavljac').checked){
					p3 = 1;
				}else{
					p3 = 0;
				}
				p4 = document.getElementById('FilterDobavljaci').value;
				break;
				
			case 18:
				l_ime = 'ispis_normativa';
				p1 = '';
				p2 = '';
				break;
				
			case 19:
			case 20:
				l_ime = 'rekapitulacija_po_danima';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				break;
				
			case 21:
				l_ime = 'ispis_cjenika';
				p1 = document.getElementById('FilterGroup').value;
				p2 = document.getElementById('FilterSort').value;
				break;
				
			case 22:
				l_ime = 'rekapitulacija_dobavljaca';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				break;
				
			case 23:
				l_ime = 'pregled_nabave_materijalno';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
				break;
				
			case 24:
			case 25:
				l_ime = 'stanje_skladista_iz_artikala';
				p1 = document.getElementById('FilterDate').value;
				p2 = document.getElementById('FilterTime').value;
				break;
			case 26:
				l_ime = 'pregled_napojnice';
				p1 = document.getElementById('FilterDateStart').value;
				p2 = document.getElementById('FilterDateEnd').value;
			break;
		}
		
		xmlhttp.open('GET', '<?=$g_path_sl?>iso/res/aj/report_create.php?report_id=' + rbr + '&p1=' + p1 + '&p2=' + p2 + '&p3=' + p3 + '&p4=' + p4 + '&p5=' + p5);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				if(la_data['result'] == 1){
					document.getElementById('report-message').innerHTML = '<span style="color:blue">Izvještaj je kreiran</span>';
					
					var l_izvoz = '';
					
					switch(rbr){
						case 2:
						case 19:
						case 20:
							l_izvoz += 
								'<td style="width:200px;" align="center">' +
								'	<center>' +
								'		<a href="#" onclick="email_box_open(2); return false;" style="display:block; margin:0 0 10px 0">' +
								'			<img src="<?=$g_path_sl?>iso/res/images/b-xls-icon.gif"></a>' +
								'		<p>Izvoz podataka na e-mail</p>' +
								'	</center>' +
								'</td>';
							break;
							
						case 9:
							l_izvoz += 
								'<td style="width:200px;" align="center">' +
								'	<center>' +
								'		<a href="#" onclick="email_box_open(2); return false;" style="display:block; margin:0 0 10px 0">' +
								'			<img src="<?=$g_path_sl?>iso/res/images/b-xls-icon.gif"></a>' +
								'		<p>Izvoz podataka na e-mail</p>' +
								'	</center>' +
								'</td>';
							l_izvoz += 
								'<td style="width:200px;" align="center">' +
								'	<center>' +
								'		<a href="#" onclick="email_box_open(3); return false;" style="display:block; margin:0 0 10px 0">' +
								'			<img src="<?=$g_path_sl?>iso/res/images/b-txt-icon.gif"></a>' +
								'		<p>Izvoz podataka u Synesis</p>' +
								'	</center>' +
								'</td>';
							break;
							
						default:
							l_izvoz = '';
					}
					
					var l_txt = 
						'<span style="font-size:9pt">' +
						'	<table width="400" style="width:400px; font-size:8pt">' +
						'	<tr>' +
						'		<td style="width:200px;" align="center" id="pregledaj-izvjestaj">' +
						'			<center>' +
						'				<a href="<?=$g_path_sl?>res/files/' + l_ime + '.pdf?t=' + new Date().getTime() + '" target="_blank" style="display:block; margin:0 0 10px 0">' +
						'					<img src="<?=$g_path_sl?>iso/res/images/b-pdf-icon.gif"></a>' +
						'				<p>Pregledaj izvještaj</p>' +
						'			</center>' +
						'		</td>' +
						l_izvoz +
						'		<td style="width:200px;" align="center">' +
						'			<center>' +
						'				<a href="#" onclick="email_box_open(1); return false;" style="display:block; width:32px; margin:0 0 10px 0">' +
						'					<img src="<?=$g_path_sl?>iso/res/images/b-email.gif"></a>' +
						'				<p>Pošalji izvještaj e-mailom</p>' +
						'			</center>' +
						'		</td>' +
						'	</tr>' +
						'	</table>' +
						'</span>';
					
					l_txt += 
						'<div id="send-email-box" style="display:none; margin:20px 0 0 200px; font-size:9pt; padding:10px; width:300px; border-style:solid; border-width:5px; border-color:#cccc99; background:#ffffff; ">' +
						'	<span id="mailer-spinner" style="display:none">' +
						'		<p align="center"><img src="<?=$g_path_sl?>iso/res/images/spinner.gif" border="0"></p>' +
						'		<p>&nbsp;</p>' +
						'		<p>Slanje e-maila u tijeku. Molimo pričekajte.</p>' +
						'	</span>' +
						'	<span id="mailer-email-info">' +
						'		<span id="destination"></span>' +
						'		<p>Molimo odaberite primatelja e-maila:</p>' +
						'		<p>&nbsp;</p>' +
						'		<p style="padding:0 0 0 10px"><input type="radio" id="mailer-primatelj-1" name="mailer-primatelj" value="1" checked> Vlasnik</p>' +
						'		<p>&nbsp;</p>' +
						'		<p style="padding:0 0 0 10px"><input type="radio" id="mailer-primatelj-2" name="mailer-primatelj" value="2"> Knjigovodstvo</p>' +
						'		<p>&nbsp;</p>' +
						'		<p style="padding:0 0 0 100px"><input type="submit" value="Pošalji e-mail"' +
						'			onclick="mailer_send_email(\'' + l_ime + '\', ' + rbr + ', \'' + p1 + '\', \'' + p2 + '\', \'' + p3 + '\', g_submit_type); return false;"></p>' +
						'		<p><a href="#" onclick="mailer_close_layer(); return false;" style="float:right">Zatvori &raquo;</a></p><p>&nbsp;</p>' +
						'	</span>' +
						'</div>' +
						'<div id="send-email-box-2" style="display:none; margin:20px 0 0 200px; font-size:9pt; padding:10px; width:300px; border-style:solid; border-width:5px; border-color:#cccc99; background:#ffffff; ">' +
						'</div>';
					
					document.getElementById('report-after').innerHTML = l_txt;
					if(typeof g_outer_report != "undefined" && g_outer_report == 1){
						document.getElementById('pregledaj-izvjestaj').innerHTML = '';
					}
					
					
					
					
				}else{
					document.getElementById('report-message').innerHTML = '<p style="color:red">Došlo je do pogreške.</p><p>&nbsp;</p>' +
						'<p>Molimo pokušajte ponovo.</p><p>&nbsp;</p><p>U slučaju ponovljenih grešaka, molimo javite se administratoru.</p>';
				}
			}
		}
		xmlhttp.send(null);
	}

	function mailer_send_email(report, report_id, param1, param2, param3, type){
		var l_receiver;
		if(document.getElementById('mailer-primatelj-1').checked){
			l_receiver = 1;
		}
		if(document.getElementById('mailer-primatelj-2').checked){
			l_receiver = 2;
		}
		
		document.getElementById('mailer-email-info').style.display = 'none';
		document.getElementById('mailer-spinner').style.display = 'block';
		
		xmlhttp.open('GET', '<?=$g_path_sl?>iso/res/aj/mailer_send_email.php?report=' + report + '&report_id=' + report_id + '&receiver=' + l_receiver +
			'&param1=' + param1 + '&param2=' + param2 + '&param3=' + param3 + '&type=' + type);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				if(la_data['result'] == 1){
					document.getElementById('send-email-box-2').innerHTML = '<p>E-mail je poslan!</p><p>&nbsp;</p>' +
						'<p><a href="#" onclick="mailer_close_layer(); return false;" style="float:right">Zatvori &raquo;</a></p><p>&nbsp;</p>';
				}else{
					document.getElementById('send-email-box-2').innerHTML = '<p style="color:red">Došlo je do pogreške.</p><p>&nbsp;</p>' +
						'<p>Molimo pokušajte ponovo.</p><p>&nbsp;</p><p>U slučaju ponovljenih grešaka, molimo javite se administratoru.</p><p>&nbsp;</p>' +
						'<p><a href="#" onclick="mailer_reset_layer(); return false;" style="float:right">Dalje &raquo;</a></p><p>&nbsp;</p>';
				}
				document.getElementById('send-email-box-2').style.display = 'block';
				document.getElementById('send-email-box').style.display = 'none';
				document.getElementById('mailer-spinner').style.display = 'none';
				document.getElementById('mailer-email-info').style.display = 'block';
			}
		}
		xmlhttp.send(null);
	}
	
	function mailer_reset_layer(){
		document.getElementById('send-email-box-2').style.display = 'none';
		document.getElementById('send-email-box').style.display = 'block';
	}
	
	function mailer_close_layer(){
		document.getElementById('send-email-box-2').style.display = 'none';
		document.getElementById('send-email-box').style.display = 'none';
	}
	
	function email_box_open(type){
		if(type == 1){
			document.getElementById('destination').innerHTML = '<b>Pošalji izvještaj e-mailom</b><br><br>';
			g_submit_type = 1;
		}
		if(type == 2){
			document.getElementById('destination').innerHTML = '<b>Izvoz podataka na e-mail</b><br><br>';
			g_submit_type = 2;
		}
		if(type == 3){
			document.getElementById('destination').innerHTML = '<b>Izvoz podataka u Synesis</b><br><br>';
			g_submit_type = 3;
		}
		var l_obj = document.getElementById('send-email-box');
		if(l_obj.style.display == 'block'){
			//l_obj.style.display = 'none';
		}else{
			l_obj.style.display = 'block';
		}
		document.getElementById('send-email-box-2').style.display = 'none';
	}
	
	function get_article_groups(){
		xmlhttp.open('GET', '<?=$g_path_sl?>iso/res/aj/get_article_groups.php');
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				if(la_data['result'] == 1){
					var obj = document.getElementById('FilterGroup');
					for(var i = obj.options.length - 1; i >= 0; i--){
						obj.remove(i);
					}
					opt = document.createElement("option");
					opt.value = '-2';
					opt.text = '-- Sve grupe --';
					obj.appendChild(opt);
					opt = document.createElement("option");
					opt.value = '-1';
					opt.text = '-- Bez grupe --';
					obj.appendChild(opt);
					for(i = 0; i < la_data['group'].length; i++){
						opt = document.createElement("option");
						opt.value = la_data['group'][i].id;
						opt.text = la_data['group'][i].name;
						obj.appendChild(opt);
					}
				}
			}
		}
		xmlhttp.send(null);
	}

	function get_groups(tip, has_grouped_by_group){
		xmlhttp.open('GET', '<?=$g_path_sl?>iso/res/aj/get_groups.php?tip=' + tip);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				if(la_data['result'] == 1){
					var obj = document.getElementById('FilterGroup');
					for(var i = obj.options.length - 1; i >= 0; i--){
						obj.remove(i);
					}
					
					if(has_grouped_by_group){
						opt = document.createElement("option");
						opt.value = -1;
						opt.text = '-- Sve grupe (grupirano) --';
						obj.appendChild(opt);
					}
					
					opt = document.createElement("option");
					opt.value = null;
					opt.text = '-- Sve grupe --';
					obj.appendChild(opt);
					for(i = 0; i < la_data['group'].length; i++){
						opt = document.createElement("option");
						opt.value = la_data['group'][i].id;
						opt.text = la_data['group'][i].name;
						obj.appendChild(opt);
					}
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function get_suppliers(){
		xmlhttp.open('GET', '<?=$g_path_sl?>iso/res/aj/get_suppliers.php');
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				if(la_data['result'] == 1){
					var obj = document.getElementById('FilterSupplier');
					for(var i = obj.options.length - 1; i >= 0; i--){
						obj.remove(i);
					}
					
					opt = document.createElement("option");
					opt.value = null;
					opt.text = '-- Svi dobavljači --';
					obj.appendChild(opt);
					
					opt = document.createElement("option");
					opt.value = -1;
					opt.text = '-- Artikli bez dobavljača --';
					obj.appendChild(opt);
						
					for(i = 0; i < la_data['supplier'].length; i++){
						opt = document.createElement("option");
						opt.value = la_data['supplier'][i].id;
						opt.text = la_data['supplier'][i].name;
						obj.appendChild(opt);
					}
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function get_users(){
		xmlhttp.open('GET', '<?=$g_path_sl?>iso/res/aj/get_users.php');
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				if(la_data['result'] == 1){
					var obj = document.getElementById('FilterUser');
					for(var i = obj.options.length - 1; i >= 0; i--){
						obj.remove(i);
					}
					opt = document.createElement("option");
					opt.value = null;
					opt.text = '---';
					obj.appendChild(opt);
					for(i = 0; i < la_data['user'].length; i++){
						opt = document.createElement("option");
						opt.value = la_data['user'][i].id;
						opt.text = la_data['user'][i].name;
						obj.appendChild(opt);
					}
				}
			}
		}
		xmlhttp.send(null);
	}
	
	<!--
	var xmlhttp = false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
		}
	}
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		xmlhttp = new XMLHttpRequest();
	}
	
	function makerequest(serverPage, objID){
		if(objID){
			var obj = document.getElementById(objID);
		}
		xmlhttp.open('GET', serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && obj) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	//-->

