
<!-- CODE for the NetMaster Online Store

// Populate Province/State Arrays {{{

provinces = new Array( 
	"Alberta",
	"British Columbia",
	"Manitoba",
	"New Brunswick",
	"Newfoundland",
	"Nova Scotia",
	"Nunavut",
	"Ontario",
	"Prince Edward Island",
	"Quebec",
	"Saskatchewan",
	"Yukon"
);	

states = new Array (
	"Alabama",
	"Alaska",
	"Arizona",
	"Arkansas",
	"California",
	"Colorado",
	"Connecticut",
	"District of Columbia",
	"Delaware",
	"Florida",
	"Georgia",
	"Hawaii",
	"Idaho",
	"Illinois",
	"Indiana",
	"Iowa",
	"Kansas",
	"Kentucky",
	"Louisiana",
	"Maine",
	"Maryland",
	"Massachusetts",
	"Michigan",
	"Minnesota",
	"Mississippi",
	"Missouri",
	"Montana",
	"Nebraska",
	"Nevada",
	"New Hampshire",
	"New Jersey",
	"New Mexico",
	"New York",
	"North Carolina",
	"North Dakota",
	"Ohio",
	"Oklahoma",
	"Oregon",
	"Pennsylvania",
	"Rhode Island",
	"South Carolina",
	"South Dakota",
	"Tennessee",
	"Texas",
	"Utah",
	"Vermont",
	"Virginia",
	"Washington",
	"West Virginia",
	"Wisconsin",
	"Wyoming"
);	
// }}}

// Define other variables and arrays {{{
prices = new Array(
	"124",		// GGOS1
	"134",		// GGOS2
	"524",		// GGBLADE
	"574",	 	// GGEXT
	"25",		// SHIPPING
	"124",  	// GGUPGRADEHW
	"124",  	// GGUPGRADESW
	"49",		// email, 1
	"99",		// email, 3
	"199",		// email, unlim
	"99",		// tel, 1
	"199",		// tel, 3
	"399"		// tel, unlim
);

productNames = new Array(
	"GG-OS (via download)",
	"GG-OS Retail",
	"GG-Blade",
	"GG-EXT",
	"Shipping",
	"Merilus FireCard Migration",
	"Merilus Gateway Guardian Migration",
	"Email Support (1 incident or 1 month)",
	"Email Support (3 incidents or 3 months)",
	"Email Support (Unlimited incidents for 1 year)",
	"Telephone Support (1 incident or 1 month)",
	"Telephone Support (3 incidents or 3 months)",
	"Telephone Support (Unlimited incidents for 1 year)"
);

shipping = 25.00;
shipping_per_addnl_item = 10.00;

shipping_added = false;

// }}}

function fillProvinceDropDown() { // {{{
	// Ok, check to see which Country we selected. If it is "International", 
	// then set State to "Other"

	// Nuke the fields in the Province/State dropdown
	var selectItem = document.storeForm.Province

	while( selectItem.length )
		selectItem.options[0] = null;

	loc = document.storeForm.Country.value;
	if( loc == "Canada" ) {
		for( var x=0; x<provinces.length; x++ ) {
			var option = new Option( provinces[x], provinces[x] );
			selectItem.options[x] = option;
			if( x == 1 ) {
				// lets default it to BC 
				selectItem.options[x].selected=true;
			}
		}
	}
	else if( loc == "USA" ) {
		for( var x=0; x<states.length; x++ ) {
			var option = new Option( states[x], states[x] );
			selectItem.options[x] = option;
		}
	}
	else {
		var option = new Option( "Other", "Other" );
		selectItem.options[0] = option;
	}

} // }}} 

function productDetect( product ) { // {{{

	var country = document.storeForm.Country.value
	var prov = document.storeForm.Province.value
	var taxAmt = parseFloat( 0.0 );
	var amount = document.storeForm.amount.value
	var taxes = parseFloat( 0.0 );

	if( product.name == "GGOS1" ) {
		amount = prices[0];
		document.storeForm.item_name.value = productNames[0];
	}
	else if( product.name == "GGOS2" ) {
		amount = prices[1];
		document.storeForm.item_name.value = productNames[1];
	}	
	else if( product.name == "GGBLADE" ) {
		amount = prices[2];
		document.storeForm.item_name.value = productNames[2];
	}	
	else if( product.name == "GGEXT" ) {
		amount = prices[3];
		document.storeForm.item_name.value = productNames[3];
	}	
	else if( product.name == "SHIPPING" ) {
		amount = prices[4];
		document.storeForm.item_name.value = productNames[4];
	}	
	else if( product.name == "GGUPGRADEHW" ) {
		amount = prices[5];
		document.storeForm.item_name.value = productNames[5];
	}	
	else if( product.name == "GGUPGRADESW" ) {
		amount = prices[6];
		document.storeForm.item_name.value = productNames[6];
	}	
	else if( product.name == "E1SUP" ) {
		amount = prices[7];
		document.storeForm.item_name.value = productNames[7];
	}	
	else if( product.name == "E3SUP" ) {
		amount = prices[8];
		document.storeForm.item_name.value = productNames[8];
	}	
	else if( product.name == "EUSUP" ) {
		amount = prices[9];
		document.storeForm.item_name.value = productNames[9];
	}	
	else if( product.name == "T1SUP" ) {
		amount = prices[10];
		document.storeForm.item_name.value = productNames[10];
	}	
	else if( product.name == "T3SUP" ) {
		amount = prices[11];
		document.storeForm.item_name.value = productNames[11];
	}	
	else if( product.name == "TUSUP" ) {
		amount = prices[12];
		document.storeForm.item_name.value = productNames[12];
	}	

	// If we have a $ at the front.. strip it {{{
	if( amount.substring( 0, 1 ) == '$' ) {
		amount = amount.substring( 1, amount.length );
	}
	// }}}

	// Initialize PayPal "Options" values....
	document.storeForm.on0.value = "";
	document.storeForm.os0.value = "";
	document.storeForm.on1.value = "";
	document.storeForm.os1.value = "";

	// Calculate tax amount, if any {{{
	if( country == "Canada" ) {
		taxAmt = 7;

		document.storeForm.on0.value = "NOTE";
		document.storeForm.os0.value = "GST has been added to the purchase price.";

		if( prov == "British Columbia" ) {
			taxAmt += 7.5;

			document.storeForm.on0.value = "NOTE";
			document.storeForm.os0.value = "GST and PST have been added to the purchase price.";
		}

		taxes = amount * ( taxAmt/100 );
	}

	if( product.name == "SHIPPING" ) {
		// There are no taxes on shipping....
		document.storeForm.on0.value = "";
		document.storeForm.os0.value = "";
		taxes = 0;
	}
	// }}}


	// Calculate total cost for this item {{{
	if( product.name == "GGBLADE" || product.name == "GGEXT" ) {
		amount = parseFloat( amount, 10 ) + taxes;
	}
	else if( product.name == "SHIPPING" ) {
		amount = parseFloat( amount, 10 );
	}
	else {
		amount = parseFloat( amount, 10 ) + taxes;
	}	
	// }}}

	document.storeForm.amount.value = cent( roundCurrency( amount ) );


	// Ok... submit to PayPal
	document.storeForm.submit();

	// Add Shipping charge, if necessary.... {{{
	if( product.name == "GGBLADE" || product.name == "GGEXT" ) {
		// Has shipping already been added?  (The $25 charge.)
		if( shipping_added == false ) {
			pause(3000);	// Must wait a bit, otherwise PayPal ignores first submit.
			document.storeForm.os0.value = "Shipping is required for an order containing a GG-Blade or GG-EXT device.";
			addShippingCharge( shipping );
			shipping_added = true;
		}
		// Else just add the $10 charge.
		else {
			pause(3000);	// Must wait a bit, otherwise PayPal ignores first submit.
			document.storeForm.os0.value = "Extra shipping charge ($10 per additional GG-Blade or GG-EXT)";
			addShippingCharge( shipping_per_addnl_item );
		}
	}
	// }}}
	
} // }}}

function roundCurrency( value ) { // {{{
	return Math.round( value*Math.pow( 10, 2 ) )/Math.pow( 10, 2 );
} // }}}

function cent( amount ) { // {{{
// returns the amount in the .99 format
	amount -= 0;
	return (amount == Math.floor(amount)) ? 
				amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
} // }}}

function addShippingCharge( charge ) { // {{{

	document.storeForm.on0.value = "NOTE";
	document.storeForm.item_name.value = productNames[4];
	document.storeForm.amount.value = charge;

	document.storeForm.submit();


} // }}}

function pause(numberMillis) { // {{{
	/*	A (bad) pause function to 'stop' program execution for a specified
		number of milliseconds.   NOTE:  This uses a busy-wait loop and, 
		therefore, is not 'nice'.  But, it works....
	*/

	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime) return;
	}
}
// }}}

-->
