﻿// JScript 文件

function GetE(id){ 
    return document.getElementById(id); 
}

//取得所有类型控件
function GetNameList(name)
{
	return document.getElementsByTagName?document.getElementsByTagName(name):new Array()
}

//隐藏所有类型控件
function HiddenControl(name)
{
    var _AllControl = GetNameList(name);
	for (var i=0; i<_AllControl.length; i++)
	{
		_AllControl[i].style.visibility = "hidden";
	}
}

//显示所有类型控件
function VisibleControl(name)
{
    var _AllControl = GetNameList(name);
	for (var i=0; i<_AllControl.length; i++)
	{
		_AllControl[i].style.visibility = "visible";
	}
}

document.onclick = function(e) {
    var e = e ? e : window.event;

    try {
        for (var iDocumentOnlick = 0; iDocumentOnlick < _arrDocumentOnlick.length; iDocumentOnlick++) {
            try { _arrDocumentOnlick[iDocumentOnlick](e); }
            catch (ex) { }
        }
    }
    catch (ex) { }
}

function AddCloseListName(Name)
{
    try { _CloseListName = _CloseListName.replace("," + Name + ",", ",") + Name + ","; }
    catch(ex) { _CloseListName = "," + Name + ","; }
}

//登录(窗口)
function UserWindowLogin(VirtualPath)
{
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Personal_User + "WindowLogin.aspx?VirtualPath=" + escape(VirtualPath) + "\" width=\"538\" height=\"324\"></iframe>";
    DialogShow(ShowData,538,324,538,324);
}

//注册(窗口)
function UserWindowSignIn(VirtualPath,Source,Source_Remark)
{
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Personal_User + "WindowSignIn.aspx?VirtualPath=" + escape(VirtualPath) + "&Source=" + escape(Source) + "&Source_Remark=" + escape(Source_Remark) + "&Time="+ new Date() +"\" width=\"570\" height=\"370\"></iframe>";
    DialogShow(ShowData,570,370,570,370);
}

//用户信息(窗口)
function UserInfoEdit(VirtualPath)
{
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Personal_User + "UserManage/UserInfoEdit.aspx?VirtualPath=" + escape(VirtualPath) + "\" width=\"538\" height=\"371\"></iframe>";
    DialogShow(ShowData,538,371,538,371);
}

//上传头像(窗口)
function UserUploadPhoto(VirtualPath)
{
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Personal_User + "UserManage/UserPhoto.aspx?VirtualPath=" + escape(VirtualPath) + "\" width=\"452\" height=\"352\"></iframe>";
    DialogShow(ShowData,452,352,452,352);
}

//未实名
function UserRealityStatus(VirtualPath)
{
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Personal_User + "UserManage/RealityManage.aspx?VirtualPath="+ escape(VirtualPath) +"\" width=\"538\" height=\"364\"></iframe>";
    DialogShow(ShowData,538,364,538,364);
}

//已实名
function UserRealityStatused(VirtualPath)
{
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Personal_User + "UserManage/RealityManage.aspx?VirtualPath="+ escape(VirtualPath) +"\" width=\"538\" height=\"250\"></iframe>";
    DialogShow(ShowData,538,250,538,250);
}

//获取URL参数
function GetUrlPara(paras)
{ 
    var url = location.href; 
    var paraString = url.substring(url.indexOf("?")+1,url.length).split("&"); 
    var paraObj = {} 
    for (i=0; j=paraString[i]; i++){ 
    paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length); 
    } 
    var returnValue = paraObj[paras.toLowerCase()]; 
    if(typeof(returnValue)=="undefined"){ 
    return ""; 
    }else{ 
    return returnValue; 
    } 
}


//复制
function CopyToClipBoard(Content)
{
    if(window.clipboardData)
    {  
        window.clipboardData.clearData();  
        window.clipboardData.setData("Text",Content);  
    }  
    else if(navigator.userAgent.indexOf("Opera")!=-1)
    {  
        window.location=Content;  
    }  
    else if(window.netscape)
    {  
        try
        {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
        }  
        catch(e)
        {  
            alert("您的firefox安全限制限制您进行剪贴板操作，请使用其他浏览器！");  
            return false;  
        }
        
        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=Content;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);
    }
    
    return true;
}

//通用-个人信息
function PersonalInfo(obj,UserID)
{
    if(UserID > 0)
    {
        obj.href = Virtual_Path_Personal_User + "UserInfo.aspx?UserID=" + UserID;
        obj.target= "_blank";
    }
    else
    {
        return false;
    }
}
//消息列表
function MessageList(VirtualPath) {
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Common_Utils + "MessageManage/MessageList.aspx?VirtualPath=" + escape(VirtualPath) + "\" width=\"802\" height=\"475\"></iframe>";
    DialogShow(ShowData, 802, 475, 802, 475);
}
//消息
function MessageInfo(Message_ID, VirtualPath, VirtualParentPath) {
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Common_Utils + "MessageManage/MessageInfo.aspx?MessageID=" + Message_ID
    + "&VirtualPath=" + escape(VirtualPath)
    + "&VirtualParentPath=" + escape(VirtualParentPath)
    + "\" width=\"499\" height=\"381\"></iframe>";
    DialogShow(ShowData, 499, 381, 499, 381);
}
//写信息
function MessageAdd(Related_MessageID, Receiver_Type, Receiver_ID, Identity, VirtualPath) {
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Common_Utils
        + "MessageManage/MessageAdd.aspx?RelatedMessageID=" + Related_MessageID
        + "&ReceiverType=" + Receiver_Type
        + "&ReceiverID=" + Receiver_ID
        + "&Identity=" + Identity
        + "&VirtualPath=" + escape(VirtualPath) + "\" width=\"802\" height=\"475\"></iframe>";
    DialogShow(ShowData, 802, 475, 802, 475);
}

function MessageAddTo(Message_ID, Receiver_Type, Receiver_ID, Identity, VirtualPath) {
    location.href = Virtual_Path_Common_Utils
        + "MessageManage/MessageAdd.aspx?MessageID=" + Message_ID
        + "&ReceiverType=" + Receiver_Type
        + "&ReceiverID=" + Receiver_ID
        + "&Identity=" + Identity
        + "&VirtualPath=" + escape(VirtualPath);
}

//收藏列表
function FavoritesList(VirtualPath,Source) {
    ScreenConvert();
    var ShowData = "<iframe marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"" + Virtual_Path_Common_Utils + "FavoritesManage/FavoritesList.aspx?VirtualPath=" + escape(VirtualPath) + "&Source=" + escape(Source) + "\" width=\"602\" height=\"412\"></iframe>";
    DialogShow(ShowData, 602, 412, 602, 412);
}

//载入中
function MainLoading()
{
    ScreenConvert();
    var ShowData = "<ul class=\"ulMainLoading\"><li>数据载入中...</li></ul>";
    DialogShow(ShowData,252,62,252,62);
}
//返回顶部滑动特效
function GoTop() {
    if ($.browser.safari) {//这里判断浏览器是否为safari 
        $('body').animate({ scrollTop: 0 }, 'fast');
        return false; //返回false可以避免在原链接后加上# 
    }
    else {
        $('html').animate({ scrollTop: 0 }, 500);
        return false;
    }
}

//取得搜索路径(个人)
function GetSearchURLForPersonal(Key, Type, Series)
{
    var _SearchUrlForPersonal = "";
    if(Key != "")
    {
        if(_SearchUrlForPersonal == "")
        {
            _SearchUrlForPersonal += "?";
        }
        else
        {
            _SearchUrlForPersonal += "&";
        }
        _SearchUrlForPersonal += "Key=" + escape(Key);
    }
    if(Type > 0)
    {
        if(_SearchUrlForPersonal == "")
        {
            _SearchUrlForPersonal += "?";
        }
        else
        {
            _SearchUrlForPersonal += "&";
        }
        _SearchUrlForPersonal += "t=" + Type;
    }
    if (Series > 0)
    {
        if(_SearchUrlForPersonal == "")
        {
            _SearchUrlForPersonal += "?";
        }
        else
        {
            _SearchUrlForPersonal += "&";
        }
        _SearchUrlForPersonal += "s=" + Series;
    }
    
    return Virtual_Path_Personal_Main + "Search/Index.aspx" + _SearchUrlForPersonal;
}

//遮罩弹框-通用
Function.prototype.binding = function() {
    if (arguments.length < 2 && typeof arguments[0] == "undefined") return this;
    var __method = this, args = jQuery.makeArray(arguments), object = args.shift();
    return function() {
        return __method.apply(object, args.concat(jQuery.makeArray(arguments)));
    }
}

var Class = function(subclass){
    subclass.setOptions = function(options){
        this.options = jQuery.extend({}, this.options,options);
        for(var key in options){
            if(/^on[A-Z][A-Za-z]*$/.test(key)){
                $(this).bind(key,options[key]);
            }
        }
    }
    var fn =  function(){
        if(subclass._init && typeof subclass._init == 'function'){
            this._init.apply(this,arguments);
        }
    }
    if(typeof subclass == 'object'){
        fn.prototype = subclass;
    }
    return fn;
}

var PopupLayer = new Class({
    options:{
        trigger:null,                            //触发的元素或id,必填参数
        popupBlk:null,                           //弹出内容层元素或id,必填参数
        closeBtn:null,                           //关闭弹出层的元素或id
        popupLayerClass:"popupLayer",            //弹出层容器的class名称
        eventType:"click",                       //触发事件的类型
        offsets:{                                //弹出层容器位置的调整值
            x:0,
            y:0
        }
    },

    _init:function(options){
        this.setOptions(options);                //载入设置
        this.isSetPosition = this.isDoPopup = this.isOverlay = true;    //定义一些开关
        this.popupLayer = $(document.createElement("div")).addClass(this.options.popupLayerClass);     //初始化最外层容器
        this.popupIframe = $(document.createElement("iframe")).attr({border:0,frameborder:0});         //容器遮罩,用于屏蔽ie6下的select
        //this.trigger = $(this.options.trigger);                         //把触发元素封装成实例的一个属性，方便使用及理解
        this.popupBlk = $(this.options.popupBlk);                       //把弹出内容层元素封装成实例的一个属性
        this.closeBtn = $(this.options.closeBtn);                       //把关闭按钮素封装成实例的一个属性
        this._construct()                                               //通过弹出内容层，构造弹出层，即为其添加外层容器及底层iframe
        
        $("[name='" + this.options.trigger + "']").bind(this.options.eventType,function(){            //给触发元素绑定触发事件
            if(this.isSetPosition){
                var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
                this.setPosition(this.options.offsets.x, scrollTop + this.options.offsets.y);
            }
            this._loadOverlay();               //如果使用遮罩则加载遮罩元素
            this.overlay.fadeIn();
            if(this.isDoPopup && (this.popupLayer.css("display")== "none")){
                this.popupLayer.fadeIn();
            }                             
        }.binding(this));

        this.options.closeBtn?this.closeBtn.bind("click",this.close.binding(this)):null;   //如果有关闭按钮，则给关闭按钮绑定关闭事件
    },
    _construct:function(){                  //构造弹出层
        this.popupLayer.append(this.popupBlk.css({opacity:1})).appendTo($(document.body)).css({position:"absolute",'z-index':9999});
        this.popupBlk.css({"left": ($(window).width()/2 - this.popupBlk.width()/2) + 'px',"top": ($(window).height()/2 - this.popupBlk.height()/2) + 'px'}).show();
        this.recalculatePopupIframe();
        this.popupLayer.hide();
    },
    _loadOverlay:function(){                //加载遮罩
        pageWidth = ($.browser.version=="6.0")?$(document).width()-21:$(document).width();
        this.overlay?this.overlay.remove():null;
        $("[name='divShareOverLay']").remove();
        this.overlay = $(document.createElement("div"));
        this.overlay.attr("name","divShareOverLay");
        this.overlay.css({position:"absolute","z-index":9998,left:0,top:0,zoom:1,display:"none",width:"100%",height:$(document).height()}).appendTo($(document.body)).append("<div style='position:absolute;z-index:2;width:100%;height:100%;left:0;top:0;opacity:0.5;filter:Alpha(opacity=50);background:#000'></div><iframe frameborder='0' border='0' style='width:100%;height:100%;position:absolute;z-index:1;left:0;top:0;filter:Alpha(opacity=0);'></iframe>");
    },
    setPosition:function(left,top){          //通过传入的参数值改变弹出层的位置
        this.popupLayer.css({left:left,top:top});
    },
    recalculatePopupIframe:function(){     //重绘popupIframe,这个不知怎么改进，只好先用这个笨办法。
        //this.popupIframe.css({position:"absolute",'z-index':-1,left:0,top:0,opacity:0,width:this.popupBlk.get(0).offsetWidth,height:this.popupBlk.get(0).offsetHeight});
    },
    close:function(){                      //关闭方法
        try{this.overlay.fadeOut();}catch(ex){}
        this.popupLayer.hide();
    }
});

//标题闪烁
(function($) {
    $.extend({
        /**
         * 调用方法： var timerArr = $.blinkTitle.show();
         *          $.blinkTitle.clear(timerArr);
         */
        blinkTitle : {
            show : function(TitleOne, TitleTwo) {
                //有新消息时在title处闪烁提示
                var step=0, _title = document.title;

                var timer = setInterval(function() {
                    step++;
                    if (step==3) {step=1};
                    if (step==1) {document.title = TitleOne + _title};
                    if (step==2) {document.title = TitleTwo + _title};
                }, 500);

                return [timer, _title];
            },     

            /**
             * @param timerArr[0], timer标记
             * @param timerArr[1], 初始的title文本内容
             */
            clear : function(timerArr) {    //去除闪烁提示，恢复初始title文本
                if(timerArr) {
                    clearInterval(timerArr[0]);
                    document.title = timerArr[1];
                };
            }
        }
    });
})(jQuery);

// **************************************************************** //
// function Trim(value)
// --------------
// 功能：删除两端空格（= Trim）
// 参数：       value 要格式化的字符串
// 返回：       格式化后的字符串
// **************************************************************** //
function Trim(value){
	var res = String(value).replace(/^[\s]+|[\s]+$/g,'');
	return res;
}
