<!-- http://www.johnwiseman.ca/blogging/tutorials/creating-a-mysql-connection-with-phpajax/ -->
  
function createXMLHttpRequest() 
{ 
  var ua; 
  if(window.XMLHttpRequest) 
  { 
  	try 
  	{ 
		ua = new XMLHttpRequest(); 
	} 
	catch(e) 
	{ 
		ua = false; 
	} 
  } 
  else if(window.ActiveXObject) 
  { 
	try 
	{ 
		ua = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	catch(e) 
	{ 
		ua = false; 
	}
  } 

  return ua; 
} 
<!-- done when page loads -->
var req = createXMLHttpRequest(); 



function sendRequest(name) 
{ 
	<!-- declared with var so it's global -->
	name  = name.replace('_',' ');
	theName = name;
	req.open('get', '/80s/getstories.php?star='+name); 
	req.onreadystatechange = processResponse; 
	req.send(null); 
} 
  
function processResponse() 
{ 
	if(req.readyState == 4)
	{ 
		var response  = req.responseXML;
         
		var text = '';
		var n = theName.replace(new RegExp(/(\s)/g),'_');
		text = '<div class="pinkboxtop"><div class="row"><span class="label"><img src = "/80s/star_images/'+n+'"></span>';
		text = text + '<span class="formw"><span class="starname">' + theName + '</span></span><br />';

		var band = response.getElementsByTagName('band');
		text = text + '<span class="formw"><span class="starname">' + band[0].firstChild.nodeValue + '</span></span>';
		text = text + '</div></div>';		
		var stories = response.getElementsByTagName('story');
		if (stories.length==0)
		{
			text = text + '<div class="greenbox"><div class="row">';
			text = text + 'No stories on this person yet</div></div>';
		}
		else
		{
			for(var k=0; k < stories.length; k++) 
			{
				text = text + '<div class="greenbox"><div class="rowleft">';
				text = text +  stories[k].firstChild.data.replace(/\n/g, "<br />");
				text = text +  '<br /><em>from ' + stories[k].childNodes[1].firstChild.data;
				text = text +  ', added ' + stories[k].childNodes[2].firstChild.data + '</em>';
				text = text + '</div></div>';
			}
		}
		
		text = text + '\n<div class="pinkboxbot"><form name="story" id ="story" method="post" action="/80s/index.php">\n';	
		text = text + '<div class="row">\n<span class="label"><label for="yourname">';	

		text = text + 'Your name:';
		text = text + '</label></span>';
		text = text + '<span class="formw"><input type="text" name="yourname" id="yourname" size="30">';
		text = text + '</span>\n</div>\n';
		/* text = text + '<div class="row"><span class="label"><label for="youremail">';
		text = text + 'Your email:';
		text = text + '</label></span>';
		text = text + '<span class="formw"><input type="text" name="youremail" id="youremail" size="30">';
		text = text + '</span>\n</div>\n';	*/
		text = text + '<div class="row"><span class="label"><label for="yourstory">';
		text = text + 'Story about this star:';
		text = text + '</label></span>';		
		text = text + '<span class="formw"><textarea type="text" name="yourstory" id="yourstory" cols="22" rows="8">';
		text = text + '</textarea></span>\n</div>';
		text = text + '<div class="row"><span class="label">&nbsp;</span>\n';
		text = text + '<input type="hidden" name="star" value="' +theName + '">';
		text = text + '<span class="formw"><input type="submit" value="send story"></span>';
		text = text + '</form><br /></div></div>';
		text = text + '<div class="copyright">Images copyright of owners</div>';	
		// alert(text.split('>').join('\n'));
		window.scrollTo(0,0);
		document.getElementById('contentcenter').innerHTML = text;
	} 
	
	else 
    {
		document.getElementById('contentcenter').innerHTML = "<img src='/80s/images/loader.gif'>";
  	}
}


