/**
 *@author XieYuchang
 @data 2004-01-25
 @function   check all of status 
 **/
var decimalPointDelimiter = "."
var whitespace = " \t\n\r";
var defaultEmptyOK = false ;
//１２个月份的天数
var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // 需要检验是否闰年
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;



/**
 *是否为空
 **/
function isEmpty ( s ) {
	return ( ( s == null ) || (s.length == 0 )) ;
}
/**
 *是否空格 , 防止输入的全部是空格
 **/
function isWhiteSpace ( s ) {
	var i ; 

	if ( isEmpty ( s ) ) {
		return true ;
	}

	for ( i = 0 ; i < s.length ; ++ i ) {
		var c = s.charAt(i) ;
		if ( whitespace.indexOf( c ) == -1 ) {
			return false ;
		}
	}
	return true ;
}

/**
 *是否字符
 **/
function isLetter ( c ) {
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) ) ;
}

/**
 *是否数字
 **/
function isDigit ( c ) {
	return ((c >= "0") && (c <= "9")) ;
}

/**
 *是否整数
 **/
function isInteger ( s ) {
	var i ; 
	if ( isEmpty(s) ) {
		if ( isInteger.arguments.length == 1 ) {
			return false  ;
		} else {
			return ( isInteger.argument[1] == true ) ;
		}
	}
	//对s一个一个字符的检查，如果有一个位不是数字的就返回false 
	//否则返回true
	for ( i = 0 ; i < s.length ; ++ i ) {
		var c = s.charAt(i) ;
		if ( !isDigit(c)) {
			return false ;
		}
	}
	return true ;
}

/**
 *是否有符号的整数.
 *允许用户输入带有符号的整数，比如 +6 , -4  ,但符号与数字之间不能有空格
 **/
function isSignedInteger ( s ) {
	if ( isEmpty( s ) ) {
		if ( isSignedInteger.arguments.length == 1 ) {
			return false ;
		} else {
			return ( isSignedInteger.arguments[1] == true ) ;
		}
	} else {
		var startPos = 0 ;
		var secondArg = false ;
		
		if ( isSignedInteger.arguments.length > 1 ) {
			secondArg = isSignedInteger.arguments[1] ;
		}

		//去除 + 号和　- 号
		if ( ( s.charAt( 0 ) == "-") || ( s.charAt(0) == "+") ) {
			startPos = 1 ;
		}
		
		return ( isIntegr(s.substring(startPos , s.length ) , secondArg ))
	}
}

/**
 *是否正整数,不包括 0
 **/
function isPositiveInteger ( s ) {
	 var secondArg = defaultEmptyOK ;

	 if ( isPositiveInteger.arguments.length > 1 ) {
		 secondArg = isPositiveInteger.arguments[1] ;
	 }

	 return ( isSignedInteger( s , secondArg) 
			&& ( ( isEmpty( s ) && secondArg ) || (parseInt( s ) > 0 ) ) ) ;
} 
/**
 *是否非负数　就是正数和0
 **/
function isNonnegativeInteger ( s ) {
	var secondArg = defaultEmptyOK ;

	if ( isNonnegativeInteger.argumentslength > 1 ) {
		secondArg = isNonnegativeInteger.arguments[1] ;
	}

	return ( isSignedInteger( s , secondArg) 
			&& ( ( isEmpty( s ) && secondArg ) || (parseInt( s ) >= 0 ) ) ) ;
}
/**
 *是否负数
 **/
function isNegativeInteger ( s ) {
	var secondArg = defaultEmptyOK ;

	if ( isNegativeInteger.arguments.length > 1 ) {
		secondArg = isNegativeInteger.arguments[1] ;
	}

	return ( isSignedInteger( s , secondArg) 
			&& ( ( isEmpty( s ) && secondArg ) || (parseInt( s ) < 0 ) ) ) ;

}

/**
 *是否非正数,就是０　和　负数
 **/
function isNonpositiveInteger ( s ) {
	var secondArg = defaultEmptyOK ;

	if ( isNegativeInteger.arguments.length > 1 ) {
		secondArg = isNegativeInteger.arguments[1] ;
	}

	return ( isSignedInteger( s , secondArg) 
			&& ( ( isEmpty( s ) && secondArg ) || (parseInt( s ) <= 0 ) ) ) ;
}


/**
 *是否浮点数
 **/
function isFloat ( s ) {
	var i ; 
	var seenDecimalPoint = false ;
	
	if ( isEmpty(s)) {
		if ( isFloat.arguments.length == 1 ) {
			return false ;
		} else {
			return ( isFloat.argument[1] == true ) ;
		}
	}
	//如果只有一个点，不是复点数
	if ( s == decimalPointDelimiter ) {
		return false ;
	}
    
	for ( i = 0 ; i < s.length ; ++ i ) {
		var c = s.charAt( i ) ;
		if ( ( c == decimalPointDelimiter) 
				&& !seenDecimalPoint ) {
			seenDecimalPoint = true ;
		} else if ( !isDigit(c)){
			return false ;
		}
	}
	return true ;

} 


/**
 *是否email,这里没有用正则表达式来表示 
 **/　
function isEmail ( s ) {
	if ( isEmpty ( s )) {
		if ( isEmail.arguments.length == 1 ) {
			return false ;
		} else {
			return ( isEmail.arguments[1] == true ) ;
		}
	}

	if ( isWhiteSpace( s ) ) {
		return false ;
	}

	var i = 1 ;
	var sLength = s.length ;

    //这里使用的方法是
	//@号是唯一必须的 ， .号也是必须唯一的

	//查找 @ 
	while ( ( i < sLength ) 
				&& ( s.charAt(i) != "@") ) {
		i ++ ;
	}
    //如果没有@返回false ,然后i + 2 ,因为email的@后面至少有２个字符
	if ( ( i >= sLength ) && ( s.charAt(i) != "@") ) {
		return false ;
	} else {
		i += 2 ;
	}
    //查找 . 号
	while ( ( i < sLength ) 
				&& ( s.charAt(i) != ".") ) {
		i ++ ;
	}
    //.号后面最少有一个字符
	if (( i >= sLength - 1) || (s.charAt(i) != ".")) {
		return false ;
	} else  {
		return true ;
	}
}

/**
 *是否年份
 **/
function isYear ( s ) {
	if ( isEmpty ( s ) ) {
		if ( isYear.arguments.length == 1 ) {
			return false ; 
		} else {
			return ( isYear.arguments[1] == true ) ;
		}
	}
	//是否非负整数
	if ( !isNonnegativeInteger( s )  ) {
		return false ;
	}
	//只支持２位和４位的年份
	return ( ( s.length == 2 ) || ( s.length == 4 )) ;
}


/**
 *是否区间数字 , 作为其他函数的一个基本方法
 **/
function isIntegerInRange ( s , start , end ) {
	if ( isEmpty ( s ) ) {
		if ( isIntegrInRange.arguments.length == 1 ) {
			return false ;
		} else {
			return ( isIntegerInRange.arguments[3] == true ) ;
		}
	}
    //是否整数,传入的false表示
	if ( !isInteger( s , false )) {
		return false ;
	}

	var num = parseInt( s ) ;
	return ( ( num >= start ) && ( num <= end)) ;
}

/**
 *是否月份 1-12
 **/
function isMonth ( s ) {
	if ( isEmpty ( s ) ) {
		if ( isMonth.arguments.length == 1 ) {
			return false ;
		} else {
			return (isMonth.arguments[1] == true ) ;
		}
	}

	return isIntegerInRange( s , 1 , 12 ) ;
}

/**
 *是否日期 1-31
 **/
function isDay ( s ) {
	if ( isEmpty ( s ) ) {
		if ( isDay.arguments.length == 1 ) {
			return false ;
		} else {
			return ( isDay.arguments[1] == true ) ;
		}
	}

	return isIntegerInRange( s , 1 , 31 ) ;
}
/**
 *是否闰年
 **/
function isRunYear ( year ) {
	return (  ( year % 4 == 0 ) 
				&& ( ( !( year % 100 == 0 )) || ( year % 400 == 0 )) ) ;
}
/**
 *是否日期 
 **/
function isDate ( year , month , day ) {
	/*
	if ( !( isYear( year , false ) 
			&& isMonth( month , false ) 
			&& isDay( day , false ) ) ) {
		return false ;
	}*/
	alert("到了！！！") ;
	var intYear  = parseInt( year ) ;
	var intMonth = parseInt( month ) ;
	var intDay	 = parseInt( day ) ;
	//日期的天数是否大于所对应的月份的天数
	if ( intDay > daysInMonth[intMonth] ) {
		return false ;
	}
	//是否闰年
	var daysInFebruary = isRunYear ( year ) ? 29 : 28 ;
	// 二月份特殊处理
	if ( ( intMonth == 2 ) && ( intDay > daysInFebruary )) {
		return false ;
	}
	return true ;
}

/**
 *功能较为强大的判断日期
 */
function isDate(str , dateObject) {
		/*允许下面的8种输入格式
		 *YYYY-MM-DD
		 *YYYY/MM/DD 
		 *YYYY\MM\DD
		 *YYYYMMDD
		 *YY-MM-DD
		 *YY/MM/DD
		 *YY\MM\DD
		 *YYMMDD
		 */

        //长度的校验
		if ( str.length != 6 && str.length != 8 && str.length != 10 ) {
			return false ;
		}
		//将str装换为用于判断的格式
		var formatDateStr = "" ;
		if ( str.length == 6 ) {
			if ( isNumber(str)) {
				//判断补上的两位年份 <50 的加上20 ,大于50的加上19
				if( parseInt(str.substring(0,2),10) < 50  ) {
					formatDateStr += "20" + str.substring(0,2) ; 
				} else {
					formatDateStr += "19" + str.substring(0,2) ;
				}
				//月份
				if ( parseInt(str.substring(2,4),10) > 0 && parseInt(str.substring(2,4),10) < 13 ) {
					formatDateStr += "-" + str.substring(2,4) ;	
				} else {
					return false ;
				}
				//日期
				if ( parseInt(str.substring(4),10) > 0 && parseInt(str.substring(4),10) < 32 ) {
					formatDateStr += "-" + str.substring(4) ;	
				} else {
					return false ;
				}
			} else {
				return false ;
			}
		} else if ( str.length == 8) {
			if ( isNumber(str)) {	
				//判断年份不能大于2008和必须小于1950
				if(  parseInt(str.substring(0,4),10) < 2100 && parseInt(str.substring(0,4),10) > 1910 ) {
					formatDateStr += str.substring(0,4) ; 
				} else {
					return false ;
				}
				//月份
				if ( parseInt(str.substring(4,6),10) > 0 && parseInt(str.substring(4,6),10) < 13 ) {
					formatDateStr += "-" + str.substring(4,6) ;	
				} else {
					return false ;
				}
				//日期
				if ( parseInt(str.substring(6),10) > 0 && parseInt(str.substring(6),10) < 32 ) {
					formatDateStr += "-" + str.substring(6) ;	
				} else {
					return false ;
				}			
			} else {
				//有符号的8位日期 判断补上的两位年份 <50 的加上20 ,大于50的加上19
				if( parseInt(str.substring(0,2),10) < 50  ) {
					formatDateStr += "20" + str.substring(0,2) ; 
				} else {
					formatDateStr += "19" + str.substring(0,2) ;
				}
				//月份
				if ( parseInt(str.substring(3,5),10) > 0 && parseInt(str.substring(3,5),10) < 13 ) {
					formatDateStr += "-" + str.substring(3,5) ;	
				} else {
					return false ;
				}
				//日期
				if ( parseInt(str.substring(6),10) > 0 && parseInt(str.substring(6),10) < 32 ) {
					formatDateStr += "-" + str.substring(6) ;	
				} else {
					return false ;
				}
			}
		} else if ( str.length == 10 ) {
				
				//判断年份不能大于2008和必须小于1950
				if(  parseInt(str.substring(0,4),10) < 2100 && parseInt(str.substring(0,4),10) > 1910 ) {
					formatDateStr += str.substring(0,4) ; 
				} else {
					return false ;
				}
				//月份
				if ( parseInt(str.substring(5,7),10) > 0 && parseInt(str.substring(5,7),10) < 13 ) {
					formatDateStr += "-" + str.substring(5,7) ;	
				} else {
					return false ;
				}
				//日期
				if ( parseInt(str.substring(8),10) > 0 && parseInt(str.substring(8),10) < 32 ) {
					formatDateStr += "-" + str.substring(8) ;	
				} else {
					return false ;
				}			
		}
		//返回之前再对日期的合法性作一次判断
		var year = formatDateStr.substring(0,4) ;
		var month = formatDateStr.substring(5,7) ;
		var day = formatDateStr.substring(8,10) ;
		if ( !isTrueDate(year,month,day) ) {
			return false ;
		}
		var datePatten = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/ ;
		var r = formatDateStr.match(datePatten) ; 
		if ( r == null ) {
			return false ;
		} else {
			eval(dateObject).value = formatDateStr ;
			return true ;
		}
	}
/**
 *判断是否数字
 */
function isNumber(str) {
	var mask = /^[0-9]*$/ ;
	var bMatched = mask.exec( str ) ;
	if ( !bMatched ) {
		return false ;
	} else {
		return true ;
	}
}

function isTrueDate ( year , month , day ) {
	
	var intYear  = parseInt( year ) ;
	var intMonth = parseInt( month ) ;
	var intDay	 = parseInt( day ) ;
	//日期的天数是否大于所对应的月份的天数
	if ( intDay > daysInMonth[intMonth] ) {
		return false ;
	}
	//是否闰年
	var daysInFebruary = isRunYear ( year ) ? 29 : 28 ;
	// 二月份特殊处理
	if ( ( intMonth == 2 ) && ( intDay > daysInFebruary )) {
		return false ;
	}
	return true ;
}
/**
 *判断要删除的纪律的js函数
 */

function deleteRecord( url ) {
		if ( confirm("确定要删除纪录吗") ) {
			var haveSelect = false ;
			if ( document.forms[0].checkbox == null ) {
				alert("当前没有纪录") ;
				return ;
			}
			if ( document.forms[0].checkbox.value == null  ) {
				for( i = 0 ; i < document.forms[0].checkbox.length ; ++ i ) {
					if ( document.forms[0].checkbox[i].checked ) {
						haveSelect = true ; 	
					}
				}
				if ( !haveSelect ) {
					alert("你至少选择一条纪录") ;
					return ;
				}
			} else {
				if (document.forms[0].checkbox.checked == false ) {
					alert("你至少选择一条纪录") ;
					return ;
				}
			}
			document.forms[0].action= url ;
			document.forms[0].submit() ;
		}
}

