function resetList(){
document.all.contentList.style.height=bheight-27-2;
}
function resetBriefing(){
document.all.briefing.style.left=bwidth-175;
document.all.briefing.style.height=bheight-27-2;
document.all.briefing.style.top=28;
}
function initDiv(){
bwidth=document.body.offsetWidth;
bheight=document.body.offsetHeight;
resetList();
}

/*打开新窗口调用以下函数-*/
function OpenSmallWin(url)
{
	OpenWin(url,'', '350', '600');
}
function OpenBigWin(url)
{
	OpenWin(url,'', '600', '800');
}
function OpenWinASSiz(url,height,width)
{
	OpenWin(url,'', height, width);
}
/*-------*/

function OpenViewWorkFlow(url)
{
   OpenModalDialog(url, "500","800");
}
function Get_Center(size, side)
{
	self.y_center=(parseInt(screen.height/2));
	self.x_center=(parseInt(screen.width/2));
	center = eval('self.'+side+'_center-('+size+'/2);');
	return(parseInt(center));
}
function OpenPrintWin(url, name, height, width)
{
	var left = Get_Center(width,'x');	
	var top = Get_Center(height,'y');
	if (top > 30)
	{
		top = top - 30;
	}
	window.open(url,name,"height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",scrollbars=no,toolbar=no,menubar=yes,location=no,resizable=yes");
}

function OpenEditWin(url)
{
	var height = 700;
	var width = 1000;
	var name = "EditForm";
	OpenWin(url, name, height, width);	
}
function OpenWin(url, name, height, width)
{
	var left = Get_Center(width,'x');	
	var top = Get_Center(height,'y');
	if (top > 30)
	{
		top = top - 30;
	}
	window.open(url,name,"height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",scrollbars=no,toolbar=no,menubar=no,location=no,resizable=no");
}
function OpenNewWin(url, name, height, width)
{
	var left = Get_Center(width,'x');	
	var top = Get_Center(height,'y');
	if (top > 30)
	{
		top = top - 30;
	}
	window.open(url,name,"height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",scrollbars=no,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes");
}

function OpenModalDialog(url, height, width)
{
   window.showModalDialog(url + "&rdm=" + Math.random(),document,"dialogHeight: " + height + "px; dialogWidth: " + width + "px;edge: Raised; center: Yes; help: No; resizable: No; scrollbars:No");
}

function OpenDialog(url, height, width)
{
	window.showModalDialog(url+ "&rdm=" + Math.random(),document,"dialogHeight: " + height + "px; dialogWidth: " + width + "px;edge: Raised; center: Yes; help: No; resizable: No; scrollbars:No");
}

function OpenSelectEmpAndDepDialog(urlPrex,IdCtr,EmployeeNameCtr,DeptIDCtr,DeptNameCtr,DeptNo)
{
	var url = urlPrex + "Common/Selector/SelectUser.aspx?IdCtr=" + IdCtr + "&EmployeeNameCtr=" + EmployeeNameCtr + "&DeptIDCtr=" + DeptIDCtr +"&DeptNameCtr=" + DeptNameCtr + "&DeptNo=" + DeptNo;
	OpenDialog(url, "480", "600")
}

function OpenSelectEmpDialog(urlPrex,IdCtr,EmployeeNameCtr,EmployeeNoCtr,DeptNo)
{
	var url = urlPrex + "Common/Selector/SelectUser.aspx?IdCtr=" + IdCtr + "&EmployeeNameCtr=" + EmployeeNameCtr + "&EmployeeNoCtr=" + EmployeeNoCtr + "&DeptNo=" + DeptNo;
	OpenDialog(url, "480", "600")
}

function OpenSelectMultiEmpDialog(urlPrex,IdCtr,EmployeeNameCtr,DeptNo,mancount,idvalue,namevalue)
{
	var url = urlPrex+"Common/Selector/SelectMultiUser.aspx?IdCtr=" + IdCtr + "&EmployeeNameCtr=" + EmployeeNameCtr + "&DeptNo=" + DeptNo+"&mancount="+mancount+"&idvalue="+escape(idvalue)+"&namevalue="+escape(namevalue);
	OpenDialog(url, "480", "600")
}

function OpenSelectRoleDialog(urlPrex,IdCtr,NameCtr)
{
	var url=urlPrex + "Common/Selector/SelectRole.aspx?IdCtr=" + IdCtr + "&NameCtr=" + NameCtr ;
	OpenDialog(url, "480", "600")
}


function CheckAll(check)
{
	var e = document.forms[0].elements;
	var l = e.length;
	var o;
	for(var i = 0; i < l; i++)
	{
		o = e[i];
		if (o.type == "checkbox")
		{
			o.checked = check;
		}
	}
}
//单选框必须选择一条记录。

function CheckOne(stralert,varform)
{
	var j=0;
	for ( var i =0; i<varform.elements.length;i++)
	{
		var e = varform.elements[i];
		if(e.type=="radio"&&e.checked==true)
		{
			j++
		}
	}
	if(j == 0)
	{
		alert(stralert);	
		return false; 
	}
}

function ValidateLength(oSrc, args)
{
	args.IsValid = (GetByteLength(args.Value) <= oSrc["limit"]); 
}
function GetByteLength(str)
{
	
	var iLen = 0;
	for(i = 0; i < str.length; i ++)
	{
		if(str.charCodeAt(i) >= 8481 && str.charCodeAt(i) <= 63486)
		{
			iLen += 2;
		}
		else
		{
			iLen += 1;
		}
	}
	return iLen;
}
function Trim(str)
{
    str = str.replace(/\ /g, '');
    return str;
}


//使用：onload ="initEnter2Tab()" form标记加上 <form name="frm" type="enter2tab">...</form>

var isCycle = false; //当光标到最后一个元素的时候，是否循环光标焦点，

var iCurrent = -1;
var frmName = "0"//input_form
//
function enterToTab()  //网页里按回车时焦点的转移
{
  var e = document.activeElement;
  if(e == null) return false;
  //获得当前表单的名字

  for(i=0;i<document.forms.length;i++){  
 for(var el in document.forms[i].elements){
  if(e.UniqueID == el.UniqueID){
   frmName = document.forms[i].name
  }    
 } 
  }
  if(window.event.keyCode == 13)
  {  
   switch(e.tagName)//标签类型
 {
     case "INPUT":
   handleInput(e)
   break;
     case "SELECT":
   handleSelect(e)   
   break;  
     case "TEXTAREA":
   handleTextarea(e)
   break;   
         default:  
    //window.status = "未知的标签名称:"+e.tagName+"，不能移动焦点！"
    }  
  }// end if
}


//处理input 标签类型
function handleInput(e)
{
   switch(e.type)
 {
     case "text":
  case "password":
  case "checkbox":
  case "radio":
  case "file":
   moveFocusToNextElement(e)
   break; 
 // case "submit"://处理有提交按钮的情况
  case "button":
   if(isHandleSubmit(e)){
    handleSubmit(e)
    focusOnNextElement(document.forms[frmName].elements,iCurrent-1)
    break;
   }
   moveFocusToNextElement(e)
   break;            
         default:  
        
    }
}
//处理select 标签类型
function handleSelect(e)
{
 moveFocusToNextElement(e)
}
//处理textarea 标签类型
function handleTextarea(e)
{
 //moveFocusToNextElement(e)
}
//移动到下一个元素

function moveFocusToNextElement(e)
{
  var oE = document.forms[frmName].elements, iCurentPos=-1;
  for(var i=0; i<oE.length; i++)
  {
    if(oE[i] == e) iCurentPos = i;
    if(iCurentPos>-1 && iCurentPos+1<oE.length)
    {
    //把焦点设置到下一个可用的元素上  
  focusOnNextElement(oE,iCurentPos)
    }
  }
}
//下一个可用元素得到焦点 n 元素的位置

function focusOnNextElement(oElements,iIndex)
{
	var oE = oElements
	var oldIndex = iIndex 
	while(oE[iIndex+1].type =="hidden" 
		|| oE[iIndex+1].disabled || oE[iIndex+1].tagName == "FIELDSET" || oE[iIndex+1].style.display == "none")
	{ 
		/*window.status += "e.name = "+oE[iIndex+1].name
		window.status += ";e.type = "+oE[iIndex+1].type
		window.status += ";e.disabled = "+oE[iIndex+1].disabled
		window.status += ";e.readOnly = "+oE[iIndex+1].readOnly+"."*/
		iIndex++;
		if(iIndex+1 == oE.length)
		{
		
			if(isCycle)
			{//设置焦点在第一元素
				focusOnNextElement(oE,-1);
			} 
			return;
		}
	}//end while
	iCurrent = iIndex+1
	oE[iCurrent].focus();
        //window.event.keyCode    = 0;
    window.event.returnValue= false; 
    return;
}
function focusFirstElement(oElements,iIndex)
{
	var oE = oElements
	var oldIndex = iIndex 
	while(oE[iIndex+1].type =="hidden" 
		|| oE[iIndex+1].tagName == "SELECT"
		|| oE[iIndex+1].readOnly == true
		|| oE[iIndex+1].disabled || oE[iIndex+1].tagName == "FIELDSET" || oE[iIndex+1].style.display == "none")
	{ 
		/*window.status += "e.name = "+oE[iIndex+1].name
		window.status += ";e.type = "+oE[iIndex+1].type
		window.status += ";e.disabled = "+oE[iIndex+1].disabled
		window.status += ";e.readOnly = "+oE[iIndex+1].readOnly+"."*/
		iIndex++;
		if(iIndex+1 == oE.length)
		{
		
			if(isCycle)
			{//设置焦点在第一元素
				focusFirstElement(oE,-1);
			} 
			return;
		}
	}//end while
	iCurrent = iIndex+1
	oE[iCurrent].focus();
        //window.event.keyCode    = 0;
    window.event.returnValue= false; 
    return;
}

//处理当前元素
function handleSubmit(element)
{
 element.click()
 return; 
}
//判断是否处理提交
function isHandleSubmit(element)
{
 var ret = false;
 if(element !=null && (element.id.toUpperCase() == "SUBMIT" || element.name.toUpperCase() == "SUBMIT" || element.isSubmit)){
  ret = true;
 }
 return ret; 
}
//初始化 initEnter2Tab()
function initEnter2Tab()
{
 for(i=0;i<document.forms.length;i++){
   document.forms[i].onkeydown = function f(){enterToTab();};
 }
 //文档初始化焦点

 if(document.forms[0].elements != null)
 {
  focusFirstElement(document.forms[0].elements,-1)
 }
} 
//格式化数字(数字，小数位数)
function FormatNumber(srcStr,nAfterDot){
    var srcStr,nAfterDot;
    var resultStr,nTen;
    srcStr = ""+srcStr+"";
    strLen = srcStr.length;
    dotPos = srcStr.indexOf(".",0);
    if (dotPos == -1){
        resultStr = srcStr+".";
        for (i=0;i<nAfterDot;i++){
            resultStr = resultStr+"0";
        }
        return resultStr;
    } else{
        if ((strLen - dotPos - 1) >= nAfterDot){
            nAfter = dotPos + nAfterDot + 1;
            nTen =1;
            for(j=0;j<nAfterDot;j++){
            nTen = nTen*10;
        }
        resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
        return resultStr;
        } else{
            resultStr = srcStr;
            for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
                resultStr = resultStr+"0";
            }
            return resultStr;
        }
    }
}


/*------------ DataGrid鼠标事件处理 ------------
功能:用于数据梆定后鼠标事件
参数说明:
obj:对像this
fontColor:字体颜色
backColor:背景颜色
----------------------------------------------*/
var objState
//------------鼠标经过时-----------
function OnFoucsMouseOver( obj,fontColor,backColor )
{
 if ( obj.rowIndex > 0 )
 {
  //obj.style.color = fontColor;
  //obj.style.backgroundColor = backColor;
  obj.style.tip = "hello";
 }
}

//-----------鼠标离开时-----------
function OnFoucsMouseOut( obj,fontColor,backColor )
{
 if ( obj.rowIndex > 0 )
 {
  if ( obj != objState )
  {
   //obj.style.color = fontColor;
   //obj.style.backgroundColor = backColor;
  }
 }
}

//-----------鼠标单击时-----------
/*
function OnFoucsClick( obj,fontColor,backColor )
{
 if ( obj.rowIndex > 0 )
 {
  if ( objState != null )
  {
   objState.style.color = "";
   objState.style.backgroundColor = "";
  }
  obj.style.color = fontColor;
  obj.style.backgroundColor = backColor;

  objState = obj;
 }
}*/

//-----------鼠标双击时-----------
/*
function OnFoucsDbClick( obj,fontColor,backColor,openUrl )
{
 //参数openUrl为要开的新窗口的地址
 if ( obj.rowIndex > 0 )
 {
  if ( objState != null )
  {
   objState.style.color = "";
   objState.style.backgroundColor = "";
  }
  obj.style.color = fontColor;
  obj.style.backgroundColor = backColor;

  objState = obj;

  window.open( openUrl );
 }
}*/
//-->


//功能：悬浮提示框
//时间：2006-12-15
//编辑：王君
//控制高级搜索提示
function SaveAndCycleTips(div1, displacement)
{
	if( document.all(div1).style.display == "" )
		document.all(div1).style.display = "none";
	else
	{
		var obj = document.all(div1);
		GetMouseXY_ForLayerindex(obj, displacement);
		obj.style.display = "";
	}
}
//得到鼠标的位置设置悬浮层的位置
function GetMouseXY_ForLayerindex(obj_div, displacement)
{
	x = document.body.scrollLeft + event.clientX - displacement;
	y = document.body.scrollTop + event.clientY;
	
	//获取屏幕宽度
	availWidth = parseInt(document.body.clientWidth);
	tblWidth = parseInt(obj_div.width);
	//获取位置x和菜单table的宽度相加之和			
	curWidth = x + tblWidth;
	//如果超出了屏幕右边则x左移动一个差量			
	if( curWidth > availWidth )
		x = x-tblWidth;
	
	obj_div.style.top = y;
	obj_div.style.left = x;
}

function $(obj)
{
	return document.all(obj).value;
}
