
trainPrice = new Array();

trainPrice[0] = 415
trainPrice[1] = 550
trainPrice[2] = 690
trainPrice[3] = 910
trainPrice[4] = 725
trainPrice[5] = 965
trainPrice[6] = 1170
trainPrice[7] = 1555
trainPrice[8] = 1115
trainPrice[9] = 1480
trainPrice[10] = 300
trainPrice[11] = 180
trainPrice[12] = 450
trainPrice[13] = 250
trainPrice[14] = 320
trainPrice[15] = 195
trainPrice[16] = 475
trainPrice[17] = 270
trainPrice[18] = 225
trainPrice[19] = 290
trainPrice[20] = 1500
trainPrice[21] = 360
trainPrice[22] = 1700
trainPrice[23] = 395
trainPrice[24] = 525
trainPrice[25] = 1200
trainPrice[26] = 1600
trainPrice[27] = 725
trainPrice[28] = 1260
trainPrice[29] = 1680
trainPrice[30] = 435
trainPrice[31] = 580
trainPrice[32] = 460
trainPrice[33] = 610
trainPrice[34] = 750
trainPrice[35] = 130
trainPrice[36] = 160
trainPrice[37] = 220
trainPrice[38] = 1050
trainPrice[39] = 1395
trainPrice[40] = 1245
trainPrice[41] = 1655
trainPrice[42] = 1390
trainPrice[43] = 1850
trainPrice[44] = 1460
trainPrice[45] = 1940
trainPrice[46] = 1350
trainPrice[47] = 1800
trainPrice[48] = 1420
trainPrice[49] = 1890
trainPrice[50] = 995
trainPrice[51] = 1325
trainPrice[52] = 1045
trainPrice[53] = 810
trainPrice[54] = 770
trainPrice[55] = 1030
trainPrice[56] = 1080
trainPrice[57] = 625
trainPrice[58] = 835
trainPrice[59] = 650
trainPrice[60] = 865
trainPrice[61] = 1400
trainPrice[62] = 1880
trainPrice[63] = 1790
trainPrice[64] = 775
trainPrice[65] = 465
trainPrice[66] = 620
trainPrice[67] = 405
trainPrice[68] = 535
trainPrice[69] = 425
trainPrice[70] = 560
trainPrice[71] = 1290
trainPrice[72] = 1720
trainPrice[73] = 600
trainPrice[74] = 790
trainPrice[75] = 375
trainPrice[76] = 495
trainPrice[77] = 1035
trainPrice[78] = 1365
trainPrice[79] = 1085
trainPrice[80] = 1445
trainPrice[81] = 900
trainPrice[82] = 1965
trainPrice[83] = 1745
trainPrice[84] = 2065
trainPrice[85] = 1870
trainPrice[86] = 2035
trainPrice[87] = 2135
trainPrice[88] = 150
trainPrice[89] = 420
trainPrice[90] = 490
trainPrice[91] = 230
trainPrice[92] = 275
trainPrice[93] = 575
trainPrice[94] = 50
trainPrice[95] = 75
trainPrice[96] = 400
trainPrice[97] = 250
trainPrice[98] = 350
trainPrice[99] = 60
trainPrice[100] = 85
trainPrice[101] = 100
trainPrice[102] = 175
trainPrice[103] = 245
trainPrice[104] = 325
trainPrice[105] = 390
trainPrice[106] = 0
trainPrice[107] = 295
trainPrice[108] = 95
trainPrice[109] = 145
trainPrice[110] = 675
trainPrice[111] = 930
trainPrice[112] = 335
trainPrice[113] = 205
trainPrice[114] = 285
trainPrice[115] = 260
trainPrice[116] = 1575
trainPrice[117] = 305
trainPrice[118] = 1785
trainPrice[119] = 135
trainPrice[120] = 165
trainPrice[121] = 595
trainPrice[122] = 155
trainPrice[123] = 215
trainPrice[124] = 330
trainPrice[125] = 345
trainPrice[126] = 449
trainPrice[127] = 200
trainPrice[128] = 385
trainPrice[129] = 65
/*************************************Update from here*****************************************/


/******************************************************************************\
	Return the value of the currently selected radio button in a radio
	group. 
\******************************************************************************/

function getSelectedRadioButton(button)
{
	result = "";
	/**/
	  if (typeof(button.length) == 'undefined') {
        // there is one item, so do this
        var buttonArray = new Array(button);
    }
      else
      {
            var buttonArray = button;
      }
	  
	for (var i = 0; i <buttonArray.length; i++)
	{
		if (buttonArray[i].checked == true)
		{
			result = buttonArray[i].value;
			break;
		}
	}
	return(result);
}


function getSelectedPrice()
{
	var unitPrice=trainPrice.value
	
	for (var i = 0; i <trainPrice.value; i++);
	{
	return  (trainPrice[i]);
	}
	
}

/******************************************************************************\
	OrderItem constructor
\******************************************************************************/

function OrderItem(qty, description, unitPrice)
{
	this.qty = qty;
	this.desc = description;
	this.unitPrice = unitPrice;
}

function placeOrder(f)
{
	var unitPrice = getSelectedPrice()
	
	var	desc = getSelectedRadioButton(f.train)

	var order = new OrderItem(f.qty.value, desc, unitPrice);
	
	var bwin = window.open("", "basket");

	// Error on line "bwin.code.basket[bwin.code.basket.length] = order;".
	if (typeof(bwin.code) == "undefined") 
	{
		window.alert("Your order window has been closed.  Clicking item 1. 'Start booking here' will open one for you.  Thank You.");
	bwin.close();
	}
	else
	{
		bwin.code.basket[bwin.code.basket.length] = order;
		drawOrderDetailsTable(bwin);
	}
}

function drawOrderDetailsTable(bwin)
{
	with (bwin)
	{
		var	orderTotal = 0;
		
		main.document.open();
		main.document.writeln("<table border=1 cellspacing=2 cellpadding=2>");
		main.document.writeln("<tr><td><img src=\"images/quantity.gif\"></td><td><img src=\"images/title.gif\"></td><td><img src=\"images/unitPrice.gif\"></td><td><img src=\"images/amount.gif\"></td><td><img src=\"images/remove.gif\"></td></tr>");

		for (var i = 0; i <code.basket.length; i++)
		{
			var lineTotal;
			var lineDesc = code.basket[i].qty
			var lineTitle = code.basket[i].desc
			
			main.document.writeln("<tr><td>",
			        code.basket[i].qty, "</td><td>",
				code.basket[i].desc, "</td><td>", 
				code.basket[i].unitPrice, "<span>\+vat\</span></td><td>",
				lineTotal = code.basket[i].qty 
					   * code.basket[i].unitPrice, "<span>\+vat\</span></td><td>",
				"<form><input type=\"button\" value=\"Remove\" onclick=\"parent.opener.deleteOrderLine(" + i + ");\"></form>");
			main.document.writeln("</td></tr>");
			orderTotal += lineTotal;
		}
		main.document.writeln("<tr><td><br /></td><td><br /></td><td align=right><img src=\"images/total.gif\">");
		main.document.writeln("</td><td align=left>", orderTotal);
		main.document.writeln("<span>\+vat\</span></td><td><br /></td></tr>");
		main.document.writeln("<tr><td colspan=2><form><input type=\"button\" value=\"5. Submit booking\" onclick=\"parent.opener.checkOrder();\"></form>");
		main.document.writeln("</td><td colspan=3><form><input type=\"button\" value=\"Close basket\" onclick=\"top.close();\">");
		main.document.writeln("</form></td></tr></table>");
		main.document.close();
		focus();
	}
		//Check quantity is entered
	if ((lineDesc == 0) || (lineDesc == "") || (lineTitle == 0) || (lineTitle == ""))
	{
	reset();
	}
}

function newBasket()
{
	var	bwin = window.open("", "basket");
	{
			// Nav 4 bug; remove bwin.code property, else later references will fail
		if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape"))
			delete(bwin.code);
			
		bwin.document.open();
		bwin.document.writeln("<title>CCFRA Order window:  Please minimise while browsing.</title>")
		bwin.document.writeln("<frameset rows='100%, *' frameborder=no border=0>");
		bwin.document.writeln("<frame name=main src='pre_order.htm'><frame name=code src='about:blank'></frameset>");
		bwin.document.close();
		bwin.code.basket = new Array();
		}
	}

function deleteArrayElement(arr, intElementToDelete)
{
     if (intElementToDelete < 0 || intElementToDelete > arr.length - 1)
     {
          return;
     }

     for (var i=intElementToDelete; i<arr.length-1; i++)
     {
          arr[i] = arr[i+1];
     }

     arr.length = arr.length - 1;
}

function deleteOrderLine(intArrayIndex)
{
     var bwin = window.open("", "basket");

     deleteArrayElement(bwin.code.basket,intArrayIndex);

     drawOrderDetailsTable(bwin)
}

var normal = new Image();
var highlight = new Image();


function populateOrderDetailsFields(oFm)
{
     var recordSeparator = "\n"
     var strOrderDetails = "";
	 var fltOrderTotal = 0;
     var bwin = window.open("", "basket");

     with (bwin.code)
     {
          for (var i=0; i<basket.length; i++)
          {
               if (strOrderDetails != "")
                    strOrderDetails += recordSeparator;

               strOrderDetails += 
			   			i+1 + ': '
						+ basket[i].qty + ' delegates for '
                        + basket[i].desc + ', at '
                        + basket[i].unitPrice + ' each.  Total = '
						+ basket[i].qty * basket[i].unitPrice + '.';
						
				fltOrderTotal += basket[i].qty * basket[i].unitPrice;
          }
     }
     oFm.orderdetails.value = strOrderDetails;
	 oFm.grandtotal.value = fltOrderTotal;
}

function buildOrderTable(oDC)
{
     var bwin = window.open("", "basket");
	 var orderTotal = 0;
	 var lineTotal;
	 var lastTotal;
	 var finalTotal;

     with (bwin.code)
     {
		oDC.writeln("<table cellspacing=\"3\" cellpadding=\"3\" align=\"center\">");
		oDC.writeln("<tr><td><p>Qty</p></td><td><p>Title</p></td><td><p>&pound; Unit Price</p></td><td><p>&pound; Amount</p></td></tr>");
		for (var i = 0; i <basket.length; i++)
		{
			oDC.writeln("<tr><td class=\"border\"><p>",
			    basket[i].qty, "</p></td><td class=\"border\"><p>",
				basket[i].desc, "</p></td><td class=\"border\"><p>", 
				basket[i].unitPrice, "<span>\+vat\</span></p></td><td class=\"border\"><p>",
				lineTotal = basket[i].qty 
					   * basket[i].unitPrice);
			oDC.writeln("<span>\+vat\</span></p></td></tr>");
			orderTotal += lineTotal;
			lastTotal = orderTotal * 0.175 + orderTotal;
			finalTotal = Math.round(lastTotal * 100) / 100;
		}
		oDC.writeln("<tr><td class=\"border\" colspan=\"3\" align=\"right\"><p>Total including VAT &pound;</p></td>");
		oDC.writeln("<td class=\"border\"align=left><p>", finalTotal);
		oDC.writeln("<span>\</span></p></td></table>");
	}
}
	

function weaveBasket()
{
	var	bwin = window.open("", "basket", "width=450,height=250,scrollbars=1,scroll(1,1)");
	
	
		/* check to see if the window already exists; if so, do nothing
		   - else we'll trash the current contents of the basket!
		*/
	if (typeof(bwin.code) == "undefined")
	{
			// Nav 4 bug; remove bwin.code property, else later references will fail
		if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape"))
			delete(bwin.code);
			
			
		bwin.document.open();
		bwin.document.writeln("<title>Order window: You can minimise or move when browsing</title>")
		bwin.document.writeln("<frameset rows='100%, *' frameborder='no' border='0'>");
		bwin.document.writeln("<frame name='main' src='pre_order.htm'><frame name='code' src='about:blank'></frameset>");
	
		bwin.document.close();
		bwin.code.basket = new Array();
	bwin.moveTo(400,400);}
}

function reset()
{
	var bwin = window.open("", "basket");
	{
	with (bwin);
		
		deleteOrderLine()
			
		window.alert("Sorry you either did not enter a price and/or a  quantity for an \n order.  Please click on the relevant price or enter a quantity \n for your order and add to Basket. Thank You.");

	}	
}

function checkOrder()
{
     var bwin = window.open("","basket");

     if (bwin.code.basket.length == 0)
	 {
         window.alert("There are currently no items in your basket \n You are being returned to the menu.");
		  
		  location.href="menu.htm";
		  }
     else
	 	{
          location.href="order1.htm";
	}
}

function checkDet()
{
     if (document.order.email.value =="" )
	 {
         window.alert("Please complete your email address thank you.")

		  order.email.focus()
		  return false;
	}
	{
     return true;
	}
}


