/**************************************************
 * Empties the field value of a field that contains
 * an anonimised message if the field is not set.
 * IN : field: [object] The field that should be
 *             changed.
 *      store: [scalar] The name of the field to
 *             store into whether the field is
 *             set to anonymous or not.
 *      color: [scalar] The text color to change
 *             to.
 * OUT: success [true| false]
 */
function anon_input_on(field, store)
{
	var result = false;
	var fstore;
	
	if (document.all)
		fstore = document.all(store);
	else if (document.getElementById)
		fstore = document.getElementById(store);
	
	if ((field) && (fstore) && (fstore.value == '1'))
	{
		if (!field.message)
			field.message = field.value;
		fstore.value = '0';
		field.value = '';
	}
	
	return result;
}

/**************************************************
 * Changes the field value of a field that contains
 * an anonimised message to that message if the
 * field is blurred and empty.
 * IN : field: [object] The field that should be
 *             changed.
 *      store: [scalar] The name of the field to
 *             store into whether the field is
 *             set to anonymous or not.
 *      color: [scalar] The text color to change
 *             to.
 * OUT: success [true| false]
 */
function anon_input_off(field, store)
{
	var result = false;
	var fstore;
	
	if (document.all)
		fstore = document.all(store);
	else if (document.getElementById)
		fstore = document.getElementById(store);
	
	if ((field) && (fstore))
		if (field.value.match(/^\s*$/))
		{
			if (field.message)
				field.value = field.message;
			fstore.value = '1';
		}
	
	return result;
}

/**************************************************
 * Validates whether required anonimised fields
 * have been set.
 * IN : an array of field_name, anon_field_name
 * OUT: success [true| false]
 */
function validate_anon_input()
{
	var result = true;
	
	var rest = arguments.length % 2;
	
	for (var i = 0; i < (arguments.length - 1) / 2; i++)
	{
		var field;
		var anon;
		
		if (document.all)
		{
			field = document.all(arguments[i * 2]);
			anon = document.all(arguments[(i * 2) + 1]);
		} else if (document.getElementById)
		{
			field = document.getElementById(arguments[i * 2]);
			anon = document.getElementById(arguments[(i * 2) + 1]);
		}
		
		if ((field) && (anon) && (anon.value == '1'))
		{
			result = false;
			field.focus();
			window.alert('Dit veld is een verplicht veld.');
			break;
		}
	}
	
	return result;
}