//window.onbeforeunload = confirmExit;
//function confirmExit() {
//	self.parent.location = "/AmplioCMS2/index.jsp";
//}


var publishing = false;

var modulIdRedirect;

function reloadExePage(urlPath) {
	// document.location.href =
	// "/AmplioCMS2"+urlPath+"?&tran_cache_token="+tran_cache_token;
}

/**
 * Prikaze podroben opis pravkar generirane napake.
 */
function podrobnaNapaka() {
	if (document.getElementById("$IDnaprednaNapaka").style.display == "block")
		document.getElementById("$IDnaprednaNapaka").style.display = "none";
	else
		document.getElementById("$IDnaprednaNapaka").style.display = "block";
}

function URLDecode(psEncodeString) {
	// Create a regular expression to search all +s in the string
	var lsRegExp = /\+/g;
	// Return the decoded string
	return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else
		var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for ( var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ')
			c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

/*
 * Funkcija vrne vrednost izbranega polja f_name ..... ime polja ki ga zelimo
 * prebrati isOption ... ali je polje tipa dropdown (true == DA, false == NE)
 */
function getFormElementValue(f_name, isOption) {
	var formElement = document.getElementById(f_name);
	if (isOption == true) {
		for (i = 0; i < formElement.options.length; i++) {
			if (formElement.options[i].selected == true)
				return formElement.options[i].value;
		}
	} else {
		return formElement.value;
	}
}

/* Funkcija izprazni vrednosti iz dolocenega dropdown elementa */
function nullOptions(aMenu) {
	var tot = aMenu.options.length
	for (i = 0; i < tot; i++) {
		aMenu.options[i] = null;
	}
	aMenu.options.length = 0;
}

/*
 * function attachEvent(__TARGET_EL, _EVENT, REF_TO_FUNCTION) { var oDiv =
 * document.getElementById(__TARGET_EL); if( oDiv.addEventListener ) {
 * oDiv.addEventListener(_EVENT,REF_TO_FUNCTION,false); } else if(
 * oDiv.attachEvent ) { oDiv.attachEvent('on'+_EVENT,REF_TO_FUNCTION); } }
 */

/**
 * Funkcija za manualno prozenje dogodkov: Dogodki: 'click', 'mousedown',
 * 'mousemove', 'mouseout', 'mouseover', and 'mouseup'
 */
function fireMouseEvent(__TARGET_EL, __EVENT) {
	var fireOnThis = document.getElementById(__TARGET_EL);
	if (document.createEvent) {
		var evObj = document.createEvent('MouseEvents');
		evObj.initMouseEvent(__EVENT, true, true, window, 0, 0, 0, 0, 0, false,
				false, true, false, 0, null);
		fireOnThis.dispatchEvent(evObj);
	} else if (document.createEventObject) {
		var evObj = document.createEventObject();
		evObj.detail = 0;
		evObj.screenX = 0;
		evObj.screenY = 0;
		evObj.clientX = 0;
		evObj.clientY = 0;
		evObj.ctrlKey = false;
		evObj.altKey = false;
		evObj.shiftKey = true;
		evObj.metaKey = false;
		evObj.button = 0;
		evObj.relatedTarget = null;
		fireOnThis.fireEvent('on' + __EVENT, evObj);
	}
}

function removeChildNodes(ctrl) {
	while (ctrl.childNodes[0]) {
		ctrl.removeChild(ctrl.childNodes[0]);
	}
}

function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) {
		obj["e" + type + fn] = fn;
		obj[type + fn] = function() {
			obj["e" + type + fn](window.event);
		}
		obj.attachEvent("on" + type, obj[type + fn]);
	}
}

// ------------------------------------
// removeEvent
function removeEvent(obj, type, fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(type, fn, false);
	else if (obj.detachEvent) {
		obj.detachEvent("on" + type, obj[type + fn]);
		obj[type + fn] = null;
		obj["e" + type + fn] = null;
	}
}

function beforeClose(event, widget) {
	var str = widget.href;
	var pairs = str.split('&');

	var togglePrefix = "";
	var toggleIndex = "";
	var toggleLength = "";
	var toggleClosing = "";

	for ( var i = 0; i < pairs.length; i++) {
		var nameValue = pairs[i].split('=');
		if (nameValue[0] == "togglePrefix") {
			togglePrefix = nameValue[1];
		}
		;
		if (nameValue[0] == "toggleIndex") {
			toggleIndex = nameValue[1];
		}
		;
		if (nameValue[0] == "toggleLength") {
			toggleLength = nameValue[1];
		}
		;
		if (nameValue[0] == "toggleClosing") {
			toggleClosing = nameValue[1];
		}
		;
	}
	// alert(" V 1: " +togglePrefix +" V 2: "+toggleIndex +" V 3: "+toggleLength
	// +" V 4: "+ toggleClosing);
	event.cancel = toggleLayer(togglePrefix, toggleIndex, toggleLength,
			toggleClosing);
}

function clearDiv(e, _fireEl, _target) {
	/*
	 * alert("ClearDIV"); var tar = document.getElementById(_target); if (
	 * tar.hasChildNodes() ) { removeChildNodes(tar); return false; } return
	 * true;
	 */
}

function createWhiteAlpha() {
	// container div for alpha transparency
	var divAlphaContainer = document.createElement('div');
	divAlphaContainer.id = "alpha_container_div";

	// alpha transparent div
	var alphaDiv = document.createElement('div');
    alphaDiv.id = "alpha_white_div";
    alphaDiv.className = "alpha_white_BG";
    divAlphaContainer.appendChild(alphaDiv);
    
    // window div on top of transparency
    var alphaWindowDiv = document.createElement('div');
    alphaWindowDiv.id = "alpha_white_window";
    alphaWindowDiv.style.marginTop = getScrollXY()[1] + "px";
    
    // content-alpha
 // content-alpha
	var contentDiv = document.createElement('div');
	contentDiv.id = "content_white_alpha";

	var newimg = document.createElement('img');
	newimg.id = "alphaWorkingImg";
	// newimg.onclick=function(){this.parentNode.removeChild(this);};
	newimg.src = "/AmplioCMS2/images/ajax-loader_alpha.gif";
	contentDiv.appendChild(newimg);
	
	alphaWindowDiv.appendChild(contentDiv);

	divAlphaContainer.appendChild(alphaWindowDiv);
    
    // zaradi ie6, ker se selecti vidijo cez alpha nivo
    var allSelect = document.getElementsByTagName("select");
    for(var i=0; i<allSelect.length; i++) {
    	allSelect[i].style.visibility = "hidden";
    }
    
    document.body.appendChild(divAlphaContainer);
}

/**
 * Funkcija kreira alpha DIV
 */
function createAlpha() {
	// container div for alpha transparency
	var divAlphaContainer = document.createElement('div');
	divAlphaContainer.id = "alpha_container_div";

	// alpha transparent div
	var alphaDiv = document.createElement('div');
	alphaDiv.id = "alpha_div";
	alphaDiv.className = "alpha_BG";
	divAlphaContainer.appendChild(alphaDiv);

	// window div on top of transparency
	var alphaWindowDiv = document.createElement('div');
	alphaWindowDiv.id = "alpha_window";
	alphaWindowDiv.style.marginTop = getScrollXY()[1] + "px";

	// var closeDiv = document.createElement('div');
	// closeDiv.id = "title_alpha_div";

	var newA = document.createElement('a');
	newA.href = "javascript: closeAlpha()";
	newA.className = "close-alpha-link";
	var linkText = document.createTextNode('_X_');
	newA.appendChild(linkText);
	// closeDiv.appendChild(newA);
	// alphaWindowDiv.appendChild(closeDiv);
	alphaWindowDiv.appendChild(newA);

	// content-alpha
	var contentDiv = document.createElement('div');
	contentDiv.id = "content_alpha";

	var newimg = document.createElement('img');
	newimg.id = "alphaWorkingImg";
	// newimg.onclick=function(){this.parentNode.removeChild(this);};
	newimg.src = "/AmplioCMS2/images/workingBig.gif";
	contentDiv.appendChild(newimg);

	alphaWindowDiv.appendChild(contentDiv);

	divAlphaContainer.appendChild(alphaWindowDiv);

	// zaradi ie6, ker se selecti vidijo cez alpha nivo
	hideAllSelects();
	
	// setAjaxFocus(data);
	
	// grem skozi vse objekte in jih skrijem (kot npr flash
	var elList = document.getElementsByTagName("embed");
	for ( var r = 0; r < elList.length; r++) {
			elList[r].style.cssText = "display:none";
	}

	document.body.appendChild(divAlphaContainer);
}

function hideAllSelects() {
	var allSelect = document.getElementsByTagName("select");
	for ( var i = 0; i < allSelect.length; i++) {
		allSelect[i].style.visibility = "hidden";
	}
}

function createAlphaNoX() {
	// container div for alpha transparency
	var divAlphaContainer = document.createElement('div');
	divAlphaContainer.id = "alpha_container_div";

	// alpha transparent div
	var alphaDiv = document.createElement('div');
	alphaDiv.id = "alpha_div";
	alphaDiv.className = "alpha_BG";
	divAlphaContainer.appendChild(alphaDiv);

	// window div on top of transparency
	var alphaWindowDiv = document.createElement('div');
	alphaWindowDiv.id = "alpha_window";
	alphaWindowDiv.style.marginTop = getScrollXY()[1] + "px";

	// var closeDiv = document.createElement('div');
	// closeDiv.id = "title_alpha_div";

	var newA = document.createElement('a');
	newA.href = "javascript: closeAlpha()";
	newA.className = "close-alpha-link";
	// var linkText=document.createTextNode('_X_');
	// newA.appendChild(linkText);
	// closeDiv.appendChild(newA);
	// alphaWindowDiv.appendChild(closeDiv);
	alphaWindowDiv.appendChild(newA);

	// content-alpha
	var contentDiv = document.createElement('div');
	contentDiv.id = "content_alpha";

	var newimg = document.createElement('img');
	newimg.id = "alphaWorkingImg";
	// newimg.onclick=function(){this.parentNode.removeChild(this);};
	newimg.src = "/AmplioCMS2/images/workingBig.gif";
	contentDiv.appendChild(newimg);

	alphaWindowDiv.appendChild(contentDiv);

	divAlphaContainer.appendChild(alphaWindowDiv);

	// zaradi ie6, ker se selecti vidijo cez alpha nivo
	var allSelect = document.getElementsByTagName("select");
	for ( var i = 0; i < allSelect.length; i++) {
		allSelect[i].style.visibility = "hidden";
	}

	document.body.appendChild(divAlphaContainer);
}

function createAlphaSessionExpired() {
	closeAlpha();
	// container div for alpha transparency
	var divAlphaContainer = document.createElement('div');
	divAlphaContainer.id = "alpha_container_div";

	// alpha transparent div
	var alphaDiv = document.createElement('div');
	alphaDiv.id = "alpha_div";
	alphaDiv.className = "alpha_BG";
	divAlphaContainer.appendChild(alphaDiv);

	// window div on top of transparency
	var alphaWindowDiv = document.createElement('div');
	alphaWindowDiv.id = "alpha_window";
	alphaWindowDiv.style.marginTop = getScrollXY()[1] + "px";

	// var closeDiv = document.createElement('div');
	// closeDiv.id = "title_alpha_div";

	var newA = document.createElement('a');
	newA.href = "javascript: closeAlpha()";
	newA.className = "close-alpha-link";
	// var linkText=document.createTextNode('_X_');
	// newA.appendChild(linkText);
	// closeDiv.appendChild(newA);
	// alphaWindowDiv.appendChild(closeDiv);
	alphaWindowDiv.appendChild(newA);

	// content-alpha
	var contentDiv = document.createElement('div');
	contentDiv.id = "content_alpha_session_timeout";

	var refresh = document.createElement('a');
	refresh.href = "javascript: closeAlpha()";
	refresh.className = "close-alpha-link-session-timeout";
	var linkText = document
			.createTextNode('Seja je potekla. Kliknite tukaj in potem shranite vse spremembe izven sistema! \n' + 'Session has expired. Click here and save all the changes out of the system!');
	refresh.appendChild(linkText);
	contentDiv.appendChild(refresh);

	alphaWindowDiv.appendChild(contentDiv);

	divAlphaContainer.appendChild(alphaWindowDiv);

	// zaradi ie6, ker se selecti vidijo cez alpha nivo
	var allSelect = document.getElementsByTagName("select");
	for ( var i = 0; i < allSelect.length; i++) {
		allSelect[i].style.visibility = "hidden";
	}

	document.body.appendChild(divAlphaContainer);
}

function closeAlpha() {

	// zaradi ie6, ker se selecti vidijo cez alpha nivo
	var allSelect = document.getElementsByTagName("select");
	for ( var i = 0; i < allSelect.length; i++) {
		allSelect[i].style.visibility = "visible";
	}

	if (document.getElementById('alpha_container_div'))
		document.body.removeChild(document
				.getElementById('alpha_container_div'));
	
	// prikazem nazaj
	var elList = document.getElementsByTagName("embed");
	for ( var r = 0; r < elList.length; r++) {
			elList[r].style.cssText = "display:block";
	}
}

// common.formFilter = function(/*DOMNode*/node) {
// summary: Returns true if the node is an input element that is enabled, has
// a name, and whose type is one of the following values: ["file", "submit",
// "image", "reset", "button"]
// var type = (node.type||"").toLowerCase();
// return !node.disabled && node.name
// && !dojo.lang.inArray(["file", "submit", "image", "reset", "button"], type);
// //boolean
// }

/** Get all form elements : based on dojo dojo.io.encodeForm * */
function getAllFormElements() {
	var arrayElements = new Array();
	var allForms = document.getElementsByTagName("form");
	for ( var f = 0; f < allForms.length; f++) {
		for ( var i = 0; i < allForms[f].elements.length; i++) {
			var elm = allForms[f].elements[i];
			if (!elm || elm.tagName.toLowerCase() == "fieldset") {
				continue;
			}
			arrayElements.push(elm);
		}
	}

	return arrayElements;
}

/**
 * Vrnemo (true) ce je element na seznamu
 */
function filterForPotrdiPostopek(/* String */nameOrId) {
	return dojo.lang.inArray( [ "potrdiPostopek" ], nameOrId); // boolean
}

function disableFormFields() {
	if (form_fields_disabled == true)
		return;
	var arrayOfElemetns = getAllFormElements(); // Form.getElements($(_FORM_NAME));
	for ( var i = 0; i < arrayOfElemetns.length; i++) {
		var idOrName = arrayOfElemetns[i].id;
		if (idOrName.length == 0)
			idOrName = arrayOfElemetns[i].name;
		if (!filterForPotrdiPostopek(idOrName)) {
			// shranimo trenutno stanje elementov
			form_fields_state[idOrName] = arrayOfElemetns[i].disabled;
			var cssClass = arrayOfElemetns[i].className;
			form_fields_bg[idOrName] = cssClass;
			arrayOfElemetns[i].disabled = true;
			if (cssClass == "") {
				arrayOfElemetns[i].className = "potrditev";
			} // end-if
			else {
				arrayOfElemetns[i].className = arrayOfElemetns[i].className
						+ " potrditev";
			} // end-else
		}
	}
	form_fields_disabled = true;
}

function enableFormFields() {
	if (form_fields_disabled == false)
		return;
	var arrayOfElemetns = getAllFormElements(); // Form.getElements($(_FORM_NAME));
	for ( var i = 0; i < arrayOfElemetns.length; i++) {
		var idOrName = arrayOfElemetns[i].id;
		if (idOrName.length == 0)
			idOrName = arrayOfElemetns[i].name;
		if (!filterForPotrdiPostopek(idOrName)) {
			if (idOrName.length == 0)
				idOrName = arrayOfElemetns[i].name;
			arrayOfElemetns[i].disabled = form_fields_state[idOrName];
			arrayOfElemetns[i].className = form_fields_bg[idOrName];
		}
	}
	form_fields_disabled = false;
	form_fields_state = new Object();
	form_fields_bg = new Object()
}

var _FOCUS = "";
var _DISABLED = "";
var _ENABLED = "";
var _NAVIGATION = "";
var _FIELDERRORS = "";
var _JAVASCRIPT = "";
/** S spremenljivko stejemo stevilo poskusov za pri nalaganju strani */
var TIMEOUT_TRY = 0;
/** Maksimalno stevilo poskusov za nalaganje strani */
var TIMEOUT_MAX_TRY = 5;
var TIMEOUT = null;
var MOJDATE_ARRAY = new Array();
var SCRIPT_ARRAY = new Array();
/**
 * Fukcija, ki se naj poklice vedno ko izvrsimo AJAX nalaganje strani. Njene
 * naloge so: - nastavljenje fokus polja
 * 
 * data : text returned from request(the html) request: XMLHttpRequest object
 * widget: widget that published the topic
 */
var countdown = 1200;
var timeout = 1000;
var timer;
function startCountdown() {
	if(document.getElementById('numberCountdown')) {
		if ((countdown - 1) >= 0) {
			countdown = countdown - 1;
			var minutes = Math.round(countdown / 60) - 1;
			var seconds = countdown - minutes * 60;
			if (seconds >= 60) {
				seconds = seconds - 60;
				minutes = minutes + 1;
			}
			if (seconds < 10) {
				seconds = "0" + seconds;
			}
			document.getElementById('numberCountdown').innerHTML = minutes + ":"
					+ seconds;
			// document.getElementById('numberCountdown').innerHTML = countdown;
			if(minutes < 4 && minutes >= 3) {
				document.getElementById('numberCountdown').style.color = "#500000";
			} else if(minutes < 3 && minutes >= 2) {
				document.getElementById('numberCountdown').style.color = "#680000";
			} else if(minutes < 2 && minutes >= 1) {
				document.getElementById('numberCountdown').style.color = "#C80000";
			} else if(minutes < 1) {
				document.getElementById('numberCountdown').style.color = "#FF0000";
				document.getElementById('numberCountdown').style.visibility
					=(document.getElementById('numberCountdown').style.visibility
							=='visible')?'hidden':'visible';
			} else {
				document.getElementById('numberCountdown').style.color = "#707070";
			}
			document.getElementById('numberCountdown').style.fontStyle = "normal";
			timer = setTimeout('startCountdown()', timeout);
		} else {
			document.getElementById('numberCountdown').innerHTML = "Session expired!!!";
			document.getElementById('numberCountdown').style.color = "red";
			document.getElementById('numberCountdown').style.fontStyle = "bold";
			createAlphaSessionExpired();
		}
	}
}

function ajaxAfter(data, request, widget) {
	hideTooltip();
	// scroll(0,0);
	if (data.indexOf("<!--#INDEXPAGE:true") != -1) {
		alert("Seja je potekla!\nSession has expired!");
		self.parent.location = "/AmplioCMS2/index.jsp";
		return;
	}
	countdown = 1200;
	clearTimeout(timer);
	startCountdown();

	if (data.indexOf("<!--#ERRORPAGE:true") != -1) {
		var errArray = new Array();
		errArray.push("layout-content");
		widget.targetsArray = errArray;
		return;
	}

	if (data.indexOf("<!--#SEJATIMEOUT:true") != -1) {
		/*
		 * var errArray = new Array(); errArray.push("layout-container");
		 * widget.targetsArray = errArray;
		 */
		self.parent.location = "/AmplioCMS2/public/login-fail.jsp";
		return;
	}

	// dogodek
	var dogStart = data.indexOf("<!-- #DOGODEK:");
	if (dogStart != -1) {
		var dogEnd = data.indexOf(" -->", dogStart);
		self.parent.location = data.substring(dogStart + 14, dogEnd);
		return;
	}

	_FOCUS = "";
	_DISABLED = "";
	_ENABLED = "";
	_NAVIGATION = "";
	_FIELDERRORS = "";
	_JAVASCRIPT = "";

	var jsToken = readAjaxCommentData("<!-- ##JSTOKEN:", data);
	_FOCUS = readAjaxCommentData("<!-- ##FOCUS:", data);
	_DISABLED = readAjaxCommentData("<!-- ##DISABLED:", data);
	_ENABLED = readAjaxCommentData("<!-- ##ENABLED:", data);
	_NAVIGATION = readAjaxCommentData("<!-- ##NAVIGATION:", data);
	_FIELDERRORS = readAjaxCommentData("<!-- ##FIELDERRORS:", data);
	_JAVASCRIPT = readAjaxCommentData("<!-- ##JAVASCRIPT:", data);
	SCRIPT_ARRAY.push(_JAVASCRIPT);

	var myData = data;
	var ixDateS = myData.indexOf("Calendar.setup");
	while (ixDateS != -1) {
		var ixDateE = myData.indexOf(");", ixDateS);
		MOJDATE_ARRAY.push(myData.substring(ixDateS, ixDateE + 2));
		ixDateS = myData.indexOf("Calendar.setup", ixDateE + 2);
	}

	// za vsak <srcipt> </srcipt>
	var myData = data;
	var ixDateS = myData.indexOf("<script>");
	while (ixDateS != -1) {
		var ixDateE = myData.indexOf("</script>", ixDateS);
		SCRIPT_ARRAY.push(myData.substring(ixDateS + 8, ixDateE));
		ixDateS = myData.indexOf("<script>", ixDateE + 2);
	}

	var myData = data;
	var ixDateS = myData.indexOf("<script type=\"text/javascript\">");
	while (ixDateS != -1) {
		var ixDateE = myData.indexOf("</script>", ixDateS);
		SCRIPT_ARRAY.push(myData.substring(ixDateS + 33, ixDateE));
		ixDateS = myData.indexOf("<script type=\"text/javascript\">",
				ixDateE + 2);
	}

	TIMEOUT = window.setTimeout("activateTimeoutAjaxAfter(\'" + jsToken
			+ "\');", 100);

}

function changeLang(data, request, widget) {
	var reData = data;
	var start = reData.indexOf("<!-- URL:");
	if (start != -1) {
		var end = reData.indexOf("%> -->", start);
		var link = reData.substring(start + 9, end);
		var errArray = new Array();
		errArray.push("layout-container");
		widget.targetsArray = errArray;
		self.parent.location = "/AmplioCMS2/" + link;
		return;
	}
}

function ajaxAfterOnLoadExe(token, focus, disabled, enabled, navigation, fielderrors, jsfunctions) {
	
	_FOCUS      = "";
	_DISABLED   = "";
	_ENABLED    = "";
	_NAVIGATION = "";
	_FIELDERRORS = "";
	_JAVASCRIPT = "";
	
	var jsToken = token;
	_FOCUS = focus;
	_DISABLED = disabled;
	_ENABLED = enabled;
	_NAVIGATION = navigation;
	_FIELDERRORS = fielderrors;
	_JAVASCRIPT = jsfunctions;
	// window.setTimeout("activateTimeoutAjaxAfter(\'"+jsToken+"\');",100);
	ajaxAfterACTIVATED();
}

function activateTimeoutAjaxAfter(_jsToken) {
	// preverimo ce imamo dostop do elementa (pomeni, da element ze na ekranu)
	if (document.getElementById(_jsToken)) {
		clearTimeout(TIMEOUT);
		ajaxAfterACTIVATED();
	} else {
		clearTimeout(TIMEOUT);
		TIMEOUT_TRY = TIMEOUT_TRY + 1; // povecamo za en poiskus
		if (TIMEOUT_TRY < TIMEOUT_MAX_TRY) {
			TIMEOUT = window.setTimeout("activateTimeoutAjaxAfter(\'"
					+ _jsToken + "\');", 200);
		}
	}
}

function ajaxAfterACTIVATED() {
	TIMEOUT_TRY = 0;
	clearTimeout(TIMEOUT);
	
	if(_JAVASCRIPT != "") {
		var scriptArray = new Array();
		scriptArray.push(_JAVASCRIPT);
		eval(scriptArray.pop());
	}
	try {
		while (SCRIPT_ARRAY.length != 0) { 
			eval(SCRIPT_ARRAY.pop());
		}
	} catch (e) {
		// TODO: handle exception
	}
	SCRIPT_ARRAY = new Array();

	if (_DISABLED != "") {
		var arrayOfDisabled = _DISABLED.split(",");
		for ( var i = 0; i < arrayOfDisabled.length; i++) {
			if (document.getElementById(arrayOfDisabled[i])) {
				var de = document.getElementById(arrayOfDisabled[i]);
				if (de.nodeName == "A") {
					de.style.visibility = "hidden";
				} else if (de.nodeName == "IMG") {
					de.style.visibility = "hidden";
				} else {
					de.disabled = true;
				}
			} else {
				if (dojo.widget.byId(arrayOfDisabled[i])) {
					dojo.widget.byId(arrayOfDisabled[i]).disable();
				}
			}
		}
	}

	if (_ENABLED != "") {
		var arrayOfEnabled = _ENABLED.split(",");
		for ( var i = 0; i < arrayOfEnabled.length; i++) {
			if (document.getElementById(arrayOfEnabled[i])) {
				var de = document.getElementById(arrayOfEnabled[i]);
				if (de.nodeName == "A") {
					de.style.visibility = "visible";
				} else if (de.nodeName == "IMG") {
					de.style.visibility = "visible";
				} else {
					de.disabled = false;
				}
			} else {
				if (dojo.widget.byId(arrayOfDisabled[i])) {
					dojo.widget.byId(arrayOfDisabled[i]).enable();
				}
			}
		}
	}

	// nastvimo title
	if (_NAVIGATION != "") {
		var arrayOfNav = _NAVIGATION.split(",");
		var isAbsolute = false;
		var html = "";
		for ( var i = 0; i < arrayOfNav.length; i++) {
			if (i == 0) {
				firstChar = arrayOfNav[0].substring(0, 1); // command
				if (firstChar == "#") {
					isAbsolute = true;
					html = arrayOfNav[0].substring(1, arrayOfNav[0].length);
				} else {
					html = document.getElementById("layout-path").innerHTML;
					html += " -> " + arrayOfNav[0];
				}
			} else {
				html += " -> " + arrayOfNav[i];
			}
		}
		document.getElementById("layout-path").innerHTML = html;
	}

	// nastavi stile za field errorje
	if (_FIELDERRORS != "") {
		var pairs = _FIELDERRORS.split('&');
		for ( var i = 0; i < pairs.length; i++) {
			var values = pairs[i].split('=');
			// var value = URLDecode(pairs[1]);
			if (document.getElementById(values[0])) {
				var cssEl = document.getElementById(values[0]);
				if (cssEl.type && cssEl.type != "hidden") {
					document.getElementById(values[0]).className = (document
							.getElementById(values[0]).className + " err");
				} else {
					var elList = document.getElementsByTagName("input");
					for ( var r = 0; r < elList.length; r++) {
						if (elList[r].name == ("dojo." + values[0])) {
							elList[r].className = elList[r].className + " err";
						}
					}
				}
			}
		}

	}

	// nastavimo fokus polje
	if (_FOCUS != "") {
		document.getElementById(_FOCUS).focus();
	} else {
		setAutoFocus();
	}

	while (MOJDATE_ARRAY.length != 0) {
		eval(MOJDATE_ARRAY.pop());
	}

	/*
	 * _FOCUS = ""; _DISABLED = ""; _ENABLED = ""; _NAVIGATION = "";
	 * _FIELDERRORS = "";
	 */
}

function readAjaxCommentData(_COMMENT, _DATA) {
	var indexS = _DATA.indexOf(_COMMENT);
	if (indexS != -1) {
		var indexE = _DATA.indexOf(' -->', indexS);
		return _DATA.substring(indexS + _COMMENT.length, indexE);
	} // end if
	return "";
}

/**
 * Set focus on first input element, that is not disabled.
 */
function setAutoFocus() {
	/*
	 * var allForms = document.getElementsByTagName("form"); for(var f=0; f<allForms.length;
	 * f++) { for(var i = 0; i < allForms[f].elements.length; i++) { var elm =
	 * allForms[f].elements[i]; var type = (elm.type||"").toLowerCase(); if(!elm ||
	 * elm.tagName.toLowerCase() == "fieldset" || elm.disabled == true ||
	 * dojo.lang.inArray(["submit", "image", "reset", "button"], type)) {
	 * continue; } elm.focus(); return; } }
	 */
}

/**
 * Fukcija preveri ali ima JSON string kaj napaka, in le-te prikaze, drugace je
 * potrebno prikazati gumb "Dokoncno potrdi"
 * 
 * data : text returned from request(the html) request: XMLHttpRequest object
 * widget: widget that published the topic
 */
function afterPotrdiPos(data, request, widget) {

	var errors = StrutsUtils.getValidationErrors(data);

	// show errors, if any
	if (errors.fieldErrors) {
		for ( var fieldName in errors.fieldErrors) {
			for ( var i = 0; i < errors.fieldErrors[fieldName].length; i++) {
				var tmpErr = document.getElementById(fieldName);
				tmpErr.innerHTML = errors.fieldErrors[fieldName][i];
				tmpErr.style.display = "block";
			}
		}
	}
}

function clearAllErrors() {
	var errorSec = document.getElementsByTagName("span");
	for ( var i = 0; i < errorSec.length; i++) {
		if (errorSec[i].className == "jsonErr") {
			errorSec[i].style.display = "none";
		}
	}
}

function disableFields(_ARRAY) {
	alert(_ARRAY);
	for ( var i = 0; i < _ARRAY.length; i++) {
		alert("Name:" + _ARRAY[i]);
	}
}

/**
 * Fire onclick event with dojo. Uporabljamo ta textfield, kjer s pritiskon na
 * ENTER klicemo fukcijo click na gumbu.
 */
function onEnterClick(e, _BUTTON) {
	var code;
	if (!e)
		var e = window.event;
	if (e.keyCode)
		code = e.keyCode;
	else if (e.which)
		code = e.which;
	// var character = String.fromCharCode(code);
	if (code == 13) {
		// document.getElementById(_BUTTON).focus();
		fireMouseEvent(_BUTTON, 'click');
	}
}

function findPosition(oElement) {
	if (typeof (oElement.offsetParent) != 'undefined') {
		for ( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
		return [ posX, posY ];
	} else {
		return [ oElement.x, oElement.y ];
	}
}

function getElementHeight(Elem) {
	if (document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}
	return elem.offsetHeight;
}

function getElementWidth(Elem) {
	if (document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}
	return elem.offsetWidth;
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if (typeof (window.innerWidth) == 'number') {
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if (document.documentElement
			&& (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if (document.body
			&& (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
}

function onloadMenu() {
	// document.getElementById('layout-menu').style.height = (getWindowSize()[1]
	// -63) + "px";
	// document.getElementById('layout-menu-inner').style.height =
	// (getWindowSize()[1] -63 -15) + "px";
}

function preloadImages() {
	if (document.images) {
		pic1 = new Image();
		pic1.src = "/AmplioCMS2/images/ajax-loader.gif";
	}
}

function pageIsLoading(count) {
	if (count < 5) {
		if (document.getElementById("pageIsLoading")) {
			preloadImages();
			document.getElementById("pageIsLoading").style.display = "none";
		} else {
			window.setTimeout("pageIsLoading(" + (count++) + ");", 100);
		}
	}
}

/** Namenske funkcije */

/* DATUM */

Datum = function() {
};

// Non-Leap year Month days..
Datum.DOMonth = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
// Leap year Month days..
Datum.lDOMonth = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

Datum.daysOfMonth = function(monthNo, p_year) {
	/*
	 * Check for leap year .. 1.Years evenly divisible by four are normally leap
	 * years, except for... 2.Years also evenly divisible by 100 are not leap
	 * years, except for... 3.Years also evenly divisible by 400 are leap years.
	 */
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Datum.DOMonth[monthNo];

		return Datum.lDOMonth[monthNo];
	} else
		return Datum.DOMonth[monthNo];
}

function trimAll(sString) {
	while (sString.substring(0, 1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length - 1, sString.length) == ' ') {
		sString = sString.substring(0, sString.length - 1);
	}
	return sString;
}

function mrvlIsNaN(value) {
	if (value == null || trimAll(value).length == 0)
		return true;
	else
		return isNaN(value);
}

Datum.toDatum = function(strDate) {
	// ali je datum tima DD.MM.YYYY
	if (strDate.indexOf('.') != -1) {
		var array = strDate.split('.');
		if (array.length != 3) {
			return null;
		}
		// preverimo leto
		if (mrvlIsNaN(array[2])) {
			return null;
		} else if (parseInt(array[2]) < 1900 || parseInt(array[2]) > 2099) {
			return null;
		}
		// preverimo mesec
		if (mrvlIsNaN(array[1]) || parseInt(array[1] - 1) > 11) {
			return null;
		}
		// preverimo dan
		if (mrvlIsNaN(array[0])
				|| parseInt(array[0]) > Datum.daysOfMonth(
						parseInt(array[1] - 1), parseInt(array[2]))) {
			return null;
		}
		return new Date(array[2], array[1] - 1, array[0]);
	} else if (strDate.length == 8) {
		// preverimo leto
		if (mrvlIsNaN(strDate.substring(4, 8))) {
			return null;
		} else if (parseInt(strDate.substring(4, 8)) < 1900
				|| parseInt(strDate.substring(4, 8)) > 2099) {
			return null;
		}
		// preverimo mesec
		if (mrvlIsNaN(strDate.substring(2, 4))
				|| parseInt(strDate.substring(2, 4) - 1) > 11) {
			return null;
		}
		// preverimo dan
		if (mrvlIsNaN(strDate.substring(0, 2))
				|| parseInt(strDate.substring(0, 2)) > Datum.daysOfMonth(
						parseInt(strDate.substring(2, 4) - 1), parseInt(strDate
								.substring(4, 8)))) {
			return null;
		}

		return new Date(strDate.substring(4, 8), strDate.substring(2, 4) - 1,
				strDate.substring(0, 2));
	} else {
		return null;
	}
}

Datum.getJsDate = function(formElement) {
	var strDate = formElement.value;
	// ali je datum tima DD.MM.YYYY
	if (strDate.indexOf('.') != -1) {
		var array = strDate.split('.');
		if (array.length != 3) {
			alert("Napa\u010dno podan datum: " + strDate);
			return null;
		}
		// preverimo leto
		if (mrvlIsNaN(array[2])) {
			alert("Napa\u010dno podan datum: leto \'" + array[2]
					+ "\' je nepravilno podano");
			return null;
		} else if (parseInt(array[2]) < 1900 || parseInt(array[2]) > 2199) {
			alert("Napa\u010dno podan datum: leto naj bo podano med 1900 in 2199");
			return null;
		}
		// preverimo mesec
		if (mrvlIsNaN(array[1]) || parseInt(array[1] - 1) > 11) {
			alert("Napa\u010dno podan datum: mesec \'" + array[1]
					+ "\' je nepravilno podan");
			return null;
		}
		// preverimo dan
		if (mrvlIsNaN(array[0])
				|| parseInt(array[0]) > Datum.daysOfMonth(
						parseInt(array[1] - 1), parseInt(array[2]))) {
			alert("Napa\u010dno podan datum: dan \'" + array[0]
					+ "\' je nepravilno podan");
			return null;
		}
		return new Date(array[2], array[1] - 1, array[0]);
	} else if (strDate.length == 8) {
		// preverimo leto
		if (mrvlIsNaN(strDate.substring(4, 8))) {
			alert("Napa\u010dno podan datum: leto \'" + strDate.substring(4, 8)
					+ "\' je nepravilno podano");
			return null;
		} else if (parseInt(strDate.substring(4, 8)) < 1900
				|| parseInt(strDate.substring(4, 8)) > 2199) {
			alert("Napa\u010dno podan datum: leto naj bo podano med 1900 in 2199");
			return null;
		}
		// preverimo mesec
		if (mrvlIsNaN(strDate.substring(2, 4))
				|| parseInt(strDate.substring(2, 4) - 1) > 11) {
			alert("Napa\u010dno podan datum: mesec \'"
					+ strDate.substring(2, 4) + "\' je nepravilno podan");
			return null;
		}
		// preverimo dan
		if (mrvlIsNaN(strDate.substring(0, 2))
				|| parseInt(strDate.substring(0, 2)) > Datum.daysOfMonth(
						parseInt(strDate.substring(2, 4) - 1), parseInt(strDate
								.substring(4, 8)))) {
			alert("Napa\u010dno podan datum: dan \'" + strDate.substring(0, 2)
					+ "\' je nepravilno podan");
			return null;
		}

		return new Date(strDate.substring(4, 8), strDate.substring(2, 4) - 1,
				strDate.substring(0, 2));
	} else {
		alert("Napa\u010dno podan datum: " + strDate);
		return null;
	}
}

Datum.twoDigit = function(intValue) {
	if (intValue < 10) {
		return "0" + intValue;
	} else {
		return intValue;
	}
}

Datum.onBlur = function(formElement) {
	if (trimAll(formElement.value).length == 0)
		return;
	var datum = Datum.getJsDate(formElement);
	if (datum != null) {
		formElement.value = Datum.twoDigit(datum.getDate()) + "."
				+ Datum.twoDigit(datum.getMonth() + 1) + "."
				+ datum.getFullYear();
	}
}

function sifrantCallback() {
	var p = arguments[0];
	for ( var i = 1; i < arguments.length; i++) {
		var pair = arguments[i].split('=');

		if (document.getElementById(pair[0])) {
			document.getElementById(pair[0]).value = p[parseInt(pair[1])];
		} else {

			var autoCompleter = dojo.widget.byId(pair[0]);
			if (autoCompleter) {
				autoCompleter.textInputNode.value = p[parseInt(pair[1])];
				// autoCompleter.comboBoxValue.value
			} else {
				var allInputs = document.getElementsByTagName("input");
				for ( var j = 0; j < allInputs.length; j++) {
					if (allInputs[j].name == pair[0]) {
						allInputs[j].value = p[parseInt(pair[1])];
						break;
					}
				}
			}
		}
	}
}

/**
 * Funckija vrne vrednost scrolanja v pikslih!
 */
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if (typeof (window.pageYOffset) == 'number') {
		// Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if (document.body
			&& (document.body.scrollLeft || document.body.scrollTop)) {
		// DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement
			&& (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		// IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

// funkcija za implementacijo expand seznamov
// whichLayer - kateri DIV zapremo oz. zapremo
// steviloLayerjev - stevilo ->da funkcija ve, do kot z for zanko
// zapirajOstale - nam pove, ali bo hkrati odprt le en div, ali poljubno stevilo
// -- > samo v tem primeru potrebujemo stevilo layerjev
function toggleLayer(prefix, whichLayer, steviloLayerjev, zapirajOstale) {

	// dodam predpono CollapseID, da vemo, katere DIVe je potrebno skrivati
	whichLayer = prefix + whichLayer;
	// najprej vse skrijem (razen tistega, na katerega kliknemo)
	if (zapirajOstale == "true") {
		for ( var i = 0; i <= steviloLayerjev; i++) {
			if (whichLayer != "CollapseID" + i)
				document.getElementById("CollapseID" + i).style.display = "none";
		}
	}

	// prikazem oz. zaprem div, glede na to ali je odprt ali zaprt
	var elem, vis;
	if (document.getElementById) // this is the way the standards work
		elem = document.getElementById(whichLayer);
	else if (document.all) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if (document.layers) // this is the way nn4 works
		elem = document.layers[whichLayer];

	vis = elem.style;
	// ce div nima lastnostni display, to ugotovimo tukaj
	if (vis.display == '' && elem.offsetWidth != undefined
			&& elem.offsetHeight != undefined)
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block'
				: 'none';

	// ce je priakzan ga skrijem, ce je skrit, ga prikazem
	vis.display = (vis.display == '' || vis.display == 'block') ? 'none'
			: 'block';

	if (vis.display == 'none') {
		removeChildNodes(elem);
		return true;
	} else {
		return false;
	}
}

var jsForUP = new Object();

function getFormElementValueRadio(f_name) {
	var formElement = document.getElementsByName(f_name);
	for (i = 0; i < formElement.length; i++) {
		if (formElement[i].checked == true)
			return formElement[i].value;
	}
	return null;
}

function checkOdDo() {
	var timeType = getFormElementValueRadio("searchDatum");
	var intervalOd, intervalDo;
	var checkInterval = false;
	if (timeType == "OD_DO") {
		intervalOd = document.getElementById("searchDatumOd");
		intervalDo = document.getElementById("searchDatumDo");
		checkInterval = true;
	} else if (timeType == "OD_DO_POIZBIRI") {
		intervalOd = document.getElementById("searchDatumOdPoIzbiri");
		intervalDo = document.getElementById("searchDatumDoPoIzbiri");
		checkInterval = true;
	}
	if (checkInterval == true
			&& (getJsDate(intervalOd) == null || getJsDate(intervalDo) == null))
		return false;

	if (checkInterval == true) {
		if (getJsDate(intervalOd) != null && getJsDate(intervalDo) != null
				&& getJsDate(intervalOd) > getJsDate(intervalDo)) {
			alert("Datum do mora biti ve\u010dji od datuma od !");
			return false;
		}
	}
	return true;
}

function checkMultibox(boolValue, fieldName, fieldValue) {
	var checkboxes = document.getElementsByTagName('input');
	var boolChecked = boolValue;
	for (i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].type == "checkbox" && checkboxes[i].name == fieldName
				&& checkboxes[i].value == fieldValue)
			checkboxes[i].checked = boolChecked;
	}
}

function checkRadios(boolValue, fieldName, fieldValue) {
	var checkboxes = document.getElementsByTagName('input');
	var boolChecked = boolValue;
	for (i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].type == "radio" && checkboxes[i].name == fieldName
				&& checkboxes[i].value == fieldValue)
			checkboxes[i].checked = boolChecked;
	}
}

function selectCheckboxes(boolValue, fieldName) {
	var checkboxes = document.getElementsByTagName('input');
	var boolChecked = boolValue;
	for (i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].type == "checkbox" && checkboxes[i].name == fieldName)
			checkboxes[i].checked = boolChecked;
	}
}

function selectDropdown(value, fieldName) {
	if(document.getElementById(fieldName)) {
		document.getElementById(fieldName).value = value;	
	}	
}

function disableCheckboxes(boolValue, fieldName) {
	var checkboxes = document.getElementsByTagName('input');
	var boolChecked = boolValue;
	for (i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].type == "checkbox" && checkboxes[i].name == fieldName)
			checkboxes[i].disabled = boolChecked;
	}
}
function validateNotEmptyCheckbox() {
	var checkboxes = document.getElementsByTagName('input');
	for (i = 0; i < arguments.length; i++) {
		var fieldName = arguments[i];
		var atLeastOne = false;
		for (j = 0; j < checkboxes.length; j++) {
			if ((checkboxes[j].type == "checkbox" || checkboxes[j].type == "radio")
					&& checkboxes[j].name == fieldName
					&& checkboxes[j].checked == true)
				atLeastOne = true;
		}
		if (atLeastOne == false) {
			alert("Izberi vsaj en iskalni parameter v vsaki skupini");
			return false;
		}
	}
	return checkOdDo();
}

/** prikaze ali skrije polje */
function prikaziSkrij(formField, prikazi) {
	if (prikazi == true) {
		document.getElementById(formField).style.visibility = "visible";
	} else if (prikazi == false) {
		document.getElementById(formField).style.visibility = "hidden";
	}
}

function brezEnter(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode == 13) {
		return false;
	} else {
		return true;
	}
}

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
}

function highlight(obj) {
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		var ieversion = new Number(RegExp.$1)
		if (ieversion < 7) {
			obj.className = 'highlight-hover';
		}
	}
}
function highlightOut(obj) {
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		var ieversion = new Number(RegExp.$1)
		if (ieversion < 7) {
			obj.className = 'highlight';
		}
	}
}

function disable(fieldId) {
	document.getElementById(fieldId).disabled = true;
}

function selectRadio(fieldId) {
	document.getElementById(fieldId).checked = true;
}

function showRequiredTaxLabel() {
	var type = document.getElementById('userRVO.companyTypeId').value;
	if (type == 1) {
		document.getElementById('taxLabel').innerHTML = "Dav\u010dna \u0161t. podjetja";
	} else if (type == 2) {
		document.getElementById('taxLabel').innerHTML = "Dav\u010dna \u0161t. podjetja *";
	}
}

function checkFCK(tagId) {
	var fckcontent = FCKeditorAPI.GetInstance(tagId).GetXHTML();
	// alert(fckcontent);
	document.getElementById(tagId).value = fckcontent;
}

function changeVisibility(tagId) {
	document.getElementById(tagId).style.visibility
	=(document.getElementById(tagId).style.visibility
			=='visible')?'hidden':'visible';
}

function check4podrobnosti(value) {
	if(value == 1) {
		document.getElementById('newsExtendId').style.visibility = "visible";
	} else {
		document.getElementById('newsExtendId').style.visibility = "hidden";
	}
}

function insertLinkToFck() {
	var linkId = getFormElementValue('idOverMenu',true);
	var linkText = document.getElementById('linkText').value;
	var htmlLink = '<a indicator="ajaxIndicator" '+
		' showError="true" showLoading="false" afterNotifyTopics="/ajaxAfter" targets="layout-content"'+
		' href="/AmplioCMS2/public/MenuPublic-viewPublic.cms2?menuId='+linkId+'" ajaxAfterValidation="false" ' +
    	' validate="false" dojoType="struts:BindAnchor" id="viewPublicFck'+linkId+'">'+linkText+'</a> '+
    	' <script type="text/javascript">djConfig.searchIds.push("viewPublicFck'+linkId+'");</script> ';
	FCKeditorAPI.GetInstance('editField').InsertHtml(htmlLink);
	
}

function popupnotice(notice) {
	alert(notice);
}

function setHiddenMenuId(id,subtekst) {
	window.location.hash = "menuId="+id;
	document.title = subtekst;
	selectedHash = document.location.hash;
	if(intervalHashSearch == '') {
		initializeHashSearch();
	}
}

function setHiddenNewsId(id,subtekst) {
	window.location.hash = "newsId="+id;
	document.title = subtekst;
	selectedHash = document.location.hash;
	setCookie('hiddenNewsId',"delete",1,false);
	if(intervalHashSearch == '') {
		initializeHashSearch();
	}
}

function publishLinkTarget() {
	var param = window.location.hash;
	if(param) {
		if(param.indexOf("menuId") > 0) {
			var id = param.split("=", 2);
			if(id[1]) {
				setCookie('hiddenMenuId',id[1],1,false);
				setTimeout('publishLayoutContent()', 100);
			}
		} else if(param.indexOf("newsId") > 0) {
			var id = param.split("=", 2);
			if(id[1]) {
				setCookie('hiddenNewsId',id[1],1,false);
				setTimeout('publishLayoutContent()', 100);
			}
		} else {
			document.location.hash = "";
			window.location.reload();
			debug("publish link location reload");
			stopHashSearch();
		}
	}
}

var selectedHash = '';
var intervalHashSearch = '';
function initializeHashSearch() {
	intervalHashSearch = window.setInterval('checkHash()', 500);
}

function stopHashSearch() {
	window.clearInterval(intervalHashSearch);
	intervalHashSearch = '';
}

function checkHash() {
	var currentHash = document.location.hash;
	if(currentHash == '') {
		stopHashSearch();
		debug("chechkHash location /AmplioCMS2/index.jsp");
		self.parent.location = "/AmplioCMS2/index.jsp";
	}
	if(selectedHash != currentHash) {
		selectedHash = currentHash;
		publishLinkTarget();
	}
}

function publishLayoutContent() {
	dojo.event.topic.publish("layoutContentTarget");
}

var intervalRandomPic = '';
function initializeRandomGallery() {
	if(intervalRandomPic == '') {
		intervalRandomPic = window.setInterval('publishRandomPic()', 4000);
	}
}

function get_url_parameter( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
	    return "";
	  else
	    return results[1];
}

var uploaded = false;
function checkUploadedFiles(){
	var ret = true;
	if(!uploaded) {
		ret = confirm("Niste pripeli datotek. \u017delite nadaljevati?");
	}
	return ret;
}
function setUploaded(arg) {
	uploaded = arg;
}

function changedSelection1(id,takeFromSession) {
	document.getElementById("hiddenGroupId").value = id;
	document.getElementById("takeFromSession").value = takeFromSession;
	dojo.event.topic.publish('selection1changed'+id);
}

function changedSelection2(id,takeFromSession) {
	document.getElementById("hiddenGroupId").value = id;
	document.getElementById("takeFromSession").value = takeFromSession;
	dojo.event.topic.publish('selection2changed'+id);
}

function changedSelection3(id,takeFromSession) {
	document.getElementById("hiddenGroupId").value = id;
	document.getElementById("takeFromSession").value = takeFromSession;
	dojo.event.topic.publish('selection3changed'+id);
}

function changedSelection4(id,takeFromSession) {
	document.getElementById("hiddenGroupId").value = id;
	document.getElementById("takeFromSession").value = takeFromSession;
	dojo.event.topic.publish('selection4changed'+id);
}

function changedSelection5(id,takeFromSession) {
	document.getElementById("hiddenGroupId").value = id;
	document.getElementById("takeFromSession").value = takeFromSession;
	dojo.event.topic.publish('selection5changed'+id);
}

function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

function showBasket() {
	if($('#printheonbasketdiv').hasClass('hidden')) {
		$('#printheonbasketdiv').removeClass('hidden');
		window.scrollTo(0,0);
	} else {
		$('#printheonbasketdiv').addClass('hidden');
	}
}

function toggleYesNoDropdown(fieldId,go)  {
	if(go) {
		$('#'+fieldId).show();	
	} else {
		$('#'+fieldId).hide(400);				
	}
	 
}

function publishRandomPic() {
	dojo.event.topic.publish("randomPictureTarget");
}

function highlight_on(thisobj, color) {
	thisobj.style.backgroundColor = color;
}

function highlight_off(thisobj, color) {
	thisobj.style.backgroundColor = color;
}

function checkUsername() {
	dojo.event.topic.publish("usernameTarget");
}

function checkModule() {
	dojo.event.topic.publish("checkModuleTarget");
}

function shortCutDodajNovico() {
	dojo.event.topic.publish("shortCutDodajNovicoTarget");
}

function shortCutDodajKategorijo() {
	// createAlpha();
	dojo.event.topic.publish("shortCutDodajKategorijoTarget");
}

function changeEventCalendarCategory() {
	dojo.event.topic.publish("changeEventCalendarCategoryTarget");
}

function changeEventCalendarDate() {
	dojo.event.topic.publish("changeEventCalendarDateTarget");
}

function changeMailGroup() {
	dojo.event.topic.publish("changeMailGroupTarget");
}

function changeGroup() {
	dojo.event.topic.publish("changeGroupTarget");
}

function changePartnerCategory() {
	dojo.event.topic.publish("changePartnerCategoryTarget");
}

function changeNewsCategory() {
	dojo.event.topic.publish("changeNewsCategoryTarget");
}

function changeUsersGroup() {
	dojo.event.topic.publish("changeUsersGroupTarget");	
}

function afterChangeOrderStatusSuccess() {
	dojo.event.topic.publish("afterChangeOrderStatusSuccess");	
}

function show_list() {
	dojo.event.topic.publish("showUploadedListTarget");
}

eval(pageIsLoading(0));

function debug(arg) {
	//alert(arg);
}
