﻿// JScript 文件


var readerID = '1';

//初始化首页
function indexInit()
{
    newsListInit();
    loginMenu();
    noticeListInit();
    scienceKnowledgeInit();
    policyRuleInit();
    administrationNoticeMenuInit();
    administrationNoticeInit(25,0);
    directionListInit();
    fouceList();
    LinkWebSiteInit();
    programmeShowInit();
}
//获得首页新闻全景的文章列表
function newsListInit()
{
    var data = AjaxClass.GetNewsList_Pre(readerID);
    if(data.value)
    {
        setTbody_threeCell(data,17,"newsList","../images/but3.jpg",2,"15px","270px");
    }
}
//获得首页科普常识的文章列表
function scienceKnowledgeInit()
{
    var data = AjaxClass.GetScienceKnowledgeList_Pre(readerID);
    if(data.value)
    {
        setTbody_threeCell(data,12,"scienceKnowledge","../images/but1.jpg",0,"15px","170px");
    }
}
//获得首页政策法规的文章列表
function policyRuleInit()
{
    var data = AjaxClass.GetPolicyRuleList_Pre(readerID);
    if(data.value)
    {
        setTbody_threeCell(data,17,"policyRule","../images/but1.jpg",0,"15px","255px");
    }
}
//获得行政公示的菜单
function administrationNoticeMenuInit()
{
    var data = AjaxClass.GetMenu(24);
    var row = document.createElement("tr");
    if(document.uniqueID)//IE浏览器
    {
        row.style.cssText = "width:460px;";
    }
    else//其他浏览器
    {
       row.setAttribute("style","width:460px;");
    }  
    var cell=null,img=null,nodeId,a=null; 
    for(var i=0;i<data.value.Tables[0].Rows.length;i++)
    {
        cell = document.createElement("td");
//        if(document.uniqueID)//IE浏览器
//        {
//            cell.style.cssText = "width: 115px;";
//        }
//        else//其他浏览器
//        {
//           cell.setAttribute("style","width: 115px;");
//        }
        cell.setAttribute("align","center");

        img = document.createElement("img");
        img.setAttribute("id","administrationNotice"+i);
        img.setAttribute("src","../images/index1_0"+i+".jpg");
        img.setAttribute("width","115px");
        if(document.uniqueID)
        {
            img.style.cssText = "cursor: hand;";   
        }
        else
        {
            img.setAttribute("style","cursor: hand;");
        }
        img.onclick = new Function("administrationNoticeInit("+data.value.Tables[0].Rows[i].nodeId+","+i+")");
        cell.appendChild(img);
        row.appendChild(cell);
    }
    cell = document.createElement("td");
    if(document.uniqueID)//IE浏览器
    {
        cell.style.cssText = "width: 200px;";
    }
    else//其他浏览器
    {
       cell.setAttribute("style","width: 200px;");
    }
    cell.setAttribute("align","right");
    a = document.createElement("a");
    a.setAttribute("id","administrationNotice_More");
    if(document.uniqueID)//IE浏览器
    {
        a.style.cssText = "color:White";
    }
    else//其他浏览器
    {
       a.setAttribute("style","color:White");
    }
    a.appendChild(document.createTextNode("更多..."));
    cell.appendChild(a);
    row.appendChild(cell);

    document.getElementById("administrationNoticeMenu").appendChild(row);
    
}
//获得首页行政公示的文章列表
//2009-06-12 lmz 去掉执法公示栏目
function administrationNoticeInit(nodeId,num)
{
    switch(num)
    {
        case 0:
            document.getElementById('administrationNotice0').setAttribute("src",'../images/index2_00.jpg');
            document.getElementById('administrationNotice1').setAttribute("src",'../images/index1_01.jpg');
            document.getElementById('administrationNotice2').setAttribute("src",'../images/index1_02.jpg');
           document.getElementById('administrationNotice3').setAttribute("src",'../images/index1_03.jpg');
        break;
        case 1:
            document.getElementById('administrationNotice0').src='../images/index1_00.jpg';
            document.getElementById('administrationNotice1').src='../images/index2_01.jpg';
            document.getElementById('administrationNotice2').src='../images/index1_02.jpg';
          document.getElementById('administrationNotice3').src='../images/index1_03.jpg';
        break;
        case 2:
            document.getElementById('administrationNotice0').src='../images/index1_00.jpg';
            document.getElementById('administrationNotice1').src='../images/index1_01.jpg';
            document.getElementById('administrationNotice2').src='../images/index2_02.jpg';
           document.getElementById('administrationNotice3').src='../images/index1_03.jpg';
        break;
        case 3:
            document.getElementById('administrationNotice0').src='../images/index1_00.jpg';
            document.getElementById('administrationNotice1').src='../images/index1_01.jpg';
            document.getElementById('administrationNotice2').src='../images/index1_02.jpg';
          document.getElementById('administrationNotice3').src='../images/index2_03.jpg';
        break;

    }
    document.getElementById("administrationNotice_More").setAttribute("href","../about/about.aspx?type=24&id="+nodeId);
    var data = AjaxClass.GetAdministrationNoticeList_Pre(nodeId,readerID);
    if(document.getElementById("administrationNotice").hasChildNodes())
    {
        var count = document.getElementById("administrationNotice").childNodes.length;
        for(var i=0;i<count;i++)
        {
            document.getElementById("administrationNotice").removeChild(document.getElementById("administrationNotice").childNodes[0]);
        }
    }
    if(data.value)
    {
        setTbody_threeCell(data,31,"administrationNotice","../images/but3.jpg",1,"15px","465px");
    }
}
//获得首页公告信息的文章列表
function noticeListInit()
{
    var data = AjaxClass.GetNoticeList_Pre(readerID);
    if(data.value)
    {
        setTbody_threeCell(data,8,"noticeList","../images/but1.jpg",1,"15px","105px");
    }
}
    //登陆菜单
    function loginMenu()
    {
        var row = null,cell=null,control=null;
        //设置第一行
        row = document.createElement("tr");
        cell = document.createElement("td");
        if(document.uniqueID)//IE浏览器
        {
            cell.setAttribute("colSpan", '2');
        }
        else//其他浏览器
        {
            cell.setAttribute("colspan", '2');
        }     
        cell.setAttribute("align", "left");
        
        control = document.createElement("img");
        if(document.uniqueID)//IE浏览器
        {
            control.style.cssText = "width:199px;";
        }
        else//其他浏览器
        {
           control.setAttribute("style","width:199px;");
        }  

        control.setAttribute("src","../images/login/login_01.gif");
        cell.appendChild(control);
        row.appendChild(cell);
        document.getElementById('Login').appendChild(row);      
        
        //设置第二行
        //第一个单元格
        row = document.createElement("tr");
        if(document.uniqueID)//IE浏览器
        {
            row.style.cssText = "height:25px;";
        }
        else//其他浏览器
        {
           row.setAttribute("style","height:25px;");
        }  
        cell = document.createElement("td");
        cell.appendChild(document.createTextNode("用 户："));
        cell.setAttribute("align", "right");
        if(document.uniqueID)//IE浏览器
        {
            cell.style.cssText = "width:80px;";
        }
        else//其他浏览器
        {
           cell.setAttribute("style","width:80px;");
        }        
        row.appendChild(cell);
        //第二个单元格
        cell = document.createElement("td");
        control = document.createElement("input");
        control.setAttribute("id","Text_username");
        control.setAttribute("type","text");
        if(document.uniqueID)//IE浏览器
        {
            control.style.cssText = "width:100px;";
        }
        else//其他浏览器
        {
           control.setAttribute("style","width:100px;");
        }
        cell.appendChild(control);
        cell.setAttribute("align", "left");
        row.appendChild(cell);
        document.getElementById('Login').appendChild(row); 
        //设置第三行
        //第一个单元格
        row = document.createElement("tr");
        if(document.uniqueID)//IE浏览器
        {
            row.style.cssText = "height:25px;";
        }
        else//其他浏览器
        {
           row.setAttribute("style","height:25px;");
        }  
        cell = document.createElement("td");
        cell.appendChild(document.createTextNode("密 码："));
        cell.setAttribute("align", "right");
        if(document.uniqueID)//IE浏览器
        {
            cell.style.cssText = "width:80px;";
        }
        else//其他浏览器
        {
           cell.setAttribute("style","width:80px;");
        }        
        row.appendChild(cell);
        //第二个单元格
        cell = document.createElement("td");
        control = document.createElement("input");
        control.setAttribute("id","Password");
        control.setAttribute("type","password");
        if(document.uniqueID)//IE浏览器
        {
            control.style.cssText = "width:100px;";
        }
        else//其他浏览器
        {
           control.setAttribute("style","width:100px;");
        }
        cell.appendChild(control);
        cell.setAttribute("align", "left");
        row.appendChild(cell);
        document.getElementById('Login').appendChild(row);
        
        //设置第四行
        row = document.createElement("tr");
        if(document.uniqueID)//IE浏览器
        {
            row.style.cssText = "height:30px;";
        }
        else//其他浏览器
        {
           row.setAttribute("style","height:30px;");
        }  
        cell = document.createElement("td");
        if(document.uniqueID)//IE浏览器
        {
            cell.setAttribute("colSpan", '2');
        }
        else//其他浏览器
        {
            cell.setAttribute("colspan", '2');
        }     
        cell.setAttribute("align", "center");
        if(document.uniqueID)//IE浏览器
        {
            cell.style.cssText = "width:180px;";
        }
        else//其他浏览器
        {
           cell.setAttribute("style","width:180px;");
        }  
        control = document.createElement("img");
        control.setAttribute("src","../images/login/submit.jpg");
        if(document.uniqueID)
        {
            control.style.cssText = "cursor: hand;";   
        }
        else
        {
            control.setAttribute("style","cursor: hand;");
        }
        control.onclick = function(){ login(); };
        cell.appendChild(control);
        row.appendChild(cell);
        document.getElementById('Login').appendChild(row);

    }
    //登陆
    function login()
    {
        var username = document.getElementById('Text_username').value;
        var pw = document.getElementById('Password').value;
        if(username != '' && pw != '')
        {
            var result = AjaxClass.Login(username,pw);
            if(result.value)
            {
                window.location.href = "../VIP/Default.aspx";
            }
            else
            {
                alert('该用户不存在！');
            }
        }
        else
        {
            alert('请输入用户名或密码！');
        }
    }
    //获得首页办事指南的文章列表
    function directionListInit()
    {
        var data = AjaxClass.GetDirectionList_Pre(readerID);
        if(data.value)
        {
            setTbody_threeCell(data,12,"directionList","../images/but2.jpg",0,"15px","170px");
        }
    }
    //获得首页关注热点的文章列表
    function fouceList()
    {
        var data = AjaxClass.GetFouceList_Pre(readerID);
        if(data.value)
        {
            setTbody_threeCell(data,18,"fouce","../images/but1.jpg",0,"15px","250px");
        }
    }
    //获得首页友情链接
    function LinkWebSiteInit()
    {
        var data = AjaxClass.GetLinkWebSiteList_Pre();
        if(data.value)
        {
            var row=null,cell=null,select1=null,select2=null,select3=null;     
            
            //设置第一个下拉式菜单
            select1 = document.createElement("select");
            select1.setAttribute("id","Select_Goverment");
            select1.onchange = function() { LinkUrl(this.value); };
            if(document.uniqueID)
            {
                select1.style.cssText = "width:180px;";
            }
            else
            {
                select1.setAttribute("style","width:180px;");
            }
            //设置第二个下拉式菜单
            select2 = document.createElement("select");
            select2.setAttribute("id","Select_Design");
            select2.onchange = function() { LinkUrl(this.value); };
            if(document.uniqueID)
            {
                select2.style.cssText = "width:180px;";
            }
            else
            {
                select2.setAttribute("style","width:180px;");
            }
            //设置第三个下拉式菜单
            select3 = document.createElement("select");
            select3.setAttribute("id","Select_Other");
            select3.onchange = function() { LinkUrl(this.value); };
            if(document.uniqueID)
            {
                select3.style.cssText = "width:180px;";
            }
            else
            {
                select3.setAttribute("style","width:180px;");
            }
            
            
            for(var i=0;i<data.value.Tables[0].Rows.length;i++)
            {
                //获得选项
                if(data.value.Tables[0].Rows[i].nodeId == "65")
                {
                      if(!select1.hasChildNodes())
                      {
                            select1.appendChild(createOption("","*****" + data.value.Tables[0].Rows[i].name + "*****"));
                      }
                      select1.appendChild(createOption(data.value.Tables[0].Rows[i].Url,data.value.Tables[0].Rows[i].title));
                }
                else if (data.value.Tables[0].Rows[i].nodeId == "66")
                {
                      if(!select2.hasChildNodes())
                      {
                            select2.appendChild(createOption("","*****" + data.value.Tables[0].Rows[i].name + "*****"));
                      }
                      select2.appendChild(createOption(data.value.Tables[0].Rows[i].Url,data.value.Tables[0].Rows[i].title));
                }
                else if(data.value.Tables[0].Rows[i].nodeId == "67")
                {
                      if(!select3.hasChildNodes())
                      {
                            select3.appendChild(createOption("","*****" + data.value.Tables[0].Rows[i].name + "*****"));
                      }
                      select3.appendChild(createOption(data.value.Tables[0].Rows[i].Url,data.value.Tables[0].Rows[i].title));
                }
            }
            //设置第一行
            row = document.createElement("tr");
            if(document.uniqueID)//IE浏览器
            {
                row.style.cssText = "height:35px;";
            }
            else//其他浏览器
            {
               row.setAttribute("style","height:35px;");
            }  
            cell = document.createElement("td");
            cell.setAttribute("align","center");
            cell.appendChild(select1);
            row.appendChild(cell);
            document.getElementById("LinkWebSite").appendChild(row);
            //设置第二行
            row = document.createElement("tr");
            if(document.uniqueID)//IE浏览器
            {
                row.style.cssText = "height:35px;";
            }
            else//其他浏览器
            {
               row.setAttribute("style","height:35px;");
            }  
            cell = document.createElement("td");
            cell.setAttribute("align","center");
            cell.appendChild(select2);
            row.appendChild(cell);
            document.getElementById("LinkWebSite").appendChild(row);
            //设置第三行
            row = document.createElement("tr");
            if(document.uniqueID)//IE浏览器
            {
                row.style.cssText = "height:35px;";
            }
            else//其他浏览器
            {
               row.setAttribute("style","height:35px;");
            }  
            cell = document.createElement("td");
            cell.setAttribute("align","center");
            cell.appendChild(select3);
            row.appendChild(cell);
            document.getElementById("LinkWebSite").appendChild(row);
        }

   }
   //设置option项
   function createOption(Url,title)
   {
      var option = document.createElement("option");
      option.setAttribute("value",Url);
      option.appendChild(document.createTextNode(title));
      return option
   }
   //链接
   function LinkUrl(url)
   {
        if(url != '')
        {
            window.open(url);
        }
   }
   //日期格式
   function getDateTime(datetime,type)
   {
       var y,m,d;
       y = datetime.substring(0,datetime.indexOf('年'));
       m = datetime.substring(datetime.indexOf('年')+1,datetime.indexOf('月')).toString('00');
       d = datetime.substring(datetime.indexOf('月')+1,datetime.indexOf('日')).toString('00');
       
       if( m.length < 2)
       {
           m = '0' + m;
       }
       if(d.length < 2)
       {
           d = '0' + d;
       }
       
       if(type == 1)
       {
           return '[' + y + '-' + m + '-' + d + ']';
       }
       else if(type == 2)
       {
           return '[' + m + '-' + d + ']';
       }

   }
   //设置文本单元
   function createCellWithText(text,linkUrl,titletext) 
   {
        var cell = document.createElement("td");
        var link = document.createElement("a");
        link.setAttribute("href",linkUrl);
        link.setAttribute("target","_blank");
        link.setAttribute("title",titletext);
        link.appendChild(document.createTextNode(text));
        cell.appendChild(link);
        return cell;
    }
    //设置图片单元
    function createCellWithPicture(pictureUrl)
    {
        var cell = document.createElement("td");
        var img = document.createElement("img");
        img.setAttribute("src",pictureUrl);
        cell.appendChild(img);
        return cell;
    }
    //设置时间单元
    function createCellWithTime(datetime)
    {
        var cell = document.createElement("td");
        cell.appendChild(document.createTextNode(datetime));
        return cell;
    }
    //设置图片行
    function createCellWithBackground(lineUrl)
    {
        var cell = document.createElement("td");
        return cell;
    }
    /*设置信息浏览
    data:数据源
    textCount:每条现实的字数，多用...代替
    controlId:用于显示该信息的元素ID
    cellWidth1:第一个单元格的宽度
    cellWidth2:第二个单元格的宽度
    pictureUrl:第一个单元格显示图片的地址
    type:显示时间的格式,同时根据时间格式来判断单元格个数
    */
    function setTbody_threeCell(data,textCount,controlId,pictureUrl,type,cellWidth1,cellWidth2)
    {
        var row = null;
        if(data.value.Tables[0].Rows.length >0)
        {
            for(var i=0;i<data.value.Tables[0].Rows.length;i++)
            {
                row = document.createElement("tr");   
                if(document.uniqueID)//IE浏览器
                {
                    row.style.cssText = "height:10px;";
                }
                else//其他浏览器
                {
                   row.setAttribute("style","height:10px;");
                }                
                var text;
                if(data.value.Tables[0].Rows[i].title.length > textCount)
                {
                    text = data.value.Tables[0].Rows[i].title.substring(0,textCount) + "...";
                }
                else
                {
                    text = data.value.Tables[0].Rows[i].title;
                }
                var linkUrl = "../read/ReadInfo.aspx?id=" + data.value.Tables[0].Rows[i].id;
                var titletext = data.value.Tables[0].Rows[i].title;
                var lineUrl = "../images/line1.jpg";
                if(type == 2)
                {
                    text = "[" + data.value.Tables[0].Rows[i].name + "] " + text;
                }
                //每一个信息有两行组成，第一行为信息，第二行为横杠
                var cell1 = createCellWithPicture(pictureUrl);//设置第一行第一个单元格
                var cell2 = createCellWithText(text,linkUrl,titletext);//设置第一行第二个单元格
                var cell3;
                if(type != 0)
                {
                   if(data.value.Tables[0].Rows[i].nodeId != 26 && data.value.Tables[0].Rows[i].nodeId != 27)
                   {
                       var datetime = getDateTime(data.value.Tables[0].Rows[i].setDatetime.toLocaleString(),type);
                       cell3 = createCellWithTime(datetime);//设置第一行第三个单元格
                   }
                }
                if(document.uniqueID)//IE浏览器
                {
                    cell1.style.cssText = "width:"+cellWidth1+";";
                    cell1.setAttribute("align","center");
                    cell2.style.cssText = "width:"+cellWidth2+";";
                }
                else//其他浏览器
                {
                   cell1.setAttribute("style","width:"+cellWidth1+";");
                   cell1.setAttribute("align","center");
//                   cell2.setAttribute("style","width:"+cellWidth2+";");
                }
                row.appendChild(cell1);
                row.appendChild(cell2);
                if(type != 0)
                {
                    if(data.value.Tables[0].Rows[i].nodeId != 26 && data.value.Tables[0].Rows[i].nodeId != 27)
                    {
                        row.appendChild(cell3);
                    }
                }
                document.getElementById(controlId).appendChild(row);
                //设置第二行
                var lineRow = document.createElement("tr");
                var lineCell1 = createCellWithBackground(lineUrl);//设置第二行第一个单元格
                var lineCell2 = createCellWithBackground(lineUrl);//设置第二行第二个单元格
                var lineCell3;
                if(type != 0)
                {
                    lineCell3 = createCellWithBackground(lineUrl);//设置第二行第三个单元格
                }
                lineRow.appendChild(lineCell1);
                lineRow.appendChild(lineCell2);
                if(type != 0)
                {
                    lineRow.appendChild(lineCell3);
                }
                if(document.uniqueID)//IE浏览器
                {
                    lineRow.style.cssText = "background-image: url("+lineUrl+"); background-repeat: repeat-x; height:10px;";
                }
                else//其他浏览器
                {
                   lineRow.setAttribute("style","background-image: url("+lineUrl+"); background-repeat: repeat-x; height:10px;");
                }
                document.getElementById(controlId).appendChild(lineRow);
            }
        }
    }
    //获得规划展示
    function programmeShowInit()
    {
        var data = AjaxClass.GetProgrammeShowList(readerID);
        var row=null,cell=null,img=null,a=null;
        if(data.value)
        {
            if(data.value.Tables[0].Rows.length >0)
            {
                row = document.createElement("tr");
                for(var i=0;i<data.value.Tables[0].Rows.length;i++)
                {
                    cell = document.createElement("td");
                    img = document.createElement("img");
                    img.setAttribute("src","../../ManagementWeb"+data.value.Tables[0].Rows[i].contentAccessoryUrl);
                    img.setAttribute("title",data.value.Tables[0].Rows[i].title);
                    if(document.uniqueID)
                    {
                        img.style.cssText = "width:150px; height:101px; vertical-align:middle; cursor: hand;";   
                    }
                    else
                    {
                        img.setAttribute("style","width:150px; height:101px; vertical-align:middle; cursor: hand;");
                    }
                    img.onclick = new Function("readProgrammeShow(" + data.value.Tables[0].Rows[i].id + ")");
                    cell.appendChild(img);
                    row.appendChild(cell);
                }
                document.getElementById("programmeShow").appendChild(row);
            }

        }
    }
    //阅读规划展示详细信息
    function readProgrammeShow(id)
    {
        window.open("../read/ReadInfo.aspx?id="+id);
    }
    