function validate_captcha()
{
	form = document.getElementById("contact-us-form");
	if (checkContactForm(form))
	{
		url="captcha2/captcha.php?"+getCaptchaData(form);
		loadXML(url,showStat)
	}
	else
		return false;
}
function showStat()
{
	var msg="";
	var proceed="";
	var nodes=xdoc.getElementsByTagName("proceed");
	if(nodes[0].childNodes[0])
		proceed=nodes[0].childNodes[0].nodeValue;
	nodes=xdoc.getElementsByTagName("msg");
	if(nodes[0].childNodes[0])
		msg=nodes[0].childNodes[0].nodeValue;
	if(proceed=="Y" && msg=="")
	{
		//document.form.submit();
		window.location = "thankyou.html";
	}
	else
	{
		//alert(msg);
		hideAllErrors();
		document.getElementById("captchaError").style.display = "inline";
		//document.getElementById("freecap").focus();
		//return false;
		new_freecap();
		document.getElementById("contact-us-form").word.focus();
	}
}
function new_freecap()
{
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload image\nSubmit the form and a new image will be loaded");
	}
}

function getCaptchaData(form)
{
	var str='';
	for(var i=0;i<form.elements.length;i++)
	{
		var itm=form.elements[i];
		if(itm.name)// && itm.value)
		{   
		    if(itm.type=="radio" || itm.type=="checkbox" ) 
			{
				if(itm.checked)
					str+=itm.name+"="+itm.value+"&";
			}
		    else
				str+=itm.name+"="+itm.value+"&";
		}
	}	
	return(str)
}
function loadXML(url,doFunc)
{
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	else
		alert('Your browser cannot handle this script');
	// xmlhttp.onreadystatechange=getAll;
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
            if (xmlhttp.status==200)
			{
				xdoc=xmlhttp.responseXML;				
				doFunc();
			}
			else
  			  alert("Problem retrieving XML data:" + xmlhttp.statusText)
	}		
    xmlhttp.open("GET",url,true)
    xmlhttp.send(null)
}