﻿  $(function() {                                   
            $.getJSON(newBloggerURL,
            function(data) {
            document.getElementById("homeRecentPosts1").innerHTML = "";  
            document.getElementById("homeRecentPosts2").innerHTML = "";
            document.getElementById("homeRecentPosts3").innerHTML = "";          
            var i = 0;        
                         
                $.each(data.feed.entry, function(i, postentry) {
                   i++;
                
                    var posttitle = postentry.title.$t;
                    var postsummary = postentry.content.$t; 
                    var postdate = postentry.published.$t;      
                    var month = postdate.substr(5,2);
				    var year = postdate.substr(0,4);
				    var day = postdate.substr(8,2);
				    var title = GetTitleForURL(posttitle); //posttitle.substring(0,GetSpecifiedChars(posttitle,50));
				    //title = ReplaceSpecialChars(title);
				    				         
                    var strSummary = postsummary.stripHTML(); 
                    var len = GetSpecifiedChars(strSummary,200);    
                    strSummary = strSummary.substring(0,len);       
                    
                    if(i==1){                    
                    document.getElementById("homeRecentPosts1").innerHTML += "<h3 class='noSpT'>" + posttitle + "</h3>";					
                    document.getElementById("homeRecentPosts1").innerHTML += "<p class='noSpB'>" + strSummary + "...</p><p align='right' class='noSpB'><a href='/blog/" + year + "/" + month + "/" + title + ".asp'>READ MORE &raquo;</a></p>";                        
                    }
                    else if(i==2){
                    document.getElementById("homeRecentPosts2").innerHTML += "<h3 class='noSpT'>" + posttitle + "</h3>";					
                    document.getElementById("homeRecentPosts2").innerHTML += "<p class='noSpB'>" + strSummary + "...</p><p align='right' class='noSpB'><a href='/blog/" + year + "/" + month + "/" + title + ".asp'>READ MORE &raquo;</a></p>";
                    }
                    else if(i==3){
                    document.getElementById("homeRecentPosts3").innerHTML += "<h3 class='noSpT'>" + posttitle + "</h3>";					
                    document.getElementById("homeRecentPosts3").innerHTML += "<p class='noSpB'>" + strSummary + "...</p><p align='right' class='noSpB'><a href='/blog/" + year + "/" + month + "/" + title + ".asp'>READ MORE &raquo;</a></p>";
                    }
                });                
                
            });
        });
        
        
        
String.prototype.stripHTML = function()
{
        // What a tag looks like
        var matchTag = /<(?:.|\s)*?>/g;
        // Replace the tag
        return this.replace(matchTag, "");
};

function GetSpecifiedChars(str,len)
{
 var newlen = len;
 var i; 
 var endLen = 250;    
  for(i=200;i<=210;i++)
  {    
       if(str.charAt(i) == " ")
       {
       newlen = i;
       break;
       }
  }
 return newlen;
} 

function ReplaceSpecialChars(str)
{
 var newStr = str;
 newStr =  str.replace(/[^a-zA-Z 0-9]+/g,'');
 return newStr;
}

function GetTitleForURL(urlTitle)
{
   //Remove Special characters 
   urlTitle =  urlTitle.replace(/[^a-zA-Z 0-9]+/g,'');
   
   //Replace any "-" by ""
   urlTitle = urlTitle.replace(/-/g, "");
   
   //Replace spaces by "-"
   urlTitle = urlTitle.replace(/ /g, "-");
   
   //Replace "--" by "-"
   urlTitle = urlTitle.replace(/--/g, "-");
   
   //alert(urlTitle)
   
   if(urlTitle.length > 50){   
   //var endPos = urlTitle.indexOf("-",45);   
   urlTitle = urlTitle.substring(0,45);
   }
      
   urlTitle = urlTitle.toLowerCase();
   //alert(urlTitle);
   return urlTitle;
}
        
        



