﻿var announceHeight = 450;
var announceWidth = 595;

$(document).ready(function(){
    $(".lnkAnnounce").each(function(){
        $(this).click(function(){
            var aid = $(this).attr("id").substr(11);
            loadAnnounce(aid);
            return false;
        });
    });
    
    $(document).click(function(e){
        if($("#AnnounceArea").length==0) return;        
        var isClickDiv = false;
        if($.browser.mozilla){
            if(e.originalTarget!=null){
                if(e.originalTarget.id=="AnnounceArea") isClickDiv = true;
                if(ContrastChildTarget($("#AnnounceArea").children(),e.originalTarget)) isClickDiv = true;
            }
        }
        else{
            if (e.target) targ = e.target
            else if (e.srcElement) targ = e.srcElement
            if (targ.nodeType == 3) 
            targ = targ.parentNode
            if(targ!=null){
                if(targ.id=="AnnounceArea") isClickDiv = true;
                if(ContrastChildTarget($("#AnnounceArea").children(),targ)) isClickDiv = true;
            }
        }
        if(!isClickDiv) removeAnnounce();
    });
    $(document).keydown(function(event){
        if(event.keyCode==27) {
            if($("#AnnounceArea").length==0) return;
            removeAnnounce();
        }
    });
    $(window).resize(function(){
        announceSetPoint();
    });
    $(window).scroll(function(){
        announceSetPoint();
    });
});

//设置公告显示位置
function announceSetPoint()
{
    if( $("#AnnounceArea").length==0) return;
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
    var scollX = de.scrollLeft;
    var scollY = de.scrollTop;    
    
    if((w-announceWidth)>0) areaX=(w-announceWidth)/2;
    if((h-announceHeight)>0) areaY=(h-announceHeight)/2;
    
    $("#AnnounceArea").css("left",areaX+scollX+"px");
    $("#AnnounceArea").css("top",areaY+scollY+"px"); 
}

//异步获取公告内容
function loadAnnounce(aid)
{
    if( $("#AnnounceArea").length!=0) removeAnnounce();
    
    $("body").append("<div id='AnnounceArea' style='width:"+announceWidth+"px;height:"+announceHeight+"px;position:absolute;display:none;background-color:#ffffff;z-index:999;'></div>");
    $("#AnnounceArea").append(strAnnounce);   
    announceSetPoint();
    
    V3.ID.BAGASite.WService.DataSubmit.GetAnnounce(aid,function(result){
        $("#announceTitle").html(result.AnnounceTitle);
        $("#announceContent").html(result.AnnounceContent); 
        $("#announceDate").html(result.AddDateTime.format("yyyy-MM-dd")); 
           
        $("#AnnounceArea").show();
    },function(){});
}

//移除显示的公告
function removeAnnounce()
{
    $("#AnnounceArea").remove();
}

var strAnnounce = '<table width="595" border="0" cellspacing="0" cellpadding="0" style="font-size: 12px;">';
strAnnounce += '  <tr><td height="7" background="/images/zhuce/bg_01.gif"></td></tr>';
strAnnounce += '  <tr><td height="219" align="center" valign="top" background="/images/zhuce/bg_02.gif">';
strAnnounce += '    <table width="590" border="0" cellspacing="0" cellpadding="0">';
strAnnounce += '      <tr><td height="30" align="center" valign="bottom" class="green14_cuo" id="announceTitle" style="padding:5px;font-size:22px;"></td></tr>';
strAnnounce += '      <tr><td align="left" valign="top"><div style="padding:10px; width:565px; height:400px; overflow-x:hidden; overflow-y:auto; white-space:normal;" id="announceContent"></div></td></tr>';
strAnnounce += '    </table></td></tr>';
strAnnounce += '  <tr><td height="28" background="/images/zhuce/bg_03.gif" align="right">发布日期：<span id="announceDate" style="padding-right:10px;"></span></td></tr></table>';
