// Javsacript helper functions for RapidBlog

// javscript to list comments out to make it mo-faster
function listComments(root) {
	var feed = root.feed;
	
	var entries = feed.entry || [];
	var html = [];
	
	
	if (!feed.entry)
		return;
	//$t = "tag:blogger.com,1999:blog-4270442078467138119.post2447883094318407169..comments"
	
	var re=/post([0-9]+)/i
		var joe=re.exec(feed.id.$t);
	var myId=joe[1];
	
	//2007-01-01T22:58:00.000-08:00
	dateRe=/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):\d{2}.\d{3}/;
	
	
	
	if (showComments==1) {
		
		/* Moo Foo 
		html.push('<a href="#" onclick="javascript:expand(',myId,')>Expand Comments</a>');
*/
		html.push('<div class="blog-entry-comments-body">');
		
		// reverse the comments if requested
		if (reverseCommentEntries==1)
			feed.entry.reverse();	
		
		for (var i = 0; i < feed.entry.length; ++i) {
			if ((i%2)==0)
				html.push('<br class="blog-entry-comments-break"/> <div class="blog-entry-comments-body-even">');
			else
				html.push('<br class="blog-entry-comments-break"/> <div class="blog-entry-comments-body-odd">');
			
			var entry = feed.entry[i];
			var title = entry.title.$t;
			var published=entry.published.$t;
			var dateArray=dateRe.exec(published);
			var thisDate=new Date(dateArray[1],dateArray[2]-1,dateArray[3],dateArray[4],dateArray[5],0)
				// var start = entry['gd$when'][0].startTime;
				var content = entry.content.$t;
			
			// Figure out the author & a web page if given one
			var URI=null;
			var author=null;
			
			author = entry.author[0].name.$t;
			
			if (entry.author[0].uri)
				var URI= entry.author[0].uri.$t;
			if (URI!=null)  {
				var httpRe=/http:\/\//;
				if (!httpRe.exec(URI)) { // if they didn't give a leading HTTP then we need to add one.
					URI="http://"+URI;
				}
				author="<a href='"+URI+"'>"+author+"</a>";
			}
			html.push(author, ' said .... <br />', '<div>', content, ' </div> ',thisDate.toLocaleString(),'</div> </div>');
			
		}
		
}



document.getElementById("comment_"+myId).innerHTML += html.join("");
}



