//<!--
//  ____________________________________________________________ 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) {

	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()
}
//
// ____________________________________________________________ Div Popup Functions
//
function showPopup(width,height,file){

	// Ajax load the content
	ajax_loadContent('PopupContent','library/help/' + file + '_inc.htm');
	ajax_loadContent('PopupHeader','library/help/' + file + '_header_inc.htm');
	
	var hdrHeight = 30; // Total height of the header bar
	var shdwOffset = 12; // Pixel offsset for the shadow div
	var padCompensation = 10; // This is set to twice the margin in the div css block
	
	var winHeight = winSize('height'); // Get the inner window height
	if (winHeight < height) {
		if (winHeight < 1) {
			winHeight = height + hdrHeight + 200; // Compensate for no window size return
		} else {
			height = winHeight - 60; // Compensate for really small windows
		}
	}
	var winWidth = winSize('width'); // Get the inner window width
	if (winWidth < width) {
		if (winWidth < 1) {
			winWidth = width + 200; // Compensate for no window size return
		} else {
			width = winWidth - 60; // Compensate for really small windows
		}
	}
	 
	var Header = document.getElementById("PopupHeader"); // Get the handle for the header bar div
	var popUp = document.getElementById("PopupContent"); // Get the handle for the content div
	var Shadow = document.getElementById("PopupShadow"); // Get the handle for the shadow div
	Header.style.top = (((winHeight - height)/2) - hdrHeight) + "px"; // Calculate the top offset
	
	Header.style.left = (winWidth - width)/2 + "px"; // Calculate the left offset
	Header.style.width = (width + padCompensation) + "px"; // Set the header bar width
	Header.style.height = hdrHeight + "px"; // Set the header bar height
	
	popUp.style.top = ((winHeight - height)/2) + "px"; // Calculate the vertical offset
	popUp.style.left = (winWidth - width)/2 + "px"; // Calculate the left offset
	popUp.style.width = width + "px"; // Set the content width
	popUp.style.height = height + "px"; // Set the content height
	
	Shadow.style.top = ((((winHeight - height)/2) - hdrHeight) + shdwOffset) + "px"; // Calculate the vertical offset
	Shadow.style.left = ((winWidth - width)/2) + shdwOffset + "px"; // Calculate the left offset
	Shadow.style.width = (width + padCompensation) + "px"; // Set the shadow width
	Shadow.style.height = height + hdrHeight + padCompensation + "px"; // Set the shadow height
	
	// Turn on the divs
	Header.style.visibility = "visible";
	popUp.style.visibility = "visible";
	Shadow.style.visibility = "visible";
}

function showPopupV(width,height,left_pos,top_pos,file){

	// Ajax load the content
	ajax_loadContent('PopupContent','library/help/' + file + '_inc.htm');
	ajax_loadContent('PopupHeader','library/help/' + file + '_header_inc.htm');
	
	var hdrHeight = 30; // Total height of the header bar
	var shdwOffset = 12; // Pixel offsset for the shadow div
	var padCompensation = 10; // This is set to twice the margin in the div css block
	
	var winHeight = winSize('height'); // Get the inner window height
	if (winHeight < height) {
		if (winHeight < 1) {
			winHeight = height + hdrHeight + 200; // Compensate for no window size return
		} else {
			height = winHeight - 60; // Compensate for really small windows
		}
	}
	var winWidth = winSize('width'); // Get the inner window width
	if (winWidth < width) {
		if (winWidth < 1) {
			winWidth = width + 200; // Compensate for no window size return
		} else {
			width = winWidth - 60; // Compensate for really small windows
		}
	}
	 
	var Header = document.getElementById("PopupHeader"); // Get the handle for the header bar div
	var popUp = document.getElementById("PopupContent"); // Get the handle for the content div
	var Shadow = document.getElementById("PopupShadow"); // Get the handle for the shadow div
	var left = "";
	var top = "";
	
	if (left_pos == "center" || left_pos == "") {
		left = (winWidth - width)/2;
	} else if (left_pos == "left") {
		left = 187;
	} else if (left_pos == "right") {
		left = winWidth - width - shdwOffset - 173;
	} else {
		left = left_pos;
	}
	
	Header.style.top = (((winHeight - height)/2) - hdrHeight) + "px"; // Calculate the top offset
	Header.style.left = left + "px"; // Calculate the left offset
	Header.style.width = (width + padCompensation) + "px"; // Set the header bar width
	Header.style.height = hdrHeight + "px"; // Set the header bar height
	
	popUp.style.top = ((winHeight - height)/2) + "px"; // Calculate the vertical offset
	popUp.style.left = left + "px"; // Set the left offset
	popUp.style.width = width + "px"; // Set the content width
	popUp.style.height = height + "px"; // Set the content height
	
	Shadow.style.top = ((((winHeight - height)/2) - hdrHeight) + shdwOffset) + "px"; // Calculate the vertical offset
	Shadow.style.left = left + shdwOffset + "px"; // Calculate the left offset
	Shadow.style.width = (width + padCompensation) + "px"; // Set the shadow width
	Shadow.style.height = height + hdrHeight + padCompensation + "px"; // Set the shadow height
	
	// Turn on the divs
	Header.style.visibility = "visible";
	popUp.style.visibility = "visible";
	Shadow.style.visibility = "visible";
}

function hidePopup(){

	var Header = document.getElementById("PopupHeader"); // Get the handle for the header bar div
	var popUp = document.getElementById("PopupContent"); // Get the handle for the content div
	var Shadow = document.getElementById("PopupShadow"); // Get the handle for the shadow div
	
	// Clear the divs
	Header.innerHTML = "&#160;";
	popUp.innerHTML = "&#160;";
	
	// Turn off the divs
	Header.style.visibility = "hidden";
	popUp.style.visibility = "hidden";
	Shadow.style.visibility = "hidden";
}

function winSize(direction) {

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if (direction == "width") {
  		return myWidth;
	} else {
  		return myHeight;
	}
}

//-->
