var ajax_request;

function createXmlHttpRequest() {
	var xmlHttp;
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		}
	}
	return xmlHttp;
}

ajax_request = createXmlHttpRequest();

var registrationServlet = "/servlet/registrationServlet";
function submitExterroRegistrationForm()
{
	var fname = document.getElementById("first_name");
	var lname = document.getElementById("last_name");
	var title = document.getElementById("title");
	var company = document.getElementById("company");
	var emailAddress = document.getElementById("email");
	
	var heard = document.getElementById("00N50000001WzUZ");
	
	var address1 = document.getElementById("address1");
	var address2 = document.getElementById("address2");
	var city = document.getElementById("city");
	var state = document.getElementById("state");
	var zipcode = document.getElementById("zipcode");
	var country = document.getElementById("country");
	var phone = document.getElementById("phone");
	var comments = document.getElementById("00N50000001bPBu");
	
	var resource = document.getElementById("00N50000001smlo");
	
	var actionType = document.getElementById("actionType");
	var requestType = document.getElementById("requestType");
    
	var name = fname.value + " " + lname.value;
		
	var url = "actionType=register&requestType=" + requestType.value + "&name=" + escape(name) + "&company=" 
			+ escape(company.value) + "&title=" + escape(title.value) 
			+ "&emailAddress=" + escape(emailAddress.value);
	
	if(phone == null || "undefined" == typeof(phone))
		url = url + "&phone=";
	else
		url = url + "&phone=" + escape(phone.value);

	if(country == null || "undefined" == typeof(country))
		url = url + "&country=";
	else
		url = url + "&country=" + escape(country.value);

	if(heard == null || "undefined" == typeof(heard))	 
		url = url + "&heard=";
	else
		url = url + "&heard=" + escape(heard.value);

	if(address1 == null || "undefined" == typeof(address1))	 
		url = url + "&address1=";
	else
		url = url + "&address1=" + escape(address1.value);

	if(address2 == null || "undefined" == typeof(address2))	 
		url = url + "&address2=";
	else
		url = url + "&address2=" + escape(address2.value);

	if(city == null || "undefined" == typeof(city))	 
		url = url + "&city=";
	else
		url = url + "&city=" + escape(city.value);

	if(state == null || "undefined" == typeof(state))	 
		url = url + "&state=";
	else
		url = url + "&state=" + escape(state.value);

	if(zipcode == null || "undefined" == typeof(zipcode))	 
		url = url + "&zip=";
	else
		url = url + "&zip=" + escape(zipcode.value);

	if(comments == null || "undefined" == typeof(comments))	 
		url = url + "&message=";
	else
		url = url + "&message=" + escape(comments.value);
	
	if(resource == null || "undefined" == typeof(resource))	 
		url = url + "&resource=";
	else
		url = url + "&resource=" + escape(resource.value);
		
	var productValue = "";
	
	var product_LH = document.getElementById('product_LH');
	var product_DW = document.getElementById('product_DW');
	var product_GC = document.getElementById('product_GC');
	var product_GO = document.getElementById('product_GO');
	
	if(product_LH != null && product_LH.checked)
		productValue = productValue + "Legal Hold";
	
	if(product_DW != null && product_DW.checked) {
		if(productValue != "")
			productValue = productValue + ";";
		productValue = productValue + "Discovery Workflow";
	}
	if(product_GC != null && product_GC.checked) {
		if(productValue != "")
			productValue = productValue + ";";
		productValue = productValue + "Genome";
	}
	
	if(product_GO != null && product_GO.checked) {
		if(productValue != "")
			productValue = productValue + ";";
		productValue = productValue + "FusionGo";
	}
	
	var params = url + "&product=" + escape(productValue);
	
	ajax_request.open("POST", registrationServlet, true);
	ajax_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax_request.setRequestHeader("Content-length", params.length);
	ajax_request.setRequestHeader("Connection", "close");
	ajax_request.onreadystatechange = completeRequest;
	ajax_request.send(params);
}

function completeRequest() {
	if (ajax_request.readyState == 4) {
		if (ajax_request.status == 200) {
			var results = ajax_request.responseText;
		} 
	}
}