var req;

function loadXMLDoc(url) 
{
	// branch for native XMLHttpRequest object
	if( window.XMLHttpRequest )
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	}
	// branch for IE/Windows ActiveX version
	else if( window.ActiveXObject )
	{
		req = new ActiveXObject( "Microsoft.XMLHTTP" );
		if( req )
		{
			req.onreadystatechange = processReqChange;
			req.open( "GET", url, true );
			req.send();
		}
	}
}

function processReqChange() 
{
	// only if req shows "complete"
	if( req.readyState == 4 )
	{
		// only if "OK"
		if( req.status == 200 )
		{
			// ...processing statements go here...
			response = req.responseXML.documentElement;
			ok = response.getElementsByTagName( 'ok' )[0].firstChild.data;
			email = response.getElementsByTagName('email')[0].firstChild.data;

			if( ok == "fail_dns" )
			{
				alert( "The email address you entered is not valid, please try again..." );				
			}
			else if( ok == "fail_email" )
			{
				alert( "The email address you entered is not valid, please try again..." );
			}
			else
			{
				if( response.getElementsByTagName( 'function' )[0].firstChild.data == "sendToFriend" )
				{
					senderName = response.getElementsByTagName( 'senderName' )[0].firstChild.data;
					alert( "Thank you " + senderName + ",\n\nAn invitation to Diabetes Health Digital Advantage has been sent to " + email + "." );
				}
				else if( response.getElementsByTagName( 'function' )[0].firstChild.data == "addDigitalSubscriber" )
				{
					alert( "Thank you,\n\n" + email + " has been added to the Diabetes Health newsletter and Diabetes Health Digital Advantage mailing lists." );
				}
			}
		}
		else
		{
			alert( "There was a problem:\n" + req.statusText + "\n\nPlease let us know about this error by emailing webmaster@diabetesheath.com" );
		}
	}
}