/*********************************************************************
This function tests, wether a formfield exists. The function is extendable 
for formfields on layers
input values:
	layername:		actually not used
	formName:		name of the formfield
	formfieldname:	name of the searched formfield
 return codes:
	 1				exists
	-1				form doesn't exist
	-2 				formfield doesn't exist
*********************************************************************/
function formfieldExists(layerName, formName, formfieldName) {
	if (document.forms[formName]) {
		if (document.forms[formName].elements[formfieldName]) {
			// formfield exists
			return 1
		} else {
			// form exists, but not the specified formfield
			return -2
		}
	} else {
		// form doesn't exist
		return -1
	}
}

/*********************************************************************
This function returns the value of a searched formfield.
It will not actually not test, if the formfield exists or
not, and if the formfield has the correct type (text,
hidden, textarea)
input values:
	layername:		actually not used
	formName:		name of the formfield
	formfieldname:	name of the searched formfield
return value:
	value of the searched formfield
*********************************************************************/
function getTextfieldValue (layerName, formName, formfieldName) {
	return document.forms[formName].elements[formfieldName].value
}

function setTextfieldValue(layerName, formName, formfieldName, formfieldValue) {
	document.forms[formName].elements[formfieldName].value = formfieldValue;
	return true;
}

/*********************************************************************
This function returns the value of a checkbox.
It will not actually not test, if the formfield exists or
not, and if the formfield is of type checkbox.
input values:
	layername:		actually not used
	formName:		name of the formfield
	formfieldname:	name of the searched formfield
return value:
	value of the checkbox
*********************************************************************/
function getCheckboxChecked (layerName, formName, formfieldName) {
	if (document.forms[formName].elements[formfieldName].checked) {
		return 1
	} else {
		return 0
	}
}

/*********************************************************************
This function returns the value of a selectbox.
It will not actually not test, if the formfield exists or
not, and if the formfield is of type select.
It is not useable for selects with multiple choices
input values:
	layername:		actually not used
	formName:		name of the formfield
	formfieldname:	name of the searched formfield
return value:
	value of the searched selectbox
*********************************************************************/
function getSelectboxValue(layerName, formName, formfieldName) {
	var selIndex = document.forms[formName].elements[formfieldName].selectedIndex
	return document.forms[formName].elements[formfieldName].options[selIndex].value
}


function focusOnFormfield(layerName, formName, formfieldName) {
	document.forms[formName].elements[formfieldName].focus()
}

