//-----------------
// Global Variables
//-----------------
var gsProductNo;   //Used to remember the Product Number for its Enlarged Picture to be displayed.

//-----------------
// Functions
//-----------------

/**
 * Add an item to the PayPal shopping cart.
 *
 * Any HTML page that calls this function must define a standard PayPal Add Item To Cart form.  By convention, this form should
 * be named "PayPalAddItem".
 *
 * Parameters:
 * sFormName_ 	- string - the name of the PayPal add item form defined within the calling HTML page.
 * sItemNumber_ - string - the SI part number to be added to the cart.  This number should have all punctuation removed from it.
 *                         For example, part number "240-351" should be passed as "240351".
 */
function paypalAddItemToCart(sFormName_, sItemNumber_)
{
	var oForm;
	var oItem;
	var sItemNo = "_" + sItemNumber_;
	
	// Make sure item is defined within the price table...
	if (typeof(gaPriceTable[sItemNo]) == "undefined")
	{
		alert("WebSite Programming Error - Item Not Found\n\n" + 
				"URL:\t\t" + document.URL + "\n" +
				"Item Number:\t" + sItemNumber_ + "\n\n" +
				"Please Contact Scientific Instruments!");
		return;
	}
	oItem = gaPriceTable[sItemNo];		// Reference the item being added to the cart

	// Make sure the PayPal form is defined
	oForm = document.getElementById(sFormName_);
	if (oForm == null)
	{
		alert("WebSite Programming Error - PayPal Form Error - Form Not Found\n\n" + 
				"URL:\t" + document.URL + "\n\n" +
				"Please Contact Scientific Instruments!");
		return;
	}

	// Make sure that PayPal form contains the necessary form variables...
	if ((typeof(oForm.cmd) == "undefined") ||
		(typeof(oForm.add) == "undefined") ||	
		(typeof(oForm.business) == "undefined") ||	
		(typeof(oForm.no_note) == "undefined") ||	
		(typeof(oForm.lc) == "undefined") ||	
		(typeof(oForm.currency_code) == "undefined") ||	
		(typeof(oForm.item_number) == "undefined") ||	
		(typeof(oForm.item_name) == "undefined") ||	
		(typeof(oForm.amount) == "undefined"))
	{
		alert("WebSite Programming Error - PayPal Form Error - Missing Fields\n\n" + 
				"URL:\t" + document.URL + "\n\n" +
				"Please Contact Scientific Instruments!");
		return;
	}		
	
	// Set the item to be added within the form, and submit the form...
	oForm.item_number.value = oItem[0];
	oForm.item_name.value = oItem[1];
	oForm.amount.value = oItem[2];
	oForm.submit();
}

/*
 * Creates the Print Preview Window.
 *
 * Parameters:
 * None
 */
function launchPrintPreviewWindow()
{
	var oNewWindow;	

	// Creates actual print preview window.
	oNewWindow = window.open("PrintPreviewTemplate.htm", "PrintPreview_Win", "width=800, height=600 scrollbars=1");
}

/*
 * Initializes the contents of the Print Preview Window.
 * !!!Pulls!!! contents onto the Print Preview Window.
 *
 * Parameters:
 * None
 */
function initPrintPreviewWindow()
{
	var oMainWindow;
	var oMainWindowDiv;
	var oPrintPreviewWindowDiv;
	var sContent;
	
	oMainWindow = window.opener;
	// Checks if the previous window that opened the Print Preview Window exists.
	// Decides what the contents should be and where to get them from.
	if (oMainWindow == null)
	{
		window.document.title = "Print Preview Window";
		sContent = '<br>...Main Document Content Displayed Here...<br>';
	}
	else
	{
		window.document.title = oMainWindow.document.title;
		oMainWindowDiv = oMainWindow.document.getElementById('contentDiv');
		sContent = oMainWindowDiv.innerHTML;
	}
	
	// Puts the contents on the Print Preview Page
	oPrintPreviewWindowDiv = window.document.getElementById('contentDiv');
	oPrintPreviewWindowDiv.innerHTML = sContent;
	
	// Checks if the window that the Print Print Preview Window exists.
	// Decides whether to delete the links after the first horizontal line.
	if (oMainWindow != null)
	{
		oPrintPreviewWindowDiv = window.document.getElementById('navTrail');
		oPrintPreviewWindowDiv.innerHTML = '';
	}
	
	window.focus();
}

/*
 * Creates the EnlargedViewWindow.
 *
 * Parameters:
 * String sProductNumber - contains a string that is the product number of an SII product.
 */
function launchEnlargedViewWindow(sProductNumber)
{
	var oNewWindow;
	gsProductNo = '_' + sProductNumber;  // Puts the number in its correct form.
	
	// Make sure product is defined within the picture table...
	if (typeof(gaPictureTable[gsProductNo]) == "undefined")
	{
		alert("WebSite Programming Error - Picture Not Found\n\n" + 
				"URL:\t\t" + document.URL + "\n" +
				"Product Number:\t" + gsProductNo + "\n\n" +
				"Please Contact Scientific Instruments!");
		return;
	}

	// Creates actual Enlarged View Window.
	oNewWindow = window.open("EnlargedViewTemplate.htm", "EnlargedView", "width=800, height=600 scrollbars=0");
}

/*
 * Initializes the contents of the Enlarged View Window.
 * !!!Pulls!!! contents onto the Enlarged View Window.
 *
 * Parameters:
 * None
 */
function initEnlargedViewWindow()
{
	var oMainWindow;
	var oPrintPreviewWindowDiv;
	var oProduct;
	var sPictureSrc;
	var sContent;
	
	oMainWindow = window.opener;
	
	// Checks if the previous window that opened the Enlarged View Window exists.
	// Decides what the contents should be and where to get them from.
	if (oMainWindow == null)
	{
		window.document.title = "Enlarged View Window";
		sContent = '<br>...Enlarged Picture Displayed Here...<br>';
	}
	else
	{
		// Make sure item is defined within the price table...
		if (typeof(gaPictureTable[oMainWindow.gsProductNo]) == "undefined")
		{
			alert("WebSite Programming Error - Picture Not Found\n\n" + 
					"URL:\t\t" + document.URL + "\n" +
					"Product Number:\t" + oMainWindow.gsProductNo + "\n\n" +
					"Please Contact Scientific Instruments!");
			return;
		}
		
		oProduct = gaPictureTable[oMainWindow.gsProductNo];  // Reference to the product being enlarged.
		window.document.title = oProduct[1];  // Sets the Title based on the product information.
		sPictureSrc = oProduct[0];  // Sets the source of the picture based on the product information.
		sContent = '<img src="' + sPictureSrc + '" border="0">'; //All images are made to 517-height
	}
	
	// Puts the contents on the Enlarged View Window Page
	oPrintPreviewWindowDiv = window.document.getElementById('contentDiv');
	oPrintPreviewWindowDiv.innerHTML = sContent;
	
	window.focus();
}