ASC.apply(Page, {
	paymentEstimator:null,
	links:{
		externalSite: '',
		chryslerFinancialSite : 'http://www.chryslerfinancial.com',
		chryslerFinancialSites : 'https://www.chryslerfinancial.com',
		
		_openNewWindow: function(url)
		{
			window.open(url);
		},
		_openLocalWindow: function(url)
		{
			window.location.href = url;
		},
		_openWindow: function(url,isLocal)
		{
			if(isLocal)
			{
				this._openLocalWindow(url);
			}
			else
			{				
				this._openNewWindow(url);
			}
		},
		openPreOwenedWindow:function(dealerCode, zipDistance, isLocal)
		{
			url= ASC.cfg.getContextPath() + '/cpov/vehicleResults.do?dealerCode=' + dealerCode+'&zipDistance='+zipDistance;
			this._openWindow(url,isLocal);
		},
		openGetPartWindow:function(isLocal)
		{
			url= this.externalSite + '/vehsuite/GetAPart.jsp';
			this._openWindow(url,isLocal);
		},
		openAppointmentWindow:function(isLocal)
		{
			url= this.externalSite + '/vehsuite/ScheduleAnAppointment.jsp';
			this._openWindow(url,isLocal);
		},
		openCurrentIncentives: function(zipCode,isLocal)
		{
			
			url = this.externalSite  +'/incentives/?zipCode=' + this.getZipCode(zipCode);
			
			this._openWindow(url,isLocal);
		},
		openCurrentIncentives1: function(zipCode,isLocal,exurl)
		{
			
			url = exurl  +'/incentives/?zipCode=' + this.getZipCode(zipCode);
			
			this._openWindow(url,isLocal);
		},
		openMoreDealerInfo:function(dealerCode,zipDistance,isLocal)
		{
			url = ASC.cfg.getContextPath() +'/fad/moreDealerInfo.do?dealerCode=' + dealerCode + '&zipDistance=' + zipDistance;
			this._openWindow(url,isLocal);
		},
		openVisitDealerWindow:function(dealerCode,url,isLocal)
		{
			//url = ASC.cfg.getContextPath() +'/fad/moreDealerInfo.do?dealerCode='+dealerCode;
			this._openWindow(url,isLocal);
		},
		openEstimatePaymentsWindow:function(options,isLocal)
		{
			if(Page.paymentEstimator==null){
				Page.paymentEstimator = new ASC.Chrysler.CPOV.PaymentEstimatorStandAlone();
			}

			Page.paymentEstimator.show();
		},
				
		openApplyForCreditWindow:function(dealerCode, brand)
		{
			//url= this.chryslerFinancialSites + '/credit/cfc2/credit-applicationQuestionnairePrepare.do';
			var zipCode = ASC.Chrysler.Cookies.getZipCode();
			if(zipCode==null){
				zipCode='';
			}
			url = ASC.cfg.getCFCreditAppUrl() + '?cobrand='+brand+'&dealer_id='+dealerCode+'&zipCode='+zipCode;
			this._openWindow(url,false);
		},
		openPrivacyPolicyWindow:function(isLocal)
		{
			url= ASC.cfg.getContextPath()  + '/privacyPolicy.do';
			this._openWindow(url,isLocal);
		},
		getZipCode: function(zipCode)
		{
			if(zipCode.length > 5)
			{
				return zipCode.substring(0,5);
			}
			else
			{
				return zipCode;
			}
		}
	},

	setPaymentEstimatorParams: function () {
		if (!this.paymentEstimator) {
			return;
		}
		var zipCode = ASC.Chrysler.Cookies.getZipCode();
		if(zipCode==null){
			zipCode='';
		}		
		var params = {
			zipCode:zipCode 
		};
		
		return params;
	}		
});


/*
 * ASC.Chrysler.BMO.PaymentEstimatorStandAlone
 * */
ASC.namespace('ASC.Chrysler.CPOV.PaymentEstimatorStandAlone');
ASC.Chrysler.CPOV.PaymentEstimatorStandAlone = 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: 729,
			height:595,
			frame:true,
			hideBorders:true,
					
			items: {
				html: html
			}
			
		}, cfg);				
				
		ASC.Chrysler.CPOV.PaymentEstimatorStandAlone.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', '710', '580', '9.0.47', '#869ca7', 'high');
				so.addVariable('host', ASC.cfg.getFinancialUrl());
				so.addVariable('mode', 'standalone')
				so.addVariable('cobrand', ASC.cfg.getTheme());
				so.addVariable('loadComplete', 'Page.setPaymentEstimatorParams');
				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();
	},
	
	getFlexDom: function ()
	{
		return ASC.getEl('objPaymentEstimator').dom
	}	
});
