/**
*   resize;

*   @param string p_TagName tag name;
*   @return null;
*/
function resize(p_TagName,p_fix,p_home) {
//alert('tagname='+p_TagName);
	if (!p_TagName) p_TagName="C0";
	if (!p_fix) p_fix=0;
//alert(p_fix);
	var WinHeight = document.documentElement.clientHeight - (p_fix);
//alert(p_TagName);
try{
	var mc1 = document.getElementById("main");
	var mc2 = document.getElementById("sidebar");
	var mc3 = eval("document.getElementById('"+p_TagName+"_maincontent')");
	var mc4 = document.getElementById("listTB");
	var statusbar = document.getElementById(p_TagName+"_statusbar");
	var statHeight = 0;
	if(typeof(statusbar)=="object") {
		try{
			statHeight = statusbar.clientHeight;
		}catch(e) {}
	}
	mc1.style.height = (WinHeight - 60)+"px";
	mc2.style.height = (WinHeight - 62)+"px";
	mc3.style.height = (WinHeight - 125-statHeight)+"px";
	if(eval("document.getElementById('"+p_TagName+"_mainDiv')")){
		var mc3 = eval("document.getElementById('"+p_TagName+"_mainDiv')");	
      var mc4 = eval("document.getElementById('"+p_TagName+"_showDiv')");
		mc3.style.height = (WinHeight - 125 - statHeight)+"px";
      mc4.style.height = (WinHeight - 125)+"px";
	}
   if(eval("document.getElementById('"+p_TagName+"_mainPgDiv')")){
      var mc3 = eval("document.getElementById('"+p_TagName+"_mainPgDiv')");
      var mc4 = eval("document.getElementById('"+p_TagName+"_showDiv')");
      mc3.style.height = (WinHeight - 155 - statHeight)+"px";
      mc4.style.height = (WinHeight - 125)+"px";
   }
}catch(e){}//alert(e.message)}
	checktab(30,3);
}
function ShowHide() {
	for (i=0;i<ShowHide.arguments.length;i++) {
		var _item = document.getElementById(ShowHide.arguments[i]);
		if (_item.className == (ShowHide.arguments[i]+"_1")) {
			_item.className = ShowHide.arguments[i]+"_2";
		} else {
			_item.className = ShowHide.arguments[i]+"_1";
		}
	}
}

/**
*   change backgroudColor of specify item

*   @param object  _item ;
*   @param integer _bgcolor new backgroundColor;
*   @return null;
*/
function chgBG(_item,_bgcolor) {
	_item.style.backgroundColor = _bgcolor;
}

/**
*   change colors of specify object,when mouse moves out ,it reverts;

*   @param object  _item ;
*   @param integer _color new borderColor;
*   @param integer _bgcolor new backgroundColor;
*   @return null;
*/
function swapStyle(_item,_bdcolor,_bgcolor) {
	var oricolor = _item.style.borderColor;
	var oribgcolor = _item.style.backgroundColor;
	_item.style.borderColor = _bdcolor;
	_item.style.backgroundColor = _bgcolor;

	_item.onmouseout = function() {
		this.style.borderColor = oricolor;
		this.style.backgroundColor = oribgcolor;
	}
}

/**
*  swap images of specify element,when mouse moves out ,it reverts;

*  @param string _image id;
*  @param string newsrc  new image source;
*  @return null;
*/
function swapImage(_image,newsrc) {
	var _img = document.getElementById(_image);
	var oriimg = _img.src;
	_img.src = newsrc;

	_image.onmouseout = function() {
		_img.src = oriimg;
	}
}

/**
*  change class of specify object to "info_actived",when onblur,it reverts;

*  @param object _obj;
*  @return null;
*/
function chgClass(_obj) {
	_obj.className = "info_actived";

	_obj.onblur = function() {
		this.className = "info_normal";
	}
}

/**
*     change borderColor and backgroundColor of specify object;

*     @param object _obj
*     @param integer _bdcolor new borderColor;
*               @param integer _bgcolor new backgroundColor;
*     @return null;
*/
function chgStyle(_obj,_bdcolor,_bgcolor) {
	if (!_bdcolor) _bdcolor = "#008080";
	if (!_bgcolor) _bgcolor = "#FFFFF0";
	var oribdcolor = _obj.style.borderColor;
	var oribgcolor = _obj.style.backgroundColor;
	_obj.style.borderColor = _bdcolor;
	_obj.style.backgroundColor = _bgcolor;

	_obj.onblur = function() {
		this.style.borderColor = oribdcolor;
		this.style.backgroundColor = oribgcolor;
	}
}

/**
*     change image;

*     @param string _image specify image id;
*     @param string _newsrc new image source;
*     @return null;
*/

function chgImage(_image,newsrc) {
	var _img = document.getElementById(_image);
	_img.src = newsrc;
}

/**
*   swap class name of specify element,when mouse moves out ,it reverts;

*   @param object _Item
*   @param string _class class name;
*   @return null;
*/
function swapClassName(_Item,_class) {
	var oriclassName = _Item.className;
	//alert(_Item.className);
	_Item.className = _class;
	//alert(_Item.className);
	_Item.onmouseout = function() {
		_Item.className = oriclassName;
	//alert(_Item.className);
	}
}

/**
*   set class name of specify element;

*   @param string pid specify element's id;
*   @param string val class name;
*   @return null;
*/
function setClassName(pid,val) {
	document.getElementById(pid).className = val;
}

/*document.oncontextmenu = document.onselectstart = function(e){
	e = e || window.event;
	e = e.target == null ? e.srcElement : e.target;
	var tag = e.tagName;
	return tag=="INPUT" || tag=="TEXTAREA"
}*/
function selectOnce(p_type,p_obj,p_id,p_cnt){
	for(var i=1;i<=p_cnt;i++){
		var obj = p_obj+i;
		var obj_id = p_id+i;
		if(p_type==i){
			document.getElementById(obj).className = "o_block";
			document.getElementById(obj_id).className = "now";
		}else{
			document.getElementById(obj).className = "o_none";
			document.getElementById(obj_id).className = "no";
		}
	}
}

/**
*   get child element ids by specify id and tag name;

*   @param string pid specify id;
*   @param string cid specify tag name;
*   @return array id array;
*/
function findElementId(pid, cid) { 
	var a = document.getElementById(pid).getElementsByTagName(cid);
	var pData = Array(a.length);
	for (i=0;i<a.length;i++){ 
		pData[i] = Array(a[i].id);
	 }
	return pData;
	//alert(pData[0]);
}

/**
*   get child element texts array by specify id and tag name;

*   @param string pid specify id;
*   @param string cid specify tag name;
*   @return arrray text array;
*/ 
function findElementText(pid, cid) { 
	var navi = window.navigator.userAgent.toUpperCase();
	var a = document.getElementById(pid).getElementsByTagName(cid);
	var pData = Array(a.length);
	for (i=0;i<a.length;i++){ 
		if (navi.indexOf("FIREFOX")>=1)
			pData[i] = Array(a[i].textContent);
		else
			pData[i] = Array(a[i].innerText);
	 }
	return pData;
	//alert(pData[0]);
} 
var allItem = new Array();
/**
*   check if tabs exceed client edge;

*   @param integer _ext length between tag and client edge;
*   @param integer space length between tags;
*   @return null;
*/
function checktab(_ext,space) {
	var _allItem = new Array();
	var showItem = new Array();
	var hideItem = new Array();
	var hideItemName = new Array();
	var pData = findElementId("maintbul","li");
	var pName =	findElementText("maintbul","li");
	var a = pData.length;
	var b = document.getElementById("main").clientWidth;
	var allwidth = j = k = 0;
	for (i=0;i<a;i++ ) {
		//alert(document.getElementById(pData[i]).clientWidth);
		allwidth = allwidth + space + document.getElementById(pData[i]).clientWidth;
		if ((allwidth+_ext) < b) {
			document.getElementById(pData[i]).style.display = "block";
			showItem[j] = pData[i];
//			alert(showItem[j]);
			j++;
		} else {
			document.getElementById(pData[i]).style.display = "none";
			hideItem[k] = pData[i];
			hideItemName[k] = pName[i];
//			alert(hideItem[k]);
			k++;
		}
	}
	if (hideItem.length>0) {
		//alert(hideItem.length);
		var _hideItem = "";
		for (m=0;m<hideItem.length;m++ ) {
			var tagId = hideItem[m].toString();
			var tagName = hideItemName[m].toString();
			var tagSeq = tagId.slice(1);
//alert(tagId+"--"+tagSeq);
			_hideItem = _hideItem + "'<span class=\"extTab\"><a href=\"javascript:void(null)\" onclick=\"divOs.selectTag("+tagSeq+");hideExtTab();\">"+tagName+"</a><span>&nbsp;&nbsp;<span style=\"text-align:right;\"><a href=\"javascript:void(null)\" onclick=\"divOs.delTag("+tagSeq+");checktab(30,3);\">X</span>',"; 
	document.getElementById("exttab").style.display = "none";
			//_hideItem = _hideItem + "'<a href=\"javascript:void(null)\" onclick=\"divOs.selectTag(5)\">"+hideItemName[m]+"</a>',"; 
		}
		_hideItem=_hideItem.slice(0,-1);
		setTimeout("showExt("+_hideItem+")",200);
		//setTimeout("showExt('test1','test2')",1000);
	} else {
		hideExt();
	}
	_allItem[0]=showItem;
	_allItem[1]=hideItem;
	//alert (showItem + "\n" + hideItem);
	allItem = _allItem;
	//alert(document.documentElement.clientWidth);
}

/**
*   show extential tab;

*   @return null;
*/
function showExt() {
	var _Ext = document.getElementById("exttab");
	var _ExtArrow = document.getElementById("exttabarrow");
	var _ExtVal = "";
	//_Ext.style.display = "block";
	_ExtArrow.style.display = "block";
	_Ext.innerHTML = "";
	for (i=0; i<showExt.arguments.length; i++) {
		var obj = document.createElement("div");
		obj.innerHTML = showExt.arguments[i];
		//_ExtVal = _ExtVal + showExt.arguments[i];
		_Ext.appendChild(obj);
	}
	//setClassName("exttab","showThis");
}

/**
*   hide extential tab and barrow;

*   @return null;
*/
function hideExt() {
	document.getElementById("exttab").style.display = "none";
	document.getElementById("exttabarrow").style.display = "none";
}

/**
*   hide extential tab;

*   @return null;
*/
function hideExtTab() {
	try{
		document.getElementById("exttab").style.display = "none";
	}catch(e){}
}
/**
*   alternate show and hide tab by specify id;

*   @param string tab id;
*   @return null;
*/
function showTab(p_tabDiv){
	if (!p_tabDiv) p_tabDiv = "exttab";
   var tabDiv = document.getElementById(p_tabDiv);
   if (tabDiv.style.display=='none'){
      tabDiv.style.display='block';
   }
   else{
      tabDiv.style.display='none';
   }
}
