/**
 * @file: main.js
 *
 * Description:
 * This file contains the javascript functions for the framework of the SG homepage.
 *
 * Design & Implementation by Lars Toensing
 *
 */

/* ############################################################################
 * ######################### general functions ################################
 * ############################################################################ */

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_GetObj()
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function searchs the object with the given name/id.
 *
 * @param   strName     --> the name/id of the object
 * @param   strDocName  --> the name of the document
 *
 * @return  object
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_GetObj(strName,strDocName) {

  var p,i,obj;
  if(!strDocName)
    strDocName=document;
  if((p=strName.indexOf("?"))>0&&parent.frames.length) {
    strDocName=parent.frames[n.substring(p+1)].document;
    strName=n.substring(0,p);
  }
  if(!(obj=strDocName[strName])&&strDocName.all)
    obj=strDocName.all[strName];
  for (i=0;!obj&&i<strDocName.forms.length;i++)
    obj=strDocName.forms[i][strName];
  for(i=0;!obj&&strDocName.layers&&i<strDocName.layers.length;i++)
    obj=c_GetObj(strName,strDocName.layers[i].document);
  if(!obj && strDocName.getElementById)
    obj=strDocName.getElementById(strName);
  return obj;
}

/* ############################################################################
 * ######################### navigation functions #############################
 * ############################################################################ */

var objTopNaviActive = null;
var strOldClassName = null;
var objMenuActive = null;
var objSubActive = null;
var objDivOpen = null;
var objMenuDivOpen = null;

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnTopNaviClick(objMenu, strName)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function sets the active or passive effect on the main menu, sets 
 * the content of the menu items on the left site and loads the start page for
 * menu into the Data iFrame. 
 *
 * @param   objMenu			--> object that contains the selected main menu 
 * 					 		entry and sets the active effect on it  
 * @param   strDivName		--> string that contains the name of the DIV that 
 *							contains the menu items for the selected main menu
 * @param   strStartPage	--> string that contains the name of the start page
 *							for the selected main menu
 * @param   strMenuID		--> the ID of the first main menu entry
 *
 * @return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnTopNaviClick(objMenu, strDivName, strStartPage, strMenuID) {
	
	if (objMenu != null){
		// the main menu has changed
		var iMenuItems = 8;
		// the number of menu items
		
		if(objMenuActive != null){
			objMenuActive.className ="trMenuItem";
			objMenuActive = null;
		}
		objFirstMenuEntry = c_GetObj(strMenuID);
		if(objFirstMenuEntry){
			objFirstMenuEntry.className ="trMenuActive";
			objMenuActive = objFirstMenuEntry;
			c_OnMenuClick(objFirstMenuEntry, strStartPage);
		}
		if(objTopNaviActive != null){
			if(objTopNaviActive.className == "tdTopNaviActive" || objTopNaviActive.className == "tdTopNaviActiveLast"){
				objTopNaviActive.className = "tdTopNaviItem"; 
			}
			else if(objTopNaviActive.className == "tdTopNaviActiveFirst"){
				objTopNaviActive.className = "tdTopNaviFirst";
			}
			// set the style of the old active menu to 'inactive'
			strID = objTopNaviActive.id;
			// get the ID of the old menu
			iNumber = parseInt(strID.substr(8));
			// get the number of the old menu
			if(iNumber > 1){
				iPrevNumber = iNumber-1;
				objPrevious = c_GetObj("TopNavi_" + iPrevNumber);
				if(objPrevious){
					if(iPrevNumber == 1){
						objPrevious.className = "tdTopNaviFirst";
					}
					else{
						objPrevious.className = "tdTopNaviItem";
					}
					// set the style of the menu that is directly located before the old menu
				}
			}
		}
		if(objDivOpen != null){
			objDivOpen.style.display ="none";
		}
		
	  	strOldClassName = objMenu.className;
	  	strID = objMenu.id;
		// get the ID of the selected menu
		iNumber = parseInt(strID.substr(8));
		// get the number of the selected menu
		if(iNumber == iMenuItems){
			// the last menu has been select
			objMenu.className = "tdTopNaviActiveLast";
		}
		else if (iNumber == 1){
			// the first menu has been selected
			objMenu.className = "tdTopNaviActiveFirst";
		}
		else{
			objMenu.className = "tdTopNaviActive"; 
		}
		// set the style of the selected menu to active
		objTopNaviActive = objMenu;
		if(iNumber > 1){
			iPrevNumber = iNumber-1;
			objPrevious = c_GetObj("TopNavi_" + iPrevNumber);
			if(objPrevious){
				if(iPrevNumber == 1){
					objPrevious.className = "tdTopNaviPreviousFirst";
				}
				else{
					objPrevious.className = "tdTopNaviPrevious";
				}
				// set the style of the menu that is directly located before the selected menu
			}
		}
		for(var i=1; i<iNumber; i++){
			objLine = c_GetObj("TopNaviLine_" + i);
			if(objLine){
				objLine.className = "tdTopNaviLineActive";
				// set the style for the navigation line before the selected menu
			}
		}
		objLine = c_GetObj("TopNaviLine_" + iNumber);
		if(objLine){
			if(iNumber == iMenuItems)
				objLine.className = "tdTopNaviLineSelectedLast";
			else
				objLine.className = "tdTopNaviLineSelected";
			// set the style for the navigation line of the selected menu
		}
		for(var i=iNumber+1; i<=iMenuItems; i++){
			objLine = c_GetObj("TopNaviLine_" + i);
			if(objLine){
				if(i == iMenuItems)
					objLine.className = "tdTopNaviLineLast";
				else
					objLine.className = "tdTopNaviLine";
				// set the style for the navigation line after the selected menu
			}
		}
		objDiv = c_GetObj(strDivName);
		if(objDiv){
			objDiv.style.display="inline";
			objDivOpen = objDiv;
			// set the div for the menu to inline
		}
		
	}
}


/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnTopNaviOver(objMenu)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the active / "mouse over" effect of the selected main 
 * menu.
 *
 * @param   objMenu	--> object that contains the selected (active) main menu 
 *                      entry and sets the mouse over effect on it
 *
 * @return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 **/

function c_OnTopNaviOver(objMenuOver){
	if (objMenuOver != null && objMenuOver != objTopNaviActive){
		strOldClassName = objMenuOver.className;
		if(objMenuOver.className == "tdTopNaviItem"){
			objMenuOver.className = "tdTopNaviOver";
		}
		else if(objMenuOver.className == "tdTopNaviFirst"){
			objMenuOver.className = "tdTopNaviOverFirst";
		}
		else if(objMenuOver.className == "tdTopNaviPreviuosFirst"){
			objMenuOver.className = "tdTopNaviOverPreviousFirst";
		}
		else if(objMenuOver.className == "tdTopNaviPrevious"){
			objMenuOver.className = "tdTopNaviOverPrevious";
		}	
	}		
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnTopNaviOut(objMenu)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the passive / "mouse out" effect when another main menu 
 * entry is activated.
 *
 * @param   objMenu	--> object that sets the mouse over (active) or the mouse 
 *							out (passive) effect on a main menu entry
 *
 * @return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 **/


function c_OnTopNaviOut(objMenu) {
	if (objMenu != null && objMenu != objTopNaviActive && strOldClassName){
		objMenu.className = strOldClassName;
	}
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnMenuClick(objMenu, strName)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the active and passive effect on the menu and sets the
 * content of the iFrame window. 
 *
 * @param   objMenu	--> object that contains the selected (active) menu	entry 
 * @param   strName	--> string that contains the name for the PHP-file that 
 *						contains the data for the menu
 *
 * @param return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnMenuClick(objMenu, strName, strMoziallaPath) {
	
	if (objMenu != null){
		// the main menu has changed
		if(objMenuActive != null){
			// a menu was selected before
			objMenuActive.className	="trMenuItem";
		}

		var objFrame = c_GetObj("Data");

		if(objFrame){
			// Mozilla 1.4 interprets the src attribute instead of the location.href attribute like IE
			if (objFrame.location == null || objFrame.location == "undefined"){
				if(strMoziallaPath)
					objFrame.src = strMoziallaPath;
				else
					objFrame.src = strName;
		 	}
		 	else{
				objFrame.location.href  = strName;
			}
		}
		
	  	objMenu.className = "trMenuActive";		
		objMenuActive = objMenu;
		
		if (objSubActive != null){
			objSubActive.className ="trSubMenuItem";
			objSubActive = null;
		}
	
		strMainID = objMenu.id;
		// get the ID for the main menu
		objMainDiv = c_GetObj("Div_" + strMainID);
		objFirstSub = c_GetObj(strMainID + "_1");
		// look for sub menus
		if(objMainDiv){ 
			// sub menus were found
			if(objMainDiv != objDivOpen){
				if(objMenuDivOpen)
					objMenuDivOpen.style.display = "none";
					// hide the previous selected sub menu
				objMainDiv.style.display = "inline";
				// set the div that contains the sub menus inline
				objMenuDivOpen = objMainDiv;
				if(objFirstSub && objSubActive == null){
					objFirstSub.className = "trSubMenuActive";
					objSubActive = objFirstSub;
				}
			}	
		}
		else{
			if(objMenuDivOpen)
				objMenuDivOpen.style.display = "none";
			objMenuDivOpen = null;
		}
		
	}	
	
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnMenuOver(objMenu)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the active / "mouse over" effect of the selected menu.
 *
 * @param   objMenu	--> the menu object
 * 
 * @return void
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnMenuOver(objMenu) {
	objMenu.className = "trMenuActive";
}


/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnMenuOut(objMenu)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the passive / "mouse out" effect when another menu entry
 * is activated.
 *
 * @param   objMenu	--> the menu object
 * 
 * @return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnMenuOut(objMenu) {
	if (objMenu != null && (objMenu != objMenuActive)) {
		objMenu.className = "trMenuItem";
	}
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnLoadFrame(objMenu, strName)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function sets the content of the iFrame window. 
 *
 * @param   strName	--> string that contains the name for the PHP-file that 
 *						contains the data for the menu
 *
 * @param return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnLoadFrame(strName, strMoziallaPath) {
	
	var objFrame = parent.c_GetObj("Data");

	if(objFrame){
		// Mozilla 1.4 interprets the src attribute instead of the location.href attribute like IE
		if (objFrame.location == null || objFrame.location == "undefined"){
			objFrame.src = strMoziallaPath;
	 	}
	 	else{
			objFrame.location.href  = strName;
		}
	}	
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnLoadIFrame(strName)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function loads the file with the given name into the data iFrame. 
 * 
 * @param   strName	--> string that contains the text (a php file) for the 
 *						iFrame source
 *
 * @param return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnLoadIFrame(strName, strNumber) {
	
	if (strName && strNumber){		
		if(strNumber.length == 1){
			// it is a main menu
			objMenu = c_GetObj("Main_" + strNumber);
			// get the appropriate menu 
			if (objMenu) {
				c_OnMainClick(objMenu, strName);
			}
		}
		else{
			// it is a sub menu
			objSubMenu = c_GetObj("Main_" + strNumber);
			objMenu = c_GetObj("Main_" + strNumber.substr(0,1));
			// get the appropriate menu 
			if (objSubMenu && objMenu) {
				c_OnMainClick(objMenu, strName);
				c_OnSubClick(objSubMenu, strName);
			}
		}
	}
	
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnLoadIFrame(strName)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function resets some div sizes, if the mozilla browser is used. 
 *
 * @param return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_CheckDivSize(){

	if (navigator.appName == "Netscape"){
		// the IE is not used
		var objDivTopNavi = c_GetObj("TopNavi");
		if(objDivTopNavi){
			objDivTopNavi.style.width = objDivTopNavi.offsetWidth+2;
		}
		var objDivMenu = c_GetObj("MenuArea");
		if(objDivMenu){
			objDivMenu.style.height = objDivMenu.offsetHeight+2;
		}	
 	}
	
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnSubClick(objMenu, strName)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the active and passive effect on the submenu and sets 
 * the content of the "text iframe" window. 
 *
 * @param   objMenu	--> object that contains the selected (active) submenu 
 *											entry 
 * @param   strName	--> string that contains the text (a php file) of the 
 *											selected submenu entry
 *
 * @param return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnSubClick(objMenu, strName) {
	
	if (objMenu != null){
		if (objSubActive != objMenu){
			// the sub menu has changed
			if(objSubActive != null)
				// a sub menu was selected
				objSubActive.className ="trSubMenuItem";
		
			objMenu.className = "trSubMenuActive";
			objSubActive = objMenu;
			
			// set the iframe window
			
			var objFrame = c_GetObj("Data");

			if(objFrame){
				// Mozilla 1.4 interprets the src attribute instead of the location.href attribute like IE
				if (objFrame.location == null || objFrame.location == "undefined"){
					objFrame.src = strName;
			 	}
			 	else{
					objFrame.location.href  = strName;
				}
			}
		}	
	}
	
}

/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnSubOver(objMenu)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the active / "mouse over" effect of the selected submenu
 *
 * @param   objMenu 	--> object that contains the selected (active) mainmenu entry and sets the mouse over effect on it
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnSubOver(objMenu) {
	objMenu.className = "trSubMenuActive";
}


/**
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  Function: c_OnSubOut(objMenu)
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * This function shows the passive / "mouse out" effect when another submenu 
 * entry is activated
 *
 * @param   objMenu 		--> object that sets the mouse out (passive) effect on 
 * a selected submenu entry
 *
 * @return void
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

function c_OnSubOut(objMenu) {
	if (objMenu != null && (objMenu != objSubActive)) {
		objMenu.className = "trSubMenuItem";
	}
}
