function confirmAction(msg,action,paramm,value,paramm2,value2) {
	if (confirm(msg)) {
		document.forms['form'].action = document.forms['form'].action + (document.forms['form'].action.indexOf("?") == -1? "?": "&") + "do[" + action + "]=1";		
		if (paramm) $(document.forms['form']).find('[name="'+paramm+'"]').val(value);
		if (paramm2) $(document.forms['form']).find('[name="'+paramm2+'"]').val(value2);
		document.forms['form'].submit();
		return true;
	}
	else {
		return false;
	}
}

function _performAction(form, action, paramm, value, paramm2, value2, paramm3, value3, paramm4, value4, paramm5, value5) {
	form.action = form.action + (form.action.indexOf("?") == -1? "?": "&") + "do[" + action + "]=1";	
	if (paramm) $(form).find('[name="'+paramm+'"]').val(value);
	if (paramm2) $(form).find('[name="'+paramm2+'"]').val(value2);
	if (paramm3) $(form).find('[name="'+paramm3+'"]').val(value3);
	if (paramm4) $(form).find('[name="'+paramm4+'"]').val(value4);
	if (paramm5) $(form).find('[name="'+paramm5+'"]').val(value5);	
	form.submit();
	return true;
}
function performAction(action, paramm, value, paramm2, value2, paramm3, value3, paramm4, value4, paramm5, value5) {
	_performAction(document.forms['form'], action, paramm, value, paramm2, value2, paramm3, value3, paramm4, value4, paramm5, value5);
}
function performFilterAction(action,paramm,value,paramm2,value2,paramm3,value3, paramm4, value4, paramm5, value5) {
	_performAction(document.forms['filterForm'], action, paramm, value, paramm2, value2, paramm3, value3, paramm4, value4, paramm5, value5);
}
function performSendEmailAction(action,paramm,value,paramm2,value2,paramm3,value3, paramm4, value4, paramm5, value5) {
	_performAction(document.forms['sendEmailForm'], action, paramm, value, paramm2, value2, paramm3, value3, paramm4, value4, paramm5, value5);
}

function undoTypeChange(obj) {
	for (var i = 0; i < obj.options.length; i++) {
		obj.options[i].selected = obj.options[i].value == originalType;
	}
}

function showEditor(name, lang) {
	lang = (lang == 'cs' || lang == 'cz' || lang == 'en' ? lang : 'en');
	if (lang == 'cz') lang = 'cs';
	
	if (typeof tableStyles=="undefined") {tableStyles = "";}

	$(document).ready(function() {
		CKEDITOR.replace(
			name,
			{
				resize_minWidth : 580,
				width: 580,
				language : lang,
				entities_latin : false,
				skin : 'kama',
				toolbar :
				[
					['Source', 'Maximize', 'ShowBlocks', 'Preview'],
					['Undo','Redo','Cut','Copy','Paste','PasteText','PasteFromWord','-','Find','Replace','-','SelectAll','RemoveFormat'],
					'/',
					['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
					['NumberedList','BulletedList','-','Outdent','Indent'],
					['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
					['Link','Unlink','Anchor'],
					'/',
					['Format','Font','FontSize'],
					['TextColor','BGColor'],
					['Image','Flash','Table','HorizontalRule','SpecialChar'],
				]
			}
		);
	});
}

// verze prohlizece
function IsNavigator () {	
	this.webkit = $.browser.webkit;
	this.safari = $.browser.webkit;
	this.chrome = $.browser.webkit;
	
	this.ie = $.browser.msie;
	
	this.opera = $.browser.opera;
	
	this.mozilla = $.browser.mozilla;
	this.firefox = $.browser.mozilla;
	this.gecko = $.browser.mozilla;
	
	this.major = parseInt($.browser.version);	
	this.version = parseFloat($.browser.version);
}

// zobrazeni obrazku ve zvlastnim okne (popup) - pokud nejsou zadany rozmery, berou se automaticky podle obrazku
function view( image, width, height, descr) {    
	var autResize = false;
	if (width == null || height == null) {
	  autResize = true;
	  width = 600;
	  height = 400;
	}
	if (autResize) {
	  isn = new IsNavigator();
	  if (isn.ie) {
		if (isn.ie && isn.major>=7) {
		  diffWidth = 30;
		  diffHeight = 75 + 12; //location + 12
		}
		else {
		  diffWidth = 30;
		  diffHeight = 50;
		}
	  }
	  else {
		diffWidth = 14;
		diffHeight = 56 + 34; //location + 34
	  }
	}
	if (descr) {
	  addW = 0;
	  addH = 40;
	  diffWidth += addW;
	  diffHeight += addH;
	  width += addW;
	  height += addH;
	}
	var imgWindow = window.open( "", "view", "menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height + ",top=150,left=150");
	var imgDoc = imgWindow.document;
	imgDoc.clear();
	imgDoc.open();
	imgDoc.writeln("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
	imgDoc.writeln("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">");
	imgDoc.writeln("<head>");
	imgDoc.writeln("<title>", document.title, "<\/title>");
	if (autResize) {
	  imgDoc.writeln("<script type=\"text/javascript\">\nfunction resize() {\n  diffWidth = ", diffWidth,"; diffHeight = ", diffHeight,";\n  window.resizeTo(window.document.images[0].width + diffWidth, window.document.images[0].height + diffHeight);\n}\n<\/script>");
	}
	imgDoc.writeln("<\/head>");
	imgDoc.writeln("<body style=\"margin: 0; padding: 0;\"" + (autResize? " onload=\"resize()\"" : "") + ">");
	imgDoc.writeln("<center><a href=\"javascript:window.close()\">");
	imgDoc.writeln("<img src=\"",image,"\" border=\"0\" alt=\"\" />");
	imgDoc.writeln("<\/a>");
	if(descr) {
		imgDoc.writeln("<br /><span style=\"font-family: Arial, Sans Serif; font-size: 12px;\">",decodeURI(descr),"</span>");
	}
	imgDoc.writeln("<\/center><\/body>");
	imgDoc.writeln("<\/html>");
	imgDoc.close();
}

// nastavi fokus na prvni prvek v danem formu
function focusFirst(form) {
	var obj = document.getElementById('initialfocus');
	if (obj) {
		obj.focus();
	}
	else {
		i=0;
		if (form) {
			while (form[i]) {
				if (form[i].type=="text" || form[i].type=="checkbox" || form[i].type=="radiobutton") {
					form[i].focus();
					break;
				}
				i++;
			}
		}
	}
}

// prida volani funkce do window.onload
function addOnLoadEvent(func) {        
	$(document).ready(function() {func();});
}

function importImages(appletId) {
	isn = new IsNavigator();
	if (!isn.ie) appletId += '_EM';
	var elm = document.getElementById(appletId);  
	if (elm) {
		var out = elm.importPhotogallery();			
		if (out != null && out.length > 0) {
			alert(out);
		}
		performAction('reloadData');
	}
}

function hideElement(elmID, overDiv) {
	elArr = document.getElementsByTagName (elmID);
	for (i = 0; i < elArr.length; i++) {
		obj = elArr[i];
		if (!obj || !obj.offsetParent) {
			continue;
		}
        
		objLeft   = obj.offsetLeft;
		objTop    = obj.offsetTop;
		objParent = obj.offsetParent;

		while (objParent && objParent.tagName.toUpperCase() != "BODY") {
			objLeft  += objParent.offsetLeft;
			objTop   += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}

		objHeight = obj.offsetHeight;
		objWidth = obj.offsetWidth;

		if ((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
		else if ((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
		else if (overDiv.offsetTop >= (objTop + objHeight));
		else if (overDiv.offsetLeft >= (objLeft + objWidth));
		else {
			obj.style.visibility = "hidden";
		}
	}     
}

function showElement(elmID) {
	elArr = document.getElementsByTagName( elmID );
	for (i = 0; i < elArr.length; i++) {
		obj = elArr[i];
		if (!obj || !obj.offsetParent) {
			continue;
		}
		obj.style.visibility = "";
	}
}

function updateAjaxCalls() {
	if (typeof initializeAjaxElements == 'function') {
		initializeAjaxElements();
	}
}

// nastavi hodnotu title elementu me do podrizenych elementu IMG
// explorer nezobrazuje title rodicovskych elementu, pokud potomek ma alt="" 
function showImgTitle(me) { 
	if(!me) return;
	$(me).children('img').first().attr('title', me.title); 
}

// cookies
function setCookie(name, value, expires, path, domain, secure) {    	
	options = {};
	if (expires) { options.expires = expires; }
	if (path) { options.path = path; }
	if (domain) { options.domain = domain; }
	if (secure) { options.secure = true; }
	$.cookie(name, value, options);
}

function getCookie(name) {
    return $.cookie(name);
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        $.cookie(name, null); 
    }
}

var mousePositionX = 0;
var mousePositionY = 0;

// vypise elementy nutne pro dalsi skripty
function writRequiredDivs() {
 	document.write('<div id="mDiv" style="position:absolute; z-index: 1000; top: 0; left: 0;"></div>');
	document.write('<div id="bubbleDiv" style="position:absolute; z-index: 2000; display: none; background-color: #FFFFE1; color: #000000; padding: 6px; border: 1px solid #000000;"></div>');	
}

// bubble
function bubble(text, align) {
	$('#bubbleDiv').html(text);
	$('#bubbleDiv').css({top: mousePositionY+10, left: mousePositionX+10});
    $('#bubbleDiv').fadeIn('fast');
	return false;
}

function bubbleClose() {
	$('#bubbleDiv').hide();
}

// po startu
writRequiredDivs();

$(document).ready(function() {
	// EXTERNAL REF links
	$('a[rel="external"]').attr("target", "_blank");
	
	// pozice mysi
	$(document).mousemove(function(e) {
		mousePositionX = e.pageX;
		mousePositionY = e.pageY;
	});

	// submenuSelect
	$('.submenuSelect').bind('change', function() {
		if ($(this).val()) {
			window.location = $(this).val();
		}
	});
	
	// skryvaci hlavicka
	$("#hidetop").bind("click", function() { 
					$("#hidetop").toggleClass("closed"); 
					$("#admin-header").slideToggle("fast");
					$.cookie("hideTop", ($.cookie("hideTop")==1 ? 0 : 1));
					return false;
			  } );	
	if($.cookie("hideTop")==1) {
		$("#hidetop").toggleClass("closed"); 
		$("#admin-header").hide();
	}

});
