allowed=true;
disable=false;

function initDivs(){
	setStyleById('d0', 'visibility', 'visible');
	setStyleById('d0', 'left','120');
	setStyleById('d1', 'visibility', 'visible');
	setStyleById('d1', 'left','180');
	setStyleById('d1', 'zIndex','9');
	setStyleById('d2', 'visibility', 'visible');
	setStyleById('d2', 'left','240');
	setStyleById('d3', 'visibility', 'visible');
	setStyleById('d3', 'left','300');
	setStyleById('d4', 'visibility', 'visible');
	setStyleById('d4', 'left','360');
	middleid = 3;
}

function movedivright(){
	disable=true;
	leftid = middleid - 1;
	rightid = middleid + 1;
	newid = middleid - 2;
	leftdiv = document.getElementById('d' + leftid);
	midddiv = document.getElementById('d' + middleid);
	rightdiv = document.getElementById('d' + rightid);
	newdiv = document.getElementById('d' + newid);
	oldleft = leftdiv.style.left;
	leftdiv.style.left = parseInt(oldleft) + 5;
	oldleft = midddiv.style.left;
	midddiv.style.left = parseInt(oldleft) + 5;
	oldleft = rightdiv.style.left;
	rightdiv.style.left = parseInt(oldleft) + 5;
	oldleft = newdiv.style.left;
	newdiv.style.left = parseInt(oldleft) + 5;
	if((midddiv.style.left == '360px')||(midddiv.style.left == '360')){
		middleid = middleid - 1
		disable=false;
	}
	else{
		window.setTimeout("movedivright();",10);
	}
	
}

function movedivleft(){
	disable=true;
	leftid = middleid - 1;
	rightid = middleid + 1;
	newid = middleid + 2;
	leftdiv = document.getElementById('d' + leftid);
	midddiv = document.getElementById('d' + middleid);
	rightdiv = document.getElementById('d' + rightid);
	newdiv = document.getElementById('d' + newid);
	oldleft = leftdiv.style.left;
	leftdiv.style.left = parseInt(oldleft) - 5;
	oldleft = midddiv.style.left;
	midddiv.style.left = parseInt(oldleft) - 5;
	oldleft = rightdiv.style.left;
	rightdiv.style.left = parseInt(oldleft) - 5;
	oldleft = newdiv.style.left;
	newdiv.style.left = parseInt(oldleft) - 5;
	//blah = midddiv.style.left;
	//alert(typeof(blah));
	if((midddiv.style.left == '240px')||(midddiv.style.left == '240')){
		middleid = middleid + 1
		disable=false;
		
	}
	else{
		window.setTimeout("movedivleft();",10);
	
	}
}

function changeLeftArrow(middleid) {
	switch(middleid){
		case 4 :
			//disable RIGHT
			setStyleById('rightarrowbot','visibility','hidden');
			break;
		case 18 :
			//enable LEFT
			setStyleById('leftarrowbot','visibility','visible');
			break;
			
	}
}

function changeRightArrow(middleid) {
	switch(middleid){
		case 3 :
			//enable RIGHT
			setStyleById('rightarrowbot','visibility','visible');
			break;
		case 17 :
			//disable LEFT
			setStyleById('leftarrowbot','visibility','hidden');
			break;
			
			
	}
}

function moveRight(){
	if((disable != true)&&(middleid != 3)){
		newdiv = middleid - 2;
		setStyleById('d' + newdiv, 'visibility','visible');
		setStyleById('d' + newdiv, 'left','180');
		movedivright();
		changeLeftArrow(middleid);
	}
}
function moveLeft(){
	if((disable != true)&&(middleid != 18)){
		newdiv = middleid + 2;
		setStyleById('d' + newdiv, 'visibility','visible');
		setStyleById('d' + newdiv, 'left','420');
		movedivleft();
		changeRightArrow(middleid);
	}	
}

function enlarge(url) {
  window.open(url,"magEnlarge","resizable,width=400,height=450,left=100,top=100");
}

function upsell(querystr, quantity, price, upsellprice) {
	if (quantity == 500){
		difference = (1000 * upsellprice) - (500 * price);
		document.getElementById("offer1").innerHTML = "<a class=biglink href='../orderform/orderform.asp?" + querystr + "&quantity=1000'>I want to order 1000 units for only $" + difference + " more</a>";
		document.getElementById("offer2").innerHTML = "<a class=biglink href='../orderform/orderform.asp?" + querystr + "&quantity=500'>I want to only order 500 units</a>";
	}
	else{
		window.location = "../orderform/orderform.asp?" + querystr + "&quantity=" + quantity;
	}
}

function keyCount(text){
	if(text.value.length > 1018) {
		alert("Please keep your comments to less than 120 characters");
		text.value = text.value.substring(0,1019);
	}
}

function clearText() {
	if(document.forms['form1'].CCC.value == "Please enter your comments, compliments or complaints in this area") {
		document.forms['form1'].CCC.value = '';
	}
}

function colorAnswer(qdex,color) {
	did = "d" + qdex;
	bid = "b" + qdex;
	setStyleById(did, "color", color);
	setStyleById(bid, "color", color);
	if((qdex == 5)||(qdex == 7)){
		lid = "l" + qdex;
		setStyleById(lid, "color", color); 
	}
}

function showAllAnswers() {
	if(allowed){
		totalQuestions = 9;
		for(index=1; index<=totalQuestions; index++) {
			colorAnswer(index, "#215AA5");
		}
	}
	else {
		allowed = true;
	}
}

function hideOtherAnswers(question) {
	totalQuestions = 9;
	for(index=1; index<=totalQuestions; index++) {
		
		if(index == question) {
			colorAnswer(index, "215AA5");
		}
		else {
			colorAnswer(index, "#c0c0c0");
		}
	}
}

function jump(question) {
	
	mylocation = "#d" + question;
	location = mylocation;
	allowed = false;
	hideOtherAnswers(question);
}

function selected(reqquantity) {
	
	for(index = 0;index < 6; index++){
		if(reqquantity == document.forms['form1'].quantity.options[index].text) {
			document.forms['form1'].quantity.options[index].selected = true;
		}
		else {
		}
	}
	calcOrderPrice();
}

function checkSelected() {
	design = document.forms['form1'].design;
	if(design.options[design.selectedIndex].value == "0") {
		alert("Please select design first");
	}
}

function changeSize(recordCount) {
	size = document.forms['form1'].size;
	design = document.forms['form1'].design;
	if(design.options[design.selectedIndex].value == "free") {
		//size.options[1] = new Option(allsizes[0],allsizes[0]);
		//size.options[2] = new Option(allsizes[1],allsizes[1]);
		//while (size.options.length - 3) size.options[3] = null;
		size.options[1].text = 	allsizes[0],allsizes[0];
		size.options[1].value = allsizes[0],allsizes[0];
		size.options[2].text = 	allsizes[1],allsizes[1];
		size.options[2].value = allsizes[1],allsizes[1];
		for(index=3;index<=recordCount; index++){
			size.options[index].text = 	"";
			size.options[index].value = "";
		}
	}
	else {
		for(index=1;index<= recordCount; index++) { 
			//size.options[index] = new Option(allsizes[index-1],allsizes[index-1]);
			size.options[index].text  = allsizes[index-1],allsizes[index-1];
			size.options[index].value = allsizes[index-1],allsizes[index-1];
		}
	}
}

function formatCurrency(num, showunit) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	
	if (showunit) 
	{
	return (((sign)?'':'-') + num + '.' + cents);
        }
        else
	{
	return (((sign)?'':'-') + '$' + num + '.' + cents);
	}

}


function removeNodes() {
	var el
	var text
	el = document.getElementById("unit");
	if (el.hasChildNodes())
  	el.removeChild(el.lastChild);
	el = document.getElementById("price");
	if (el.hasChildNodes())
  	el.removeChild(el.lastChild);
	el = document.getElementById("ship");
	if (el.hasChildNodes())
  	el.removeChild(el.lastChild);
	el = document.getElementById("setup");
	if (el.hasChildNodes())
  	el.removeChild(el.lastChild);
  	el = document.getElementById("gst");
	if (el.hasChildNodes())
  	el.removeChild(el.lastChild);
	el = document.getElementById("total");
	if (el.hasChildNodes())
  	el.removeChild(el.lastChild);
}

function appendNodes(unitprice, price, gst, total) {
	var el
	var text
	//text = document.createTextNode("$" + unitprice);
	el = document.getElementById("unit");
	//el.appendChild(text);
	el.innerHTML = "$" + unitprice;
	
	//text = document.createTextNode(formatCurrency(price));
	el = document.getElementById("price");
	//el.appendChild(text);
	el.innerHTML = formatCurrency(price);
	
	//text = document.createTextNode("$0.00");
	el = document.getElementById("ship");
	//el.appendChild(text);
	el.innerHTML = "$0.00";
	
	//text = document.createTextNode("$25.00");
	el = document.getElementById("setup");
	//el.appendChild(text);
	
	//changed to $0.00
	el.innerHTML = "$0.00";
	//el.innerHTML = "$25.00";
	
	//text = document.createTextNode(formatCurrency(gst));
	el = document.getElementById("gst");
	//el.appendChild(text);
	el.innerHTML = formatCurrency(gst);
	
	//text = document.createTextNode(formatCurrency(total));
	el = document.getElementById("total");
	//el.appendChild(text);
	el.innerHTML = formatCurrency(total);
}

function calcOrderPrice() {
  	//removeNodes();
  	quantitydex = document.forms['form1'].quantity.selectedIndex;
  	quantityval = parseInt(document.forms['form1'].quantity.options[quantitydex].text);
  	unitprice = parseFloat(pricefield[quantitydex]);
  	var price = parseInt(quantityval * unitprice);
	//removed the $25 setup fee
	/* Old line: var gst = (price+25)/10; */
	/* New line: */ var gst = (price)/10;
	
	/* Old line: var total = price + gst + 25; */
	/* New line: */ var total = price + gst;
	
	document.forms['form1'].grandtotal.value = price;
	appendNodes(unitprice, price, gst, total);
}

function calcPriceCalc() {
  	//removeNodes();
	designval = document.forms['form1'].design.value;
	sizeval = document.forms['form1'].size.value;
	quantityval = document.forms['form1'].quantity.value;

	if((designval != "0") && (sizeval != "0") && (quantityval != "0")) {
		sizedex = document.forms['form1'].size.selectedIndex;
		quantitydex = document.forms['form1'].quantity.selectedIndex;
		unitprice = parseFloat(pricerecord[(sizedex)-1][(quantitydex) - 1]);
		//unitprice = parseFloat(pricerecord[(sizedex)-1][parseInt(quantitydex) - 1]);
		quant = parseInt(document.forms['form1'].quantity.options[document.forms['form1'].quantity.selectedIndex].value);
		var price = quant * unitprice;
		// var price = parseInt(quant * unitprice);
		var total = price;
		
		//Remove the $25
		//var gst = (total+25)/10;
		var gst = (total)/10;

		//total = total + gst + 25;
		total = total + gst;
		// 15 jan 2004 - need to round unitprice and zero pad
		//unitprice = Math.round(unitprice*Math.pow(10,2))/Math.pow(10,2);
		unitprice = formatCurrency(unitprice, 1);
		appendNodes(unitprice, price, gst, total);
	}
	else {
		appendNodes("0.00","0","0","0")
	}
}

function MM_findObj(n, d) { //v4.0
var p,i,x;
if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
}
if(!(x=d[n])&&d.all) x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n);
return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {
	test=args[i+2]; val=MM_findObj(args[i]);
    if (val) {
		nm=val.name;
		if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) {
				p=val.indexOf('@');
				if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
			}
			else if (test!='R') {
				num = parseFloat(val);
				if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
				if (test.indexOf('inRange') != -1) {
					p=test.indexOf(':');
					min=test.substring(8,p);
					max=test.substring(p+1);
					if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
				}
			}
		}
		else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
	}
}
if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// ugly workaround for missing support for selectorText in Netscape6/Mozilla
// call onLoad() or before you need to do anything you would have otherwise used
// selectorText for.
var ugly_selectorText_workaround_flag = false;
var allStyleRules;
// code developed using the following workaround (CVS v1.15) as an example.
// http://lxr.mozilla.org/seamonkey/source/extensions/xmlterm/ui/content/XMLTermCommands.js
function ugly_selectorText_workaround() {
	if((navigator.userAgent.indexOf("Gecko") == -1) ||
	   (ugly_selectorText_workaround_flag)) {
		return; // we've already been here or shouldn't be here
	}
	var styleElements = document.getElementsByTagName("style");
	
	for(var i = 0; i < styleElements.length; i++) {
		var styleText = styleElements[i].firstChild.data;
		// this should be using match(/\b[\w-.]+(?=\s*\{)/g but ?= causes an
		// error in IE5, so we include the open brace and then strip it
		allStyleRules = styleText.match(/\b[\w-.]+(\s*\{)/g);
	}

	for(var i = 0; i < allStyleRules.length; i++) {
		// probably insufficient for people who like random gobs of 
		// whitespace in their styles
		allStyleRules[i] = allStyleRules[i].substr(0, (allStyleRules[i].length - 2));
	}
	ugly_selectorText_workaround_flag = true;
}


// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
	var n
	if((n = MM_findObj(i)) != null){
		n.style[p] = v;
	}
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
	var n = document.getElementById(i);
	var s = eval("n.style." + p);

	// try inline
	if((s != "") && (s != null)) {
		return s;
	}

	// try currentStyle
	if(n.currentStyle) {
		var s = eval("n.currentStyle." + p);
		if((s != "") && (s != null)) {
			return s;
		}
	}
	
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[y] == i) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) ||
						   (rules[y].selectorText == i)) {
							return z[p];
						}
					}
				}
			}
		}
	}
	return null;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}

	return null;
}

// setStyleByTag: given an element type, style property and 
// value, and whether the property should override inline styles or
// just global stylesheet preferences, apply the style.
// args:
//  e - element type or id
//  p - property
//  v - value
//  g - boolean 0: modify global only; 1: modify all elements in document
function setStyleByTag(e, p, v, g) {
	if(g) {
		var elements = document.getElementsByTagName(e);
		for(var i = 0; i < elements.length; i++) {
			elements.item(i).style[p] = v;
		}
	} else {
		var sheets = document.styleSheets;
		if(sheets.length > 0) {
			for(var i = 0; i < sheets.length; i++) {
				var rules = sheets[i].cssRules;
				if(rules.length > 0) {
					for(var j = 0; j < rules.length; j++) {
						var s = rules[j].style;
						// selectorText broken in NS 6/Mozilla: see
						// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
						ugly_selectorText_workaround();
						if(allStyleRules) {
							if(allStyleRules[j] == e) {
								s[p] = v;
							}			
						} else {
							// use the native selectorText and style stuff
							if(((s[p] != "") && (s[p] != null)) &&
							   (rules[j].selectorText == e)) {
								s[p] = v;
							}
						}

					}
				}
			}
		}
	}
}

// getStyleByTag: given an element type and style property, return
// the property's value
// args:
//  e - element type
//  p - property
function getStyleByTag(e, p) {
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		for(var i = 0; i < sheets.length; i++) {
			var rules = sheets[i].cssRules;
			if(rules.length > 0) {
				for(var j = 0; j < rules.length; j++) {
					var s = rules[j].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[j] == e) {
							return s[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((s[p] != "") && (s[p] != null)) &&
						   (rules[j].selectorText == e)) {
							return s[p];
						}
					}

				}
			}
		}
	}

	// if we don't find any style sheets, return the value for the first
	// element of this type we encounter without a CLASS or STYLE attribute
	var elements = document.getElementsByTagName(e);
	var sawClassOrStyleAttribute = false;
	for(var i = 0; i < elements.length; i++) {
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if((node.attributes.item(j).nodeName == 'class') ||
			   (node.attributes.item(j).nodeName == 'style')){
			   sawClassOrStyleAttribute = true;
			}
		}
		if(! sawClassOrStyleAttribute) {
			return elements.item(i).style[p];
		}
	}
}



