function sl_ajax_callback() {
  var outputDiv = document.getElementById("errOutput");

  if(outputDiv != null){
    outputDiv.innerHTML = '';//clear error message if any
    outputDiv.style.display = "none";
  }

	sl_toggle_div('post_announcement_form');
};

function sl_toggle_div(element) {
	var element = document.getElementById(element);
	( element.style.display == "none" ) ?  Zapatec.Effects.show(element, 7, 'fade') : Zapatec.Effects.hide(element, 7, 'fade');
}

/* Old effect functions for use with scriptaculous/prototype/etc */
function toggle(element) {
  var element = $(element);
  ( element.style.display == "none" ) ? element.style.display = "" : element.style.display = "none";
}

function toggle2(element) {
  ( element.style.display == "none" ) ? element.style.display = "" : element.style.display = "none";
}

function toggleDivEffect(element) {

  element = $(element);
   ( element.style.display == "none" ) ? new Effect.Appear(element, {duration: 0.4}) : new Effect.Fade(element, {duration: 0.4});
}


function textCounter(field, count_id, maxlimit) {
    if (field.value.length > maxlimit) {// if too long...trim it!
    	field.value = field.value.substring(0, maxlimit);
		}
    // otherwise, update 'characters left' counter
    else {
			elem = document.getElementById(count_id);
			elem.innerHTML = maxlimit - field.value.length;
		}
}

function GreyIn(field, val) {
  if(field.value == val) {
    field.value='';
    field.style.color='#000000';
  }
}

function GreyOut(field, val) {
  if(field.value == '') {
    field.value=val;
    field.style.color='#a0a0a0';
  }
}

function ToggleTab(id) {
  var tmp;

	elem = document.getElementById(id);
  ( elem.style.display == "none" ) ? elem.style.display = "block" : elem.style.display = "none";

  setCookie(id, elem.style.display, 365);
}

function ToggleHelpDiv() {
	var tmp;
	element = document.getElementById("sl_help");

  ( element.style.display == "none" ) ? element.style.display = "block" : element.style.display = "none";

	setCookie('help_div', element.style.display, 365);
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+"="+escape( value ) +
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" )

+ //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function ajaxRequest(url,data) {
	var aj = new Ajax.Request(
				url, {
				method:'get',
				parameters: data,
				onComplete: getResponse
				}
			);
}

function getResponse(oReq) {
	//$('Results').innerHTML = oReq.responseText;
}



//---- Custom checkboxes

//window.onload = initChecks;
//var d=document;
//function initChecks() {
	//so_checkCanCreate();
//}

function so_checkCanCreate() {
	// make sure the browser has images turned on. If they are, so_createCustomCheckBoxes will
	// fire when this small test image loads. otherwise, the user will get the hard-coded checkboxes
	testImage = d.body.appendChild(d.createElement("img"));

	// MSIE will cache the test image, causing it to not fire the onload event the next time the
	// page is hit. The parameter on the end will prevent this.
	testImage.src = "/images/1pixel.gif?" + new Date().valueOf();
	testImage.id = "so_testImage";
	testImage.onload = so_createCustomCheckBoxes;
}

function so_createCustomCheckBoxes() {
	// bail out is this is an older browser
	if(!d.getElementById)return;
	// remove our test image from the DOM
	d.body.removeChild(d.getElementById("so_testImage"));
	// an array of applicable events that we'll need to carry over to our custom checkbox
	events = new Array("onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup");
	// a reference var to all the forms in the document

	frm = d.getElementsByTagName("form");
	// loop over the length of the forms in the document

	for(i=0;i<frm.length;i++) {
		// reference to the elements of the form
		c = frm[i].elements;
		// loop over the length of those elements
		for(j=0;j<c.length;j++) {
			// if this element is a checkbox, do our thing

			if(c[j].getAttribute("type") == "checkbox") {
				// hide the original checkbox
				c[j].style.position = "absolute";
				c[j].style.left = "-9000px";
				// create the replacement image
				n = d.createElement("img");
				n.setAttribute("class","chk");
				// check if the corresponding checkbox is checked or not. set the
				// status of the image accordingly
				if(c[j].checked == false) {
					n.setAttribute("src","/images/checkbox.jpg");
					n.setAttribute("title","click here to select this option.");
					n.setAttribute("alt","click here to select this option.");
					n.setAttribute("style","vertical-align:middle");
				} else {
					n.setAttribute("src","/images/checkbox-checked.jpg");
					n.setAttribute("title","click here to deselect this option.");
					n.setAttribute("alt","click here to deselect this option.");
					n.setAttribute("style","vertical-align:middle");
				}
				// there are several pieces of data we'll need to know later.
				// assign them as attributes of the image we've created
				// first - the name of the corresponding checkbox
				n.xid = c[j].getAttribute("name");
				// next, the index of the FORM element so we'll know which form object to access later

				n.frmIndex = i;
				// assign the onclick event to the image
				n.onclick = function() { so_toggleCheckBox(this,0);return false; }
				// insert the image into the DOM
				c[j].parentNode.insertBefore(n,c[j].nextSibling)
				// this attribute is a bit of a hack - we need to know in the event of a label click (for browsers that support it)
				// which image we need turn on or off. So, we set the image as an attribute!
				c[j].objRef = n;
				// assign the checkbox objects event handlers to its replacement image
				for(e=0;e<events.length;e++) if(eval('c[j].' +events[e])) eval('n.' + events[e] + '= c[j].' + events[e]);
				// append our onchange event handler to any existing ones.
				fn = c[j].onchange;
				if(typeof(fn) == "function") {
					c[j].onchange = function() { fn(); so_toggleCheckBox(this.objRef,1); return false; }
				} else {
					c[j].onchange = function () { so_toggleCheckBox(this.objRef,1); return false; }
				}
			}
		}
	}
}

function so_toggleCheckBox(imgObj,caller) {
	// if caller is 1, this method has been called from the onchange event of the checkbox, which means
	// the user has clicked the label element. Dont change the checked status of the checkbox in this instance
	// or we'll set it to the opposite of what the user wants. caller is 0 if coming from the onclick event of the image
	
	// reference to the form object
	formObj = d.forms[imgObj.frmIndex];
	// the name of the checkbox we're changing
	objName = imgObj.xid;
	// change the checked status of the checkbox if coming from the onclick of the image
	if(!caller)formObj.elements[objName].checked = !formObj.elements[objName].checked?true:false;
	// finally, update the image to reflect the current state of the checkbox.
//var imgFalse = '/images/checkbox.jpg';
//var imgTrue = '/images/checkbox-checked.jpg';
	if(imgObj.src.indexOf("/images/checkbox-checked.jpg")>-1) {
		imgObj.setAttribute("src","/images/checkbox.jpg");
		imgObj.setAttribute("title","click here to select this option.");
		imgObj.setAttribute("alt","click here to select this option.");
		imgObj.setAttribute("style", "vertical-align:middle");
	} else {
		imgObj.setAttribute("src","/images/checkbox-checked.jpg");
		imgObj.setAttribute("title","click here to deselect this option.");
		imgObj.setAttribute("alt","click here to deselect this option.");
		imgObj.setAttribute("style", "vertical-align:middle");
	}
}



<!-- More -->

function checkAll(){
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e=document.forms[0].elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		{
			e.checked=document.forms[0].allbox.checked;
		}
	}
}

function selectAll(id)
{
	// get the elements name
	var elem = document.getElementById(id);
	//var id = elem.id;
	var name = /^([a-z]+)(_select_all)$/i.exec(id);
 
	name = name[1];
 
	re = new RegExp('^'+name+'_[0-9]+$');
 
	// get the elements stauts
	var state = elem.checked;
 
	// get the form element, search "up"
	var form = elem.parentNode;
	while(form.nodeName.toLowerCase() != "form")
	{
		if(!form.parentNode) break;
		form = form.parentNode;
	}
 
	// search through forms children for email_ checkboxes
	for (i=0;i<form.elements.length;i++)
	{
		if (form.elements[i].type=='checkbox')
		{
			// Find checkbox for each member of the group:
			if (re.test(form.elements[i].name))
			{
				form.elements[i].checked = state;
			}
		}
	}
}

function toggleCheck(value, prefix){
	var inputs = document.getElementsByTagName("input");
	var reg = new RegExp(prefix);

	for(var i=0; i<inputs.length; i++){
		if(inputs[i].type=="checkbox" && reg.test(inputs[i].name))
			inputs[i].checked = value;
	}
}

function decision(message, url){
	if(url) {
		if(confirm(message)) location.href = url; exit;
	} else {
		if(confirm(message)) return true; else return false;
	}
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
		}
		return "";
}
