/*
	iskele.js
	v1.0 - 28/mrt/2006 - Bob Kersten - Initial version.
	(C) Copyright 2006 iskele.
	All rights reserved.
*/

var framework = new iskeleFramework();

function submitContactForm() {
	// This function tries to send the contact form to the server using ajax techniques.
	var form = document.forms['contactForm'];

	// Let's revert all the fields to their original state and appearance and remove
	// any error message that might be visible.
	var fields = Array('field_name', 'field_company', 'field_phone', 'field_email', 'field_question');
	var field, error;
	if (error = document.getElementById('error')) error.className = 'invisible';
	for (i = 0; i < fields.length; i++)
		if (field = document.getElementById(fields[i])) field.className = 'field';

	// Then we're going to use the framework to push the fields to the server and wait for
	// an error or notification.
	framework.requestPostUrl(form.getAttribute('action'), form, function(result_) {
		if (result_.indexOf('|') > -1) {
			// Something went wrong while processing the contact form. Let's show the user
			// the returned error message and highlight the erroneous field.
			var errors = result_.split('|');
			error.innerHTML = errors[0];
			error.className = '';
			fields = errors[1].split(';');
			for (i = 0; i < fields.length; i++) {
				field = document.getElementById(fields[i]);
				if (i == 0) field.focus();
				if (field) {
					field.className = 'errorfield';
				}
			}
		} else {
			// The form was processed successfully, so post the returned notice in the field
			// destined for notifications.
			var notice = document.getElementById('notice');
			notice.innerHTML = result_;
			notice.className = '';
			var div = document.getElementById('fields');
			div.className = 'invisible';
			error.className = 'hidden';
		}
	} );
	return false;
}