document.write("<scr"+"ipt   type='text/javascript'   src=/javascript/prototype.js></scr"+"ipt>");
document.write("<input type = 'hidden' name = 'redirect_url' id = 'redirect_url' />");
document.write("<link href='/css/doudou.css?20081020' rel='stylesheet' type='text/css' />");


var loginDivWidth = 220;
var sign_in_flow = '<div id="loginBox"><form method="post" action="/pc/" name="form_login"><div id="loginForm"><h3>用户登录</h3><div class="title"><label for="loginEmail">邮箱地址：</label><span><input id="pc_mail_input" type="input" class="input1" name="pc_mail"/></span> </div><div class="title"><label for="loginPw">帐户密码：</label><span><input id="password_input" type="password"  class="input1" name="password"/></span> </div><!--div class="title"><span>校验码：<input id="validatorcode_input" type="input"  style=" color:#999; border:1px solid #cccccc; height:22px;width:50px;vertical-align:middle" name="validatorcode"/>&nbsp;<img src="/pc/register/captcha" id="captcha_image" alt="" align="absmiddle"></span> </div--><div  style="margin-top:100px"><input type="button" value="登 录" class="btn1"  name="login" onclick="jslogin();"/><input type="button" value="取消" class="btn1 " onclick="login_cancelSign();"/></div></div><div id="loginBtns1"> <a href="javascript:js_register();"><img src="/images/freeRegister.gif" alt="" class="rightMargin" /></a> <a href="/pc/member/get_password"><img src="/images/forgetpw.gif" alt="" /></a></div></form></div>';
	
  
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 popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('iframe');
    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("login_sign_div")) {
    G("login_sign_div").style.display = '';
   } else {
    var signDiv = GC('div');
    document.body.appendChild(signDiv);
    signDiv.id = 'login_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("sign_button")) {
            G("login_sign_div").focus();
            G("sign_button").click();
           }
          }
         };
    with (signDiv.style) {
     position = 'absolute';
     left = (document.documentElement.clientWidth - loginDivWidth)/2 + 'px';
     if (isIE()) {
        top = (document.documentElement.clientHeight - 300)/2 + document.documentElement.scrollTop + 'px';      
     } else {
        top = (document.documentElement.clientHeight - 300)/2 + 'px';      
     }
     width = loginDivWidth + 'px';
     zIndex = 99;
     background = '#FFFFFF';
    }
   }
   if(isLogin) {
    G("login_sign_div").innerHTML = sign_in_flow;
   }
}
  
	
function login_cancelSign(){
    document.body.removeChild(G('login_sign_div'));
    document.body.removeChild(G('cover_div'));
    document.body.style.overflow = '';
};

function check_login(url){
//	if( [% c.user_exists %] == 0){
		document.getElementById('redirect_url').value = url;
		popCoverDiv();  
		popSign(1);  
		document.body.style.overflow = "hidden";
		G("pc_mail_input").focus();
        G("captcha_image").src="/pc/register/captcha?"+Math.random();
		return false;
//	}
//	return 1;
}

function jslogin(){
   var mail = G("pc_mail_input").value.trim();
   var password = G("password_input").value.trim();
   var validatorcode = '' ; //G("validatorcode_input").value.trim();
   var url="/pc/js_login?mail="+mail;
   url = url + '&password='+password + '&validatorcode=' + validatorcode; 
	var myAjax = new Ajax.Request( url,{method: 'post', onComplete: login_result } );
   
}

function login_result( httpReq ){
	var _flag = httpReq.responseText;
	var redirect_url = G("redirect_url").value.trim();
    if( _flag == 3 ){ 
        location.href="/pc/member/information/edit"; 
    }else{
	    if( _flag == 1 ){ 
	        location.href=redirect_url ;
	    } else {
	        error = '<div style="color:#FF0000";">用户名或者密码或者验证码输入错误!</div>';
	        htmlText = sign_in_flow;
	        G("login_sign_div").innerHTML = error + htmlText;
	        G("captcha_image").src="/pc/register/captcha?"+Math.random();
	    }
    }
}

function js_register(){
	var redirect_url = G("redirect_url").value.trim();
    location.href="/pc/register?url="+redirect_url; 
}

