function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http = createRequestObject();


function insert(Index){

	/* 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. 
	*/
	http.open('get', 'phpinc/process.php?'+ Index +'&rand='+Math.random(1));
	/* Define a function to call once a response has been received. This will be our handleProductCategories function that we define below. */
	http.onreadystatechange = handleInsert; 
	/* Send the data. We use something other than null when we are sending using the POST method. */
	http.send(null);
}

function handleInsert(){
	/* 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(http.readyState != 4){		
			document.getElementById('divone').style.display = '';
			document.getElementById('divtwo').style.display = 'none';
			document.getElementById('submit').disabled = true;
	}
	if(http.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. */
		if (http.status == 200) {
            // ...processing statements go here...
        	
			var response = http.responseText; 
			if(response != '') {	alert(response); 
				document.getElementById('divone').style.display = 'none';
				document.getElementById('divtwo').style.display = '';
				document.getElementById('divtwo').innerHTML = response;
				document.getElementById('submit').disabled = false;
			}
			else {					
				document.getElementById('divone').style.display = 'none';
				document.getElementById('divtwo').style.display = '';
				document.getElementById('submit').disabled = false;
				if(document.getElementById('dtype').innerHTML == 'company') { resetcompanyform(); }
				else if(document.getElementById('dtype').innerHTML == 'personal') { resetpersonalform(); }
				else if(document.getElementById('dtype').innerHTML == 'event') { reseteventform(); }				
				
				form.name.value
			}

		/* And now we want to change the product_categories &lt;div&gt; content.we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		} else {
            alert("There was a problem retrieving the data:\n" + http.statusText);
        }
	}
}

function insertdivs(Index){
	http.open('get', 'phpinc/process.php?'+ Index +'&rand='+Math.random(1));
	http.onreadystatechange = handleInsertdivs;
	http.send(null);
}

function handleInsertdivs(){
	if(http.readyState != 4){
			document.getElementById('divone').style.display = '';
	}
	if(http.readyState == 4){ 	
		if (http.status == 200) {
			document.getElementById('divone').style.display = 'none';			
			var response = http.responseText;
			response = response.split('|');
			document.getElementById('divcat').innerHTML = response[0];
			document.getElementById('divscat').innerHTML = response[1];
		} else {
            alert("There was a problem retrieving the data:\n" + http.statusText);
        }
	}
}