/*
 * Copyright 2006 David & Goliath, All Rights Reserved
 * $Id: common.js,v 1.4 2009/09/11 20:57:16 tredman Exp $
 * Common JavaScript utility functions for shopping cart
 */

function getBaseObject(x) {
  if(document.getElementById && document.getElementById(x)) { return document.getElementById(x); }
  else if (document.all && document.all(x)) { return document.all(x); }
  else if (document.layers && document.layers[x]) { return document.layers[x]; }
  else { return false; }
}

function validateText(x) { x.value = x.value.replace("<","").replace(">","").toUpperCase(); }

function colorListShow(f) {
	var t = getBaseObject("colorlist").style, l = getBaseObject("aclabel").style, s;
	if (f) { s = "visible"; l.color = "white"; } else { s = "hidden"; l.color = "gray"; }
	t.visibility = s;
}

function validateAddress(x) {
	x = x.toUpperCase();
	if (x.search(/BOX/) == -1) { return true; } else { return false; }
}

function checkRequiredFields() {
	var fl = new Array();
	var rf = new Array(
		"blastname", "bfirstname", "baddress1", "bcity", "bzip",
		"bcountry", "bphone", "bemail", "slastname", "sfirstname",
		"saddress1", "scity", "szip", "scountry"
	);
	var rfd = new Array(
		"Billing Last Name", "Billing First Name", "Billing Address", "Billing City", "Billing Postal Code",
		"Billing Country", "Billing Phone", "Billing E-Mail", "Shipping Last Name", "Shipping First Name",
		"Shipping Address", "Shipping City", "Shipping Postal Code", "Shipping Country"
	);
	var i, x = 0;
	for (i = 0; i < rf.length; i++) {
		if (getBaseObject(rf[i]).value == "" || getBaseObject(rf[i]).value == "0") {
			fl[x++] = rfd[i];
			getBaseObject(rf[i]).style.backgroundColor = "wheat";
		}
	}
	return fl;
}

var mi = new Array("orders", "reports", "process");

function hideAll() {
	for (x in mi) getBaseObject(mi[x]+"_menu").style.visibility = 'hidden';
	getBaseObject("drop_shadow").style.visibility = 'hidden';
}

function showSubMenu(x) {
	var y = getBaseObject("drop_shadow").style;
	var z = getBaseObject(x.id+"_menu");
	getBaseObject(x.id+"_menu").style.visibility = 'visible';
	y.width = parseInt(z.offsetWidth);
	y.height = parseInt(z.offsetHeight);
	y.top = parseInt(z.offsetTop) + 2;
	y.left = parseInt(z.offsetLeft) + 2;
	y.visibility = 'visible';
}

function menuPopup(x){
	if (getBaseObject(x.id+"_menu").style.visibility.toLowerCase() == 'hidden') { hideAll(); showSubMenu(x); }
	else { hideAll(); }
}

function jump(x, y) { document.location = "?mode=" + y; }
