	
	function unesi_inventuru(){
		document.getElementById('dodajDatotekuLayer').style.display = 'block';
		document.getElementById('clickHereIDButton').style.display = 'none';
		document.getElementById('upload_frame').src = g_path_sl_res + 'inventura_upload.php';
		return false;
	}
	
	function save_new_item_in_dd(obj, mode){
		if(mode == 2){
			obj.parentNode.parentNode.parentNode.parentNode.style.display = 'none';
			return;
		}
		
		var inputs = obj.parentNode.parentNode.getElementsByTagName('INPUT');
		var str = '';
		for(var i = 0; i < inputs.length; i++){
			if(inputs[i].type == 'text' || inputs[i].type == 'hidden'){
				str += '&' + inputs[i].id + '=' + inputs[i].value;
			}
		}
		str = str.substring(1);
		
		xmlhttp.open('POST', 'res/aj/save_new_item_in_dd.php', true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				if(la_data['result'] == 0){
				
					var la_tmp = la_data['error'].split(',');
					for(var i = 0; i < la_tmp.length; i++) {
						if(la_tmp[i] == 1){
							document.getElementById('item-' + i).style.background = '#ffaaaa';
						}
					}
					obj.parentNode.parentNode.parentNode.parentNode.scrollTop = 0;
					alert('POGREŠKA! Niste upisali sva obavezna polja!');
					
				}else{
				
					obj.parentNode.parentNode.parentNode.parentNode.style.display = 'none';
					
					var opt = document.createElement("option");
					opt.value = la_data['result'];
					opt.text = la_data['name'];
					
					var selectObj = document.getElementById('formfield_' + la_data['rbr']);
					
					selectObj.appendChild(opt);
					
					for(var i = 0; i < selectObj.options.length; i++) {
						if(selectObj.options[i].value == la_data['result']){
							selectObj.options[i].selected = true;
							break;
						}
					}
					
				}
			}
		}
		xmlhttp.send(str);
	}
	
	function add_new_item_in_dd(obj, rbr, rbr_atribut){
		var l_html = obj.parentNode.innerHTML;
		
		if(l_html.indexOf('add-new-item-layer') < 0){
			obj.parentNode.innerHTML += '<div class="add-new-item-layer" id="add-new-item-layer-' + rbr + '-' + rbr_atribut + '"></div>';
		}
		document.getElementById('add-new-item-layer-' + rbr + '-' + rbr_atribut).style.display = 'block';
		document.getElementById('add-new-item-layer-' + rbr + '-' + rbr_atribut).scrollTop = 0;
		
		xmlhttp.open('GET', g_path_sl_res + 'aj/add_new_item_in_dd.php?rbr=' + rbr + '&rbr_atribut=' + rbr_atribut);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				if(la_data['result'] != 0){
					document.getElementById('add-new-item-layer-' + rbr + '-' + rbr_atribut).innerHTML = la_data['result'];
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function primka_send_email(type, rbr){
		var l_receiver;
		if(document.getElementById('mailer-primatelj-' + rbr + '-1').checked){
			l_receiver = 1;
		}
		if(document.getElementById('mailer-primatelj-' + rbr + '-2').checked){
			l_receiver = 2;
		}
		
		document.getElementById('mailer-email-info-' + rbr).style.display = 'none';
		document.getElementById('mailer-spinner-' + rbr).style.display = 'block';
		
		//document.write(g_path_sl_res + 'aj/primka_send_email.php?report_id=' + type + '&rbr=' + rbr + '&receiver=' + l_receiver);
		//return;
		
		xmlhttp.open('GET', g_path_sl_res + 'aj/primka_send_email.php?report_id=' + type + '&rbr=' + rbr + '&receiver=' + l_receiver);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				if(la_data['result'] == 1){
					document.getElementById('mailer-spinner-' + rbr).innerHTML = '<p>E-mail je poslan!</p><p>&nbsp;</p>' +
						'<p><a href="#" onclick="primka_close_layer(' + rbr + '); return false;" style="float:right">Zatvori &raquo;</a></p><p>&nbsp;</p>';
				}else{
					document.getElementById('mailer-spinner-' + rbr).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="primka_reset_layer(' + rbr + '); return false;" style="float:right">Dalje &raquo;</a></p><p>&nbsp;</p>';
				}
				//document.getElementById('mailer-email-info-' + rbr).style.display = 'block';
			}
		}
		xmlhttp.send(null);
	}
	
	function primka_reset_layer(rbr){
		document.getElementById('mailer-spinner-' + rbr).style.display = 'none';
		document.getElementById('mailer-email-info-' + rbr).style.display = 'block';
	}
	
	function primka_close_layer(rbr){
		document.getElementById('email-send-' + rbr).style.display = 'none';
	}
	
	function primka_email_send(obj, type, rbr){
		var spans = obj.parentNode.parentNode.parentNode.getElementsByTagName('SPAN');
		for(var i = 0; i < spans.length; i++){
			if(spans[i].className == 'primka-email-send'){
				spans[i].style.display = 'none';
			}
		}
		
		document.getElementById('email-send-' + rbr).innerHTML = 
			'	<span id="mailer-spinner-' + rbr + '" style="display:none">' +
			'		<p align="center"><img src="' + g_path_sl_res + 'images/spinner.gif" border="0"></p>' +
			'		<p class="blue">Slanje e-maila u tijeku. Molimo pričekajte.</p>' +
			'		<p>&nbsp;</p>' +
			'	</span>' +
			'	<span id="mailer-email-info-' + rbr + '">' +
			'		<p><b>Pošalji izvještaj e-mailom</b></p>' +
			'		<p>Molimo odaberite primatelja e-maila:</p>' +
			'		<p><input type="radio" id="mailer-primatelj-' + rbr + '-1" name="mailer-primatelj-' + rbr + '" value="1" checked> Vlasnik</p>' +
			'		<p><input type="radio" id="mailer-primatelj-' + rbr + '-2" name="mailer-primatelj-' + rbr + '" value="2"> Knjigovodstvo</p>' +
			'		<p><input type="submit" value="Pošalji e-mail"' +
			'			onclick="primka_send_email(' + type + ', ' + rbr + '); return false;" class="sbm"></p>' +
			'		<p><a href="#" onclick="primka_close_layer(' + rbr + '); return false;" style="float:right" class="zatvori">Zatvori &raquo;</a></p><p>&nbsp;</p>' +
			'	</span>';
		document.getElementById('email-send-' + rbr).style.display = 'block';
	}
	
	
	function create_plovila_ugovor(id){
		//document.write(g_path_sl_res + 'aj/create_plovila_ugovor.php?id=' + id);
		//return;
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/create_plovila_ugovor.php?id=' + id);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				//alert(xmlhttp.responseText);
				la_data = JSON.parse(xmlhttp.responseText);
				
				if(la_data[0] == 'ok'){
					active_tab = 2;
					var ps = document.getElementById('allLabels').getElementsByTagName('P');
					for(var i = 0; i < ps.length; i++){
						if(ps[i].className.indexOf('evidencijaPlovilaDatotekaLabel') >= 0){
							var as = ps[i].getElementsByTagName('A');
							open_close_all_labels(as[0]);
							break;
						}
					}
					
					set_redak(2, 1);
					subform_new_row(125, 0, 0, la_data[1], 1, la_data[2] + ':::[SEP]:::' + la_data[3], '');
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function printForm(rbr, id){
		//alert(rbr);
		document.getElementById('printLay').style.display = 'block';
		
		//document.write(g_path_sl_res + 'aj/create_invoice.php?rbr=' + rbr);
		//return;
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/create_invoice.php?rbr=' + rbr);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				//alert(xmlhttp.responseText);
				la_data = JSON.parse(xmlhttp.responseText);
				
				//alert(la_data[3]);
				//alert(la_data[4]);
				
				if(la_data[0] == 'ok'){
					document.getElementById('printLay').innerHTML = 'Račun ' + la_data[2] + '<br><br>';
					document.getElementById('printLay').innerHTML += '<a href="' + g_path_sl_res + 'files/' + la_data[1] + '" target="_blank">Download</a><br><br>';
					document.getElementById('printLay').innerHTML += '<br><br><br><br>';
					document.getElementById('printLay').innerHTML += '<a href="#" onclick="folder_close_layer(\'printLay\'); return false;">Zatvori prozor</a><br><br>';
					window.open(g_path_sl_res + 'files/' + la_data[1], '_blank', 'width=800,height=600');
				}else{
					document.getElementById('printLay').innerHTML = 'Došlo je do pogreške prilikom kreiranja računa. Pokušajte ponovo.<br><br>';
					document.getElementById('printLay').innerHTML += '<a href="#" onclick="folder_close_layer(\'printLay\'); return false;">Zatvori prozor</a><br><br>';
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function racunaj_rabat2(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14){
		racunaj_pdv(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14);
	}
	
	function racunaj_pdv(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14){
		for(i = 1; i <= a_redak[0]; i++){
			obj = document.getElementById('formfield_9_' + i + '_1');
			get_iznos_ponuda(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14);
		}
	}
	

	function get_iznos_ponuda(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14){
	
		//alert(obj.id);
		if(obj.id.indexOf('formfield_DELETE_') >= 0){
			l_name = obj.id.replace('formfield_DELETE', '');
		}else{
			l_name = obj.id.replace('formfield_' + f1, '');
		}
		//alert(l_name);
		
		//alert('formfield_' + f2 + l_name);
		//alert('formfield_' + f14);
		
		if(f14 == '0'){
			l_rabat2 = 0;
		}else{
			l_rabat2 = document.getElementById('formfield_' + f14).value;
		}
		
		//alert('formfield_' + f2 + l_name);
		//alert('formfield_' + f3 + l_name);
		
		l_value = document.getElementById('formfield_' + f2 + l_name).value * 
			document.getElementById('formfield_' + f3 + l_name).value;
		l_value_rabat = document.getElementById('formfield_' + f2 + l_name).value * document.getElementById('formfield_' + f3 + l_name).value * 
			document.getElementById('formfield_' + f4 + l_name).value / 100;
		if(document.getElementById('formfield_' + f9).checked){
			l_value_pdv = (l_value - l_value_rabat) * 0.25;
		}else{
			l_value_pdv = 0;
		}
		
		document.getElementById('formfield_' + f5 + l_name).value = l_value_rabat;
		document.getElementById('formfield_' + f6 + l_name).value = l_value - l_value_rabat;
		document.getElementById('formfield_' + f7 + l_name).value = l_value_pdv;
		document.getElementById('formfield_' + f8 + l_name).value = l_value - l_value_rabat + l_value_pdv;
		
		document.getElementById('formfield_' + f5 + l_name + '_dis').value = l_value_rabat;
		document.getElementById('formfield_' + f6 + l_name + '_dis').value = l_value - l_value_rabat;
		document.getElementById('formfield_' + f7 + l_name + '_dis').value = l_value_pdv;
		document.getElementById('formfield_' + f8 + l_name + '_dis').value = l_value - l_value_rabat + l_value_pdv;
		
		la_tmp = l_name.split('_');
		for(var i = 2; i < la_tmp.length; i++){
			l_name_sub = '_' + la_tmp[i];
		}
		
		var l_u_iznos = 0;
		var l_u_rabat = 0;
		var l_u_pdv = 0;
		var l_u_ukup = 0;
		
		for(i = 1; i <= a_redak[0]; i++){
			if(document.getElementById('delete_row_' + i + '_1').value == '1'){
				continue;
			}
			
			l_num1 = document.getElementById('formfield_' + f6 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num1) && l_num1 != ''){
				l_u_iznos += parseFloat(l_num1);
			}
			
			l_num2 = document.getElementById('formfield_' + f5 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num2) && l_num2 != ''){
				l_u_rabat += parseFloat(l_num2);
			}
			
			l_num3 = document.getElementById('formfield_' + f7 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num3) && l_num3 != ''){
				l_u_pdv += parseFloat(l_num3);
			}
			
			l_num4 = document.getElementById('formfield_' + f8 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num4) && l_num4 != ''){
				l_u_ukup += parseFloat(l_num4);
			}
		}
		
		document.getElementById('formfield_' + f10).value = l_u_iznos * (1 - l_rabat2 / 100);
		document.getElementById('formfield_' + f10 + '_dis').value = l_u_iznos * (1 - l_rabat2 / 100);
		
		document.getElementById('formfield_' + f11).value = l_u_rabat;
		document.getElementById('formfield_' + f11 + '_dis').value = l_u_rabat;
		
		document.getElementById('formfield_' + f12).value = l_u_pdv * (1 - l_rabat2 / 100);
		document.getElementById('formfield_' + f12 + '_dis').value = l_u_pdv * (1 - l_rabat2 / 100);
		
		document.getElementById('formfield_' + f13).value = l_u_ukup * (1 - l_rabat2 / 100);
		document.getElementById('formfield_' + f13 + '_dis').value = l_u_ukup * (1 - l_rabat2 / 100);
	}
	
	var g_first_time_pdv = 1;
	function get_pdv(){
		if(g_first_time_pdv == 1){
			g_first_time_pdv = 0;
			
			var l_value = '';
			var l_name;
			for(i = 1; i <= a_redak[0]; i++){
				l_name = '_' + i + '_1';
				l_value += document.getElementById('formfield_2' + l_name).value + ':';
			}
			
			xmlhttp.open("GET", g_path_sl_res + 'aj/get_pdv.php?min=1&max=' + a_redak[0] + '&value=' + l_value);
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
					la_data = JSON.parse(xmlhttp.responseText);
					
					for(i = 0; i < la_data.length; i++){
						l_name = '_' + parseInt(i + 1) + '_1';
						ga_pdv[l_name] = la_data[i];
						l_pdv = la_data[i];
					}
				}
			}
			xmlhttp.send(null);
		}
	}
	
	var a_zapis_rbr_old_value = new Array();
	function select_zapis(value, str){
		la_tmp = str.split(';');
		for(var i = 0; i < la_tmp.length; i++){
			la2_tmp = la_tmp[i].split(':');
			
			if(!eval(document.getElementById('formfield_' + la2_tmp[1]))){
				continue;
			}
			if(!eval(document.getElementById('div_formfield_' + la2_tmp[1]))){
				continue;
			}
			if(value == la2_tmp[0]){
				//document.getElementById('formfield_' + la2_tmp[1]).value = a_zapis_rbr_old_value[la2_tmp[0]];
				//document.getElementById('div_formfield_' + la2_tmp[1]).innerHTML = a_zapis_rbr_old_value[la2_tmp[0]];
				//document.getElementById('formfield_' + la2_tmp[1]).style.display = 'block';
				document.getElementById('div_formfield_' + la2_tmp[1]).style.background = '#e2d2c2';
				document.getElementById('div_formfield_' + la2_tmp[1]).style.color = '#222222';
			}else{
				//alert(document.getElementById('formfield_' + la2_tmp[1]).value);
				//a_zapis_rbr_old_value[la2_tmp[0]] = document.getElementById('formfield_' + la2_tmp[1]).value;
				//document.getElementById('formfield_' + la2_tmp[1]).value = '';
				//document.getElementById('div_formfield_' + la2_tmp[1]).innerHTML = '';
				//document.getElementById('formfield_' + la2_tmp[1]).style.display = 'none';
				document.getElementById('div_formfield_' + la2_tmp[1]).style.background = '#f1f1f1';
				document.getElementById('div_formfield_' + la2_tmp[1]).style.color = '#999999';
			}
		}
	}
	
	function stavka_promijeni_status_medjus(id, type){
		if(type == 1 && !confirm('Jeste li sigurni da želite Otknjižiti željenu stavku?')){
			return;
		}
		if(type == 2 && !confirm('Jeste li sigurni da želite Proknjižiti željenu stavku?')){
			return;
		}
		
		//document.write(g_path_sl_res + 'aj/stavka_promijeni_status_medjus.php?id=' + id + '&type=' + type);
		//return;
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/stavka_promijeni_status_medjus.php?id=' + id + '&type=' + type);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				if(xmlhttp.responseText == 1){
					//window.location.reload();
					
					var l_href = document.location.href.replace('&medjusmsg=saved', '');
					var la_tmp = l_href.split('#');
					l_href = la_tmp[0];
					l_href = l_href.replace('&medjusmsgotknjizi=saved', '');
					l_href = l_href.replace('&medjusmsgproknjizi=saved', '');
					if(type == 1){
						document.location.href = l_href + '&medjusmsgotknjizi=saved';
					}
					if(type == 2){
						document.location.href = l_href + '&medjusmsgproknjizi=saved';
					}
				}else{
					alert('Dogodila se pogreška 759385. Kontaktirajte administratora!');
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function stavka_promijeni_status(id, type){
		if(type == 1 && !confirm('Jeste li sigurni da želite Otknjižiti željenu stavku?')){
			return;
		}
		if(type == 2 && !confirm('Jeste li sigurni da želite Proknjižiti željenu stavku?')){
			return
		}
		xmlhttp.open("GET", g_path_sl_res + 'aj/stavka_promijeni_status.php?id=' + id + '&type=' + type);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				if(xmlhttp.responseText == 1){
					//window.location.reload();
					
					var l_href = document.location.href.replace('&primkamsg=saved', '');
					var la_tmp = l_href.split('#');
					l_href = la_tmp[0];
					l_href = l_href.replace('&primkamsgotknjizi=saved', '');
					l_href = l_href.replace('&primkamsgproknjizi=saved', '');
					if(type == 1){
						document.location.href = l_href + '&primkamsgotknjizi=saved';
					}
					if(type == 2){
						document.location.href = l_href + '&primkamsgproknjizi=saved';
					}
				}else{
					alert('Dogodila se pogreška 75934. Kontaktirajte administratora!');
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function get_marza(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, outer_call){
		var l_name = obj.id.replace('formfield_' + f1, '');
		var marza_kom;
		var marza_posto;
		var marza_iznos;
		
		l_f5 = document.getElementById('formfield_' + f5 + l_name).value;
		l_f6 = document.getElementById('formfield_' + f6 + l_name).value;
		l_f7 = document.getElementById('formfield_' + f7 + l_name).value;
		
		var l_pdv = ga_pdv[l_name];
		
		if(outer_call == 1){
			l_f4 = parseFloat(document.getElementById('formfield_' + f4 + l_name).value);
			marza_posto = (l_f4 / (1 + l_pdv / 100)/(l_f5 * (1 - l_f6 / 100)) - 1) * 100;
			marza_posto = roundNumber(marza_posto, 2);
			marza_kom = (l_f4 / (1 + l_pdv / 100)) - (l_f5 * (1 - l_f6 / 100));
			marza_kom = roundNumber(marza_kom, 2);
		}else{
			if(f3 != f1){
				marza_posto = parseFloat(document.getElementById('formfield_' + f1 + l_name).value);
				l_f4 = (1 + marza_posto / 100) * (1 + l_pdv / 100) * (l_f5 * (1 - l_f6 / 100));
				marza_kom = (l_f4 / (1 + l_pdv / 100)) - (l_f5 * (1 - l_f6 / 100));
				marza_kom = roundNumber(marza_kom, 2);
			}
			if(f2 != f1){
				marza_kom = parseFloat(document.getElementById('formfield_' + f1 + l_name).value);
				l_f4 = (marza_kom + (l_f5 * (1 - l_f6 / 100))) * (1 + l_pdv / 100);
				marza_posto = (l_f4 / (1 + l_pdv / 100)/(l_f5 * (1 - l_f6 / 100)) - 1) * 100;
				marza_posto = roundNumber(marza_posto, 2);
			}
		}
		marza_iznos = l_f7 * marza_kom;
		marza_iznos = roundNumber(marza_iznos, 2);
		
		if(outer_call == 1){
			document.getElementById('formfield_' + f4 + l_name).value = l_f4;
			document.getElementById('formfield_' + f2 + l_name).value = marza_posto;
			document.getElementById('formfield_' + f3 + l_name).value = marza_kom;
		}else{
			if(f2 != f1){
				document.getElementById('formfield_' + f4 + l_name).value = l_f4;
				document.getElementById('formfield_' + f2 + l_name).value = marza_posto;
			}
			if(f3 != f1){
				document.getElementById('formfield_' + f4 + l_name).value = l_f4;
				document.getElementById('formfield_' + f3 + l_name).value = marza_kom;
			}
		}
		document.getElementById('formfield_' + f8 + l_name).value = marza_iznos;
		document.getElementById('formfield_' + f8 + l_name + '_dis').value = marza_iznos;
		
		
		// ovo se ne zove kad je funkcija get_marza vec pozvana iz funkcije get_iznos_primka, a kako se ne bi dogodila beskonacna petlja medjusobnog pozivanja
		if(outer_call == 0){
			var la_tmp = obj.id.split('_');
			var l_obj_id = obj.id.replace('_' + la_tmp[1] + '_', '_' + f7 + '_');
			var new_obj = document.getElementById(l_obj_id);
			get_iznos_primka(new_obj, f7, f9, f10, f5, f6, f4, f11, f2, f3, f8, f12, f13, 1);
		}
	}
	
	
	function get_iznos_primka(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, outer_call){
		var l_name = obj.id.replace('formfield_' + f1, '');
		var l_zbr = parseFloat(document.getElementById('formfield_' + f3 + l_name).value) *
			parseFloat(document.getElementById('formfield_' + f4 + l_name).value);
		l_zbr = l_zbr * (1 - parseFloat(document.getElementById('formfield_' + f5 + l_name).value) / 100);
		l_zbr = roundNumber(l_zbr, 2);
		
		document.getElementById('formfield_' + f2 + l_name).value = l_zbr;
		document.getElementById('formfield_' + f2 + l_name + '_dis').value = l_zbr;
		
		
		
		var l_zbr_p = parseFloat(document.getElementById('formfield_' + f3 + l_name).value) *
			parseFloat(document.getElementById('formfield_' + f6 + l_name).value);
		l_zbr_p = roundNumber(l_zbr_p, 2);
		
		document.getElementById('formfield_' + f7 + l_name).value = l_zbr_p;
		document.getElementById('formfield_' + f7 + l_name + '_dis').value = l_zbr_p;
		
		
		
		la_tmp = l_name.split('_');
		for(var i = 2; i < la_tmp.length; i++){
			l_name_sub = '_' + la_tmp[i];
		}
		
		var l_u_iznos = 0;
		var l_u_iznos_p = 0;
		for(i = 1; i <= a_redak[0]; i++){
			if(document.getElementById('delete_row_' + i + '_1').value == '1'){
				continue;
			}
			
			l_num1 = document.getElementById('formfield_' + f2 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num1) && l_num1 != ''){
				l_u_iznos += parseFloat(l_num1);
			}
			
			l_num2 = document.getElementById('formfield_' + f7 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num2) && l_num2 != ''){
				l_u_iznos_p += parseFloat(l_num2);
			}
		}
		
		l_u_iznos = roundNumber(l_u_iznos, 2);
		l_u_iznos_p = roundNumber(l_u_iznos_p, 2);
		
		document.getElementById('formfield_' + f11).value = l_u_iznos;
		document.getElementById('formfield_' + f11 + '_dis').value = l_u_iznos;
		document.getElementById('formfield_' + f12).value = l_u_iznos_p;
		document.getElementById('formfield_' + f12 + '_dis').value = l_u_iznos_p;
		
		// zovi samo ako te zove iz input polja... a ako te npr. zove funkcija get_marza, onda ovdje ne ulazi kako se ne bi dogodila beskonacna petlja
		if(outer_call == 0){
			var la_tmp = obj.id.split('_');
			var l_obj_id = obj.id.replace('_' + la_tmp[1] + '_', '_' + f8 + '_');
			var new_obj = document.getElementById(l_obj_id);
			get_marza(new_obj, f8, f8, f9, f6, f4, f5, f3, f10, f2, f3, f7, f11, f12, 1);
		}
	}
	
	function get_zopc_data_new(obj, f1, f2, f3, f4, f5){
		var l_name = obj.id.replace('formfield_' + f1, '');
		
		var l_npv = roundNumber(parseFloat(obj.value) * parseFloat(document.getElementById('formfield_' + f2 + l_name).value), 2);
		var l_razlika = roundNumber(parseFloat(l_npv) - parseFloat(document.getElementById('formfield_' + f3 + l_name).value), 2);
		
		document.getElementById('formfield_' + f4 + l_name).value = l_npv;
		document.getElementById('formfield_' + f4 + l_name + '_dis').value = l_npv;
		document.getElementById('formfield_' + f5 + l_name).value = l_razlika;
		document.getElementById('formfield_' + f5 + l_name + '_dis').value = l_razlika;
	}
	
	function get_zopc_data(obj, f1, f2, f3, f4, f5, f6, f7, f8){
		l_name = obj.id.replace('formfield_' + f1, '');
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_zopc_data.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				document.getElementById('formfield_' + f2 + l_name).value = la_data[0];
				document.getElementById('formfield_' + f2 + l_name + '_dis').value = la_data[0];
				document.getElementById('formfield_' + f3 + l_name).value = la_data[1];
				document.getElementById('formfield_' + f3 + l_name + '_dis').value = la_data[1];
				document.getElementById('formfield_' + f4 + l_name).value = la_data[2];
				document.getElementById('formfield_' + f5 + l_name).value = la_data[3];
				document.getElementById('formfield_' + f5 + l_name + '_dis').value = la_data[3];
				document.getElementById('formfield_' + f6 + l_name).value = la_data[4];
				document.getElementById('formfield_' + f6 + l_name + '_dis').value = la_data[4];
				document.getElementById('formfield_' + f7 + l_name).value = la_data[5];
				document.getElementById('formfield_' + f7 + l_name + '_dis').value = la_data[5];
				document.getElementById('formfield_' + f8 + l_name).value = la_data[6];
				document.getElementById('formfield_' + f8 + l_name + '_dis').value = la_data[6];
			}
		}
		xmlhttp.send(null);
	}
	
	function get_razlika_inventura(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9){
		if(obj.id.indexOf('formfield_5_') == 0 || obj.id.indexOf('formfield_6_') == 0){
			l_name = obj.id.replace('formfield_5', '').replace('formfield_6', '');
		}else{
			l_name = obj.id.replace('formfield_' + f1, '');
		}
		
		var l_zbr = document.getElementById('formfield_' + f1 + l_name).value - document.getElementById('formfield_' + f3 + l_name).value;
		document.getElementById('formfield_' + f2 + l_name).value = l_zbr;
		document.getElementById('formfield_' + f2 + l_name + '_dis').value = l_zbr;
		
		/*
		document.getElementById('formfield_' + f4 + l_name).value = roundNumber(l_zbr * document.getElementById('formfield_' + f6 + l_name + '_dis').value, 2);
		document.getElementById('formfield_' + f4 + l_name + '_dis').value = roundNumber(l_zbr * document.getElementById('formfield_' + f6 + l_name + '_dis').value, 2);
		document.getElementById('formfield_' + f5 + l_name).value = roundNumber(l_zbr * document.getElementById('formfield_' + f7 + l_name + '_dis').value, 2);
		document.getElementById('formfield_' + f5 + l_name + '_dis').value = roundNumber(l_zbr * document.getElementById('formfield_' + f7 + l_name + '_dis').value, 2);
		*/
		document.getElementById('formfield_' + f4 + l_name).value = roundNumber(l_zbr * document.getElementById('formfield_' + f6 + l_name).value, 2);
		document.getElementById('formfield_' + f4 + l_name + '_dis').value = roundNumber(l_zbr * document.getElementById('formfield_' + f6 + l_name).value, 2);
		document.getElementById('formfield_' + f5 + l_name).value = roundNumber(l_zbr * document.getElementById('formfield_' + f7 + l_name).value, 2);
		document.getElementById('formfield_' + f5 + l_name + '_dis').value = roundNumber(l_zbr * document.getElementById('formfield_' + f7 + l_name).value, 2);
		
		la_tmp = l_name.split('_');
		for(var i = 2; i < la_tmp.length; i++){
			l_name_sub = '_' + la_tmp[i];
		}
		
		var l_u_iznos = 0;
		var l_u_iznos_p = 0;
		for(i = 1; i <= a_redak[0]; i++){
			if(document.getElementById('delete_row_' + i + '_1').value == '1'){
				continue;
			}
			
			l_num1 = document.getElementById('formfield_' + f4 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num1) && l_num1 != ''){
				l_u_iznos += parseFloat(l_num1);
			}
			
			l_num2 = document.getElementById('formfield_' + f5 + '_' + i + l_name_sub).value;
			if(!isNaN(l_num2) && l_num2 != ''){
				l_u_iznos_p += parseFloat(l_num2);
			}
		}
		
		l_u_iznos = roundNumber(l_u_iznos, 2);
		l_u_iznos_p = roundNumber(l_u_iznos_p, 2);
		
		document.getElementById('formfield_' + f8).value = l_u_iznos;
		document.getElementById('formfield_' + f8 + '_dis').value = l_u_iznos;
		document.getElementById('formfield_' + f9).value = l_u_iznos_p;
		document.getElementById('formfield_' + f9 + '_dis').value = l_u_iznos_p;
	}
	
	function get_proizv_medjuskl_data_kolicina(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10){
		l_name = obj.id.replace('formfield_' + f1, '');
		
		//alert(document.getElementById('formfield_' + f1 + l_name).value);
		//alert(document.getElementById('formfield_' + f2 + l_name).value);
		//return;
		
		if(document.getElementById('formfield_' + f2 + l_name).value != 'NULL'){
			l_uk_nc = parseFloat(document.getElementById('formfield_' + f1 + l_name).value) * 
				parseFloat(document.getElementById('formfield_' + f3 + l_name).value);
			l_uk_pc = parseFloat(document.getElementById('formfield_' + f1 + l_name).value) * 
				parseFloat(document.getElementById('formfield_' + f4 + l_name).value);
				
			document.getElementById('formfield_' + f7 + l_name).value = l_uk_nc;
			document.getElementById('formfield_' + f7 + l_name + '_dis').value = l_uk_nc;
			document.getElementById('formfield_' + f8 + l_name).value = l_uk_pc;
			document.getElementById('formfield_' + f8 + l_name + '_dis').value = l_uk_pc;
			
			
			la_tmp = l_name.split('_');
			for(var i = 2; i < la_tmp.length; i++){
				l_name_sub = '_' + la_tmp[i];
			}
			
			var l_u_iznos = 0;
			var l_u_iznos_p = 0;
			for(i = 1; i <= a_redak[0]; i++){
				if(document.getElementById('delete_row_' + i + '_1').value == '1'){
					continue;
				}
				
				l_num1 = document.getElementById('formfield_' + f7 + '_' + i + l_name_sub).value;
				if(!isNaN(l_num1) && l_num1 != ''){
					l_u_iznos += parseFloat(l_num1);
				}
				
				l_num2 = document.getElementById('formfield_' + f8 + '_' + i + l_name_sub).value;
				if(!isNaN(l_num2) && l_num2 != ''){
					l_u_iznos_p += parseFloat(l_num2);
				}
			}
			
			l_u_iznos = roundNumber(l_u_iznos, 2);
			l_u_iznos_p = roundNumber(l_u_iznos_p, 2);
		
			document.getElementById('formfield_' + f9).value = l_u_iznos;
			document.getElementById('formfield_' + f9 + '_dis').value = l_u_iznos;
			document.getElementById('formfield_' + f10).value = l_u_iznos_p;
			document.getElementById('formfield_' + f10 + '_dis').value = l_u_iznos_p;
		}
	}
	
	function get_proizv_medjuskl_data(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10){
		l_name = obj.id.replace('formfield_' + f1, '');
		
		//document.write(g_path_sl_res + 'aj/get_proizv_medjuskl_data.php?value=' + obj.value);
		//return;
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_proizv_medjuskl_data.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				document.getElementById('formfield_' + f3 + l_name).value = la_data[0];
				document.getElementById('formfield_' + f3 + l_name + '_dis').value = la_data[0];
				document.getElementById('formfield_' + f4 + l_name).value = la_data[1];
				document.getElementById('formfield_' + f4 + l_name + '_dis').value = la_data[1];
				document.getElementById('formfield_' + f5 + l_name).value = la_data[2];
				document.getElementById('formfield_' + f5 + l_name + '_dis').value = la_data[2];
				document.getElementById('formfield_' + f6 + l_name).value = la_data[3];
				document.getElementById('formfield_' + f6 + l_name + '_dis').value = la_data[3];
				
				if(document.getElementById('formfield_' + f2 + l_name).value != ''){
					l_uk_nc = parseFloat(document.getElementById('formfield_' + f2 + l_name).value) * 
						parseFloat(document.getElementById('formfield_' + f3 + l_name).value);
					l_uk_pc = parseFloat(document.getElementById('formfield_' + f2 + l_name).value) * 
						parseFloat(document.getElementById('formfield_' + f4 + l_name).value);
					document.getElementById('formfield_' + f7 + l_name).value = l_uk_nc;
					document.getElementById('formfield_' + f7 + l_name + '_dis').value = l_uk_nc;
					document.getElementById('formfield_' + f8 + l_name).value = l_uk_pc;
					document.getElementById('formfield_' + f8 + l_name + '_dis').value = l_uk_pc;
					
					
					la_tmp = l_name.split('_');
					for(var i = 2; i < la_tmp.length; i++){
						l_name_sub = '_' + la_tmp[i];
					}
					
					var l_u_iznos = 0;
					var l_u_iznos_p = 0;
					for(i = 1; i <= a_redak[0]; i++){
						if(document.getElementById('delete_row_' + i + '_1').value == '1'){
							continue;
						}
						
						l_num1 = document.getElementById('formfield_' + f7 + '_' + i + l_name_sub).value;
						if(!isNaN(l_num1) && l_num1 != ''){
							l_u_iznos += parseFloat(l_num1);
						}
						
						l_num2 = document.getElementById('formfield_' + f8 + '_' + i + l_name_sub).value;
						if(!isNaN(l_num2) && l_num2 != ''){
							l_u_iznos_p += parseFloat(l_num2);
						}
					}
					
					l_u_iznos = roundNumber(l_u_iznos, 2);
					l_u_iznos_p = roundNumber(l_u_iznos_p, 2);
				
					document.getElementById('formfield_' + f9).value = l_u_iznos;
					document.getElementById('formfield_' + f9 + '_dis').value = l_u_iznos;
					document.getElementById('formfield_' + f10).value = l_u_iznos_p;
					document.getElementById('formfield_' + f10 + '_dis').value = l_u_iznos_p;
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function get_inventura_data(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10){
		l_name = obj.id.replace('formfield_' + f1, '');
		
		//document.write(g_path_sl_res + 'aj/get_inventura_data.php?value=' + obj.value);
		//return;
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_inventura_data.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				document.getElementById('formfield_' + f2 + l_name).value = la_data[0];
				//document.getElementById('formfield_' + f2 + l_name + '_dis').value = la_data[0];
				document.getElementById('formfield_' + f3 + l_name).value = la_data[1];
				//document.getElementById('formfield_' + f3 + l_name + '_dis').value = la_data[1];
				document.getElementById('formfield_' + f4 + l_name).value = la_data[2];
				document.getElementById('formfield_' + f4 + l_name + '_dis').value = la_data[2];
				document.getElementById('formfield_' + f6 + l_name).value = 0;
				document.getElementById('formfield_' + f6 + l_name + '_dis').value = 0;
				
				document.getElementById('formfield_' + f5 + l_name).value = la_data[2];
				document.getElementById('formfield_' + f5 + l_name).focus();
				document.getElementById('formfield_' + f5 + l_name).select();
				
				
				var la_tmp = obj.id.split('_');
				var l_obj_id = obj.id.replace('_' + la_tmp[1] + '_', '_' + f5 + '_');
				var new_obj = document.getElementById(l_obj_id);
				get_razlika_inventura(new_obj, f5, f6, f4, f7, f8, f2, f3, f9, f10);
			}
		}
		xmlhttp.send(null);
	}
	
	var ga_pdv = new Array();
	function get_artikl_nc_pc_popust(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13){
		l_name = obj.id.replace('formfield_' + f1, '');
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_artikl_nc_pc_popust.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				document.getElementById('formfield_' + f2 + l_name).value = la_data[0];
				
				document.getElementById('formfield_' + f3 + l_name).value = la_data[1];
				if(eval(document.getElementById('formfield_' + f3 + l_name + '_dis'))){
					document.getElementById('formfield_' + f3 + l_name + '_dis').value = la_data[1];
				}
				
				document.getElementById('formfield_' + f4 + l_name).value = la_data[2];
				ga_pdv[l_name] = la_data[3];
				//alert(ga_pdv[l_name]);
				document.getElementById('formfield_' + f5 + l_name).focus();
				document.getElementById('formfield_' + f5 + l_name).select();
				
				
				document.getElementById('formfield_' + f13 + l_name).value = la_data[4];
				if(eval(document.getElementById('formfield_' + f13 + l_name + '_dis'))){
					document.getElementById('formfield_' + f13 + l_name + '_dis').value = la_data[4];
				}
				
				
				var la_tmp = obj.id.split('_');
				var l_obj_id = obj.id.replace('_' + la_tmp[1] + '_', '_' + f5 + '_');
				var new_obj = document.getElementById(l_obj_id);
				get_iznos_primka(new_obj, f5, f9, f5, f2, f4, f3, f10, f6, f7, f8, f11, f12, 0);
			}
		}
		xmlhttp.send(null);
	}
	
	function get_artikl_nc_pc_last_primka(obj, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13){
		l_name = obj.id.replace('formfield_' + f1, '');
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_artikl_nc_pc_last_primka.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				document.getElementById('formfield_' + f2 + l_name).value = la_data[0];
				
				document.getElementById('formfield_' + f3 + l_name).value = la_data[1];
				if(eval(document.getElementById('formfield_' + f3 + l_name + '_dis'))){
					document.getElementById('formfield_' + f3 + l_name + '_dis').value = la_data[1];
				}
				
				document.getElementById('formfield_' + f4 + l_name).value = la_data[2];
				ga_pdv[l_name] = la_data[3];
				//alert(ga_pdv[l_name]);
				document.getElementById('formfield_' + f5 + l_name).focus();
				document.getElementById('formfield_' + f5 + l_name).select();
				
				
				document.getElementById('formfield_' + f13 + l_name).value = la_data[4];
				if(eval(document.getElementById('formfield_' + f13 + l_name + '_dis'))){
					document.getElementById('formfield_' + f13 + l_name + '_dis').value = la_data[4];
				}
				
				
				var la_tmp = obj.id.split('_');
				var l_obj_id = obj.id.replace('_' + la_tmp[1] + '_', '_' + f5 + '_');
				var new_obj = document.getElementById(l_obj_id);
				get_iznos_primka(new_obj, f5, f9, f5, f2, f4, f3, f10, f6, f7, f8, f11, f12, 0);
			}
		}
		xmlhttp.send(null);
	}
	
	
	function get_cijena_fields(obj, f1, f2, f3, f4, f5, f6, f7){
		l_name = obj.id.replace('formfield_' + f1, '');
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_cijena_fields.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				
				document.getElementById('formfield_' + f2 + l_name).value = la_data[0];
				document.getElementById('formfield_' + f3 + l_name).value = la_data[1];
				document.getElementById('formfield_' + f4 + l_name).value = la_data[2];
				document.getElementById('formfield_' + f4 + l_name + '_dis').value = la_data[2];
				document.getElementById('formfield_' + f5 + l_name).value = la_data[3];
				document.getElementById('formfield_' + f6 + l_name).value = la_data[4];
				document.getElementById('formfield_' + f7 + l_name).value = la_data[5];
				
			}
		}
		xmlhttp.send(null);
	}
	
	function get_iznos_kn(f1, f2, f3, f4, f5){
		l_value = document.getElementById('formfield_' + f2).value * document.getElementById('formfield_' + f5).value;
		document.getElementById('formfield_' + f3).value = l_value;
		document.getElementById('formfield_' + f3 + '_dis').value = l_value;
	}
	
	function get_kupac_data(obj, f1, f2, f3, f4, f5){
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_kupac_data.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				document.getElementById('formfield_' + f1).value = la_data[0];
				document.getElementById('formfield_' + f1 + '_dis').value = la_data[0];
				document.getElementById('formfield_' + f2).value = la_data[1];
				document.getElementById('formfield_' + f2 + '_dis').value = la_data[1];
				document.getElementById('formfield_' + f3).value = la_data[2];
				document.getElementById('formfield_' + f3 + '_dis').value = la_data[2];
				document.getElementById('formfield_' + f4).value = la_data[3];
				document.getElementById('formfield_' + f4 + '_dis').value = la_data[3];
				document.getElementById('formfield_' + f5).value = la_data[4];
				document.getElementById('formfield_' + f5 + '_dis').value = la_data[4];
			}
		}
		xmlhttp.send(null);
	}
	
	function get_tecaj_value(obj, field, more){
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_tecaj_value.php?value=' + obj.value);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				result = xmlhttp.responseText;
				document.getElementById('formfield_' + field).value = result;
				if(more != 'false'){
					get_iznos_kn('13', '9', '14', '12', '13');
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function onchange_more(id){
		document.getElementById(id.replace('_dis', '')).value = document.getElementById(id).value;
	}
	
	function switch_field(obj_val, data){
		//alert(data);
		//alert(obj_val);
		la_data = data.split(',');
		for(var i = 0; i < la_data.length; i++){
			if(i % 2 == 1){
				document.getElementById('formfield_' + la_data[i] + '_dis').disabled = true;
				//alert(la_data[i - 1]);
				if(obj_val != la_data[i - 1]){
					document.getElementById('formfield_' + la_data[i] + '_dis').selectedIndex = 'NULL';
					document.getElementById('formfield_' + la_data[i]).value = '';
				}
			}
		}
		for(var i = 0; i < la_data.length; i++){
			if(i % 2 == 0 && obj_val == la_data[i]){
				//alert(i + ' ' + la_data[i] + ' ' + la_data[i + 1]);
				document.getElementById('formfield_' + la_data[i + 1] + '_dis').disabled = false;
			}
		}
	}
	
	var sfTabTableTab = 0;
	function move_left_right(rbr, max_rbr){
		if(rbr == 2){
			if(sfTabTableTab < max_rbr - 1){
				sfTabTableTab++;
				for(var i = 0; i < sfTabTableTab; i++){
					document.getElementById('sfTabTableTab_' + i).style.display = 'none';
				}
			}
		}else{
			if(sfTabTableTab > 0){
				sfTabTableTab--;
				for(var i = sfTabTableTab; i <= sfTabTableTab; i++){
					document.getElementById('sfTabTableTab_' + i).style.display = 'block';
				}
			}
		}
	}
	
	function submitCSS(rbr){
		la_classes = document.getElementById('defaultCSSActiveP').innerHTML.split(' :::: ');
		l_classes = la_classes[0];
		
		la_tmp = l_classes.split(' ');
		l_tmp = la_tmp[0].replace('.', '');
		
		la_tmp_2 = la_tmp[1].replace('.', '').split('-');
		
		l_tmp_2 = la_tmp_2[0] + '-';
		if(l_tmp_2[0] == 'f'){
			l_tmp_2i = l_tmp_2.replace('f', 'i');
		}
		if(l_tmp_2[0] == 'i'){
			l_tmp_2i = l_tmp_2.replace('i', 'f');
		}
		
		la_changes = new Array();
		
		var alls = document.getElementById('formcss' + l_tmp).getElementsByTagName('*');
		for(var i = 0; i < alls.length; i++){
			for(var j = 0; j < 220; j++){
				//alert(l_tmp_2 + j);
				if(alls[i].className == l_tmp_2 + j){
					l_obj_selected = alls[i];
					if(l_obj_selected.style.cssText){
						//alert(alls[i].className + ' ' + l_obj_selected.style.cssText);
						la_changes[alls[i].className] = l_obj_selected.style.cssText;
					}
					break;
				}
			}
			for(var j = 0; j < 220; j++){
				//alert(l_tmp_2i + j);
				if(alls[i].className == l_tmp_2i + j){
					l_obj_selected = alls[i];
					if(l_obj_selected.style.cssText){
						//alert(alls[i].className + ' ' + l_obj_selected.style.cssText);
						la_changes[alls[i].className] = l_obj_selected.style.cssText;
					}
					break;
				}
			}
		}
		
		var a = '';
		var b = '';
		for(var i in la_changes){
			a = a + i + '#';
			b = b + la_changes[i] + '{_#_}';
			//alert(i + " -> " + la_changes[i]);
		}
		//alert(a);
		//alert(b);
		
		a = encodeURIComponent(a);
		b = encodeURIComponent(b);
		
		//document.write(g_path_sl_res + 'aj/css_gen.php?rbr=' + rbr + '&a=' + a + '&b=' + b);
		//return;
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/css_gen.php?rbr=' + rbr + '&a=' + a + '&b=' + b);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				//alert('res/css/klasa/css-5' + rbr + '-' + xmlhttp.responseText + '.css');
				document.getElementById('cssforma').href = 'res/css/klasa/css-5' + rbr + '-' + xmlhttp.responseText + '.css';
			}
		}
		xmlhttp.send(null);
		
		
	}
	
	function esizeCSS(action){
		la_classes = document.getElementById('defaultCSSActiveE').innerHTML.split(' :::: ');
		l_classes = la_classes[0];
		
		la_tmp = l_classes.split(' ');
		
		l_tmp = la_tmp[0].replace('.', '');
		l_tmp_2 = la_tmp[1].replace('.', '');
		
		
		var alls = document.getElementById('formcss' + l_tmp).getElementsByTagName('*');
		for(var i = 0; i < alls.length; i++){
			if(alls[i].className == l_tmp_2){
				l_obj_selected = alls[i];
				break;
			}
		}
				
		l_css_str = l_obj_selected.style.cssText;
		
		switch(action){
			case 1:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) - parseInt(5);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 2:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) - parseInt(20);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 3:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) - parseInt(40);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 4:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) + parseInt(40);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 5:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) + parseInt(20);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 6:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) + parseInt(5);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 7:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) + parseInt(4);
				l_css_str += 'height:' + l_height + 'px;';
				break;
				
			case 8:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) + parseInt(20);
				l_css_str += 'height:' + l_height + 'px;';
				break;
				
			case 9:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) + parseInt(40);
				l_css_str += 'height:' + l_height + 'px;';
				break;
				
			case 10:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) - parseInt(40);
				l_css_str += 'height:' + l_height + 'px;';
				break;
				
			case 11:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) - parseInt(20);
				l_css_str += 'height:' + l_height + 'px;';
				break;
				
			case 12:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) - parseInt(4);
				l_css_str += 'height:' + l_height + 'px;';
				break;
		}
		
		l_obj_selected.style.cssText = l_css_str;
		
		document.getElementById('defaultCSSActiveE').innerHTML = l_classes + ' :::: ' + l_obj_selected.style.cssText;
	}
	
	
	function psizeCSS(action){
		la_classes = document.getElementById('defaultCSSActiveP').innerHTML.split(' :::: ');
		l_classes = la_classes[0];
		
		la_tmp = l_classes.split(' ');
		
		l_tmp = la_tmp[0].replace('.', '');
		l_tmp_2 = la_tmp[1].replace('.', '');
		
		var divs = document.getElementById('formcss' + l_tmp).getElementsByTagName('DIV');
		for(var i = 0; i < divs.length; i++){
			if(divs[i].className == l_tmp_2){
				l_obj_selected = divs[i];
				break;
			}
		}
				
		l_css_str = l_obj_selected.style.cssText;
		
		//alert(l_css_str);
		
		switch(action){
			case 1:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) - parseInt(5);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 2:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) - parseInt(20);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 3:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) - parseInt(40);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 4:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) + parseInt(40);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 5:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) + parseInt(20);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 6:
				l_width = l_obj_selected.style.width.replace('px', '');
				l_width = parseInt(l_width) + parseInt(5);
				l_css_str += 'width:' + l_width + 'px;';
				break;
				
			case 7:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) - parseInt(5);
				l_css_str += 'height:' + l_height + 'px;';
				break;
				
			case 8:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) - parseInt(20);
				l_css_str += 'height:' + l_height + 'px;';
				break;
				
			case 9:
				l_height = l_obj_selected.style.height.replace('px', '');
				l_height = parseInt(l_height) - parseInt(40);
				l_css_str += 'height:' + l_height + 'px;';
				break;
		}
		
		//l_obj_selected.style.cssText = l_css_str + ' background-color:red; ';
		
		l_obj_selected.style.cssText = l_css_str;
		
		document.getElementById('defaultCSSActiveP').innerHTML = l_classes + ' :::: ' + l_obj_selected.style.cssText;
	}
	
	function moveCSS(action){
		la_classes = document.getElementById('defaultCSSActiveP').innerHTML.split(' :::: ');
		l_classes = la_classes[0];
		
		la_tmp = l_classes.split(' ');
		
		l_tmp = la_tmp[0].replace('.', '');
		l_tmp_2 = la_tmp[1].replace('.', '');
		
		var divs = document.getElementById('formcss' + l_tmp).getElementsByTagName('DIV');
		for(var i = 0; i < divs.length; i++){
			if(divs[i].className == l_tmp_2){
				l_obj_selected = divs[i];
				break;
			}
		}
				
		l_css_str = l_obj_selected.style.cssText;
		
		switch(action){
			case 1:
				l_left = l_obj_selected.style.left.replace('px', '');
				l_left = parseInt(l_left) - parseInt(5);
				l_css_str += 'left:' + l_left + 'px;';
				break;
				
			case 2:
				l_left = l_obj_selected.style.left.replace('px', '');
				l_left = parseInt(l_left) - parseInt(20);
				l_css_str += 'left:' + l_left + 'px;';
				break;
				
			case 3:
				l_left = l_obj_selected.style.left.replace('px', '');
				l_left = parseInt(l_left) - parseInt(40);
				l_css_str += 'left:' + l_left + 'px;';
				break;
				
			case 4:
				l_left = l_obj_selected.style.left.replace('px', '');
				l_left = parseInt(l_left) + parseInt(40);
				l_css_str += 'left:' + l_left + 'px;';
				break;
				
			case 5:
				l_left = l_obj_selected.style.left.replace('px', '');
				l_left = parseInt(l_left) + parseInt(20);
				l_css_str += 'left:' + l_left + 'px;';
				break;
				
			case 6:
				l_left = l_obj_selected.style.left.replace('px', '');
				l_left = parseInt(l_left) + parseInt(5);
				l_css_str += 'left:' + l_left + 'px;';
				break;
				
			case 7:
				l_top = l_obj_selected.style.top.replace('px', '');
				l_top = parseInt(l_top) - parseInt(5);
				l_css_str += 'top:' + l_top + 'px;';
				break;
				
			case 8:
				l_top = l_obj_selected.style.top.replace('px', '');
				l_top = parseInt(l_top) - parseInt(20);
				l_css_str += 'top:' + l_top + 'px;';
				break;
				
			case 9:
				l_top = l_obj_selected.style.top.replace('px', '');
				l_top = parseInt(l_top) - parseInt(40);
				l_css_str += 'top:' + l_top + 'px;';
				break;
				
			case 10:
				l_top = l_obj_selected.style.top.replace('px', '');
				l_top = parseInt(l_top) + parseInt(40);
				l_css_str += 'top:' + l_top + 'px;';
				break;
				
			case 11:
				l_top = l_obj_selected.style.top.replace('px', '');
				l_top = parseInt(l_top) + parseInt(20);
				l_css_str += 'top:' + l_top + 'px;';
				break;
				
			case 12:
				l_top = l_obj_selected.style.top.replace('px', '');
				l_top = parseInt(l_top) + parseInt(5);
				l_css_str += 'top:' + l_top + 'px;';
				break;
		}
		
		l_obj_selected.style.cssText = l_css_str;
		
		document.getElementById('defaultCSSActiveP').innerHTML = l_classes + ' :::: ' + l_obj_selected.style.cssText;
	}
	
	function selectP(obj){
		l_obj = obj.parentNode.parentNode;
		l_class = l_obj.className;
		
		l_obj_form = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
		
		l_class_connect = '.' + l_obj_form.className + ' .' + l_class;
		l_class_connectE = '.' + l_obj_form.className + ' .' + l_class.replace('f', 'i');
		
		
		l_objP = obj.parentNode.parentNode;
		l_objE = obj.parentNode.parentNode;
		
		for(var i = 0;  i < document.styleSheets.length; i++){
			if(document.styleSheets[i].href && document.styleSheets[i].href.indexOf('/klasa/') >= 0){
				
				for(var j = 0;  j < document.styleSheets[i].cssRules.length; j++){
				
				
					if(document.styleSheets[i].cssRules[j].selectorText == l_class_connect){
					
						document.getElementById('defaultCSSActiveP').innerHTML= l_class_connect;
						
						la_css = document.styleSheets[i].cssRules[j].cssText.split('{');
						l_css_str = la_css[1].replace('}', '');
						
						if(!l_objP.style.cssText){
							l_objP.style.cssText = l_css_str;
						}
						
					}
					
					
					if(document.styleSheets[i].cssRules[j].selectorText == l_class_connectE){
					
						document.getElementById('defaultCSSActiveE').innerHTML= l_class_connectE;
						
						la_css = document.styleSheets[i].cssRules[j].cssText.split('{');
						l_css_str = la_css[1].replace('}', '');
						
						
						var alls = l_objE.getElementsByTagName('*');
						for(var k = 0; k < alls.length; k++){
							if(alls[k].className == l_class.replace('f', 'i')){
								l_objE = alls[k];
								break;
							}
						}
						
						
						if(!l_objE.style.cssText){
							l_objE.style.cssText = l_css_str;
						}
					}
					
				}
			}
		}
		
		
		var divs = l_obj_form.getElementsByTagName('DIV');
		for(var i = 0; i < divs.length; i++){
			la_tmp = divs[i].className.split('-');
			if(divs[i].className.indexOf('f') == 0 && la_tmp.length == 2){
				if(document.all){
					divs[i].style.removeAttribute('background-color');
				}else{
					divs[i].style.removeProperty('background-color');
				}
			}
		}
		
		l_objP.style.cssText = l_obj.style.cssText + ' background-color:gray; ';
	}
	
	/*
	function selectE(obj){
		l_obj = obj.parentNode.parentNode;
		l_class = l_obj.className.replace('f', 'i');
		
		l_class_connect = '.' + obj.parentNode.parentNode.parentNode.parentNode.parentNode.className + ' .' + l_class;
		
		for(var i = 0;  i < document.styleSheets.length; i++){
			if(document.styleSheets[i].href && document.styleSheets[i].href.indexOf('/klasa/') >= 0){
				for(var j = 0;  j < document.styleSheets[i].cssRules.length; j++){
					if(document.styleSheets[i].cssRules[j].selectorText == l_class_connect){
						
						document.getElementById('defaultCSSActiveP').innerHTML= l_class_connect;
						
						la_css = document.styleSheets[i].cssRules[j].cssText.split('{');
						l_css_str = la_css[1].replace('}', '');
						
						
						var alls = l_obj.getElementsByTagName('*');
						for(var k = 0; k < alls.length; k++){
							if(alls[k].className == l_class){
								l_obj = alls[k];
								break;
							}
						}
						
						
						if(!l_obj.style.cssText){
							l_obj.style.cssText = l_css_str;
						}
						
						break;
					}
				}
			}
		}
	}
	*/
	
	function genDefCSS(rbr){
		//alert(rbr);
		xmlhttp.open("GET", g_path_sl_res + 'aj/css_gen.php?rbr=' + rbr + '&a=-1&b=-1');
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				//alert('res/css/klasa/css-5' + rbr + '-' + xmlhttp.responseText + '.css');
				document.getElementById('cssforma').href = 'res/css/klasa/css-5' + rbr + '-' + xmlhttp.responseText + '.css';
			}
		}
		xmlhttp.send(null);
	}
	
	function alarm_pin(rbr){
		xmlhttp.open("GET", g_path_sl_res + 'aj/alarm.php?type=2&rbr=' + rbr);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var l_tmp = xmlhttp.responseText;
				if(l_tmp == '0'){
					document.getElementById('pin-img-' + rbr).src = 'res/images/pin.gif';
				}
				if(l_tmp == '1'){
					document.getElementById('pin-img-' + rbr).src = 'res/images/pin-on.gif';
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function alarm_close(rbr){
		xmlhttp.open("GET", g_path_sl_res + 'aj/alarm.php?type=1&rbr=' + rbr);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var l_tmp = xmlhttp.responseText;
				if(l_tmp == '1'){
					document.getElementById('alarm-' + rbr).style.display = 'none';
				}
			}
		}
		xmlhttp.send(null);
	}
	
	
	function check_click_label(obj){
		var la_tmp;
		//alert(obj.value);
		var cbs = obj.parentNode.parentNode.parentNode.getElementsByTagName('INPUT');
		for(var i = 0; i < cbs.length; i++){
			if(cbs[i].type == 'checkbox'){
				la_tmp = cbs[i].className.split(' ');
				if(la_tmp[0] == 'checkbox-click'){
					var bs = cbs[i].parentNode.parentNode.getElementsByTagName('B');
					if(obj.value.indexOf('{' + bs[0].innerHTML + '}') == -1){
						cbs[i].checked = false;
					}else{
						cbs[i].checked = true;
					}
				}
			}
		}
	}
	
	function cb_click_label(obj, rbr, value){
		//alert(obj.checked);
		
		if(obj.checked){
			document.getElementById('formfield_' + rbr).value += '{' + value + '}';
		}else{
			//alert(document.getElementById('formfield_' + rbr).value + ' xxx ' + '{' + value + '}' + "\r\n");
			document.getElementById('formfield_' + rbr).value = document.getElementById('formfield_' + rbr).value.replace('{' + value + '}', '');
		}
	}
	
	function submitThisFormAndBack(sid_grupa, rbr){
		if(no_submit == 1){
			return;
		}
		obj = document.getElementById('mainContent');
		var forms = obj.getElementsByTagName('FORM');
		for(var i = 0; i < forms.length; i++){
			if(forms[i].name.substring(0, 6) == 'forma_'){
				forms[i].spremi_i_dodaj.value = '1';
				forms[i].spremi_i_dodaj_grupa.value = sid_grupa;
				forms[i].spremi_i_dodaj_back_rbr.value = rbr;
				if(checkfields(forms[i].name)){
					forms[i].submit();
				}
			}
		}
	}
	
	function submitThisForm(){
		if(no_submit == 1){
			return;
		}
		obj = document.getElementById('mainContent');
		var forms = obj.getElementsByTagName('FORM');
		for(var i = 0; i < forms.length; i++){
			//alert(forms[i].name);
			if(forms[i].name.substring(0, 6) == 'forma_'){
				if(checkfields(forms[i].name)){
					forms[i].submit();
				}
			}
		}
	}
	
	function opcl_connectFields(obj, id, value, connect){
		if(document.getElementById('connectFields_' + id).style.display == 'block'){
			obj.innerHTML = '+';
			close_layer('connectFields_' + id);
		}else{
			obj.innerHTML = '-';
			makerequest(g_path_sl_res + 'aj/connectFields_fill.php?id=' + id + '&value=' + encodeURIComponent(value) + 
				'&connect=' + encodeURIComponent(connect), 'connectFields_' + id);
			open_layer('connectFields_' + id);
		}
	}
	
	function setMemo(id){
		l_result = document.getElementById('fmemo_' + id).value;
		
		document.getElementById('formfield_' + id).value = l_result;
		document.getElementById('formfield_' + id + '_dis').value = l_result;
		close_layer('memo_' + id);
	}
	
	var a_select_ajax = new Array();
	function select_ajax_fill(obj, rbr, id, addition){
		//alert('1');
		//document.write(g_path_sl_res + 'aj/select_ajax_fill.php?rbr=' + rbr + '&id=' + id + '&selected=' + selected);
		//return;
		
		if(a_select_ajax[obj.id] == 'undefined'){
			a_select_ajax[obj.id] = 1;
		}else{
			if(a_select_ajax[obj.id] == 1){
				a_select_ajax[obj.id] = 0;
				return;
			}
			a_select_ajax[obj.id] = 1;
		}
		
		xmlhttp.open("GET", g_path_sl_res + 'aj/select_ajax_fill.php?rbr=' + rbr + '&id=' + id + '&addition=' + addition);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				//alert(obj.innerHTML);
				//alert(a_select_ajax[obj.id]);
				
				l_obj_value = obj.value;
				
				for(var i = obj.options.length - 1; i >= 0; i--){
					obj.remove(i);
				}
				
				var opt;
				
				opt = document.createElement("option");
				opt.value = 'NULL';
				opt.text = ' -- ';
				obj.appendChild(opt);
					
				for(var i = 0; i < la_data.length; i++){
					opt = document.createElement("option");
					opt.value = la_data[i]['rbr'];
					opt.text = la_data[i]['ime'];
					obj.appendChild(opt);
				}
				
				if(l_obj_value == 'NULL'){
				}else{
					obj.value = l_obj_value;
				}
				
			}
		}
		xmlhttp.send(null);
	}
	
	var mydropdown_id;
	function setMultiMydropdown(id, rbr, value){
		document.getElementById('formfield_' + id).value = rbr;
		document.getElementById('formfield_' + id + '_dis').value = value;
		mydropdown_id = id;
		//get_artikl_nc_pc_popust(document.getElementById('formfield_' + id), '2', '5', '6', '7', '3', '8', '9', '10', '4', '12');
		get_inventura_data(document.getElementById('formfield_' + id), '2', '5', '6', '15', '16', '3') ;
		close_layer('multimydropdown_' + id);
	}
	
	function setMultiDD(id){
		obj = document.getElementById('fmultidd_' + id);
		var is = obj.getElementsByTagName('INPUT');
		var l_result = '';
		for(var i = 0; i < is.length; i++){
			if(is[i].checked){
				l_result += ', ' + is[i].value;
			}
		}
		l_result = l_result.substring(2);
		document.getElementById('formfield_' + id).value = l_result;
		document.getElementById('formfield_' + id + '_dis').value = l_result;
		close_layer('multidd_' + id);
	}
	
	function opcl_memo(id){
		makerequest(g_path_sl_res + 'aj/memo_fill.php?id=' + id + '&value=' + encodeURIComponent(document.getElementById('formfield_' + id).value), 'memo_' + id);
		open_layer('memo_' + id);
	}
	
	function opcl_mydropdown(id, rules){
		makerequest(g_path_sl_res + 'aj/multimydropdown_fill.php?id=' + id + '&rules=' + rules +
			'&value=' + document.getElementById('formfield_' + id).value, 'multimydropdown_' + id);
		open_layer('multimydropdown_' + id);
	}
	
	function opcl_multidd(id, rules){
		//alert(rules);
		//document.write(g_path_sl_res + 'aj/multidd_fill.php?id=' + id + '&rules=' + rules +
			//'&value=' + encodeURIComponent(document.getElementById('formfield_' + id).value), 'multidd_' + id);
		//return;
		//alert(document.getElementById('formfield_' + id).value);
		//alert(encodeURIComponent(document.getElementById('formfield_' + id).value));
		makerequest(g_path_sl_res + 'aj/multidd_fill.php?id=' + id + '&rules=' + rules +
			'&value=' + encodeURIComponent(document.getElementById('formfield_' + id).value), 'multidd_' + id);
		open_layer('multidd_' + id);
	}
	
	var no_submit;
	function checkfieldsLogin(obj, rbr){
		xmlhttp.open("GET", g_path_sl_res + 'aj/check_double_login.php?value=' + obj.value + '&rbr=' + rbr);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var l_tmp = xmlhttp.responseText;
				if(l_tmp == '-1'){
					obj.style.background = "#ffffc2";
					obj.title = "";
					no_submit = 0;
				}else{
					obj.style.background = "#ffadad url(res/images/b-stop-login.gif) no-repeat center 5px";
					obj.title = "Korisničko ime već postoji";
					obj.focus();
					no_submit = 1;
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function checkfields(form_name){
		var is_false = 0;
		var la_data = new Array();
		
		var la_value = new Array();
		var la_table = new Array();
		
		//alert(document.getElementById('subform_lines_0').value);
		
		la_value[0] = document.getElementById("checkfieldsvalue").value;
		la_table[0] = form_name;
		
		if(eval(document.getElementById("subform_tabs"))){
			for(var i = 0; i < document.getElementById("subform_tabs").value; i++){
				la_value[i + 1] = document.getElementById("checkfieldsvalue_" + i).value;
				//la_table[i + 1] = document.getElementById("checkfieldsform_" + i).value;
				la_table[i + 1] = form_name;
			}
		}
		
		for(i = 0; i < la_value.length; i++){
			if(la_value[i] == ''){
				continue;
			}
		
			la_data = la_value[i].split(':');
			
			//alert('mandatory: ' + la_data.length);
				
			for(j = 0; j < la_data.length; j++){
				
				if(i == 0){
					l_lines_num = 1;
				}else{
					//alert('::' + document.getElementById('subform_lines_0').value);
					//alert('::: ' + i + ' :' + document.getElementById("subform_lines_" + i).value);
					l_lines_num = document.getElementById("subform_lines_" + parseInt(i - 1)).value;
				}
				
				//alert('num: ' + l_lines_num);
				
				for(l_line = 1; l_line <= l_lines_num; l_line++){
					if(i == 0){
						l_lines_add = '';
						l_tab_add = '';
					}else{
						l_lines_add = '_' + l_line;
						l_tab_add = '_' + i;
					}
					
					//alert('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add);
					//continue;
					
					//alert('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add);
					//alert(obj);
					
					if(i == 0){
						//alert('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add);
						var obj = eval('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add);
						if(typeof(obj) == 'undefined'){
							var obj = eval('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add + '_dis');
						}
						//alert(obj);
						if(obj.tagName == 'SELECT'){
							var bs = obj.parentNode.parentNode.parentNode.getElementsByTagName("B");
						}else{
							var bs = obj.parentNode.parentNode.getElementsByTagName("B");
						}
						for(var k = 0; k < bs.length; k++){
							if(obj.value == "" || obj.value == "NULL"){
								//obj.style.background = "#ffadad";
								obj.style.background = "#ffadad url(res/images/b-stop.gif) no-repeat center 5px";
								bs[k].style.color = "red"; 
								bs[k].style.fontWeight = "bold"; 
								/*
								if(bs[k].innerHTML.indexOf("* ") == -1){
									bs[k].innerHTML = "* " + bs[k].innerHTML + "<img src='res/images/b-stop.gif' border='0' class='stopImage'>"; 
								}
								if(bs[k].innerHTML.indexOf("<img ") == -1){
									bs[k].innerHTML = bs[k].innerHTML + "<img src='res/images/b-stop.gif' border='0' class='stopImage'>"; 
								}
								*/
								is_false = 1;
							}else{
								obj.style.background = "#ffffc2";
								bs[k].style.color = "black"; 
								bs[k].style.fontWeight = "normal"; 
								/*
								bs[k].innerHTML = bs[k].innerHTML.replace("* ", ""); 
								bs[k].innerHTML = bs[k].innerHTML.replace("<img src='res/images/b-stop.gif' border='0' class='stopImage'>", ""); 
								bs[k].innerHTML = bs[k].innerHTML.replace("<img src=\"res/images/b-stop.gif\" border=\"0\" class=\"stopImage\">", ""); 
								bs[k].innerHTML = bs[k].innerHTML.replace("<img src='res/images/b-stop.gif' class='stopImage' border='0'>", ""); 
								bs[k].innerHTML = bs[k].innerHTML.replace("<img src=\"res/images/b-stop.gif\" class=\"stopImage\" border=\"0\">", ""); 
								*/
							}
						}
					}else{
						var obj = eval('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add + '_dis');
						if(typeof(obj) == 'undefined'){
							var obj = eval('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add);
						}
						
						/*
						if(i == 2){
							alert('document.' + la_table[i] + '.formfield_' + la_data[j] + l_lines_add + l_tab_add);
							alert(obj);
						}
						*/
						
						
						if(obj.value == "" || obj.value == "NULL"){
							obj.style.background = "#ffadad url(res/images/b-stop.gif) no-repeat center 5px";
							//obj.style.background = "#ffadad";
							is_false = 1;
						}else{
							obj.style.background = "#ffffc2";
						}
						
					}
						
				}
			}
		}
		
		if(is_false == 1){
			return false;
		}
		//return false;
		return true;
	}
	
	function get_max_line(obj, max_column){
		la_tmp = max_column.split('-');
		la_name = obj.name.split('_');
		
		l_max_check = la_name[0] + '_' + la_tmp[1] +  '_' + la_name[2] + '_' + la_name[3];
		is_obj = document.getElementById(l_max_check);
		if(is_obj.value == '' || parseInt(is_obj.value) != is_obj.value){
			return;
		}
		
		
		l_obj_const = la_name[0] + '_' + la_tmp[1] +  '_X_' + la_name[3];
		
		l_max_value = -1;
		result = -1;
		for(i = 1; i < 200; i++){
			l_obj_new = l_obj_const.replace('_X_', '_' + i + '_');
			if(eval(document.getElementById(l_obj_new))){
				is_obj = document.getElementById(l_obj_new);
				l_num = parseInt(is_obj.value);
				if(l_num >= 0){
					if(l_num > l_max_value){
						l_max_value = l_num;
						result = i;
					}
				}
			}else{
				break;
			}
		}
		return result;
	}
	
	function get_file_max(obj, layer, value_id, max_column){
		
		la_name = obj.name.split('_');
		l_max_line = get_max_line(obj, max_column);
		
		if(la_name[2] == l_max_line){
			var obj1 = document.getElementById(layer);
			var obj2 = document.getElementById('formfield_' + value_id);
			obj1.innerHTML = '<a href="' +obj.value + '" target="_blank"><img src="res/images/document.jpg" border="0" title="' + obj.value + '"></a>';
			obj2.value = obj.value;
		}
	}
	
	function get_value_from_form_max(obj, layer, value_id, max_column){
		/*
		la_tmp = max_column.split('-');
		la_name = obj.name.split('_');
		
		l_max_check = la_name[0] + '_' + la_tmp[1] +  '_' + la_name[2] + '_' + la_name[3];
		is_obj = document.getElementById(l_max_check);
		if(is_obj.value == '' || parseInt(is_obj.value) != is_obj.value){
			return;
		}
		
		
		l_obj_const = la_name[0] + '_' + la_tmp[1] +  '_X_' + la_name[3];
		
		l_max_value = -1;
		l_max_line = -1;
		for(i = 1; i < 200; i++){
			l_obj_new = l_obj_const.replace('_X_', '_' + i + '_');
			if(eval(document.getElementById(l_obj_new))){
				is_obj = document.getElementById(l_obj_new);
				l_num = parseInt(is_obj.value);
				if(l_num >= 0){
					if(l_num > l_max_value){
						l_max_value = l_num;
						l_max_line = i;
					}
				}
			}else{
				break;
			}
		}
		*/
		
		la_name = obj.name.split('_');
		l_max_line = get_max_line(obj, max_column);
		
		if(la_name[2] == l_max_line){
			var obj1 = document.getElementById(layer);
			var obj2 = document.getElementById('formfield_' + value_id);
			obj1.innerHTML = obj.options[obj.selectedIndex].text;
			obj2.value = obj.value;
		}
	}
	
	function get_value_from_form(obj, layer, value_id){
		var obj1 = document.getElementById(layer);
		var obj2 = document.getElementById('formfield_' + value_id);
		obj1.innerHTML = obj.options[obj.selectedIndex].text;
		obj2.value = obj.value;
	}
	
	function get_value_from_table(value, data, layer, value_id){
		var obj1 = document.getElementById(layer);
		var obj2 = document.getElementById('formfield_' + value_id);
		xmlhttp.open("GET", g_path_sl_res + 'aj/get_value_from_table.php?value=' + value + '&data=' + data);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				obj1.innerHTML = xmlhttp.responseText;
				obj2.value = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	
	function concat_fields(field, layerId, ime, source_str){
		la_tmp = source_str.split(':');
		
		l_obj_str_rez = '';
		for(var i = 0; i < la_tmp.length; i++){
			l_obj_str_rez += 'document.forma_' + ime + '.formfield_' + la_tmp[i] + '.value + " " + ';
		}
		l_obj_str_rez = l_obj_str_rez.substring(0, l_obj_str_rez.length - 9);
		
		eval('tmp_val = ' + l_obj_str_rez);
		
		document.getElementById(layerId).innerHTML = tmp_val;
		eval('document.forma_' + ime + '.formfield_' + field + '.value = "' + tmp_val + '";');
	}
	
	
	function sf_subtracts(tab, redak, dest_field, source_field, layerId, ime, bonus_sum, bonus_mul){
		var l_zbr;
		var l_obj_str;
		var l_obj_str_drugi;
		var obj;
		var l_onaj_drugi;
		var l_layerId_new;
		
		for(var i = 0; i < document.getElementById("subform_tabs").value; i++){
			if(i + 1 != tab){
				continue;
			}
			
			l_zbr = 0;
			
			l_obj_str = "document.forma_" + ime + ".formfield_" + source_field + "_" + redak + "_" + (i + 1);
			obj = eval(l_obj_str);
			
			l_layerId_new = layerId.replace('-n', '')
			l_layerId_new = l_layerId_new.replace('-p', '')
			
			l_onaj_drugi = l_layerId_new.replace('subtractDisplay', '');
			l_onaj_drugi = l_onaj_drugi.replace('-' + source_field, '');
			l_onaj_drugi = l_onaj_drugi.replace('-', '');
			
			l_obj_str_drugi = "document.forma_" + ime + ".formfield_" + l_onaj_drugi + "_" + redak + "_" + (i + 1);
			
			obj2 = eval(l_obj_str_drugi);
			
			if(obj.value > 0 && obj2.value > 0){
				if(layerId.indexOf('-n') >= 0){
					l_zbr = l_zbr - obj.value;
					l_zbr = parseInt(l_zbr) + parseInt(obj2.value);
				}else{
					l_zbr = parseInt(l_zbr) + parseInt(obj.value);
					l_zbr = l_zbr - obj2.value;
				}
			}
			
			if(l_zbr == 0){
				l_zbr = '';
			}
			
			document.getElementById(l_layerId_new + '-' + redak).innerHTML = l_zbr;
			document.getElementById("formfield_" + dest_field + "_" + redak + "_" + (i + 1)).value = l_zbr;
			
			//alert(l_layerId_new + '-' + redak);
			//alert("formfield_" + dest_field + "_" + redak + "_" + (i + 1));
		}
		
		if(bonus_sum){
			bonus_sum = bonus_sum.replace(/\//g, ':');
			la_bonus_sum = bonus_sum.split(':');
			
			l_zbr_all = 0;
			for(i = 1; i <= a_redak[tab - 1]; i++){
				//alert('1: ' + document.getElementById(l_layerId_new + '-' + i).innerHTML);
				l_zbr_value = document.getElementById(l_layerId_new + '-' + i).innerHTML;
				if(l_zbr_value){
					l_zbr_all += parseInt(l_zbr_value);
				}
			}
			
			//alert(" xxx formfield_" + la_bonus_sum[2].replace('field-', ''));
			
			document.getElementById(la_bonus_sum[3]).innerHTML = l_zbr_all;
			document.getElementById("formfield_" + la_bonus_sum[2].replace('field-', '')).value = l_zbr_all;
			
			//alert(l_zbr_all);
		}
		
		if(bonus_mul){
			bonus_mul = bonus_mul.replace(/\//g, ':');
			la_bonus_mul = bonus_mul.split(':');
			l_tmp = la_bonus_mul[3].replace('mulDisplay-', '');
			la_tmp = l_tmp.split('-');
			//alert('----->' + l_tmp);
			
			l_mul = 1;
			for(i = 0; i < la_tmp.length; i++){
				//alert(document.getElementById("formfield_" + la_tmp[i]).value);
				l_mul = l_mul * document.getElementById("formfield_" + la_tmp[i]).value;
			}
			
			//alert(l_mul);
			
			document.getElementById(la_bonus_mul[3]).innerHTML = l_mul + ' Kn';
			document.getElementById("formfield_" + la_bonus_mul[2].replace('field-', '')).value = l_mul + ' Kn';
		}
		
	}
	
	
	function sf_sums(tab, line, field, layerId, ime){
		var l_sum = 0;
		var l_obj_str;
		var obj;
		for(var i = 0; i < document.getElementById("subform_tabs").value; i++){
			if(i + 1 != tab){
				continue;
			}
			for(var j = 0; j < document.getElementById("subform_lines_" + i).value; j++){
				if(document.getElementById("delete_row_" + (j + 1) + "_" + (i + 1)).value == "1"){
					continue;
				}
				l_obj_str = "document.forma_" + ime + ".formfield_" + field + "_" + (j + 1) + "_" + (i + 1);
				//alert(l_obj_str);
				obj = eval(l_obj_str);
				if(obj.value != ""){
					l_sum += parseFloat(obj.value);
				}
			}
		}
		document.getElementById(layerId).innerHTML = roundNumber(l_sum, 2) + " Kn";
		document.getElementById("formfield_" + line).value = roundNumber(l_sum, 2);
	}
	
	function sf_max(tab, line, field, layerId, ime){
		var l_max = 0;
		var l_obj_str;
		var obj;
		for(var i = 0; i < document.getElementById("subform_tabs").value; i++){
			if(i + 1 != tab){
				continue;
			}
			for(var j = 0; j < document.getElementById("subform_lines_" + i).value; j++){
				if(document.getElementById("delete_row_" + (j + 1) + "_" + (i + 1)).value == "1"){
					continue;
				}
				l_obj_str = "document.forma_" + ime + ".formfield_" + field + "_" + (j + 1) + "_" + (i + 1);
				//alert(l_obj_str);
				obj = eval(l_obj_str);
				l_value = obj.value;
				if(l_value != ""){
					l_value = parseInt(l_value);
					if(l_value > l_max){
						l_max = l_value;
					}
				}
			}
		}
		document.getElementById(layerId).innerHTML = l_max;
		document.getElementById("formfield_" + line).value = l_max;
	}
	


	var zadatak_changed = 0;
	function zadatak_set_changed(obj, id){
		if(zadatak_changed == 0){
			document.getElementById('imgZadatakChanged').src = g_path_sl_res + 'images/b-changed-selected.gif';
			obj.title = 'Zadatak je označen kao izmijenjen.';
			zadatak_changed = 1;
			document.getElementById('action_plus').value = '1';
			document.getElementById('action_id').value = id;
		}
	}
	
	function roundNumber(number, decimal_points){
		if(!decimal_points) return Math.round(number);
		if(number == 0){
			var decimals = "";
			for(var i = 0; i < decimal_points; i++){
				decimals += "0";
			}
			return "0."+decimals;
		}
	
		var exponent = Math.pow(10, decimal_points);
		var num = Math.round((number * exponent)).toString();
		return num.slice(0, -1 * decimal_points) + "." + num.slice(-1 * decimal_points);
	}

	function check_hash_change(){
		if(document.location.hash == ''){
			close_layers();
			viz.setSelection([{}]);
		}
		
		var la_hash = document.location.hash.substring(1).split('/');
		
		if(la_hash[0] == 1 && la_hash[1] == 1){
			display_layer(la_hash[2]);
		}
		
		if(la_hash[0] == 3 && la_hash[1] == 1){
			//alert('aa');
			display_layer(la_hash[2], '', 0, 0);
		}
		if(la_hash[0] == 3 && la_hash[1] == 2){
			display_layer(la_hash[2]);
		}
	}
	
	function check_open(edited, a, b){
		if(edited == 1){
			var la_hash = document.location.hash.split('/');
			//alert(la_hash[1]);
			if(la_hash[2]){
				display_layer(la_hash[2]);
			}
		}
	}
	
	function open_close_all_tabs(obj_tab, rbr, id){
		obj = document.getElementById('allTabs');
		var ps = obj.getElementsByTagName('P');
		var la_class = new Array();
		for(var i = 0; i < ps.length; i++){
			la_class = ps[i].className.split(' ');
			//alert(la_class[0].replace('TableTab', 'Table') + '-' + i);
			l_tmp_class = la_class[0].replace('TableTabAkt', 'Table');
			l_tmp_class = l_tmp_class.replace('TableTab', 'Table');
			document.getElementById(l_tmp_class + '-' + rbr + '-' + i).style.display = 'none';
			//alert(ps[i].className);
			ps[i].className = ps[i].className.replace('sfTabTableTabAkt', 'sfTabTableTab');
		}
		la_class_label = obj_tab.parentNode.className.split(' ');
		document.getElementById(la_class_label[0].replace('TableTab', 'Table') + '-' + rbr + '-' + id).style.display = 'block';
		obj_tab.parentNode.className = obj_tab.parentNode.className.replace('sfTabTableTab', 'sfTabTableTabAkt');
	}
	
	function open_close_all_labels_tab_related(obj_label, str, rbr){
		open_close_all_labels(obj_label);
		//alert(str);
		la_tmp = str.split(':');
		if(la_tmp[1] == rbr){
			document.getElementById(la_tmp[0]).style.display = 'block';
		}else{
			document.getElementById(la_tmp[0]).style.display = 'none';
		}
	}
	
	function open_close_all_labels(obj_label){
		obj = document.getElementById('allLabels');
		var ps = obj.getElementsByTagName('P');
		var la_class = new Array();
		for(var i = 0; i < ps.length; i++){
			la_class = ps[i].className.split(' ');
			document.getElementById(la_class[0].replace('Label', '')).style.display = 'none';
			ps[i].className = ps[i].className.replace(' sfTabAkt', ' sfTab');
		}
		la_class_label = obj_label.parentNode.className.split(' ');
		document.getElementById(la_class_label[0].replace('Label', '')).style.display = 'block';
		obj_label.parentNode.className = obj_label.parentNode.className.replace(' sfTab', ' sfTabAkt');
	}
	
	function new_file(rbr, is_redak_tab, type, id, file_flag){
		document.getElementById('dodajDatotekuLayer').style.display = 'block';
		document.getElementById('upload_frame').src = g_path_sl_res + 'file_upload.php?rbr=' + rbr + '&is_redak_tab=' + is_redak_tab + 
			'&type=' + type + '&id=' + id + '&file_flag=' + file_flag;
	}
	
	function new_document(id, rbr, activeDocument, redak){
		document.getElementById('dodajDatotekuLayer').style.display = 'block';
		alert(document.getElementById('upload_frame').src);
		document.getElementById('upload_frame').src = g_path_sl_res + 'document_upload.php?id=' + id + '&rbr=' + rbr + 
			'&activeDocument=' + activeDocument + '&redak=' + redak;
		alert(document.getElementById('upload_frame').src);
	}

	//var redak = 0;
	//var is_redak_set = 0;
	
	var active_tab = 1;
	var active_table_tab = 1;
	var a_redak = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	var a_is_redak_set = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	function set_redak(value, tab_rbr){
		if(a_is_redak_set[tab_rbr] == 0){
			a_redak[tab_rbr] = value;
			a_is_redak_set[tab_rbr] = 1;
		}
		if(document.getElementById('clickHereIDInv')){
			document.getElementById('clickHereIDInv').style.display = 'none';
		}
	}
	
	function subform_delete_row(link_obj, rbr, tab_rbr){
		obj = document.getElementById('delete_row_' + rbr + '_' + tab_rbr);
		if(obj.value == '0'){
			obj.value = '1';
			document.getElementById('group_' + rbr + '_' + tab_rbr).setAttribute('style', 'background:#EE6D40');
			//link_obj.innerHTML = 'Undelete';
			link_obj.innerHTML = '<img src="res/images/b-del-delete-selected-m.gif" border="0">';
		}else{
			obj.value = '0';
			document.getElementById('group_' + rbr + '_' + tab_rbr).removeAttribute('style');
			//link_obj.innerHTML = 'Delete';
			link_obj.innerHTML = '<img src="res/images/b-del-m.gif" border="0">';
		}
	}
	
	function subform_new_row(rbr, default_tab, pk_rbr, parent_pk_rbr, tab_rbr, fill_values, addition){
		//alert('subform_lines_' + tab_rbr);
		//alert(document.getElementById('subform_lines_' + tab_rbr).value);
		
		a_redak[tab_rbr]++;
		document.getElementById('subform_lines_' + tab_rbr).value = a_redak[tab_rbr];
		
		//alert(document.getElementById('subform_lines_' + tab_rbr).value);
		
		
		//document.getElementById('subformNewLine').style.display = 'block';
		
		//document.write('res/aj/subform.php?rbr=' + rbr + '&default_tab=' + default_tab + '&pk_rbr=' + pk_rbr +
		//	'&redak=' + a_redak[tab_rbr] + '&parent_pk_rbr=' + parent_pk_rbr + '&tab_rbr=' + tab_rbr);
		//return;
		//alert(redak);
		
		makerequest_addcontent(g_path_sl_res + 'aj/subform.php?rbr=' + rbr + '&default_tab=' + default_tab + '&pk_rbr=' + pk_rbr +
			'&redak=' + a_redak[tab_rbr] + '&parent_pk_rbr=' + parent_pk_rbr + '&tab_rbr=' + tab_rbr + '&addition=' + addition,
			'subformRedak' + a_redak[tab_rbr] + '_' + tab_rbr, fill_values);
			//'&pk_rbr=' + pk_rbr + '&redak=' + redak, 'subformNewLine');
	}
	
	var activeDocument = '';
	function document_get_ch(value){
		activeDocument = value;
		document.getElementById('adddata').innerHTML = '';
		
		
		//document.write('res/aj/document_get_ch.php?value=' + value);
		//return;
		
		
		makerequest(g_path_sl_res + 'aj/document_get_ch.php?value=' + value, 'chdata');
		folder_close_layer('adddata');
		folder_open_layer('chdata');
		document.getElementById('documentSaveButton').style.display = 'block';
		//folder_open_layer('lnkDodajDatoteku');
	}
	
	function document_get(value, layer, column, reverse){
		//folder_close_layer('lnkDodajDatoteku');
		redak = 0;
		is_redak_set = 0;
		
		//document.write('res/aj/document_get.php?value=' + value + '&aj=' + layer + '&column=' + column + '&reverse=' + reverse);
		//return;
		makerequest_4(g_path_sl_res + 'aj/document_get.php?value=' + value + '&aj=' + layer + '&column=' + column + '&reverse=' + reverse, 'visBottomFolder', '', '', '');
		//document.getElementById('menuAction').innerHTML = 'Akcija: "Pregled dokumenata"';
		document.getElementById('menuAction').innerHTML = g_akcija_pregled_dokumenata;
		document.getElementById('documentSaveButton').style.display = 'none';
	}
	
	function document_get_add(value, layer){
		folder_close_layer('chdata');
		redak = 0;
		is_redak_set = 0;
		//document.write('res/aj/document_get_add.php?value=' + value);
		//return;
		document.getElementById('chdata').innerHTML = '';
		makerequest(g_path_sl_res + 'aj/document_get_add.php?value=' + value, 'adddata');
		folder_open_layer('adddata');
		//document.getElementById('menuAction').innerHTML = 'Akcija: "Dodaj novi dokument"';
		document.getElementById('menuAction').innerHTML = g_akcija_dodaj_novi_dokument;
		document.getElementById('documentSaveButton').style.display = 'block';
		//folder_open_layer('lnkDodajDatoteku');
	}
	
	function folder_get_add(value){
		//alert(value);
		if(value == ''){
			//document.getElementById('menuAction').innerHTML = 'Akcija: "Dodaj novu mapu nulte razine"';
			document.getElementById('menuAction').innerHTML = g_akcija_dodaj_novu_mapu;
		}else{
			makerequest(g_path_sl_res + 'aj/folder_get_add.php?value=' + value, 'adddata');
			//document.getElementById('menuAction').innerHTML = 'Akcija: "Dodaj novu (pod)mapu"';
			document.getElementById('menuAction').innerHTML = g_akcija_dodaj_novu_podmapu;
			document.getElementById('chdata').innerHTML = '';
			folder_close_layer('chdata');
			folder_open_layer('adddata');
		}
	}
	
	function folder_get_ch(value){
		document.getElementById('adddata').innerHTML = '';
		makerequest(g_path_sl_res + 'aj/folder_get_ch.php?value=' + value, 'chdata');
		//document.getElementById('menuAction').innerHTML = 'Akcija: "Promijeni podatke"';
		document.getElementById('menuAction').innerHTML = g_akcija_promijeni_podatke;
		folder_close_layer('adddata');
		folder_open_layer('chdata');
	}
	
	function folder_ins(id, layer){
		if(confirm('Jeste li sigurni da želite dodati podatke?')){
			makerequest_ins(g_path_sl_res + 'aj/folder_ins.php?value=' + id +
				'&naziv=' + document.formdataadd.naziv.value, id, 'visOver');
		}
		return false;
	}
	
	function folder_upd(id, layer){
		//document.write('res/aj/folder_upd.php?value=' + id + '&naziv=' + document.formdata.naziv.value + '&guid=' + document.formdata.guid.value);
	
		if(confirm('Jeste li sigurni da želite promijeniti podatke?')){
			makerequest_upd(g_path_sl_res + 'aj/folder_upd.php?value=' + id +
				'&naziv=' + document.formdata.naziv.value + '&guid=' + document.formdata.guid.value, id, 'visOver');
		}
		return false;
	}
	
	function folder_open_layer(layer){
		document.getElementById(layer).style.display = 'block';
	}
	
	function folder_close_layer(layer){
		document.getElementById(layer).style.display = 'none';
	}
	
	function open_layer(layer){
		document.getElementById(layer).style.display = 'block';
	}
	
	function close_layer(layer){
		document.getElementById(layer).style.display = 'none';
	}
	
	function folder_del(id){
		if(confirm('Jeste li sigurni da želite obrisati odabrani podatak?')){
			makerequest_del(g_path_sl_res + 'aj/folder_del.php?value=' + id, id, '');
			//alert(id);
		}
		return false;
	}
	
	
	function setSearch(value, rbr){
		document.getElementById('searchResults').style.display = 'none';
		document.getElementById('searchField' + rbr).value = value;
		return false;
	}
	
	function checkSearch(value, param1, param2, rbr){
		//alert(value);
		if(value.length >= 2){
			//document.write('res/aj/search.php?value=' + value + '&param1=' + param1 + '&param2=' + param2 + '&rbr=' + rbr);
			//return;
			makerequest_search(g_path_sl_res + 'aj/search.php?value=' + value + '&param1=' + param1 + '&param2=' + param2 + '&rbr=' + rbr, 'searchResults');
			document.getElementById('searchResults').style.top = (35 * rbr + 1) + 'px';
			document.getElementById('searchResults').style.display = 'block';
		}
	}
	
	function new_image(id, rbr){
		document.getElementById('imgdiv_' + rbr).style.display = 'block';
		document.getElementById('upload_frame').src = g_path_sl_res + 'image_upload.php?id=' + id + '&rbr=' + rbr;
	}
	
	function forma_del(dest, id){
		if(confirm('Jeste li sigurni da treba obrisati odabrani podatak?')){
			//document.write(g_path_sl_res + 'res/aj/forma_del.php?value=' + id + '&dest=' + dest);
			//return false;
			makerequest_del_forma(g_path_sl_res + 'aj/forma_del.php?value=' + id + '&dest=' + dest);
		}
		return false;
	}
	
	
	function osd_get_ch(value){
		document.getElementById('adddata').innerHTML = '';
		makerequest(g_path_sl_res + 'aj/osd_get_ch.php?value=' + value, 'chdata');
		//document.getElementById('menuAction').innerHTML = 'Akcija: "Promijeni podatke"';
		document.getElementById('menuAction').innerHTML = g_akcija_promijeni_podatke;
		folder_close_layer('adddata');
		folder_open_layer('chdata');
	}
	
	function osd_get_add(value){
		document.getElementById('chdata').innerHTML = '';
		makerequest(g_path_sl_res + 'aj/osd_get_add.php?value=' + value, 'adddata');
		//document.getElementById('menuAction').innerHTML = 'Akcija: "Dodaj novu organizacijsku jedinicu"';
		document.getElementById('menuAction').innerHTML = g_akcija_dodaj_novu_org_jedinicu;
		folder_close_layer('chdata');
		folder_open_layer('adddata');
	}
	/*
	function osd_ins(id, layer){
		if(confirm('Jeste li sigurni da želite dodati podatke?')){
			makerequest_ins('res/aj/osd_ins.php?value=' + id + '&sifra=' + document.formdataadd.sifra.value +
				'&naziv=' + document.formdataadd.naziv.value, id, 'visOver');
		}
		return false;
	}
	
	function osd_upd(id, layer){
		if(confirm('Jeste li sigurni da želite promijeniti podatke?')){
			makerequest_upd('res/aj/osd_upd.php?value=' + id + '&sifra=' + document.formdata.sifra.value +
				'&naziv=' + document.formdata.naziv.value + '&guid=' + document.formdata.guid.value, id, 'visOver');
		}
		return false;
	}
	*/
	
	function osd_open_layer(layer){
		document.getElementById(layer).style.display = 'block';
	}
	
	function osd_del(id){
		//if(confirm('Jeste li sigurni da želite obrisati odabranu organizacijsku jedinicu?')){
		if(confirm(g_akcija_brisi_org_jedinicu)){
			makerequest_del(g_path_sl_res + 'aj/osd_del.php?value=' + id, id, 'visOver');
			//alert(id);
		}
		return false;
	}
	
	var aTimer2 = new Array();
	var aLayerOpened2 = new Array();
	
	function opL2(id){
		clLTimerReset2();
		clLReset2();
		aLayerOpened2.push(id);
		document.getElementById(id).style.display = 'block';
		document.getElementById(id.replace('smm', 'mm')).className = 'a2 aAkt2';
	}
	
	function clL2(id, time){
		aTimer2.push(setTimeout('document.getElementById(\'' + id + '\').style.display = \'none\'', time));
		document.getElementById(id.replace('smm', 'mm')).className = 'a2';
	}
	
	function clLTimerReset2(){
		for(i = 0; i < aTimer2.length; i++){
			clearTimeout(aTimer2.pop());
		}
	}
	
	function clLReset2(){
		for(i = 0; i < aLayerOpened2.length; i++){
			id = aLayerOpened2.pop();
			document.getElementById(id).style.display = 'none';
		}
	}
	
	<!--
	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){
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	
	function makerequest_4(serverPage, objID1, objID2, objID3, objID4){
		var obj1 = document.getElementById(objID1);
		if(objID2){
			var obj2 = document.getElementById(objID2);
		}
		if(objID3){
			var obj3 = document.getElementById(objID3);
		}
		if(objID4){
			var obj4 = document.getElementById(objID4);
		}
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = JSON.parse(xmlhttp.responseText);
				obj1.innerHTML = la_data[0];
				if(obj2){
					obj2.innerHTML = la_data[1];
				}
				if(obj2){
					obj3.innerHTML = la_data[2];
				}
				if(obj2){
					obj4.innerHTML = la_data[3];
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function makerequest_addcontent(serverPage, objID, fill_values){
		//alert(objID);
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				//alert(objID);
				//alert(xmlhttp.responseText);
				//alert(obj.innerHTML);
				obj.innerHTML = xmlhttp.responseText;
				document.getElementById('subformNewLineId').scrollTop = document.getElementById('subformNewLineId').scrollHeight;
				
				if(fill_values){
					var la_tmp = fill_values.split(':::[SEP]:::');
					
					// nadji broj X, koji je ustvari max broj od 'subformRedakX_1'
					var divs = document.getElementById('evidencijaPlovilaDatoteka').getElementsByTagName('DIV');
					l_max = -1;
					for(var i = 0; i < divs.length; i++){
						var la_id = divs[i].id.split('_');
						if(la_id[0].indexOf('subformRedak') >= 0 && la_id[la_id.length - 1] == '1'){
							if(typeof(divs[i]) != 'undefined'){
								l_max = la_id[0].replace('subformRedak', '');
							}
						}
					}
					l_max = parseInt(l_max) - 1;
					
					
					document.getElementById('formfield_4_' + l_max + '_2_dis').value = la_tmp[0] + ' - ver.' + l_max;
					
					document.getElementById('formfield_4_' + l_max + '_2').value = la_tmp[0] + ' - ver.' + l_max;
					
					document.getElementById('dodajDatotekuImg_' + l_max + '_2').innerHTML = '<img src="res/images/document.jpg" border="0" title="Datoteka je dodana">';
					document.getElementById('formfield_5_' + l_max + '_2').value = la_tmp[1];
					
					x = 0;  //horizontal coord
					y = document.height; //vertical coord
					window.scroll(x, y);
					
					alert('Ugovor je kreiran i upisan u donje polje forme.');
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function makerequest_search(serverPage, objID){
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	
	
	function makerequest_ins(serverPage, id, objID){
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = xmlhttp.responseText.split('::-x-x-::');
				switch(la_data[0]){
					case 'error':
						alert('Dogodila se pogreška! Molimo kontaktirajte administratora.');
						break;
					
					case 'inserted':
						alert('Podaci su uspješno dodani.');
						
						var a_data_new = new Array();
						a_data_new.length = 0;
						
						la_data = JSON.parse(la_data[1]);
						for(i = 0; i < la_data.length; i++){
							la_tmp = la_data[i][0].split(', f:');
							la_tmp[0] = la_tmp[0].substr(4, la_tmp[0].length - 5);
							la_tmp[1] = la_tmp[1].substr(1, la_tmp[1].length - 3);
							
							a_data_new[i] = new Array(
								{v:la_tmp[0], f:la_tmp[1]},
								la_data[i][1],
								la_data[i][2]
							);
						}
						a_data = a_data_new;
						break;
				}
				
				obj.innerHTML = '';
				obj.style.display = 'none';
				
				document.getElementById('visBottom').style.display = 'none';
				document.getElementById('visualization').innerHTML = '';
				drawVisualization(a_data);
			}
		}
		xmlhttp.send(null);
	}
	
	function makerequest_upd(serverPage, id, objID){
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				la_data = xmlhttp.responseText.split('::-x-x-::');
				switch(la_data[0]){
					case 'error':
						alert('Dogodila se pogreška! Molimo kontaktirajte administratora.');
						break;
					
					case 'updated':
						alert('Podaci su uspješno promijenjeni.');
						
						var a_data_new = new Array();
						a_data_new.length = 0;
						
						la_data = JSON.parse(la_data[1]);
						for(i = 0; i < la_data.length; i++){
							la_tmp = la_data[i][0].split(', f:');
							la_tmp[0] = la_tmp[0].substr(4, la_tmp[0].length - 5);
							la_tmp[1] = la_tmp[1].substr(1, la_tmp[1].length - 3);
							
							a_data_new[i] = new Array(
								{v:la_tmp[0], f:la_tmp[1]},
								la_data[i][1],
								la_data[i][2]
							);
						}
						a_data = a_data_new;
						break;
				}
				
				obj.innerHTML = '';
				obj.style.display = 'none';
				
				document.getElementById('visBottom').style.display = 'none';
				document.getElementById('visualization').innerHTML = '';
				drawVisualization(a_data);
			}
		}
		xmlhttp.send(null);
	}
	
	
	function makerequest_del_forma(serverPage){
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				//alert(xmlhttp.responseText);
				switch(xmlhttp.responseText){
					case 'foreign_key':
						alert('Nije moguće obrisati odabrani podatak jer se podatak koristi u drugim dijelovima aplikacije.');
						break;
						
					case 'error':
						alert('Dogodila se pogreška! Molimo kontaktirajte administratora.');
						break;
					
					case 'deleted':
						alert('Odabrani podatak uspješno je obrisan.');
						l_href = document.location.href.replace('&added=1', '');
						l_href = l_href.replace('&edited=1', '');
						document.location.href = l_href;
						//window.location.reload();
						break;
				}
			}
		}
		xmlhttp.send(null);
	}
	
	
	function makerequest_del(serverPage, id, objID){
		if(objID){
			var obj = document.getElementById(objID);
		}
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				
				switch(xmlhttp.responseText){
					case 'foreign_key':
						alert('Nije moguće obrisati odabrani podatak jer postoji sadržaj unutar odabranog podatka ' +
							'ili se podatak koristi u drugim dijelovima aplikacije.');
						break;
						
					case 'error':
						alert('Dogodila se pogreška! Molimo kontaktirajte administratora.');
						break;
					
					case 'deleted':
						alert('Odabrani podatak uspješno je obrisan.');
						
						var a_data_new = new Array();
						a_data_new.length = 0;
						var l_cnt = 0
						for(i = 0; i < a_data.length; i++){
							if(id == a_data[i][0]['v']){
								continue;
							}
							a_data_new[l_cnt++] = a_data[i];
						}
						
						a_data.length--;
						a_data = a_data_new;
						
						break;
				}
				
				if(obj){
					obj.innerHTML = '';
					obj.style.display = 'none';
				}
				
				if(eval(document.getElementById('visBottom'))){
					document.getElementById('visBottom').style.display = 'none';
				}
				if(eval(document.getElementById('visBottomFolder'))){
					document.getElementById('visBottomFolder').style.display = 'none';
				}
				document.getElementById('visualization').innerHTML = '';
				drawVisualization(a_data);
				
				var la_query = document.location.href.split('#');
				la_query[0] = la_query[0].replace('&edited=1', '').replace('&added=1', '').replace('&error=1', '');
				document.location = la_query[0];
			}
		}
		xmlhttp.send(null);
	}
	
	
	//-->

	function otvori_prozor2(adresa, prozor, sirina, visina, povecavanje, skrolbar){
		var ow2 = window.open(adresa ,	prozor,	'width = ' + sirina + ',height = ' + visina + ',resizable = ' + povecavanje + ',scrollbars = ' + skrolbar);
		if(ow2){
			ow2.focus();
		}
	}
