WND_Params = new Array();
WND_Params['scrollbars'] = 1;
WND_Params['resizable'] = 2;
WND_Params['titlebar'] = 4;
WND_Params['menubar'] = 8;
WND_Params['toolbar'] = 16;
WND_Params['location'] = 32;
WND_Params['status'] = 64;
WND_Params['directories'] = 128;

function WND_openPopup (href, urlParams, wndWidth, wndHeight, wndParams, wndName, wndSystem)
{
	var time = new Date ();
	if (!wndName) 	wndName = 'popup_' + time.getTime ();
	if (urlParams)	href = href + '?' + urlParams;

    w  = screen.width;
    h  = screen.height;
    w = ( w / 2 ) - ( wndWidth / 2);
    h = ( h / 2 ) - ( wndHeight / 2);
    h = h - h * 0.5;
	position = 'left=' + w + ', top=' + h;

	var wnd_properties = '';
	for (keys in WND_Params)
		wnd_properties += ''+keys+'=' + ((wndParams & WND_Params[keys]) != 0 ? 'yes,' : 'no,');

	wndParams = 'width=' + wndWidth + ',height=' + wndHeight + ',' + position + ','+(wnd_properties.substring(0,wnd_properties.length-1));
//href +=  '&gid=' + time.getTime ();

	wnd = window.open (href, wndName, wndParams);

	return wnd;
}

function WND_close()
{
	window.close ();
}

function WND_print()
{
    window.print ();
}

function WND_resize( x, y )
{
    var resizeToWidth = x + '';
    var resizeToHeight = y + '';

    if (resizeToWidth.search('%') != -1)
        resizeToWidth = (screen.availWidth * parseInt(resizeToWidth))/100;

    if (resizeToHeight.search('%') != -1)
        resizeToHeight = (screen.availHeight * parseInt(resizeToHeight))/100;

    parent.resizeTo(resizeToWidth , resizeToHeight);
}

function WND_move( x, y )
{
    var moveToX = x+'';
    var moveToY = y+'';

    if (moveToX.search('left') != -1)
        moveToX = '';
    if (moveToX.search('center') != -1)
        moveToX = (screen.availWidth - document.body.offsetWidth)/2+'';
    if (moveToX.search('right') != -1)
        moveToX = screen.availWidth - document.body.offsetWidth + '';

    if (moveToY.search('top') != -1)
        moveToY = '';
    if (moveToY.search('center') != -1)
        moveToY = (screen.availHeight - document.body.offsetHeight)/2+'';
    if (moveToY.search('bottom') != -1)
        moveToY = screen.availHeight - document.body.offsetHeight + '';

    parent.moveTo(moveToX, moveToY);
}

function WND_saveas(  )
{
    document.execCommand('SaveAs');
}

function WND_redirect ( url )
{
//debug('is redirect');
	this.location = url;
}

//----------------------------[ not standard WND ]----------------------------
    function catchKey (getKeyCode)
	{
		if (getKeyCode == event.keyCode)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

    function url ( url_path )
    {
		this.location = url_path;
	}
	
	function ResizeSelf(x,y){
		parent.resizeTo(x,y);
	}
	
	function timedResize () {
		// tie 4px neviem preco ale vzdy tam chybali, tak som ich tam dal - Reizo
		var dh = document.body.scrollHeight - document.body.offsetHeight + 4;
		// toto osetrenie je kvoli debugom
		if ((dh + document.body.clientHeight) <= self.screen.availHeight) {
			resizeBy(0,dh);
		}
	}
	
	function resizeSelf_new (resizeObject) {
		
		var tableStatus = 0;
		var scrollAdd = 0;
		
		if(document.getElementById('admin_nav')) {
			tableStatus = document.getElementById('admin_nav').offsetHeight;
		}
		
		var width = document.getElementById(resizeObject).offsetWidth;
		var height = document.getElementById(resizeObject).offsetHeight + tableStatus;
		
		width = width + '';
		height =  height + '';
		
		var center_position_x = screen.width/2;
		var center_position_y = screen.height/2;
		
		var screen_width    = parseInt(width);
		move_to_x = center_position_x - (screen_width/2);
		resizeToWidth = screen_width;
		
		var screen_height   = parseInt(height);
		move_to_y = center_position_y - (screen_height/2);
		resizeToHeight = (screen_height > screen.availHeight) ? screen.availHeight : screen_height;
		
		if (resizeToHeight >= screen.availHeight) {
			resizeToHeight = screen.availHeight;
			move_to_y = 0;
			scrollAdd = 20;
		}
		if (resizeToWidth >= screen.availWidth) {
			resizeToWidth = screen.availWidth;
			move_to_x = 0;
			scrollAdd = 0;
		}
		
		parent.moveTo(move_to_x,move_to_y);
		
		if(!top.iframe_rid) {
			parent.resizeTo(resizeToWidth + scrollAdd, resizeToHeight);
			
			var dw = width - document.body.clientWidth;
			var dh;
			if (resizeToHeight == screen.availHeight) {
				dh = 0;
			} else {
				dh = height - document.body.clientHeight;
			}
			parent.resizeBy(dw + scrollAdd, dh);
		}
		window.setTimeout(timedResize, 10);
	}
	

	function resizeSelf(width, height, maximalize, resizeObject)
	{
		if (width == -1 && height == -1 && !maximalize && resizeObject) {
			resizeSelf_new (resizeObject);
			return;
		}
		
        var tableScroll = 30;
        var tableStatus = 23;
        if(document.all['admin_nav'])
            tableStatus += 20;

        // osetrenie resize na XP !!!
        if(navigator.userAgent.indexOf('Windows NT 5.1') != -1)
            tableStatus += 10;

        if(width == -1)
        {
            width = document.all[resizeObject].offsetWidth + tableScroll;
            width = width+'';
        }
        if(height == -1)
        {
            height = document.all[resizeObject].offsetHeight + tableScroll + tableStatus;
            height = height+'';
        }

		var center_position_x = screen.width/2;
		var center_position_y = screen.height/2;

		if (maximalize == 1)
		{
			parent.resizeTo(screen.availWidth, screen.availHeight);
            parent.moveTo(0,0);
		}
		else
		{
	        if(width.search('%') != -1)
	        {
                var screen_width_percent    = parseInt(width.replace('%', ''))/100;
                move_to_x = center_position_x - (screen.width*screen_width_percent/2);
                resizeToWidth = screen.width*screen_width_percent;
                if (resizeToWidth > screen.availWidth)
                {
                	resizeToWidth = screen.availWidth;
                	move_to_x = 0;
            	}
	        }
            else
            {
                var screen_width    = parseInt(width);
                move_to_x = center_position_x - (screen_width/2);
                resizeToWidth = screen_width;
                if (resizeToWidth > screen.availWidth)
                {
                	resizeToWidth = screen.availWidth;
                	move_to_x = 0;
            	}
            }

            if(height.search('%') != -1)
            {
                var screen_height_percent   = parseInt(height.replace('%', ''))/100;
                move_to_y = center_position_y - (screen.height*screen_height_percent/2);
                resizeToHeight = screen.height*screen_height_percent;
                if (resizeToHeight >= screen.availHeight)
                {
                	resizeToHeight = screen.availHeight;
                	move_to_y = 0;
            	}
            }
            else
            {
                var screen_height   = parseInt(height);
                move_to_y = center_position_y - (screen_height/2);
                resizeToHeight = (screen_height > screen.availHeight) ? screen.availHeight : screen_height;
                if (resizeToHeight >= screen.availHeight)
                {
                	resizeToHeight = screen.availHeight;
                	move_to_y = 0;
            	}
            }

            parent.moveTo(move_to_x,move_to_y);

            if(!top.iframe_rid)
                parent.resizeTo(resizeToWidth , resizeToHeight);

		}
	}

    function windowFocus()
    {
        window.focus();
    }

	function ScrollOff() {
        document.body.scroll = 'no';
	}

	function set_window (width, height, maximalize, menubar, toolbar, statusbar, advertisement) {
		if (maximalize == 1) {
			parent.resizeTo(screen.width, screen.height);

		} else {
			parent.resizeTo(width, height);
		}
	}
