﻿function trim(instr)
{
  return instr.replace(/^[\s]*/gi,"").replace(/[\s]*$/gi,"");
}

function checkEnter()
{
  if (window.event.keyCode == 13)
  {
    document.getElementById("ibtnOK").focus();
  }
}

function getByteLength(strIN)
{
//計算byte
  var i,cnt=0;
  for (i=0; i<strIN.length; i++)
  {
    if (escape(strIN.charAt(i)).length >= 4) cnt+=2;
    else cnt++;
  }
  return cnt;
}

function checklogin(txtUSER_ID,txtPASSWORD)
{
  var txt;
  if (document.getElementById(txtUSER_ID).value=='')
  {
    txt=document.getElementById(txtUSER_ID);
	alert('請輸入帳號');
	txt.focus();
	return false;
  }
  if (document.getElementById(txtPASSWORD).value=='')
  {
	txt=document.getElementById(txtPASSWORD);
    alert('請輸入密碼');
	txt.focus();
	return false;
  }
}

function checkforget(txtUSER_ID,txtemail)
{
  var txt;			
  if (document.getElementById(txtUSER_ID).value=='')
  {
	 txt=document.getElementById(txtUSER_ID);
     alert('請輸入帳號');
	 txt.focus();       
	 return false;
  }
  
  if (document.getElementById(txtemail).value=='')
  {
	 txt=document.getElementById(txtemail);
	 alert('請輸入電子信箱');
	 txt.focus();       
	 return false;
  }
  else
  {
	  var fobj=document.getElementById(txtemail).value;
      var check=/.+@.+\..+/;
      if (fobj.match(check) ==null )
      {
        txt=document.getElementById(txtemail);
        alert("請輸入正確的電子信箱"); 
        txt.focus(); 
        txt.value="";
        return false;
      }
   } 
}

function checkcontact(txtUSER_ID,txttel,txtemail,txtsubject,txtq)
{
  var txt;			
  if (document.getElementById(txtUSER_ID).value=='')
  {
	 txt=document.getElementById(txtUSER_ID);
     alert('請輸入帳號');
	 txt.focus();       
	 return false;
  }
  
  if (document.getElementById(txttel).value=='')
  {
	  txt=document.getElementById(txttel);
	  alert('請輸入連絡電話');
	  txt.focus();       
	  return false;
  }
  
  if (document.getElementById(txtemail).value=='')
  {
	  txt=document.getElementById(txtemail);
	  alert('請輸入連絡信箱');
	  txt.focus();       
	  return false;
  }
  else
  {
       var fobj=document.getElementById(txtemail).value;
       var check=/.+@.+\..+/;
       if (fobj.match(check) ==null )
       {
          txt=document.getElementById(txtemail);
          alert("請輸入正確的連絡信箱"); 
          txt.focus(); 
          txt.value="";
          return false;
       }
  } 
	
   if (document.getElementById(txtsubject).value=='')
   {
	  txt=document.getElementById(txtsubject);
	  alert('請輸入主旨');
	  txt.focus();
	  return false;
   }
   
   if (document.getElementById(txtq).value=='')
   {
	  txt=document.getElementById(txtq);
      alert('請輸入說明');
	  txt.focus();       
	  return false;
   }
}

function checkddl(ddlyear,ddlmonth){
var txt;
var yy="";
var mm="";
	if (document.getElementById(ddlyear).value=='請選擇'){
	    txt=document.getElementById(ddlyear);
		alert('請選擇(年)');
		txt.focus();       
		return false;
		}else{
		yy=document.getElementById(ddlyear).value;
		}	
	if (document.getElementById(ddlmonth).value=='請選擇'){
	    /*txt=document.getElementById(ddlmonth);
		alert('請選擇(月)');
		txt.focus();       
		return false;*/
		}else{
		mm=document.getElementById(ddlmonth).value;
		}	
location.href='news_list.aspx?year='+yy+'&month='+mm;								
return false;

}



function checkjoin(txtUSER_ID,txtPASSWORD,txtR_PASSWORD,txtemail,txtPHONE1,txtPHONE2,txtNAME,ddlyear,ddlmonth,ddlday,rblF,rblM,txtimgcheck,ddlMember,rbManager_y,txtManager,txtTCard_1,txtTCard_2)
{
    var txt;

	if (trim(document.getElementById(txtUSER_ID).value)=='')
	{
	    txt=document.getElementById(txtUSER_ID);
		alert('請輸入帳號');
		txt.focus();       
		return false;
	}
			
	if (trim(document.getElementById(txtPASSWORD).value)=='')
	{
	    txt=document.getElementById(txtPASSWORD);
		alert('請輸入密碼');
		txt.focus();       
		return false;
	}
	
	if (trim(document.getElementById(txtR_PASSWORD).value)=='')
	{
	    txt=document.getElementById(txtR_PASSWORD);
		alert('請輸入確認密碼');
		txt.focus();       
		return false;
	}			
	
	if (document.getElementById(txtPASSWORD).value!=document.getElementById(txtR_PASSWORD).value)
	{
	    txt=document.getElementById(txtPASSWORD);
		alert('密碼與確認密碼不符');
		txt.focus();       
		return false;
	}	
		
	if (trim(document.getElementById(txtemail).value)=='')
	{
	    txt=document.getElementById(txtemail);
		alert('請輸入電子信箱');
		txt.focus();       
		return false;
	}
	else
	{
		var fobj=document.getElementById(txtemail).value;
        var check=/.+@.+\..+/;
        if (fobj.match(check) ==null )
        {
           txt=document.getElementById(txtemail);
           alert("請輸入正確的電子信箱"); 
           txt.focus(); 
           txt.value="";
           return false;
        }
	}
	
	if(trim(document.getElementById(txtPHONE1).value)==''&& trim(document.getElementById(txtPHONE2).value)=='')
	{
	  txt=document.getElementById(txtPHONE1);
	  alert("請至少輸入一個電話號碼");
	  txt.focus();
	  return false;
	}
	
	txt=document.getElementById(txtPHONE1);
	var phone1=document.getElementById(txtPHONE1).value;
    var z="0123456789()#";
    var nab=phone1.length-1;
    for (var i=0;i<=nab;i++)
    {
      if (z.indexOf(phone1.substr(i,1)) == -1)
      { 
        alert("請輸入正確電話格式");
        txt.focus();
        return false;
      }
    }
    if(phone1 == "0")
    { 
      alert("請輸入正確電話格式");
      txt.focus();
      return false;
    }
    
    txt=document.getElementById(txtPHONE2);
    var phone2=document.getElementById(txtPHONE2).value;
    var nab1=phone2.length-1;
    for (var j=0;j<=nab1;j++)
    {
      if (z.indexOf(phone2.substr(j,1)) == -1)
      {
        alert("請輸入正確電話格式");
        txt.focus();
        return false;
      }
    }
    if(phone2 == "0")
    {
      alert("請輸入正確電話格式");
      txt.focus();
      return false;
    }
	
	
	if (document.getElementById(ddlMember).value=='請選擇')
	{
	    txt=document.getElementById(ddlMember);
		alert('請選擇成員身分');
		txt.focus();       
		return false;
	}
	//if (document.getElementById(ddlMember).value=='07')
	//{
	//  if(document.getElementById(txtTCard_1).value=='' && document.getElementById(txtTCard_2).value=='')
	//  {
	//    txt=document.getElementById(txtTCard_1);
	//    alert('請填寫 全國教師會會員卡號 或 教師識別證卡號');
	//    txt.focus();
	//    return false;
	//  }
	//}
		
	if (trim(document.getElementById(txtNAME).value)=='')
	{
	    txt=document.getElementById(txtNAME);
		alert('請輸入暱稱');
		txt.focus();       
		return false;
	}
		
	if (document.getElementById(ddlyear).value=='請選擇')
	{
	    txt=document.getElementById(ddlyear);
		alert('請選擇生日(年)');
		txt.focus();       
		return false;
	}
	
	if (document.getElementById(ddlmonth).value=='請選擇')
	{
	    txt=document.getElementById(ddlmonth);
		alert('請選擇生日(月)');
		txt.focus();       
		return false;
	}
		
	if (document.getElementById(ddlday).value=='請選擇')
	{
	    txt=document.getElementById(ddlday);
		alert('請選擇生日(日)');
		txt.focus();       
		return false;
	}
		
	if (document.getElementById(rblF).checked==false && document.getElementById(rblM).checked==false)
	{
		txt=document.getElementById(rblF);
		alert('請選擇性別');
		txt.focus();       
		return false;
	}
	
	if(document.getElementById(rbManager_y).checked==true && trim(document.getElementById(txtManager).value)=='')
	{
	   txt=document.getElementById(txtManager);
	   alert("請輸入活動代碼");
	   txt.focus();
	   return false;
	}
		
	if (document.getElementById(txtimgcheck).value=='')
	{
	    txt=document.getElementById(txtimgcheck);
		alert('請輸入圖片驗證');
		txt.focus();       
		return false;
	}

}


function checkinfo(txtPASSWORD,txtR_PASSWORD,txtemail,txtPHONE1,txtPHONE2,txtNAME,ddlyear,ddlmonth,ddlday,rblF,rblM,ddlMember,rbManager_y,txtManager,txtTCard_1,txtTCard_2)
{
   var txt;

   if (trim(document.getElementById(txtPASSWORD).value)=='')
   {
	    txt=document.getElementById(txtPASSWORD);
		alert("請輸入密碼");
		txt.focus();       
		return false;
   }
   
   if (trim(document.getElementById(txtR_PASSWORD).value)=='')
   {
	    txt=document.getElementById(txtR_PASSWORD);
		alert('請輸入確認密碼');
		txt.focus();       
		return false;
   }			
	
   if (document.getElementById(txtPASSWORD).value != document.getElementById(txtR_PASSWORD).value)
   {
	    txt=document.getElementById(txtPASSWORD);
		alert('密碼與確認密碼不符');
		txt.focus();       
		return false;
   }
   
   if(document.getElementById(rbManager_y).checked==true && trim(document.getElementById(txtManager).value)=='')
   {
	   txt=document.getElementById(txtManager);
	   alert("請輸入活動代碼");
	   txt.focus();
	   return false;
   }   
		
   if (document.getElementById(txtemail).value=='')
   {
	    txt=document.getElementById(txtemail);
		alert('請輸入電子信箱');
		txt.focus();       
		return false;
   }
   else
   {
		var fobj=document.getElementById(txtemail).value;
        var check=/.+@.+\..+/;
        if (fobj.match(check) ==null )
        {
          txt=document.getElementById(txtemail);
          alert("請輸入正確的電子信箱"); 
          txt.focus(); 
          txt.value="";
          return false;
        }
	}
	
	if(trim(document.getElementById(txtPHONE1).value)=='' && trim(document.getElementById(txtPHONE2).value)=='')
	{
	  txt=document.getElementById(txtPHONE1);
	  alert("請至少輸入一個聯絡電話號碼");
	  txt.focus();
	  return false;
	}
	
	txt=document.getElementById(txtPHONE1);
	var phone1=document.getElementById(txtPHONE1).value;
    var z="0123456789()#";
    var nab=phone1.length-1;
    for (var i=0;i<=nab;i++)
    {
      if (z.indexOf(phone1.substr(i,1)) == -1)
      { 
        alert("請輸入正確電話號碼格式");
        txt.focus();
        return false;
      }
    }
    if(phone1 == "0")
    { 
      alert("請輸入正確電話號碼格式");
      txt.focus();
      return false;
    }
    
    txt=document.getElementById(txtPHONE2);
    var phone2=document.getElementById(txtPHONE2).value;
    var nab1=phone2.length-1;
    for (var j=0;j<=nab1;j++)
    {
      if (z.indexOf(phone2.substr(j,1)) == -1)
      {
        alert("請輸入正確電話號碼格式");
        txt.focus();
        return false;
      }
    }
    if(phone2 == "0")
    {
      alert("請輸入正確電話號碼格式");
      txt.focus();
      return false;
    }
	
	
	if (document.getElementById(ddlMember).value=='請選擇')
	{
	    txt=document.getElementById(ddlMember);
		alert('請選擇成員身分');
		txt.focus();       
		return false;
	}
	
	//if (document.getElementById(ddlMember).value=='07')
	//{
	//  if (document.getElementById(txtTCard_1).value=='' && document.getElementById(txtTCard_2).value=='')
	//  {
	//    txt=document.getElementById(txtTCard_1);
	//    alert('請填寫 全國教師會會員卡號 或 教師識別證卡號');
	//    txt.focus();
	//    return false;
	//  }
	//}
		
	if (trim(document.getElementById(txtNAME).value)=='')
	{
	    txt=document.getElementById(txtNAME);
		alert('請輸入網路代稱');
		txt.focus();       
		return false;
	}
		
	if (document.getElementById(ddlyear).value=='請選擇')
	{
	    txt=document.getElementById(ddlyear);
		alert('請選擇生日(年)');
		txt.focus();       
		return false;
	}
			
	if (document.getElementById(ddlmonth).value=='請選擇')
	{
	    txt=document.getElementById(ddlmonth);
		alert('請選擇生日(月)');
		txt.focus();       
		return false;
	}
		
	if (document.getElementById(ddlday).value=='請選擇')
	{
	    txt=document.getElementById(ddlday);
		alert('請選擇生日(日)');
		txt.focus();       
		return false;
	}
		
	if (document.getElementById(rblF).checked==false&&document.getElementById(rblM).checked==false)
	{
		txt=document.getElementById(rblF);
		alert('請選擇性別');
		txt.focus();       
		return false;
	}	
}

//檢查身份證
function gfcChkID(pID)
{
    //var tobjRtn = new Object();
    var tobjRtn = true;
    var ixI;
    var tAreaNo;
    var tSum;
    var tAreaCode;
    var tSecondID;         //身份證第二碼

    if (pID == "" || pID == null)
    {
        //tobjRtn.eErr = false;
        tobjRtn = false;
        return tobjRtn;
    }
    tobjRtn.eErr = true;
    pID = pID.toUpperCase(); 
    if (pID.length != 10)//確定身份證字號有10碼
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S010');
        tobjRtn = false;
        return tobjRtn;             
    }       
    tAreaCode = pID.substr(0,1);
    if (tAreaCode.valueOf() < "A" || tAreaCode.valueOf() > "Z")//確定首碼在A-Z之間
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S011');
        tobjRtn = false;
        return tobjRtn;
    }  
    if (isNaN(parseInt(pID.substring(1,10),10)) == true) //確定2-10碼是數字
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S012');
        tobjRtn = false;
        return tobjRtn;
    }   
    //身份證號碼第 2 碼必須為 1 或 2
    tSecondID = pID.substr(1,1);
    if (tSecondID != "1" && tSecondID != "2")
    {   
        //tobjRtn.eErrDesc = gfcGetErrDesc('S013');
        tobjRtn = false;
        return tobjRtn;
    }
    //取得首碼對應的區域碼，A ->10, B->11, ..H->17,I->34, J->18...
    tAreaNo = "ABCDEFGHJKLMNPQRSTUVXYWZIO".search(tAreaCode) + 10;
    pID = tAreaNo.toString(10) + pID.substring(1,10);   
   
    //  取得CheckSum的值
    //  核對身份證號碼是否正確
    //  A  = 身份證號碼區域碼第 1碼
    //  A0 = 身份證號碼區域碼第 2碼 * (10 - 1)
    //  A1 = 身份證號碼第 2碼 * (10 - 2)
    //  A2 = 身份證號碼第 3碼 * (10 - 3)
    //  A3 = 身份證號碼第 4碼 * (10 - 4)
    //  A4 = 身份證號碼第 5碼 * (10 - 5)
    //  A5 = 身份證號碼第 6碼 * (10 - 6)
    //  A6 = 身份證號碼第 7碼 * (10 - 7)
    //  A7 = 身份證號碼第 8碼 * (10 - 8)
    //  A8 = 身份證號碼第 9碼 * (10 - 9)
    //  CheckSum = A + A0 + A1 + A2 + ........ + A7 + A8

    tSum = parseInt(pID.substr(0,1),10) + parseInt(pID.substr(10,1),10);   

    for(ixI=1;ixI<=9;ixI++)
    {   
        tSum = tSum + parseInt(pID.substr(ixI,1),10)*(10-ixI);
    }  
	
    if ((tSum % 10) != 0)
    {
        //tobjRtn.eErrDesc = gfcGetErrDesc('S013');
        tobjRtn = false;
        return tobjRtn;
    }
    //tobjRtn.eErr = false;
    tobjRtn = true;
    return tobjRtn;
}

function testNu2m(){
//48~57是數字0~9
//40~57是數字0~9跟一些電話號碼符號
//35是#號
if ( !(window.event.keyCode>=35 && window.event.keyCode<=57 ))
      window.event.keyCode = 0;
}

function r_imgcheck(id){
document.getElementById(id).outerHTML='<img style="cursor:hand" id=imgcheck onclick="r_imgcheck(this.id);" src=imgcheck.aspx>';
}

//經銷商(top)
function distributor_n()
{
  var txt;
  txt=document.getElementById("txtManager");
  txt.value='';
}
//經銷商(down)

//教師會認證(top)
function teacher()
{
  if(document.getElementById("ddlMember").options[document.getElementById("ddlMember").selectedIndex].value=='07')
  {
    document.getElementById("pal_teacher").style.display="block";
  }
  else
  {
    document.getElementById("pal_teacher").style.display="none";
  }
}
//教師會認證(down)

//服務說明(top)
function view(id)
{
  if (document.getElementById(id).style.display=="none")
  {
    document.getElementById(id).style.display="block";
  }
  else
  {
    document.getElementById(id).style.display="none";
  }
}
//服務說明(down)

//母親節賀卡(top)
function checkMail(txtMail)
{
  if(document.getElementById(txtMail).value=='')
  {
    txt=document.getElementById(txtMail);
    alert('請輸入電子信箱');
    txt.focus();       
    return false;  
  }
  else
  {
    var fobj=document.getElementById(txtMail).value;
    var check=/.+@.+\..+/;
    if (fobj.match(check) ==null)
    {
      txt=document.getElementById(txtMail);
      alert("請輸入正確的電子信箱"); 
      txt.focus(); 
      txt.value="";
      return false;
    }  
  }
}
//母親節賀卡(down)
