var provider;
var preview;
var cssSwitchURL;
var make;
var model;

TRS.TypeMap.BrowseByVehicleType = function (data){
		 var element = $("div[@name=" + data.dataProviderName + "]");
// Code modifications done according to the new UI - Adea
		 var htmCode = '<div class="csContainer_title">Choose by Segment</div>';
		 htmCode += '<div class="choose_inner_div">';
		 htmCode += '<div class="choose_inner_img"><img src="images/box_inner_top.gif" /></div>';
		 htmCode += '<div class="choose_inner_cont">';
		
		htmCode += '<ul>';
		for (var i = 5; i < Math.min(9, data.data.length); i++){
			htmCode += '<li><a href="search_vehicle.jsp?cov='+data.data[i].text+'&'+cssSwitchURL+'"	title="'+data.data[i].text+'"><img src="'+data.data[i].imagePath+'" width="53" height="25" alt="'+data.data[i].text+'" />'+data.data[i].text+' </a></li>';
			if (i < 8){
			   htmCode += '<br/><br/><br/>';
			}
			if(i == 6){
				htmCode += '</ul>';
				htmCode += '<ul><br/><br/>';
			}
		}
		htmCode += '</ul>';
		htmCode += '</div>';
		htmCode += '<div class="choose_inner_img"><img src="images/box_inner_bottom.gif" /></div>';
		htmCode += '</div>';
		element.empty();
		element.append(htmCode);
}

TRS.TypeMap.BrowseByBrand = function (data){
		var element = $("div[@name=" + data.dataProviderName + "]");
		// Code modifications done according to the new UI - Adea
		var moreThan15 = (data.data.length > 15)? true:false;
		var dataLength = 15;
		var midPoint = 8;
		//update midpoint if the content is less than 15...
		if(!moreThan15){
			midPoint = Math.ceil(data.data.length/2);
			dataLength = data.data.length;
		}
		var htmCode = '<div class="csBrand">'; 
		htmCode += '<div class="csContainer_title">Choose by Brand</div>';
		htmCode += '<table width="145" cellspacing="0" cellpadding="0" border="0" align="left">';
		htmCode += '<tbody>';
		for(var i = 0; i <  midPoint; i++){
			htmCode += '<tr>';
			htmCode += '<td valign="top" style="width:50px;height:23px;" ><a href="search_vehicle.jsp?bov='+data.data[i].text+'&'+cssSwitchURL+'" title="'+data.data[i].text+'" onclick="javascript: trilogy_autoretail_onMakeSelectionListener(\''+data.data[i].text+'\')">'+data.data[i].text+' </a></td>';
			if(dataLength % 2 == 1 && i == midPoint-1){
			// More... link added to display all brands 
				if(midPoint + i == 15){
					htmCode += '<td valign="top" style="width:50px;height:23px;" align="left"><a href="javascript:void(0)" onClick="TRS.TypeMap.BrowseByAllBrands(makeswithURL);"><b>More...</b></a></td>';
				}
				htmCode += '</tr>';				
			}else{
				htmCode += '<td valign="top" style="width:50px;height:23px;" align="left"><a href="search_vehicle.jsp?bov='+data.data[midPoint + i].text+'&'+cssSwitchURL+'" title="'+data.data[midPoint + i].text+'" onclick="javascript: trilogy_autoretail_onMakeSelectionListener(\''+data.data[midPoint + i].text+'\')">'+data.data[midPoint + i].text+' </a></td>';
				
				htmCode += '</tr>';
			}
		}
		/*if ( (2 * midPoint) < data.data.length){
			htmCode += '<tr>';
			htmCode += '<td align="center" colspan="2"><a href="newcars_home.jsp?'+cssSwitchURL+'" title="See All Brands...">See All Brands... </a></td></tr>';
		}*/
		htmCode += '</tbody></table>';
		element.empty();
		element.append(htmCode);
}

TRS.TypeMap.BrowseByPriceRange = function (data){
		var element = $("div[@name=" + data.dataProviderName + "]");
		// Code modifications done according to the new UI - Adea
		var htmCode = '<div class="csContainer_price_title">Choose by Price Range</div>';
		htmCode += '<ul>';		
		for (var i = 0; i < data.data.length; i++){
			htmCode += '<li>';
			var price = data.data[i].text;
			/*if(0 != i && i != (data.data.length - 1)){
				price += ' Range';
		    }*/
			htmCode += '<a href="search_vehicle.jsp?prov='+data.data[i].text+'&'+cssSwitchURL+'" title="'+price+'">'+price+'</a></li>';
			if (i == 2){
				htmCode += '</ul>';
				htmCode += '<ul>';
			}
		}
		htmCode += '</ul>';
		
		element.empty();
		element.append(htmCode);
}

function updatePriceButton(){
	var priceButtonHtml = '<a href="vehicle_pricing_home.jsp?mov='+$('#modelPricing  option:selected').val()+'&'+cssSwitchURL+'"	title="see all pricing" class="btnArrow">see all pricing</a>';
	$("#pricingButton").html(priceButtonHtml);
}

function callPricingPage(){
	var pricingPage = 'vehicle_pricing_home.jsp?mov='+$('#modelPricing  option:selected').val()+'&'+cssSwitchURL;
	var make = $('#brandPricing option:selected').val();
	var yearModel = $('#modelPricing  option:selected').html();
	var yrMdlArray = splitModelYear(yearModel);
	trilogy_autoretail_onModelSelectionListener(make, yrMdlArray[1], yrMdlArray[0]);
	this.location.href = pricingPage;
}

function callQuotePage(){
	var zipcode = $('#zipQuote').val();
	if(!checkZip(zipcode)){
		alert("Please enter a valid zip code");
		return;
	}
	var pricingPage = 'vehicle_gaq_home.jsp?modelId='+$('#modelQuote  option:selected').val()+'&'+cssSwitchURL+'&zipcode='+zipcode;
	var make = $('#brandQuote option:selected').val();
	var yearModel = $('#modelQuote  option:selected').html();
	var yrMdlArray = splitModelYear(yearModel);
	trilogy_autoretail_onModelSelectionListener(make, yrMdlArray[1], yrMdlArray[0]);
	trilogy_autoretail_onZipSelectionListener($('#zipQuote').val());
	this.location.href = pricingPage;
}

TRS.TypeMap.carSpotType = function(data){
	var sptVeh = data.data[0];
	var ymm = sptVeh.year+' '+sptVeh.make+' '+sptVeh.model;
	var spotlightHtml = '<div class="imgContainerSpot">';
	// Code modifications done according to the new UI - Adea
	spotlightHtml += '<a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += '<img height="80" src="'+sptVeh.vehicleImagePath+'" alt="Car Showcase" width="109" height="69" /></a>';
	spotlightHtml += '</div>';
	spotlightHtml += '<div class="txtContainer"><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'" class="csContainer_title_link">'+sptVeh.make+' '+sptVeh.model+'</a><br />';
	spotlightHtml +=' <span class="regularTxt">**Ex Showroom Price: Rs.'+ CurrencyFormatted(sptVeh.maxPrice)+' <br /><br />';
	spotlightHtml +='The New Optra Magnum is designed for power with no compromises.</span></div>';
	spotlightHtml += '<div class="content">';
	//spotlightHtml += '<p><a href="vehicle_overview_home.jsp?modelId='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'"></a>';
	//spotlightHtml += sptVeh.year+' '+sptVeh.make+'<br/>';
	//spotlightHtml += sptVeh.model+'</a></p>';
	/**
	spotlightHtml += '<p>Out Rating :</p>';
	spotlightHtml += '<img src="'+sptVeh.vehicleCustomRatingImagePath+'" alt="Car Showcase" />';
	*/
	spotlightHtml += '<table cellspacing="0" cellpadding="2" border="0" align="left"><tbody>';
	//spotlightHtml += '<tr><td>MSRP:</td><td>Rs.'+ CurrencyFormatted(sptVeh.maxPrice)+'</td></tr>';
	spotlightHtml += '</tbody></table>';
	spotlightHtml += '</div>';
	
	spotlightHtml += '<div class="navigationdiv">&raquo; <a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" class="navLinks" title="Overview">Overview</a> |';
	spotlightHtml += ' <a href="vehicle_photos_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" class="navLinks" title="Photos">Photos</a> | ';
	spotlightHtml += '<a href="vehicle_features_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" class="navLinks" title="Features">Features</a> | ';
	spotlightHtml += '<a href="vehicle_pricing_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" class="navLinks" title="Pricing">Pricing</a></div>';
	$("#tabCont1").html(spotlightHtml);
}

TRS.TypeMap.truckSpotType = function(data){
	var sptVeh = data.data[0];
	var ymm = sptVeh.year+' '+sptVeh.make+' '+sptVeh.model;
	var spotlightHtml = '<div class="imgContainer">';
	spotlightHtml += '<a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += '<img height="80" src="'+sptVeh.vehicleImagePath+'" alt="Truck Showcase" /></a>';
	spotlightHtml += '</div>';
	spotlightHtml += '<div class="content">';
	spotlightHtml += '<p><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += sptVeh.year+' '+sptVeh.make+'<br/>';
	spotlightHtml += sptVeh.model+'</a></p>';
	/**
	spotlightHtml += '<p>Out Rating :</p>';
	spotlightHtml += '<img src="'+sptVeh.vehicleCustomRatingImagePath+'" alt="Car Showcase" />';
	*/
	spotlightHtml += '<table cellspacing="0" cellpadding="2" border="0" align="left"><tbody>';
	spotlightHtml += '<tr><td>MSRP:</td><td>Rs.'+ CurrencyFormatted(sptVeh.maxPrice)+'</td></tr>';
	spotlightHtml += '</tbody></table>';
	spotlightHtml += '</div>';
	spotlightHtml += '<p class="allLink"><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Overview">Overview</a> |';
	spotlightHtml += ' <a href="vehicle_photos_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Photos">Photos</a> | ';
	spotlightHtml += '<a href="vehicle_features_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Features">Features</a> | ';
	spotlightHtml += '<a href="vehicle_pricing_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Pricing">Pricing</a></p>';
	$("#tabCont2").html(spotlightHtml);
}

TRS.TypeMap.SUVSpotType = function(data){
	var sptVeh = data.data[0];
	var ymm = sptVeh.year+' '+sptVeh.make+' '+sptVeh.model;
	var spotlightHtml = '<div class="imgContainer">';
	spotlightHtml += '<a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += '<img height="80" src="'+sptVeh.vehicleImagePath+'" alt="SUV Showcase" /></a>';
	spotlightHtml += '</div>';
	spotlightHtml += '<div class="content">';
	spotlightHtml += '<p><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += sptVeh.year+' '+sptVeh.make+'<br/>';
	spotlightHtml += sptVeh.model+'</a></p>';
	/**
	spotlightHtml += '<p>Out Rating :</p>';
	spotlightHtml += '<img src="'+sptVeh.vehicleCustomRatingImagePath+'" alt="Car Showcase" />';
	*/
	spotlightHtml += '<table cellspacing="0" cellpadding="2" border="0" align="left"><tbody>';
	spotlightHtml += '<tr><td>MSRP:</td><td>Rs.'+ CurrencyFormatted(sptVeh.maxPrice)+'</td></tr>';
	spotlightHtml += '</tbody></table>';
	spotlightHtml += '</div>';
	spotlightHtml += '<p class="allLink"><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Overview">Overview</a> |';
	spotlightHtml += ' <a href="vehicle_photos_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Photos">Photos</a> | ';
	spotlightHtml += '<a href="vehicle_features_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Features">Features</a> | ';
	spotlightHtml += '<a href="vehicle_pricing_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Pricing">Pricing</a></p>';
	$("#tabCont3").html(spotlightHtml);
}
TRS.TypeMap.CrossOverSpotType = function(data){
	var sptVeh = data.data[0];
	var ymm = sptVeh.year+' '+sptVeh.make+' '+sptVeh.model;
	var spotlightHtml = '<div class="imgContainer">';
	spotlightHtml += '<a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += '<img height="80" src="'+sptVeh.vehicleImagePath+'" alt="CrossOver Showcase" /></a>';
	spotlightHtml += '</div>';
	spotlightHtml += '<div class="content">';
	spotlightHtml += '<p><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += sptVeh.year+' '+sptVeh.make+'<br/>';
	spotlightHtml += sptVeh.model+'</a></p>';
	/**
	spotlightHtml += '<p>Out Rating :</p>';
	spotlightHtml += '<img src="'+sptVeh.vehicleCustomRatingImagePath+'" alt="Car Showcase" />';
	*/
	spotlightHtml += '<table cellspacing="0" cellpadding="2" border="0" align="left"><tbody>';
	spotlightHtml += '<tr><td>MSRP:</td><td>Rs.'+ CurrencyFormatted(sptVeh.maxPrice)+'</td></tr>';
	spotlightHtml += '</tbody></table>';
	spotlightHtml += '</div>';
	spotlightHtml += '<p class="allLink"><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Overview">Overview</a> |';
	spotlightHtml += ' <a href="vehicle_photos_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Photos">Photos</a> | ';
	spotlightHtml += '<a href="vehicle_features_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Features">Features</a> | ';
	spotlightHtml += '<a href="vehicle_pricing_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Pricing">Pricing</a></p>';
	$("#tabCont4").html(spotlightHtml);
}
TRS.TypeMap.VanSpotType = function(data){
	var sptVeh = data.data[0];
	var ymm = sptVeh.year+' '+sptVeh.make+' '+sptVeh.model;
	var spotlightHtml = '<div class="imgContainer">';
	spotlightHtml += '<a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += '<img height="80" src="'+sptVeh.vehicleImagePath+'" alt="Van Showcase" /></a>';
	spotlightHtml += '</div>';
	spotlightHtml += '<div class="content">';
	spotlightHtml += '<p><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="'+ymm+'">';
	spotlightHtml += sptVeh.year+' '+sptVeh.make+'<br/>';
	spotlightHtml += sptVeh.model+'</a></p>';
	/**
	spotlightHtml += '<p>Out Rating :</p>';
	spotlightHtml += '<img src="'+sptVeh.vehicleCustomRatingImagePath+'" alt="Car Showcase" />';
	*/
	spotlightHtml += '<table cellspacing="0" cellpadding="2" border="0" align="left"><tbody>';
	spotlightHtml += '<tr><td>MSRP:</td><td>Rs.'+ CurrencyFormatted(sptVeh.maxPrice)+'</td></tr>';
	spotlightHtml += '</tbody></table>';
	spotlightHtml += '</div>';
	spotlightHtml += '<p class="allLink"><a href="vehicle_overview_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Overview">Overview</a> |';
	spotlightHtml += ' <a href="vehicle_photos_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Photos">Photos</a> | ';
	spotlightHtml += '<a href="vehicle_features_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Features">Features</a> | ';
	spotlightHtml += ' <a href="vehicle_pricing_home.jsp?mov='+sptVeh.vehicleID+'&'+cssSwitchURL+'" title="Pricing">Pricing</a></p>';
	$("#tabCont5").html(spotlightHtml);
}
// New function added to browse all car brands - removed the filter that displays only 15 brands
TRS.TypeMap.BrowseByAllBrands = function (data){
		
		var element = $("div[@name=" + data.dataProviderName + "]");
		var dataLength = data.data.length;
		var midPoint = 10;
		
		var htmCode = '<div class="csBrand">'; 
		htmCode += '<div class="csContainer_title">Choose by Brand</div>';
		htmCode += '<table width="145" cellspacing="0" cellpadding="0" border="0" align="left">';
		htmCode += '<tbody>';
		for(var i = 0; i <  midPoint; i++){
			htmCode += '<tr>';
			htmCode += '<td valign="top" style="width:50px;height:23px;" ><a href="search_vehicle.jsp?bov='+data.data[i].text+'&'+cssSwitchURL+'" title="'+data.data[i].text+'" onclick="javascript: trilogy_autoretail_onMakeSelectionListener(\''+data.data[i].text+'\')">'+data.data[i].text+' </a></td>';
			if(midPoint+i < dataLength){
				htmCode += '<td valign="top" style="width:50px;height:23px;" align="left"><a href="search_vehicle.jsp?bov='+data.data[midPoint + i].text+'&'+cssSwitchURL+'" title="'+data.data[midPoint + i].text+'" onclick="javascript: trilogy_autoretail_onMakeSelectionListener(\''+data.data[midPoint + i].text+'\')">'+data.data[midPoint + i].text+' </a></td>';
			}
			htmCode += '</tr>';
		}
		htmCode += '</tbody></table>';
		
		var rightBorder = document.getElementById("rightBordera");
		rightBorder.style.height = '342px';
		var leftBorder = document.getElementById("leftBordera");
		leftBorder.style.height = '342px';
		
		element.empty();
		element.append(htmCode);
}