var xmlHttp = null; // Defines that xmlHttp is a new variable.
// Try to get the right object for different browser
try {
	// Firefox, Opera 8.0+, Safari, IE7+
	xmlHttp = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
} catch (e) {
	// Internet Explorer
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}
function buildURL(thisform) {
	var tmpformdata = "";
	for (i = 0; i < thisform.length; i++) {
		//Build Send String (we only care about hidden fields and radio buttons
		if (thisform.elements[i].type == "hidden") { //Handle hidden
			tmpformdata = tmpformdata + addToURL(tmpformdata) + thisform.elements[i].name + "=" + escape(thisform.elements[i].value);
			
		} else if (thisform.elements[i].type == "radio") { //Handle Radio buttons
			if (thisform.elements[i].checked == true) {				
				tmpformdata = tmpformdata + addToURL(tmpformdata) + thisform.elements[i].name + "=" + escape(thisform.elements[i].value);				
			}
		}
	}
	//alert(tmpformdata);
	return tmpformdata;
}
function addToURL(tmpString) {
	if (tmpString != "") {
		return "&";
	} else {
		return "";
	}
}
function TMMUpdate(theTMMForm) {
	var url = "/TanMaximizer/?" + buildURL(theTMMForm) + "&rand=" + Math.floor(Math.random() * 1000000000);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4)
			try { // In some instances, status cannot be retrieved and will produce an error (e.g. Port is not responsive)
			if (xmlHttp.status == 200) {
				//Set the main HTML of the body to the info provided by the AJAX Request
				document.getElementById("TMMMain").innerHTML = xmlHttp.responseText;
			}
		} catch (e) {
			document.getElementById("TMMMain").innerHTML = "Error on Ajax return call : " + e.description;
		}
	}
	try {
		xmlHttp.send(null);
	} catch (e) {
		alert(e);
	}
	return false;
}
