var first, last, mail, reqtype, commenttxt,info, hash, formsub, url, req, digits;

function prepComment()
{
	first = document.getElementById("firstname").value;
	last = document.getElementById("lastname").value;
	mail = document.getElementById("email").value;
	digits = document.getElementById("phone").value;
	reqtype = document.getElementById("requesttype")[document.getElementById("requesttype").selectedIndex].value;
	commenttxt = document.getElementById("comment").value;
	info = document.getElementById("signmeup").value;
	formsub = 1;
	
	//if (commenttxt == "")
	//{
	//	alert('Please enter a comment');
	//}
	//else
	//{
		if (!sendComment()) alert("Comment could not be sent due to a technical error.");
	//}
	return false;
}

function resetForm()
{
	first = last = mail = reqtype = digits = commenttxt = info = "";
	formsub = 0;
	sendComment();
}


function sendComment() {

	hash = "firstname=" + first + "&";
	hash += "lastname=" + last + "&";
	hash += "email=" + mail + "&";
	hash += "phone=" + digits + "&";
	hash += "requesttype=" + reqtype + "&";
	hash += "comment=" + commenttxt + "&";
	hash += "signmeup=" + info + "&";
	hash += "formsubmit=" + formsub;

	url = "contactus_form.php?" + hash;
	
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
					req = false;
			}
		}
	}

	if(req) {
		req.onreadystatechange = heardComment;
		req.open("GET", url, true);
		req.send("");
		return true; 
	}
	else
	{
		return false;
	}
}

function heardComment() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			//success
			//alert(req.responseText);
			updateForm(req.responseText);
		} else {
			//error
			alert('error');
		}
	}
}

function updateForm(content)
{
	document.getElementById("contactform").innerHTML = content;
}