function switch_module(nr)
{
	var i = 0;
	var el = '';
	var li = '';
	var clsname = ''
	do {
		i ++;
		el = document.getElementById('module-submenu-' + i);
		if (el) {
			if (i == nr) {
				el.style.display = 'block';
				clsname = 'active'
			} else {
				el.style.display = 'none';
				clsname = '';
			}
			li = document.getElementById('module-switch-' + i);
			li.className = clsname;
		} else break;
	} while (1);
}

function wgranet(uri)
{
    window.open(uri, "page", "menubar=yes, location=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
    return false;
}


function w(uri)
{
    window.open(uri, "newpage", "menubar=yes, location=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
    return false;
}


function wi(url, width, height)
{
    width += 50; height += 50;
    window.open(url, 'foto', 'width='+width+', height='+height+', toolbar=no, location=no, resizable=yes, scrollbars=yes, top=100, left=100');
    return false;
}

// správce obrázků
function wim(uri)
{
    var height = screen.height - 150;
    window.open(uri, "image_manager", "width=1024, height=" + height +", menubar=no, location=no, status=no, toolbar=no, scrollbars=yes, resizable=yes,left=50,top=50");
    return false;
}

// správce souborů
function wfm(uri)
{
    var height = screen.height - 150;
    window.open(uri, "file_manager", "width=1024, height=" + height +", menubar=no, location=no, status=no, toolbar=no, scrollbars=yes, resizable=yes,left=50,top=50");
    return false;
}

// okno s uploaderem obrázků (velký obrázek + výtvoření náhledů)
function wup(uri)
{
    window.open(uri, "uploader", "width=1024, height=800, menubar=no, location=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes,left=50,top=50");
    return false;
}

// zobrazení historie položky (článku, zboží, galerie atd.)
function whst(uri)
{
    window.open(uri, "history", "width=1024, height=768, menubar=no, location=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
    return false;
}

// okno pro hromadný upload
function wmu(uri)
{
    window.open(uri, "massuploader", "width=1024, height=800, menubar=no, location=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes,left=50,top=50");
    return false;
}



// #### Asi přijde smazat

function preview(area, lang)
{
    w('../text_formatting.php?lang=' + lang + '&area=' + area);
    return false;
}

var Y = 0;
var X = 0;

function get_cursor(e)
{
    Y = window.event ? window.event.offsetY : e.pageY;
    X = window.event ? window.event.offsetX : e.pageX;
}

document.onmousemove = get_cursor;
imageopacity = 0;
all_images = new Array();

function view_thumb_image(anchor,id,uri,width,height)
{
    var el = document.getElementById(id);
    var anch = document.getElementById(anchor).style;
	if (window.event) {
        anch.position = 'relative';
    }
	var a = new Array();
	var b = '';
	for (i = 0; i < all_images.length; i ++) {
		a = all_images.slice(i, i +1);
		b = a.pop();
		if (b != id) hide_tmb(b);
	}
    window.setTimeout('view_tmb("' + id + '", ' + width + ', ' + height + ', "' + uri + '")', 25);
	//window.setTimeout("hide_tmb('" + id + "')", 5000);
}


function view_tmb(id, width, height, uri)
{
    var el = document.getElementById(id);
    el.style.display = 'block';
    el.style.visibility = 'visible';
	var y = Y + 40;
	var x = X + 20;
	el.style.left = x + 'px' ;
	el.style.top = y + 'px';

    el.style.width = width + 'px';
    el.style.height = height + 'px';

    el.src = uri;
    if (navigator.appName == "Microsoft Internet Explorer") {
        el.style.filter = "BlendTrans(duration=2.0, percent=8)";
    }
	var a = new Array();
	var b = '';
	var c = new Array();
	var i = 0;
	var d = 0;
	var result = false;
	for (i = 0; i < all_images.length; i ++) {
		a = all_images.slice(i, i +1);
		b = a.pop();
		if (b != id) {
			c[d] = b;
			d ++;
		} else result = true;
	}
	if (!result) c[d] = id;
	all_images = c;
}


function hide_thumb_image(anchor, id)
{
    if (window.event) {
		window.setTimeout("hide_anchor('" + anchor + "')", 25);
    }
    var el = document.getElementById(id);
    el.style.visibility = 'hidden';
    window.setTimeout('hide_tmb("' +id + '")', 25);
}

function hide_anchor(anchor)
{
	var anch = document.getElementById(anchor);
	anch.style.position = 'static';
}	

function hide_tmb(id)
{
    var el = document.getElementById(id);
    el.style.display = 'none';
	el.style.visibility = 'visible';
	var a = new Array();
	var b = '';
	var c = new Array();
	var i = 0;
	var d = 0;
	for (i = 0; i < all_images.length; i ++) {
		a = all_images.slice(i, i +1);
		b = a.pop();
		if (b != id) {
			c[d] = b;
			d ++;
		}
	}
	all_images = c;
}



function translate(key, insert, insert2)
{
    var output = '';
    if (Lg[key].length) output = Lg[key];
    else output = 'No translation';

    output = output.replace('_XYZ_', insert);
    output = output.replace('_XYZ2_', insert2);
    return output;
}

function trim(hodnota)
{
	if(hodnota.charAt(0) == " ") {
		hodnota = hodnota.substring(1,hodnota.length);
		hodnota = trim(hodnota);
	}
	if(hodnota.charAt(hodnota.length-1) == " ") {
		hodnota = hodnota.substring(0,hodnota.length-1);
		hodnota=trim(hodnota);
	}
	return hodnota;
}

var admin_submenus = new Array();

function add_submenu(submenu)
{
	var i = admin_submenus.length;
	admin_submenus[i] = submenu;
}

function switch_admin_menu(submenu)
{
	var el = document.getElementById(submenu);
	var el2 = document.getElementById('admin-item-' + submenu);
	if (el.className == 'admin-invisible-submenu') {
		el.className = 'admin-visible-submenu';
		el2.className = 'admin-selected';
	}
	var i = 0;
	var is_in_submenus = false;
	for (i = 0; i < admin_submenus.length; i ++) {
		if (admin_submenus[i] != submenu) {
			el = document.getElementById(admin_submenus[i]);
			el.className = 'admin-invisible-submenu';
			el2 = document.getElementById('admin-item-' + admin_submenus[i]);
			el2.className = '';
		} else is_in_submenus = true;
	}
	for (i = 0; i < 30; i ++) {
		el = document.getElementById('admin-item-' + i);
		if (el) el.className = '';
	}
	i = admin_submenus.length;
	if (!is_in_submenus) admin_submenus[i] = submenu;
	return false;
}

function htmldecode(string)
{
	if (!string) return '';
	var position = -1;
	var html_entities = new Array('&quot;', '&#039;', '&lt;', '&gt;');
	var html_chars = new Array('"', "'", '<', '>');
	var entity = '';
	var chr = '';
	var new_entity = '';
	var len = 0;
	var position = -1;
	var i = 0;
	for (i = 0; i < 4; i ++) {
		entity = html_entities[i];
		chr = html_chars[i];
		len = entity.length;
		while (string.indexOf(entity) >= 0) {
			position = string.indexOf(entity);
			string = string.substring(0, position) + chr + string.substring(position + len) ;
		}
	}
	return string;
}

function check_admin_search()
{
	var el = document.getElementById('admin_search').value;
	el = trim(el);
	if (!el.length) {
		alert(translate('No_text_entered_for_search'));
		return false
	}
	return true;
}

function switch_limited_view(value)
{
	var elfalse = document.getElementById('lv_false');
	var visibility = 'visible';
	if (elfalse.checked) visibility = 'hidden';
	if (value == 'f') visibility = 'hidden';
	if (value == 't') visibility = 'visible';

	var selectors = document.getElementById('date-selectors');
	selectors.style.visibility = visibility;
}

function vis_menu(html_id)
{
	var el = document.getElementById('submenu' + html_id);
	if (el) el.style.display = 'block';
}

function hid_menu(html_id)
{
	var el = document.getElementById('submenu' + html_id);
	if (el) el.style.display = 'none';
}

