// JavaScript Document

function $$(id) {
	if(typeof(id)=='Object') return id;
	if (document.getElementById(id)) return document.getElementById(id);
	return false;
}

/*	Hides all elements in 'hide' array, and will display the show element
*/function toggle(show,hide)  {
	for (var i=0; hide[i]; i++) {
		if ($$(hide[i])) {
			$$(hide[i]).style.display='none';
		}
	}
	$$(show).style.display='block';
}

function inputFocus(el,str) {
	if (el.value==str) {
		el.value='';
	}
}
function inputBlur(el,str) {
	if (el.value=='') {
		el.value=str;
	}
}

/*	29-09-10; LJB; Added Scope for callback to JS Object Method
function ajaxObject(url, callbackFunction) {
*/function ajaxObject(url, callbackFunc, callbackObj) {
	var that=this;
	this.updating = false;
	this.abort = function() {
		if (that.updating) {
			that.updating=false;
			that.AJAX.abort();
			that.AJAX=null;
		}
	}
	this.update = function(passData,postMethod) {
		if (that.updating) { return false; }
		that.AJAX = null;
		if (window.XMLHttpRequest) {
			that.AJAX=new XMLHttpRequest();
		} else {
			that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (that.AJAX==null) {
			return false;
		} else {
			that.AJAX.onreadystatechange = function() {
				if (that.AJAX.readyState==4) {
					that.updating=false;
					that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);
					that.AJAX=null;
				}
			}
			that.updating = new Date();
			if (/post/i.test(postMethod)) {
				var uri=urlCall+'?'+that.updating.getTime();
				that.AJAX.open("POST", uri, true);
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				that.AJAX.send(passData);
			} else {
				var uri=urlCall+'?'+passData+'&tstamp='+(that.updating.getTime());
				that.AJAX.open("GET", uri, true);
				that.AJAX.send(null);
			}
			return true;
		}
	}
	var urlCall = url;
	this.callback = callbackFunc || function () { };
}

function ajaxForm(frm,cb) {
	var data='';
	for(var i=0; frm[i]; i++) {
		if (frm[i].tagName=='INPUT') {
			data=data+frm[i].name+'='+frm[i].value+'&';
		}
		if (frm[i].tagName=='SELECT') {
			data=data+frm[i].name+'='+frm[i].options[frm[i].selectedIndex].value+'&';
		}
	}
	var ajax=new ajaxObject(frm.action,cb);
	ajax.update(data,'POST');
	return false;
}
