/*--------------------------------------------------*/
/* GLOBAL FUNCTIONS									*/
/*--------------------------------------------------*/

//------------------------------
// Ajax Request
//------------------------------
function getXMLHTTPRequest()
{
	try
	{
		req = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				req = false;
			}
		}
	}
	if(!req)
	{
		alert("Error creating Ajax Object, please contact Web & Systems Dept.");
	}
	else
	{
		return req;
	}
	return req;
}

var http_info = getXMLHTTPRequest();
var http_pirep = getXMLHTTPRequest();
var http_fav = getXMLHTTPRequest();
var http_crew = getXMLHTTPRequest();

//------------------------------
// Change Tab
//------------------------------
function change_tab(tab_income_id, pilotid)
{
	// Split Tab Name
	var tab_raw_id = tab_income_id.toString();
	var tab_string = tab_raw_id.split("_");
	var tab_section = tab_string[1];
	var tab_id = tab_string[2];
	
	// Update tab classes
	var tab_current = document.getElementById("tab_"+tab_section+"_status").value;
	document.getElementById(tab_current).className = "tab_off";
	document.getElementById(tab_raw_id).className = "tab_on";
	document.getElementById("tab_"+tab_section+"_status").value = tab_raw_id;
	
	// Run Appropriate Function
	if(tab_section == "info")
	{
		run_info_section(tab_id, pilotid);
		return true;
	}
	if(tab_section == "pirep")
	{
		run_pirep_section(tab_id, pilotid);
		return true;
	}
	if(tab_section == "fav")
	{
		run_fav_section(tab_id, pilotid);
		return true;
	}
	if(tab_section == "crew")
	{
		run_crew_section(tab_id, pilotid);
		return true;
	}
	
	// No section found, error
	alert("Error getting tab section!");
	return false;
}

//------------------------------
// Show Loading
//------------------------------
function show_loading(section)
{
	var html = "<div width='100%' align='center'><img src='images/icons/wait.gif' border='0' alt='Loading Data...' />&nbsp;&nbsp;<span class='subheaderbold'>Loading Data...</span></div>";
	document.getElementById(section).innerHTML = html;
}

/*--------------------------------------------------*/
/* INFO FUNCTIONS									*/
/*--------------------------------------------------*/

//------------------------------
// Run Info Section
//------------------------------
function run_info_section(tab_id, pilotid)
{
	if(tab_id == "1")
	{
		http_info.open("GET", "content/community/scripts/profile_action.php?sec=info&tab=1&pilotid="+pilotid+"", true);
		http_info.onreadystatechange = return_info_1;
		http_info.send(null);
	}
	
	if(tab_id == "2")
	{
		http_info.open("GET", "content/community/scripts/profile_action.php?sec=info&tab=2&pilotid="+pilotid+"", true);
		http_info.onreadystatechange = return_info_2;
		http_info.send(null);
	}
}

//------------------------------
// Return Tab 1
//------------------------------
function return_info_1()
{
	if(http_info.readyState == 4)
	{
		if(http_info.status == 200)
		{
			// Get Results
			var total_flight_time = http_info.responseXML.getElementsByTagName("total_flight_time")[0].childNodes[0].nodeValue;
			var transfer_time = http_info.responseXML.getElementsByTagName("transfer_time")[0].childNodes[0].nodeValue;
			var total_flights = http_info.responseXML.getElementsByTagName("total_flights")[0].childNodes[0].nodeValue;
			var online_flights = http_info.responseXML.getElementsByTagName("online_flights")[0].childNodes[0].nodeValue;
			var offline_flights = http_info.responseXML.getElementsByTagName("offline_flights")[0].childNodes[0].nodeValue;
			var fsp_flights = http_info.responseXML.getElementsByTagName("fsp_flights")[0].childNodes[0].nodeValue;
			var total_flights_month = http_info.responseXML.getElementsByTagName("total_flights_month")[0].childNodes[0].nodeValue;
			var vloc = http_info.responseXML.getElementsByTagName("vloc")[0].childNodes[0].nodeValue;
			var current_rank = http_info.responseXML.getElementsByTagName("current_rank")[0].childNodes[0].nodeValue;
			var next_rank_hours = http_info.responseXML.getElementsByTagName("next_rank_hours")[0].childNodes[0].nodeValue;
			var join_date = http_info.responseXML.getElementsByTagName("join_date")[0].childNodes[0].nodeValue;
			var pilot_status = http_info.responseXML.getElementsByTagName("pilot_status")[0].childNodes[0].nodeValue;
			var nationality = http_info.responseXML.getElementsByTagName("nationality")[0].childNodes[0].nodeValue;
			var career_mode = http_info.responseXML.getElementsByTagName("career_mode")[0].childNodes[0].nodeValue;
			
			var flight_info = online_flights+" / "+offline_flights+" / "+fsp_flights;
			
			// Format HTML
			var html = "<table cellpadding='2' cellspacing='0' width='100%'>";
			html += "<tr><td><b>Total Flight Time:</b></td><td>"+total_flight_time+"</td><td><b>Current Rank:</b></td><td>"+current_rank+"</td></tr>";
			html += "<tr><td><b>Transfer Time:</b></td><td>"+transfer_time+"</td><td><b>Next Rank In:</b></td><td>"+next_rank_hours+"</td></tr>";
			html += "<tr><td><b>Total Flights:</b></td><td>"+total_flights+"</td><td><b>Joined Us:</b></td><td>"+join_date+"</td></tr>";
			html += "<tr><td><b>Online / Offline / FSP:</b></td><td>"+flight_info+"</td><td><b>Status:</b></td><td>"+pilot_status+"</td></tr>";
			html += "<tr><td><b>Flights This Month:</b></td><td>"+total_flights_month+"</td><td><b>Nationality:</b></td><td>"+nationality+"</td></tr>";
			html += "<tr><td><b>Virtual Location:</b></td><td>"+vloc+"</td><td><b>Career Mode:</b></td><td>"+career_mode+"</td></tr>";
			html += "</table>";
			
			// Print
			document.getElementById("tab_info_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_info_content");
	}
}

//------------------------------
// Return Tab 2
//------------------------------
function return_info_2()
{
	if(http_info.readyState == 4)
	{
		if(http_info.status == 200)
		{
			// Get Results
			var award_id_array = http_info.responseXML.getElementsByTagName("award_id");
			var award_image_array = http_info.responseXML.getElementsByTagName("award_image");
			var award_name_array = http_info.responseXML.getElementsByTagName("award_name");
			var award_date_array = http_info.responseXML.getElementsByTagName("award_date");
			var award_description_array = http_info.responseXML.getElementsByTagName("award_description");
			
			// Format HTML
			var html = "<table cellpadding='2' cellspacing='0' width='100%' border='2' bordercolor='#C0C0C0'><tr align='center'><td><b>Award</b></td><td><b>Date Awarded</b></td><td><b>Description</b></td></tr>";
			
			// Cycle Awards
			for( i=0; i<award_id_array.length; i++ )
			{
				var award_image = award_image_array.item(i).firstChild.data.toString();
				var award_name = award_name_array.item(i).firstChild.data.toString();
				var award_date = award_date_array.item(i).firstChild.data.toString();
				var award_description = award_description_array.item(i).firstChild.data.toString();
				
				html += "<tr align='center'><td><img src='images/awards/"+award_image+"' alt='"+award_name+"' /></td><td>"+award_date+"</td><td>"+award_description+"</td></tr>";
			}
			
			// Format HTML
			html += "</table>";
			
			// Print
			document.getElementById("tab_info_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_info_content");
	}
}

/*--------------------------------------------------*/
/* PIREP FUNCTIONS									*/
/*--------------------------------------------------*/

//------------------------------
// Run Pirep Section
//------------------------------
function run_pirep_section(tab_id, pilotid)
{
	if(tab_id == "1")
	{
		http_pirep.open("GET", "content/community/scripts/profile_action.php?sec=pirep&tab=1&pilotid="+pilotid+"", true);
		http_pirep.onreadystatechange = return_pirep_1;
		http_pirep.send(null);
	}
	
	if(tab_id == "2")
	{
		http_pirep.open("GET", "content/community/scripts/profile_action.php?sec=pirep&tab=2&pilotid="+pilotid+"", true);
		http_pirep.onreadystatechange = return_pirep_2;
		http_pirep.send(null);
	}
	
	if(tab_id == "3")
	{
		http_pirep.open("GET", "content/community/scripts/profile_action.php?sec=pirep&tab=3&pilotid="+pilotid+"", true);
		http_pirep.onreadystatechange = return_pirep_3;
		http_pirep.send(null);
	}
}

//------------------------------
// Flight Generator
//------------------------------
function flight_generator(tabletop)
{
	// Get Results
	var hours = http_pirep.responseXML.getElementsByTagName("hours")[0].childNodes[0].nodeValue;
	var pax = http_pirep.responseXML.getElementsByTagName("pax")[0].childNodes[0].nodeValue;
	var distance = http_pirep.responseXML.getElementsByTagName("distance")[0].childNodes[0].nodeValue;
	var fuel = http_pirep.responseXML.getElementsByTagName("fuel")[0].childNodes[0].nodeValue;
	var cargo = http_pirep.responseXML.getElementsByTagName("cargo")[0].childNodes[0].nodeValue;
	
	var error = http_pirep.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue;
	if(error == 'good')
	{
		var pirep_id_array = http_pirep.responseXML.getElementsByTagName("pirep_id")
		var pirep_flight_array = http_pirep.responseXML.getElementsByTagName("pirep_flight");
		var pirep_dep_array = http_pirep.responseXML.getElementsByTagName("pirep_dep");
		var pirep_arr_array = http_pirep.responseXML.getElementsByTagName("pirep_arr");
		var pirep_aircraft_array = http_pirep.responseXML.getElementsByTagName("pirep_aircraft");
	}
					
	// Format Statistics
	var html_statistics = "<table cellpadding='2' cellspacing='0' width='100%'>";
	html_statistics += "<tr><td colspan='2'><b>"+tabletop+"</td></tr>";
	html_statistics += "<tr><td><b>Hours:</b></td><td>"+hours+"</td></tr>";
	html_statistics += "<tr><td><b>Passengers:</b></td><td>"+pax+"</td></tr>";
	html_statistics += "<tr><td><b>Distance:</b></td><td>"+distance+" nm</td></tr>";
	html_statistics += "<tr><td><b>Fuel:</b></td><td>"+fuel+" lbs</td></tr>";
	html_statistics += "<tr><td><b>Cargo:</b></td><td>"+cargo+" lbs</td></tr>";
	html_statistics += "</table>";
			
	// Cycle Pireps
	var html_pireps = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='4'><b>Latest Pireps</b></td></tr>";
	
	if(error == 'good')
	{
		for( i=0; i<pirep_id_array.length; i++ )
		{
			var pirep_flight = pirep_flight_array.item(i).firstChild.data.toString();
			var pirep_dep = pirep_dep_array.item(i).firstChild.data.toString();
			var pirep_arr = pirep_arr_array.item(i).firstChild.data.toString();
			var pirep_aircraft = pirep_aircraft_array.item(i).firstChild.data.toString();
					
			html_pireps += "<tr><td>"+pirep_flight+"</td><td>"+pirep_dep+"</td><td>"+pirep_arr+"</td><td>"+pirep_aircraft+"</td></tr>";
		}
	}
	else
	{
		html_pireps += "<tr><td colspan='4'>No pireps have been filed.</td></tr>";
	}
			
	html_pireps += "</table>";
			
	// Output
	var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td width='50%' valign='top'>"+html_statistics+"</td><td valign='top' width='50%'>"+html_pireps+"</td></tr></table>";
	
	return html;
}

function flight_generator_vfr(tabletop)
{
	// Get Results
	var total_hours = http_pirep.responseXML.getElementsByTagName("total_hours")[0].childNodes[0].nodeValue;
	var day_hours = http_pirep.responseXML.getElementsByTagName("day_hours")[0].childNodes[0].nodeValue;
	var night_hours = http_pirep.responseXML.getElementsByTagName("night_hours")[0].childNodes[0].nodeValue;
	
	var error = http_pirep.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue;
	if(error == 'good')
	{
		var pirep_id_array = http_pirep.responseXML.getElementsByTagName("pirep_id")
		var pirep_dep_array = http_pirep.responseXML.getElementsByTagName("pirep_dep");
		var pirep_arr_array = http_pirep.responseXML.getElementsByTagName("pirep_arr");
		var pirep_aircraft_array = http_pirep.responseXML.getElementsByTagName("pirep_aircraft");
	}
					
	// Format Statistics
	var html_statistics = "<table cellpadding='2' cellspacing='0' width='100%'>";
	html_statistics += "<tr><td colspan='2'><b>"+tabletop+"</td></tr>";
	html_statistics += "<tr><td><b>Total Hours:</b></td><td>"+total_hours+"</td></tr>";
	html_statistics += "<tr><td><b>Day Hours:</b></td><td>"+day_hours+"</td></tr>";
	html_statistics += "<tr><td><b>Night Hours:</b></td><td>"+night_hours+"</td></tr>";
	html_statistics += "</table>";
			
	// Cycle Pireps
	var html_pireps = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='4'><b>Latest Pireps</b></td></tr>";
	
	if(error == 'good')
	{
		for( i=0; i<pirep_id_array.length; i++ )
		{
			var pirep_dep = pirep_dep_array.item(i).firstChild.data.toString();
			var pirep_arr = pirep_arr_array.item(i).firstChild.data.toString();
			var pirep_aircraft = pirep_aircraft_array.item(i).firstChild.data.toString();
					
			html_pireps += "<tr><td>"+pirep_dep+"</td><td>"+pirep_arr+"</td><td>"+pirep_aircraft+"</td></tr>";
		}
	}
	else
	{
		html_pireps += "<tr><td colspan='3'>No pireps have been filed.</td></tr>";
	}
			
	html_pireps += "</table>";
			
	// Output
	var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td width='50%' valign='top'>"+html_statistics+"</td><td valign='top' width='50%'>"+html_pireps+"</td></tr></table>";
	
	return html;
}

//------------------------------
// Return Tab 1
//------------------------------
function return_pirep_1()
{
	if(http_pirep.readyState == 4)
	{
		if(http_pirep.status == 200)
		{
			var html = flight_generator("Mainstrem & Tour Statistics");
			
			document.getElementById("tab_pirep_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_pirep_content");
	}
}

//------------------------------
// Return Tab 2
//------------------------------
function return_pirep_2()
{
	if(http_pirep.readyState == 4)
	{
		if(http_pirep.status == 200)
		{
			var html = flight_generator_vfr("Flying Club Statistics");
			
			document.getElementById("tab_pirep_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_pirep_content");
	}
}

//------------------------------
// Return Tab 3
//------------------------------
function return_pirep_3()
{
	if(http_pirep.readyState == 4)
	{
		if(http_pirep.status == 200)
		{
			var html = flight_generator("FSP Statistics");
			
			document.getElementById("tab_pirep_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_pirep_content");
	}
}

/*--------------------------------------------------*/
/* FAVOURITE FUNCTIONS								*/
/*--------------------------------------------------*/

//------------------------------
// Run Fav Section
//------------------------------
function run_fav_section(tabid, pilotid)
{
	if(tabid == 1)
	{
		http_fav.open("GET", "content/community/scripts/profile_action.php?sec=fav&tab=1&pilotid="+pilotid+"", true);
		http_fav.onreadystatechange = return_fav_1;
		http_fav.send(null);
	}
	if(tabid == 2)
	{
		http_fav.open("GET", "content/community/scripts/profile_action.php?sec=fav&tab=2&pilotid="+pilotid+"", true);
		http_fav.onreadystatechange = return_fav_2;
		http_fav.send(null);
	}
	if(tabid == 3)
	{
		http_fav.open("GET", "content/community/scripts/profile_action.php?sec=fav&tab=3&pilotid="+pilotid+"", true);
		http_fav.onreadystatechange = return_fav_3;
		http_fav.send(null);
	}
	if(tabid == 4)
	{
		http_fav.open("GET", "content/community/scripts/profile_action.php?sec=fav&tab=4&pilotid="+pilotid+"", true);
		http_fav.onreadystatechange = return_fav_4;
		http_fav.send(null);
	}
}

//------------------------------
// Return Fav 1
//------------------------------
function return_fav_1()
{
	if(http_fav.readyState == 4)
	{
		if(http_fav.status == 200)
		{
			var pilotid = http_fav.responseXML.getElementsByTagName("pilotid")[0].childNodes[0].nodeValue;
			
			// TIME
			var time_error = http_fav.responseXML.getElementsByTagName("time_error")[0].childNodes[0].nodeValue;
			
			if(time_error == "good")
			{
				var time_time_array = http_fav.responseXML.getElementsByTagName("time_time");
				var time_count_array = http_fav.responseXML.getElementsByTagName("time_count");
				
				var time_html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='2'><b>Favourite Time To Fly</b></td></tr>";
				
				for( i=0; i<time_time_array.length; i++ )
				{
					var time_time = time_time_array.item(i).firstChild.data.toString();
					var time_count = time_count_array.item(i).firstChild.data.toString();
					
					time_html += "<tr><td>"+time_time+"</td><td>"+time_count+"</td></tr>";
				}
				
				time_html += "</table>";
			}
			else
			{
				var time_html = "<b>Favourite Time To Fly</b><br /><br />No pireps filed";
			}
			
			// DAY
			var day_error = http_fav.responseXML.getElementsByTagName("day_error")[0].childNodes[0].nodeValue;
			
			if(day_error == "good")
			{
				var day_day_array = http_fav.responseXML.getElementsByTagName("day_day");
				var day_count_array = http_fav.responseXML.getElementsByTagName("day_count");
				
				var day_html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='2'><b>Favourite Day To Fly</b></td></tr>";
				
				for( n=0; n<day_day_array.length; n++ )
				{
					var day_day = day_day_array.item(n).firstChild.data.toString();
					var day_count = day_count_array.item(n).firstChild.data.toString();
					
					day_html += "<tr><td>"+day_day+"</td><td>"+day_count+"</td></tr>";
				}
				
				day_html += "<tr><td colspan='2'><img src='images/icons/graph.png' border='0' alt='Graph' />&nbsp;<a rel='lightbox' href='content/community/scripts/profile_charts.php?sec=fav&chart=day&pilotid="+pilotid+"' title='Favourite Day To Fly'>View statistics as a graph...</a></td></tr></table>";
			}
			else
			{
				var day_html = "<b>Favourite Day To Fly</b><br /><br />No pireps filed";
			}
			
			// OUTPUT
			var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td valign='top' width='50%'>"+time_html+"</td><td width='50%' valign='top'>"+day_html+"</td></tr></table>";
			
			document.getElementById("tab_fav_content").innerHTML = html;
			
			// Lightbox
			Lightbox.prototype.updateImageList();
		}
	}
	else
	{
		show_loading("tab_fav_content");
	}
}

//------------------------------
// Return Fav 2
//------------------------------
function return_fav_2()
{
	if(http_fav.readyState == 4)
	{
		if(http_fav.status == 200)
		{
			// DEPARTURE
			var departure_error = http_fav.responseXML.getElementsByTagName("departure_error")[0].childNodes[0].nodeValue;
			
			if(departure_error == "good")
			{
				var departure_icao_array = http_fav.responseXML.getElementsByTagName("departure_icao");
				var departure_name_array = http_fav.responseXML.getElementsByTagName("departure_name");
				var departure_country_array = http_fav.responseXML.getElementsByTagName("departure_country");
				var departure_count_array = http_fav.responseXML.getElementsByTagName("departure_count");
				
				var departure_html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='4'><b>Favourite Departure Airports</b></td></tr>";
				
				for( i=0; i<departure_icao_array.length; i++ )
				{
					var departure_icao = departure_icao_array.item(i).firstChild.data.toString();
					var departure_name = departure_name_array.item(i).firstChild.data.toString();
					var departure_country = departure_country_array.item(i).firstChild.data.toString();
					var departure_count = departure_count_array.item(i).firstChild.data.toString();
					
					departure_html += "<tr><td>"+departure_icao+"</td><td>"+departure_name+"</td><td><img src='images/flags/"+departure_country+".gif' border='0' alt='"+departure_country+"' /></td><td>"+departure_count+"</td></tr>";
				}
				
				departure_html += "</table>";
			}
			else
			{
				var departure_html = "<b>Favourite Departure Airports</b><br /><br />No pireps filed";
			}
			
			//ARRIVAL
			var arrival_error = http_fav.responseXML.getElementsByTagName("arrival_error")[0].childNodes[0].nodeValue;
			
			if(arrival_error == "good")
			{
				var arrival_icao_array = http_fav.responseXML.getElementsByTagName("arrival_icao");
				var arrival_name_array = http_fav.responseXML.getElementsByTagName("arrival_name");
				var arrival_country_array = http_fav.responseXML.getElementsByTagName("arrival_country");
				var arrival_count_array = http_fav.responseXML.getElementsByTagName("arrival_count");
				
				var arrival_html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='4'><b>Favourite Destination Airports</b></td></tr>";
				
				for( n=0; n<departure_icao_array.length; n++ )
				{
					var arrival_icao = arrival_icao_array.item(n).firstChild.data.toString();
					var arrival_name = arrival_name_array.item(n).firstChild.data.toString();
					var arrival_country = arrival_country_array.item(n).firstChild.data.toString();
					var arrival_count = arrival_count_array.item(n).firstChild.data.toString();
					
					arrival_html += "<tr><td>"+arrival_icao+"</td><td>"+arrival_name+"</td><td><img src='images/flags/"+arrival_country+".gif' border='0' alt='"+arrival_country+"' /></td><td>"+arrival_count+"</td></tr>";
				}
				
				arrival_html += "</table>";
			}
			else
			{
				var arrival_html = "<b>Favourite Destination Airports</b><br /><br />No pireps filed";
			}
			
			// OUTPUT
			var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td width='50%' valign='top'>"+departure_html+"</td><td width='50%' valign='top'>"+arrival_html+"</td></tr></table>";
			
			document.getElementById("tab_fav_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_fav_content");
	}
}

//------------------------------
// Return Fav 3
//------------------------------
function return_fav_3()
{
	if(http_fav.readyState == 4)
	{
		if(http_fav.status == 200)
		{
			// FIXED WING
			var fixed_error = http_fav.responseXML.getElementsByTagName("fixed_error")[0].childNodes[0].nodeValue;
			
			if(fixed_error == "good")
			{
				var fixed_type_array = http_fav.responseXML.getElementsByTagName("fixed_type");
				var fixed_count_array = http_fav.responseXML.getElementsByTagName("fixed_count");
				
				var fixed_html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='2'><b>Favourite Fixed Wing Aircraft</b></td></tr>";
				
				for( i=0; i<fixed_type_array.length; i++ )
				{
					var fixed_type = fixed_type_array.item(i).firstChild.data.toString();
					var fixed_count = fixed_count_array.item(i).firstChild.data.toString();
					
					fixed_html += "<tr><td>"+fixed_type+"</td><td>"+fixed_count+"</td></tr>";
				}
				
				fixed_html += "</table>";
			}
			else
			{
				var fixed_html = "<b>Favourite Fixed Wing Aircraft</b><br /><br />No fixed wing pireps filed";
			}
			
			// CHOPPER
			var chopper_error = http_fav.responseXML.getElementsByTagName("chopper_error")[0].childNodes[0].nodeValue;
			
			if(chopper_error == "good")
			{
				var chopper_type_array = http_fav.responseXML.getElementsByTagName("chopper_type");
				var chopper_count_array = http_fav.responseXML.getElementsByTagName("chopper_count");
				
				var chopper_html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><Td colspan='2'><b>Favourite Chopper Aircraft</b></td></tr>";
				
				for( n=0; n<chopper_type_array.length; n++ )
				{
					var chopper_type = chopper_type_array.item(n).firstChild.data.toString();
					var chopper_count = chopper_count_array.item(n).firstChild.data.toString();
					
					chopper_html += "<tr><td>"+chopper_type+"</td><td>"+chopper_count+"</td></tr>";
				}
				
				chopper_html = "</table>";
			}
			else
			{
				var chopper_html = "<b>Favourite Chopper Aircraft</b><br /><br />No chopper pireps filed";
			}
			
			// OUTPUT
			var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td width='50%' valign='top'>"+fixed_html+"</td><td width='50%' valign='top'>"+chopper_html+"</td></tr></table>";
			
			document.getElementById("tab_fav_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_fav_content");
	}
}

//------------------------------
// Return Fav 4
//------------------------------
function return_fav_4()
{
	if(http_fav.readyState == 4)
	{
		var type_error = http_fav.responseXML.getElementsByTagName("type_error")[0].childNodes[0].nodeValue;
		
		if(type_error == "good")
		{
			var type_array = http_fav.responseXML.getElementsByTagName("type");
			var count_array = http_fav.responseXML.getElementsByTagName("count");
			
			var type_html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td colspan='2'><b>Favourite Flight Types</b></td></tr>";
			
			for( i=0; i<type_array.length; i++ )
			{
				var flight_type = type_array.item(i).firstChild.data.toString();
				var flight_count = count_array.item(i).firstChild.data.toString();
				
				type_html += "<tr><td>"+flight_type+"</td><td>"+flight_count+"</td></tr>";
			}
			
			type_html += "</table>";
			
			var pilotid = http_fav.responseXML.getElementsByTagName("pilotid")[0].childNodes[0].nodeValue;
			
			var graph_html = "<img src='images/icons/graph.png' border='0' alt='Graph' />&nbsp;<a rel='lightbox' href='content/community/scripts/profile_charts.php?sec=fav&chart=type&pilotid="+pilotid+"' title='Favourite Flight Types'>View statistics as a graph...</a>";
		}
		else
		{
			var type_html = "<b>Favourite Flight Type</b><br /><br />No pireps filed";
			var graph_html = "";
		}
		
		
		// Output
		var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr><td width='50%' valign='top'>"+type_html+"</td><td width='50%' valign='center'>"+graph_html+"</td></tr></table>";
		
		document.getElementById("tab_fav_content").innerHTML = html;
		
		// Lightbox
		Lightbox.prototype.updateImageList();
	}
	else
	{
		show_loading("tab_fav_content");
	}
}

/*--------------------------------------------------*/
/* CREW FUNCTIONS									*/
/*--------------------------------------------------*/

//------------------------------
// Run Crew Section
//------------------------------
function run_crew_section(tabid, pilotid)
{
	if(tabid == 1)
	{
		http_crew.open("GET", "content/community/scripts/profile_action.php?sec=crew&tab=1&pilotid="+pilotid+"", true);
		http_crew.onreadystatechange = return_crew_1;
		http_crew.send(null);
	}
	if(tabid == 2)
	{
		http_crew.open("GET", "content/community/scripts/profile_action.php?sec=crew&tab=2&pilotid="+pilotid+"", true);
		http_crew.onreadystatechange = return_crew_2;
		http_crew.send(null);
	}
	if(tabid == 3)
	{
		http_crew.open("GET", "content/community/scripts/profile_action.php?sec=crew&tab=3&pilotid="+pilotid+"", true);
		http_crew.onreadystatechange = return_crew_3;
		http_crew.send(null);
	}
	if(tabid == 4)
	{
		http_crew.open("GET", "content/community/scripts/profile_action.php?sec=crew&tab=4&pilotid="+pilotid+"", true);
		http_crew.onreadystatechange = return_crew_4;
		http_crew.send(null);
	}
}

//------------------------------
// Return Tab 1
//------------------------------
function return_crew_1()
{
	if(http_crew.readyState == 4)
	{
		if(http_crew.status == 200)
		{
			// Check
			var error = http_crew.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue;
			if(error == "good")
			{
				// Get Vars
				var id_array = http_crew.responseXML.getElementsByTagName("id");
				var title_array = http_crew.responseXML.getElementsByTagName("title");
				var image_array = http_crew.responseXML.getElementsByTagName("link");
				var rating_array = http_crew.responseXML.getElementsByTagName("rating");
				
				// Start HTML
				var html = "<table cellpadding='2' cellspacing='0' width='100%' text-align='center'><tr>";
				
				// Loop Images
				for( i=0; i<id_array.length; i++ )
				{
					var image_title = title_array.item(i).firstChild.data.toString();
					var image = image_array.item(i).firstChild.data.toString();
					var rating = rating_array.item(i).firstChild.data.toString();
					
					html += "<td align='center'><span class='boldblue'>"+image_title+"</span><br /><a rel='lightbox' href='images/gallery/"+image+"' title='"+image_title+"'><img src='images/gallery/thumbs/th_"+image+"' border='0' alt='Click to enlarge...' /></a><br /><br /><img src='images/videos/"+rating+".gif' border='0' alt='"+rating+"' /><br /></td>";
				}
				
				// End HTML
				html += "</tr></table>";
			}
			else
			{
				var html = "<center>This member has not uploaded any screenshots...</center>";
			}
			
			document.getElementById("tab_crew_content").innerHTML = html;
			
			// Lightbox
			Lightbox.prototype.updateImageList();
		}
	}
	else
	{
		show_loading("tab_crew_content");
	}
}

//------------------------------
// Return Tab 2
//------------------------------
function return_crew_2()
{
	if(http_crew.readyState == 4)
	{
		if(http_crew.status == 200)
		{
			// Check
			var error = http_crew.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue;
			if(error == "good")
			{
				// Get vars
				var id_array = http_crew.responseXML.getElementsByTagName("id");
				var title_array = http_crew.responseXML.getElementsByTagName("title");
				var description_array = http_crew.responseXML.getElementsByTagName("description");
				var rating_array = http_crew.responseXML.getElementsByTagName("rating");
				
				// Start HTML
				var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr>";
				
				// Loop Videos
				for( i=0; i<id_array.length; i++ )
				{
					var id = id_array.item(i).firstChild.data.toString();
					var video_title = title_array.item(i).firstChild.data.toString();
					var description = description_array.item(i).firstChild.data.toString();
					var rating = rating_array.item(i).firstChild.data.toString();
					
					html += "<td align='center'><span class='boldblue'>"+video_title+"</span><br />"+description+"<br /><br /><img src='images/videos/"+rating+".gif' border='0' alt='"+rating+"' /><br /><br /><a href='index.php?page=crew_room&require=videos&act=view&id="+id+"' title='View Video'>View Video</a><br /></td>";
				}
				
				//End HTML
				html += "</tr></table>";
			}
			else
			{
				var html = "<center>This member has not uploaded any videos...</center>";
			}
			
			document.getElementById("tab_crew_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_crew_content");
	}
}

//------------------------------
// Return Tab 3
//------------------------------
function return_crew_3()
{
	if(http_crew.readyState == 4)
	{
		if(http_crew.status == 200)
		{
			var error = http_crew.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue;
			if(error == "good")
			{
				// Get Vars
				var id_array = http_crew.responseXML.getElementsByTagName("id");
				var title_array = http_crew.responseXML.getElementsByTagName("title");
				var rating_array = http_crew.responseXML.getElementsByTagName("rating");
				
				// Start HTML
				var html = "<table cellpadding='2' cellspacing='0' width='100%'><tr>";
				
				// Loop Reviews
				for( i=0; i<id_array.length; i++ )
				{
					var id = id_array.item(i).firstChild.data.toString();
					var review_title = title_array.item(i).firstChild.data.toString();
					var rating = rating_array.item(i).firstChild.data.toString();
					
					html += "<td align='center'><span class='boldblue'>"+review_title+"</span><br /><br /><img src='images/videos/"+rating+".gif' border='0' alt='"+rating+"' /><br /><br /><a href='index.php?page=crew_room&require=reviews&act=view&id="+id+"' title='View Review'>View Review</a><br /></td>";
				}
				
				// End HTML
				html += "</tr></table>";
			}
			else
			{
				var html = "<center>This member has not uploaded any reviews...</center>";
			}
			
			document.getElementById("tab_crew_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_crew_content");
	}
}

//------------------------------
// Return Tab 4
//------------------------------
function return_crew_4()
{
	if(http_crew.readyState == 4)
	{
		if(http_crew.status == 200)
		{
			var error = http_crew.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue;
			if(error == "good")
			{
				// Get Vars
				var id_array = http_crew.responseXML.getElementsByTagName("id");
				var date_array = http_crew.responseXML.getElementsByTagName("date");
				var title_array = http_crew.responseXML.getElementsByTagName("title");
				
				// Start HTML
				var html = "<table cellpadding='2' cellspacing='0' width='100%'>";
				
				// Loop News
				for( i=0; i<id_array.length; i++ )
				{
					var id = id_array.item(i).firstChild.data.toString();
					var news_date = date_array.item(i).firstChild.data.toString();
					var news_title = title_array.item(i).firstChild.data.toString();
					
					html += "<tr><td>"+news_date+"</td><td>"+news_title+"</td><td><a href='index.php?page=crew_room&require=news&act=view&id="+id+"' title='View Article'>View Article</a></td></tr>";
				}
				
				// End HTML
				html += "</table>";
			}
			else
			{
				var html = "<center>This member has not submitted any news...</center>";
			}
			
			document.getElementById("tab_crew_content").innerHTML = html;
		}
	}
	else
	{
		show_loading("tab_crew_content");
	}
}
