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'][''+paramm].value=value;
		if (paramm2) document.forms['form'][''+paramm2].value=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[''+paramm].value=value;
	if (paramm2) form[''+paramm2].value=value2;
	if (paramm3) form[''+paramm3].value=value3;
	if (paramm4) form[''+paramm4].value=value4;
	if (paramm5) form[''+paramm5].value=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 = 'en';
	if (typeof tableStyles=="undefined") { tableStyles = ""; }

	$(document).ready(function() {
		CKEDITOR.replace(
			name,
			{
				resize_minWidth : 580,
				width: 580,
				language : lang,
				entities_latin : false,
				skin : 'v2',
				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 && (isn.ie && out.length > 0 || 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) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

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>');
	//document.write('<div id="liveview" style="filter:alpha(opacity=90); -moz-opacity: 0.8; opacity: 0.8; position:absolute; z-index: 3000; display: none; background-color: #D4D3D5; color: #000000; padding: 6px;"><iframe id="liveview-frame" style="background-color: #FFFFFF;" src="#" width="250" height="150" scrolling="no"></iframe></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();
}

// live view
/*var liveviewTimer = null;
function liveview(url) {
	isn = new IsNavigator();
	if ((isn.gecko && isn.version>=1.9) || (isn.ie && isn.major>=8) || (isn.webkit) || (isn.opera)) {
		liveviewTimer = setTimeout(function() {
			clearTimeout(liveviewTimer);
			wScale = 0.3;
			wScalePerc = wScale * 100;
			$('#liveview-frame').load(function() {				
				$('#liveview-frame').contents().find('body').css('-moz-transform', 'scale('+wScale+')');
				$('#liveview-frame').contents().find('body').css('-moz-transform-origin', '0 0');
				$('#liveview-frame').contents().find('body').css('-o-transform', 'scale('+wScale+')');
				$('#liveview-frame').contents().find('body').css('-o-transform-origin', '0 0');
				$('#liveview-frame').contents().find('body').css('-webkit-transform', 'scale('+wScalePerc+'%)');
				$('#liveview-frame').contents().find('body').css('-webkit-transform-origin', '0 0');
				$('#liveview-frame').contents().find('body').css('zoom', wScalePerc+'%');
				$('#liveview').css({top: mousePositionY+15, left: mousePositionX+15});
				$('#liveview').fadeIn('fast');
			});
			$('#liveview-frame').attr('src', url);
		}, 1200);
	}
	
	return false;
}

function liveviewClose() {
	if (liveviewTimer) { clearTimeout(liveviewTimer); }
	$('#liveview').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();
		}
	});
});
