//----------------------------------------------------------------------------
// 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.

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.className += " popup_menuButtonActive";

  // Position the associated drop down menu under the button and
  // show it.

  if (browser.isNS) {
    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 + 12;
  maxY = scrolled_size.height - button.menu.offsetHeight;

  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.

  removeClassName(button, "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.className += " 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.

  removeClassName(menu.activeItem, "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 (hasClassName(spanList[i], "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 (hasClassName(spanList[j], "popup_menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "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 &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

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) {
    
    //alert(select_key);
    if (select_key == true) {
            select_key = false;
            return;
    }

    if(confirm_menu_item !== null) {
        _v1_confirm_menu_item = confirm_menu_item;
    } else {
        _v1_confirm_menu_item = null;
    }
    
    theButt = false;
    
    if (tip!=0) {
        if (window.event && window.event.button == 2
            || event.which && event.which == 3) {
            theButt = true
        }
    } else {
        if (window.event && window.event.button == 1
            || event.which && event.which == 1) {
            theButt = true
        }
    }
    
    if (theButt) {
        if (invisibleItems != undefined && 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);
            }
        }
    

        if (tip!=0) {
            document.oncontextmenu=new Function("return false");

            if (browser.isOP) {
                //windownews = window.open("", "", "status=no,location=no,toolbar=no,menubar=no,resizable=no,scrollbars=no,width=1,height=1,top=2000,left=4000");
        windownews = window.open("", "", "status=no,location=no,toolbar=no,menubar=no,resizable=no,scrollbars=no");
        windownews.blur();
                windownews.close();
            }
        }
        
        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
*
* Thanks for the code Scott!
*/
function hideSelectBoxes() {
    for(var i = 0; i < document.forms.length; i++) {
        for(var e = 0; e < document.forms[i].length; e++){
            if(document.forms[i].elements[e].tagName == "SELECT") {
                document.forms[i].elements[e].style.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() {
    for(var i = 0; i < document.forms.length; i++) {
        for(var e = 0; e < document.forms[i].length; e++){
            if(document.forms[i].elements[e].tagName == "SELECT") {
            document.forms[i].elements[e].style.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);});
}

/* Metode za pokazivanje i skrivanje popup prozora */
var wt_width=0, wt_height=0;
var scTop=0,scLeft=0;
var fullWidth=0, fullHeight=0;

function show_window(wurl, wtitle) { // width, height
    var windowSize = get_window_size();
    var scrolledSize = get_scrolled_size();
    var args = show_window.arguments;
    var popupWidth, popupHeight;
    
    if (args.length == 4) {// Zadani su i širina i visina popupa
        var popupWidth = args[2];
        var popupHeight = args[3];
    }
    
    if(isNaN(popupWidth) || popupWidth == 0) {
        popupWidth = 550;
    }
    
    if(isNaN(popupHeight) || popupHeight == 0) {
        popupHeight = 500;
    }
    
    windowSize.height = windowSize.height - 100;
    windowSize.width = windowSize.width - 100;;
    if(windowSize.height > 1 && windowSize.height < popupHeight || popupHeight == -1) {
        popupHeight = windowSize.height;
    }
    if(windowSize.width > 1 && windowSize.width < popupWidth || popupWidth == -1) {
        popupWidth = windowSize.width;
    }
    
    fullWidth = scrolledSize.width;
    fullHeight = scrolledSize.height;
    
    if (popupHeight > fullHeight) popupHeight = fullHeight;
    if (popupWidth > fullWidth) popupWidth = fullWidth;

    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);
    }
    scLeft = parseInt(document.body.scrollLeft);

    gPopupMask = document.getElementById("popupMask");
    
    gPopupMask.style.height = fullHeight + document.body.scrollHeight + "px";
      
    gPopupMask.style.width = fullWidth + "px";
    gPopupMask.style.top = 0 + "px";
    gPopupMask.style.left = 0 + "px";
    gPopupMask.style.display = 'block';
    
    dialogLeft = (fullWidth - popupWidth) / 2;
    dialogTop =  scTop + 50;

    webdialog = document.getElementById("webDialog");
    
    if (!browser.isIE && screen.width > 500 && screen.height > 500) {
        webdialog.style.position = "fixed";
        dialogTop = 50;
    }
    webdialog.style.left = dialogLeft + "px";
    webdialog.style.top = dialogTop + "px";
    webdialog.style.width = popupWidth + "px";
    webdialog.style.height = popupHeight + "px"; 

    webdialogbody = document.getElementById("webDialogBody");
    webdialogbody.style.width = popupWidth + "px";
    webdialogbody.style.height = popupHeight + "px";

    webdialogsrc = document.getElementById("webDialogSrc");
    
    /* 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;
    }
    webdialogsrc.src = wurl;
    
    if (wtitle!="" && wtitle!=null) set_window_title(wtitle);

    webdialog.style.display = "block";
    webdialogsrc.style.display = "block";
    webdialog.style.visibility = "visible";

    hideSelectBoxes();
}

var refresh_window=0;
var hide_timeout = null;
function hide_window(hide) {
    if(hide != true) {
        hide_timeout = setTimeout("hide_window(true);", 10);
        return;
    }
        
    // sakrij prozor
    webdialog = document.getElementById("webDialog");
    webdialogsrc = document.getElementById("webDialogSrc");
    webdialogsrc.src = _selfbase + '/lib/popup_loading.html';
    webdialog.style.display = "none";
    webdialogsrc.style.display = "none";
    webdialog.style.visibility = "hidden";

    gPopupMask = document.getElementById("popupMask");
    gMsg = document.getElementById("popupMask_msg");

    displaySelectBoxes();

    if (refresh_window==1) {
        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';
        
        /*tmp_url = document.location.href;
        tmp_poz = tmp_url.lastIndexOf("#");
        tmp_anchor="";
        if (tmp_poz!=-1) {
            tmp_anchor = tmp_url.substring(tmp_poz);
            tmp_url = tmp_url.substring(0,tmp_poz); 
        }
        
        tmp_poz = tmp_url.lastIndexOf("&");
        if (tmp_poz == tmp_url.length-1) {
            tmp_url = tmp_url.substring(0,tmp_poz-1);   
        }
        
        tmp_poz = tmp_url.lastIndexOf("&ref_popup=");
        var d = new Date();
        if (tmp_poz!=-1) {
            tmp_url = tmp_url.substring(0,tmp_poz);         
            tmp_url += "&ref_popup="+ d.getTime();
        } else {            
            tmp_poz = tmp_url.lastIndexOf("?");
            if (tmp_poz!=-1) {
                tmp_poz2 = tmp_url.lastIndexOf("?ref_popup=");
                if (tmp_poz2!=-1) {
                    tmp_url = tmp_url.substring(0,tmp_poz2);
                    tmp_url += "?ref_popup="+d.getTime();
                } else {
                    if (tmp_poz==tmp_url.length-1)
                        tmp_url += "ref_popup="+d.getTime();    
                    else 
                        tmp_url += "&ref_popup="+d.getTime();   
                }
            } else {
                tmp_url += "?ref_popup="+d.getTime();   
            }
        }*/
            
        //document.location.href = tmp_url+tmp_anchor;
        
        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();
    } else {
        gPopupMask.style.display = 'none';
    }
}

function refresh_win() {
    refresh_window = 1;
}

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

function resize_to(w_width,w_height) {
    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";
}

