// Vignette Generated Content Marker - DO NOT REMOVE
// stores reference to XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObjectDisaronno();
	
//Retrieves XMLHttpRequest object
function createXmlHttpRequestObjectDisaronno() {
	//will store the reference to the XMLHttpRequest object
	var xmlHttp;
	//if running Internet Explorer
	if(window.ActiveXObject) {
       try {
           xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
		catch (e) {
		xmlHttp = false;
		}
	} else {
		// if running Mozilla or other
		try {
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) {
			xmlHttp = false;
		}
	}
	//return the created object or display an error message
	if (!xmlHttp) {
		alert("Error here");
	} else {
		return xmlHttp;
	}
}

//Make asynchronous HTTP request using the XMLHttpRequest object
function disaronnoInvite(name, type, font) {
if (type == "night_out") {
	type = "Night out";
} 
if (type =="night_in") {
	type = "Night in";	
} 
if (type =="new_years") {
	type = "New years";	
}
if (type =="family") {
	type = "Family get together";	
} 
if (type =="christmas") {
	type = "Christmas";	
} 
 if (type =="friends") {
	type = "Friends reunion";	
} 

//alert("name is "+ name + ", font is "+ font );
	//proceed only if xmlHttp object isn't busy
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		xmlHttp.open("GET", "http://www.ivillage.co.uk/disaronnomessage.xml?name=" + name +"&type=" + type + "&font=" + font, true);
		//define the method to handle server responses
		xmlHttp.onreadystatechange = handleServerResponseDisaronno;
		//make the server request
		xmlHttp.send(null);
	} else {
		//if the connection is busy try again after 1 second
		setTimeout('disaronnoInvite("'+ name +'", "'+ type +'", "'+ font +'");', 1000);
	}
}
	
//executed automatically when a message is received from the server
function handleServerResponseDisaronno() {
	//move forward only if transaction has completed
	if (xmlHttp.readyState == 4) {
		//status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) {
			//extract the XML received from the server
			xmlResponse = xmlHttp.responseXML;
			//obtain the document element (the root element) of the XML structure
			xmlDocumentElement = xmlResponse.documentElement;
			//messageArray = xmlDocumentElement.getElementsByTagName("message");
			nameArray = xmlDocumentElement.getElementsByTagName("name");
			typeArray = xmlDocumentElement.getElementsByTagName("type");
			fontArray = xmlDocumentElement.getElementsByTagName("font");
			//posterArray = xmlDocumentElement.getElementsByTagName("poster");
			//postArray = xmlDocumentElement.getElementsByTagName("post");
			//alert("Returned message is " + messageArray);
			var html = "";
			//iterate through arrays to create html structure
			for (var i=0; i<nameArray.length; i++) {
				html += "<font face="+ fontArray.item(i).firstChild.data +">" + nameArray.item(i).firstChild.data +"'s " + typeArray.item(i).firstChild.data +" party!<br /><br /> Your message here </font>" ;
			}
			//update the client display with data received from the server
			var divMessage = document.getElementById("message");
			divMessage.innerHTML = html;
			//document.getElementById('divMessage').style.display = 'block';
			//restart sequence
			//setTimeout('vote()',1000)
		} else {
			//a http status different that 200 signals an error
			alert("problem: " + xmlHttp.statusText);
		}
	}
}