﻿/*****************************************************************************
函数名称：fucCheckNull
函数功能：检查是否为空
参数	：obj，要检查的对象
参数	：strAlertMsg 要显示的提示信息
返回    ：消息提示框  true/false
日期	：2004-03-19
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckNull(obj,strAlertMsg)
{
    strTemp=obj.value;
	strTemp=strTemp.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
	if (strTemp.length<1)
			{
				alert(strAlertMsg);
				obj.focus();
				return false;
			}
}

/*****************************************************************************
函数名称：fucCheckMail
函数功能：检查对象的值是否为Email Address
参数	：obj,要检查的对象
返回    ：消息提示框  true/false
日期	：2004-03-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckMail(obj,strAlertMsg)
 {
		strAddress=obj.value;
		strAddress=strAddress.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
				
		//匹配规则：
		//只允许以字母开头，用a-z,A-Z,0-9以及下划线组成的email名
		//email后面的域名只允许字母或下划线开头,至少一个.,以字母或下划线结束
		var newPar=/^[a-zA-Z](\w*)@\w+\.(\w|.)*\w+$/
		if(strAddress.length>0 && newPar.test(strAddress)==false)
		{
		   alert(strAlertMsg);
		   obj.focus();	
		   return false;	
		 }
		 else
		 {
		    return true;
		 }
 }
 
 /*****************************************************************************
函数名称：fucCompareValue
函数功能：检查两个对象的值是否一致
参数	：obj1,对象1
参数	：obj2,对象2
参数	：strAddress,提示信息
返回    ：消息提示框  true/false
日期	：2004-03-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCompareValue(obj1,obj2,strAlertMsg)
 {
		strValue1=obj1.value;
		strValue2=obj2.value;
		strValue1=strValue1.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
		strValue2=strValue2.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
				
		if(strValue1!=strValue2)
		{
		   alert(strAlertMsg);
		   obj1.focus();	
		   return false;	
		 }
		 else
		 {
		    return true;
		 }
 }
 
 /*****************************************************************************
函数名称：fucCheckLength
函数功能：判断字符串的长度是否已经超出制定的范围
参数	：obj,要检查的对象
参数	：iStrMax,字符串约束的最大长度
参数	：strAlertMsg 要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-20
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckLength(obj,iStrMax,strAlertMsg)
{
	strTemp=obj.value;
	strTemp=strTemp.replace(/"/,"&quot");
	strTemp=strTemp.replace(/</g,"&lt");
	strTemp=strTemp.replace(/>/g,"&gt");
	strTemp=strTemp.replace(/'/g,"''");
	strTemp=strTemp.replace(/\n/g,"<br>");
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++)
	{
		//如果是标准字符，占一个字符长度
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else  //如果是非标准字符（汉字），占两个字符长度
			sum=sum+2;
	}
	
	if(sum>iStrMax)
	{
	  //超出了约束的最大字符长度
	   alert(strAlertMsg);
	   obj.focus();
	   return false;
	}
	else
	{
	   return true;
	}
		
}

 /*****************************************************************************
函数名称：fucCheckLength
函数功能：判断字符串的长度是否为指定的范围
参数	：obj,要检查的对象
参数	：iStrLength,字符串约束的长度
参数	：strAlertMsg 要显示的提示信息
返回    ：消息提示框  true/false
日期	：2005-2-5
作者    ：刘朝辉
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckDimLength(obj,iStrLength,strAlertMsg)
{
	strTemp=obj.value;
	strTemp=strTemp.replace(/"/,"&quot");
	strTemp=strTemp.replace(/</g,"&lt");
	strTemp=strTemp.replace(/>/g,"&gt");
	strTemp=strTemp.replace(/'/g,"''");
	strTemp=strTemp.replace(/\n/g,"<br>");
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++)
	{
		//如果是标准字符，占一个字符长度
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else  //如果是非标准字符（汉字），占两个字符长度
			sum=sum+2;
	}
	
	if(sum!=iStrLength)
	{
	  //超出了约束的最大字符长度
	   alert(strAlertMsg);
	   obj.focus();
	   return false;
	}
	else
	{
	   return true;
	}
		
}

 /*****************************************************************************
函数名称：fucCheckLength
函数功能：判断字符串的长度是否为指定的范围(不提示）
参数	：obj,要检查的对象
参数	：iStrLength,字符串约束的长度
参数	：strAlertMsg 要显示的提示信息
返回    ：消息提示框  true/false
日期	：2005-2-5
作者    ：刘朝辉
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckDimLengthNoMsg(obj,iStrLength)
{
	strTemp=obj.value;
	strTemp=strTemp.replace(/"/,"&quot");
	strTemp=strTemp.replace(/</g,"&lt");
	strTemp=strTemp.replace(/>/g,"&gt");
	strTemp=strTemp.replace(/'/g,"''");
	strTemp=strTemp.replace(/\n/g,"<br>");
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++)
	{
		//如果是标准字符，占一个字符长度
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else  //如果是非标准字符（汉字），占两个字符长度
			sum=sum+2;
	}
	
	if(sum!=iStrLength)
	{
	  //超出了约束的最大字符长度
	   return false;
	}
	else
	{
	   return true;
	}
		
}

/*****************************************************************************
函数名称：fucCheckObjAndNull
函数功能：检查两个对象中的值不同时为空
参数	：strObj1 对象的ID
参数	：strObj2  对象的ID
参数	：strAlertMsg 要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-30
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckObjAndNull(strObj1,strObj2,strAlertMsg)
{
        var obj1=document.all[strObj1];
		var strTmp1="";		
		if(obj1!=null)
		{
		  strTmp1=obj1.value;
		}
		
		var obj2=document.all[strObj2];
		var strTmp2="";
		if(obj2!=null)
		{
		  strTmp2=obj2.value;
		}
		
		//检查不同时为空
		strTemp1=strTemp1.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
        strTemp2=strTemp2.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
        if ((strTemp1.length<1) && (strTemp2.length<1))
		{
		    strObj1.focus();
			alert(strAlertMsg);
			return false;
		}
		else
	    {
	      return true;
	    }
		
}

/*****************************************************************************
函数名称：fucCheckDateFormat
函数功能：验证输入日期的格式是否正确,如2003-09-01 或 空
参数	：obj,要检查的对象
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckDateFormat(obj,strAlertMsg)
{
    strDate=obj.value;
    strDate=strDate.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
    
   //验证规则：长日期格式，不足用0补齐，如2003-09-01
    var newPar=/^\d{4}\-\d{2}\-\d{2}$/
    if(strDate.length>0 && newPar.test(strDate)==false)
    {
        obj.focus();
		alert(strAlertMsg);	
	    return false;
	}
	else
	{
	   return true;
	}
		
}

/*****************************************************************************
函数名称：fucCheckTimeFormat
函数功能：验证输入日期的格式是否正确,如 hh:ss 或 空
参数	：strTime,要检查的对象
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-11-20
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckTimeFormat(obj,strAlertMsg)
{
    strTime=obj.value;//日期字符串
    strTime=strDate.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
    
   //验证规则：时间格式(只到分) hh:mm
    var newPar=/^([0,1][0-9])|[2][0-3]:[0-5][0-9]$/
    if(strTime.length>0 && newPar.test(strTime)==false)
    {
        obj.focus();
		alert(strAlertMsg);	
	    return false;
	}
	else
	{
	   return true;
	}
		
}



/*****************************************************************************
函数名称：fucCheckDateOrder
函数功能：验证开始日期必须在结束日期之后(比较的日期格式：2003-09-01)
参数	：strDate,开始日期字符串
参数	：strEDate,结束日期字符串
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckDateOrder(objSDate,objEDate,strMsg)
{
    strSDate=objSDate.value;//日期字符串
    strSDate=strDate.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
    
    strEDate=objEDate.value;//日期字符串
    strEDate=strEDate.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
    
    strSDate=strSDate.replace(/\-/,"\/");
    strEDate=strEDate.replace(/\-/,"\/");
    
    if(strMsg==""||strMsg==null)
    {
       strMsg="您输入的开始日期在结束日期之后！";
    }
   
   //比较时间
    if(new Date(strSDate).getTime()>new Date(strEDate).getTime())
    {
        objEDate.focus();
        alert(strMsg);
        return false;
     }
     else
     {
        return true;
     }
}

/*****************************************************************************
函数名称：fucIsInteger
函数功能：检查是否为 空 或 整数
参数	：obj,要验证的数值
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucIsInteger(obj,strAlertMsg)
 {
        strInteger=obj.value;//要验证的数值
        strInteger=strInteger.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
        
		//验证规则：整数
		var newPar=/^(-|\+)?\d+$/
		if(strInteger.length>0 && newPar.test(strInteger)==false)
		{
		   obj.focus();
		   alert(strAlertMsg);	
		   return false;	
		 }
		 else
		 {
		    return true;
		 }
 }
		
/*****************************************************************************
函数名称：fucIsFloat
函数功能：检查是否为 空 或 有效数值（实数）
参数	：obj,要验证的数值
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucIsFloat(obj,strAlertMsg)
 {
        strFloat=obj.value;//要验证的数值
        strFloat=strFloat.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
        
		//验证规则：整数
		var newPar=/^(-|\+)?\d*.?\d+$/
		if(strFloat.length>0 && newPar.test(strFloat)==false)
		{
		   obj.focus();
		   alert(strAlertMsg);	
		   return false;	
		 }
		 else
		 {
		    return true;
		 }
 }
 
/*****************************************************************************
函数名称：fucIsUnsignedInteger
函数功能：检查是否为 空 或 正整数
参数	：obj,要验证的数值
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucIsUnsignedInteger(obj,strAlertMsg)
 {
		strInteger=obj.value;//要验证的数值
        strInteger=strInteger.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
        
		//验证规则：正整数
		var newPar=/^\d*[123456789]\d*$/
		if(strInteger.length>0 && newPar.test(strInteger)==false)
		{
		   obj.focus();
		   alert(strAlertMsg);	
		   return false;	
		 }
		 else
		 {
		    return true;
		 }
 }
 
 /*****************************************************************************
函数名称：fucIsUnsignedInteger
函数功能：检查是否为 空 或 非负数
参数	：obj,要验证的数值
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucIsNoUnsignedInteger(obj,strAlertMsg)
 {
		strInteger=obj.value;//要验证的数值
        strInteger=strInteger.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
        
		//验证规则：非负数
		var newPar=/^\d+$/
		if(strInteger.length>0 && newPar.test(strInteger)==false)
		{
		   obj.focus();
		   alert(strAlertMsg);	
		   return false;	
		 }
		 else
		 {
		    return true;
		 }
 }
 
  /*****************************************************************************
函数名称：fucCheckDigitInteger
函数功能：检查字符串的所有位是否均为数字
参数	：obj,要验证的字符串
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckDigitInteger(obj,strAlertMsg)
{
	var strTemp;
	strTemp=obj.value;
	strTemp=strTemp.replace(/"/,"&quot");
	strTemp=strTemp.replace(/</g,"&lt");
	strTemp=strTemp.replace(/>/g,"&gt");
	strTemp=strTemp.replace(/'/g,"''");
	strTemp=strTemp.replace(/\n/g,"<br>");
	var i,result=true;
	var newPar=/^\d+$/
	for(i=0;i<strTemp.length;i++)
	{
		if(strTemp.length>0 && newPar.test(strTemp)==false)
		{
			result=false;
			break;
		}
	}
	
	if(result==false)
	{
		obj.focus();
		alert(strAlertMsg);
	}
	
	return result;
}

/*****************************************************************************
函数名称：fucCheckHTML
函数功能：检查是否为正确的HTML文件发布路径
参数	：obj,要检查的字符串地址
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckHTML(obj)
 {
		strAddress=obj.value;//要检查的字符串地址
		strAddress=strAddress.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
				
		//匹配规则：
		//只允许以http:\\开头
		//以.htm或html结尾
		var newPar=/^[hH][tT]{2}[pP]:(\/|\\){2}(\w|.|-|\/|\\)+(\/|\\)(\w|-)+.[hH][tT][mM](l|L)*$/
		if(strAddress.length>0 && newPar.test(strAddress)==false)
		{
		   obj.focus();
		   alert("请输入正确的html发布地址！");	
		   return false;	
		 }
		 else
		 {
		    return true;
		 }
 }
 
 /*****************************************************************************
函数名称：getNowDate
函数功能：检查是否为空
返回    ：当前日期:yyyy-mm-dd
日期	：2003-10-17
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function getNowDate()
{
	var today=new Date();
	year = today.getUTCFullYear(); 
	month =today.getUTCMonth()+1; 
	day = today.getUTCDate(); 
	if (month <= 9) month = "0" + month; 
	if (day <= 9) day = "0" + day; 
	var clocktext =year+"-"+month+"-"+day;
	return clocktext;
}
 

/*****************************************************************************
函数名称：getNowTime
函数功能：获取当前时间 
返回    ：当前日期:yyyy-mm-dd hh:mm:ss
日期  ：2003-11-17
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function getNowTime()
{
    var today=new Date();					//获取当前的日期实例
	var year = today.getUTCFullYear();		//年
	var month =today.getUTCMonth()+1;		//月
	var day = today.getUTCDate();			//日
	var hour=today.getHours();				//时
	var minute=today.getMinutes();			//分
	var second=today.getSeconds();			//秒
	if (month <= 9) month = "0" + month; 
	if (day <= 9) day = "0" + day;
	if (hour <= 9) hour = "0" + hour;
	if (minute <= 9) minute = "0" + minute;
	if (second <= 9) second = "0" + second;
	var clocktext =year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
	return clocktext;
}

/*****************************************************************************
函数名称：fucCheckDateEnable
函数功能：验证输入日期的格式是否正确,如2003-09-01 或 空
参数	：obj,要检查的对象
参数	：strAlertMsg, 出错时要显示的提示信息
返回    ：消息提示框  true/false
日期	：2003-10-21
作者    ：金晶
修改人  ：
修改日  ：
******************************************************************************/
function fucCheckDateEnable(obj,strAlertMsg)
{
    strDate=obj.value;
    strDate=strDate.replace(/^(\s)*|(\s)*$/g,"");//去掉字符串两边的空格
    
   //验证规则：长日期格式，不足用0补齐，如2003-09-01
    var newPar=/^\d{4}\-\d{2}\-\d{2}$/
    if(strDate.length>0 && newPar.test(strDate)==false)
    {
        obj.focus();
		alert(strAlertMsg);	
	    return false;
	}
	else
	{
		var datearray = strDate.split("-");
		var year = parseInt(datearray[0]); 
		var month = parseInt(datearray[1]); 
		var day = parseInt(datearray[2]);
		if ((year > 9999) || (year < 100)) 
		{ 
			obj.focus();
			alert(strAlertMsg);	
			return false;
		} 
		else if ((month > 12) || (month < 1)) 
		{ 
			obj.focus();
			alert(strAlertMsg);	
			return false;
		} 
		else 
		{ 
			switch (month) 
			{ 
				case 1: 
				case 3: 
				case 5: 
				case 7: 
				case 8: 
				case 10: 
				case 12: 
				if ((day < 1) || (day > 31)) 
				{ 
					obj.focus();
					alert(strAlertMsg);	
					return false;
				} 
				break;
				
				case 4: 
				case 6: 
				case 9: 
				case 11: 
				if ((day < 1) || (day > 30)) 
				{ 
					obj.focus();
					alert(strAlertMsg);
					return false;
				} 
				break; 
				default: 
				if ((year % 100 == 0) && (year % 4 == 0)) 
				{ 
					if ((day < 1) || (day > 29)) 
					{ 
						obj.focus();
						alert(strAlertMsg);
						return false;
					} 
				} 
				else 
				{ 
					if ((day < 1) || (day > 28)) 
					{ 
						obj.focus();
						alert(strAlertMsg);
						return false;
					} 
				} 
			}
		}
	}
	return true;	
}
