// check for browser compatibility
	isIE = (document.all) ? true : false; 
	
	function reCalc(id)	{
				
		if (id != 0)	{
			var courseID = parseInt(id);
			if (!eval('document.forms[0].courseID_'+id+'.checked'))	{
							
				//alert('de-checked');
				
				// get current price
				var nCurrentPrice = parseFloat(document.forms[0].current_price.value);
				var nOldPrice = 0;		// intitialise old price
								
				if (eval('document.forms[0].current_value_'+String(courseID)+'.value') != "")	{
					// we have a previous price for this form control, subtract this previous price from current
					// total before adding the new price.
					nOldPrice = parseFloat(eval('document.forms[0].current_value_'+String(courseID)+'.value'));			
				
					//alert("old price: "+nOldPrice);
					nCurrentPrice = nCurrentPrice - nOldPrice; 			
					//alert("new current price: " + nCurrentPrice);						
				}
				eval('document.forms[0].current_value_'+String(courseID)+'.value = 0');
								
			}
			else	{					
				var courseID = parseInt(id);				
				var nPrice = getPrice(courseID);																
				var nCurrentPrice = parseFloat(document.forms[0].current_price.value);				
				var nOldPrice = 0;
	
				// see if there is an old price											
				if (eval('document.forms[0].current_value_'+String(courseID)+'.value') != "")	{
					// we have a previous price for this form control, subtract this previous price from current
					// total before adding the new price.
					nOldPrice = parseFloat(eval('document.forms[0].current_value_'+String(courseID)+'.value'));			
					nCurrentPrice = nCurrentPrice - nOldPrice; 			
				}
				
				// store the new item price in ahidden var so if teh user changes this option
				// again, we can subtract what they selected before adding the new price.
				eval('document.forms[0].current_value_'+String(courseID)+'.value = nPrice');
				
				nCurrentPrice = nCurrentPrice + nPrice;
			}
		}
		else	{
			var nCurrentPrice = parseFloat(document.forms[0].current_price.value);
		
		}
	
		document.forms[0].subTotal.value = nCurrentPrice;
			
		// store the current price so we know it the next time around.
		document.forms[0].current_price.value = parseFloat(roundNumber(nCurrentPrice));
		
		// work out and display the subscriber discount
		if (document.forms[0].subscriber.checked)	{
			// minus 10% subscriber discount
			var nDiscount = (nCurrentPrice/100)*10;
			nCurrentPrice = nCurrentPrice - parseFloat(nDiscount);			
			var strSubDiscount = String(parseFloat(roundNumber(nDiscount)));
		}
		else	{
			// set discount ot 0
			var strSubDiscount = '0';
		}
						
		document.forms[0].subDiscount.value = strSubDiscount;
					
		// work out VAT
		var nVAT = (nCurrentPrice/100)*17.5; 
		nCurrentPrice = nCurrentPrice + parseFloat(nVAT);
		
		document.forms[0].vat.value = String(parseFloat(roundNumber(nVAT)));		
		document.forms[0].total.value = String(roundNumber(nCurrentPrice));	
	
		// set total amount so it gets sent to world pay.
		document.forms[0].amount.value = roundNumber(nCurrentPrice);
		
	}

	function getPrice(courseID)	{
		
		// retrieve the value of the selected date
		var nValue = eval('document.forms[0].dates_'+String(courseID)+'.options[document.forms[0].dates_'+String(courseID)+'.selectedIndex].value');
		
		//alert("value of drop down: "+nValue);
		
		// split the date value into 2 parts the first part is the price
		// the second part is the course date ID
		nValue = String(nValue);
		var nIndex = nValue.indexOf('_');
		var price = nValue.substr(0, nIndex);
		
		//alert("found price: "+ price);
		
		var nQty = eval('document.forms[0].qty_'+String(courseID)+'.options[document.forms[0].qty_'+String(courseID)+'.selectedIndex].value')
		//alert("Quantity: "+nQty);
		//alert("price: "+price);
		var nTot = parseFloat(parseFloat(price) * parseFloat(nQty));
		
		//alert("Total price: "+nTot);
		
		return parseFloat(nTot);
		
	}
	
	// this function rounds numbers to 2 deciaml places
	function roundNumber(num)	{
		var result=Math.round(parseFloat(num)*100)/100;
		return result;

	}
	
	// re-loads the course quantity list on course date selecteion
	function loadQtyList(nCourseID)	{
	
		// retrieve the total num of places for this current booking	
		var nQty = getDateQty(nCourseID);
		//alert("Qty for the selected date: "+nQty);
	
		var obj = eval('document.forms[0].qty_'+String(nCourseID));
	
		with(document.forms[0])	{
			
			//alert("num of qty items : "+obj);
			
			// remove all items from the places list
			for(var i=0;i<obj.options.length;i++){
				obj.remove(i);	
			}
			
			// re-load the places list based upon number of 
			//places for selected course date 
			for(var i=1;i<=nQty;i++){
    			obj[i-1] = new Option(i,i);
			}
		}		
	}
	
	function getDateQty(courseID)	{
		
		// retrieve the value of the selected date
		var nValue = eval('document.forms[0].dates_'+String(courseID)+'.options[document.forms[0].dates_'+String(courseID)+'.selectedIndex].value');
		
		//alert("value of drop down: "+nValue);
		
		// split the date value into 2 parts the first part is the price
		// the second part is the course date ID
		Value = String(nValue);
		var nIndex = nValue.indexOf('_');
		var dateID = nValue.substr(nIndex+1, nValue.length);
		
		//alert("Date id: "+dateID);
		
		//alert("looking for hidden field: "+'document.forms[0].qty_store_'+String(dateID)+'.value');
		
		nQty = eval('document.forms[0].qty_store_'+String(dateID)+'.value');
		
		//alert("found qty: "+ nQty);
		
		return parseInt(nQty);
		
	}