﻿// 用来显示数据中新闻链接
// 用来做新产品结构式的显示
// 注册命名空间Grandsoft.GEA, Grandsoft.GCM
Namespace.register("ZhuFly.Corp");
// 在Grandsoft.GEA命名空间里面声明类NewStruct
// 工作类
var gCropNews = null ;
ZhuFly.Corp.CorpNews = function(iCapacity, url)
{
   // 一页能够显示的新闻条数，最大10条
   this.iCapacity = iCapacity ;
   // 获取新闻的URL
   this.url = url;
   // 同步对象
   this.ajaxObj = null ;
   // 返回了多少条企业新闻
   this.iRetCnt = 0 ;
}

ZhuFly.Corp.CorpNews.prototype.callServer = function(callBackFun)
{
   if (this.ajaxObj == null)
   {
      alert("同步对象，初始化失败");
      return null;
   }
   this.ajaxObj.open( "get", this.url + "&time="+(new Date()).getTime(), true );
   this.ajaxObj.setRequestHeader("Cache-Control","no-cache"); 
   this.ajaxObj.onreadystatechange = callBackFun;
   this.ajaxObj.send( null );
}

ZhuFly.Corp.CorpNews.prototype.CreateAjax = function()
{
   this.ajaxObj  = CreatAjaxObj();
   if (null == this.ajaxObj )
   {
      alert( "Error initializing ZhuFly.GEA.NewStruct.ajaxObj HttpRequest!" );
   }
}

function IniCropNewsTitle()
{
   gCropNews = new ZhuFly.Corp.CorpNews(10, "CropNews.ashx?onlyTitle=true");
   if (gCropNews == null)
   {
      alert("memory failed!");
   }
   gCropNews.CreateAjax();
   gCropNews.callServer(NewsTitleReadly);
}
function NewsTitleReadly()
{
   if ( gCropNews.ajaxObj.readyState == 4 )
   {
      if( gCropNews.ajaxObj.status == 200 )
      {
         try
         {
            var xmlResponse = gCropNews.ajaxObj.responseXML;
            gCropNews.iRetCnt = xmlResponse.getElementsByTagName( "recCnt" )[0].firstChild.nodeValue;
            var sRightHtml = "<ul>" ;
            var sTitle = "";
            var sNID = "" ;
            for (newsIndex = 0 ; newsIndex < gCropNews.iRetCnt ;
            newsIndex ++ )
            {
               sTitle  = xmlResponse.getElementsByTagName( "NewsTitle" )[newsIndex].firstChild.nodeValue;
               sNID    = xmlResponse.getElementsByTagName( "nID" )[newsIndex].firstChild.nodeValue;
               sRightHtml +=  "<li > <a href='CropNewsDetail.shtml?nID=" + sNID +"' target=‘_blank’ >" + sTitle + "</a></li>";
            }
            sRightHtml += "</ul>";
            setInnerHTML(document.getElementById("nNewsTitle"), sRightHtml);
//             sRightHtml = xmlResponse.getElementsByTagName( "Contractus" )[0].firstChild.nodeValue;
//             setInnerHTML(document.getElementById("rContractus"), sRightHtml)
         }
         catch(failed)
         {
            //alert(failed.name + failed.description );
         }
      }
      else  // 超时处理，
      {
         //alert("服务超时，请稍后重试！");
      }
   }
}

// window.onload = function()
// {
//     IniCropNewsTitle();
// }