﻿
//var dUserid
//var dUserName
//var islogin = false;

////同步得到用户信息,若登录
//$.ajax({
//    type: "GET",
//    url: "/WebServe/userHand.ashx?usertype=2&r=" + Math.random((new Date()).getSeconds()),
//    async: false,
//    dataType: "json",
//    success: function(data) {
//        if (data.userid != "-1" && data.userName != "-1") {
//            dUserid = data.userid;
//            dUserName = data.userName;
//            islogin = true;
//        }

//    }
//});
/////--------------end-------------------------------




$(function() {
    //    dUserid = $("#C_hidpingUserID").val();
    //    dUserName = $("#C_hidpingUserName").val();
    //    if (dUserid != -1 && dUserName != -1)
    //        islogin = true;
    var htmlHead = '';
    htmlHead += '<li class="spannoSelect defaultHeadover " id="Homepages"><a href="/index.htm">首页</a></li>';
    if (islogin == true) {
        htmlHead += '<li class="heightli" id="myyp123li" style="display:none"><span class="lined"></span></li>';
        htmlHead += '<li class="headHomepage defaultHeadover"  style="display:none" id="myyp123"><a href="/MyYiping/Homepage.htm"><div id="Homepic" class="Homepic1"></div> 我的易评网</a></li>';
    }
    htmlHead += '<li class="heightli"><span class="lined"></span></li>';
    htmlHead += '<li class="spannoSelect defaultHeadover" id="productReview" style="position:relative; z-index:0px;">';
    htmlHead += '<a href="/review/hotReview">找评论</a></li>';
    htmlHead += '<li class="heightli"><span class="lined"></span></li>';
    htmlHead += '<li class="spannoSelect defaultHeadover"   id="Writereview"><a href="/MyYiping/NewReview.aspx">写评论</a></li>';
    htmlHead += '<li class="heightli" ><span class="lined"></span></li>';
   // htmlHead += '<li class="spannoSelect defaultHeadover"   id="FreeTrial"><a id="gotoTryProduct" style="color:#FFFF00" href="/producttry.aspx">免费试用</a></li>';

    $('#NavigationURL').html(htmlHead);

    if (islogin == true) {
        $("#lg1").show();
        $("#lg2").html("<a href='/MyYiping/Homepage.htm'>" + dUserName + "</a>");
        $('#myyp123li').show();
        $('#myyp123').show();
    }
    else { $("#lg").show(); }


    var url = document.location.href;
    var navigID = "#Homepages";
    if (url.indexOf("index.htm") != -1) {
        navigID = "#Homepages";
    }
    else if (url.toLowerCase().indexOf("myyiping") != -1) {
        navigID = "#myyp123";
    }
    else if (url.toLowerCase().indexOf("product") != -1 || url.toLowerCase().indexOf("review") != -1) {
        navigID = "#productReview";
    }
    if (url.toLowerCase().indexOf("myyiping/newreview") != -1)
    { navigID = "#Writereview"; }
    if (url.toLowerCase().indexOf("producttry") != -1)
    { navigID = "#FreeTrial"; }


    if ((window.location.href.indexOf('searchinfo.aspx') > 1 || window.location.href.indexOf('MyYiping') > 1) && window.location.href.indexOf('userself.aspx') == -1
    //    || window.location.href.indexOf('Homepage.htm') > 1
    //        || window.location.href.indexOf('myletter.aspx') > 1 || window.location.href.indexOf('SelfProduct.aspx') > 1
    ) {
        //if (!$.browser.msie) { SelfProduct.aspx
        if (!$.browser.msie) {
            $('.lined').css('margin-top', '2px');
        }
        //}
    }


    if ($(navigID).find('div').length == 1) {
        $(navigID).addClass("indexHomepage Headover"); //黑色字体
        $(navigID).removeClass("defaultHeadover");
        $('#Homepic').addClass("Homepic2").removeClass("Homepic1");
        //        if (!$.browser.msie) {
        //            $('.lined').css('margin-top', '2px');
        //        }
    }
    else {
        $(navigID).addClass("indexSrc Headover"); //黑色字体
        $(navigID).removeClass("defaultHeadover");
        if (navigID == '#FreeTrial') {
            $('#gotoTryProduct').css('color', 'black');
        }
    }

    var i = 0;
    var timeout;
    var timecategor;
    var timecategor2;
    $("#NavigationURL li:even").each(function(i, n) {



        $(this).hover(function() {

            if (i != 0) {
                clearTimeout(timeout);
            }
            $(navigID).addClass("defaultHeadover").removeClass("Headover");
            if ($(this).html() != $(navigID).html()) {
                i = 1;

                if (navigID == '#FreeTrial') {
                    $('#gotoTryProduct').css('color', 'White');
                }
                if ($(navigID).find('div').length == 1) {
                    $(navigID).removeClass("indexHomepage").addClass("headHomepage");
                    $('#Homepic').addClass("Homepic1").removeClass("Homepic2");
                }
                else {
                    $(navigID).removeClass("indexSrc").addClass("spannoSelect");

                }
            }

            if ($(this).find('div').length == 1) {
                $(this).addClass("indexHomepage").removeClass("defaultHeadover").addClass("Headover");
                $('#Homepic').addClass("Homepic2").removeClass("Homepic1");
            }
            else {
                $(this).addClass("indexSrc").removeClass("defaultHeadover").addClass("Headover");
            }



            //产品试用
            $(this).find('#gotoTryProduct').css('color', '#f29b05');
        }, function() {//移除
            var navigIDs = $(navigID);
            if ($(this).html() != $(navigID).html()) {
                timeout = setTimeout(function() {

                    if (navigID == '#FreeTrial') {
                        $('#gotoTryProduct').css('color', 'black');
                    }

                    if (navigID == '#myyp123') {

                        if ($(this).find('div').length != 1) {
                            //alert(this);
                            //移除后触发
                            navigIDs.addClass("indexHomepage").addClass("headHomepage").removeClass("headHomepage");
                            $('#Homepic').addClass("Homepic2").removeClass("Homepic1");
                        }
                        else {
                            navigIDs.addClass("indexSrc").addClass("spannoSelect").removeClass("spannoSelect");
                        }

                    }
                    else {
                        if ($(this).find('div').length == 1) {
                            //alert(this);
                            //移除后触发
                            navigIDs.addClass("indexHomepage").addClass("headHomepage").removeClass("headHomepage");
                        }
                        else {
                            navigIDs.addClass("indexSrc").addClass("spannoSelect").removeClass("spannoSelect");
                        }

                    }

                    if ($(this).find('div').length == 1) {
                        $(navigID).addClass("Headover").removeClass("defaultHeadover");
                    }
                    else {
                        $(navigID).addClass("Headover").removeClass("defaultHeadover");
                    }
                }, 300);

                if ($(this).find('div').length == 1) {

                    $(this).removeClass("indexHomepage").removeClass("Headover").addClass("defaultHeadover");
                    $('#Homepic').addClass("Homepic1").removeClass("Homepic2");
                }
                else {
                    $(this).removeClass("indexSrc").removeClass("Headover").addClass("defaultHeadover");
                }
                navigIDs.removeClass("Headover").addClass("defaultHeadover");
                $(this).find('#gotoTryProduct').css('color', '#FFFF00');
            }
        })
    });

    var search = $("#SearVal");
    var defalulkeyword = "搜索评论、产品、用户";

    //搜索url
    $("#imgSearch").click(function() {
        var searVal = $.trim($(search).val());
        if (searVal == "" || searVal == defalulkeyword) { alert('请输入您要搜索的评论、产品、用户名称'); return false; }
        searVal = escape(searVal);
        document.location.href = '/searchinfo.aspx?keyword=' + searVal;
    });

    //处理搜索回车事件
    search.keyup(function(event) {

        if ($.trim(search.val()) == defalulkeyword) { search.val(""); }
        if (event.which == 13) {
            $("#imgSearch").click();
        }
    });

    search.focus(function() {

        if ($.trim($(this).val()) == defalulkeyword) { $(this).val(""); $(this).removeClass("search666"); }
    });

    search.blur(function() { if ($.trim(search.val()) == "") { search.val(defalulkeyword); search.addClass("search666"); } });

    $("#headform").submit(function() {
        return false;
    });

    if ($("#serchkeyword").text() != "")
        search.val($("#serchkeyword").text());
    else { search.val(defalulkeyword); search.addClass("search666"); }


    $(".xboxcontent_2").click(function() {
        setCookie("showTip", "true", 1);
        $("#messtiplit").hide();
    });

    ///数秒后再执行
    setTimeout(function() {
     
    if (getCookies("showTip") == null && dUserid!=-1) {
            $.get("/WebServe/Handler1.ashx?num=29&r=" + new Date().getSeconds(), function(data) {
                if (data != "") {
                    $("#messtiplit").fadeIn(1000);
                    $(".xboxcontent").append(data);
                }

            })
        }

    }, 1000);


});




//@参数:三个变量用来设置新的cookie:
//cookie的名称,存储的Cookie值,
// 以及Cookie过期的时间.
// 这几行是把天数转换为合法的日
function setCookie(NameOfCookie, value, expiredays) {

    var ExpireDate = new Date();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
    
    document.cookie = NameOfCookie + "=" + escape(value) +
  ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

///获取cookie值
function getCookies(NameOfCookie) {

   
    if (document.cookie.length > 0) {

        begin = document.cookie.indexOf(NameOfCookie + "=");
       
        if (begin != -1) {

            begin += NameOfCookie.length + 1; //cookie值的初始位置
            end = document.cookie.indexOf(";", begin); //结束位置
            if (end == -1) end = document.cookie.length; //没有;则end为字符串结束位置
            return unescape(document.cookie.substring(begin, end));
        }
        else
            return null;
    }

    return null;

    // cookie不存在返回null
};

$(function() {

    //    var flash = '<object type="application/x-shockwave-flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" value="http://www.123ping.com/images/active_2011_3_24.swf" width="120px" height="250px"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">';
    //        flash+='<param name="movie" value="http://www.123ping.com/images/active_2011_3_24.swf" /><param value="250px" name="quality"><param value="transparent" name="wmode">';
    //	    flash+='<embed width="120px" height="250px" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" wmode="transparent" src="http://www.123ping.com/images/active_2011_3_24.swf"></object>';
    var lflash = "<a href='http://vdong.cn/tologin.aspx' target='_blank'><img src='/images/120X300l.jpg' id='imgl' style='cursor:pointer;border:none'></a>";
    var rflash = "<a href='http://vdong.cn/tologin.aspx' target='_blank'><img src='/images/120X300r.gif' id='imgr' style='cursor:pointer;border:none'></a>";
    $("<div id='AdverLayerl' style='width:120px'><div id='closedLayerl' style='cursor:pointer;float:left'>关闭</div>" + lflash + "</div>").appendTo($("body"));
    $("<div id='AdverLayerr' style='width:120px'><div id='closedLayerr' style='cursor:pointer;float:right'>关闭</div>" + rflash + "</div>").appendTo($("body"));
    $("#AdverLayerl").css({ "position": "absolute", "left": "10px" });
    $("#AdverLayerr").css({ "position": "absolute", "right": "10px" });
    var Layerright = function(obj) {
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var myb = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
        var popupHeight = obj.height();
        var popupWidth = obj.width();
        obj.css({
            "position": "absolute",
            "top": (myb + (windowHeight - 250) / 2)+"px"
        });
    };
    Layerright($("#AdverLayerl"));
    $(window).scroll(function() { Layerright($("#AdverLayerl")); });
    Layerright($("#AdverLayerr"));
    $(window).scroll(function() { Layerright($("#AdverLayerr")); });
    $("#closedLayerl").click(function() { $("#AdverLayerl").hide(); });
    $("#closedLayerr").click(function() { $("#AdverLayerr").hide(); });
});
