function toggle_record(pic_id, id)
{
	if(document.getElementById(id).style.display == '')
	{
		document.getElementById(pic_id).src='images/down.gif';
		document.getElementById(pic_id).alt='expand';
		document.getElementById(id).style.display='none';
	}
	else
	{
		document.getElementById(pic_id).src='images/up.gif';
		document.getElementById(pic_id).alt='close';
		document.getElementById(id).style.display='';
	}
}

function show_help(topic, lang)
{
	void window.open("lit_db_help.php?topic=" + topic + "&lang=" + lang, "lit_db_help", "width=500,height=500,dependent=yesscreenX=10,screenY=10,scrollbars=yes");
}

function list_window(id_to_add)
{
	void window.open("list.php?action=add&item_id=" + id_to_add, "lit_db_list", "width=500,height=500,dependent=yesscreenX=10,screenY=10,scrollbars=yes");
}

function checkDatabaseForm()
{
	var firstError = "";
	var emptyFields = "";
	var notSelected = "";
	var wrongValues = "";
	
	// text
	if(document.recordForm.form_title.value == "")
	{
		emptyFields += "- title\n";
		if(firstError == "") firstError = "form_title";
	}
	if(document.recordForm.form_author.value == "")
	{
		emptyFields += "- author\n";
		if(firstError == "") firstError = "form_author";
	}
	if(document.recordForm.form_source.value == "")
	{
		emptyFields += "- source\n";
		if(firstError == "") firstError = "form_source";
	}
	if(document.recordForm.form_text.value == "")
	{
		emptyFields += "- text\n";
		if(firstError == "") firstError = "form_text";
	}
	
	// select
	if(document.recordForm.form_language.value == "")
	{
		notSelected += "- language\n";
		if(firstError == "") firstError = "form_language";
	}
	if(document.recordForm.form_source_type.value == "")
	{
		notSelected += "- source type\n";
		if(firstError == "") firstError = "form_source_type";
	}
	
	// wrong values
	if(document.recordForm.form_title.value.length > 100)
	{
		wrongValues += "- title must be shorter than 50\n";
		if(firstError == "") firstError = "form_title";
	}
	if(document.recordForm.form_author.value.length > 50)
	{
		wrongValues += "- author must be shorter than 50\n";
		if(firstError == "") firstError = "form_author";
	}
	if(document.recordForm.form_source.value.length > 100)
	{
		wrongValues += "- source must be shorter than 100\n";
		if(firstError == "") firstError = "form_source";
	}
	if(document.recordForm.form_date_published_year.value.length > 4)
	{
		wrongValues += "- please enter a correct year\n";
		if(firstError == "") firstError = "form_date_published_year";
	}
	if(document.recordForm.form_url.value.length > 200)
	{
		wrongValues += "- url must be shorter than 200\n";
		if(firstError == "") firstError = "form_url";
	}
	
	if(emptyFields == "" && notSelected == "" && wrongValues == "") document.recordForm.submit();
	else
	{
		if(firstError != "") document.recordForm[firstError].focus();
		var msg = "";
		msg += "____________________________________________________\n\n";
		msg += "the form couln't be send because of the following errors.\nplease correct all errors!\n";
		msg += "____________________________________________________\n";
		
		if(emptyFields != "") msg += "\nmissing information:\n\n" + emptyFields;
		if(notSelected != "") msg += "\nyou have to select a value for the following fields:\n\n" + notSelected;
		if(wrongValues != "") msg += "\nthe following information is incorrect:\n\n" + wrongValues;
		msg += "\n____________________________________________________\n";
		
		alert(msg);
	}
}

function checkUserForm()
{
	var firstError = "";
	var emptyFields = "";
	var notSelected = "";
	var wrongValues = "";
	
	// text
	if(document.userForm.form_username.value == "")
	{
		emptyFields += "- username\n";
		if(firstError == "") firstError = "form_username";
	}
	if(document.userForm.form_first_name.value == "")
	{
		emptyFields += "- first name\n";
		if(firstError == "") firstError = "form_first_name";
	}
	if(document.userForm.form_last_name.value == "")
	{
		emptyFields += "- last name\n";
		if(firstError == "") firstError = "form_last_name";
	}
	if(document.userForm.form_email.value == "")
	{
		emptyFields += "- email\n";
		if(firstError == "") firstError = "form_email";
	}
	
	// select
	if(document.userForm.form_preferred_language.value == "")
	{
		notSelected += "- preferred language\n";
		if(firstError == "") firstError = "form_preferred_language";
	}
	if(document.userForm.form_use_cookies.value == "")
	{
		notSelected += "- use cookies\n";
		if(firstError == "") firstError = "form_use_cookies";
	}
	if(document.userForm.form_user_rank.value == "")
	{
		notSelected += "- userrank\n";
		if(firstError == "") firstError = "form_user_rank";
	}
	
	if(document.userForm.form_username.value.length > 15)
	{
		wrongValues += "- username must be shorter than 12\n";
		if(firstError == "") firstError = "form_username";
	}
	if(document.userForm.form_first_name.value.length > 25)
	{
		wrongValues += "- first name must be shorter than 25\n";
		if(firstError == "") firstError = "form_first_name";
	}
	if(document.userForm.form_last_name.value.length > 25)
	{
		wrongValues += "- last name must be shorter than 25\n";
		if(firstError == "") firstError = "form_last_name";
	}
	if(document.userForm.form_icq.value.length > 10)
	{
		wrongValues += "- icq must be shorter than 10\n";
		if(firstError == "") firstError = "form_icq";
	}
	if(document.userForm.form_msm.value.length > 10)
	{
		wrongValues += "- msm must be shorter than 10\n";
		if(firstError == "") firstError = "form_msm";
	}
	if(document.userForm.form_aim.value.length > 10)
	{
		wrongValues += "- aim must be shorter than 10\n";
		if(firstError == "") firstError = "form_aim";
	}
	if(document.userForm.form_hp.value.length > 150)
	{
		wrongValues += "- homepage must be shorter than 150\n";
		if(firstError == "") firstError = "form_hp";
	}
	if(document.userForm.form_date_of_birth_year.value.length > 4)
	{
		wrongValues += "- please enter a correct year\n";
		if(firstError == "") firstError = "form_date_of_birth_year";
	}
	if(document.userForm.form_country.value.length > 50)
	{
		wrongValues += "- country must be shorter than 50\n";
		if(firstError == "") firstError = "form_country";
	}
	
	if(emptyFields == "" && notSelected == "" && wrongValues == "") document.userForm.submit();
	else
	{
		if(firstError != "") document.userForm[firstError].focus();
		var msg = "";
		msg += "____________________________________________________\n\n";
		msg += "the form couln't be send because of the following errors.\nplease correct all errors!\n";
		msg += "____________________________________________________\n";
		
		if(emptyFields != "") msg += "\n\nmissing information:\n\n" + emptyFields;
		if(notSelected != "") msg += "\n\nyou have to select a value for the following fields:\n\n" + notSelected;
		if(wrongValues != "") msg += "\n\nthe following information is incorrect:\n\n" + wrongValues;
		msg += "\n____________________________________________________\n";
		
		alert(msg);
	}
}