function check_registration()
{
	var frm 		= document.getElementById('registration');
	var error_found = false;

	clear_errors();

	// Check email
	if (frm.email.value == '')
	{
		setError('emaillabel');
		error_found = true;
	}
	// Check password
	if (frm.password.value == '')
	{
		setError('passwordlabel');
		error_found = true;
	}
	if (frm.password2.value == '')
	{
		setError('password2label');
		error_found = true;
	}
	if (frm.password.value != frm.password2.value)
	{
		setError('passwordlabel');
		setError('password2label');
		error_found = true;
	}
	if (frm.firstname.value == '')
	{
		setError('namelabel');
		error_found = true;
	}
	else
	{
		if (frm.lastname.value == '')
		{
			setError('namelabel');
			error_found = true;
		}
	}
	return !(error_found);
}
function check_contact_form()
{
	var aIndex = document.getElementById('nature_of_enquiry').value;


	for (oNatureType in aList)
	{
		if(aList[oNatureType].label == aIndex)
		{
			iErrorsFound = check_form_items(aList[oNatureType]);
		}
	}

	if (iErrorsFound == 1)
		alert(iErrorsFound + " error was found.");
	else if(iErrorsFound > 1)
		alert(iErrorsFound + " errors were found.");
	else
		return true;

	return false;
}
function check_form_items(oItems)
{
	var iErrorsFound = 0;
	for (iId in oItems.fields)
	{
		oElement = oItems.fields[iId];
		//alert(iId + ': ' + oElement.type);
		if(document.getElementById(oElement.name).value == '')
		{
			// Whoops, you didn't fill everything out!
			// Naughty you!! :)
			setError(document.getElementById('title_' + oElement.name));
			iErrorsFound ++;
		}
		else if (iId > 0)
		{
			unsetError(document.getElementById('title_' + oElement.name));
		}
	}

	if(document.getElementById('brief_details').value == '')
	{
		setError(document.getElementById('title_brief_details'));
		iErrorsFound ++;
	}
	else
		unsetError(document.getElementById('title_brief_details'));

	if(document.getElementById('other_comments_or_ideas').value == '')
	{
		setError(document.getElementById('title_other_comments_or_ideas'));
		iErrorsFound ++;
	}
	else
		unsetError(document.getElementById('title_other_comments_or_ideas'));

	return iErrorsFound;
}
function setError(oObject)
{
	oObject.className = 'error';
	//alert(oObject.className);
}
function unsetError(oObject)
{
	if (oObject.className == 'error')
		oObject.className = 'kop';
}

function update_fields()
{
	var aIndex = document.getElementById('nature_of_enquiry').value;

	// Clean it out!
	document.getElementById('variable_details').innerHTML = '';

	for (oNatureType in aList)
	{
		if(aList[oNatureType].label == aIndex)
		{
			if (aList[oNatureType].fields.length > 0)
			{
				generate_form(aList[oNatureType]);
				document.getElementById('details').style.display = 'block';
			}
			else
				document.getElementById('details').style.display = 'none';
		}
	}
}
function generate_form(oItems)
{
	var oDiv = document.getElementById('variable_details');
	sHTML = '';
	for (iId in oItems.fields)
	{
		// Let's build the HTML here!
		oElement = oItems.fields[iId];
		if (oElement.type == 'text')
		{
			// Create a text-element
			sHTML = sHTML + '<div class="kop" id="title_' + oElement.name + '">' + oElement.label + '</div>';
			sHTML = sHTML + '<div class="text"><input tabindex="' + iId + '" type="text" id="' + oElement.name + '" name="' + oElement.name + '" value="' + oElement.values + '" /></div>';
		}
		else if (oElement.type == 'textarea')
		{
			// Create a text-element
			sHTML = sHTML + '<div class="kop" id="title_' + oElement.name + '">' + oElement.label + '</div>';
			sHTML = sHTML + '<div class="text"><textarea tabindex="' + iId + '" name="' + oElement.name + '" id="' + oElement.name + '">' + oElement.values + '</textarea></div>';
		}
		else if (oElement.type == 'select')
		{
			// Create a text-element
			sHTML = sHTML + '<div class="kop" id="title_' + oElement.name + '">' + oElement.label + '</div>';
			sHTML = sHTML + '<div class="text"><select tabindex="' + iId + '" name="' + oElement.name + '" id="' + oElement.name + '">';

			sOptions = '';
			for(iValuesId in oElement.values)
			{
				sOptions = sOptions + '<option value="' + oElement.values[iValuesId] + '">' + oElement.values[iValuesId] + '</option>';
				//document.getElementById(oElement.name).options[iTeller] = new Option(oElement.values[iValuesId], oElement.values[iValuesId]);
			}

			sHTML = sHTML + sOptions + '</select></div>';

		}
	}
	oDiv.innerHTML = sHTML;
}
function update_fields_old()
{
	var sType = document.getElementById('nature_of_enquiry').value;

	document.getElementById('business_development').style.display = 'none';
	document.getElementById('education').style.display = 'none';
	document.getElementById('entertainment_personal_use').style.display = 'none';
	document.getElementById('member_of_the_press').style.display = 'none';

	if (sType != '')
	{
		document.getElementById(sType).style.display = 'block';
		document.getElementById('details').style.display = 'block';
	}
	else
	{

		document.getElementById('details').style.display = 'none';
	}
}