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;
} 
var loginDivWidth = 300;

/*定义登录页面*/	
var sign_in_flow = '<table width="300"  border="0" cellpadding="0" cellspacing="0"><tr height="25" width="100%"><td bgcolor="#6666CC"><b><font color="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MPB Member Login</font></b></td></tr><tr height="10"><td></td></tr>'
+'<form action="../member/member_hide_this.asp" method="post" name="frm_Login" id="frm_Login"><tr height="28"><td><div><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User Name:&nbsp;</b>'
+'<input type="text" name="username" id="username" maxlength="30" style="width:150px;ime-mode:disabled;" /></div></td></tr>'
+'<tr height="28"><td><div><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password&nbsp;:&nbsp;</b><input type="password" name="password" id="password" maxlength="30" style="width:150px" /></div></td></tr>'
+'<tr height="28"><td><div >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="submit" type="submit" id="username" onclick="signFlow(1);" value="Login"/>'
+'&nbsp;&nbsp;<input name="button" type="button" onclick="cancelSign();" value="cancel"/></div></td></tr></form>'
+'<tr height="28"><td align="left"><a href="javascript:loadForgetPwdFlow();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="0000FF"><b>Find back your account</b></font></a></td></tr><tr height="5"><td></td></tr></table>';

/*定义找回账户密码页面*/	  
var get_back_password= '<form name="form1" method="post" action="../member/forget_password_action.asp"><table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td colspan="3"><div align="center" style="background:#6666CC;height:25px;line-height:25px;"><font color="#FFFFFF"><b>Find back you MPB account</b></font></div></td>'
+'</tr><tr height="5"><td colspan="3"></td></tr><tr><td width="25">&nbsp;</td><td width="250" align="left">&nbsp;&nbsp;&nbsp; Please enter your registered email address, and we will send you a message with your user name and password.If you can not receive the message,please contact webmaster for help.</td>      <td width="25">&nbsp;</td></tr><tr height="28"><td>&nbsp;</td><td><strong>Please enter your registered email:</strong></td><td>&nbsp;</td></tr><tr height="28"><td>&nbsp;</td><td><input name="Email" type="text" size="30" /></td><td>&nbsp;</td></tr><tr height="28"><td>&nbsp;</td><td><div align="center">&nbsp;&nbsp;<input type="submit" name="Submit" value="Submit" />  &nbsp;&nbsp;<input name="button" type="button" onclick="cancelSign();" value="cancel"/></div></td><td>&nbsp;</td></tr></table>  </form>';

function loadSignInFlow(){
	G("sign_div").innerHTML = sign_in_flow;
	G("username").focus();
};
/*注册
var sign_up_flow = '<div style="background:#CCFF00;">Create New Account</div><div>e-mail:*</div><div>'
       + '<input type="text" id="username" maxlength="64" size="30"/>'
       + '</div><div>password:*</div><div><input type="password" id="password" size="30"/>'
        + '</div><div>password again:*</div><div><input type="password" id="sign_repwd" size="30"/>'
        + '</div><div><input type="button" value="creat account" onclick="signFlow(0);" id="username"/> '
        + ' <input type="button" value="cancel" onclick="cancelSign();"/></div>'
        + '<p><a href="javascript:loadSignInFlow();">login</a></p>';

function loadSignUpFlow(){
	G("sign_div").innerHTML = sign_up_flow;
	G("username").focus();
};
*/
function cancelSign(){
	G("sign_div").style.display = 'none';
	G("cover_div").style.display = 'none';
	document.body.style.overflow = '';
};

var forget_pwd_flow = '<div style="background:#FF99FF;">Forget Password</div><div>e-mail:*</div><div>'
+ '<input type="text" id="username" maxlength="64" size="30"/>'
+ '</div><div><input type="button" value="sent pwd to e_mail" onclick="signFlow(2);" id="username"/>'
+ '<input type="button" value="cancel" onclick="cancelSign();"/></div>';

function loadForgetPwdFlow(){
	G("sign_div").innerHTML = get_back_password;
	G("username").focus();
};

/*
function checkEmail(){
	if((G("username").value.indexOf('@')<=0)||(G("username").value.indexOf('.')<=0)){
		return '<div style="color:#FF0000";">Sorry, unrecognized e_mail.</div>';
	}
	return '';
}
*/
/*
function checkPwd(){
	if(G("password").value.trim() == ''){
		return '<div style="color:#FF0000";">Password field is required.</div>';
	}
	return '';
}
function checkRePwd(){
	if(G("password").value.trim() != G("sign_repwd").value.trim()){
		return '<div style="color:#FF0000";">The specified passwords do not match.</div>';
	}
	return '';
}
*/

function signFlow(isSignIn){
	var error = checkEmail();
	var htmlText = null;
	if (isSignIn == 1) {
		if (error == ''){
			Error = checkPwd();
		}
		htmlText = sign_in_flow;
	} else if (isSignIn == 0) {
		if (error == ''){
		Error = checkPwd();
		if (error == ''){
			Error = checkRePwd();
		}
	}
	htmlText = sign_up_flow;
} else if (isSignIn == 2) {
	htmlText = forget_pwd_flow;
	}
	var eMailValue = G("username").value.trim();
	if (error == '') {
	} else {
		G("sign_div").innerHTML = error + htmlText;
    G("username").value = eMailValue; 
	}
};

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;
     }
    }
   }
}
function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
} 

function popSign(isLogin){
   if (G("sign_div")) {
    G("sign_div").style.display = '';
   } else {
    var signDiv = GC('div');
    document.body.appendChild(signDiv);
    signDiv.id = 'sign_div';
    signDiv.align = "center";
    signDiv.onkeypress = function(evt){
          var e = window.event?window.event:evt;
          if (e.keyCode==13 || e.which==13) {
           if (G("username")) {
            G("sign_div").focus();
            G("username").click();
           }
          }
         };
    with (signDiv.style) {
     position = 'absolute';
 //    left = (document.documentElement.clientWidth - loginDivWidth)/2 + 'px';
 //    top = (document.documentElement.clientHeight - 300)/2 + 'px';
      left ='400px';
      top ='150px';
     width = loginDivWidth + 'px';
     zIndex = 99;
     background = '#FFFFFF';
     border = '#6666CC solid 2px';
    }
   }
   if(isLogin) {
    G("sign_div").innerHTML = sign_in_flow;
   } else {
    G("sign_div").innerHTML = change_pwd_flow;
   }
  
}
function popSignFlow(isLogin) {
   popCoverDiv();  
   popSign(isLogin);  
   document.body.style.overflow = "hidden";
     
      if(isLogin) {
       G("username").focus();
      } else {
       G("old_pwd").focus();
      }
}
/*
function changePwd(){
    var error = checkOldPwd();
    if (error == ''){
     error = checkPwd();
    }
   if (error == ''){
    error = checkRePwd();
   }

    var oldPwd = G("old_pwd").value.trim();
    var newPwd = G("password").value.trim();
   if (error == '') {
     var url = basePath + "?q=tripuser/tripuser_change_pwd_ajax/" + oldPwd + "/" + newPwd;
     exeRequest(url, getSignText, null);
    } else {
    G("sign_div").innerHTML = error + change_pwd_flow;
    }
};
function checkOldPwd(){
   if(G("old_pwd").value.trim() == ''){
    return '<div style="color:#FF0000";">Old Password field is required.</div>';
   }
   return '';
}
var change_pwd_flow = '<div style="background:#33FFFF;">Change Your Password</div><div>old password:*</div><div>'
       + '<input type="password" id="old_pwd" size="30"/>'
       + '</div><div>new password:*</div><div><input type="password" id="password" size="30"/>'
        + '</div><div>new password again:*</div><div><input type="password" id="sign_repwd" size="30"/>'
        + '</div><div><input type="button" value="change password" onclick="changePwd();" id="username"/> '
        + ' <input type="button" value="cancel" onclick="cancelSign();"/></div>';
*/