// FUNCTION TO EXPAND AND COLLAPSE STORIES AND HELP TOPIS
function expand(divName) {
	var lastOpenDiv = $("divIdHolder").value;

	// IF A DIV IS OPEN, CLOSE IT BEFORE OPENING A NEW ONE
	if (lastOpenDiv != "" && $(divName).style.display == 'none') {
		Effect.BlindUp(lastOpenDiv, { duration: 0.25 });
	}
	
	// IF DIV IS HIDDEN THEN SHOW IT
	if ($(divName).style.display == 'none') {
		Effect.BlindDown(divName, { duration: 0.25 });
		document.all("divIdHolder").value = divName;
	}
	// ELSE HIDE THE DIV
	else {
		Effect.BlindUp(divName, { duration: 0.25 });
		document.all("divIdHolder").value = "";
	}
}

// FUNCTION TO HIDE FORMS
function hideForm(id){
	// IF CLOSE BUTTON ON EDIT FORM IS CLICKED
	if (id != 0) {	
		Effect.BlindUp($('editDiv-'+id), { duration: 0.25 });
	}
	// ELSE CLOSE BUTTON ON ADD FORM IS CLICKED
	else {
		Effect.BlindUp($('addFormHolder'), { duration: 0.25 });
	}	
	setTimeout(function() {delay(id);}, 45);
	$('outter').style.display = "none";
}

function delay(id) {
	// IF EDIT DIV NEEDS TO BE HIDDEN
	if (id != 0) {
		$('editDiv-'+id).innerHTML = '';
	}
	// ELSE ADD DIV NEEDS TO BE HIDDEN
	else {
		$('addFormHolder').innerHTML = '';
	}
}

// AJAX CALL TO SHOW ADD FORM
function addForm(url, control) {
	
	$('outter').style.opacity = "0.35";
	$('outter').style.filter = "alpha(opacity = 35)";
	$('outter').style.display = "block";
	$('spinnerBox').style.display = "block";
	
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			$('addFormHolder').innerHTML = transport.responseText;
			if (control != 'issue') {
				$('buttons').style.display = 'block';
			}
			Effect.SlideDown($('addFormHolder'), { duration: 0.25 });
			$('spinnerBox').style.display = "none";
			if (control != 'notes') {
				setTimeout(function() {$(control).focus();}, 45);
			}
			if (control=='story' || control=='notes') {
				addMarkupControls();
			}
		}
	});
}

// AJAX CALL TO SHOW EDIT FORM
function editForm(id, url, control) {
	
	$('outter').style.opacity = "0.35";
	$('outter').style.filter = "alpha(opacity = 35)";
	$('outter').style.display = "block";
	$('spinnerBox').style.display = "block";

	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			$('editDiv-'+id).innerHTML = transport.responseText;
			if (control != 'issue') {
				$('buttons').style.display = 'block';
			}
			Effect.SlideDown($('editDiv-'+id), { duration: 0.25 });
			$('spinnerBox').style.display = "none";
			
			setTimeout(function() {$(control).focus();}, 45);
			if (control=='story') {
				addMarkupControls();
			}		
		}
	});
}

// FUNCTION TO POP UP MESSAGE WHEN DELETE IS CLICKED
function deleteRecord(url, name) {
	var result = confirm("Are you sure you wish to delete this " + name);
	if (result == true) {
		$('spinnerBox').style.display = "block";
		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				$('msgBox').innerHTML = transport.responseText;
				$('msgBox').style.display = 'block';
				$('msgBox').fade({ duration: 7.0 });
				refreshGrid(); 
				$('spinnerBox').style.display = "none";
			}
		});
	}
} 