/*
 $Id: functions.js,v 1.11 2011-04-04 12:21:10 radovan Exp $
 Common JavaSript Functions
 */
var popWin;

function Del(){
    return confirm("Chcete data opravdu smazat?");
}

function DelAll(){
    q = confirm("POZOR! Bude se mazat skupina dat!");
    if (q) 
        q = Del();
    return q;
}

function openWIN(target, x, y){
    popWin = window.open('', target, 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=' + x + ',height=' + y + ',left=10,top=10');
    popWin.focus();
}

function openWinURL(url, target, x, y){
    popWin = window.open(url, target, 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=' + x + ',height=' + y + ',left=10,top=10');
    popWin.focus();
}

function test_and_openWIN(url, target, x, y){
    if (!window.openedWin) {
        window.openedWin = window.open(url, target, 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=' + x + ',height=' + y + ',left=30,top=30');
    }
    window.openedWin.focus();
}

// ----- Otevreni noveho okna ve stredu obrazovky -----
function openWINcenter(page, target, dx, dy){
    x = (screen.width - dx) / 2;
    y = (screen.height - dy) / 2;
    openWINxy(page, target, dx, dy, x, y);
}

function openImageWIN(target, x, y){
    var popWin = window.open('', target, 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=' + x + ',height=' + y + ',left=10,top=10');
    popWin.focus();
}


function openImageFullWIN(target, image_url){

    x = self.window.screen.availWidth - 20;
    y = self.window.screen.availHeight - 40;
    popWin = window.open('?acc=preview&image=' + image_url, target, 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=' + x + ',height=' + y + ',left=5,top=0');
    popWin.focus();
}

// ----- Otevreni noveho okna na pozici [x,y] -----
function openWINxy(page, target, dx, dy, x, y){
    popWin = window.open(page, target, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=' + dx + ',height=' + dy + ',left=' + x + ',top=' + y);
    popWin.focus();
}

function getObj(id) {
	return document.getElementById(id);
}

function getContent(url, target) {
	return getRequest(url, target);
}

// ----- Zobrazi/skryje objekt -----
function display_swap() {
	if(arguments.length>0) {
		for(var i=0; i<arguments.length; i++) {
			var obj = getObj(arguments[i]);
			if (obj!='undefined' && obj!=null) {
				if (obj.style.display == 'none') {
					obj.style.display = 'block';
				} else {
					obj.style.display = 'none';
				}
			}
		}
	}
}

// ----- Otevre requestem dialogove okno -----
function dialog(url, target, width, height) {
	var w = width ? width : 300;
	var h = height ? height : 100;
	var winw = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
	var winh = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
	var ofsx = window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft;
	var ofsy = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
	var popup = new Element('div',{ id:target });
	popup.inject(document.body);
	popup.style.left = (Math.round((winw-w)/2)+ofsx)+'px';
	popup.style.top = (Math.round((winh-h)/2)+ofsy)+'px';
	if(width) popup.style.width = w+'px';
	if(height) popup.style.height = h+'px';
	popup.style.minWidth = '150px';
	popup.style.minHeight = '50px';
	popup.load(url);
}

function changeSign() {
	if(arguments.length>0) {
		for(var i=0; i<arguments.length; i++) {
			var obj = getObj(arguments[i]);
			if (obj!='undefined' && obj!=null) {
				if (obj.innerHTML == '+') {
					obj.innerHTML = '-';
				} else {
					obj.innerHTML = '+';
				}
			}
		}
	}
}

// ----- Vypis do Firebug konzole -----
function log(txt) {
	try {console.log(txt);} catch(e) {}
}
