
// Helper class used with prototype.js AJAX. Upon request completion, it
// updates the given element's innerHTML with the returned HTML code
AjaxUpdater = Class.create();
AjaxUpdater.prototype =
{
		initialize : function(id, url)
		{
			this.options = {};
			this.options.method = 'get';
			this.options.asynchronous = true;
			if(id)
			{
				this.id = id;
				this.options.onComplete = this.onComplete.bind(this);
			}
			loadingIndicator(true);
			new Ajax.Request(url, this.options);
		},
		onComplete : function(request)
		{
//			alert(request.responseText);
			$(this.id).innerHTML = request.responseText;
			request.responseText.evalScripts();
			loadingIndicator(false);
		}
};

function do_ajax(id, url)
{
		new AjaxUpdater(id, url);
}

function loadingIndicator(show)
{
		var elem = $('loading_indicator');
		if (!elem)
		{
				elem = $(document.createElement('div'));
				elem.id = 'loading_indicator';
				elem.hide().update('Loading...');
				document.body.appendChild(elem);
		}
		if (show) 
			elem.show()
		else
			elem.hide();			
}

function toggle_sel(FormName, FieldName, selControl)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = true;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = selControl.checked;
}
function openImage(aa,url){
		aa.href=url;
		myLightbox.start(aa);
		aa.href='#';
		return false;
}
