//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;
var my_event = null;
var _v1_confirm_menu_item = null;

// Capture mouse clicks on the page so any active button can be
// deactivated.

$(document).mousedown(function(event) {
    pageMousedown(event);
});
/*
if (browser.isIE)
    document.onmousedown = pageMousedown;
else
    document.addEventListener("mousedown", pageMousedown, true);
*/

function pageMousedown(event) {
    
    var el;
    
    my_event = event;
    
    // If there is no active button, exit.
    
    if (activeButton == null) {
        document.oncontextmenu = "";
        return;
    }
    
    // Find the element that was clicked on.
    
    if (browser.isIE) {
        el = window.event.srcElement;
    } else {
        el = (event.target.tagName ? event.target : event.target.parentNode);
    }
    
    // If the active button was clicked on, exit.
    
    if (el == activeButton) {
        return;
    }
    
    // If the element is not part of a menu, reset and clear the active
    // button.
    
    if (getContainerWith(el, "DIV", "popup_menu") == null) {
        resetButton(activeButton);
        activeButton = null;
    }
}

function buttonClick(event, menuId) {
    
    var button;
    
    // Get the target button element.
    
    if (browser.isIE)
        button = window.event.srcElement;
    else
        button = event.currentTarget;
    
    // Blur focus from the link to remove that annoying outline.
    
    //button.blur();
    
    // Associate the named menu to this button if not already done.
    // Additionally, initialize menu display.
    
    if (button.menu == null) {
        button.menu = document.getElementById(menuId);
        if (button.menu.isInitialized == null)
            menuInit(button.menu);
    }
    
    // Reset the currently active button, if any.
    
    if (activeButton != null)
        resetButton(activeButton);
    
    // Activate this button, unless it was the currently active one.
    
    if (button != activeButton) {
        depressButton(button);
        activeButton = button;
    }
    else
        activeButton = null;
    
    return false;
}

function buttonMouseover(event, menuId) {
    
    var button;
    
    // Find the target button element.
    
    if (browser.isIE)
        button = window.event.srcElement;
    else
        button = event.currentTarget;
    
    // If any other button menu is active, make this one active instead.
    
    if (activeButton != null && activeButton != button)
        buttonClick(event, menuId);
}

function depressButton(button) {
    
    var x, y;
    
    // Update the button's style class to make it look like it's
    // depressed.
    
    $(button).addClass("popup_menuButtonActive");
    
    // Position the associated drop down menu under the button and
    // show it.
    
    if(my_event && my_event.pageX !== undefined) {
        x = my_event.pageX;
        y = my_event.pageY;
    } else {
        x = event.clientX + document.body.scrollLeft;
        y = event.clientY + document.body.scrollTop;
    }
    
    //x = getPageOffsetLeft(button);
    //y = getPageOffsetTop(button);
    
    // For IE, adjust position.
    
    if (browser.isIE) {
        x += button.offsetParent.clientLeft;
        y += button.offsetParent.clientTop;
    }
    
    // otkrij gdje se na prozoru nalazi i napravi pomak gore, dolje ili lijevo
    var maxX, maxY;
    var scrolled_size = get_scrolled_size();
    
    maxX = scrolled_size.width - button.menu.offsetWidth - 5;
    maxY = scrolled_size.height - button.menu.offsetHeight - 15;
    
    if (x > maxX)
        x = Math.max(0, maxX);
    y = Math.max(0, Math.min(y, maxY));
    
    
    
    button.menu.style.left = x + "px";
    button.menu.style.top  = y + "px";
    button.menu.style.visibility = "visible";
    
    // For IE; size, position and show the menu's IFRAME as well.
    
    if (button.menu.iframeEl != null)
    {
        button.menu.iframeEl.style.left = button.menu.style.left;
        button.menu.iframeEl.style.top  = button.menu.style.top;
        button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
        button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
        button.menu.iframeEl.style.display = "";
    }
}

function resetButton(button) {
    
    // Restore the button's style class.
    
    $(button).removeClass("popup_menuButtonActive");
    
    // Hide the button's menu, first closing any sub menus.
    
    if (button.menu != null) {
        closeSubMenu(button.menu);
        button.menu.style.visibility = "hidden";
        
        // For IE, hide menu's IFRAME as well.
        
        if (button.menu.iframeEl != null)
            button.menu.iframeEl.style.display = "none";
    }
}

//----------------------------------------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------------------------------------

function menuMouseover(event) {
    
    var menu;
    
    // Find the target menu element.
    
    if (browser.isIE)
        menu = getContainerWith(window.event.srcElement, "DIV", "popup_menu");
    else
        menu = event.currentTarget;
    
    // Close any active sub menu.
    
    if (menu.activeItem != null)
        closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {
    
    var item, menu, x, y;
    
    // Find the target item element and its parent menu element.
    
    if (browser.isIE)
        item = getContainerWith(window.event.srcElement, "A", "popup_menuItem");
    else
        item = event.currentTarget;
    menu = getContainerWith(item, "DIV", "popup_menu");
    
    // Close any active sub menu and mark this one as active.
    
    if (menu.activeItem != null)
        closeSubMenu(menu);
    menu.activeItem = item;
    
    // Highlight the item element.
    
    $(item).addClass("popup_menuItemHighlight");
    
    // Initialize the sub menu, if not already done.
    
    if (item.subMenu == null) {
        item.subMenu = document.getElementById(menuId);
        
        if (item.subMenu.isInitialized == null) {
            menuInit(item.subMenu);
        }
    }
    
    // Get position for submenu based on the menu item.
    
    x = getPageOffsetLeft(item) + item.offsetWidth;
    y = getPageOffsetTop(item);
    
    if (browser.isOP) {
        x -= 28;
        y -= 10;
    }
    
    // Adjust position to fit in view.
    
    var scrolled_size = get_scrolled_size();
    
    var maxX, maxY;
    
    maxX = scrolled_size.width - item.subMenu.offsetWidth;
    maxY = scrolled_size.height - item.subMenu.offsetHeight;
    
    if (x > maxX)
        x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
                + (menu.offsetWidth - item.offsetWidth));
    y = Math.max(0, Math.min(y, maxY));
    
    // Position and show it.
    
    item.subMenu.style.left       = x + "px";
    item.subMenu.style.top        = y + "px";
    item.subMenu.style.visibility = "visible";
    
    // For IE; size, position and display the menu's IFRAME as well.
    
    if (item.subMenu.iframeEl != null)
    {
        item.subMenu.iframeEl.style.left    = item.subMenu.style.left;
        item.subMenu.iframeEl.style.top     = item.subMenu.style.top;
        item.subMenu.iframeEl.style.width   = item.subMenu.offsetWidth + "px";
        item.subMenu.iframeEl.style.height  = item.subMenu.offsetHeight + "px";
        item.subMenu.iframeEl.style.display = "";
    }
    
    // Stop the event from bubbling.
    
    if (browser.isIE)
        window.event.cancelBubble = true;
    else
        event.stopPropagation();
}

function closeSubMenu(menu) {
    
    if (menu == null || menu.activeItem == null)
        return;
    
    // Recursively close any sub menus.
    
    if (menu.activeItem.subMenu != null) {
        closeSubMenu(menu.activeItem.subMenu);
        
        
        // Hide the sub menu.
        menu.activeItem.subMenu.style.visibility = "hidden";
        
        // For IE, hide the sub menu's IFRAME as well.
        
        if (menu.activeItem.subMenu.iframeEl != null)
            menu.activeItem.subMenu.iframeEl.style.display = "none";
        
        menu.activeItem.subMenu = null;
    }
    
    // Deactivate the active menu item.
    
    $(menu.activeItem).removeClass("popup_menuItemHighlight");
    menu.activeItem = null;
}

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------

function menuInit(menu) {
    
    var itemList, spanList;
    var textEl, arrowEl;
    var itemWidth;
    var w, dw;
    var i, j;
    
    // For IE, replace arrow characters.
    
    if (browser.isIE) {
        menu.style.lineHeight = "2.5ex";
        spanList = menu.getElementsByTagName("SPAN");
        for (i = 0; i < spanList.length; i++)
            if ($(spanList[i]).hasClass("popup_menuItemArrow")) {
                spanList[i].style.fontFamily = "Webdings";
                spanList[i].firstChild.nodeValue = "4";
            }
    }
    
    // Find the width of a menu item.
    
    itemList = menu.getElementsByTagName("A");
    if (itemList.length > 0)
        itemWidth = itemList[0].offsetWidth;
    else
        return;
    
    // For items with arrows, add padding to item text to make the
    // arrows flush right.
    
    for (i = 0; i < itemList.length; i++) {
        spanList = itemList[i].getElementsByTagName("SPAN");
        textEl  = null;
        arrowEl = null;
        for (j = 0; j < spanList.length; j++) {
            if ($(spanList[j]).hasClass("popup_menuItemText"))
                textEl = spanList[j];
            if ($(spanList[j]).hasClass("popup_menuItemArrow")) {
                arrowEl = spanList[j];
            }
        }
        if (textEl != null && arrowEl != null) {
            textEl.style.paddingRight = (itemWidth
                    - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
            
            // For Opera, remove the negative right margin to fix a display bug.
            
            if (browser.isOP)
                arrowEl.style.marginRight = "0px";
        }
    }
    
    // Fix IE hover problem by setting an explicit width on first item of
    // the menu.
    
    if (browser.isIE) {
        w = itemList[0].offsetWidth;
        itemList[0].style.width = w + "px";
        dw = itemList[0].offsetWidth - w;
        w -= dw;
        itemList[0].style.width = w + "px";
    }
    
    // Fix the IE display problem (SELECT elements and other windowed controls
    // overlaying the menu) by adding an IFRAME under the menu.
    
    if (browser.isIE) {
        menu.iframeEl = menu.parentNode.insertBefore(document.createElement("IFRAME"), menu);
        menu.iframeEl.style.display = "none";
        menu.iframeEl.style.position = "absolute";
    }
    
    // Mark menu as initialized.
    
    menu.isInitialized = true;
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {
    
    // Starting with the given node, find the nearest containing element
    // with the specified tag name and style class.
    
    while (node != null) {
        if (node.tagName != null && node.tagName == tagName &&
                $(node).hasClass(className)
        ) {
            return node;
        }
        node = node.parentNode;
    }
    
    return node;
}

function hasClassName(el, name) {
	return $(el).hasClass(name);
}

function removeClassName(el, name) {
	$(el).removeClass(name);
}

function getPageOffsetLeft(el) {
    
    var x;
    
    // Return the x coordinate of an element relative to the page.
    
    x = el.offsetLeft;
    if (el.offsetParent != null)
        x += getPageOffsetLeft(el.offsetParent);
    
    return x;
}

function getPageOffsetTop(el) {
    
    var y;
    
    // Return the x coordinate of an element relative to the page.
    
    y = el.offsetTop;
    if (el.offsetParent != null)
        y += getPageOffsetTop(el.offsetParent);
    
    return y;
}

//var select_key=false;
/*
function selectKeyDown(event) {
    if (event.keyCode==16)
        select_key = true;
}

function selectKeyUp(event) {
    if (event.keyCode==16)
        select_key = false;
}
*/
var _v1_invisible_array;

var _prikazi_meni_is_empty;
function prikazi_meni(tip, event, menu_name, menu_div, params, invisibleItems, confirm_menu_item) {
	if(event.shiftKey) {
		return true;
	}
	
	var dom_menu_div = $("#" + menu_div);
	var dom_menu_div_holder = dom_menu_div.closest(".popup_menu_holder");
	if(!dom_menu_div_holder.parent().is("body")) {
	    dom_menu_div_holder.prependTo("body");
	}
	
    if(confirm_menu_item !== null) {
        _v1_confirm_menu_item = confirm_menu_item;
    } else {
        _v1_confirm_menu_item = null;
    }
    
	if (invisibleItems!="" && invisibleItems!=null)
        _v1_invisible_array = invisibleItems.split(',');
	else
        _v1_invisible_array = null;
	
	//_v1_invisible_array=[11,12,32];

	_prikazi_meni_is_empty = true;

	v1menu_invisible(document.getElementById(menu_div).getElementsByTagName('div')[0], 0);
	if(_prikazi_meni_is_empty)
		return false;
    j=0;
    var mn = document.getElementById(menu_div);
    var as = mn.getElementsByTagName('a');
    for (var i=0;i<as.length;i++)
    {
		/* replace number in rand=1234 with random number */
		var h_1, h_2;
		var h = as[i].href;
		h_1 = h.indexOf("_rand=");
		if(h_1 != -1)
		{
			h_1 = h_1+6;
			for(h_2 = h_1; h_2 < h.length && !isNaN(h.substring(h_2,h_2+1)); h_2++);
			h = h.substring(0, h_1) + Math.floor(Math.random()*55555) + h.substring(h_2);
			as[i].href = h;
		}
		
        if (as[i].href.indexOf("v1menupost")!=-1) {
            br = as[i].href.lastIndexOf("')");
            if (br!=-1) {
                temp = as[i].href.substring(0,br);
                brtemp = temp.lastIndexOf("'");
                as[i].href = temp.substring(0,brtemp) + "'"+params+"')";
            } else {
                as[i].href = as[i].href + "','"+params+"')";
            }
        } else {
            if (as[i].href.indexOf("_v1")!=-1) {
                br = as[i].href.indexOf("&_v1param");
                if (br!=-1) {
                    if (as[i].href.indexOf("show_window")!=-1) as[i].href = as[i].href.substring(0,br) + "&_v1param="+params+"&_add=GET')";
                    else as[i].href = as[i].href.substring(0,br) + "&_v1param="+params+"&_add=GET";
                } else {
                    if (as[i].href.indexOf("show_window")!=-1) {
                        as[i].href = as[i].href + "&_v1param="+params+"&_add=GET')";
                    } else {
                        var anchor;
                        var anchor_index;
                        anchor_index = as[i].href.lastIndexOf("#");
                        if(anchor_index != -1) {
                            anchor = as[i].href.substring(anchor_index);
                            as[i].href = as[i].href.substring(0, anchor_index);
                        } else {
                            anchor = '';
                        }
                        as[i].href = as[i].href + "&_v1param="+params+"&_add=GET"+anchor;
                    }
                }
            }
        }

        if(as[i].type != "")
          as[i].href = as[i].type;

        // If #prm is given, change it with parameter
        if (as[i].href.indexOf("#prm")!=-1) {
           as[i].type = as[i].href;

           s = new String(as[i].href);
           as[i].href = s.replace("#prm",params);
        }
    }


    document.oncontextmenu=new Function("return false");
    return buttonClick(event, menu_name);
}

function v1menu_invisible(menu, offset)
{
	var a_all = menu.getElementsByTagName('a');
	var offset;
	var show;
	var invisible;
	var counter=0;
	
	for(var i=0;i<a_all.length;i++)
	{
		i_offset = counter+offset;
		counter++;
		a = a_all[i];
		//alert(i_offset + " ("+i+"/"+offset+") - "+a.innerHTML);
		
		if(_v1_invisible_array != null)
		{
			invisible = parseInt(_v1_invisible_array[0]);
			if(invisible < i_offset)
			{
				alert("Error: hiding menu ("+invisible+"<"+i_offset+")");
			}
			else if(invisible == i_offset)
			{
				a.style.display = 'none';
				_v1_invisible_array.shift();
			}
			else
			{
				_prikazi_meni_is_empty = false;
				a.style.display = 'block';
			}
		}
		else
		{
			_prikazi_meni_is_empty = false;
			a.style.display = 'block';
		}
		
		if(a.href == "javascript:void(null)")
		{
			var k = a.onmouseover.toString();
			
			var d = k.indexOf("menuItemMouseover(event, ");
			if(d != -1)
			{
				k = k.substring(d+26);
				d = Math.max(k.indexOf('"'), k.indexOf("'"));
				if(d != -1)
				{
					k = k.substr(0, d);
					offset = v1menu_invisible(document.getElementById(k), i_offset+1);
					counter = 0;
				}
			}
		}
	}
	return offset+a_all.length;
}

function v1menupost(elem_id,myconfirm,formName,formAction,params) {
    // dohvati formu
    formEl = document.getElementById(elem_id);

    if (formEl!=null) {
        // postavi parametre forme
        formEl.name = formName;
        formEl.action = formAction;
        formEl._v1param.value = params;

		if (myconfirm!="") {
            if(_v1_confirm_menu_item !== null) {
                myconfirm += " (" + _v1_confirm_menu_item + ")";
                _v1_confirm_menu_item = null;
            }
			test = confirm(myconfirm);	
			if (!test) return sakrij_meni();				
		}
		
        // submitaj formu
        formEl.submit();
    }
}

function sakrij_meni(ptitle) {
	if (ptitle!="") {
		set_window_title(ptitle);
	}
	resetButton(activeButton);
    activeButton = null;
}

function getViewportHeight() {
    if (window.innerHeight!=window.undefined) return window.innerHeight;
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
    if (document.body) return document.body.clientHeight;
    return window.undefined;
}
function getViewportWidth() {
    if (window.innerWidth!=window.undefined) return window.innerWidth;
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
    if (document.body) return document.body.clientWidth;
    return window.undefined;
}

/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function hideSelectBoxes() {
    var hideBoxes = $("#lightbox_block").data('hideBoxes');
    if(hideBoxes === undefined) {
        hideBoxes = [];
        $("#lightbox_block").data('hideBoxes', hideBoxes);
    }
    
    // object elements could be a problem too
    $("select").each(function(index) {
        if($(this).css('visibility') == 'visible') {
            hideBoxes.push($(this));
            $(this).css('visibility', 'hidden');
        }
    });
}

/**
* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displaySelectBoxes() {
    var hideBoxes = $("#lightbox_block").data('hideBoxes');
    if(hideBoxes === undefined) {
        hideBoxes = [];
        $("#lightbox_block").data('hideBoxes', hideBoxes);
    }

    while(hideBoxes.length > 0) {
        var element = hideBoxes.pop();
        element.css('visibility', 'visible');
    }
}

// uhvati pritiskanje key-a "s" (select)
/*
if (!browser.isIE) {
    document.addEventListener("keydown", function(ev) { selectKeyDown(ev);},false);
    document.addEventListener("keyup", function(ev) { selectKeyUp(ev);},false);
} else {
    document.attachEvent('onkeydown',function(ev) { selectKeyDown(ev);});
    document.attachEvent('onkeyup',function(ev) { selectKeyUp(ev);});
}
*/

function init_drag_res(){
    $("#lightbox_block").draggable({ 
        refreshPositions: true,
        
        start: function(event, ui) {
            $("#lightbox_body").append('<div id="lightbox_mask" style="background-color:none; position: absolute; left: 0pt; top: 0pt; right: 0pt; bottom: 0pt;"></div>');
        },
        stop: function(event, ui) {
            $("#lightbox_mask").remove();
        }
    });
    $("#lightbox_block").resizable({ 
        animateEasing: 'swing',
        minHeight: 200, 
        minWidth: 300, 
        alsoResize: '#lightbox_body',
        
        start: function(event, ui) {
            $("#lightbox_body").append('<div id="lightbox_mask" style="background-color:none; position: absolute; left: 0pt; top: 0pt; right: 0pt; bottom: 0pt;"></div>');
        },
        stop: function(event, ui) {
            $("#lightbox_mask").remove();
        }
    });
}

function show_window(wurl, wtitle) { // width, height
 
    $("body").append(
            '<div id="lightbox_overlay" style="width:100%; display:none;"></div>' + 
            '<div id="lightbox_block" style="width:400px; display:none;">' + 
            '   <div id="lightbox_head">' +
            '       <a class="button right" href="javascript:hide_window();">' + _lc_window_close + '</a>' +
            '       <div id="lightbox_logo">&nbsp;</div>' +
            '       <div id="lightbox_title"></div>' +
            '   </div>' + 
            '   <div id="lightbox_body"><iframe id="lightbox_iframe" frameborder="0"></iframe></div>' + 
            '</div>');

    init_drag_res();

    var args = show_window.arguments;
    var data = null;
    if (args.length == 5) { // Zadani su i širina i visina popupa (možda) i dodatni parametri
        data = args[4];
        wurl += '&' + $.param(args[4]);
    }
    
    /* replace number in rand=1234 with random number */
	var h_1, h_2;
	var h = wurl;
	h_1 = h.indexOf("_rand=");
	if(h_1 != -1)
	{
		h_1 = h_1+6;
		for(h_2 = h_1; h_2 < h.length && !isNaN(h.substring(h_2,h_2+1)); h_2++);
		h = h.substring(0, h_1) + Math.floor(Math.random()*55555) + h.substring(h_2);
		wurl = h;
	}
	
	
    hideSelectBoxes();
	$("#lightbox_overlay").fadeTo(0,0.01);
    $("#lightbox_block").fadeTo(0,0.01);
    $("#lightbox_overlay").fadeTo("fast",0.85);
    
    $('#lightbox_iframe').attr('src', wurl);
    $('#lightbox_iframe').load(function(){
		if (wtitle!="" && wtitle!=null) set_window_title(wtitle);
		    
		var windowWidth, windowHeight;

		if (window.innerWidth) {
		    windowWidth=window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
		    windowWidth=document.documentElement.clientWidth;
		}
		else if (document.body) {
		    windowWidth=document.body.clientWidth;
		}

		if (window.innerHeight) {
		    windowHeight=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
		    windowHeight=document.documentElement.clientHeight;
		}
		else if (document.body) {
		    windowHeight=document.body.clientHeight;
		}
		
		var popupWidth = 0;
		var popupHeight = 0;

		if (args.length == 4) {// Zadani su i širina i visina popupa
		    popupWidth = args[2];
		    popupHeight = args[3];
		}
		if(popupWidth === null || popupWidth === undefined) {
		    popupWidth = 0;
		}
		if(popupHeight === null || popupHeight === undefined) {
		    popupHeight = 0;
        }
		
		     
		var headerHeight = document.getElementById('lightbox_head').offsetHeight;
		
		if (popupWidth >= windowWidth*0.9 || popupWidth == 0){
		    popupWidth = windowWidth*0.5;
		}
		
		if ((popupHeight + headerHeight) >= windowHeight || popupHeight == 0){
		    popupHeight = windowHeight*0.75;
		}
        

        var left = - popupWidth/2;
        var top =  - (popupHeight + headerHeight)/2;
		
        $("#lightbox_block").css({  
            "position": "fixed",
            "left": "50%",  
            "top": "50%" , 
            "margin-left": left + "px",
            "margin-top": top + "px",
		    "height": (popupHeight + headerHeight) + "px",
		    "width": popupWidth + "px"
		});

		$("#lightbox_body").css({  
		    "height": (popupHeight - 14) + "px",
		    "width": (popupWidth-6) + "px",
		    "padding": "0 3px"
		});

		$("#lightbox_iframe").css({  
		    "height": "100%",
		    "width": "100%"
		});
		
		$("#lightbox_block").fadeTo("fast",1);
        
		var frame_dom = $($("#lightbox_iframe").get(0).contentWindow);
		frame_dom.keyup(function(event) {
		    if(event.which == 27) {
		        popup_close_simple_do();
		    }		    
		});
		$("#lightbox_overlay").click(function(event) {
		    popup_close_simple_do();
		});
		$('body').bind('keyup.v1popupEvent', function(event) {
		    if(event.which == 27) {
                popup_close_simple_do();
            }
        });
		
		//FIXME: Almost all of this should not be in .load
		$(this).unbind('load');
    });
}

var refresh_window_flag = 0;
var hide_timeout = null;
var popup_close_simple = false;

function refresh_win() {
    refresh_window_flag = 1;
}

function popup_close_simple_do() {
    var popup_cw = $("#lightbox_iframe").get(0).contentWindow;
    if(popup_cw.popup_close_simple) {
        hide_window();
    } else {
        $(popup_cw.document).find("form");
        var close = true;
        $(popup_cw.document).find("form").each(function() {
            var id = $(this).attr('id');
            if(id != 'ap2_v1submitform') {
                close = false;
            }
        });
        if(close) {
            hide_window();
        } else {
            //TODO: Ask?
        }
    }
}

function hide_window() {
    if(!refresh_window_flag) {
        $("#lightbox_overlay").fadeOut("fast",function(){
            $("#lightbox_overlay").remove();
            displaySelectBoxes();
        });
    }

    $("#lightbox_block").fadeOut("fast",function(){
        $("#lightbox_block").remove();
    });
    
    $('body').unbind('.v1popupEvent');
    
    if(refresh_window_flag) {
        refresh_window();
    }
}

function refresh_window() {
    /*
    if (browser.isIE) {
        scTop = parseInt(document.body.scrollTop);
    } else if (browser.isNS) {
        scTop = parseInt(window.scrollY);
    } else if (browser.isOP) {
        scTop = parseInt(document.documentElement.scrollTop);
    }

    pleft = (fullWidth - 300) / 2;
    ptop = scTop + 100;
    gMsg.style.top =  ptop + "px";
    gMsg.style.left =  pleft + "px";
    gMsg.innerHTML = "<table width='100%' height='100%' border='0'><tr><td valign='center'><div style='color: #FFFFFF; text-align: center;'>" + _lc_window_refreshing + "</div></td></tr></table>";
    gMsg.style.display = 'block';
    */
    
    if(_request_method == 'GET') {
        document.getElementById("ap2_v1submitform").action = document.location.href;
    } else {
        var tmp_url = document.location.href;
        var poz = tmp_url.indexOf("?");
        
        if(poz != -1) {
            tmp_url = tmp_url.substring(0, poz);
        }
        document.getElementById("ap2_v1submitform").action = tmp_url;
    }
    document.getElementById("ap2_v1submitform").submit(); 
}

function set_window_title(newtitle) {
    windowTitle = document.getElementById("lightbox_title");
    if (windowTitle) {
        windowTitle.innerHTML = newtitle;
    }
}

function resize_to(w_width,w_height) {
    return false;

    dialogLeft = (fullWidth - w_width) / 2;
    dialogTop = scTop + 50;

    webdialog = document.getElementById("webDialog");
    webdialog.style.left = dialogLeft + "px";
    webdialog.style.top = dialogTop + "px";
    webdialog.style.width = w_width+"px";
    webdialog.style.height = w_height+"px";

    webdialogbody = document.getElementById("webDialogBody");
    webdialogbody.style.width = w_width+"px";
    webdialogbody.style.height = w_height+"px";
}

