$(document).ready(function () {

	/*------------------------------------------------------
    *drop down change route function
	------------------------------------------------------*/
    $('#routeSelect').change(function () {
	
	changeRoute($(this).attr('value'));
	});

		  
    /*------------------------------------------------------
    * ADD AND SEARCH CONTENT
    ------------------------------------------------------*/

    $('#addcontentbtn').click(function () {
        $("#add_content").show();
    });

    $('#searchcontentbtn').click(function () {
        $("#search_box").show();
    });

    $('#searchTxt').keyup(function (e) {
        if (e.keyCode == 13 && $(this).val() !== "") {
            searchKeywords();
        }
    });

    $('#searchBtn').click(function () {
        if ($("#searchTxt").val() !== "") {
            searchKeywords();
        }
    });

    $('#toggle1, #toggle2').toggle(function () {
        $(this).siblings(".toggleArea").show();
        $(this).removeClass("expand");
        $(this).addClass("collapse");
        $(this).attr({
            'title': 'Collapse'
        });
    }, function () {
        $(this).siblings(".toggleArea").hide();
        $(this).removeClass("collapse");
        $(this).addClass("expand");
        $(this).attr({
            'title': 'Expand'
        });
    });

    $('#searchTxt').bind("keyup blur change", function (event) {
        if ($(this).val() !== "") {
            $(this).next(".resetsearch").removeClass("resetoff");
            $(this).next(".resetsearch").addClass("reseton");
        }
        else {
            $(this).next(".resetsearch").removeClass("reseton");
            $(this).next(".resetsearch").addClass("resetoff");
        }
    });

    $('.resetsearch').click(function () {
        if ($(this).hasClass("reseton")) {
            $(this).removeClass("reseton");
            $(this).addClass("resetoff");
            $(this).prev(".fsearchinput").val("");
            clearSearch();
        }
    });

    /*------------------------------------------------------
    * LOCATE
    ------------------------------------------------------*/
    $('#address').keyup(function (e) {
        if (e.keyCode == 13) {
            locate();
        }
    });

    $('#locateBtn').click(function () {
        locate();
    });


    $('#address').bind("keyup blur change", function (event) {
        if ($(this).val() !== "") {
            $(this).next(".resetlocate").removeClass("resetoff");
            $(this).next(".resetlocate").addClass("reseton");
        }
        else {
            $(this).next(".resetlocate").removeClass("reseton");
            $(this).next(".resetlocate").addClass("resetoff");
        }
    });

    $('.resetlocate').click(function () {
        if ($(this).hasClass("reseton")) {
            $(this).removeClass("reseton");
            $(this).addClass("resetoff");
            $(this).prev(".fsearchinput").val("");
            clearLocate();
        }
    });

});	
