var mIntervalID,mSelectedFeeds,mCurrentFeed="",dontReOrder=false,mLoginConfirmed=false,mRefreshing=false,mAjaxCompletionCount=0,hiddenLoaderCount=0;$(document).ready(function(){mIntervalID=window.setInterval("postBack()",1.8e6);$("ul.tabs").children().each(function(){$(this).removeClass("tab-on")});$("ul.tabs").children(":first").addClass("tab-on");$.ajaxSetup({type:"post",contentType:"application/json; chrset-utf-8",dataType:"json"});$('[id$="btnSearch"]').click(function(a){a.preventDefault();performSearch()});$('[id$="ClearSearch"]').click(function(a){a.preventDefault();clearSearch()});$('[id$="lnkSave"], [id$="imgSave"]').click(function(a){a.preventDefault();saveFeedSelections()});$("#divMessage").dialog({autoOpen:false,title:"You Are Not Logged In!",buttons:{Yes:function(a){a.preventDefault();mLoginConfirmed=true;storeSelectedFeeds(true);window.location="login"},No:function(a){a.preventDefault();mLoginConfirmed=false;$(this).dialog("close")}},close:function(){if(!mLoginConfirmed)if(mCurrentFeed!=null&&mCurrentFeed.length>0){$("#"+mCurrentFeed).removeAttr("checked");mCurrentFeed=""}},closeOnEscape:false,open:function(){$(".ui-dialog-titlebar-close").hide()},closeText:"",dialogClass:"alert",draggable:false,modal:true,resizable:false});$("#divStarPosts").dialog({autoOpen:false,title:"You Are Not Logged In!",buttons:{Yes:function(a){a.preventDefault();window.location="login"},No:function(a){a.preventDefault();$(this).dialog("close")}},close:function(){$(this).dialog("close")},closeOnEscape:false,open:function(){$(".ui-dialog-titlebar-close").hide()},closeText:"",dialogClass:"alert",draggable:false,modal:true,resizable:false});$("div.search-noresults").show();$("div.search-results").hide();$(this).ajaxComplete(function(c,b,a){if(a.url.indexOf("getFeedInfo")>0){if(mAjaxCompletionCount<$('input[name$="chkFeed"]:checked').length)mAjaxCompletionCount++;if(mAjaxCompletionCount==$('input[name$="chkFeed"]:checked').length){$("div."+(mRefreshing?"refreshing":"loading")).remove();mAjaxCompletionCount=0}}$("a.tooltip[href]").qtip({position:{my:"bottom right",at:"top left"}})});$.ajax({url:"/default.aspx/getLogonStatus",data:JSON.stringify({}),success:function(a){if(!a.d){$("#searchMessage").dialog({autoOpen:false,title:"Want More Results?",buttons:{Yes:function(a){a.preventDefault();mLoginConfirmed=true;storeSelectedFeeds(true);window.location="login"},No:function(a){a.preventDefault();mLoginConfirmed=false;$(this).dialog("close")}},closeOnEscape:false,open:function(){$(".ui-dialog-titlebar-close").hide()},closeText:"",dialogClass:"alert",draggable:false,modal:true,resizable:false});$("#searchMessage .login-message").text("Do you want to login now?")}else $("#searchMessage").dialog({autoOpen:false,title:"Want more results?",buttons:{OK:function(){$("#searchMessage").dialog("close")}},close:function(){if(!mLoginConfirmed)if(mCurrentFeed!=null&&mCurrentFeed.length>0){$("#"+mCurrentFeed).removeAttr("checked");mCurrentFeed=""}},closeOnEscape:false,open:function(){$(".ui-dialog-titlebar-close").hide()},closeText:"",dialogClass:"alert",draggable:false,modal:true,resizable:false});mUserLoggedIn=a.d;mSelectedFeeds==null&&$.ajax({url:"/default.aspx/getSelectedFeeds",data:JSON.stringify({}),success:function(a){mSelectedFeeds=a.d;getFeeds()},async:false});if(mUserLoggedIn){$.ajax({url:"/default.aspx/getSaveFeedsStatus",data:JSON.stringify({}),success:function(a){a.d&&saveFeedSelections()}});$("#reChkAll").show()}else $("#reChkAll").hide()}});SetupStockTicker()});function notifyUser(){var a=mRefreshing?"refreshing":"loading",b=mRefreshing?"Refreshing Feeds...":"Loading Feeds...";if($(".loading").size()==0){$('<div class="'+a+'">'+b+"</div>").insertBefore("h3").toggle("pulsate",1e3);setInterval(function(){$("p."+a).toggle("pulsate",1e3)},2e3)}}function getFeeds(){storeSelectedFeeds(true);setFeedDivVisibility();clearSearch()}function setFeedDivVisibility(){var a=$('input[name$="chkFeed"]:checked').size();while($(".rssLinks").size()<a)createFeedDiv();$(".rssLinks").each(function(b){if(b>a-1){$(this).empty();$(this).hide()}else $(this).show()})}function storeSelectedFeeds(b){var a=new Array($("input:checkbox").size());$("input:checkbox").each(function(b){if($(this).attr("checked")=="checked")a[b]=true;else a[b]=false});if(b){var c={SelectedFeeds:a};$.ajax({url:"/default.aspx/cacheSelectedFeeds",data:JSON.stringify(c)})}else mSelectedFeeds=a}function postBack(){storeSelectedFeeds(false);var a={Refresh:true};$.ajax({url:"/default.aspx/SetRefreshStatus",data:JSON.stringify(a)});$("form").submit()}function stopInterval(){window.clearInterval(mIntervalID)}function createFeedDiv(){notifyUser();$(".rssLinks:last").clone().empty().insertAfter($(".rssLinks:last"));var a=$(".rssLinks:last").attr("id").slice(-2);if(isNaN(a))a=$(".rssLinks:last").attr("id").slice(-1);$(".rssLinks:last").attr("id","FeedContent"+ ++a)}function performSearch(){if(!mUserLoggedIn){$(".reminder-container").hide();$(".search-message").html("Power Search scans your selected sources. Login to select more sources to enable more results.");$("p.login-message").html("Do you want to login now?")}if($('[id$="txtSearch"]').val().length>0){clearSearch();$("div.search-noresults").hide();$("div.search-results").show();$('<p class="searching">Searching....</p>').insertBefore("ul.SearchResults").toggle("pulsate",2e3);$(".rssLinks a").each(function(){$(this).removeHighlight().highlight($('[id$="txtSearch"]').val())});$("span.highlight").each(function(){var b=$("<li>",{html:$(this).parent().clone()}).appendTo("ul.SearchResults"),a=$(this).parent().parent().parent().parent().siblings("div.feed-name-container").children(":first").text();a+=" - "+$(this).parent().siblings("span.date").text();b.append("<br>"+a+"&nbsp;");var c=$(this).parent().siblings(".StarPost").clone();b.append(c)});$("ul.SearchResults li").each(function(){$(this).html($(this).html().replace("gotoFeed","gotoSearch"))});storeSearchTerms();$("div.search-results p").remove();$("ul.SearchResults li").length==0&&$("<p>No matches found.</p>").insertBefore("ul.SearchResults")}else return false;var a=$(".feed-container").length;if(a<6&&$.cookie("dontremind")==null){if(a!=1)$("#search-count").text(a+" news sources");else $("#search-count").text(a+" news source");$("#searchMessage").dialog("open")}}setInterval(function(){$("#dontremind").is(":checked")&&$.cookie("dontremind",true,{expires:365})},500);function clearSearch(){$("div.search-noresults").show();$("div.search-results").hide();$(".rssLinks a").each(function(){$(this).removeHighlight()});$("ul.SearchResults").empty();$("div.search-results p").remove()}function storeSearchTerms(){var b=[];$("div[data-feedName]").each(function(){b.push($(this).attr("data-feedName"))});var a=$('[id$="txtSearch"]').val();if(a.length>0)LogAction("Search","Search",a);else return false;$.ajax({url:"Default.aspx/SaveSearchResults",contentType:"application/json;charset=utf-8",data:JSON.stringify({searchTerm:a,feedNames:b})})}function postClicked(a,b){var c={FeedName:b};if(b.length>0){c={SearchResults:""};$.ajax({url:"Default.aspx/cacheSearchResults",data:JSON.stringify(c)})}$.cookie(a,a,{expires:365});$.ajax({url:"Feeds.asmx/setPostURLFeed",data:JSON.stringify({FeedName:b,PostURL:a}),success:function(){showPost(a)},error:function(a){alert(a)}})}function showPost(a){a=a.replace("http://","");window.location="post/"+a}function saveFeedSelections(){var a;if(mUserLoggedIn){var b=new Array($("input:checked").size());$("input:checked").each(function(a){b[a]=$(this).next().text()});a={SelectedFeeds:b};$.ajax({url:"/default.aspx/saveFeedSelections",data:JSON.stringify(a),success:function(){$('[id$="imgSaveComplete"]').show("fast");window.setTimeout(function(){$('[id$="imgSaveComplete"]').hide("slow")},1e4)}})}else{a={SaveFeeds:true};$.ajax({url:"/default.aspx/setSaveFeedsStatus",data:JSON.stringify(a),async:false});$("#pViewFeeds").hide();$("#pSaveFeeds").show();$("#divMessage").dialog("open")}}function updateVisitedLinks(){$("a.Link").each(function(){lURL=$(this).attr("data-feedUrl");$.cookie(lURL)!=null&&$(this).addClass("visited")})}$(document).ready(function(){function h(a,b){return parseInt($(a).attr("data-orderNumber"))-parseInt($(b).attr("data-orderNumber"))}function a(){if(!dontReOrder){var a=$(".rssLinks");a.sort(h);$.each(a,function(b,a){$("#feed-box-wrapper").append(a)})}}var e=false;$.ajax({url:"/default.aspx/getLogonStatus",data:JSON.stringify({}),success:function(a){e=a.d}});function i(c,a){var b=$("input[data-fname='"+c+"']").val();a(b)}notifyUser();this.OpenNonLoggedUserMessage=function(){$("#divStarPosts").dialog("open")};$("img.StarPost").live("click",function(){var d,g=$(this),k=$(this).attr("data-StrImg"),e=$(this).attr("data-feedName"),i=$(this).attr("data-feedTitle"),j=$(this).attr("data-feedUrl"),a=$(this).attr("data-FeedId"),b=$(this).attr("data-ItemDate"),c=$(this).attr("data-StarID"),h=$(this).attr("data-SourceIcon");if(a==undefined)a=0;if(b==undefined)b="";if(c==undefined)c=0;$.ajax({url:"/default.aspx/getLogonStatus",data:JSON.stringify({}),success:function(l){d=l.d;if(!d)f.OpenNonLoggedUserMessage(function(){});else{var m={StarId:c,Title:i,URL:j,SourceIcon:h,FeedGroupId:a,PostDate:b},k="Default.aspx/StarUnStarPosts";$.ajax({url:k,type:"POST",data:JSON.stringify(m),contentType:"application/json;charset=utf-8",success:function(a){if(a.d==0){g.attr("src","style/images/bulletstar-on.png");LogAction("Starred","Select",e)}else if(a.d==1){g.attr("src","style/images/bulletstar-off.png");LogAction("Starred","De-Select",e)}}})}}})});$(".select-item").each(function(){if($(this).find("input[type=checkbox]").is(":checked")){var b=$($(this).find("input[type=hidden]")[2]).val(),c=$($(this).find("input[type=hidden]")[3]).val();dontReOrder=true;$.ajax({contentType:"application/json;charset=utf-8",data:JSON.stringify({feedName:b,FeedId:c}),url:"/default.aspx/GetFeed",type:"POST",success:function(c){c=c.d;var d=$("#feed-box-template").tmpl(c);if(c.FeedItems.length==0)$("<p style='color:Gray;font-size:14px;text-align:center'>This news source is currently unavailable.</p>").insertBefore($(d).find("ul"));else $.each(c.FeedItems,function(c,a){a.FeedName=b;$("#feed-item-template").tmpl(a).appendTo($(d).find("ul"))});$("#feed-box-wrapper").append(d);dontReOrder=false;a();dontReOrder=true;updateVisitedLinks()}})}});setTimeout(function(){$("div.loading").hide()},3e3);$("input[type=checkbox]:not(:checked)").length==0&&$("#chkAll").text("uncheck all news sources");var d=false;$("#chkAll").click(function(){d=true;if($(this).text()=="check all news sources"){$(".select-item input[type=checkbox]").not(":first").removeAttr("checked");$(".select-item input[type=checkbox]").change();$(".select-item input[type=checkbox]").attr("checked","checked");$(".select-item input[type=checkbox]").change();var a=$(".select-item input[type=checkbox]").size();hiddenLoaderCount=$(".select-item input[type=checkbox]").size();$(this).text("uncheck all news sources");!e&&$("div.loading").hide()}else{$(".select-item input[type=checkbox]").not(":first").removeAttr("checked");$(".select-item input[type=checkbox]").change();$(this).text("check all news sources")}});setTimeout(function(){$(".select-item input[type=checkbox]").not(":checked").size()==0&&$("#chkAll").text("uncheck all news sources")},2e3);$(".select-item input[type=checkbox]").click(function(){d=false});var b,g,j,f=this;this.RefreshFeeds=function(){$.ajax({contentType:"application/json;charset=utf-8",data:JSON.stringify({}),url:"/default.aspx/GetDefaultFeedsListForUser",success:function(a){b=a.d;f.RecheckFeeds()}})};this.RecheckFeeds=function(){b!=undefined&&$.each(b,function(b,a){g=a.FeedName;$("input:checkbox").each(function(){if($(this).next().text()==g){$(this).attr("checked","checked");$(this).change();return false}})})};$("#reChkAll").click(function(){$(".select-item input[type=checkbox]").each(function(){if($(this).attr("checked")=="checked"&&$(this).attr("disabled")!="disabled"){$(this).removeAttr("checked");$(this).change()}});f.RefreshFeeds(function(){})});var c=0;$(".select-item input[type=checkbox]").change(function(){dontReOrder=true;var f=this,b=$($(this).siblings("input[type=hidden]")[2]).val(),g=$($(this).siblings("input[type=hidden]")[3]).val();i(b,function(j){if(j=="true"&&!e){$(f).removeAttr("checked");$("#divMessage").dialog("open")}else{$("div.loading").size()<1&&notifyUser();$("div.loading").size()>1&&$("div.loading").not(":first").remove();if($(f).is(":checked")){LogAction("Feeds","Add",b);var h={feedName:b,FeedId:g};$.ajax({contentType:"application/json;charset=utf-8",data:JSON.stringify(h),url:"/default.aspx/GetFeed",type:"POST",success:function(e){if(d)c++;e=e.d;var f=$("#feed-box-template").tmpl(e);if(e.FeedItems.length==0)$("<p style='color:Gray;font-size:14px;text-align:center'>This news source is currently unavailable.</p>").insertBefore($(f).find("ul"));else $.each(e.FeedItems,function(c,a){a.FeedName=b;$("#feed-item-template").tmpl(a).appendTo($(f).find("ul"))});if(c>=hiddenLoaderCount-1){c=0;setTimeout(function(){$(".loading").fadeOut(300,function(){$(this).remove()})},500)}$("#feed-box-wrapper").append(f);dontReOrder=false;a();dontReOrder=true}})}else{LogAction("Feeds","Remove",b);var i="'[data-feedName=\""+b+"\"]'";$(i).remove();a();$("div.loading").remove()}}})});setInterval(function(){a()},500)});function gotoFeed(b,a){var c={name:b,url:a,PostRequestMode:"ViewPost"};$.cookie(a,a,{expires:365});$.ajax({url:"Default.aspx/GoToFeed",type:"POST",data:JSON.stringify(c),contentType:"application/json;charset=utf-8",success:function(){location.href="/post/"+a}})}function gotoSearch(c,a){var b={url:a,name:c,PostRequestMode:"Search"};$.cookie(a,a,{expires:365});$.ajax({url:"Default.aspx/GoToFeed",type:"POST",data:JSON.stringify(b),contentType:"application/json;charset=utf-8",success:function(){location.href="/post/"+a}})}
