
//共用前端函数，与页面的具体功能无关
 
//检查字符串是否为空	
function isEmptyString(s)
 {
   return (s == null || /^ *$/.test(s));
 }

//检查传入的参数是否为数字  （可以包含小数点）,不允许为空
function isNumber(s)
{
	if (isEmptyString(s))
	{
		return false;
	}
	else if (isNaN(s))
	{
		return false;
	}
	else
	{
		return true;
	}
}

//检查传入的参数是否为数字  （可以包含小数点）,允许为空
function isNumber2(s)
{
	if (isNaN(s))
	{
		return false;
	}
	else
	{
		return true;
	}
}

//检查给定的字串是否为有效的日期 ,不允许为空串	
function isDate(s)
{
var year, month, day;
var d;
       
	// basic validation
	// A valid Date string will be: MM/DD/YYYY
	if (
			isEmptyString(s) ||
			(
				(10 != s.length)
			) ||
			(
				('-' != s.charAt(4)) ||
				('-' != s.charAt(7))
			)
	   ) //!e if
	{
		return false;
	}

	// logical validation
	// ensure no wrong date such as 02/29/2001
	year	= parseInt(s.substr(0,4), 10);
	month	= parseInt(s.substr(5,2), 10);
	day		= parseInt(s.substr(8,2), 10);

	// construct a temporary Date Object
	d	= new Date(year, month - 1, day);

	// ensure the newly created Date Object equal to the one we expected
	if (
			(year		!= d.getFullYear()) ||
			(month - 1	!= d.getMonth()) ||
			(day		!= d.getDate())
	   )
	{
		return false;
	}

	// the input string s is a valid Date string
	return true;
 } //!#e isDate(...)

//检查给定的字串是否为有效的日期 ,可以为空串	
function isDate2(s)
{
var year, month, day;
var d;
       if (isEmptyString(s))
       {
       return true;
       }
	// basic validation
	// A valid Date string will be: MM/DD/YYYY
	if (		
			(
				(10 != s.length)
			) ||
			(
				('-' != s.charAt(4)) ||
				('-' != s.charAt(7))
			)
	   ) //!e if
	{
		return false;
	}

	// logical validation
	// ensure no wrong date such as 02/29/2001
	year	= parseInt(s.substr(0,4), 10);
	month	= parseInt(s.substr(5,2), 10);
	day		= parseInt(s.substr(8,2), 10);

	// construct a temporary Date Object
	d	= new Date(year, month - 1, day);

	// ensure the newly created Date Object equal to the one we expected
	if (
			(year		!= d.getFullYear()) ||
			(month - 1	!= d.getMonth()) ||
			(day		!= d.getDate())
	   )
	{
		return false;
	}

	// the input string s is a valid Date string
	return true;
 } //!#e isDate(...)


//检查输入的页码是否有效	
function IsValidPageNum(s)
{  
   if (s.indexOf(" ")>=0)
   {
   	alert("输入的页数不能包含空格，请重新输入！");
   	return false;
   }
   else if (isNaN(s)) 
   {	
   	alert("输入的页数中不能含有非数字字符，请重新输入！");
   	return false;
   }
   else if (parseInt(s)<=0)
   {
   	alert("页数不能为零或负值，请重新输入！");
   	return false;
   }
   return true;
}//!#e IsValidPageNum(...)

//显示多页条目列表示时，调转到指定的页面
//注意调用此函数，页码输入框的命名为“NumOfPage”
function GoToPage(tempLarge,FileUrl)
{
	var obj,val,url;
	obj	= eval("document.all.NumOfPage");
	val	= obj.value;
	if (isEmptyString(val))
	{
	    alert("页数为空，请重新输入！")
	    obj.focus();
		return false;
	}
	if (!IsValidPageNum(val))
	{
	    obj.focus();
	    return;
	}
	
	if (val > tempLarge)
	{
	 alert("您输入的页数已经超过了检索出的最大的页数,现在给您显示最后一页！");
	 val = tempLarge;	 
	}
	url = FileUrl + "?p_Page=" + val;
   window.navigate(url);
}
