/* This implementation of the XMLHttpRequest object is taken from digg.com */
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	} catch (E) {
		xmlhttp=false
	}
}
@else
	xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false
	}
}
function myXMLHttpRequest() {
	var xmlhttplocal;
	try {
		xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
			xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
		} catch (E) {
			xmlhttplocal=false;
		}
	}

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
		try {
			var xmlhttplocal = new XMLHttpRequest();
		} catch (e) {
			var xmlhttplocal=false;
			alert('couldn\'t create xmlhttp object');
		}
	}
	return(xmlhttplocal);
}

/* The variable http will hold our new XMLHttpRequest object. */
var xmlhttp = myXMLHttpRequest(); 

function addattendee(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '/text/attendee.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
	xmlhttp.onreadystatechange = handleattendee; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleattendee(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = "";
		var counted = document.getElementById('attendee').value;
		
		/* LOOK BACK HERE FOR JAVASCRIPT INCLUDES.
		SEE HOW I DID THAT THING BELOW "response = response + ..."
		YEAH, THAT, REMEMBER THAT.*/
		for(i=0;i<counted;i++){
	   	//	var selectname = "additionalPriorCoverage" + String(i);
	   		
		//	var divname = "additionalPriorCoverageMain" + String(i);
			//response = response + xmlhttp.responseText + "<p class=\"formheader\">Prior Coverage</p> <div class=\"row\"> <span class=\"formw\"><select name=\"" + selectname + "\" onChange=\"priorCover('" + selectname + "', '" + divname + "');\"> <option value=\"Select\">Select an option below</option> <option value=\"Yes\">Yes</option> <option value=\"No\">No</option> </select> </span> </div></div> <div id=\"" + divname + "\"> </div>";
			//alert(response);
			response = response + xmlhttp.responseText;
		}
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('attendeecontent').innerHTML = response;
	}
}
