function ajaxObject() {
	var ab;
	if (window.XMLHttpRequest) {
		ab = new XMLHttpRequest(); // For Mozilla browsers
	} else if (window.ActiveXObject) {
		ab = new ActiveXObject("Microsoft.XMLHTTP"); // For IE
		if(!ab) {
			ab = new ActiveXObject("Msxml2.XMLHTTP"); // For IE
		}
	} else {
		return false;
	}
	return ab;
}

var httpAjax;
httpAjax = ajaxObject();

function getPage(page) {
	requestPage = "get.pages.php?p="+page;
	httpAjax.open("GET", requestPage, true);
	httpAjax.onreadystatechange = handlePageResponse;
	httpAjax.send(null);
}

function handlePageResponse() {
	if(httpAjax.readyState == 4) {
		if(httpAjax.status == 200) {
			document.getElementById("dynamicContent").innerHTML = httpAjax.responseText;
		} else {
			document.getElementById("dynamicContent").innerHTML = "Sorry I could not retrive the content.";
		}
	} else {
		document.getElementById("dynamicContent").innerHTML = "Loading Content...";	
	}
}

/* WE DO NOT NEED THE BOTTOM UNLESS WE ARE GOING TO SUBMIT A FORM */
function iniMail() {
	query = "?firstname="+ encodeURIComponent(document.getElementById("firstname").value);
	query += "&lastname="+ encodeURIComponent(document.getElementById("lastname").value);
	query += "&email="+ encodeURIComponent(document.getElementById("email").value);
	query += "&comment="+ encodeURIComponent(document.getElementById("comments").value);
	//window.alert(query);
	sndReq(query);
}

function sndReq(query) {
	requestPage = "send.mail.php"+query;
	httpAjax.open("GET", requestPage, true);
	httpAjax.onreadystatechange = handleMail;
	httpAjax.send(null);
}


function handleMail() {
	if(httpAjax.readyState == 4) {
		if(httpAjax.status == 200) {
			document.getElementById("dynamicContent").innerHTML = httpAjax.responseText;
		} else {
			document.getElementById("dynamicContent").innerHTML = "Sorry I could not retrive the content.";
		}
	} else {
		document.getElementById("dynamicContent").innerHTML = "Loading Content...";	
	}
}


/* THIS IS OUR TEST AJAX POST */
function postTest(query) {
	httpAjax.onreadystatechange = handlePending;
	httpAjax.open("post", "ajax.test.php", true);
	httpAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	httpAjax.send(query); /* IF WE ARE NOT SENDING ANYTHING WE SEND null */
}

function handlePending() {
	if(httpAjax.readyState == 4) {
		if(httpAjax.status == 200) {
			document.getElementById("pendingMessage").innerHTML = httpAjax.responseText;
		} else {
			document.getElementById("pendingMessage").innerHTML = "Someting seems to be worng with the communication with the server please ask for help!";
		}
	}
}


//------------------------------
