/* prikazovanje in skrivanje menija */
function changeMenu(id, total) {
  for (i=total;i>=0;i--)
  {
    if (i!=id) {hideMenu('submenu' + i);};
  };
  showMenu('submenu' + id);
}

function hideMenu(d) {
	if(d.length < 1) {
		return;
	}
	document.getElementById(d).style.display = "none";
}

function showMenu(d) {
	if(d.length < 1) {
		return;
	}
	document.getElementById(d).style.display = "block";
}

function classMenu(obj, pos) {
	var linkList = document.getElementById("menu").getElementsByTagName("li");
	for (i = 0; i < linkList.length; i++) {
		linkList[i].className = "";
	}
	if (pos == 1) {
		obj.className = "first-selected";
	}
	else {
		obj.previousSibling.className = "none";
		obj.className = "selected";	
	}
}

/* odpre napredni iskalnik */
function openLayerCMS(link, lang) {
	var i=0
	for (i=0;i<link.childNodes.length;i++) {
		if (document.images[link.childNodes[i].id] != null ) {
			link.childNodes[i].src = "../img/" + lang + "/button-napredno-iskanje-off.gif";
			break;
		}
	}	
	link.onclick = new Function("closeLayerCMS(this,'" + lang + "');return false;");
	document.getElementById("detailSearch").style.display = "block";
}


function closeLayerCMS(link, lang) {
	var i=0
	for (i=0;i<link.childNodes.length;i++) {
		if (document.images[link.childNodes[i].id] != null ) {
			link.childNodes[i].src = "../img/" + lang + "/button-napredno-iskanje-on.gif";
			break;
		}
	}	
	link.onclick = new Function("openLayerCMS(this,'" + lang + "');return false;");
	document.getElementById("detailSearch").style.display = "none";
}

/* funkcija za prikaz tabele */
function showTable(div, img) {
	imgTableOpen = new Image();
	imgTableOpen.src = '../img/icon-down.gif.gif';
	
	imgTableClose = new Image();
	imgTableClose.src = '../img/icon-next.gif';

	var divDisplay = document.getElementById(div).style.display;
	var imgDisplay = document.images[img].src
	
	if (divDisplay == 'none') {
		document.getElementById(div).style.display = 'block';
		document.images[img].src = '../img/icon-down.gif';
	}
	else {
		document.getElementById(div).style.display = 'none';
		document.images[img].src = '../img/icon-next.gif';
	}
}

/* sprememba velikosti fontov in kontrast*/
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
	
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

/* dodaj med priljubljene */
function bookmarkSite(title, url) {
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}

/* spletna mesta KD */
var hideSitesTimer = null;

function showSites() {
	stopSitesTimer();
	document.getElementById('kd-sites').style.display = "block";
}

function hideSites() {
	stopSitesTimer();
	document.getElementById('kd-sites').style.display = "none";
}

function startSitesTimer() {
	stopSitesTimer();
	hideSitesTimer = setTimeout('hideSites()',500);
}

function stopSitesTimer() {
	if (hideSitesTimer != null) {
		clearTimeout(hideSitesTimer);
		hideSitesTimer = null;
	}
}


    function EasterSunday(year)
    {
        var g = year % 19;
        var c = year / 100;
        var h = (c - Math.floor(c / 4) - Math.floor((8 * c + 13) / 25) 
                                            + 19 * g + 15) % 30;
        var i = h - Math.floor(h / 28) * (1 - Math.floor(h / 28) * 
                    Math.floor(29 / (h + 1)) * Math.floor((21 - g) / 11));

        var day   = i - ((year + Math.floor(year / 4) + 
                      i + 2 - c + Math.floor(c / 4)) % 7) + 28;
        var month = 3;

        if (day > 31)
        {
            month++;
            day = day - 31;
        }
        var easterDate = new Date();
        easterDate.setFullYear(year, month - 1, day);
        easterDate.setHours(0,0,0,0);
        return easterDate;
    } 
    
    function EasterMonday(year)    
    {
        var easterSunday = EasterSunday(year);
        var date1 = easterSunday;
        easterSunday.setDate(easterSunday.getDate() + 1);
        return date1;
    }

    function DateSame(datum1, datum2)    
    {
        return (!(datum1 < datum2) && !(datum1 > datum2));
    }

    function IsSloHoliday(datum)
    {
        var returnValue = false;
        
        var tempDatum = new Date();
        tempDatum.setHours(0,0,0,0);
        try
        {
            datum.setHours(0,0,0,0);
            tempDatum.setFullYear(datum.getFullYear());
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(0,1)));
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(0,2)));            
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(1,8)));
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(3,27)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(4,1)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(4,2)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(5,25)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(7,15)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(9,31)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(10,1)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(11,25)));                        
            returnValue = returnValue | DateSame(datum, (tempDatum.setMonth(11,26)));                        
            returnValue = returnValue | DateSame(datum, EasterMonday(datum.getFullYear()))
       
        }
        catch (ex)
        {
        }
        return returnValue;                            
    }
    
    function clickDefaultButton(e, buttonid){
      var evt = e ? e : window.event;

      var bt = document.getElementById(buttonid);

      if (bt){

          if (evt.keyCode == 13){

                bt.click();

                return false;

          }

      }

    }
    
    function WebDateChooser_CalendarRenderDay(oCalendar, oDay, oEvent)
    {
        var currentDay = new Date();
        currentDay.setFullYear(oDay.year, oDay.month-1, oDay.day);
        oDay.css = oDay.css = oCalendar.css[0];
        
        var isCurrentDaySelected = (oDay.selected == true);
        var isCurrentDayToday = ((oCalendar.today != null) && (oCalendar.today[0] == oDay.year)  && (oCalendar.today[1] == oDay.month) && (oCalendar.today[2] == oDay.day));
        var isCurrentDayWeekendHoliday = ((IsSloHoliday(currentDay)== true ) || (oDay.dow == 6) || (oDay.dow == 0));
        var isCurrentDayInCurrentMonth = !(((oDay.day > 8) && (oDay.index < 8)) || ((oDay.day < 15) && (oDay.index > 27)));
        
        if (isCurrentDaySelected || isCurrentDayToday)
        {
            if (isCurrentDaySelected) oDay.css = oDay.css + " " + oCalendar.css[4];
            if (isCurrentDayToday) oDay.css = oDay.css + " " + oCalendar.css[3];
        }
        else if (isCurrentDayWeekendHoliday) oDay.css = oDay.css + " " + oCalendar.css[1];
        else if (!isCurrentDayInCurrentMonth) oDay.css  = oDay.css + " " + oCalendar.css[2];
        
        if ((IsSloHoliday(currentDay)== true ) || (oDay.dow == 6) || (oDay.dow == 0) || (currentDay < oCalendar.MinDate))
        {   
            oDay.element.style.cursor = "not-allowed";
        }
        else
        {
            oDay.element.style.cursor = "";
        }
    } 
    
    function WebDateChooser_CalendarDayChanging(oCalendar, oDay, oEvent)
    {
        if ((IsSloHoliday(oDay)== true ) || (oDay.getDay() == 6) || (oDay.getDay() == 0) || (oDay < oCalendar.MinDate))
        {   
            oEvent.cancel = true;
        }
    }     
    
    /* Metode za delo s popup-i (PopupControl.ascx - Ajax Extension Toolkit, ModalPopUp) */
    
    function setIframeScroll(iframeid, mode) { // mode can be either "yes" or "no"
         var oldIframe = document.getElementById(iframeid);
         if ((oldIframe != null) && (mode != null))
         {
             var newIframe = oldIframe.cloneNode(true);
             newIframe.attributes.scrolling.value = mode;
             oldIframe.parentNode.insertBefore(newIframe, oldIframe);
             newIframe.parentNode.removeChild(oldIframe);
         }
    }
    
    // tiskanje frame-a
    function printFrameByID(frameID)
    {
        var frameObj = document.getElementById(frameID);
        if (frameObj != null)
        {
            var frameWindow = frameObj.contentWindow || frameObj;
            frameWindow.focus();
            frameWindow.print();
        }
    }
        
    // zapiranje popup-a    
    function closeModalPopUp(behaviourID)
    {
      var modalPopup = $find(behaviourID);
      if (modalPopup != null) modalPopup.hide();
    }

    // prikaz popup-a
    function showModalPopUp(behaviourID)
    {
      var modalPopup = $find(behaviourID);
      if (modalPopup != null) modalPopup.show();
    }

    // preverjanje, če je stran odprta v frame-u / samostojno 
    function isInIFrame()
    {
        return (window.top!=window.self);
    } 
    
    // osnovna funkcija, ki se kliče, ko gremo iz nadokna, nazaj v polje za izbiro elementa    
    function BasicModalPopUpCallBack(callBackTargetControl, callBackParams)
    {
        if ((callBackTargetControl != null) && (callBackTargetControl.value != null))
        {
            callBackTargetControl.value = callBackParams;
            
            if (callBackTargetControl.MPBehaviourID != null) closeModalPopUp(callBackTargetControl.MPBehaviourID);            
        }
    }
    
    // osnovna funkcija, ki se kliče, da poberemo parametre polja za izbiro elementa
    function BasicModalPopUpGetParams(targetControl)
    {
        var params = null;
        if ((targetControl != null) && (targetControl.value != null))
        {
            params = targetControl.value;
        }
        return params;
    }    
    
    // funkcija vrne HtmlDomDocument objekt iframe-a neodvisno od browserja
    function GetIFrameDocument(iFrameObject)
    {
        var oDoc = iFrameObject.contentWindow || iFrameObject.contentDocument;
        if (oDoc.document) {
            oDoc = oDoc.document;
        }   
        return oDoc;
    }
    
    // funkcija nastavi IFrame-u podatke za CallBack - target kontrolo in funkcija ki se kliče
    // parametri:
    //  -iFrameObject           (IFrame objekt)
    //  -callBackFunc           (pointer na funkcijo, ki prejme 1. argument objekt kontrole, 2. argument parametre callback-a)
    //  -callBackTargetControl  (objekt kontrole, ki se lahko uporabi za 1. argument pri klicu callBackFunc)
    function SetIframeCallBackData(iframeObject, callBackFunc, callBackTargetControl)
    {        
       try
       {
        var oDoc = GetIFrameDocument(iframeObject);        
        oDoc.JsCallBackFunc = callBackFunc;
        oDoc.JsCallBackTargetControl = callBackTargetControl;
       }
       catch (ex) {}
    }
    
    function JSHTMLEncode (str)
    {
        var div = document.createElement('div');
        var text = document.createTextNode(str);
        div.appendChild(text);
        return escape(div.innerHTML);
    }; 
    
    
    // pomožna funkcija ki jo dodajamo v objekt za modalpopup- naloada ModalPopUp z URL-jem in (poljubno) nastavi parametre za callback
    // parametri:
    //  -strURL                 (URL ki se odpre v frame-u)
    //  -callBackFunc           (pointer na funkcijo, ki prejme 1. argument objekt kontrole, 2. argument parametre callback-a)
    //  -getURLParamStringFunc  (pointer na funkcijo, ki prejme 1. argument objekt kontrole in vrne parametre za nadokno, ki se jih doda URL-ju- se jih tudi zakodira)    
    //  -targetControl  (objekt kontrole, ki se lahko uporabi za 1. argument pri klicu callBackFunc)
    function Cstm_LoadURL_Func(strURL, callBackFunc, getURLParamStringFunc, targetControl)
    {
        if ((this !=null) && (this.Cstm_IFrameID != null) && (document.getElementById(this.Cstm_IFrameID) != null))
        {
            var iFrameObjID = this.Cstm_IFrameID;
            var iFrameObj = document.getElementById(iFrameObjID);            
            var urlParamString = "";
            if (getURLParamStringFunc != null) try {urlParamString=getURLParamStringFunc(targetControl);} catch(ex) {};
            if ((urlParamString != "") && (urlParamString != null))
            {
                urlParamString = JSHTMLEncode(urlParamString);
                strURL = strURL + ((strURL.indexOf('?') > -1) ? '&' : '?') + 'Params='+urlParamString;
            }
            
            iFrameObj.src = strURL;            
           
            if ((callBackFunc != null) || (targetControl !=null))
            {
                iFrameObj.onload = function () {SetIframeCallBackData(iFrameObj, callBackFunc, targetControl);};
                iFrameObj.onreadystatechange = function () {if (iFrameObj.readyState=='complete') SetIframeCallBackData(iFrameObj, callBackFunc, targetControl);};
            }
        }
    }
    
    
    function SetModalPopUpPropertiesByID(strMPBehaviourID, intWidth, intHeight, scrollbarVisibility)
    {
        var mpObject = $find(strMPBehaviourID);
        if ((mpObject != null) && (mpObject.Cstm_LoadURL != null) && (mpObject.Cstm_IFrameID != null))
        {
            var iFrameObj = document.getElementById(mpObject.Cstm_IFrameID);
            if (intWidth != null) try { iFrameObj.width = intWidth; } catch (ex) {};
            if (intHeight != null) try { iFrameObj.height = intHeight; } catch (ex) {};            
            try {setIframeScroll(mpObject.Cstm_IFrameID, scrollbarVisibility);} catch (ex) {};     
            try
            {
                for (i=0;i<$(".iframe-window").length;i++)
                {
                    $(".modalPopup")[i].style.width= $(".iframe-window")[i].width;                                                        
                    $(".top-window")[i].style.width= $(".iframe-window")[i].width;
                    $(".bottom-window")[i].style.width= $(".iframe-window")[i].width;
                }
            }   
            catch (ex) {};         
        }        
    }
    
    function SetModalPopUpProperties(intWidth, intHeight, scrollbarVisibility)
    {
        SetModalPopUpPropertiesByID('CustomMP', intWidth, intHeight, scrollbarVisibility);
    }    
    
    // naloadamo popupcontrolo z URL-jem in ga odpremo
    // parametri:
    //  -strMPBehaviourID       (Behaviour ID popup-a)    
    //  -strURL                 (URL ki se odpre v frame-u)
    //  -showScrollBars         (ali v iFrame-u prikažemo scrollbare yes/no/auto; default = no)    
    //  -callBackFunc           (pointer na funkcijo, ki prejme 1. argument objekt kontrole, 2. argument parametre callback-a)
    //  -getURLParamStringFunc  (pointer na funkcijo, ki prejme 1. argument objekt kontrole in vrne parametre za nadokno, ki se jih doda URL-ju)    
    //  -targetControl          (objekt kontrole, ki se lahko uporabi za 1. argument pri klicu callBackFunc/getURLParamStringFunc)    
    function LoadModalPopUpByBID(strMPBehaviourID, strURL, showScrollBars, callBackFunc, getURLParamStringFunc, targetControl)
    {
        var mpObject = $find(strMPBehaviourID);
        if ((mpObject != null) && (mpObject.Cstm_LoadURL != null) && (mpObject.Cstm_IFrameID != null))
        {            
            try {setIframeScroll(mpObject.Cstm_IFrameID, showScrollBars);} catch (ex) {};
            mpObject.Cstm_LoadURL(strURL, callBackFunc, getURLParamStringFunc, targetControl);
            mpObject.show();
            
            if (targetControl != null)
                targetControl.MPBehaviourID = strMPBehaviourID;
        }
        false;
    }
    
    // naloadamo default popupcontrolo (BehaviourID='CustomMP', mora bit že na strani; pri nas v FramedMaster-ih) z URL-jem in ga odpremo
    // parametri:
    //  -strURL                 (URL ki se odpre v frame-u)
    //  -showScrollBars         (ali v iFrame-u prikažemo scrollbare yes/no/auto; default = no)    
    //  -callBackFunc           (pointer na funkcijo, ki prejme 1. argument objekt kontrole, 2. argument parametre callback-a)
    //  -getURLParamStringFunc  (pointer na funkcijo, ki prejme 1. argument objekt kontrole in vrne parametre za nadokno, ki se jih doda URL-ju)
    //  -targetControl          (objekt kontrole, ki se lahko uporabi za 1. argument pri klicu callBackFunc/getURLParamStringFunc)    
    function LoadModalPopUp(strURL, showScrollBars, callBackFunc, getURLParamStringFunc, targetControl)
    {
        LoadModalPopUpByBID('CustomMP', strURL, showScrollBars, callBackFunc, getURLParamStringFunc, targetControl);
    }    
    
function CheckPageValid()
{
    var isValid = true;
    if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) isValid = false;
    return isValid;
}

function ClickOnce(varName, varValue)
{
    var clickRes = CheckPageValid();
    if (clickRes)
    {
        try
        {
            clickRes = varValue == '';k
            if (clickRes)
            {
                eval(varName + ' = \'1\';');
            }
        }
        catch (e) {}
    }
    return clickRes;
}   

function pageLoad() {

    for (i = 0; i < $(".iframe-window").length; i++) {
        $(".modalPopup")[i].style.width = $(".iframe-window")[i].width;
        $(".top-window")[i].style.width = $(".iframe-window")[i].width;
        $(".bottom-window")[i].style.width = $(".iframe-window")[i].width;
    }

    /* oznacevanje vrstic pri tabeli */
    var overSwappClassesO = new Array(
		new Array('even-icon', 'selected-icon'), //zamenjaj even-icon z even-icon
		new Array('even', 'selected'), //zamenjaj even class z selected classom
		new Array('odd-icon', 'selected-icon'), //zamenjaj odd-icon z selected-icon
		new Array('odd', 'selected') //zamenjaj odd class z selected classom
	);

    var outSwappClassesO = new Array(
		new Array('selected-icon', 'even-icon'),
		new Array('selected', 'even'),
		new Array('selected-icon', 'odd-icon'),
		new Array('selected', 'odd')
	);

    var overSwappClassesE = new Array(
		new Array('odd-icon', 'selected-icon'), //zamenjaj odd-icon z selected-icon
		new Array('odd', 'selected'), //zamenjaj odd class z selected classom
		new Array('even-icon', 'selected-icon'), //zamenjaj even-icon z even-icon
		new Array('even', 'selected') //zamenjaj even class z selected classom
	);

    var outSwappClassesE = new Array(
		new Array('selected-icon', 'odd-icon'),
		new Array('selected', 'odd'),
		new Array('selected-icon', 'even-icon'),
		new Array('selected', 'even')
	);

    //jQuery onload funkcija
    $(function() {
        // "listener" za tabelo
        $(".selectable tr:not(.not-selectable):even").hover(
			function() {
			    toggleRow($(this), overSwappClassesE, true);
			},
			function() {
			    toggleRow($(this), outSwappClassesE, false);
			}
		);
        $(".selectable tr:not(.not-selectable):odd").hover(
			function() {
			    toggleRow($(this), overSwappClassesO, true);
			},
			function() {
			    toggleRow($(this), outSwappClassesO, false);
			}
		);

        // "listener" za tabelo za clickable
        $(".clickable tr:not(.not-clickable)").click(
			function() {
			    toggleRowClick($(this));
			}
		);

        //listener za openlink pri kliku na vrstico
        $(".openlink tr:not(.not-openlink)").click(
			function() {
			    document.location = OPEN_LINK;
			}
		);
    });
}

/* oznacevanje vrstic pri tabeli */
var overSwappClassesO = new Array(
	new Array('even-icon', 'selected-icon'), //zamenjaj even-icon z even-icon
	new Array('even', 'selected'), //zamenjaj even class z selected classom
	new Array('odd-icon', 'selected-icon'), //zamenjaj odd-icon z selected-icon
	new Array('odd', 'selected') //zamenjaj odd class z selected classom
);

var outSwappClassesO = new Array(
	new Array('selected-icon', 'even-icon'),
	new Array('selected', 'even'),
	new Array('selected-icon', 'odd-icon'),
	new Array('selected', 'odd')
);

var overSwappClassesE = new Array(
	new Array('odd-icon', 'selected-icon'), //zamenjaj odd-icon z selected-icon
	new Array('odd', 'selected'), //zamenjaj odd class z selected classom
	new Array('even-icon', 'selected-icon'), //zamenjaj even-icon z even-icon
	new Array('even', 'selected') //zamenjaj even class z selected classom
);

var outSwappClassesE = new Array(
	new Array('selected-icon', 'odd-icon'),
	new Array('selected', 'odd'),
	new Array('selected-icon', 'even-icon'),
	new Array('selected', 'even')
);

//jQuery onload funkcija
$(function() {
    // "listener" za tabelo
    $(".selectable tr:not(.not-selectable):even").hover(
		function() {
		    toggleRow($(this), overSwappClassesE, true);
		},
		function() {
		    toggleRow($(this), outSwappClassesE, false);
		}
	);
    $(".selectable tr:not(.not-selectable):odd").hover(
		function() {
		    toggleRow($(this), overSwappClassesO, true);
		},
		function() {
		    toggleRow($(this), outSwappClassesO, false);
		}
	);

    // "listener" za tabelo za clickable
    $(".clickable tr:not(.not-clickable)").click(
		function() {
		    toggleRowClick($(this));
		}
	);

    //listener za openlink pri kliku na vrstico
    $(".openlink tr:not(.not-openlink)").click(
		function() {
		    document.location = OPEN_LINK;
		}
	);
});

function toggleRowClick(row) {
    //najdi parent tabelo od te vrstice
    parentTable = row.parent();
    while (parentTable.attr('nodeName').toLowerCase() != 'table')
        parentTable = parentTable.parent();

    //oznaci kliknjeno vrstico, ostale 'odoznaci'
    $.each(parentTable.find('tr:not(.not-clickable)'), function() {

        if ($(this)[0] == row[0]) {//oznaci kliknjeno vrstico
            //izkoristi prejsno funkcijo, ki bo kle samo slike zamenjala
            toggleRow($(this), overSwappClassesE, true);
            //se classe zamenjej
            $(this).find('td.data').removeClass('data').addClass('data-selected white');
        }
        else {//odoznaci ostale vrstice
            //izkoristi prejsno funkcijo, ki bo kle samo slike zamenjala
            toggleRow($(this), overSwappClassesE, false);
            //se classe zamenjej
            $(this).find('td.data-selected').removeClass('data-selected').removeClass('white').addClass('data');
        }
        //console.log(parentTable.attr('nodeName'));
    });
}

function toggleRow(row, csstogglers, selected) {
    //ce ima prvi td v tej vrstici sliko, jo zamenjaj
    if ((imgTD = row.children(":first").children(":first")).attr('nodeName') == 'IMG')
        if (imgTD.attr('src').indexOf("alert") != -1) //samo ce je to una slika s puscico
        imgTD.attr('src', selected ? '../img/table-icon-alert.png' : '../img/table-icon-alert.png');
    //posisci vse vrstice s classom na 1. mestu vsakega csstoglerja v csstoglerjih in jim zamenjej class z classom na 2. mestu vsakega csstoglerja v csstogglerjih
    jQuery.each(csstogglers, function() {
        row.find('td.' + this[0]).attr('class', '').addClass(this[1]);
    }
	);
    if (selected) {
        row.find('.data').addClass('white').addClass('data-selected').removeClass('data');
        row.find('.red').addClass('white');
        row.find('.green').addClass('white');
        row.find('.help').addClass('black');
        jQuery.each(row.find('img'), function() {
            if ($(this).attr('src') == '../img/icon-exchange-down.gif')
                $(this).attr('src', '../img/table-sort-down.gif');
            else if ($(this).attr('src') == '../img/icon-exchange-up.gif')
                $(this).attr('src', '../img/table-sort-up.gif');
            else if ($(this).attr('src') == '../img/icon-exchange.gif')
                $(this).attr('src', '../img/table-sort.gif');
        }
		);

    }
    else {
        row.find('.data-selected').removeClass('white').removeClass('data-selected').addClass('data');
        row.find('.red').removeClass('white');
        row.find('.green').removeClass('white');
        row.find('.help').removeClass('black');
        jQuery.each(row.find('img'), function() {
            if ($(this).attr('src') == '../img/table-sort-down.gif')
                $(this).attr('src', '../img/icon-exchange-down.gif');
            else if ($(this).attr('src') == '../img/table-sort-up.gif')
                $(this).attr('src', '../img/icon-exchange-up.gif');
            else if ($(this).attr('src') == '../img/table-sort.gif')
                $(this).attr('src', '../img/icon-exchange.gif');
        }
		);
    }
}
    
    /* oznacevanje vrstic pri tabeli */
function selectRow(id, selection, css) {
	if (selection == true) {
		if( (imgel = $(id).childElements()[0].childElements()[0]).nodeName=="IMG" ){
			if (imgel.src.match('table-arrow') != null) {
				imgel.src = '../img/table-arrow-selected.gif';
			}
		}
	}
	var childs = $(id).childElements();
	j = 0;
	
	for (i = 0; i < childs.length; i++) {
		j++;
		if (childs[i].className.match('odd-icon') != null || childs[i].className.match('even-icon') != null) {
			childs[i].className = 'selected-icon';
		}
		else {
			childs[i].className = 'selected' ;
		}
		var childs2 = childs[i].childElements();
		for (k = 0; k < childs2.length; k++) {
			if(childs2[k].nodeName=="SPAN")
				childs2[k].setStyle({color:'#FFFFFF'});
		}
	}
}

function deselectRowOdd(id, selection, css) {
	if (selection == true) {
		if( (imgel = $(id).childElements()[0].childElements()[0]).nodeName=="IMG" ){
			if (imgel.src.match('table-arrow') != null) {
				imgel.src = '../img/table-arrow.gif';
			}
		}
	}
	var childs = $(id).childElements();
	j = 0;
	for (i = 0; i < childs.length; i++) {
		if (childs[i].nodeType == 1) {
			j++;
			if (childs[i].className.match('selected-icon') != null) {
				childs[i].className = 'odd-icon';
			}
			else {
				childs[i].className = 'odd';
			}
			var childs2 = childs[i].childElements();
			barva = 0
			for (k = 0; k < childs2.length; k++) {
				if(childs2[k].nodeName=="IMG" ){
						if (childs2[k].src.match('icon-exchange-up') != null) {
							barva = 1;
						}
						if (childs2[k].src.match('icon-exchange-down') != null) {
							barva = 2;
						}
					}
					
					else if(childs2[k].nodeName=="SPAN" ){
						
						if (barva != 0 )
						{
							if (barva == 1){
								childs2[k].setStyle({color:'#009966'});
							}
								
							else {
								childs2[k].setStyle({color:'#ff0000'});
							}
							barva = 0
						}
						else 
						{
							childs2[k].setStyle({color:'#000000'});
						}
					}	
			}
		}
	}
}

function deselectRowEven(id, selection, css) {
	if (selection == true) {
		if( (imgel = $(id).childElements()[0].childElements()[0]).nodeName=="IMG" ){
			if (imgel.src.match('table-arrow') != null) {
				imgel.src = '../img/table-arrow.gif';
			}
		}
	}
	var childs = $(id).childElements();
	j = 0;
	for (i = 0; i < childs.length; i++) {
		if (childs[i].nodeType == 1) {
			j++;
			if (childs[i].className.match('selected-icon') != null) {
				childs[i].className = 'even-icon';
			}
			else {
				childs[i].className = 'even';
			}
			var childs2 = childs[i].childElements();
			barva = 0
			for (k = 0; k < childs2.length; k++) {
				
					if(childs2[k].nodeName=="IMG" ){
						if (childs2[k].src.match('icon-exchange-up') != null) {
							barva = 1;
						}
						if (childs2[k].src.match('icon-exchange-down') != null) {
							barva = 2;
						}
					}
					
					else if(childs2[k].nodeName=="SPAN" ){
						
						if (barva != 0 )
						{
							if (barva == 1){
								childs2[k].setStyle({color:'#009966'});
							}
								
							else {
								childs2[k].setStyle({color:'#ff0000'});
							}
							barva = 0
						}
						else 
						{
							childs2[k].setStyle({color:'#000000'});
						}
					}
			}
		}
	}
 }
 
  function makeRowSelect(tablename, tableid, rowid, value) {
    var rows = $(tableid).rows;
	for (i = 0; i < rows.length; i++) { 
	
	   var imgel =rows[i].cells[0].childNodes[0];
	   if (imgel != null)	
	   {
		   if(imgel.nodeName == "IMG" ){
		     	if (imgel.src.match('table-arrow') != null) {
			    	imgel.src = '../img/table-spacer.gif';
			    }
			    if (rows[i].id == rowid){
		          	imgel.src = '../img/table-arrow.gif';
                   	eval ("document.forms[0]." + tablename + "_value.value = '" + value + "'");
		        	}
			   
		   }
	   }
	}
}

/* prikazovanje in skrivanje akcijske pasice */
function showAction(table, id, total) {
	for (i=total;i>0;i--)
	{
		if (i!=id) {hideMenu(table + '-' + i);};
	};
	showMenu(table + '-' + id);
}

function hideTimerAction(table, total) {
	setTimeout("hideAction('" + table + "'," + total+ ")", 500);
}

function hideAction(table, total) {
	for (i=total;i>0;i--)
	{
		hideMenu(table + '-' + i);
	};
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

