/*
 * Copyright (c) Web Arts AG - http://www.web-art.com
 * 
 * Javascript wrapper functions for layernavigation
 * The following javascript files are required to use layernavigation:
 * - menu styles file (e.g. dl_menu_styles.js)
 * - milonic_src.js
 * - mmenudom.js
 * - mmenuns4.js
 * 
 * Created on 2005-11-25 by jvolgmann
 *
 * $Id: dl_layernavigation.js 5115 2008-09-18 16:26:38Z tobi $
 * $HeadURL: http://svn.web-arts.de/svn/www.deutsche-leasing.com/branches/features/20090917_hwupgrade2009/www/sc/js/dl_layernavigation.js $
 * 
 * TODO Create test case for this class
 */

/**
 * Create a new menu with level 1
 * 
 * WARNING: This wrapper method is specific!
 *
 * @return menu instance
 */
function createMenuLevel1(name) {
     with (milonic=new menuname(name)) {
          overflow="scroll";
          style=menuStyle;
          top="offset=-1";
          left="offset=1";
     }
     return milonic;
}

/**
 * Create a new menu with level 2
 * 
 * WARNING: This wrapper method is specific!
 *
 * @return menu instance
 */
function createMenuLevel2(name) {
     with (milonic=new menuname(name)) {
          overflow="scroll";
          style=menuStyle2Lvl;
     }
     return milonic;
}

/**
 * Create a new menu with level 3
 * 
 * WARNING: This wrapper method is specific!
 *
 * @return menu instance
 * @access public
 */
function createMenuLevel3(name) {
     with (milonic=new menuname(name)) {
          style=menuStyle2Lvl;
     }
     return milonic;
}

/**
 * Create a new menu with level 4
 * 
 * WARNING: This wrapper method is specific!
 *
 * @return menu instance
 * @access public
 */
function createMenuLevel4(name) {
     with (milonic=new menuname(name)) {
          style=menuStyle2Lvl;
     }
     return milonic;
}

/**
 * wrapper method to add a sub menu
 *
 * @param menu - menu instance
 * @param name - name of showmenu
 * @param text - displayed text
 * @param url - link url
 * @param starttime - starttime of Zeitsteuerung
 * @param endtime - starttime of Zeitsteuerung
 * @access public
 */
function addSubMenu(menu, name, text, url, target, starttime, endtime) {

     if (starttime && endtime) {
        // visibile if servertime is within start and endtime
        if (starttime < layer_servertime && layer_servertime < endtime) {
           menu.aI(generateSubMenu(name, text, url, target));
        }
     } else {
       // normal menu Item
       menu.aI(generateSubMenu(name, text, url, target));
     }
}

/**
 * generate text entry for menu item
 *
 * @param name - name of submenu to show
 * @param text - text of submenu
 * @param url - link
 * @access private
 */
function generateSubMenu(name, text, url, target) {
    menuItemString = "image=/sc/img/dot0.gif;overimage=/sc/img/dot1.gif";

    menuItemString += ";text=" + text + ";showmenu=" + name + ";";
    
    if (url) {
      menuItemString += "url=" + url;
    }
    
    if(target) {
    	if(target == '_blank') {
	      menuItemString += ";target='blank'";
	   }
    }

    return menuItemString;
}


/**
 * wrapper method to add a menu item
 *
 * @param menu - menu instance
 * @param text - displayed text
 * @param url - link url
 * @param starttime - starttime of Zeitsteuerung
 * @param endtime - starttime of Zeitsteuerung
 * @access public
 */
function addMenuItem(menu, text, url, target, starttime, endtime) {

     if (starttime && endtime) {
        // visibile if servertime is within start and endtime
        // TODO: Prüfen ob das richtig ist. Ich vertue mich jedesmal damit
        if (starttime <= layer_servertime && layer_servertime <= endtime) {
           menu.aI(generateMenuItem(text, url, target));
        }
     } else {
       // normal menu Item
       menu.aI(generateMenuItem(text, url, target));
     }
}

/**
 * generate text entry for menu item
 * 
 * @param text - displayed text
 * @param url - linked url
 * @access private
 */
function generateMenuItem(text, url, target) {
    menuItemString = "image=/sc/img/dot0.gif;overimage=/sc/img/dot1.gif";
    
    

    menuItemString += ";text=" + text + ";";
    
    if (url) {
      menuItemString += "url=" + url;
    }
    
    if(target) {
    	if(target == '_blank') {
	      menuItemString += ";target=_new";
	   }
    }

    return menuItemString;
}

/**
 * Add seperator to given menu
 *
 * @param menu - menu instance
 * @access public
 */
function addSeparator(menu) {
    menu.aI("image=/sc/img/layer_separator.gif;")
}
function damp(menuElementId,title,name) {
	drawMenus();
	var link = document.getElementById(menuElementId).parentNode;
	link.onmouseover = function onmover(event) {popup(title,name);}
	link.onmouseout = function onmout(event) {popdown();}
}
function dimp(menuElementId,title) {
	drawMenus();
	var link = document.getElementById(menuElementId).parentNode;
	link.onmouseover = function onmover(event) {DL_overNextName(this);popup(title,menuElementId);}
	link.onmouseout = function onmout(event) {DL_outNextName(this);popdown();}
}

