/*******************************************************/ 
/* 查檢用函數
/* isIDnum;  查檢身份證格式
/* strDateTime;  查檢日期格式
/*******************************************************/ 

  function isIDnum(num) {
    num=num.toLowerCase()
    //先用RE語法檢查輸入的格式是否正確
    patten=/^[a-z][12][0-9]{8}$/
    if(patten.test(num)) {
      h="abcdefghjklmnpqrstuvxywzio"
      x=10+h.indexOf(num.substring(0,1))
      chksum=(x-(x%10))/10+(x%10)*9
      for(i=1;i<9;i++)
         chksum+=num.substring(i,i+1)*(9-i)
      chksum=(10-chksum%10)%10
      if(chksum==num.substring(9,10))
        return true
    }
    return false
  }
  
  function strDateTime(str) {
      var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
      if (r==null)
          return false;

      var d= new Date(r[1], r[3]-1, r[4]);

      return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
  }
  
  
/*******************************************************/ 
/* DaysOfTheMonth,SetCorrectDate; 下拉選單日期設定
/*******************************************************/  
  
/*******************************************************/ 
/* 傳回這個月有幾天 */ 
/*******************************************************/ 
function DaysOfTheMonth (Year_p,Month_p) { 
var Monthday = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
  if ((Year_p % 4 == 0 && Year_p % 100 != 0) || Year_p % 400 == 0) { 
    Monthday[1] = 29;//是閏年 
  } 
  return Monthday[Month_p]; 
} 

/*******************************************************/ 
/* 設定正確的日期 */ 
/*******************************************************/ 
function SetCorrectDate(YearSelect_p,MonthSelect_p,DaySelect_p) { 
//取得使用者所選取的數值 
var Year = eval(YearSelect_p.options[YearSelect_p.selectedIndex].value) + 1911 ; 
//Year = parseInt(Year) + 1911;//變成西元年 
var Month = MonthSelect_p.selectedIndex; 
var Day = DaySelect_p.selectedIndex; 

var DaysOfSelectMonth = DaysOfTheMonth (Year, Month);//這個月有幾天 

var EndDay = DaysOfSelectMonth-1; 

  if ( Day>=EndDay ) { 
    DaySelect_p.options[EndDay].selected = true;//設定選取 
  }

var i = 0; 
var OldDaySelectLength = DaySelect_p.length;  //原來Day的ComboBox的長度 

  //原來Day的ComboBox的長度>這個月應有的天數 
  if ( OldDaySelectLength>DaysOfSelectMonth ) { 
    //將這個月多餘的天數去掉 
    for ( i=DaysOfSelectMonth ; i<OldDaySelectLength; i++ ) { 
      DaySelect_p.options[i] = null; 
    } 
    DaySelect_p.length = DaysOfSelectMonth;//設定天數ComboBox的新長度 
    //return 0; 
  } 

  //原來Day的ComboBox的長度<這個月應有的天數
  if ( OldDaySelectLength<DaysOfSelectMonth ) { 
    //補上短缺的天數 
    for ( i=OldDaySelectLength; i<DaysOfSelectMonth ; i++ ) { 
      DaySelect_p.options[i] = new Option (i+1, i+1); 
    } 
  } 
}

