/* Javascript for field archery target details */
/* Eric Anderson October 2004 */

	/* Each target definition array has 7 elements */
	/* Field round 				*/
	/* 	1. face size 			*/
	/* 	2. shot lengths for adults 	*/
	/* 	3. shot lengths for juniors 	*/ 	
	/* Hunter round 				*/
	/* 	4. face size 			*/
	/* 	5. shot lengths for adults 	*/
	/* 	6. shot lengths for juniors 	*/
	/* Field and Hunter 			*/
	/* 	7. shot lengths for cubs 	*/

	var TBun = new Array('20cm', '35, 30, 25, 20ft', 'as adult','20cm', '4 x 11yd', 'as adult', '4 x 20ft');
	var T15  = new Array('35cm', '4 x 15yd', 'as adult', '35cm', '2 x 15, 2 x 14yd', 'as adult', '4 x 10yd');
	var T20  = new Array('35cm', '4 x 25yd', 'as adult', '35cm', '2 x 19, 2 x 17yd', 'as adult', '4 x 10yd');
	var T25  = new Array('35cm', '4 x 25yd', 'as adult', '35cm', '2 x 23, 2 x 20yd', 'as adult', '4 x 10yd');
	var T30  = new Array('35cm', '4 x 30yd', 'as adult', '35cm', '4 x 32yd fan', 'as adult', '4 x 10yd');
	var T35  = new Array('50cm', '4 x 35yd fan', 'as adult', '50cm', '4 x 36yd fan', 'as adult', '4 x 20yd');
	var T40  = new Array('50cm', '4 x 40yd', 'as adult', '50cm', '4 x 40yd', 'as adult', '4 x 20yd');
	var T45  = new Array('50cm', '4 x 45yd', 'as adult', '50cm', '4 x 44yd', 'as adult', '4 x 15yd');
	var T45w = new Array('50cm', '45, 40, 35, 30yd', 'as adult', '35cm', '4 x 28yd fan', 'as adult', '4 x 15yd fan');
	var T50  = new Array('50cm', '4 x 50yd', 'as adult', '50cm', '4 x 48yd', 'as adult', '4 x 20yd');
	var T55  = new Array('65cm', '4 x 55yd', '4 x 40yd', '50cm', '53, 48, 44, 41yd', '4 x 41yd', '4 x 20yd');
	var T60  = new Array('65cm', '4 x 60yd', '4 x 45yd', '65cm', '58, 53, 48, 45yd', '4 x 45yd', '4 x 25yd');
	var T65  = new Array('65cm', '4 x 65yd', '4 x 50yd', '65cm', '64, 59, 55, 52yd', '4 x 50yd', '4 x 30yd');
	var T80  = new Array('65cm', '80, 70, 60, 50yd', '4 x 50yd', '65cm', '70, 65, 61, 58yd', '4 x 50yd', '30, 25, 20, 15yd');

	/* Standard unit consists of 14 shots */
	var stdCourse = new Array('Standard Classification Unit', TBun, T15, T20, T25, T30, T45w, T35, T40, T45, T50, T55, T60, T65, T80);
	/* Whitemark course configuration */
	/* June 2008 */
	var whitemark = new Array('White Mark Bowmen Classification Course', T35, T45, T15, T65, T25, T40, T20, T45w, T80, T55, T30, T60, TBun, T50);
	whitemark['T30'] = T30;
	whitemark['T20'] = T20;
	whitemark['T15'] = T15;
	whitemark['T55'] = T55;
	whitemark['T80'] = T80;
	whitemark['T35'] = T35;
	whitemark['T45w'] = T45w;
	whitemark['T50'] = T50;
	whitemark['T25'] = T25;
	whitemark['T60'] = T60;
	whitemark['T40'] = T40;
	whitemark['TBun'] = TBun;
	whitemark['T65'] = T65;
	whitemark['T45'] = T45;
	/* Array for image URLs populated by "wmview_URLs.js" */
	var wmURLs = new Array();
	/* Array for view windows */
	var viewWindows = new Array(); 

	/* generate a table row for 1 shot */
	function genTarget(targNo) {
		shot = course[targNo];
		/*if (targNo % 2 == 1) rs ='"oddrow"'; 
		else rs = '"evenrow"'; 
		doc ='<TR CLASS=' + rs + '><TD>' + targNo + '</TD>'; */

		 /* alternate row shading */
		doc ='<TR ' + ((targNo % 2 == 1) ? 'CLASS="tablemainodd"' : '') + '><TD>' + targNo + '</TD>';
		for (x = 0; x<7; x++){
			doc = doc + '<TD>' + shot[x]+ '</TD>';
		}
		doc = doc +'</TR>';
		return doc;
	}

	/* generate HTML code to display a table of details for 14 targets */ 
	function genTargetTable(courseChoice) {
		course = courseChoice;
		document.open();
		document.write('<TABLE BORDER CELLSPACING="0" CELLPADDING="5" CLASS="tablemain">');
		document.write('<TR><TH COLSPAN="8">' + course[0] + '</TH></TR>');
		document.write('<TR><TH ROWSPAN="2" VALIGN="BOTTOM">No.</TH><TH COLSPAN="3">Field</TH><TH COLSPAN="3">Hunter</TH><TH ROWSPAN="2">Cubs</TH></TR>');
		document.write('<TR><TH>face</TH><TH>Adults</TH><TH>Juniors</TH><TH>face</TH><TH>Adults</TH><TH>Juniors</TH></TR>');
		for (y=1; y<15; y++) {
			document.write(genTarget(y));
		}
		document.write('</TABLE>');
		document.close();
		
	}

	/* generate HTML code to display details of a chosen target in a popup window */
	/* parameter is one of the Txx array variables */
	function genSingleTarget(targ) {
		shot = targ;
		doc = '';
		doc = doc + '<HTML><HEAD><TITLE>Target details</TITLE>';
		doc = doc + '<link rel="stylesheet" type="text/css" href="style.css">';
 
		/* creates a pseudo automatic window closure */
		doc = doc + '<BODY ONMOUSEOUT="javascript:window.close();">';

		doc = doc + getSingleTarget(targ);

		/* create or refresh popup window */
		targetWindow = window.open('','oneTarget','width=350,height=180');
		targetWindow.document.write(doc);
		targetWindow.document.close();
		targetWindow.focus();
	}

	/* generate HTML code to display details of a chosen target  */
	/* parameter is one of the Txx array variables */
	function getSingleTarget(shot) {

		doc = '<CENTER><TABLE BORDER CELLSPACING="0" CELLPADDING="5" CLASS="tablemain">';
		/* headings */
		doc = doc + '<TR><TH>round</TH><TH>Field</TH><TH>Hunter</TH></TR>';
		/* face sizes */
		doc = doc + '<TR CLASS="tablemainodd"><TH>face</TH><TD>' + shot[0] + '</TD><TD>' + shot[3] + '</TD></TR>';
		/* junior distances */
		doc = doc + '<TR><TH>Adult</TH><TD>' + shot[1] + '</TD><TD>' + shot[4] + '</TD></TR>';
		/* adult distances */
		doc = doc + '<TR CLASS="tablemainodd"><TH>Junior</TH><TD>' + shot[2] + '</TD><TD>' + shot[5] + '</TD></TR>';
		/* cub distances */
		doc = doc + '<TR><TH>Cub</TH><TD>' + shot[6] + '</TD><TD>' + shot[6] + '</TD></TR>';
		doc = doc + '</TABLE></CENTER>';
		return doc;
	}


	function showTargetList() {
		if (typeof(listWindow) != 'undefined' && !listWindow.closed) listWindow.focus();
		listWindow = window.open('wmtarget_list.htm','tl','width=650,height=500,resizable=yes');
	}

	function showView(viewCode){
		/* get URL from associative array */
		thisURL = wmURLs[viewCode];
		if (thisURL == null || thisURL == '') window.open('noview.htm','','width=250,height=40');
		else {
			viewWin = viewWindows[viewCode];
			if (viewWin != null && !viewWin.closed) viewWin.focus();
			else viewWindows[viewCode] = window.open(thisURL, viewCode,'width=700,height=360,resizable=yes,scrollbars=yes');
		}
	}
		