/*
 *ASC.Chrysler.FAD.FadTabs
* */
ASC.namespace('ASC.Chrysler.FAD.FadTabs');
ASC.Chrysler.FAD.FadTabs = ASC.extend(Ext.util.Observable,{

	renderTo:null,
	tabs:null,
	constructor:function(cfg)
	{
		ASC.apply(this, cfg);
		this.initTabs();
	},
	initTabs:function()
	{
		if(this.items && this.renderTo && this.items.length)
		{
			this.tabs = new Ext.TabPanel({
		        renderTo: this.renderTo,
		        width:this.width,
		        activeTab: this.activeTab,
		        frame:true,
		        height:this.height,
		        items:this.items
		    });
		}
	}

});

/*
 *ASC.Chrysler.FAD.FadTabs
* */
ASC.namespace('ASC.Chrysler.FAD.ViewLink');
ASC.Chrysler.FAD.ViewLink = ASC.extend(Ext.util.Observable,{

	renderTo:null,
	listView:null,
	mapView:null,
	print:null,
	imagePath:null,
	view:null,
	constructor:function(cfg)
	{
		ASC.apply(this, cfg);
		this.initView();
		this.view.overwrite(this.renderTo,cfg);
	},
	initView:function()
	{
		this.view = new Ext.XTemplate(
			'<div id="listTab" class="header_list_view">',
				'<a  href="javascript:Page.callListView(true);" id="link_listView1" class="link_listView_active">&nbsp;</a>',

	          	'<div id="listViewHeader" class="header_view_title_1">',
					'<a href="javascript:Page.callListView(true);" id="link_listView">{listView}</a>',
				'</div>',
			'</div>',
			'<div class="header_middle">|</div>',
			'<div id="mapTab" class="header_map_view">',
				'<a href="javascript:Page.callMapView(true);" id="link_mapView1" class="link_mapView_dft">&nbsp;</a>',
				'<div id="mapViewHeader" class="header_view_title_2">',
					'<a href="javascript:Page.callMapView(true);" id="link_mapView">{mapView}</a>',
				'</div>',
			'</div>',
	        '<div id="headerPrintBar" style="display:none;" class="tag_navigation_right">',
				'<div class="tag_navigation_right_img"><img src="{imagePath}/fad/fad_icon_01.gif" /></div>',
				'<div class="tag_navigation_right_text">',
					'<a href="javascript:Page.printPage();" name="&lpos=content&lid=print">{print}</a>',
				'</div>',
	    	'</div>',

				{
				  getClassName:function(xindex,pageindex)
				  {

				  }
				}
			);
		this.view.compile();
	}

});

/*
 *ASC.Chrysler.FAD.FadTabsHTML
* */
ASC.namespace('ASC.Chrysler.FAD.FadTabsHTML');
ASC.Chrysler.FAD.FadTabsHTML = ASC.extend(Ext.util.Observable,{

	items:null,
	services:null,
	constructor:function(cfg)
	{
	    ASC.apply(this, cfg);
	    var spanishService = ASC.message("fad_findDealers_seHablaEspanol");
        var onlineService = ASC.message("fad_findDealers_onlineService");
        var rentalService = ASC.message("fad_findDealers_rentalService");
        var shuttleService = ASC.message("fad_findDealers_shuttle");
        var serviceContracts = ASC.message("fad_findDealers_serviceContracts");
        var satServic = ASC.message("fad_findDealers_satService");
        var cpov = ASC.message("fad_findDealers_cpov");
    	var expressLube = ASC.message("fad_findDealers_expressLube");
        var fleetElite =ASC.message("fad_findDealers_fleetElite");
        var businessLink = ASC.message("fad_findDealers_businessLink");
        var sprinter = ASC.message("fad_findDealers_sprinter");
//        var fiveStar = ASC.message("fad_findDealers_fiveStar");
		var ramCabs = ASC.message("fad_findDealers_ramChassisCabs");

	    this.services = [{name:onlineService,sname:"onlineService",val:"Y"},
         {name:spanishService,sname:"isSpanish",val:"Y"},
//         {name:fiveStar,sname:"isfiveStar",val:"Y"},
         {name:expressLube,sname:"hasExpressLube",val:"Y"},
         {name:cpov,sname:"hasCPOV",val:"Y"},
         {name:shuttleService,sname:"hasShuttle",val:"Y"},
         {name:satServic,sname:"hasSatService",val:"Y"},
         {name:fleetElite,sname:"hasFleetElite",val:"Y"},
         {name:rentalService,sname:"hasRentalService",val:"Y"},
         {name:serviceContracts,sname:"hasServiceContract",val:"Y"},
         {name:businessLink,sname:"hasBusinessLink",val:"Y"},
         {name:ramCabs,sname:"isChassisCabs",val:"Y"},
         {name:sprinter,sname:"hasSprinter",val:"Y"}
         ];
		this.htmlTpl.init();
		this.initItems();
	},
	initServicesValue:function(len){
		var services = new Array();
		for(var i=0;i<len;i++){
			var service =this.services[i];
			var serviceName = service.sname;
			if( this.params && this.params[serviceName] == 'Y')
				service.checked = "Y";
			else
				service.checked = "N";
			services.push(service);
		}
		return services;
	},

	getServices:function()
	{
		if(this.brand)
		{
			switch(this.brand.toLowerCase())
			{
				case "fiatusa":
					return this.initServicesValue(0);
				case "chrysler":
					return this.initServicesValue(9);
				case "dodge":
					return this.initServicesValue(9);
				case "ramtrucks":
					return this.initServicesValue(12);
				case "jeep":
					return this.initServicesValue(9);
			}
		}
		return this.initServicesValue(12);
	},
	htmlTpl:{
	   init:function()
	   {
		 this.initByZipTpl();
		 this.initByCSTpl();
		 this.initByDealerTpl();
	   },
	   initByZipTpl:function()
	   {
		   this.byZipTpl = new Ext.XTemplate(
				   '<div class="taddiv2">',
				   '<div class="tabdiv1 tab_div_left"><div class="areaTitle"><span class="areaTitle">'+ASC.message("fad_dima_title2")+'</span><span class="areaTitle"> ('+ASC.message("fad_findDealers_zipCode")+')</span></div>',
				   '<div>',
				   '<table cellpadding="0" cellspacing="0" border="0">',
					'<tr><td style="font-size:12px" valign="middle">',
		            '<input id="sZipCode" class="charText byzip" maxlength="5" onkeydown="Page.onEnterForZip(event,\'sZipCode\');" type="text" value="{[Page.zipCode?Page.zipCode:""]}"  >',
					'</td><td style="font-size:12px;font-weight:bold;" valign="middle">',
					'	&nbsp;&nbsp;&nbsp;'+ASC.message("fad_findDealers_searchArea")+':&nbsp;&nbsp;',
					'</td><td  valign="middle">',
		            '	<select id="selectArea"',
					'		style="display: inline;">',
		            '   	<option value="10">10 '+ASC.message("fad_findDealers_milesupp"),
					'		&nbsp;</option>',
		            ' 	<option value="25" selected="selected">25 '+ASC.message("fad_findDealers_milesupp"),
					'		&nbsp;</option>',
		            '  	<option value="50">50 '+ASC.message("fad_findDealers_milesupp"),
					'		&nbsp;</option>',
		            '  	<option value="100">100 '+ASC.message("fad_findDealers_milesupp"),
					'	&nbsp;</option>',
		            '  	<option value="200">200 '+ASC.message("fad_findDealers_milesupp"),
					'	&nbsp;</option>',
		            '	</select>',
		            '	&nbsp;&nbsp;',
					'</td>',
					'<td valign="middle"> ',
					'<a class="searchText" id="searchBtn_zip" href="javascript:void(0);" onclick="Page.searchDealerListByZip();">'+ASC.message("fad_findDealers_search")+'</a>',
					//'	<input class="search_button" type="image" src="'+ASC.cfg.getImgLocalePath()+'/sni/Search_Btn.gif" onclick="Page.searchDealerListByZip();" />',
					'</td>',
					'</tr></table>',
					'</div>',
					'<div class="errorMsg" id="errorMsg_zipCode">',
					'&nbsp;',
					'</div>',
					'</div>',
					'<div class="tabdiv1">',
					'<tpl if="services.length &gt; 0">',
						'<div class="tabdiv3 serviceTitle">'+ASC.message("fad_findDealers_serviceTitle")+'</div>',
					'</tpl>',
					'<form id="byzipForm">',
					'<ul class="services">',
							'<tpl for="services">',
								'<tpl if="xindex%2 == 1">',
									'<tpl if="checked == \'Y\'">',
										'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}" checked><label for="zip_{[xindex]}">{name}</label></li>',
									'</tpl>',
									'<tpl if="checked == \'N\'">',
										'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}"><label for="zip_{[xindex]}">{name}</label></li>',
									'</tpl>',
								'</tpl>',
							'</tpl>',
					'</ul>',
					'<ul class="services">',
						'<tpl for="services">',
							'<tpl if="xindex%2 == 0">',
								'<tpl if="checked == \'Y\'">',
									'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}" checked><label for="zip_{[xindex]}">{name}</label></li>',
								'</tpl>',
								'<tpl if="checked == \'N\'">',
									'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}"><label for="zip_{[xindex]}">{name}</label></li>',
								'</tpl>',
							'</tpl>',
						'</tpl>',
					'</ul>',
					'</form>',
					'</div>',
				   '</div>'
		    );
		   this.byZipTpl.compile();
	   },
	   initByCSTpl:function()
	   {
		   this.byCSTpl =  new Ext.XTemplate(
				   '<div class="taddiv2">',
				   '<div class="tabdiv1 tab_div_left"><div class="areaTitle"><span class="areaTitle">'+ASC.message("fad_dima_title2")+'</span></div>',
				   '<div>',
				   '<table cellpadding="0" cellspacing="0" border="0">',
					'<tr><td style="font-size:12px;font-weight:bold;">'+ASC.message("fad_findDealers_city")+':&nbsp;&nbsp;</td><td style="font-size:12px" valign="middle">',
		            '<input id="bycity" type="text" class="charText byCS" onkeydown="Page.onEnterForCityState(event,\'bycity\');" >',
					'</td><td style="font-size:12px;font-weight:bold;" valign="middle">',
					'	&nbsp;&nbsp;&nbsp;'+ASC.message("fad_findDealers_state")+':&nbsp;&nbsp;',
					'</td><td  valign="middle">',
					'<select id="bystates" style="display:inline;width:80px;" onkeydown="Page.onEnterForCityState(event,\'bystates\');" ><option value="">'+ASC.message("fad_findDealers_select")+'&nbsp;&nbsp;</option>',
			        '<option value="AK">AK</option>',
			        '<option value="AL">AL</option>',
			        '<option value="AR">AR</option>',
			        '<option value="AZ">AZ</option>',
			        '<option value="CA">CA</option>',
			        '<option value="CO">CO</option>',
			        '<option value="CT">CT</option>',
			        '<option value="DC">DC</option>',
			        '<option value="DE">DE</option>',
			        '<option value="FL">FL</option>',
			        '<option value="GA">GA</option>',
			        '<option value="HI">HI</option>',
			        '<option value="IA">IA</option>',
			        '<option value="ID">ID</option>',
			        '<option value="IL">IL</option>',
			        '<option value="IN">IN</option>',
			        '<option value="KS">KS</option>',
			        '<option value="KY">KY</option>',
			        '<option value="LA">LA</option>',
			        '<option value="MA">MA</option>',
			        '<option value="MD">MD</option>',
			        '<option value="ME">ME</option>',
			        '<option value="MI">MI</option>',
			        '<option value="MN">MN</option>',
			        '<option value="MO">MO</option>',
			        '<option value="MS">MS</option>',
			        '<option value="MT">MT</option>',
			        '<option value="NC">NC</option>',
			        '<option value="ND">ND</option>',
			        '<option value="NE">NE</option>',
			        '<option value="NH">NH</option>',
			        '<option value="NJ">NJ</option>',
			        '<option value="NM">NM</option>',
			        '<option value="NV">NV</option>',
			        '<option value="NY">NY</option>',
			        '<option value="OH">OH</option>',
			        '<option value="OK">OK</option>',
			        '<option value="OR">OR</option>',
			        '<option value="PA">PA</option>',
			        '<option value="RI">RI</option>',
			        '<option value="SC">SC</option>',
			        '<option value="SD">SD</option>',
			        '<option value="TN">TN</option>',
			        '<option value="TX">TX</option>',
			        '<option value="UT">UT</option>',
			        '<option value="VA">VA</option>',
			        '<option value="VT">VT</option>',
			        '<option value="WA">WA</option>',
			        '<option value="WI">WI</option>',
			        '<option value="WV">WV</option>',
			        '<option value="WY">WY</option>',
			        '</select>',
		            '	&nbsp;&nbsp;',
					'</td>',
					'<td valign="middle"> ',
					'<a class="searchText" id="searchBtn_cs" href="javascript:void(0);" onclick="Page.searchDealerListByCity();" >'+ASC.message("fad_findDealers_search")+'</a>',
					//'	<input class="search_button" type="image" src="'+ASC.cfg.getImgLocalePath()+'/sni/Search_Btn.gif" onclick="Page.searchDealerListByCity();" />',
					'</td>',
					'</tr></table>',
					'</div>',
					'<div class="errorMsg" id="errorMsg_city">',
					'&nbsp;',
					'</div>',
					'</div>',
					'<div class="tabdiv1">',
					'<tpl if="services.length&gt;0">',
						'<div class="tabdiv3 serviceTitle">'+ASC.message("fad_findDealers_serviceTitle")+'</div>',
					'</tpl>',
					'<form id="bycityForm">',
						'<ul class="services">',
						'<tpl for="services">',
							'<tpl if="xindex%2 == 1">',
								'<tpl if="checked == \'Y\'">',
									'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}" checked><label for="zip_{[xindex]}">{name}</label></li>',
								'</tpl>',
								'<tpl if="checked == \'N\'">',
									'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}"><label for="zip_{[xindex]}">{name}</label></li>',
								'</tpl>',
							'</tpl>',
						'</tpl>',
						'</ul>',
						'<ul class="services">',
							'<tpl for="services">',
								'<tpl if="xindex%2 == 0">',
									'<tpl if="checked == \'Y\'">',
										'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}" checked><label for="zip_{[xindex]}">{name}</label></li>',
									'</tpl>',
									'<tpl if="checked == \'N\'">',
										'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}"><label for="zip_{[xindex]}">{name}</label></li>',
									'</tpl>',
								'</tpl>',
							'</tpl>',
						'</ul>',
					'</form>',
					'</div>',
				   '</div>'

		    );
		   this.byCSTpl.compile();
	   },
	   initByDealerTpl:function()
	   {
		   this.byDealerTpl = new Ext.XTemplate(
				   '<div class="taddiv2">',
				   '<div class="tabdiv1 tab_div_left"><div class="areaTitle"><span class="areaTitle">'+ASC.message("fad_dima_title2")+'</span></div>',
				   '<div>',
				   '<table cellpadding="0" cellspacing="0" border="0">',
					'<tr><td style="font-size:12px;font-weight:bold;">'+ASC.message("fad_findDealers_dealerName")+':&nbsp;&nbsp;</td><td style="font-size:12px" valign="middle">',
		            '<input type="text" id="sDealerName"  class="charText" style="width:150px;margin-right:20px;" onkeydown="Page.onEnterForDealerName(event,\'sDealerName\');" >',
					'</td><td valign="middle"> ',
					'<a class="searchText" id="searchBtn_dealer" href="javascript:void(0);" onclick="Page.searchDealerListByDealerName();">'+ASC.message("fad_findDealers_search")+'</a>',
					//'	<input class="search_button" type="image" src="'+ASC.cfg.getImgLocalePath()+'/sni/Search_Btn.gif" onclick="Page.searchDealerListByDealerName();" />',
					'</td>',
					'</tr></table>',
				   '</div>',
					'<div class="errorMsg" id="errorMsg_dealerName">',
					'&nbsp;',
					'</div>',
					'</div>',
					'<div class="tabdiv1">',
					'<tpl if="services.length &gt;0">',
						'<div class="tabdiv3 serviceTitle">'+ASC.message("fad_findDealers_serviceTitle")+'</div>',
					'</tpl>',
					'<form id="byDealerNameForm">',
							'<ul class="services">',
								'<tpl for="services">',
									'<tpl if="xindex%2 == 1">',
										'<tpl if="checked == \'Y\'">',
											'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}" checked><label for="zip_{[xindex]}">{name}</label></li>',
										'</tpl>',
										'<tpl if="checked == \'N\'">',
											'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}"><label for="zip_{[xindex]}">{name}</label></li>',
										'</tpl>',
									'</tpl>',
								'</tpl>',
							'</ul>',
							'<ul class="services">',
								'<tpl for="services">',
									'<tpl if="xindex%2 == 0">',
										'<tpl if="checked == \'Y\'">',
											'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}" checked><label for="zip_{[xindex]}">{name}</label></li>',
										'</tpl>',
										'<tpl if="checked == \'N\'">',
											'<li><input type="checkbox" onclick="Page.clickInStoreServices(this,\'{name}\');" id="zip_{[xindex]}" name="{sname}" class="checkbox" value="{val}"><label for="zip_{[xindex]}">{name}</label></li>',
										'</tpl>',
									'</tpl>',
								'</tpl>',
							'</ul>',
					'</form>',
					'</div>',
					'</div>'

		    );
		   this.byDealerTpl.compile();
	   },
	   getByZipHTML:function(obj)
	   {
		  return this.byZipTpl.applyTemplate({services:obj});
	   },
	   getByCSHTML:function(obj)
	   {
		  return  this.byCSTpl.applyTemplate({services:obj});
	   },
	   getByDealerHTML:function(obj)
	   {
		  return  this.byDealerTpl.applyTemplate({services:obj});
	   }
	},
	initItems:function()
	{
		this.items = [{
            title: '<div class="tab_left">By ZIP</div>',
			//title: 'By ZIP',
			listeners: {activate: this.handleByZIPActivate},
            html: this.htmlTpl.getByZipHTML(this.getServices())
        },{
            title: '<div class="tab_left">By City/State</div>',
            listeners: {activate: this.handleByCSActivate},
            html:this.htmlTpl.getByCSHTML(this.getServices())
        },{
            title: '<div class="tab_left">By Dealer Name</div>',
            listeners: {activate: this.handleByDealerActivate},
            html: this.htmlTpl.getByDealerHTML(this.getServices())
        }
    ];
	},
	handleByZIPActivate : function (tab){
		tab.focus();
		ASC.Chrysler.trackLinkMetrics('content','search_by_zip');
    },
	handleByCSActivate : function (tab){
    	tab.focus();
		ASC.Chrysler.trackLinkMetrics('content','search_by_city_state');
    },
	handleByDealerActivate : function (tab){
    	tab.focus();
		ASC.Chrysler.trackLinkMetrics('content','search_by_dealer_name');
    }

});

/*
 * ASC.Chrysler.FAD.MapView
 * */
ASC.namespace('ASC.Chrysler.FAD.MapView');
ASC.Chrysler.FAD.MapView = ASC.extend(
		Ext.util.Observable,{
			constructor:function(cfg)
			{
				ASC.apply(this, cfg);
				this.initTpl();
				if(this.dealerList && this.renderTo)
				{
					this.render();
				}
			},
			render:function()
			{
				this.mapViewTpl.overwrite(this.renderTo,{dealersList:this.dealerList,showNumber:this.showNumber,showAlphabet:this.showAlphabet,isPrint:this.isPrint,pageSize:this.pageSize,pageIndex:this.pageIndex});

			},
			initTpl:function()
			{
				this.mapViewTpl = new Ext.XTemplate(
						 '<table class="listitem_table" cellpadding="0" cellspacing="0" border="0">',
						 '<tpl for="dealersList">',
					     '<tr class={[xindex%2==0?"list_item_tr_noborder":"list_item_tr"]}>',
					     	 '<td class="listitem_td_icon">',
					     	 	'<div class="sub_navigation_middle_leftupimg" nochange="true" >',
									'<div class="logoImage"><img src="{[this.getBrandLogo(Page.brand)]}" border="0"/></div>',
									'<div class="number"><div class="number_num">',
					     	 	'<tpl if="parent.showAlphabet">',
				     	 			'B',
				     	 		'</tpl>',
					     	 	'<tpl if="! parent.showAlphabet">',
					     	 		'{[xindex + (parent.pageIndex-1)*parent.pageSize]}',
					     	 	'</tpl>',
					     	 	'</div></div></div>',
					     	 '</td>',
						     '<td  class="{[this.getCssClass(\"listitem_td_1\",parent.isPrint)]}">',
							     '<div class="listitem_1" title="{name}">',
								     '<tpl if="! parent.isPrint">',
								     	'<a onclick="Page.getDealerInfoFromList(\'{dealerCode}\')">{name}</a>',
								     '</tpl>',
								     '<tpl if="parent.isPrint">',
								     	'{name}',
								     '</tpl>',
							     '</div>',
							     '<tpl if="this.isValidDistance(distance)">',
							     	'<div class="listitem_2">{distance} {[this.translate("fad_findDealers_milesAway")]}</div>',
							     '</tpl>',
//							     '<tpl if="fiveStar == \'Y\'">',
//							     	'<div class="listitem"><img src="{[this.getFiveStarImage()]}"/></div>',
//							     '</tpl>',
//							     '<tpl if="fiveStar != \'Y\'">',
//							     	'<div class="listitem">&nbsp;</div>',
//							     '</tpl>',
							     '<div class="listitem" title="{address1}">{[this.lowerCase(values.address1)]}</div>',
							     '<div class="listitem" title="{city}, {state} {[this.formatZip(values.zip)]}">{[this.subStr(this.lowerCase(values.city)+", "+values.state+" "+this.formatZip(values.zip))]}</div>',
							     '<div class="listitem">{[this.formatPhone(values.salesPhone)]}</div>',
							     '<tpl if="! parent.isPrint">',
							     	 '<div class="listitem_last">',
                                        '<tpl if="!parent.showAlphabet" >',
							     		    '<a href="javascript:Page.callDirectionView(\'{dealerCode}\');" class="direction">{[this.translate("fad_get_directions")]}</a>',
                                        '</tpl>',
							     		'<tpl if="values.dealerSitePointer == \'3\'">',
								     		'<tpl if="parent.showAlphabet">',
								     			'<div class="view" onclick="javascript:Page.trackDealerWebsite(\'{dealerCode}\',\'DIR_WEB\');">',
								     			'<a class="{[this.getCssName("direction_map_"+values.dealerCode)]}" href="{[this.getDealerSite(values.dealerSitePointer,values.url,values,parent)]}" target="_blank" id="direction_map_{dealerCode}">{[this.translate("fad_view_dealers_website")]}</a>',
						     	 			'</tpl>',
						     	 			'<tpl if="! parent.showAlphabet">',
						     	 				'<div class="view" onclick="javascript:Page.trackDealerWebsite(\'{dealerCode}\',\'WEB\');">',
						     	 				'<a class="{[this.getCssName("map_"+values.dealerCode)]}" href="{[this.getDealerSite(values.dealerSitePointer,values.url,values,parent)]}" target="_blank" id="map_{dealerCode}">{[this.translate("fad_view_dealers_website")]}</a>',
						     	 			'</tpl>',
							     		'</div></tpl>',
							     	 '</div>',
							     	 '<div class="blank">&nbsp;</div>',
							     '</tpl>',
							     '<tpl if="parent.isPrint">',
							     	'<div class="blank">&nbsp;</div>',
							     '</tpl>',
						     '</td>',
						     '<td class="listitem_td_icon"><tpl if="parent.showAlphabet && !parent.isPrint"><div class="closeDirection"><a href="javascript:Page.gotoPreviousView();">X</a></div></tpl>',
						     '</td>',
					     '</tr>',
					     '</tpl>',
					     '</table>',
						{
							translate: function (key)
							{
								return ASC.message(key);
							},
							subAndLowerCase : function(str){
								if(str.length > 50)
								{
									str = str.toLowerCase();
									return str;//.substr(0,50) + '...';
								}
								else
								{
									return str.toLowerCase();
								}
							},
							getCssClass: function(cssClass,isPrint){
								 if( isPrint )
									 return cssClass+"_print";
								 else
									 return cssClass;
							},
							getCssName: function(id){
								/*if( Page.map_id == id || Page.direction_map_id == id)
									 return "view_button_active";
								 else*/
									 return "view_button";
							},
							getFiveStarImage: function(){
					    		 return ASC.cfg.getContextPath() + "/resources/images/all/en/fivestar.gif";
					    	},
							lowerCase: function(str){
								return str.toLowerCase();
							},
							subStr: function (str)
							{
								if(str.length > 50)
								{
									return str;//.substr(0,50) + '...';
								}
								else
								{
									return str;
								}
							},
							getBrandLogo: function(brand){
								if(brand)
								{
									brand = brand.toLowerCase();
									return ASC.cfg.getContextPath() + "/resources/images/brands/"+brand+".gif";
								}
					    	},
							formatPhone: function(phone){
								return ASC.Chrysler.formatPhoneNumberUseHyphen(phone);
							},
							getDealerSite: function(dealerSitePointer,url,obj,parent){
					    		 if( dealerSitePointer!="3" ){
					    			 url = ASC.cfg.getContextPath() + '/fad/moreDealerInfo.do?dealerCode='+obj.dealerCode+'&fromFadZip='+ Page.zipCode+"&=zipDistance"+obj.distance+"&city="+parent.centerCity+"&state="+parent.centerState;
					    		 }
					    		 return url;
					    	},
							formatZip: function(zip){
								return ASC.util.formatZipPostalCode(zip);
							},
							isValidDistance: function(distance){
									if( distance && distance !== 'null' ){
										return true;
									}
									return false;
								}
						}
				);
				this.mapViewTpl.el = this;
				this.mapViewTpl.compile();

		},
		update:function(cfg)
		{
			if(cfg.dealerList)
			{
				ASC.apply(this, cfg);
				this.mapViewTpl.el = this;
				this.render();
			}
		}
		}
 );
/*
 * ASC.Chrysler.FAD.ListView
 * */
ASC.namespace('ASC.Chrysler.FAD.ListView');
ASC.Chrysler.FAD.ListView = ASC.extend(Ext.util.Observable,{
	dealerList:null ,
	renderTo:null ,
	store:null,
	constructor:function(dealerList,cfg)
	{
		ASC.Chrysler.FAD.ListView.superclass.constructor.apply(this);
		ASC.apply(this, cfg);
		this.addEvents({"render":true});
		this.initTemplate();
		if(dealerList)
		{
			this.loadData(dealerList);
		}
	},
	initTemplate:function()
	{
		this.listViewTemp = new Ext.XTemplate(
		     '<table class="listitem_table" cellpadding="0" cellspacing="0" border="0">',
		     '<tpl for="dealerList.dealers">',
		     '<tr class={[xindex%2==0?"list_item_tr_noborder":"list_item_tr"]}>',
			     '<td  class="{[this.getCssClass(\"listitem_td_1\",parent.isPrint)]}">',
				     '<div class="listitem_1" title="{name}">{name:this.subStr}</div>',
				     '<tpl if="this.isValidDistance(distance)">',
				     	'<div class="listitem_2">{distance} {[this.translate("fad_findDealers_distanceDesc")]}</div>',
				     '</tpl>',
//				     '<tpl if="fiveStar == \'Y\'">',
//				     	'<div class="listitem"><img src="{[this.getFiveStarImage()]}"/></div>',
//				     '</tpl>',
//				     '<tpl if="fiveStar != \'Y\'">',
//				     	'<div class="listitem">&nbsp;</div>',
//				     '</tpl>',
				     '<div class="listitem">{[this.lowerCase(values.address1)]}</div>',
				     '<div class="listitem">{[this.lowerCase(values.city)]}, {state} {[this.formatZip(values.zip)]}</div>',
				     '<div class="listitem">{[this.getFormatePhone(values.salesPhone)]}</div>',
				     '<tpl if="! parent.isPrint">',
				     	'<div class="listitem_last"><a href="javascript:Page.callDirectionView(\'{dealerCode}\');" class="direction">{[this.translate("fad_get_directions")]}</a><div>',
				     '</tpl>',
			     '</td>',
			     '<tpl if="! parent.isPrint">',
				     '<td  class="listitem_td_2">',
					     	'<tpl if="values.dealerSitePointer == \'3\'"><div class="view" onclick="javascript:Page.trackDealerWebsite(\'{dealerCode}\');"><a  class="{[this.getCssName("list_"+values.dealerCode)]}" href="{[this.getDealerSite(values.dealerSitePointer,values.url,values,parent)]}" target="_blank" id="list_{dealerCode}">{[this.translate("fad_view_dealers_website")]}</a></div></tpl>',
							'<tpl if="values.dealerSitePointer != \'3\'">&nbsp;</tpl>',
					'</td>',
			     '</tpl>',
			     '<tpl if=" parent.isPrint">',
				     '<td  class="listitem_td_2_print">',

				     '</td>',
			     '</tpl>',
			     '<td  class="{[this.getCssClass(\"listitem_td_3\",parent.isPrint)]}">',
			        '<tpl if="this.isExistDealerHours(dealerHoursHtml)">',
				     	'<div class="listitem_1">{[this.translate("fad_new_vehicle_sales")]}</div>',
				     	'<div class="listitem">',
					     	'{dealerHoursHtml}',
		            	'</div>',
	            	'</tpl>',
			     '</td>',
			     '<td  class="{[this.getCssClass(\"listitem_td_4\",parent.isPrint)]}">',
                    '<div class="FIAT_NoShow" >',
			     	'<div class="listitem_1">{[this.translate("fad_instore_service")]}</div>',
                    '<div class="listitem_legend">',
                    '<tpl for="services">',
                        '<tpl if="xindex == 7 "></div><div class="listitem_legend"></tpl>',
                        '<div class="listitem">{.}</div>',
                    '</tpl>',
                    '</div>',
                    '</div>',
		     	 '</td>',
		     '</tr>',
		     '<tr>',
		     	'<td><div class="blank">&nbsp;</div></td>',
		     '</tr>',
		     '</tpl>',
		     '</table>',
		     {
		    	 translate: function (key)
				 {
					return ASC.message(key);
				 },

				 getCssClass: function(cssClass,isPrint){
					 if( isPrint )
						 return cssClass+"_print";
					 else
						 return cssClass;
				 },
				 getCssName: function(id){
					 /*if( Page.list_id == id )
						 return "view_button_active";
					 else*/
						 return "view_button";
				 },
		    	 getZipCode:function(longZip)
		    	 {
		    	     if(longZip.length > 5)
		    	     {
		    	    	 return longZip.substring(0,5);
		    	     }
		    	     return longZip;
		    	 },
		    	 getFormatePhone:function(phone)
		    	 {
		    		 return ASC.Chrysler.formatPhoneNumberUseHyphen(phone);
		    	 },
		    	 getFiveStarImage: function(){
		    		 return ASC.cfg.getContextPath() + "/resources/images/all/en/fivestar.gif";
		    	 },
		    	 getDealerSite: function(dealerSitePointer,url,obj,parent){
		    		 if( dealerSitePointer!="3" ){
		    			 url = ASC.cfg.getContextPath() + '/fad/moreDealerInfo.do?dealerCode='+obj.dealerCode+'&fromFadZip='+ Page.zipCode+"&=zipDistance"+obj.distance+"&city="+parent.centerCity+"&state="+parent.centerState;
		    		 }
		    		 return url;
		    	 },
		    	 isValidDistance: function(distance){
						if( distance && distance !== 'null' ){
							return true;
						}
						return false;
				 },
				 lowerCase: function(str){
						return str.toLowerCase();
				 },
                 formatZip: function(zip){
								return ASC.util.formatZipPostalCode(zip);
				 },
				 isFiatBrand:function(){
					 return Page.brand.toLowerCase() == "fiatusa";
				 },
				 isExistDealerHours:function(html){
					 return html && html.length > 0;
				 },
				 subStr: function (str)
				 {
					if(str.length > 24)
					{
						return str;//.substr(0,24) + '...';
					}
					else
					{
						return str;
					}
				 }
		     }
		);
	}
	,
	loadData:function(data)
	{
		if(data)
		{
			this.dealerList = data;
			for(var i=0;i<this.dealerList.dealers.length;i++){
				var dealer = this.dealerList.dealers[i];
				var services = new Array();
                if(dealer.dealerSitePointer == '3')
                {
                    services.push(ASC.message("fad_findDealers_onlineService"));
                }
                if(dealer.hasRentalService == 'Y')
                {
                    services.push(ASC.message("fad_findDealers_rentalService"));
                }
                if(dealer.hasShuttle == 'Y')
                {
                    services.push(ASC.message("fad_findDealers_shuttle"));
                }
                if(dealer.hasSatService == 'Y')
                {
                    services.push(ASC.message("fad_findDealers_satService"));
                }
                if(dealer.hasCPOV == 'Y')
                {
                    services.push(ASC.message("fad_findDealers_cpov"));
                }
                if(dealer.hasExpressLube == 'Y')
                {
                    services.push(ASC.message("fad_findDealers_expressLube"));
                }
                if(dealer.hasFleetElite == 'Y')
                {
                    services.push(ASC.message("fad_findDealers_fleetElite"));
                }
				if(dealer.hasSpanishPersonnel == 'Y')
				{
					services.push(ASC.message("fad_findDealers_seHablaEspanol"));
				}
				if(dealer.hasBusinessLink == 'Y')
				{
					services.push(ASC.message("fad_findDealers_businessLink"));
				}
				if(dealer.hasSprinter == 'Y')
				{
					services.push(ASC.message("fad_findDealers_sprinter"));
				}
//				if(dealer.fiveStar == 'Y')
//				{
//					services.push(ASC.message("fad_findDealers_fiveStar"));
//				}
				if(dealer.hasSDTruck == 'Y')
				{
					services.push(ASC.message("fad_findDealers_ramChassisCabs"));
				}
				if(dealer.hasServiceContract == 'Y')
				{
					services.push(ASC.message("fad_findDealers_serviceContracts"));
				}
				dealer.services = services;
			}
			this.render();
		}
	},
	render:function()
	{
		this.listViewTemp.overwrite(this.renderTo,{dealerList:this.dealerList,isPrint:this.isPrint});
		this.fireEvent("render");
	},
	update:function(data)
	{
		if(data)
		{
			this.loadData(data);
		}
	}
});

/*
 * ASC.Chrysler.FAD.ChooseDealer
 * */

ASC.namespace('ASC.Chrysler.FAD.ChooseDealer');
ASC.Chrysler.FAD.ChooseDealer = ASC.extend(Ext.Window, {

	id:null,
	dealerList:null,
	constructor: function (dealerList, cfg)
	{
		var windowId =  this.id = Ext.id();
		this.dealerList = dealerList;
		if(cfg && cfg.pageCount && cfg.pageIndex)
		{
			this.pageCount = cfg.pageCount;
			this.pageIndex = cfg.pageIndex;
		}
		this.initDlgTemplates();
		var html = this.buildContents();
		var buttons = null;
		var spacer = new Ext.Toolbar.Spacer();
		this.selectBtn = new Ext.Button({
			text: 'FIND DEALER',
			cls: "x-btn-text",
			scope: this,
			ctCls: 'dlgBtn',
			disabled: false,
			hidden: false,
			handler: function () {
				var opt = this.getSelectedDealer();
				this.fireEvent('dealerSelected',opt);
				this.destroy();
			}
		});
		var preDisabled = this.pageIndex == 1 ? true:false;

		this.preBtn = new Ext.Button({
			text: '&lt;&lt;',
			cls: "x-btn-text",
			scope: this,
			ctCls: 'dlgBtn',
			disabled: preDisabled,
			hidden: false,
			handler: function () {
				Page.chooseDealerChangePage(-1);
			}
		});
		var nextDisabled = this.pageIndex == this.pageCount ? true:false;
		this.nextBtn = new Ext.Button({
			text: '&gt;&gt;',
			cls: "x-btn-text",
			scope: this,
			ctCls: 'dlgBtn',
			disabled: nextDisabled,
			hidden: false,
			handler: function () {
				Page.chooseDealerChangePage(1);
			}
		});
		if( this.pageCount && this.pageCount > 1 ){
			txtItem = new Ext.Toolbar.TextItem('<span style="font-size:12px;font-weight:bold;line-height:1;">Page '+this.pageIndex+' of '+this.pageCount+'</span>');
			buttons = [this.selectBtn,spacer,txtItem,this.preBtn,this.nextBtn];
		}
		else
			buttons = [this.selectBtn];
		var winCfg = ASC.apply({
			id: windowId,
			ctCls: 'ppweb-mustHaveDlg',
			cls :  'chooseDealer',
			title: 'Which dealer were you looking for?',
			headerAsText: true,
			constrainHeader: true,
			draggable: true,
			closable: true,
			plain: true,
			layout: 'fit',
			border: true,
			modal: true,
			resizable: false,
			width: 430,

			items: {
				html: html
			},

			buttons: buttons
		}, cfg);

		ASC.Chrysler.FAD.ChooseDealer.superclass.constructor.call(this, winCfg);

		this.addEvents({
			dealerSelected:true
		});
	},
	close:function()
	{
		this.suspendEvents();
		this.destroy();
	},
	initDlgTemplates: function ()
	{
		this.chooseDealerTpl = new Ext.XTemplate(
			'<div style="width:410px;height:130px;overflow:auto;">',
			'<table border="0" cellpadding="0" cellspacing="0" class="chooseTable">',
				'<tpl for="dealers">',
					'<tr>',
				   		'<td><input type="radio" id="{dealerCode}" name="chooseDealers_group" {[xindex==1?"checked":""]}></td>',
				   		'<td style="padding-left:10px">{name} in {city} {state}</td>',
					'</tr>',
				'</tpl>',
		   	'</table>',
		   	'</div>'
		);
		this.chooseDealerTpl.compile();
	},

	buildContents: function ()
	{
		return this.chooseDealerTpl.applyTemplate({
			dealers: this.dealerList,
			windowId: this.id,
			pageCount:this.pageCount,
			pageIndex:this.pageIndex
		});
	},

	getSelectedDealer: function ()
	{
		var inputs = document.getElementsByName('chooseDealers_group');
		for (var i=0; i<inputs.length; i++) {
			var input = inputs[i];
			if (inputs[i].checked) {
				return inputs[i].id;
			}
		}
		return null;
	},
	update:function(cfg)
	{
		ASC.apply(this, cfg);
	}
});

/*
 *ASC.Chrysler.FAD.FadTabs
* */
ASC.namespace('ASC.Chrysler.FAD.DirectionView');
ASC.Chrysler.FAD.DirectionView = ASC.extend(Ext.util.Observable,{

	renderTo:null,
	dealerCode:null,
	view:null,
	constructor:function(cfg)
	{
		ASC.apply(this, cfg);
		this.dealerCode = cfg.dealerCode;
		this.initDirectionView();
		this.view.overwrite(this.renderTo,cfg);
	},
	initDirectionView:function()
	{
		this.view = new Ext.XTemplate(
				'<div class="map_dealerList">',
					'<div id="directionDealer"></div>',
					'<div class="blank">&nbsp;</div>',
					'<table class="listitem_table" cellspacing="0" cellpadding="0" border="0">',
						'<tr class="direction_tr">',
							'<td class="direction_icon">',
								'<div class="direction_addressIcon">A</div>',
							'</td>',
							'<td class="direction_address">',
								'<input id="startAddress" onkeydown="Page.onEnterForDirection(event,\'startAddress\');"  style="width:270px;"/>',
							'</td>',
						'</tr>',
						'<tr><td><div class="blank">&nbsp;</div></td></tr>',
						'<tr class="direction_tr">',
							'<td class="direction_icon">',
								'<div class="direction_addressIcon">B</div>',
							'</td>',
							'<td class="direction_address">',
								'<input id="endAddress" onkeydown="Page.onEnterForDirection(event,\'endAddress\');"  style="width:270px;"/>',
							'</td>',
						'</tr>',
					'</table>',
					'<div class="direction_view_button"><span><a id="direction_view_button_{dealerCode}" class="{[this.getCssName("direction_view_button_"+values.dealerCode)]}" href="javascript:Page.getDirection(\'{dealerCode}\');">{[this.translate("fad_get_directions")]}</a></span></div>',
					'<div style="display:none;color:red;margin-top:10px;" id="search_error">'+ASC.message("fad_findDealers_searchError")+'</div>',
					'<div id="DirectionsDesc" class="content_directions" style="margin-top:10px;height: 400px; overflow-y: auto;"></div>',
				'</div>',
				'<div style="float:left;margin-left:20px;">&nbsp;</div>',
				'<div id="directionMap" class="dealerMap"></div>',

				{

				  translate: function (key)
				  {
						return ASC.message(key);
				  },
				  getCssName: function(id){
					  /*if( Page.direction_view_button_id == id )
						  return "direction_view_button_active";
					  else*/
						  return "direction_view_button";
				  }

				}
			);
		this.view.compile();
	}

});

