
// array to hold the initial values of the controls
var $text_defaults = new Array();

// attach the onload event
window.onload = do_onload;

/**
 * onload event handler
 *
 * Store the inital values of all the document's input and textareaa, and attached events
 * for their onfocus and onblur events. Also attach the form submit behavior to the 
 * send button.
 */
function do_onload() {
	$controls = new Array('input', 'textarea');

	for ($y = 0; $y < $controls.length; $y++) {
		$inputs = document.getElementsByTagName($controls[$y]);
	
		for ($x = 0; $x < $inputs.length; $x++) {
			if ($inputs[$x].value != '') {
				$text_defaults[$inputs[$x].name] = $inputs[$x].value;
				$inputs[$x].onfocus = do_onfocus;
				$inputs[$x].onblur = do_onblur;
			}
		}
	}
	
	$send_button = document.getElementById('send');

	if (!$send_button) {
		return false;
	}

	$send_button.onclick = function() {
		document.getElementById('contact_form').submit();
		return false;
	}
}

/**
 * onblur event handler
 *
 * If the control's value is empty, set it back to the inital value
 */
function do_onblur() {
	if (this.value == '') {
		this.value = $text_defaults[this.name];	
	}
}

/**
 * onfocus event handler
 *
 * If the control's value is the default value, set it to blank
 */
function do_onfocus() {
	if (this.value == $text_defaults[this.name]) {
		this.value = '';	
	}
}
