//<!--
//  ____________________________________________________________ Initialize the global variables
//
var IE_4Plus = 0;			// IE 4+ browser flag
var NS_3Plus = 0;			// Netscape 3+ browser flag
var NS_7Plus = 0;			// Netscape 7+ browser flag
var FancyMode = 0;			// Image rollover capable flag
var OfferCode = "";			// Coupon code that can be remembered per page
var DiscountText = "";		// Used to provide feedback
var DiscountPercent = "";	// Used for calculations
var MaxDiscount = "";		// Used for calculations
var MaxDiscountText = "";	// Used to provide feedback
//
//  ____________________________________________________________ Get the browser and version
//
var BrowserName = navigator.appName.substring(0,7);
if (BrowserName == "Netscap") {
	var browserVer = parseFloat(navigator.appVersion);
	if (browserVer >= 3) { NS_3Plus = 1; }
}
if (BrowserName == "Mozilla") {
	var geckoIndex = navigator.appVersion.indexOf("Gecko",0);
	//var browserVer = parseFloat(navigator.appVersion.substring(versionIndex));
	if (geckoIndex > 0) { NS_7Plus = 1; }
}
if (BrowserName == "Microso") {
	var versionIndex = navigator.appVersion.indexOf("MSIE",0)+5;
	var browserVer = parseFloat(navigator.appVersion.substring(versionIndex));
	if (browserVer >= 4) { IE_4Plus = 1; }
}
if (NS_3Plus || IE_4Plus || NS_7Plus) { FancyMode = 1; }
//
// ____________________________________________________________ View cart submit
//
function ViewCart() {

	// Submit the item
	document.view_cart.business.value = "galatea@resonantenergies.com";
	document.view_cart.submit();
	document.view_cart.business.value = "";
}
//
// ____________________________________________________________ Basic cart submit
//
function Add2Cart(name,qty,price,opn0,ops0,opn1,ops1) {

	// Set the item name
	document.paypal.item_name.value = name;
	
	// Check the quantity
	if (qty != "") {
		document.paypal.quantity.value = qty;
	} else {
		document.paypal.quantity.value = "1";
	}
	// Set the price
	document.paypal.amount.value = price;
	
	// Set the options
	document.paypal.on0.value = opn0;
	document.paypal.os0.value = ops0;
	document.paypal.on1.value = opn1;
	document.paypal.os1.value = ops1;

	// Submit the item
	document.paypal.business.value = "galatea@resonantenergies.com";
	document.paypal.submit();
	document.paypal.business.value = "";
}
//
// ____________________________________________________________ Main cart submit
//
function msAdd2Cart(itemnum,name,avail,qty,rprice,sprice,opn0,ops0,opn1,ops1,shipping) {
//alert(qty);
	if (isNaN(qty)) { qty = "1"; }
	
	// These variables are for doing a numeric comparison instead of string comparison
	// Force the input to integer
	var available = parseInt(avail,10);
	var quantity = parseInt(qty,10);
	
	// Set the item name
	document.paypal.item_name.value = name;
	
	// Deal with backorders
	// Is the item availability specified
	if (avail != "") {
		// We have the availability, so ...
		if (avail == "-1") {
			// The item is unique, so we're done
			document.paypal.quantity.value = "1";
		} else {
			// The item is not unique
			if (quantity > available && avail != "-99") {
				// Set the title to indicate a backorder
				document.paypal.item_name.value = "Backorder: " + name;
			}
			document.paypal.quantity.value = qty;
		}
	} else {
		// We don't have the availability, default to 1
		document.paypal.quantity.value = "1";
	}
	
	// Set the price
	document.paypal.amount.value = sprice;
	
	// Set the options
	document.paypal.on0.value = opn0;
	document.paypal.os0.value = ops0;
	document.paypal.on1.value = opn1;
	document.paypal.os1.value = ops1;
	
	// Set the shipping
	if (shipping == "") {document.paypal.no_shipping.value = "0";}
	if (shipping != "" && shipping == "0") {document.paypal.no_shipping.value = "1";}

	// Submit the item
	document.paypal.business.value = "galatea@resonantenergies.com";
	document.paypal.submit();
	document.paypal.business.value = "";
}
//
//  ____________________________________________________________ Do Nothing
//
function DoNothing() {}
//
//  ____________________________________________________________ Show the highlighted button
//
function ButtonHigh(button,index) {
	if (FancyMode) {
		document.images[index].src = HighImage[button].src;
	}
}
//
//  ____________________________________________________________ Show the normal button
//
function ButtonLow(button,index) {
	if (FancyMode) {
		document.images[index].src = LowImage[button].src;
	}
}
//
//  ____________________________________________________________ Show the clicked button
//
function ButtonClick(button,index) {
	if (FancyMode) {
		document.images[index].src = ClickImage[button].src;
	}
}
//
// ____________________________________________________________ Jump out of frames
//
function IfImInFrames()
{
	if (top.location != self.location) {
		top.location = self.location;
	}
}
//
// ____________________________________________________________ Reload the page
//
function ReCall(thispage)
{
	self.location = thispage;
}
//
// _____________________________________________________________ String cleaners
//
function StripSpace(name)
{
	var regexp = / /;
	while(name.search(regexp) != -1)
	{
		name = name.replace(regexp, "");
	}
	return name;
}
function PlusSpace(name)
{
	var regexp = / /;
	while(name.search(regexp) != -1)
	{
		name = name.replace(regexp, "+");
	}
	return name;
}
function EscapeSpace(name)
{
	var regexp = / /;
	while(name.search(regexp) != -1)
	{
		name = name.replace(regexp, "%20");
	}
	return name;
}
//
// ____________________________________________________________ Foil
//
function Foil(act1,act2,sbj) {
	line = "mai" + "lto%" + "3A";
	line = line + act1 + act2 + "%" + "40";
	line = line + "resonant" + "energies" + "%" + "2E" + "com";
	line = line + "%" + "3F" + "Sub" + "ject" + "%" + "3D" + sbj;
	document.location = unescape(line);
}
//
// ____________________________________________________________ Expand or Contract menus
//
function ExpandCollapse(direction) {
	var NewURL = self.location.toString();
	var Offset = NewURL.indexOf("?");
	var TransChar = "?";
	var Param = "all";
	if (Offset != -1) { TransChar = "&"; }
	if (direction != "+") { Param = ""; }
	self.location = NewURL + TransChar + "exp=" + Param;
}
//
// ____________________________________________________________ Set the theme number
//
function SetTheme(number) {
	var NewURL = self.location.toString();
	var Offset = NewURL.indexOf("&thm=");
	if (Offset = -1) {
		Offset = NewURL.indexOf("?thm=");
		var TransChar = "?";
	} else {
		var TransChar = "&";
	}
	if (Offset != -1) {
		NewURL = NewURL.substr(0,Offset);
	}
	self.location = NewURL + TransChar + "thm=" + number;
}
//
// ____________________________________________________________ Set decimal places
//
function SetDecimal(expr,decplaces)
{
	var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
	while (str.length <= decplaces) {
		str = "0" + str;
	}
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}
//
// ____________________________________________________________ Set decimal places
//
function GoSearch(str)
{
	var regexp = /_/;
	while(str.search(regexp) != -1)
	{
		str = str.replace(regexp, " ");
	}
	self.document.SiteSearch.query.value = str;
	self.document.SiteSearch.submit()
}
//-->

