function switchOffFlash(off) {
	var objectarray = document.getElementsByTagName("object");
	if(objectarray) {
		for(var i in objectarray) {
			//alert(objectarray[i].style);
			if(objectarray[i].style) {
				if(objectarray[i].style.visibility) {
					if(objectarray[i].style.visibility != null) {
						objectarray[i].style.visibility = (off) ? "hidden" : "";
					}
				}
			}
		}
	}
}
/**
 * MainMenu
 */
var tm1=0

function hideShow(id,key)
{
    var element = document.getElementById(id);
if(element != null)
    if(element.className=="makeMenu")
    {
      element.style.display=key;
    }

}

function doMenu(id)
{
    for(var i=1;i != menu_count+1;i++)
    {
        var nameid = "m"+i;
        var key = 'none';
        
        if(nameid==id){
		key='block';        
        hideShow(nameid,key);
        document.getElementById("acko"+i).style.textDecoration='none'; 		// styl pri otevrenem menu
        }
        else {
		document.getElementById("acko"+i).style.textDecoration='none';		// styl pri zavrenem menu
		key='none';
		hideShow(nameid,key);
		}
    }
    if (id != '') cancelOut()    	
}

function cancelOut()
{
	if (tm1 != 0)
	{
		clearTimeout(tm1)
		tm1 = 0
	}
}

function hidemenu()
{
	doMenu('')
} 

function mhide()
{
	cancelOut()
	tm1 =setTimeout("hidemenu()",334);
}

/**
 * Search
 */
function searchKeyEnter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
   		sendCommand("CmdSearch");
   		return false;
    }
	else
   		return true;
}
/**
 * SearchResult
 */
function searchKeyEnterFromResult(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
   		sendCommand("CmdSearchAgain");
   		return false;
    }
	else
   		return true;
}

/**
 * Login
 */
// odchytavani klavesy ENTER (13) v polích login a password
function loginKeyEnter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13 )
    {
   
   		sendCommand('CmdLogin',null);
   		return false;
    }
	else
   		return true;
}


/**
 * Dialogové okno pro frontend.
 * Statická třída.
 * 
 * @example
 *   Dialog.open('obsah dialog','Nadpis dialogu',objekt, callback);
 */
var Dialog = {
	speed_open_bg : 0,
	speed_open_win : 0,
	speed_close_bg : 200,
	speed_close_win : 200,
	/**
	 * Otevření dialogu
	 * @param  string Obsah
	 * @param  string Nadpis
	 * @param  objekt Objekt, kde se kliklo
	 * @param  objekt Callback
	 * @return objekt this
	 */
	open : function(content, header, e, callback) {
		if(typeof header == 'undefined') var header = 'Dialog'; 
		var id = Math.ceil(Math.random()*100000);
		var html = '';
		html += '<div class="dialog_bg" style="height: '+$("body").outerHeight()+'px; width: '+$("body").outerWidth()+'px" id="dialog_bg_'+id+'"></div>';
		html += '<div class="dialog_window" style="display: none" id="dialog_window_'+id+'">';
		html += ' <div class="close" onclick="Dialog.close('+id+');"></div>';
		html += ' <div class="container">';
		html += '  <div class="header">';
		html += '  '+header;
		html += '  </div>';
		html += '  <div class="content">';
		html += '  '+content;
		html += '  </div>';
		html += ' </div>';
		html += '</div>';
		/* vložíme pozadí, ale okno zůstane zatím skryté */
		$("#dialogs").html( html );
		/*
		var window_width = $("#dialogs div.dialog_window").outerWidth();
		var body_width = $("body").outerWidth();
		var percent_body_width = parseInt($("body").outerWidth() / 100);
		var left = (50 * percent_body_width) - parseInt(window_width / 2);
		/* position absolute pouze pro IE6 a starší */
		var position = ($.browser.msie) ? ((parseFloat($.browser.version) > 7) ? "absolute" : "fixed") : "fixed";
		/*
		var top = (position == "fixed") ? "20%" : "40%";
		$("#dialogs div.dialog_window").css( { 'left' : (left / percent_body_width)+'%', 'position' : position, 'top' : top } ).show();
		*/
		$("#dialogs div.dialog_window").css( {'position' : position} ).show();
		return this;
	},
	/**
	 * Zavření dialogu
	 * @param  mixed Objekt nebo ID
	 * @param  objekt Callback
	 * @return boolean
	 */
	close : function(param,callback) {
		if(typeof callback == 'undefined') {
			var callback = null;
		}
		if(typeof param == 'undefined') { 
			this._close(null,callback);
		}
		else if(typeof param == 'object') {
			var w = $(param).parents("div[id^='dialog_window_']");
			//var w = $(param).parent();
			if(w.length == 1) {
				this._close($(w).attr("id"),callback);
			}
			else {
				this._close(null,callback);
			}
		}
		else {
			this._close(param,callback);
		}
	},
	_close : function(id,callback) {
		// pokud není předán parametr, zavřeme vše
		if(typeof id == 'undefined' || id == null) {
			$("#dialogs").html('');
			CallBack.call( callback );
			return true;
		}
		else {
			// zkusíme získat ID dialogu
			try {
				id = parseInt(id);
			}
			// pokud selže, zavřeme vše
			catch(e) {
				return this._close(null,callback);
			}
			// výsledek není platné číslo, zavřeme vše
			if(isNaN(id)) {
				return this._close(null,callback);
			}
			// zavřeme dialog s pozadím (předpokládáme, že jsou obě ID shodná....proč by nebyla?)
			try {
				$("#dialog_window_"+id).fadeOut(200,function(){
					$("#dialog_bg_"+id).fadeOut(200,function(){
						CallBack.call( callback );
					});
				});
			}
			catch(e) {
				return this._close(null,callback);
			}
			return true;
		}
	}
}
/**
 * Volání callbacku.
 * Statická třída.
 * 
 * @example
 *   var source = { callback : 'MojeFunkce', params : [1,true,'hodnotaX','hodnotaY'] }
 *   Callback.call( source );
 */
var CallBack = {
	/**
	 * Volání samotného callbacku s parametry
	 * @param  mixed
	 * @return boolean
	 */
	call : function( source ) {
		if(typeof source == "object") {
			try {
				/* Vytvoříme objekt pro volání */
				var cb = CallBack._callback;
				/* Nastavíme funkci */
				cb._setFunction( source.callback );
				/* Připravíme parametry */
				var params = [];
				try {
					for(var i = 0; i < source.params.length; i++) {
						var p = source.params[i];
						if(typeof p == "string") {
							params.push("'"+p+"'");
						}
						if(typeof p == "boolean" || typeof p == "number" || typeof p == "boolean") {
							params.push(p.toString());
						}
					}
					/* Nastavíme parametry */
					cb._setParams( params.join(",") );
				}
				catch(e) { }
				/* Zavoláme výsledek */
				cb._call();
			}
			catch(e) {
				return false;
			}
			return true;
		}
	},
	/**
	 * Privátní objekt volaná uvnitř objektu Callback.
	 */
	_callback : {
		/**
		 * Název funkce
		 * @var function
		 */
		_fnc : null,
		/**
		 * Parametry funkce
		 * @var array
		 */
		_params : new Array(),
		/**
		 * Volání objektu.
		 */
		_call : function() {
			try {
				eval(this._fnc+"("+this._params+");");
			}
			catch(e) { }
		},
		/**
		 * Nastavení funkcí
		 * @param string Funkce
		 */ 
		_setFunction : function( fnc ) {
			try {
				this._fnc = fnc.toString();
			}
			catch(e) { }
		},
		/**
		 * Nastvení parametrů funkce
		 * @param string Parametry v jednom řetězci
		 */
		_setParams : function( params ) {
			try {
				this._params = params.toString();
			}
			catch(e) { }
		}
	}
}


