﻿var common = {};
common.form = {};
common.ajax = {};
common.mouse = {};
common.verifyCode = {};
common.constants = {
    TAG_ATTR_SUBMIT_BUTTON_VALUE: '_val'
};
//换一个验证码
var refreshVerifyCode = common.verifyCode.refresh = function() {
    var verifyCodeImg = $('#verifyCodeImg');
    if (!verifyCodeImg.attr('_src')) {
        verifyCodeImg.attr('_src', verifyCodeImg.attr('src'));
    }
    verifyCodeImg.attr('src', verifyCodeImg.attr('_src') + "?" + Math.random());
    if ($('#verifyCode').size()) {
        $('#verifyCode').get(0).select();
    }
    return false;
};
//获取鼠标坐标
var getMouseCoordinates = common.mouse.offset = function(ev) {
    ev = ev ? ev : window.event;
    if (ev.pageX || ev.pageY)
        return { x: ev.pageX, y: ev.pageY };
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
};
//获取AJAX加载中的信息
var getAjaxLoadingDivFloat = common.ajax.message = function(init) {
    var ajaxLoadingFloat = $('.ajaxLoadingFloat');
    if (!ajaxLoadingFloat.size() && init) {
        $('body').append('<div class="ajaxMessage ajaxLoadingFloat" style="display:none; background-color:white; position:absolute;z-index:1001; border:solid #333333 1px; padding:0 4px 0 4px;">请稍等...</div>');
        return $('.ajaxLoadingFloat');
    } else {
        return ajaxLoadingFloat;
    }
};
//获取AJAX加载错误的信息
var getAjaxLoadErrorDivFloat = common.ajax.error = function(init) {
    var ajaxLoadErrorFloat = $('.ajaxLoadErrorFloat');
    if (!ajaxLoadErrorFloat.size() && init) {
        $('body').append('<div class="ajaxMessage ajaxLoadErrorFloat" style="display:none; background-color:white; position:absolute;z-index:1001; border:solid #333333 1px; padding:0 4px 0 4px;">加载错误</div>');
        return $('.ajaxLoadErrorFloat');
    } else {
        return ajaxLoadErrorFloat;
    }
};
//为了兼容旧版的showAjaxLoading()
var showAjaxLoadingFloat = showAjaxLoading = common.ajax.loading = function(ev) {
    $('.ajaxMessage:not(.ajaxLoadingGlobal)').hide();
    var coordinates = getMouseCoordinates(ev);
    common.ajax.message(true).show().css({ left: coordinates.x, top: coordinates.y + 20 });
};
//表单提交的时候，使按钮变灰同时显示为“请稍等...”，防止重复提交
common.form.loading = function(x) {
    if ($(this).attr('onsubmit'))
        return;
    var submitButton = $(this).find('input[@type=submit]');
    if (submitButton.size())
        submitButton.attr(common.constants.TAG_ATTR_SUBMIT_BUTTON_VALUE, submitButton.val())
			.val('稍等..').attr('disabled', 'disabled');
};
//表单提交失败的时候，使按钮取消变灰同时显示原来的value
common.form.cancel = function($form) {
    $form = $($form);
    var $submit = $form.find('input[@type=submit]');
    if ($submit.size() && $submit.attr(common.constants.TAG_ATTR_SUBMIT_BUTTON_VALUE)) {
        $submit.val($submit.attr(common.constants.TAG_ATTR_SUBMIT_BUTTON_VALUE))
			.removeAttr('disabled').removeAttr(common.constants.TAG_ATTR_SUBMIT_BUTTON_VALUE);
    }
};
//自动聚焦表单内的文本输入框和密码输入框
common.form.focus = function($form) {
    //todo 辨别不同的数据类型
    var $inputs = $form.find('input');
    var html = '';
    for (var i = 0; i < $inputs.size(); i++) {
        var $input = $inputs.eq(i);
        var t = $input.attr('type');
        if (t == 'text' || t == 'password') {
            if (!$.trim($input.val())) {
                $input.focus();
                break;
            }
        }
    }
};
//复制文字到粘贴板，对firefox和opera也生效
var copy2Clipboard = common.copy = function(text) {
    if (window.clipboardData) {
        window.clipboardData.setData("Text", text);
    } else {
        var $f = $("#flashcopier");
        $f.size() ? {} : $f = $('<div id="flashcopier" style="width:0;height:0;"></div>').appendTo('body');
        $f.html('<embed src="/Theme/Default/images/flashcopier.swf" FlashVars="clipboard=' + encodeURIComponent(text) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>');
    }
};
//修改ie6的一个bug，css的url(...)导致的背景图片的闪烁
if ($.browser.msie && $.browser.version / 1 == 6) {
    try {
        document.execCommand("BackgroundImageCache", false, true);
    } catch (e) { }
}
$(function() {
    //导航菜单的鼠标相关事件
    $('#nav .pull_down').mouseover(function(ev) {
        if ($(this).siblings('.menu:visible').size()) {
            $('.menu:visible').hide();
        } else {
            $('.menu:visible').not($(this).siblings('.menu').show()).hide();
        }
        $(this).blur();
        return false;
    }).add('#nav .word').mouseover(function() {
        var m = $(this).siblings('.menu');
        if ($('.menu:visible').size() && m.size())
            $('.menu:visible').not(m.show()).hide();
    });
    $('#nav .application .word').click(function(ev) {
        $(this).siblings('.pull_down').triggerHandler('click', ev);
        $(this).blur();
    });
    //使导航菜单不被<select/>覆盖
    $('.menu').bgiframe();
    //刷新验证码的超链接生效
    $('.verifyCodeLink').click(refreshVerifyCode);

    $(window).ajaxSuccess(function() {
        $('.ajaxMessage').hide();
    }).ajaxError(function() {
        var loadingDivFloat = common.ajax.message();
        var loadErrorDivFloat = getAjaxLoadErrorDivFloat(true);
        if (loadingDivFloat.size() && loadingDivFloat.css('display') != 'none')
            loadErrorDivFloat.show().css({ left: loadingDivFloat.css('left'), top: loadingDivFloat.css('top') });
        $('.ajaxMessage').not(loadErrorDivFloat).hide();
    }).ajaxStart(function() {
        $('.ajaxLoadingGlobal').show();
    }).ajaxComplete(function() {
        $('.ajaxLoadingGlobal').hide();
    });


    $('form').submit(common.form.loading);


    //登陆的时候返回本页
    $('#loginForm').submit(function() {
        var forwardUrl = $(this).find('input[@name=forwardUrl]');
        if (forwardUrl && forwardUrl.val() == 'javascript:location.href')
            forwardUrl.val(location.href);
        else if (forwardUrl && !forwardUrl.val())
            forwardUrl.val(location.href);
        //forwardUrl.val('/start/');
    });
    //输入框聚焦的时候选中其中的内容
    $('input[@type=text],input[@type=password]').focus(function() {
        this.select();
    });
    $(document).click(function() {
        //AJAX加载错误信息隐藏
        getAjaxLoadErrorDivFloat().hide();
        //隐藏导航菜单
        $('.menu:visible').hide();
    });
    showSysMsg(1);
    setInterval("showSysMsg(1);", 300000);
    $('#closebutton').click(function() { $('#showsysmsg1').notificationmsg('hide'); }); //通知关掉

});

//标题闪动器，usage: documentTitleTwinkler.twinkle('风清扬上线了');
var documentTitleTwinkler = {
    documentTitle: document.title,
    twinkleCount: 0,
    twinkleWords: '',
    setTimeoutHandler: null,
    runTimeout: function() {
        document.title = '[' + (this.twinkleCount % 2 == 0 ? '●' : '○') + this.twinkleWords + ']';
        if (this.twinkleCount++ <= 100) {
            this.setTimeoutHandler = window.setTimeout("documentTitleTwinkler.runTimeout()", this.speed);
        } else {
            document.title = this.documentTitle;
        }
    },
    twinkle: function(words, speed) {
        this.speed = speed ? speed : 500;
        this.twinkleWords = words;
        if (this.setTimeoutHandler) {
            clearTimeout(this.setTimeoutHandler);
        }
        this.runTimeout();
    }
};
var surnames = ["哀", "爱", "艾", "安",
			"昂", "奥", "敖", "巴", "把", "百", "白", "摆", "班", "半", "办", "板", "邦",
			"包", "鲍", "保", "暴", "宝", "豹", "堡", "北", "卑", "贝", "本", "贲", "闭",
			"毕", "边", "卞", "表", "别", "宾", "并", "邴", "伯", "博", "薄", "柏", "步",
			"布", "部", "卜", "才", "蔡", "藏", "仓", "苍", "操", "曹", "岑", "茶", "察",
			"柴", "镡", "唱", "常", "畅", "昌", "苌", "朝", "超", "巢", "晁", "车", "陈",
			"谌", "迟", "池", "崇", "种", "丑", "瘳", "出", "处", "初", "楚", "储", "揣",
			"啜", "钏", "淳", "慈", "从", "丛", "爨", "崔", "寸", "达", "笪", "代", "戴",
			"但", "淡", "党", "荡", "刀", "邓", "登", "底", "狄", "邸", "刁", "定", "丁",
			"东", "冻", "董", "斗", "窦", "堵", "杜", "督", "都", "段", "端", "对", "顿",
			"敦", "多", "朵", "鄂", "恩", "尔", "法", "凡", "范", "樊", "芳", "方", "房",
			"飞", "费", "封", "丰", "冯", "奉", "俸", "佛", "扶", "浮", "富", "福", "伏",
			"付", "复", "符", "傅", "甫", "苻", "尕", "改", "干", "甘", "淦", "刚", "冮",
			"高", "皋", "郜", "杲", "葛", "戈", "盖", "艮", "更", "耿", "庚", "工", "公",
			"弓", "宫", "贡", "巩", "龚", "勾", "苟", "缑", "古", "股", "鼓", "谷", "顾",
			"辜", "关", "管", "官", "灌", "冠", "贯", "光", "广", "归", "贵", "桂", "过",
			"国", "果", "郭", "呙", "虢", "哈", "海", "韩", "撖", "杭", "郝", "蒿", "和",
			"合", "河", "何", "贺", "赫", "横", "衡", "红", "洪", "后", "厚", "侯", "後",
			"户", "呼", "虎", "胡", "狐", "扈", "斛", "花", "化", "滑", "怀", "槐", "还",
			"宦", "桓", "郇", "黄", "皇", "回", "惠", "火", "霍", "及", "计", "季", "纪",
			"吉", "姬", "籍", "汲", "冀", "戢", "丌", "嵇", "暨", "蓟", "稽", "家", "加",
			"郏", "贾", "简", "蹇", "翦", "将", "江", "降", "姜", "蒋", "焦", "矫", "敫",
			"接", "节", "截", "揭", "介", "颉", "金", "晋", "靳", "井", "经", "敬", "景",
			"荆", "靖", "酒", "巨", "具", "剧", "居", "菊", "鞠", "隽", "卡", "开", "阚",
			"康", "亢", "可", "克", "柯", "孔", "寇", "库", "蒯", "郐", "旷", "匡", "邝",
			"奎", "夔", "蒉", "喇", "来", "赖", "蓝", "兰", "狼", "郎", "朗", "老", "劳",
			"乐", "勒", "雷", "冷", "里", "力", "立", "利", "历", "黎", "栗", "厉", "励",
			"郦", "连", "练", "梁", "谅", "廖", "辽", "蓼", "烈", "林", "凌", "留", "刘",
			"柳", "龙", "隆", "陇", "楼", "娄", "路", "鹿", "陆", "卢", "鲁", "芦", "禄",
			"逯", "栾", "伦", "罗", "洛", "雒", "吕", "马", "麻", "买", "麦", "满", "莽",
			"毛", "冒", "茆", "门", "蒙", "孟", "梦", "米", "宓", "糜", "弭", "苗", "缪",
			"闵", "明", "抹", "墨", "莫", "麽", "牟", "木", "母", "牧", "穆", "慕", "睦",
			"那", "纳", "乃", "南", "能", "倪", "尼", "聂", "乜", "宁", "甯", "牛", "钮",
			"农", "侬", "区", "欧", "怕", "盘", "潘", "泮", "庞", "逄", "裴", "蓬", "彭",
			"皮", "邳", "朴", "平", "屏", "繁", "番", "仆", "蒲", "莆", "浦", "普", "溥",
			"濮", "齐", "奇", "漆", "戚", "柒", "祁", "祈", "亓", "綦", "钱", "千", "乾",
			"黔", "骞", "强", "羌", "乔", "谯", "郄", "琴", "秦", "钦", "覃", "青", "庆",
			"卿", "求", "秋", "丘", "仇", "邱", "裘", "渠", "曲", "屈", "蘧", "璩", "麴",
			"瞿", "全", "权", "泉", "阙", "冉", "饶", "任", "容", "融", "荣", "戎", "汝",
			"茹", "阮", "瑞", "芮", "润", "撒", "洒", "萨", "赛", "三", "散", "桑", "森",
			"沙", "山", "闪", "煽", "陕", "鄯", "剡", "上", "尚", "商", "邵", "韶", "召",
			"蛇", "折", "厍", "佘", "申", "沈", "慎", "莘", "生", "盛", "是", "时", "石",
			"师", "史", "施", "世", "侍", "寿", "树", "束", "舒", "殳", "帅", "双", "水",
			"税", "舜", "思", "司", "斯", "松", "宋", "速", "宿", "苏", "粟", "随", "隋",
			"眭", "睢", "孙", "所", "塔", "太", "台", "邰", "谈", "潭", "谭", "檀", "郯",
			"澹", "汤", "唐", "桃", "陶", "腾", "滕", "同", "通", "统", "童", "仝", "钭",
			"土", "屠", "涂", "脱", "拓", "庹", "完", "万", "宛", "望", "王", "汪", "位",
			"卫", "危", "魏", "韦", "尉", "隗", "文", "闻", "温", "翁", "沃", "武", "伍",
			"吴", "吾", "乌", "毋", "巫", "仵", "邬", "西", "席", "锡", "习", "郗", "奚",
			"夏", "先", "线", "鲜", "咸", "羡", "冼", "向", "项", "香", "相", "萧", "肖",
			"筱", "写", "谢", "解", "信", "辛", "忻", "刑", "兴", "幸", "邢", "行", "熊",
			"修", "秀", "许", "须", "续", "徐", "绪", "胥", "玄", "宣", "轩", "禤", "学",
			"薛", "踅", "寻", "荀", "烟", "言", "严", "岩", "延", "颜", "阎", "燕", "郾",
			"鄢", "闫", "晏", "养", "羊", "仰", "扬", "杨", "阳", "要", "姚", "尧", "幺",
			"野", "叶", "冶", "邺", "以", "衣", "易", "乙", "益", "伊", "裔", "义", "弋",
			"印", "银", "阴", "尹", "殷", "应", "英", "嬴", "永", "雍", "由", "右", "游",
			"尤", "酉", "于", "鱼", "余", "遇", "虞", "俞", "禹", "宇", "郁", "喻", "庾",
			"蔚", "於", "远", "元", "原", "袁", "苑", "爰", "月", "越", "岳", "悦", "云",
			"恽", "贠", "宰", "昝", "臧", "曾", "查", "窄", "翟", "祭", "占", "战", "粘",
			"展", "詹", "湛", "张", "章", "掌", "仉", "招", "赵", "肇", "诏", "真", "阵",
			"甄", "郑", "支", "职", "植", "智", "郅", "钟", "终", "衷", "仲", "周", "舟",
			"竹", "朱", "诸", "祝", "褚", "竺", "术", "颛", "卓", "禚", "字", "资", "訾",
			"纵", "宗", "邹", "祖", "尊", "左", "欧阳", "上官", "皇甫", "令狐", "诸葛", "端木",
			"司徒", "申屠", "颛孙", "夏侯", "司马", "宇文", "东方", "公冶", "东野", "闻人", "太史",
			"慕容", "呼延", "完颜", "西门", "梁丘", "轩辕", "相里", "公孙", "尔朱", "濮阳", "贯丘",
			"独孤", "万俟", "叱干", "李", "田"];



function $$(id) {
    return document.getElementById(id);
}

function showSysMsg(systype) 
{
  
  $.get("/Ajax/Comm/GetSysMsg.aspx", { action: "SysMsg", systype: systype },
  function(data) {
    if (data != 0) {
          ShowMsgDiv(data);
      }
  });

}

function ShowMsgDiv(msg) {
    $("#modalbody").html(msg);
    //$('#showsysmsg1').notificationmsg({ animation: "slide" });
    //$('#showsysmsg1').notificationmsg('show');
    documentTitleTwinkler.twinkle($("#modalbody").text(),500);
}

function showreward(systype) {

    $.get("/Ajax/Comm/Getreward.aspx", { action: "getreward", systype: systype },
  function(data) {
      if (data) {
          msgwin(data, 4000);
      }
  });

}

function msgwin(s, t) {

    var msgWinObj = $$('msgwin');
    if (!msgWinObj) {
        var msgWinObj = document.createElement("div");
        msgWinObj.id = 'msgwin';
        msgWinObj.style.display = 'none';
        msgWinObj.style.position = 'absolute';
        msgWinObj.style.zIndex = '999999';
        $$('append_parent').appendChild(msgWinObj);
    }
    msgWinObj.innerHTML = s;
    msgWinObj.style.display = '';
    msgWinObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
    msgWinObj.style.opacity = 0;
    var sTop = document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
    pbegin = sTop + (document.documentElement.clientHeight / 4);
    pend = sTop + (document.documentElement.clientHeight / 9);
    setTimeout(function() { showmsgwin(pbegin, pend, 0, t) }, 10);
    msgWinObj.style.left = ((document.documentElement.clientWidth - msgWinObj.clientWidth) / 5) + 'px';
    msgWinObj.style.top = pbegin + 'px';
}

function showmsgwin(b, e, a, t) {
    step = (b - e) / 10;
    var msgWinObj = $$('msgwin');
    newp = (parseInt(msgWinObj.style.top) - step);
    if (newp > e) {
        msgWinObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + a + ')';
        msgWinObj.style.opacity = a / 100;
        msgWinObj.style.top = newp + 'px';
        setTimeout(function() { showmsgwin(b, e, a += 10, t) }, 10);
    } else {
        msgWinObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
        msgWinObj.style.opacity = 1;
        setTimeout('displayOpacity(\'msgwin\', 100)', t);
    }
}

function displayOpacity(id, n) {
    if (!$$(id)) {
        return;
    }
    if (n >= 0) {
        n -= 10;
        $$(id).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + n + ')';
        $$(id).style.opacity = n / 100;
        setTimeout('displayOpacity(\'' + id + '\',' + n + ')', 50);
    } else {
        $$(id).style.display = 'none';
        $$(id).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
        $$(id).style.opacity = 1;
    }
}

function display(id) {
    var obj = $$(id);
    obj.style.display = obj.style.display == '' ? 'none' : '';
}
