Event.observe(window, 'load', page_loaded, false);
	
function page_loaded(evt) {
	Event.observe('name',                  'blur',   checkFormItem, false);
	Event.observe('email',                 'blur',   checkEmail, false);
	Event.observe('question',                  'blur',   checkFormItem, false);
	Event.observe('verzenden',		   'click',  verzenden, false);
	$('name').focus();
}

function verzenden(evt){
	showIndicator();
	check( "checkEmail",    "email" );
	check( "checkInput",    "name" );
	check( "checkInput",    "question" );
	ajaxLock();
}

function check ( which, what ) {
	// TODO finish this 
	//var form   = document.forms[0].name;
	var form = "contact";
	eval ("var elem   = document." + form + "." + what + ";");  
	eval ("var url    = baseurl + 'ajax/" + which + "';");
	var rand   = Math.random(9999);
	var pars   = 'id=' + elem.id + '&value=' + elem.value + '&form= ' + form + '&rand=' + rand;
	var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onLoading: false, onComplete: responseForm} ); 
}

function ajaxLock () {
	var url    = baseurl + 'ajax/lock';
	var rand   = Math.random(9999);
	var pars   = 'rand=' + rand;
	var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onLoading: false, onComplete: ajaxUnlock} ); 
}

function ajaxUnlock () {
	formSubmit();
}

function formSubmit() {
	hideIndicator();
    	if ($('errors').innerHTML.blank()) {
    		document.contact.submit();
		return true;
	}
	return false;
}

function showIndicator() {
	$('indicator').style.display = "block";
}

function hideIndicator() {
	$('indicator').style.display = "none";
}