﻿$(function() {	
	 KeyDown();
    if (!CheckLogin(".GXUSERNAME")) {
        //未登录
        SendBackdoor();
    }
    else {//已登录
        SendBackdoor();
    }
});
function SendBackdoor() {
    var url = "/Ajax/IsLogin.ashx";
    var Cookie = $.cookie(".GXUSERID");
    var pars = "{\"UserID\":\"" + Cookie + "\"}";
    if (Cookie != null && Cookie != "") {
        pub_getws(url, ChangeHeaderContent, pars);
    } else {
        $(".orderHeaderTop").show();
    }
}
function ChangeHeaderContent(data) {
    if (data.Success) {
        //登入成功
        $(".orderHeaderTop").children().remove();
        $(".orderHeaderTop").append("<ul><li>欢迎您！<span class=\"userNameSpan\">" + data.Description + "</span></li><li><a   class=\"ExitClassBtn\"  href=\"javascript:void(0);\">退出</a></li><li><a target=\"_blank\" href=\"http://user.guanxin.com\">个人中心</a></li><li class=\"mybox\"><a target=\"_blank\" href=\"http://user.guanxin.com/Reminder/ReminderList\">我的提醒<span>(" + data.UserRemindNum + ")</span></a></li><li class=\"myshop\"><a target=\"_blank\" href=\"http://shop.guanxin.com/ShopCart/Index\">购物车<span>(" + data.shopCarNum + ")</span></a></li><li><a target=\"_blank\" href=\"http://faq.guanxin.com\">帮助</a></li></ul>");
    }
    ExitBackdoor();
    $(".orderHeaderTop").show();
}

function ExitBackdoor() {
    $(".ExitClassBtn").click(function() {
        $.cookie('.GXUSERID', '', { expires: -1, path: '/', domain: '.guanxin.com' });
        $.cookie('.GXUSERNAME', '', { expires: -1, path: '/', domain: '.guanxin.com' });
        window.top.location.href = 'http://www.guanxin.com';
        return false;
    });
}

//search
function KeyDown(){
        var $text = $(".headerBRtext").val();
        var words = "请输入关键字";
        $(".headerBRtext").focusin(function() {
            if ($(".headerBRtext").val() == words)
                $(".headerBRtext").val("");
        });
        $(".headerBRtext").focusout(function() {
            if ($(".headerBRtext").val() == "")
                $(".headerBRtext").val(words);
        });
        //首页搜索
        $(".headerBRbtn").click(function() {
	        	SearchHeader();
        });
		$("#headertext").keydown(function(e) {
	        if (e.which == 13) {
	        	SearchHeader();
	        }
	});
	var SearchArticleHtml = "<form id=\"ArticleForm\" action=\"http://info.guanxin.com/RetrieveArticle\" method=\"get\" target=\"_blank\"><input id=\"title\" name=\"title\"  type=\"hidden\" /><input id=\"sort\" name=\"sort\" value=\"1\"  type=\"hidden\" /></form>";
	var SearchShopHtml = "<form id=\"ShopForm\" action=\"http://shop.guanxin.com/Product/ProTypeList\" method=\"get\" target=\"_blank\"><input id=\"HeadSearchSelect\" name=\"HeadSearchSelect\" value=\"0\"  type=\"hidden\" /><input id=\"HeadSearch\" name=\"HeadSearch\"  type=\"hidden\" /></form>";
	$(".headerbottom").append("<div style=\"overflow:hidden;width:0;height:0;\">"+SearchArticleHtml+SearchShopHtml+"</div>");
}
function SearchHeader(){
	var Text = $(".headerBRtext").val();
	if(Text != "" && Text != "请输入关键字"){
	    if($("#wz").attr("checked")){
	       $("#title").val(Text);
	        document.getElementById("ArticleForm").submit();
	    }    
	    if($("#fa").attr("checked")){
	       $("#HeadSearch").val(Text);
	        document.getElementById("ShopForm").submit();
	    }
	 }else{
	 	alert("请输入您要查询的内容");
	 	return false;
	 }
}
