/* 		B.2.0.0 / 10.11.2006

		############################
		##  KNJIŽNICA BILLING.JS  ##
		############################

		(C) 2006 Garaža studio, d.o.o.
		Vse pravice pridržane

		Verzije:
		========

		* [B.0.0.1 / 13.02.2006]
			Razvojna verzija
		* [B.1.0.0 / 01.05.2006]
			Prva verzija
		* [B.1.0.1 / 08.05.2006]
			Dodano Javascript potrditveno okno ob brisanju/prekinitvi povezave
		* [B.1.0.2 / 18.05.2006]
			Spremembe dizajna in obrazcev
		* [B.1.0.3 / 05.07.2006]
			Dodana funkcija toggleDiv()
		* [B.1.0.4 / 19.07.2006]
			Popup okna se sedaj odpirajo na sredini zaslona
		* [B.1.0.5 / 02.10.2006]
			Dopolnitev funkcije openMenuExplorer()
		* [B.1.0.6 / 10.10.2006]
			Sprememba funkcije openDateTime()
			Sprememba funkcije selectDate()
		* [B.1.1.1 / 10.10.2006]
			Dodana funkcija openSysHelp()
		* [B.1.2.1 / 16.10.2006]
			Dodana funkcija openCMSstatistics()
		* [B.1.3.1 / 04.11.2006]
			Dodana funkcija makeDescriptor()
		* [B.1.3.2 / 06.11.2006]
			Dopolnitev funkcije makeDescriptor()
			Dopolnitev funkcije openCatExplorer()
		# [B.2.0.0 / 10.11.2006]
			DRUGA VERZIJA

*/

function openSysHelp(lang, module_id) {
	var x, y, w, h;
	w = 700;
	h = 500;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		popWin.location.href = 'aapplet.php?lang=' + lang + '&module=systemhelp&action=view&id=' + module_id;
		popWin.focus();
	}
}


function openCMSstatistics(lang, page_id, lang_id, is_active, page_type, startmonth, startyear, endmonth, endyear) {
	var x, y, w, h;
	w = 700;
	h = 500;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		popWin.location.href = 'aapplet.php?lang=' + lang + '&module=cmsstatsprint&id=' + page_id + '&lang_id=' + lang_id + '&is_active=' + is_active + '&page_type=' + page_type + '&startmonth=' + startmonth + '&startyear=' + startyear + '&endmonth=' + endmonth + '&endyear=' + endyear;
		popWin.focus();
	}
}


function openFileExplorer(lang, file_name, inputField) {
	var x, y, w, h;
	w = 600;
	h = 500;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		popWin.location.href = 'aapplet.php?lang=' + lang + '&module=fileselect&action=list&file=' + document.getElementById(inputField).value + '&inputfield=' + inputField;
		popWin.focus();
	}
}
function selectFile(file_name, inputField) {
	if (window.opener && !window.opener.closed) {
		window.opener.document.getElementById(inputField).value = file_name;
	}
	closeMe();
}


function openCatExplorer(lang, value, inputField, parent_id, cat_type, table, flags) {
	var x, y, w, h;
	w = 600;
	h = 500;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		popWin.location.href = 'aapplet.php?lang=' + lang + '&module=cmscatselect&action=list&id=' + document.getElementById(inputField).value + '&inputfield=' + inputField + '&parent_id=' + parent_id + '&cat_type=' + cat_type + '&table=' + table + '&flags=' + flags;
		popWin.focus();
	}
}


function openMenuExplorer(lang, value, inputField, parent_id, table, module) {
	var x, y, w, h;
	w = 600;
	h = 500;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		popWin.location.href = 'aapplet.php?lang=' + lang + '&module=' + module + '&action=list&id=' + document.getElementById(inputField).value + '&inputfield=' + inputField + '&parent_id=' + parent_id + '&table=' + table;
		popWin.focus();
	}
}


function openSysMenuExplorer(lang, value, inputField, parent_id) {
	var x, y, w, h;
	w = 600;
	h = 500;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		popWin.location.href = 'aapplet.php?lang=' + lang + '&module=sysmenuselect&action=list&id=' + document.getElementById(inputField).value + '&inputfield=' + inputField + '&parent_id=' + parent_id;
		popWin.focus();
	}
}


function openDateTime(lang, pmode, field) {
	var x, y, w, h;
	w = 600;
	h = 500;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		href = 'aapplet.php?lang=' + lang + '&module=datetime&mode=' + pmode + '&field=' + field + 
				((pmode &  4) ? ('&hour=' 	+ document.getElementById(field + "hour").value) 	: "") + 
				((pmode &  2) ? ('&minute=' + document.getElementById(field + "minute").value) 	: "") + 
				((pmode &  1) ? ('&second=' + document.getElementById(field + "second").value) 	: "") + 
				((pmode &  8) ? ('&day=' 	+ document.getElementById(field + "day").value) 	: "") + 
				((pmode & 16) ? ('&month=' 	+ document.getElementById(field + "month").value) 	: "") + 
				((pmode & 32) ? ('&year=' 	+ document.getElementById(field + "year").value) 	: "")
				;
		popWin.location.href = href;
		popWin.focus();
	}
}
function selectDate(pmode, field, pday) {
	if (window.opener && !window.opener.closed) {

		if (pmode &  4) window.opener.document.getElementById(field + "hour").value 	= document.getElementById("hour").value;
		if (pmode &  2) window.opener.document.getElementById(field + "minute").value 	= document.getElementById("minute").value;
		if (pmode &  1) window.opener.document.getElementById(field + "second").value 	= document.getElementById("second").value;
		if (pmode &  8) window.opener.document.getElementById(field + "day").value 		= ((pday > 0) ? pday : (document.getElementById("day").value));
		if (pmode & 16) window.opener.document.getElementById(field + "month").value 	= document.getElementById("month").value;
		if (pmode & 32) window.opener.document.getElementById(field + "year").value 	= document.getElementById("year").value;

		/* if (pmode & 1) {
			window.opener.document.getElementById(field + "hour").value = document.getElementById("hour").value;
			window.opener.document.getElementById(field + "minute").value = document.getElementById("minute").value;
			window.opener.document.getElementById(field + "second").value = document.getElementById("second").value;
		}
		if (pmode & 2) {
			window.opener.document.getElementById(field + "day").value = ((pday > 0) ? pday : (document.getElementById("day").value));
			window.opener.document.getElementById(field + "month").value = document.getElementById("month").value;
			window.opener.document.getElementById(field + "year").value = document.getElementById("year").value;
		} */
	}
	closeMe();
}


function openCityExplorer(lang, city, inputField) {
	var x, y, w, h;
	w = 600;
	h = 300;
	x = (screen.width)  ? (screen.width  - w)/2 : 100;		if (x < 0) x = 0;
	y = (screen.height) ? (screen.height - h)/2 : 100;		if (y < 0) y = 0;
	popWin = window.open('', 'popupwindow', 'toolbar=no,location=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width='+w+',height='+h+',top='+y+',left='+x);
	if (popWin != null) {
		popWin.location.href = 'aapplet.php?lang=' + lang + '&module=postselect&city=' + document.getElementById(inputField).value + '&field=' + inputField;
		popWin.focus();
	}
}
function selectCity(inputField) {
	if (window.opener && !window.opener.closed) {
		window.opener.document.getElementById(inputField).value = document.getElementById("city").value;
	}
	closeMe();
}


function selectElement(new_value, inputField) {
	if (window.opener && !window.opener.closed) {
		window.opener.document.getElementById(inputField).value = new_value;
	}
	closeMe();
}


function toggleDiv(div) {
	var visible = document.getElementById(div).style.display;
	// document.write(div + " visible: " + visible);
	if (visible == "block") {
		document.getElementById(div).style.display = "none";
		document.getElementById(div).style.visibility = "hidden";
		document.getElementById("pic_" + div).src = "_billings/images/icon_mini_closed.gif";
	} else {
		document.getElementById(div).style.display = "block";
		document.getElementById(div).style.visibility = "visible";
		document.getElementById("pic_" + div).src = "_billings/images/icon_mini_open.gif";
	}
}


function makeDescriptor(source, destination) {
	var descriptor = "";
	var title = document.getElementById(source).value;
	var len = title.length;
	var pos = 0;

	title = title.toLowerCase();
	while (pos < len) {
		znak = title.charCodeAt(pos);
		if (znak > 0x60 && znak < 0x7B || znak == 0x2D || znak == 0x5F) {
			descriptor += title.charAt(pos);
		} else if (znak > 0x2F && znak < 0x3A) {
			descriptor += title.charAt(pos);
		} else if (znak == 0x20) {
			descriptor += "-";
		} else if (title.charAt(pos) == "č" || title.charAt(pos) == "ć") {
			descriptor += "c";
		} else if (title.charAt(pos) == "đ") {
			descriptor += "d";
		} else if (title.charAt(pos) == "š") {
			descriptor += "s";
		} else if (title.charAt(pos) == "ž") {
			descriptor += "z";
		} else {
			// descriptor += "|" + znak + "|";
		}
		pos++;
	}
	if (descriptor) {
		znak = title.charCodeAt(0);
		if (znak > 0x2F && znak < 0x3A || znak == 0x20) descriptor = "a" + descriptor;
		document.getElementById(destination).value = descriptor;
	}
}


