// Wrapper to get a cross-browser XMLHttp object
function GetXmlHTTPObject()
{
	var xmlhttp = null;

	if (window.XMLHttpRequest) // Firefox/Mozilla
		xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject) // IE Version
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
	return xmlhttp;
}

function AJAXSubscribe(f)
{
	var http = GetXmlHTTPObject();
	
	if(http)
	{
		var query = new Array();
		
		query[0] = 'title=' + f.Title.value;
		query[1] = 'forename=' + f.Forename.value;
		query[2] = 'surname=' + f.Surname.value;
		query[3] = 'companyname=' + f.CompanyName.value;
		query[4] = 'telephone=' + f.Telephone.value;
		query[5] = 'email=' + f.Email.value;
		query[6] = 'ajax=1';
		query[7] = 'r=' + new Date().getTime();

		var url = '/do_subscribe.asp?' + query.join('&');
		
		http.open('GET', url, true); 
		
		// Wire up the event handler and send the request
		http.onreadystatechange = function() { HandleHttpResponse(http); }; 
		http.send(null);

		return false;
	}
	else
	{
		return true;
	}
}

// Code to handle the RSS XML response
function HandleHttpResponse(http) 
{ 
	// Pick out the container we are trying to fill in the HTML doc
	var container = document.getElementById('subscribearea');
	
	// If the request is complete
	if(http.readyState == 4)
	{ 
		var	result = http.responseXML.getElementsByTagName('result')[0].attributes.getNamedItem('msg').value;
		container.innerHTML = '<h2>Keep yourself informed</h2><p id="sublink">' + result + '</p>';
	} 
	else
	{
		// Handle other states here
	}
	
	// Kill the XMLHttp object
	http = null;
}

function ShowSubscribeForm(x)
{
	document.getElementById('sublink').style.display = (x == 1) ? 'none' : 'block';
	document.getElementById('subscribeform').style.display = (x == 1) ? 'block' : 'none';
}