var xmlHttp

function checkUser(usr)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="ajax/guestbook_user.php"
	url=url+"?name="+usr
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=NameStateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function checkPass(usr,pas)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="ajax/guestbook_user.php"
	url=url+"?name="+usr
	url=url+"&password="+pas
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=NameStateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function NameStateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("nameHint").innerHTML=xmlHttp.responseText 
	} 
}
function reloadImage()
{
	document.getElementById('verificationHint').src = document.getElementById('verificationHint').src + "?sid="+Math.random();
	document.getElementById('code').value="";
	document.getElementById('code').focus();
}
function checkCode(code)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="ajax/guestbook_code.php"
	url=url+"?code="+code
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=CodeStateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function CodeStateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		if(xmlHttp.responseText!="")
			document.getElementById("code").value=xmlHttp.responseText
	} 
}
function cleanCode(codeValue)
{
	with(document.getElementById("code"))
	{
		if(value=="CODE DOES NOT MATCH!")
		{
			value="";
		}
	}
}
function focusMessage()
{
	document.getElementById('message').focus();
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function validateForm(form)
{
	with(form)
	{
		if(code.value=="" || code.value=="CODE DOES NOT MATCH!")
		{
			alert("Verification code is missing or is incorrect!");
			code.focus();

			return false;
		}

		if(!validateField(name,"Name is missing!"))
		{
			return false;
		}

		if(!validateField(message,"The actual message is missing!"))
		{
			return false;
		}

		
	}

	return true;
}

function validateField(field,message)
{
	with(field)
	{
		if(value==null || value=="")
		{
			alert(message);
			focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}
