/*
window.onerror = function() {
	return true;
};
*/

//*****************************************************************************************************************************************************

var doc = document;
var DOM_Level_2 = (doc.getElementById && doc.getElementsByTagName);

//*****************************************************************************************************************************************************

function zamenjajStil(pot, lastnost, vrednost)
{
	if (!DOM_Level_2) return;
	var obj = dobiDoloceneObjekte(pot);
	if (obj == null) return;
	var obj_dolzina = obj.length, obj_stil = null;
	if (obj_dolzina) {
		for (var i=0; i<obj_dolzina; i++) {
			obj_stil = obj[i].style;
			if (obj_stil) {
				if (typeof(eval('obj_stil.'+lastnost))!='undefined') {
					eval('obj_stil.'+lastnost+'=\''+vrednost+'\'');
				}
			}
		}
	} else {
		obj_stil = obj.style;
		if (obj_stil) {
			if (typeof(eval('obj_stil.'+lastnost))!='undefined') {
				eval('obj_stil.'+lastnost+'=\''+vrednost+'\'');
			}
		}
	}
}

//*****************************************************************************************************************************************************

function pocistiPrivzetoVrednost(ime, privzeta_vrednost) //odstraniPrivzetoVrednost
{
	if (!DOM_Level_2) return;
	var element;
	if (!(element = doc.getElementById(ime))) return;
	//Odstranimo privzeto vrednost
	if (element.value == privzeta_vrednost) element.value = '';
	//Izberemo besedilo
	else element.select();
}

function ponastaviPrivzetoVrednost(ime, privzeta_vrednost) //dodajPrivzetoVrednost
{
	if (!DOM_Level_2) return;
	var element;
	if (!(element = doc.getElementById(ime))) return;
	if (element.value == '') element.value = privzeta_vrednost;
}

//*****************************************************************************************************************************************************

function nastaviVelikostPisave(id)
{
	if (document.getElementById && document.getElementById(id)) {
		var z_meja = 1.8, s_meja = 0.8;
		velikost_pisave = parseFloat(dobiPiskotek('velikost_pisave'));
		if (velikost_pisave <= z_meja && velikost_pisave >= s_meja) document.getElementById(id).style.fontSize = velikost_pisave + 'em';
	}
}

function dobiVelikostPisave(id)
{
	if (document.getElementById && document.getElementById(id)) {
		var velikost_pisave = document.getElementById(id).style.fontSize;
		velikost_pisave = parseFloat(velikost_pisave);
		if (isNaN(velikost_pisave)) velikost_pisave = 1;
	}
	return velikost_pisave;
}

function povecajVelikostPisave(id)
{
	var interval = 0.2;
	var meja = 1.8;
	if (document.getElementById && document.getElementById(id)) {
		velikost_pisave = dobiVelikostPisave(id);
		if (velikost_pisave < meja) {
			document.getElementById(id).style.fontSize = ((velikost_pisave * 100 + interval * 100) / 100) + 'em';
			nastaviPiskotek('velikost_pisave', ((velikost_pisave * 100 + interval * 100) / 100) + 'em', 356);
		}
	}
	//return false;
}

function zmansajVelikostPisave(id)
{
	var interval = 0.2;
	var meja = 0.8;
	if (document.getElementById && document.getElementById(id)) {
		velikost_pisave = dobiVelikostPisave(id);
		if (velikost_pisave > meja) {
			document.getElementById(id).style.fontSize = ((velikost_pisave * 100 - interval * 100) / 100) + 'em';
			nastaviPiskotek('velikost_pisave', ((velikost_pisave * 100 - interval * 100) / 100) + 'em', 356);
		}
	}
	//return false;
}

//*****************************************************************************************************************************************************

function nastaviPiskotek(ime, vrednost, potece_dni)
{
	if (document.cookie) {
		var potece_datum = new Date();
		potece_datum.setDate(potece_dni);
		document.cookie = ime + "=" + escape(vrednost) + ((potece_dni==null) ? "" : ";expires=" + potece_datum);
	}
}

function dobiPiskotek(ime)
{
	if (document.cookie) {
		if (document.cookie.length > 0) {
			var zacetek, konec;
			zacetek = document.cookie.indexOf(ime + "=");
			if (zacetek != -1) {
				zacetek = zacetek + ime.length + 1;
				konec = document.cookie.indexOf(";", zacetek);
				if (konec == -1) konec = document.cookie.length;
				return unescape(document.cookie.substring(zacetek, konec));
			}
		}
	}
	return null;
}

//*****************************************************************************************************************************************************

function pretvoriZbirkoVrniMnozico(zbirka)
{
	var mnozica = new Array(), i, dolzina_zbirka = zbirka.length;
	for (i = 0; i < dolzina_zbirka; i++) mnozica[i] = zbirka[i];
	return mnozica;
}

function dobiElementePoRazredu(razred, vozel, oznaka)
{
	// Kot zadetek vrne tudi, če je razred najden na vozlu
	if (!DOM_Level_2 || !razred) return;
	if (vozel == null) vozel = doc;
	if (oznaka == null) oznaka = '*';
	var zbirka = vozel.getElementsByTagName(oznaka);
	var zadetki = new Array();
	var vzorec = new RegExp('\\s*' + razred + '\\s*');
	var i, j = -1, dolzina_zbirka = zbirka.length;
	if (vzorec.test(vozel.className)) zadetki[++j] = vozel;
	for (i = 0; i < dolzina_zbirka; i++) {
		if (vzorec.test(zbirka[i].className)) zadetki[++j] = zbirka[i];
	}
	return zadetki;
}


function dobiDoloceneObjekte()
{
	if (!DOM_Level_2) return;
	var arg = dobiDoloceneObjekte.arguments;
	if (!arg) return;
	var i, j, k, dolzina_arg = arg.length, dolzina_navodila, dolzina_obj;
	var zanka_izhod, navodila, obj, nov_obj, indikator_tip, indikator_ime;
	var rezultat = null, je_enako_poz = -1, nabor = false, zbirka = null;
	for (i = 0; i < dolzina_arg; i++) {
		zanka_izhod = false;
		obj = null;
		navodila = arg[i].split('/');
		dolzina_navodila = navodila.length
		for (j = 0; j < dolzina_navodila; j++) {
			if (obj == null) obj = doc;
			je_enako_poz = navodila[j].indexOf('=');
			indikator_tip = navodila[j].substring(0, je_enako_poz);
			indikator_ime = navodila[j].substring(je_enako_poz + 1);
			switch(indikator_tip) {
				case 'element':
					if (nabor) {
						nov_obj = new Array();
						dolzina_obj = obj.length;
						for (k = 0; k < dolzina_obj; k++) nov_obj = nov_obj.concat(pretvoriZbirkoVrniMnozico(obj[k].getElementsByTagName(indikator_ime)));
						if (nov_obj.length) obj = nov_obj;
						else {
							obj = null;
							zanka_izhod = true;
						}
					} else {
						obj = pretvoriZbirkoVrniMnozico(obj.getElementsByTagName(indikator_ime));
						nabor = true;
					}
					break;
				case 'razred':
					if (nabor) {
						nov_obj = new Array();
						dolzina_obj = obj.length;
						for (k = 0; k < dolzina_obj; k++) nov_obj = nov_obj.concat(dobiElementePoRazredu(indikator_ime, obj[k]));
						if (nov_obj.length) obj = nov_obj;
						else {
							obj = null;
							zanka_izhod = true;
						}
					} else {
						nov_obj = dobiElementePoRazredu(indikator_ime, obj);
						if (nov_obj.length) {
							obj = nov_obj;
							nabor = true;
						} else {
							obj = null;
							zanka_izhod = true;
						}
					}
					break;
				default: //case 'id':
					if (nabor) {
						//Ta način je podprt, samo za namen validacije pravilne postavitve id-ja
						//npr. če imamo na eni strani isti id na div-u, na drugi pa na ul-ju, mi pa hočemo
						//dopolniti obnašanje samo tistemu, ki se nahaja na ul elementu
						nov_obj = null;
						dolzina_obj = obj.length;
						for (k = 0; k < dolzina_obj; k++) {
							//Vrnemo samo prvi zadetek
							if (obj[k].id == indikator_ime) { //Preverimo, če je id na trenutnem elementu
								nov_obj = obj[k];
								break;
							}
						}
						if (nov_obj != null) {
							obj = nov_obj;
						} else {
							obj = null;
							zanka_izhod = true;
						}
					} else obj = obj.getElementById(indikator_ime);
					nabor = false;
			}
			if (zanka_izhod) break;
		}
		if (nabor) {
			if (rezultat == null) rezultat = new Array();
			rezultat = rezultat.concat(obj);
		}
		else rezultat = obj;
	}
	return rezultat;
}

//*****************************************************************************************************************************************************

//Advanced Pop Up function
var NewWin = '';
function OpenWindow(URL, Name, Params)
{
	var DefaultLeft = 0;
	var DefaultTop = 0;
	var DefaultWidth = 640;
	var DefaultHeight = 480;
	var DefaultScrollbars = 1;
	var DefaultResizable = 1;
	var CustomWidth = 0, CustomHeight = 0;
	if (!NewWin.closed && NewWin.location) {
		NewWin.location.href = URL;
	}
	else {
		var RegExpr, RegExprMatch;
		var CustomParams = '';
		if (!Params || Params.indexOf('left') == -1) CustomParams += 'left=' + DefaultLeft;
		if (!Params || Params.indexOf('top') == -1) CustomParams += (CustomParams != '' ? ', ' : '') + 'top=' + DefaultTop;
		if (!Params || Params.indexOf('width') == -1) CustomParams += (CustomParams != '' ? ', ' : '') + 'width=' + DefaultWidth;
		if (!Params || Params.indexOf('height') == -1) CustomParams += (CustomParams != '' ? ', ' : '') + 'height=' + DefaultHeight;
		if (!Params || Params.indexOf('scrollbars') == -1) CustomParams += (CustomParams != '' ? ', ' : '') + 'scrollbars=' + DefaultScrollbars;
		if (!Params || Params.indexOf('resizable') == -1) CustomParams += (CustomParams != '' ? ', ' : '') + 'resizable=' + DefaultResizable;
		if (Params && Params != '') CustomParams += (CustomParams != '' ? ', ' : '') + Params;
		RegExpr = /width=\d+/; //width=640
		RegExprMatch = RegExpr.exec(CustomParams);
		if (RegExprMatch) { //null || Array()
			RegExpr = /width=/;
			CustomWidth = RegExprMatch[0].replace(RegExpr, '');
			//alert(CustomWidth);
		}
		RegExpr = /height=\d+/; //height=480
		RegExprMatch = RegExpr.exec(CustomParams);
		if (RegExprMatch) { //null || Array()
			RegExpr = /height=/;
			CustomHeight = RegExprMatch[0].replace(RegExpr, '');
			//alert(CustomHeight);
		}
		//alert(URL+'\n'+Name+'\n'+Params+'\n'+CustomParams);
		NewWin = window.open(URL, Name, CustomParams);
		if (!NewWin) return true;
		if (!NewWin.opener) NewWin.opener = self;
		//NewWin.onload = fitWinToContentAndCenter('PageBorder');
		if (CustomWidth > 0 && CustomHeight > 0) CenterWin(NewWin, CustomWidth, CustomHeight);
		
	}
	if (NewWin.focus) NewWin.focus();
	return false;
}

function GetRefToElement(ElementID, DocObj)
{
	if (!DocObj) DocObj = document;
	if (document.getElementById) return DocObj.getElementById(ElementID);
	if (document.all) return DocObj.all[ElementID];
	if (document.layers) {
		if (DocObj.layers[ElementID]) return DocObj.layers[ElementID];
		else {
			var i, RefObj;
			for (i = 0; !RefObj && i < DocObj.layers.length; i++) {
				RefObj = GetRefToElement(ElementID, DocObj.layers[i].document);
			}
			return RefObj;
		}
	}
	return document[ElementID];
}

//Fit to content and center
function FitWinToContentAndCenter(ElementID)
{
	//Get reference
	var ElementObj = GetRefToElement(ElementID);
	if (!ElementObj) return false;
	window.resizeTo(100, 100);
	//Get element dimensions
	var ElementW, ElementH;
	if (ElementObj.clip) { //NS4
		ElementW = ElementObj.clip.width;
		ElementH = ElementObj.clip.height;
	}
	else { //Others
		ElementW = ElementObj.offsetWidth;
		ElementH = ElementObj.offsetHeight;
	}
	if (!ElementH) return false;
	//alert(ElementW+'\n'+ElementH);
	window.resizeTo(ElementW + 200, ElementH + 200); //200 is ~ max px of toolbars
	var WinW = 0, WinH = 0;
	if (self.innerHeight) { //All except Explorer
		WinW = self.innerWidth;
		WinH = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { //Explorer 6 Strict Mode
		WinW = document.documentElement.clientWidth;
		WinH = document.documentElement.clientHeight;
	}
	else if (document.body) { //Other Explorers
		WinW = document.body.clientWidth;
		WinH = document.body.clientHeight;
	}
	if (window.opera && !document.childNodes) WinW += 16;
	//alert(WinW+'\n'+WinH);
	window.resizeTo(ElementW = (ElementW + ((ElementW + 200) - WinW)), ElementH = (ElementH + ((ElementH + 200) - WinH)));
	//alert(ElementW+'\n'+ElementH);
	CenterWin(window, ElementW, ElementH);
}

function CenterWin(WinObj, WinW, WinH)
{
	var ScrW, ScrH;
	if (screen.availHeight) {
		ScrW = screen.availWidth;
		ScrH = screen.availHeight;
	}
	else {
		ScrW = screen.width;
		ScrH = screen.height;
	}
	WinObj.moveTo((ScrW - WinW) / 2, (ScrH - WinH) / 2);
}

//*****************************************************************************************************************************************************

function InsertFlash(Target, ID, Version, File, Width, Height, Parameters) {
	var ParametersObjectStr = ''
	var ParametersEmbedStr = ''
	var s, v
	for (s in Parameters) {
		v = Parameters[s]
		ParametersObjectStr += '<param name="'+s+'" value="'+v+'" />'
		ParametersEmbedStr += ' '+s+'="'+v+'" '
	}
	var FlashHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
			'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+Version+',0,0,0" ' +
			'width="'+Width+'" height="'+Height+'" id="'+ID+'">' +
			'<param name="movie" value="'+File+'" />' +
			ParametersObjectStr +
			'<embed src="'+File+'" menu="true" ' +
				'pluginspage="http://www.macromedia.com/go/getflashplayer"  ' +
				'type="application/x-shockwave-flash" width="'+Width+'" height="'+Height+'" name="'+ID+'" '+ParametersEmbedStr+' />' +
		'</object>'
	document.getElementById(Target).innerHTML = FlashHTML
}

function VerifyBrowserFlashSupport(FlashVersion) {
	var flashinstalled = 0;
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x) {
			flashinstalled = 2;
			if (x.description) {
				var y = x.description;
				if (y.charAt(y.indexOf('.')-1) >= FlashVersion) return true;
			}
		}
		if ((FlashVersion == 2) && (navigator.plugins["Shockwave Flash 2.0"])) {
			return true;
		}
	} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
	} else {
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + FlashVersion);
			return true;
		}
		catch(e){
		}
	}
	return false;
}

function InsertFlashOrHTML(Target, ID, Version, File, Width, Height, Parameters, NoFlashHTML) {
	if (VerifyBrowserFlashSupport(Version)) {
		InsertFlash(Target, ID, Version, File, Width, Height, Parameters)
	} else {
		document.getElementById(Target).innerHTML = NoFlashHTML
	}
}

//*****************************************************************************************************************************************************
