﻿/// <reference path="JQuery.js" />
//#region JS通用功能
//获取当前页的绝对地址或虚拟目录
var setRootPath = function (root) {
    ///<summary>
    ///获取当前页的绝对地址或虚拟目录
    ///</summary>
    var last = root.charAt(root.length - 1);
    rootPath = root;
};


//全选，多选,反选
function SelectChkBox(container, isChecked) {
    ///<summary>
    ///全选，多选,反选
    ///</summary>
    ///	<param name="container" type="String">
    ///checkbox所在的容器
    ///</param>
    ///	<param name="isChecked" type="Boolean">
    ///	可选，如果没有填：反选
    ///  true 全选
    ///  false 不选
    ///	</param>
    if (arguments.length < 2) {
        $("#" + container + " input[@type='checkbox']").each(function () {
            $(this).attr("checked", !$(this).attr("checked"));
        });
    }
    else {
        $("#" + container + " input[@type='checkbox']").each(function () {
            $(this).attr("checked", isChecked);
        });
    }
};

function GetSelChk(container) {
    ///<summary>
    ///获取某一容器里的checkbox选中的值
    ///</summary>
    var items = "";
    $("#" + container + " input[type='checkbox']").each(function () {
        if ($(this).attr("checked") == true && ($(this).attr("name") == "")) {
            var value = $(this).val();
            items += value != 0 ? $(this).val() + "," : "";
        }
    });
    if (item.length > 0) {
        items = items.substring(0, items.length - 1);
    }
    return items;
};

var SearchPath = function (parameter) {
    ///<summary>
    ///重新设置URL,生成符合条件的参数
    ///</summary>
    ///	<param name="parameter" type="json">
    ///	对应的URL参数，{Key:Value}形式
    ///	</param>
    var href = location.href;
    for (v in parameter) {
        var reg = new RegExp('[\?\&]' + v + '=([^\&]*)(\&?)', 'i');
        if (href.match(reg)) {
            href = href.replace(new RegExp(v + '=([^\&]*)', 'i'), v + "=" + parameter[v]);
        }
        else {
            var n = href.indexOf("?");
            href += (n > 0 ? "&" : "?") + v + "=" + parameter[v];
        }
    }
    return href;
};

//弹出确认对话框
var isConfirm = function () {
    return confirm("您确定要删除此条信息吗？");
};

var DeleteItem = function (arge0, arge1, arge2) {
    ///	<summary>
    ///		通用删除功能
    ///	</summary>
    if (!isConfirm()) {
        return;
    }
    $.ajax({
        type: "post",
        url: rootPath + "Ajax/AjaxHandler.ashx",
        async: true,
        data: { o: "delitem", t: arge0, k: arge1, i: arge2 },
        beforeSend: function () { $("#loading").show(); },
        error: function (d) { $("#loading").html("<img src=\"../images/loading.gif\" align=\"middle\" />处理失败……"); $("#loading").hide(2000); },
        complete: function () { $("#loading").hide(); },
        success: function (s) {
            var json = eval('(' + s + ')');
            if ("1" == json.Status) {
                location.href = location.href;
            }
            else {
                alert(json.Msg);
            }
            return false;
        }
    });
};

var EditItem = function (param, tab, KeyName, KeyValue) {
    $.ajax({
        type: "post",
        url: rootPath + "Ajax/AjaxHandler.ashx",
        async: true,
        data: param + "&o=edititem&tab=" + tab + "&keyname=" + KeyName + "&keyvalue=" + KeyValue,
        beforeSend: function () { $("#loading").show(); },
        error: function (d) { $("#loading").html("<img src=\"../images/loading.gif\" align=\"middle\" />处理失败……"); $("#loading").hide(5000); },
        complete: function () { $("#loading").hide(5000); },
        success: function (s) {
            var json = eval('(' + s + ')');
            if ("1" == json.Status) {
                location.href = location.href;
                //   $("#loading").html("<img src=\"images/loading.gif\" align=\"middle\" />处理成功"); $("#loading").hide(5000);
            }
            else {
                alert(json.Msg);
            }
            return false;
        }
    });
};

//打开全屏窗口
function WinOpenFullScreen(strURL) {
    var sheight = screen.height - 70;
    var swidth = screen.width - 10;
    var winoption = "left=0,top=0,height=" + sheight + ",width=" + swidth + ",toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes";
    var tmp = window.open(encodeURI(strURL), '', winoption);
    return tmp;
};

/////cookies操作
jQuery.cookie = function (name, value, options) {
    ///	<summary>
    ///		1: $.cookie(name) - 获取name所对应的Cookie的值。
    ///		2: $.cookie(name, value) - 设置name所对应的值为value。
    ///		3: $.cookie(name, value, options) - 设置name所对应的值为value，并设置相应的属性。
    ///	</summary>

    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

var addFavorite = function () {
    ///	<summary>
    ///		加入收藏
    ///	</summary>
    var title = document.title;
    var url = document.location.href;
    try {
        window.external.addFavorite(url, title);
    } catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
};

var setHome = function (obj) {
    ///	<summary>
    ///		设为首页
    ///	</summary>
    var vrl = window.location;
    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);
        }
    }
};


///无缝滚动
var Marquee = function (id) {
    ///<summary>
    ///无缝滚动
    ///</summary>
    ///	<param name="id" type="String">滚动容器</param>
    ///	<param name="Direction" type="String">滚动方向 Left:向左 Right:向右 Top:向上 Bottom:向下</param>
    ///	<returns type="void" />  
    try { document.execCommand("BackgroundImageCache", false, true); } catch (e) { };
    var container = document.getElementById(id);
    var original = document.getElementById(id + "Old");
    var clone = document.getElementById(id + "Clone");
    var speed = arguments[2] || 10;
    var direction = arguments[1];
    clone.innerHTML = original.innerHTML;
    var rolling = function () {
        switch (direction) {
            case "Top":
                if (container.scrollTop == clone.offsetTop) {
                    container.scrollTop = 0;
                } else {
                    container.scrollTop++;
                }
                break;
            case "Bottom":
                if (container.scrollTop == 0) {
                    container.scrollTop = clone.offsetTop;
                } else {
                    container.scrollTop--;
                }
                break;

            case "Left":
                if (container.scrollLeft == clone.offsetLeft) {
                    container.scrollLeft = 0;
                } else {
                    container.scrollLeft++;
                }
                break;

            case "Right":
                if (container.scrollLeft == 0) {
                    container.scrollLeft = clone.offsetLeft;
                } else {
                    container.scrollLeft--;
                }
                break;
        }
    }
    var timer = setInterval(rolling, speed)//设置定时器
    container.onmouseover = function () { clearInterval(timer) } //鼠标移到marquee上时，清除定时器，停止滚动
    container.onmouseout = function () { timer = setInterval(rolling, speed) } //鼠标移开时重设定时器
};

//#endregion 


//#region 后台代码的JS功能实现
//后台记录列表的鼠标效果
function changeto(obj) {
    obj.className = "showMsgA";
}
function changeback(obj) {
    obj.className = "showMsg";
}
function checkall(obj) {
    $(":checkbox").attr("checked", obj.checked);
}

//删除文章信息
function DeleteArticle(id) {
    var whatID = "";
    if (arguments.length > 0) {
        whatID = id;
    } else {
        whatID = GetSelChk("DataList");
    }
    if (whatID == "") {
        alert("请选择要处理的记录"); return false;
    }
    return DeleteItem("Fox_Article", "ArticleID", whatID);
}

//删除文章信息
function DeleteDownLoad(id) {
    var whatID = "";
    if (arguments.length > 0) {
        whatID = id;
    } else {
        whatID = GetSelChk("DataList");
    }
    if (whatID == "") {
        alert("请选择要处理的记录"); return false;
    }
    return DeleteItem("Fox_DownLoad", "DID", whatID);
}

//更改文章信息状态
function setStatu(t, f, v, k) {
    var items = GetSelChk("DataList");
    if (items == "") {
        alert("请选择要处理的记录"); return false;
    }
    $.post(rootPath + "Ajax/AjaxHandler.ashx", { o: "chkitem", i: items, t: t, k: k, v: v, f: f }, function (s) {
        var json = eval('(' + s + ')');
        if ("1" == json.Status) {
            location.href = location.href;
        }
        else {
            alert(json.Msg);
        }
    });
}



///文章信息搜索
function SearchItems() {
    var key = $("#KeyWord");
    var start = $("#start").val();
    var end = $("#end").val();
    var statu = $("#Statu").val();
    key = encodeURIComponent(key.val());
    location.href = SearchPath({ Key: key, Start: start, End: end, Statu: statu, PageNo: 1 });
    return false;
}

//#endregion


function nTabs(tabObj, obj) {
    var tabList = document.getElementById(tabObj).getElementsByTagName("li");
    for (i = 0; i < tabList.length; i++) {
        if (tabList[i].id == obj.id) {
            document.getElementById(tabObj + "_Title" + i).className = "active";
            document.getElementById(tabObj + "_Content" + i).style.display = "block";
        } else {
            document.getElementById(tabObj + "_Title" + i).className = "normal";
            document.getElementById(tabObj + "_Content" + i).style.display = "none";
        }
    }
}
/*第一种形式 第二种形式 更换显示样式*/
function setTab() {
    if (cursel == 3)
        cursel = 0;
    cursel++;
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        menu.className = i == cursel ? "hover" : "";
        con.style.display = i == cursel ? "block" : "none";
    }
}

/*第一种形式 第二种形式 更换显示样式*/
function setTab1(name, cursel, n) {
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        menu.className = i == cursel ? "hover" : "";
        con.style.display = i == cursel ? "block" : "none";
    }
}

//更改字体大小
var status0 = '';
var curfontsize = 10;
var curlineheight = 18;
function fontZoomA() {
    if (curfontsize > 8) {
        document.getElementById('fontzoom').style.fontSize = (--curfontsize) + 'pt';
        document.getElementById('fontzoom').style.lineHeight = (--curlineheight) + 'pt';
    }
}
function fontZoomB() {
    if (curfontsize < 64) {
        document.getElementById('fontzoom').style.fontSize = (++curfontsize) + 'pt';
        document.getElementById('fontzoom').style.lineHeight = (++curlineheight) + 'pt';
    }
}

function SetLinkPath(LinkPath) {
    $("#LinkPath").html(LinkPath);
}



function addEvent(obj, evtType, func, cap) {
    cap = cap || false;
    if (obj.addEventListener) {
        obj.addEventListener(evtType, func, cap);
        return true;
    } else if (obj.attachEvent) {
        if (cap) {
            obj.setCapture();
            return true;
        } else {
            return obj.attachEvent("on" + evtType, func);
        }
    } else {
        return false;
    }
}
function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageXOffset) {
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollLeft) {
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {
        xScroll = document.body.scrollLeft;
    }
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
}
function GetPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}
//广告脚本文件 js漂浮广告代码(简洁!) AdMove.js
/*
例子
<div id="Div2">
***** content ******
</div>
var ad=new AdMove("Div2");
ad.Run();
*/
////////////////////////////////////////////////////////
var AdMoveConfig = new Object();
AdMoveConfig.IsInitialized = false;
AdMoveConfig.ScrollX = 0;
AdMoveConfig.ScrollY = 0;
AdMoveConfig.MoveWidth = 0;
AdMoveConfig.MoveHeight = 0;
AdMoveConfig.Resize = function () {
    var winsize = GetPageSize();
    AdMoveConfig.MoveWidth = winsize[2];
    AdMoveConfig.MoveHeight = winsize[3];
    AdMoveConfig.Scroll();
}
AdMoveConfig.Scroll = function () {
    var winscroll = getPageScroll();
    AdMoveConfig.ScrollX = winscroll[0];
    AdMoveConfig.ScrollY = winscroll[1];
}
addEvent(window, "resize", AdMoveConfig.Resize);
addEvent(window, "scroll", AdMoveConfig.Scroll);
function AdMove(id) {
    if (!AdMoveConfig.IsInitialized) {
        AdMoveConfig.Resize();
        AdMoveConfig.IsInitialized = true;
    }
    var obj = document.getElementById(id);
    obj.style.position = "absolute";
    var W = AdMoveConfig.MoveWidth - obj.offsetWidth;
    var H = AdMoveConfig.MoveHeight - obj.offsetHeight;
    var x = W * Math.random(), y = H * Math.random();
    var rad = (Math.random() + 1) * Math.PI / 6;
    var kx = Math.sin(rad), ky = Math.cos(rad);
    var dirx = (Math.random() < 0.5 ? 1 : -1), diry = (Math.random() < 0.5 ? 1 : -1);
    var step = 1;
    var interval;
    this.SetLocation = function (vx, vy) { x = vx; y = vy; }
    this.SetDirection = function (vx, vy) { dirx = vx; diry = vy; }
    obj.CustomMethod = function () {
        obj.style.left = (x + AdMoveConfig.ScrollX) + "px";
        obj.style.top = (y + AdMoveConfig.ScrollY) + "px";
        rad = (Math.random() + 1) * Math.PI / 6;
        W = AdMoveConfig.MoveWidth - obj.offsetWidth;
        H = AdMoveConfig.MoveHeight - obj.offsetHeight;
        x = x + step * kx * dirx;
        if (x < 0) { dirx = 1; x = 0; kx = Math.sin(rad); ky = Math.cos(rad); }
        if (x > W) { dirx = -1; x = W; kx = Math.sin(rad); ky = Math.cos(rad); }
        y = y + step * ky * diry;
        if (y < 0) { diry = 1; y = 0; kx = Math.sin(rad); ky = Math.cos(rad); }
        if (y > H) { diry = -1; y = H; kx = Math.sin(rad); ky = Math.cos(rad); }
    }
    this.Run = function () {
        var delay = 10;
        interval = setInterval(obj.CustomMethod, delay);
        obj.onmouseover = function () { clearInterval(interval); }
        obj.onmouseout = function () { interval = setInterval(obj.CustomMethod, delay); }
    }
}
function hidead()
{ document.getElementById("ad").style.display = "none"; }
