/***********************************************/
//
//WindowFunctions.js
//
/***********************************************/
function showCopyright() {
	var dialogObject = new Object() ;
	dialogObject.Title = "Copyright Statement" ;
	dialogObject.SourceUrl = "Copyright.asp" ;
	dialogObject.UseCancel = false ;
	dialogObject.UseApply = false ;
	window.showModalDialog("dialogHost.asp", dialogObject, "dialogWidth:505px; dialogHeight:307px; center:yes; help:no; resizable:no; status:no") ;
}

function showDialogFrame(SourceUrl, dialogWidth, dialogHeight)
{
	var dialogObject = new Object() ;
	dialogObject.Title = escape("修改登录密码") ;
	dialogObject.SourceUrl = SourceUrl ;
	dialogObject.UseCancel = false ;
	dialogObject.UseApply = false ;
	dialogObject.UseOk = false ;
	
	var retVal = window.showModalDialog("dialogHost.asp", dialogObject, "dialogWidth:" + dialogWidth + "px; dialogHeight:" + dialogHeight + "px; center:yes; help:no; resizable:no; status:no") ;
	
	return retVal;
}

function openWin(url, target, width, height, menubar, resizable, scrollbars)
{
	var win = window.open(url, target, 'width=' + width + ', height=' + height + ', top='+((screen.availHeight-height-25)/2)+', left=' + ((screen.availWidth-width-5)/2) + ', menubar='+menubar+',resizable='+resizable+',scrollbars='+scrollbars+'');
}

//******选择函数 Start************
function SelectAll()
{
	var chk = event.srcElement;
	var obj = document.all;
	for(i=0; i<obj.length; i++)
	{
		if(obj[i].tagName == "INPUT" && obj[i].type.toLowerCase() == "checkbox" && (!obj[i].disabled))
		{
			if(chk.checked)
				obj[i].checked=true;
			else
				obj[i].checked=false;
		}
	}
}

function Select()
{
	/*
	var chk = event.srcElement;
	if(!chk.checked)
	{
		var obj = document.all;
		for(i=0; i<obj.length; i++)
		{
			if(obj[i].tagName == "INPUT" && obj[i].type.toLowerCase() == "checkbox")
			{
				if(obj[i].name.substr(14,12)=="chkSelectAll")
				{
					obj[i].checked=false;
				}
			}
		}	
	}
	*/
}

function getSelectLength()
{
	var count = 0;
	var obj = document.all;
	for(i=0; i<obj.length; i++)
	{
		if(obj[i].tagName == "INPUT" && obj[i].type.toLowerCase() == "checkbox")
		{
			if(obj[i].name.substr(0,12)!="chkSelectAll")
			{
				if (obj[i].checked)
					count ++;
			}
		}
	}	
	
	return count;
}

//******选择函数 End************

//去掉字符串前面的空格，函数：LTrimString(StringIn)
function LTrimString(StringIn)
{
	var num=StringIn.length; 
	while(num!=0 && StringIn.substr(0,1)==" ")
	{
		StringIn=StringIn.substr(1,num-1);
		num=StringIn.length;
	}
	return StringIn
}
//去掉字符串后面的空格，函数：RTrimString(StringIn)
function RTrimString(StringIn)
{
	var num=StringIn.length;

	while(num!=0 && StringIn.substr(num-1,1)==" ")
	{
		StringIn=StringIn.substr(0,num-1);
		num=StringIn.length;
	}
	return StringIn
}

//去掉字符串前后的空格，函数：TrimString(StringIn)
function trim(StringIn)
{
	return RTrimString(LTrimString(StringIn));
}

//////////////////////////////////////////////////////
function isNumeric(s)
{
	var patrn = /\d{1,}(\.\d{1,})/;
	if (!patrn.exec(s))
		return false;
		
	return true;
}
		
//校验登录名：只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
function isRegisterUserName(s)
{
	var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
	if (!patrn.exec(s))
		return false;
	else
		return true;
}

//校验用户姓名：只能输入1-30个以字母开头的字串
function isTrueName(s)
{
	var patrn=/^[a-zA-Z]{1,30}$/;
	if (!patrn.exec(s))
		return false;
	else
		return true;
}

function isEmail (theStr) 
{
	var atIndex = theStr.indexOf('@');
	var dotIndex = theStr.indexOf('.', atIndex);
	var flag = true;
	theSub = theStr.substring(0, dotIndex+1)

	if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) 
	{
		return(false); 
	}
	else 
	{ 
	return(true); 
	}
}
//////////////////////////////////////////////////////
// 日期函数 /////////////////////////////////////////////////////////////////////////////////////////////
function isDateString(sDate)
{	var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
	var iaDate = new Array(3)
	var year, month, day

	if (arguments.length != 1) return false
	iaDate = sDate.toString().split("-")
	if (iaDate.length != 3) return false
	if (iaDate[1].length > 2 || iaDate[2].length > 2) return false
	if (isNaN(iaDate[0])||isNaN(iaDate[1])||isNaN(iaDate[2])) return false

	year = parseFloat(iaDate[0])
	month = parseFloat(iaDate[1])
	day=parseFloat(iaDate[2])

	if (year < 1900 || year > 2100) return false
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
	if (month < 1 || month > 12) return false
	if (day < 1 || day > iaMonthDays[month - 1]) return false
	return true
}

function stringToDate(sDate, bIgnore)
{	var bValidDate, year, month, day
	var iaDate = new Array(3)
	
	if (bIgnore) bValidDate = true
	else bValidDate = isDateString(sDate)
	
	if (bValidDate)
	{  iaDate = sDate.toString().split("-")
		year = parseFloat(iaDate[0])
		month = parseFloat(iaDate[1]) - 1
		day=parseFloat(iaDate[2])
		return (new Date(year,month,day))
	}
	else return (new Date(1900,1,1))
}
		//校验登录名：只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
		function isRegisterUserName(s)
		{
			var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
			if (!patrn.exec(s))
				return false;
			else
				return true;
		}
		
		//校验用户姓名：只能输入1-30个以字母开头的字串
		function isTrueName(s)
		{
			var patrn=/^[a-zA-Z]{1,30}$/;
			if (!patrn.exec(s))
				return false;
			else
				return true;
		}
		
		//校验密码：只能输入6-20个字母、数字、下划线
		function isPassword(s)
		{
			var patrn=/^(\w){6,20}$/;
			if (!patrn.exec(s))
				return false;
			else
				return true;
		}
		//校验是否全由数字组成
		function isDigit4(s)
		{
		var patrn=/^[0-9]{4}$/;
		if (!patrn.exec(s))
			return false;
		else
			return true;
		}

		//校验是否全由数字组成(1-20位)
		function isDigit(s)
		{
			var patrn = /^[0-9]{1,20}$/;
			if (!patrn.exec(s)){return false;}
			return true;
		}

// 调整文本框大小函数 /////////////////////////////////////////////////////////////////////////////////////////////
function change(obj,i) {
he=parseInt(obj.style.height);
if (he>=80&&he<=400)
   if (i>0)
   obj.style.height=he+i+'px';
   else
   obj.style.height='80px';
else 
   obj.style.height='80px';
}
//*****************************************************************  
//函数名: SetFocus
//输  入: ID,为页面中控件的ID名
//输  出: 设置当前焦点的位置
//功  能: 设置当前焦点的位置
//*****************************************************************
function SetFocus(ID){document.getElementById(ID).focus();}
//*****************************************************************  
//函数名:ShowMsgAndSetFocus
//输  入: ID,为页面中控件的ID名，str为错误提示字符串
//输  出: 弹出错误提示信息，同时将当前的焦点位置移动到指定的位置
//功  能: 弹出错误提示信息，并设置当前焦点的位置
//*****************************************************************
function ShowMsgAndSetFocus(str,ID){alert(str,5);document.getElementById(ID).focus();}
///////////////////////////////////////////////////////////////////////////////////////////////////////