// RestonTech StoreFront
// Copyright (c) 2003,2004 RestonTech, Ltd
// This code is protected by copyright law, duplication is
// expressly prohibited.

// The following routines are part of the RestonTech StoreFront.
// They are intended to be used ONLY with the corresponding
// server-based utilities provided to RestonTech StoreFront
// customers.

// This file is used on each page with items, to facilitate loading
// correct values.

var HostName = "www.dcimprov.com";
var Message = 	"The D.C. Improv store must be called directly to purchase items.\n" +
				"Press 'OK' to enable the shopping cart features.\n" +
				"Press 'Cancel' to continue loading, with the shopping cart disabled.";
var ChangeURL = true;

// Check to see if loaded inside another domain (e.g. Google cache) and warn
//if (location.host != HostName) {
//	ChangeURL = window.confirm(Message);
//	if (ChangeURL) location.href = 'http://' + HostName + '/';
//	ChangeURL = false;
//	}

// Check for frames, reload into frames if page called directly
if (ChangeURL && (self == self.parent)) {
	top.location.replace( '/?' + location.pathname.substring(1) );
	}

// Make alias of order data structure
var order = parent.order;
var count;	// holding value

// Loads values of items already chosen back into form. Mainly useful
// to allow visitors to go back and forth, picking and choosing as they
// go (back).
function compute() {
	// Alias to counter element in top frame
	count = parent.store_top.document.display.count;
	var f = document.forms.length;
	for (i=0; i<f; i++) {
		n = document.forms[i].name;
		if (order[n]) {
			document.forms[i].order.checked = true;
			if (document.forms[i].num.length) {
				document.forms[i].num.options.selectedIndex = order[n];
				} // end if
			else {
				document.forms[i].num.text = order[n];
				} // end else
			} // end if
		} // end for
	var c = 0;
	for (i in order) {
		c += order[i];
		}
	count.value = c;
	} // end compute()

// When a checkbox is set, set the corresponding number field to '1' (it was
// '0' before being checked). When a checkbox is unset, set the number field
// to '0'.
function check(item) {
	var f = "document." + item;
	if (order[item]) {
		order[item]++;
		}
	else {
		order[item] = 1;
		}
	var old_num = order[item] ? order[item] : 0;
//	if (eval(f + ".num.length")) {
//		eval(f + ".num.selectedIndex = (" + f + ".order.checked) ? 1 : 0");
//		order[item] = eval(f + ".num.selectedIndex");
//		} // end if
//	else {
//		eval(f + ".num.value = (" + f + ".order.checked) ? '1' : '0'");
//		eval(f + ".num.text = (" + f + ".order.checked) ? '1' : '0'");
//		order[item] = eval(f + ".num.value");
//		} // end else
	// update display count
	var c = 0;
	for (i in order) {
		c += order[i];
		}
	count.value = c;
//	count.value = parseInt(count.value) + order[item] - old_num;
	} // end check()

// When a select field is changed, set the corresponding checkbox if any
// number of items were selected, unset the checkbox if zero items are entered.
function sel(item) {
	var f = "document." + item;
	var old_num = order[item] ? order[item] : 0;
	if (eval(f + ".num.length")) {
		eval(f + ".order.checked = (" + f + ".num.selectedIndex > 0) ? true : false");
		order[item] = eval(f + ".num.selectedIndex");
		} // end if
	else {
		eval(f + ".order.checked = (" + f + ".num.value > 0) ? true : false");
		order[item] = eval(f + ".num.value");
		} // end else
	// update display count
	count.value = parseInt(count.value) + order[item] - old_num;
	} // end num()

