// Common JavaScript functions for Union Danoise

// Set colors for cell bgr
var bgr_on = "#add8e6"; // Light blue
var bgr_off = "#ffffff"; // White

// Set browser types
var IE4 = (document.all); // Internet Explorer 4.0 or newer
var NS4 = (document.layers); // Netscape 4.0
var NS6 = ((document.getElementById) && (!document.all)); // Netscape 6.0 or newer or Mozilla Firefox
//var Nav = 0;

// Function for positioning cell bgr image in topmenu when page in frame is loaded
function set_top_img (id, pos_new, path) {
  if ((parent['topmenu']) && (parent['topmenu'].document) && ((IE4) || (NS6) )) {
    if (parent['topmenu'].document.pos == undefined) { // If reload of topmenu
      parent['topmenu'].document.pos = 1;
    }
    if (IE4) {
      var td_obj_new = eval("parent['topmenu'].document.all." + id + "_" + pos_new)
    } else if (NS6) {
      var td_obj_new = eval("parent['topmenu'].document.getElementById('" + id + "_" + pos_new + "')");
    }
    if (td_obj_new) {
      var td_obj_new_style = td_obj_new.style;
      var on_img = "url(" + path + "images/al_on.png)";
      // Turn on cell bgr image in new position
      td_obj_new_style.backgroundImage = on_img;
    }

    // Turn off cell bgr image in current position
    if ((parent['topmenu'].document.pos) // Current position is set
         && (pos_new != parent['topmenu'].document.pos) // Different from new position
       ) { // If new position
      if (IE4) {
        var td_obj_cur = eval("parent['topmenu'].document.all." + id + "_" + parent['topmenu'].document.pos)
      } else if (NS6) {
        var td_obj_cur = eval("parent['topmenu'].document.getElementById('" + id + "_" + parent['topmenu'].document.pos + "')");
      }
    }
    if (td_obj_cur) {
      var td_obj_cur_style = td_obj_cur.style;
      var off_img = "url(" + path + "images/tu_off.png)";
      // Turn off cell bgr image in new position
      td_obj_cur_style.backgroundImage = off_img;
    }
    parent['topmenu'].document.pos = pos_new; // Set previous position to new position
  } // End if all conditions set
} // End set_top_img

// Function for positioning cell bgr image in frame sidemenu when page in frame is loaded
function set_menu_img (id_new, frame_name, path, off_file) {
  var frame_menu = eval("parent['" + frame_name + "']");
  // If side menu frame name exists
  if (frame_menu) {
    if (IE4) {
      var td_obj_new = eval("parent['" + frame_name + "']" + ".document.all['" + id_new + "']");
    } else if (NS6) {
      var td_obj_new = eval("parent['" + frame_name + "']" + ".document.getElementById('" + id_new + "')");
    }
    // If TD object exists
    if (td_obj_new) {
      var td_obj_new_style = td_obj_new.style;
      // If TD style object exists
      if (td_obj_new_style) {
        var on_img = "url(" + path + "images/al_on.png)";
        // Turn on cell bgr in new position
        td_obj_new_style.backgroundImage = on_img;
        // Check if id_cur is defined
        if (eval("parent['" + frame_name + "'].document.id_cur") == undefined) {
          if (frame_name == "leftmenu") {
            // Default to start_page
            eval("parent['" + frame_name + "'].document.id_cur = \"start_page\"");
          } else if (frame_name == "rightmenu") {
            // Default to member_login
            eval("parent['" + frame_name + "'].document.id_cur = \"member_login\"");
          }
        }
        // Get the value of id_cur
        var id_cur_local = eval("parent['" + frame_name + "'].document.id_cur");        
        if (id_new != id_cur_local) { // If new position
          // Get TD object for current TD
          if (IE4) {
            var td_obj_cur = eval("parent['" + frame_name + "']" + ".document.all['" + id_cur_local + "']");
          } else if (NS6) {
            var td_obj_cur = eval("parent['" + frame_name + "']" + ".document.getElementById('" + id_cur_local + "')");
          }
          // Get the style object
          var td_obj_cur_style = td_obj_cur.style;
          // Set the url for the off image
          var off_img = "url(" + path + "images/" + off_file + ")";
          // Turn off cell bgr in previous position
          td_obj_cur_style.backgroundImage = off_img;
          // Set the new current id value
          eval("parent['" + frame_name + "'].document.id_cur = id_new");
        } // End if new position

        // Turn off celle in the opposite frame
        if (frame_name == "leftmenu") {
          var opp_frame_name = "rightmenu";
          off_file = "bl_off.png";
        } else if (frame_name == "rightmenu") {
          var opp_frame_name = "leftmenu";
          off_file = "gr_off.png";
        }
        // If opposite frame exists
        if (eval("parent['" + opp_frame_name + "']")) {
          // Get the value of id_cur in opposite frame
          var opp_id_cur_local = eval("parent['" + opp_frame_name + "'].document.id_cur");        
          // If cur_id is set in opposite frame
          if (opp_id_cur_local ) { 
            // Get TD object for current TD in opposite frame
            if (IE4) {
              var opp_td_obj_cur = eval("parent['" + opp_frame_name + "']" + ".document.all['" + opp_id_cur_local + "']");
            } else if (NS6) {
              var opp_td_obj_cur = eval("parent['" + opp_frame_name + "']" + ".document.getElementById('" + opp_id_cur_local + "')");
            }
            // Get the style object
            var opp_td_obj_cur_style = opp_td_obj_cur.style;
            // Set the url for the off image
            var off_img = "url(" + path + "images/" + off_file + ")";
            // Turn off cell bgr in previous position
            opp_td_obj_cur_style.backgroundImage = off_img;
          } // End if cur_id is set in opposite frame
          // End Turn off celle in the opposite frame
        } // End if opposite frame exists
      } // End if td_obj_style
    } // End if td_obj
  } // End if frame_name
} // End set_menu_img

//Function to display menu section in topmenu frame
function ShowMenu() {
//alert("ShowMenu");
  if ((parent.page) && (parent.page.id_top) && (parent.page.id_top != "")) {
    id_top = parent.page.id_top; // Set the id of the submenu to show
  } else {
    id_top = "start_page";
  }
  // Write style block to display the submenu
  document.writeln('\<style type="text/css"\>#' + id_top + '{display : block;}\<\/style\>');
}//end ShowMenu

//Function for displaying menu section in topmenu frame
function pull_menu (menu_file, id) {
  // If topmenu and different menu section
  if ((parent['topmenu']) && (id != parent['topmenu'].id_top)) {
    parent['topmenu'].location = menu_file; // Set location
  }
} //End pull_menu

// Function for showing details of object in new window incl. search string with id
// Arguments: file (action file), id (object id), w (width of window, h (height of window)
function dt(file,id,w,h) {
  href = file + '?id=' + id;
  detail_window = window.open(href, 'det_window', 'width=' + w + ',height=' + h + ',top=20,left=20,dependent=yes,resizable=yes,scrollbars=yes,titlebar=yes,status=yes');
} // End function dt

// Function for showing enlarged image in new window
function enl_image (title,img_scr,wid,hei) {
  // Open new window
  w = open("", 'image', 'dependent=yes,resizable=yes,scrollbars=no,titlebar=yes,status=no,width=' + wid + ',height=' + hei + ',top=20,left=20');
  w.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>" + title + "<\/title>");
  w.document.write("<\/head><body style=\"margin: 0px;  margin-top: 0px;\" bgcolor=\"#FFFFFF\"> <div align=\"center\"> <img src=\"" + img_scr + "\" border=\"0\" alt=\"" + title + "\" title=\"" + title + "\"></div>");
  w.document.write("<\/body><\/html>");
  w.document.close();
} // End function enl_image

// Function for showing details of object in new window incl. search string with id
// Arguments: file (action file), id (object id), w (width of window, h (height of window)
function dt(file,id,w,h) {
  href = file + '?id=' + id;
  detail_window = window.open(href, 'det_window', 'width=' + w + ',height=' + h + ',top=20,left=20,dependent=yes,resizable=yes,scrollbars=yes,titlebar=yes,status=yes');
  detail_window.focus(); // Bring detail_window to the top
} // End function dt