function colorsInit(colorOk,id_array)
{
	for (x = 0; x < id_array.lenght; x++)
   {
	   document.getElementById(id_array[x]).style.backgroundColor=colorOk;
	   document.getElementById(id_array[x]).style.backgroundImage='none';
   }
}

function errorDisplay(objID,message,colorError,colorOk,obj)
{
	document.getElementById(objID).style.backgroundColor=colorError;
	document.getElementById(objID).focus();
	obj.innerHTML = message;
}

function makerequest(serverPage,objID,divID)
{
var obj = document.getElementById(objID);
var obj2 = document.getElementById(divID);
var xmlhttp;
	if (window.ActiveXObject)
	{
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else 
	{
	xmlhttp = new XMLHttpRequest();	
	}
xmlhttp.open("GET",serverPage);
xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{	
			var colorError = "yellow";
			var colorOk = "#FFFFFF";

				var id_array = new Array("question_name","question_email","question_phone","question_contents");
				colorsInit(colorOk,id_array);
	
				if (xmlhttp.responseText == 'question_name_empty')
				{
					errorDisplay('question_name','Please type in your name.',colorError,colorOk,obj);
				}
				else if (xmlhttp.responseText == 'question_email_empty')
				{
					errorDisplay('question_email','Please type in your email.',colorError,colorOk,obj);
				}		
				else if (xmlhttp.responseText == 'question_email_invalid')
				{
					errorDisplay('question_email','Please type in your email correctly.',colorError,colorOk,obj);
				}
				else if (xmlhttp.responseText == 'question_phone_empty')
				{
					errorDisplay('question_phone','Please type in your phone #.',colorError,colorOk,obj);
				}
				else if (xmlhttp.responseText == 'question_contents_empty')
				{
					errorDisplay('question_contents','Please type in your message',colorError,colorOk,obj);
				}
				else if (xmlhttp.responseText == 'OK')
				{
				colorsInit(colorOk,id_array);
 				obj.innerHTML = '<img src="i/spinner_white.gif" />&nbsp;Processing...';
				//alert(document.getElementById('textF').value);
				obj2.innerHTML = 'Thank you for your question.<br/><a href="javascript:window.location.reload( false );">Send another message...</a>';
				}
				else
				{
					obj.innerHTML = xmlhttp.responseText;
				}
			
		}
		else if (xmlhttp.readyState == 1)
		{
			obj.innerHTML = '<img src="i/spinner_white.gif" />&nbsp;Processing...';
		}
		
		
	}
xmlhttp.send(null);
}

function validate_question_form(question_name,question_email,question_phone,question_contents)
{
	serverPage = "validator.php?action=validate_question&question_name=" + question_name + "&question_email=" + question_email + "&question_phone=" + question_phone + "&question_contents=" + question_contents;
	objID = "question_message_box";
	divID = "contact_form";
	makerequest(serverPage,objID,divID);
}