// xGetElementsByTagName r4, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xGetElementsByTagName(t,p) {
	
	var list = null;
	t = t || '*';
	p = p || document;
	if (typeof p.getElementsByTagName != 'undefined') { // DOM1
		list = p.getElementsByTagName(t);
		if (t=='*' && (!list || !list.length)) list = p.all; // IE5 '*' bug
	}
	else { // IE4 object model
		if (t=='*') list = p.all;
		else if (p.all && p.all.tags) list = p.all.tags(t);
	}
	return list || new Array();
}

function getHTMLBlock(blockid, blocktitle) {
	
	var html = "";
	
	var split = blocktitle.split("|");
	var xml = split[0];
	var xsl = split[1];
	var split_s = split[2].split(",");
	var php = split_s[0];
	var classname = split_s[1];
	
	// Display loader
	document.getElementById(blockid).innerHTML = "<img heigth=15 width=15 border=0 src=\"/images/extra/loader.gif\">";
	
	if (blockid) {
		// Post details via ajax
		var url = "/ajax/contentBlock.php?xml="+xml+"&xsl="+xsl+"&php="+php+"&classname="+classname;
		
		new Ajax.Request(url, {
			method:'get',
			onSuccess: function(transport) {
				html = transport.responseText || "";
				document.getElementById(blockid).className = "";
				document.getElementById(blockid).innerHTML = html;
			},
			onFailure: function() {
				// do nothing
			}
		});
	} else {
		// do nothing
	}
}

function convertBlockCalls() {
	
	// get all divs
	var blocks = xGetElementsByTagName("div");
	for (var i = 0 ; i < blocks.length; i++) {
		var block = blocks[i];
		// is this a block holder div??
		if (block.className == "blockholder") {
			// get the content
			getHTMLBlock(block.id, block.title);
		}
	}
}
