var http = createRequestObject(); 

/* The following function creates an XMLHttpRequest object... */
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
}


function getForklift(){
	var forklift = document.getElementById("forklift").value;
	http.open('get', 'includes/rental_estimate.php?fnc=forklift&forklift=' + escape(forklift));
	http.onreadystatechange = handleForklift; 
	http.send(null);
}
function handleForklift(){
	if(http.readyState == 4){ //Finished loading the response
		var forklift_cost = http.responseText;
		document.getElementById('forklift_cost').innerHTML = forklift_cost;
		getTotal();
	}
}

function getFurniture(){
	var furniture = document.getElementById("furniture").value;
	
	http.open('get', 'includes/rental_estimate.php?fnc=furniture&furniture=' + escape(furniture));
	http.onreadystatechange = handleFurniture; 
	http.send(null);

}
function handleFurniture(){
	if(http.readyState == 4){ //Finished loading the response
		var furniture_cost = http.responseText;
		document.getElementById('furniture_cost').innerHTML = furniture_cost;
		getTotal();
	}
}

function getPower(){
	var power = document.getElementById("power").value;
	
	http.open('get', 'includes/rental_estimate.php?fnc=power&power=' + escape(power));
	http.onreadystatechange = handlePower; 
	http.send(null);

}
function handlePower(){
	if(http.readyState == 4){ //Finished loading the response
		var power_cost = http.responseText;
		document.getElementById('power_cost').innerHTML = power_cost;
		getTotal();
	}
}

function getStagehands(){
	var stagehands = document.getElementById("stagehands").value;
	
	http.open('get', 'includes/rental_estimate.php?fnc=stagehands&stagehands=' + escape(stagehands));
	http.onreadystatechange = handleStagehands; 
	http.send(null);
}
function handleStagehands(){
	if(http.readyState == 4){ //Finished loading the response
		var stagehands_cost = http.responseText;
		document.getElementById('stagehands_cost').innerHTML = stagehands_cost;
		getTotal();
	}
}

function getPrice(){ // ARENA RENTAL PRICE - based on attendance and ticket price
	var attendance = document.getElementById("attendance").value;
	var ticket_price = document.getElementById("ticket_price").value;
	
	var profit = attendance * ticket_price;
	http.open('get', 'includes/rental_estimate.php?fnc=price&attendance=' + escape(attendance) + '&ticket_price=' + escape(ticket_price));
	http.onreadystatechange = handlePrice; 
	http.send(null);

}
function handlePrice(){ // ARENA RENTAL PRICE - based on attendance and ticket price
	if(http.readyState == 4){ //Finished loading the response
		var profit = http.responseText;
		document.getElementById('profit').innerHTML = profit;
		getSecurity();
	}
}
function getSecurity(){ // SECURITY PRICE - based on attendance, doors open, load out
	var doors_hour = document.getElementById("doors_hour").value;
	var doors_min = document.getElementById("doors_min").value;
	var out_hour = document.getElementById("out_hour").value;
	var out_min = document.getElementById("out_min").value;
	var attendance = document.getElementById("attendance").value;
	
	http.open('get', 'includes/rental_estimate.php?fnc=security&attendance=' + escape(attendance) + '&doors_hour=' + escape(doors_hour) + '&doors_min=' + escape(doors_min) + '&out_min=' + escape(out_min) + '&out_hour=' + escape(out_hour));
	http.onreadystatechange = handleSecurity; 
	http.send(null);

}
function handleSecurity(){ // SECURITY PRICE - based on attendance, doors open, load out
	if(http.readyState == 4){ //Finished loading the response
		var security = http.responseText;
		document.getElementById('security').innerHTML = security;
		getElectrician();
	}
}

function getElectrician(){ // ELECTRICIAN PRICE - based on load in, load out
	var in_hour = document.getElementById("in_hour").value;
	var in_min = document.getElementById("in_min").value;
	var out_hour = document.getElementById("out_hour").value;
	var out_min = document.getElementById("out_min").value;
	
	http.open('get', 'includes/rental_estimate.php?fnc=electrician&in_hour=' + escape(in_hour) + '&in_min=' + escape(in_min) + '&out_min=' + escape(out_min) + '&out_hour=' + escape(out_hour));
	http.onreadystatechange = handleElectrician; 
	http.send(null);

}
function handleElectrician(){ // ELECTRICIAN PRICE - based on load in, load out
	if(http.readyState == 4){ //Finished loading the response
		var electrician = http.responseText;
		document.getElementById('electrician').innerHTML = electrician;
		getPolicing();
	}
}

function getPolicing(){ // POLICING COST
	var doors_hour = document.getElementById("doors_hour").value;
	var doors_min = document.getElementById("doors_min").value;
	var event_hour = document.getElementById("event_hour").value;
	var event_min = document.getElementById("event_min").value;
	var attendance = document.getElementById("attendance").value;
	
	http.open('get', 'includes/rental_estimate.php?fnc=policing&doors_hour=' + escape(doors_hour) + '&doors_min=' + escape(doors_min) + '&event_min=' + escape(event_min) + '&event_hour=' + escape(event_hour) + '&attendance=' + escape(attendance));
	http.onreadystatechange = handlePolicing; 
	http.send(null);

}
function handlePolicing(){
	if(http.readyState == 4){ //Finished loading the response
		var policing = http.responseText;
		document.getElementById('policing').innerHTML = policing;
		//getEventStaff();
		getHouse();
	}
}

function getEventTime(){
	var in_hour = document.getElementById("in_hour").value;
	var in_min = document.getElementById("in_min").value;
	var out_hour = document.getElementById("out_hour").value;
	var out_min = document.getElementById("out_min").value;
	
	http.open('get', 'includes/rental_estimate.php?fnc=event_time&in_hour=' + escape(in_hour) + '&in_min=' + escape(in_min) + '&out_min=' + escape(out_min) + '&out_hour=' + escape(out_hour));
	http.onreadystatechange = handleEventTime; 
	http.send(null);

}
function handleEventTime(){
	if(http.readyState == 4){ //Finished loading the response
		var total_time = http.responseText;
		document.getElementById('total_time').innerHTML = total_time;
		
		var in_hour = document.getElementById("in_hour").value;
		var in_min = document.getElementById("in_min").value;
		var out_hour = document.getElementById("out_hour").value;
		var out_min = document.getElementById("out_min").value;
		
		http.open('get', 'includes/rental_estimate.php?fnc=event_time_display&in_hour=' + escape(in_hour) + '&in_min=' + escape(in_min) + '&out_min=' + escape(out_min) + '&out_hour=' + escape(out_hour));		
		http.onreadystatechange = handleRentalTimes; 
		http.send(null);

	}
}
function handleRentalTimes(){
	if(http.readyState == 4){ //Finished loading the response
		var time_lapse = http.responseText;
		document.getElementById('time_lapse').innerHTML = time_lapse;
		getSecurity();
	}
}
