function showBlock(i) { 

	if (document.getElementById) {  

		document.getElementById(i).style.display =  "block";  
	
	} else if ( document.all[i] ) {

		document.all[i].style.display =  "block"; 

	}

}
function showInline(i) { 

	if (document.getElementById) {  

		document.getElementById(i).style.display =  "inline";  
	
	} else if ( document.all[i] ) {

		document.all[i].style.display =  "inline"; 

	}

}
function hide(i) { 

	if (document.getElementById) {  

		document.getElementById(i).style.display =  "none";  
	
	} else if ( document.all[i] ) {

		document.all[i].style.display =  "none"; 

	}

}

function getElement( base, i ) {
	if (base.getElementById) {  
		return base.getElementById(i);  
	} else {
		return base.all[i];	
	}
}
	
function swapClass(i,c) { 

	if (document.getElementById) {  

		document.getElementById(i).className =  c;  
	
	} else if ( document.all[i] ) {

		document.all[i].className = c;	

	}

}

function showLogin()
{
	hide('toplinks');
	hide('toplinkserror');
	showInline('toplinksform');
}
function submitLogin()
{
	document.loginform.submit();
}
function signoff()
{
	document.logoutform.submit();
}
function submitComment()
{
	document.commentform.submit();
}


function submitChannelVote( channel, post, divid )
{
	loadXML( "/vote/channel/" + channel + "/post/" + post, function( xml ) {

		var gvotexml = xml.documentElement.getElementsByTagName("globalvotes");
		var cvotexml = xml.documentElement.getElementsByTagName("channelvotes");
		
		var globalvotes = parseInt( gvotexml[0].firstChild.data);
		var channelvotes = parseInt( cvotexml[0].firstChild.data);

		var votediv = getElement(document, divid);
		votediv.innerHTML = globalvotes + format_plural( globalvotes, "<br>vote<br>", "<br>votes<br>" ) + channelvotes + format_plural( channelvotes, "<br>channel vote<br>", "<br>channel votes<br>");

	});
}
function submitGlobalVote( post, divid )
{
	loadXML( "/vote/post/" + post, function( xml ) {

		var gvotexml = xml.documentElement.getElementsByTagName("globalvotes");
		
		var globalvotes = parseInt( gvotexml[0].firstChild.data);
		var votediv = getElement(document, divid);
		votediv.innerHTML = globalvotes + format_plural( globalvotes, "<br>vote<br>", "<br>votes<br>" );

	});
}
function format_plural( number, singular, plural )
{
	if ( number == 1)
	{
		return singular;
	}
	else
	{
		return plural;
	}
}

var xmlRequest;
var finishedHandler;
var xmlqueue = new Array();
var xmlloadtimer = null;
var xmlprocessing = false;
function loadXML( xmlurl, handlerfunction )
{
	var loadobject = new Object();
	loadobject.xmlurl = xmlurl;
	loadobject.handlerfunction = handlerfunction;
	xmlqueue.push( loadobject );
	startXMLWatcher(true);
}
function startXMLWatcher( firstrun )
{
	
	if ( firstrun && xmlloadtimer == null && xmlprocessing == false )
	{
		xmlloadtimer = setInterval( 'startXMLWatcher(false)', 10 );
		return;
	}
	if ( xmlqueue.length < 1 )
	{	
		var tokill = xmlloadtimer;
		xmlprocessing = false;
		xmlloadtimer = null;
		clearInterval(tokill);
		return;
	}
	if ( xmlprocessing == true )
	{
		return;
	}
	else
	{
		xmlprocessing = true;
	}
	var loadobj = xmlqueue.shift();
	xmlAsyncLoad( loadobj.xmlurl, loadobj.handlerfunction );
}

function watchxmlstatus( )
{
	if ( xmlRequest.readyState == 4  && xmlRequest.status == 200 )
	{
		var xml = new Object();
		xml.documentElement = xmlRequest.responseXML;
	
		finishedHandler( xml );
		xmlprocessing = false;
	}
}	
function xmlAsyncLoad( xmlurl, handlerfunction )
{
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlRequest = new XMLHttpRequest();
		try
		{
			xmlRequest.overrideMimeType('text/xml');
		}
		catch (err)
		{
		}
	} else if (window.ActiveXObject) { // IE
		try
		{
			xmlRequest= new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (err)
		{
			try
			{
				xmlRequest= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (err2)
			{
			}
		}

	}
		
	xmlRequest.onreadystatechange = watchxmlstatus;
	finishedHandler = handlerfunction;
	xmlRequest.open( 'GET', xmlurl, true );
	xmlRequest.send(null);
}


