var webjs = "http://www.mop.com";
var backUrl = document.location.href;
var isLogined = false;
function DecodeCookie(str){
		var strArr;
		var strRtn="";
		strArr=str.split("O");
		for (var i=strArr.length-1;i>=0;i--) 
		strRtn+=String.fromCharCode(eval(strArr[i]));
	return strRtn;
}

function getMopidFromCookie() {
	var id = 0;
	var allcookie = document.cookie.split('; ');
	for(var i=0;i<allcookie.length;i++){
		var cookiename = allcookie[i].split('=')[0];
		if(cookiename=='mop_logon'){
			var value = unescape(allcookie[i].split('=')[1]);
			var tmp = value.split("|");
			id = parseInt(tmp[0]);
		}
	}
	return id;
}
var mopId=getMopidFromCookie() ;
var nickname = "";
var loginTimes = '';
var mp = '';
var mm = '';
var status = '';
var allcookie = document.cookie.split('; ');


for(var i=0;i<allcookie.length;i++){
	var cookiename = allcookie[i].split('=')[0];
	if(cookiename == 'mop_status'){
		var tmpString = unescape(allcookie[i].split('=')[1]);
		status = DecodeCookie(tmpString);
		status = status.replace('?','O').replace('?','O').replace('?','O');
		try
		{
			var stat = status.split("|");
			nickname = stat[0];
			loginTimes = stat[7];
			mp = stat[2];
			mm = stat[3];
		}
		catch (e) {
		}
	}
}


document.writeln("<style>");
document.writeln("<!--");
document.writeln("");
document.writeln("\/*top*\/");
document.writeln("");
//document.writeln("#banner_wai{width:835px;top:0;left:0;height:26px;background:#f1f1f3;border-bottom:1px solid #727272;border-top:1px solid #fff;font-family: \"Tahoma\", \"宋体\";}");
document.writeln("#banner_wai{width:835px;top:0;left:0;height:26px;background:#f1f1f3;border-top:1px solid #fff;font-family: \"Tahoma\", \"宋体\";}");
document.writeln("#banner{width:820px;margin:0 auto;padding-top:2px;text-align:left;font-family: \"Tahoma\", \"宋体\";}");
document.writeln("#banner .vmiddle{vertical-align:middle;font-size:12px;}");
document.writeln("#banner a {color:#3566a9; text-decoration:none;}");
document.writeln("#banner .inputk{width:100px;border:1px solid #ccc;font-size:12px;}");
document.writeln("");
document.writeln("#banner .loged{width:115px;position:relative;padding:0 5px;}");
document.writeln("#banner .loged h3{padding-left:5px;margin:0;font-size:12px;font-weight:normal;font-family: \"Tahoma\", \"宋体\";}");
document.writeln("#banner .loged img{padding-left:5px; vertical-align:middle;padding-top:3px; cursor:pointer;}");
document.writeln("#banner .loged_open{width:113px;padding:5px;position:absolute;border:solid #d1d1d1;border-width:0 1px 1px;background:#fff;top:-6px;left:0;}");
document.writeln("#banner .loged_open h4{margin:0;padding-left:5px;font-size:12px;font-weight:normal;border-bottom:1px solid #d9d9d9;padding-bottom:7px;}");
document.writeln("#banner .loged_open img{padding-left:5px; vertical-align:middle;padding-top:3px; cursor:pointer;}");
document.writeln("#banner .loged_open .mess{line-height:23px;color:#3566ab;padding:4px;}");
document.writeln("#banner .tslink a{ background:url(http:\/\/image2.mop.com\/mop\/index2009\/images\/c.gif) no-repeat 0 5px;padding:0 12px 0 7px;}");
document.writeln("*+html #banner .tslink a{ background:url(http:\/\/image2.mop.com\/mop\/index2009\/images\/c.gif) no-repeat 0 4px;}")
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("-->");
document.writeln("<\/style>") ;
 function subStr(str,length){
	var a=str.match(/[^\x00-\xff]|\w{1,2}/g);
	return a.length<length?str:a.slice(0,length).join("")+"..";
}
document.writeln("<form name=login onSubmit=\"document.charset=\'gb2312\';\" accept-charset=\"gb2312\" action=\"http:\/\/passport.mop.com\/Login?url="+location.href+"\" target='_top' method=\"post\">");
if(nickname != "") {
	isLogined = true; 
	//判断用户是否绑定手机
	var bindMobile = 0;
	var closeBindMobile=0;
	var allcookie = document.cookie.split('; ');
	var searchCount = 0;
	for(var i=0;i<allcookie.length;i++){
		 var cookiename = allcookie[i].split('=')[0];
		 if(cookiename == 'bind_mobile'){
		    bindMobile=allcookie[i].split('=')[1];
		    searchCount++;
		 }
		 if(cookiename == 'close_bind_mobile'){
		 	closeBindMobile=allcookie[i].split('=')[1];
		    searchCount++;
		 }
		 if(searchCount >= 2){
		    break;
		 }
	}
	var bmclass = "btn_bd2";
	var isShow = "ycdkC";
	
	if( bindMobile == 1 ){
		bmclass = "btn_bd";
		
	}
	//已绑定或关闭提示 不再自动提示
	if(bindMobile == 1 || closeBindMobile == 1){
		isShow = "ycdkC ycdkC2";
	}
	
	
	//处理一下用户名，如果超长，就截掉
	var name_display = subStr(nickname, 6);
	
	var mopid = getMopidFromCookie();
	document.writeln("<div id=\"banner_wai\" style=\"display:block;z-index:99999999;\">");
	document.writeln("	<div id=\"banner\" style=\"padding-top:1px;float: right; margin-right: 10px;z-index:99999999;\">");
	document.writeln("   	  <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	document.writeln("      	<tr>");
	//document.writeln("            <td width=\"20%\"><a href='"+webjs+"/topic/feedback.jsp' target='_blank'><font color='red'>给测试版提交反馈</font></a></td>");
	document.writeln("            <td width=\"15%\">&nbsp;</td>");
	document.writeln("            <td style=\"text-align:right\"><div class=\"yhxx\">欢迎您：");
	document.writeln("				<a href=\"http://login.hi.mop.com/Login.do?ss=mophome_top&origURL=http://hi.mop.com/\" target='_blank'>"+ name_display +"<\/a>");
	
	document.writeln("　登录：" + loginTimes + "　MP：" + mp +"</div>");
	document.writeln("<ul class=\"dkarea\">");
	document.writeln("<li class=\"dk_bsj\"><a href=\"#\" class=\""+bmclass+"\" id=\"bindmobile\" title=\"绑定手机\"></a>");
	document.writeln("<div id=\"bindmobilediv\" class=\""+isShow+"\">");
	document.writeln("<div class=\"inn\"> <a href=\"#\" id=\"close1\" class=\"btn_dkg\"></a>");
	document.writeln("<p class=\"bdnr\">现在绑定手机，每天可打卡领取<span class=\"ztB\">“5MP x 连续登录天数”</span>MP奖励哟！</p>");
	document.writeln("<a href=\"http://passport.mop.com/security/mobile\" target=\"_blank\" class=\"btn_qbd\"></a> </div>");
	document.writeln("</div></li>");
	document.writeln("<li class=\"dk_dk\"><a href=\"#\" class=\"btn_dk\"></a>");
	document.writeln("<div id=\"dakadiv\" class=\"ycdkC ycdkC2\">");
	document.writeln("<div class=\"inn\"> <a href=\"##\" id=\"close2\" class=\"btn_dkg\"></a>");
	document.writeln("<p class=\"dkxs\"><span class=\"dkmp\">MP:<i id=\"dkmp\">0</i><i id=\"addmp\" class=\"light\"></i></span><a href=\"#\" id=\"dkaction\" class=\"btn_xbd\">立即打卡</a></p>");
	document.writeln("<p class=\"dkgm\"><span class=\"dkmp\"><b>连续登录：</b><i id=\"dkcount\">1</i>天</span><a href=\"#\" class=\"ztB\" id=\"buylogins\" style=\"display: none;\">购买连续登录</a></p>");
	document.writeln("</div></div></li></ul>");
	
	document.writeln(" &nbsp;&nbsp;<a href='http://msg.hi.mop.com' target='_blank'>消息</a><a href='http://msg.hi.mop.com' id='js_message' target='_blank'></a>　<a href='http://tt.mop.com/user/'>我的地盘</a>　<a href=\"http://passport.mop.com/Logout?backUrl="+document.location.href+"\" id='exittt'><img src=\"http://txt.mop.com/dwdzh/images/dzhdhtImages/exitnew.gif\" border=\"0\" style=\"vertical-align:middle;\"\/></a>　\n");
	
	document.writeln("<a href='"+webjs+"'>回到首页</a>");
	document.writeln("<\/td>"); 
	document.writeln("      <\/tr>");
	document.writeln("    <\/table>");
	document.writeln("	<\/div>");
	document.writeln("<\/div>");
	
	
	
	$(function(){
		var messageFlag = true;
		var allcookie =document.cookie.split('; ');
		for(var i=0;i<allcookie.length;i++){
			var cookiename = allcookie[i].split('=')[0];
		    if(cookiename == 'message_time'){
		    	var messageTime=allcookie[i].split('=')[1];
		        var myDate = new Date();
		        var mytime=myDate.getTime();
		        if(mytime-5*60*1000<messageTime){
		        	messageFlag = false;
		        }
		    }
		}
		if(messageFlag){
			//Jone Sche 20110927 append ajax 查询是否有新消息
			$.ajax({
				type: "GET",
				url: "/user/newmessage.do",
				cache: false,
				success: function(msg){
					if(msg > 0){
						$('#js_message').html("<font color='red'>new</font>");
					}
				},
				error: function(msg) {
					
				}
			});
		}
	
		//立即打卡按钮事件
		$("#dkaction").bind("click",function(){
			$("#dkaction").unbind();
			$("#dkaction").addClass("btn_ybd");
			$.ajax({
				url: "http://passport.mop.com/punch-the-clock/punch",
				//crossDomain:true, 
				//async:false,
				dataType:"jsonp",
				success: function(msg){
					if(msg.status == 200){
						var $addmp = $("#addmp");
						$addmp.html("+"+msg.mpPlused);
						$addmp.fadeIn(1000);
						$addmp.fadeOut(2000,function(){
							$addmp.html("");
							var newMp = parseInt($("#dkmp").html(),10) + msg.mpPlused;
							$("#dkmp").attr("class","light");
							$("#dkmp").html(newMp);
						});
					}
				}
			});
			
		});
		
		//赎回提交按钮
		$("#retrievable").bind("click",function(){
			$.ajax({
				url: "http://passport.mop.com/punch-the-clock/retrieve-record",
				dataType:"jsonp",
				success: function(msg){
					if(msg.status == 200){
						//关闭确定按钮
						$("#retrievable").hide();
						//关闭赎回弹出框
						$("#platformdiv").hide();
						//关闭赎回链接
						$("#buylogins").hide();
						//修改连续登录天数
						var $dkcount = $("#dkcount");
						$dkcount.fadeOut(1000,function(){
							$dkcount.html(msg.keepLoginDays);
						});
						$dkcount.fadeIn(2000);
						//修改现有显示MP
						var $dkmp = $("#dkmp");
						$dkmp.fadeOut(1000,function(){
							$dkmp.html(msg.mp);
							$dkmp.attr("class","light");
						});
						$dkmp.fadeIn(2000);
						
					}else{
						//失败提示
						var $retrievableReason = $("#retrievableReason");
						$retrievableReason.fadeOut(1000,function(){
							$retrievableReason.html("操作失败："+msg.message);
						});
						$retrievableReason.fadeIn(2000);
					}
				}
			});
			
		});
		
		//赎回弹出框取消按钮
		$("#closeBuy").bind("click",function(){
			$("#platformdiv").hide();
		});
		
		//赎回弹出框事件
		$("#buylogins").bind("click",function(){
			$.ajax({
				url: "http://passport.mop.com/punch-the-clock/record",
				dataType:"jsonp",
				success: function(msg){
					if(msg.status == 200){
						//擦除历史信息
						$("#retrievableReason").html("");
						$("#loginDaysRecord").html(msg.keepLoginDaysRecord);
						$("#mpRetrieve").html(msg.mpForRetrieve);
						$("#mpNum").html(msg.mp);
						//是否满足赎回条件可以赎回
						if(msg.retrievable){
							$("#retrievable").show();
						}else{
							
							$("#retrievableReason").html(decodeURI(msg.retrievableReasonEncoded));
						}
						//测试代码
						//$("#retrievable").show();
						//test end
						$("#platformdiv").show();
					}
				}
			});
		});
		
		
		
		//打卡弹出框
		$(".btn_dk").bind("click",function(){
			$.ajax({
				url: "http://passport.mop.com/punch-the-clock/status",
				//crossDomain:true, 
				//async:false,
				dataType:"jsonp",
				success: function(msg){
					if(msg.status == 200){
						//现有MP
						$("#dkmp").html(msg.mp);
						//连续登录天数
						$("#dkcount").html(msg.keepLoginDays);
						//判断今天是否打过卡
						if(!msg.punchable){
							$("#dkaction").unbind();
							$("#dkaction").addClass("btn_ybd");
						}
						//历史最大连续登录天数比较
						if(msg.keepLoginDays<msg.keepLoginDaysRecord){
							$("#buylogins").show();
						}
						$("#dakadiv").show();
					}
				}
			});
			
		});
		
		
		//打卡弹出框的X按钮
		$("#close2").bind("click",function(){
			$("#dakadiv").hide();
		});
		//初始化手机绑定事件
		if(bindMobile == 0){
			//手机图标点击事件 显示弹出框
			$("#bindmobile").bind("click",function(){
				$("#bindmobilediv").attr("class","ycdkC");
			});
			//手机绑定弹出框的X按钮
			$("#close1").bind("click",function(){
				$("#bindmobilediv").addClass("ycdkC2");
				if(closeBindMobile == 0){
					
					document.cookie="close_bind_mobile=1;path=/";
				}
			});
		}
		$("#exittt").bind("click",function(){
			
			document.cookie="close_bind_mobile=0;path=/";
		});
		
	});
	$(document).ready(function(){
		$("#topsearch").submit(function(){
			var q=$.trim($("#topsokey").val());
			if(q==''){
			 alert("请输入内容！");
			 return false ;
			}
			if(q.indexOf(".")==-1){
				q=encodeURIComponent(q);
				url="http://www.mop.com/so/tt/"+q ;
				document.location.href=url ;
				return false ;
			}
			return true ;
			
		});	
	});
} else {
	
	document.writeln("<script type='text/javascript' src='http://txt.mop.com/ttv2/js/connector_fortop.js' charset='gbk'></script>");
	document.writeln("<div id=\"banner_wai\" style=\"display:block;\">");
	document.writeln("	<div id=\"banner\" style=\"margin-right:-16px;\">");
	document.writeln("   	  <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	document.writeln("      	<tr>");
	//document.writeln("				<td width='195'><a href='"+webjs+"/topic/feedback.jsp' target='_blank'><font color='red'>给测试版提交反馈</font></a></td>");
	document.writeln("            <td width=\"15%\">&nbsp;</td>");
	document.writeln("       	  <td width=\"50\">登录名：<\/td>");
	document.writeln("          <td width=\"110\"><input type=\"text\" name=\"user_name\" id=\"textfield\" class=\"inputk\" \/><\/td>");
	document.writeln("            <td width=\"40\">密码：<\/td>");
	document.writeln("          <td width=\"110\"><input type=\"password\" name=\"password\" id=\"textfield2\" class=\"inputk\" \/><\/td>");
	document.writeln("          <td width=\"20\"><input type=\"checkbox\" name=\"auto_login\" value=\"1\" id=\"checkbox\"  class=\"vmiddle\"\/><\/td>");
	document.writeln("            <td width=\"55\"><div style=\"padding-top:2px;\">自动登录<\/div><\/td>");
	document.writeln("          	<td><input type=\"image\" src=\"http:\/\/image2.mop.com\/mop\/index2009\/images\/icon_00.gif\" class=\"vmiddle\"\/></td>");
	document.writeln("<td><span class='logoL' style='height:16px; display:inline-block; float:right; padding-top:0px; *padding-top:0px;'>");
	document.writeln("<span mopcon='renren'></span>");
	document.writeln("<span mopcon='baidu'></span>");
	document.writeln("<span mopcon='tencentconnector'></span>");
	document.writeln("<span mopcon='weibo'></span>");
	document.writeln("</span></td>");
	document.writeln(" <td><a href='http://passport.mop.com/sign/login_1.jsp?from=http://tt.mop.com' target='_blank'><img src=\"http:\/\/image2.mop.com\/mop\/index2009\/images\/icon_01.gif\" style=\"border:none;\"  class=\"vmiddle\" \/></a><\/td>");
	document.writeln("            <td width=\"65\"><a href='"+webjs+"'>回到首页</a><\/td>"); 
	document.writeln("      <\/tr>");
	document.writeln("    <\/table>");
	document.writeln("	<\/div>");
	document.writeln("<\/div>");
}
document.writeln("<\/form>");

function isAutoLogin(){
    if (document.cookie.length > 0) {
        var cookieContent = document.cookie;
        var cookieArray = cookieContent.split(";");
        for (var i = 0; i < cookieArray.length; i++) {
            var values = cookieArray[i].split("=");
            if (jQuery.trim(values[0])== 'mop_auto_login') {
                 if(unescape(values[1] !="undefined")){
                	 return true;
                 }
            } 
            	
        }
    }
    return false;
}
 
//用户自动登录自动跳转到AutoLgoin登录页面
if(!isLogined && isAutoLogin()){
	window.location='http://passport.mop.com/AutoLogin?url='+backUrl;
}



