function toggleVis(id) {
	// Toggle Display of object (showMode used for CBC)
	obj = document.getElementById(id);
	obj.style.display == showMode ? obj.style.display = 'none' : obj.style.display = showMode;
	var bodyTop = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	obj.style.top = obj.offsetTop + bodyTop + 'px';
}
function toggleShow(id) {
	// Toggle Visibility of object		
	obj = document.getElementById(id);
	obj.style.visibility == 'visible' ? obj.style.visibility = 'hidden' : obj.style.visibility = 'visible';
}
function toggleOverlay() {
	obj = document.getElementById('overlay');
	obj.style.display == showMode ? obj.style.display = 'none' : obj.style.display = showMode;
	var bodyHeight = Math.max(Math.max(document.body.scrollHeight,document.documentElement.scrollHeight),document.documentElement.offsetHeight);
	obj.style.height = bodyHeight + 'px';
}
function ajaxPost(url,enctype,xmlData) {
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: xmlData, 
			onSuccess: showResponse,
			onFailure: reportError,
			onException: reportError
		});	
}
function reportError(originalRequest) {
	//alert(originalRequest.responseText);
	document.getElementById('info').innerHTML = '<div class="resp_failure">'+originalRequest.responseText+'</div>';
}
function showResponse(originalRequest) {
	resp = originalRequest.responseText;
	if (resp.length > 0) {
			//alert(resp);
			document.getElementById('info').innerHTML = '<div class="resp_success">'+resp+'</div>';
	}
	// Reload to reveal changes (until we write AJAX to reload...)
	parent.document.getElementById('ajax_label').style.backgroundImage = "url(images/closelabel.gif)";
	//window.location.reload();
}
function ajaxPost_old(url,enctype,xmlData) {
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=ajaxAction;
		xmlhttp.open("POST",url,false);
		xmlhttp.setRequestHeader('Content-Type',enctype);
		xmlhttp.send(xmlData);
	} else {
		alert("Your Browser is not AJAX Enabled");
	}
}
function ajaxAction() {
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			resp = xmlhttp.responseText;
		} else {
			resp = "Form Post Error, Please Try Again";
			//resp = xmlhttp.error;			// For Viewing Connection Errors
			resp = xmlhttp.responseText; 	// For Viewing 500 Errors
		}
		alert(resp);
		// Reload to reveal changes (until we write AJAX to reload...)
		window.location.reload();
	}
}
function buildPost(form) {
	var qs = ''
	for (e=0;e<form.elements.length;e++) {
		if (form.elements[e].name!='') {
			var name = form.elements[e].name;
			qs+=(qs=='')?'':'&'
			qs+= name+'='+escape(form.elements[e].value);
		}
	}
	qs+="\n";
	return qs
}
function ajaxForm(url,form) {
	form = document.forms[form];
	enctype = form.encoding;
	xmlData = buildPost(form);
	parent.document.getElementById('ajax_label').style.backgroundImage = "url(images/loadinglabel.gif)";
	ajaxPost(url,enctype,xmlData);
}
function ireload(iframe,get) {
	// Reload iframe after closing
	var f = document.getElementById(iframe);
	f.src = f.src+get;
}
// Use this to get around caching the forms
var acount = 0;
function appendAvatar(form,record) {
	form = document.forms[form];
	// Check if item selected already
	a1 = form.data.value;
	if (a1!==''&&acount>0) {
		a = a1.split(',');
		for (n in a) {
			if (record==a[n]) {
				// Remove item from array
				a.splice(n,1);
				form.data.value = a.join(',');
				document.getElementById('av_'+record).className = 'avatar';
				acount--;
				return false;
			}
		}
		// Add item to array
		a = a.concat(record);
		form.data.value = a.join(',');
		acount++;
	} else {
		form.data.value = record;
	}
	document.getElementById('av_'+record).className = 'avatar deleted';
}
function buildAjaxWindow(title,info,url,scrolling) {
	ajaxwindow = document.getElementById('ajax_window');
	titlebox = document.getElementById('ajax_title');
	infobox = document.getElementById('ajax_info');
	iframe = document.getElementById('ajax_frame');
	titlebox.innerHTML = title;
	infobox.innerHTML = info;
	iframe.src = url;
	iframe.scrolling = scrolling;
}