var xhrtf = false;
var updateElement = "tell_a_friend";


// this function is changed per different ajax functionality, 
// there can be multiple instances of this function all using 2 functions below
// the script referenced takes the parameters and outputs the dynamic content
// the 2 functions below then are generic - they perform the request and output the response
// @param: updateElement is the id of span or div to update with ajax content

function tellFriend(friend_name,friend_email,sender_name,pagelink) {

	makeRequestSelect("/lib/catalogue/scripts/ajax.tell_friend.php?friend_name="+friend_name+"&friend_email="+friend_email+"&sender_name="+sender_name+"&link="+pagelink);
	
	return false;
	
}



// generic function - no need to alter

function makeRequestSelect(url) {

	if (window.XMLHttpRequest) {
	
		xhrtf = new XMLHttpRequest();
		
	}else{
	
		if (window.ActiveXObject) {
		
			try {
			
				xhrtf = new ActiveXObject("Microsoft.XMLHTTP");
				
			}
			
			catch (e) { }
		}
		
	}

	if (xhrtf) {
	
		xhrtf.onreadystatechange = showContent;
		xhrtf.open("GET", url, true);
		xhrtf.send(null);
		
	}else{
	
		document.getElementById(updateElement).innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
		
	}
	
}



// generic function - no need to alter

function showContent() {

	if (xhrtf.readyState == 4) {
	
		if (xhrtf.status == 200) {
		
			var outMsg = (xhrtf.responseXML && xhrtf.responseXML.contentType=="text/xml") ? xhrtf.responseXML.getElementsByTagName("choices")[0].textContent : xhrtf.responseText;
			
		}else{
		
			var outMsg = "There was a problem with the request " + xhrtf.status;
			
		}
		
		document.getElementById(updateElement).innerHTML = outMsg;
		
	}
	
}