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 = 310;
 
	  
var sign_in_flow = 
'<table width="100%" border="0" cellspacing="0" cellpadding="0">'
  + '<tr><td height="25" bgcolor="#FF6600" style="color:#fff; font-weight:bold;">　福客登录：</td><td width="80" height="25" bgcolor="#FF6600" align="center" valign="middle" style="color:#fff; font-weight:bold;"><a href="#" onclick="cancelSign();" style="color:#ff0000">返回　</a></td></tr>'
  + '<tr bgcolor="#FFFFFF"><td colspan="2"><form action="" method="post"  name=myform  onSubmit="return checkform()" style="margin:0; padding:0;">'
  + '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="25" align="center" valign="middle" >　用户名：<input name="form_username" type="text" class="input" id="form_username" style="height:18px; width:150px"/></td></tr>'
  + '<tr><td height="25" align="center" valign="middle" > 　密　码：<input name="form_password" type="password" class="input" id="form_password" size="20"style="height:18px; width:150px" /></td></tr>'
  + '<tr><td height="25" align="center" valign="middle" ><input name="form_time" type="checkbox" id="form_time" value="31536000" />记住我 ｜<font color="#ff0000"><a href="http://www.fortj.com/reg.php" target="_blank">马上注册</a></font></td></tr>'
    + '<input type=hidden name=submitok value="checkuser">'
      + '<input type=hidden name="posturl" value="<?php  echo $jumpurl; ?>">'
 + '<tr><td height="25" align="center" valign="middle" ><label><input name="submit" type="submit" value="登录" /></label></td></tr>'
  + '</table></form></td></tr></table>'
// '<div style="width:310px; line-height:25px;background:url(http://www.fortj.com/style/img/LoginBar.gif) no-repeat; font-size:14px; font-weight:bolder; color:#fff;">　福客登录：</div>'
//       + '<div style=" width:308px; background:#FFFFFF; border:1px solid #ccc; border-top:none">'
//       + '<form action="" method="post"  name=myform  onSubmit="return checkform()" style="margin:0; padding:0;">'
//	   + '<div style=" width:210px; float:left">'
//	   + '<p style="height:20px;"></p>'
//       + '<p style=" line-height:35px;font-size:12px; color:#333333"><span style=" width:350px;line-height:25px;background:url(http://www.fortj.com/style/img/LoginBar.gif) no-repeat; font-size:14px; font-weight:bolder; color:#fff;"></span>　用户名：<input name="form_username" type="text" class="input" id="form_username"style="height:18px;width:140px" /></p>'
//	   + '<br/>'
//	   + '<p style=" line-height:35px;font-size:12px; color:#333333"><span style=" width:350px; line-height:25px;background:url(http://www.fortj.com/style/img/LoginBar.gif) no-repeat; font-size:14px; font-weight:bolder; color:#fff;"></span>　密　码：<input name="form_password" type="password" class="input" id="form_password"style="height:18px;width:140px" /></p>'
//	  + '<p style=" line-height:30px;font-size:12px; color:#333333;">　　　　　<a href="#" target="_blank"><font color="#ff0000">忘记密码？</font></a>｜<a href="http://www.fortj.com/reg.php" target="_blank">注册</a>｜<a href="#" onclick="cancelSign();" style="color:#ff0000">返回</a></p>'
//	   + '<input type=hidden name=submitok value="checkuser">'
//       + '<input type=hidden name="posturl" value="<?php  echo $jumpurl; ?>">'
//	   + '</div><div style=" width:96px; height:100px; float:left; padding:15px 0 ;text-align:left;font-size:12px; color:#333333""><input name="submit" type="submit" value=""style="background:url(http://www.fortj.com/style/img/LoginButten.gif) no-repeat; width:70px; height:50px; border:0;" />　　<input name="form_time" type="checkbox" id="form_time" value="31536000" />记住我 </div>'
//	    
//	   + '</form>'
//       + '</div>'
function loadSignInFlow(){
   G("sign_div").innerHTML = sign_in_flow;
    G("sign_email").focus();
};
var sign_up_flow = '<div style="background:#CCFF00;">Create New Account</div><div>e-mail:*</div><div>'
       + '<input type="text" id="sign_email" maxlength="64" size="30"/>'
       + '</div><div>password:*</div><div><input type="password" id="sign_pwd" 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="sign_button"/> '
        + ' <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("sign_email").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="sign_email" maxlength="64" size="30"/>'
        + '</div><div><input type="button" value="sent pwd to e_mail" onclick="signFlow(2);" id="sign_button"/>   '
        + '   <input type="button" value="cancel" onclick="cancelSign();"/></div>';
function loadForgetPwdFlow(){
   G("sign_div").innerHTML = forget_pwd_flow;
    G("sign_email").focus();
};
function checkEmail(){
   if((G("sign_email").value.indexOf('@')<=0)||(G("sign_email").value.indexOf('.')<=0)){
    return '<div style="color:#FF0000";">Sorry, unrecognized e_mail.</div>';
   }
   return '';
}
function checkPwd(){
   if(G("sign_pwd").value.trim() == ''){
    return '<div style="color:#FF0000";">Password field is required.</div>';
   }
   return '';
}
function checkRePwd(){
   if(G("sign_pwd").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("sign_email").value.trim();
   if (error == '') {
    } else {
    G("sign_div").innerHTML = error + htmlText;
    G("sign_email").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 = "left";
    signDiv.onkeypress = function(evt){
          var e = window.event?window.event:evt;
          if (e.keyCode==13 || e.which==13) {
           if (G("sign_button")) {
            G("sign_div").focus();
            G("sign_button").click();
           }
          }
         };
    with (signDiv.style) {
     position = 'absolute';
     left = (document.documentElement.clientWidth - loginDivWidth)/2 + 'px';
     top = (document.documentElement.clientHeight - 310)/2 + 'px';
     width = loginDivWidth + 'px';
     zIndex = 99;
     background = '';
     border = 'none';
    }
   }
   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("sign_email").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("sign_pwd").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="sign_pwd" 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="sign_button"/> '
        + ' <input type="button" value="cancel" onclick="cancelSign();"/></div>';

