// utils.js
// Copyright (c) 2004, LIGOBIB Bibliotekssystem AB
// All Rights Reserved
//
// init_page - Initialize a page when loading..
function init_page() {reload_meny();}
// init_frame - Prepare a frame for showing.
function init_frame() {reload_meny();}

// force a reload of the top menu
function do_reload_meny () {window.parent.frames[1].location.reload(true);}

// reload_meny - Check if we need to reload our menyframe
function reload_meny() {
   var tw = window.parent.frames[1];
   //var tw = window.parent.frames[0];
   var co = get_cookie("refresh_meny");
            
   if (co != null && co == "true") {
      tw.location.reload(true);
      document.cookie = "refresh_meny=false;path=/Application;";
   }
}

// Set focus by ID
function set_focus (sName) {
   var c = document.getElementById(sName);
   c.focus();
   c.select();  
}

// get_cookie - Retrieve a cookie named "sName".
function get_cookie(sName) {
   var aCookie = document.cookie.split("; ");
   for (var i=0; i < aCookie.length; i++) {var aCrumb = aCookie[i].split("=");if (sName == aCrumb[0]) return aCrumb[1];}
   return null;
}

// show_dialog - Show a dialog window, and retrieve return value
function show_dialog(url, caption, message, height, width) {
   s = "dialogHeight:" + height + "pt;dialogWidth:"+width+"pt;help:0;status:0";
   a = "cap="+caption+"&msg="+message; 
   u = url+"?"+a;
   return window.showModalDialog(u,a,s);                               
}

function popup (url, caption, height, width) {
   var s = "resizable=no,height=" + height + ",width=" + width;
   window.open (url, caption, s);
}

function popup_full (url, caption, height, width) {
   s = "resizable=yes,scrollbars=yes,menubar=yes,height=" + height + ",width=" + width;
   window.open (url, caption, s);
}

function popup_xy (url, caption, height, width, xpos, ypos) {
   s = "resizable=no,height=" + height + ",width=" + width + ",left=" + xpos + ",top=" + ypos;
   window.open (url,caption,s);
}

function show_help (help_code) {
   s = "height=400,width=450,left=300,scrollbars=1";
   url = "/Application/help/" + help_code + ".htm";
   window.open (url,null,s);
}

// Delete. Do a postback if true      
function Delete(prompt, postback_function) {
   if (confirm(prompt)) {
      __doPostBack(postback_function, '');
   }
}

function goto_url (url) {document.location = url;}

