function create_object(){
	var request_type;
	
	try{
		// Opera 8.0+, Firefox, Safari
		request_type = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			request_type = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request_type = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// other
				alert("Your browser broke!");
				return false;
			}
		}
	}
	return request_type;
}

var http = create_object();
var nocache = 0;


function contact() {

document.getElementById('contact_result').innerHTML = "<p></p>";

var name = encodeURI(document.getElementById('name').value);
var email = encodeURI(document.getElementById('email').value);
var company = encodeURI(document.getElementById('company').value);
var phone = encodeURI(document.getElementById('phone').value);
var fax = encodeURI(document.getElementById('fax').value);
var country = encodeURI(document.getElementById('country').value);
var state = encodeURI(document.getElementById('state').value);
var city = encodeURI(document.getElementById('city').value);
var address = encodeURI(document.getElementById('address').value);
var zip = encodeURI(document.getElementById('zip').value);
var subject = encodeURI(document.getElementById('subject').value);
var content = encodeURI(document.getElementById('content').value);
	
// Set random number to add to URL request (for IE)
nocache = Math.random();

if (check_contact_form()){

	if (check_email_address(email)){
	
	http.open('get', 'assets/contact/contact.php?name='+name+'&email='+email+'&company='+company+'&phone='+phone+'&fax='+fax+'&country='+country+'&state='+state+'&city='+city+'&address='+address+'&zip='+zip+'&subject='+subject+'&content='+content+'&nocache = '+nocache);
	http.onreadystatechange = contactReply;
	http.send(null);
	}else{
		document.getElementById('contact_result').innerHTML = "<p><span style='font-size:small;color:red;'>The E-mail address is not valid.</span></p>";
	}
	
}else{
	//in case of bad inpute
	document.getElementById('contact_result').innerHTML = "<p><span style='font-size:small;color:red;'>Please make sure to fill in all the required details.</span></p>";
}

}


function contactReply() {

if(http.readyState == 4){

	var response = http.responseText;
	//alert(response);
	if(response == 'true'){
		//reset form
		document.getElementById('contact_form').reset();
		document.getElementById('contact_result').innerHTML = "<p><span style='font-size:small;color:green;'>Your message has been successfully delivered, We will contact you soon!</span></p>";
	}else{
		document.getElementById('contact_result').innerHTML = "<p><span style='font-size:small;color:red;'>An error has occurred during the process. Your message has not been delivered, please try again.</span></p>";
	}
}

}


//check for form fields validation
function check_contact_form(){

//validate mandatroy fields
if (document.getElementById('name').value==''){
	return false;
}
if (document.getElementById('email').value==''){
	return false;
}
if (document.getElementById('subject').value==''){
	return false;
}
if (document.getElementById('content').value==''){
	return false;
}

return true;

}


function check_email_address(email_address){

if ((email_address.indexOf('@')==-1) || (email_address.indexOf('.')==-1)){
	return false;
}else{
	return true;
}

}




