﻿	var nav_tab_active_class = 'active';
	var nav_tab_selected_class = 'selected';
	var nav_tab_normal_class = 'normal';
	var nav_reset_timer_id;
	var nav_reset_flag=false;
	var nav_reset_time = 1000;

    function setinfo(message) {
        var el = document.getElementById('divinfo');
        el.innerHTML = message;
    }
 
	/*
	 * hides a dom element by setting its display css attribute to 'none';
	 */
	function nav_hidebyid(element_id) {
		var el = document.getElementById(element_id);
		return nav_hide(el);
	}
	
	/*
	 * hides a dom element by setting its display css attribute to 'none';
	 */
	function nav_hide(el) {
		if (el) {
			if (el.style) {
				el.style.display='none';
			} else {
				//el.display='none';
			}
			return true;
		} else {
			return false;
		}
	}
	
	/*
	 * shows a dom element by setting its display css attribute to 'block';
	 */
	function nav_showbyid(element_id) {
		var el = document.getElementById(element_id);
		return nav_show(el);
	}
	
	/*
	 * shows a dom element by setting its display css attribute to 'block';
	 */
	 function nav_show(el) {
	 	if (el) {
			if (el.style) {
				el.style.display='block';
			} else {
				//el.display='block';
			}
			return true;
		} else {
			return false;
		}
	 }
	
	/*
	 * sets the css class of a dom element
	 */
	function nav_set_class(element_id, cls) {
		var element = document.getElementById(element_id);
		if (element) {
			element.className = cls;
			return true;
		} else {
			return false;
		}
	}
	
	/*
	 * returns the css class of a dom element
	 */
	function nav_get_class(element_id) {
		var el = document.getElementById(element_id);
		if (el) {
			return el.className;
		} else {
			return '';
		}
	}
	
		
	/*
	 * returns the currently selected navigation tab element
	 */
	var nav_selected_tab_id = '';
	var nav_selected_tab_iscurrentpage = false;
	function nav_selected_tab() {
		var el;
		if (nav_selected_tab_id) {
			el=document.getElementById(nav_selected_tab_id);
		}
		return el;
	}
	
	
	/*
	 * sets the selected tab id
	 */
	function nav_set_selected_tab(element_id, tab_is_current_page) {
	    var element;
	    element = document.getElementById(element_id);
	    if (element) {
		    nav_selected_tab_id = element_id;
		    nav_set_selected_menu(element.getAttribute('menu_id'));
		    nav_selected_tab_iscurrentpage = (tab_is_current_page || false);
		}
	}
	
	
	/*
	 * displays the selected tab and menu
	 */
	function nav_reset_tabs() {
		//if (nav_reset_menu()) {
		    
			return nav_set_active_tab(nav_selected_tab_id);
		//} else {
		//	return false;
		//}
	}
	
	
	/*
	 * returns the current active navigation tab element
	 */
	var nav_active_tab_id = '';
	function nav_active_tab() {
		var el;
		if (nav_active_tab_id) {
			el=document.getElementById(nav_active_tab_id);
		}
		return el;
	}
	
	
	/*
	 * sets the current active navigation tab element
	 */
	function nav_set_active_tab(tab_id) {
		nav_cancelreset();
		
		// if element_id same as the current tab's element_id then don't do anything
		if (tab_id == nav_active_tab_id) {return true;}
				
		// get current active tab and new tab
		var active_tab = nav_active_tab();
		var new_tab = document.getElementById(tab_id);
				
		// if found new tab
		if (new_tab) {
			
			// try to de-activate the previously active tab
			if (active_tab) {
				if (nav_selected_tab_id == nav_active_tab_id) {
					nav_set_class(active_tab.getAttribute('link_id'),nav_tab_selected_class);	
				} else {
					nav_set_class(active_tab.getAttribute('link_id'),nav_tab_normal_class);
				}
			}
			
			nav_set_class(new_tab.getAttribute('link_id'), nav_tab_active_class);
			nav_set_active_menu(new_tab.getAttribute('menu_id'));
			nav_active_tab_id = tab_id;
						
			return true;
		} else {
			return false;
		}
	}
	
	
	/*
	 * returns the current selected menu element
	 */
	var nav_selected_menu_id = '';
	function nav_selected_menu() {
		var el;
		if (nav_selected_menu_id) {
			el = document.getElementById(nav_selected_menu_id);
		}
		return el;
	}
	
	
	/*
	 * sets the selected menu id
	 */
	function nav_set_selected_menu(element_id) {
		nav_selected_menu_id = element_id;
		nav_set_active_menu(element_id);
	}
	
	
	/*
	 * displays the selected menu
	 */
	function nav_reset_menu() {
		return nav_set_active_menu(nav_selected_menu_id);
	}
	
	
	/*
	 * returns the current active menu element
	 */
	var nav_active_menu_id = '';
	function nav_active_menu() {
		var el;
		if (nav_active_menu_id) {
			el = document.getElementById(nav_active_menu_id);
		}
		return el;
	}
	
	
	/*
	 * sets the current active menu element by its element id
	 */
	function nav_set_active_menu(element_id) { 
	    if (element_id == nav_active_menu_id) {return true;}
		var active_menu = nav_active_menu();
		var new_menu = document.getElementById(element_id);
		
		if (new_menu) {
			if (nav_show(new_menu)){
				if (active_menu){nav_hide(active_menu);} else {}
				nav_active_menu_id = element_id;
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}


	function nav_reset() {
		if (nav_reset_timer_id) {return;}
		if (nav_active_tab_id!=nav_selected_tab_id) {
			nav_reset_flag=true;
			nav_reset_timer_id = setTimeout('nav_reset_callback()',nav_reset_time);
		}
	}
	
	function nav_reset_callback() {
		if (nav_reset_timer_id){
			clearTimeout(nav_reset_timer_id);
			nav_reset_timer_id = null;
		}
		
		if (nav_reset_flag)	{
			nav_reset_flag=false;
			nav_reset_tabs();
		}
	}
	
	function nav_cancelreset() {
		if (nav_reset_timer_id){
			clearTimeout(nav_reset_timer_id);
			nav_reset_timer_id = null;
		}
		
		if (nav_reset_flag){nav_reset_flag=false;}
	}
	
	function nav_menu_mouseover(e) {
		nav_cancelreset();
	}
	
	function nav_menu_mouseout(e) {
		// get event reference 
		if (!e) var e = window.event;
		if (!e) return;
		
		// get target of mouse out
		var event_target = (window.event) ? e.srcElement : e.target;
		
		// if not mouseout of an LI element then quit
		//if (event_target.nodeName != 'UL' && event_target.nodeName != 'DIV') return;
		if (event_target.nodeName == 'A') return;
		
		nav_reset();
	}
	
	
	/*
	 * tab mouse out event
	 */
	function nav_tab_mouseout(e){
		// get event reference 
		if (!e) var e = window.event;
		if (!e) return;
		
		// get target of mouse out
		var event_target = (window.event) ? e.srcElement : e.target;
		
		// if not mouseout of an LI element then quit
		if (event_target.nodeName != 'LI' && event_target.nodeName != 'A') return;
		
		// Mouseout took place when mouse actually left the tab LI element
		// Handle event
		nav_reset();
	}
	
	/*
	 * tab mouseover event
	 */
	function nav_tab_mouseover(e) {
		// get event reference 
		
		if (!e) var e = window.event;
		if (!e) return;
		
		// get target of mouse over
		var event_target = (window.event) ? e.srcElement : e.target;
			
				
		// Mouseover took place when mouse actually entered the tab LI element
		// Handle event
		nav_set_active_tab(event_target.getAttribute('tab_id'), event_target.menu_id);
	}
	
	/*
	 * document mouseover event
	 */
	function nav_document_mouseover(e) {
		// get event reference 
		
		if (!e) var e = window.event;
		
		// get target of mouse over
		var event_target = (window.event) ? e.srcElement : e.target;
		
		// if not mouseover of the BODY element then quit
		if (event_target.nodeName != 'BODY') return;
		
		
		nav_reset();
		
	}
	
	function nav_tab_init(tab_id) {
	    var el = document.getElementById(tab_id);
	    if (el) {
	        el.onmouseover = nav_tab_mouseover;
	        el.onmouseout = nav_tab_mouseout;
	    }
	}
	function nav_menu_init(menu_id) {
	    var el = document.getElementById(menu_id);
	    if (el) {
	        el.onmouseover = nav_menu_mouseover;
	        el.onmouseout = nav_menu_mouseout;
	    }
	}





