// FLD - Forschungsleistungsdokumentation
// (c) 2002 by Gregor Retti
//
// default.js
/* window.onerror=null; */
// editor scripts

function set_bereich(sel_value,sel_text)
	{
	window.document.semem_form.bereich.value=sel_text;
	}

// validation scripts

function check_integer (obj,value)
	{
	if (!is_integer(value) && value.length > 0) {
		alert ("Numbers only!");
		obj.focus();
		return false;
		}
	else {
		return true;
		}
	}


function is_integer (value)
	{
	return (value == parseInt(value));
	}

function check_format (value, format)
	{
	if (value.length != format.length)
		{
		return false;
		}
	for (var i = 0; i < format.length; i++)
		{
		if (format.charAt(i) == '#' && !is_integer(value.charAt(i)))
			{
			return false;
			}
		else if (format.charAt(i) != '#' && format.charAt(i) != value.charAt(i))
			{
			return false;
			}
		}
	return true;
	}

function check_length (obj, value, max)
	{
	if (value.length > max)
		{
		alert ("Maximum size is " + max + "!");
		obj.focus();
		return false;
		}
	return true;
	}

function check_date_format (obj, value)
	{
	if (value.length == 0) {
		return true;
		}
	if (! check_format(value,"##-##-####"))
		{
		alert ("Date format is DD-MM-YYYY, e.g. 28-11-2002");
		obj.focus();
		return false;
		}
	return true;
	}

function check_date_or_year_format (obj,value)
	{
	if (value.length == 0) {
		return true;
		}
	if (check_format(value,"##-##-####")) {
		return true;	
		}
	if (check_format(value,"####")) {
		return true;
		}	
	alert ("Date format is DD-MM-YYYY, e.g. 28-11-2002, or year alone as YYYY!");
	obj.focus();
	return false;
	}

function check_isbn_format (obj,value)
	{
	if (value.length == 0) {
		return true;
		}
	if (check_format(value,"#-#-#######-#") ||
		check_format(value,"#-##-######-#") ||
		check_format(value,"#-###-#####-#") ||
		check_format(value,"#-####-####-#") ||
		check_format(value,"#-#####-###-#") ||
		check_format(value,"#-######-##-#") ||
		check_format(value,"#-#######-#-#"))
		{
		return true;
		}
	alert ("ISBN format is N-NNN-NNNNN-N, e.g. 0-672-32240-4");
	obj.focus();
	return false;
	}


function put_into_aut_search(sel_item)
	{
	if (sel_item.length > 0) {
		window.document.edit_author.s_aut_new.value=sel_item;
		window.document.edit_author.s_aut_new_hidden.value=sel_item;
		// window.document.forms[1].Insert.click();
		}
	}

function put_empty_into_aut_new()
	{
	window.document.edit_author.s_aut_new.value="";
	window.document.edit_author.s_aut_new_hidden.value="";
	}
