var isIE = document.all?true:false;
var isNS4 = document.layers?true:false;
var isNS6 = (document.getElementById && !document.all) ? true : false;

function HideLayer(lay) {
	if (isIE) document.all[lay].style.visibility = "hidden";
	else if (isNS4) document.layers[lay].visibility = "hide";
	else if (isNS6) document.getElementById([lay]).style.visibility = "hidden";
}

function ShowLayer(lay) {
	if (isIE) document.all[lay].style.visibility = "visible";
	else if (isNS4) document.layers[lay].visibility = "show";
	else if (isNS6) document.getElementById([lay]).style.visibility = "visible";
}

function WriteLayer(lyr,str) {
	if (isIE) {
		document.all[lyr].innerHTML = str
	}
	if (isNS4) {
		document.layers[lyr].document.open();
		document.layers[lyr].document.write(str);
		document.layers[lyr].document.close();
	}
	if (isNS6) {
		document.getElementById([lyr]).innerHTML = str;
	}
}

function isBlank(s) {
		for (var i=0; i < s.length; i++) {
			c = s.charAt(i);
			if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
		}
		if (s != "") return false;
		return true;
}

function isEmail(s) {
	if (s != null) {
		var pos1 = s.indexOf('@');
		var pos2 = s.indexOf('.');
		invalid_ch = "\/#?!, ";

			for (var i=0;i<s.length;i++) {  // check for invalid chars
			if(invalid_ch.indexOf(s.charAt(i)) != -1) {
				return false;				
			}
		}
		if ((pos1 == -1) || (pos2 == -1) || (s.indexOf('@', pos1+1) != -1)) {
			return false;
		}
		return true;
	}
}

function Strip(str) {
	str = str.replace("__", "");
	str = str.replace("_NUM", "");
	return str;
}

function validate(f) {
	var msg = "";
	var errors = "";
	var emptyFields = "";
	var error1 = -1;

	for (var i=0; i<f.length; i++) {
		var e = f.elements[i];
		if (((e.type == "text") || (e.type == "textarea") || (e.type == "password") || (e.type == "select-one")) && (e.name.indexOf("__") != -1)) {
			if ((e.value == null) || (e.value == "") || isBlank(e.value)) {
				emptyFields += "\n- "+ Strip(e.name);
				if (error1 == -1) {
					error1 = i;
				}
				continue;
			}
		}
		if ((e.name.indexOf("date") != -1) && (!isBlank(e.value))) {
			var fdate = e.value;
			if (!Date.parse(fdate)) {
				errors += "- Please enter a valid "+ Strip(e.name) +"!\n";
				if (error1 == -1) {
					error1 = i;
				}
			}
		}
		if ((e.name.indexOf("email") != -1) && (!isBlank(e.value))) {
			var email = e.value;
			if (!isEmail(email)) {
				errors += "- Invalid email address format.\n";
				if (error1 == -1) {
					error1 = i;
				}
			}
		}
		if ((e.name.indexOf("_NUM") != -1) && (!isBlank(e.value)) && (isNaN(e.value))) {
			errors += "- Non-numeric: " + Strip(e.name) + ".\n";
			if (error1 == -1) {
				error1 = i;
			}
		}
	}
	if (emptyFields) {
		msg += "The following required field(s) is(are) missing: "+ emptyFields + "\n\n";
	}
	if (errors) {
		msg += "Please correct the followng error(s):\n"+errors;
	}
	if ((errors) || (emptyFields)) {
		alert(msg);
		if ((f.elements[error1].type == "text") || (f.elements[error1].type == "textarea")) {
			f.elements[error1].select();
			f.elements[error1].focus();
		}
		else {
			f.elements[error1].focus();
		}
		return false;
	}
	if ((!emptyFields) && (!errors)) return true;
}

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens) {
	/* IN - num:            the number to be formatted
		   decimalNum:     the number of decimals after the digit
		   bolLeadingZero: true / false to use leading zero
		   bolParens:      true / false to use parenthesis for - num
	
	  RETVAL - formatted number
	*/
   var tmpNum = num;

   // Return the right number of decimal places
   tmpNum *= Math.pow(10,decimalNum);
   tmpNum = Math.floor(tmpNum);
   tmpNum /= Math.pow(10,decimalNum);

   var tmpStr = new String(tmpNum);

   // See if we need to hack off a leading zero or not
   if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
	   if (num > 0)
		   tmpStr = tmpStr.substring(1,tmpStr.length);
	   else
		   // Take out the minus sign out (start at 2)
		   tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        


   // See if we need to put parenthesis around the number
   if (bolParens && num < 0)
	   tmpStr = "(" + tmpStr.substring(1,tmpStr.length) + ")";

   return tmpStr;
}

function CommaFormatted(amount) {
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.', 2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
	var nn = n.substr(n.length-3);
	a.unshift(nn);
	n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if (d == undefined) { amount = n + ".00"; }
	
	else { 
	if (d.length < 2) d = d + "0";
	amount = n + '.' + d;
	}
	amount = minus + amount;
	return amount;
}

// -----------------------------

function item(name, name2)
{
if (document.images)
{
this.on = new Image();
this.on.src = name;
this.off = new Image();
this.off.src = name2;
}
}
function itemnew(name, name2, name3)
{
item[name] = new item(name3, name2);
}
function itemon(imgname)
{
if (document.images)
{
document[imgname].src = item[imgname].on.src;
}
}
function itemoff(imgname)
{
if (document.images)
{
document[imgname].src = item[imgname].off.src;
}
}
itemnew("products", "nav/01.gif", "nav/01b.gif");
itemnew("network", "nav/02.gif", "nav/02b.gif");
itemnew("profile", "nav/03.gif", "nav/03b.gif");
itemnew("advantage", "nav/04.gif", "nav/04b.gif");
itemnew("commitment", "nav/05.gif", "nav/05b.gif");
itemnew("contact", "nav/06.gif", "nav/06b.gif");