function chInput(form)
{
	// declare arrays to hold all the errors
	var req_error = new Array();
	var email_error = new Array();
	var num_error = new Array();
	var phone_error = new Array();
	var letters_error = new Array();
	var popup_msg = def_popup_msg;
	
	// prepare arrays for the field formating
	var numeric = new Array();
	var email = new Array();
	var phone = new Array();
	var letters = new Array();
	
	//fill arrays
	for (var i=0; i<format.length; i++)
	{
		var o = format[i];
		var n = o.split("=");

		if (n[1] == "email") email[email.length]= n[0];
		if (n[1] == "phone") phone[phone.length]= n[0];
		if (n[1] == "numeric") numeric[numeric.length]= n[0];		
		if (n[1] == "letters") letters[letters.length]= n[0];		 
	}

	
	// for each of the form's fields
	for(var i = 0; i < form.length; i++) 
	{
		var e = form.elements[i];
		// check for required fields 
		for (var r = 0; r < required.length; r++)
		{
			if (e.name == required[r])
			{
				 var error = false;
				 error = checkRequired(e);
				 if (error)	req_error[req_error.length] = e.name; // store errors in the req_error array
			}
		}
		// check for fields which are supposed be numerical
		for (var n=0; n < numeric.length; n++)
		{
			if (e.name == numeric[n])
			{

				 var error = false;
				 error = checkPattern(e,/[^\d\.\,]/);
				 if (error)	num_error[num_error.length] = e.name;  // store errors in the num_error array
			}
		}
		// check for correct email formating - this one is not too sophisticated though..
		for (var m=0; m < email.length; m++)
		{
			if (e.name == email[m])
			{
				 var error = false;
				 error = checkEmail(e);
				 if (error)	email_error[email_error.length] = e.name;  // store errors in the email_error array
			}
		}
		// check for correct formating of the phone fields 
		for (var p =0; p < phone.length; p++)
		{
			if (e.name == phone[p])
			{
				var error = false;
				error =checkPattern(e, /[^\d()\s-]/);
				if (error) phone_error[phone_error.length] = e.name;  // store errors in the phone_error array
			}
		}
		// check for correct formating of the alphabetical fields
		for (var l =0; l < letters.length; l++)
		{
			if (e.name == letters[l])
			{
				var error = false;
				error =checkPattern(e, /[^A-Za-z\s\.\'\-]/);
				if (error) letters_error[letters_error.length] = e.name;  // store errors in the letters_error array
			}
		}
		// clear images in case of there was previouslly an arrow
		if (document.images[e.name]) // if such image exists
		{
			document.images[e.name].src = clear_img;
		}
	}

	if (req_error.length > 0)
	{
		popup_msg += "\n\n" + req_msg;

		// prepare the error mesage
		for (var i=0; i<req_error.length; i++)
		{
			var name = req_error[i];
			// change the image to the little blinking arrow 
			swapImg(name);
			// find the nice name for the error message
			name = lookupName(name);
			popup_msg += "\n          . " + name;
		}
	}
	
	if ( num_error.length >0 )
	{
		popup_msg += "\n\n" + num_msg;
		for (var i=0; i<num_error.length; i++)
		{
			var name = num_error[i];
			// change the image to the little blinking arrow 
			swapImg(name);
			// find the nice name for the error message
			name = lookupName(name);
			popup_msg += "\n          . " + name;		}
	}
	
	if (letters_error.length >0)
	{
		popup_msg += "\n\n" + letters_msg;
		for (var i=0; i<letters_error.length; i++)
		{
			var name = letters_error[i];
			// change the image to the little blinking arrow 
			swapImg(name);
			// find the nice name for the error message
			name = lookupName(name);
			popup_msg += "\n          . " + name;		}
	}
	
	if (phone_error.length >0)
	{
		popup_msg += "\n\n" + phone_msg;
		for (var i=0; i<phone_error.length; i++)
		{
			var name = phone_error[i];
			// change the image to the little blinking arrow 
			swapImg(name);
			// find the nice name for the error message
			name = lookupName(name);
			popup_msg += "\n          . " + name;		}
	}
	
	if (email_error.length >0)
	{
		popup_msg += "\n\n" + email_msg;
		for (var i=0; i<email_error.length; i++)
		{
			var name = email_error[i];
			// change the image to the little blinking arrow 
			swapImg(name);
			// find the nice name for the error message
			name = lookupName(name);
			popup_msg += "\n          . " + name;		}
	}
	
	if (popup_msg == def_popup_msg)
	{
		return true;  // popup message did not change -- no errors found clear for submitting
	}
	else
	{	
		alert(popup_msg);  // display popup message
		return false;
	}

}

function checkRequired(element)
{
	var result = false;

	if (element.value == "")
	{
        result = true;
	}
	
	if ((element.type == "radio") && (element.checked == false))
	{
		result = false;
	}
	return (result);
}

function checkPattern(element, pattern)
{
	var result = false;
	if (pattern.test(element.value) && element.value != "") // do not match if value is empty
	{
        result = true;
	}
	return (result);
}

function checkEmail(element)
{
	var result = false;
	if (element.value != "")// do not test if value is empty
	{
		if ((element.value.indexOf('@',0) == -1) || (element.value.indexOf('.',0) == -1)) result = true;
	}
	return (result);
}

function swapImg(img_name)
{
	//not used
}

function lookupName(bad_name)
{
	var result = bad_name;
	for (var q=0; q<nice_names.length; q++)
	{
		if (nice_names[q].indexOf(bad_name) == 0)  // the field name must start on the first position in the string 
		{
			// string with the nice name found - split it and use it..
			var n = nice_names[q].split("=");  // split into array 
			good_name = n[1];      // use the part after = to change the name
			result = good_name;
			break;			 //	 no need to look any further the same field name can appear only once
		}
	}
	return result;  // nice name if found or bad name if not found
}
