﻿var pool = new AjaxPool(ajaxFactory);
var sector;
function Sector()
{
    this.listElement = document.getElementById('Div_SonMenuSector');
}

function StartSector()
{
    sector = new Sector();
    
    if(sector.listElement.innerHTML == '')
        sector.Request();
}

Sector.prototype.Request = function()
{
    var ajax = pool.borrowAjax(this.CallBack, this.Faild);
    var rpURL = 'http://www.meihua.info/stat/actionpage/GetSector.aspx';
    sector.listElement.innerHTML = '';
    ajax.elementLoad = sector.listElement;
    ajax.go(rpURL, 'GET', null);
}

Sector.prototype.CallBack = function(sender)
{
    var xmlDoc = sender.req.responseXML;
    var msg = xmlDoc.selectSingleNode('MeihuaNet/Message').text;
    
    if(msg == "OK")
    {
        var fNodes = xmlDoc.selectNodes('MeihuaNet/FirstSector');
        
        var allCount, rowCount;
        allCount = fNodes.length;
        rowCount = Math.floor(allCount / 3 + (allCount % 3 == 0 ? 0 : 1));
            
        var html = '';
        
        html += '<table width="100%" border="0" cellspacing="5" cellpadding="0">';
        
        if (allCount > 0)
        {
            var index = 0;
            for(var i=0;i<rowCount;i++)
            {
                html += '<tr>';
                for(var j=0;j<3;j++)
                {
                    var width = "33%";

                    if(j==1)
                        width = "34%";

                    html += '<td width="' + width + '">';

                    index = i * 3 + j;
                    if (index >= allCount)
                    {
                        html += '<td>&nbsp;</td>';
                    }
                    else
                    {
                        var sectorID = fNodes[index].selectSingleNode('SectorID').text;
                        var sectorName = fNodes[index].selectSingleNode('SectorName').text;
                        
                        //html += '<a href="http://www.meihua.info/stat/actionpage/QuerySearch.aspx?sectorID=' + sectorID + '&sectorName=' + encodeURIComponent(sectorName) + '" class="BlankLink">' + sectorName + '</a>';
                        html += '<a href="http://www.meihua.info/stat/ListView.aspx?type=2&cType=1&sectorID=' + sectorID + '&sectorName=' + encodeURIComponent(sectorName) + '" class="BlankLink">' + sectorName + '</a>';
                    }

                    html += '</td>';
                }
                html += '</tr>';
            }
        }
        else
        {
            html += '<tr>';
            html += '<td>暂无数据</td>';
            html += '</tr>';
        }
        
        html += '</table>';
        
        if(sector.listElement == null)
        {
            sector.listElement = document.getElementById('Div_SonMenuSector');
        }
        
        try
        {
            sector.listElement.innerHTML = html;
        }
        catch(e)
        {
            $('#Div_SonMenuSector').html(html);
        }
    }
    else
    {
        alert('错误的操作，请重试！');
    }
}

var left2 = 0;
function ShowSectorDiv(divID)
{
	var obj = document.getElementById(divID);
	obj.style.display = 'block';
	
	if(left2 == 0)
	    left2 = obj.offsetLeft;
	obj.style.left = left2;
	
	StartSector();
}
