var ajax = false;
var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING       = 1;
var READY_STATE_LOADED        = 2;
var READY_STATE_INTERACTIVE   = 3;
var READY_STATE_COMPLETE      = 4;

function AjaxCall(url, params, httpMethod, callBack) {
	httpMethod = (httpMethod == 'POST')? 'POST' : 'GET';
	ajax = false;

	if (!params) {
		params = null;
	}

	// create the XMLHttp object (Cross-Browsers)
	if (window.XMLHttpRequest) {       // Mozilla, Safari,...
		ajax = new XMLHttpRequest();
		if (ajax.overrideMimeType) {
			ajax.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // Internet Explorer
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	// unable to create XMLHTTP objects
	if (!ajax) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	if (httpMethod == 'GET') {
		url = url + '?' + params;
	}

	ajax.onreadystatechange = eval(callBack);
	ajax.open(httpMethod, url, true);

	if (httpMethod == 'POST') {
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	ajax.send(params);
}

function alertContents() {
	if (ajax.readyState != READY_STATE_COMPLETE) {
		document.getElementById('loadingBox').top = screen.availHieght / 2;
		document.getElementById('loadingBox').left = screen.availWidth / 2;
		document.getElementById('loadingBox').style.display = '';
		document.getElementById('contentBody').innerHTML = '';
	}
	if (ajax.readyState == READY_STATE_COMPLETE) {
		document.getElementById('loadingBox').style.display = 'none';
		if (ajax.status == 200) {
			document.getElementById('contentBody').innerHTML = ajax.responseText;
			document.getElementById('contentBody').style.display = '';
		} else {
			alert('There was a problem with the request. Error: ' + ajax.status);
		}
	}
}

function toggleDivGroup(div, active) {
	children = document.getElementById(div).childNodes;

	for(i=0; i<=children.length-1; i++) {
		//alert(children[i]);
		if (children[i].id == active) {
			children[i].style.display = '';
		} else {
			children[i].style.display = 'none';
		}
	}
}

function toggleForm(formName, focusElement) {		
	if (document.getElementById(formName).style.display=='') {
		document.getElementById(formName).style.display='none';
	} else {
		document.getElementById(formName).style.display='';
		document.getElementById(focusElement).focus();
	}
}

/***********************************************
* Highlight Table Cells Script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Specify highlight behavior. "TD" to highlight table cells, "TR" to highlight the entire row:
var highlightbehavior="TR"

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor){
source=ie? event.srcElement : e.target
if (source.tagName=="TABLE")
return
while(source.tagName!=highlightbehavior && source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
while (slave.parentNode)
if ((slave = slave.parentNode) == master)
return true;
return false;
}

function changeback(e,originalcolor){
if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
return
if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
source.style.backgroundColor=originalcolor
}