// JavaScript Document

/*****************************************************************
弹出窗口
*****************************************************************/
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr,Math.round(Math.random()*10000).toString(), 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

/*****************************************************************
菜单层显示开关
*****************************************************************/
function switchDivMenu(MenuObj)
{
	if(MenuObj.style.display=='none')
		MenuObj.style.display='block';
	else
		MenuObj.style.display='none';
}

/*****************************************************************
控件开关
*****************************************************************/
function switchEnable(EnabledObj)
{
	if(EnabledObj.disabled)
		EnabledObj.disabled=false;
	else
		EnabledObj.disabled=true;
}

/*****************************************************************
打开日历控件
*****************************************************************/		
function openCalendar(inputTextObj,calendarPagePath,fullTime)
{
	if(inputTextObj)
	{
		var dateStr="";
		if(fullTime)
			dialogHeight="300px";
		else
			dialogHeight="240px";
		dateStr=showModalDialog(calendarPagePath+'calendar.htm', 'yyyy-mm-dd' ,'dialogWidth:286px;dialogHeight:'+dialogHeight+';status:no;help:no');
		var datePartArray=new Array();
		datePartArray=dateStr.split("-");
		if(parseInt(datePartArray[1])<10)
			datePartArray[1]="0"+datePartArray[1];
		if(parseInt(datePartArray[2])<10)
			datePartArray[2]="0"+datePartArray[2];
		dateStr="";
		for(i=0;i<datePartArray.length;i++)
		{
			if(dateStr=="")
				dateStr+=datePartArray[i];
			else
				dateStr+="-"+datePartArray[i];
		}
		inputTextObj.value=dateStr;
	}
}

/*****************************************************************
//打开文本编辑器
*****************************************************************/
function openHtmlEdit(obj_name,htmlEditerPath,win_width,win_height,urlSearchString)
{
	//textObj=obj_name.split(",");
	textObj=obj_name;
	if(!win_width)
		win_width=700;
	if(!win_height)
		win_height=400;
	win_left=(screen.width-win_width)/2;
	win_top=(screen.height-win_height)/2;
	fullUrl=htmlEditerPath+'edit.php';
	if(!isEmpty(urlSearchString))
		fullUrl=fullUrl+urlSearchString;
	window.open(fullUrl,'editWin','toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+win_width+',height='+win_height+',left='+win_left+', top='+win_top+',screenX='+win_left+',screenY='+win_top+'');
}

/*****************************************************************
打开数据选择窗口
*****************************************************************/		
function openSelectPage(pageUrl,paraArray,windowWidth,windowHeight)
{
	var selectWindowWidth=800;
	var selectWindowHeight=620;
	if(windowWidth)
		selectWindowWidth=windowWidth;
	if(windowHeight)
		selectWindowHeight=windowHeight;
	return(showModalDialog(pageUrl, paraArray ,'dialogWidth:'+selectWindowWidth+'px;dialogHeight:'+selectWindowHeight+'px;status:no;help:no'));
}

/*****************************************************************
打开模式窗口维护select控件中的数据
*****************************************************************/
function maintenanceSelectData(framePageUrl,maintenancePageUrl,selectObj,selectedValue,blankItemLabel,windowWidth,windowHeight)
{
	newSelectDataArray=openSelectPage(framePageUrl,maintenancePageUrl,windowWidth,windowHeight);
	setSelectValue(selectObj,newSelectDataArray,selectedValue,blankItemLabel);
}

/*****************************************************************
将选择窗口返回的数据填入相应控件
*****************************************************************/		
function setValueFromSelectPage(selectPageReturnValue,setValueObj,setLabelObj,formNameSubmit)
{
	if(selectPageReturnValue)
	{
		//alert(selectPageReturnValue);
		if(setValueObj)
			setValueObj.value=selectPageReturnValue[0];
		if(setLabelObj)
		{
			if(selectPageReturnValue[1])
				setLabelObj.value=selectPageReturnValue[1];
			else
				setLabelObj.value=selectPageReturnValue[0];
		}
		if(formNameSubmit)
			//eval("document."+formNameSubmit+".submit();");
			formNameSubmit.submit();
	}
}

function disableInput(message)
{
	if(!isEmpty(message))
		alert(message);
	return(false)	
}

//过滤搜索表单提交
function filterSearchSubmit(noEmptyObjArray)
{
	for(i=0;i<noEmptyObjArray.length;i++)
	{
		if(isEmpty(noEmptyObjArray[i]))
		{
			return(false);
			break;
		}
	}	
}

//重新装入页面，且地址中不跟？与任何地址行参数
function reloadPageWithoutSearch()
{
	window.location=window.location.pathname;	
}

//禁止
function forbid(promptInfo)
{
	if(!isEmpty(promptInfo))
		alert(promptInfo);
	return(false);
}

//回车提交表单
function enterKeySubmit(submitButton)
{
    if (event.keyCode == 13)
    {
        event.returnValue=false;
        event.cancel = true;
        submitButton.click();
    }
}

//将多选的下拉列表值组成以","分隔的字串
function getMultiSelectedValue(selectObj)
{
	var valueStr="";
	if(selectObj)
	{
		for(idx=0;idx<selectObj.length;idx++)
		{
			if(valueStr=="")
				valueStr=selectObj[idx].value;
			else
				valueStr+=","+selectObj[idx].value;
		}
	}
	return(valueStr);
}

//两个多选框中移动选中的值
function moveSelected(fromSelect,toSelect)
{
	if(fromSelect&&toSelect)
	{
		var selectedIdx=new Array();
		for(idx=0;idx<fromSelect.length;idx++)
		{
			if(fromSelect[idx].selected)
			{
				var oOption = document.createElement("OPTION");
				oOption.text=fromSelect[idx].text;
				oOption.value=fromSelect[idx].value;
				toSelect.add(oOption);
				selectedIdx.push(idx);
			}
		}
		for(idx=0;idx<selectedIdx.length;idx++)
		{
			fromSelect.remove(selectedIdx[idx]-idx);
		}
	}
}

function timeClock(displayContainerId)
{
	var Timer=new Date();
	var hours=Timer.getHours();
	var minutes=Timer.getMinutes();
	var seconds=Timer.getSeconds();
	//var noon="AM";
	//if(hours>12)
	//{
		//noon="PM";
		//hours=hours-12;
	//}
	//if(hours==0)
		//hours=12;
	if(minutes<=9)
		minutes="0"+minutes;
	if(seconds<=9)
		seconds="0"+seconds;
	displayContainerId.innerText=hours+":"+minutes+":"+seconds;
}

function setSelectValue(selectObj,valueArray,selectedValue,blankItemLabel)
{
	if(selectObj)	
	{
		while(selectObj.length>0)
		{
			selectObj.remove(0);
		}
		if(blankItemLabel)
		{
			var oOption = document.createElement("OPTION");
			oOption.text=blankItemLabel;
			oOption.value="";
			selectObj.add(oOption);
		}
		selectedIdx=0;
		for(idx=0;idx<valueArray.length;idx++)
		{
			var oOption = document.createElement("OPTION");
			oOption.text=valueArray[idx][1];
			oOption.value=valueArray[idx][0];
			if(selectedValue)
			{
				if(trim(selectedValue)==trim(oOption.value))
				{
					selectedIdx=idx;
				}
			}
			selectObj.add(oOption);
		}
		selectObj.selectedIndex=selectedIdx;
	}
}

function addDate(type,NumDay,dtDate)
{
	var date = new Date(dtDate)
	type = parseInt(type) //类型 
	lIntval = parseInt(NumDay)//间隔
	switch(type)
	{
		case 6 ://年
		date.setYear(date.getYear() + lIntval)
		break;
		case 7 ://季度
		date.setMonth(date.getMonth() + (lIntval * 3) )
		break;
		case 5 ://月
		date.setMonth(date.getMonth() + lIntval)
		break;
		case 4 ://天
		date.setDate(date.getDate() + lIntval)
		break
		case 3 ://时
		date.setHours(date.getHours() + lIntval)
		break
		case 2 ://分
		date.setMinutes(date.getMinutes() + lIntval)
		break
		case 1 ://秒
		date.setSeconds(date.getSeconds() + lIntval)
		break;
		default:    
    } 
 	return date.getYear() +'-' + ((date.getMonth()+1)<10?'0'+(date.getMonth()+1):''+(date.getMonth()+1)) + '-' +(date.getDate()<10?'0'+date.getDate():''+date.getDate())+ ' '+ (date.getHours()<10?'0'+date.getHours():''+date.getHours())+':'+(date.getMinutes()<10?'0'+date.getMinutes():''+date.getMinutes())+':'+(date.getSeconds()<10?'0'+date.getSeconds():''+date.getSeconds());
 }
 
function switchMenu(menuObj,turnOnIndex)
{
	if(menuObj)
	{
		if(menuObj.length)
		{
			if(menuObj[turnOnIndex].style.display=='none')
			{
				for(idx=0;idx<menuObj.length;idx++)
				{
					menuObj[idx].style.display='none';
				}
				menuObj[turnOnIndex].style.display='block';
			}//else
			//{
				//for(idx=0;idx<menuObj.length;idx++)
				//{
					//menuObj[idx].style.display='none';
				//}
			//}
		}
		else
		{
			if(menuObj.style.display=='none')
				menuObj.style.display='block';
			//else
				//menuObj.style.display='none'
		}
	}
}

/*****************************************************************
多选框组是否有项目被勾选
checkBoxObj:多选框组对象
*****************************************************************/	
function isAnyChecked(checkBoxObj)
{
	result=false;
	if(!isEmpty(checkBoxObj))
	{
		if(isEmpty(checkBoxObj.length))
		{
			if(checkBoxObj.checked)
				result=true;
		}
		else
		{
			for(i=0;i<checkBoxObj.length;i++)
			{
				if(checkBoxObj[i].checked)
				{
					result=true;
					break;
				}
			}
		}
	}
	return(result);
}
	
/*****************************************************************
多选框组是否所有项目都被勾选
checkBoxObj:多选框组对象
*****************************************************************/	
function isAllChecked(checkBoxObj)
{
	result=true;
	if(checkBoxObj)
	{
		if(!checkBoxObj.length)
		{
			if(!checkBoxObj.checked)
				result=false;
		}
		else
		{
			for(i=0;i<checkBoxObj.length;i++)
			{
				if(!checkBoxObj[i].checked)
				{
					result=false;
					break;
				}
			}
		}
	}
	return(result);
}

/*****************************************************************
勾选多选框组中所有选项
checkBoxObj:多选框组对象
*****************************************************************/		
function checkAllChildren(childrenCheckBoxObj)
{
	if(childrenCheckBoxObj)
	{
		if(isAllChecked(childrenCheckBoxObj))
		{
			if(!childrenCheckBoxObj.length)
			{
				childrenCheckBoxObj.checked=false;
			}
			else
			{
				for(i=0;i<childrenCheckBoxObj.length;i++)
				{
					if(childrenCheckBoxObj[i].checked)
					{
						childrenCheckBoxObj[i].checked=false;
					}
				}
			}
		}
		else
		{
			if(!childrenCheckBoxObj.length)
			{
				childrenCheckBoxObj.checked=true;
			}
			else
			{
				for(i=0;i<childrenCheckBoxObj.length;i++)
				{
					if(!childrenCheckBoxObj[i].checked)
					{
						childrenCheckBoxObj[i].checked=true;
					}
				}
			}				
		}			
	}		
}

/*****************************************************************
勾选多选框组的父级选框
childrenCheckBoxObj:多选框组对象
motherCheckBoxObj:父级选框对象
*****************************************************************/		
function checkMother(childrenCheckBoxObj,motherCheckBoxObj)
{	
	if(childrenCheckBoxObj&&motherCheckBoxObj)
	{
		if(isAllChecked(childrenCheckBoxObj))
		{
			if(!motherCheckBoxObj.checked)
				motherCheckBoxObj.checked=true;
		}
		else
		{
			if(motherCheckBoxObj.checked)
				motherCheckBoxObj.checked=false;
		}
	}
}

function getSelectedRecordIdString(checkboxObj)
{
	if(checkboxObj)
	{
		selectedIdString=null;
		if(checkboxObj.length)
		{
			for(i=0;i<checkboxObj.length;i++)
			{
				if(checkboxObj[i].checked)
				{
					if(selectedIdString)
						selectedIdString+=','+checkboxObj[i].value;
					else
						selectedIdString=checkboxObj[i].value;
				}
			}
		}
		else
		{
			if(checkboxObj.checked)
				selectedIdString=checkboxObj.value;
		}
	}
	return(selectedIdString);
}


function getActiveObjIndex(objByName,uniqueIdStr)
{
	var returnIdx=-1;
	if(objByName)
	{
		if(objByName.length>1)
		{
			for(i=0;i<objByName.length;i++)
			{
				if(objByName[i].uniqueID==uniqueIdStr)
				{
					returnIdx=i;
					break;
				}
			}
		}
	}
	return(returnIdx);
}