//<meta http-equiv="Content-Type" content="text/html; charset=big5">下方加
//<script src="js_check.js"></script>
//取得文件本身的 URL
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0,xend);

var xmlobj;                                     //定義XMLHttpRequest
function CreateXMLHttpRequest() 
{
  if(window.ActiveXObject)
  {
    //如果瀏覽器支援Active Xobject，則建立ActiveXObject  
    xmlobj = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  else if(window.XMLHttpRequest) 
  {
    //如果瀏覽器支援XMLHttp Request，則建立XMLHttpRequest
    xmlobj = new XMLHttpRequest();
  }
}

function detectBrowser()//判斷是否用IE瀏覽器
 { 
  var sAgent = navigator.userAgent.toLowerCase();
  this.isIE = (sAgent.indexOf("msie")!=-1); //IE6.0-7
  this.isFF = (sAgent.indexOf("firefox")!=-1);//firefox
  this.isSa = (sAgent.indexOf("safari")!=-1);//safari
  this.isOp = (sAgent.indexOf("opera")!=-1);//opera
  this.isNN = (sAgent.indexOf("netscape")!=-1);//netscape
  this.isMa = this.isIE;//marthon
  this.isOther = (!this.isIE && !this.isFF && !this.isSa && !this.isOp && !this.isNN && !this.isSa);//unknown Browser
 }
 
var oBrowser = new detectBrowser(); 

//keyCode:數字鍵 48~57 
//        . 46
//        space 32
//        英文字 65~90
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openwin_set(theURL,str)
{
  var openwindows=window.open(theURL,'myWindowset',str);
  openwindows.focus();
}
function openwin(theURL)
{
  var openwindows=window.open(theURL,'myWindow','width=600, height=600,scrollbars=yes');
  openwindows.focus();
} 
function openwin1(theURL)
{
  var openwindows1=window.open(theURL,'myWindow1','width=600, height=600,scrollbars=yes');
  openwindows1.focus();
} 
function bigword()
{ //轉成大寫
  if((event.keyCode<=122) && (event.keyCode>=97)){
    event.keyCode=event.keyCode-32;
  }
  }

	function formatNumber(number,pattern)
	{
		var str			= number.toString();
		var strInt;
		var strFloat;
		var formatInt;
		var formatFloat;
		if(/\./g.test(pattern))
		{
			formatInt		= pattern.split('.')[0];
			formatFloat		= pattern.split('.')[1];
		}
		else
		{
			formatInt		= pattern;
			formatFloat		= null;
		}

		if(/\./g.test(str))
		{
			if(formatFloat!=null)
			{
				var tempFloat	= Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);
				strInt		= (Math.floor(number)+Math.floor(tempFloat)).toString();				
				strFloat	= /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';			
			}
			else
			{
				strInt		= Math.round(number).toString();
				strFloat	= '0';
			}
		}
		else
		{
			strInt		= str;
			strFloat	= '0';
		}
		if(formatInt!=null)
		{
			var outputInt	= '';
			var zero		= formatInt.match(/0*$/)[0].length;
			var comma		= null;
			if(/,/g.test(formatInt))
			{
				comma		= formatInt.match(/,[^,]*/)[0].length-1;
			}
			var newReg		= new RegExp('(\\d{'+comma+'})','g');

			if(strInt.length<zero)
			{
				outputInt		= new Array(zero+1).join('0')+strInt;
				outputInt		= outputInt.substr(outputInt.length-zero,zero)
			}
			else
			{
				outputInt		= strInt;
			}

			var 
			outputInt			= outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')
			outputInt			= outputInt.replace(/^,/,'');

			strInt	= outputInt;
		}

		if(formatFloat!=null)
		{
			var outputFloat	= '';
			var zero		= formatFloat.match(/^0*/)[0].length;

			if(strFloat.length<zero)
			{
				outputFloat		= strFloat+new Array(zero+1).join('0');
				//outputFloat		= outputFloat.substring(0,formatFloat.length);
				var outputFloat1	= outputFloat.substring(0,zero);
				var outputFloat2	= outputFloat.substring(zero,formatFloat.length);
				outputFloat		= outputFloat1+outputFloat2.replace(/0*$/,'');
			}
			else
			{
				outputFloat		= strFloat.substring(0,formatFloat.length);
			}

			strFloat	= outputFloat;
		}
		else
		{
			if(pattern!='' || (pattern=='' && strFloat=='0'))
			{
				strFloat	= '';
			}
		}

		return strInt+(strFloat==''?'':'.'+strFloat);
	}


function intword()
{//大小寫+數字+_
  if(((event.keyCode<=47) && (event.keyCode>=32)) || ((event.keyCode<=64) && (event.keyCode>=58)) || ((event.keyCode<=94) && (event.keyCode>=91)) || (event.keyCode==96) || ((event.keyCode<=126) && (event.keyCode>=123))){
   event.keyCode=8;
  }
}

//網頁寫上 onKeyPress=int()
function int()
{//僅數字
  if((event.keyCode<=47) && (event.keyCode>=32)||(event.keyCode<=126) && (event.keyCode>=58)){
   event.keyCode=8;
  }
}

//網頁寫上 onKeyPress=intdot()
function intdot()
{//僅數字+.

  if(!(((event.keyCode>=48) && (event.keyCode<=57)) || (event.keyCode==46))){
   event.keyCode=8;
  }
  
}

//網頁寫上 onKeyPress=intline()
function intline()
{//僅數字-

  if(!(((event.keyCode>=48) && (event.keyCode<=57)) || (event.keyCode==46) || (event.keyCode==35) || (event.keyCode==45))){
   event.keyCode=8;
  }
  
}

function check_onedotint( nameid)
{
//alert(nameid.value.length);	
   var len = nameid.value.length;   
   var ck =0;
   for(var i=0;i<len;i++)
   {  var c= nameid.value.charAt(i);
      if(c == ".")
      {
      	ck = ck + 1;
      	if(ck > 1)
      	{
          alert("請輸入數字,最多再加一個小數點符號!");
          nameid.focus();
          return false;        
        }	
      }   
      else if((!(c>="0"&&c<="9")) && nameid != "")
      {
        alert("請輸入數字!");
        nameid.focus();
        return false;        
      }
   }
   return true;
}
function CheckNumeric( nameid )
{
//	alert(nameid.value.length);
   var len = nameid.value.length;
   for(var i=0;i<len;i++)
   {  var c= nameid.value.charAt(i);
      if((!(c>="0"&&c<="9")) && nameid.value != "")
      {
        alert("請輸入數字!");
        nameid.focus();
        return false;        
      }
   }
   return true;
}

function CheckNumeric_Div( nameid )
{
//	alert(nameid.value.length);
   var len = nameid.length;
   for(var i=0;i<len;i++)
   {  var c= nameid.charAt(i);
      if((!(c>="0"&&c<="9")) && nameid != "")
      {
        alert("請輸入數字!");
        return false;        
      }
   }
   return true;
}

function CheckNumericLine( nameid )
{
//	alert(nameid.value.length);
   var len = nameid.value.length;
   for(var i=0;i<len;i++)
   {  var c= nameid.value.charAt(i);
      if((!((c>="0"&&c<="9") || c == "-" || c == "#")) && nameid.value != "")
      {
        alert("僅可輸入數字、-和#!");
        nameid.focus();
        return false;        
      }
   }
   return true;
}

function check_nameid ( nameid )
{
   var len = nameid.length;
   var ck =0;
   if(len==0 && document.MyForm.emo[0].checked)
      return "";
   for(var i=0;i<len;i++)
   {  var c= nameid.charAt(i);
      if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="_")))
      {
         return "帳號只能是數字,英文字母及'_'等符號,其他的符號都不能使用 !\n";

      }
   }
    return "";
}

// ================= Check Date for Input Chinese Date and convert to AD Date

function CheckSelectDate(SelectY, SelectM, SelectD, Cname)
{
  var ChineseDate= parseInt(SelectY.options[SelectY.selectedIndex].value) + "-" + parseInt(SelectM.options[SelectM.selectedIndex].value) + "-" + parseInt(SelectD.options[SelectD.selectedIndex].value);
  var ThisYear;
  var ThisMonth;
  var ThisDay;
  var iThisYear;
  var iThisMonth;
  var iThisDay;
  var iADThisYear
  var ADYear;
  var ADMonth;
  var ADDay;
  var intTemp1;
  var intTemp2;
  if (ChineseDate != "") 
  {
      ThisYear = parseInt(SelectY.options[SelectY.selectedIndex].value);
      ThisMonth = parseInt(SelectM.options[SelectM.selectedIndex].value);
      ThisDay = parseInt(SelectD.options[SelectD.selectedIndex].value);

      iThisDay = parseInt(SelectD.options[SelectD.selectedIndex].value, 10);
      iThisMonth = parseInt(SelectM.options[SelectM.selectedIndex].value, 10);
      iThisYear = parseInt(SelectY.options[SelectY.selectedIndex].value, 10);

      if ( (iThisMonth==4 )|| (iThisMonth==6) || (iThisMonth==9) || (iThisMonth==11) )                
      {
        if( (iThisDay == 31))                
        {
          alert(Cname + "：此月無31日，請重新選擇");

          return false;
        }
      }

      if (iThisMonth==2)        
      {
        // 閏年
        if( ( (iThisYear % 4 == 0) && (iThisYear % 100 != 0) ) || (iThisYear % 400 == 0) )        
        {
          if (iThisDay < 1 || iThisDay > 29)        
          {
            alert(Cname + "：此月只到29日，請重新選擇");

            return false;
          }
        }
        else
        {
          if (iThisDay < 1 || iThisDay > 28)        
          {
            alert(Cname + "：此月只到28日，請重新選擇");

            return false;
          }

        }
      }
      return true;

  }
}

function CheckDateValue(ChineseDate)
{

  var ThisYear;
  var ThisMonth;
  var ThisDay;
  var iThisYear;
  var iThisMonth;
  var iThisDay;
  var iADThisYear;
  var ADYear;
  var ADMonth;
  var ADDay;
  var intTemp1;
  var intTemp2;
  if (ChineseDate != "") 
  {
    intTemp1 = ChineseDate.indexOf("/");
    intTemp2 = ChineseDate.indexOf("/",intTemp1+1);
    intTemp3 = ChineseDate.indexOf("-");
    intTemp4 = ChineseDate.indexOf("-",intTemp3+1);    
    if (intTemp1== -1 || intTemp2== -1)
    {
      if (intTemp3== -1 || intTemp4== -1)
      {    	
        alert("日期格式不正確, 請依 年/月/日 或 年-月-日 輸入");
        return false;
      }
      else
      {
        intTemp1 = intTemp3;
        intTemp2 = intTemp4;
        return true;
      }	 	  
    }
    else
    {
      ThisYear = ChineseDate.substring(0,intTemp1);
      ThisMonth = ChineseDate.substring(intTemp1+1, intTemp2);
      ThisDay = ChineseDate.substring(intTemp2+1, ChineseDate.length);

      if (isNaN(ThisYear) || isNaN(ThisMonth) || isNaN(ThisDay) )
      {
        alert("日期格式不正確, 請依 年/月/日 或 年-月-日 輸入");
        return false;
      }
      else
      {
        iThisDay = parseInt(ThisDay, 10);
        iThisMonth = parseInt(ThisMonth, 10);
        iThisYear = parseInt(ThisYear, 10);

        if ( (iThisMonth==1) || (iThisMonth==3) || (iThisMonth==5) || (iThisMonth==7) || (iThisMonth==8) || (iThisMonth==10) || (iThisMonth==12) )        
        {
          if( (iThisDay<1) || (iThisDay>31) )                
          {
            alert("日期  輸入錯誤");
            return false;
          }
        }

        if ( (iThisMonth==4 )|| (iThisMonth==6) || (iThisMonth==9) || (iThisMonth==11) )                
        {
          if( (iThisDay<1) || (iThisDay>30) )                
          {
            alert("日期  輸入錯誤");
            return false;
          }
        }

        if (iThisMonth==2)        
        {
          // 閏年
          if( ( (iADThisYear % 4 == 0) && (iADThisYear % 100 != 0) ) || (iADThisYear % 400 == 0) )        
          {
            if (iThisDay < 1 || iThisDay > 29)        
            {
              alert("日期  輸入錯誤");
              return false;
            }
          }
          else
          {
            if (iThisDay < 1 || iThisDay > 28)        
            {
              alert("日期  輸入錯誤");
              return false;
            }
          }
        }

        if ( iThisMonth < 1 || iThisMonth > 12 )
        {
          alert("月份  輸入錯誤");
          return false;
        }

        if ( parseInt(ThisYear) > 2037 )
        {
          alert("年份  輸入錯誤");
          return false;
        }

        ADYear=ThisYear;
        if (ThisMonth.length==1){ ADMonth="0" + ThisMonth; } else { ADMonth=ThisMonth+""; }
        if (ThisDay.length==1){ ADDay="0" + ThisDay; } else { ADDay=ThisDay; }

 //       Input =ADYear+"/"+ADMonth+"/"+ADDay;
 
        return true;
      }
    }
  }
}

function CheckDate(Input)
{
  var ChineseDate=Input.value;
  var ThisYear;
  var ThisMonth;
  var ThisDay;
  var iThisYear;
  var iThisMonth;
  var iThisDay;
  var iADThisYear;
  var ADYear;
  var ADMonth;
  var ADDay;
  var intTemp1;
  var intTemp2;
  if (ChineseDate != "") 
  {
    intTemp1 = ChineseDate.indexOf("/");
    intTemp2 = ChineseDate.indexOf("/",intTemp1+1);
    intTemp3 = ChineseDate.indexOf("-");
    intTemp4 = ChineseDate.indexOf("-",intTemp3+1);    
    if (intTemp1== -1 || intTemp2== -1)
    {
      if (intTemp3== -1 || intTemp4== -1)
      {    	
        alert("日期格式不正確, 請依 年/月/日 或 年-月-日 輸入");
        Input.focus();
        return false;
      }
      else
      {
        intTemp1 = intTemp3;
        intTemp2 = intTemp4;
      }	 	  
    }
    else
    {
      ThisYear = ChineseDate.substring(0,intTemp1);
      ThisMonth = ChineseDate.substring(intTemp1+1, intTemp2);
      ThisDay = ChineseDate.substring(intTemp2+1, ChineseDate.length);

      if (isNaN(ThisYear) || isNaN(ThisMonth) || isNaN(ThisDay) )
      {
        alert("日期格式不正確, 請依 年/月/日 或 年-月-日 輸入");
        Input.focus();
        return false;
      }
      else
      {
        iThisDay = parseInt(ThisDay, 10);
        iThisMonth = parseInt(ThisMonth, 10);
        iThisYear = parseInt(ThisYear, 10);

        if ( (iThisMonth==1) || (iThisMonth==3) || (iThisMonth==5) || (iThisMonth==7) || (iThisMonth==8) || (iThisMonth==10) || (iThisMonth==12) )        
        {
          if( (iThisDay<1) || (iThisDay>31) )                
          {
            alert("日期  輸入錯誤");
            Input.focus();
            return false;
          }
        }

        if ( (iThisMonth==4 )|| (iThisMonth==6) || (iThisMonth==9) || (iThisMonth==11) )                
        {
          if( (iThisDay<1) || (iThisDay>30) )                
          {
            alert("日期  輸入錯誤");
            Input.focus();
            return false;
          }
        }

        if (iThisMonth==2)        
        {
          // 閏年
          if( ( (iADThisYear % 4 == 0) && (iADThisYear % 100 != 0) ) || (iADThisYear % 400 == 0) )        
          {
            if (iThisDay < 1 || iThisDay > 29)        
            {
              alert("日期  輸入錯誤");
              Input.focus();
              return false;
            }
          }
          else
          {
            if (iThisDay < 1 || iThisDay > 28)        
            {
              alert("日期  輸入錯誤");
              Input.focus();
              return false;
            }
          }
        }

        if ( iThisMonth < 1 || iThisMonth > 12 )
        {
          alert("月份  輸入錯誤");
          Input.focus();
          return false;
        }

        if ( parseInt(ThisYear) > 2037 )
        {
          alert("年份  輸入錯誤");
          Input.focus();
          return false;
        }

        ADYear=ThisYear;
        if (ThisMonth.length==1){ ADMonth="0" + ThisMonth; } else { ADMonth=ThisMonth+""; }
        if (ThisDay.length==1){ ADDay="0" + ThisDay; } else { ADDay=ThisDay; }

        Input.value=ADYear+"/"+ADMonth+"/"+ADDay;
        return true;
      }
    }
  }
}

function CheckYear(Input)
{
  var  Tyear=Input.value;
 
  if (Tyear.length!=4)
  {
    alert("請輸入4位數年度");
    Input.focus();
    return false;
  }
  if ( parseInt(Tyear) > 2037  ||  parseInt(Tyear)< 2001)
  {
    alert("年度  輸入錯誤");
    Input.focus();
    return false;
  }
}

function CheckMDate(Input)
{
  var ChineseDate=Input.value;
  var ThisYear;
  var ThisMonth;
  var ThisDay;
  var iThisYear;
  var iThisMonth;
  var iThisDay;
  var iADThisYear
  var ADYear;
  var ADMonth;
  var ADDay;
  var intTemp1;
  var intTemp2;
  if (ChineseDate != "") 
  {
    intTemp1 = ChineseDate.indexOf("-");
    intTemp2 = ChineseDate.indexOf("-",intTemp1+1);
    intTemp3 = ChineseDate.indexOf("/");
    intTemp4 = ChineseDate.indexOf("/",intTemp3+1);
  
    if (intTemp1== -1 || intTemp2== -1)
    {
      if (intTemp3 == -1 || intTemp4 == -1)
      {
  	alert("日期格式不正確, 請依 年-月-日 或 年/月/日 輸入");
        Input.focus();
        return false;
      }
      else
      {
        ThisYear = ChineseDate.substring(0,intTemp3);
        ThisMonth = ChineseDate.substring(intTemp3+1, intTemp4);
        ThisDay = ChineseDate.substring(intTemp4+1, ChineseDate.length);          	
        if (isNaN(ThisYear) || isNaN(ThisMonth) || isNaN(ThisDay) )
        {
          alert("日期格式不正確, 請依 年-月-日 或 年/月/日 輸入");
          Input.focus();
          return false;
        }
        else
        {
          iThisDay = parseInt(ThisDay, 10);
          iThisMonth = parseInt(ThisMonth, 10);
          iThisYear = parseInt(ThisYear, 10);
          if ( (iThisMonth==1) || (iThisMonth==3) || (iThisMonth==5) || (iThisMonth==7) || (iThisMonth==8) || (iThisMonth==10) || (iThisMonth==12) )        
          {
            if( (iThisDay<1) || (iThisDay>31) )                
            {
              alert("日期  輸入錯誤");
              Input.focus();
              return false;
            }
          }
          if ( (iThisMonth==4 )|| (iThisMonth==6) || (iThisMonth==9) || (iThisMonth==11) )                
          {
            if( (iThisDay<1) || (iThisDay>30) )                
            {
              alert("日期  輸入錯誤");
              Input.focus();
              return false;
            }
          }
          if (iThisMonth==2)        
          {
            // 閏年
            if( ( (iADThisYear % 4 == 0) && (iADThisYear % 100 != 0) ) || (iADThisYear % 400 == 0) )        
            {
              if (iThisDay < 1 || iThisDay > 29)        
              {
                alert("日期  輸入錯誤");
                Input.focus();
                return false;
              }
            }
            else        
            {
              if (iThisDay < 1 || iThisDay > 28)        
              {
                alert("日期  輸入錯誤");
                Input.focus();
                return false;
              }
            }
          }
          if ( iThisMonth < 1 || iThisMonth > 12 )
          {
            alert("月份  輸入錯誤");
            Input.focus();
            return false;
          }
          if ( parseInt(ThisYear) > 2037 )
          {
            alert("年份  輸入錯誤");
            Input.focus();
            return false;
          }
          ADYear=ThisYear;
          if (ThisMonth.length==1)
          {
            ADMonth="0" + ThisMonth;
          }
          else
          {
            ADMonth=ThisMonth+"";
          }
          if (ThisDay.length==1)
          {
            ADDay="0" + ThisDay;
          }
          else
          {
            ADDay=ThisDay;
          }
          Input.value=ADYear+"/"+ADMonth+"/"+ADDay;
          return true;
        }                         
      }	      
    }
    else
    {
      ThisYear = ChineseDate.substring(0,intTemp1);
      ThisMonth = ChineseDate.substring(intTemp1+1, intTemp2);
      ThisDay = ChineseDate.substring(intTemp2+1, ChineseDate.length);
      if (isNaN(ThisYear) || isNaN(ThisMonth) || isNaN(ThisDay) )
      {
        alert("日期格式不正確, 請依 年-月-日 或 年/月/日  輸入");
        Input.focus();
        return false;
      }
      else
      {
        iThisDay = parseInt(ThisDay, 10);
        iThisMonth = parseInt(ThisMonth, 10);
        iThisYear = parseInt(ThisYear, 10);
        if ( (iThisMonth==1) || (iThisMonth==3) || (iThisMonth==5) || (iThisMonth==7) || (iThisMonth==8) || (iThisMonth==10) || (iThisMonth==12) )        
        {
          if( (iThisDay<1) || (iThisDay>31) )                
          {
            alert("日期  輸入錯誤");
            Input.focus();
            return false;
          }
        }
        if ( (iThisMonth==4 )|| (iThisMonth==6) || (iThisMonth==9) || (iThisMonth==11) )                
        {
          if( (iThisDay<1) || (iThisDay>30) )                
          {
            alert("日期  輸入錯誤");
            Input.focus();
            return false;
          }
        }
        if (iThisMonth==2)        
        {
          // 閏年
          if( ( (iADThisYear % 4 == 0) && (iADThisYear % 100 != 0) ) || (iADThisYear % 400 == 0) )        
          {
            if (iThisDay < 1 || iThisDay > 29)        
            {
              alert("日期  輸入錯誤");
              Input.focus();
              return false;
            }
          }
          else        
          {
            if (iThisDay < 1 || iThisDay > 28)        
            {
              alert("日期  輸入錯誤");
              Input.focus();
              return false;
            }
          }
        }
        if ( iThisMonth < 1 || iThisMonth > 12 )
        {
          alert("月份  輸入錯誤");
          Input.focus();
          return false;
        }
        if ( parseInt(ThisYear) > 2037 )
        {
          alert("年份  輸入錯誤");
          Input.focus();
          return false;
        }
        ADYear=ThisYear;
        if (ThisMonth.length==1)
        {
          ADMonth="0" + ThisMonth;
        }
        else
        {
          ADMonth=ThisMonth+"";
        }
        if (ThisDay.length==1)
        {
          ADDay="0" + ThisDay;
        }
        else
        {
          ADDay=ThisDay;
        }
        Input.value=ADYear+"-"+ADMonth+"-"+ADDay;
        return true;
      }
    }
  }
}




//====================== Check whether Input value is Number ===============
/*
function CheckNumeric(input)        
{

  var CheckPara = parseFloat(input.value);

  if (input.value=="") 
  {
    CheckPara=0;
  }

  if (isNaN(CheckPara)) 
  {
    alert("請輸入數字!!");
    input.focus();
    return false;
  }
  return true;
}
*/
//==================== for ID begin =========================



function  check_id(id) {

        var r = idcheck(id.value);

        if (r == 0) {}
        if (r == 1) {

             window.alert("Error: 身份證第一個字必須是英文字母");

             id.focus();}

        if (r == 2)  {

            window.alert("Error: 輸入之身份證號碼的欄位個數錯誤");

            id.focus();}

        if (r == 3)  {

            window.alert("Error: 不是一個正確的身份證號碼");

            id.focus();}

        if (r >= 4)  {

            window.alert("Error: 第" + (r - 4) + "欄位不是數字");

            id.focus();}

}



function idcheck(id)

{
  var Num = new Array(11);  // Two elements to save the leading alphabet
 
  if(id.length == 0) return 0;
 
  if (id.length != 10) return 2;
 
  Num[0] = id.charCodeAt(0);
 
  if ((parseInt(Num[0]) < 65) || (parseInt(Num[0]) > 122)) return 1;
 
  Num[0] = id.charAt(0);
 
  if ((Num[0] == "A") || (Num[0] == "a")) { Num[0]=1; Num[1] = 0;}
 
  if ((Num[0] == "B") || (Num[0] == "b")) { Num[0]=1; Num[1] = 1;}
 
  if ((Num[0] == "C") || (Num[0] == "c")) { Num[0]=1; Num[1] = 2;}
 
  if ((Num[0] == "D") || (Num[0] == "d")) { Num[0]=1; Num[1] = 3;}
 
  if ((Num[0] == "E") || (Num[0] == "e")) { Num[0]=1; Num[1] = 4;}
 
  if ((Num[0] == "F") || (Num[0] == "f")) { Num[0]=1; Num[1] = 5;}
 
  if ((Num[0] == "G") || (Num[0] == "g")) { Num[0]=1; Num[1] = 6;}
 
  if ((Num[0] == "H") || (Num[0] == "h")) { Num[0]=1; Num[1] = 7;}
 
  if ((Num[0] == "I") || (Num[0] == "i")) { Num[0]=3; Num[1] = 4;} //
 
  if ((Num[0] == "J") || (Num[0] == "j")) { Num[0]=1; Num[1] = 8;}
 
  if ((Num[0] == "K") || (Num[0] == "k")) { Num[0]=1; Num[1] = 9;}
 
  if ((Num[0] == "L") || (Num[0] == "l")) { Num[0]=2; Num[1] = 0;}
 
  if ((Num[0] == "M") || (Num[0] == "m")) { Num[0]=2; Num[1] = 1;}
 
  if ((Num[0] == "N") || (Num[0] == "n")) { Num[0]=2; Num[1] = 2;}
 
  if ((Num[0] == "O") || (Num[0] == "o")) { Num[0]=3; Num[1] = 5;} //
 
  if ((Num[0] == "P") || (Num[0] == "p")) { Num[0]=2; Num[1] = 3;}
 
  if ((Num[0] == "Q") || (Num[0] == "q")) { Num[0]=2; Num[1] = 4;}
 
  if ((Num[0] == "R") || (Num[0] == "r")) { Num[0]=2; Num[1] = 5;}
 
  if ((Num[0] == "S") || (Num[0] == "s")) { Num[0]=2; Num[1] = 6;}
 
  if ((Num[0] == "T") || (Num[0] == "t")) { Num[0]=2; Num[1] = 7;}
 
  if ((Num[0] == "U") || (Num[0] == "u")) { Num[0]=2; Num[1] = 8;}
 
  if ((Num[0] == "V") || (Num[0] == "v")) { Num[0]=2; Num[1] = 9;}
 
  if ((Num[0] == "W") || (Num[0] == "w")) { Num[0]=3; Num[1] = 2;} //
 
  if ((Num[0] == "X") || (Num[0] == "x")) { Num[0]=3; Num[1] = 0;}
 
  if ((Num[0] == "Y") || (Num[0] == "y")) { Num[0]=3; Num[1] = 1;}
 
  if ((Num[0] == "Z") || (Num[0] == "z")) { Num[0]=3; Num[1] = 3;} //

//WScript.echo(Num[0]); WScript.echo(Num[1]);

  for (i=2; i< 11; i++) 
  {
    Num[i] = id.charAt(i-1);

    if (isNaN(Num[i])) 
    {
      return 4 + i;
    }
//WScript.echo(i," ",Num[i]);
  }
  var out = eval(Num[0]) + eval(Num[1])*9 + eval(Num[2])*8 + eval(Num[3])*7

                          + eval(Num[4])*6 + eval(Num[5])*5 + eval(Num[6])*4 + eval(Num[7])*3

                          + eval(Num[8])*2 + eval(Num[9]) + eval(Num[10]);
  out = out % 10;

//WScript.echo(out);

  if (out == 0) return 0;

  else          return 3;
}

//==================== for ID end =========================

function check_pwd ( pwd )
{
   var len = pwd.length;
   var ck =0;
   if(len==0 && document.MyForm.emo[0].checked)
      return "";
   for(var i=0;i<len;i++)
   {  var c= pwd.charAt(i);
      if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")))
      {
         return "密碼只能是數字、英文字母等符號,其他的符號都不能使用 !\n";
      }
   }
    return "";
}
function checkmail(formemail,formtrue)
{
//  var emailcontent=document.frm.email.value;
  var emailcontent=formemail;
  var atpos=emailcontent.indexOf("@",2);
  var dotpos=emailcontent.indexOf(".",atpos+2);
  var dotpos2=emailcontent.lastIndexOf(".");
  var emaillength=emailcontent.length;
  var lastdoppos=emaillength-dotpos2;

  if(emailcontent=="")
  {
     if(formtrue == "false")
     { 
       alert("請輸入E-mail!!!\n");
       return false;
     }
     else
     {
       return true;
     }
  }
  else
  {
    if(emaillength<=5 || atpos<=0 || dotpos<=0 || lastdoppos<3)
    {
            alert("請輸入正確的E-mail!!!\n");
                  return false;
    }
    else
    {
            return true;
    }
  }  
}

function check_email ( email )
{
   var len = email.length;
   var ck =0;
   if(len==0 && document.MyForm.emo[0].checked)
      return "";
   for(var i=0;i<len;i++)
   {  var c= email.charAt(i);
      if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="_")||(c==".")||(c=="@")))
         return "電子郵件地址只能是數字,英文字母及'_'等符號,其他的符號都不能使用 !\n";
   }

   if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(len-1)))
      return "電子郵件地址不合法 !\n";
   if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,len).indexOf("@")!=-1))
      return "電子郵件地址不合法 !\n";
   if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(len-1)))
      return "電子郵件地址不完全 !\n";
   return "";
}

// ================= Combination Address components --- Start
function SetAddressCombination(frmInput)
{
  frmInput.AddressCombination.value = CombinateAddress(frmInput.zip.value, frmInput.City.value, frmInput.Canton.value, frmInput.Village.value, frmInput.VillageOpt.value, frmInput.Block.value, frmInput.Road.value, frmInput.RoadOpt.value, frmInput.Section.value, frmInput.Alley.value, frmInput.Lane.value, frmInput.SubLane.value, frmInput.No.value, frmInput.SubNo.value, frmInput.Floor.value, frmInput.Suite.value, frmInput.Room.value, frmInput.Supplement.value);
}

function CombinateAddress(Pzip, PCity, PCanton, PVillage, PVillageOpt, PBlock, PRoad, PRoadOpt, PSection, PAlley, PLane, PSubLane, PNo, PSubNo, PFloor, PSuite, PRoom, PSupplement)
{
  var ReAddress;

  if (Pzip != ""){ ReAddress=Pzip; }
  if (PCity !=""){ ReAddress=ReAddress + PCity; }
  if (PCanton != ""){ ReAddress=ReAddress + PCanton; }
  if (PVillage != ""){ ReAddress=ReAddress + PVillage + PVillageOpt; }
  if (PBlock != ""){ ReAddress=ReAddress + PBlock + "鄰"; }
  if (PRoad != "" ){ ReAddress=ReAddress + PRoad + PRoadOpt; }
  if (PSection != ""){ ReAddress=ReAddress + PSection + "段"; }
  if (PAlley != ""){ ReAddress=ReAddress + PAlley + "巷"; }
  if (PLane != "" ){ ReAddress=ReAddress + PLane + "弄"; }
  if (PSubLane        != ""){ ReAddress=ReAddress + PSubLane + "衖"; }
  if (PNo != "")
  {  
    ReAddress=ReAddress + PNo ;
    if (PSubNo != ""){ ReAddress=ReAddress + "之" + PSubNo; }
    ReAddress=ReAddress + "號";
  }
  if (PFloor != ""){ ReAddress=ReAddress + PFloor + "樓" ; }
  if (PSuite != ""){ ReAddress=ReAddress + "之" + PSuite; }
  if (PRoom != ""){ ReAddress=ReAddress + "  " + PRoom + "室"; }
  if (PSupplement != ""){ ReAddress=ReAddress + "  " + PSupplement; }

  return ReAddress;

}

// ================= Combination Address components ---- End

// ================= Combination Address components2 ---- Start

function SetAddressCombination2(frmInput2)
{
  frmInput2.AddressCombination2.value = CombinateAddress(frmInput2.zip2.value, frmInput2.City2.value, frmInput2.Canton2.value, frmInput2.Village2.value, frmInput2.VillageOpt2.value, frmInput2.Block2.value, frmInput2.Road2.value, frmInput2.RoadOpt2.value, frmInput2.Section2.value, frmInput2.Alley2.value, frmInput2.Lane2.value, frmInput2.SubLane2.value, frmInput2.No2.value, frmInput2.SubNo2.value, frmInput2.Floor2.value, frmInput2.Suite2.value, frmInput2.Room2.value, frmInput2.Supplement2.value);
}

// ================= Combination Address components2 ---- End

//==================== for zip code begin =========================

County = new Array("", "臺北市", "基隆市", "臺北縣", "宜蘭縣", "新竹市",

                "新竹縣", "桃園縣", "苗栗縣", "臺中市", "臺中縣", "彰化縣",

                "南投縣", "嘉義市", "嘉義縣", "雲林縣", "臺南市", "臺南縣",

                "高雄市", "高雄縣", "澎湖縣", "屏東縣", "臺東縣", "花蓮縣",

                "金門縣", "連江縣", "南海諸島", "釣魚台列嶼");

Zone = new Array(27);

// 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("", "金沙鎮","金湖鎮","金寧鄉","金城鎮","烈嶼鄉","烏坵鄉");

// for "連江縣"

Zone[24] = new Array("", "南竿鄉","北竿鄉","莒光鄉","東引");

// for "南海諸島"

Zone[25] = new Array("", "東沙","西沙");

// for "釣魚台列嶼"

Zone[26] = new Array("");



zipCode = new Array(27);

// for "臺北市"

zipCode[0] = new Array("", "100","103","104","105","106","108","110","111",

        "112","114","115","116","117");

// for "基隆市"

zipCode[1] = new Array("", "200","201","202","203","204","205","206");

// for "臺北縣"

zipCode[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 "宜蘭縣"

zipCode[3] = new Array("", "260","261","262","263","264","265","266","267",

        "268","269","270","272");

// for "新竹市"

zipCode[4] = new Array("300");

// for "新竹縣"

zipCode[5] = new Array("", "302","303","304","305","306","307","308","310",

        "311","312","313","314","315");

// for "桃園縣"

zipCode[6] = new Array("", "320","324","325","326","327","328","330","333",

        "334","335","336","337","338");

// for "苗栗縣"

zipCode[7] = new Array("", "350","351","352","353","354","356","357",

        "358","360","361","362","363","364","365","366","367","368","369");

// for "臺中市"

zipCode[8] = new Array("", "400","401","402","403","404","406","407","408");

// for "臺中縣"

zipCode[9] = new Array("", "411","412","413","414","420","421","422","423",

        "424","426","427","428","429","432","433","434","435","436","437",

        "438","439");

// for "彰化縣"

zipCode[10] = 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 "南投縣"

zipCode[11] = new Array("", "540","541","542","544","545","546","551","552",

        "553","555","556","557","558");

// for "嘉義市"

zipCode[12] = new Array("600");

// for "嘉義縣"

zipCode[13] = new Array("", "602","603","604","605","606","607","608","611",

        "612","613","614","615","616","621","622","623","624","625");

// for "雲林縣"

zipCode[14] = new Array("", "630","631","632","633","634","635","636","637",

        "638","640","643","646","647","648","649","651","652","653","654",

        "655");

// for "臺南市"

zipCode[15] = new Array("", "700","701","702","703","704","708","709");

// for "臺南縣"

zipCode[16] = new Array("", "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 "高雄市"

zipCode[17] = new Array("", "800","801","802","803","804","805","806","807",

        "811","812","813");

// for "高雄縣"

zipCode[18] = new Array("", "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 "澎湖縣"

zipCode[19] = new Array("", "880","881","882","883","884","885");

// for "屏東縣"

zipCode[20] = 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 "臺東縣"

zipCode[21] = new Array("", "950","951","952","953","954","955","956","957",

        "958","959","961","962","963","964","965","966");

// for "花蓮縣"

zipCode[22] = new Array("", "970","971","972","973","974","975","976","977",

        "978","979","981","982","983");

// for "金門縣"

zipCode[23] = new Array("", "890","891","892","893","894","896");

// for "連江縣"

zipCode[24] = new Array("", "209","210","211","212");

// for "南海諸島"

zipCode[25] = new Array("", "817","819","290");

// for "釣魚台列嶼"

zipCode[26] = new Array("290");


function initCounty(countyInput)
{
  countyInput.length = County.length;
  for (i = 0; i < County.length; i++) 
  {
    countyInput.options[i].value = County[i];
    countyInput.options[i].text = County[i];
  }
  countyInput.selectedIndex = 0;
}

function initZone(countyInput, zoneInput, post)
{
  changeZone(countyInput, zoneInput, post);
}

function changeZone(countyInput, zoneInput, post) 
{
	
  selectedCountyIndex = countyInput.selectedIndex;
  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];
  }
  zoneInput.selectedIndex = 0;
  showzipCode(countyInput, zoneInput, post);
}



function showzipCode(countyInput, zoneInput, post) 
{
  post.value = zipCode[countyInput.selectedIndex][zoneInput.selectedIndex];
}

//==================== for zip code end =========================

function StringLength(strIn)                
{
  var iLen = 0;
  for(i=0; i<strIn.length; i++)        
  {
    if(strIn.charCodeAt(i) > 128)
      iLen = iLen + 2;
    else
      iLen++;
  }
  return iLen;
}

function setfield()
{
  document.send_newsletter.now_send[1].checked = true;	
}

