﻿//-----------------------------------------------------------------------------
var _ddlCounty, _ddlBranch, _txtLocation
var _txtMinPrice, _txtMaxPrice, _txtBedrooms

function Initialise(ddlCounty, ddlBranch, txtLocation, txtMinPrice, txtMaxPrice, txtBedrooms)
{
    _ddlCounty = document.getElementById(ddlCounty);
    _ddlBranch = document.getElementById(ddlBranch);
    _txtLocation = document.getElementById(txtLocation);
    _txtMinPrice = document.getElementById(txtMinPrice);
    _txtMaxPrice = document.getElementById(txtMaxPrice);
    _txtBedrooms = document.getElementById(txtBedrooms);
    
}

function CheckForm()
{ 
    if (_ddlCounty.selectedIndex == 0)
    {
        alert("Please select a county");
        _ddlCounty.focus();
        return false;
    }

    if ((_ddlBranch.selectedIndex == 0) && (_ddlBranch.length > 1))
    {
        alert("Please select a branch to notify");
        _ddlBranch.focus();
        return false;
    }

    if (isBlank(_txtLocation.value))
    {
        alert("Please enter a location");
        _txtLocation.focus();
        return false;
    }

    if (isInteger(_txtMinPrice.value) == false)
    {
        alert("Please enter a numeric value for minimum price");
        _txtMinPrice.focus();
        return false;
    }

    if (isInteger(_txtMaxPrice.value) == false)
    {
        alert("Please enter a numeric value for maximum price");
        _txtMaxPrice.focus();
        return false;
    }
    else if (parseInt(_txtMaxPrice.value) < 1)
    {
        alert("Please enter a numeric value greater than zero for maximum price");
        _txtMaxPrice.focus();
        return false;            
    }

    if (isInteger(_txtBedrooms.value) == false)
    {
        alert("Please enter a numeric value for bedrooms");
        _txtBedrooms.focus();
        return false;
    }

    if (CheckContactDetails() == false)
        return(false);

    return true;		
}