/**********************************************************************************
 * JavaScript File
 * this file contains all the used javascript functions
 *
 * Created: 21/5/2005 | Modified: 23/10/2005
 * Author: C.A. Nouta
 *
 * Copyright (c) 2005 Sanware. 
 * All rights reserved.
 **********************************************************************************/

/* the fields that may not be empty */
var Fields	= new Array( 0, 1, 2 );

/* the error messages for the empty fields */
var Errors	= new Array();
Errors[0]	= "Vergeet niet uw naam in te vullen!";
Errors[1]	= "Vergeet niet uw e-mail adres in te vullen!";
Errors[2]	= "Vergeet niet uw bericht in te vullen!";

/**
 * Trim
 * this functions removes whitespace at the begin and end of a string
 * @param str - the string where we want to remove the whitespaces from
 * @return the string str without the whitespaces at the begin and end
 */
function Trim(str) { return str.replace(/^\s*|\s*$/g,""); }

/**
 * CheckField
 * checks if the given field is empty
 * @param id - the number of the field to check
 * @return true || false
 */
function CheckField(id) { return !( Trim(document.emailform.elements[Fields[id]].value) == ""); } 

/**
 * CheckForm
 * this function checks a whole form if all the wanted fields are applied
 * @return true || false
 */
function CheckForm() {

	var isOk	= new Boolean(true);	/* is the form correct */
	var	i		= -1;					/* to specify the field */

	/* check every wanted field */
    progress:
	for (i = 0; i <= (Fields.length - 1); i++)
		if (CheckField(i) == false) {
			
			/* field is empty */
			isOk = false;
			break progress;

		} 

	/* if there is a error */
	if (isOk == false) {
		
		/* give a warning */
		alert(Errors[i]);
		document.emailform.elements[Fields[i]].focus(); 

	}

	/* return the result */
	return isOk;

}
