/* search for particular cars javascript */

// set the timer id
var timerID = null;

function ShowCarDetail(URL)
{
	// show the ajax throbber
	ShowThrobber();
	
	// handles the on success state
	var handlerfunc = function(t)
	{			
		setTimeout(function() 
		{
			// hide the ajax throbber
			HideThrobber();
		}, 500);
	}
	
	// update the car details div with the required data..
	new Ajax.Updater('car_details', URL, {evalScripts:true,onSuccess:handlerfunc});
}

// Display the postal address details if required
function ShowOrHideDiv(DivName, ShowDiv)
{
//	var ShowDiv = document.getElementById(CheckBoxName).checked;

	// if the postal details are required - display
	if (ShowDiv=='Show')
	{
		Effect.BlindDown(DivName, {duration: 0.5});
		document.getElementById(DivName.concat('_show_button')).style.display = 'none';
		document.getElementById(DivName.concat('_hide_button')).style.display = 'inline';
	}
	else // otherwise - hide
	{
		Effect.BlindUp(DivName, {duration: 0.5});
		document.getElementById(DivName.concat('_show_button')).style.display = 'inline';
		document.getElementById(DivName.concat('_hide_button')).style.display = 'none';
	}
}


// display the required details in the region search form area
function UpdateRegionSearch(element, DivName, URL)
{
	// show the ajax throbber
	ShowThrobber();
	
	// handles the on success state
	var handlerfunc = function(t)
	{			
		setTimeout(function() 
		{
			// hide the ajax throbber
			HideThrobber();
		}, 500);
	}
	
	// get the value for the current element..
	var RegionValue = element.value;
	
	// append the value to the end of the url..
	URL += '&SearchType='.concat(RegionValue);
	
	// update the div
	new Ajax.Updater(DivName, URL, {evalScripts:true, onSuccess:handlerfunc});
}

function UpdateRegionLocationDiv(Div, URL)
{
	// set the vars..
	var State = '';
	var Region = '';
	var RegionLocation = '';
	
	// get the state, region and location values from the list..
	var LocationDiv = document.getElementById(Div);
	
	// get all the select elements within this div..
	var DropBoxes = LocationDiv.getElementsByTagName('select');
	
	// iterate through the drop boxes and get the values..
	for (i = 0; i < DropBoxes.length; i++)
	{
		if (DropBoxes[i].id == Div.concat('_state'))
			State = DropBoxes[i].value;
		else if (DropBoxes[i].id == Div.concat('_region'))
			Region = DropBoxes[i].value;
		else if (DropBoxes[i].id == Div.concat('_location'))
			RegionLocation = DropBoxes[i].value;
	}
	
	// append state, region and location values to the url..
	URL += '&State=' + State + '&Region=' + Region + '&Location=' + RegionLocation;
	
	//  update the div..
	UpdateDiv(Div, URL);
}



// Show the photo in the frame..
function ShowPhoto(URL)
{
	// stop the slide show if there is one
	if (timerID)
		clearTimeout(timerID);
		
	// update the photo section..
	new Ajax.Updater('car_images', URL, {evalScripts:true});
}

// start the slide show
function StartSlideShow(URL)
{
	// goto the next slide
	NextSlide(URL);
}

// stop the slide show
function StopSlideShow(URL)
{
	// update the photo section..
	if (timerID)
		clearTimeout(timerID);
	
	// update the ajax with the new item..
	new Ajax.Updater('car_images', URL, {evalScripts:true});
}

// goto the next slide in the slideshow
function NextSlide(URL)
{
	// update the photo section.. after 3 seconds
	timerID = setTimeout(function() 
	{
		new Ajax.Updater('car_images', URL, {evalScripts:true});
	}, 3000);	
}

// updates the shortlist
function UpdateShortlist(URL)
{	
	// show the ajax throbber
	ShowThrobber();
	
	// handles the on success state
	var handlerfunc = function(t)
	{			
		setTimeout(function() 
		{
			// hide the ajax throbber
			HideThrobber();
		}, 500);
	}
	
	// run the xmlhttp request and get the data..
	new Ajax.Updater('user_short_list', URL, {onSuccess:handlerfunc});
}

// updates the browsing shortlist
function UpdateBrowseShortlist(DivID, URL)
{	
	// show the ajax throbber
	ShowThrobber();
	
	// handles the on success state
	var handlerfunc = function(t)
	{			
		setTimeout(function() 
		{
			// hide the ajax throbber
			HideThrobber();
		}, 500);
	}
	
	// run the xmlhttp request and get the data..
	new Ajax.Updater(DivID, URL, {onSuccess:handlerfunc});
}

// updates the browsing comparelist
function UpdateBrowseComparelist(DivID, AdvertID, URL, UpdateURL)
{	
	// show the ajax throbber
	ShowThrobber();
	
	// handles the on success state
	var handlerfunc = function(t)
	{			
		setTimeout(function() 
		{
			// hide the ajax throbber
			HideThrobber();
			
			// now foreach compare div on the page.. update the details..
			var CompareDivs = getElementsByClassName(document, "div", "compare_list_option");

			// iterate and set the compare options..
			for (var i = 0; i <= (CompareDivs.length - 1); i++)
			{
				// get the advert id for the div..
				var CompareID = CompareDivs[i].id;
				var CompareParts = CompareID.toString().split('_');		
				new Ajax.Updater(CompareID, UpdateURL.concat('&AdvertID=').concat(CompareParts[3]), {});
			}
			
		}, 500);
	}
	
	// run the xmlhttp request and get the data..
	new Ajax.Updater(DivID.concat('_').concat(AdvertID), URL, {onSuccess:handlerfunc});
}


function GetNextResult(URL)
{	
	// show the ajax throbber
	ShowThrobber();
	
	// handles the on success state
	var handlerfunc = function(t)
	{			
		setTimeout(function() 
		{
			// hide the ajax throbber
			HideThrobber();
		}, 500);
	}
	
	// get the car details
	new Ajax.Updater('all_details', URL, {evalScripts:true,onSuccess:handlerfunc});
}

function GetSortedResults(DivName, URL)
{
	var OrderBy = document.getElementById('order_by').value;
	var OrderType = document.getElementById('order_type').value;
	var ItemsPerPage = document.getElementById('items_per_page').value;
	URL += "&OrderBy="+OrderBy+"&OrderType="+OrderType+"&PerPage="+ItemsPerPage;

	new Ajax.Updater(DivName, URL, {evalScripts:true});
}

function GetSortedResults2(DivName, URL)
{
	var OrderBy = document.getElementById('order_by').value;
	var OrderType = document.getElementById('order_type').value;
	var ItemsPerPage = document.getElementById('items_per_page').value;
	URL += "&OrderBy="+OrderBy+"&OrderType="+OrderType+"&PerPage="+ItemsPerPage;

	self.location=URL;
	// remove ajax - rdiaz - 14-12-07
	//new Ajax.Updater(DivName, URL, {evalScripts:true});
}

function AdvancedSearch()
{
	var elem = document.getElementById('QuickSearch').elements;
	//var QuickSearch = document.getElementById('QuickSearch');
	//Selects = QuickSearch.getElementsByTagName("select");
	//alert(Selects.length);	
	var URL = "index.htm?Action=used_car_search&";
	for(i=0; i< elem.length; i++)
	{
	//	if(elem[i].name.indexOf("SearchFormData") >= 0)
			URL += elem[i].name+"="+elem[i].value+"&";
	}
//	alert(URL);
	
	window.document.location = URL;
	
}
/* end of file */
