/**
 * Kniznica RainJS
 *
 * Obsah:
 *   trieda   RCapsLock         testovanie ci je zapnuty caps lock
 *   trieda   RForm             validacia formularov
 *   trieda   RCookies          praca s cookies
 *   trieda   RAdminMenu        vysuvacie administratorske menu
 *   trieda   RCalendar         vyskakovaci kalendar
 *
 *   funkcia  rLoadScript       nacita externy skript
 *   funkcia  rDump             vrati dump objektu
 *   funkcia  rPrint            vypise dump objektu do dokumentu
 *   funkcia  rAlert            zobrazi dump objektu v alert okne
 *   funkcia  rOpenImage        otvori obrazok v novom pop-up okne
 *   funkcia  rAjaxStatus       zobrazi status prebiehajucej AJAX operacie
 *   funkcia  rTableMouseOver   nastavi mouseover efekt pre tabulky table.cms-listing
 *   funkcia  rFixFlash         osetri zvlastne zobrazovanie flashu v MSIE 6
 *   funkcia  rFixFormAction    kazdemu formularu, ktory nema atribut action, nastavi URL aktualnej stranky
 *
 *
 * Kniznica RainJS je zavisla na kniznici Prototype (otestovane s verziou 1.5.0),
 * ktora je takisto OpenSource, volne k dispozicii na http://www.prototypejs.org.
 *
 *
 * RainJS - JavaScript Utility Library
 *
 * Copyright (C) 2005 - 2009  Oto Komiňák (www.oto.kominak.sk)
 *
 *
 * LICENSE:
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA
 *
 * @package     RainJS
 * @author      Oto Komiňák
 * @copyright   2005-2008 Oto Komiňák
 * @link        http://www.oto.kominak.sk
 * @license     http://www.opensource.org/licenses/lgpl-license.php GNU LGPL
 * @filesource
 */



/**
 * Trieda na validaciu formularov
 */
function RForm(objName, formName) {

    this.objName  = objName;
    this.formName = formName;

    this.fields         = { };
    this.errors         = 0;
    this.modified       = false;
    this.watchingUnload = false;

    /**
     *  Pole jednoduchych datovych typov
     *
     * Pole obsahuje regularne vyrazy pre validaciu emailov, telefonnych cisel, ...
     * Ostatne zlozitejsie datove typy su kontrolovane samostatne: integer, text, regex.
     * Pre podrobnosti vid funkciu validate().
     */
    this.regex = {
        "empty":        /^\s*$/,
        "email":        /^[^@]+@[^@.]+\.[^@]*\w\w$/,
        "mobile":       /^0[0-9]{2,3} [0-9]{3} [0-9]{3}$/,
        //"mobileIntl":   /^\+[0-9]{2,3} [0-9]{3} [0-9]{3}$/,
        "phone":        /^\+?[0-9\ ]+$/
    };


    /**
     * Nastavi obsluzne funkcie vsetkym vsetupnym poliam spomenutym v this.fields.
     */
    this.setHandlers = function() {
        var name;
        for (name in this.fields) {
            if (!name) continue;
            var input = $(name);
            var div   = input.parentNode;

            eval("input.onchange = function() { " + this.objName + ".validate(this); };");

            var children = div.getElementsByTagName("span");
            if (children.length >= 1) {
                this.fields[name].spanText = children[0].innerHTML;
            }
        }
    };


    /**
     * Funkcia zapne kontrolu nechceneho opustenia formulara
     *
     * Nechcene opustenie formualra nastane, ak uzivatel zmenil niektore zo
     * sledovanych vstupnych poli, a bez ulozenia zmien opusta stranku.
     */
    this.watchUnload = function () {
        if (watchUnload) {
            this.watchingUnload = true;
            eval(
                "window.onunload = function() { " +
                "   if ((" + this.objName + ".modified) && (confirm(I18N.RainJS.leaveUnsaved))) { " +
                "       $(\"" + this.formName + "\").submit(); " +
                "   } " +
                "}"
            );
        }
    };


    /**
     * Nastavi status vstupnemu polu: ok / error
     */
    this.setStatus = function(div, ok, message) {
        div = $(div);
        div.removeClassName("input-ok");
        div.removeClassName("input-error");
        if (ok) {
            div.addClassName("input-ok");
        } else {
            div.addClassName("input-error");
            this.errors += 1;
        }

        // Span element, ktory obsahuje informacie o validite input boxu
        var children = div.getElementsByTagName("span");
        if (children.length >= 1) {
            $(children[0]).update(message);
        }

        return ok;
    };


    /**
     * Skontroluje validitu vstupneho pola
     */
    this.validate = function(input) {
        // Nastavenia z pola this.fields relevantne pre tento div
        var field = this.fields[input.id];

        // Volanie uzivatelskeho handleru
        if (field.onchange) {
            field.onchange();
            field = this.fields[input.id];
        }

        // Div element, ktory obsahuje label, input a span
        var div = input.parentNode;

        // Hodnota pola bez medzier na zaciatku a na konci
        var value = input.value.replace(/^\s+|\s+$/g, '');
        //value = trim(input.value);

        this.modified = true;

        //if (this.regex.empty.test(input.value)) {
        if (value == "") {
            return this.setStatus(div, !field.required, field.spanText);
            if (field.required) {
                return this.setStatus(div, false, I18N.RainJS.error);
            } else {
                return this.setStatus(div, true, I18N.RainJS.optional);
            }
        }

        // Najprv skusime, ci nejde o jednoduchy typ z this.regex.
        if (this.regex[field.type]) {
            if (this.regex[field.type].test(value)) {
                return this.setStatus(div, true, I18N.RainJS.ok);
            } else {
                var messageId = "error";
                switch (field.type) {
                    case "email": messageId = "wrongEmail";     break;
                    case "phone": messageId = "error";          break;
                }
                return this.setStatus(div, false, I18N.RainJS[messageId]);
            }
        }

        // Dalej skusime, ci nejde o specialny typ "regex", kde je nutne
        // uviest specificky regularny vyraz.
        if (field.type == "regex") {
            if (field.regex.test(value)) {
                return this.setStatus(div, true, I18N.RainJS.ok);
            } else {
                return this.setStatus(div, false, I18N.RainJS.error);
            }
        }

        // Typ "text"
        if (field.type == "text") {
            if ((field.min != null) && (value.length < field.min)) {
                return this.setStatus(div, false, I18N.RainJS.minLength + " " + field.min);
            }
            if ((field.max != null) && (value.length > field.max)) {
                return this.setStatus(div, false, I18N.RainJS.maxLength + " " + field.max);
            }
            return this.setStatus(div, true, I18N.RainJS.ok);
        }

        // Typ "integer" (cele cislo)
        if (field.type == "integer") {
            var regex = /^-?[0-9]+$/;
            if (!regex.test(value)) {
                return this.setStatus(div, false, I18N.RainJS.wrongInteger);
            }
            var n = parseInt(value);
            if ((field.min != null) && (n < field.min)) {
                return this.setStatus(div, false, I18N.RainJS.min + " " + field.min);
            }
            if ((field.max != null) && (n > field.max)) {
                return this.setStatus(div, false, I18N.RainJS.max + " " + field.max);
            }
            return this.setStatus(div, true, I18N.RainJS.ok);
        }

        // Typ "float" (desatinne cislo s bodkou alebo ciarkou)
        if (field.type == "float") {
            var regex = /^-?[0-9]*[,.]?[0-9]+$/;
            if (!regex.test(value)) {
                return this.setStatus(div, false, I18N.RainJS.wrongInteger);
            }
            var n = parseFloat(value.replace(/,/, '.'));
            if ((field.min != null) && (n < field.min)) {
                return this.setStatus(div, false, I18N.RainJS.min + " " + field.min);
            }
            if ((field.max != null) && (n > field.max)) {
                return this.setStatus(div, false, I18N.RainJS.max + " " + field.max);
            }
            return this.setStatus(div, true, I18N.RainJS.ok);
        }

        return true;
    };


    /**
     * Spusti validaciu vsetkych poli formulara
     *
     * Ak je showAlert true, zobrazi sa vystrazne okno s oznamenim o chybne vyplnenom formulari
     */
    this.validateAllFields = function (showAlert) {
        this.errors = 0;

        if (this.watchingUnload) {
            window.onunload = function() { };
        }

        if (!this.beforeValidate()) {
            this.errors += 1;
            return false;
        }

        var name, input;
        for (name in this.fields) {
            if (!name) continue;
            input = $(name);
            input.onchange(input);
        }

        if (!this.afterValidate()) {
            this.errors += 1;
        }

        if (this.errors > 0) {
            if (showAlert) {
                alert(I18N.RainJS.checkForm);
            }
            return false;
        } else {
            return true;
        }
    };


    this.beforeValidate = function () { return true; };

    this.afterValidate = function () { return true; };
}


/**
 * Trieda na pracu s cookies
 */
function RCookies() {

    this.getCookie = function (name)  {
        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
            return null;
        }
        if ( start == -1 ) return null;
        var end = document.cookie.indexOf( ';', len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
    };


    this.setCookie = function (name, value, expires, path, domain, secure) {
        var today = new Date();
        today.setTime( today.getTime() );
        if ( expires ) {
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );
        document.cookie = name+'='+escape( value ) +
            ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
            ( ( path ) ? ';path=' + path : '' ) +
            ( ( domain ) ? ';domain=' + domain : '' ) +
            ( ( secure ) ? ';secure' : '' );
    };

    this.deleteCookie = function (name, path, domain) {
        if ( getCookie( name ) ) document.cookie = name + '=' +
                ( ( path ) ? ';path=' + path : '') +
                ( ( domain ) ? ';domain=' + domain : '' ) +
                ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    };
};



/**
 * Skryvacie administracne menu
 */
function RAdminMenu(obj, div, leftPadding, checkbox) {

    eval("$('" + div + "').onmouseover = function() { " + obj + ".menuOut(); };");
    eval("$('" + div + "').onmouseout  = function() { " + obj + ".menuIn();  };");

    this.obj        = obj;
    this.div        = $(div);

    this.timerOut   = null;
    this.timerIn    = null;

    this.interval   = 10;
    this.dx         = 10;

    this.leftPos        = -this.div.getWidth() + leftPadding;
    this.div.style.left = this.leftPos + "px";

    this.hiding = $(checkbox);

    var hide = (new RCookies()).getCookie("RAdminMenuHiding");
    this.hiding.checked = (hide == 0 ? true : false);

    // Odkrytie menu
    this.menuOut = function () {
        if (this.timerIn) clearInterval(this.timerIn);

        this.timerOut = setInterval(this.obj + ".menuOutMotion()", this.interval);
    };


    // Elementarny posun pre menuOut()
    this.menuOutMotion = function () {
        if (parseInt(this.div.style.left) < 0) {
            this.div.style.left = parseInt(this.div.style.left) + this.dx + "px";

        } else if (this.timerOut) {
            this.div.style.left = "0px";
            clearInterval(this.timerOut);
        }
    };


    // Skrytie menu
    this.menuIn = function () {
        clearInterval(this.timerOut);
        if (this.hiding.checked == false)
            this.timerIn = setInterval(this.obj + ".menuInMotion()", this.interval);
    };


    // Elementarny posun pre menuIn()
    this.menuInMotion = function () {
        if (parseInt(this.div.style.left) > this.leftPos) {
            this.div.style.left = parseInt(this.div.style.left) - this.dx + "px";

        } else if (this.timerIn) {
            this.div.style.left = this.leftPos + "px";
            clearInterval(this.timerIn);
        }
    };


    // Po nacitani stranky sa menu hned zjavi, nevyrolluje sa
    if (this.hiding.checked == true) {
        this.div.style.left = "0px";
        this.menuOut();
    }
}



/**
 * Vyskakovaci kalendar
 */
function RCalendar(objName, field, div) {

    this.objName = objName;   // nazov instancie tejto triedy
    this.field   = $(field);  // vstupne pole
    this.div     = $(div);    // div s kalendarom

    this.day   = 0;
    this.month = 0;
    this.year  = 0;


    // Zobrazi/skryje kalendar
    this.show = function() {
        if (this.div.style.display == "none") {
            for (i = 0; i < document.getElementsByClassName("calendar").length; i++) {
                document.getElementsByClassName("calendar")[i].style.display = "none";
            }
            //document.getElementsByClassName("calendar").each(function(e) { e.style.display = "none"; });
            this.div.style.display = "block";
            this.year = this.month = this.day = 0;
            this.initCalendar();
        } else {
            this.div.style.display = "none";
        }
    };


    // Naformatuje 2-ciferne cislo
    this.formatNum2 = function(i) {
        return (i < 10 ? "0" : "") + i;
    };


    // Naformatuje 4-ciferne cislo
    this.formatNum4 = function(i) {
        return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
    };


    // Inicializuje a vygeneruje kalendar
    this.initCalendar = function() {

        // volame prvykrat
        if (!this.year && !this.month && !this.day) {

            if (this.field.value) {
//                value      = this.field.value;
                var date   = this.field.value.split(".");
                this.day   = parseInt(date[0],10);
                this.month = parseInt(date[1],10) - 1;
                this.year  = parseInt(date[2],10);
            }
            if (isNaN(this.year) || isNaN(this.month) || isNaN(this.day) || this.day == 0) {
                var dt     = new Date();
                this.year  = dt.getFullYear();
                this.month = dt.getMonth();
                this.day   = dt.getDate();
            }

        // posuvame sa v kalendari
        } else {

            if (this.month > 11) {
                this.month = 0;
                this.year++;
            }
            if (this.month < 0) {
                this.month = 11;
                this.year--;
            }
        }

        this.div.innerHTML = "";

        var str = "";
        var selected;
        var i;
        
        // zatvaraci button
        str += '<div class="calendar-close">';
        str += '<a href="#" onclick="' + this.objName + ".div.style.display='none'; return false;" + '">[X]</a>';
        str += '</div>';
        
        // rok
        str += '<div class="calendar-year">';
        //str += '<form method="post" onsubmit="return false">';
        str += '<a href="#" onclick="' + this.objName + '.year--; ' + this.objName + '.initCalendar(); return false;">&laquo;</a> ';

        str += '<select id="select_year" name="yearsel" onchange="' + this.objName + ".year = parseInt($('select_year').value); " + this.objName + '.initCalendar();">';
        for (i = this.year - 25; i < this.year + 25; i++) {
            if (i == this.year) selected = ' selected="selected"';
            else selected = '';
            str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
        }
        str += '</select>';

        str += ' <a href="#" onclick="' + this.objName + '.year++; ' + this.objName + '.initCalendar(); return false;">&raquo;</a>';
        //str += '</form>';
        str += '</div>';

        // mesiac
        str += '<div class="calendar-month">';
        //str += '<form method="post" onsubmit="return false">';
        str += '<a href="#" onclick="' + this.objName + '.month--; ' + this.objName + '.initCalendar(); return false;">&laquo;</a> ';

        str += '<select id="select_month" name="monthsel" onchange="' + this.objName + ".month = parseInt($('select_month').value); " + this.objName + '.initCalendar();">';
        for (i = 0; i < 12; i++) {
            if (i == this.month) selected = ' selected="selected"';
            else selected = '';
            str += '<option value="' + i + '" ' + selected + '>' + I18N.RainJS.months[i] + '</option>';
        }
        str += '</select>';

        str += ' <a href="#" onclick="' + this.objName + '.month++; ' + this.objName + '.initCalendar(); return false;">&raquo;</a>';
        //str += '</form>';
        str += '</div>';

        str += '<div class="clear"></div>';
        

        // tabulka

        // header
        str += '<table class="calendar" align="center"><tr>';
        for (i = 0; i < 7; i++) {
            str += "<th>" + I18N.RainJS.days[i] + "</th>";
        }
        str += "</tr>";

        var firstDay = new Date(this.year, this.month,     0).getDay();
        var lastDay  = new Date(this.year, this.month + 1, 0).getDate();

        str += "<tr>";

        // zaciatocne prazdne policka
        var dayInWeek = 0;
        var style;

        for (i = 0; i < firstDay; i++) {
            if (i == 5) {
                style = ' class="sat"';
            } else if (i == 6) {
                style = ' class="sun"';
            } else {
                style = '';
            }
            str += "<td" + style + ">&nbsp;</td>";
            dayInWeek++;
        }

        for (i = 1; i <= lastDay; i++) {
            if (dayInWeek == 7) {
                str += "</tr><tr>";
                dayInWeek = 0;
            }

            var dispmonth = 1 + this.month;

            var actVal = "";
            actVal += this.formatNum2(i) + "." + this.formatNum2(dispmonth) + "." + this.formatNum4(this.year);

            if (i == this.day) {
                style = ' class="selected"';
            } else {
                if (dayInWeek == 5) {
                    style = ' class="sat"';
                } else if (dayInWeek == 6) {
                    style = ' class="sun"';
                } else {
                    style = '';
                }
            }
            str += "<td" + style + "><a href=\"#\" onclick=\"" + this.objName + ".returnDate('" + actVal + "'); return false;\">" + i + "</a></td>";
            dayInWeek++;
        }

        // koncove prazdne policka
        for (i = dayInWeek; i < 7; i++) {
            if (i == 5) {
                style = ' class="sat"';
            } else if (i == 6) {
                style = ' class="sun"';
            } else {
                style = '';
            }
            str += "<td" + style + ">&nbsp;</td>";
        }

        str += "</tr></table>";

        this.div.innerHTML = str;
    };


    // Nastavi input polu zvoleny datum a skryje kalendar
    this.returnDate = function(d) {
        this.field.value = d;
        this.div.style.display = "none";
        this.year = this.month = this.day = 0;
    };

}


/**
 * Trieda na testovanie zapnuteho capslocku
 */
function RCapsLock(obj,capsOnFnc,capsOffFnc) {
	
	if(RCapsLock.instances==undefined) {
		RCapsLock.instances = {};
	}
	this.id = RCapsLock.instances.length;
	RCapsLock.instances[RCapsLock.instances.length] = this;
	
	if (document.addEventListener) {
		eval('obj.addEventListener(\'keypress\',function(e) {RCapsLock.instances['+this.id+'].keypress(e,'+capsOnFnc+','+capsOffFnc+')},false)');
	} else if (document.attachEvent) {
		eval('obj.attachEvent(\'onkeypress\',function(e) {RCapsLock.instances['+this.id+'].keypress(e,'+capsOnFnc+','+capsOffFnc+')})');
	} else {
		  // no support for addEventListener *or* attachEvent, so quietly exit
	}

	this.keypress = function(e,capsOnFnc,capsOffFnc) {
		var ev = e ? e : window.event;
		if (!ev) {
			return;
		}
		var targ = ev.target ? ev.target : ev.srcElement;
		// get key pressed
		var which = -1;
		if (ev.which) {
			which = ev.which;
		} else if (ev.keyCode) {
			which = ev.keyCode;
		}

		// get shift status
		var shift_status = false;
		if (ev.shiftKey) {
			shift_status = ev.shiftKey;
		} else if (ev.modifiers) {
			shift_status = !!(ev.modifiers & 4);
		}
		if (((which >= 65 && which <=  90) && !shift_status) ||
		    ((which >= 97 && which <= 122) && shift_status)) {
		  // uppercase, no shift key
		  capsOnFnc();
		} else {
			var char = String.fromCharCode(which);
			if(char.toLowerCase() == char) var is_lower_case = true;
			if(char.toUpperCase() == char) var is_upper_case = true;
		      
			if((is_lower_case && shift_status && !is_upper_case) ||
				(is_upper_case && !shift_status && !is_lower_case)) {
				capsOnFnc();
			} else if(!(is_upper_case && is_lower_case)) {
				capsOffFnc();
			}
		}
	};
}


/**
 * Nacita externy JavaScriptovy subor
 */
function rLoadScript(url) {
    var e = document.createElement("script");
    e.src = url;
    e.type="text/javascript";
    document.getElementsByTagName("head")[0].appendChild(e);
}


/**
 * Vygeneruje dump objektu
 */
function rDump(obj, name, html, indent, depth) {
    var nl = "\n";

    if (depth > 10) {
        return indent + name + ": <Maximum Depth Reached>" + nl;
    }

    if (typeof obj == "object") {
        var child = null;
        var output = indent + name + nl;
        indent += html ? "&nbsp;&nbsp;&nbsp;&nbsp;" : "    ";

        for (var item in obj) {
            try {
                child = obj[item];
            } catch (e) {
                child = "<Unable to Evaluate>";
            }
            if (typeof child == "object") {
                output += rDump(child, item, html, indent, depth + 1);
            } else {
                output += indent + item + ": " + child + nl;
            }
        }
        return output;

    } else {
        return obj;
    }
}


/**
 * Zobrazi dump objektu v alert okne
 */
function rAlert(obj) {
    alert(rDump(obj, "", false, "", 0));
}


/**
 * Vypise dump objektu do dokumentu
 */
function rPrint(obj) {
    document.write("<div style=\"text-align: left\"><pre>" + rDump(obj, "", true, "", 0) + "</pre></div>");
}


/**
 * Otvori obrazok (resp. akukolvek url) v novom pop-up okne
 */
function rOpenImage(url) {
    window.open(url, 'w', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=660,height=660');
}


/**
 * Nastavi status AJAX poziadavky do div#ajaxStatus
 */
function rAjaxStatus(status, message) {
    clearTimeout(rAjaxStatusTimer);

    if (status) {
        $("ajaxStatus").className = "ajax-status ajax-status-" + status;
        $("ajaxStatus").innerHTML = message;
        if (status == "ok") {
            rAjaxStatusTimer = setTimeout("rAjaxStatus()", 2000);
        }
    } else {
        $("ajaxStatus").className = "ajax-status";
        $("ajaxStatus").innerHTML = "&nbsp;";
    }
}
var rAjaxStatusTimer = null;


/**
 * Prida riadkom v table.cms-listing efekt pre mouse over
 */
function rTableMouseOver() {
    var tables = document.getElementsByClassName("cms-listing");

    for (var i = 0; i < tables.length; i++) {
        var rows = tables[i].getElementsByTagName("tr");
        var j = 0;

        var firstRowParent = rows[0].parentNode.tagName;
        if ((firstRowParent == "THEAD") || (firstRowParent == "thead")) j++;

        for (; j < rows.length; j++) {
            rows[j].onmouseover = function () {
                if (!rTableMouseOverDisabled) $(this).addClassName("mouseover");
            };
            rows[j].onmouseout = function () {
                $(this).removeClassName("mouseover");
            };
        }
    }
}
var rTableMouseOverDisabled = false;


/**
 * Osetri MSIE Flash bug/feature.
 */
function rFixFlash() {
    var n = navigator.userAgent;
    var w = n.indexOf("MSIE");

    if ((w > 0) && (parseInt(n.charAt(w + 5)) > 5)) {
        var T = ["object", "embed", "applet"];
        for (var j = 0; j < 2; j++) {
            var E = document.getElementsByTagName(T[j]);
            for (var i = 0; i < E.length; i++) {
                var P = E[i].parentNode;
                var H = P.innerHTML;
                P.removeChild(E[i]);
                P.innerHTML = H;
            }
        }
    }
}


/**
 * Kazdemu formularu, ktory nema atribut action (alebo ho ma prazdny),
 * nastavi action na akutlanu url (window.pathname)
 */
function rFixFormAction() {
    if ((document.forms) && (document.forms.length > 0)) {
        for (var i = 0; i < document.forms.length; i++) {
            var action = document.forms[i].getAttribute("action");
            if ((action == null) || (action == "")) {
                document.forms[i].setAttribute("action", window.location.pathname + window.location.search);
            }
        }
    }
}


/**
 * Nastavi focus prvemu vstupnemu prvku (input)
 */
function rFocusOnFirstFormInput() {
    var allFormElements = $$("div.cms-form div.input");
    if (allFormElements.length > 0) {
        var firstFormElement = allFormElements[0].select("input, selectbox")[0];
        if ((firstFormElement) && (firstFormElement.type != "hidden")) {
            firstFormElement.focus();
        }
    }
}


/**
 * Ak neexistuje Firebug konzola, vytvorime aspon prazdnu nahradu.
 * Vdaka tomu nebudu na stranke zobrazovane chyby, ak v kode boli ponechane volania console.log() a stranka
 * sa zobrazuje v browseri bez Firebugu.
 */
function rFixFirebug() {
	if (typeof console == 'undefined') {
	    var console = {};
	    console.log = function(msg) {
	        return;
	    };
	}
}

