﻿function filterStartYear()
{
	/* UNCOMMENT TO ENGAGE YEAR FILTERING
	
	var myStart=document.getElementById('selYearStart');
	var myEnd=document.getElementById('selYearEnd');
	myEnd.value=myStart.value;
	*/
	return true;
}
function filterEndYear()
{
	/* UNCOMMENT TO ENGAGE YEAR FILTERING
	
	var myStart=document.getElementById('selYearStart');
	var myEnd=document.getElementById('selYearEnd');
	if(myStart.value>myEnd.value)
	{
		myEnd.value=myStart.value;
	}
	*/
	return true;
}
function validateZipCode(elem)
{
	var str = elem.value;
	if(str.length != 5)
	{
		alert("Zip code length should be 5 digits (U.S. zip codes only)");
		return false;
	}
	else
	{
		return true;
	}
}
function filterSearchMethod(o)
{
	var divmodel=document.getElementById('divModel');
	var selmodel=document.getElementById('selModel');
	var divcategory=document.getElementById('divCategory');
	var selcategory=document.getElementById('selCategory');
	if(o.id=='Model')
	{
		selcategory.options[0].selected=true;
		divcategory.style.display='none';
		divmodel.style.display='block';
	}
	else if(o.id='Category')
	{
		selmodel.options[0].selected=true;
		divmodel.style.display='none';
		divcategory.style.display='block';
	}
}

// Called from results page form
function reQuery(){
    if (oValidation.IsZip($('#zipCode').val())) {
	    FixDropdowns(); // for removal of category dropdown
	    document.getElementById('refineForm').submit();
    } else {
        alert('Zip code length should be 5 digits (U.S. zip codes only)');
        return false;
    }
}

function FixDropdowns() {

	// We have removed the "Category" filter and moved all of the categories into
	//  the model dropdown. Instead of changing all of the model/category logic, we'll
	//  just populate the fields before the form is submitted
	// Right now, an option with the text "------" separates models and categories.
	// This code will work as long as that remains
	
	// Check to see if a category was selected (we need to check by option name)
	var selmodel=document.getElementById('selModel');
	// Get index for the value of "-----"
	var iDashIndex = 0;
	for (var iCount = 0; iCount < selmodel.options.length; iCount++) {
		if (selmodel.options[iCount].text.indexOf("---") >= 0) {
			iDashIndex = iCount;
			break;			
		}
	}
	// See if the value chosen was a category (past the ----)
	if (selmodel.options.selectedIndex >= iDashIndex) {

		// Select this value from the category dropdown (now a textbox)
		var selcategory=document.getElementById('selCategory');
		selcategory.value = selmodel.options[selmodel.options.selectedIndex].value;

		// Select "all models" (make sure to do this after grabbing the category value)
		selmodel.options[0].selected=true;		

		
	} else {
		var selcategory=document.getElementById('selCategory');
		selcategory.value = 'Any';

	}


}

// Called from main search page
function ValidateSearchForm() {

	FixDropdowns(); // for removal of category dropdown

	 if(validateZipCode(document.forms[1].zipCode))document.forms[1].submit();

}

function selectRadioButton(rb){
	var hidden=document.getElementById('transmission');
	hidden.value=rb.id;
}

function drawResultsString(s){
	var mytarget=document.getElementById('resultsString');
	//innerText for IE, textContent for Firefox
	mytarget.innerText=s;
	mytarget.textContent=s;
}
function drawPaginationLinks(s){
	var mytarget=document.getElementById('paginationLinks');
	mytarget.innerHTML=s;
}
function swapOver(o){
	o.src=o.src.replace(/\.jpg/, '_over.jpg');
}
function swapOut(o){
	o.src=o.src.replace(/_over/, '');
}
function rowOver(o){
    if (o){
	    o.style.backgroundColor='#CCCCCC';
	    o.style.cursor='pointer';
	}
}
function rowOut(o){
    if (o){
	    o.style.backgroundColor='#FFFFFF';
	    o.style.cursor='default';
	}
}

// Closes the loading text in the search results area.
// Triggered by onload of the results iframe.
function CloseLoading() {

	if (document.getElementById('LoadingDiv')) {
		document.getElementById('LoadingDiv').style.display='none';
	}
}
