﻿Type.registerNamespace('Vehix.Presentation.Inventory')
Vehix.Presentation.Inventory.Selector = function(id,validationGroup,conditionElementIDs,certifiedPreOwnedElementID,yearRangeHighElementID,yearRangeLowElementID,bodyStyleElementID,makeElementID,modelElementID,trimElementID,priceRangeHighElementID,priceRangeLowElementID,priceQuoteElementID,radiusElementID,zipElementID,navigateElementID,href,scopeKey)
{
	Vehix.Presentation.Inventory.Selector.initializeBase(this);
	
	var element;
	
	this.set_id(id);
	this.set_enableChangedEvent(false);
	this._validationGroup = validationGroup;

	this._newConditionElementID = conditionElementIDs[0];
	this._usedConditionElementID = conditionElementIDs[1];
	this._bothConditionElementID = conditionElementIDs[2];
	this._certifiedPreOwnedElementID = certifiedPreOwnedElementID;
	this._yearRangeHighElementID = yearRangeHighElementID;
	this._yearRangeLowElementID = yearRangeLowElementID;
	
	this._bodyStyleElementID = bodyStyleElementID;
	if(element = $get(this._bodyStyleElementID))
	{
		element.onchange = new Function('$find(\''+ id +'\').changed(\'bodyStyle\',this.options[this.selectedIndex].value)');
	}

	this._makeElementID = makeElementID;
	if(element = $get(this._makeElementID))
	{
		element.onchange = new Function('$find(\''+ id +'\').changed(\'make\',this.options[this.selectedIndex].value)');
	}
	
	this._modelElementID = modelElementID;
	if(element = $get(this._modelElementID))
	{
		element.onchange = new Function('$find(\''+ id +'\').changed(\'model\',this.options[this.selectedIndex].value)');
	}
	
	this._trimElementID = trimElementID;
	if(element = $get(this._trimElementID))
	{
		element.onchange = new Function('$find(\''+ id +'\').changed(\'trim\',this.options[this.selectedIndex].value)');
	}
	
	this._priceRangeHighElementID = priceRangeHighElementID;
	this._priceRangeLowElementID = priceRangeLowElementID;
	
	this._priceQuoteElementID = priceQuoteElementID;
	this._radiusElementID = radiusElementID;
	this._zipElementID = zipElementID;
	
	this._navigateElementID = navigateElementID;
	if(element = $get(this._navigateElementID))
	{
		element.href = 'javascript:$find(\''+ id +'\').navigate()';
	}
	
	this._href = href;

	if(Sys.Application.findComponent(id) == null)
	{
		Sys.Application.addComponent(this);
		Sys.Application.add_load(new Function('if(!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()){$find(\''+ id+'\').restore()}'));	
	}
	
	this._scopeKey = scopeKey;
}
Vehix.Presentation.Inventory.Selector.prototype = 
{
	get_category : function()
	{
		return this._category;
	},
	get_condition : function()
	{
		var result = 0;
		var elements = [$get(this._newConditionElementID),$get(this._usedConditionElementID),$get(this._bothConditionElementID)];
		if(elements[0] && elements[0].checked)
		{
			result = 1;
		}
		if(elements[1] && elements[1].checked)
		{
			result = 2;
		}
		if(elements[2] && elements[2].checked)
		{
			result = 3;
		}
		return result;
	},
	set_condition : function(value)
	{
		var elements = [$get(this._newConditionElementID),$get(this._usedConditionElementID),$get(this._bothConditionElementID)];
		if(elements[0] && elements[1] && elements[2])
		{
			elements[0].checked = (value == 1)
			elements[1].checked = (value == 2)
			elements[2].checked = (value == 3)
		}
	},
	get_certifiedPreOwned : function()
	{
		var result = false;
		var element = $get(this._certifiedPreOwnedElementID);
		if(element)
		{
			result = element.checked;
		}
		return result;
	},
	set_certifiedPreOwned : function(value)
	{
		var element = $get(this._certifiedPreOwnedElementID);
		if(element)
		{
			element.checked = value;
		}
	},
	get_yearHigh : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._yearRangeHighElementID));
	},
	set_yearHigh : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._yearRangeHighElementID),value);
	},
	get_yearLow : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._yearRangeLowElementID));
		
	},
	set_yearLow : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._yearRangeLowElementID),value);
	},
	get_bodyStyle : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._bodyStyleElementID));
	},
	set_bodyStyle : function(value)
	{
		var element = $get(this._bodyStyleElementID);
		if(element)
		{
			Vehix.Presentation.trySetSelectedValue(element,value);	
			Sys.UI.Behavior.getBehaviorByName(element,'CascadingDropDownBehavior').set_SelectedValue(value);
		}
	},
	get_make : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._makeElementID));
	},
	set_make : function(value)
	{
		var element = $get(this._makeElementID);
		if(element)
		{
			Vehix.Presentation.trySetSelectedValue(element,value);	
			Sys.UI.Behavior.getBehaviorByName(element,'CascadingDropDownBehavior').set_SelectedValue(value);
		}
	},
	get_model : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._modelElementID));
	},
	set_model : function(value)
	{
		var element = $get(this._modelElementID);
		if(element)
		{
			Vehix.Presentation.trySetSelectedValue(element,value);	
			Sys.UI.Behavior.getBehaviorByName(element,'CascadingDropDownBehavior').set_SelectedValue(value);
		}
	},
	get_trim : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._trimElementID));
	},
	set_trim : function(value)
	{
		var element = $get(this._trimElementID);
		if(element)
		{
			Vehix.Presentation.trySetSelectedValue(element,value);	
			Sys.UI.Behavior.getBehaviorByName(element,'CascadingDropDownBehavior').set_SelectedValue(value);
		}
	},
	get_priceLow : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._priceRangeLowElementID));
	},
	set_priceLow : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._priceRangeLowElementID),value);
	},
	get_priceHigh : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._priceRangeHighElementID));
	},
	set_priceHigh : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._priceRangeHighElementID),value);
	},
	get_priceQuote : function()
	{
		var result = null;
		var element = $get(this._priceQuoteElementID);
		if(element)
		{
			result = element.checked;
		}
		return result;
	},
	set_priceQuote : function(value)
	{
		var element = $get(this._priceQuoteElementID);
		if(element)
		{
			element.checked = value;
		}
	},	
	get_radius : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._radiusElementID));
	},
	set_radius : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._radiusElementID),value);
	},
	get_zip : function()
	{
		var result = null;
		var element = $get(this._zipElementID);
		if(element)
		{
			result = element.value;
		}
		return result;
	},
	set_zip : function(value)
	{
		var element = $get(this._zipElementID);
		if(element)
		{
			element.value = value;
		}
	},
	get_href : function()
	{
		return this._href;
	},
	set_href : function(value)
	{
		this._href = value;
	},
	restore : function(state)
	{
		if(!state) state = Vehix.Presentation.getCookie('Inventory Selector State');
		if(state)
		{
			try
			{
				this.set_enableChangedEvent(false);
				state = eval('('+ state +')')
				if(state.scopeKey == this._scopeKey)
				{
					this.set_condition(state.condition);
					this.set_certifiedPreOwned(state.certifiedPreOwned);
					this.set_yearHigh(state.yearHigh);
					this.set_yearLow(state.yearLow);
					this.set_bodyStyle(state.bodyStyle);
					this.set_make(state.make);
					this.set_model(state.model);
					this.set_trim(state.trim);
					this.set_priceHigh(state.priceHigh);
					this.set_priceLow(state.priceLow);
					this.set_priceQuote(state.priceQuote);
					this.set_radius(state.radius);
					this.set_zip(state.zip);
				}
			}
			catch(e)
			{
				alert(e.message);
			}
			finally
			{
				this.set_enableChangedEvent(true);
			}
		}
	},
	persist : function()
	{
		var expires = new Date();
		expires.setTime(expires.getTime() + (3600000 * 1));
		Vehix.Presentation.setCookie('Inventory Selector State',{scopeKey:this._scopeKey,condition:this.get_condition(),certifiedPreOwned:this.get_certifiedPreOwned(),yearLow:this.get_yearLow(),yearHigh:this.get_yearHigh(),bodyStyle:this.get_bodyStyle(),make:this.get_make(),model:this.get_model(),trim:this.get_trim(),priceLow:this.get_priceLow(),priceHigh:this.get_priceHigh(),priceQuote:this.get_priceQuote(),radius:this.get_radius(),zip:this.get_zip()},expires);
	},
	navigate : function()
	{
		if(Page_ClientValidate(this._validationGroup) == true)
		{
			this.persist();
			var href = this.get_href();
			var queryString = new Vehix.Presentation.QueryString(href);
			if(this.get_condition())
			{
				queryString.set_item('condition',this.get_condition());
			}
			if(this.get_certifiedPreOwned())
			{
				queryString.set_item('condition',4);
			}
			if(this.get_yearLow())
			{
				queryString.set_item('yearbeg',this.get_yearLow());
			}
			if(this.get_yearHigh())
			{
				queryString.set_item('yearend',this.get_yearHigh());
			}
			if(this.get_bodyStyle())
			{
				queryString.set_item('bodystyle',this.get_bodyStyle());
			}
			if(this.get_make())
			{
				queryString.set_item('make',this.get_make());
			}
			if(this.get_model())
			{
				queryString.set_item('smodel',this.get_model());
			}
			if(this.get_trim())
			{
				queryString.set_item('trim',this.get_trim());
			}
			if(this.get_priceLow())
			{
				queryString.set_item('pricebeg',this.get_priceLow());
			}
			if(this.get_priceHigh())
			{
				queryString.set_item('priceend',this.get_priceHigh());
			}
			if(this.get_priceQuote())
			{
				queryString.set_item('noprice',this.get_priceQuote());
			}
			if(this.get_radius())
			{
				queryString.set_item('radius',this.get_radius());
			}
			if(this.get_zip())
			{
				queryString.set_item('zip',this.get_zip());
			}
			if(this.get_priceQuote() != null)
			{
				queryString.set_item('noprice',this.get_priceQuote());
			}
			document.location.href = queryString.toString(Vehix.Presentation.QueryString.stripQuery(href));
		}
	}
}
Vehix.Presentation.Inventory.Selector.registerClass('Vehix.Presentation.Inventory.Selector',Vehix.Presentation.Selector);

Vehix.Presentation.Inventory.EndecaSelector = function(id,validationGroup,makeElementID,modelElementID,bodyStyleElementID,priceElementID,yearElementID,yearFromElementID,yearToElementID,zipElementID,navigateElementID,href,scopeKey)
{
	Vehix.Presentation.Inventory.EndecaSelector.initializeBase(this);
	
	var element;
	
	this.set_id(id);
	this.set_enableChangedEvent(false);
	this._validationGroup = validationGroup;

	this._makeElementID = makeElementID;
	if(element = $get(this._makeElementID))
	{
		element.onchange = new Function('var s = $find(\''+ id +'\');s.set_enableChangedEvent(false);s.set_bodyStyle(\'\');s.set_price(\'\');s.set_enableChangedEvent(true);s.changed(\'make\',this.options[this.selectedIndex].value)');
	}
	
	this._modelElementID = modelElementID;
	if(element = $get(this._modelElementID))
	{
		element.onchange = new Function('var s = $find(\''+ id +'\');s.set_enableChangedEvent(false);s.set_bodyStyle(\'\');s.set_price(\'\');s.set_enableChangedEvent(true);s.changed(\'model\',this.options[this.selectedIndex].value)');
	}

	this._bodyStyleElementID = bodyStyleElementID;
	if(element = $get(this._bodyStyleElementID))
	{
		element.onchange = new Function('var s= $find(\''+ id +'\');s.set_enableChangedEvent(false);s.set_model(\'\');s.set_make(\'\');s.set_price(\'\');s.set_enableChangedEvent(true);s.changed(\'bodyStyle\',this.options[this.selectedIndex].value)');
	}
	
	this._priceElementID = priceElementID;
	if(element = $get(this._priceElementID))
	{
		element.onchange = new Function('var s = $find(\''+ id +'\');s.set_enableChangedEvent(false);s.set_model(\'\');s.set_make(\'\');s.set_bodyStyle(\'\');s.set_enableChangedEvent(true);s.changed(\'price\',this.options[this.selectedIndex].value)');
	}
	
	this._yearElementID = yearElementID;
	if(element = $get(this._yearElementID))
	{
		element.onchange = new Function('$find(\''+ id +'\').changed(\'year\',this.options[this.selectedIndex].value)');
	}
	
	this._yearFromElementID = yearFromElementID;
	if(element = $get(this._yearFromElementID))
	{
		element.onchange = new Function('$find(\''+ id +'\').changed(\'yearFrom\',this.options[this.selectedIndex].value)');
	}
	this._yearToElementID = yearToElementID;
	if(element = $get(this._yearToElementID))
	{
		element.onchange = new Function('$find(\''+ id +'\').changed(\'yearTo\',this.options[this.selectedIndex].value)');
	}

	this._zipElementID = zipElementID;
	
	this._navigateElementID = navigateElementID;
	if(element = $get(this._navigateElementID))
	{
		element.href = 'javascript:$find(\''+ id +'\').navigate()';
	}
	
	this._href = href;

	if(Sys.Application.findComponent(id) == null)
	{
		Sys.Application.addComponent(this);
		Sys.Application.add_load(new Function('if(!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()){$find(\''+ id+'\').restore()}'));	
	}
	
	this._scopeKey = scopeKey;
}
Vehix.Presentation.Inventory.EndecaSelector.prototype = 
{
	get_make : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._makeElementID));
	},
	set_make : function(value)
	{
		var element = $get(this._makeElementID);
		if(element)
		{
			Vehix.Presentation.trySetSelectedValue(element,value);	
			Sys.UI.Behavior.getBehaviorByName(element,'CascadingDropDownBehavior').set_SelectedValue(value);
		}
	},
	get_model : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._modelElementID));
	},
	set_model : function(value)
	{
		var element = $get(this._modelElementID);
		if(element)
		{
			if(!value || value == '')
			{
				element.disabled=true;
			}
			Vehix.Presentation.trySetSelectedValue(element,value);	
			Sys.UI.Behavior.getBehaviorByName(element,'CascadingDropDownBehavior').set_SelectedValue(value);
		}
	},
	get_bodyStyle : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._bodyStyleElementID));
	},
	set_bodyStyle : function(value)
	{
		var element = $get(this._bodyStyleElementID);
		if(element)
		{
			Vehix.Presentation.trySetSelectedValue(element,value);	
		}
	},
	get_price : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._priceElementID));
	},
	set_price : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._priceElementID),value);
	},
	get_year : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._yearElementID));
	},
	set_year : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._yearElementID),value);
	},
	get_yearFrom : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._yearFromElementID));
	},
	set_yearFrom : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._yearFromElementID),value);
	},
	get_yearTo : function()
	{
		return Vehix.Presentation.tryGetSelectedValue($get(this._yearToElementID));
		
	},
	set_yearTo : function(value)
	{
		Vehix.Presentation.trySetSelectedValue($get(this._yearToElementID),value);
	},
	get_zip : function()
	{
		var result = null;
		var element = $get(this._zipElementID);
		if(element)
		{
			result = element.value;
		}
		return result;
	},
	set_zip : function(value)
	{
		var element = $get(this._zipElementID);
		if(element)
		{
			element.value = value;
		}
	},
	get_href : function()
	{
		return this._href;
	},
	set_href : function(value)
	{
		this._href = value;
	},
	restore : function(state)
	{
		if(!state) state = Vehix.Presentation.getCookie('Inventory Selector State');
		if(state)
		{
			try
			{
				this.set_enableChangedEvent(false);
				state = eval('('+ state +')')
				if(state.scopeKey == this._scopeKey)
				{
					this.set_make(state.make);
					this.set_model(state.model);
					this.set_bodyStyle(state.bodyStyle);
					this.set_price(state.price);
					this.set_year(state.year);
					this.set_yearFrom(state.yearFrom);
					this.set_yearTo(state.yearTo);
					this.set_zip(state.zip);
				}
			}
			catch(e)
			{
				alert(e.message);
			}
			finally
			{
				this.set_enableChangedEvent(true);
			}
		}
	},
	persist : function()
	{
		var expires = new Date();
		expires.setTime(expires.getTime() + (3600000 * 1));
		Vehix.Presentation.setCookie('Inventory Selector State',{scopeKey:this._scopeKey,bodyStyle:this.get_bodyStyle(),make:this.get_make(),model:this.get_model(),price:this.get_price(),year:this.get_year(),yearFrom:this.get_yearFrom(),yearTo:this.get_yearTo(),zip:this.get_zip()},expires);
	},
	navigate : function()
	{
		if(Page_ClientValidate(this._validationGroup) == true)
		{
			this.persist();
			var href = this.get_href();
			var queryString = new Vehix.Presentation.QueryString(href);
			if(this.get_make())
			{
				queryString.set_item('make',this.get_make());
			}
			if(this.get_model())
			{
				queryString.set_item('smodel',this.get_model());
			}
			if(this.get_bodyStyle())
			{
				queryString.set_item('bodystyle',this.get_bodyStyle());
			}
			if(this.get_price())
			{
				queryString.set_item('price',this.get_price());
			}
			if(this.get_year())
			{
				queryString.set_item('year',this.get_year());
			}
			if(this.get_yearFrom())
			{
				queryString.set_item('yearbeg',this.get_yearFrom());
			}
			if(this.get_yearTo())
			{
				queryString.set_item('yearend',this.get_yearTo());
			}
			if(this.get_zip())
			{
				queryString.set_item('zip',this.get_zip());
			}
			document.location.href = queryString.toString(Vehix.Presentation.QueryString.stripQuery(href));
		}
	}
}
Vehix.Presentation.Inventory.EndecaSelector.registerClass('Vehix.Presentation.Inventory.EndecaSelector',Vehix.Presentation.Selector);

Vehix.Presentation.Inventory.InventorySearchResult = function(id,scopeKey,container,currentPage,pageCount,pageSize,noPriceBannerString,outOfMarketBannerString,currentPageLabel,listingsPerPage,ascendingSortButtons,descendingSortButtons,ascendingSortLinks,descendingSortLinks,pageLinkContaners,isMyVehix,isLoggedIn,isSellerInventory,searchResultState,dealerBannerState)
{
	Vehix.Presentation.Inventory.InventorySearchResult.initializeBase(this);
	this.set_id(id);
	this._scopeKey = scopeKey;
	this._container = container;
	this._currentPage = currentPage;
	this._pageSize = pageSize;
	this._noPriceBannerString = noPriceBannerString;
	this._outOfMarketBannerString = outOfMarketBannerString;
	this._sort = null;
	this._sortDirection = null;
	this._currentPageLabel = currentPageLabel;
	this._listingsPerPage = listingsPerPage;
	this._ascendingSortButtons = ascendingSortButtons;
	this._descendingSortButtons = descendingSortButtons;
	this._ascendingSortLinks = ascendingSortLinks;
	this._descendingSortLinks = descendingSortLinks;
	this._pageLinkContaners = pageLinkContaners;
	this._searchResultState = searchResultState;
	this._dealerBannerState = dealerBannerState;
	this._dealerBannerIndex = 0;
	this._refreshUnits = true;
	this._render = true;
	this._isMyVehix = isMyVehix;
	this._isLoggedIn = isLoggedIn;
	this._isSellerInventory = isSellerInventory;
	for(var index = 0;index < this._searchResultState.Vehicles.length;index++)
	{
		var vehicle = this._searchResultState.Vehicles[index];
		vehicle.Search = this._searchResultState;
		vehicle.get_seller = function() { return this.Search.Sellers[this.SellerIndex]; }
		vehicle.get_model = function() { return this.Search.Models[this.ModelIndex]; }
		vehicle.get_engine = function() { return this.Search.Engines[this.EngineIndex]; }
		vehicle.get_transmission = function() { return this.Search.Transmissions[this.TransmissionIndex]; }
		vehicle.get_color = function() { return this.Search.Colors[this.ColorIndex]; }
		vehicle.get_image = function() { return this.Search.Images[this.ImageIndex]; }
		vehicle.get_cssClass = function() { return this.Search.CssClasses[this.CssClassIndex]; }
	}
	if(this._dealerBannerState && this._dealerBannerState.length > 1)
	{
		this._dealerBannerState.sort(
			function(x,y)
			{
				if(x.InventoryUrl == y.InventoryUrl)
				{
					return 0;
				}
				var r = Math.random();
				if(r > .5)
				{
					return -1;
				}
				else
				{
					return 1;
				}
			}
		);
	}
	
	if(Sys.Application.findComponent(id) == null)
	{
		Sys.Application.addComponent(this);
		Sys.Application.add_load(new Function('if(!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()){$find(\''+ id +'\').restore()}'));	
	}
	
	this.bind();
}
Vehix.Presentation.Inventory.InventorySearchResult.prototype = 
{	
	get_pageSize : function()
	{
		return this._pageSize;
	},
	set_pageSize : function(value)
	{
		this._pageSize = value;
		for(var index = 0; index < this._listingsPerPage.Selectors.length;index++)
		{
			Vehix.Presentation.trySetSelectedValue($get(this._listingsPerPage.Selectors[index]),value);
		}
		this.persist();
		this._renderPageLinks();
		this.render();
	},
	get_currentPage : function()
	{
		return this._currentPage;
	},
	get_pageCount : function()
	{
		var result = 1;
		if(this._searchResultState && this._searchResultState.Vehicles && this._searchResultState.Vehicles.length > 0)
		{
			result = Math.ceil(this._searchResultState.Vehicles.length / this._pageSize);
		}
		return result;
	},
	get_enableRefreshUnits : function()
	{
		return this._enableRefreshUnits;
	},
	set_enableRefreshUnits : function(value)
	{
		this._enableRefreshUnits = value;
	},
	get_enableRender : function()
	{
		return this._render;
	},
	set_enableRender : function(value)
	{
		this._render = value;
	},
	_bindSortHeaders : function()
	{	
		function setClassName(elements,className)
		{
			for(var item in elements)
			{
				var item = $get(elements[item]);
				if(item != null)
				{
					item.className = className
				}
			}
		}

		setClassName(this._ascendingSortButtons, 'sortAscending_11x10');
		setClassName(this._descendingSortButtons,'vsHidden');
						
		if(this._sortDirection == Vehix.Presentation.SortDirection.Ascending)
		{
			$get(this._ascendingSortLinks[this._sort]).className = 'vsHidden'
			$get(this._ascendingSortButtons[this._sort]).className= 'vsHidden';
			$get(this._descendingSortLinks[this._sort]).className = 'headerSortLink'
			$get(this._descendingSortButtons[this._sort]).className = 'sortAscending_11x10';
		}
		else
		{
			$get(this._descendingSortLinks[this._sort]).className = 'vsHidden'
			$get(this._descendingSortButtons[this._sort]).className= 'vsHidden';
			$get(this._ascendingSortLinks[this._sort]).className = 'headerSortLink'
			$get(this._ascendingSortButtons[this._sort]).className = 'sortDescendingOn_11x10';
		}
	},
	_renderPageLinks : function()
	{
		if(this._render)
		{		
			var start = this.get_currentPage() - 4;
			if(start < 0)
			{
				start = 0;
			}
			var end = start + 10;
			if(end > this.get_pageCount())
			{
				end = this.get_pageCount();
			}
			var find = '$find(\''+ this.get_id() +'\')';	
			function renderPrevious(element)
			{
				var a = newAnchor();
				a.className = "grayLink";
				a.appendChild(newTextNode("<< Prev"));
				a.href = 'javascript:'+ find +'.pagePrevious()';		
				element.appendChild(a);
			}
			function renderNext(element)
			{
				var a = newAnchor();
				a.className = "grayLink";
				a.appendChild(newTextNode("Next >>"));
				a.href = 'javascript:'+ find +'.pageNext()';
				element.appendChild(a);
			}
			function renderSeperator(element)
			{
				var s = newSpan();
				s.appendChild(newTextNode(" : "));
				s.className = "orangeText"
				element.appendChild(s);
			}		
			function renderPageLink(element,currentPage,page)
			{
				var a = newAnchor();
				if(page == currentPage)
				{
					a.className = "blueBoldLink";
					a.href= 'javascript:void(0);';	
				}
				else
				{
					a.className = "grayLink " + page;
					a.href= 'javascript:'+ find +'.pageTo('+ page +');';
				}
				a.appendChild(newTextNode(String(page)));
				element.appendChild(a);
			}
			
			var currentPageLabel = $get(this._currentPageLabel[0]);
			currentPageLabel.innerHTML = '';
			currentPageLabel.appendChild(newTextNode("Page " + this.get_currentPage() + " of " + this.get_pageCount()));
			currentPageLabel = $get(this._currentPageLabel[1]);
			currentPageLabel.innerHTML = '';
			currentPageLabel.appendChild(newTextNode("Page " + this.get_currentPage() + " of " + this.get_pageCount()));
			
			for(var index = 0;index < this._pageLinkContaners.length;index++)		
			{
				var element = $get(this._pageLinkContaners[index]);
				element.innerHTML = '';
				if(this.get_currentPage() > 1)
				{
					renderPrevious(element);
					renderSeperator(element);
				}
				for(var current = start;current < end;current++)
				{
					var page = current + 1;
					renderPageLink(element,this.get_currentPage(),page);
					if(page != end)
					{
						renderSeperator(element)
					}
				}
				if(this.get_currentPage() < this.get_pageCount())
				{
					renderSeperator(element);
					renderNext(element);
				}
			}
		}
	},
	bind : function()
	{
		var find = '$find(\''+ this.get_id() +'\')';
		$get(this._ascendingSortButtons.Year).onclick = new Function('try{'+ find +'.sortByYear(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._ascendingSortButtons.Price).onclick = new Function('try{'+ find +'.sortByPrice(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._ascendingSortButtons.Mileage).onclick = new Function('try{'+ find +'.sortByMileage(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._ascendingSortButtons.Distance).onclick = new Function('try{'+ find +'.sortByDistance(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._descendingSortButtons.Year).onclick = new Function('try{'+ find +'.sortByYear(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		$get(this._descendingSortButtons.Price).onclick = new Function('try{'+ find +'.sortByPrice(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		$get(this._descendingSortButtons.Mileage).onclick = new Function('try{'+ find +'.sortByMileage(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		$get(this._descendingSortButtons.Distance).onclick = new Function('try{'+ find +'.sortByDistance(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		$get(this._ascendingSortLinks.Year).onclick = new Function('try{'+ find +'.sortByYear(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._ascendingSortLinks.Price).onclick = new Function('try{'+ find +'.sortByPrice(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._ascendingSortLinks.Mileage).onclick = new Function('try{'+ find +'.sortByMileage(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._ascendingSortLinks.Distance).onclick = new Function('try{'+ find +'.sortByDistance(Vehix.Presentation.SortDirection.Ascending);return false;}catch(e){return true;}')
		$get(this._descendingSortLinks.Year).onclick = new Function('try{'+ find +'.sortByYear(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		$get(this._descendingSortLinks.Price).onclick = new Function('try{'+ find +'.sortByPrice(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		$get(this._descendingSortLinks.Mileage).onclick = new Function('try{'+ find +'.sortByMileage(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		$get(this._descendingSortLinks.Distance).onclick = new Function('try{'+ find +'.sortByDistance(Vehix.Presentation.SortDirection.Descending);return false;}catch(e){return true;}')
		for(var index = 0; index < this._listingsPerPage.Selectors.length;index++)
		{
			$get(this._listingsPerPage.Selectors[index]).onchange = new Function('try{var selector = $get(\''+ this._listingsPerPage.Selectors[index] +'\');'+ find+'.set_pageSize(selector.options[selector.selectedIndex].value);return false;}catch(e){return true}');
		}
		this._renderPageLinks();
	},
	render : function()
	{
		if(this._render && this._searchResultState != null && this._searchResultState.Vehicles != null && this._searchResultState.Vehicles.length > 0)
		{
			var element = $get(this._container);
			var from = this.get_pageSize() * (this.get_currentPage() - 1)
			var to = from + this.get_pageSize();
			if(to > this._searchResultState.Vehicles.length)
			{
				to = this._searchResultState.Vehicles.length;
			}
			var bodyStyle = null;
			var model = null;
			s.products = '';
			element.innerHTML = '';
			var pageViewProductScope = new Vehix.Collections.Dictionary();
			
			function renderRowSeperator(element)
			{
				var d = newDiv();
				d.className = "DataRowSeparatorImage";
				element.appendChild(d);
			}
			
			function renderRow(element,vehicle,isMyVehix,isLoggedIn,pageSize,position)
			{
				var seller = vehicle.get_seller();
				var model = vehicle.get_model();
				var transmission = vehicle.get_transmission();
				var engine = vehicle.get_engine();
				var color = vehicle.get_color();
				var image = vehicle.get_image();
				var cssClass = vehicle.get_cssClass();
				var d = newDiv();
				d.className = "SearchDataRow" + cssClass;				
				var detailsUrl = Uri.resolveUrl("~/inventory/VehicleDetails.aspx").addQuery(document.location.search);
				detailsUrl.setQueryValue('SearchPageSize',pageSize)
				detailsUrl.setQueryValue('SearchPagePosition',position);
				detailsUrl.setQueryValue('inventoryid',vehicle.ID.Hex);
				var fadUrl = Uri.resolveUrl("~/dealer/findADealer.aspx").addQuery(document.location.search);				
				fadUrl.removeQueryValue('SearchPageSize');
				fadUrl.removeQueryValue('SearchPagePosition');
				fadUrl.removeQueryValue('make');
				fadUrl.removeQueryValue('model');
				fadUrl.removeQueryValue('inventoryid');
				fadUrl.setQueryValue('sellerid',seller.ID.Hex);
				var resolveDetailsUrl = detailsUrl.toString();
				renderPhotoColumn(d,vehicle.Gallery,resolveDetailsUrl,image,cssClass);
				renderYearMakeModelColumn(d,resolveDetailsUrl,model,vehicle.Style,vehicle.FormattedBodyStyle,isMyVehix,vehicle.ID.Hex,isLoggedIn,cssClass);
				renderPriceColumn(d,vehicle.FormattedPrice,cssClass);
				renderMileageColumn(d,vehicle.FormattedMileage,cssClass);
				renderSellerDistanceColumn(d,resolveDetailsUrl,fadUrl.toString(),seller,cssClass);
				renderInformationColumn(d,resolveDetailsUrl,vehicle.FormattedCondition,transmission,engine,color,cssClass);
				element.appendChild(d);				
			}
			
			function renderPhotoColumn(element,gallery,url,image,cssClass)
			{
				var d = newDiv();
				d.className = "ColumnPhoto" + cssClass;;
				var dPTB = newDiv();
				dPTB.className = "VehiclePhotoTopBorder" + cssClass;;
				d.appendChild(dPTB);
				var dVPC = newDiv();
				dVPC.className = "VehiclePhotoContainer" + cssClass;;
				d.appendChild(dVPC);
				var aVP = newAnchor();
				aVP.href = url;
				dVPC.appendChild(aVP);
				var iVP = document.createElement("img");
				iVP.src = image
				iVP.className = "VehiclePhoto" + cssClass;;
				iVP.onmouseout = function()
				{
					gvx_hidePopup();
				}
				iVP.onmouseover = function(event)
				{
					var e = event;
					if(!e)
						e = window.event;
					gvx_doHide=false;
					gvx_doPopupInfo(e, iVP);
				}
				iVP.alt = "";
				iVP.removeAttribute("height", 0);
				aVP.appendChild(iVP);
				var dPBB = newDiv();
				dPBB.className = "VehiclePhotoBottomBorder" + cssClass;;
				d.appendChild(dPBB);
				if(gallery)
				{
					var dMPL = newDiv();
					dMPL.className = "MultiPixLink";
					d.appendChild(dMPL);
					var aMPL = newAnchor();
					aMPL.className = "MultiPixIcon";
					aMPL.href = url;
					dMPL.appendChild(aMPL);
					var iMP = new Image();
					iMP.src = Uri.resolveUrl("~/_images/multipixicon" + cssClass + ".gif").toString();
					iMP.style.borderStyle = "none";
					aMPL.appendChild(iMP);
					var aMPTL = newAnchor();
					aMPTL.className = "grayLink";
					aMPTL.href = url;
					var txt = newTextNode("More Photos >>");
					aMPTL.appendChild(txt);
					dMPL.appendChild(aMPTL);
				}
				element.appendChild(d);
			}
			
			function renderYearMakeModelColumn(element,url,model,style,bodyStyle,isMyVehix,id,isLoggedIn,cssClass)
			{
				var d = newDiv();
				d.className = "ColumnYearModel" + cssClass
				var aY = newAnchor();
				aY.className = "grayLink block";
				aY.href = url;
				var tY = newTextNode(Vehix.Presentation.ToEmpty(model.Year));
				aY.appendChild(tY);
				d.appendChild(aY);
				var aMK = newAnchor();
				aMK.className = "grayLink block";
				aMK.href = url;
				var tMK = newTextNode(Vehix.Presentation.ToEmpty(model.Make));
				aMK.appendChild(tMK);
				d.appendChild(aMK);
				var aMD = newAnchor();
				aMD.className = "grayLink block";
				aMD.href = url;
				var tMD = newTextNode(Vehix.Presentation.ToEmpty(model.Name));
				aMD.appendChild(tMD);
				d.appendChild(aMD);
				var aT = newAnchor();
				aT.className = "grayLink block";
				aT.href = url;
				var tT = newTextNode(Vehix.Presentation.ToEmpty(style));
				aT.appendChild(tT);
				d.appendChild(aT);
				var aB = newAnchor();
				aB.className = "grayLink block";
				aB.href = url;
				var tB = newTextNode(Vehix.Presentation.ToEmpty(bodyStyle));
				aB.appendChild(tB);
				d.appendChild(aB);
				element.appendChild(d);
				if(isMyVehix)
				{
					var aB = newAnchor()
					aB.className='yearModelSaveHyperLink';
					aB.href = 'javascript:saveVehicle(this,\''+ id +'\','+ isLoggedIn +')';
					var tB = newTextNode('Save This Vehicle');
					aB.appendChild(tB);
				}
				d.appendChild(aB);
				element.appendChild(d);
			}
			
			function renderPriceColumn(element,price,cssClass)
			{
				var d = newDiv();
				d.className = "ColumnPrice" + cssClass;
				var dP = newDiv();
				dP.className = "VehiclePrice" + cssClass;
				var tP = newTextNode(price);
				dP.appendChild(tP);
				d.appendChild(dP);
				element.appendChild(d);
			}
			
			function renderMileageColumn(element,mileage,cssClass)
			{
				var d = newDiv();
				d.className = "ColumnMileage" + cssClass;
				var dM = newDiv();
				dM.className = "VehicleMileage" + cssClass;
				var tM = newTextNode(Vehix.Presentation.ToEmpty(mileage));
				dM.appendChild(tM);
				d.appendChild(dM);
				element.appendChild(d);
			}
			
			function renderSellerDistanceColumn(element,url,inventoryUrl,seller,cssClass)
			{
				var d = newDiv();
				d.className = "ColumnSellerDistance" + cssClass;
				var dS = newDiv();
				dS.className = "DealerName" + cssClass;
				var tS = newTextNode(seller.Name);
				dS.appendChild(tS);
				d.appendChild(dS);
				var dD = newDiv();
				dD.className = "DealerDistance" + cssClass;
				var tD = newTextNode(seller.FormattedDistance);
				dD.appendChild(tD);
				d.appendChild(dD);
				var dP = newDiv();
				dP.className = "DealerPhone" + cssClass;
				var tP = newTextNode(Vehix.Presentation.ToEmpty(seller.Phone));
				dP.appendChild(tP);
				d.appendChild(dP);
				if(seller.Name != 'Private Seller')
				{
					var a = newAnchor();
					a.className = "grayLink block";
					a.href = inventoryUrl;
					var tA = newTextNode("Search Dealer Inventory");
					a.appendChild(tA);
					d.appendChild(a);
				}
				if(seller.VideoUrl && seller.VideoUrl != '')
				{
					var a = newAnchor();
					var img = newImage();
					img.className = 'VideoIcon'
					img.src = Uri.resolveUrl("~/_images/videoicon"+ cssClass +'.gif').toString();
					a.className = "grayLink DealerVideoLink";
					a.href = 'javascript:doDealerVideo(this,\''+ seller.ID.Hex +'\',\''+ seller.VideoUrl +'\')';
					var tA = newTextNode("Dealer Video >>");
					a.appendChild(tA);
					d.appendChild(img);
					d.appendChild(a);					
				}
				element.appendChild(d);
			}
			
			function renderInformationColumn(element,url,condition,transmission,engine,color,cssClass)
			{
				var d = newDiv();
				d.className = "ColumnInformation" + cssClass;
				var dI = newDiv();
				dI.className = "VehicleCondition" + cssClass;
				d.appendChild(dI);
				var tI = newTextNode(Vehix.Presentation.ToEmpty(condition));
				dI.appendChild(tI);
				var tT = newTextNode(Vehix.Presentation.ToEmpty(transmission));
				d.appendChild(tT);
				d.appendChild(newBr());
				var tE = newTextNode(Vehix.Presentation.ToEmpty(engine));
				d.appendChild(tE);
				d.appendChild(newBr());
				var tC = newTextNode(Vehix.Presentation.ToEmpty(color));
				d.appendChild(tC);
				element.appendChild(d);
			}
			
			function renderGroupShowcaseAd(element,o)
			{
				if(s)
				{
					if(s.products.length > 0)
					{
						s.products += ',';
					}
					s.products += ';'+ o.id +':Inventory Seller Showcase Impression;;;event18=1';
				}
				var d = newDiv();
				d.className = "DealerShowcaseAdsPanel";
				var logo = new Image();
				logo.className = "ShowcaseAdsDealerGroupLogo";
				logo.src = Uri.resolveUrl("~/_images/!.gif").toString();
				if(o.LogoUrl != "")
					logo.src = o.LogoUrl;
				d.appendChild(logo);
				var dTl = newDiv();
				dTl.className = "ShowcaseAdsDealerGroupTaglinePanel";
				d.appendChild(dTl);
				var sTl = newSpan();
				sTl.className = "DealerGroupTagline";
				dTl.appendChild(sTl);
				var tTl = newTextNode(o.DealerGroupTagline);
				sTl.appendChild(tTl);
				var dL = newDiv();
				dL.className = "ShowcaseAdsDealerGroupLinksPanel";
				if(o.InventoryLink != "" && o.InventoryLink != "null")
				{
					var aD = newAnchor();
					aD.className = "ShowcaseAdsDealerGroupLink";
					aD.href = o.InventoryLink;
					var tD = newTextNode("Dealer Directory >>");
					aD.appendChild(tD);
					dL.appendChild(aD);
				}
				if(o.VideoUrl != "" && o.VideoUrl != "null")
				{
					var aV = newAnchor();
					aV.className = "ShowcaseAdsDealerGroupLink";
					aV.href = o.VideoUrl;
					var tV = newTextNode("Watch Video >>");
					aV.appendChild(tV);
					dL.appendChild(aV);
				}
				if(o.WebsiteUrl != "" && o.WebsiteUrl != "null")
				{
					var aW = newAnchor();
					aW.className = "ShowcaseAdsDealerGroupLink";
					aW.href = o.WebsiteUrl;
					var tW = newTextNode("Visit Website >>");
					aW.appendChild(tW);
					dL.appendChild(aW);
				}
				d.appendChild(dL);
				element.appendChild(d);
			}
			
			function renderShowcaseAd(element,o)
			{
				if(s)
				{
					if(s.products.length > 0)
					{
						s.products += ',';
					}
					s.products += ';'+ o.SellerId +':Inventory Seller Showcase Impression;;;event18=1';
				}
				var d = newDiv();
				d.className = "DealerShowcaseAdsPanel";
				var logo = new Image();
				logo.src = Uri.resolveUrl("~/_images/!.gif").toString();
				if(o.LogoUrl != "")
					logo.src = o.LogoUrl;
				logo.className = "ShowcaseAdsDealerLogo";
				d.appendChild(logo);
				var dA = newDiv();
				dA.className = "ShowcaseAdsDealerAddressPanel";
				d.appendChild(dA);
				var dN = newDiv();
				dN.className = "ShowcaseAdsDealerName";
				var tN = newTextNode(o.Name);
				dN.appendChild(tN);
				dA.appendChild(dN);
				var dAd = newDiv();
				dAd.className = "ShowcaseAdsDealerAddress";
				var tAd = newTextNode(o.Address);
				dAd.appendChild(tAd);
				dA.appendChild(dAd);
				var dCsz = newDiv();
				dCsz.className = "ShowcaseAdsDealerCityStateZip";
				var tCsz = newTextNode(o.City + ", " + o.State + " " + o.PostalCode);
				dCsz.appendChild(tCsz);
				dA.appendChild(dCsz);
				var dP = newDiv();
				dP.className = "ShowcaseAdsDealerPhone";
				var tP = newTextNode(o.Phone);
				dP.appendChild(tP);
				dA.appendChild(dP);
				var dL = newDiv();
				dL.className = "ShowcaseAdsDealerLinksPanel";
				if(o.InventoryUrl && o.InventoryUrl != "")
				{
					var aS = newAnchor();
					aS.className = "ShowcaseAdsDealerLink";
					aS.onclick = new Function('var ls = new s_gi(s_account);ls.eVar8=\''+ o.SellerId  +'\';ls.events=\'purchase\';ls.products = \';'+ o.SellerId +':Showcase Inventory Click Through\';ls.linkTrackVars = \'events,eVar8,products\';ls.linkTrackEvents = \'purchase\';ls.tl(this,\'o\',ls.products);document.location = this.href;');
					aS.href = o.InventoryUrl;
					var tS = newTextNode("Search Dealer Inventory >>");
					aS.appendChild(tS);
					dL.appendChild(aS);
				}
				if(o.FreePriceQuoteUrl && o.FreePriceQuoteUrl != "")
				{
					var aFpq = newAnchor();
					aFpq.className = "ShowcaseAdsDealerLink";
					aFpq.href = o.FreePriceQuoteUrl;
					aFpq.onclick = new Function('var ls = new s_gi(s_account);ls.eVar8=\''+ o.SellerId +'\';ls.events=\'purchase\';ls.products = \';'+ o.SellerId  +':Showcase Price Quote Click Through\';ls.linkTrackVars = \'events,eVar8,products\';ls.linkTrackEvents = \'purchase\';ls.tl(this,\'o\',ls.products);document.location = this.href;');
					var tFpq = newTextNode("Get a Free Price Quote >>");
					aFpq.appendChild(tFpq);
					dL.appendChild(aFpq);
				}
				if(o.VideoUrl && o.VideoUrl != "")
				{
					var aV = newAnchor();
					aV.className = "ShowcaseAdsDealerLink";
					aV.href = o.VideoUrl;
					aV.onclick = new Function('window.open(this.href,\'_blank\');var ls = new s_gi(s_account);ls.eVar8=\''+ o.SellerId +'\';ls.events=\'purchase\';ls.products = \';'+ o.SellerId + ':Showcase Advertisement Video Click Through\';ls.linkTrackVars = \'events,eVar8,products\';ls.linkTrackEvents = \'purchase\';ls.tl(this,\'o\',ls.products);return false;');
					var tV = newTextNode("Watch Dealer Video >>");
					aV.appendChild(tV);
					dL.appendChild(aV);
				}
				if(o.WebsiteUrl && o.WebsiteUrl != "")
				{
					var aW = newAnchor();
					aW.className = "ShowcaseAdsDealerLink";
					aW.onclick = new Function('window.open(this.href,\'_blank\');var ls = new s_gi(s_account);ls.eVar8=\''+ o.SellerId +'\';ls.events=\'purchase\';ls.products = \';'+ o.SellerId +':Showcase Website Click Through\';ls.linkTrackVars = \'events,eVar8,products\';ls.linkTrackEvents = \'purchase\';ls.tl(this,\'o\',ls.products);return false;');
					aW.href = o.WebsiteUrl;
					var tW = newTextNode("Visit the Dealer Website >>");
					aW.appendChild(tW);
					dL.appendChild(aW);
				}
				d.appendChild(dL);
				element.appendChild(d);
			}
			
			function renderBanner(element,s)
			{
				var d = newDiv();
				d.className = "DealersOutsideOfMarketBanner";
				var t = newTextNode(s);
				d.appendChild(t);
				element.appendChild(d);
			}
			
			for(var current = from;current < to;current++)
			{
				var vehicle = this._searchResultState.Vehicles[current];
				if(current != from)
				{
					renderRowSeperator(element);
				}
				bodyStyle = vehicle.BocdyStyle;
				model = vehicle.get_model();
				if(this._dealerBannerState && this._dealerBannerState.length > 0 && (current == from + 5 || (current - from != 0 && (current - from + 5) % 10 == 0)))
				{
					if(this._dealerBannerState[this._dealerBannerIndex].DealerGroupTagline && this._dealerBannerState[this._dealerBannerIndex].DealerGroupTagline != null)
					{
						renderGroupShowcaseAd(element,this._dealerBannerState[this._dealerBannerIndex]);
					}
					else
					{
						renderShowcaseAd(element,this._dealerBannerState[this._dealerBannerIndex]);
					}
					renderRowSeperator(element);
					this._dealerBannerIndex < this._dealerBannerState.length - 1 ? this._dealerBannerIndex++ : this._dealerBannerIndex = 0;
				}
				if(current != 0 && this._searchResultState.Vehicles[current-1].Price != 0 && this._searchResultState.Vehicles[current].Price == 0 && !this._isSellerInventory)
				{
					renderBanner(element,this._noPriceBannerString)
				}
				if(this._sort == null)
				{
					if(current != 0 && !this._searchResultState.Vehicles[current].get_seller().InMarket && this._searchResultState.Vehicles[current-1].get_seller().InMarket)
					{
						renderBanner(element,this._outOfMarketBannerString);
					}
				}
				renderRow(element,vehicle,this._isMyVehix,this._isLoggedIn,this.get_pageSize(),current);
				var count = 0;
				if(!pageViewProductScope.containsKey(vehicle.get_seller().ID.Hex))
				{
					pageViewProductScope.add(vehicle.get_seller().ID.Hex,count);
				}
				else
				{
					count = pageViewProductScope.get_item(vehicle.get_seller().ID.Hex);
				}
				count++;
				pageViewProductScope.set_item(vehicle.get_seller().ID.Hex,count);
			}
			if(this._enableRefreshUnits && ((bodyStyle != null || model != null) || current >= to))
			{
				if(!bodyStyle) 
				{
					bodyStyle = '';
				}
				setTimeout(new Function('refreshAds(\''+ bodyStyle +'\',\''+ model.Make +'\',\''+ model.Name +'\')'),1);
			}
			
			if(s && pageViewProductScope)
			{
				for(var enumerator = pageViewProductScope.getEnumerator();enumerator.moveNext();)
				{
					if(s.products.length > 0)
					{
						s.products += ',';
					}
					s.products += ';'+ enumerator.get_key() +';'+ enumerator.get_current();
				}
				s.t();
			}
		}
	},
	pageNext : function()
	{
		var nextIndex = this._currentPage + 1;
		if(this.get_pageCount() >= nextIndex )
		{
			this._currentPage = nextIndex
		}
		this.pageTo(this._currentPage);	
	},
	pagePrevious : function()
	{
		var previousIndex = this._currentPage - 1;
		if(previousIndex > 0)
		{
			this._currentPage = previousIndex
		}
		this.pageTo(this._currentPage);	
	},
	pageTo : function(pageIndex)
	{
		if(pageIndex > 0 && pageIndex <= this.get_pageCount())
		{
			this._currentPage = pageIndex;
			this._renderPageLinks();
			this.persist();
			this.render();
			window.scrollTo(0, 0);
		}
	},
	sortByYear : function(direction)
	{
		this._searchResultState.Vehicles.sort(
			function(x,y)
			{
				var result = 0;
				
				if(x.Price != 0 && y.Price == 0)
				{
					result--;
				}
				else if(x.Price == 0 && y.Price != 0)
				{
					result++;
				}
				
				if(result == 0)
				{
					x = x.get_model().Year;
					y = y.get_model().Year;
					if(x > y)
					{
						result++;
					}
					else if(x < y)
					{
						result--;
					}
					if(direction == Vehix.Presentation.SortDirection.Descending)
					{
						result = result * -1;
					}
				}
				return result;
			}
		)
		this._sort = 'Year';
		this._sortDirection = direction;
		this.pageTo(1);
		this._bindSortHeaders();
	},
	sortByPrice : function(direction)
	{
		this._searchResultState.Vehicles.sort(
			function(x,y)
			{
				var result = 0;
				
				if(x.Price != 0 && y.Price == 0)
				{
					result--;
				}
				else if(x.Price == 0 && y.Price != 0)
				{
					result++;
				}
				
				if(result == 0)
				{
					x = x.Price;
					y = y.Price;
					if(x > y)
					{
						result++;
					}
					else if(x < y)
					{
						result--;
					}
					if(direction == Vehix.Presentation.SortDirection.Descending)
					{
						result = result * -1;
					}
				}
				return result;
			}
		)
		this._sort = 'Price';
		this._sortDirection = direction;
		this.pageTo(1);
		this._bindSortHeaders();
	},
	sortByMileage : function(direction)
	{
		this._searchResultState.Vehicles.sort(
			function(x,y)
			{
				var result = 0;
				
				if(x.Price != 0 && y.Price == 0)
				{
					result--;
				}
				else if(x.Price == 0 && y.Price != 0)
				{
					result++;
				}
				
				if(result == 0)
				{
					x = x.Mileage;
					y = y.Mileage;
					if(x > y)
					{
						result++;
					}
					else if(x < y)
					{
						result--;
					}
					if(direction == Vehix.Presentation.SortDirection.Descending)
					{
						result = result * -1;
					}
				}
				return result;
			}
		)
		this._sort = 'Mileage';
		this._sortDirection = direction;
		this.pageTo(1);
		this.persist();
		this._bindSortHeaders();
	},
	sortByDistance : function(direction)
	{
		this._searchResultState.Vehicles.sort(
			function(x,y)
			{
				var result = 0;
				
				if(x.Price != 0 && y.Price == 0)
				{
					result--;
				}
				else if(x.Price == 0 && y.Price != 0)
				{
					result++;
				}
				
				if(result == 0)
				{
					x = x.get_seller().Distance;
					y = y.get_seller().Distance;
					if(x > y)
					{
						result++;
					}
					else if(x < y)
					{
						result--;
					}
					if(direction == Vehix.Presentation.SortDirection.Descending)
					{
						result = result * -1;
					}
				}
				return result;
			}
		)
		this._sort = 'Distnace';
		this._sortDirection = direction;
		this.pageTo(1);
		this.persist();
		this._bindSortHeaders();
	},
	restore : function(state)
	{
		if(!state) state = Vehix.Presentation.getCookie('Inventory Search State');
		if(state)
		{
			try
			{
				this.set_enableRefreshUnits(false);
				this.set_enableRender(false);
				state = eval('('+ state +')')
				if(state.scopeKey == this._scopeKey)
				{
					var render = false;
					if(state.sort)
					{
						if(state.sort == 'Year')
						{
							render = true;
							this.sortByYear(state.direction);
						}
						if(state.sort == 'Price')
						{
							render = true;
							this.sortByPrice(state.direction);
						}
						if(state.sort == 'Mileage')
						{
							render = true;
							this.sortByMileage(state.direction);
						}
						if(state.sort == 'Distance')
						{
							this.sortByDistance(state.direction);
						}
					}
					if(this._currentPage != state.currentPage)
					{
						render = true;
						this.pageTo(state.currentPage);
					}
					if(this.get_pageSize() != state.pageSize)
					{
						render = true;
						this.set_pageSize(state.pageSize);
					}
					if(render)
					{
						this.set_enableRender(true);
						this._renderPageLinks();
						this.render();
					}
				}
			}
			catch(e)
			{
				alert(e.message);
			}
			finally
			{
				this.set_enableRefreshUnits(true);
				this.set_enableRender(true);
			}
		}
	},
	persist : function()
	{
		var expires = new Date();
		expires.setTime(expires.getTime() + (3600000 * 1));
		Vehix.Presentation.setCookie('Inventory Search State',{scopeKey:this._scopeKey,pageSize:this.get_pageSize(),currentPage:this._currentPage,sort:this._sort,sortDirection:this._sortDirection},expires);
	}
}
Vehix.Presentation.Inventory.InventorySearchResult.registerClass('Vehix.Presentation.Inventory.InventorySearchResult',Sys.Component);


Type.registerNamespace('AjaxControlToolkit');AjaxControlToolkit.CascadingDropDownSelectionChangedEventArgs = function(oldValue, newValue) {
AjaxControlToolkit.CascadingDropDownSelectionChangedEventArgs.initializeBase(this);this._oldValue = oldValue;this._newValue = newValue;}
AjaxControlToolkit.CascadingDropDownSelectionChangedEventArgs.prototype = {
get_oldValue : function() {
return this._oldValue;},
get_newValue : function() {
return this._newValue;}
}