/*
Common javascript function file

Richard Scrimshaw - RJS Contracting Services Ltd - 2009

This file provides standard javascript functions and is included by most pages.

Version 1.0

Functions included: 
	toggleDiv(id,flagit) {
	newtoggleDiv(id,flagit,otherhideid) {
	getXMLHTTPRequest()
	responseAjaxHTML(reqdid)
	responseAjaxXML(reqdid)
	

*/

function toggleDiv(id,flagit) {
	if (flagit=="1"){
		if (document.layers) document.layers[''+id+''].visibility = "show"
		else if (document.all) document.all[''+id+''].style.visibility = "visible"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
	}
	else 
	if (flagit=="0"){
		if (document.layers) document.layers[''+id+''].visibility = "hide"
		else if (document.all) document.all[''+id+''].style.visibility = "hidden"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
}
//-->
function newtoggleDiv(id,flagit,otherhideid) {
	if (flagit=="1"){
		if (document.layers) document.layers[''+id+''].visibility = "show"
		else if (document.all) document.all[''+id+''].style.visibility = "visible"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible";
		if(otherhideid) { //If the optional argument is there, hide that id.
			if (document.layers) document.layers[''+otherhideid+''].visibility = "hide"
			else if (document.all) document.all[''+otherhideid+''].style.visibility = "hidden"
			else if (document.getElementById) document.getElementById(''+otherhideid+'').style.visibility = "hidden"
		}
	}
	else if (flagit=="0"){
		if (document.layers) document.layers[''+id+''].visibility = "hide"
		else if (document.all) document.all[''+id+''].style.visibility = "hidden"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
}


function getXMLHTTPRequest()
{
var request = false;
try
	{
	request = new XMLHttpRequest(); /* e.g. Firefox */
	}
catch(err1)
	{
	try
		{
		request = new ActiveXObject("Msxml2.XMLHTTP");
		/* Some versions of IE - thanks, Microsoft */
		}
	catch(err2)
		{
		try
			{
			request = new ActiveXObject("Microsoft.XMLHTTP");
			/* Some OTHER versions of IE - thanks again, Microsoft */
			}
		catch(err3)
			{
			request = false;
			}
		}
	}
return request;
}

var myRequest = getXMLHTTPRequest();


function responseAjaxHTML(reqdid)
/*
This is my preferred approach to handling Ajax responses.
Takes, as an argument, the ID of the tag pair (normally a DIV) where the returned string will be placed.
*/
{
if (myRequest.readyState == 4)
	{
	if (myRequest.status == 200)
		{
		var mytext = myRequest.responseText;
		document.getElementById(reqdid).innerHTML = mytext;
		}
	else
		{
		alert('An error has occurred:' + myRequest.statusText);
		}
	}
else
	{
//	alert('An readyState error has occurred:' + this.readyState);
	}
}

function responseAjaxXML(reqdid)
{
/*
This function is an example and will need to be customised to handle the particular XML structure.
*/
if (myRequest.readyState == 4)
	{
	if (myRequest.status == 200)
		{
/*		var greetNode = myRequest.responseXML.getElementsByTagName("greeting")[0];
		var greetText = greetNode.childNodes[0].nodeValue;
		alert("Greeting Text: " + greetText);
*/
//		alert("The Server Said : " + myRequest.responseText);		
		}
	else
		{
		alert('An error has occurred:' + myRequest.statusText);
		}
	}
}



/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/***********************************************
*
* Use it like this:-
*
<a href="javascript:bookmarksite('Dynamic Drive', 'http://www.dynamicdrive.com')">Bookmark this site!</a>
*/
/***********************************************

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

