
var head_attr=new Object();
var head_method={
	initMethod:function(){
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf("msie 6.0") != -1) {
			try { 
				document.execCommand("BackgroundImageCache", false, true);
			} catch(e) {
				
			}
	}
	head_method.getUserCookieByJs();
	head_method.jQueryEvent();
	},setCookie:function(name,value,Days)//两个参数，一个是cookie的名子，一个是值
	{
    	var exp  = new Date();  
    	exp.setTime(exp.getTime() + Days*24*60*60*1000);
    	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
	},deleteCookie:function(name)//两个参数，一个是cookie的名子，一个是值
	{
    	var exp  = new Date();  
    	exp.setTime(exp.getTime()-10000);
    	document.cookie = name + "=;expires=" + exp.toGMTString();
	},jQueryEvent:function(){
		$("#nav li[class='nav_head_li']").mouseover(function(){
		$(this).addClass("sfhover").children("a").css({
			"color":"white"
		});
		$(this).children("ul").show();
		}).mouseout(function(){
		$(this).removeClass("sfhover").children("a").css("color","");
		$(this).children("ul").hide();
		});	
		$(document).ready(function(){
			if(head_attr.user_name!=null&&head_attr.user_name=="administrator")$("#blog_manage").show();
			$("#logout_head").click(function(){
				head_method.logout();
			});
		
		});	
	},getQueryString:function(name){
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
		 try{
			return decodeURI(r[2]);
		 }catch(err){
			return decodeURI(unescape(r[2]));
		 }
		}
        return null;
    },decodeFun:function(s)
	{
     var fnl = "", code = 0;
     for(var i = 0; i < s.length >> 1; i++){
           code = new Number("0x" + s.substr(i * 2, 2));
           fnl += String.fromCharCode((code ^ (2015 << 7 - i % 8 | 2015 >> i % 8 | 0x80)) & 0x7f);
     }
     return fnl;
	},getInfByCookie:function(cookie_name){
		var cookie = document.cookie;
		var cookie_array;
		if (cookie.indexOf(";") != -1) {
			cookie_array = cookie.split(";");
		}else {
			cookie_array = cookie;
		}
		var cookie_arr;
		if (cookie_array != null&&cookie_array.length>0) {
			for (var i = 0; i < cookie_array.length; i++) {
				if (cookie_array[i] != null && cookie_array[i].indexOf(cookie_name) != -1) {
					cookie_arr = cookie_array[i];
					break;
				}
			}
		}
		return cookie_arr;
	},logout:function(){
		if($("#userid").val()==null||$("#userid").val().length==0)return;
		head_method.deleteCookie("PASSIT_USER_"+$("#userid").val());
		var reg=/(change|contact|passit_share|history|statistics|blog_manage|xml_manage)(\.shtml)?/i;						
		if (reg.test(document.URL)) {
			window.setTimeout(function(){
				document.location="/index";
			},1000);
			
		}else{
			$("#userid").val("");
			$("#username").val("");
			$("#unlogin_head").show().siblings().hide();
		}
	},  getUserCookieByJs:function(){
		var value=head_method.getInfByCookie("PASSIT_USER");
					if (value != null) {
						var user_id, user_name;
						if (value.indexOf("=") != -1) {
							var cookie_name = value.split("=")[0];
							user_name = value.split("=")[1];
							var num = cookie_name.lastIndexOf("_");
							if (num != -1) {
								user_id = cookie_name.substring(num + 1);
							}
						}	
						if (user_id != null && user_id >= 0 && user_name != null && user_id != user_name) {
							try {
								head_attr.user_name = decodeURIComponent(head_method.decodeFun(user_name));
							}catch(err){
								head_attr.user_name = head_method.decodeFun(user_name);
							}
							$("#user_name").html(head_attr.user_name);
							$("#userid").val(user_id);
							$("#username").val(head_attr.user_name);
							$("#login_head").show().siblings().hide();
							$("#login_head").children("a[class='account']").html("我的账户("+head_attr.user_name+")");
						
							var reg=/(xml_manage|blog_manage)\.shtml/i;
							if (reg.test(document.URL)) {
								if(head_attr.user_name!="administrator")
						  		 document.location="index";	
							}
						}
					}else{
						var reg=/(change|contact|passit_share|share|history|statistics|blog_manage|xml_manage)(\.shtml)?/i;						
						if(reg.test(document.URL)){
						   if (document.URL.indexOf("/share") == -1) {
						   	head_method.setCookie("PASSIT_REDIRECT",document.URL,0.01);
						   	document.location = "login?type=0";
						   }
						}
					}
				var history=head_method.getInfByCookie("PASSIT_HISTORY");
				if(history=null&&history.indexOf("=")!=-1){
						history_value=history.split("=")[1];
						$("#history_status").val(history_value);
				}
	},getUserInfo:function(){
		var is_had=false;
			if(document.cookie.indexOf("PASSIT_USER")!=-1){
				if(document.URL.indexOf("/login")!=-1){
					document.location="/index";
				}else{
					head_method.getUserCookieByJs();
					head_method.stop_getUserInfo();
					$("#login_head").show().siblings().hide();
					$("#ajax_login_out").hide();
					$("#mask_div").hide();
					$("#login_head").children("a[class='account']").html("我的账户("+head_attr.user_name+")");
					if (document.URL.indexOf("/default_plugin") != -1) {
						var value=$(".defau-input").eq(0).text();
						$(".defau-input").eq(0).text(value.replace("pub=0","pub="+$("#userid").val()));
					}
					if (document.URL=="http://www.passit.cn/"||document.URL.indexOf("/index") != -1) {
						var value=$("#fastget textarea").eq(0).text();
						$("#fastget textarea").eq(0).text(value.replace("pub=0","pub="+$("#userid").val()));
					}
					if (document.URL.indexOf("/customize") != -1) {
						$("#custom_login").hide();
						if(typeof(cus_method)!='undefined'&&cus_method!=null)cus_method.getUserDefineCode();
					}
				}
				is_had=true;
			}
		if(!is_had)head_attr.handle=window.setTimeout(head_method.getUserInfo,500);
	},stop_getUserInfo:function(){
		if(head_attr.handle!=null)window.clearTimeout(head_attr.handle);
	}
	
};
head_method.initMethod();




