﻿;
function addCookie(objName, objValue, objHours) {
    var str = objName + "=" + escape(objValue);
    if (objHours > 0) {//为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours * 3600 * 1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
}

// 获取cookie值
function GetCookie(sName) {
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return unescape(aCrumb[1]);
    }
    // a cookie with the requested name does not exist
    return null;
}

function __bingoGoTo(url) {
    var serperate = url.indexOf("?") >= 0 ? "&" : "?";
    window.location.href = url + serperate + 'Source=' + window.location;
    return false;
}

function __bingoGoBack() {
    var target = "";
    var len = arguments.length;

    if (len > 0) {
        target = arguments[0]; //url
    }
    else if (typeof __bingoSource != "undefined" && __bingoSource != "") {//__bingoSource 由basepage注册的全局变量
        target = __bingoSource;
    }
    else {
        alert("参数Source为空，无法返回");
        return;
    }

    window.location.href = target;
    return false;
}

//后台管理页面重置函数，需要重置的控件必须加上"_reset='true'"
function __bingoJsReset() {
    //客户端是input的
    $("input[_reset='true']").each(function () {
        var self = $(this);
        self.val("");
    });

    //获取下拉框的
    $("select[_reset='true']").each(function () {
        var self = $(this);
        self.val("");
    });

    return false;
}

//显示系统日期 
function __bingoGetFormatDate() {
    var now = new Date();
    var year = now.getYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();

    return year + "年" + month + "月" + day + "日";
}

//获取当前天的星期
function __bingoGetDayOfWeek() {
    var now = new Date();
    var day = now.getDay();
    var dayArr = new Array("星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    return dayArr[day];
}

//设为首页
function __bingoSetHomePage(obj) {
    if (obj == null) {
        return;
    }

    var url = window.location.protocol + '//' + window.location.host;
    obj.style.behavior = "url(#default#homepage)";
    obj.setHomePage(url);
    obj.style.behavior = "";
}

function __bingoShowDialog(sURL, title, width, height) {
    var sFeatures = "dialogHeight:" + height + "px;dialogWidth:" + width + "px;status=0;scroll=0";
    var url = sURL;
    return window.showModalDialog(url, null, sFeatures);
}

function __bingoGetFlashHtml(adid,src, w, h, id) {
    var tmpHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + w + '" height="' + h + '" id="' + id + '">';
    tmpHtml += '<param name="movie" value="' + src + '" />';
    tmpHtml += '<param name="quality" value="high" />';
    tmpHtml += '<embed src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>';
    tmpHtml += '</object>';

    return tmpHtml;
}

function __bingoGetADImageHtml(adid,src, w, h, description,linkUrl,id) {
    var adHtml = '<a href="' + linkUrl + '" _adid="' + adid + '" title="' + description + '" target="_blank"><img height=' + h + ' src="' + src + '" width=' + w + ' /></a>';
    return adHtml;
}

function __bingoLogAdClickCount(adId) {
    var urlLogClickCount = "/_Layouts/ApplicationPages/Proxy/LogAdClickCount.ashx?adid=" + adId + "&ran=" + Math.random();
    $.get(urlLogClickCount, { Action: "get" }, function (data, textStatus) { });
}

function __bingoChangeAdLinkAction() {
    //具有扩展属性的a标签都是记录点击率的广告
    $("a[_adid]").each(function (i) {
        this._ex_href = this.href;
        this.href = "javascript:void(0);";
        this.target = "";//取消的原来的打开方式，如"_blank";
        this.onclick = function () {
            __bingoLogAdClickCount(this._adid);//记录点击率
            window.open(this._ex_href);
        }
    });
}

function __bingoAutoSetIFrame(id, src, autoHeight, autoPageTitle) {
    if (id == '' || src == '')
        return;

    $(document).ready(function () {
        var _iframe = document.getElementById(id);
        //_iframe.width = width == "" ? "100%" : width;

        _iframe.src = src + (src.indexOf('?') != -1 ? '&' : '?') + '_frmId=' + id + "&_autoHeight=" + autoHeight + "&_syncPageTitle=" + autoPageTitle + "&_rand=" + Math.random();
    });
}

function __bingoIFrameAutoSize(objIFrame) {
    try{
        if (objIFrame.id && objIFrame.height) {
            if (objIFrame.height != "") {
                document.getElementById(objIFrame.id).height = objIFrame.height;
            }
        }

        if (typeof (objIFrame.pageTitle) != "undefined" && objIFrame.pageTitle != "") {
            document.title = objIFrame.pageTitle;
        }

        if (typeof (objIFrame.isHide) != "undefined") {
            var iframeContainer = document.getElementById("div-" + objIFrame.id);

            if (!iframeContainer)
                return;

            if (objIFrame.isHide == "true") {
                iframeContainer.style.display = "none";
            }
        }
    }
    catch(ex)
    {
        //alert("out:" + ex.Description);
    }
}

function __bingoShowObject(objId)
{
    $("#"+objId).show('');
}

function __bingoDelayShowDivEditBar(divBarId,delay) {
    window.setTimeout("__bingoShowObject('" + divBarId + "')", delay);
}

function __bingoOnToggleDiv(clickObj, divId) {
    var imgJia = clickObj._jia;
    var imgJian = clickObj._jian;

    var elem = document.getElementById(divId);
    if (elem.style.display == 'none') {
        elem.style.display = '';
        if (imgJian != "") {
            clickObj.src = imgJian;
        }
    }
    else {
        elem.style.display = 'none';
        if (imgJia != "") {
            clickObj.src = imgJia;
        }
    }
}

function __bingoLoadPng(o) {
    if (document.all) {//判断是否ie
        try {
            var img = o;
            var imgName = o.src.toUpperCase();
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : "";
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                var imgStyle = "display:inline-block;" + img.style.cssText;
                if (img.align == "left")
                    imgStyle = "float:left;" + imgStyle;
                if (img.align == "right") 
                    imgStyle = "float:right;" + imgStyle;
                if (img.parentElement.href) 
                    imgStyle = "cursor:hand;" + imgStyle;
                var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>";
                img.outerHTML = strNewHTML;
            }
        }
        catch (e) {
            alert(e.Message);
        }
    }
}

//该函数为jQuery的Load函数的的简单封装，加入了显示Loading功能
function __bingoAjaxLoad(htmlContainerId, url, params, callback) {
    var getObjString;
    if (htmlContainerId.indexOf("#") != -1)
        getObjString = htmlContainerId;
    else
        getObjString = "#" + htmlContainerId;

    if (typeof (callback) != "function") {
        $(getObjString).prepend("<div style='text-align:center'>正在刷新中...</div>");
    }

    $(getObjString).load(url, params, callback);
}

//通用Tab切换
function __setTab(tabId, n) {
    var tli = $("li > a", document.getElementById(tabId));
    var containerTagName = "ul";
    var hoverClassName = "current";

    if (arguments.length > 2) {
        containerTagName = arguments[2];
    }

    if (arguments.length > 3) {//4个参数
        hoverClassName = arguments[3];
    }

    var mli = document.getElementById(tabId + "-div").getElementsByTagName(containerTagName);

    try {
        for (i = 0; i < tli.length; i++) {
            tli[i].className = i == n ? hoverClassName : "";
            mli[i].style.display = i == n ? "block" : "none";
        }
    } catch (e) {
        //alert(e.Message);
    }
}

//----------------------######### 门户框架公用函数 End   ##########----------------------------------------

//----------------------$$$$$$$$$ 以下开始为项目用的函数 $$$$$$$$------------------------------------------
///显示授权对话框
function __bingoShowPermissionDialog(scopeId, resType, title, isInherit) {
    var url = '/Admin/Permission/SysPermissionList.aspx?IsInherit=' + isInherit +
              '&ScopeId=' + scopeId + '&type=' + resType + '&showname=' + encodeURI(title) + "&t=" + Math.random();
    __bingoShowDialog(url, title, 700, 450);
    return false;
}

//列表全选方法
function __bingoSelectAll(obj, gridviewID) {
    if (obj == null) {
        return;
    }

    var grd = document.getElementById(gridviewID);
    for (var i = 1; i < grd.rows.length; i++) {
        if (grd.rows[i].cells[0].children.length > 0) {
            chbItem = grd.rows[i].cells[0].children[0].children[0];
            chbItem.checked = obj.checked;
        }
    }
}

//检察是否有选择删除的记录
function __bingoCheckSelected(gridviewID) {
    var isFind = false;
    var grd = document.getElementById(gridviewID);
    for (var i = 1; i < grd.rows.length; i++) {
        if (grd.rows[i].cells[0].children.length > 0) {
            chbItem = grd.rows[i].cells[0].children[0].children[0];
            if (chbItem.checked) {
                isFind = true;
                break;
            }
        }
    }
    if (isFind) {
        return confirm("确定要删除所选的记录吗？");
    }
    else {
        alert("请选择要删除的记录！");
        return false;
    }
}


function __bingoRereshEmail(iframeId) {
    var emailIframe = document.getElementById(iframeId);

    if (emailIframe) {
        var orginSrc = "";
        if (typeof (emailIframe._orgUrl) == "undefined") {
            emailIframe._orgUrl = emailIframe.src;
        }
        orginSrc = emailIframe._orgUrl;
        emailIframe.src = orginSrc + "&ran=" + Math.random();
    }
}
