/* 
 * Javascript / Ajax engine
 * Contact Form
 * @author Mark Graves
 * @version 05/11/2007
*/

// XMLHttpRequest initialization for AJAX
var xhr = null;

function get_xhr() {
	if( window.XMLHttpRequest ) { // Firefox et autres
		xhr = new XMLHttpRequest(); 
	} else if( window.ActiveXObject ) { // Internet Explorer 
		try {
			xhr = new ActiveXObject( "Msxml2.XMLHTTP" );
		} catch( e ) {
			xhr = new ActiveXObject( "Microsoft.XMLHTTP" );
		}
	} else { // XMLHttpRequest non support par le navigateur 
		alert( "Your browser don't support XMLHTTPRequest..." ); 
		xhr = false; 
	}
}

// Start waiting
function startWait() {
	document.getElementById('wait').style.display = "block";
}

// Stop waiting
function stopWait() {
	document.getElementById('wait').style.display = "none";
}

// Paste selected parameters on the select container
function sendContact() {
	startWait();
	// Instanciate ajax
	get_xhr();
	// call ajaxSiteEngine.inc.php on POST and asynchronimous method
	xhr.open ( "POST", "/js/ajaxContact.inc.php", true );
	xhr.setRequestHeader ( 'Content-Type', 'application/x-www-form-urlencoded' );
	// send parameters
	xhr.send ( "action=send_contact&your_name=" + document.getElementById('your_name').value + "&your_email=" + document.getElementById('your_email').value + "&your_message=" + document.getElementById('your_message').value + "&code=" + document.getElementById('code').value );
	// return result
	xhr.onreadystatechange = function () {
		// Do anything only if server request true
		if( ( xhr.readyState == 4 ) && ( xhr.status == 200 ) ) {
			var result = xhr.responseText;
			eval( result );
		}
		//stopWait(); Uncomment if loading leave on page
	}
	return true;
}

