//Create and event for the onload function
//in here we will setup all other events
//this ensures that any element we are trying to add an event to exists already
Event.observe(
window,
'load',
function()
{
  var elementCounter = 0;

  //add our highlight effect to anything with the unread class
  //drawing attention to them for the user
  $$('.unread').each(function(element)
  {
    new Effect.Pulsate(element,{pulses:3,queue:{position:'end',scope:'unread_'+elementCounter}});
    elementCounter++;
  }
  );
}
);

/**
 * This function is for parsing what rowdata has been selected, and giving that
 * information to a hidden formfield for posting 
 *
 * @author ccollier
 * @name populateBulkActionValues
 * @param string strIdContainerField
 * @param string strContainingDiv
 * @return bool
 */
function populateBulkActionValues(strIdContainerField, strIdContainingDiv) {
	//Initialize the variables used in in the function 
	var strIds = '';
	var strId = '';
	var comma = '';
	var formName = strIdContainerField.substring(strIdContainerField.length-3, strIdContainerField);
	var checkboxes = $(strIdContainingDiv).select('input[type="checkbox"]');
		
	//Loop through each of the checkboxes, and build a string representing the
	// selected values for the builk action
	for(var i in checkboxes) {
		//first, check to see if the checkbox is checked (which is intrinsic that this IS a checkbox()
		if(checkboxes[i].checked) {
			//Next store the name of the checkbox locally
			strId = checkboxes[i].name;
			
			//Next, replace the string information from the name, to obtain the id
			strId = strId.substring(15, strId.length);
			
			//Append the 
			strIds = strIds + comma + strId;
			comma = ',';
		}
	}
	//update the value of the form element that stores the csv of ids for this form
	document.forms[formName].elements[strIdContainerField].value = strIds;
	return true;
}

/**
 * This function is selecting all available checkboxes 
 *
 * @author ccollier
 * @name selectAllCheckBoxes
 * @param string strIdContainerField
 * @return bool
 */
function selectAllCheckBoxes(strIdContainingDiv) {

	var checkboxes = $(strIdContainingDiv).select('input[type="checkbox"]');
	//Loop through each of the checkboxes, and build a string representing the
	// selected values for the builk action
	for(var i in checkboxes) {
		checkboxes[i].checked = true;
	}
}

/**
 * This function is selecting all available checkboxes 
 *
 * @author ccollier
 * @name selectAllCheckBoxes
 * @param string strIdContainerField
 * @return bool
 */
function deSelectAllCheckBoxes(strIdContainingDiv) {


	var checkboxes = $(strIdContainingDiv).select('input[type="checkbox"]');
	//Loop through each of the checkboxes, and build a string representing the
	// selected values for the builk action
	for(var i in checkboxes) {
		checkboxes[i].checked = false;
	}
}

function insertFCKEditor() {
/*
	if($('fckeditorField___Config')) {
		objConfig = $('fckeditorField___Config');
		objFrame = $('fckeditorField___Frame');
		objParent = objConfig.parentNode;
		
		objParent.removeChild(objConfig);
		objParent.removeChild(objFrame);
	
	}

	if($('MB_content') && $('fckeditorField')) {
		var oFCKeditor = new FCKeditor('fckeditorField') ;
		oFCKeditor.BasePath = '/js-lib/fckeditor/' ;
		oFCKeditor.ReplaceTextarea() ;
	}
	*/
}

function removeFCKEditor() {
/*
	if($('fckeditorField___Config')) {
		objConfig = $('fckeditorField___Config');
		objFrame = $('fckeditorField___Frame');
		objParent = objConfig.parentNode;
		
		objParent.removeChild(objConfig);
		objParent.removeChild(objFrame);
	
	}
	
	if($('fckeditorField')) {
		var obj = $('fckeditorField');
		var objParent = obj.parentNode;
		
		var objNew = document.createElement("TEXTAREA");
		objNew.className = 'FCKEditor';
		objNew.name = 'threadPost';
		objNew.rows = '15';
		objNew.id = 'fckeditorField';
		
		objParent.removeChild(obj);
		objParent.appendChild(objNew);
	}
	*/
}