var help_section = "section=A10";
var help_subsection = "msg=1";
var help_index = "Help_Index";
var step_index = "Step_Index";


/**
 * This function is a pretty way of clearing text
 */
var stickyElement = "sticky-message";
function stickyAppear(msg) {
	var element = $(stickyElement);
	if (element != null) {
		element.innerHTML = msg;
		var queue = Effect.Queues.get('global');
		queue.each(function(e) { e.cancel() });
		new Effect.Appear(element, {duration: .5, to: .7});
	}
}
function stickyMessage(msg) {
	
	var element = $(stickyElement);
	if (element != null && element.visible) {
		element.innerHTML = msg;
		var queue = Effect.Queues.get('global');
		queue.each(function(e) { e.cancel() });
	}
	else {
		stickyAppear(msg);
	}
	
	setTimeout("stickyFade();", 5000);
}
function stickyFailedMessage() {
	stickyMessage('Failed');
}
function stickyFade() {
	new Effect.Fade(stickyElement, {duration: .5, from: .7});
}

function reportError(request)
{
	alert('Sorry. There was an error.');
}

/**
 * gets a cookie from the browser
 */
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) { 
			c_start = c_start + c_name.length+1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function requestHelp(index, step) {

	if (step == null) {
		step = 0;
	}

	var params = help_index + "=" + index + "&" + step_index + "=" + step + 
		"&" + help_section + "&" + help_subsection;
	requestAjax("Help", params);
}

function editHelp(index, step) {

	if (step == null) {
		step = 0;
	}

	var params = help_index + "=" + index + "&" + step_index + "=" + step + 
		"&" + help_section + "&" + help_subsection + "&ajax_edit=1";
	requestAjax("Help", params);
}

function requestAjax(id, request) {
	//request += "&wftUser=" + getCookie("wftUser") + "&PHPSESSID=" + getCookie("PHPSESSID");
	new Ajax.Updater(id, "Main.php",
			{
				method: "get",
				parameters: request
			}
		);

}