/*
 * @maxatwork: Поиск по списку точек
 */
 

if (!AtmsOffices) 
    var AtmsOffices = function()
    {
        
    }

AtmsOffices.SearchPlaceHolder = function ( searchField, placeholder ) 
{
    this.searchField = jQuery(searchField);
    this.emptyVal = placeholder;
    this.searchField.val(placeholder);
    
    var _this = this;
    
    this.searchField.focus( function () { return _this.OnFocus(_this); } );
    this.searchField.blur( function () { return _this.OnBlur(_this); } );
    
    this.OnFocus(this);
    this.OnBlur(this);
}

AtmsOffices.SearchPlaceHolder.prototype = {
    OnFocus : function ( _this ) 
    {
        _this.searchField.removeClass('empty');
        if ( _this.searchField.val() == _this.emptyVal )
            _this.searchField.val('');
            
        return false;   
    },
    
    OnBlur : function ( _this ) 
    {
        if ( _this.searchField.val() == '' )
        {
            _this.searchField.addClass('empty');
            _this.searchField.val(_this.emptyVal);
        }
        else
            _this.searchField.removeClass('empty');
            
        return false;
    }
}

AtmsOffices.SetSearchExample = function ( e ) 
{
    jQuery('#points-search').val( jQuery(this).html() );
    jQuery('#points-search').removeClass('empty');
    AtmsOffices.PageSearch.startSearch( jQuery(this).html() );
}

AtmsOffices.SetSubfilter = function ( filterObj )
{
    if(filterObj.checked) jQuery('#points').addClass( filterObj.value );
    else jQuery('#points').removeClass( filterObj.value );
    /* Коряво, кнешна, но времени че-т совсем мало */
	if(filterObj.value == "filter-has-rempant") AtmsOffices.SetCaptionSubfilter(filterObj);
	//console.log(AtmsOffices, AtmsOffices.metroFilter);
	if (metroFilter){
		metroFilter.FilterStations();
	}
/*	if(jQuery(".filter-has-rempant-key.metro-found").length == 1){
		jQuery(".filter-has-rempant-key.metro-found").addClass("last");
	}
	else{
		jQuery(".filter-has-rempant-key.metro-found:first").removeClass("last");

		jQuery(".filter-has-rempant-key.metro-found:last").addClass("last");
	}*/
}

AtmsOffices.SetCaptionSubfilter = function( filterObj )
{
	if(filterObj.checked){
		jQuery('table.data:not(:has(.filter-has-rempant-key))').each(
			function(){
				jQuery(this).addClass("not-rempant-parent");
			}
		);
	}
	else
	{
		jQuery(".not-rempant-parent").each(
			function(){
				jQuery(this).removeClass("not-rempant-parent");
			}
		);
	}
}