var timer;
function Show_Login(){
	var w=293;
	var h=148;
var content='<img src="images/Login_Top_L.jpg" class="login_title_left_img" /><div class="login_title_div"><div class="login_title_title">User Login</div><a href="javascript:removediv();">&times;</a></div><img src="images/Login_Top_R.jpg" class="login_title_right_img" /><br /><div class="login_content"><div id="login_msg"></div><br><span class="login_content_text">Username£º</span><input type="text" id="login_username" class="login_content_input" /><br /><br /><span class="login_content_text">Password£º</span><input type="password" id="login_password" class="login_content_input" /><br /><br /><div class="login_content_button"><input type="image" src="images/Login_DL.jpg" class="login_content_button_w_h" name="Submit" value="Login" onclick="chk_login(1);" />&nbsp;<input name="Submit2"  type="image" value="submit" src="images/Login_QX.jpg" class="login_content_button_w_h" onclick="removediv();"/></div><div class="login_content_bottom"><a class="login_reg_button" href="ZhuCe.asp">to enroll</a>&nbsp;&nbsp;<a href="forget_password.asp" style="text-decoration:none;color:#666;">forgot password£¿</a></div></div>';
clearTimeout(timer);
s_h=document.documentElement.scrollTop;
s_w=document.documentElement.scrollLeft;
b_h=document.documentElement.clientHeight;
b_w=document.documentElement.clientWidth;
w_h=document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight;
w_w=document.documentElement.scrollWidth;
hi=(b_h-h)/2+s_h-50;
wi=(b_w-w)/2+s_w;
if ($('msg_bg')==null&&$('msg')==null){
var msg_bg=document.createElement("div");
var msg=document.createElement("div");
		msg_bg.style.cssText="position:absolute;z-index:1;background:#000;width:"+w_w+"px;height:"+w_h+"px;top:0px;left:0px;-moz-opacity: 0.5; opacity: 0.5; filter:alpha(opacity=50); "
		msg_bg.id="msg_bg";
	msg.style.cssText="background:none;position:absolute;top:"+hi+"px;left:"+wi+"px;z-index:2;width:"+w+"px; height:"+h+"px;";
	msg.id="msg";
	msg.innerHTML=(content);
	document.body.style.overflow = 'hidden'; 
	document.body.style.height=w_h+"px";
	selecthidden();
	window.document.body.appendChild(msg_bg); 
	window.document.body.appendChild(msg);
//time=setTimeout("removediv()",10000);
}else{
clearTimeout(timer);
removediv();
Show_Login();
//time=setTimeout("removediv()",10000);
}
}
function removediv()
{
clearTimeout(timer);
var div = $("msg_bg");  
  div.parentNode.removeChild(div); 
  div = $("msg"); 
  div.parentNode.removeChild(div);  //É¾³ý
  document.body.style.overflow = ''; 
  selectshow();
}
function selecthidden(){
 var  input_elements=document.getElementsByTagName("select");
 var  theLength=input_elements.length;
 for(i=0;i<theLength;i++)
 {
  input_elements[i].style.visibility="hidden";
  }
}
// ÏÔÊ¾ select
function selectshow(){
 var  input_elements=document.getElementsByTagName("select");
 var  theLength=input_elements.length;
 for(i=0;i<theLength;i++)
 {
  input_elements[i].style.visibility="";
  }
}
var chk_err="";
function chk_empty(id,name,type){
if($(id).value==""){
if(chk_err=="") f_id=id;
chk_err+=name+type;
$(f_id).focus();
}else{
chk_err=chk_err;
}
}

function chk_login(check_types){
chk_err="";
switch(check_types){
case 1:
chk_empty('login_username','Username',' ');
chk_empty('login_password','Password',' ');
if(chk_err==""){
	uid=escape($('login_username').value);
	psd=escape($('login_password').value);
user_login(check_types,uid,psd);
}else{
$('login_msg').innerHTML="<img src='images/err.gif' style='width:18px; height:18px;vertical-align:-5px;'/>&nbsp;follow must be type£º"+chk_err;
}
break;
default:
chk_empty('username','username','\n');
chk_empty('password','password','\n');
if(chk_err==""){
	uid=escape(document.getElementById('username').value);
	psd=escape(document.getElementById('password').value);
user_login(check_types,uid,psd);
}else{
alert("follow must be type£º\n"+chk_err);
}
break;
}
}

function user_login(check_types,username,password){
var sURL = "User_Login.Asp?type=login&username="+username+"&password="+password+"&n="+Math.random() ;
var xmlhttp = createAjax() ;
if (xmlhttp) {  
xmlhttp.open("get",sURL,true) ;
xmlhttp.send(null) ;
xmlhttp.onreadystatechange=function() {  
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
eval("var json = " + xmlhttp.responseText) ;
var json=json;
if(json.err_msg=="0"){
if(check_types==1){
$('login_msg').innerHTML="<img src='images/Loading.gif' style='width:18px; height:18px;vertical-align:-5px;'/>&nbsp;User["+json.username+"]success login£¡";
clearTimeout(timer);
time=setTimeout("removediv()",1000);
index_user_login(json.username,json.user_type);
}else{
	index_user_login(json.username,json.user_type);
	}
}else{
	if(check_types==1){
$('login_msg').innerHTML="<img src='images/err.gif' style='width:18px; height:18px;vertical-align:-5px;'/>&nbsp;username or password is not right£¡";
	}else{
		alert('username or password is error');
		}
	}
}else{
if(check_types==1) $('login_msg').innerHTML="<img src='images/Loading.gif' style='width:18px; height:18px;vertical-align:-5px;'/>&nbsp;contact with server,please wait a minute...";
}
}
}
}
function check_user_type(user_type){
	switch(user_type){
		case 1:
		return "common";
		break;
		case 2:
		return "agent"
		break;
		case 3:
		return "sailor"
		break;
		default:
		return "anonymous ";
		break;
		}
	}
function index_user_login(username,user_type){
	if($('index_user_login')){
		$('index_user_login').innerHTML="<div style=\"margin:10px 15px 0 15px;color:#F00;line-height:20px;\">hi,welcome!<br>Username£º"+username+"<br/>level£º"+check_user_type(user_type)+"<br/><a href=\"Orders.asp\" style=\"color:#666666\">my order</a>&nbsp;&nbsp;<a href=\"chg_password.asp\" style=\"color:#666666\">modify password</a>&nbsp;&nbsp;<a href=\"User_Login.Asp?type=logout\" style=\"color:#666666\">logo out</a></div>";
		}
		$('top_user_inf').className="top_user_inf";
		$('top_user_inf').innerHTML="<div style=\"position:absolute; top:65px; width:300px; height:30px; line-height:30px; z-index:1;\"><a href=\"Orders.asp\" style=\"color:#666666\">my order</a>&nbsp;&nbsp;<a href=\"chg_password.asp\" style=\"color:#666666\">modify password</a>&nbsp;&nbsp;<a href=\"User_Login.Asp?type=logout\" style=\"color:#666666\">logo out</a></div>"+username;
	}