function imGetParameter(sParamName) {
	var sQueryString = "";
	var iStart = 0;
	var iEnd = 0;
	if (window.top.location.search != 0)
		sQueryString = unescape(window.top.location.search);
	sParamName = sParamName + "=";
	if (sQueryString.length > 0) {
		iStart = sQueryString.indexOf(sParamName);
		if ( iStart != -1 ) {
			iStart += sParamName.length;
			iEnd = sQueryString.indexOf("&",iStart);
			if (iEnd == -1)
				iEnd = sQueryString.length;
			return sQueryString.substring(iStart,iEnd);
		}
		return null;
	}
	return null;
}

function imBlogAlert() {
	alert(imBLang[30]);
	return false;
}

function imBlogShowPost(id,ext,bFirst) {
  var bp = imBPosts[id];
	document.write("	<div class=\"imBlogPostTitle\">" + bp['title'] + "</div>\n");
	document.write("	<div class=\"imBlogPostDetails\">" + imBLang[0] + " <strong>" + bp['author'] + "</strong> " + imBLang[1] + " <a class=\"ImLink\" href=\"?category=" + bp['category'] + "\">" + imBCatName[bp['category']] + "</a> &#149; " + bp['timestamp'] + "</div>\n");
	if(ext != 0 || bFirst)
		document.write("	" + bp['body'] + "\n");
  else
	  document.write("	" + bp['summary'] + "<br />\n");
  if(ext == 0 || bFirst)
    document.write("	" + "<div class=\"imBlogPostRead\"><a class=\"ImLink\" href=\"?id=" + id + "\">" + imBLang[2] + " &#187;</a></div>");
	if(ext != 0)
		document.write("	<br /><br /><div class=\"imBlogPostFooHTML\">" + bp['foo_html'] + "</div>\n");
	if(ext != 0 && bp['comments'] != 0) {
		document.write("	<div class=\"imBlogComments\">\n");
		document.write("	<div class=\"imBlogCommentsForm\">\n");
		document.write("		<form action=\"#\" method=\"post\" onsubmit=\"return imBlogAlert()\">\n");
		document.write("			<input type=\"hidden\" name=\"post\" value=\"" + id + "\" />\n");
		document.write("			<label>" + imBLang[6] + "*</label> <input type=\"text\" id=\"form_name\" name=\"name\" /><br />\n");
		document.write("			<label>" + imBLang[7] + "*</label> <input type=\"text\" id=\"form_email\" name=\"email\" /><br />\n");
		document.write("			<label>" + imBLang[8] + "</label> <input type=\"text\" id=\"form_url\" name=\"url\" /><br />\n");
		document.write("			<label>" + imBLang[9] + "*</label> <textarea id=\"form_body\" name=\"body\"></textarea><br />\n");
		document.write("			<input type=\"submit\" value=\"" + imBLang[10] + "\" />\n");
		document.write("		</form>\n");
		document.write("	</div>\n");
		document.write("	</div>\n");
	}
}

function imBlogShowCategory(category) {
	var bps = imBCat[category];
	if(bps instanceof Array) {
		for(i = bps.length-1; i >= 0; i--)
			imBlogShowPost(bps[i],0,(i==bps.length-1? true:false));
	}
	else
		document.write("<div class=\"imBlogEmpty\">Empty category</div>\n");
}

function imBlogShowMonth(month) {
	var bps = imBMonths[month];
	if(bps instanceof Array) {
		for(i = bps.length-1; i >= 0; i--)
			imBlogShowPost(bps[i],0,(i==bps.length-1? true:false));
	}
	else
		document.write("<div class=\"imBlogEmpty\">Empty month</div>\n");
}

function imBlogShowLast(count) {
	var i = 0;
	var bps = Array();
	for(key in imBPosts)
		bps[i++] = key;
	if(bps instanceof Array)
		for(i = bps.length-1; i >= (bps.length-count > 0 ? bps.length-count : 0); i--)
			imBlogShowPost(bps[i],0,(i==bps.length-1? true:false));
	else
		document.write("<div class=\"imBlogEmpty\">Empty blog</div>");
}

function imBlogShowSearch(search) {
	var i = 0;
	var bps = Array();
	for(key in imBPosts)
		bps[i++] = key;
	j = 0;
	if(bps instanceof Array) {
		for(i = bps.length-1; i >= 0; i--) {
      if(imBPosts[bps[i]]['title'].toLowerCase().indexOf(search.toLowerCase()) != -1 || imBPosts[bps[i]]['summary'].toLowerCase().indexOf(search.toLowerCase()) != -1 || imBPosts[bps[i]]['body'].toLowerCase().indexOf(search.toLowerCase()) != -1) {
				imBlogShowPost(bps[i],0);
				j++;
			}
		}
		if(j == 0)
			document.write("<div class=\"imBlogEmpty\">Empty search</div>\n");
	}
	else
		document.write("<div class=\"imBlogEmpty\">No articles found in this category</div>\n");
}
