<!-- 

function createArray(size) {
	for (var i=0; i < size; i++) {
	this[i] = null }
	return this
	}

function Product(descrip, money) {
	this.description = descrip;
	this.price = money;
	}

function Category(name) {
	this.title = name;
	this.product = new createArray(1);
	this.product[0] = new Product("Please Select a Product", 0.00);
	}

	var category = new createArray(1);

// STEP NUMBER ONE
// enter the color for rows of the table
// (either javascript name or hex code)
color1 = "silver";
color2 = "silver";

// STEP NUMBER TWO:
// change the following declarations to fit your needs
//
// category[1] = new Category("Category Title Goes Here");
//  category[1].product[1] = new Product("Prod. 1 Name", price);
//  category[1].product[2] = new Product("Prod. 2 Name", price);
//  category[1].product[3] = new Product("Prod. 3 Name", price);
//
// category[2] = new Category("Category Title Goes Here");
//  category[2].product[1] = new Product("Prod. 1 Name", price);
//  category[2].product[2] = new Product("Prod. 2 Name", price);
//  category[2].product[3] = new Product("Prod. 3 Name", price);
//
// NOTE: You must define both the category array and the product array
// consecutively starting at 1. Again, the index of both arrays starts at 1


category[1] = new Category("Fixed period Subscription Options if you prefer");

category[1].product[1] = new Product("Current issue only BY EMAIL", 10.00);
category[1].product[2] = new Product("3 months UK/US/WW edition BY EMAIL", 25.00);
category[1].product[3] = new Product("12 months UK/US/WW Edition BY EMAIL", 77.00);
category[1].product[5] = new Product("Last 3 BACK ISSUES BY EMAIL", 7.00);
// ***** NO NEED TO CHANGE ANY CODE AFTER THIS COMMENT ***

function SetLengths() {
	// This function iterates through the categories, and now the products have been set above limits the catagories product list to what it has current contains
	// So that in the next function call (writeTableRow(i)) it can definitively say how many product are in this category!

	var k=1;
	while(category[k] != null)
		k++
		category.length = k;
		for (i=1; i<category.length; i++) {
			var j=1;
			while (category[i].product[j] != null)   j++;
			category[i].product.length = j;
			}
		}

SetLengths();

function writeTableRow(i) {
	// For Category[i] it draws the row, in the right Color and the relevant select gadgets
	// Callback function for the product is update[$currentrow]
	// When then price is focus every other field is de-selected
	// menuX = categoryX is the product currently selected
	// priceX = the price of the selected product

	document.write('<tr bgcolor="' + ((i%2 == 0) ? color1 : color2) + '">');
	document.write('<td>' + category[i].title.toUpperCase() + ':<br>'  + '<select size="1" name="menu' + i + '" onChange="update(' + i + ')">');
	len = category[i].product.length;
	for (j=0; j<len; j++) {
	if (j != 0)
		document.write('<option>' + category[i].product[j].description + ' -  ' + fix(category[i].product[j].price) + ' UK Pounds' + '</option>');
		else
		document.write('<option selected value=" ">Please Select a Subscription</option>');
		}
	document.write('</select></td><td valign=bottom>' + '<input type="text" value="0.00" name="price' + i + '" '  + 'size=12 maxlength=12 onFocus="document.form1.price' + i + '.blur()">' + '</td></tr>');
	}

function writeTable() {
	// Draws the whole table using iterative calls to writeTableRow(i) + plus the special case of the last row!
	document.write('<table cellspacing=1 cellpadding=5 border=0>');
	for (i=1; i<category.length; i++) writeTableRow(i);
	document.write('<tr bgcolor="' + ((category.length%2==0) ? color1 : color2) + '"><td align=right>GRAND TOTAL: </td><td><input type="text" ' + 'name="total" size=12 maxlength=12 value="0.00"></td></tr></table>');
	}

function update(num) {
	//Update priceX with the price of the newly selected item! and then updates the grand total!
	// Fills in relevant hidden values

	eval('selected = document.form1.menu' + num + '.selectedIndex;');
	//Gets the Product index eval is means that it is not worked out till the function is called ie returns the number of the item ie the second item would return 2

	//Item Deselected, ie:- -1 from the discount
	if(category[num].product[selected].description ==  "Please Select a Subscription" ) {
		} else {
			//Item Deselected, ie:- +1 to the discount
			}
	cost = fix(category[num].product[selected].price);
	//Gets the price of the selected item
	eval('document.form1.price' + num + '.value = cost;');

	var grand_total = 0;
	var description = "";
	var first = 1;
	for (i=1; i<category.length; i++) {
		eval('grand_total += parseFloat(document.form1.price' + i + '.value);');
		eval('selected = document.form1.menu' + i + '.selectedIndex;');
		if(category[i].product[selected].description !=  "Please Select a Subscription" ) {
			if(first == 1){
				description = category[i].product[selected].description;
				first = 2;
				} else {
					description = description + " + " + category[i].product[selected].description;
					}
			}
		}
	// Goes through every row and price and stores it in the grand total
	document.form1.total.value = fix(grand_total);
	document.selectJunior.amount.value = fix(grand_total);
	document.selectJunior.desc.value = description;
	}

function fix(num) {
	// passed should look like this "category[1].product[2].price"
	// should get a string of the price out!

	string = "" + num;
	if (string.indexOf('.') == -1) return string + '.00';
	seperation = string.length - string.indexOf('.');
	if (seperation > 3) return string.substring(0,string.length-seperation+3);
		else if (seperation == 2) return string + '0';
	return string;
	}


// -->


