/*
form.js

Contains:
submitForm()
checkFormForDefaultValues()

Written by Meinaart van Straalen - Zicht nieuwe media ontwerpers b.v. (c) 2005
*/

// Submits a form, checks if a form has a onsubmit handler.
// If that's the case it only submits the form when the onsubmit handler returns true.
// This function is used for submitting forms with javascript without breaking the onsubmit
// form validation.
function submitForm( form ) {
	if( form.onsubmit != undefined ) {
		if( form.onsubmit() ) {
			form.submit();
		}
	} else {
		form.submit();
	}
}

// Loops through all form elements and checks for a "focusValue" attribute
// If exists it adds focusValue functionality:
// - onfocus make value empty
// - onblur restore focusValue if value is still empty
// - fills value with focusValue
function checkFormForFocusValues( form ) {
	for( var i = 0; i < form.elements.length; i++ ) {
		if( form.elements[i].getAttribute( "focusValue" ) != null &&
			form.elements[i].getAttribute( "focusValue" ) != "" ) {
			
			form.elements[i].onfocus = function() {
				if( this.value == this.getAttribute( "focusValue" ) ) {
					this.value = "";
				}
			}
			form.elements[i].onblur = function() {
				if( this.value == "" ) {
					this.value = this.getAttribute( "focusValue" );
				}
			}
			form.elements[i].onblur();
		}
	}
}

// Checks all forms in current document
function checkForms() {
	if( !document.getElementById ) return;
	
	var forms = document.forms;
	for( var i = 0; i < forms.length; i++ ) {
		checkFormForFocusValues( forms[i] );
	}
}
