Type.registerNamespace("Portal");
Type.registerNamespace("Portal.NewsChannel");

Portal.NewsChannel.NewsPanel = function(element)
{
    
    Portal.NewsChannel.NewsPanel.initializeBase(this,[element]);
    
    this._category = "";
    this._categoryDisplayName = "";
    
    this._categoryURL = "";
    this._topHeadlineCount = 1;
    this._summarySuccessDelegate = null;
    this._summaryFailureDelegate = null;
}

Portal.NewsChannel.NewsPanel.prototype = 
{
       
       initialize: function()
       {
           this.get_element().innerHTML = "<table width='100%' cellpadding='0' cellspacing='0'>"+
                 "<tr><td style='border-bottom:solid 0px #000000;font-size:14px;font-weight:bold'>"+strMore+" "+strNews+"</td></tr>" +
                 "<tr><td id='HeadlineDiv'>  <ul id='HeadlinesList'></ul></div> </td></tr></table>";
                 
           if(this._summarySuccessDelegate === null)
            this._summarySuccessDelegate = Function.createDelegate(this, this._summarySuccess);
        
            if(this._summaryFailureDelegate === null)
            this._summaryFailureDelegate = Function.createDelegate(this, this._summaryFailure);
            

            //set_category:function(value){this._category = value;this.raisePropertyChanged('category');},
    
       },   
        get_category: function(){return this._category;},
        set_category:function(value){this._category = value;this.raisePropertyChanged('category');},
        get_categoryURL: function(){return this._categoryURL;},
        set_categoryURL:function(value){this._categoryURL = value;this.raisePropertyChanged('categoryURL');},
                        
        get_categoryDisplayName: function(){return this._categoryDisplayName;},
        set_categoryDisplayName:function(value){this._categoryDisplayName = value;this.raisePropertyChanged('categoryDisplayName');},
       updated: function()
        {
            Portal.NewsChannelSvc.a(this.get_category(), this._summarySuccessDelegate, this._summaryFailureDelegate);
        },
        _summarySuccess: function(results)
        {
            this._updateSummaries(results);
        },
        _summaryFailure: function(results)
        {
            Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");
        },
        _updateSummaries: function(results)
        {
            if(results.length<6)
                max=results.length-1;
            else 
                max=6;
            for(i=0;i<max;i++)
            {
                $get('HeadlinesList',this.get_element()).innerHTML=$get('HeadlinesList',this.get_element()).innerHTML + '<li class="NewsPanelClass">'+ '<span class="ptBulletContainer"><span class="ptModBullet"/></span></span><a onclick="LogClient(\'1105\',\'portalmain\');" href="NewsChannel.aspx?CatID='+this.get_categoryURL()+'&ArticleID='+results[i].articleId + '">'+this._trimContentString(results[i].headline)+ '</a></li>';                
            }
        },
        _trimContentString: function(str)
        {
            if(str.length<45)
                return str;
            var sub = str.substr(0,45);
            var idxSpace = sub.lastIndexOf(' ');
            sub = sub.substr(0,idxSpace) + "&#8230;";
            return sub;
        }
}


Portal.NewsChannel.NewsPanel.registerClass('Portal.NewsChannel.NewsPanel',Sys.UI.Control);

//NewsReader Container
Portal.NewsChannel.NewsReader = function(element)
{
    Portal.NewsChannel.NewsReader.initializeBase(this,[element]);
    this._category = "";
    this._categoryURL = "";

    this._categoryDisplayName = "";
    this._topHeadlineCount = 1;
    this._headlinePageCount = 10;
    this._topStoryReader = null;
    this._topHeadlineReaders = null;
    this._headlinesListReader = null;
    this._fullStoryReader = null;
    this._articleID = "";
    
    this._articleSummaryList = null;
    
    this._summarySuccessDelegate = null;
    this._summaryFailureDelegate = null;
    
    this._showQuickReadDelegate = null;
    this._showFullStoryDelegate = null;
    this._hideFullStoryDelegate = null;
}

Portal.NewsChannel.NewsReader.prototype = 
{
    get_articleSummaryList: function(){return this._articleSummaryList;},
    set_articleSummaryList:function(value){this._articleSummaryList = value;this.raisePropertyChanged('articleSummaryList');},

    get_topHeadlineCount: function(){return this._topHeadlineCount;},
    set_topHeadlineCount:function(value){this._topHeadlineCount = value;this.raisePropertyChanged('topHeadlineCount');},
    
    get_headlinePageCount: function(){return this._headlinePageCount;},
    set_headlinePageCount:function(value){this._headlinePageCount = value;this.raisePropertyChanged('headlinePageCount');},

    get_category: function(){return this._category;},
    set_category:function(value){this._category = value;this.raisePropertyChanged('category');},
    
    get_categoryURL: function(){return this._categoryURL;},
    set_categoryURL:function(value){this._categoryURL = value;this.raisePropertyChanged('categoryURL');},

       
    get_categoryDisplayName: function(){return this._categoryDisplayName;},
    set_categoryDisplayName:function(value){this._categoryDisplayName = value;this.raisePropertyChanged('categoryDisplayName');},
        
    get_articleID: function(){return this._articleID;},
    set_articleID:function(value){this._articleID = value;this.raisePropertyChanged('articleID');},
    
    add_showQuickRead: function(handler){this.get_events().addHandler('showQuickRead',handler);},
    remove_showQuickRead: function(handler){this.get_events().removeHandler('showQuickRead',handler);},
    
    
    
    initialize: function()
    {
        this.get_element().innerHTML = "<div id='NewsChannelDiv'>" +
        "<div id='TitleContainer' class='ptModTitle'><div id='TitleDiv'>"+this._categoryDisplayName+"</div></div>" +
        "<div id='TopStoryContainer'></div>" +
        "<div id='TopHeadlinesContainer' class='ptTopHeadLinesContainer'><div id='TopHeadlinesTitle' class='ptTitle'><span>"+strLatest+" "+strNews+"</span></div></div>" +
        "<div id='HeadlinesListContainer' width='100%'></div>" +
        "</div>" +
        "<div id='FullStoryContainer' width='100%'></div>";
        
        Sys.UI.DomElement.addCssClass(this.get_element(), "ptModNewsChannel");
        

        if(this._showFullStoryDelegate === null)
            this._showFullStoryDelegate = Function.createDelegate(this, this._showFullStoryHandler);
            
        if(this._hideFullStoryDelegate === null)
            this._hideFullStoryDelegate = Function.createDelegate(this, this.hideFullStory);
        
        if(this._showQuickReadDelegate === null)
            this._showQuickReadDelegate = Function.createDelegate(this, this._showQuickReadHandler);
        
        if(this._topStoryReader === null)
            this._topStoryReader = $create(Portal.NewsChannel.TopStoryReader,{category:this.get_category()},{clickFullStory:this._showQuickReadDelegate},{parent: this.get_id()},$get("TopStoryContainer",this.get_element()));

        if(this.get_articleID()=="")
        {
            Sys.UI.DomElement.addCssClass(this.get_element(), "loadingProgress");
            this._topHeadlineReaders = new Array();        
            for(var  _topcount = 1;_topcount <= this.get_topHeadlineCount();_topcount++)
            {
                var _container = $get('TopHeadlinesContainer',this.get_element());
                var ctlElem = document.createElement('DIV');
                ctlElem.id = 'TopHeadlineElem' + _topcount;
                _container.appendChild(ctlElem);
                var _reader = $create(Portal.NewsChannel.TopHeadLinesReader,{headlineNumber: _topcount, category:this.get_category()},{clickQuickRead:this._showQuickReadDelegate, clickHeadline: this._showFullStoryDelegate},{parent: this.get_id()},ctlElem);
                Array.add(this._topHeadlineReaders,_reader);
            }
            
            
            this._headlinesListReader = $create(Portal.NewsChannel.HeadlinesListReader,
                {articlesPerPage: this.get_headlinePageCount(),articleStartIndex:this.get_topHeadlineCount()+1},
                {clickHeadline: this._showFullStoryDelegate},{parent: this.get_id()},$get("HeadlinesListContainer",this.get_element()));
            this.hideFullStory();
        }
        else
        {
            this._fullStoryReader = $create(Portal.NewsChannel.FullStoryReader,{category:this.get_category()},{hideFullStory: this._hideFullStoryDelegate},{parent: this.get_id()},$get("FullStoryContainer",this.get_element()));
            this.showFullStory(this.get_articleID());
        }
        
        if(this._summarySuccessDelegate === null)
            this._summarySuccessDelegate = Function.createDelegate(this, this._summarySuccess);
            
        if(this._summaryFailureDelegate === null)
            this._summaryFailureDelegate = Function.createDelegate(this, this._summaryFailure);
            
        
        this._hideNewsReader();
    },
    dispose: function()
    {
        if(this._summarySuccessDelegate) delete this._summarySuccessDelegate;
        if(this._summaryFailureDelegate) delete this._summaryFailureDelegate;

        if(this._fullStoryReader) delete this._fullStoryReader;
        if(this._topHeadlineReaders)
        {
            for(var _topcount = 0;_topcount < this._topHeadlineReaders.length;_topcount++)
            {
                delete this._topHeadlineReaders[_topcount];
            }        
            Array.clear(this._topHeadlineReaders);
            delete this._topHeadlineReaders;
        }
        
        if(this._topStoryReader) delete this._topStoryReader;
        
        if(this._showQuickReadDelegate) delete this._showQuickReadDelegate;        
        if(this._showFullStoryDelegate) delete this._showFullStoryDelegate;        
        if(this._hideFullStoryDelegate) delete this._hideFullStoryDelegate;        
    },
    updated: function()
    {
        if(this.get_articleID() == "")
        Portal.NewsChannelSvc.a(this.get_category(), this._summarySuccessDelegate, this._summaryFailureDelegate);
    },    
    _showQuickReadHandler: function(sender, args)
    {
        var f = this.get_events().getHandler('showQuickRead');
        if(f)f(this,args);
    },
    _showFullStoryHandler: function(sender, args)
    {
        if(args && args.get_articleNumber)this.showFullStory(args.get_articleNumber());
    },
    _summarySuccess: function(results)
    {
        this.set_articleSummaryList(results);
        Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");
        this._showNewsReader();
    },
    
    _summaryFailure: function(results)
    {
        Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");
    },
    showFullStory:function(articleID)
    {
        $get('FullStoryContainer',this.get_element()).style.display = '';
        this._hideNewsReader();
        this._fullStoryReader.set_articleID(articleID);
    },
    hideFullStory:function()
    {
        $get('FullStoryContainer',this.get_element()).style.display = 'none';
        this._showNewsReader();
    },
    _hideNewsReader: function()
    {
        $get('NewsChannelDiv',this.get_element()).style.display = 'none';
    },
    _showNewsReader: function()
    {
        $get('NewsChannelDiv',this.get_element()).style.display = '';
    }    
}
Portal.NewsChannel.NewsReader.registerClass('Portal.NewsChannel.NewsReader',Sys.UI.Control);










//Top Story
Portal.NewsChannel.TopStoryReader = function(element)
{
    Portal.NewsChannel.TopStoryReader.initializeBase(this,[element]);
    this._article = null;
    this._articleChangeDelegate = null;
    this._articleSuccessDelegate = null;
    this._articleFailureDelegate = null;
    this._clickQuickReadDelegate = null;
    this._category="";
}

Portal.NewsChannel.TopStoryReader.prototype = 
{
    add_clickFullStory: function(handler){this.get_events().addHandler('clickFullStory',handler);},
    remove_clickFullStory: function(handler){this.get_events().removeHandler('clickFullStory',handler);},

    initialize: function()
    {
        this.get_element().innerHTML = 
        "<div id='HeadlineContainer' class='ptMainHeadline'><span id='HeadlineSpan'></span></div>" +
        "<div id='PreviewContainer' class='ptPreview'>" +
            "<div id='PreviewImageContainer'></div>" + 
            "<div><span id='PreviewSpan'></span></div>" + 
            "<div><span id='FullLinkSpan' class='ptFullStoryLink ptReadLink'>"+strQuickRead+" &gt;</span></div></div>" +
        "<div id='feedErrorMessageID' class='feedErrorMessage' style='display:none'>Sorry, feed cannot be read.</div>";
        
        Sys.UI.DomElement.addCssClass(this.get_element(), "ptTopStory");
        Sys.UI.DomElement.addCssClass(this.get_element(), "loadingProgress");         
                     
        if(this._articleChangeDelegate === null)
            this._articleChangeDelegate = Function.createDelegate(this, this._articleChanged);
        this.get_parent().add_propertyChanged(this._articleChangeDelegate);
        
        if(this._articleSuccessDelegate === null)
            this._articleSuccessDelegate = Function.createDelegate(this, this._articleSuccess);
            
        if(this._articleFailureDelegate === null)
            this._articleFailureDelegate = Function.createDelegate(this, this._articleFailure);            
            
        if(this._clickQuickReadDelegate === null)
            this._clickQuickReadDelegate = Function.createDelegate(this, this._clickQuickReadHandler);        
        $addHandler($get('FullLinkSpan',this.get_element()),'click',this._clickQuickReadDelegate);    

        this._hideAllChildren();
    },
    
    get_category: function(){return this._category;},
    set_category:function(value){this._category = value;this.raisePropertyChanged('category');},
    
    dispose: function()
    {
        $removeHandler($get('FullLinkSpan',this.get_element()),'click',this._clickQuickReadDelegate); 
        if(this._clickQuickReadDelegate) delete this._clickQuickReadDelegate;
        if(this._articleFailureDelegate) delete this._articleFailureDelegate;
        if(this._articleSuccessDelegate) delete this._articleSuccessDelegate;
        
        this.get_parent().remove_propertyChanged(this._articleChangeDelegate);
        if(this._articleChangeDelegate) delete this._articleChangeDelegate;    
    },
    _clickQuickReadHandler: function(sender, eventObj)
    {
        var args = new Portal.NewsChannel.QuickReadArg(this._article,this.get_parent().get_articleSummaryList()[0],0);
        var f = this.get_events().getHandler('clickFullStory');
        if(f)f(this,args);
    },
    _articleChanged: function(sender,property)
    {
        if(this.get_parent().get_articleSummaryList().length>=1)
        {
            if(property.get_propertyName() == 'articleSummaryList')
            {
                Portal.NewsChannelSvc.b(this.get_parent().get_articleSummaryList()[0].articleId, this.get_category(), this._articleSuccessDelegate, this._articleFailureDelegate);
                //$get('FullLinkSpan',this.get_element()).innerHTML="<a onclick=\"LogClient('1100','portalmain');\" href='NewsChannel.aspx?CatID="+this.get_parent().get_category()+"&ArticleID="+this.get_parent().get_articleSummaryList()[0].articleId+ "'>Full Story &gt;</a>";
            }
        }
        else
        {
            Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");         
            //this.get_element().innerHTML='<span class="feedErrorMessage">Sorry, feed cannot be read.</span>';
            $get('feedErrorMessageID',this.get_element()).style.display='block';
            $get('PreviewContainer',this.get_element()).style.display='none';
            
        }
    },
    _articleSuccess: function(results)
    {
        this._article= results;
        this._updateArticle(results);
    },
    _articleFailure: function(results)
    {
        Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");         
    },
    _updateArticle: function(article)   
    {
        var oHL = $get('HeadlineSpan',this.get_element());
        oHL.innerHTML = "<a onclick=\"LogClient('1100','portalmain');\" href='NewsChannel.aspx?CatID="+this.get_parent().get_categoryURL()+"&ArticleID="+this.get_parent().get_articleSummaryList()[0].articleId+ "'><span class='HeadlineColorClass'>" + article.headline +"</span></a>";
        
        //var articleImage = this.get_parent().get_articleSummaryList()[0].imageLocation;
        var articleImage = article.imageLocation220;
        
        
        if(articleImage!="")
        {
            var oPI = $get('PreviewImageContainer',this.get_element());
            oPI.innerHTML = "<a onclick=\"LogClient('1100','portalmain');\" href='NewsChannel.aspx?CatID="+this.get_parent().get_categoryURL()+"&ArticleID="+this.get_parent().get_articleSummaryList()[0].articleId+ "'>" + "<img style='border:none;' id='PreviewImage' src='"+articleImage+"'/>" +"</a>";
            //var oPI = $get('PreviewImage',this.get_element());
            //oPI.src = articleImage;
        }
        
        var oPS = $get('PreviewSpan',this.get_element());
        oPS.innerHTML = this._trimContentString(article.text);
        
        this._showAllChildren();
        Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");         
    },
    _trimContentString: function(str)
    {
        str = str.replace(/<br\/>/gi,' ');  
        str = str.replace(/<br>/gi,' ');
        
        var reg = new RegExp("(\\S*\\s){80}","ig");
        
        if(typeof(str.match(reg))=='undefined' || str.match(reg)==null)
            return str;
        return str.match(reg)[0] + "&#8230;";
        var sub = str.substr(0,255);
        var idxSpace = sub.lastIndexOf(' ');
        sub = sub.substr(0,idxSpace) + "&#8230;";
        return sub;
    },
    _hideAllChildren: function()
    {
        $get('HeadlineContainer',this.get_element()).style.visibility="hidden";
        $get('PreviewContainer',this.get_element()).style.visibility="hidden";
    },
    _showAllChildren: function()
    {
        $get('HeadlineContainer',this.get_element()).style.visibility="visible";
        $get('PreviewContainer',this.get_element()).style.visibility="visible";   
    }      
}
Portal.NewsChannel.TopStoryReader.registerClass('Portal.NewsChannel.TopStoryReader',Sys.UI.Control);






Portal.NewsChannel.QuickReadArg = function(article, articleSummary, newsIndex)
{
    Portal.NewsChannel.QuickReadArg.initializeBase(this);
    this._articleSummary = articleSummary;
    this._article = article;
    this._newsIndex = 0;
}
Portal.NewsChannel.QuickReadArg.prototype = 
{
    get_article: function(){return this._article;},
    set_article:function(value){this._article = value;},
    
    get_articleSummary: function(){return this._articleSummary;},
    set_articleSummary:function(value){this._articleSummary = value;},
    
    get_newsIndex: function(){return this._newsIndex;},
    set_newsIndex:function(value){this._newsIndex = value;}    
    
}
Portal.NewsChannel.QuickReadArg.registerClass("Portal.NewsChannel.QuickReadArg", Sys.EventArgs);

Portal.NewsChannel.FullStoryArg = function(articleNumber)
{
    Portal.NewsChannel.FullStoryArg.initializeBase(this);
    this._articleNumber = articleNumber;
}
Portal.NewsChannel.FullStoryArg.prototype = 
{
    get_articleNumber: function(){return this._articleNumber;},
    set_articleNumber:function(value){this._articleNumber = value;}
}
Portal.NewsChannel.FullStoryArg.registerClass("Portal.NewsChannel.FullStoryArg", Sys.EventArgs);

//Top Headlines
Portal.NewsChannel.TopHeadLinesReader = function(element)
{
    Portal.NewsChannel.TopHeadLinesReader.initializeBase(this,[element]);
    this._headlineNumber = 1;
    this._article = null;
    this._category="";
    this._articleChangeDelegate = null;
    this._articleSuccessDelegate = null;
    this._articleFailureDelegate = null;
    this._clickQuickReadDelegate = null;
    this._clickHeadlineDelegate = null;
}

Portal.NewsChannel.TopHeadLinesReader.prototype = 
{
    get_headlineNumber: function(){return this._headlineNumber;},
    set_headlineNumber:function(value){this._headlineNumber = value;this.raisePropertyChanged('articleSummaryList');},
    
    get_article: function(){return this._article;},
    set_article:function(value){this._article = value;this.raisePropertyChanged('article');},
    
    get_category: function(){return this._category;},
    set_category:function(value){this._category = value;this.raisePropertyChanged('category');},

    add_clickQuickRead: function(handler){this.get_events().addHandler('clickQuickRead',handler);},
    remove_clickQuickRead: function(handler){this.get_events().removeHandler('clickQuickRead',handler);},
    
    add_clickHeadline: function(handler){this.get_events().addHandler('clickHeadline',handler);},
    remove_clickHeadline: function(handler){this.get_events().removeHandler('clickHeadline',handler);},
    
    initialize: function()
    {
        this.get_element().innerHTML = "<div id='TopHeadlineHeadline' class='ptHeadline'><span ID='TopHeadlineSpan' class='ptReadLink'></span></div>" +
        "<div id='TopHeadlineText'><span ID='TopStoryTextSpan' class='ptStoryText'></span></div>" +
        "<div id='TopHeadlineQuickRead' class='ptQuickRead'><span id='DateLineSpan'class='ptDateLine'></span><span id='ptReadLinkSpan' class='ptReadLink'>"+strQuickRead+" &gt;</span></div>";
        
        Sys.UI.DomElement.addCssClass(this.get_element(), "ptTopHeadLines");        
        Sys.UI.DomElement.addCssClass(this.get_element(), "loadingProgress");        
        
        if(this._articleChangeDelegate === null)
            this._articleChangeDelegate = Function.createDelegate(this, this._articleChanged);
        this.get_parent().add_propertyChanged(this._articleChangeDelegate);
        
        if(this._articleSuccessDelegate === null)
            this._articleSuccessDelegate = Function.createDelegate(this, this._articleSuccess);
            
        if(this._articleFailureDelegate === null)
            this._articleFailureDelegate = Function.createDelegate(this, this._articleFailure);         
            
        if(this._clickQuickReadDelegate === null)
            this._clickQuickReadDelegate = Function.createDelegate(this, this._clickQuickReadHandler);
        $addHandler($get('ptReadLinkSpan',this.get_element()),'click', this._clickQuickReadDelegate);

        if(this._clickHeadlineDelegate === null)
            this._clickHeadlineDelegate = Function.createDelegate(this, this._clickHeadlineHandler);
//        $addHandler($get('TopHeadlineSpan',this.get_element()),'click', this._clickHeadlineDelegate);
        
        this._hideAllChildren();    
    },
    dispose: function()
    {
        //$removeHandler($get('TopHeadlineSpan',this.get_element()),'click', this._clickHeadlineDelegate);
        if(this._clickHeadlineDelegate) delete this._clickHeadlineDelegate;

        $removeHandler($get('ptReadLinkSpan',this.get_element()),'click', this._clickQuickReadDelegate);
        if(this._clickQuickReadDelegate) delete this._clickQuickReadDelegate;
                
        if(this._articleFailureDelegate) delete this._articleFailureDelegate;
        if(this._articleSuccessDelegate) delete this._articleSuccessDelegate;
        
        this.get_parent().remove_propertyChanged(this._articleChangeDelegate);
        if(this._articleChangeDelegate) delete this._articleChangeDelegate;     
    },
    _clickQuickReadHandler: function()
    {
        LogClient('1101','portalmain');
        var args = new Portal.NewsChannel.QuickReadArg(this.get_article(), this.get_parent().get_articleSummaryList()[this.get_headlineNumber()], this.get_headlineNumber() );
        var f = this.get_events().getHandler('clickQuickRead');
        if(f)f(this,args);
    },
    _clickHeadlineHandler: function()
    {
        var args = new Portal.NewsChannel.FullStoryArg(this.get_headlineNumber());
        var f = this.get_events().getHandler('clickHeadline');
        if(f)f(this,args);
    },
    _articleChanged: function(sender,property)
    {
        if(property.get_propertyName() == 'articleSummaryList')
        {
            if(this.get_parent().get_articleSummaryList()[this.get_headlineNumber()]!=null)
                Portal.NewsChannelSvc.b(this.get_parent().get_articleSummaryList()[this.get_headlineNumber()].articleId, this.get_category(),this._articleSuccessDelegate, this._articleFailureDelegate);
            else
            {
                Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");
            }
        }
    },
    _articleSuccess: function(results)
    {
        this._updateArticle(results);
    },
    _articleFailure: function(results)
    {
    },
    _updateArticle: function(article)   
    {
        this.set_article(article);
        
        var oHL = $get('TopHeadlineSpan',this.get_element());
        oHL.innerHTML = "<a onclick=\"LogClient('1100','portalmain');\" href='NewsChannel.aspx?CatID="+this.get_parent().get_categoryURL()+"&ArticleID="+article.articleId+"'><span class='HeadlineColorClass'>"+article.headline+"</span></a>";
                    
        var oPS = $get('TopStoryTextSpan',this.get_element());
        oPS.innerHTML = this._trimContentString(article.text);
        
        var oDL = $get('DateLineSpan',this.get_element());
        var dt = article.dateLine;
        /*var reg = new RegExp(">(.*)<","ig");
        dt = dt.match(reg)[0];
        dt = dt.replace(">","");
        dt = dt.replace("<","");*/
        oDL.innerHTML = dt;        
        this._showAllChildren();
        Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");
    },
    _trimContentString: function(str)
    {
        str = str.replace('<br/>','');
        str = str.replace('<br>','');
        
        var reg = new RegExp("(\\S*\\s){12}","ig");
        
        if(typeof(str.match(reg))=='undefined' || str.match(reg)==null)
            return str;
                    
        return str.match(reg)[0]  + "&#8230;";
        var sub = str.substr(0,50);
        var idxSpace = sub.lastIndexOf(' ');
        sub = sub.substr(0,idxSpace) + "&#8230;";
        return sub;
    },
    _hideAllChildren: function()
    {
        $get('TopHeadlineHeadline',this.get_element()).style.visibility="hidden";
        $get('TopHeadlineText',this.get_element()).style.visibility="hidden";
        $get('TopHeadlineQuickRead',this.get_element()).style.visibility="hidden";
    },
    _showAllChildren: function()
    {
        $get('TopHeadlineHeadline',this.get_element()).style.visibility="visible";
        $get('TopHeadlineText',this.get_element()).style.visibility="visible";
        $get('TopHeadlineQuickRead',this.get_element()).style.visibility="visible";       
    }    
}
Portal.NewsChannel.TopHeadLinesReader.registerClass('Portal.NewsChannel.TopHeadLinesReader',Sys.UI.Control);








//HeadlinesList
Portal.NewsChannel.HeadlinesListReader = function(element)
{
    Portal.NewsChannel.HeadlinesListReader.initializeBase(this,[element]);
    this._articlesPerPage = 1;
    this._articleStartIndex = 0;
    this._currentPage = 1;
    
    this._articleChangeDelegate = null;   
}

Portal.NewsChannel.HeadlinesListReader.prototype = 
{
    get_articlesPerPage: function(){return this._articlesPerPage;},
    set_articlesPerPage:function(value){this._articlesPerPage = value;this.raisePropertyChanged('articlesPerPage');},

    get_articleStartIndex: function(){return this._articleStartIndex;},
    set_articleStartIndex:function(value){this._articleStartIndex = value;this.raisePropertyChanged('articleStartIndex');},
    
    get_currentPage: function(){return this._currentPage;},
    set_currentPage:function(value){this._currentPage = value;this.raisePropertyChanged('currentPage');},
    
    add_clickHeadline: function(handler){this.get_events().addHandler('clickHeadline',handler);},
    remove_clickHeadline: function(handler){this.get_events().removeHandler('clickHeadline',handler);},

    initialize: function()
    {
        this.get_element().innerHTML = "<div ID='HeadlineListTitle' class='ptTitle'>"+strMore+" "+strNews+"</div>" +
        "<div ID='HeadlineListContent' class='ptHeadlinesList'><UL ID='HeadlinesList'></UL></div>" +
        "<div ID='HeadlineListPaging' class='ptHeadlinesListNav'></div>";
        
        Sys.UI.DomElement.addCssClass(this.get_element(), "ptMoreHeadLines");
                
        if(this._articleChangeDelegate === null)
            this._articleChangeDelegate = Function.createDelegate(this, this._articleChanged);
        this.get_parent().add_propertyChanged(this._articleChangeDelegate);
        this.add_propertyChanged(this._articleChangeDelegate);
    },
    dispose: function()
    {
        this.get_parent().remove_propertyChanged(this._articleChangeDelegate);
        if(this._articleChangeDelegate) delete this._articleChangeDelegate;     
    },
    _articleChanged: function(sender,property)
    {
        if(property.get_propertyName() == 'articleSummaryList')
        {
            this._updateArticle();
        }else if (property.get_propertyName() == 'currentPage')
        {
            this._updateArticle();
        }
    },
    raiseHeadlineClick: function(articleno)
    {
        var args = new Portal.NewsChannel.FullStoryArg(articleno);
        var f = this.get_events().getHandler('clickHeadline');
        if(f)f(this,args);
    },
    _updateArticle: function()   
    {
        var nStart = this.get_articleStartIndex() + (this.get_articlesPerPage() * (this.get_currentPage()-1));
        var nEnd = nStart + this.get_articlesPerPage();
        var oSummaries = this.get_parent().get_articleSummaryList();
        var oUL = $get('HeadlinesList',this.get_element());
        oUL.innerHTML = "";
        for(var i = nStart;i<nEnd;i++)
        {
            if(!oSummaries[i]) break;
            var oItem = document.createElement('LI');
            oItem.id = "HeadlineListItem_"+i;
            oUL.appendChild(oItem);
            oItem.innerHTML = "<span class='ptBulletContainer'><span class='ptModBullet'></span></span><a onclick=\"LogClient('1100','portalmain');\"  href='NewsChannel.aspx?CatID="+this.get_parent().get_categoryURL()+"&ArticleID="+oSummaries[i].articleId+"'><span class='ptReadLink'>"+oSummaries[i].headline+"</span></a>";
        }
        
        var oPL = $get('HeadlineListPaging',this.get_element());
        var cur_idx = this.get_articleStartIndex();
        var nPage = 1;
        var finalHTM = "";
        // show HeadlineListPaging only if there are > 1 entries
        $get('HeadlineListPaging').style.display = 'none';
        do{
            if(nPage != this.get_currentPage())
            {
                var spanHTM = "<SPAN id='HeadLineListPageNumber"+nPage+"' onclick=\"$find('"+this.get_id()+"').set_currentPage("+nPage+")\" class='ptHeadlinesListPageNum ptReadLink'>"+nPage+"</SPAN>"
                finalHTM += spanHTM;
            }
            else
            {
                var spanHTM = "<SPAN id='HeadLineListPageNumber"+nPage+"' class='ptHeadlinesListPageNum ptCurrentPage'>"+nPage+"</SPAN>"
                finalHTM += spanHTM;
            }
            //advance
            nPage++;
            cur_idx += this.get_articlesPerPage();
        }while(cur_idx < oSummaries.length)
        if (nPage > 2)
            $get('HeadlineListPaging').style.display = '';
        oPL.innerHTML = finalHTM;
    }    
}
Portal.NewsChannel.HeadlinesListReader.registerClass('Portal.NewsChannel.HeadlinesListReader',Sys.UI.Control);

//Full Story
//HeadlinesList
Portal.NewsChannel.FullStoryReader = function(element)
{
    Portal.NewsChannel.FullStoryReader.initializeBase(this,[element]);
    this._articleID = 0;
    this._category="";
    this._article = null;
    this._articleChangeDelegate = null;
    this._articleSuccessDelegate = null;
    this._articleFailureDelegate = null;
    this._backButtonDelegate = null;
}

Portal.NewsChannel.FullStoryReader.prototype = 
{
    get_articleID: function(){return this._articleID;},
    set_articleID:function(value){this._articleID = value;this.raisePropertyChanged('articleID');},

    get_article: function(){return this._article;},
    set_article:function(value){this._article = value;this.raisePropertyChanged('article');},
    
    get_category: function(){return this._category;},
    set_category:function(value){this._category = value;this.raisePropertyChanged('category');},
        
    add_hideFullStory: function(handler){this.get_events().addHandler('hideFullStory',handler);},
    remove_hideFullStory: function(handler){this.get_events().removeHandler('hideFullStory',handler);},
    
    initialize: function()
    {
        this.get_element().innerHTML = "<div ID='FullStoryHeadlineDiv' class='ptFSHeadline'>"+
        "<SPAN ID='StorySourceLogo' style='float:right;'></SPAN>" +
        "<SPAN ID='FullStoryHeadline'></SPAN></div>" +
        "<div ID='FullStoryContent' class='ptFSContent'>" +
        "<div ID='FullStoryPhotoDiv' class='ptFSPhoto'></div>" +
        "<div ID='FullStoryDateLineDiv' class='ptFSDateLine'><SPAN ID='FullStoryDateLine'></SPAN></div>" +
        "<div ID='FullStoryDateTimeDiv' class='ptFSDateLine'><SPAN ID='FullStoryDateTime'></SPAN></div>" +
        "<div ID='FullStoryByLineDiv' class='ptFSByLine'><SPAN ID='FullStoryByLine'></SPAN></div>" +
        "<div ID='FullStoryTextDiv' class='ptFSText'><SPAN ID='FullStoryText'></SPAN></div>" +
        "</div>";
        
        
        //"<div ID='FullStoryBackLinkDiv' class='ptFSBackLink'><SPAN ID='FullStoryBackLink' class='ptReadLink'>&lt; Back</SPAN></div>";
        
        Sys.UI.DomElement.addCssClass(this.get_element(), "ptFullStory");
        Sys.UI.DomElement.addCssClass(this.get_element(), "loadingProgress");
        
        if(this._articleChangeDelegate === null)
            this._articleChangeDelegate = Function.createDelegate(this, this._articleChanged);
        this.add_propertyChanged(this._articleChangeDelegate);
        
        if(this._articleSuccessDelegate === null)
            this._articleSuccessDelegate = Function.createDelegate(this, this._articleSuccess);
            
        if(this._articleFailureDelegate === null)
            this._articleFailureDelegate = Function.createDelegate(this, this._articleFailure);
            
        if(this._backButtonDelegate === null)
            this._backButtonDelegate = Function.createDelegate(this, this._backButtonHandler);
        //$addHandler($get('FullStoryBackLink',this.get_element()),'click',this._backButtonDelegate);
    },
    dispose: function()
    {
        //$removeHandler($get('FullStoryBackLink',this.get_element()),'click',this._backButtonDelegate);
        if(this._backButtonDelegate) delete this._backButtonDelegate;
        if(this._articleFailureDelegate) delete this._articleFailureDelegate; 
        if(this._articleSuccessDelegate) delete this._articleSuccessDelegate; 
        this.remove_propertyChanged(this._articleChangeDelegate);
        if(this._articleChangeDelegate) delete this._articleChangeDelegate; 
    },
    _articleSuccess: function(results)
    {
        this._updateArticle(results);
    },
    _articleFailure: function(results)
    {
    },
    _updateArticle: function(article)
    {
        Sys.UI.DomElement.removeCssClass(this.get_element(), "loadingProgress");
        $get('FullStoryHeadline',this.get_element()).innerHTML = article.headline;
        if(article.imageLocation!="")
            $get('FullStoryPhotoDiv',this.get_element()).innerHTML = "<Img ID='FullStoryPhoto' src='"+article.imageLocation+"'/>";
        else
            $get('FullStoryPhotoDiv',this.get_element()).style.display="none";
        $get('FullStoryDateLine',this.get_element()).innerHTML = article.dateLine;
        //$get('FullStoryDateTime',this.get_element()).innerHTML = article.dateTime;
        $get('FullStoryByLine',this.get_element()).innerHTML = article.byLine;
        $get('FullStoryText',this.get_element()).innerHTML = article.text;        
        $get('StorySourceLogo',this.get_element()).innerHTML = article.sourceLogo;  
        this._showAllChildren();
    },
    _articleChanged: function(sender,property)
    {
        if(property.get_propertyName() == 'articleID')
        {
            this._hideAllChildren();
            Sys.UI.DomElement.addCssClass(this.get_element(), "loadingProgress");
            Portal.NewsChannelSvc.b(this.get_articleID(), this.get_category(), this._articleSuccessDelegate, this._articleFailureDelegate);
        }
    },
    _backButtonHandler: function(sender, eventObj)
    {
        var f = this.get_events().getHandler('hideFullStory');
        if(f)f(this,Sys.EventArgs.Empty);
    },
    _hideAllChildren: function()
    {
        $get('FullStoryHeadlineDiv',this.get_element()).style.visibility="hidden";
        $get('FullStoryContent',this.get_element()).style.visibility="hidden";
        //$get('FullStoryBackLinkDiv',this.get_element()).style.visibility="hidden";
    },
    _showAllChildren: function()
    {
        $get('FullStoryHeadlineDiv',this.get_element()).style.visibility="visible";
        $get('FullStoryContent',this.get_element()).style.visibility="visible";  
        //$get('FullStoryBackLinkDiv',this.get_element()).style.visibility="visible";   
    }   

}
Portal.NewsChannel.FullStoryReader.registerClass('Portal.NewsChannel.FullStoryReader',Sys.UI.Control);


//Full Story
//HeadlinesList
Portal.NewsChannel.CategoryPreview = function(element)
{
    Portal.NewsChannel.CategoryPreview.initializeBase(this,[element]);
    this._currentCatergory;
    this._currentCatergoryURL;
    this._categoryDisplayName ="";
    this._categorySuccessDelegate = null;
    this._categoryFailureDelegate = null;
    this._clickID = null;
    
}

Portal.NewsChannel.CategoryPreview.prototype = 
{
   
    get_currentCatergory: function(){return this._currentCatergory;},
    set_currentCatergory:function(value){this._currentCatergory = value;this.raisePropertyChanged('currentCatergory');},
    get_currentCatergoryURL: function(){return this._currentCatergoryURL;},
    set_currentCatergoryURL:function(value){this._currentCatergoryURL = value;this.raisePropertyChanged('currentCatergoryURL');},
    get_categoryDisplayName: function(){return this._categoryDisplayName;},
    set_categoryDisplayName:function(value){this._categoryDisplayName = value;this.raisePropertyChanged('categoryDisplayName');},
    
    
    
    get_clickID: function(){return this._clickID;},
    set_clickID:function(value){this._clickID = value;this.raisePropertyChanged('clickID');},
    
        
    initialize: function()
    {
         this.get_element().innerHTML = "<div id='categoryDiv'>" +
        "<div id='TitleContainer'><div id='TitleDiv' class='ptCategoryLink'><b><a onclick=\"LogClient('"+this.get_clickID()+"','portalmain');\"  href='NewsChannel.aspx?CatID="+this.get_currentCatergoryURL()+"'>"+this.get_categoryDisplayName()+" &gt;</a></b></div></div>" +
        "<div id='TopStoryCont'></div>" +
        "<div id='catHeadlinesContainer' class='ptHeadlineCategory' width='100%'><span id='catHeadline'></span></div>" +
        //"<div id='FullStoryContainer' width='100%' class='ptCategoryLink'><b><a onclick=\"LogClient('"+this.get_clickID()+"','portalmain');\" href='NewsChannel.aspx?CatID="+this.get_currentCatergory()+"'>more "+this.get_categoryDisplayName()+" &gt;</a></div>"+
        "</div>";
        
        Sys.UI.DomElement.addCssClass(this.get_element(), "ptCategoryPanel");
        
        if(this._categorySuccessDelegate === null)
            this._categorySuccessDelegate = Function.createDelegate(this, this._categorySuccess);
            
        if(this._categoryFailureDelegate === null)
            this._categoryFailureDelegate = Function.createDelegate(this, this._categoryFailure);
            
            
    },
    dispose: function()
    {
            if(this._categorySuccessDelegate) delete this._categorySuccessDelegate;     
            if(this._categoryFailureDelegate) delete this._categoryFailureDelegate;     
    },
    updated: function()
    {
        Portal.NewsChannelSvc.a(this._currentCatergory, this._categorySuccessDelegate, this._categoryFailureDelegate);
    },
    _categorySuccess:function(results)
    {
        this._updateFooterPanel(results);
    },
    _categoryFailure:function()
    {
    },
    _updateFooterPanel:function(results)
    {
        if(results.length<1) return;
        if(results[0].imageLocation220=="")
            results[0].imageLocation220="newsThumbnail.png";
        $get('TopStoryCont',this.get_element()).innerHTML="<div onclick='LogClient(\"1100\",\"portalmain\"); window.open(\"NewsChannel.aspx?CatID="+this.get_currentCatergoryURL()+"&ArticleID="+results[0].articleId+ "\",\"_top\");' class='ptCatergoryImage' id='TopStoryContainer'  style='background-image: url("+ results[0].imageLocation220 +")'></div>";
        //<img class='ptHeadlineImage' id='categoryImage' src='"+results[0].imageLocation +"'/></a>"; //results[0].imageLocation ;                
        $get('catHeadline',this.get_element()).innerHTML="<a onclick=\"LogClient('1100','portalmain');\" href='NewsChannel.aspx?CatID="+this.get_currentCatergoryURL()+"&ArticleID="+results[0].articleId+ "'>" +results[0].headline+ "</a>";                
    }

//<div id='TopStoryContainer' class='ptCatergoryImage'><img id='categoryImage'/></div>" +
}
Portal.NewsChannel.CategoryPreview.registerClass('Portal.NewsChannel.CategoryPreview',Sys.UI.Control);


Portal.NewsChannel.RssFeedList = function(element)
{
    Portal.NewsChannel.RssFeedList.initializeBase(this,[element]);
    this._feedURL = "";
    this._title = "";
    this._feedSuccessDelegate = null;
    this._feedFailureDelegate = null;
    this._rssClickDelegate  = new Array();  
    this._quickReadTitle = "";
    this._rssResults = null;
    this._popupCtl = null;
    this._showNewsRssPopup = true;
}

Portal.NewsChannel.RssFeedList.prototype = 
{
    get_feedURL: function(){return this._feedURL;},
    set_feedURL:function(value){this._feedURL = value;this.raisePropertyChanged('feedURL');},
    
    get_title: function(){return this._title;},
    set_title:function(value){this._title = value;this.raisePropertyChanged('title');},
    
    get_close: function(){return this._close;},
    set_close:function(value){this._close = value;this.raisePropertyChanged('close');},

    get_showNewsRssPopup: function(){return this._showNewsRssPopup;},
    set_showNewsRssPopup:function(value){this._showNewsRssPopup = value;this.raisePropertyChanged('showNewsRssPopup');},

    get_quickReadTitle: function(){return this._quickReadTitle;},
    set_quickReadTitle:function(value){this._quickReadTitle = value;this.raisePropertyChanged('quickReadTitle');},         
            
    get_PopupCtl: function(){
        if(!this._popupCtl){
            this._createPopupControl()
        }
        return this._popupCtl;
    },        
            
    initialize: function()
    {
        Portal.NewsChannel.RssFeedList.callBaseMethod(this,"initialize");
        this.get_element().innerHTML = "<table cellpadding='0' cellspacing='0' style='width:301px;'><tr><td class='ptRightBoxTitle'><span>"
        +this.get_title()+
        "</span><td></tr>" +
        "<tr><td><div class='ptRssDiv'><div id='feedContent'></div></div></td></tr>";
                       
        if(this._feedSuccessDelegate === null)
            this._feedSuccessDelegate = Function.createDelegate(this, this._feedSuccess);
            
        if(this._feedFailureDelegate === null)
            this._feedFailureDelegate = Function.createDelegate(this, this._feedFailure);
    },
    dispose: function()
    {
        if(this._feedSuccessDelegate) delete this._feedSuccessDelegate;     
        if(this._feedFailureDelegate) delete this._feedFailureDelegate;  
        for(var i =0 ; i < this._rssResults.length ; i++)
        {
            if(this._rssClickDelegate [i]) delete this._rssClickDelegate [i];
        }
        Portal.NewsChannel.RssFeedList.callBaseMethod(this,"dispose");   
    },
    updated: function()
    {
        Portal.ClientRssSvc.GetDetails(this.get_feedURL(),1,5,this._feedSuccessDelegate);
    },
    _feedSuccess:function(results)
    {
        this._updateFeeds(results)
    },
    _feedFailure:function()
    {
    },
    _updateFeeds:function(rssArticles)
    {          
        this._rssResults = rssArticles;
        var finalHTML = "";
        
        if((rssArticles.length == 0) || (rssArticles.length == 1 && rssArticles[0].ArtHeadline == ""))
        {
            finalHTML = "<div class='feedErrorMessage'>"+ strClientRss_NoFeedErr +"</div>";
            $get("feedContent",this.get_element()).innerHTML = finalHTML;
        }
        else
        {
            for(var i=0;i<rssArticles.length && rssArticles[0].ArtHeadline != "";i++)
            {
                var rssString = "rss_" + i;                   
                finalHTML += "<div style='width:100%; cursor : pointer;' onclick=\"LogClient('1102','portalmain');\" id="+ "'" +rssString+ "'"+ "><div style='display:inline'><span class='ptBulletContainer'><span class='ptModBullet'></span></span></div><div class='ptRSSQuickReadColor' style='display:inline'>" +this._trimContentString(rssArticles[i].ArtHeadline)+"</div></div>";            
                //finalHTML += "<tr style='width:100%; cursor : pointer;' onclick=\"LogClient('1102','portalmain');\" id="+ "'" +rssString+ "'"+ "><td style='vertical-align:text-top'><div ><span class='ptBulletContainer'><span class='ptModBullet'></span></span></div></td><td><div class='ptRSSQuickReadColor'>" +this._trimContentString(rssArticles[i].ArtHeadline)+"</div></td></tr>"
                this._rssClickDelegate [i] = null;          
            }
            //finalHTML = "<table width='100%' cellpadding='0' cellspacing='0'>" + finalHTML + "</table>";
            $get("feedContent",this.get_element()).innerHTML = finalHTML;
            
            for(var i =0 ; i<rssArticles.length;i++ )
            {
                var rssString = "rss_"+i;
                if(this._rssClickDelegate[i]  === null)  
                {
                    this._rssClickDelegate[i]  = Function.createDelegate(this, this._rssClickDelegateHandler);            
                    $addHandler($get(rssString ,this.get_element()),'click',this._rssClickDelegate [i]);
                }
            }
        }
    
    },
    
    _rssClickDelegateHandler :function(position)
    {
        var articleObj = null;        
        for(var i = 0; i < this._rssResults.length ; i++)
        {
            if(((position.target.innerHTML).indexOf(this._trimContentStringWithoutDots(this._rssResults[i].ArtHeadline))) != -1)
            {
                articleObj = this._rssResults[i];
            }
        }                    

        if(this.get_showNewsRssPopup())
        {
            var pop = this.get_PopupCtl(this._popupCtl);
            var oDiv = $get(pop.get_PopupControlID()+'_Title');
            oDiv.innerHTML = this.get_quickReadTitle();
            
            var theDiv = $get(pop.get_PopupControlID()+'_PopupContent');
            theDiv.innerHTML = document.getElementById("quickReadDialogRSS").innerHTML;
            theDiv.style.display = "block";
            
            $get('articleTitleRSS',theDiv).innerHTML=articleObj.ArtHeadline;
            $get('articleText1RSS',theDiv).innerHTML=articleObj.RSSFullDetails.trim();
            
            if(articleObj.ImageUrl!="")
                $get('articleImageRSS',theDiv).innerHTML = "<im"+"g src='"+articleObj.ImageUrl +"' style='padding:0px 0px 0px 0px'/>";
            else
                $get('articleImageRSS',theDiv).innerHTML = "";
            $get('readLinkRSS',theDiv).innerHTML="<span class=\"ptCategoryLink\" ><a target='_blank' onclick=\"LogClient('1170','portalmain');\" href='"+articleObj.StoryUrl+"'>"+strReadStory+"></a> </span>";
            $get('articleTitleRSS',theDiv).innerHTML="<span ><a target='_blank' onclick=\"LogClient('1169','portalmain');\" href='"+articleObj.StoryUrl+"'>"+articleObj.ArtHeadline+"</a> </span>";
            
            pop.show();
        }
        else
        {
            window.open(articleObj.StoryUrl, '_blank');
        }
    },
    
    _createPopupControl:function()
    {
        var el = Insp.UI.PopupHelper.getGenericPopupElement('rsspop'+'_Popup');
        el.className = 'Popup_Frame';
        this._popupCtl = $create(AjaxControlToolkit.ModalPopupBehavior,{"id":'rsspop'+'_PopupBehavior',"BackgroundCssClass":"MBD","CancelControlID":el.id+'_PopupCancelImage',"PopupControlID":el.id}, null, null, $get(el.id+'_Title'));
    },
    
    _trimContentString: function(str)
    {
        if(str.length <= 45) return str;
        var sub = str.substr(0,45);
        var idxSpace = sub.lastIndexOf(' ');
        sub = sub.substr(0,idxSpace) + "&#8230;";
        return sub;
    },
    
    _trimContentStringWithoutDots : function(str)
    {
        if(str.length <= 45) return str;
        var sub = str.substr(0,45);
        var idxSpace = sub.lastIndexOf(' ');
        sub = sub.substr(0,idxSpace);
        return sub.trim();
    }
}
Portal.NewsChannel.RssFeedList.registerClass('Portal.NewsChannel.RssFeedList',Sys.UI.Control);

Portal.NewsChannel.PopSearchList = function(element)
{
    Portal.NewsChannel.PopSearchList.initializeBase(this,[element]);
    this._feedSuccessDelegate = null;
    this._feedFailureDelegate = null;
    this._searchURL = "";
    this._itemCount = 6;
}

Portal.NewsChannel.PopSearchList.prototype = 
{
    get_searchURL:function(){return this._searchURL;},
    set_searchURL:function(value){this._searchURL = value;this.raisePropertyChanged('searchURL');},
    
    get_itemCount:function(){return this._itemCount;},
    set_itemCount:function(value){this._itemCount = value;this.raisePropertyChanged('itemCount');},

    initialize: function()
    {
        Portal.NewsChannel.PopSearchList.callBaseMethod(this,"initialize");
        var e = this.get_element();
        e.innerHTML = "<div class='PopSearchTitle' style='width:100%;'>"+strTopSearch+"</div>"+
            "<div width='100%;'><ul id='KeywordList'></ul></div><div id='ResultDiv' style='display:none'></div";
        Sys.UI.DomElement.addCssClass(e, "ptPopSearch");
        
        if(this._feedSuccessDelegate === null)
            this._feedSuccessDelegate = Function.createDelegate(this, this._feedSuccess);
            
        if(this._feedFailureDelegate === null)
            this._feedFailureDelegate = Function.createDelegate(this, this._feedFailure);        
     },
    dispose: function()
    {
        if(this._feedSuccessDelegate) delete this._feedSuccessDelegate;     
        if(this._feedFailureDelegate) delete this._feedFailureDelegate;     
       Portal.NewsChannel.PopSearchList.callBaseMethod(this,"dispose");   
    },
    updated: function()
    {
        Portal.NewsChannelSvc.GetPopularSearchResults(this._feedSuccessDelegate, this._feedFailureDelegate);
    },
    _feedSuccess:function(results)
    {
        this._populateList(results);
    },
    _feedFailure:function()
    {
        
    },
    _populateList:function(results)
    {
        var hdiv = $get("ResultDiv",this.get_element());
        hdiv.innerHTML = results;
        var items = hdiv.getElementsByTagName('li');
        if(items!= null)
        {
            for(var i=0,idx=0;(i<this.get_itemCount())&& (idx < items.length);idx++)
            {
                var oa = items[idx].getElementsByTagName('a');
                if(oa[0].innerHTML.length <= 18)
                {
                    this._addWordToList(oa[0].innerHTML,i);
                    i++;
                }
            }
        }
    },
    _addWordToList:function(word,idx)
    {
        var klist = $get("KeywordList",this.get_element());
        var li = document.createElement('li');
        li.innerHTML = '<span class="ptBulletContainer"><span class="ptModBullet"></span></span><a href="'+this.get_searchURL().replace(/\[SearchItem\]/ig,word)+'" target='+ strNewsCh_target +' onclick="LogClient(\'108\',\'ptsidebar\');">'+word+'</a>';
        klist.appendChild(li);
    }
}
Portal.NewsChannel.PopSearchList.registerClass('Portal.NewsChannel.PopSearchList',Sys.UI.Control);


if(typeof(Sys) !== 'undefined')Sys.Application.notifyScriptLoaded();


