// JavaScript Document

function addBookmark()
{
	url = "http://www.motormart.co.uk/";
	title = "MotorMart.co.uk - The Car Search Engine";

	if(window.sidebar)								// Mozilla Firefox Bookmark
	{ 
		window.sidebar.addPanel(title, url,"");
	}
	else if(window.external)						// IE Favorite
	{
		window.external.AddFavorite(url, title);
	}
	else if(window.opera && window.print)			// Opera Hotlist
	{
		return true;
	}
 }

function write_email(bit03, bit04, bit01, bit02)
{
	document.write("<a href='mailto:" + bit01 + bit02 + bit03 + bit04 + "'>" + bit01 + bit02 + bit03 + bit04 + "</a>");
}

function hideQuickSearch()
{
	var theMinPrice			= document.getElementById("minPriceField");
	var theMaxPrice			= document.getElementById("maxPriceField"); 
	var thePostcode			= document.getElementById("postcodeField");
	var thePostcodeRequired	= document.getElementById("postcodeRequiredField");

	document.forms['quick_search'].min_price.disabled		=	true;
	document.forms['quick_search'].max_price.disabled		=	true;	
	document.forms['quick_search'].postcode.disabled		=	true;

	theMinPrice.style.display			= 'none';
	theMaxPrice.style.display			= 'none';
	thePostcode.style.display			= 'none';
	thePostcodeRequired.style.display	= 'none';	
	
	document.forms['quick_search'].min_price.backgroundColor		=	'';
	document.forms['quick_search'].max_price.backgroundColor		=	'';	
	document.forms['quick_search'].postcode.backgroundColor			=	'';	
}

function showQuickSearch()
{
	var theMinPrice			= document.getElementById("minPriceField");
	var theMaxPrice			= document.getElementById("maxPriceField"); 
	var thePostcode			= document.getElementById("postcodeField");
	var thePostcodeRequired	= document.getElementById("postcodeRequiredField");
	
	document.forms['quick_search'].min_price.disabled		=	false;
	document.forms['quick_search'].max_price.disabled		=	false;	
	document.forms['quick_search'].postcode.disabled		=	false;
	
	theMinPrice.style.display			= '';
	theMaxPrice.style.display			= '';
	thePostcode.style.display			= '';
	thePostcodeRequired.style.display	= '';
	
	document.forms['quick_search'].min_price.backgroundColor		=	'';
	document.forms['quick_search'].max_price.backgroundColor		=	'';	
	document.forms['quick_search'].postcode.backgroundColor			=	'';	
}

function hideMainSearch()
{
	var theThumbnailField	= document.getElementById("thumb_block");
	var thePostcodeRequired	= document.getElementById("postcode_required");
	
	document.forms['search_main'].seller.disabled			=	true;
	document.forms['search_main'].trim.disabled				=	true;
	document.forms['search_main'].min_price.disabled		=	true;
	document.forms['search_main'].max_price.disabled		=	true;
	document.forms['search_main'].mileage.disabled			=	true;
	document.forms['search_main'].year_made.disabled		=	true;
	document.forms['search_main'].fuel.disabled				=	true;
	document.forms['search_main'].transmission.disabled		=	true;
	document.forms['search_main'].distance.disabled			=	true;
	document.forms['search_main'].postcode.disabled			=	true;
	document.forms['search_main'].max_results.disabled		=	true;
	document.forms['search_main'].order_by.disabled			=	true;
	
	document.forms['search_main'].seller.style.backgroundColor			=	'#CCCCCC';
	document.forms['search_main'].trim.style.backgroundColor			=	'#CCCCCC';
	document.forms['search_main'].min_price.style.backgroundColor		=	'#CCCCCC';
	document.forms['search_main'].max_price.style.backgroundColor		=	'#CCCCCC';
	document.forms['search_main'].mileage.style.backgroundColor			=	'#CCCCCC';
	document.forms['search_main'].year_made.style.backgroundColor		=	'#CCCCCC';
	document.forms['search_main'].fuel.style.backgroundColor			=	'#CCCCCC';
	document.forms['search_main'].transmission.style.backgroundColor	=	'#CCCCCC';
	document.forms['search_main'].distance.style.backgroundColor		=	'#CCCCCC';
	document.forms['search_main'].postcode.style.backgroundColor		=	'#CCCCCC';
	document.forms['search_main'].max_results.style.backgroundColor		=	'#CCCCCC';
	document.forms['search_main'].order_by.style.backgroundColor		=	'#CCCCCC';
	
	theThumbnailField.style.visibility						=	'hidden';
	thePostcodeRequired.style.visibility					=	'hidden';
}

function showMainSearch()
{
	var theThumbnailField	= document.getElementById("thumb_block");
	var thePostcodeRequired	= document.getElementById("postcode_required");
	
	document.forms['search_main'].seller.disabled			=	false;
	document.forms['search_main'].trim.disabled				=	false;
	document.forms['search_main'].min_price.disabled		=	false;
	document.forms['search_main'].max_price.disabled		=	false;	
	document.forms['search_main'].mileage.disabled			=	false;
	document.forms['search_main'].year_made.disabled		=	false;
	document.forms['search_main'].fuel.disabled				=	false;
	document.forms['search_main'].transmission.disabled		=	false;
	document.forms['search_main'].distance.disabled			=	false;
	document.forms['search_main'].postcode.disabled			=	false;
	document.forms['search_main'].max_results.disabled		=	false;
	document.forms['search_main'].order_by.disabled			=	false;
	
	document.forms['search_main'].seller.style.backgroundColor			=	'';
	document.forms['search_main'].trim.style.backgroundColor			=	'';
	document.forms['search_main'].min_price.style.backgroundColor		=	'';
	document.forms['search_main'].max_price.style.backgroundColor		=	'';
	document.forms['search_main'].mileage.style.backgroundColor			=	'';
	document.forms['search_main'].year_made.style.backgroundColor		=	'';
	document.forms['search_main'].fuel.style.backgroundColor			=	'';
	document.forms['search_main'].transmission.style.backgroundColor	=	'';
	document.forms['search_main'].distance.style.backgroundColor		=	'';
	document.forms['search_main'].postcode.style.backgroundColor		=	'';
	document.forms['search_main'].max_results.style.backgroundColor		=	'';
	document.forms['search_main'].order_by.style.backgroundColor		=	'';	
	
	theThumbnailField.style.visibility						=	'visible';
	thePostcodeRequired.style.visibility					=	'visible';
}


// Function created by Mindcom
function pop_models(m_list, m_ids, form_name)
{
	dd = document.forms[form_name].model;
	if(dd)
	{
		dd.options.length = 0;
		for(i = 0; i < m_list.length; i++)	
		{
			dd.options[i] = new Option(m_list[i], m_ids[i]);
		}
	}
}
function reset_models(m_list, m_ids, form_name, selected_model)
{
	this_make = document.forms['search_main'].make.selectedIndex;
							
	pop_models(m_list[this_make], m_ids[this_make], 'search_main');
	
	es = document.forms[form_name].model
	for(i = 0; i < es.length; i++)
	{
		if(es.options[i].value == selected_model)
		{
			es.selectedIndex = i;
		}
	}
}

function formcheck(form_name)
{
	f = document.forms[form_name];
	failed = false;
	
	// Check selected min price is not higher than the max price
	if(parseInt(f.min_price.value) > parseInt(f.max_price.value))
	{
		alert("Your maximum price must be higher than your minimum price.");
		failed = true;
	}
	
	// If postcode is left blank, advise user
	if(f.radios[0].checked)
	{
		if((f.postcode.value == "POSTCODE*") || (f.postcode.value == ""))
		{		
			if(!f.postcode.disabled)
			{
				alert("You must enter your postcode.");
				failed = true;
			}
		}
	}

	if(failed) // If one of the checks failed
	{
		return false;
	}	
	else
	{
		return true;
	}
}

function openCarDetails(car_link)
{
	car_link = "/misc/viewcar.php?car_id="+car_link;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(car_link, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600,left = 290,top = 237');");
}

function openGreatDeals(which_query)
{
	s123_link = "/misc/s123results.php?query="+which_query;
	day = new Date();
	id = day.getTime();	
	
	if(which_query == 0)
	{
		title = "Great Deals on Car Loans | MotorMart.co.uk";
	}
	else if(which_query == 1)
	{
		title = "Great Deals on Car Insurance | MotorMart.co.uk";
	}
	else
	{
		title = "Great Deals on Breakdown Recovery | MotorMart.co.uk";
	}	
	eval("page" + id + " = window.open(s123_link, title, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=450,left = 290,top = 237');");
}