
//检查输入的内容是否为数字
function CheckNum(src)
  {
	thisvalue=src.value;
	if(isNaN(thisvalue)){
		alert("这里只能输入数字");
		src.focus();
		src.select();
   }
}

//选择日期
function SelectDate(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 168 ; // + deltaX;
	showy = event.screenY - event.offsetY + 20; // + deltaY;
	newWINwidth = 210 + 4 + 18;
	var retval = window.showModalDialog("./common/SelectDate.htm","","dialogWidth:200px;dialogHeight:250px;dialogLeft:"+showx+"px; dialogTop:"+showy+"px;Resizable:0;help=no;status:No;center:yes;scroll:no" );
	if( retval != null ){
		ctrlobj.value = retval;
	}
}

//选择日期和时间
function SelectDateTime(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 168 ; // + deltaX;
	showy = event.screenY - event.offsetY + 20; // + deltaY;
	newWINwidth = 210 + 4 + 18;
	var retval = window.showModalDialog("./common/SelectDateTime.htm","","dialogWidth:210px;dialogHeight:260px;dialogLeft:"+showx+"px; dialogTop:"+showy+"px;Resizable:0;help=no;status:No;center:yes;scroll:no" );
	if( retval != null ){
		ctrlobj.value = retval;
	}
}

//选择所有记录
function SelectAllRow(thisfrom)
{
	if( document.all.rowId )
	{
		document.all.rowId.checked = thisfrom.checked;
		for(i=0;i<document.all.rowId.length;i++)
		if( document.all.rowId[i].disabled != true ) document.all.rowId[i].checked = thisfrom.checked;
	}
}
function sort(sortField){
	if(sortField!=document.all.sortField.value){
		document.all.sortField.value=sortField;
		document.all.sortDirection.value=0;
	}else{
		if(document.all.sortDirection.value==0){
			document.all.sortDirection.value=1;
		}else{
			document.all.sortDirection.value=0;
		}
		
		
	}
	var actionString=document.forms[0].action;
	document.forms[0].action=actionString.substring(0, actionString.indexOf(".do")+3)+"?action=sort";
	document.forms[0].submit();
}
function chkall(e){
	var all=document.all;
	for(i=0;i<all.length;i++){
	 if(all[i].type=='checkbox'){
		if(all[i].name.indexOf("detailList[")!=-1 && all[i].name.indexOf("].isSelected")!=-1){
			all[i].checked=e.checked;
		}
	 }
	}
}

//自定义弹出窗口
function wsOpen(strUrl,thisWidth,thisHeight,scrollType,resizeType) 
{ 
	var thisLeft = (window.screen.width - thisWidth) / 2; 
	var thisTop = (window.screen.height - thisHeight - 50) / 2; 
	window.open(strUrl,'','width=' + thisWidth + ',height=' + thisHeight + ',left=' + thisLeft + ',top=' + thisTop + ',scrollbars = ' + scrollType + ',resizable=' + resizeType); 
}

//最大化弹出窗口
function wsMaxOpen(strUrl,strName) 
{ 
	var thisWidth = (screen.availHeight)*1.37;
	var thisHeight = (screen.availWidth)*0.695;
	var thisLeft = 0;//(window.screen.width - thisWidth) / 2; 
	var thisTop = 0;//(window.screen.height - thisHeight - 50) / 2; 
	window.open(strUrl,strName,'width=' + thisWidth + ',height=' + thisHeight + ',left=' + thisLeft + ',top=' + thisTop + ',scrollbars=1,resizable=1'); 
} 

//修改记录的弹出窗口
function wsEditItem(strUrl,thisWidth,thisHeight,scrollType,resizeType)
{
	row_x = 0;
	var tempRowId = "";
	
	if( ! document.all.rowId )
	{	//如果没有任何记录则直接返回
		return false;
	}
	
	if( ! document.all.rowId.length )
	{	//如果只有一条记录则视rowId为一个字段而不是数组
		if( document.all.rowId.checked == true )
		{
			row_x++;
			tempRowId = document.all.rowId.value;
		}
	}
	else
	{
		for(i=0;i<document.all.rowId.length;i++)
		{
			if( document.all.rowId[i].checked == true )
			{
				row_x++;
				tempRowId = document.all.rowId[i].value;
			}
		}
	}
	
	if( row_x == 0 || row_x > 1 )
	{
		alert("请从列表中选择一条记录！");
		return false;
	}
	else if(row_x == 1)
	{
		if( strUrl.substring(strUrl.length-5,strUrl.length) == ".aspx" )
		{
			strUrl = strUrl + "?rowId=" + tempRowId;
		}
		else
		{
			strUrl = strUrl + "&rowId=" + tempRowId;
		}
		WebOAOpen(strUrl ,thisWidth,thisHeight,scrollType,resizeType);
		return false;
	}
}

//选择多条记录的弹出窗口
function wsSelectItem(strUrl,thisWidth,thisHeight,scrollType,resizeType)
{
	row_x = 0;
	var tempRowId = "";
	
	if( ! document.all.rowId )
	{	//如果没有任何记录则直接返回
		return false;
	}
	
	if( ! document.all.rowId.length )
	{	//如果只有一条记录则视rowId为一个字段而不是数组
		if( document.all.rowId.checked == true )
		{
			row_x++;
			tempRowId = document.all.rowId.value;
		}
	}
	else
	{
		for(i=0;i<document.all.rowId.length;i++)
		{
			if( document.all.rowId[i].checked == true )
			{
				row_x++;
				if(tempRowId == "")
				{
					tempRowId = document.all.rowId[i].value;
				}
				else
				{
					tempRowId = tempRowId + "," + document.all.rowId[i].value;
				}
			}
		}
	}
	
	if(row_x == 0)
	{
		alert("请从列表中选择一条或多条记录！");
		return false;
	}
	else if(row_x >= 1)
	{
		if( strUrl.substring(strUrl.length-5,strUrl.length) == ".aspx" )
		{
			strUrl = strUrl + "?rowId=" + tempRowId;
		}
		else
		{
			strUrl = strUrl + "&rowId=" + tempRowId;
		}
		WebOAOpen(strUrl ,thisWidth,thisHeight,scrollType,resizeType);
		return false;
	}
}

//从LeftSelect列表框将项目移到RightSelect列表框Begin
function goLeftToRight(LeftSelect,RightSelect)
{	
	if( LeftSelect.length == 0 ) {
		//alert("左边可选项目已经全部被选择！");
		return false;	
	}
	
	var leftHaveSe = false;
	for (i0 = 0; i0 < LeftSelect.length; i0++) {
    	if ( LeftSelect[i0].selected ) {
			leftHaveSe = true;
			break;
		}
	}	
	if( !leftHaveSe ){
		//alert("请在左边可选项目栏选择一个项目！");
		return false;
	}
	
	if( RightSelect.length > 0 ) {
		for(var c2 = 0 ; c2 < RightSelect.length ; c2++ ) {		
			RightSelect.options[c2].selected = false;
		}
	}

	for (i = 0; i < LeftSelect.length; i++) {
    	if ( LeftSelect[i].selected ) {
			var x = LeftSelect[i];
			var tempop = new Option();
			tempop.value = x.value;
			tempop.text = x.text;
			var s2len = RightSelect.length;
			var s2Have = false;
			if( s2len >= 0 ) {
				for(var lo2 = 0 ; lo2 < RightSelect.length ; lo2++ ) {
					if( RightSelect.options[lo2].value == tempop.value ) {
						//alert( tempop.text + " 已经选择了!" );
						s2Have = true;
						break;						
					}
				}				
			}
			if( !s2Have ) {
				var lastIn = RightSelect.length;
				RightSelect.options[lastIn] = tempop;	
				RightSelect.options[lastIn].selected = true;
			}
		}
	}
	
	if( RightSelect.length > 0 ) {
		for(var j2 = 0 ; j2 < RightSelect.length ; j2++ ) {
			for( var j1 = 0 ; j1 < LeftSelect.length ; j1++ ) {
				var s2val = RightSelect.options[j2].value;
				var s1val = LeftSelect.options[j1].value;
				if( s2val == s1val ) {
					LeftSelect.options[j1] = null;
					continue;
				}
			}
		}
	}		
}
//从LeftSelect列表框将项目移到RightSelect列表框End

//从RightSelect列表框将项目移到LeftSelect列表框Begin
function goRightToLeft(LeftSelect,RightSelect)
{
	if( RightSelect.length == 0 ) {
		//alert("右边已选项目已经全部移走！");
		return false;			
	}
	
	var rightHaveSe = false;
	for (var i22 = 0; i22 < RightSelect.length; i22++) {
    	if ( RightSelect[i22].selected ) {
			rightHaveSe = true;
			break;
		}
	}	
	if( !rightHaveSe ){
		//alert("请在右边已项目栏选择一个项目！");
		return false;
	}
	
	if( LeftSelect.length > 0 ) {
		for(var c2 = 0 ; c2 < LeftSelect.length ; c2++ ) {		
			LeftSelect.options[c2].selected = false;
		}
	}

	for (i = 0; i < RightSelect.length; i++) {
    	if ( RightSelect[i].selected ) {
			var x = RightSelect[i];
			var tempop = new Option();
			tempop.value = x.value;
			tempop.text = x.text;
			var s2len = LeftSelect.length;
			var s2Have = false;
			if( s2len >= 0 ) {
				for(var lo2 = 0 ; lo2 < LeftSelect.length ; lo2++ ) {
					if( LeftSelect.options[lo2].value == tempop.value ) {
						//alert( tempop.text + " 已经被移走了!" );
						s2Have = true;
						break;						
					}
				}				
			}
			if( !s2Have ) {
				var lastIn = LeftSelect.length;
				LeftSelect.options[lastIn] = tempop;	
				LeftSelect.options[lastIn].selected = true;
			}
		}
	}
	
	if( LeftSelect.length > 0 ) {
		for(var j2 = 0 ; j2 < LeftSelect.length ; j2++ ) {
			for( var j1 = 0 ; j1 < RightSelect.length ; j1++ ) {
				var s2val = LeftSelect.options[j2].value;
				var s1val = RightSelect.options[j1].value;
				if( s2val == s1val ) {
					RightSelect.options[j1] = null;
					continue;
				}
			}
		}
	}
}
//从RightSelect列表框将项目移到LeftSelect列表框End


//根据部门选择人员Begin
function selectmultiperson(cid,cname)
{
	//选择多人
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("common/selectmultiperson.jsp?type=0",oldvalue,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}
function selectmultipersontelmobile(cid,cname)
{
	//选择用户手机号码
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("common/selectmultiperson.jsp?type=1",oldvalue,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}

function selectsingleperson(cid,cname)
{
  //选择一人
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("common/selectsingleperson.jsp",oldvalue,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}

function selectnoacctperson(cid,cname)
{
  //选择无帐号一人
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("common/selectnoacctperson.jsp",oldvalue,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}

//选择部门Begin
function selectmultidepartment(cid,cname)
{
	//选择多个部门
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("SelectMultiDepartmentTreeAction.do?action=setUp&selectType=multi",oldvalue,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}

function selectsingledepartment(cid,cname)
{
	//选择一个部门
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("SelectMultiDepartmentTreeAction.do?action=setUp&selectType=single",oldvalue,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}
//选择部门End


//选择岗位Begin
function selectmultipost(cid,cname)
{
	//选择多个岗位
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("SelectPostTreeAction.do?action=setUp",oldvalue,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}
function selectsinglepost(cid,cname)
{
	//选择一个岗位
	var single=true;
	var oldvalue="";
	var newvalue="";

	if(cid.value!="" && cname.value!="")
	{
		oldvalue = cname.value+"@"+cid.value;
	}

	var ReturnValue = window.showModalDialog("SelectPostTreeAction.do?action=setUp",single,"dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}

//选择岗位End

function getWeek()
{
	var D=new Date();
	var yy=D.getYear();
	var mm=D.getMonth()+1;
	var dd=D.getDate();
	var ww=D.getDay();
	if (ww==0) ww="<font color=RED>星期日</font>";
	if (ww==1) ww="星期一";
	if (ww==2) ww="星期二";
	if (ww==3) ww="星期三";
	if (ww==4) ww="星期四";
	if (ww==5) ww="星期五";
	if (ww==6) ww="<font color=green>星期六</font>";
	return ww;
}


function openMain_bak(mainurl)
{
	var popup = null;
	var _width = (screen.availHeight)*1.37;
	var _height = (screen.availWidth)*0.695;
	var _left = 0;
	var _top = 0;
	
	popup = window.open("","","width=" + _width + ",height=" + _height + ",left=" + _left + ",top=" + top + ",scrollbars = 1,resizable=1,status=no"); 
	if (popup != null)
	{
		if (popup.opener == null)
		{
			popup.opener = self; 
		}
		popup.location.href = mainurl;
		window.opener = "null";
		window.close();
	}
}
function openMain(mainurl)
{
	window.location=mainurl;
}

//选反所有列表
function checkall(e)
{
	var all=document.all;
	for(i=0;i<all.length;i++){
	 if(all[i].type=='checkbox'){
		if(all[i].name.indexOf("detailList[")!=-1 && all[i].name.indexOf("].isSelected")!=-1){
			all[i].checked=e.checked;
		}
	 }
	}
}

//判断是否有选择列表
function isCheckList()
{
	var all=document.all;
	for(i=0;i<all.length;i++){
	 if(all[i].type=='checkbox'){
		if(all[i].name.indexOf("detailList[")!=-1 && all[i].name.indexOf("].isSelected")!=-1){
			if(all[i].checked){
				return true;
			}
		}
	 }
	}
	return false;
}

function Pause(nMillis)
{
 showModalDialog("javascript:document.writeln(\"<script>setTimeout('window.close()'," + nMillis + ");<" + "/script>\")");
}

//确认是否删除
function isDelete()
{
	if(confirm("真的要删除吗？")){
		return true;
	}
	else{
		return false;
	}
}


//检查开始日期是否小于等于结束日期
function compareDate(DateOne,DateTwo)
{
	if(DateOne.lastIndexOf(".")>10)
		DateOne = DateOne.substring(0,DateOne.lastIndexOf("."));
	if(DateTwo.lastIndexOf(".")>10)
		DateTwo = DateTwo.substring(0,DateTwo.lastIndexOf("."));

	var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ("-"));
	var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ("-")+1);
	var OneYear = DateOne.substring(0,DateOne.indexOf ("-"));
	
	var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ("-"));
	var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ("-")+1);
	var TwoYear = DateTwo.substring(0,DateTwo.indexOf ("-"));

	if (DateOne=="" || DateTwo=="" || Date.parse(OneMonth+"/"+OneDay+"/"+OneYear) <= Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear))
	{
		return true;
	}
	else
	{
		alert("开始日期不能大于结束日期！");
		return false;
	}
}


function selectCustomer(cid,cname)
{
	var newvalue="";
	var ReturnValue = window.showModalDialog("customer_list.do?action=setUp","","dialogWidth:480px;dialogHeight:330px;Resizable:0;help=no;status:No;center:yes;scroll:auto" );
	if( ReturnValue != null ){
		newvalue=ReturnValue.split("@");
		if(newvalue.length==2){
			cname.value = newvalue[0];
			cid.value = newvalue[1];
		}
	}
}


