// read a file from the server
function getEHostingRates() {
	// only continue if xmlHttp isn't void
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		// try to connect to the server
		try {
			// Grab Values
			var plan = document.getElementById('plan').value;			
			var mailboxNo = document.getElementById('mailboxNo').value;
			var mailboxSpace = document.getElementById('mailboxSpace').value;
			
			if(mailboxNo > 0 && mailboxSpace > 0) {
				// create the params string
				var params = "sid=" + Math.random() + "&plan=" + plan + "&mailboxNo=" + mailboxNo + "&mailboxSpace=" + mailboxSpace;			
				// initiate the asynchronous HTTP request
				xmlHttp.open("GET", "ajax_get_ehosting_price.php?" + params, true);
				xmlHttp.onreadystatechange = handlePriceRequestStateChange;
				xmlHttp.send(null);
			}
		}
		// display the error in case of failure
		catch (e) {
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function called when the state of the HTTP request changes
function handlePriceRequestStateChange() {
	// when readyState is 4, we are ready to read the server response
	if (xmlHttp.readyState == 4) {
		// continue only if HTTP status is "OK"
		if (xmlHttp.status == 200) {
			try {
				// do something with the response from the server
				handlePriceServerResponse();
			}
			catch(e) {
				// display error message
				alert("Error reading the response: " + e.toString());
			}
		} 
		else {
			// display status message
			alert("There was a problem retrieving the data:\n" + 
			xmlHttp.statusText);
		}
	}
}

// handles the response received from the server
function handlePriceServerResponse() {
	// extract the XML retrieved from the server
	xmlResponse = xmlHttp.responseXML;
	// obtain the document element (the root element) of the XML structure
	xmlDocumentElement = xmlResponse.documentElement;
	// get the text message, which is in the first child of
	// the the document element
	responseText = xmlDocumentElement.firstChild.data;

	myPrices = responseText.split("-");
	// Display Results
	document.getElementById('lbl_monthly').innerHTML = myPrices[0];
	document.getElementById('lbl_quaterly').innerHTML = myPrices[1];
	document.getElementById('lbl_annually').innerHTML = myPrices[2];			
}