var do_req;

function DoHTTPRequest(url, process_handler)
{

	// append date
	cDate = new Date;
	url = url + "&" + cDate.getTime() + "=1&";
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest)
	{
		do_req = new XMLHttpRequest();
 	}
	else if (window.ActiveXObject)      // branch for IE/Windows ActiveX version
		do_req = new ActiveXObject("Microsoft.XMLHTTP");

	if (do_req)
	{
		if(process_handler)
			do_req.onreadystatechange = process_handler;
		do_req.open("GET", url, true);
		do_req.send(null);
	}
}

function ProcessChangeRaceResults()
{
	var http_output;
	// only if req shows "complete"
	if (do_req.readyState == 4)
	{
		// only if "OK"
		if (do_req.status == 200)
		{
			http_output = do_req.responseText;

			if(http_output)
			{
				var terminating_pos = http_output.indexOf('~!end_user~');
				var username = http_output.substr(17, terminating_pos-17);
				document.getElementById("results_panel_"+username).innerHTML = http_output;
   			}


		}
		else
		{
			alert("There was a problem retrieving the ProcessActivityUpdate data:" + do_req.statusText);
		}
	}
}

function ProcessChangeJoeyPanel()
{
	var http_output;
	// only if req shows "complete"
	if (do_req.readyState == 4)
	{
		// only if "OK"
		if (do_req.status == 200)
		{
			http_output = do_req.responseText;

			if(http_output)
			{
				document.getElementById("panel_joey").innerHTML = http_output;
   			}


		}
		else
		{
			alert("There was a problem retrieving the ProcessActivityUpdate data:" + do_req.statusText);
		}
	}
}
function ProcessChangeMikePanel()
{
	var http_output;
//alert(do_req.readyState);
	// only if req shows "complete"
	if (do_req.readyState == 4)
	{
		// only if "OK"
		if (do_req.status == 200)
		{
			http_output = do_req.responseText;
//alert("status ok");
			if(http_output)
			{
				document.getElementById("panel_mike").innerHTML = http_output;
   			}
		}
		else
		{
			alert("There was a problem retrieving the ProcessActivityUpdate data:" + do_req.statusText);
		}
	}
}

function GetHistoryDeliveryURL(username, start_date, end_date)
{
	var output;

	if(!start_date || !end_date)
	{
		output = 'home.php?param=show_history&user='+username+'&';
		output += username+'_history_start_year=';
		output += document.getElementById(username+'_history_start_year').value;
		output += '&';
		output += username+'_history_start_month=';
		output += document.getElementById(username+'_history_start_month').value;
		output += '&';
		output += username+'_history_start_day=';
		output += document.getElementById(username+'_history_start_day').value;
		output += '&';
		output += username+'_history_end_year=';
		output += document.getElementById(username+'_history_end_year').value;
		output += '&';
		output += username+'_history_end_month=';
		output += document.getElementById(username+'_history_end_month').value;
		output += '&';
		output += username+'_history_end_day=';
		output += document.getElementById(username+'_history_end_day').value;
		output += '&';
	}
	else
	{
		output = 'home.php?param=show_history&user='+username+'&'+'start_date='+start_date+'&end_date='+end_date+'&';
 	}
		
	return output;
}

function ShowExtendedWindow(schedule_id)
{
	window.open('extended_schedule.php?schedule_id='+schedule_id, '', 'scrollbars=1, resizable=1,height=400, width=400');
}