/*
    Copyright (c) 2008, SpatialPoint, LLC.
    
    All rights reserved.
    
    http://www.spatialpoint.com
*/

function validateRouteAddressControls()
{

    if (IsEmptyTextBox('TextPostalCode'))
    {
        alert('Please enter at least a postal code');
        
        ClearRequriedAddressFieldControlLabel('TextPostalCode');
        HighlightRequriedAddressFieldControlLabel('TextPostalCode');

        return false;
    }
     return true;
}

function validateAddressControls() {

    if (IsEmptyTextBox('TextAddress') && (document.getElementById(dropDownListSubdivisionId)==null || document.getElementById(dropDownListSubdivisionId).selectedIndex == 0))
    {
        alert(unmatchedAddress);
        
        HighlightRequriedAddressFieldControlLabel('TextAddress');
        
        return false;
    }
     return true;
}

function addressChanged()
{
    var countryListControl = document.getElementById(dropDownListCitiesId);

    if (countryListControl != null) {
        countryListControl.disabled = true;
        countryListControl.options.length = 0;
    }

    var subdivisionListControl = document.getElementById(dropDownListSubdivisionId);

    if (subdivisionListControl != null) {
        subdivisionListControl.selectedIndex = 0;
    }
}


function clearAddressText() {
    var address = document.getElementById("routeToAddress");
    if (address != null) {
        if (address.value == defaultAddressText) address.value = "";
    }
}

function isKeyPressed(evt, code) {
    // this function supports IE, Netscape, and FireFox
    evt = (evt) ? evt : (window.event) ? event : null;

    if (evt) {
        var charCode = (evt.charCode) ? evt.charCode :
			((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));

        return (charCode == code);
    }

    return false;
}


function onSubdivisionChanged(subdivisionDropDown) {
    var myindex = subdivisionDropDown.selectedIndex;

    var countryListControl = document.getElementById(dropDownListCitiesId);


    if (myindex != 0) {
        var selValue = subdivisionDropDown.options[myindex].value;

        countryListControl.options.length = 0;
        for (var i = 0; i < subDivisionList[selValue].length; i++) {
            countryListControl.options.add(new Option(subDivisionList[selValue][i], subDivisionList[selValue][i]));
        }

        if (document.getElementById('TextAddress') != null) {
            document.getElementById('TextAddress').value = '';
        }
        countryListControl.disabled = false;
    }
    else {
        countryListControl.disabled = true;
        countryListControl.options.length = 0;
    }
}
