﻿var CurrentDepartment = "";

function UpdateOpeningTimes()
{
    if (CurrentDepartment == "")
    {
        CurrentDepartment = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Department").options[0].value;
    }

    var Department = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Department").value;
    
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_" + CurrentDepartment).style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_" + Department).style.display = "";
    
    CurrentDepartment = Department;
}

function GetVehicleCount()
{
    var Brand = document.getElementById("ctl00_ContentPlaceHolder_MainContent_Hidden_Make").value;
    
    var Make = Brand;
    
    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Make") != null)
    {
        Make = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Make").value;
    }
    
    var Range = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Range").value;
    var BodyStyle = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Style").value;
    var TransmissionType = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Transmission").value;
    var FuelType = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Fuel").value;
    var MinPrice = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_MinPrice").value;
    var MaxPrice = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_MaxPrice").value;
    var Age = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Age").value;
    var Mileage = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Mileage").value;
    var Keyword = document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Keyword").value;
    var PhotosOnly = document.getElementById("ctl00_ContentPlaceHolder_MainContent_Checkbox_PhotosOnly").checked;
    VehicleSearch.GetVehicleCount(Brand, Make, Range, BodyStyle, TransmissionType, FuelType, MinPrice, MaxPrice, Age, Mileage, Keyword, PhotosOnly, GetVehicleCountComplete);
}

function GetVehicleCountComplete(_Result)
{
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_Label_VehicleCount").innerHTML = _Result;
}

function ValidateUsedSearch()
{
    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Range").value == "")
    {
        alert("Please select a Model");
        return false;
    }
}

function ValidateNewSearch()
{
    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_New_Range").value == "")
    {
        alert("Please select a Model");
        return false;
    }
}

function ResetRange()
{
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_DropDownList_Range").value = "";
}
