var CHECK_EMPTY_FILE_MESSAGE = "Error: you must specify an attached file.";
var CHECK_REVIEWER_ACCOUNT_MESSAGE_1 = "Error: you must fill in the username field.";
var CHECK_REVIEWER_ACCOUNT_MESSAGE_2 = "Error: you must fill in the password field.";
var CHECK_REVIEWER_ACCOUNT_MESSAGE_3 = "Error: you must fill in the confirm password field.";
var CHECK_REVIEWER_ACCOUNT_MESSAGE_4 = "Error: password and confirm password fields must be the same.";
var CONFIRM_CANCEL_MESSAGE = "Are you sure you want to leave this page ?\n\nRefreshing or leaving this page will lose all unsaved changes.";
var CONFIRM_DELETE_MESSAGE = "Are you sure you want to delete this item ?";
var MAILTO_COMPANY_ERROR = "Error: you must fill in the company/organisation field.";
var MAILTO_FIRSTNAME_ERROR = "Error: you must fill in the firstname/lastname field.";

var s_timer = null;

function CheckEmptyFile(element)
{
	if ((element.value == null) || (element.value == ''))
	{
		alert(CHECK_EMPTY_FILE_MESSAGE);
		
		return false;
	}
	
	return true;
}

function CheckReviewerAccount()
{
	var username = document.getElementById("username").value;
	
	if ((username == null) || (username == ""))
	{
		alert(CHECK_REVIEWER_ACCOUNT_MESSAGE_1);
		
		return false;
	}
	
	var password = document.getElementById("password").value;
	
	if ((password == null) || (password == ""))
	{
		alert(CHECK_REVIEWER_ACCOUNT_MESSAGE_2);
		
		return false;
	}
	
	var confirmpassword = document.getElementById("confirmpassword").value;
	
	if ((confirmpassword == null) || (confirmpassword == ""))
	{
		alert(CHECK_REVIEWER_ACCOUNT_MESSAGE_3);
		
		return false;
	}
	
	if (password != confirmpassword)
	{
		alert(CHECK_REVIEWER_ACCOUNT_MESSAGE_4);
		
		return false;
		
	}
	
	return true;
}

function ConfirmCancel()
{
	return confirm(CONFIRM_CANCEL_MESSAGE);
}

function ConfirmDelete()
{
	return confirm(CONFIRM_DELETE_MESSAGE);
}

function ImageOnmouseout(name, url)
{
	var image = document.getElementById(name);
	image.src = url;
}

function ImageOnmouseover(name, url)
{
	var image = document.getElementById(name);
	image.src = url;
}

function Mailto(page)
{
	var firstname = document.getElementById("firstname").value;
	
	if ((firstname == null) || (firstname == ""))
	{
		alert(MAILTO_FIRSTNAME_ERROR);
		
		return false;
	}
	
	var company = document.getElementById("company").value;
	
	if ((company == null) || (company == ""))
	{
		alert(MAILTO_COMPANY_ERROR);
		
		return false;
	}
	
	var href = "mailto:contact@socrades.eu";
	
	if (page == null)
	{
		href += "?subject=SOCRADES: Feedback (";
		href += document.getElementById("firstname").value;
		href += " - ";
		href += document.getElementById("company").value;
		href += ")&body=";
		href += document.getElementById("comments").value;
	}
	else
	{
		href += "?subject=SOCRADES: Comment on page: " + page;
		href += "&body=";
		href += document.getElementById("comments").value;
	}
	
	window.location.href = href;
	
	return false;
}

function SectionHide()
{
	if (s_timer != null)
	{
		document.getElementById("s_project").style.visibility = "hidden";
		document.getElementById("s_documents").style.visibility = "hidden";
		document.getElementById("s_standardization").style.visibility = "hidden";		
		document.getElementById("s_downloads").style.visibility = "hidden";
		document.getElementById("s_demonstrators").style.visibility = "hidden";
		document.getElementById("s_private").style.visibility = "hidden";
	}
}

function SectionOnmouseout()
{
	s_timer = setTimeout("SectionHide()", 200);
}

function SectionOnmouseover(name)
{
	if (s_timer != null)
	{
		clearTimeout(s_timer);
		s_timer = null;
	}
	
	if (name == "s_project")
	{
		document.getElementById("s_project").style.visibility = "visible";
		document.getElementById("s_documents").style.visibility = "hidden";
		document.getElementById("s_standardization").style.visibility = "hidden";
		document.getElementById("s_downloads").style.visibility = "hidden";
		document.getElementById("s_demonstrators").style.visibility = "hidden";
		document.getElementById("s_private").style.visibility = "hidden";
	}
	else if (name == "s_documents")
	{
		document.getElementById("s_project").style.visibility = "hidden";
		document.getElementById("s_documents").style.visibility = "visible";
		document.getElementById("s_standardization").style.visibility = "hidden";
		document.getElementById("s_downloads").style.visibility = "hidden";
		document.getElementById("s_demonstrators").style.visibility = "hidden";
		document.getElementById("s_private").style.visibility = "hidden";
	}
	else if (name == "s_standardization")
	{
		document.getElementById("s_project").style.visibility = "hidden";
		document.getElementById("s_documents").style.visibility = "hidden";
		document.getElementById("s_standardization").style.visibility = "visible";
		document.getElementById("s_downloads").style.visibility = "hidden";
		document.getElementById("s_demonstrators").style.visibility = "hidden";
		document.getElementById("s_private").style.visibility = "hidden";
	}
	else if (name == "s_downloads")
	{
		document.getElementById("s_project").style.visibility = "hidden";
		document.getElementById("s_documents").style.visibility = "hidden";
		document.getElementById("s_standardization").style.visibility = "hidden";
		document.getElementById("s_downloads").style.visibility = "visible";
		document.getElementById("s_demonstrators").style.visibility = "hidden";
		document.getElementById("s_private").style.visibility = "hidden";
	}
	else if (name == "s_demonstrators")
	{
		document.getElementById("s_project").style.visibility = "hidden";
		document.getElementById("s_documents").style.visibility = "hidden";
		document.getElementById("s_standardization").style.visibility = "hidden";
		document.getElementById("s_downloads").style.visibility = "hidden";
		document.getElementById("s_demonstrators").style.visibility = "visible";
		document.getElementById("s_private").style.visibility = "hidden";
	}
	else if (name == "s_private")
	{
		document.getElementById("s_project").style.visibility = "hidden";
		document.getElementById("s_documents").style.visibility = "hidden";
		document.getElementById("s_standardization").style.visibility = "hidden";
		document.getElementById("s_downloads").style.visibility = "hidden";
		document.getElementById("s_demonstrators").style.visibility = "hidden";
		document.getElementById("s_private").style.visibility = "visible";
	}
	else
	{
		document.getElementById("s_project").style.visibility = "hidden";
		document.getElementById("s_documents").style.visibility = "hidden";
		document.getElementById("s_standardization").style.visibility = "hidden";		
		document.getElementById("s_downloads").style.visibility = "hidden";
		document.getElementById("s_demonstrators").style.visibility = "hidden";
		document.getElementById("s_private").style.visibility = "hidden";
	}
}