﻿function Control_QHead() {

}

Control_QHead.login = function(name, pwd, usercode, callback) {
    var s = ""
    $.ajax({
        type: "POST",
        async: true,
        url: postUrl_N + "/aas/Control/QHead_N.ashx",
        data: { 'method': 'login', 'name': name, 'pwd': pwd, 'usercode': usercode },
        success: function(msg) {
            //s = msg ;
            callback({ 'value': msg });
        }
    });

    //	return {'value':s} ;
}

Control_QHead.isLogin = function() {
    var s = ""
    $.ajax({
        type: "POST",
        async: false,
        url: postUrl_N + "/aas/Control/QHead_N.ashx",
        data: { 'method': 'isLogin' },
        success: function(msg) {
            s = msg;
        }
    });
    if (s.toLowerCase() == 'true')
        return { 'value': true };

    return { 'value': false };
}

Control_QHead.FakeUrl = function(shopID) {
    var s = ""
    $.ajax({
        type: "POST",
        async: false,
        url: postUrl_N + "/aas/Control/QHead_N.ashx",
        data: { 'method': 'FakeUrl', 'shopID': shopID },
        success: function(msg) {
            s = msg;
        }
    });
    return { 'value': s };
}

Control_QHead.linkLog = function(cookvalue) {
    var s = ""
    $.ajax({
        type: "POST",
        async: false,
        url: postUrl_N + "/aas/Control/QHead_N.ashx",
        data: { 'method': 'linkLog', 'cookvalue': cookvalue },
        success: function(msg) {
            s = msg;
        }
    });
    return { 'value': s };
}

Control_QHead.UserUrl = function() {
    var s = ""
    $.ajax({
        type: "POST",
        async: false,
        url: postUrl_N + "/aas/Control/QHead_N.ashx",
        data: { 'method': 'UserUrl' },
        success: function(msg) {
            s = msg;
        }
    });
    return { 'value': s };
}



//当前选中导航链接索引
var lstCurIndexHead = 0;
var ulFS1;
var go_top_head;
$(document).ready(function() {


    //设置搜索框默认值
    txtDefaultTxt({
        'txtID': txtSearch_Head
            , 'defaultTxt': '请输入搜索关键字'
            , 'defaultCss': 'input-1'
            , 'NewTxtCss': 'input-1'
    });

    //回车触发搜索 
    setTxtEnter({
        'id': txtSearch_Head
		, 'callback': function(e) {
		    Serch();
		}
    })

    var w = queryWord;
    w = w == '' ? '请输入搜索关键字' : w;
    $("#" + txtSearch_Head).val(w);

    lstCurIndexHead = type_head == "" ? 0 : type_head;
    //  lstCurIndexHead = lstCurIndexHead == 5 ? 3 :lstCurIndexHead;

    //设置导航
    var liNav = $("#ulNav li").mouseover(function() {
        $(this).removeClass().addClass("tab-cur");
    })
        .mouseout(function() {
            if (liNav.index($(this)) != lstCurIndexHead) {
                if (liNav.index($(this)) == lstCurIndexHead) return;
                $(this).removeClass();
            }
        });

    var p1 = 50;
    var setDis = function() {
        p.css("display", "none");
    }

    var aHese = $("#aHse").mouseover(function() {
        var p = $("#pCs1");
        if (p[0].t) {
            clearTimeout(p[0].t);
            p[0].t = null;
        }

        p.css("display", "");
        aHese.removeClass().addClass("");

    })
		.mouseout(function() {
		    var p = $("#pCs1");
		    if (p[0].t) return;
		    p[0].t = setTimeout(function() {
		        p.css("display", "none");
		        aHese.removeClass().addClass("");
		    }, p1)
		})

    $("#pCs1").mouseover(function() {
        var p = $("#pCs1");
        if (p[0].t) {
            clearTimeout(p[0].t);
            p[0].t = null;
        }

        p.css("display", "");
        aHese.removeClass().addClass("");
    })
	   .mouseout(function() {
	       var p = $("#pCs1");
	       if (p[0].t) return;
	       p[0].t = setTimeout(function() {
	           p.css("display", "none");
	           aHese.removeClass().addClass("");
	       }, p1)
	   })

    ///
    //	 ulFS1 =  $("#ulFS1");
    //	 ulFS1[0].lstIndex = '0';
    //     var ulFSl1 = $("> li",ulFS1).each(function(i){
    //			$(this).click(function(){
    //				 if(ulFS1[0].lstIndex){
    //					ulFSl1.eq(parseInt(ulFS1[0].lstIndex)).removeClass("tab-cur") ;
    //					ulFS1[0].lstIndex = $(this).attr("index") ;
    //				 }
    //				 $(this).addClass("tab-cur") ;
    //			 })
    //			 .attr("index",i);
    //	 })

    //回到顶部
    var timeout_ie = 600, absTop = document.documentElement.clientHeight / 2 - 30, ofr = 5;
    var isIE6 = $.browser.msie && $.browser.version == "6.0";
    go_top_head = $("#go_top")
		 .click(function() {
		     window.scrollTo(0, 0);
		 })
    if (isIE6)
        go_top_head.css({ "position": "absolute", "right": ofr });
    else {
        go_top_head.css({ "position": "fixed", "right": ofr, "top": absTop });
    }
    var setGo_Top = function() {
        var top = (document.documentElement.scrollTop || document.body.scrollTop) + absTop;
        go_top_head.css({ "top": top, "display": "" });
    }

    //初使化操作
    var top = (document.documentElement.scrollTop || document.body.scrollTop);
    if (isIE6) {
        if (top != 0) {
            setGo_Top();
        }
    }
    else {

        if (top == 0) {
            go_top_head[0].op = 0;
        }
        else {
            go_top_head[0].op = 100;
            go_top_head.css("display", "");
        }
    }
    //结束初使化操作

    window.onscroll = function() {
        var top = document.documentElement.scrollTop || document.body.scrollTop;
        if (top == 0) {
            if (go_top_head[0].ts) {
                clearTimeout(go_top_head[0].ts);
                go_top_head[0].ts = null;
            }

            go_top_head.css("display", "none")[0]
				.op = 0;
        }
        else {
            if (isIE6) {

                if (go_top_head[0].ts) {
                    clearTimeout(go_top_head[0].ts);
                    go_top_head[0].ts = null;
                }
                go_top_head.css("display", "none");

                go_top_head[0].ts = setTimeout(function() {
                    setGo_Top();
                }, timeout_ie)
            }
            else {
                if (go_top_head[0].op != 0) return;
                setOpacity(go_top_head[0], 0);
                var opa = 0;
                go_top_head.css("display", "");
                DemonMove2({
                    'offset': 100
					, 'execute': function(t) {
					    opa += t;
					    go_top_head[0].op = opa;
					    setOpacity(go_top_head[0], opa);
					}
					, 'p': -10
					, 'time': 80
                })

            }
        }

    }

    //修正ie6中 flobg fixed定位
    if (isIE6) {
        $(document.body).addClass("body_ie6");
        $("#flobg").addClass("fixable_ie6").css("visibility", "visible");
    }
    else {
        $("#flobg").css({ "width": '100%', 'left': '0px', 'bottom': '0px', 'position': 'fixed', "visibility": "visible" })
    }

    var yQdialog;

    //邀请有奖
    $("#aYQ").click(function() {
        //邀请有将
        var yaoqing = function() {
            //弹出邀请层
            var defaultLocal = $("#divYaoQ")
            var divFlow = defaultLocal.find("> div");
            yQdialog = showBaseDialog({
                width: 400
							, height: 120
							, title: '提示'
							, titleAlign: 'center'
							, zIndex: 2500
							, onload: function(title, content) {
							    if ($("#txtYQURL").val() == "") {
							        $("#txtYQURL").val("http://" + Control_QHead.UserUrl().value);
							    }
							    $(content).append(divFlow);
							}
							, unload: function(title, content) {
							    divFlow.appendTo(defaultLocal);
							    //调用该窗口的宿主是浮动层
							    return true;
							}
            });
        }

        var islogin = Control_QHead.isLogin()
        if (islogin.value == false) {
            //没有登录 不能领取 转到登录页面
            //window.location.href = "Login/Login.aspx";
            var dPar = $("#dialogLogin");
            var dDialog = $("#dialogLogin > div ");

            //设置验证码相对路径
            validImgPath = "login/ValidateImage.aspx";
            qLoginDialog = showLoginDialog(
						null
						, function(result, arr) {
						    if (result) {
						        yaoqing();
						    }
						}
						, dDialog
						, dPar
						, "快速登陆"
					);
        }
        else {
            yaoqing()
        }

    })

    //邀请有奖 事件结束

    //复制邀请链接
    $("#btnYQFZ").click(function() {
        copyToClipboard($("#txtYQURL").val());
        yQdialog.title.close();
    })
})
//结束回到顶部

var loginImgCodeR = imgLoginr_head;

//搜索
function Serch() {
    var t = $("#" + txtSearch_Head);
    t.val($.trim(t.val()));
    var c = t.val();
    if (c == "请输入搜索关键字" || c == "") return;
    if (c == "") return;
    var vH = "";
    switch ($("#Select1").val()) {
        case "1":
            vH = "http://www.maidongxi.com/CouponSearchList.aspx?w=" + escape(c)
            break;
        case "2":
            vH = "http://www.maidongxi.com/sale/saleSearchList.aspx?w=" + escape(c)
            break;
        case "3":
            var turnForm = document.createElement("form");
            turnForm.style.display = "none";
            document.body.appendChild(turnForm);
            var opt = document.createElement("textarea");
            opt.name = 'keyword';
            opt.value = c;
            turnForm.appendChild(opt);
            turnForm.action = "http://www.maidongxi.com/Cooperate.aspx?k=" + escape(c);
            turnForm.method = "post";
            turnForm.submit();
            break;
    }
    if (vH == "") return;
    window.location.href = vH;
    return false;
}


function HotSearch(t) {
    window.location.href = "http://www.maidongxi.com/CouponSearchList.aspx?w=" + escape(t);
    return false;
}

function ShareWebSite(type) {
    var title = encodeURIComponent(document.title);
    var url = window.location.href;
    var links = "";
    switch (type) {
        case "tsina":
            links = " http://v.t.sina.com.cn/share/share.php?title=" + title +
                "&url=" + url + "&source=maidongxi";
            break;
        case "t163":
            links = " http://t.163.com/article/user/checkLogin.do?link=http://news.163.com/&source=maidongxi&info="
            + title + encodeURIComponent(location.href);
            break;
        case "kaixin100":
            links = " http://www.kaixin001.com/repaste/share.php?rtitle=" + title + "&rurl=" +
                url + "&rcontent=" + title + "  " + url + "";
        case "renren":
            window.open(" http://share.renren.com/share/buttonshare.do?link=" +
                url + "&title=" + title + "", "blank", "width=450,height=400");
            break;
        case "douban":
            links = " http://www.douban.com/recommend/?url=" + url + "&title=" + title + "&comment=" + title + " " + url;
            break;
        case "tqq":
            links = " http://v.t.qq.com/share/share.php?title=" + title
                + "&url=" + url + "&source=maidongxi&site= www.maidongxi.com";
            break;
        case "TaoJH":
            links = " http://share.jianghu.taobao.com/share/addShare.htm?title=" + title + "&url=" + url + "&content=" + title + " " + url;
            break;
        case "QQZone":
            links = " http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + url + "&title=" + title + "";
            break;
        case "CopyUrl":
            copyToClipboardHead(url);
            break;
    }
    if (links.length > 0) {
        window.open(links, "blank", "width=600,height=400");
    }
}

function copyToClipboardHead(txt) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", txt);
        alert("复制成功,请粘贴到您的QQ/MSN上推荐给你的好友!");
    }
    else if (navigator.userAgent.indexOf("Opera") != -1) {
        window.location = txt;
    }
    else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
        }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip)
            return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans)
            return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext = txt;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip)
            return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
    }
}  

