/** form非空判断 */
function checkElementToMessage(){
	if(arguments[0]){
		for (var i = 1; i < arguments.length; i++) {
			var el = arguments[i];
	        if (el != "" && el.indexOf('|')>=0) {
	            if($("#" + el.split('|')[0]).val()==""){
	        	    alert(el.split('|')[1]);
	        	    return false;
	        	}
			}
		}
	}
	return arguments[0];
}
//校驗是否是數字，傳入object的id
function isNum(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if ("" == s){
		return true;
	} 
	if (isNaN(s)) {
		//object.value = "";
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}

//校驗是否是數字，傳入object的id，可以為空
function isNumCanNull(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if ("" == s){
		return true;
	} 
	if(isNaN(s)) {
		//object.value = "";
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}

//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-”
function isTel(id, popMsg) {
//国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)" 
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
	//var pattern=/^(1[3,5,8,7]{1}[\d]{9})|((([4,8]00)-(\d{3,4})-(\d{3,4}))|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{3,7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
	//var pattern=/(^[0-9]{3,4}\-[0-9]{7,8}\-[0-9]{3,4}$)|(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}\-[0-9]{3,4}$)|(^[0-9]{7,15}$)/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			alert(popMsg);
			//object.value = "";
			object.focus();
			return false;
		}
	}
	return true;
}
//校驗email
function isEmail(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[a-zA-Z0-9_\-.]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			//object.value = "";
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

//校验手机号码：必须以数字开头，除数字外，可含有“-”  
//支持除154号段外所有11位数手机号码，支持手机号前加86,17951,支持普通电话号码但要用-把区号和号码分隔
function isMobile(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var reg0 = /^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/;
	var reg1 = /^(0|86|17951)?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/;
	var reg2 = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
	var reg3 = /^([4,8]00)-(\d{4})-(\d{3})$/;
	var my = false;
	
	if (reg0.test(s)) {
		my = true;
	}
	if (reg1.test(s)) {
		my = true;
	}
	if (reg2.test(s)) {
		my = true;
	}
	if (reg3.test(s)) {
		my = true;
	}
	if ("" != s) {
		if (!my) {
			//object.value = "";
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//校验(国内)邮政编码   
function isPostalCode(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[0-9]{6}$/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			//object.value = "";
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//校验日期  2009-01-01 或 2009/01/01或20090101 是正確格式
//並把input欄位的值改為yyyy/MM/dd格式 
function isDate(id,popMsg){
var object = document.getElementById(id);
	var s = object.value;
	var result1 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(10|12|0?[13578])(\/)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(11|0?[469])(\/)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(0?2)(\/)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(\/)(0?2)(\/)(29)$)|(^([3579][26]00)(\/)(0?2)(\/)(29)$)|(^([1][89][0][48])(\/)(0?2)(\/)(29)$)|(^([2-9][0-9][0][48])(\/)(0?2)(\/)(29)$)|(^([1][89][2468][048])(\/)(0?2)(\/)(29)$)|(^([2-9][0-9][2468][048])(\/)(0?2)(\/)(29)$)|(^([1][89][13579][26])(\/)(0?2)(\/)(29)$)|(^([2-9][0-9][13579][26])(\/)(0?2)(\/)(29)$))/);
	var result2 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/);         
    var result3 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(10|12|0[13578])(3[01]|[12][0-9]|0[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(11|0[469])(30|[12][0-9]|0[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(02)(2[0-8]|1[0-9]|0[1-9])$)|(^([2468][048]00)(02)(29)$)|(^([3579][26]00)(02)(29)$)|(^([1][89][0][48])(02)(29)$)|(^([2-9][0-9][0][48])(02)(29)$)|(^([1][89][2468][048])(02)(29)$)|(^([2-9][0-9][2468][048])(02)(29)$)|(^([1][89][13579][26])(02)(29)$)|(^([2-9][0-9][13579][26])(02)(29)$))/);
	if ("" != object) {
		if(result1!=null){
			object.value = composeCalendar(s,"\/");
		}else if(result2!=null){
			object.value = composeCalendar(s,"-");
		}else if(result3!=null){
			object.value = s.substring(0,4)+"\/"+s.substring(4,6)+"\/"+s.substring(6,8);
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

//校验日期  2009-01 或 2009/01或200901 是正確格式
//並把input欄位的值改為yyyy/MM格式 
function isDateyyyyMM(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var result1 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(10|12|0?[13578])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(11|0?[469])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(0?2)$)|(^([2468][048]00)(\/)(0?2)$)|(^([3579][26]00)(\/)(0?2)$)|(^([1][89][0][48])(\/)(0?2)$)|(^([2-9][0-9][0][48])(\/)(0?2)$)|(^([1][89][2468][048])(\/)(0?2)$)|(^([2-9][0-9][2468][048])(\/)(0?2)$)|(^([1][89][13579][26])(\/)(0?2)$)|(^([2-9][0-9][13579][26])(\/)(0?2)$))/);
	var result2 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)$)|(^([2468][048]00)(-)(0?2)$)|(^([3579][26]00)(-)(0?2)$)|(^([1][89][0][48])(-)(0?2)$)|(^([2-9][0-9][0][48])(-)(0?2)$)|(^([1][89][2468][048])(-)(0?2)$)|(^([2-9][0-9][2468][048])(-)(0?2)$)|(^([1][89][13579][26])(-)(0?2)$)|(^([2-9][0-9][13579][26])(-)(0?2)$))/);         
    var result3 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(10|12|0?[13578])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(11|0?[469])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(0?2)$)|(^([2468][048]00)(0?2)$)|(^([3579][26]00)(0?2)$)|(^([1][89][0][48])(0?2)$)|(^([2-9][0-9][0][48])(0?2)$)|(^([1][89][2468][048])(0?2)$)|(^([2-9][0-9][2468][048])(0?2)$)|(^([1][89][13579][26])(0?2)$)|(^([2-9][0-9][13579][26])(0?2)$))/);         
	if ("" != object) {
		if(result1!=null){
			object.value = composeYYYYMM(s,"\/");
		}else if(result2!=null){
			object.value = composeYYYYMM(s,"-");
		}else if(result3!=null){
			object.value = s.substring(0,4)+"\/"+s.substring(4,6);
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

function composeCalendar(ca,delimiter){
	var idx = ca.indexOf(delimiter);
	var len = ca.length; 
	var year = ca.substring(0,idx);
	ca = ca.substring(idx+1,len);
	idx = ca.indexOf(delimiter);
	var month = ca.substring(0,idx);
	var day = ca.substring(idx+1,len);
	if(month.length<2){
		month = "0"+month;
	}
	if(day.length<2){
		day = "0"+day;
	}
	return year+"\/"+month+"\/"+day;
}

function composeYYYYMM(ca,delimiter){
	var idx = ca.indexOf(delimiter);
	var len = ca.length; 
	var year = ca.substring(0,idx);
	month = ca.substring(idx+1,len);
	if(month.length<2){
		month = "0"+month;
	}
	return year+"\/"+month;
}
//校驗時間是，hhss 12:01  1201都是正確的
//校驗後時間格式變為hh:ss
function isHHSS(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		var result1 = s.match(/((^(0|1)[0-9][0-5][0-9]$)|(^2[0-3][0-5][0-9]$)|(^(0|1)[0-9]:[0-5][0-9]$)|(^2[0-3]:[0-5][0-9]$))/);
		if(result1!=null){
			if(s.length == 4){
				object.value = s.substring(0,2)+":"+s.substring(2,4);
			}
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//檢核輸入值不得大於系統日
function isSystemDate(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var myDate  = new Date(); 
	var yy = myDate.getYear() +""; 
	var mm = myDate.getMonth() + 1+"";
	var dd = myDate.getDate()+""; 
	if(mm.length<2){
		mm="0"+mm;
	}
	if(dd.length<2){
		dd="0"+dd;
	}
	
	var nowDateFormat=yy+"/"+mm+"/"+dd;
	if(s!=null && ""!=s) {
		if(s <= nowDateFormat){
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

//不能為空
function dateNotEmpty(value, popMsg){
	var patrn= /.*\s+.*/;
	if (patrn.exec(value) || value == ''){
		alert(popMsg);
	 	return false; 
	}else{
		return true;
	} 
}
//校驗欄位長度不能大於len
function checklength(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l > len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}

//校驗欄位長度不能大於len，可以为空
function checklengthnotnull(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l > len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}

//校驗欄位長度不能小於len
function checklengthnotLt(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l < len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}

//校驗欄位長度不能小於len，可以為空
function checklengthnotLtnotnull(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l < len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}

//校驗欄位長度等於len
function equallength(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
		if (s.length !=  len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	return true;
}
//判断数字与范围，小時為[0~24]的數值資料 
function checkNumHour(id,popMsg){ 
	if(!isNum(id,popMsg)){
		return false;
	}
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=""){
		s = trimVal(s);
		s = parseInt(s);
		if(s >= 0 && s <= 24){ 
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		} 
	} 
	return true;
}
  		
//判断数字与范围，分為[0~59]的數值資料 
function checkNumMinute(id,popMsg){ 
	if(!isNum(id,popMsg)){
		return false;
	}
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=""){ 
		s = trimVal(s);
		s = parseInt(s);
		if(s >= 0 && s <= 59){ 
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		} 
	} 
	return true;
}  		
//必須是數字和字母，以字母開頭
function isAlphaNum(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	var patrn=/^[a-zA-Z]{1}[a-zA-Z0-9_]*$/
	if (!patrn.exec(s)){
		alert(popMsg);
		object.focus();
	 	return false; 
	}else{
		return true;
	} 
} 
//不能為空
function notEmpty(id, popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var flag = false;
	if(s != null) {
		s = trimVal(s);
		if(s == '') {
			flag = true; 
		}
	} else {
		flag = true;
	}
	if(flag) {
		alert(popMsg);
		object.focus();
	 	return false; 
	}
	return true;
}
//校验数字英文，可以为空
function isId1(id, popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[A-Za-z0-9]+$/;
	if(s == ''){
		return true;
	}
	if (!pattern.exec(s)) {
		alert(popMsg);
		object.focus();
		return false;
	}	
	return true;
}

//校验是否标识符
function isId(id, popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	//var pattern = /^[a-zA-Z][a-zA-Z0-9_]+$/;
	var pattern = /^[a-zA-Z0-9_]+$/;
	if (!pattern.exec(s)) {
		alert(popMsg);
		//object.value = "";
		object.focus();
		return false;
	}
	return true;
}
//校验是否合法名称
function isName(id, popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ''){
		return true;
	}
	var pattern = /^[a-zA-Z0-9_\u0391-\uFFE5]+$/;
	if (!pattern.exec(s)) {
		alert(popMsg);
		//object.value = "";
		object.focus();
		return false;
	}
	return true;
}

//檢核時間不能大於當前時間，時間格式為yyyy/mm/dd
function compNowDate(id,popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	var stoday = new Date(); 
	var syear = stoday.getYear().toString(); 
	var smonth = (stoday.getMonth()+1).toString(); 
	var sday = stoday.getDate().toString(); 
	if(smonth.length == 1) 
	{ 
	smonth = "0"+smonth; 
	} 
	if(sday.length == 1) 
	{ 
	sday = "0"+sday; 
	} 
	var strToday = syear+"/"+smonth+"/"+sday;
	if(s>strToday){
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}

//檢核時間不能大於當前時間，時間格式為yyyy/mm
function compNowYYYYMM(id,popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	var stoday = new Date(); 
	var syear = stoday.getYear().toString(); 
	var smonth = (stoday.getMonth()+1).toString(); 
	if(smonth.length == 1) 
	{ 
	smonth = "0"+smonth; 
	} 
	var strToday = syear+"/"+smonth;
	if(s>strToday){
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}

//多元素值比较器
function Compare(smallerId,biggerId,popMsg)
{
	//执行校验方法
	var executeCompare = function()
	{
		var smallerObj = document.getElementById(this.smallerId);
		var biggerObj = document.getElementById(this.biggerId);
		if(smallerObj.value.length>biggerObj.value.length)
		{
			alert(this.popMsg);
			return false;
		}
		if(smallerObj.value>biggerObj.value)
		{
			alert(this.popMsg);
			return false;
		}
		return true;
	}
	this.smallerId = smallerId;
	this.biggerId = biggerId;
	this.popMsg = popMsg;
	this.executeCompare = executeCompare;
}
	
//校驗器，在jsp onload時，先push要校驗的訊息，當校驗時，做execute即可。
//push时,若为多校验则第一个参数输入为"M" or "m"
//当为单校验时参数依次为输入项ID,校验方法,弹出信息.长度选项可选,且需要传入大于0的数字.
//当为多校验时后续参数依次为较小值的输入项目ID,较大值的输入项目ID,弹出的错误信息

function Validator()
{
	//需要校验的ITEM
	this.arr = new Array();
	
	//执行校验方法
	var execute = function()
	{
		for(var index = 0;index< this.arr.length;index = index + 1)
		{
			var obj = this.arr[index];
			if( obj instanceof Item)
			{
				if(obj.len=="0")
				{
					if(!obj.method(obj.elementId,obj.popMsg))
						return false;
				}
				else
				{
					if(!obj.method(obj.elementId,obj.len,obj.popMsg))
						return false;
				}
			}
			else if( obj instanceof Compare)
			{
				if(!obj.executeCompare())
					return false;
			}
		}
		return true;
	}
	
	//单校验时
	//1.校验的输入项目ID
	//2.校验具体方法
	//3.弹出的错误信息
	//4.校验项目长度（可选）
	//多校验时
	//1."M"或"m"
	//2.输入的比较项目应为较小的输入项目ID
	//3.输入的比较项目应为较大的输入项目ID
	//4.弹出的错误信息
	var push = function()
	{
		var compareType = arguments[0];
		if(compareType=="M" || compareType=="m")
			this.arr[this.arr.length] = new Compare(arguments[1],arguments[2],arguments[3]);
		else
		{
			if(arguments.length==4)
				this.arr[this.arr.length] = new Item(arguments[0],arguments[1],arguments[2],arguments[3]);
			else if(arguments.length==3)
				this.arr[this.arr.length] = new Item(arguments[0],arguments[1],arguments[2],"0");
			else
				alert("您输入的参数个数只能为3或4,如该接口有任何问题请联系我");
		}
	}
	
	//移除校验规则
	//若为单校验,则参数为项目ID
	//若为多校验,则参数为较小的输入项目ID,较大的输入项目ID
	var pop = function()
	{	
		for(var index = 0;index< this.arr.length;)
		{
			var obj = this.arr.pop();
			if(obj instanceof Item && arguments.length==1)
			{
				if(obj.elementId==arguments[0])
					continue;
			}
			else if(obj instanceof Compare && arguments.length==2)
			{
				if(obj.smallerId==arguments[0] && obj.biggerId==arguments[1])
					continue;
			}
			index = index + 1;
			this.arr.unshift(obj);
		}
	}
	
	//校验实体
	function Item(elementId,method,popMsg,len)
	{
		this.elementId = elementId;
		this.method = method;
		this.popMsg = popMsg;
		this.len = len;
	}
	this.push = push;
	this.pop = pop;
	this.execute = execute;
}

//去掉前后空白
function trimVal(val){
	if (!val) {
		return "";
	}
	return val.replace(/(^\s*)|(\s*$)/g,"");
}
//校驗數字必須大於等於給定值
function numberGE(id,num,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		if(parseInt(s)<parseInt(num)){
			alert(popMsg);
			return false;
		}else{
			return true;
		}
	}
	return true;
}
//校驗數字必須小於等於給定值
function numberLE(id,num,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		if(parseInt(s)>parseInt(num)){
			alert(popMsg);
			return false;
		}else{
			return true;
		}
	}
	return true;
}
//檢核若有多筆Email時，每筆Email格式是否正確（Email間以傳入的flag來作區隔）
function checkEmails(id, flag, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var rtn = false;
	var pattern = /^[a-zA-Z0-9_\-.]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
	if(s!=null && ""!=s) {
		if(s.indexOf(flag) != -1) {
			var arr = s.split(flag);
			if(arr!=null && arr.length>0) {
				for(i=0; i<arr.length; i++) {
					if("" != arr[i]) {
						if (!pattern.exec(arr[i])) {
							rtn = true;
							break;
						}
					}
				}
				if(rtn) {
					alert(popMsg);
					object.focus();
					return false;
				}
			}
		} else {
			if (!pattern.exec(s)) {
				alert(popMsg);
				object.focus();
				return false;
			}
		}
	}
	return true;
}
//校驗object是否是數組
function isArray(object){   
	return (typeof(object.length) != "undefined");
}  

//校驗checkbox是否被勾選，若沒有一項被勾選，則返回false；否則，返回true
function checkboxNotChecked(name,msg) {
	var object = document.getElementsByName(name);
	if(isArray(object)) {
		var flag = false;
		for(i=0; i<object.length; i++) {
			if(object[i].checked) {
				flag = true;
				break;
			}
		}
		if(!flag) {
			alert(msg);
			return false;
		}
	} else {
		if(!object.checked) {
			alert(msg);
			return false;
		}
	}
	return true;
}
//校驗start必須小於等於end
function isLe(start,end){
	var object1 = document.getElementById(start);
	var object2 = document.getElementById(end);
	if ("" != object1.value && "" != object2.value) {
		if(object1.value <= object2.value){
			return true;
		}else{
			return false;
		}
	}
	return true;
}
//判斷select不為空
function notEmptySelect(sel,popMsg){
	var obj = document.getElementById(sel);
	if (obj.length == 0){
		alert(popMsg);
		return false
	}else{
		return true;
	}
}
//取得系統日期
function getSystemDate(){
	var now = new Date(); //获取系统日期，即Sat Jul 29 08:24:48UTC+0800 2006
	var yy = now.getYear()+""; //截取年，即2006
	var mm = now.getMonth()+ 1 + ""; //截取月，即07
	var dd = now.getDate()+"";//截取日，即29
	if(mm.length<2){
		mm="0"+mm;
	}
	if(dd.length<2){
		dd="0"+dd;
	}
	return yy+"/"+mm+"/"+dd;
}
//返回指定年月最後一天，傳如month=6，實際上是7月
function getLastDay(year,month)   
{   
 var new_year = year;    //取当前的年份   
 var new_month = month;//取下一个月的第一天，方便计算（最后一天不固定）   
 if(month>12)            //如果当前大于12月，则年份转到下一年   
 {   
  new_month -=12;        //月份减   
  new_year++;            //年份增   
 }   
 var new_date = new Date(new_year,new_month,1);                //取当年当月中的第一天   
 var lastDay =  (new Date(new_date.getTime()-1000*60*60*24)).getDate();//获取当月最后一天日期   
 return year+"/"+month+"/"+lastDay;
}

 //计算字符长度,中文占两个字
function calculate_byte(maxLength,complainReason,count) {  
   var nStrLength=document.getElementById(complainReason).value.length;
   /*
    var sTmpStr, sTmpChar;
   var nOriginLen = 0;
   var nStrLength = complainReason.length;
   sTmpStr = new String(complainReason);
   nOriginLen = sTmpStr.length;
   for ( var i=0 ; i < nOriginLen ; i++ ) {
           sTmpChar = sTmpStr.charAt(i);

          if (escape(sTmpChar).length > 4) {
                   nStrLength += 2;
           } else if (sTmpChar!='/r') {
                   nStrLength ++;
           }
   }
   */
  if(nStrLength<=maxLength){
	  document.getElementById(count).innerHTML="已输入："+nStrLength+"/"+maxLength+"字符";
  }else if(nStrLength>maxLength){
	  document.getElementById(complainReason).value=document.getElementById(complainReason).value.substr(0,maxLength);
  }
}