/* ASC.Chrysler.BMO.Disclaimer
*
* */
ASC.namespace('ASC.Chrysler.BMO.Disclaimer');
ASC.Chrysler.BMO.Disclaimer = ASC.extend(Ext.util.Observable, {
	window: null,
	contextPath: null,	
	
	constructor: function (context)
	{
		this.contextPath = context;
		ASC.Chrysler.BMO.Disclaimer.superclass.constructor.apply(this);
	},
	
	initWindow: function ()
	{
		var windowId = Ext.id();
		var html = '<iframe src="' + this.contextPath + '/bmo/pricingDisclosure.do?hideClose=true" style="border: none;width:100%;height:100%;" id = "disclaimerFrame" name="disclaimerFrame" frameborder="0"></iframe>';
		
		this.window = new Ext.Window({
			id: windowId,
			cls: '',
			title: 'Disclaimer',
			closable: true,
			draggable: false,
			header:true,
			width: 600,
			height: 290,			
			modal: true,
			resizable: false,
			plain: true,			
			layout: 'fit',
			border: false,
			items: {
				html: html,
				border: false
			}
		});
		this.window.on('hide',this.trackLinkMetrics,this);
	},
	
	trackLinkMetrics: function(){
		ASC.Chrysler.trackLinkMetrics('info_content','close_info_legal');
	},
	
	show: function ()
	{
		if(this.window==null){
			this.initWindow();
		}
		this.window.show();	
	}	
});

/*
 * ASC.Chrysler.BMO.ExpandImage
 * */
 
ASC.namespace('ASC.Chrysler.BMO.ExpandImage');
ASC.Chrysler.BMO.ExpandImage = ASC.extend(Ext.util.Observable, {
	
	window: null,
	widthPadding: 12,
	heightPadding: 16,
	
	constructor: function ()
	{
		ASC.Chrysler.BMO.ExpandImage.superclass.constructor.apply(this);		
	},
		
	initWindow: function (imgName, width, height)
	{
		var windowId = Ext.id();		
		var html = '<img src="'+ ASC.cfg.getIofUrl() + imgName + '&width='+width+'&height='+height+'&NOIMG=CC_NOIMAGE_W.jpg" width="'+width+'" height="'+height+'" />';
		var windowWidth = width + this.widthPadding;
		var windowHeight = height + this.heightPadding;		
		this.window = new Ext.Window({
			id: windowId,
			cls: '',
			title: '',
			closable: true,
			header:true,
			width: windowWidth,
			height: windowHeight,
			modal: true,
			resizable: false,
			plain: true,
			layout: 'fit',
			border: false,
			items: {
				html: html,
				border: false
			}		
		});		
		this.window.on('hide',this.destroyWindow,this);			
	},
	
	show: function (imgName, width, height)
	{
		this.initWindow(imgName, width, height);
		this.window.show();
	
	},
	destroyWindow: function ()
	{
		this.window.destroy();
		delete this.window;
	}
});

/*
 * ASC.Chrysler.BMO.VehicleTally
 * */
ASC.namespace('ASC.Chrysler.BMO.VehicleTally');
ASC.Chrysler.BMO.VehicleTally= ASC.extend(Ext.util.Observable,{
	
	renderTo:null,
	tallyData:null,
	
	
	constructor: function (tallyData,cfg)
	{
		ASC.Chrysler.BMO.VehicleTally.superclass.constructor.apply(this);
		ASC.apply(this, cfg);
	
		this.addEvents({"render":true});
		this.initTemplates();
		this.loadData(tallyData);
	},
	
	loadData:function(tallyData)
	{
		this.tallyData = tallyData;
		this.render();
	},
	
	render:function()
	{
		var ob = this.tallyData;
		this.widgetTpl.overwrite(this.renderTo, [ob.base.msrp,ob.selectedOptions.msrp,
		                                         ob.destination,ob.accessories.msrp,
		                                         ob.total.msrp]);		
		this.fireEvent("render");
	},
	
	initTemplates: function ()
	{
			this.widgetTpl = new Ext.XTemplate( 
			'<table class="right_desc_money" border="0" cellpadding="0" cellspacing="0">',
	            '<tr>',
	              	'<td class="left_item">{[this.translate("bmo_base")]}</td>',
	                '<td class="right_item">${0}</td>',
	            '</tr>',
	            '<tr>',
	                '<td class="left_item">',
						'<span class="right_package_blackbold">{[this.translate("bmo_selecttions")]}</span>',
						'<span class="right_package_underline" id="view_my_selections">',
							'<a href="javascript:Page.viewMySelections();">{[this.translate("bmo_show")]}</a>',
						'</span>',
					'</td>',
	                '<td class="right_item">${1}</td>',
	            '</tr>',
	            '<tr>',
	            	'<td colspan="2">',
	            		'<span id="my_selected_options"></span>',
	            	'</td>',
	            '</tr>',
	            '<tr>',
	               	'<td class="left_item">{[this.translate("bmo_destination")]}</td>',
	                '<td class="right_item">${2}</td>',
	            '</tr>',
	            '<tr>',
	            	'<td class="left_item">{[this.translate("bmo_combined")]}<img src="' + ASC.cfg.getImgLocalePath() + '/bmo/bodycontainer_icon_09.gif" /></td>',
	                '<td class="right_item">${3}</td>',
	            '</tr>',
	            '<tr>',
	                '<td class="right_package_item_name_netprice">{[this.translate("bmo_net")]}</td>',
	                '<td class="right_package_item_name_netprice_x1">${4}</td>',
	            '</tr>',
	            '<tr>',
	                '<td class="left_item">{[this.translate("bmo_estimated")]}</td>',
	                '<td class="right_item">',
						'<a href="javascript:void(0);">{[this.translate("bmo_calculate")]}</a>',
					'</td>',
	            '</tr>',
	       '</table>',
    		{
				translate: function (key)
				{
					return ASC.message(key);
				}
    		}
			);
			
			this.widgetTpl.compile();
			//this.vehicleTallyTemplate.append(this.renderTo,[this.tallyData.XXX],false);
	},
	update:function(tallyData)
	{
		if(tallyData)
		{
			this.loadData(tallyData);
			this.render();
		}
	}
});

ASC.namespace('ASC.Chrysler.BMO.GroupingStore');

ASC.Chrysler.BMO.GroupingStore = ASC.extend(Ext.data.GroupingStore, {
	
	updateData: function (data)
	{
		ASC.forEach(data.options, function (option, index) {
			var optRecord = this.getById(option.optCode);
			if (!optRecord) { return; }
			
			optRecord.set('state', option.state);
			optRecord.set('msrpFormatted', option.msrpFormatted);
			optRecord.set('contentList', option.contentList);
			
			optRecord.commit(true);
			
		}, this);
		
		
		this.fireEvent('datachanged', this);
	}
	
});

ASC.namespace('ASC.Chrysler.BMO.OptionsGrid');

(function () {

ASC.Chrysler.BMO.OptionsGrid = ASC.extend(Ext.grid.GridPanel, {
	
	configCfg: null,
	stateTpl: null,
	stateNoClickTpl: null,
	grid: null,
	
	showSwatch: false,
		
	constructor: function (cfg, configData)
	{	
			
		ASC.apply(this, cfg);
		var me = this;
				
		this.initTemplates();
		
		Ext.QuickTips.init();
    
		var xg = Ext.grid;
		
		var optionRecord = Ext.data.Record.create([		    
		    {name: 'header'},
		    {name: 'optCode'},
		    {name: 'level'},
		    {name: 'state'},
		    {name: 'msrpFormatted'},
		    {name: 'invoiceFormatted'},
		    {name: 'userFormatted'},
		    {name: 'description'},
		    {name: 'note'},
		    {name: 'hasContent'},		    
		    {name: 'extendedDesc'},
		    {name: 'contentList'}
		]);
		
	    var reader = new Ext.data.JsonReader({
	    	root: 'options',
	    	id: 'optCode'
	    }, optionRecord);
		
		var store = new ASC.Chrysler.BMO.GroupingStore({
            reader: reader,
            data: configData,			            
            sortInfo:{field: 'header', direction: "ASC"},
            remoteSort: true,
            groupField:'header'
       	});
       	
       	store.filterBy(function (record, id) {
			var emissionsOptCodes = new Array("NAA", "NAE", "NAS", "YCH",
       	            "YCF");
       		for(var i=0; i< emissionsOptCodes.length; i++)
       		{
       			if(record.data.optCode.toUpperCase() == emissionsOptCodes[i])
       				return false;
       		}
       		return record.data.optCode !== 'HEADER';
       	});
		
		/* Setup ASCRowExpander and Column Renderer */
		var expander = new xg.ASCRowExpander({
			tpl: me.extendedOptionDescriptionTpl			
		});		
		
		var optionDescRenderer = function (value, metadata, record, rowIndex, colIndex, store)
		{
			var d = record.data;
			if (!d.hasContent) {
				return value;
			}
			return me.optionDescriptionTpl.apply({value: value, href: 'javascript:void(0);'});
		};
		
		var configStateIconRenderer = function (value, metadata, record, rowIndex, colIndex, store)
		{
			return me.stateTpl.applyTemplate({
				state: value, 
				optCode: record.data.optCode,
				showExtTooltip: ('C' === value),
				desc: record.data.description
			});
		};
		
		var msrpRenderer = function (value, metadata, record, rowIndex, colIndex, store)
		{
			var d = record.data;
			//alert(d.msrpFormatted);
			if( d.msrpFormatted == 'onlyAvailableInContent' ){
				value = '<a href="javascript:ASC.Chrysler.trackLinkMetrics(\'content\',\'get_pricing_info\');Page.selectOption(\''+ d.optCode + '\');">'+ASC.message("bmo_onlyAvailableInContent")+'</a>';
			}
			return value;
		};
		
		var columns = [
			expander,
	       	{header: "&nbsp;", width: 32, sortable: false, dataIndex: 'state', renderer: configStateIconRenderer},
	       	{header: 'Header', width: 0, sortable: false, dataIndex: 'header'}, 
	        {id: 'configDescriptions', header: 'Description', width: 500, sortable: false, dataIndex: 'description', renderer: optionDescRenderer},	        
	        {header: 'MSRP*', width: 150, sortable: false, dataIndex: 'msrpFormatted', renderer: msrpRenderer, align: 'right'},
	        {header: 'spacer', width: 5, sortable: false, dataIndex: '' }	        	   
		];
		
		var view = new Ext.grid.GroupingView({
        	forceFit: false,
        	hideGroupedColumn: true,
			showGroupName: false,
			autoScroll: true,
			startGroup: this.startGroupTpl  								        	
       	});
				
		var gridCfg = {
			store: store,
			columns: columns,
			view: view,
			
			hideHeaders: true,
	        enableHdMenu: false,
	        title: '',
	        frame: false,
	        border: false,
	        width: 685,
	        autoHeight: true,
	        collapsible: false,
	        trackMouseOver: false,
	        stripeRows: false,
			
			renderTo: (this.renderTo ? this.renderTo : undefined),
			plugins: expander
		};
		
	
		ASC.Chrysler.BMO.OptionsGrid.superclass.constructor.call(this, gridCfg);
		
		//Make sure the user cannot select a row
		this.selModel.on('beforerowselect', function () { return false; });
	},
	
	initTemplates: function ()
	{		
		if (!this.startGroupTpl) {
			this.startGroupTpl = new Ext.XTemplate(
				'<div id="{groupId}" class="x-grid-group">',
					'<div id="{groupId}-hd" class="a-xgrid3-group" style="">',
				   		'<table class="" border="0" cellpadding="0" cellspacing="0">',
				    		'<tr>',
				    			'<th style="text-align:left;">{text}</th>',
				    		'</tr>',
				    	'</table>',
					'</div>',
					'<div id="{groupId}-bd" class="">'
			);
			this.startGroupTpl.compile();
		}
		
		if (!this.optionDescriptionTpl) {			
			this.optionDescriptionTpl = new Ext.XTemplate('<span class = "gridDescription">{value}</span> ',
				'<img class="x-grid3-asc-row-expander" src="' + ASC.cfg.getImgLocalePath() +  '/bmo/bodycontainer_icon_09.gif" onclick="ASC.Chrysler.trackLinkMetrics(\'info_content\',\'{[this.metricsCleaner(values.value)]}\');" />',				
				'<span onmousedown="javascript:ASC.Chrysler.trackLinkMetrics(\'info_content\',\'close_{[this.metricsCleaner(values.value)]}\');"class="a-xgrid3-extOptionClose"><a class="x-grid3-asc-row-expander" href="javascript:void(0);">Close</a></span>', {
					metricsCleaner: function(str)
					{
						if (typeof str !== 'string') { str = str.toString(); }
						return str.replace(/\//g,"_")
								  .replace(/[^a-zA-Z0-9,\s,+,-,_]/g,'')
								  .replace(/[\s+]/g,"_")
								  .toLowerCase();	
					}
				}
			);
			this.optionDescriptionTpl.compile();
		}
		
		if (!this.extendedOptionDescriptionTpl) {
			this.extendedOptionDescriptionTpl = new Ext.XTemplate(
				'<tpl if="this.displayExtended(extendedDesc)">',
					'<div class="a-xgrid3-extendedDesc">{extendedDesc}</div>',
				'</tpl>',
				'<tpl if="this.hasContentList(contentList)">',
					'<div class="a-xgrid3-optionContent">',
						'<label class="">{[this.translate("bmo_included")]}</label>',
						'<ul class="a-xgrid3-contentList">',
							'<tpl for="this.getContentList(contentList)">',
								'<li>{description}',
									'<tpl if="extendedDesc">',
										'    <a href="javascript:Page.gridDisplayInfo(\'{parent.optCode}_{values.code}\');" id="extended_desc_icon_{parent.optCode}_{values.code}" class="extdesc_infoIcon"><img src="' + ASC.cfg.getImgLocalePath() +  '/bmo/bodycontainer_icon_09.gif"/></a>',
										'  <a href="javascript:Page.gridCloseInfo(\'{parent.optCode}_{values.code}\');" id="extended_desc_close_{parent.optCode}_{values.code}" class="extdesc_closebtn_hide a-xgrid3-extOptionClose">Close</a>',
										'<div id="extended_desc_text_{parent.optCode}_{values.code}" style="display:none" class="a-xgrid3-contentItem_extDesc">{extendedDesc}</div>',					
									'</tpl>',
								'</li>',
							'</tpl>',
						'</ul>',
					'</div>',
				'</tpl>'
				,{
					hasContentList: function(contentList){
						if( contentList != null && contentList.length > 0 ){
							return true;
						}
						return false;
					},
					
					displayExtended: function(extendedDesc){
						return extendedDesc!=null && extendedDesc.length > 0
					},
					
					translate: function (key)
					{
						return ASC.message(key);
					},
					
					getContentList: function( contentList ){
						var flatContentList = [];
						for( i=0; i<contentList.length; i++ ){
							var contentItem = contentList[i];
							flatContentList.push(contentItem);
							if( contentItem.contentList != null && contentItem.contentList.length > 0){
								for(k=0; k<contentItem.contentList.length; k++){
									flatContentList.push(contentItem.contentList[k]);
								}
							}
						}
						return flatContentList;
					}					
				}
			);
			this.extendedOptionDescriptionTpl.compile();
		}
		
		if (!this.stateTpl) {			
			this.stateTpl = new Ext.XTemplate('<span class="a-xgrid3-stateIco"><a href="javascript:ASC.Chrysler.trackLinkMetrics(\'options\',\'{[this.metricsCleaner(values.desc)]}\');Page.selectOption(\'{optCode}\');"><img src="' + 
				ASC.cfg.getImgPath() + 
				'/bmo/bodycontainer_icon_{state}.gif" alt="" <tpl if="showExtTooltip">ext:qtip="' + ASC.message('bmo_tipRequireChanges') + '"</tpl> /></a></span>',
				{
					metricsCleaner: function(str)
					{
						if (typeof str !== 'string') { str = str.toString(); }
						return str.replace(/[^a-zA-Z0-9,\s,+,-,_]/g,'').replace(/[\s+]/g,"_").toLowerCase();	
					}				
				}
			);	
			this.stateTpl.compile();
		}
		
		/*
		if (!this.stateNoClickTpl) {
			this.stateNoClickTpl = new Ext.Template('<img src="' + ASC.cfg.getImgPath() + '/configurator/configState_{state}.gif" alt="" />');
			this.stateNoClickTpl.compile();
		}
		*/		
	},
	
	updateOptions: function (configResponse) {
		this.getStore().updateData(configResponse);
		
		//Go through the rows and see if there are any rows there are supposed to be open
		
		var expander = this.plugins;		
		var view = this.getView();
		
		for (var i=0; i<this.getStore().totalLength; i++) {
			var row = view.getRow(i);
			
			//When caching is turned off on the ASCRowExpander the extended 
			//content will get updated in the grid however the grid closes 
			//any expanded rows therefore if we check for any rows that have the
			//css class that indicates the row is supposed to be expanded we can
			//force it open
			if (row && row.className.indexOf('x-grid3-row-expanded') !== -1) {
				expander.expandRow(i);
			}
		}
		
		
		var a=1;
		
	}
	
});
				
})();


/*
 * ASC.Chrysler.BMO.SelectedOptions
 * */
ASC.namespace('ASC.Chrysler.BMO.SelectedOptions');
ASC.Chrysler.BMO.SelectedOptions= ASC.extend(Ext.util.Observable,{
	
	renderTo:null,
	tallyData:null,
	
	constructor: function (cfg)
	{
		ASC.Chrysler.BMO.SelectedOptions.superclass.constructor.apply(this);

		ASC.apply(this, cfg);
		this.addEvents({"render":true});
		this.initTemplates();
		//this.loadData(selectedOptions);
	},
	
	loadData:function(selectedOptions)
	{
		this.selectedOptions = selectedOptions;
		this.render();
	},
	
	render:function()
	{
		this.widgetTpl.overwrite(this.renderTo, {options:this.selectedOptions});		
		this.fireEvent("render");
	},
	
	initTemplates: function ()
	{
			this.widgetTpl = new Ext.XTemplate( 
				'<table border="0" cellpadding="0" cellspacing="0" class="selected_options">',
					'<tpl for="options">',
		            	'<tr>',
		              		'<td class="item_name">{description}</td>',
		                	'<td class="item_price">{[this.getDisplayMsrp(values.msrpFormatted)]}</td>',
		            	'</tr>',
		            '</tpl>',
		        '</table>',
		        {
			        getDisplayMsrp:function(msrpFormatted){
			        	if( msrpFormatted == "onlyAvailableInContent" ){
			        		return ASC.message('bmo_summary_onlyAvailableInContent');
			        	}else{
			        		return msrpFormatted;
			        	}
			        }
		        }
			);
			
			this.widgetTpl.compile();
	},
	update:function(selectedOptions)
	{
		if(selectedOptions)
		{
			this.loadData(selectedOptions);
			this.render();
		}
	}
});

	ASC.namespace('ASC.Chrysler.BMO.CombinedIncentives');
	ASC.Chrysler.BMO.CombinedIncentives= ASC.extend(Ext.util.Observable,{
	
	renderTo:null,
	incentivesData:null,
	constructor: function (incentivesData, incentivesCategory, cfg)
	{
	
		ASC.Chrysler.BMO.CombinedIncentives.superclass.constructor.apply(this);
		ASC.apply(this, cfg);
	
		this.addEvents({"render":true});
		this.initTemplates();
		this.loadData(incentivesData, incentivesCategory);
		},
		
		calculateSubTotal: function( incentives ){
			var s = 0;
			for(i=0; i<incentives.length; i++ ){
				if( incentives[i].incentiveType != 'SCB' ){
					s += incentives[i].programCashValue;
				}
			}
			return s;
		},
		
		getIncentivesByCategory: function( incentives, incentivesCategory ){
			var incentivesList = [];
			for(i=incentives.length-1; i>=0; i--){
				if( incentives[i].incentiveCategory == 'A' || incentives[i].incentiveCategory == incentivesCategory){
					incentivesList.push(incentives[i]);
				}
			}
			return incentivesList;
		},
		
		loadData:function(incentivesData, incentivesCategory)
		{
			var subtotal = this.calculateSubTotal(incentivesData);
			this.incentivesData = {
						incentives:incentivesData,
						total: subtotal,
						hasIncentives: incentivesData != null && incentivesData.length > 0,
						incentivesCategory: incentivesCategory
			};

			this.render();
		},
		render:function()
		{
			this.widgetTpl.overwrite(this.renderTo, {incentives:this.incentivesData.incentives, 
													 total:this.incentivesData.total, 
													 hasIncentives: this.incentivesData.hasIncentives, 
													 incentivesCateg:this.incentivesData.incentivesCategory});		
			this.fireEvent("render");
		},
		initTemplates: function ()
		{
			this.widgetTpl = new Ext.XTemplate(	 
			'<div id="incentives_list" class="incentives_list_div">',
				'<table class="incentives_table" border="0" cellpadding="0" cellspacing="0">',
						'<tr>',
							'<td class="tally_incentives_header">',
								'<input type="radio" id="purchase_incentivesOffer" name="incentivesOffer" {[this.isPurchase(values.incentivesCateg)?"checked":""]} onClick="javascript:Page.selectIncentiveCategory(\'P\');">',
							'</td>',
							'<td class="tally_incentives_header">',
								'<label for="purchase_incentivesOffer">Purchase Offer</label>',
							'</td>',
							'<td class="tally_incentives_header">',
								'<input type="radio" id="lease_incentivesOffer" name="incentivesOffer" {[!this.isPurchase(values.incentivesCateg)?"checked":""]} onClick="javascript:Page.selectIncentiveCategory(\'L\');">',
							'</td>',
							'<td class="tally_incentives_header">',
								'<label for="lease_incentivesOffer">Lease Offer</label>',
							'</td>',
						'</tr>',
					'<tpl if="!hasIncentives">',	
						'<tr>',
							'<td colspan="2" class="item_name_incentive">',
								'Current Incentives $0',
							'</td>',
						'</tr>',
					'</tpl>',
				'</table>',
				'<table class="incentives_table" border="0" cellpadding="0" cellspacing="0">',
					'<tpl for="incentives">',
						'<tr>',
							'<td class="item_name_incentive">{programName}',
							/*'<tpl if="this.isLeaseLoyaltyCash(incentiveType)"> **</tpl>',
							'<tpl if="this.isCFBonusCash(incentiveType)"> *</tpl>',*/
							'<tpl if="this.isOwnerLoyalty(incentiveType)"> ***</tpl>',
							'<tpl if="this.isGMACBonusCash(incentiveType)"> *****</tpl>',
							/*'<tpl if="this.isSegmentConquestBonus(incentiveType)"> ****</tpl>',*/
							'</td>',
							'<td class="incentive_price">-{[ASC.util.formatCurrency(values.programCashValue, 0)]}</td>',
						'</tr>',
					'</tpl>',
				'</table>',
			'</div>',
			{
				isLeaseLoyaltyCash:function(incentiveType)
				{
					if(incentiveType=='LLC'){
						return true;
					}
					return false;
				},
				
				isCFBonusCash:function(incentiveType)
				{
					if(incentiveType=='CFB'){
						return true;
					}
					return false;
				},
				
				isOwnerLoyalty:function(incentiveType)
				{
					if(incentiveType=='OTY'){
						return true;
					}
					return false;
				},
				
				isGMACBonusCash:function(incentiveType)
				{
					if(incentiveType=='GMA'){
						return true;
					}
					return false; 
				},
				
				isSegmentConquestBonus:function(incentiveType)
				{
					if(incentiveType=='SCB'){
						return true;
					}
					return false;
				},
				
				translate: function (key)
				{
					return ASC.message(key);
				},
				
				hasIncentives: function( incentives ){
					return (incentives != null && incentives.length > 0);
				},
				
				formatTotal: function( value ){
					var fTotal = ASC.util.formatCurrency(value, 0);
					if( parseFloat(value) != 0 ){
						fTotal = '-'+fTotal;
					}
					return fTotal;
				},
				
				isPurchase: function( incentivesCateg ){
					return incentivesCateg == 'P'
				}
			}
			);
		
			this.widgetTpl.compile();

	},
	update:function(incentivesData, incentivesCategory)
	{
		if(incentivesData)
		{
			this.loadData(incentivesData, incentivesCategory);
			this.render();
		}
	}
});

ASC.loadBundle({
    locale: 'en_US',
    
    messages: {        
        'optionsGrid_included':'Included'	        
    }
});


/*
 * ASC.Chrysler.BMO.PaymentEstimator
 * */
ASC.namespace('ASC.Chrysler.BMO.PaymentEstimator');
ASC.Chrysler.BMO.PaymentEstimator = ASC.extend(Ext.Window, {
	
	id: '',
	/**
	 * @param {Object} cfg Window configurator parameters that are passed on to Ext.Window
	 */
	constructor: function (cfg)
	{	
		//this.initDlgTemplates();		
		
		var html = '<div id="objPaymentEstimator_container">' +
			'<div style="text-align:center; margin:5px;">' +
				'<h5>Adobe Flash Player is required to use the Payment Estimator</h5>' +							
				'<div style="padding: 5px 0 20px 0;">We have detected that you do not have Adobe Flash Player installed.</div>' +
				'<p>Please install Adobe Flash Player <a href="http://www.adobe.com/go/getflashplayer" title="Install Adobe Flash Player"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>' +
			'</div>' +
		'</div>';
	
		var winCfg = ASC.apply({			
			closeAction: 'hide',
			headerAsText: false,
			closable: true,
			plain: false,
			layout: 'fit',
			modal: true,
			constrainHeader: true,
			border: false,
			modal: true,
			resizable: false,
			width: 522,
			height:this.getWindowHeight(),
			frame:true,
			hideBorders:true,
			pageX:200,
			pageY:30,
					
			items: {
				html: html
			}
			
		}, cfg);				
				
		ASC.Chrysler.BMO.PaymentEstimator.superclass.constructor.call(this, winCfg);
		
		var me = this;
		this.on('beforeshow', function () {			
			if (!me.initializedFlash) {
				var swfUrl = ASC.cfg.getFinancialUrl() + 'paymentestimator/paymentestimator.swf';
				var so = new SWFObject(swfUrl, 'objPaymentEstimator', '510', '567', '9.0.47', '#869ca7', 'high');
				so.addVariable('host', ASC.cfg.getFinancialUrl());
				so.addVariable('mode', 'integrated')
				so.addVariable('cobrand', ASC.cfg.getTheme());
				so.addVariable('loadComplete', 'Page.setPaymentEstParams');
				so.useExpressInstall(ASC.cfg.getContextPath() + '/resources/js/swf/expressinstall.swf');
				
				so.addParam('movie', swfUrl);
				so.addParam('allowScriptAccess', 'always');
				
				so.write("objPaymentEstimator_container");
				
				me.initializedFlash =true;
			}
			
		}, me);
			
	},
	
	getPayment: function ()
	{
		return this.getFlexDom().getPayment();
	},
	
	updateParams: function (params)
	{
		return this.getFlexDom().updateParams(params);
	},
	getFlexDom: function ()
	{
		return ASC.getEl('objPaymentEstimator').dom;
		/*
		if(Ext.isIE){
			return ASC.getEl('objPaymentEstimator').dom
		}else{
			return ASC.getEl('objPaymentEstimator').dom
		}*/
	},
	
	getWindowHeight:function(){
		if(Ext.isIE || Ext.isIE7){
			return 595;
		}
		return 580;
	}
});

//this is displayed in the vehicle tally
ASC.namespace('ASC.Chrysler.BMO.EstimatedPayment');
ASC.Chrysler.BMO.EstimatedPayment= ASC.extend(Ext.util.Observable,{
	
	renderTo:null,
	paymentData:null,
	
	constructor: function (paymentData, cfg)
	{
	
		ASC.Chrysler.BMO.EstimatedPayment.superclass.constructor.apply(this);
		ASC.apply(this, cfg);
	
		this.addEvents({"render":true});
		this.initTemplates();
		this.loadData(paymentData);
	},
		
	loadData:function(paymentData)
	{
		this.paymentData = {
			monthlyPayment: paymentData == null ? -1 : paymentData.monthlyPayment,
			term: paymentData == null ? -1 : paymentData.term,
			apr: paymentData == null ? -1 : paymentData.apr
		};
		this.render();
	},
		
	render:function()
	{
		this.widgetTpl.overwrite(this.renderTo, {monthlyPayment: this.paymentData.monthlyPayment,
												 term: this.paymentData.term,
												 apr: this.paymentData.apr
												});		
		this.fireEvent("render");
	},
	
	initTemplates: function ()
	{
		this.widgetTpl = new Ext.XTemplate(		 
			'<table class="right_desc_money" border="0" cellpadding="0" cellspacing="0">',
				'<tr>',
//					'<td class="left_item"><label class="estimatedPayment_bold">{[this.translate("bmo_estimatedPayment")]}</label>',
//						'<tpl if="monthlyPayment != -1">',
//							' <a id="paymentEditLink" class="editPayment" href="javascript:ASC.Chrysler.trackLinkMetrics(\'content\', \'edit_estimated_payment\');Page.displayPayment();">{[this.translate("bmo_edit")]}</a>',
//						'</tpl>',
//					'</td>',
//					'<tpl if="monthlyPayment === -1">',
//						'<td class="right_item"><a href="javascript:ASC.Chrysler.trackLinkMetrics(\'content\', \'calculate\');Page.displayPayment();" id="calculateBtn">{[this.translate("bmo_calculate")]}</a></td>',
//					'</tpl>',
//					'<tpl if="monthlyPayment != -1">',
//						'<td class="right_item" ><label class="estimatedPayment_bold">{[this.formatCurrency(values.monthlyPayment)]}</label></td>',
//					'</tpl>',					
//				'</tr>',
//				'<tpl if="monthlyPayment != -1">',
//					'<tr>',
//						'<td colspan="2" id="paymentPeriod">',
//							'{[this.translate("bmo_paymentPurchase")]} {apr}% {[this.translate("bmo_paymentFor")]} {term} {[this.translate("bmo_paymentMonths")]}', 
//						'</td>',
//					'</tr>',
//				'</tpl>',
			'</table>',
			{
				translate: function (key)
				{
					return ASC.message(key);
				},
				
				formatCurrency: function( value ){
					return ASC.util.formatCurrency(value, 0);
				}
			}
		);
	
		this.widgetTpl.compile();

	},
	update:function(paymentData)
	{
		this.loadData(paymentData);
		this.render();
	}
});

ASC.namespace('ASC.Chrysler.BMO.ViewAllMakeTrims');
ASC.Chrysler.BMO.ViewAllMakeTrims = ASC.extend(Ext.util.Observable, {
	
	window: null,
	bmoPageName:null,
	constructor: function ( bmoPageName )
	{
		this.bmoPageName = bmoPageName;
		ASC.Chrysler.BMO.ViewAllMakeTrims.superclass.constructor.apply(this);		
	},
		
	initWindow: function (windowHtml)
	{
		var me = this;
		var windowId = Ext.id();
		var html = '<iframe src="' + ASC.cfg.getContextPath() + '/vsmc/vehicleSpecModels.do?modelYearCode='+Page.modelYearCode+'&popup=true&pageId=2&bmoTabName='+this.bmoPageName+'&ccode='+Page.ccode+'&llp='+Page.llp+'" style="width:100%; height:100%; border: none;" id = "viewAllMakeTrimsFrame" name="viewAllMakeTrimsFrame" frameborder="0"></iframe>';

		var btnClose = new Ext.Button({
			id: 'btnClose',
			text: ASC.message('bmo_close'), 
			cls: '',
			scope: this,
			ctCls: '',
			handler: function () { me.window.hide(); }
		});

		this.window = new Ext.Window({
			id: windowId,
			cls: '',
			title: Page.vehicleDescription + ': View All Features <a href="javascript:Page.hideWindow(\'features\');" style="position:absolute;right:13px;text-decoration:none;"><div style="width:40px;text-align:center;height:20px;line-height:17px;background-color:'+ this.getBrandColor() + ';color:#fff;font-size:10px;">Close</div></a>',
			constrainHeader: true,
			closable: false,
			closeAction: 'hide',
			draggable: false,
			header:true,
			width: 980,
			height: 500,
			modal: true,
			resizable: false,
			plain: true,			
			layout: 'fit',
			border: false,
			items: {
				html: html,
				border: false
			},
			
			buttons: [
				btnClose
			]		
		});
	},
	
	hide: function ()
	{
		this.window.hide();
	},
	
	show: function ()
	{
		if(this.window==null){
			this.initWindow();
		}
		this.window.show();
	},
	
	destroyWindow: function ()
	{
		if(this.window != null){
			this.window.destroy();
			delete this.window;
		}
	},
	
	getBrandColor: function()
	{
		if( ASC.cfg.getTheme() == 'chrysler' ){
			return '#00628E';
		}else if( ASC.cfg.getTheme() == 'dodge' ){
			return '#8B2323';
		}else if( ASC.cfg.getTheme() == 'jeep' ){
			return '#3A3225';
		}
		return '';
	}
	
});
