var errorArray;
var numError;

function reloadVerCode()
{
	document.getElementById('vercodeimg').src='imageVerification.php?q='+Math.random();
}

function verifyContactForm()
{
	document.getElementById('submitButton').disabled=true;
	d('loading','block');
	errorArray = new Array();
	numError = 0;

	if (document.getElementById('customer_type').value == "other" && !isValidText(trim(document.getElementById('customer_type_other').value), 1, 15, true))
		errorArray[numError++] = "Customer Type||customer_type_other";;
	if (!isValidText(trim(document.getElementById('name').value), 1, 30, true))
		errorArray[numError++] = "Name||name";
	if (!isValidPhone(trim(document.getElementById('phone').value), false))
		errorArray[numError++] = "Phone||phone";
	if (!isValidPhone(trim(document.getElementById('phone').value), 1, 30, true) && !isValidText(trim(document.getElementById('email').value), 1, 100, true))
		errorArray[numError++] = "Valid E-Mail or Phone||email";
	if (document.getElementById('country').value == "other" && !isValidText(trim(document.getElementById('country_other').value), 1, 15, true))
		errorArray[numError++] = "Country||country_other";
	if (!isValidText(trim(document.getElementById('message').value), 1, null, true))
		errorArray[numError++] = "Message||message";
	
	doAjax('controller.php?action=isvalidvercode&vercode='+trim(document.getElementById('verification').value),'vercode');
}

function finishVerifyContactForm()
{
	// set all backgrounds to good (white)
	document.getElementById('message').style.backgroundColor = "#FFFFFF";
	document.getElementById('message').style.fontWeight = "normal";
	var elements = document.getElementsByTagName("input");
	for(j in elements)
	{
		if (elements[j].type == "text" && elements[j].id != "keyword-search")
		{
			elements[j].style.backgroundColor="white";
			elements[j].style.fontWeight="normal";
		}
	}
	
	var outputError = "The following fields have not been filled in properly: \n\n";
	var data;
	for (error in errorArray)
	{
		data = errorArray[error].split("||");
		outputError += data[0]+"\n";
		document.getElementById(data[1]).style.backgroundColor="red";
		document.getElementById(data[1]).style.fontWeight="bold";
	}

	document.getElementById('submitButton').disabled=false;
	d('loading','none');
	
	if (numError > 0)
	{
		document.getElementById('verification').value='';
		reloadVerCode();
		alert (outputError);
		return false;
	}
	else
	{
		document.getElementById('inforequestform').submit();	
	}	
}