// JavaScript - Contact Page

var xmlHttp;
var field;

function GetXmlHttpObject()
{
	var xmlHttp = null;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function validateForm(str, meth, id)
{
	if(str.length == 0)
	{
		ID.document.getElementById(id);
		ID.innerHTML = "";
		return
	}

	field = id;
	xmlHttp = GetXmlHttpObject();

	var url = "_ajaxHandler.php";
	url = url+"?mode=formval";
	url = url+"&str="+str;
	url = url+"&meth="+meth;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChanged()
{
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		formStyle(field, xmlHttp.responseText);
	}
}

function formStyle(id, style)
{
	if(style == 'correct')
	{
		ID = document.getElementById(id);
		ID.style.border = '2px #00CC00 solid';
		ID.style.background = '#CCFFCC';
		ID.style.color = '#000000';
	}
	else if(style == 'error')
	{
		ID = document.getElementById(id);
		ID.style.border = '2px #FF0000 solid';
		ID.style.background = '#FFCCCC';
		ID.style.color = '#000000';
	}
	else if(style == 'default')
	{
		ID = document.getElementById(id);
		ID.style.border = '2px #339999 solid';
		ID.style.background = '#FFFFFF';
		ID.style.color = '#000000';
	}
	else
	{
		ID = document.getElementById(id);
		ID.style.border = '2px #339999 solid';
		ID.style.background = '#FFFFFF';
		ID.style.color = '#000000';
	}
}