﻿function GetVehicleCount()
{
    var Brand = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_Hidden_Make").value;
    var Make = Brand;
    
    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Make") != null)
    {
        Make = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Make").value;                                    
    }
    
    var Range = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Range").value;
    var BodyStyle = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Style").value;
    var TransmissionType = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Transmission").value;
    var FuelType = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Fuel").value;
    var MinPrice = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_MinPrice").value;
    var MaxPrice = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_MaxPrice").value;
    var Age = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VVehicleSearch_Standard_DropDownList_Age").value;
    var Mileage = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Mileage").value;
    var Keyword = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Keyword").value;
    var PhotosOnly = document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_Checkbox_PhotosOnly").checked;        
}

function GetVehicleCountComplete(_Result)
{
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_Label_VehicleCount").innerHTML = _Result;
}

function ValidateUsedSearch()
{
    if(document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Make").value == "")
    {
        alert("Please select a Make");
        return false;
    }
    
    if(document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Range").value == "")
    {
        alert("Please select a Model");
        return false;
    }
    
    var regEx = /\b[A-Z][A-Z0-9][A-Z0-9]?[A-Z0-9]? ?[0-9][A-Z]{2}\b/g;
    
    if(!regEx.test(document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_txtPostCode").value.toUpperCase()))    
    {        
        alert("Please enter a valid postcode");
        return false;
    }
}

function ValidateNewSearch()
{
    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_New_Make").value == "")
    {
        alert("Please select a Make");
        return false;
    }
    
    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_New_Range").value == "")
    {
        alert("Please select a Model");
        return false;
    }

    var regEx = /\b[A-Z][A-Z0-9][A-Z0-9]?[A-Z0-9]? ?[0-9][A-Z]{2}\b/g;

    if (!regEx.test(document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_txtPostCode_NewCars").value.toUpperCase())) {
        alert("Please enter a valid postcode");
        return false;
    }
}

function ValidateNewVansSearch() 
{
    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_NewVans_Make").value == "") {
        alert("Please select a Make");
        return false;
    }

    if (document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_NewVans_Make").value != "other" && document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_NewVans_Range").value == "") {
        alert("Please select a Model");
        return false;
    }
    
    var regEx = /\b[A-Z][A-Z0-9][A-Z0-9]?[A-Z0-9]? ?[0-9][A-Z]{2}\b/g;

    if (!regEx.test(document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_txtPostCode_NewVans").value.toUpperCase())) {
        alert("Please enter a valid postcode");
        return false;
    }
}

function ResetRange()
{
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_Range").value = "";
}

function ResetRangeNew()
{
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_New_Range").value = "";
}

function ResetRangeNewVans() 
{
    document.getElementById("ctl00_ContentPlaceHolder_MainContent_VehicleSearch_Standard_DropDownList_NewVans_Range").value = "";
}
