<!--
/*************************************************************
'Filename         : function.js
'Author           : Jamin Lin (林志明)(System Analyst)
'Date of creation : 2002/05/17
'Version          : 0.7
'Purpose          : Javascript Function
'Date modified    : 2003/07/22
'What has been changed (include date/name of author) :
'Remark			  : (1)2003/07/22 modify check_ID Function
'			      : (2)2003/09/23 Add 兩個值比較
'*************************************************************/

//檢查Password和確認密碼欄位格式
function check_word(h1,h2,meg){
 if(h1!=h2) return true;
 else {alert(meg);
 return false;}
} 



//檢查欄位是否空白
function check_space(a,meg){
 if(a!='' && a.length>=0) return true;
 else {alert(meg);
   return false;}
}


//檢查Radio是否空白
function check_sex(e,e1,meg){
 if(e==true || e1==true) return true;
 else {alert(meg);
 return false;}
}


//檢查E-mail欄位格式
function email(b,meg){
 if(b.indexOf("@")==-1 || b.indexOf(".")==-1 || b.indexOf(" ")!=-1 || b.indexOf(",")!=-1 || b.length<3 ) 
 {alert(meg); 
  return false;}
else return true;}


//檢查Password欄位格式
function password(c,meg){
 if(c!='' && c.length>=4) return true;
 else {alert(meg); 
 return false;}
} 


//檢查Password和確認密碼欄位格式
function passwordcheck(h1,h2,meg){
 if(h1==h2) return true;
 else {alert(meg);
 return false;}
} 


//檢查身份證字號欄位格式
function ids() {
  this.A=1;this.B=0;this.C=9;this.D=8;this.E=7;
  this.F=6;this.G=5;this.H=4;this.J=3;this.K=2;
  this.L=2;this.M=1;this.N=0;this.P=9;this.Q=8;
  this.R=7;this.S=6;this.T=5;this.U=4;this.V=3;
  this.X=3;this.Y=2;this.W=1;this.Z=0;this.I=9;this.O=8;
}
 var id=new ids;


function check_ID(c){ 
        
	    if (c==''){
			alert('請輸入您的身份證字號!!');
			return false;
		}
		
		if (c.length!= 10) {
                alert("很抱歉喔!身份證字號格式不對!");
                return false;
        }
        
        c=(c.charAt(0)).toUpperCase()+c.substring(1,10);
        var cs=id[c.charAt(0)];
        for (var i=1;i<10;i++) {
                var d=c.charAt(i);
                cs=cs+d*(9-i);
                if (d<"0" || d>"9") {
                alert("很抱歉喔!身份證字號格式不對!");
                return false;
                }
        }
        cs=cs+d*1;
        if ((cs % 10) != 0) {
             alert("很抱歉喔!身份證字號檢查碼不對!");
             return false;	
        }   
        return true;    
}
      
        
//檢查UserName欄位格式
function username(obj) {
    var checkStr = obj.value	// 驗證字串
    var checkOK = "abcdefghijklmnopqrstuvwxyz"	// 合法字元
    var allValid = true
    var allNum = ""
	obj.value = obj.value.toLowerCase()
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
	  	alert("你的帳號不是英文字ㄟ")
		obj.focus();
        return false
      }
      allNum += ch
    }
    return true
}


//開啟新視窗
function OpenWin(url,w,h,l,t){
        Newwin=window.open(url,"win","menubar=0,toolbar=0,loaction=0,directories=0,status=0,scrollbars=0,resizeable=1,width="+w+",height="+h+",left="+l+",top="+t+"");
        Newwin.focus();
}   

//開啟新視窗
function OpenWinSc(url,scrollbars,w,h,l,t){
        NewwinSc=window.open(url,"win","menubar=0,toolbar=0,loaction=0,directories=0,status=0,scrollbars="+scrollbars+",resizeable=1,width="+w+",height="+h+",left="+l+",top="+t+"");
        NewwinSc.focus();
}

//檢查username欄位格式
function checkUsernameFormat(obj, msg) {
    var checkStr = obj.value	// 驗證字串
    var checkOK = "abcdefghijklmnopqrstuvwxyz1234567890"	// 合法字元
    var allValid = true
    var allNum = ""
	obj.value = obj.value.toLowerCase()
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
	  	alert(msg)
		obj.focus();
        return false
      }
      allNum += ch
    }
    return true
}

//檢查Radio欄位temp
function checkRadio4(obj, msg) {
    len = obj.length;
	for(i=0;i<len;i++)
		if(obj[i].checked == true)
			return true
	alert(msg)
	return false
}



//檢查Radio欄位
function checkRadio(obj, msg) {
    len = obj.length;
    if (isNaN(len)==false){ 
	for(k=0;k<len;k++)
           if(obj[k].checked == true)
            return true
	    alert(msg)
	    return false
    }else{
     if(obj.checked == true)
            {return true;}
            else{
	    alert(msg);
	    return false;}
    }
}



//設定checkbox欄位
function ToggleAll(obj,checked) {
    len = obj.length;
    if (isNaN(len)==false){
      var i = 0;
      for(i = 0; i < len; i++) {
          obj[i].checked = checked;
      }
    }else{
      obj.checked = checked
    }
}



//檢查Text欄位是否小於指指定長度
function Check_Text_Smaller_Length(obj, len, msg) {
	if(obj.value.length <= len)
		return true
	alert(msg)
	obj.focus()
	obj.select()
	return false
}


//檢查Text欄位是否大於指指定長度
function Check_Text_Greater_Length(obj, len, msg) {
	if(obj.value!='' && obj.value.length >= len)
		return true
	alert(msg)
	obj.focus()
	obj.select()
	return false
}


//檢查數字格式
function checkNumberFormat(obj, msg) {
    var checkStr = obj.value	// 驗證字串
    var checkOK = "1234567890"	// 合法字元
    var allValid = true
    var allNum = ""
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
	  	alert(msg)
		obj.focus();
        return false
      }
      allNum += ch
    }
    return true
}


//檢查 E-mail 格式
function checkEmailFormat(obj, msg) {
	if (obj.value.length > 0)
	{
		at = obj.value.indexOf("@")
		dot = obj.value.indexOf(".",at)
		len = obj.value.length
		comma = obj.value.indexOf(",")
		space = obj.value.indexOf(" ")
		lastToken = obj.value.lastIndexOf(".") + 1
		if ((at <= 0) || (dot <= (1+1)) || (comma != -1) || (space != -1) || (len-lastToken < 2) || (len-lastToken > 3)) {
			alert(msg)
			obj.focus()
			return false	// 格式錯誤
		}
	} else {
		alert(msg)
		obj.focus()
		return false	// 無填寫資料
	}
	return true
}

//功能表收縮功能
//------------------------------
function Menu_founction(in_menu,switch_img)
{
  if (in_menu.style.display=="block")
  {
    in_menu.style.display="none";
    switch_img.src="img/on.gif"; 
    switch_img.title="按我打開來";
  }else{
    in_menu.style.display="block";
    switch_img.src="img/off.gif"; 
    switch_img.title="按我縮起來";  
  }
} 
//------------------------------


// 檢查日期格式正確與否
// ***************************************************************** 
function getFormatDate(strMsg,strYear,strMonth,strDay,strTime){
	var strDate,arrDate,comDate;
	if (strYear.length < 4){
		if (parseInt(strYear,10) <= 0){
			alert(strMsg + "年份需大於零!!");
			return "";
		}
		strYear = "" + (parseInt(strYear,10)+1911);
	}else{
		if (parseInt(strYear,10) < 1911){
			alert(strMsg + "年份需大於1911!!");
			return "";
		}
	}
	strDate = strYear +"/"+ strMonth +"/"+ strDay;
	if (strTime == ''){
		comDate = new Date(strDate);
	}else{
		comDate = new Date(strDate +" "+ strTime);
	}
    arrDate = strDate.split("/");
    
    if ((comDate.getMonth()+1) != parseInt(arrDate[1],10)){
        alert(strMsg + "格式錯誤!!");
		return "";
    }
	return comDate;
}

//E-Mail格式檢查
// ***************************************************************** 
function chkEmail(emailTag){
	//var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
        var pattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (!pattern.test(emailTag.value)) {
		alert("E-mail格式錯誤!!");
		emailTag.focus();
		return false;
	}else{
		return true;
	}
}

//電話格式檢查
// ***************************************************************** 
function chkTel(telTag){
	//var pattern = /^([0-9]|[\-])+$/g;
	var pattern = /^([0-9]|[\-])+$/;
	if (!pattern.test(telTag.value) || telTag.value.length<7) {
		alert("電話格式錯誤!!");
		telTag.focus();
		return false;
	}else{
		return true;
	}
}

//縣市/郵遞區號
// ***************************************************************** 
var county,zone,postCode;
county=new Array("台北市", "基隆市", "新北市", "宜蘭縣", "新竹市", 
		"新竹縣", "桃園縣", "苗栗縣", "台中市", "彰化縣",
		"南投縣", "嘉義市", "嘉義縣", "雲林縣", "台南市",
		"高雄市", "澎湖縣", "屏東縣", "台東縣", "花蓮縣",
		"金門縣", "連江縣", "南海諸島", "釣魚台列嶼");
zone=new Array(24);
postCode=new Array(24);
// for "台北市"
zone[0]=new Array("中正區","大同區","中山區","松山區","大安區","萬華區",
		"信義區","士林區","北投區","內湖區","南港區","文山區");
// for "基隆市"
zone[1]=new Array("仁愛區","信義區","中正區","中山區","安樂區","暖暖區","七堵區");
// for "新北市"
zone[2]=new Array("萬里區","金山區","板橋區","汐止區","深坑區","石碇區","瑞芳區",
		"平溪區","雙溪區","貢寮區","新店區","坪林區","烏來區","永和區","中和區","土城區",
		"三峽區","樹林區","鶯歌區","三重區","新莊區","泰山區","林口區","蘆洲區","五股區",
		"八里區","淡水區","三芝區","石門區");
// for "宜蘭縣"
zone[3]=new Array("宜蘭市","頭城鎮","礁溪鄉","壯圍鄉","員山鄉","羅東鎮","三星鄉",
		"大同鄉","五結鄉","冬山鄉","蘇澳鎮","南澳鄉");
// for "新竹市"
zone[4]=new Array("新竹市");
// for "新竹縣"
zone[5]=new Array("竹北市","湖口鄉","新豐鄉","新埔鄉","關西鎮","芎林鄉","寶山鄉",
		"竹東鎮","五峰鄉","橫山鄉","尖石鄉","北埔鄉","峨嵋鄉");
// for "桃園縣"
zone[6]=new Array("中壢市","平鎮市","龍潭鄉","楊梅鎮","新屋鄉","觀音鄉","桃園市",
		"龜山鄉","八德市","大溪鎮","復興鄉","大園鄉","蘆竹鄉");
// for "苗栗縣"
zone[7]=new Array("竹南鎮","頭份鎮","三灣鄉","南庄鄉","獅潭鄉","後龍鎮","通霄鎮","苑裡鎮","苗栗市",
		"造橋鄉","頭屋鄉","公館鄉","大湖鄉","泰安鄉","銅鑼鄉","三義鄉","西湖鄉","卓蘭鄉");
// for "台中市"
zone[8]=new Array("中區","東區","南區","西區","北區","北屯區","西屯區","南屯區",
		"太平區","大里市","霧峰區","烏日區","豐原區","后里區","石岡區",
		"東勢區","和平區","新社區","潭子區","大雅區","神岡區","大肚區","沙鹿區","龍井區",
		"梧棲區","清水區","大甲區","外埔區","大安區");
// for "彰化縣"
zone[9]=new Array("彰化市","芬園鄉","花壇鄉","秀水鄉","鹿港鎮","福興鄉","線西鄉","和美鎮","伸港鄉",
		"員林鎮","社頭鄉","永靖鄉","埔心鄉","溪湖鎮","大村鄉","埔鹽鄉","田中鎮","北斗鎮",
		"田尾鄉","埤頭鄉","溪州鄉","竹塘鄉","二林鎮","大城鄉","芳苑鄉","二水鄉");
// for "南投縣"
zone[10]=new Array("南投市","中寮鄉","草屯鎮","國姓鄉","埔里鎮","仁愛鄉","名間鄉",
		"集集鄉","水里鄉","魚池鄉","信義鄉","竹山鎮","鹿谷鄉");
// for "嘉義市"
zone[11]=new Array("嘉義市");
// for "嘉義縣"
zone[12]=new Array("番路鄉","梅山鄉","竹崎鄉","阿里山鄉","中埔鄉","大埔鄉","水上鄉","鹿草鄉","太保市",
		"朴子市","東石鄉","六腳鄉","新港鄉","民雄鄉","大林鎮","溪口鄉","義竹鄉","布袋鎮");
// for "雲林縣"
zone[13]=new Array("斗南市","大埤鄉","虎尾鎮","土庫鎮","褒忠鄉","東勢鄉","台西鄉","崙背鄉","麥寮鄉","斗六市",
		"林內鄉","古坑鄉","莿桐鄉","西螺鎮","二崙鄉","北港鎮","水林鄉","口湖鄉","四湖鄉","元長鄉");
// for "台南市"
zone[14]=new Array("中區","東區","南區","西區","北區","安平區","安南區",
		"永康區","歸仁區","新化區","左鎮區","玉井區","楠西區","南化區","仁德區","關廟區","龍崎區",
		"官田區","麻豆區","佳里區","西港區","七股區","將軍區","學甲區","北門區","新營區","後壁區",
		"白河區","東山區","六甲區","下營區","柳營區","鹽水區","善化區","大內區","山上區","新市區","安定區");
// for "高雄市"
zone[15]=new Array("新興區","前金區","苓雅區","鹽埕區","鼓山區",
		"旗津區","前鎮區","三民區","楠梓區","小港區","左營區",
		"仁武區","大社區","岡山區","路竹區","阿蓮區","田寮區","燕巢區","橋頭區","梓官區",
		"彌陀區","永安區","湖內區","鳳山區","大寮區","林園區","鳥松區","大樹區","旗山區",
		"美濃區","六龜區","內門區","杉林區","甲仙區","桃源區","三民區","茂林區","茄萣區");
// for "澎湖縣"
zone[16]=new Array("馬公市","西嶼鄉","望安鄉","七美鄉","白沙鄉","湖西鄉");
// for "屏東縣"
zone[17]=new Array("屏東市","三地門鄉","霧台鄉","瑪家鄉","九如鄉","里港鄉","高樹鄉","鹽埔鄉","長治鄉","麟洛鄉","竹田鄉",
		"內埔鄉","萬丹鄉","潮州鎮","泰武鄉","來義鄉","萬巒鄉","嵌頂鄉","新埤鄉","南州鄉","林邊鄉","東港鎮",
		"琉球鄉","佳冬鄉","新園鄉","枋寮鄉", "枋山鄉","春日鄉","獅子鄉","車城鄉","牡丹鄉","恆春鎮","滿州鄉");
// for "台東縣"
zone[18]=new Array("台東市","綠島鄉","蘭嶼鄉","延平鄉","卑南鄉","鹿野鄉","關山鎮","海端鄉",
		"池上鄉","東河鄉","成功鎮","長濱鄉","太麻里鄉","金峰鄉","大武鄉","達仁鄉");
// for "花蓮縣"
zone[19]=new Array("花蓮市","新城鄉","秀林鄉","吉安鄉","壽豐鄉","鳳林鎮","光復鄉",
		"豐濱鄉","瑞穗鄉","萬榮鄉","玉里鎮","卓溪鄉","富里鄉");
// for "金門縣"
zone[20]=new Array("金沙鎮","金湖鎮","金寧鄉","金城鎮","烈嶼鄉","烏坵鄉");
// for "連江縣"
zone[21]=new Array("南竿鄉","北竿鄉","莒光鄉","東引");
// for "南海諸島"
zone[22]=new Array("東沙","西沙");
// for "釣魚台列嶼"
zone[23]=new Array("釣魚台列嶼");

postCode=new Array(24);
// for "台北市"
postCode[0]=new Array("100","103","104","105","106","108","110","111","112","114","115","116");
// for "基隆市"
postCode[1]=new Array("200","201","202","203","204","205","206");
// for "新北市"
postCode[2]=new Array("207","208","220","221","222","223","224","226","227",
			"228","231","232","233","234","235","236","237","238","239",
			"241","242","243","244","247","248","249","251","252","253");
// for "宜蘭縣"
postCode[3]=new Array("260","261","262","263","264","265","266","267","268","269","270","272");
// for "新竹市"
postCode[4]=new Array("300");
// for "新竹縣"
postCode[5]=new Array("302","303","304","305","306","307","308","310","311","312","313","314","315");
// for "桃園縣"
postCode[6]=new Array("320","324","325","326","327","328","330","333","334","335","336","337","338");
// for "苗栗縣"
postCode[7]=new Array("350","351","352","353","354","356","357","358","360",
			"361","362","363","364","365","366","367","368","369");
// for "台中市"
postCode[8]=new Array("400","401","402","403","404","406","407","408",
			"411","412","413","414","420","421","422","423","424","426","427",
			"428","429","432","433","434","435","436","437","438","439");
// for "彰化縣"
postCode[9]=new Array("500","502","503","504","505","506","507","508","509",
			"510","511","5112","513","514","515","516","520","521",
			"522","523","524","525","526","527","528","530");
// for "南投縣"
postCode[10]=new Array("540","541","542","544","545","546","551","552","553","555","556","557","558");
// for "嘉義市"
postCode[11]=new Array("600");
// for "嘉義縣"
postCode[12]=new Array("602","603","604","605","606","607","608","611","612",
			"613","614","615","616","621","622","623","624","625");
// for "雲林縣"
postCode[13]=new Array("630","631","632","633","634","635","636","637","638","640",
			"643","646","647","648","649","651","652","653","654","655");
// for "台南市
postCode[14]=new Array("700","701","702","703","704","708","709",
			"710","711","712","713","714","715","716","717","718","719",
			"720","721","722","723","724","725","726","727","730","731",
			"732","733","734","735","736","737","741","742","743","744","745");
// for "高雄市"
postCode[15]=new Array("800","801","802","803","804","805","806","807","811","812","813",
			"814","815","820","821","822","823","824","825","826",
			"827","828","829","830","831","832","833","840","842",
			"843","844","845","846","847","848","849","851","852");
// for "澎湖縣"
postCode[16]=new Array("880","881","882","883","884","885");
// for "屏東縣"
postCode[17]=new Array("900","901","902","903","904","905","906","907","908","909","911",
			"912","913","920","921","922","923","924","925","926","927","928",
			"929","931","932","940","941","942","943","944","945","946","947");
// for "台東縣"
postCode[18]=new Array("950","951","952","953","954","955","956","957",
			"958","959","961","962","963","964","965","966");
// for "花蓮縣"
postCode[19]=new Array("970","971","972","973","974","975","976","977","978","979","981","982","983");
// for "金門縣"
postCode[20]=new Array("890","891","892","893","894","896");
// for "連江縣"
postCode[21]=new Array("209","210","211","212");
// for "南海諸島"
postCode[22]=new Array("817","819","290");
// for "釣魚台列嶼"
postCode[23]=new Array("290");

var otherCountyLen;
function initCounty(countyTag,otherCounty,countyValue){
	if (otherCounty!=""){
		var arrOtherCounty,oc;
			arrOtherCounty=otherCounty.split("|");
		otherCountyLen=arrOtherCounty.length;
		countyTag.length=county.length + arrOtherCounty.length;
		for (var j=0;j<arrOtherCounty.length;j++){
			countyTag.options[j].value=arrOtherCounty[j];
			countyTag.options[j].text=arrOtherCounty[j];
			if (countyTag.options[j].text==countyValue)
				countyTag.options[j].selected = true;
		}
		for (var i=0;i<county.length;i++){
			countyTag.options[i+arrOtherCounty.length].value=county[i];
			countyTag.options[i+arrOtherCounty.length].text=county[i];
			if (countyTag.options[i+arrOtherCounty.length].text==countyValue)
				countyTag.options[i+arrOtherCounty.length].selected=true;
		}
	}
	else{
		countyTag.length=county.length;
		for (var i=0;i<county.length;i++){
			countyTag.options[i].value=county[i];
			countyTag.options[i].text=county[i];
			if (countyTag.options[i].text==countyValue)
				countyTag.options[i].selected=true;
		}
	}
}

function chgPostCode(countyTag,postCodeTag,otherPostCode){
	if (otherPostCode!=""){
		var arrOtherPostCode,op;
			arrOtherPostCode=otherPostCode.split("|");
		var countySelectedIndex=countyTag.selectedIndex;
		var postCodeSelectedIndex;
			postCodeSelectedIndex=0;
		if (otherCountyLen>0){
			if (countySelectedIndex<otherCountyLen){
				postCodeTag.length=arrOtherPostCode.length;
				for (var j=0;j<arrOtherPostCode.length;j++){
					postCodeTag.options[j].value=arrOtherPostCode[j];
					postCodeTag.options[j].text=arrOtherPostCode[j];
					if (postCodeTag.options[j].value==document.getElementById("rsPostCode").value)
						postCodeSelectedIndex=j;
						//postCodeTag.options[j].selected = true;
				}
			}else{
				postCodeTag.length=postCode[countySelectedIndex-otherCountyLen].length + arrOtherPostCode.length;
				for (var j=0;j<arrOtherPostCode.length;j++){
					postCodeTag.options[j].value=arrOtherPostCode[j];
					postCodeTag.options[j].text=arrOtherPostCode[j];
					if (postCodeTag.options[j].value==document.getElementById("rsPostCode").value)
						postCodeSelectedIndex=j;
						//postCodeTag.options[j].selected = true;
				}
				for (var i=0;i<postCode[countySelectedIndex-otherCountyLen].length;i++){
					postCodeTag.options[i+arrOtherPostCode.length].value=postCode[countySelectedIndex-otherCountyLen][i] +"|"+ zone[countySelectedIndex-otherCountyLen][i];
					postCodeTag.options[i+arrOtherPostCode.length].text=postCode[countySelectedIndex-otherCountyLen][i] + zone[countySelectedIndex-otherCountyLen][i];
					if (postCodeTag.options[i+arrOtherPostCode.length].value==document.getElementById("rsPostCode").value)
						postCodeSelectedIndex=i+arrOtherPostCode.length;
						//postCodeTag.options[j].selected = true;
				}
			}
		}else{
			postCodeTag.length=postCode[countySelectedIndex].length + arrOtherPostCode.length;
			for (var j=0;j<arrOtherPostCode.length;j++){
				postCodeTag.options[j].value=arrOtherPostCode[j];
				postCodeTag.options[j].text=arrOtherPostCode[j];
				if (postCodeTag.options[j].value==document.getElementById("rsPostCode").value)
					postCodeSelectedIndex=j;
					//postCodeTag.options[j].selected = true;
			}
			for (var i=0;i<postCode[countySelectedIndex].length;i++){
				postCodeTag.options[i+arrOtherPostCode.length].value=postCode[countySelectedIndex][i] +"|"+ zone[countySelectedIndex][i];
				postCodeTag.options[i+arrOtherPostCode.length].text=postCode[countySelectedIndex][i] + zone[countySelectedIndex][i];
				if (postCodeTag.options[i+arrOtherPostCode.length].value==document.getElementById("rsPostCode").value)
					postCodeSelectedIndex=i+arrOtherPostCode.length;
					//postCodeTag.options[j].selected = true;
			}
		}
	}else{
		postCodeTag.length=postCode[countySelectedIndex].length;
		for (var i=0;i<postCode[countySelectedIndex].length;i++){
			postCodeTag.options[i].value=postCode[countySelectedIndex][i] +"|"+ zone[countySelectedIndex][i];
			postCodeTag.options[i].text=postCode[countySelectedIndex][i] + zone[countySelectedIndex][i];
			if (postCodeTag.options[i].value==document.getElementById("rsPostCode").value)
				postCodeSelectedIndex=i;
				//postCodeTag.options[i].selected=true;
		}
	}
	postCodeTag.options[postCodeSelectedIndex].selected=true;
	//showAddress(countyTag,postCodeTag);
}

function initZone1(countyInput,zoneInput,postInput,otherCounty,zoneValue){
	changeZone1(countyInput,zoneInput,postInput,otherCounty,zoneValue);
}

function initZone2(countyInput,zoneInput,postInput,addressInput,otherCounty,zoneValue){
	changeZone2(countyInput,zoneInput,postInput,addressInput,otherCounty,zoneValue);
}

function changeZone1(countyInput,zoneInput,postInput,otherCounty,zoneValue){
	if (countyInput.options[countyInput.selectedIndex].value==otherCounty){
		zoneInput.length=1;
		zoneInput.options[0].value="";
		zoneInput.options[0].text="";
		postInput.value="";
		return;
	}
	selectedCountyIndex=countyInput.selectedIndex-otherCountyLen;
	zoneInput.length=zone[selectedCountyIndex].length;
	for (i=0;i<zone[selectedCountyIndex].length;i++){
		zoneInput.options[i].value=zone[selectedCountyIndex][i];
		zoneInput.options[i].text=zone[selectedCountyIndex][i];
		if (zoneInput.options[i].text==zoneValue)
			zoneInput.options[i].selected=true;
	}
	showPostCode1(countyInput,zoneInput,postInput);
}

function changeZone2(countyInput,zoneInput,postInput,addressInput,otherCounty,zoneValue){
	if (countyInput.options[countyInput.selectedIndex].value==otherCounty){
		zoneInput.length=1;
		zoneInput.options[0].value="";
		zoneInput.options[0].text="";
		postInput.value="";
		addressInput.value="";
		return;
	}
	selectedCountyIndex=countyInput.selectedIndex-otherCountyLen;
	zoneInput.length=zone[selectedCountyIndex].length;
	for (i=0;i<zone[selectedCountyIndex].length;i++){
		zoneInput.options[i].value=zone[selectedCountyIndex][i];
		zoneInput.options[i].text=zone[selectedCountyIndex][i];
		if (zoneInput.options[i].text==zoneValue)
			zoneInput.options[i].selected=true;
	}
	showPostCode2(countyInput,zoneInput,postInput,addressInput);
}

function showPostCode1(countyInput,zoneInput,postInput){
	postInput.value=postCode[countyInput.selectedIndex-otherCountyLen][zoneInput.selectedIndex];
}

function showPostCode2(countyInput,zoneInput,postInput,addressInput){
	postInput.value=postCode[countyInput.selectedIndex-otherCountyLen][zoneInput.selectedIndex];
	addressInput.value=countyInput.options[countyInput.selectedIndex].value + zoneInput.options[zoneInput.selectedIndex].value;
}

// ***************************************************************** 
function genDateTag(tagAlias,tagName,yearValue,monthValue,dayValue,chkToday,addType,addDay,yearPeriod,className){
	var sDateTag,sYearName,sMonthName,sDayName,sSelName,defaultText,sClass,sFunc;
	var dDate;
	var iEndValue;
	sYearName="BirthYear";
	sMonthName="BirthMonth";
	sDayName="BirthDay";

	if (className!="") sClass="class=\""+ className +"\"";
	switch(addType){
		case "Y":
			dDate=DateAdd("y",addDay,new Date());
			break;
		case "M":
			dDate=DateAdd("m",addDay,new Date());
			break;
		case "D":
			dDate=DateAdd("d",addDay,new Date());
			break;
	}
	switch(tagName){
		case "Y":
			iEndValue=dDate.getFullYear()-yearPeriod;
			sSelName=sYearName;
			defaultText="西元";
			sFunc="onchange=\"genDateTag(\'"+ tagAlias +"\',\'M\',this.value,\'\',\'\',\'"+ chkToday +"\',\'"+ addType +"\',"+ addDay +","+ yearPeriod +",\'"+ className +"\')\"";
			break;
		case "M":
			if (chkToday=="Y"){
				if (parseInt(eval("document.getElementById(\""+ tagAlias + sYearName +"\")").value,10)>=dDate.getFullYear())
					iEndValue=dDate.getMonth()+1;
				else
					iEndValue=12;
			}else{
				iEndValue=12;
			}
			sSelName=sMonthName;
			defaultText="月";
			sFunc="onchange=\"genDateTag(\'"+ tagAlias +"\',\'D\',\'"+ eval("document.getElementById(\""+ tagAlias + sYearName +"\")").value +"\',this.value,\'\',\'"+ chkToday +"\',\'"+ addType +"\',"+ addDay +","+ yearPeriod +",\'"+ className +"\')\"";
			break;
		case "D":
			if (chkToday=="Y"){
				if (parseInt(eval("document.getElementById(\""+ tagAlias + sYearName +"\")").value,10)>=dDate.getFullYear() && parseInt(eval("document.getElementById(\""+ tagAlias + sMonthName +"\")").value,10)>=(dDate.getMonth()+1))
					iEndValue=dDate.getDate();
				else
					iEndValue=DateAdd("d",-1,DateAdd("m",1,new Date(yearValue +"/"+ monthValue +"/01"))).getDate();
			}else{
				iEndValue=DateAdd("d",-1,DateAdd("m",1,new Date(yearValue +"/"+ monthValue +"/01"))).getDate();
			}
			sSelName=sDayName;
			defaultText="日";
			sFunc="";
			break;
	}
	sDateTag ="<select name=\""+ tagAlias + sSelName +"\" id=\""+ tagAlias + sSelName +"\" "+ className +" "+ sFunc +">";
	sDateTag +="<option value=\"\">"+ defaultText +"</option>";
	switch(tagName){
		case "Y":
			for (var y=dDate.getFullYear();y>=iEndValue;y--){
				if ((""+y)==yearValue)
					sDateTag +="<option value=\""+ y +"\" selected>"+ y +"</option>";
				else
					sDateTag +="<option value=\""+ y +"\">"+ y +"</option>";
			}
			break;
		case "M":
			if (eval("document.getElementById(\""+ tagAlias + sYearName +"\")").value!=""){
				for (var m=1;m<=iEndValue;m++){
					if (m<10){
						if (("0"+m)==monthValue)
	    						sDateTag +="<option value=\"0"+ m +"\" selected>0"+ m +"</option>";
	    					else
	    						sDateTag +="<option value=\"0"+ m +"\">0"+ m +"</option>";
					}else{
						if ((""+m)==monthValue)
							sDateTag +="<option value=\""+ m +"\" selected>"+ m +"</option>";
						else
							sDateTag +="<option value=\""+ m +"\">"+ m +"</option>";
					}
				}
			}
			break;
		case "D":
			if (eval("document.getElementById(\""+ tagAlias + sMonthName +"\")").value!=""){
				for (var d=1;d<=iEndValue;d++){
					if (d<10){
						if (("0"+d)==dayValue)
				 			sDateTag +="<option value=\"0"+ d +"\" selected>0"+ d +"</option>";
				 		else
				 			sDateTag +="<option value=\"0"+ d +"\">0"+ d +"</option>";
					}else{
						if ((""+d)==dayValue)
							sDateTag +="<option value=\""+ d +"\" selected>"+ d +"</option>";
						else
							sDateTag +="<option value=\""+ d +"\">"+ d +"</option>";
					}
				}
			}
			break;
	}
	sDateTag +="</select>";
	switch(tagName){
		case "Y":
			document.getElementById ("YearSpan").innerHTML=sDateTag;
			genDateTag(tagAlias,"M",yearValue,monthValue,dayValue,chkToday,addType,addDay,className);
			genDateTag(tagAlias,"D",yearValue,monthValue,dayValue,chkToday,addType,addDay,className);
			break;
		case "M":
			document.getElementById ("MonthSpan").innerHTML=sDateTag;
			genDateTag(tagAlias,"D",yearValue,monthValue,dayValue,chkToday,addType,addDay,className);
			break;
		case "D":
			document.getElementById ("DaySpan").innerHTML=sDateTag;
			break;
	}
}

function DateAdd(interval,number,date){
	switch(interval.toLowerCase()){
		case "y": return new Date(date.setFullYear(date.getFullYear()+number));
		case "m": return new Date(date.setMonth((date.getMonth())+number));
		case "d": return new Date(date.setDate(date.getDate()+number));
		case "w": return new Date(date.setDate(date.getDate()+7*number));
		case "h": return new Date(date.setHours(date.getHours()+number));
		case "n": return new Date(date.setMinutes(date.getMinutes()+number));
		case "s": return new Date(date.setSeconds(date.getSeconds()+number));
		case "l": return new Date(date.setMilliseconds(date.getMilliseconds()+number));
	} 
}
//alert(DateAdd("d",1,new Date()));

function DateDiff(interval,date1,date2){
	var long = date2.getTime() - date1.getTime(); //相差毫秒
	switch(interval.toLowerCase()){
		case "y": return parseInt(date2.getFullYear() - date1.getFullYear());
		case "m": return parseInt((date2.getFullYear() - date1.getFullYear())*12 + (date2.getMonth()-date1.getMonth()));
		case "d": return parseInt(long/1000/60/60/24);
		case "w": return parseInt(long/1000/60/60/24/7);
		case "h": return parseInt(long/1000/60/60);
		case "n": return parseInt(long/1000/60);
		case "s": return parseInt(long/1000);
		case "l": return parseInt(long);
	}
}
//alert(DateDiff("d",new Date(2008,03,01),new Date(2008,03,20)));

function IsDate(dateval){
	var arr = new Array();
	
	if(dateval.indexOf("-") != -1){
		arr = dateval.toString().split("-");
	}else if(dateval.indexOf("/") != -1){
		arr = dateval.toString().split("/");
	}else{
		return false;
	}
	
	//yyyy-mm-dd || yyyy/mm/dd
	if(arr[0].length==4){
		var date = new Date(arr[0],arr[1]-1,arr[2]);
		if(date.getFullYear()==arr[0] && date.getMonth()==arr[1]-1 && date.getDate()==arr[2]){
			return true;
		}
	}
	//dd-mm-yyyy || dd/mm/yyyy
	if(arr[2].length==4){
		var date = new Date(arr[2],arr[1]-1,arr[0]);
		if(date.getFullYear()==arr[2] && date.getMonth()==arr[1]-1 && date.getDate()==arr[0]){
			return true;
		}
	}
	//mm-dd-yyyy || mm/dd/yyyy
	if(arr[2].length==4){
		var date = new Date(arr[2],arr[0]-1,arr[1]);
		if(date.getFullYear()==arr[2] && date.getMonth()==arr[0]-1 && date.getDate()==arr[1]){
			return true;
		}
	}
	
	return false;
}
//alert(IsDate("2008-02-28"));
//alert(IsDate("02/30/2008"));

//ASCII轉UNICODE
function StringA2U(source) {
	var result;
		result="";
	for (var i=0; i<source.length; i++){
		result += "&#"+ source.charCodeAt(i) + ";";
	}
	return result;
}



 //-->

