/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2011 Brand Labs LLC
 * 
 *--------------------------------------------------------------------------*/

var Confirmation = {
	ORDER_INFO_URL: '/v/custom-pages/asp/get_order.asp',
	TOP_HTML_TEMPLATE: '<div class="confirmation_top">You\'re all set! Your order has been placed. <br /> Your order number is: #{orderNum}</div>'
		+ '<div class="confirmation_middle">Below is a copy of your order information for your review. Thanks for shopping GAMAGO. You\'ll shortly be receiving an email copy of your order.<br /><br />If you have any questions, please contact us at <a href="mailto:customerservice@gamago.com">customerservice@gamago.com</a>.</div>',
		
	load: function(){
		try{
			Confirmation.ContentArea = $('content_area');
			if(Confirmation.ContentArea == undefined || Confirmation.ContentArea == null){
				return;
			}
			var urlHash = new Hash(location.href.toQueryParams());
			Confirmation.OrderId = urlHash.get('OrderID');
			if(Confirmation.OrderId == undefined || Confirmation.OrderId == null){
				return;
			}
		
			// Clear content area
			Confirmation.ContentArea.down('table').remove();
		
			// Add content to top of page
			var htmlTemplate = new Template(Confirmation.TOP_HTML_TEMPLATE);
			var html = htmlTemplate.evaluate({
				orderNum: Confirmation.OrderId
			});
			Confirmation.ContentArea.insert({
				bottom: html
			});
			
			// Get order details
			new Ajax.Request(Confirmation.ORDER_INFO_URL, {
				parameters: {
					orderId: Confirmation.OrderId,
					customerId: ''
				},
				method: 'post',
				onSuccess: function(transport) {
					try{
						Confirmation.ContentArea.insert({
							bottom: transport.responseText
						});						
					}catch(e){/*Ignore*/}
					
				},
				evalJS: false,
				evalJSON: false,
				encoding: 'windows-1252'
			});
			
		}catch(e){/*Ignore*/}
	}
};

try {
	document.observe('dom:loaded', function(){
		if(location.pathname.toLowerCase() == '/orderfinished.asp'){
			Confirmation.load();
		}
	});
} catch(e) {/*Ignore*/}
