﻿function Search() {
    var searchtxt = $("#searchtxt").val();
    searchtxt = $.trim(searchtxt);
    if (searchtxt == "") {
        if ($("#currentSelect").html() == "视 频") {
            window.location.href = "/list.html";
        }
        if ($("#currentSelect").html() == "文 章") {
            window.location.href = "/Article/list.html";
        }
        if ($("#currentSelect").html() == "资 料") {
            window.location.href = "/Down/list.html";
        }

        if ($("#currentSelect").html() == "Flv视频") {
            window.location.href = "/flvvideo/list.html";
        }
    }
    else {
        if ($("#currentSelect").html() == "视 频") {
            window.location.href = "/search/" + searchtxt + ".html";
        }
        if ($("#currentSelect").html() == "文 章") {
            window.location.href = "/Article/search/" + searchtxt + ".html";
        }
        if ($("#currentSelect").html() == "资 料") {
            window.location.href = "/Down/search/" + searchtxt + ".html";
        }

        if ($("#currentSelect").html() == "Flv视频") {
            window.location.href = "/Flvvideo/search/" + searchtxt + ".html";
        }
    }
}

function searchtab(tab) {
    if (tab == "0") {
        $("#currentSelect").html("视 频");
    }
    if (tab == "1") {
        $("#currentSelect").html("文 章");
    }
    if (tab == "2") {
        $("#currentSelect").html("资 料");
    }
    if (tab == "3") {
        $("#currentSelect").html("Flv视频");
    }
}

function SubmitKeyClick(button) {
    if (event.keyCode == 13) {
        event.keyCode = 9;
        event.returnValue = false;
        document.getElementById(button).click();
        //document.all[button].click();
    }
}

function collect(v_title) {
    var url = window.location;
    $.get("/ajax/collect.ashx?url=" + url + "&t=" + v_title,
  function (data) {
      if (data == "-1") {
          if (confirm('您好！，收藏需要用户身份验证，你现在需要登录后再收藏吗？')) {
              window.location.href = '/login.aspx?url=' + window.location;
          }
          //alert('请先登录后在收藏!');
      }
      if (data == "1") {
          alert('收藏成功！要查阅的时候在 我的空间-我的收藏里面就可以找到了');
      }
      if (data == "0") {
          alert('收藏失败!请稍后再试');
      }
  });
}


function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function SetHome(obj,vrl){
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                        }
                        catch (e) {
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
            }

            function CopyContent() {
                var str = document.getElementById("v_title").innerHTML;
                str = "<h1>" + str + "</h1>";
                str = str + document.getElementById("d_c").innerHTML;
                copy_clip(str, "已复制本内容,请粘贴本内容发布你的日志分享给你的好友吧！");
            }


            function copy_clip(copy,desc) {
                if (window.clipboardData) {
                    window.clipboardData.setData("Text", copy);
                }
                else if (window.netscape) {
                    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
                    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 = copy;
                    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);
                }
                alert("已复制" + desc);
                return false;
            }


            function readCookie(name) {
                var cookieValue = "";
                var search = name + "=";
                if (document.cookie.length > 0) {
                    offset = document.cookie.indexOf(search);
                    if (offset != -1) {
                        offset += search.length;
                        end = document.cookie.indexOf(";", offset);
                        if (end == -1) end = document.cookie.length;
                        cookieValue = unescape(document.cookie.substring(offset, end))
                    }
                }
                return cookieValue;
            }

            function writeCookie(name, value, hours) {
                var expire = "";
                if (hours != null) {
                    expire = new Date((new Date()).getTime() + hours * 3600000);
                    expire = "; expires=" + expire.toGMTString();
                }
                document.cookie = name + "=" + escape(value) + expire;
            }

