﻿var localSearch = new GlocalSearch();

function onPostCodeChanged(postcode) {
    localSearch.setSearchCompleteCallback(null,
    function() {
        if (postcode.length < 3) return;

        var hfLng = document.getElementById('ctl00_contentMain_ucGarageLocator_hfLng');
        var hfLat = document.getElementById('ctl00_contentMain_ucGarageLocator_hfLat');

        if (localSearch.results[0]) {
            hfLng.value = localSearch.results[0].lat;
            hfLat.value = localSearch.results[0].lng;
        } else {
            hfLng.value = "0.00";
            hfLat.value = "0.00";
        }
    });

    localSearch.execute(postcode + ", UK");
}

function onClicked() {
    var txt = document.getElementById('ctl00_contentMain_ucGarageLocator_tbSearch');

    if (txt.value == ' ' || txt.value == '' || txt.value == 'enter place or postcode') {
        alert("Please enter place or postcode");
        return false;
    }

    return true;
}
