﻿// JavaScript Document
var oSysMenus = []
var oFloater = [];

function clearFloater(){
	//var length = oSysWins.length > oSysMenus.length ? oSysWins.length : oSysMenus.length;
	var length = oSysMenus.length;
	for(var i = 0; i < length; i++){
		//if(oSysWins[i] != undefined) oFloater.push(oSysWins[i]);
		//if(oSysMenus[i] != undefined) oFloater.push(oSysMenus[i]);
		oFloater.push(oSysMenus[i]);
	}
	for(var i = 0; i < oFloater.length; i++){
		oFloater[i].hide();
	}
}
function fixbug(){
	for(var i = 0; i < $('header_menu').getElementsByTagName('a').length; i++){
		$('header_menu').getElementsByTagName('a')[i].className = $('header_menu').getElementsByTagName('a')[i].className.split("_")[0] + "_n";
	}
	clearFloater();
}

var menu_styles = {
						menu:"sysmenuBar",
						menu_frame:"sysmenuBarTable",
						iconwidth:"iconwidth",
						defaultwidth:"defaultwidth",
						textminiwidth:"textMiniWidth"
					};
					
function SysMenu(menuarr,styles){
	this.menuarr = menuarr == null ? [] : menuarr;
	this.styles = styles;
	
	var oMenu;
	var oMenu_table;
	var oMenu_tbody;
	var oMenu_tr = [];
	var oMenu_td = [];
	var oMenu_a = [];
	
	var superthis;
	
	this.createToObj = function(obj){
		oMenu = document.createElement('div');
		oMenu_table = document.createElement('table');
		oMenu_table.cellPadding = 0;
		oMenu_table.cellSpacing = 2;
		oMenu_table.border = 0;
		if(CommonFunctions._isIE) oMenu_tbody = document.createElement('tbody');

		oMenu.className = this.styles.menu;
		oMenu.id = this.menuarr[0].id.split("_")[0];
		oMenu_table.className = this.styles.menu_frame;
		
		
		if(this.menuarr != []){
			for(var i = 0; i < this.menuarr.length; i++){
				oMenu_tr[i] = document.createElement('tr');
				oMenu_td[i] = document.createElement('td');
				oMenu_a[i] = document.createElement('a');
				
				oMenu_a[i].innerHTML = this.menuarr[i].name;
				oMenu_a[i].title = this.menuarr[i].title;
				oMenu_a[i].href = this.menuarr[i].href;
				//oMenu_a[i].href = "javascript:void(0)";
				//oMenu_a[i].href = this.menuarr[i].href == "" ? "javascript:void(0)" : this.menuarr[i].href;
				oMenu_a[i].sId = i;
				oMenu_a[i].onclick =  function(){	
					//window.location.href = superthis.menuarr[this.sId].href;
					if(superthis.menuarr[this.sId].onclick != null) superthis.menuarr[this.sId].onclick();	
					superthis.hide();
				}
				oMenu_td[i].appendChild(oMenu_a[i]);
				oMenu_tr[i].appendChild(oMenu_td[i]);
				if(CommonFunctions._isIE) oMenu_tbody.appendChild(oMenu_tr[i]); else oMenu_table.appendChild(oMenu_tr[i]);
				oMenu_a[i].className = this.menuarr[i].classname + " " + (this.menuarr[i].name == "" ? this.styles.iconwidth : this.styles.defaultwidth);
				if(this.menuarr[i].classname == "") oMenu_a[i].style.textIndent = 0;
			}
			
		}
		
		if(CommonFunctions._isIE) oMenu_table.appendChild(oMenu_tbody);
		oMenu.appendChild(oMenu_table);
		
		obj.appendChild(oMenu);
		
		var maxwidth = 0;
		for(var i = 0; i < this.menuarr.length; i++){
			if(oMenu_a[i].innerHTML != ""){
				for(var j = i + 1; j < this.menuarr.length - 1; j++){
					if(oMenu_a[i].offsetWidth > oMenu_a[j].offsetWidth){
						maxwidth = oMenu_a[i].offsetWidth;
					}else{
						maxwidth = oMenu_a[j].offsetWidth;
					}
				}
			}
			
		}
		if(maxwidth != 0){
			for(var i = 0; i < this.menuarr.length; i++){
				if(maxwidth < 100){
					oMenu_a[i].className = oMenu_a[i].className.split(" ")[0] + " " + this.styles.textminiwidth;
				}
			}
		}
		superthis = this;
		this.hide();
		oSysMenus.push(this);
	}
	
	this.show = function(o){
		oParent = o;
		o.className = o.className.split("_")[0] + "_a";
		for(var i = 0; i < oSysMenus.length; i++){
			if(oSysMenus[i].returnObject() != oMenu){
				oSysMenus[i].hide();
			}
		}
		oMenu.style.top = CommonFunctions.getAbsolutePoint(o).t + o.offsetHeight + "px";
		oMenu.style.left = CommonFunctions.getAbsolutePoint(o).l + "px";

		oMenu.style.display == "none" ? oMenu.style.display = "" : oMenu.style.display = "none";
		var interval = 0;
		oMenu.onmouseover = function(){
			clearTimeout(interval);
		}
		oMenu.onmouseout = function(){
			interval = setTimeout(this.hide,500);
		}.bind(this)
	}
	this.hide = function(){
		oMenu.style.display = "none";
		$("header_menu_" + oMenu.id.split("m")[1]).className = $("header_menu_" + oMenu.id.split("m")[1]).className.split("_")[0] + "_n";
	}
	
	this.returnObject = function(){
		return oMenu;
	}
}