<!-- hide

var HelpWindow;
var HelpPage;
var XCEmail;
var KeyWindow;
var MapPoints;


/*
********************************************************************************

Main shared functions

*********************************************************************************
*/

function getObject(sName)
{

  if (document.getElementById)
  {
  	this.obj = document.getElementById(sName);
		this.style = document.getElementById(sName).style;
  }
  else if (document.all)
  {
		this.obj = document.all[sName];
		this.style = document.all[sName].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[sName];
   	this.style = document.layers[sName];
  }

}


function new_parent_img(loc)
{
/*
  if (!document.getElementById) {
  	return;
  }

  if (!parent.document.getElementById('hd_img')) {
  	return;
  } else {
		parent.document.getElementById('hd_img').style.backgroundImage = loc;
	}
*/
}


function backToFlight()
{

	// this will supercede viewFlight

	var url = document.leagueForm['xcLeaguePath'].value + 'viewFlight.php?';
	url += 'year=' + document.leagueForm['year'].value;
	url += '&leagueView=' + document.leagueForm['leagueView'].value;
	url += '&showView=' + document.leagueForm['showView'].value;
	url += '&xcFlightId=' + document.leagueForm['xcFlightId'].value;

	var val = document.leagueForm['showFlightDate'].value;
	if (val != '') {
		url += '&showFlightDate=' + val;
	}

	val = document.leagueForm['ids'].value;
	if (val != '') {
		url += '&ids=' + val;
	}

	location.href = url;

}


function backToLeague()
{

	// this will supercede viewLeague

	var url = document.leagueForm['xcLeaguePath'].value + 'view.php?';
	url += 'year=' + document.leagueForm['year'].value;
	url += '&leagueView=' + document.leagueForm['leagueView'].value;
	url += '&showView=' + document.leagueForm['showView'].value;

	var val = document.leagueForm['showFlightDate'].value;
	if (val != '') {
		url += '&showFlightDate=' + val;
	}

	location.href = url;

}


function backToAdmin()
{

	document.leagueForm['back'].value = 1;
	document.leagueForm.action = document.leagueForm['xcLeaguePath'].value + 'admin.php';
	document.leagueForm.submit();
	
}


function viewLeague(url, year, leagueView, showView, day)
{

	document.leagueForm.enctype = 'application/x-www-form-urlencoded';

	if (day != '') {
		var endPos = url.indexOf('view.php');
		url = url.substring(0, endPos);
		url += 'viewDaily.php';
		var suffix = '&showFlightDate=' + day;
	} else {
		var suffix = '';
	}

	window.status = '';

	var qs = '?';
	qs += 'year=' + year;
	qs += '&leagueView=' + leagueView;
	qs += '&showView=' + showView;
	qs += suffix;

	document.leagueForm.action = url + qs;
	document.leagueForm.submit();


}


function viewFlight(url, year, league, flightId, day)
{

	if (!day || day == 'undefined') {
		day = '';
	} else {
		day = '&showFlightDate=' + day;
	}

	window.status = '';

	document.leagueForm.enctype = 'application/x-www-form-urlencoded';

	var endPos = url.indexOf('view.php');
	url = url.substring(0, endPos);

	var qs = '?';
	qs += 'year=' + year;
	qs += '&leagueView=' + league;
	qs += '&xcFlightId=' + flightId;
	qs += day;

	document.leagueForm.action = url + 'viewFlight.php' + qs;
	document.leagueForm.submit();

}



/*
********************************************************************************

Help functions

*********************************************************************************
*/

function getHelp(sPage, converter)
{

	if (typeof(converter) != 'undefined') {
		var name = 'xcLeagueConverter';
	} else {
		var name = 'xcLeagueHelp';
	}
	
	sPage = 'help/' + sPage + '.htm';

	if (HelpWindow != null && (!HelpWindow.closed)) {

		if (sPage == HelpPage) {
			HelpWindow.focus();
		} else {
			HelpPage = sPage;
			HelpWindow.name = name;
			HelpWindow.location = sPage;
			HelpWindow.focus();
		}

		return true;
	}

	HelpPage = sPage;

	h = 350;
	w = 450;
	m = 10;

	x = screen.width - (w + m);
	y = m;

	var Values = 'height=' + h + ',width=' + w + ',top=' + y + ',left=' + x + ',status=no,toolbar=no,menubar=no,resizable=no,location=no,scrollbars=yes';
	HelpWindow = window.open(sPage, name, Values);

	return true;

}


function getHelpNew(topic, converter)
{

	if (typeof(converter) != 'undefined') {
		var name = 'xcLeagueConverter';
	} else {
		var name = 'xcLeagueHelp';
	}
	
	var sPage = 'help.php?topicId=' + topic;

	if (HelpWindow != null && (!HelpWindow.closed)) {

		if (sPage == HelpPage) {
			HelpWindow.focus();
		} else {
			HelpPage = sPage;
			HelpWindow.name = name;
			HelpWindow.location = sPage;
			HelpWindow.focus();
		}

		return true;
	}

	HelpPage = sPage;

	h = 350;
	w = 450;
	m = 10;

	x = screen.width - (w + m);
	y = m;

	var Values = 'height=' + h + ',width=' + w + ',top=' + y + ',left=' + x + ',status=no,toolbar=no,menubar=no,resizable=no,location=no,scrollbars=yes';
	HelpWindow = window.open(sPage, name, Values);

	return true;

}


function closeHelp()
{

	if (HelpWindow != null) {
		HelpWindow.close();
	}

}



/*
********************************************************************************

View functions

*********************************************************************************
*/

function viewSelect(leagueSelect)
{

	var leagueSel = document.leagueForm['leagueView'];
	var showSel = document.leagueForm['showView'];

	// if leagueSelect has changed we need to update show select options
	if (leagueSelect) {

		// see if selected value is in arLeagueIds to set showClubOption
		var showClubOption = false;
		for (i = 0; i < arLeagueIds.length; i++) {
			if (leagueSel.options[leagueSel.selectedIndex].value == arLeagueIds[i]) {
				showClubOption = true;
				continue;
			}
		}

		// see if ClubOption is in show select to set wasShown
		var wasShown = false;
		if (showSel.options.length == arShowViewName.length) {
			wasShown = true;
		}

		var showIndex = showSel.selectedIndex;

		// set show select length and showIndex
		if (showClubOption == true) {

			showSel.options.length = arShowViewName.length;

			// showing now, not showing previously
			if (wasShown == false) {
				if (showIndex >= clubOption) {
					showIndex++;
				}
			}

		} else {

			showSel.options.length = arShowViewName.length - 1;

			// not showing now, but shown previously
			if (wasShown == true) {

				if (showIndex == clubOption) {
					showIndex = 0;
				}

				if (showIndex > clubOption) {
					showIndex--;
				}

			}

		}

		// populate show select
		arIndex = 0;
		for (i = 0; i < showSel.options.length; i++) {
			if (i == clubOption && showClubOption == false) {
				arIndex ++;
			}

			showSel.options[i].value = arShowViewValue[arIndex];
			showSel.options[i].text = arShowViewName[arIndex];
			arIndex ++;
		}

		// set selectedIndex
		showSel.options.selectedIndex = showIndex;

	}

	if (leagueSel.options[leagueSel.selectedIndex].value == CurrentLeague
	&& showSel.options[showSel.selectedIndex].value == CurrentShow) {
		document.leagueForm['goButton'].disabled = true;
	} else {
		document.leagueForm['goButton'].disabled = false;
		document.leagueForm['goButton'].focus();
	}

}


function viewLeagueStart()
{

	viewSelect(true);
	document.leagueForm['goButton'].disabled = true;
	
}


function viewDailyInfoSynopticStart()
{

	synSelect(true);
	
	if (document.leagueForm['goButton']) {
		document.leagueForm['goButton'].visible = 'none';
	}
	
}


function writeLink(url, title, text, click)
{

	var sLine = "<a href='" + url + "' ";
	sLine += " onmouseover='window.status=\"" + title + "\"; return true;'";
	sLine += " onmouseout='window.status=\"\"; return true;'";
	sLine += " title=\"" + title + "\"";
	
	if (typeof(click) != 'undefined' && click != '') {
		sLine += " onclick=\"" + click + "\"";
	}
	
	sLine += ">" + text + "</a>";
	document.write(sLine);
	
}


function writeLinkEx(url, title, text, click, mouse, id)
{

	var sLine = "<a href='" + url + "' ";
	sLine += " id=\"" + id + "\"";
	
	sLine += " onmouseover=\"" + mouse + "\"";
	sLine += " onmouseout='window.status=\"\"; return true;'";
	sLine += " title=\"" + title + "\"";
	
	if (typeof(click) != 'undefined' && click != '') {
		sLine += " onclick=\"" + click + "\"";
	}
	
	sLine += ">" + text + "</a>";
	document.write(sLine);
	
}


function showClub(id, name)
{

	Block = new getObject(id + 'Block');
	Caption = new getObject(id + 'Caption');

	Link = new getObject(id + 'Link');
	
	if (Block.style.display == 'none') {
		Block.style.display = 'block';
		Caption.obj.innerHTML = 'Hide Other Flights';
		Link.obj.title = 'Hide other ' + name + ' flights';
		document[id + 'Pic'].src = HideIcon.src; 
	} else {
		Block.style.display = 'none';
		Caption.obj.innerHTML = 'Show Other Flights';
		Link.obj.title = 'Show other ' + name + ' flights';
		document[id + 'Pic'].src = ShowIcon.src; 
	}


}

function showMouseOver(id, name) {

	Block = new getObject(id + 'Block');

	if (Block.style.display == 'none') {
		window.status = 'Show other ' + name + ' Flights';
	} else {
		window.status = 'Hide other ' + name + ' Flights';
	}
	
	return true;
	
}

function imageSwap(pic, to)
{

	document[pic].src = to.src; 	
	
}


function fullView(url)
{

	var full = getCookie('fullView');

	if (full == null || full == '0') {
		full = '1';
	} else {
		full = '0';
	}
	
	
	document.cookie = "fullView=" + full;
	location.href = url;
	
}


function getCookie(cookieName)
{

	if (document.cookie.length > 0) {

		var cookieStart = document.cookie.indexOf(cookieName + "=");

		if (cookieStart!= -1) {

			cookieStart = cookieStart + cookieName.length + 1; 
			var cookieEnd = document.cookie.indexOf(";", cookieStart);

			if (cookieEnd == -1) {
			cookieEnd = document.cookie.length;
			}

			return unescape(document.cookie.substring(cookieStart, cookieEnd));

		}

	}

	return null;

}


function notReady()
{
	alert('Sorry, this page is still under construction');
}


/*
********************************************************************************

Edit functions

*********************************************************************************
*/

function editClick(flag)
{

	/*
	Function sets flightEdit hidden field

		1 - Enter flight
		2	- Edit flight
		3 - Delete flight and tracklog
		4 - Delete tracklog only
		5 - Upload new tracklog
		6 - Validate flight

	*/

	/*
	This bit is for loop radios. Not implemented yet
	Block = new getObject('loop');

	if (Block != null) {

		if (flag == 6) {
			Block.style.display = 'block';
		} else {
			Block.style.display = 'none';
		}

	}
	*/

	document.leagueForm['flightEdit'].value = flag;
	
}


function doDelete()
{

	document.leagueForm['deleteConfirmed'].value = 1;
	document.leagueForm.submit();

}


function sendEditEmail()
{

	var url = 'mailto:' + XCEmail + '?';
	url += 'subject=XC League Amendment';

	var Input = document.leagueForm['leagueView'];
	url += '&body=League: ' + Input.value + '%0D%0A';

	if (Input.value == 'National') {
		Input = document.leagueForm['score'];
		var score = Input.value;
	} else {
		Input = document.leagueForm['clubScore'];
		var score = Input.value;
	}

	Input = document.leagueForm['firstName'];
	url += 'Pilot: ' + Input.value + ' ';

	Input = document.leagueForm['lastName'];
	url += Input.value + '%0D%0A';

	Input = document.leagueForm['flightDate'];
	url += 'Flight date: ' + Input.value + '%0D%0A';

	Input = document.leagueForm['xcFlightId'];
	url += 'Flight Id: ' + Input.value + '%0D%0A';

	url += 'Score: ' + score + '%0D%0A%0D%0A';

	url += 'Please amend this flight as follows:' + '%0D%0A%0D%0A';
	url += '[Your instructions here]';

	document.location = url;

}

function sendCommentEmail()
{

	var url = 'mailto:' + XCEmail + '?';
	url += 'subject=XC League Comment';
	url += '&body=[Your comments here]';

	document.location = url;

}


function goToPage(url)
{

	document.location = url;

}


/*
********************************************************************************

Upload functions

*********************************************************************************
*/

function sendTrack()
{

	var file = document.leagueForm['datafile'].value;

	//Check filename input
	if (file == '') {
		alert('Please enter your tracklog file');
		document.leagueForm['datafile'].focus();
		return;
	}

	//Check extension is igc
  ext = file.substring(file.length-3, file.length);
  ext = ext.toLowerCase();
  if(ext != 'igc') {
		alert('Please select a valid tracklog file with an ".igc" extension');
		document.leagueForm['datafile'].focus();
		return;
  }


	/*
	//Check date matches

	var s = '';
	var len = file.length - 1;

	for (i = len; i > -1; i--) {

		if (file.charAt(i) == '\\' || file.charAt(i) == '/') {
			break;
		} else {
			s = file.charAt(i) + s;
		}


	}

	var arDate = s.split("-");
	var date = arDate[0];
	var invalid = false;

	if (arDate.length > 0) {
		date += '-' + arDate[1];
	} else {
		invalid = true;
	}

	if (arDate.length > 1) {
		date += '-' + arDate[2];
	} else {
		invalid = true;
	}

	if (invalid == true) {

		alert('Your file name is invalid. You must save your file\nwith the "IGC long file name" option checked.');
		return;
	} else {

		var flDate = document.leagueForm['flightDate'].value;

		if (flDate != date) {
			alert('Your file date (' + date + ') does not match your flight date (' + flDate + ')');
			return;
		}

	}

	*/

	document.leagueForm.submit();

}


/*
********************************************************************************

Menu functions

*********************************************************************************
*/


function openKey()
{

	if (KeyWindow != null && (!KeyWindow.closed)) {
		KeyWindow.focus();
		return true;
	}


	KeyWindow = window.open('key.htm', 'xcLeagueKey',
		"height=360, width=400, top=10, left=10, status=no, toolbar=no, menubar=no, location=no, resizable=no, scrollbars=yes");

	return true;

}


function closeKey()
{

	if (KeyWindow != null) {
		KeyWindow.close();
	}

}


/*
********************************************************************************

DailyInfo functions

*********************************************************************************
*/

function synSelect(start)
{

	var synTime = document.leagueForm['synTime'];
	var synDay = document.leagueForm['synDay'];
	
	if (synTime && synDay) {

		// set selected index in case of refresh
		if (typeof(start) != 'undefined') {
			synTime.selectedIndex = 2;
			synDay.selectedIndex = 0;
			return;
		}
	
		Line = new getObject('chartLine');
		var time = synTime.options[synTime.selectedIndex].value;
		var day = synDay.options[synDay.selectedIndex].value;
		
		if (synDay.selectedIndex == 0) {
			Line.obj.innerHTML = '<b>Surface analysis ' + time + ':00 UTC</b>';
		} else {
		
			Line.obj.innerHTML = '<b>Surface analysis ' + time + ':00 UTC</b> <span style=\'color: red;\'>- Day minus ' + synDay.selectedIndex + '</span>';
		}
		
		var chartUrl = baseChartUrl + day + time + '.gif';
		document.chartImage.src = chartUrl;
		
	}

}


/*
********************************************************************************

Admin functions

*********************************************************************************
*/

function adminClick(flag)
{

	/*
	Function sets adminTask hidden field

		1 - ADTSK_LEAGUE_ADMIN
		2	- ADTSK_PAYMENT_UPDATES
		3 - ADTSK_COMPETITION_ENTER
		4 - ADTSK_DEVELOPER_ONLY

	*/

	document.leagueForm['adminTask'].value = flag;
	
}


function pilotSelectClick()
{

	BhpaBlock = new getObject('bhpaBlock');
	NameBlock = new getObject('nameBlock');

	if (document.leagueForm.pilotSelect[0].checked == true) {
		BhpaBlock.style.display = 'none';
		NameBlock.style.display = 'block';
		document.leagueForm.pilot.focus();
	} else {
		BhpaBlock.style.display = 'block';
		NameBlock.style.display = 'none';
		document.leagueForm.pilotNo.focus();
	}

}


function isBlank(sValue)
{
	var sWhitespace = " \t\n\r";

	// Is sValue empty?
	if ((sValue == null) || (sValue.length == 0))
		return true;

	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.

	var sChar = '';

   for (var i = 0; i < sValue.length; i++) {

		// Check that current character isn't whitespace.
		sChar = sValue.charAt(i);

		if (sWhitespace.indexOf(sChar) == -1)
			return false;

   }

   // All characters are whitespace.
   return true;

}


function selectPilot() {

	//If name is checked set pilotNo from select box
	if (document.leagueForm.pilotSelect[0].checked == true) {
	
		//Get value of pilot select
		var Sel = document.leagueForm['pilot'];
		var sValue = Sel.options[Sel.selectedIndex].value;

		if (sValue == '') {
			
			alert('Please select a pilot from the list.');
			Sel.focus();
			return;
			
		} else {

			var arNo = sValue.split(' #');
			document.leagueForm.pilotNo.value = arNo[1];
			
		}
		
	} else {

		// BhpaNo checked for check valid entry
		var sValue = document.leagueForm.pilotNo.value;
		
		if (isBlank(sValue)) {
			
			alert('Please input the pilot\'s Bhpa No.');
			document.leagueForm.pilotNo.value = '';
			document.leagueForm.pilotNo.focus();
			return;
		}
		
	}
	
	document.leagueForm.submit();

}


function paymentSelect(start)
{

	var Sel = document.leagueForm['paymentStatus'];
	var Orig = document.leagueForm['paymentStatusOrig'].value;

	if (typeof(start) != 'undefined') {
		Sel.options.selectedIndex = Orig;
	}
	
	if (Sel.selectedIndex == Orig) {
		document.leagueForm['nextButton'].disabled = true;
	} else {
		document.leagueForm['nextButton'].disabled = false;
		document.leagueForm['nextButton'].focus();
	}

}


function updatePilot(flag)
{

	/*
	flag
	1 - Edit Pilot Details
	2 - Update Payment Details
	3 - Competition
	*/

	document.leagueForm.submit();

}


/*
********************************************************************************

Draw flight functions

*********************************************************************************
*/


function drawFlight(points, col, stroke)
{

	//Set main values
	var OffsetX = 50;
	var OffsetY = 500;

	//Extract points

	var arPoints = points.split(';');

	//Strip out last blank value, if it exists
	if (arPoints[arPoints.length - 1] == '') {
		arX = new Array(arPoints.length - 1);
  	arY = new Array(arPoints.length - 1);
  } else {
		arX = new Array(arPoints.length);
  	arY = new Array(arPoints.length);
  }

  var x = 0;
  var y = 0;

  for (var i = 0; i < arPoints.length; i++) {

 		if (arPoints[i] == '') {
 			continue;
 		}

  	arPairs = arPoints[i].split(',');

  	x = parseFloat(arPairs[0]);
  	arX[i] = Math.round((x - OffsetX) / 2);
  	
   	y = parseFloat(arPairs[1]);

   	//Check y co-ord is not greater map size
   	if (y >= 1000) {
   		return;
   	}

   	y = Math.round(y / 2);

   	//Convert y co-ord to top
   	arY[i] = (OffsetY - y);
  	
  }

	//alert("x: " + arX + "\ny: " + arY);

	drawDoc.clear();
  drawDoc.setColor(col);
  drawDoc.setStroke(stroke);
  drawDoc.drawPolyline(arX, arY);
  drawDoc.paint();

}


/*
********************************************************************************

Email cloaker functions. See Email Protector.htm.

Use 29 and 31 as primes
say function modified by John Stevenson to set XCEmail global variable
set function created to set XCEmail without writing to document
*********************************************************************************
*/

	// <!-- 1936472251
	// This script is (C) Copyright 2004 Jim Tucek
	// Leave these comments alone!  For more info, visit
	// www.jracademy.com/~jtucek/email/

function meet(algebra,forest,horse) {
	algebra += ' ';
	var bed = algebra.length;
	var camera = 0;
	var stairs = '';
	for(var circumstance = 0; circumstance < bed; circumstance++) {
		camera = 0;

		while(algebra.charCodeAt(circumstance) != 32) {
			camera = camera * 10;
			camera = camera + algebra.charCodeAt(circumstance)-48;
			circumstance++;
		}
		stairs += String.fromCharCode(understand(camera,forest,horse));
	}
	parent.location = 'm'+'a'+'i'+'l'+'t'+'o'+':'+stairs;

}

function say(dam,encounter,time) {
	dam += ' ';
	var philosophy = dam.length;
	var physicist = 0;
	XCEmail = '';
	for(var hour = 0; hour < philosophy; hour++) {
		physicist = 0;
		while(dam.charCodeAt(hour) != 32) {
		physicist = physicist * 10;
		physicist = physicist + dam.charCodeAt(hour)-48;
		hour++;
		}

		document.write(String.fromCharCode(understand(physicist,encounter,time)));
		XCEmail += String.fromCharCode(understand(physicist,encounter,time));
	}

}

function set(dam,encounter,time) {
	dam += ' ';
	var philosophy = dam.length;
	var physicist = 0;
	XCEmail = '';
	for(var hour = 0; hour < philosophy; hour++) {
		physicist = 0;
		while(dam.charCodeAt(hour) != 32) {
		physicist = physicist * 10;
		physicist = physicist + dam.charCodeAt(hour)-48;
		hour++;
		}

		XCEmail += String.fromCharCode(understand(physicist,encounter,time));
	}

}

function understand(privacy,hieroglyphic,hand) {
	if (hand % 2 == 0) {
		machine = 1;
		for(var monkey = 1; monkey <= hand/2; monkey++) {
			matrix = (privacy*privacy) % hieroglyphic;
			machine = (matrix*machine) % hieroglyphic;
		}
	} else {
		machine = privacy;
		for(var mortality = 1; mortality <= hand/2; mortality++) {
			matrix = (privacy*privacy) % hieroglyphic;
			machine = (matrix*machine) % hieroglyphic;
		}
	}
	return machine;
}


function test(id)
{

	Block = new getObject(id);
	
	if (Block.style.display == 'none') {
		Block.style.display = 'block';
	
	} else {
		Block.style.display = 'none';
	
	}


}
// end hide -->
