/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();

/* -------------------------- */
/* Contact */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */

var nocache = 0;
function contact_form() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('login_response').innerHTML = "<div id='contact_error'><img src='img/loader.gif' alt='loading' style='height:14px;' />     Loading...</div>"

// Required: verify that all fileds are not empty. Use encodeURI() to solve some issues about character encoding.
var name = encodeURI(document.getElementById('name').value);
var email = encodeURI(document.getElementById('email').value);
var enquiry = encodeURI(document.getElementById('enquiry').value);

// Set the random number to add to URL request
nocache = Math.random();

// Pass the form variables like URL variable
http.open('get', 'js/send_email.php?name='+name+'&email='+email+'&enquiry='+enquiry+'&nocache = '+nocache);
http.onreadystatechange = Reply;
http.send(null);
}
	function Reply() {
		if(http.readyState == 4){ 
		var response = http.responseText;
		 
		if(response == 1){
		// if fields are empty
		document.getElementById('login_response').innerHTML = 'Please fill in all the fields.';
		}
		else if(response == 2){
		// if email isnt valid
		document.getElementById('login_response').innerHTML = 'Please enter a valid email..';
		}
		else if(response == 3){
		// if email has been sent
		document.getElementById('contact_form').innerHTML = '<div id="contact_success">Your enquiry has been sent.</div>';
		}
		else if(response == 10){
		// if email hasnt been sent
		document.getElementById('login_response').innerHTML = 'Your email has not been sent.';
		}
		
	}
}


