function set_paging_for_dealer_listing_page(base_url)
{
	if(typeof document.getElementById('records').value != 'undefined' && document.getElementById('records').value!='-1')
	{
		document.location = 	base_url + "/records/" + document.getElementById('records').value;		
	}
}
function DealersSearchFormSubmit(){
	base = document.getElementById( "dealersSearchForm" ).action;
	
	with( document.dealersSearchForm )
	{
		if( state.value != "-1" && state.value != "0" ) base += "/State/" + state.value;
		if( zipCode.value != "" ){
			
			if(zipCode.value.length!=5 || isNaN(zipCode.value) )
			{
				alert("Enter a valid 5 digit zipcode");	
				zipCode.focus();
				return false;
			}			
			base += "/zipCode/" + zipCode.value;
		}
		if( withInRange.value != "-1" && withInRange.value != "0" ) base += "/withInRange/" + withInRange.value;
		if( dMake.value != "-1" ) base += "/dMake/" + dMake.value;
		if( dModel.value != "-1" ) base += "/dModel/" + dModel.value;
	}
	if(document.dealers_search_result)
	{
		with(document.dealers_search_result)
		{
			if(records.value != "-1") base += "/records/" + records.value;
		}
	}
	
	document.location = base;
	return false;
}

function NewsearchFormSubmit(){
	base = document.getElementById( "searchForm" ).action;
	
	with( document.searchForm )
	{
		if (typeof vehicle_type != "undefined" )
			if( vehicle_type.value != "-1" ) base += "/type/" + vehicle_type.value;
		
		if( year.value != "-1" ) base += "/Year/" + year.value;
		if( style.value != "-1" ) base += "/Style/" + style.value;
		if( make.value != "-1" ) base += "/Make/" + make.value;
		if( model.value != "-1" ) base += "/Model/" + model.value;				

		if ( typeof(new_or_used) != 'undefined' )
		{
			if( new_or_used != null )
			{
					if(new_or_used[0].checked==true)
						base += "/filter/" + new_or_used[0].value;
					
					if(new_or_used[1].checked==true)
						base += "/filter/" + new_or_used[1].value;
			}
		}
		
		
				
		// view select
		if (document.searchForm.view != undefined){
			var view_value = "";
			if(!view)
				view_value = "grid";
			else
			{
				for(var i = 0; i < view.length; i++) {
					if(view[i].checked) {
						view_value = view[i].value;
						;
					}
				}
			}		
			base += "/view/" + view_value;
		}
		// view select
		

		if(typeof zipcode != 'undefined' && typeof radzip != 'undefined' && !isNaN(zipcode.value) && zipcode.value.length==5 && radzip.value!="0" ) 
			base += "/zipcode/" + zipcode.value + "/searchradius/" + radzip.value + "/unit/miles";
		
		
		
		if( monthly.value != "-1" ) base += "/monthly/" + monthly.value;
	}

		if ($('psort') != null )
		{			
			if( document.getElementById('psort').value != "-1" ) base += "/psort/" + document.getElementById('psort').value;
			if( document.getElementById('ysort').value != "-1" ) base += "/ysort/" + document.getElementById('ysort').value;
			if( document.getElementById('ksort').value != "-1" ) base += "/ksort/" + document.getElementById('ksort').value;
			if( document.getElementById('msort').value != "-1" ) base += "/msort/" + document.getElementById('msort').value;
			if(typeof document.getElementById('osort') != 'undefined' && document.getElementById('osort').value != "-1" ) base += "/osort/" + document.getElementById('osort').value;
		}

	
	if(document.search_result)
	{
		with(document.search_result)
		{
			if(records.value != "-1") base += "/records/" + records.value;
		}
	}
	
	document.location = base;
}


function searchFormSubmit(){
	base = document.getElementById( "searchForm" ).action;
	
	with( document.searchForm )
	{
		if (typeof vehicle_type != "undefined" )
			if( vehicle_type.value != "-1" ) base += "/type/" + vehicle_type.value;
		
		if( year.value != "-1" ) base += "/Year/" + year.value;
		if( style.value != "-1" ) base += "/Style/" + style.value;
		if( make.value != "-1" ) base += "/Make/" + make.value;
		if( model.value != "-1" ) base += "/Model/" + model.value;				

		if ( typeof(new_or_used) != 'undefined' )
		{
			if( new_or_used != null )
			{
					if(new_or_used[0].checked == true)
						base += "/filter/" + new_or_used[0].value;
						
					if(new_or_used[1].checked == true)
						base += "/filter/" + new_or_used[1].value;
			}
		}
		
		
				
		// view select
		if (document.searchForm.view != undefined){
			var view_value = "";
			if(!view)
				view_value = "grid";
			else
			{
				for(var i = 0; i < view.length; i++) {
					if(view[i].checked) {
						view_value = view[i].value;
						;
					}
				}
			}		
			base += "/view/" + view_value;
		}
		// view select
		

		if(typeof zipcode != 'undefined' && typeof radzip != 'undefined' && !isNaN(zipcode.value) && zipcode.value.length==5 && radzip.value!="0" )
		{
			base += "/zipcode/" + zipcode.value + "/searchradius/" + radzip.value + "/unit/miles";			
		}
		
		if( psort.value != "-1" ) base += "/psort/" + psort.value;
		if( ysort.value != "-1" ) base += "/ysort/" + ysort.value;
		if( ksort.value != "-1" ) base += "/ksort/" + ksort.value;
		if( msort.value != "-1" ) base += "/msort/" + msort.value;
		if(typeof osort != 'undefined' && osort.value != "-1" ) base += "/osort/" + osort.value;
		
		if( monthly.value != "-1" ) base += "/monthly/" + monthly.value;
	}
	if(document.search_result)
	{
		with(document.search_result)
		{
			if(records.value != "-1") base += "/records/" + records.value;
		}
	}		
	
	document.location = base;
	return false;
}




function site_search()
{
	document.location = document.getElementById( "DetailsearchForm" ).action + escape( document.DetailsearchForm.search_text_box.value );
	return false;
}





function bidSearchFormSubmit(){
	base = document.getElementById( "searchForm" ).action;
	
	with( document.searchForm )
	{
		if( year.value != "-1" ) base += "/Year/" + year.value;
		if( style.value != "-1" ) base += "/Style/" + style.value;
		if( make.value != "-1" ) base += "/Make/" + make.value;
		if( model.value != "-1" ) base += "/Model/" + model.value;

		if( psort.value != "-1" ) base += "/psort/" + psort.value;
		if( ysort.value != "-1" ) base += "/ysort/" + ysort.value;
		if( ksort.value != "-1" ) base += "/ksort/" + ksort.value;
		if( msort.value != "-1" ) base += "/msort/" + msort.value;
		
		if( monthly.value != "-1" ) base += "/monthly/" + monthly.value;
	}
	if(document.search_result)
	{
		with(document.search_result)
		{
			if(records.value != "-1") base += "/records/" + records.value;
		}
	}
	//document.location = base + "/result.html";
	document.location = base;
}
function compareFormSubmit(){
		document.getElementById("search_result").submit();
}
function set_paging(base_url){
	if(document.search_result)
	{
		if (base_url == undefined) {
			base = document.getElementById( "search_result" ).action;
		} else {
			base = base_url;
		}
			
		if(document.search_result.records.value != "-1") base += "/records/" + document.search_result.records.value;
		document.location = base;
	}
}
function IsCurrencyValid(amount)
{
	//// Allows commas and decimal points.
	var regexpression = /^\d+(,\d+)*(\.\d{2})*$/;
	
	if(regexpression.test(amount))
	{
		return true;
	}
	else
	{
		return false;	
	}
	
}
function FilterCurrency(amount)
{
	// Replace all commas from currencies input boxes
	var f;
	f = amount.replace(/,/g,"");
	f = f.replace(/ /g,"");
	return f;
}
function xajax_show_models_for_vechicle(make)
{
		new Ajax.Updater('show_models', '/ajax_functions/show_models_for_vechicle/' + make, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_show_vehicle_styles(make,model)
{
		new Ajax.Updater('show_styles', '/ajax_functions/show_vehicle_styles/' + make + '/' + model, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_show_reserve_price(vid,offerprice)
{
		new Ajax.Updater('footer', '/ajax_functions/show_reserve_price/' + vid + '/' + offerprice, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_add_to_compare(vin)
{
	new Ajax.Updater('footer', '/ajax_functions/add_to_compare/' + vin, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_view_video(video)
{
	new Ajax.Updater('enlarge_image', '/ajax_functions/view_video/' + video, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_show_models_for_vehicle_alerts(make)
{
	new Ajax.Updater('alert_model', '/ajax_functions/show_models_for_vehicle_alerts/' + make, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_delete_from_compare(cvin)
{
	new Ajax.Updater('footer', '/ajax_functions/delete_from_compare/' + cvin, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_clear_all_vehicles()
{
	new Ajax.Updater('footer', '/ajax_functions/clear_all_vehicles/', {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function xajax_vehicle_type_changed(vehicle_type)
{
	new Ajax.Updater('footer', '/ajax_functions/vehicle_type_changed/' + vehicle_type, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});	
}
function xajax_TopVehiclesOfBrand(param1,param2)
{
	new Ajax.Updater('brand_vehicles', '/ajax_functions/TopVehiclesOfBrand/' + param1 + '/' + param2, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});	
}
function xajax_SearchDdlChanged(is_merrimack,ddlName)
{
	with( document.searchForm )
	{
		if ( typeof(new_or_used) != 'undefined' )
		{
			if( new_or_used != null )
			{
				if(new_or_used[0].checked==true)
					is_merrimack = new_or_used[0].value;
				
				if(new_or_used[1].checked==true)
					is_merrimack = new_or_used[1].value;
			}
		}
	}
	
	if(ddlName!="year" && $('year')!=null && $('year').value=="-1")
	{
		new Ajax.Updater('show_years', '/ajax_functions/show_years_for_vehicles/' + $('model').value + '/' + $('make').value + '/' + $('style').value + '/' + is_merrimack, {onLoading:function(request,json){ $('show_years').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});	
	}
	
	if(ddlName!="make" && $('year')!=null && $('make').value=="-1")
	{
		new Ajax.Updater('makez', '/ajax_functions/show_makes_for_vehicles/' + $('year').value + '/' + $('model').value + '/' + $('style').value + '/' + is_merrimack, {onLoading:function(request,json){ $('makez').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
	}
	
	if(ddlName!="style" && $('year')!=null && $('style').value=="-1")
	{
		new Ajax.Updater('show_styles', '/ajax_functions/show_vehicle_styles/' + $('make').value + '/' + $('model').value + '/' + $('year').value + '/' + is_merrimack, {onLoading:function(request,json){ $('show_styles').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
	}
	
	if(ddlName!="model" && $('model').value=="-1")
	{
		if($('year')==null)
			year = "-1";
		else
			year = $('year').value;			
		
		make = 	$('make').value;
		
		
		new Ajax.Updater('show_models', '/ajax_functions/show_models_for_vechicle/' + make + '/' + $('style').value + '/' + year + '/' + is_merrimack, {onLoading:function(request,json){ $('show_models').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
	}
	
}
function xajax_SearchDdlChanged_v1(div_id)
{
	make = $('dealersSearchForm').make.value;
	year = "-1";
	is_merrimack = "yes";
	new Ajax.Updater(div_id, '/ajax_functions/show_models_for_vechicle/' + make + '/-1/' + year + '/' + is_merrimack, {asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
}
function resetAllCombos(is_merrimack)
{
	year = "-1";
	make = "-1";
	model = "-1";
	style = "-1";
	
	new Ajax.Updater('show_years', '/ajax_functions/show_years_for_vehicles/' + model + '/' + make + '/' + style + '/' + is_merrimack, {onLoading:function(request,json){ $('show_years').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
	
	new Ajax.Updater('makez', '/ajax_functions/show_makes_for_vehicles/' + year + '/' + model + '/' + style + '/' + is_merrimack, {onLoading:function(request,json){ $('makez').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
	
	new Ajax.Updater('show_styles', '/ajax_functions/show_vehicle_styles/' + make + '/' + model + '/' + year + '/' + is_merrimack, {onLoading:function(request,json){ $('show_styles').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});
	
	new Ajax.Updater('show_models', '/ajax_functions/show_models_for_vechicle/' + make + '/' + style + '/' + year + '/' + is_merrimack, {onLoading:function(request,json){ $('show_models').innerHTML = '<img src="/images/ajax-loading.gif" border="0" />'; } ,asynchronous:true, evalScripts:true, onComplete:function(request, json){void(0);}, parameters:'id=1'});	
}