Type.registerNamespace("Insp");
Type.registerNamespace("Insp.UI");

Insp.UI.RssCollEdit = function(element)
{
    Insp.UI.RssCollEdit.initializeBase(this,[element]);
    this._collType = "";
    this._currColl = null;
    this._category = "";
    this._collDetails = null;
    this._actCategory = "";
    this._criteria = null;
    this._wError = false;
    this._sZip = false;
    this._currTitle = null;
    
    this._currCat = null;
    this._cobrand = "";
    this._saveData = false;
    
    this._saveClickDelegate = null;
    this._cancelClickDelegate = null;
    this._EnterKeyPressedDelegate = null;
    this._catCallbackDelegate = null;
    this._catFailureDelegate = null;
    this._catChangedDelegate = null;
    this._saveSuccessDelegate = null;
    this._saveFailureDelegate = null;
    this._critValidDlg = null;
    this._critFailDlg = null;
}

Insp.UI.RssCollEdit.prototype = {
    
    get_collType: function(){return this._collType;},
    set_collType: function(value){this._collType = value;this.raisePropertyChanged('collType');},
    
    get_category: function(){return this._category;},
    set_category: function(value){this._category = value;this.raisePropertyChanged('category');},
    
    get_currColl: function(){return this._currColl;},
    set_currColl: function(value){this._currColl = value;this.raisePropertyChanged('currColl');},
    
    get_actCategory: function(){return this._actCategory;},
    set_actCategory: function(value){this._actCategory = value;this.raisePropertyChanged('actCategory');},
    
    get_isCollection: function(){return this._isCollection;},
    set_isCollection: function(value){this._isCollection = value;this.raisePropertyChanged('isCollection');},
    
    get_criteria: function(){return this._criteria;},
    set_criteria: function(value){this._criteria = value;this.raisePropertyChanged('criteria');},
    
    dispose: function()
    {
		$removeHandler($get("SelCategories",this.get_element()),'change',this._catChangedDelegate);
		if(this._catChangedDelegate) delete this._catChangedDelegate;
		if(this._catFailureDelegate) delete this._catFailureDelegate;
		if(this._catCallbackDelegate) delete this._catCallbackDelegate;
        $removeHandler($get('BtnCancel',this.get_element()),'click',this._cancelClickDelegate);
        if(this._cancelClickDelegate) delete this._cancelClickDelegate;
        $removeHandler($get('BtnSave',this.get_element()),'click',this._saveClickDelegate);
        if(this._saveClickDelegate) delete this._saveClickDelegate;
        this.remove_enterPressed(this._EnterKeyPressedDelegate)
        if(this._EnterKeyPressedDelegate) delete this._EnterKeyPressedDelegate;
        Insp.UI.RssCollEdit.callBaseMethod(this,'dispose');
    },
    initialize: function()
    {
        Insp.UI.RssCollEdit.callBaseMethod(this,'initialize');
        if (this._saveClickDelegate === null) {
            this._saveClickDelegate = Function.createDelegate(this, this._saveClickHandler);
        }
        
        $addHandler($get('BtnSave',this.get_element()),'click',this._saveClickDelegate);

        if (this._cancelClickDelegate === null) {
            this._cancelClickDelegate = Function.createDelegate(this, this._cancelClickHandler);
        }
        $addHandler($get('BtnCancel',this.get_element()),'click',this._cancelClickDelegate);
        if (this._EnterKeyPressedDelegate === null) {
            this._EnterKeyPressedDelegate = Function.createDelegate(this, this._saveClickHandler);
        }
        //Handle Enter Key
        this.add_enterPressed(this._EnterKeyPressedDelegate);
        if (this._catCallbackDelegate === null) {
            this._catCallbackDelegate = Function.createDelegate(this, this._catCallbackHandler);
        }
        if (this._catFailureDelegate === null) {
            this._catFailureDelegate = Function.createDelegate(this, this._catFailureHandler);
        }
        if (this._catChangedDelegate === null) {
            this._catChangedDelegate = Function.createDelegate(this, this._catChangedHandler);
        }
        $addHandler($get("SelCategories",this.get_element()),'change',this._catChangedDelegate);
        if (this._saveSuccessDelegate === null) {
            this._saveSuccessDelegate = Function.createDelegate(this, this._saveSuccessHandler);
        }
        if (this._saveFailureDelegate === null) {
            this._saveFailureDelegate = Function.createDelegate(this, this._saveFailureHandler);
        }
        if (this._critValidDlg === null) {
            this._critValidDlg = Function.createDelegate(this, this._critValidHnd);
        }
        if (this._critFailDlg === null) {
            this._critFailDlg = Function.createDelegate(this, this._critFailHnd);
        }
    },
    updated: function()
    {
		Portal.ClientRSSCollectionSvc.GetCollections(this.get_collType(),this._catCallbackDelegate,this._catFailureDelegate);
        Insp.UI.RssCollEdit.callBaseMethod(this,'updated');
        var tc =  $get("txtCriteria",this.get_element());
        if(tc)tc.value = this.get_criteria();
    },
    _catChangedHandler: function(evt)
    {
		var s = $get("SelCategories",this.get_element());
		var id = s.options[s.selectedIndex].value;
		this._populateCurrentCats(id);
    },
    _populateCurrentCats: function(id)
    {
		var coll = this._findCollFromId(id);
		if(coll)
		{
			var c = $get("categories",this.get_element())
			{
				c.innerHTML = "";
				for(var x =0;x<coll.categories.length;x++)
				{
					var li= document.createElement('LI');
					li.innerHTML = "<input type='checkbox' checked='true' id='"+this.get_module().get_moduleID()+coll.categories[x].id+"' name='"+coll.categories[x].id+"'/>"+
					"<label for="+this.get_module().get_moduleID()+coll.categories[x].id+">"+coll.categories[x].name+"</label>";
					c.appendChild(li);
				}
			}
			if(coll.id == this.get_currColl())
				this._setSelectedCategories(coll);
			var cd = $get("CriteriaDiv",this.get_element());
			if(coll.type && coll.type=="criteria")
				cd.style.display="";
			else
				cd.style.display="none";
		}
    },
    _setSelectedCategories: function(coll)
    {
		var cats = this.get_category().split('|');
		var ips = $get("categories",this.get_element()).getElementsByTagName('input');
		for(var x = 0;x<ips.length;x++)
		{
			ips[x].checked = false;
			for(var y = 0;y<cats.length;y++)
			{
				if(cats[y] == ips[x].name)
				{
					ips[x].checked = true;
				}
			}
		}
    },
    _getSelectedCategories: function()
    {
		var ips = $get("categories",this.get_element()).getElementsByTagName('input');
		var cats = "";
		for(var x = 0;x<ips.length;x++)
		{
			if(ips[x].checked == true)
			{
				if(cats !== "")cats = cats+"|";
				cats = cats+ips[x].name;
			}
		}
		return cats;
    },
    _findCollFromId: function(id)
    {
		if(this._collDetails.colls){
			for(var x=0;x<this._collDetails.colls.length;x++)
			{
				if(this._collDetails.colls[x].id == id)
					return this._collDetails.colls[x];
			}
		}
		if(this._collDetails.groups)
		{
			for(var y in this._collDetails.groups)
			{
				for(var x=0;x<this._collDetails.groups[y].colls.length;x++)
				{
					if(this._collDetails.groups[y].colls[x].id == id)
						return this._collDetails.groups[y].colls[x];
				}
			}
		}
		return null;
    },
    _catCallbackHandler: function(results)
    {
		if(results!= null && (results.groups!=null || results.colls!=null))
		{
			this._collDetails = results;	
			this._populateColls();
		}
    },
    _catFailureHandler: function(res)
    {
    },
    _populateColls: function()
    {
		var s = $get("SelCategories",this.get_element());
		if(s)
		{
			if(this._collDetails.colls)
			{
				this._addColls(s,this._collDetails.colls)
			}
			if(this._collDetails.groups)
			{
				this._addGroups(s,this._collDetails.groups)
			}
			s.value = this._currColl;
			this._populateCurrentCats(this._currColl);
		}
    },
    _addColls: function(par, colls)
    {
		for(var x=0;x<colls.length;x++)
		{
			var o = document.createElement('option');
			o.innerHTML= colls[x].name;
			o.value= colls[x].id;
			par.appendChild(o);
		}
    },
    _addGroups: function(par, groups)
    {
    	for(var x=0;x<groups.length;x++)
		{
			var o = document.createElement('optgroup');
			o.label = groups[x].name;
			par.appendChild(o);
			this._addColls(o,groups[x].colls);
		}
    },
    _showError: function(str)
    {
		var e = $get("errorMessage",this.get_element());
		e.innerHTML = str;
		e.style.display = "";
		
    },
    _hideError: function()
    {
		var e = $get("errorMessage",this.get_element());
		e.innerHTML = "";
		e.style.display = "none";
		
    },
    _saveClickHandler: function(eventObj)
    {
    	var s = $get("SelCategories",this.get_element());
		var collid = s.options[s.selectedIndex].value;
		var cats = this._getSelectedCategories();
		if(!cats || cats == "")
		{
			this._showError(strClientRssCollect_ErrCategory);
			return;
		}

		
		var crit = $get("txtCriteria",this.get_element()).value;
		var coll = this._findCollFromId(collid);
		if(coll.type && coll.type == "criteria")
		{
			Portal.ClientRSSCollectionSvc.ValidateCriteria(crit, this.get_collType(),collid,this._critValidDlg,this._critFailDlg);
			return;
		}
		
		Portal.ClientRSSCollectionSvc.s(collid, cats, crit, this.get_module().get_moduleID(),this._saveSuccessDelegate,this._saveFailureDelegate);
    },
    _critValidHnd: function(result)
    {
		if(result)
		{
			var s = $get("SelCategories",this.get_element());
			var collid = s.options[s.selectedIndex].value;
			var cats = this._getSelectedCategories();
			var crit = $get("txtCriteria",this.get_element()).value;
			Portal.ClientRSSCollectionSvc.s(collid, cats, crit, this.get_module().get_moduleID(),this._saveSuccessDelegate,this._saveFailureDelegate);
		}else{
			this._showError(strClientRssCollect_ErrCriteria);
		}
    },
    _critFailHnd: function(results)
    {
		this._showError(strClientRssCollect_ErrCriteria);
    },
    _cancelClickHandler: function(eventObj)
    {
		var s = $get("SelCategories",this.get_element());
		s.value = this._currColl;
		this._populateCurrentCats(this._currColl);
		var tc =  $get("txtCriteria",this.get_element());
        if(tc)tc.value = this.get_criteria();
        this._hideError();
		this.get_module().set_showEditPart(false);
    },
    _saveSuccessHandler: function(results)
    {
		if(results == "success")
			this.get_module().refreshModule();
    },
	_saveFailureHandler: function(results)
    {
    }    
}

Insp.UI.RssCollEdit.registerClass('Insp.UI.RssCollEdit',Insp.UI.ModuleEditCtl);

Type.registerNamespace("Insp");
Type.registerNamespace("Insp.UI");

Insp.UI.RssColl = function(element)
{
    Insp.UI.RssColl.initializeBase(this,[element]);
    this._url = "";
    this._collType = "";
    this._collection = "";
    this._category = "";
    this._title = "";
    this._collDetails = null;
    this._currColl = null;
    this._actCategory = "";
    this._actView = "";
    this._criteria = "";
    this._showTitle = null;
    
    this._tabStripCtl = null;

	this._catSuccessDlg = null;
	this._catFailureDlg = null;
	this._tabSuccessDlg = null;
	this._tabFailureDlg = null;
	this._urlSuccessDlg = null;
	this._urlFailureDlg = null;
	this._feedCallbackDlg = null;
	this._tabChangeDlg = null;
    this._components = [];
  
}

Insp.UI.RssColl.prototype = {
    get_collType: function(){return this._collType;},
    set_collType: function(value){this._collType = value;this.raisePropertyChanged('collType');},
    
    get_collection: function(){return this._collection;},
    set_collection: function(value){this._collection = value;this.raisePropertyChanged('collection');},
    
    get_category: function(){return this._category;},
    set_category: function(value){this._category = value;this.raisePropertyChanged('category');},
    
    get_url: function(){return this._url;},
    set_url: function(value){this._url = value;this.raisePropertyChanged('url');},
    
    get_actCategory: function(){return this._actCategory;},
    set_actCategory: function(value){this._actCategory = value;this.raisePropertyChanged('actCategory');},
    
    get_actView: function(){return this._actView;},
    set_actView: function(value){this._actView = value;this.raisePropertyChanged('actView');},
    
    get_criteria: function(){return this._criteria;},
    set_criteria: function(value){this._criteria = value;this.raisePropertyChanged('criteria');},
    
    get_showTitle: function(){return this._showTitle;},
    set_showTitle: function(value){this._showTitle = value;this.raisePropertyChanged('showTitle');},
    
    dispose: function()
    {
        Insp.UI.RssColl.callBaseMethod(this,'dispose');
    },
    initialize: function()
    {
        Insp.UI.RssColl.callBaseMethod(this,'initialize');
		this.addCssClass("ptModRSSCollection");
		this.addCssClass("moduleloading");
		if (this._feedCallbackDlg === null) {
            this._feedCallbackDlg = Function.createDelegate(this, this._feedCallbackHnd);
        }
		if (this._catSuccessDlg === null) {
            this._catSuccessDlg = Function.createDelegate(this, this._catSuccessHnd);
        }
        if (this._catFailureDlg === null) {
            this._catFailureDlg = Function.createDelegate(this, this._catFailureHnd);
        }
        if (this._tabSuccessDlg === null) {
            this._tabSuccessDlg = Function.createDelegate(this, this._tabSuccessHnd);
        }
        if (this._tabFailureDlg === null) {
            this._tabFailureDlg = Function.createDelegate(this, this._tabFailureHnd);
        }
        if (this._urlSuccessDlg === null) {
            this._urlSuccessDlg = Function.createDelegate(this, this._urlSuccessHnd);
        }
        if (this._urlFailureDlg === null) {
            this._urlFailureDlg = Function.createDelegate(this, this._urlFailureHnd);
        }
        if (this._tabChangeDlg === null) {
            this._tabChangeDlg = Function.createDelegate(this, this._tabChangeHnd);
        }
    },
    updated: function()
    {
		Portal.ClientRSSCollectionSvc.GetCollections(this.get_collType(),this._catSuccessDlg,this._catFailureDlg);
        Insp.UI.RssColl.callBaseMethod(this,'updated');
    },
    _catSuccessHnd: function(results)
    {
		this.removeCssClass("moduleloading");
		this._collDetails = results;
		this._currColl = this._findCollFromId(this.get_collection());
		if(this._currColl.type && this._currColl.type=="criteria")
		{
			Portal.ClientRSSCollectionSvc.GetCriteriaUrl(this.get_collType(),this.get_collection(),this.get_criteria(),this.get_actCategory(),this._urlSuccessDlg,this._urlFailureDlg);
		}else
		{
			this._populateTabs();
			var cat = this._findCatFromId(this.get_actCategory());
			this._showPanelCtl(cat);
		}
    },
    _catFailureHnd: function(results)
    {
    },
    _urlSuccessHnd: function(result)
    {
		if(result && result !== "")
		{
			this._populateTabs();
			var cat = this._findCatFromId(this.get_actCategory());
			cat.url = result;
			this._showPanelCtl(cat);
		}
    },
    _urlFailureHnd: function(results)
    {
    },
    _feedCallbackHnd: function(results)
    {
		this.removeCssClass("moduleloading");
    },
    _tabChangeHnd: function(sender,args)
    {
		var cat = this._findCatFromId(args.get_currentTab());
		this._showPanelCtl(cat);
		Portal.ClientRSSCollectionSvc.SetActiveCat(cat.id,this.get_module().get_moduleID(),this._tabSuccessDlg,this._tabFailureDlg);
    },
    _tabSuccessHnd: function(results)
    {
		if(results == true)
		{
		}
    },
    _tabFailureHnd: function(results)
    {
    },
    _createPanelCtl: function(cat)
    {
        var oDiv = document.createElement('Div');
		oDiv.id = "rssCollPnl"+cat.id;
		$get('CatPanel',this.get_element()).appendChild(oDiv);   
		var e = $create(Insp.UI.RssCollPanel,{url:cat.url, logo:cat.logo, showLogo:this.get_showTitle()},null,{parent:this.get_id()},oDiv);
		this.addComponent(e); 
    },
    _showPanelCtl: function(cat)
    {
		var ctls = this.getComponents();
		for(var i =0;i<ctls.length;i++)
		{
			ctls[i].set_visible(false);
		}
		var e = this._findPanelCtl(cat.id);
		if(!e)
			this._createPanelCtl(cat);
		else
			e.set_visible(true);
    },
    _populateTabs: function()
    {
		var cats = this.get_category().split('|');
		var ti = [];
		if(cats.length == 1)
		{
			$get("TabStrip",this.get_element()).style.display="none";
			return;
		}
		for(var x =0; x<cats.length ; x++ )
		{
			var cat = this._findCatFromId(cats[x]);
			ti[ti.length] = {"name":cat.name,"value":cat.id};
		}
		this._tabStripCtl = $create(Insp.UI.TabStrip,{items:ti,currentTab:this.get_actCategory()},{tabChanged:this._tabChangeDlg},{parent:this.get_id()},$get("TabStrip",this.get_element()));
    },
    _findCatFromId: function(id)
    {
		for(var x = 0;x<this._currColl.categories.length;x++)
		{
			if(this._currColl.categories[x].id == id)
			{
				return this._currColl.categories[x];
			}
		}
    },
    _findCollFromId: function(id)
    {
		if(this._collDetails.colls){
			for(var x=0;x<this._collDetails.colls.length;x++)
			{
				if(this._collDetails.colls[x].id == id)
					return this._collDetails.colls[x];
			}
		}
		if(this._collDetails.groups)
		{
			for(var y in this._collDetails.groups)
			{
				for(var x=0;x<this._collDetails.groups[y].colls.length;x++)
				{
					if(this._collDetails.groups[y].colls[x].id == id)
						return this._collDetails.groups[y].colls[x];
				}
			}
		}
		return null;
    },
    _findPanelCtl: function(id)
    {
        return this.findComponent('rssCollPnl' + id);
    },
    _clearComponents: function()
    {
        for(var a in this._components)
        {
            delete this._components[a];
        }
    },
    addComponent: function(e)
    {
        if(Sys.Component.isInstanceOfType(e))
            this._components[e.get_id()] = e;
    },
    getComponents: function()
    {
        var a=[];b= this._components;
        for(var c in b)
        {
            a[a.length] = b[c];
        }
        return a;
    },
    findComponent: function(id)
    {
        return this._components[id];
    },
    removeComponent: function(b)
    {
        var a = b.get_id();
        if(a){delete this._components[a];}
    }
}

Insp.UI.RssColl.registerClass('Insp.UI.RssColl',Insp.UI.ModuleContentCtl);

Insp.UI.RssCollPanel = function(element)
{
    Insp.UI.RssCollPanel.initializeBase(this,[element]);
    this._url = "";
    this._logo = ""
    this._showLogo = true;
    this._numStories = 5;
    
    this._articles = null;
    this._paginator = null;
    this._popupCtl = null;
    
    this._components = [];
    
    this._feedSuccessDlg = null;
    this._feedFailureDlg = null;
    this._headlineClickDlg = null;
    this._mainStoryClickDlg = null;
    this._pageChangedDlg = null;
}

Insp.UI.RssCollPanel.prototype = {
    get_url: function(){return this._url;},
    set_url: function(value){this._url = value;this.raisePropertyChanged('url');},
    
    get_logo: function(){return this._logo;},
    set_logo: function(value){this._logo = value;this.raisePropertyChanged('logo');},
    
    get_showLogo: function(){return this._showLogo;},
    set_showLogo: function(value){this._showLogo = value;this.raisePropertyChanged('showLogo');},
    
    get_numStories: function(){return this._numStories;},
    set_numStories: function(value){this._numStories = value;this.raisePropertyChanged('numStories');},
    
    get_PopupCtl: function(){
        if(!this._popupCtl){
            this._createPopupControl()
        }
        return this._popupCtl;
    },

    dispose: function()
    {
		if(this._mainStoryClickDlg) delete this._mainStoryClickDlg;
		if(this._pageChangedDlg) delete this._pageChangedDlg;
		if(this._headlineClickDlg) delete this._headlineClickDlg;
		if(this._feedFailureDlg) delete this._feedFailureDlg;
		if(this._feedSuccessDlg) delete this._feedSuccessDlg;
        Insp.UI.RssCollPanel.callBaseMethod(this,'dispose');
    },
    initialize: function()
    {
        Insp.UI.RssCollPanel.callBaseMethod(this,'initialize');
		this.addCssClass("moduleloading");
		this.addCssClass("ptModRssCollPanel");
		
		this.get_element().innerHTML = $get("rssCollTemplate").innerHTML;
		this.set_visibilityMode(Sys.UI.VisibilityMode.collapse);
		
		$get("LogoImg",this.get_element()).style.display='none';
		$get("MainStory",this.get_element()).style.display='none';
		$get("ArtListCont",this.get_element()).style.display='none';
		
		if (this._feedSuccessDlg === null) {
            this._feedSuccessDlg = Function.createDelegate(this, this._feedSuccessHnd);
        }
        
        if (this._feedFailureDlg === null) {
            this._feedFailureDlg = Function.createDelegate(this, this._feedFailureHnd);
        }
        
        if (this._headlineClickDlg === null) {
            this._headlineClickDlg = Function.createDelegate(this, this._headlineClickHnd);
        }
        
        if (this._pageChangedDlg === null) {
            this._pageChangedDlg = Function.createDelegate(this, this._pageChangedHnd);
        }
         
        if (this._mainStoryClickDlg === null) {
            this._mainStoryClickDlg = Function.createDelegate(this, this._mainStoryClickHnd);
        }
        $addHandler($get("MainHeadlineLink",this.get_element()),'click',this._mainStoryClickDlg);
        $addHandler($get("gotoArticleLink",this.get_element()),'click',this._mainStoryClickDlg);
    },
    updated: function()
    {
		Portal.ClientRSSCollectionSvc.GetArticles(this.get_url(),this._feedSuccessDlg,this._feedFailureDlg);
        Insp.UI.RssCollPanel.callBaseMethod(this,'updated');
    },
    _feedSuccessHnd: function(results)
    {
		this.removeCssClass("moduleloading");
		this._articles = results;
		if(this._articles.length == 0)
			this._showErrorMsg(strClientRssCollect_NoFeedErr);
		else
			this._initPanel();
    },
    _feedFailureHnd: function(results)
    {
		this.removeCssClass("moduleloading");
    },
    _headlineClickHnd: function(sender,args)
    {
		this._showQuickRead(args.get_rssArticle());
    },
    _mainStoryClickHnd: function(sender,evt)
    {
		this._showQuickRead(this._articles[0]);
    },
    _showQuickRead: function(article)
    
    {
        articles = this._articles;
		var pop = this.get_PopupCtl();
        var oDiv = $get(pop.get_PopupControlID()+'_TitleRss');
        oDiv.innerHTML = this.get_parent().get_module().get_moduleTitle();
        var theDiv = $get(pop.get_PopupControlID()+'_PopupContentRss');
        theDiv.innerHTML = "<h2 class='ptRSSStoryHeadline'><a onclick=\"LogClient('1169','portal module');\" href='"+article.StoryUrl+"' target='_blank'>"+
	        article.ArtHeadline + "</a></h2><span class='ptRSSGoToArticleStoryPanel'><a onclick=\"LogClient('1170','portal module');\" href='"+article.StoryUrl+"' target='_blank'>Read full story&gt;</a></span>";
        var divWithL = $get(pop.get_PopupControlID()+'_PopupContentWithLinkRss');
        divWithL.innerHTML = "<br>" + article.RSSFullDetails;     
        //$create(Insp.UI.Rss.RssPanel,{rssTitle:Title.innerHTML,rssUrl:url},null,null,$get('RSSHeadlineList',theDiv));
        $get(pop.get_PopupControlID()+'_HeadlinesList').innerHTML = "";
        var ULEle=$get(pop.get_PopupControlID()+'_HeadlinesList')
        for(i=0;i<articles.length && i < 7;i++)
        {
            if(articles[i].StoryUrl != article.StoryUrl)
            {
                var liEle= document.createElement("li");
                liEle.className="NewsPanelClass";
                liEle.id="NewsItem_"+i;
                ULEle.appendChild(liEle);
                $create(PopupNewsElement,{"article":articles[i],"pop":pop},null,null,liEle);
            }
        }
        LogPageView(634,0,0);
        pop.show();
    },
    _pageChangedHnd: function(sender,args)
    {
		this._updatePageLinks(args.get_currentPage());
    },
    _initPanel: function()
    {
		$get("LogoImg",this.get_element()).style.display='';
		$get("MainStory",this.get_element()).style.display='';
		$get("ArtListCont",this.get_element()).style.display='';
		
		var ld = $get("LogoImg",this.get_element());
		if(this.get_showLogo() && (this.get_logo() !== ""))
		{
			ld.innerHTML = "<img src='"+this.get_logo()+"' class='ptModHeaderImage'/>";
		}else if( this.get_showLogo() && this._articles[0].RSSImagePath !== ""){
			ld.innerHTML = "<img src='"+this._articles[0].RSSImagePath+"' class='ptModHeaderImage'/>";
		}else
			ld.style.display="none";
		$get("MainHeadlineLink",this.get_element()).innerHTML = this._articles[0].ArtHeadline;
		$get("MainArticle",this.get_element()).innerHTML = this._articles[0].ArtDetails;
		this._initLinks();
    },
    _showErrorMsg: function(error)
    {
		var ed = $get("ErrDiv",this.get_element());
		ed.innerHTML = error;
		ed.style.display = "";
    },
    _hideErrorMsg: function(error)
    {
		var ed = $get("ErrDiv",this.get_element());
		ed.innerHTML = "";
		ed.style.display = "none";
    },
    _updatePageLinks: function(pageno)
    {
		for(var i = 1; i<this._articles.length;i++)
		{
			var e = this._findLinkCtl(i);
			if(e)e.set_visible(false);
		}
		var si =  1+ (this.get_numStories() * (pageno-1));
		var ni = 1 + (this.get_numStories() * pageno);
		if(ni > (this._articles.length))ni = this._articles.length;
		for(var i=si;i<ni;i++)
		{
			var e = this._findLinkCtl(i);
			if(e)e.set_visible(true);
		}
    },
    _initLinks:function()
    {
		for(var i = 1; i<this._articles.length;i++)
		{
			if(!this._findLinkCtl(i))this._createLinkCtl(i,this._articles[i]);
		}
		var e = $create(Insp.UI.Paginator,{currentPage:1, itemsPerPage:this.get_numStories(),totalItems:this._articles.length-1,numPageLinks:5},{pageChanged:this._pageChangedDlg},{parent:this.get_id()},$get('PaginateDiv',this.get_element()));
		this._updatePageLinks(1);
    },
    _createLinkCtl:function(id,article)
    {
        var oDiv = document.createElement('DIV');
		oDiv.id = "rssCollHLItem"+id;
		$get('ArticleList',this.get_element()).appendChild(oDiv);   
		var e = $create(Insp.UI.RssCollHeadlineItem,{rssArticle:article},{clicked:this._headlineClickDlg},{parent:this.get_id()},oDiv);
		this.addComponent(e); 
    },
    _findLinkCtl:function(id)
    {
        return this.findComponent('rssCollHLItem' + id);
    },
    _createPopupControl:function()
    {
        var el = Insp.UI.PopupHelper.getGenericPopupElementRss(this.get_parent().get_module().get_moduleID()+this.get_id()+'_Popup');
        el.className = 'Popup_Frame';
        this._popupCtl = $create(AjaxControlToolkit.ModalPopupBehavior,{"id":this.get_parent().get_module().get_moduleID()+this.get_id()+'_PopupBehavior',"BackgroundCssClass":"MBD","CancelControlID":el.id+'_PopupCancelImageRss',"PopupControlID":el.id}, null, null, $get(el.id+'_TitleRss'));
        
    },
    addComponent:function(e)
    {
        if(Sys.Component.isInstanceOfType(e))
            this._components[e.get_id()] = e;
    },
    getComponents:function()
    {
        var a=[];b= this._components;
        for(var c in b)
        {
            a[a.length] = b[c];
        }
        return a;
    },
    findComponent:function(id)
    {
        return this._components[id];
    },
    removeComponent:function(b)
    {
        var a = b.get_id();
        if(a){delete this._components[a];}
    }
}

Insp.UI.RssCollPanel.registerClass('Insp.UI.RssCollPanel',Sys.UI.Control,Sys.IContainer);

Insp.UI.RssCollHeadlineItem = function(element)
{
    Insp.UI.RssCollHeadlineItem.initializeBase(this,[element]);
	
	this._rssArticle = null;
    this._clickDelegate = null;
}

Insp.UI.RssCollHeadlineItem.prototype = {
	
    get_rssArticle: function(){return this._rssArticle;},
    set_rssArticle: function(value){this._rssArticle = value;this.raisePropertyChanged('rssArticle');},
    
    add_clicked: function(handler){this.get_events().addHandler('clicked',handler);},
    remove_clicked: function(handler){this.get_events().removeHandler('clicked',handler);},
    
    dispose: function()
    {
        if(this._clickDelegate) delete this._clickDelegate;
        $removeHandler($get('headlineLink',this.get_element()), 'click',this._callbackDelegate);
        
        Insp.UI.RssCollHeadlineItem.callBaseMethod(this,'dispose');
    },
    initialize: function()
    {
        Insp.UI.RssCollHeadlineItem.callBaseMethod(this,'initialize');
        
        //Construct More Stories
		var moreStories = $get('moreStories',this.get_element());
        
		this.get_element().innerHTML = "<span class='ptBulletContainer'><span class='ptModBullet'></span></span><span class='ptBulletText'><a class='RssHeadline' id='headlineLink'></a></span>";
		this.addCssClass("ptRSSHeadline");
		
		this.set_visibilityMode(Sys.UI.VisibilityMode.collapse);
		this.set_visible(false);
		
        if (this._clickDelegate === null) {
            this._clickDelegate = Function.createDelegate(this, this._clickHandler);
        }
        
        $addHandler($get('headlineLink',this.get_element()),'click',this._clickDelegate);
				
		$get('headlineLink',this.get_element()).innerHTML = this._rssArticle.ArtHeadline;
    },
    updated: function()
    {
        Insp.UI.RssCollHeadlineItem.callBaseMethod(this,'updated');
    },
    _clickHandler: function(result)
    {
        LogClient('922','portal module');
        var args = new Insp.UI.RssCollHeadlineClickArg(this.get_rssArticle());
        var f = this.get_events().getHandler('clicked');
        if(f)f(this,args);
    }
}

Insp.UI.RssCollHeadlineItem.registerClass('Insp.UI.RssCollHeadlineItem',Sys.UI.Control);




Insp.UI.RssCollHeadlineClickArg = function(rssArticle)
{
    Insp.UI.RssCollHeadlineClickArg.initializeBase(this);
    this._rssArticle = rssArticle;
}
Insp.UI.RssCollHeadlineClickArg.prototype = 
{
    get_rssArticle: function(){return this._rssArticle;},
    set_rssArticle:function(value){this._rssArticle = value;}
}
Insp.UI.RssCollHeadlineClickArg.registerClass("Insp.UI.RssCollHeadlineClickArg", Sys.EventArgs);


PopupNewsElement = function(element)
{
    PopupNewsElement.initializeBase(this,[element]);
    this._article =null;
    this._callbackDelegate = null;
    this._pop = null;
    this._ArticleSuccessDelegate = null;
}

PopupNewsElement.prototype =
{
        get_article: function(){return this._article;},
        set_article: function(value){this._article = value;this.raisePropertyChanged('article');},
        get_pop: function(){return this._pop;},
        set_pop: function(value){this._pop = value;this.raisePropertyChanged('pop');},
        
        initialize: function() 
        {
            PopupNewsElement.callBaseMethod(this,'initialize');
            this.get_element().innerHTML = '<span class="ptBulletContainer"><span class="ptModBullet"></span></span><span style="cursor:pointer;text-decoration:underline;color:blue;" id="RSSPopupLink">'+this._trimContentString(this._article.ArtHeadline)+ '</span>';
            if (this._callbackDelegate === null) {
               this._callbackDelegate = Function.createDelegate(this, this.callbackHandler);
            }
            
            if (this._ArticleSuccessDelegate === null) {
               this._ArticleSuccessDelegate = Function.createDelegate(this, this._ArticleSuccessHandler);
            }
            
            $addHandler($get('RSSPopupLink',this.get_element()),'click',this._callbackDelegate);
            
        },
       _trimContentString: function(str)
       {
            if(str.length<70)
                return str;
            var sub = str.substr(0,70);
            var idxSpace = sub.lastIndexOf(' ');
            sub = sub.substr(0,idxSpace) + "&#8230;";
            return sub;
       },
        _ArticleSuccessHandler:function(args)
        {
            if(args.indexOf('|') > 0)
            {
                var stArgs = args.split('|');
                details = stArgs[0];
                divWithLink = stArgs[1];
                link = stArgs[2];
            }
        
            var theDiv = $get(this._pop.get_PopupControlID()+'_PopupContentRss');
            theDiv.innerHTML = details;
            var divWithL = $get(this._pop.get_PopupControlID()+'_PopupContentWithLinkRss');
            divWithL.innerHTML = divWithLink;

        },
        dispose:function()
        {
            PopupNewsElement.callBaseMethod(this,'dispose');
        },
        updated:function()
        {
            
            PopupNewsElement.callBaseMethod(this,'updated');
        },
        callbackHandler:function()
        {
            var divWithL = $get(this._pop.get_PopupControlID()+'_PopupContentWithLinkRss');
            divWithL.innerHTML = "<div class='NHLoading' style='width:100%;height:280px'></div>";          
            Portal.ClientRssSvc.GetArticle(this._article.RSSArticleID,this._ArticleSuccessDelegate);
            LogPageView(634,0,0);
        }    
}
PopupNewsElement.registerClass('PopupNewsElement',Sys.UI.Control);
