// -----------------------------------------------------------------------------------------------
//
//	Copyright 2009, Orbital Guidance Industries, Ltd. (orbitalguidance.com), All rights reserved.
//
//	This work is provided under a royalty-free, non-exclusive license in perpetuity to
//	Port Authority (1portauthority.com).
//
// -----------------------------------------------------------------------------------------------

var PAapplyDiscount = new Class(
{
	options:
	{
		step2: null,
		step3: null,
		discountContainer: null,
		discount: null,
		locator: null,
		buy: null,
		checkContainer: null,
		checkContainer2: null,
		checkContainer3: null,
		checkContainer4: null,
		checkContainer5: null,
		paypalContainer: null,
		actionContainer: null,
		actionContainer2: null,
		fc: [
				'FOSZL2C', 'FOS73YK', 'FOS8KXC', 'FOS4YPB', 'FOSXA9G', 'FOSDXL5', 'FOSKTBX', 'FOSLXHG',
				'FOS7N78', 'FOS4GQL', 'FOSEP2Y', 'FOS48P7', 'FOS5R7X', 'FOS9EZ2', 'FOS2DVK', 'FOSDYQ1',
				'FOST7YL', 'FOSJ4KL', 'FOSKG4A', 'FOSDNQI', 'FOSQWDA', 'FOS72WH', 'FOSXUN9', 'FOSQ8NM',
				'FOSJ8PF', 'FOS8AF8', 'FOS6JML', 'FOSH3TM', 'FOSN28C', 'FOSCFE7', 'FOS3WEA', 'FOSJEQ4',
				'FOSLIMQ', 'FOSX97M', 'FOS56HE', 'FOSJ8UL', 'FOSZABQ', 'FOS8QRF', 'FOS9H82', 'FOSR5WG',
				'FOSZ7WV', 'FOSWDF4', 'APADCAUC', 'APA59YE', 'APA61RK', 'APA4AL6'
			]
	},
	
	initialize: function(options)
	{
		this.setOptions(options);

		this.options.discount.addEvents(
		{
			'keyup': function()
			{
				var dc = this.options.discount.value.clean().toUpperCase();
				
				switch (dc)
				{
//					case 'FOSOV':     { this.swapButtonCode('8144964',5); break; }
					case 'FOS666':    { this.swapButtonCode('2TX67BKYLFQKL',1); break; }
					case 'FOSOV':     { this.swapButtonCode('8244790',1); break; }
					case 'FOSTWEET':  { this.swapButtonCode('8244812',1); break; }
					case 'FOSLINKED': { this.swapButtonCode('8244830',1); break; }
					case 'FOSATL':    {	this.swapButtonCode('8408912',1); break; }
					case 'APAMEM':    {	this.swapButtonCode('8898516',3); break; }
					case 'APANEW':    {	this.swapButtonCode('8898545',3); break; }
					case 'APANON':    {	this.swapButtonCode('8898554',3); break; }
					case 'AAMEM':     {	this.swapButtonCode('8898566',4); break; }
					case 'AANON':     {	this.swapButtonCode('8898578',4); break; }
					case 'FOSPI':     {	this.swapButtonCode('9061240',1); break; }
					case 'FOSAPE':    {	this.swapButtonCode('9061356',1); break; }
					case 'FOSLE':     {	this.swapButtonCode('9061379',1); break; }
					case 'FOSSES':    {	this.swapButtonCode('9061394',1); break; }
					case 'FOS1PP':    {	this.swapButtonCode('9061452',1); break; }
					case 'FOSPMM':    {	this.swapButtonCode('9061477',1); break; }
					case 'FOSCH09':   {	this.swapButtonCode('9061435',1); break; } 
					case 'FOSCFI':	  {	this.swapButtonCode('11128408',1); break; } 
					case 'FOSHM':	  {	this.swapButtonCode('11268277',1); break; } 
					case 'FOSJH':	  {	this.swapButtonCode('11268340',1); break; } 
					case 'FOSRMO':	  {	this.swapButtonCode('MS7MCRBYHGNNU',1); break; }
					case 'FOSPC':	  {	this.swapButtonCode('656R2HWGKYKF8',1); break; }
					case 'FOSRETV':	  {	this.swapButtonCode('YAYGUHBSHTZFN',1); break; }
					case 'FOSFDL':	  {	this.swapButtonCode('762UQJXDACF4S',1); break; }

					default:
					{
						if (this.options.fc.contains(dc))
						{
							this.swapButton(dc);
						}
						
						break;
					}
				}
			}.bind(this)
		});
		
		this.options.discount.fireEvent('keyup');
	},
	
	swapButtonCode: function(value, msg)
	{
		this.options.buy.value = value;
		
		this.hideElement(this.options.checkContainer5);
		
		if (msg != 5)
		{
			this.hideElement(this.options.discountContainer);
		}
		
		var container;
		
		switch (msg)
		{
			case 1: { container = this.options.checkContainer1; break; }
			case 3: { container = this.options.checkContainer3; break; }
			case 4: { container = this.options.checkContainer4; break; }
			case 5: { container = this.options.checkContainer5; break; }
		}
		
		this.showElement(container);
	},
	
	swapButton: function(dc)
	{
		this.options.locator.value = dc;
		this.hideElement(this.options.discountContainer);
		this.showElement(this.options.checkContainer2);
		this.hideElement(this.options.paypalContainer);
		this.hideElement(this.options.actionContainer);
		this.showElement(this.options.actionContainer2);
	},
	
	hideElement: function(element)
	{
		element.setStyle('display', 'none');
	},
	
	showElement: function(element)
	{
		element.setStyle('display', 'block');
	}
});

PAapplyDiscount.implement(new Options, new Events);
