/**
 * Display the welcome menu.
 */
function showWelcomeMenu() {	
	changeTopMenu();
	/*
	var topMenuObj = document.getElementById("top_menu");	
	var menu_html = "<ul>";
	var menuLength = gWelcomeMenu.menuName.length;			
	for (var i=0;i<menuLength;i++) {
		var menuItemName = gWelcomeMenu.menuName[i];		
		var menuActionName = gWelcomeMenu.menuActionName[i];
		if (menuActionName == 'addContact.action')
			menuActionName = gUabRootpath+gUabUrlContentpath+"addContact.action";
		var menuNameLang = eval("gMenuNameLang."+menuItemName);		
		
		menu_html += "<li><a href='"+menuActionName+"'>"; 		
		menu_html += "<img src='"+gUrlInfoObj.mainURL+"images/menu_"+menuItemName+"_"+gUrlInfoObj.userLang+".gif' alt='"+menuNameLang+"' border='0' />";
		menu_html += "</a></li>";
	}
	menu_html += "</ul>";				
	topMenuObj.innerHTML = menu_html;
	*/			 
}


/**
 * Change the menu from the return data.
 * 
 */
function changeTopMenu() {	
	var topMenu = document.getElementById("gSaveTopMenu");	
	var returnMenuData = document.getElementById("gReturnMenuData");	
	topMenu.innerHTML = returnMenuData.innerHTML;
		
}
/**
 * Display the listmail menu.
 */
function showListMailMenu() {	
	changeTopMenu();
	menu_init();
	table_init();
}
/**
 * Display the searchMail menu.
 */
function showSearchMailMenu() {	
	changeTopMenu();
	menu_init();
	table_init();
}

/**
 * Display the readMail menu.
 */
function showReadMailMenu() {	
	changeTopMenu();
	menu_init();	
}

/**
 * Display the sendmail menu.
 */
function showSendMailMenu() {
	document.getElementById("welcomeMenu").style.display = "none";
	document.getElementById("sendMailMenu").style.display = "none";
	document.getElementById("listMailMenu").style.display = "";
	document.getElementById("searchMailMenu").style.display = "none";
	document.getElementById("readMailMenu").style.display = "none";
}



/**
 *check if the document download completely.
 **/
function eventManagerKeepTrack() {
	if (document.readyState == "complete"){     
		return;
	} else {
		setTimeout("eventManagerKeepTrack()",1);
	}
}


/**
 *If the Item element has childNodes.
 *@param the element obj.
 *@return if has childnodes return true,else return false;
 */
function ifHasElement(Item) {
	var Node = Item.childNodes;
	for(var j=0;j<Node.length;j++) {	
		if(Node.item(j).nodeType==1)		
			return true;			
	}	
	return false;
}


/**
 *find out the appointed name from oRoot.
 *@param node the ctrl file root.
 *@param name the appointed name.
 *@return domElement if the find out the appointed name the return the element.
 */
 /*
function queryByNodeName(node,nodeName) {
    // is this a text or CDATA node?
		
    if ((node.nodeType == 3 || node.nodeType == 4) && node.parentNode.tagName == nodeName) {
        return node.data;
    }
    var i;
    var returnValue = [];
  
    for (i = 0; i < node.childNodes.length; i++) {
        returnValue.push(queryByNodeName(node.childNodes[i],nodeName));
    }		
  	
    return returnValue.join('');
}
*/
function queryByNodeName(oRoot,name) {
	try{
		var oChildren = oRoot.childNodes;		
		for (var i=0;i<oChildren.length;i++) {
			var oChild = oChildren.item(i);
			if (oChild.nodeName==name)
				return oChild;			
		}
		return false;
	} catch (err) {
		return false;
	}
}

/**
 *find out the Element that attribute value equals the appointed param.
 *@param oRoot the root value.
 *@param actionID the appointed attribute name.
 *@param str the attribute value;
 *@return the according element.
 */
function queryByAttributeValue(oRoot,actionID,str){	
	var oChild = oRoot.childNodes;
	var iCount=oChild.length;
	var iChild;

	for(var i=0;i<iCount;i++){ 
		if (oChild.item(i).nodeType==1) {
			if (oChild.item(i).getAttribute(""+actionID)==str) {							
				return oChild.item(i);
			}
		}
	}
	return false;
}


/**
 * Throughout, whitespace is defined as one of the characters
 *  "\t" TAB \u0009
 *  "\n" LF  \u000A
 *  "\r" CR  \u000D
 *  " "  SPC \u0020
 *
 * This does not use Javascript's "\s" because that includes non-breaking
 * spaces (and also some other characters).
 */


/**
 * Determine whether a node's text content is entirely whitespace.
 *
 * @param nod  A node implementing the |CharacterData| interface (i.e.,
 *             a |Text|, |Comment|, or |CDATASection| node
 * @return     True if all of the text content of |nod| is whitespace,
 *             otherwise false.
 */
function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}


/**
 * Determine if a node should be ignored by the iterator functions.
 *
 * @param nod  An object implementing the DOM1 |Node| interface.
 * @return     true if the node is:
 *                1) A |Text| node that is all whitespace
 *                2) A |Comment| node
 *             and otherwise false.
 */

function is_ignorable( nod ) {
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

/**
 * Version of |previousSibling| that skips nodes that are entirely
 * whitespace or comments.  (Normally |previousSibling| is a property
 * of all DOM nodes that gives the sibling node, the node that is
 * a child of the same parent, that occurs immediately before the
 * reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest previous sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_before( sib )
{
  while ((sib = sib.previousSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |nextSibling| that skips nodes that are entirely
 * whitespace or comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest next sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |lastChild| that skips nodes that are entirely
 * whitespace or comments.  (Normally |lastChild| is a property
 * of all DOM nodes that gives the last of the nodes contained
 * directly in the reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The last child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function last_child( par )
{
  var res=par.lastChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.previousSibling;
  }
  return null;
}

/**
 * Version of |firstChild| that skips nodes that are entirely
 * whitespace and comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The first child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function first_child( par )
{
  var res=par.firstChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.nextSibling;
  }
  return null;
}

/**
 * Version of |data| that doesn't include whitespace at the beginning
 * and end and normalizes all whitespace to a single space.  (Normally
 * |data| is a property of text nodes that gives the text of the node.)
 *
 * @param txt  The text node whose data should be returned
 * @return     A string giving the contents of the text node with
 *             whitespace collapsed.
 */
function data_of( txt )
{
  var data = txt.data;
  // Use ECMA-262 Edition 3 String and RegExp features
  data = data.replace(/[\t\n\r ]+/g, " ");
  if (data.charAt(0) == " ")
    data = data.substring(1, data.length);
  if (data.charAt(data.length - 1) == " ")
    data = data.substring(0, data.length - 1);
  return data;
}

function showMenuConfigObj(menuConfigObj) {
	var topMenuObj = document.getElementById("top_menu");
	var topMenuSonObj = document.getElementById("top_menu_son");
	var menu_html = "<ul>";
	var menuLength = menuConfigObj.menuName.length;					
	for (var i=0;i<menuLength;i++) {
		var menuItemName = menuConfigObj.menuName[i];
		var menuActionName = menuConfigObj.menuActionName[i];
		var sonMenuItemLen = menuItemName.length;
		var titleMenu = menuItemName[0];				
		var titleMenuNameLang = eval("gMenuNameLang."+titleMenu);		
		menu_html += "<li><a href='#"+titleMenu+"Shortcuts'>"; 		
		menu_html += "<img src='"+gUrlInfoObj.mainURL+"images/menu_"+titleMenu+"_"+gUrlInfoObj.userLang+".gif' alt='"+titleMenuNameLang+"' id='"+titleMenu+"Menu' border='0' />";
		menu_html += "</a></li>";
		alert(menu_html);
	}	
	menu_html += "</ul>";//create the "top"					
	topMenuObj.innerHTML = menu_html;
	alert(menu_html);
	var menu_son_html = "";
	
	for (var i=0;i<menuLength;i++) {
		var menuItemName = menuConfigObj.menuName[i];
		var menuActionName = menuConfigObj.menuActionName[i];
		var sonMenuItemLen = menuItemName.length;
		var titleMenu = menuItemName[0];			
		if (sonMenuItemLen == 1) continue; 
		menu_son_html += "<div id='"+titleMenu+"Shortcuts' class='shortcuts'>";
		menu_son_html += "<div><ul class='first'>";
		
		for (var m=2;m<sonMenuItemLen;m++) {			
			var sonMenu = menuItemName[m];
			//alert(menuActionName[m]);
			if (sonMenu == "gFolderListArray") {
				var folderLen = gFolderListArray.length;				
				//if the sonMenu is FolderObj;				
				for (var n=0;n<folderLen;n++) {
					var folderObj = gFolderListArray[n];
					var folderID = folderObj.folderID;
					var folderName = folderObj.folderName;
					var menuSonActionName = 'javascript:void(moveMailBox("'+folderID+'","'+titleMenu+'","listMail"))';
					
					menu_son_html += "<li class='special'><a href='"+menuSonActionName+"'>"+folderName+"</a></li>";
				}
			} else {
				var sonMenuNameLang = eval("gMenuNameLang."+sonMenu);
				menu_son_html += "<li class='special'><a href='"+menuActionName[m]+"'>"+sonMenuNameLang+"</a></li>";	
			}
			
		}
		menu_son_html += "</ul></div></div>"		
	}
		
	topMenuSonObj.innerHTML = menu_son_html;
	//alert(topMenuSonObj.innerHTML);
	//document.write(menu_son_html);
	menu_init();//listmail's menu
	table_init();//listmail's table
}

/**
 * update left navigation.
 */
function updateLeftNav() {
	var url = "folderManage.action";
	var pars = "actionType=periodUpdate";
	var myAjax = new Ajax.Updater('foldMenuDiv', url, {method: 'post', parameters: pars});
}

