function tshow(theDiv)
{
	if ( document.getElementById(theDiv) )
	{
		var theDiv = document.getElementById(theDiv);
		theDiv.style.display = 'block';
	}
}
function thide(theDiv)
{
	if ( document.getElementById(theDiv) )
	{
		var theDiv = document.getElementById(theDiv);
		theDiv.style.display = 'none';
	}
}



function sToggle(theDiv)
{
	if ( document.getElementById(theDiv + 'icon') )
	{
		var icon = document.getElementById(theDiv + 'icon');
		var iconPresent = true;
	}

	if ( document.getElementById(theDiv) )
	{
		theDiv = document.getElementById(theDiv);
		if ( theDiv.style.display == 'block' )
		{
			theDiv.style.display = 'none';
			if ( iconPresent ) 
			{ 
				icon.setAttribute('src', '/images/plus.gif');
				icon.style.width = '9px';
				icon.style.height = '9px';
			}
		}
		else
		{
			theDiv.style.display = 'block';
			if ( iconPresent ) 
			{ 
				icon.setAttribute('src', '/images/minus.gif'); 
				icon.style.width = '9px';
				icon.style.height = '9px';
			}
		}
	}
	
}


function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{
        			oldonload();
      			}
      			func();
		}
	}
}

/* hijax.js v1 jeremy keith v2 stuart sillitoe 2007 */
function Hijax()
{
	var container;
	var url;
	var canvas;
	var data;
	var loading;
	var callback;
	var request;

	this.setContainer = function(value)
	{
		container = value;
	};

	this.setUrl = function(value)
	{
		url = value;
	};

	this.setCanvas = function(value)
	{
		canvas = value;
	};

	this.setLoading = function(value)
	{
		loading = value;
	};

	this.setCallback = function(value)
	{
		callback = value;
	};

	this.captureData = function()
	{
		// is data coming from a form?
		if ( container.nodeName.toLowerCase() == "form" )
		{
			container.onsubmit = function()
			{
				var query = '';
				for ( var i=0; i<this.elements.length; i++ )
				{
					// seems to pass radio / checkbox values even when not checked, which
					// then override actual selected values! hence this nested if statement
					if ( this.elements[i].type == 'radio' || this.elements[i].type == 'checkbox' )
					{
						if ( this.elements[i].checked == false )
						{
							continue;
						}
					}
					query += this.elements[i].name;
					query += '=';
					query += escape(this.elements[i].value);
					query += '&';
				}
				data = query;
				return !start();
			};
		}
		else
		{
			var links = container.getElementsByTagName('a');
			for ( var i=0; i<links.length; i++ )
			{
				links[i].onclick = function()
				{
					var query = this.getAttribute('href').split('?')[1];
					url += '?' + query;
					return !start();
				};
			}
			links = null;
		}
	};


	var start = function()
	{
		request = getHTTPObject();
		if ( !request || !url )
		{
			return false;
		}
		else
		{
			initiateRequest();
			return true;
		}
	};


	var getHTTPObject = function()
	{
		var xmlhttp = false;
		if ( window.XMLHttpRequest )
		{
			xmlhttp = new XMLHttpRequest();
		}
		else if ( window.ActiveXObject )
		{
			try
			{
				xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			}
			catch(e)
			{
				try
				{
					xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
				}
				catch(e)
				{
					xmlhttp = false
				}
			}
		}
		return xmlhttp;
	};


	var initiateRequest = function()
	{
		if (loading)
		{
			loading();
		}
		request.onreadystatechange = completeRequest;
		if (data)
		{
			request.open('POST', url, true);
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.send(data);
		}
		else
		{
			request.open('GET', url, true);
			request.send(null);
		}
	};


	var completeRequest = function()
	{
		if ( request.readyState == 4 )
		{
			if ( request.status == 200 | request.status == 304 )
			{
				if (canvas)
				{
					canvas.innerHTML = request.responseText;
				}
				if (callback)
				{
					callback();
				}
			}
		}
	};

} // end Hijax object




// /////////// extra functions

// display loading, shows loading text in canvas object, or any given element object
function displayLoading(element)
{
	element.innerHTML = '<br/><br/><br/><br/>loading...<br/>';
}
