//======================================================================
//
//	newdogcode.js
//
//	- written by Jerry Auld, Otago Computing Inc.
//  	- November 30, 2004
//	
//	- from code imported from old site's NDGlobals.js
//
//	Revision History:
//	- 2004-11-30 -- Initial code transfer. (JA-OCI)
//    - 2005-01-18 -- When removing a selected area, jump to add/remove dialog.
//	- 2005-01-26 -- Provide a cancel path backwards in pop-up flow.
//	- 2005-02-17 -- Add in search pages and code from old search site.
//	- 2005-05-11 -- Add new globals to support local JS database files.
// 	- 2006-06-20 -- Add CD ROM variable.
//	- 2007-06-06 -- Add new substreams to AskPassword. (Bag, Vest, Pants)
//	- 2008-05-26 -- Remove GST from pricing grid calculations.
//
//----------------------------------------------------------------------


//--- Global Variables -------------------------------------------------

    var currProd = 'San2000'; //'0';
    var globalIndex = 386; // -1;
    var prodType = '';
    var ginitialCategory = "New Products";  // Set this to the Web Category in the DB to determine which category display when the site is opened.
    var gCurrentCategory = '';
    var gCurrentDBCategory = ''; // (JA-OCI -- 2005-02-17)

    var NDPassword = 'jeep11';
    var NDPasswordC = 'jeep11';
    var NDPasswordG = false;
    var NDPasswordO = '';
    var isAgent = false;
    var isFlash = false;
    var isCDROM = false;

    var NDAgentName = 'Bernie Kokott';
    var NDAgentPhone = '(403) 275-2336';
    var NDAgentEmail = 'bernie@new-dog.com';

    // Featured Category variables:
    //  These variables are enacted at first redition of the website page:
    //  Change these by changing the "initialCategory" variable above.
    var gFeaturedGraphic = "MensTShirts";
    var gFeaturedTitle = "";
    var gFeaturedDesc = "";

    // Featured Category variables:
    //  These variables are enacted on each subsequent redition of the website page:
    //  Change these by changing the "CurrentCategory" variable above.
    var gCurrentGraphic = "";
    var gCurrentTitle = "";
    var gCurrentDesc = "";

    // These vars are for Silkscreen and Embroidery pricing
    var Colour = 'N/A';
    var Price = 0;
    var Areas = [['',0,0]];
    var SmallAmt = 0;
    var MedAmt = 0;
    var LargeAmt = 0;
    var XLAmt = 0;
    var XXLAmt = 0;
    var XXXLAmt = 0;
    var SmallCost = 0;
    var MedCost = 0;
    var LargeCost = 0;
    var XLCost = 0;
    var XXLCost = 0;
    var XXXLCost = 0;
    var SmallUnit = 0;
    var MedUnit = 0;
    var LargeUnit = 0;
    var XLUnit = 0;
    var XXLUnit = 0;
    var XXXLUnit = 0;
    var totalUnit = 0;
    var totalCost = 0;
    var totalAmt = 0;
    var infostr = '';
    var areasstr = '';
    var XXLbase = 0;
    var XXXLbase = 0;
    var usRate = 0.9;  //US Exchange Rate
    var USA = false;

    // These vars are for Specialty pricing:
    var SpecClrs = 1;
    var SpecClrs2 = 1;
    var SpecLoc2 = false;
    var imprintInfo = '';

    // These variables are used for the custom dialogs: (JA-OCI 17-Aug-04)
    var gsOtagoConfirm = '';
    var gsOtagoQuestion = '';
    var gfOtagoConfirm = false;
    var gsOtagoResume = '';
    var gsOtagoCancel = '';   // Added to be able to jump back when a pop-up is cancelled. (JA-OCI 2005-Jan-26)
    var gsOtagoInput = '';
    var gfOtagoInput = false;
    var gsOtagoDefault = '';
    var giOtagoInputSize = 25;
    var giOtagoPosition = 0;
    var gfShowQuantities = false;
    var gsOtagoSelect = '';
    var gfOtagoSelect = false;
    var gaOtagoSelections = ['1','2','3','4','5','6','7','8'];

    // These are preset arrays for use in the streams popup selections: (JA-OCI 2004-Sep-30)
    var gaNewdogNumColours = ['1','2','3','4','5','6','7','8'];
    var gaNewdogNumStitches = ['Small (1000 - 8000 stitches)','Medium (8000 - 18000 stitches)','Large (18000 - 45000 stitches)'];

    // These variables are for the printable InfoForm: (JA-OCI 2004-Sep-27)
    var gsIFSalesperson = 'None';
    var gsIFClientName = 'None';
    var gsIFClientEmail = 'None';
    var gsIFClientCompany = 'None';
    var gsIFClientCity = 'None';
    var gsIFOtherInfo = 'None';
    
    // These variables are for filtering the search results from the PriceRange search:
    var gfFilterPriceRange = false;
    var gfFilterGarments = false;
    var gfFilterSpecialty = false;
    var gfFilterAll = true;

    // These variables are for the old search pages added in (JA-OCI -- 2005-02-17)
    var strCategory = '';
    var strPrice = '';
    var selectedProduct = '';
    var selectedSupplier = '';
    var strProduct = '';
    var strSupplier = '';
    var gfCategory = true;
    var gfPriceRange = false;
    var gfProduct = false;
    var gfDBCategory = false;	// (JA-OCI -- 2005-03-23)


    // These globals control the selected area graphics on the Art Selection pages: 
    // Ja-OCI -- 2005-04-02
    var gfAreaSelected = false;
    var gsAreaToCancel = '';
    var gsAreaRolloverToReplace = '';
    var gsAreaRolloverToCancel = '';

    // These globals added to support local JS datafiles to enhance site speed.
    var gsBlankPrice = '';
    var gsDescription = '';
    var gsImprintInfo = '';
    var gfCaps = false;
    var gfJackets = false;
    var gfGarment = false;
    var giMinQty = 24;
    var gsSupplier = '';
    var gsCatalogPage = '';
    var gsClrMapPath = '';
    var gfSpecOneArea = false;
    var gsFullName = '';
    var gsSizes = '';
    var gsAvailColours = '';
    var gsStream = '';
		
	//This is so the site knows whether it's the first runthrough or not - MR
	var runThru = false;

//--- Reset All SilkScreen and Embroidery Variables --------------------

    function ResetVars() {
		// alert("Starting to reset all silkscreen, embroidery, and specialty variables.");
		Price = 0;
		Areas = [['',0,0]];
		SmallAmt = 0;
    	MedAmt = 0;
    	LargeAmt = 0;
    	XLAmt = 0;
    	XXLAmt = 0;
		XXXLAmt = 0;
		SmallCost = 0;
    	MedCost = 0;
    	LargeCost = 0;
    	XLCost = 0;
    	XXLCost = 0;
		XXXLCost = 0;
		SmallUnit = 0;
    	MedUnit = 0;
    	LargeUnit = 0;
    	XLUnit = 0;
    	XXLUnit = 0;
    	XXXLUnit = 0;
		totalUnit = 0;
    	totalCost = 0;
    	totalAmt = 0;
    	XXLbase = 0;
    	XXXLbase = 0;
		USA = false;
		areastr = '';
		SpecClrs = 1;
		imprintInfo = '';
		gsBlankPrice = '';
		gsDescription = '';
		gsImprintInfo = '';
		gfCaps = false;
		gfJackets = false;
		gfGarment = false;
		giMinQty = 24;
		gsSupplier = '';
		gsCatalogPage = '';
		gsClrMapPath = '';
		gfSpecOneArea = false;
		gsOtagoConfirm = '';
		gsOtagoQuestion = '';
		gfOtagoConfirm = false;
		gsOtagoResume = '';
		gsOtagoCancel = '';
		gsOtagoInput = '';
		gfOtagoInput = false;
		gsOtagoDefault = '';
		giOtagoInputSize = 25;
		giOtagoPosition = 0;
		gfShowQuantities = false;
		gsOtagoSelect = '';
		gfOtagoSelect = false;
		gsIFSalesperson = 'None';
		gsIFClientName = 'None';
		gsIFClientPhone = 'None';
		gsIFClientCompany = 'None';
		gsIFClientCity = 'None';
		gsIFOtherInfo = 'None';
		gfFilterPriceRange = false;
		gfFilterGarments = false;
		gfFilterSpecialty = false;
		gfFilterAll = true;
		strCategory = '';
		strPrice = '';
		selectedProduct = '';
		selectedSupplier = '';
		strProduct = '';
		strSupplier = '';
		gfCategory = true;
		gfPriceRange = false;
		gfProduct = false;
		gfDBCategory = false;
		gfAreaSelected = false;
		gsAreaToCancel = '';
		gsAreaRolloverToReplace = '';
		gsAreaRolloverToCancel = '';
		gsFullName = '';
		gsSizes = '';	
		gsStream = '';
		// alert('Reseting all silkscreen, embroidery, and specialty variables.');
    }

//---------------------------------------------------------------------
//
//	setFeaturedGlobals
//
//	-- JA-OCI -- 2004-12-04
//	-- Set the initial variabls needed to display the webpage based on the ginitialCategory variable:
//
//---------------------------------------------------------------------


    function setFeaturedGlobals() {

		// Set the initial webpage view based on the global setting:
		for (var i = 0; i < ndWebCategories.length; i++) {
			if (ndWebCategories[i][0] == ginitialCategory) {

			// [0] = the Category to match to the preset global and show as the title bar on the page.
			// [1] = the Category Type - currenty not used. (JA-OCI -- 2004.12.04)
			// [2] = the path to the category graphic.
			// [3] = the URL link text.
			// [4] = the Category Description.

			// Set the variables:
			gFeaturedGraphic = ndWebCategories[i][2];
			gFeaturedTitle = ndWebCategories[i][3];
			gFeaturedDesc = ndWebCategories[i][4];
			
			}
		}

		// Error check: resolve nulls to the default:
		if(gFeaturedGraphic == "") { gFeaturedGraphic = "images/category/MensTShirts.jpg"; }
		if(gFeaturedTitle == "") { gFeaturedTitle = "T-Shirts - Men's"; }
		if(gFeaturedDesc == "") { gFeaturedDesc = "A Fantastic NewDog Product!"; }

    }

//---------------------------------------------------------------------
//
//	setCurrentGlobals
//
//	-- JA-OCI -- 2004-12-07
//	-- Set the variables needed to display the webpage based on the gCurrentCategory variable:
//
//---------------------------------------------------------------------


    function setCurrentGlobals() {

		// Set the current webpage view based on the global setting:
		for (var i = 0; i < ndWebCategories.length; i++) {
			if (ndWebCategories[i][0] == gCurrentCategory) {

			// [0] = the Category to match to the preset global and show as the title bar on the page.
			// [1] = the Category Type - currenty not used. (JA-OCI -- 2004.12.04)
			// [2] = the path to the category graphic.
			// [3] = the URL link text.
			// [4] = the Category Description.

			// Set the variables:
			gCurrentGraphic = ndWebCategories[i][2];
			gCurrentTitle = ndWebCategories[i][3];
			gCurrentDesc = ndWebCategories[i][4];
			
			}
		}

		// Error check: resolve nulls to the default:
		if(gCurrentGraphic == "") { gCurrentGraphic = "images/tshirts-mens.jpg"; }
		if(gCurrentTitle == "") { gCurrentTitle = "T-Shirts - Men's"; }
		if(gCurrentDesc == "") { gCurrentDesc = "A Fantastic NewDog Product!"; }

    }


//---------------------------------------------------------------------
//
//	askPassword
//
//	-- JA-OCI -- 2004-12-07
//	-- Check credentials to allow passage into the streams:
//
//---------------------------------------------------------------------

    function askPassword() {

		// skip entire thing if user has been through once this session already or if product is blank - MR
		if (runThru == true) {
			NDPasswordG = true;
		} else if (prodType == 'Blank') {
			NDPasswordG = true;
		} else {	
			// Ask for a password or deny entry via pop-up window.
			var loginType = GetCookie('ndlogin');
			if(loginType == null) {
				// NDPasswordO = ''; // They have never logged in or have cookies turned off.
				// 2005-08-06 - JA-OCI: Allow the user first of two free passes before asking passwords:
				NDPasswordG = true;
				runThru = true;
				top.SetCookie('ndlogin','1',top.expiry);
				alert('Our Estimator is one of the tools we\'ve created for our Clients.  It requires a Login ID and Password supplied by Newdog.  For non-Clients we offer five Estimate opportunities for you to see what Newdog could do for you.');
			} else if(loginType == '1') {
				// 2005-08-06 - JA-OCI: Allow the user second free pass before asking passwords:
				NDPasswordG = true;
				runThru = true;
				top.SetCookie('ndlogin','2',top.expiry);
				alert('Our Estimator is one of the tools we\'ve created for our Clients.  It requires a Login ID and Password supplied by Newdog.  For non-Clients we offer five Estimate opportunities for you to see what Newdog could do for you.');
			} else if(loginType == '2') {
				// 2005-08-06 - JA-OCI: Allow the user second free pass before asking passwords:
				NDPasswordG = true;
				runThru = true;
				top.SetCookie('ndlogin','3',top.expiry);
				alert('Our Estimator is one of the tools we\'ve created for our Clients.  It requires a Login ID and Password supplied by Newdog.  For non-Clients we offer five Estimate opportunities for you to see what Newdog could do for you.');
					} else if(loginType == '3') {
				// 2005-08-06 - JA-OCI: Allow the user second free pass before asking passwords:
				NDPasswordG = true;
				runThru = true;
				top.SetCookie('ndlogin','4',top.expiry);
				alert('Our Estimator is one of the tools we\'ve created for our Clients.  It requires a Login ID and Password supplied by Newdog.  For non-Clients we offer five Estimate opportunities for you to see what Newdog could do for you.');
					} else if(loginType == '4') {
				// 2005-08-06 - JA-OCI: Allow the user second free pass before asking passwords:
				NDPasswordG = true;
				runThru = true;
				top.SetCookie('ndlogin','5',top.expiry);
				alert('Our Estimator is one of the tools we\'ve created for our Clients.  It requires a Login ID and Password supplied by Newdog.  For non-Clients we offer five Estimate opportunities for you to see what Newdog could do for you.');
			} else if(loginType == '5') {
				NDPasswordG = false; // They've had their two free-passes and must now authenticate.
			} else if(loginType == NDPassword) {
				// The cookie contains the agent password
				isAgent = true;
				runThru = true;
				NDPasswordG = true;
			} else {
			//A password exists but is not 1, 2, or the agent password - validate against database
				// for (var i = 0 ; i < ndAccounts.length; i++) {
				// 	if(ndAccounts[i][3] == loginType) {
						NDPasswordG = true;
						runThru = true;
				// 		i = ndAccounts.length;
				// 	}
				// }
			}
		}

		if (NDPasswordG == true) {
			// Go down the pricing stream based on prodType and the substream by gsStream.
			switch (prodType) {
				case "Silkscreened":
				   // alert("You are entering the Silkscreen pricing scheme.");
				   // Jump to the art selection page:
				   if(gsStream == 'Jacket') {  // gfJackets
					 if(isAgent == true) {
						// NavBar.location.replace("menu_wo.html");
						MainFrame.location.replace("agentfile/SilkscreenPricing/jacketart.php");
						 } else {
						// NavBar.location.replace("menu_wo.html");
						MainFrame.location.replace("clientfile/SilkscreenPricing/jacketart.php");
						}
				   } else {
					  if(gsStream == 'Vest') {
						if(isAgent == true) {
						// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("agentfile/SilkscreenPricing/vestart.php");
						} else {
							// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("clientfile/SilkscreenPricing/vestart.php");
						}
					} else if(gsStream == 'Bag') {
						if(isAgent == true) {
							// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("agentfile/SilkscreenPricing/bagart.php");
						} else {
							// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("clientfile/SilkscreenPricing/bagart.php");
						}
					} else {
						if(isAgent == true) {
							// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("agentfile/SilkscreenPricing/silkart.php");
						} else {
							// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("clientfile/SilkscreenPricing/silkart.php");
						}
					}
				   }
				   break;
				case "Embroidered":
					//alert("You are entering the Embroidery pricing scheme.");
					// Jump to the art selection page:
					if(gsStream == "Cap") {  // gfCaps
						if(isAgent == true) {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("agentfile/EmbroideryPricing/capart.php"); // CapArtSelection.html");
						} else {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("clientfile/EmbroideryPricing/capart.php"); // CapArtSelection.html");
						}
					} else if(gsStream == 'Jacket') {  // gfJackets
						if(isAgent == true) {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("agentfile/EmbroideryPricing/jacketart.php");
						} else {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("clientfile/EmbroideryPricing/jacketart.php");
						}
					} else if(gsStream == "Garment") { // gfGarment
						if(isAgent == true) {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("agentfile/EmbroideryPricing/embart.php");
						} else {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("clientfile/EmbroideryPricing/embart.php"); // EmbArtSelection.html");
						   // MainFrame.location.replace("clientfile/EmbroideryPricing/test.php");
						}
					} else if(gsStream == 'Pants') {
						if(isAgent == true) {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("agentfile/EmbroideryPricing/pantart.php");
						} else {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("clientfile/EmbroideryPricing/pantart.php"); // EmbArtSelection.html");
						   // MainFrame.location.replace("clientfile/EmbroideryPricing/test.php");
						}
					} else 	if(gsStream == 'Vest') {
						if(isAgent == true) {
							// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("agentfile/EmbroideryPricing/vestart.php");
						} else {
							// NavBar.location.replace("menu_wo.html");
							MainFrame.location.replace("clientfile/EmbroideryPricing/vestart.php");
						}
					} else if(gsStream == 'Bag') {
						if(isAgent == true) {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("agentfile/EmbroideryPricing/bagart.php");
						} else {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("clientfile/EmbroideryPricing/bagart.php"); // EmbArtSelection.html");
						   // MainFrame.location.replace("clientfile/EmbroideryPricing/test.php");
						}
					} else {
						// JA-OCI -- 2005-03-12 -- Go direct to Embroidery Quantities after pre-setting Location 1.
						// JA-OCI -- 2005-03-17 -- Bug in IE. Massage code.
						// Areas = [['LOCATION 1',1000]];  - Do This in EmbroideryQuantities
						if(isAgent == true) {
							   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("agentfile/EmbroideryPricing/nonart.php");
						} else {
						   // NavBar.location.replace("menu_wo.html");
						   MainFrame.location.replace("clientfile/EmbroideryPricing/nonart.php");
						}	
					}
					break;
				case "Specialty":
				   //alert("You are entering the Specialty pricing scheme.");
				   // Jump to the quantity selection page:
				   if(isAgent == true) {
					// NavBar.location.replace("menu_wo.html");
					MainFrame.location.replace("agentfile/SpecialtyPricing/SpecQuantities.php");
				   } else {
					// NavBar.location.replace("menu_wo.html");
					MainFrame.location.replace("clientfile/SpecialtyPricing/SpecQuantities.php");
					// MainFrame.location.replace("clientfile/SpecialtyPricing/test.php");
				   }
				   break;
				case "Blank":
				   //alert("You are entering the Blank pricing scheme for all streams.");
				   // Jump to the quantity selection page:
				   if(isAgent == true) {
					MainFrame.location.replace("agentfile/BlankPricing/BlankQuantities.php");
				   } else {
					MainFrame.location.replace("clientfile/BlankPricing/BlankQuantities.php");
				   }
				   break;
				default:
				   alert("You can not enter a pricing scheme as the product has not been categorized as Silkscreen, Embroidery, or Specialty.");
				   // Return to the main page:
				   // NavBar.location.replace("menu_wo.html");
				   MainFrame.location.replace("index.html");
				   // document.history.go(-1);
				   break;
			}
		} else {
		   var win = window.open("NDPassword.html","NDPasswordWin","width=250,height=100,screenX=350,screenY=300,top=250,left=350");
		   win.focus();
		}
    }


//--- Parse Argunments from URL Search section -------------------------

    // This function parses comma-separated name=value argument pairs from
    // the query string of the URL. It stores the name=value pairs in 
    // properties of an object and returns that object.

    function getArgs() {
    	var args = new Object();
    	var query = location.search.substring(1);  	// Get query string.
    	var pairs = query.split(",");              	// Break at comma.
	// alert(pairs.length + " args found in " + query);
    	for(var i = 0; i < pairs.length; i++) {
	    var pos = pairs[i].indexOf('=');       	// Look for "name=value".
	    if (pos == -1) continue;               	// If not found, skip.
	    var argname = pairs[i].substring(0,pos);  	// Extract the name.
	    var value = pairs[i].substring(pos+1); 	// Extract the value.
	    args[argname] = unescape(value);          	// Store as a property.
    	}
    	return args;                               	// Return the object.
    }


//-----------------------------------------------------------------------------------------

    function getStyleName() {
	return top.currProd;
    }

//-----------------------------------------------------------------------------------------

    function getDescription() {
	return top.gsDescription;
    }

//-----------------------------------------------------------------------------------------

    function doNothing() {
	// This is an empty routine to close a popup on a cancel butten, etc.
    }

	
//=================================================================
//
//	SILKSCREEN PRICING STREAM
//
//=================================================================

//-------------- List the Areas Selected -----------------------------------------------


    function setArea(areaName) {
	
	// Set the area. If already set, remove.
	//   - Rewrote this routine (JA-OCI 17-Aug-04) To allow for custom prompts and input dialogs.
	//   - (JA-OCI 2005-01-17) If an area is selected that is already selected,
      //     remove it and go straight to add/remove dialog.
	//   - (JA-OCI 2005-01-26) Return to previous popup if cancel is clicked.
      //   - (JA-OCI 2005-04-02) Add global flags to control Area Selection rollovers.

	var i = 0;
	var outString = '';
	var found = false;
	var conflict = false;
	var placed = false;
	var colours = 0;

	top.gfscOnEdit = false;
	gfAreaSelected = false;  // Ensure no area selection rollover occurs to highlight an area unless it is safely selected.

	// Test to ensure ULC/URC and Full front are not both selected:
	if(areaName == 'Full Front') {
	    // Check for existing ULC or URC.
	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] == 'Upper Left Chest') {
		    alert('You can not select Full Front because you have already selected Upper Left Chest. ' + 
			  'If you want Full Front you must first click on ULC to deselect it.');
		    conflict = true;
		    break;
		}
		if(Areas[i][0] == 'Upper Right Chest') {
		    alert('You can not select Full Front because you have already selected Upper Right Chest. ' + 
			  'If you want Full Front you must first click on URC to deselect it.');
		    conflict = true;
		    break;
		}
	    }
	}
	if(conflict) return;
	if(areaName == 'Upper Left Chest') {
	    // Check for existing Full Front.
	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] == 'Full Front') {
		    alert('You can not select Upper Left Chest because you have already selected Full Front. ' + 
			  'If you want ULC you must first click Full Front to deselect it.');
		    conflict = true;
		    break;
		}
	    }
	}
	if(conflict) return;
	if(areaName == 'Upper Right Chest') {
	    // Check for existing Full Front.
	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] == 'Full Front') {
		    alert('You can not select Upper Right Chest because you have already selected Full Front. ' + 
			  'If you want URC you must first click Full Front to deselect it.');
		    conflict = true;
		    break;
		}
	    }
	}
	if(conflict) return;
	gfAreaSelected = true;  // Okay, rollover the area to be highlighted.


	// If this area already exists, then delete it and jump to the add/remove dialog window:
	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] == areaName) {
		Areas[i][0] = '';
		Areas[i][1] = 0;
		found = true;
	    }
	}

	// Tighten up the array:
	if(found) { // Remove the area.
	    for(i = 0; i < Areas.length; i++) {
		if(Areas[i][0] == '') {
		    if(i != (Areas.length - 1)) {
		    	Areas[i][0] = Areas[i+1][0];
		    	Areas[i][1] = Areas[i+1][1];
		    	Areas[i+1][0] = '';
		    	Areas[i+1][1] = 0;
		    }
		}
	    }
	    Areas.length = Areas.length - 1;
	    if(Areas.length == 0) {
		Areas = [['',0]];
		alert('You have deleted all your locations. Please select at least one.');
		return; // The user must select a location.
	    }

	    var outString = '';

	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] != '') {
	    	   outString = outString + Areas[i][0] + ", ";
	    	}
	    }

	    gsOtagoConfirm = outString;
	    gsOtagoResume = jumpToSilkscreenQuantities;
          gsOtagoCancel = doNothing; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-26)
	    var winOCPU2 = window.open("OtagoAddRemove.html","","width=400,height=220,screenX=300,screenY=300,top=300,left=300");
	    winOCPU2.focus();

	    return; // My work here is done.
	}


	// Add the selected area:
	if(!found) {
	    // Add the area to the first blank or, failing that, at the end of the list.
	    for(i = 0; i < Areas.length; i++) {
	      if(Areas[i][0] == '') {
		    Areas[i][0] = areaName;
		    giOtagoPosition = i; // Remember the i position to enter the colours in after prompting for them.
		    placed = true;
	    	}
		if(placed) break;
	    }
	    if(!placed) {
		Areas[Areas.length] = new Array(3);
		Areas[Areas.length-1][0] = areaName;
		giOtagoPosition = Areas.length-1; // Remember the new position to enter the colours in after prompting for them.
	    }
	}

   	// Now prompt for the number of colours:
	gsOtagoQuestion = "Select the number of colours to be printed at this location:<br><br>There is a maximum of 8 colours.";
	gsOtagoDefault = '1';
	gsOtagoSelect = '';
	gfOtagoSelect = false;
	gaOtagoSelections = gaNewdogNumColours;
	gsOtagoResume = handleColourPrompt;
      gsOtagoCancel = cancelSelection; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-26)
	var winOCPU = window.open("OtagoSelect.html","PopOtagoSelectWin","width=400,height=150,screenX=300,screenY=300,top=300,left=300");
	winOCPU.focus();

    }

//-------------- Cancel out of the Area Selection and ensure that the image rollover is reversed ---

    function cancelSelection() {

	// Delete the last area selected:
	if(Areas.length > 1) {
	   Areas[Areas.length - 1][0] = '';
	   Areas[Areas.length - 1][1] = 0;
	   Areas.length = Areas.length - 1;
	} else {
	   Areas = [['',0]];
	}

	// Reverse the selection:
	MainFrame.changeSrc(gsAreaToCancel,gsAreaRolloverToReplace,gsAreaRolloverToCancel);

	gfAreaSelected = false;

    }

//-------------- Routine to call if the askForSizeBreakdown is cancelled ---

    function confirmAreas() {
	if(Areas.length == 0) {
		Areas = [['',0]];
		alert('You have deleted all your locations. Please select at least one.');
		return; // The user must select a location.
	}

	var outString = '';

	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] != '') {
	    	   outString = outString + Areas[i][0] + ", ";
	    }
	}

	gsOtagoConfirm = outString;
	gsOtagoResume = jumpToSilkscreenQuantities;
      gsOtagoCancel = doNothing; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-20)
	var winOCPU2 = window.open("OtagoAddRemove.html","","width=400,height=220,screenX=300,screenY=300,top=300,left=300");
	winOCPU2.focus();

    }

//-------------- Validate and assign the input number of colours -----------

    function handleColourPrompt() {

	// Handle the user's specified number of colours:
	var goodResponse = 0;

	var colours = gsOtagoSelect;
	colours -= 0; // make into a number.

	if(isNaN(colours)) goodResponse = 1;
 	if(colours > 8) goodResponse = 1;
 	if(colours < 1) goodResponse = 1;
	if(goodResponse == 1) { 
	    // Prompt again for the number of colours. Set the number to one just in case.
	    Areas[giOtagoPosition][1] = 1;

		gsOtagoQuestion = "Select the number of colours to be printed at this location:<br><br>There is a maximum of 8 colours.";
		gsOtagoDefault = '1';
		gsOtagoSelect = '';
		gfOtagoSelect = false;
		gaOtagoSelections = gaNewdogNumColours;
		gsOtagoResume = handleColourPrompt;
      	gsOtagoCancel = doNothing; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-26)
	    var winOCPU = window.open("OtagoSelect.html","","width=400,height=200,screenX=300,screenY=300,top=300,left=300");
	    winOCPU.focus();
	} else {
	    Areas[giOtagoPosition][1] = colours;
	    finishAreaSelection(); // Complete the Area Selection process.
	}
    }

//-------------- Finish up the Area Selection -----------

    function finishAreaSelection() {

	// Continue on from handleColourPrompt()
	var i = 0;
	var outString = '';

	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] != '') {
	    	outString = outString + Areas[i][0] + ", ";
	    }
	}

	areastr = '';
	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] != '') {
	    	areastr = areastr + "                 " + 
			  Areas[i][0] + "(# of colours - " + Areas[i][1] + ")\r";
	    }
	}

	// Determine if the user has finished specifying areas - if so, jump to the Quantity page:
	if(outString.length == 0) {
	    alert('You have no locations selected, please select one.');
	}
	else {
	    
		// Prompt to keep going (JA-OCI 17-Aug-04)
		gsOtagoConfirm = outString;
	    	gsOtagoResume = jumpToSilkscreenQuantities;
		gsOtagoCancel = handleColourPrompt;
	    	var winOCPU = window.open("OtagoAddRemove.html","PopOtagoConfirmWin","width=400,height=220,screenX=300,screenY=300,top=300,left=300");
		winOCPU.focus();
	}
}

//-------------- Jump to the Silkscreen Quantities page -----------

    function jumpToSilkscreenQuantities() {
	if(gfOtagoConfirm=='No') {
		gfShowQuantities = false;
		// top.MainFrame.location.replace("SilkscreenQuantities.html");
		top.MainFrame.location.replace("SilkscreenQuantities.php");
	} else {
		// Do nothing so they can add another area.
	}
    }

//-------------- Ask for Size Breakdown -----------
// JA-OCI 2005-06-13 -- sacked by Bernie's request to show no sizes always.

    function askForSizeBreakdown() {
	if(gfOtagoConfirm=='No') { // Ask so we can show the quantities page:
		gsOtagoConfirm = "Do you know your Size breakdown?";
	    	gsOtagoResume = jumpToSilkscreenQuantities;
		if(gsOtagoCancel==doNothing) {   // Then it has come from a deletion.
			gsOtagoCancel = confirmAreas;
		} else {	// Then it has come from a selection.
			gsOtagoCancel = finishAreaSelection;
		}
	    	var winOCPU = window.open("OtagoConfirm.html","","width=250,height=100,screenX=300,screenY=300,top=300,left=300");
		winOCPU.focus();
	} else {
		// Do nothing so they can add another area.
	}
    }

//-------------- Jump to the Silkscreen Quantities page -----------
// JA-OCI 2005-06-13 -- sacked by Bernie's request to show no sizes always.

    function jumpToSilkscreenQuantitiesOld() {
	if(gfOtagoConfirm=='No') {
		gfShowQuantities = false;
		top.MainFrame.location.replace("SilkscreenQuantities.html");
	} else if(gfOtagoConfirm=='Yes') {
		gfShowQuantities = true;
		top.MainFrame.location.replace("SilkscreenQuantities.html");
	} else {
		// Do nothing.
	}
    }

//=================================================================
//
//	EMBROIDERY PRICING STREAM
//
//=================================================================

//-------------- Set Embroidery Areas -----------

    function setEmbArea(areaName) {
	
	// Set the area. If already set, remove.
	//   - (JA-OCI 2005-01-17) If an area is selected that is already selected,
      //     remove it and go straight to add/remove dialog.
	//   - (JA-OCI 2005-01-26) Return to previous popup if cancel is clicked.

	var i = 0;
	var outString = '';
	var found = false;
	var conflict = false;
	var placed = false;
	var stitches = 0;
	var answer = false;
	var embSize = '';

	top.gfscOnEdit = false;
	gfAreaSelected = false;  // Ensure no area selection rollover occurs to highlight an area unless it is safely selected.

	// Test to ensure ULC/URC and Full front are not both selected:
	if(areaName == 'Full Front') {
	    // Check for existing ULC or URC.
	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] == 'Upper Left Chest') {
		    alert('You can not select Full Front because you have already selected Upper Left Chest. ' + 
			  'If you want Full Front you must first click ULC to deselect it.');
		    conflict = true;
		    break;
		}
		if(Areas[i][0] == 'Upper Right Chest') {
		    alert('You can not select Full Front because you have already selected Upper Right Chest. ' + 
			  'If you want Full Front you must first click URC to deselect it.');
		    conflict = true;
		    break;
		}
	    }
	}
	if(conflict) return;
	if(areaName == 'Upper Left Chest') {
	    // Check for existing Full Front.
	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] == 'Full Front') {
		    alert('You can not select Upper Left Chest because you have already selected Full Front. ' + 
			  'If you want ULC you must first click Full Front to deselect it.');
		    conflict = true;
		    break;
		}
	    }
	}
	if(conflict) return;
	if(areaName == 'Upper Right Chest') {
	    // Check for existing Full Front.
	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] == 'Full Front') {
		    alert('You can not select Upper Right Chest because you have already selected Full Front. ' + 
			  'If you want URC you must first click Full Front to deselect it.');
		    conflict = true;
		    break;
		}
	    }
	}
	if(conflict) return;
	gfAreaSelected = true;  // Okay, rollover the area to be highlighted.


	// If this area already exists, then delete it and jump to the add/remove dialog window:
	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] == areaName) {
		Areas[i][0] = '';
		Areas[i][1] = 0;
		found = true;
	    }
	}

	// Tighten up the array:
	if(found) {
	    for(i = 0; i < Areas.length; i++) {
		if(Areas[i][0] == '') {
		    if(i != (Areas.length - 1)) {
		    	Areas[i][0] = Areas[i+1][0];
		    	Areas[i][1] = Areas[i+1][1];
		    	Areas[i+1][0] = '';
		    	Areas[i+1][1] = 0;
		    }
		}
	    }
	    Areas.length = Areas.length - 1;
	    if(Areas.length == 0) {
		Areas = [['',0]];
		alert('You have deleted all your locations. Please select at least one.');
		return; // The user must select a location.
	    }

	    var outString = '';

	    for(i = 0; i < Areas.length; i++) {
	    	if(Areas[i][0] != '') {
	    	   outString = outString + Areas[i][0] + ", ";
	    	}
	    }

	    gsOtagoConfirm = outString;
	    gsOtagoResume = jumpToEmbroideryQuantities;
          gsOtagoCancel = doNothing; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-20)
	    var winOCPU2 = window.open("OtagoAddRemove.html","","width=400,height=220,screenX=300,screenY=300,top=300,left=300");
	    winOCPU2.focus();

	    return; // My work here is done.	    
	}

	// 21Jan03 JA-OCI - Prompt user for the number of stitches, estimate a size if they don't know.
	// 23Aug04 JA-OCI - Changed code to use generic popups.

	if(!found) {
	    // Add the area to the first blank or, failing that, at the end of the list.
	    for(i = 0; i < Areas.length; i++) {
	      if(Areas[i][0] == '') {
		    Areas[i][0] = areaName;
		    giOtagoPosition = i; // Remember the i position to enter the colours in after prompting for them.
		    placed = true;
	    	}
		if(placed) break;
	    }
	    if(!placed) {
		Areas[Areas.length] = new Array(3);
		Areas[Areas.length-1][0] = areaName;
		giOtagoPosition = Areas.length-1; // Remember the new position to enter the colours in after prompting for them.
	    }
	}

   	// Now ask if they know the number of stitches:
	gsOtagoConfirm = "Do you know the number of Stitches required to sew this design?";
	gsOtagoResume = handleStitchesKnow;
      gsOtagoCancel = cancelSelection; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-20)
	var winOCPU = window.open("OtagoConfirm.html","","width=250,height=125,screenX=300,screenY=300,top=300,left=300");
	winOCPU.focus();

    }

//-------------- Routine to call if the askForEmbSizeBreakdown is cancelled ---

    function confirmEmbAreas() {
	if(Areas.length == 0) {
		Areas = [['',0]];
		alert('You have deleted all your locations. Please select at least one.');
		return; // The user must select a location.
	}

	var outString = '';

	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] != '') {
	    	   outString = outString + Areas[i][0] + ", ";
	    }
	}

	gsOtagoConfirm = outString;
	gsOtagoResume = jumpToEmbroideryQuantities;
      gsOtagoCancel = doNothing; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-20)
	var winOCPU2 = window.open("OtagoAddRemove.html","","width=400,height=220,screenX=300,screenY=300,top=300,left=300");
	winOCPU2.focus();

    }

//-------------- cancelStitchesKnow ----------------------

    function cancelStitchesKnow() {
	// Run from cancelling the pop-up asking if they know their stitch #. (handleStitchesKnow)
	// Ask again if they know the number of stitches:
	gfOtagoConfirm = '';	
	gsOtagoConfirm = "Do you know the number of Stitches required to sew this design?";
	gsOtagoResume = handleStitchesKnow;
      gsOtagoCancel = doNothing; // Empty string so the cancel button will just close the pop-up. (JA-OCI 2005-Jan-20)
	var winOCPU = window.open("OtagoConfirm.html","","width=250,height=125,screenX=300,screenY=300,top=300,left=300");
	winOCPU.focus();
    }

//-------------- handleStitchesKnow ----------------------

    function handleStitchesKnow() {

	// If they know, then ask for the number, else estimate the size:
	if(gfOtagoConfirm=='Yes') {
	    gsOtagoQuestion = "How many Stitches are in this design?<br><br>There is a minimum of 1000 Stitches, and a maximum of 45000, per embroidery. Please enter a number between 1000 and 45000.";
	    gsOtagoDefault = '1000';
	    giOtagoInputSize = 5;
	    gfOtagoInput = false;
	    gsOtagoInput = 0;
	    gsOtagoResume = handleStitchesPrompt;
          gsOtagoCancel = cancelStitchesKnow;
	    var winOCPU = window.open("OtagoInput.html","","width=400,height=175,screenX=250,screenY=250,top=250,left=250");
	    winOCPU.focus();
	} else { 
	    // if(gfOtagoConfirm=='No') {
	    // JA-OCI - 2005-01-05  -- removed to select range based on area selected.
	    gfOtagoInput = false;
	    gsOtagoInput = 0;
	    handleStitchesPrompt();
      }
	gfOtagoConfirm = '';
	
    }

//-------------- handleStitchesPrompt ----------------------

    function handleStitchesPrompt() {

	// Handle the user's specified number of stitches:
	var goodResponse = 0;
	var stitches = 1000;
	if(gfOtagoInput) {
		stitches = gsOtagoInput;
	} else {
		// JA-OCI - 2005-01-05  -- removed to select range based on area selected.
		// stitches = gsOtagoSelect;
		if(Areas[Areas.length-1][0] == "Full Back") stitches = 22000;
		else if(Areas[Areas.length-1][0] == "Full Front") stitches = 14500;
		else stitches = 8000;
	}

	if(isNaN(stitches)) {
	   if(stitches == 'Small (1000 - 8000 stitches)') stitches = 4000;
	   else if(stitches == 'Medium (8000 - 18000 stitches)') stitches = 13000;
	   else if(stitches == 'Large (18000 - 45000 stitches)') stitches = 23000;
	   else goodResponse = 1;
	} else {
	   stitches -= 0; // make into a number.
	}
 	if(stitches > 45000) goodResponse = 1;
 	if(stitches < 1000) goodResponse = 1;
	if(goodResponse == 1) { 
	    // Prompt again for the number of stitches. Set the number to 1000 just in case.
	    reAskNumStitches();
	} else {
	    Areas[giOtagoPosition][1] = stitches;
	    handleSetUpPrompt(); // Complete the Area Selection process.
	}
    }

//-------------- reAskNumStitches --------------------------

    function reAskNumStitches() {
	    // Prompt again for the number of stitches. Set the number to 1000 just in case.
	    gsOtagoQuestion = "How many Stitches are in this design?<br><br>There is a minimum of 1000 Stitches, and a maximum of 45000, per embroidery. Please enter a number between 1000 and 45000.";
	    gsOtagoDefault = '1000';
	    giOtagoInputSize = 5;
	    gfOtagoInput = false;
	    gsOtagoInput = 0;
	    gsOtagoResume = handleStitchesPrompt;
          gsOtagoCancel = cancelStitchesKnow;
	    Areas[giOtagoPosition][1] = 1000;
	    gfOtagoSelect = false;
	    gfOtagoInput = false;
	    var winOCPU = window.open("OtagoInput.html","","width=400,height=200,screenX=300,screenY=300,top=300,left=300");
	    winOCPU.focus();
    }

//-------------- handleSetUpPrompt -------------------------

    function handleSetUpPrompt() {

	// See if they want NewDog to do the setup (JA-OCI 23-Aug-04):
	gsOtagoConfirm = "Will Newdog have to setup your Embroidery design?";
	if(gsOtagoResume == handleStitchesKnow) {
		gsOtagoCancel = cancelStitchesKnow; // back to if they know the # of stitches.
	} else if(gsOtagoResume == askForEmbSizeBreakdown) {
		gsOtagoCancel = cancelStitchesKnow; // back to if they know the # of stitches.
	} else {
		gsOtagoCancel = reAskNumStitches; // Back to # Stitches prompt.
	}
	gsOtagoResume = finishEmbAreaSelection;
	var winOCPU = window.open("OtagoConfirm.html","","width=250,height=120,screenX=300,screenY=300,top=300,left=300");
	winOCPU.focus();
    }

//-------------- Finish up the Embroidery Area Selection -----------

    function finishEmbAreaSelection() {

	// Continue on from handleSetUpPrompt()
	var i = 0;
	var outString = '';

	// 21Jan03 JA-OCI - Add in the cost of setup, if applicable:
	if(gfOtagoConfirm=='Yes') {
	   if((Areas[giOtagoPosition][0] == "Full Back") || (Areas[giOtagoPosition][0] == "Full Front")) { 
		Areas[giOtagoPosition][2] = 200;  // Costs 200 bucks to get this setup. - JA-OCI 2005-06-14
	   } else {
		Areas[giOtagoPosition][2] = 100;  // Costs 100 bucks to get this setup. - JA-OCI 2005-06-14
	   }
	}

	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] != '') {
	    	outString = outString + Areas[i][0] + ", ";
	    }
	}

	areastr = '';
	for(i = 0; i < Areas.length; i++) {
	    if(Areas[i][0] != '') {
	    	areastr = areastr + "                 " + 
			  Areas[i][0] + "(# of stitches - " + Areas[i][1] + ")\r";
	    }
	}

	// Determine if the user has finished specifying areas - if so, jump to the Quantity page:
	if(outString.length == 0) {
	    alert('You have no locations selected, please select one.');
	} else {
	   if((gfGarment) || (gfCaps)) {
		// Prompt to keep going (JA-OCI 17-Aug-04)
		gsOtagoConfirm = outString;
	    	gsOtagoResume = jumpToEmbroideryQuantities;
		gsOtagoCancel = handleSetUpPrompt;
	    	var winOCPU = window.open("OtagoAddRemove.html","","width=400,height=220,screenX=250,screenY=250,top=250,left=250");
		winOCPU.focus();
	   } else {
		// Only one location, so go straight to costs. (JA-OCI 2004-11-18)
		gfOtagoConfirm = 'No';
		jumpToEmbroideryQuantities();
	   }
	}
   }

//-------------- Jump to the Embroidery Quantities page -----------

    function jumpToEmbroideryQuantities() {
	if(gfOtagoConfirm=='No') {
	   gfShowQuantities = false;
	   // top.MainFrame.location.replace("EmbroideryQuantities.html");
	   top.MainFrame.location.replace("EmbroideryQuantities.php");
	} else {
	   // Do nothing so they can add another area.
	}
    }


//-------------- Ask for Size Breakdown -----------
// JA-OCI 2005-06-13 -- sacked by Bernie's request to show no sizes always.

    function askForEmbSizeBreakdown() {
	if(gfOtagoConfirm=='No') { // Ask so we can show the quantities page:
	   if(gfCaps) {
	   	gfShowQuantities = false;
	   	top.MainFrame.location.replace("EmbroideryQuantities.html");
	   } else {
		gsOtagoConfirm = "Do you know your Size breakdown?";
	    	gsOtagoResume = jumpToEmbroideryQuantities;
		if(gsOtagoCancel == doNothing) { // then we are here from a deletion.
			gsOtagoCancel = confirmEmbAreas;
		} else { // we are here from a selection.
			if(gfGarment) {
				gsOtagoCancel = finishEmbAreaSelection;
			} else {
				gsOtagoCancel = handleSetUpPrompt;
			}
		}
	    	var winOCPU = window.open("OtagoConfirm.html","","width=250,height=120,screenX=300,screenY=300,top=300,left=300");
		winOCPU.focus();
	   }
	} else {
		// Do nothing so they can add another area.
	}
    }

//-------------- Jump to the Embroidery Quantities page -----------
// JA-OCI 2005-06-13 -- sacked by Bernie's request to show no sizes always.

    function jumpToEmbroideryQuantitiesOld() {
	if(gfOtagoConfirm=='No') {
		gfShowQuantities = false;
		top.MainFrame.location.replace("EmbroideryQuantities.html");
	} else if(gfOtagoConfirm=='Yes') {
		gfShowQuantities = true;
		top.MainFrame.location.replace("EmbroideryQuantities.html");
	} else {
		// Do nothing.
	}
    }


//------------------------------------------------------------------------------
//
//	CALCULATING TOTALS FOR ALL STREAMS
//
//------------------------------------------------------------------------------

function roundNumber(num) {
	var rnum = num;
	var rlength = 2; // The number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	return newnumber;
}

//-------------- Calculate the Qty and Costs and store (for no specified sizes) -----------

    function calcTotalsNoSizes() {
	
	top.gfscOnEdit = false;

	if(Areas.length == 0) {
	  alert('There are no areas selected. I can not calculate any costs.');
	  return;
	}

	// Calc the prices:
	var basPrice = Price; //  * 1.10; // Removed 20Jan03 as per Bernie's request.
	// Get the total amount from the form:
	var aAmt = top.MainFrame.document.ndQuantityForm.aAmt.value - 0;
	var aSetup = 0;

	// JA-OCI 25-Sep-03  --  Added to check minimum amounts as per Bernie's request.
	// JA-OCI 13-Nov-04  --  Change minimums to be 12.
	// JA-OCI 22-Nov-04  --  Unless it is a 'Cap' in which case use the database default.
	// JA-OCI 03-Apr-07  --  Ignore minimums, it is set by database. Just test to see it is over minqty.
	if(top.prodType=='Embroidered') {	
	//  if(gfCaps) {
		// If the amount is less than the minimum, alert the user and reset the amount to be the minimum: (JA-OCI 2004-11-22)
		var minQty = giMinQty;
		// alert('The minimum quantity is: ' + minQty + ' and you have requested: ' + aAmt);
		if(minQty > aAmt) {
		   alert("The minimum imprinted quantity for this product is " + minQty);
		   aAmt = minQty;
		   top.MainFrame.document.ndQuantityForm.aAmt.value = aAmt;
      	}
	//  } else {
	//    if(aAmt < 12) {
	//	alert("The minimum imprinted quantity for this product is 12");
	//	aAmt = 12;
	//	top.MainFrame.document.ndQuantityForm.aAmt.value = 12;
		// alert('The minimum amount is 12. I can not calculate any costs.');
		// top.MainFrame.document.ndQuantityForm.aAmt.value = 0
	    	// return;
	//    }
	//  }
	}
	if(top.prodType=='Silkscreened') {
	  // if(gfCaps) {
		// If the amount is less than the minimum, alert the user and reset the amount to be the minimum: (JA-OCI 2004-11-22)
		var minQty = giMinQty;
		// alert('The minimum quantity is: ' + minQty + ' and you have requested: ' + aAmt);
		if(minQty > aAmt) {
		   alert("The minimum imprinted quantity for this product is " + minQty);
		   aAmt = minQty;
		   top.MainFrame.document.ndQuantityForm.aAmt.value = aAmt;
      	}
	 // } else {
	 //   if(aAmt < 12) {
	 //	alert("The minimum imprinted quantity for this product is 12");
	 //	aAmt = 12;
	 //	top.MainFrame.document.ndQuantityForm.aAmt.value = 12;
	    	// alert('The minimum amount is 12. I can not calculate any costs.');
		// top.MainFrame.document.ndQuantityForm.aAmt.value = 0
	    	// return;
	  //  }
	  // }
	}

	// Get the total cost from the pricing grid:
	var aCost = 0.0;
	var aClr = 0;
	for(var i=0; i < Areas.length; i++) {
	    aClr = Areas[i][1];
	    if(top.prodType=='Silkscreened') {
		aCost += getSilkscreenCost(aClr, aAmt);
	    }
	    else {
		if(aClr>0) {
		   aCost += getEmbroideryCost(aClr, aAmt);
		}
	    }
	    if(Areas[i][2]>0) aSetup += 75;
	}

	var uCost = (aCost + basPrice); // Unit selling price.
	// uCost += aSetup // Add the setup cost of 75 dollars for each specified area.
	if(USA) { uCost = uCost * usRate; } // Exchange rate.

	// JA-OCI - 2008-05-26: Bernie requested that GST be removed from this calculation.
	// else { uCost = uCost * 1.06; } // Add GST.

	// JA-OCI - 2007-02-15: Added this to round the uCost figure.
	uCost = roundNumber(uCost);

	var tCost = (uCost * aAmt) + aSetup; // Total selling cost plus the setup cost of 75 dollars for each specified area.
	tCost = roundNumber(tCost);
	// top.MainFrame.document.ndQuantityForm.uCost.value = makeString(uCost);
	if(aAmt == 0) uCost = 0;

	top.MainFrame.document.ndQuantityForm.aCost.value = makeString(uCost);
	top.MainFrame.document.ndQuantityForm.tCost.value = makeString(tCost);

	// Save in the Global Variables:
	top.SmallAmt = 0;
    	top.MedAmt = 0;
    	top.LargeAmt = 0;
    	top.XLAmt = 0;
    	top.XXLAmt = 0;
	top.XXLAmt = 0;0
	top.XXXLAmt = 0;
    	top.XXXLAmt = 0;
	top.SmallCost = 0;
    	top.MedCost = 0;
    	top.LargeCost = 0;
    	top.XLCost = 0;
	top.XXLCost = 0;
	top.XXXLCost = 0;
	top.totalUnit = makeString(uCost);
    	top.totalCost = makeString(tCost);
    	top.totalAmt = aAmt;

	if(USA) {
	    top.MainFrame.document.ndQuantityForm.tCost.value = 'US ' + top.MainFrame.document.ndQuantityForm.tCost.value;
	}
	else {
	    top.MainFrame.document.ndQuantityForm.tCost.value = 'C ' + top.MainFrame.document.ndQuantityForm.tCost.value;
	}

    }

//-------------- Calculate the Qty and Costs and store ------------------------------------

    function calcTotals() {

	// Dec. 11 - Remove base price markup as this will be set in the initial parameter list.
	//  	     Thus, " * 1.35;" was taken off the end of each 'Unit selling price' calc line.

	top.gfscOnEdit = false;

	if(Areas.length == 0) {
	  alert('There are no areas selected. I can not calculate any costs.');
	  return;
	}
	
	// Calc the prices:
	var basPrice = Price; //  * 1.10; // Removed 20Jan03 as per Bernie's request.
	var basXXLPrice = XXLbase; //  * 1.10; // Removed 20Jan03 as per Bernie's request.
	var basXXXLPrice = XXXLbase; //  * 1.10; // Removed 20Jan03 as per Bernie's request.
	var basXXLPrice = XXLbase * 1.25; // Reintroduced 30Jan05 as per Bernie's request. Raised to 1.25 2005-05-26.
	var basXXXLPrice = XXXLbase * 1.25; // Reintroduced 30Jan05 as per Bernie's request. Raised to 1.25 2005-05-26.
	var aSetup = 0;

	// Get the total amount from the form:
	var aAmt = top.MainFrame.document.ndQuantityForm.sAmt.value - 0;
	aAmt += top.MainFrame.document.ndQuantityForm.mAmt.value - 0;
	aAmt += top.MainFrame.document.ndQuantityForm.lAmt.value - 0;
	aAmt += top.MainFrame.document.ndQuantityForm.xlAmt.value - 0;
	if(XXLbase > 0) aAmt += top.MainFrame.document.ndQuantityForm.xxlAmt.value - 0;
	if(XXXLbase > 0) aAmt += top.MainFrame.document.ndQuantityForm.xxxlAmt.value - 0;

	// Get the total cost from the pricing grid:
	var aCost = 0.0;
	var aClr = 0;
	for(var i=0; i < Areas.length; i++) {
	    aClr = Areas[i][1];
	    if(top.prodType=='Silkscreened') {
		aCost += getSilkscreenCost(aClr, aAmt);
	    }
	    else {
		aCost += getEmbroideryCost(aClr, aAmt);
	    }
	    if(Areas[i][2]>0) aSetup += 75;
	}
	
	var sCost = 0.0;
	var sAmt = top.MainFrame.document.ndQuantityForm.sAmt.value - 0;
	if(sAmt>0) {
	    sCost = (aCost + basPrice); // Unit selling price.
	    if(USA) { sCost = sCost * usRate; } // Exchange rate.

		// JA-OCI - 2008-05-26: Bernie requested that GST be removed from this calculation.
		// else { sCost = sCost * 1.06; } // Add GST.

	    // top.MainFrame.document.ndQuantityForm.suCost.value = makeString(sCost);
	    top.MainFrame.document.ndQuantityForm.sCost.value = makeString(sCost);
	    sCost = (sCost * sAmt); // Total selling cost.
	} else {
	    top.MainFrame.document.ndQuantityForm.sCost.value = 0;
	}

	var mCost = 0.0;
	var mAmt = top.MainFrame.document.ndQuantityForm.mAmt.value - 0;
	if(mAmt>0) {
	    mCost = (aCost + basPrice); // Unit selling price.
	    if(USA) { mCost = mCost * usRate; } // Exchange rate.

		// JA-OCI - 2008-05-26: Bernie requested that GST be removed from this calculation.
		// else { mCost = mCost * 1.06; } // Add GST.

	    // top.MainFrame.document.ndQuantityForm.muCost.value = makeString(mCost);
	    top.MainFrame.document.ndQuantityForm.mCost.value = makeString(mCost);
	    mCost = (mCost * mAmt); // Total selling cost.
	} else {
	    top.MainFrame.document.ndQuantityForm.mCost.value = 0;
	}

	var lCost = 0.0;
	var lAmt = top.MainFrame.document.ndQuantityForm.lAmt.value - 0;
	if(lAmt>0) {
	    lCost = (aCost + basPrice); // Unit selling price.
	    if(USA) { lCost = lCost * usRate; } // Exchange rate.

		// JA-OCI - 2008-05-26: Bernie requested that GST be removed from this calculation.
		// else { lCost = lCost * 1.06; } // Add GST.

	    // top.MainFrame.document.ndQuantityForm.luCost.value = makeString(lCost);
	    top.MainFrame.document.ndQuantityForm.lCost.value = makeString(lCost);
	    lCost = (lCost * lAmt); // Total selling cost.
	} else {
	    top.MainFrame.document.ndQuantityForm.lCost.value = 0;
	}

	var xlCost = 0.0;
	var xlAmt = top.MainFrame.document.ndQuantityForm.xlAmt.value - 0;
	if(xlAmt>0) {
	    xlCost = (aCost + basPrice); // Unit selling price.
	    if(USA) { xlCost = xlCost * usRate; } // Exchange rate.
	    
		// JA-OCI - 2008-05-26: Bernie requested that GST be removed from this calculation.
		// else { xlCost = xlCost * 1.06; } // Add GST.

	    // top.MainFrame.document.ndQuantityForm.xluCost.value = makeString(xlCost);
	    top.MainFrame.document.ndQuantityForm.xlCost.value = makeString(xlCost);
	    xlCost = (xlCost * xlAmt); // Total selling cost.
	} else {
	    top.MainFrame.document.ndQuantityForm.xlCost.value = 0;
	}
	
	if(XXLbase > 0) {
	    var xxlCost = 0.0;
	    var xxlAmt = top.MainFrame.document.ndQuantityForm.xxlAmt.value - 0;
	    if(xxlAmt>0) {
	    	xxlCost = (aCost + basXXLPrice); // Unit selling price.
	    	if(USA) { xxlCost = xxlCost * usRate; } // Exchange rate.
	    	
		// JA-OCI - 2008-05-26: Bernie requested that GST be removed from this calculation.
		// else { xxlCost = xxlCost * 1.06; } // Add GST.

	    	// top.MainFrame.document.ndQuantityForm.xxluCost.value = makeString(xxlCost);
	    	top.MainFrame.document.ndQuantityForm.xxlCost.value = makeString(xxlCost);
	    	xxlCost = (xxlCost * xxlAmt); // Total selling cost.
	    } else {
	    	top.MainFrame.document.ndQuantityForm.xxlCost.value = 0;
	    }
	}

	if(XXXLbase > 0) {
	    var xxxlCost = 0.0;
	    var xxxlAmt = top.MainFrame.document.ndQuantityForm.xxxlAmt.value - 0;
	    if(xxxlAmt>0) {
	    	xxxlCost = (aCost + basXXXLPrice); // Unit selling price.
	    	if(USA) { xxxlCost = xxxlCost * usRate; } // Exchange rate.
	    	
		// JA-OCI - 2008-05-26: Bernie requested that GST be removed from this calculation.
		// else { xxxlCost = xxxlCost * 1.06; } // Add GST.

	    	// top.MainFrame.document.ndQuantityForm.xxxluCost.value = makeString(xxxlCost);
	    	top.MainFrame.document.ndQuantityForm.xxxlCost.value = makeString(xxxlCost);
	    	xxxlCost = (xxxlCost * xxxlAmt);  // Total selling cost.
	    } else {
	    	top.MainFrame.document.ndQuantityForm.xxxlCost.value = 0;
	    }
	}	

	// Total the Quantities:
	top.MainFrame.document.ndQuantityForm.tAmt.value = 
		(top.MainFrame.document.ndQuantityForm.sAmt.value - 0) +
		(top.MainFrame.document.ndQuantityForm.mAmt.value - 0) +
		(top.MainFrame.document.ndQuantityForm.lAmt.value - 0) +
		(top.MainFrame.document.ndQuantityForm.xlAmt.value - 0);

	if(XXLbase > 0) {
	    top.MainFrame.document.ndQuantityForm.tAmt.value =
		(top.MainFrame.document.ndQuantityForm.tAmt.value - 0) +
		(top.MainFrame.document.ndQuantityForm.xxlAmt.value - 0);
	}
	if(XXXLbase > 0) {
	    top.MainFrame.document.ndQuantityForm.tAmt.value =
		(top.MainFrame.document.ndQuantityForm.tAmt.value - 0) +
		(top.MainFrame.document.ndQuantityForm.xxxlAmt.value - 0);
	}

	// Total the Costs:
	var tmpCost = sCost + mCost + lCost + xlCost;
	if(XXLbase > 0) {
	    tmpCost += xxlCost;
	}
	if(XXXLbase > 0) {
	    tmpCost += xxxlCost;
	}
	
	tmpCost += aSetup; // Add in the setup costs.
	top.MainFrame.document.ndQuantityForm.tCost.value = makeString(tmpCost); 

	// Save in the Global Variables:
	top.SmallAmt = top.MainFrame.document.ndQuantityForm.sAmt.value;
    	top.MedAmt = top.MainFrame.document.ndQuantityForm.mAmt.value;
    	top.LargeAmt = top.MainFrame.document.ndQuantityForm.lAmt.value;
    	top.XLAmt = top.MainFrame.document.ndQuantityForm.xlAmt.value;
    	if(XXLbase == 0) {
	    top.XXLAmt = 0;
	}
	else {
	    top.XXLAmt = top.MainFrame.document.ndQuantityForm.xxlAmt.value;
	}
	if(XXXLbase == 0) {
	    top.XXXLAmt = 0;
	}
	else {
    	    top.XXXLAmt = top.MainFrame.document.ndQuantityForm.xxxlAmt.value;
	}
	top.SmallCost = top.MainFrame.document.ndQuantityForm.sCost.value;
    	top.MedCost = top.MainFrame.document.ndQuantityForm.mCost.value;
    	top.LargeCost = top.MainFrame.document.ndQuantityForm.lCost.value;
    	top.XLCost = top.MainFrame.document.ndQuantityForm.xlCost.value;
	if(XXLbase == 0) {
	    top.XXLCost = 0;
	}
	else {
	    top.XXLCost = top.MainFrame.document.ndQuantityForm.xxlCost.value;
	}
	if(XXXLbase == 0) {
	    top.XXXLCost = 0;
	}
	else {
    	    top.XXXLCost = top.MainFrame.document.ndQuantityForm.xxxlCost.value;
	}
	
	// top.SmallUnit = top.MainFrame.document.ndQuantityForm.suCost.value;
    	// top.MedUnit = top.MainFrame.document.ndQuantityForm.muCost.value;
    	// top.LargeUnit = top.MainFrame.document.ndQuantityForm.luCost.value;
    	// top.XLUnit = top.MainFrame.document.ndQuantityForm.xluCost.value;
	// if(XXLbase == 0) {
	//     top.XXLUnit = 0;
	// }
	// else {
	//     top.XXLUnit = top.MainFrame.document.ndQuantityForm.xxluCost.value;
	// }
	// if(XXXLbase == 0) {
	//     top.XXXLUnit = 0;
	// }
	// else {
    	//     top.XXXLUnit = top.MainFrame.document.ndQuantityForm.xxxluCost.value;
	// }

    	top.totalCost = top.MainFrame.document.ndQuantityForm.tCost.value;
    	top.totalAmt = top.MainFrame.document.ndQuantityForm.tAmt.value;

	if(USA) {
	    top.MainFrame.document.ndQuantityForm.tCost.value = 'US ' + top.MainFrame.document.ndQuantityForm.tCost.value;
	}
	else {
	    top.MainFrame.document.ndQuantityForm.tCost.value = 'C ' + top.MainFrame.document.ndQuantityForm.tCost.value;
	}
	
    }

  //-------------- Convert Price to a String with Decimals -------------------------------------

    function makeString(thePrice) {
	
	// Make price a string and ensure two (and only two) decimal places.
	var intPos;

	if(thePrice == null) { thePrice=0.00; }

	thePrice = thePrice + "";
	if(thePrice == 'NaN') { thePrice=0.00 + ""; }

	// Find the decimal and extend or truncate as needed.
	intPos = thePrice.indexOf('.');

	if(intPos==-1) { // whole number.
	  thePrice = thePrice + '.00';
	}
	else if((intPos+2)==thePrice.length) { // One decimal place.
	  thePrice = thePrice + '0';
	}
	else if((intPos+3)==thePrice.length) { // Two places - perfect!
	  // do nothing.
	}
	else { // Truncate to two places.
	  thePrice = thePrice.slice(0,intPos+3);
	}

	// Add a dollar sign if there is only one:
	intPos = thePrice.indexOf('$');
	if(intPos==-1) thePrice = '$' + thePrice;

	return thePrice;
    }

  //-------------- Get the cost for the Silkscreen imprint by number of colours -----------------

    function getSilkscreenCost(colour, quantity) {

	// This is the colour/price matrix. Return the cost per imprint.
	// - Colour comes in as a number. The number of colours for this imprint.
	// - quantity comes in as a number. The number of shirts for this size ordered.

	top.gfscOnEdit = false;

	var cost;
	
	var colour = colour - 0;		// Subtract zero to ensure that this is a number.
	var qty = quantity - 0;			// Subtract zero to ensure that this is a number.

	if(colour>8) colour = 8;
	if(colour==0) return 0; 		// No number of colours specified.
	if(qty==0) return 0;			// No quantity specified.
	
	switch(colour) {
	  case 1:
	    if(qty<=23) return (7.25);
	    if(qty<=47) return (4.64);
	    if(qty<=71) return (2.76);
	    if(qty<=99) return (2.18);
	    if(qty<=249) return (1.45);
	    if(qty<=999) return (1.16);
	    if(qty<=2499) return (1.00);
	    if(qty<=5000) return (0.87);
	    if(qty>=5001) return (0.80);
	    break;
	  case 2:
	    if(qty<=23) return (10.15);
	    if(qty<=47) return (6.45);
	    if(qty<=71) return (3.83);
	    if(qty<=99) return (3.03);
	    if(qty<=249) return (2.02);
	    if(qty<=999) return (1.61);
	    if(qty<=2499) return (1.30);
	    if(qty<=5000) return (1.20);
	    if(qty>=5001) return (1.10);
	    break;
	  case 3:
	    if(qty<=23) return (11.60);
	    if(qty<=47) return (7.80);
	    if(qty<=71) return (4.63);
	    if(qty<=99) return (3.65);
	    if(qty<=249) return (2.44);
	    if(qty<=999) return (1.94);
	    if(qty<=2499) return (1.68);
	    if(qty<=5000) return (1.46);
	    if(qty>=5001) return (1.33);
	    break;
	  case 4:
	    if(qty<=23) return (14.50);
	    if(qty<=47) return (8.58);
	    if(qty<=71) return (5.10);
	    if(qty<=99) return (4.03);
	    if(qty<=249) return (2.68);
	    if(qty<=999) return (2.15);
	    if(qty<=2499) return (1.86);
	    if(qty<=5000) return (1.61);
	    if(qty>=5001) return (1.48);
	    break;
	  case 5:
	    if(qty<=23) return (15.95);
	    if(qty<=47) return (9.74);
	    if(qty<=71) return (5.79);
	    if(qty<=99) return (4.57);
	    if(qty<=249) return (3.05);
	    if(qty<=999) return (2.44);
	    if(qty<=2499) return (2.10);
	    if(qty<=5000) return (1.83);
	    if(qty>=5001) return (1.68);
	    break;
	  case 6:
	    if(qty<=23) return (18.85);
	    if(qty<=47) return (11.44);
	    if(qty<=71) return (6.61);
	    if(qty<=99) return (5.22);
	    if(qty<=249) return (3.48);
	    if(qty<=999) return (2.78);
	    if(qty<=2499) return (2.41);
	    if(qty<=5000) return (2.09);
	    if(qty>=5001) return (1.91);
	    break;
	  case 7:
	    if(qty<=23) return (21.75);
	    if(qty<=47) return (12.99);
	    if(qty<=71) return (7.71);
	    if(qty<=99) return (6.09);
	    if(qty<=249) return (4.06);
	    if(qty<=999) return (3.25);
	    if(qty<=2499) return (2.80);
	    if(qty<=5000) return (2.44);
	    if(qty>=5001) return (2.23);
	    break;
	  case 8:
	    if(qty<=23) return (26.10);
	    if(qty<=47) return (14.85);
	    if(qty<=71) return (8.82);
	    if(qty<=99) return (6.96);
	    if(qty<=249) return (4.64);
	    if(qty<=999) return (3.71);
	    if(qty<=2499) return (3.20);
	    if(qty<=5000) return (2.78);
	    if(qty>=5001) return (2.55);
	    break;
	  default:
	    return 0;
	    break;
	}

    }


  //-------------- Get the cost for the embroidery by number of stitches -----------------

    function getEmbroideryCost(stitches, quantity) {

	// This is the colour/price matrix. Return the cost per imprint.
	// - Stitches comes in as a number. The number of stitches (category) for this embroidery.
	// - quantity comes in as a number. The number of shirts for this size ordered.

	top.gfscOnEdit = false;

	var cost;
	
	var stitchesIn = stitches - 0;		// Subtract zero to ensure that this is a number.
	var qty = quantity - 0;			// Subtract zero to ensure that this is a number.
	var stitch = 0;

	if(stitchesIn<=3500) stitch = 1;
	else if(stitchesIn<=5000) stitch = 2;
	else if(stitchesIn<=6500) stitch = 3;
	else if(stitchesIn<=8000) stitch = 4;
	else if(stitchesIn<=9500) stitch = 5;
	else if(stitchesIn<=12000) stitch = 6;
	else if(stitchesIn<=14500) stitch = 7;
	else if(stitchesIn<=17000) stitch = 8;
	else if(stitchesIn<=19500) stitch = 9;
	else if(stitchesIn<=22000) stitch = 10;
	else stitch = 11;

	if(stitch==0) return 0; 		// No number of stitches specified.
	if(qty==0) return 0;			// No quantity specified.
	
	// OCI-JA 2008-05-19: updated embroidery grid as per Bernie's instructions.
	switch(stitch) {
	  case 1:
	    if(qty<=48) return (3.50);
	    if(qty<=84) return (3.25);
	    if(qty<=144) return (3.00);
	    if(qty<=240) return (2.75);
	    if(qty<=499) return (2.50);
	    if(qty>=500) return (2.50);
	    break;
	  case 2:	// This is the Small category.
	    if(qty<=48) return (4.25);
	    if(qty<=84) return (3.75);
	    if(qty<=144) return (3.50);
	    if(qty<=240) return (3.25);
	    if(qty<=499) return (3.00);
	    if(qty>=500) return (3.00);
	    break;
	  case 3:
	    if(qty<=48) return (5.00);
	    if(qty<=84) return (4.50);
	    if(qty<=144) return (4.25);
	    if(qty<=240) return (3.75);
	    if(qty<=499) return (3.50);
	    if(qty>=500) return (3.50);
	    break;
	  case 4:
	    if(qty<=48) return (5.25);
	    if(qty<=84) return (4.75);
	    if(qty<=144) return (4.50);
	    if(qty<=240) return (4.00);
	    if(qty<=499) return (3.75);
	    if(qty>=500) return (3.75);
	    break;
	  case 5:	// This is the Medium category.
	    if(qty<=48) return (5.75);
	    if(qty<=84) return (5.25);
	    if(qty<=144) return (5.00);
	    if(qty<=240) return (4.50);
	    if(qty<=499) return (4.25);
	    if(qty>=500) return (4.25);
	    break;
	  case 6:
	    if(qty<=48) return (7.00);
	    if(qty<=84) return (6.50);
	    if(qty<=144) return (6.00);
	    if(qty<=240) return (5.50);
	    if(qty<=499) return (5.00);
	    if(qty>=500) return (5.00);
	    break;
	  case 7:
	    if(qty<=48) return (8.75);
	    if(qty<=84) return (8.00);
	    if(qty<=144) return (7.25);
	    if(qty<=240) return (7.00);
	    if(qty<=499) return (6.25);
	    if(qty>=500) return (6.25);
	    break;
	  case 8:
	    if(qty<=48) return (10.75);
	    if(qty<=84) return (9.75);
	    if(qty<=144) return (9.00);
	    if(qty<=240) return (8.00);
	    if(qty<=499) return (7.75);
	    if(qty>=500) return (7.75);
	    break;
	  case 9:	// This is the Large category.
	    if(qty<=48) return (19.00);
	    if(qty<=84) return (18.00);
	    if(qty<=144) return (16.00);
	    if(qty<=240) return (14.00);
	    if(qty<=499) return (12.00);
	    if(qty>=500) return (10.00);
	    break;
	  case 10:
	    if(qty<=48) return (21.00);
	    if(qty<=84) return (19.00);
	    if(qty<=144) return (18.00);
	    if(qty<=240) return (16.00);
	    if(qty<=499) return (14.00);
	    if(qty>=500) return (12.00);
	    break;
	  case 11:
	    if(qty<=48) return (23.00);
	    if(qty<=84) return (21.00);
	    if(qty<=144) return (19.00);
	    if(qty<=240) return (18.05);
	    if(qty<=499) return (16.00);
	    if(qty>=500) return (15.00);
	    break;
	  default:
	    return 0;
	    break;
	}

    }

//-----------------------------------------------------------------------------------------

    function getPrice() {

     	// enter a dollar string, convert it, and apply the calculations.
	// return a dollar string.

        var price;
	 
	// Base Price
	price = Price * 1.10; // Add the base markup.

	// Add Imprint Cost 1
	  if(document.ndOrderForm.numimp.value>=1) {
	    price = price + getColourQty(document.ndOrderForm.colour1.value);
	  }
	  
	  // Add Imprint Cost 2
	  if(document.ndOrderForm.numimp.value>=2) {
	    price = price + getColourQty(document.ndOrderForm.colour2.value);
	  }
	  
	  // Add Imprint Cost 3
	  if(document.ndOrderForm.numimp.value>=3) {
	    price = price + getColourQty(document.ndOrderForm.colour3.value);
	  }
	  
	  // Add Imprint Cost 4
	  if(document.ndOrderForm.numimp.value>=4) {
	    price = price + getColourQty(document.ndOrderForm.colour4.value);
	  }

	// Add price modifiers
	price = price * document.ndOrderForm.quantity.value * 1.35;

	if(document.ndOrderForm.currency.checked) {
	  price = makeString(price);
	  gprice = price;
	  price = '$ ' + price + ' CDN';
	}	
	else {
	  price = price * 0.65;
	  price = makeString(price);
	  gprice = price;
	  price = '$ ' + price + ' US';
	}

	document.ndOrderForm.subtotal.value = price;
	return price;
    }

//-------------- Set the country -------------------------------------------------------------

    function setCountry() {
	if(top.MainFrame.document.ndQuantityForm.ctry.checked) {
	    top.USA = true;
	    alert('Prices shown in US dollars.');
	}
	else {
	    top.USA = false;
	    alert('Prices shown in Canadian dollars.');
	}
	top.calcTotals();
    }

//-------------- Set the country (no sizes) --------------------------------------------------

    function setCountryNoSizes() {
	if(top.MainFrame.document.ndQuantityForm.ctry.checked) {
	    top.USA = true;
	    alert('Prices shown in US dollars.');
	}
	else {
	    top.USA = false;
	    alert('Prices shown in Canadian dollars.');
	}
	top.calcTotalsNoSizes();
    }

//-------------- Set the country (Speciality) --------------------------------------------------

    function setCountrySpec() {
	if(top.MainFrame.document.ndQuantityForm.ctry.checked) {
	    top.USA = true;
	    alert('Prices shown in US dollars.');
	}
	else {
	    top.USA = false;
	    alert('Prices shown in Canadian dollars.');
	}
	top.calcSpecTotals();
    }


//-------------- Change the number of colours ------------------------------------------------

    function setClrs() {
	if(top.Areas.length > 0) { top.Areas[0][1] = top.MainFrame.document.ndQuantityForm.locClr0.selectedIndex+1; }
	if(top.Areas.length > 1) { top.Areas[1][1] = top.MainFrame.document.ndQuantityForm.locClr1.selectedIndex+1; }
	if(top.Areas.length > 2) { top.Areas[2][1] = top.MainFrame.document.ndQuantityForm.locClr2.selectedIndex+1; }
	if(top.Areas.length > 3) { top.Areas[3][1] = top.MainFrame.document.ndQuantityForm.locClr3.selectedIndex+1; }
	if(top.Areas.length > 4) { top.Areas[4][1] = top.MainFrame.document.ndQuantityForm.locClr4.selectedIndex+1; }
	if(top.Areas.length > 5) { top.Areas[5][1] = top.MainFrame.document.ndQuantityForm.locClr5.selectedIndex+1; }

	top.calcTotals();
    }

//-------------- Change the number of colours (no sizes specified) ---------------------------

    function setClrsNoSizes() {
	if(top.Areas.length > 0) { top.Areas[0][1] = top.MainFrame.document.ndQuantityForm.locClr0.selectedIndex+1; }
	if(top.Areas.length > 1) { top.Areas[1][1] = top.MainFrame.document.ndQuantityForm.locClr1.selectedIndex+1; }
	if(top.Areas.length > 2) { top.Areas[2][1] = top.MainFrame.document.ndQuantityForm.locClr2.selectedIndex+1; }
	if(top.Areas.length > 3) { top.Areas[3][1] = top.MainFrame.document.ndQuantityForm.locClr3.selectedIndex+1; }
	if(top.Areas.length > 4) { top.Areas[4][1] = top.MainFrame.document.ndQuantityForm.locClr4.selectedIndex+1; }
	if(top.Areas.length > 5) { top.Areas[5][1] = top.MainFrame.document.ndQuantityForm.locClr5.selectedIndex+1; }

	top.calcTotalsNoSizes();
    }

//-------------- End of Silkscreen Pricing Functions -----------------------------------------



//-------------- Change the number of stitches ------------------------------------------------

    function setStitches() {
	if(top.Areas.length > 0) { top.Areas[0][1] = top.MainFrame.document.ndQuantityForm.locClr0.value; }
	if(top.Areas.length > 1) { top.Areas[1][1] = top.MainFrame.document.ndQuantityForm.locClr1.value; }
	if(top.Areas.length > 2) { top.Areas[2][1] = top.MainFrame.document.ndQuantityForm.locClr2.value; }
	if(top.Areas.length > 3) { top.Areas[3][1] = top.MainFrame.document.ndQuantityForm.locClr3.value; }
	if(top.Areas.length > 4) { top.Areas[4][1] = top.MainFrame.document.ndQuantityForm.locClr4.value; }
	if(top.Areas.length > 5) { top.Areas[5][1] = top.MainFrame.document.ndQuantityForm.locClr5.value; }

	top.calcTotals();
    }

//-------------- Change the number of stitches (no sizes specified) ---------------------------

    function setStitchesNoSizes() {
	if(top.Areas.length > 0) { top.Areas[0][1] = top.MainFrame.document.ndQuantityForm.locClr0.value; }
	if(top.Areas.length > 1) { top.Areas[1][1] = top.MainFrame.document.ndQuantityForm.locClr1.value; }
	if(top.Areas.length > 2) { top.Areas[2][1] = top.MainFrame.document.ndQuantityForm.locClr2.value; }
	if(top.Areas.length > 3) { top.Areas[3][1] = top.MainFrame.document.ndQuantityForm.locClr3.value; }
	if(top.Areas.length > 4) { top.Areas[4][1] = top.MainFrame.document.ndQuantityForm.locClr4.value; }
	if(top.Areas.length > 5) { top.Areas[5][1] = top.MainFrame.document.ndQuantityForm.locClr5.value; }

	top.calcTotalsNoSizes();
    }

//-------------- End of Embroidery Pricing Functions -----------------------------------------


//--------------------------------------------------------------------------------------
//
// Routines for the search pages:
//	- Added 2005-02-17 -- JA-OCI
//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------
// Create a drop-down list dynamically:

function genSelect(name, id, select, onChangeStr) {

    var optStr = "";
    var arrObj = eval(name);
    
    for (var i=0; i<arrObj.length; i++) {
	optStr += '<OPTION VALUE="' + arrObj[i] +
	    (i == select ? '" SELECTED' : '"') + '>' + arrObj[i];
    }
    return '<SELECT NAME="' + id + '"' + (onChangeStr ? ' onChange="' + 
	onChangeStr + ';"' : '') + '>' + optStr + '</SELECT>';

}

//--------------------------------------------------------------------------------------
// Create a drop-down list dynamically:

function genSelect0(name, id, select, onChangeStr) {

    var optStr = "";
    var arrObj = eval(name);

    for (var i=0; i<arrObj.length; i++) {
	optStr += '<OPTION VALUE="' + arrObj[i][0] +
	    (i == select ? '" SELECTED' : '"') + '>' + arrObj[i][0];
    }
    return '<SELECT NAME="' + id + '"' + (onChangeStr ? ' onChange="' + 
	onChangeStr + ';"' : '') + '>' + optStr + '</SELECT>';

}

//--------------------------------------------------------------------------------------
// Create a drop-down list dynamically of only Silkscreen or Embroidery products:

function genSelectG(name, id, select, onChangeStr) {

    var optStr = "";
    var arrObj = eval(name);

    for (var i=0; i<arrObj.length; i++) {
	if(arrObj[i][7] != "Specialty") {
	   optStr += '<OPTION VALUE="' + arrObj[i][0] + (i == select ? '" SELECTED' : '"') + '>' + arrObj[i][0];
	}
    }
    return '<SELECT NAME="' + id + '"' + (onChangeStr ? ' onChange="' + 
	onChangeStr + ';"' : '') + '>' + optStr + '</SELECT>';

}



//======================================================================