function blogFeed(urlSource, size, descrLength, displayDate, displayAuthor, style, targetDiv) {
	showBlogWait(targetDiv);
	var url = encodeURIComponent(urlSource);
	var time = getBlogTime();
	var params = 'source=' + url + "&size=" + size + "&desc=" + descrLength + "&displayDate=" + displayDate + "&displayAuthor=" + displayAuthor + "&style=" + style + '&time' + time;
	var contextPath= "";
	if(window.contextPath) contextPath = window.contextPath;
	
	new Ajax.Request(
		contextPath + 'ajaxBlogs.jsp',
		{
			method: 'get',
			parameters: params,
			onComplete: function(response) {
				processBlogFeedResponse(response, targetDiv);
			}
		});
}

function getBlogTime() {
	var now = new Date();
	var hour        = now.getHours();
	var monthnumber = now.getMonth()+1;
	var monthday    = now.getDate();
	var year        = now.getYear()+1900;

	var datetime = year+''+monthnumber+''+monthday+''+hour;
	return datetime;
}

function processBlogFeedResponse(req, targetDiv) {
	var xmlDoc = req.responseXML;
	if(xmlDoc == null){
		processBlogError(targetDiv);
		return;
	}
	var result;

    try {
		var resultTag=xmlDoc.getElementsByTagName("result");
		result = resultTag[0].firstChild.nodeValue;
		if (result.length == 0) processBlogError(req, xmlDoc);
	} catch (err){
		processBlogError(targetDiv);
		return;
	}
	
	$(targetDiv).innerHTML = result;
}						

function processBlogError(targetDiv) {
	var results = "<p>We are unable to access the blogs, please try again later</p>";
	$(targetDiv).innerHTML = results;
}

function showBlogWait(targetDiv) {
	var contextPath= "";
	if(window.contextPath) contextPath = window.contextPath;
	var html=new StringBuffer();
	html.append("<p><img src='");
	html.append(contextPath);
	html.append("http://www.sybase.co.ma/images/indicator.gif' alt='Processing' /> Retrieving blog data...</p>");
	
	$(targetDiv).innerHTML = html.toString();
}

function StringBuffer() { 
	   this.buffer = []; 
}

StringBuffer.prototype.append = function append(string) { 
   this.buffer.push(string); 
   return this; 
}; 

StringBuffer.prototype.toString = function toString() { 
   return this.buffer.join(""); 
};