//檢查Cookie
function get_cookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			offset=j;
			
			//沒有資料
			if (document.cookie.substring(offset+1, 1) == ";"){
				return null;
			}
			if (offset+1>clen){
				return null;
			}
			           
			var endstr = document.cookie.indexOf (";", offset);
			
			if (endstr == -1) endstr = document.cookie.length;
			return unescape (document.cookie.substring(offset, endstr));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}


//解碼程式 , 在unescape後解碼還原中文
function decodecookie(str)
{
  var strArr;
  var strRtn="";
  strArr=str.split("a");
  for (var i=strArr.length-1;i>=0;i--) 
    {strRtn+=String.fromCharCode(eval(strArr[i]));}

    return strRtn;
}




function get_cookie2(name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) {
	offset=j;

      //沒有資料
      if (document.cookie.substring(offset+1, 1) == ";")
          return null;
      if (offset+1>clen)
          return null;

	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;


    return decodecookie(unescape(document.cookie.substring(offset, endstr)));

      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }
   return null;
}



//login.js專用
function check1()
{
  var f = document.form2;
  var y = '';
  if (f.dfpcard.value == '') {y+='您忘了填寫「會員卡號」喔!\n';}
  if (f.pincode.value == '') {y+='您忘了填寫「密碼」喔!\n';}
  
  if (y=='')
    {return true;}
  else 
  {
      //y = '項目前有「*」號者，表示為必要填寫欄位喔!\n\n' + y
      alert(y);
      return false;
  }
}



        
function sleep(timeNum){   
	window.setTimeout(writeNum,1000,timeNum);   
} 

function logoutChek(){
	var gbstr = ''; 
	var versn = '';
	gbstr = document.cookie.indexOf("Referer=")

	if (gbstr > -1 ) {
		versn = 'GB'
	}
	else{
		versn = 'EC'
	}
	window.location.href = "ht" + "tps://calec.china-airlines.com" + "/e_club/tw/logout_t.asp?ver=" + versn + "&tm=" + (new Date()).getSeconds();
	
}

document.write('						<div id="memberArea">');
document.write('						<!--- 如果未登入跑這段 開始 --->');

var loginyn = get_cookie('clubid');  

if ((loginyn == null) || (loginyn == "")) { 
	var gbpos = ''
	var gb =''
 
document.write('							<form name="form2" method="post" autocomplete="off" onsubmit="return check1();">');
document.write('								<div style="width:110px; text-align:left; margin:0 auto;">');
document.write('									<div style="margin-bottom:3px"><input type="text" name="dfpcard" class="input" size="21" maxlength="9" onblur="if(this.value==\'\'){this.value=\'會員卡號\'}else{this.value=this.value.toUpperCase();}" onfocus="if(this.value==\'會員卡號\') this.value=\'\'" value="會員卡號" autocomplete="off"></div>');
document.write('									<div style="margin-bottom:5px"><input type="password" name="pincode" class="input" size="14" maxlength="8" autocomplete="off"> <input type="image" src="/ch/imgs/btn_go.gif" width="22" height="22" align="absmiddle" border="0"></div>');
document.write('								</div>');
document.write('							</form>');

expdate = new Date("Jun 24,2008");
	if (expdate >= new Date()){
		hyperLinkStr = 'http://www.china-airlines.com/ch/dfpch/dfpch000173.htm'
	}
	else{
		hyperLinkStr = 'https://calec.china-airlines.com/club/tw/clubjo_t.asp'
	}

document.write('							<a href="' + hyperLinkStr + '">加入會員</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://calec.china-airlines.com/club/tw/pwdqry_t.asp">密碼查詢</a><br>');
document.write('							<a href="https://calec.china-airlines.com/club/tw/crdqry_t.asp">卡號查詢</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://calec.china-airlines.com/club/tw/emlreq_t.asp">申請密碼</a>');
document.write('						<!--- 如果未登入跑這段 結束 --->');
gbpos = document.cookie.indexOf ("Referer=")
if (gbpos > -1 ) {
	gb = "T"
}
document.form2.action='ht' + 'tps://calec.china-airlines.com/e_club/tw/login_t.asp?gbver=' + gb;

} else {   

document.write('		<!--- 如果已登入跑這段 開始 --->');
document.write('		<table width="130" border="0" cellspacing="0" cellpadding="0" align="center">');
document.write('			<tr>');
document.write('			<td colspan="3"><img src="/ch/imgs/member_infotop.gif" width="130" height="7"></td>');
document.write('								</tr>');
document.write('								<tr>');
document.write('									<td bgcolor="B8D2EE"><img src="/ch/imgs/empty.gif" width="1" height="1"></td>');
document.write('									<td width="128" bgcolor="E4F1FF" class="memberInfo"><span>' + get_cookie2("infoname") + '</span> ，您好！<br>');
document.write('										卡號：' + get_cookie("clubid") + '<br>');
document.write('										可換獎哩程：<br><div align="right" style="margin-right:5px">' + get_cookie("infomileage") + '哩</div></td>');
document.write('									<td bgcolor="B8D2EE"><img src="/ch/imgs/empty.gif" width="1" height="1"></td>');
document.write('								</tr>');
document.write('								<tr>');
document.write('		<td colspan="3"><img src="/ch/imgs/member_infobtm.gif" width="130" height="7"></td>');
document.write('								</tr>');
document.write('								<tr align="center">');
document.write('	<td colspan="3"><a href="javascript:logoutChek();"><img src="/ch/imgs/btn_logout.gif" width="39" height="22" vspace="4" border="0"></a></td>');
document.write('								</tr>');
document.write('							</table>');
document.write('	<script id="crec"></script><script id="crgb"></script>');
document.write('						<!--- 如果已登入跑這段 結束 --->');
}
document.write('						</div>');