function ShowMessages() {
	if($('flash')!=null){
		Effect.Appear('flash');
		setTimeout("DelayHide('flash')",7000);
	}
	if($('errorExplanation')!=null){
		Effect.Appear('errorExplanation');		
		setTimeout("DelayHide('errorExplanation')",7000);
	}
}

function ShowHistory() {
	if($('history')!=null){
		Effect.Appear('history');		
		setTimeout("DelayHide('history')",5000);
	}
}

function DelayHide(divname) {
	Effect.Fade(divname);
	return true;	
}

var participantEdit = false;
function EditParticipants() {
	if(participantEdit) {
		$('participantEdit').style.display = 'none';
		participantEdit = false;
	} else {
		$('participantEdit').style.display = 'block';	
		participantEdit = true;
	}
	$('participant_name').value = '';
}


function ChangeSearchOption() {
	var option_element = $('searchoptions_visible');
	var option_toggle = $('optiontoggle');
	var visible = option_element.value;
	if(visible == "true"){
		option_element.value = 'false';
		option_toggle.style.background = 'url(/images/searchoptions_closed.gif)';
		Effect.BlindUp('searchoptions');
	} else {
		option_element.value = 'true';
		option_toggle.style.background = 'url(/images/searchoptions_open.gif)';
		Effect.BlindDown('searchoptions');
	}
}


function HashMap() {
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}   
	this.removeItem = function(in_key) 	{
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}	   
		return tmp_value;
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value) 	{
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}
			this.items[in_key] = in_value;
		}	   
		return in_value;
	}

	this.hasItem = function(in_key) 	{
		return typeof(this.items[in_key]) != 'undefined';
	}
}


var elementVisible = new HashMap();
function DisplayTagthis(divId) {	
	var divname = 'addtag' + divId;
	var formname = 'tagthisform' + divId;	
	var form = document.getElementById 
    		? document.getElementById(formname) 
    		: document.forms[formname];
	var tagthisVisible = elementVisible.hasItem(divname);
		
	if(tagthisVisible){
		$(divname).style.display = 'none';
		form.tag_name.value = '';	
		elementVisible.removeItem(divname);	
	} else {
		$(divname).style.display = 'block';
		form.tag_name.focus();
		form.tag_name.value = '';
		elementVisible.setItem(divname, true);
	}
}
function ClearTagInput(divId) {
	var formname = 'tagthisform' + divId;	
	var form = document.getElementById 
    		? document.getElementById(formname) 
    		: document.forms[formname];	
	form.tag_name.value = '';
	UpdateTagListing();
}

function UpdateTagListing() {	
	new Ajax.Updater('tag_list','/tags/list', {asynchronous:true});
}

function changeFileProjectId() {
	$('filename_project_id').value = $('message_project_id').value;
}

function submitForm(){
	$('submit_message').style.display = 'block';
	document.formedit.submit();
}

function submitQuestionnaire(){
	if(confirm('Just to confirm are you sure you want to submit this questionnaire as it stands? Once you do your answers cannot be changed.')){
		$('questionnaire').style.display = 'none';
		$('submit_message').style.display = 'block';
		document.questionnaireform.submit();
	}
}

var calendar_stored = '';
function calendarPopup(calendar_day){
	if(calendar_stored != ''){
		if(calendar_stored != calendar_day){
			$(calendar_stored).style.display = 'none';
			$(calendar_day).style.display = 'block';
			calendar_stored = calendar_day;
		} else {
			$(calendar_day).style.display = 'none';
			calendar_stored = '';
		}
	} else {
		$(calendar_day).style.display = 'block';
		calendar_stored = calendar_day;
	}
}

var currentDirectory = 'directory0';
function changeDirectory() {
	$(currentDirectory).style.display = 'none';
	currentDirectory = $('changedirectory').value;
	$(currentDirectory).style.display = 'block';
}

function showUploadStatus() {
	Effect.Appear('FileUploadProgress');
}
function hideUploadStatus(){
	setTimeout("Effect.Fade('FileUploadProgress')",4000);
}

function showSyncMessage() {
	Effect.Appear('syncmessage');
	setTimeout("Effect.Fade('syncmessage')", 4000);
}
