function cancelLogin(){
    G("login_div").style.display = 'none';
    G("cover_div").style.display = 'none';
   document.body.style.overflow = '';
};


function MemberLoginGoBack(){
	if(http_request.readyState==4){
     if(http_request.status==200){
		  var return_str = http_request.responseText;
		   if ("OK" == return_str)
		   {
			   alert("您已安全登入可以進行下步操作!");
			   //document.quick_post.submit();
			   //cancelLogin();
			   ip_alreadly_vote = 1;
			   user_is_login = 1;
			    post_check();
	
		   }else{
				alert(return_str);
				G("mmm_name").focus();
		   }    	
     }else{
          alert("您所請求的頁面不正常!");
     }
   }
}





function MemberLoginFunc(){
	var m_name = document.MemberLogin.m_name.value;
	var m_pass = document.MemberLogin.m_pass.value;
	//var m_code = document.MemberLogin.m_code.value;

	var url = "Ajax_login.php";
	//var content = "name="+m_name+"&"+"pass="+m_pass+"&"+"code="+m_code+"&action=login";
	var content = "name="+m_name+"&"+"pass="+m_pass+"&action=login";
	send_request(url, "GET", content, MemberLoginGoBack);
}




function G(id){
  return document.getElementById(id);
}
     
function GC(t){
  return document.createElement(t);
}
    
String.prototype.trim = function(){
  return this.replace(/(^\s*)|(\s*$)/g, '');
}
    
function isIE(){
  return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}
    
function getBodySize(){
  var bodySize = [];
  with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
  }
    return bodySize;
}
 
function popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('div');
    document.body.appendChild(coverDiv);
    coverDiv.id = 'cover_div';
    
    with(coverDiv.style) {
     position = 'absolute';
     background = '#CCCCCC';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     width = bodySize[0] + 'px'
     height = bodySize[1] + 'px';
     zIndex = 98;
     if (isIE()) {
      filter = "Alpha(Opacity=60)";
     } else {
      opacity = 0.6;
     }
    }
   }
}

var loginDivWidth = 400;

/*
var Login_box_string =  '<div>'
					   +'<form  method="post" name="MemberLogin">'
					   + '<table width="300"  border="0" cellspacing="0" cellpadding="0">'
					   +'<tr>'
					   +'<td colspan="3"><img src="images/box_login_top.jpg" width="300" height="30" /></td>'
					   +'</tr>'
					   +'<tr>'
					   +'<td width="7" background="images/box_vote_left.jpg"></td>'
					   +'<td width="300" align="left">'
					   +'<table width="100%"  border="0" cellspacing="0" cellpadding="0" >'
					   +'<tr><td class="font_green">帳號:</td><td><input name="m_name" size="12" type="text" class="input" id="mmm_name"></td></tr>'
					   +'<tr><td class="font_green">密碼:</td><td><input name="m_pass" size="12" type="password" class="input"></td></tr>'
					   +'<tr><td class="font_green" valign="bottom">驗證碼:</td><td><input name="m_code" size="4" maxlength="4" type="text" class="input">&nbsp;<img src="authimg.php" ></td></tr>'
					   +'<tr><td colspan="2">'
					   +'<img src="images/login.jpg"  border="0" alt="登入" onclick="javascript:MemberLoginFunc();">'
					   +'<img style="CURSOR: hand;" src="images/forget_pass.jpg"  alt="忘記密碼" onclick="javascript:location.href=\'get_password.php\'" border="0">'
					   +'</td></tr>'
					   +'<tr><td colspan="2"  align="center" valign="top"><a href="javascript:void(cancelLogin());" class="font_green"><b>關閉登陸框</b></a></td></tr>'
					   +'</table>'
					   +'</td>'
					   +'<td width="7" background="images/box_vote_right.jpg"></td>'
					   +'</tr>'
					   +'<tr>'
					   +' <td colspan="3"><img src="images/box_vote_bottom.jpg" width="300" height="13" /></td>'
					   +'</tr>'
					   +'</table>'
					   +'</form>'
					   +'</div>';
*/



var Login_box_string = '<style type="text/css">'
					   +'.d_wrap01 { width:400px;  border:#ccc 1px solid; border-top:#ccc 3px solid; background:#fff; }'
					   +'.d_wrap01 ul,li { list-style:none; padding:0px; margin:0px; }'
					   +'.d_logintitle { background:#efefef url(images/icon.gif) left no-repeat; padding-left:23px; font-weight:bolder; height:22px; font-weight:bolder; color:#333; font-size:12px; overflow:hidden; }'
					   +'.d_logintitle td { vertical-align:middle; }'
					   +'.d_logincontent { padding:8px; padding-left:15px; }'
					   +'.d_loginform { padding-left:15px; }'
					   +'.d_loginform label { width:60px; font-size:12px; color:#666; display:block; float:left; }'
					   +'.d_loginform li { padding-bottom:8px; }'
					   +'</style>'
					   +'<div class="d_wrap01">'
					   +'	<div class="d_logintitle">'
					   +'		<TABLE style="width:100%">'
					   +'<TR>'
					   +'			<TD style="font-size:12px; text-align:left; padding-top:3px;">會員登入</TD>'
					   +'			<TD style="text-align:right; padding-right:3px;"><a href="javascript:void(cancelLogin());"><img src="images/close.gif" border="0"></a></TD>'
					   +'		</TR>'
					   +'		</TABLE>'
					   +'	</div>'
					   +'	<div class="d_logincontent">'
					   + LOGIN_BOX_TOP_STRING
					   +'</div>'
					   +'<form  method="post" name="MemberLogin">'
					   +'<div class="d_loginform">'
					   +'<ul>'
					   +'<li><label>帳號:</label><INPUT TYPE="text" NAME="m_name" style="border:#ccc 1px solid; height:18px;"></li>'
					   +'<li><label>密碼:</label><INPUT TYPE="password" NAME="m_pass" style="border:#ccc 1px solid; height:18px;"></li>'
					   //+'<li><label>驗證碼:</label><INPUT TYPE="text" NAME="m_code" style="border:#ccc 1px solid; height:18px; width:4em;">&nbsp;<img src="authimg.php" ></li>'
					   +'<li><INPUT TYPE="button" onclick="javascript:MemberLoginFunc();" value="登入全民公投會員" style="border:#ccc 1px solid; background:#ccc;font-size:12px; width:100px;">&nbsp;<input type="button" onclick="javascript:jumpLoginPage();" value="加入全民公投會員" style="border:#ccc 1px solid; background:#ccc;font-size:12px; width:100px;"></li>'
					   +'</ul>'
					   +'</div>'
					   +'</form>'
					   +'</div>';



function LoadLoginBox(){
	if (G("login_div"))
	{
		G("login_div").style.display = '';
	}else{
		var loginDiv = GC('login_div');
		document.body.appendChild(loginDiv);
		loginDiv.id = 'login_div';
		loginDiv.align = 'center';
		with(loginDiv.style) {
			position = 'absolute';
			left = (document.documentElement.clientWidth - loginDivWidth)/2 + 'px';
			top = (document.documentElement.clientHeight - 300)/2 + 'px';
			width = loginDivWidth + 'px';
			zIndex = 99;
			background = '#FFFFFF';
			border = '#cccccc solid 1px';
		}
	}
	G("login_div").innerHTML = Login_box_string;
}


function popLoadLoginBox(){
	popCoverDiv();//create
	LoadLoginBox();
	document.body.style.overflow = "hidden";
	//G("mmm_name").focus();
	window.scrollTo(0,0);
}

					
function jumpLoginPage(){
	window.location.href='reg.php?action=agree&from=ajax&backurl='+backurl;
}

