//函數名  : chkDate 
//功能介紹: 檢查是否為西元日期 
//參數說明: 要檢查的字串值(西元曆) yyyy/mm/dd 
//返回值  : false:不是  true:是 
function chkDate(datestr) { 
    var year, month, day; 
    var pattern = /^\d{4}\/\d{1,2}\/\d{1,2}$/; //d{4}=yyyy/d{1,2}=mm/d{1,2}=dd
    var tmpary  = new Array() ;
    if (!pattern.test(datestr)) {
       window.alert("日期格式錯誤! yyyy/mm/dd");
       return false; 
    }
    
    tmpary = datestr.split("/"); 
    year  = tmpary[0]; 
    month = tmpary[1]; 
    day   = tmpary[2]; 

    if (month<1 || month>12 || day>31 || day<1) {
       window.alert("月份或日期輸入錯誤!");
       return false; 
    }
    
    if (month == 2 && day > 28) { 
        if ((year%4==0 && year%100!=0) || (year%400==0)) { // 為閏年 
            if (day > 29){ 
               window.alert("閏年2月只有29天哦!");
               return false; 
            }
        } 
        else {  // 非閏年 
           window.alert("非閏年2月只有28天哦!");
           return false; 
        } 
    } 
    if (day>30 && ((month % 2) == Math.floor(month/8))){
       window.alert("本月份只有三十天哦!");
       return false; 
    }
    return true; 
} 

//函數名  : chkInt
//功能介紹: 檢查是否為數字 
//參數說明: 要檢查的字串值(西元曆) yyyy/mm/dd 
//返回值  : false:不是  true:是 
function chkInt(intstr)
{
		format=/^[0-9]*$/;
			if(!format.test(intstr))
			{return false;}
		return true;
}

//函數名  : chkEmail
//功能介紹: 檢查是否為數字 
//參數說明: 要檢查的字串值(西元曆) yyyy/mm/dd 
//返回值  : false:不是  true:是 
function chkEmail(strEmail)
{
		format=/^.+@.+\..+$/;
			if(!format.test(strEmail))
			{alert("信箱填寫不正確!");
			return false;
		}
		return true;
}


//函數名  : chkPassword
//功能介紹: 檢查二次密碼是否相同 
function chkPassword(pwd1,pwd2)
{
	if(pwd1=="" && pwd2=="")
	{
		return false;
	}
	if(pwd1==pwd2)
	{
		return true;
	}
	else
	{
		alert("密碼二次輸入不相同!");
		return false;
	}
	
}

//函數名  : chkID
//功能介紹: 檢查身份證字號是否正確 
function chkID( id ) 

{
	id = id.toUpperCase();
   tab = "ABCDEFGHJKLMNPQRSTUVXYWZIO"
   A1 = new Array (1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3 );
   A2 = new Array (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5 );
   Mx = new Array (9,8,7,6,5,4,3,2,1,1);

   if ( id.length != 10 )
   	   {alert("身份證字號錯誤!");
		return false;}
   i = tab.indexOf( id.charAt(0) );
   if ( i == -1 ) 
   	   {alert("身份證字號錯誤!");
		return false;}
   sum = A1[i] + A2[i]*9;

   for ( i=1; i<10; i++ )
   {
      v = parseInt( id.charAt(i) );
      if ( isNaN(v) ) 
   	   {alert("身份證字號錯誤!");
		return false;}
      sum = sum + v * Mx[i];
   }
   if ( sum % 10 != 0 )
   	   {alert("身份證字號錯誤!");
		return false;}
	   return true;
}
//函數名  : chkLetter
//功能介紹: 檢查字母是否正確 
function chkLetter( letter ) 
{
for(i=0;i<letter.length;i++)
	{
		if((letter.charCodeAt(i)<97||letter.charCodeAt(i)>122)&&
		(letter.charCodeAt(i)<48||letter.charCodeAt(i)>57))
		{
			if(letter.charCodeAt(i)!=95)
			chk=false;break;
		}
		else
		chk=true;
	}
if(chk==false)
return false;
else
return true;
}

function chkStudentID(str)
{
if(str.length<=1){return false;}
for(i=1;i<str.length;i++)
	if(str.charCodeAt(i)<48||str.charCodeAt(i)>59)
	{chk=false;break;}
	else
	chk=true;

if(chk==false)
return false;
else
return true;
	
}
function chkWord(word)
{
	format=/^[a-z,A-Z,0-9,_]*$/;
	if (!format.test(word))	 return false;	
	return true;
}
function chkWord2(word)
{
	format=/^[a-z,A-Z,0-9]*$/;
	if (!format.test(word))	 return false;	
	return true;
}

