function createRequestObject()
{
	try
	{
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
	}
	return xmlhttp;
}

var http = createRequestObject();
var sess = createRequestObject();

// IMAGE REFRESHING

function refreshimg()
{
	var url = 'captcha/image_req.php';
	dorefresh(url, displayimg);
}

function dorefresh(url, callback)
{
	sess.open('POST', 'newsession.php', true);
	sess.send(null);
	http.open('POST', url, true);
	http.onreadystatechange = displayimg;
	http.send(null);
}

function displayimg()
{
	if(http.readyState == 4)
	{
		var showimage = http.responseText;
		document.getElementById('captchaimage').innerHTML = showimage;
	}
}


function sendForm(){
	if(validator.form()==false){
		return false;
	}
		var fnameVal = $("#fname").val();
		var lnameVal = $("#lname").val();
		var cemailVal = $("#cemail").val();
		var noteVal = $("#note").val();
		var captchaVal = $("#captcha").val();
		var subjectVal = $("#subject").val();
		//
			$('#form').hide();
			$("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
			
			$.post("contact.php",
   				{ fname: fnameVal, subject: subjectVal, lname: lnameVal, cemail: cemailVal, note: noteVal, captcha: captchaVal },
   					function(data){
						$("#form").slideUp("normal", function() {				   
							
							$("#form").before('<h1>Success</h1><p>Your email was sent! We will respond to you quickly.</p>');											
							scrollTo(0,0);	

						});
   					}
				 );
			return false;
}
