function formatcurrency(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return "$" + s;
}

function getElement(element) {
	if (document.getElementById) {
		return document.getElementById(element);
	}	
	else if (document.all) {
		return document.all(element);
	}
	else if (document.layers){
		return document.layers[element];
	}
	else {
		return null;
	}
}

function getDocElement(doc, element) {
	if (doc.getElementById) {
		return doc.getElementById(element);
	}	
	else if (doc.all) {
		return doc.all(element);
	}
	else if (doc.layers){
		return doc.layers[element];
	}
	else {
		return null;
	}
}

function setSpanText(id, text) {
	var spanObj = getElement(id);
	spanObj.innerHTML = text;
}

function borderit(which,color){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
		which.style.borderColor=color;
	}
}

function openwin(htmlFile, win_width, win_height) {
	thewin=open("","NewWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width="+win_width+",height="+win_height);
	thewin.location = htmlFile;
}

function trim ( s ) {
	s = s.replace( /^\s*/, "" );
	s = s.replace( /\s*$/, "" );
	return s;
}

function moredetails(productoptionid) {
	// close any other option more details windows first.
	for(var i = 1; i <= 20; i++) {
		var obj = getElement("optionmoredetails" + i);
		if(obj != null) {
			obj.style.display = 'none';
		}
	}
	var obj = getElement("optionmoredetails" + productoptionid);
	if(obj != null) {
		obj.style.display = '';
	}
}

function moredetailsClose(productoptionid) {
	var obj = getElement("optionmoredetails" + productoptionid);
	if(obj != null) {
		obj.style.display = 'none';
	}
}

function getOptionPrice() {
	var aPostVars = new Array();

	var obj = getElement("productid");
	if(obj != null) {
		aPostVars.push( "productid=" + encodeURI(obj.value) );
	}

	for(var i = 1; i <= 20; i++) {
		var obj = getElement("productoptionvalueid" + i);
		if(obj != null) {
			if(obj.type == 'radio') {
				obj = eval("document.forms[0].productoptionvalueid" + i);
				if(obj != null) {
					for(var j = 0; j < obj.length; j++) {
						if(obj[j].checked) {
							aPostVars.push( "productoptionvalueid=" + encodeURI(obj[j].value) );
						}
					}
				}
			} else {
				aPostVars.push( "productoptionvalueid=" + encodeURI(obj.value) );
			}
		}
	}
	ajaxPOST("ajaxGetOptionPrice.asp", "", "pricebox", aPostVars, true);
}

function addressSetBillingSame(theform, el) {
	var aFields = Array('company','contact','address1','address2','state','city','zip','phone','cell','fax','email');

	if(el.checked) {
		for(i=0; i < aFields.length; i++) {
			var shipelement = 'document.' + theform.name + '.ship' + aFields[i];
			var billelement = 'document.' + theform.name + '.bill' + aFields[i];
			var billobj = eval(billelement);
			var shipobj = eval(shipelement);
			if(billobj != null && shipobj != null) {
				billobj.value = shipobj.value;
			}
		}
	}

}