//  @import com.hedgehoglab.application.view.BaseView;
//  @import com.hedgehoglab.KeySequencer;

function DealsSearchView(scope){
    BaseView.call(this,scope);
    KeySequencer2.call(this,{
        element:$('#fldSearchField',scope.element)
        ,on_sequence_ready:on_sequence_ready
                // ,on_sequence_changed:on_sequence_changed
        // 		,delay:500
        //         ,min_value_length:3
    });

	var _this=this;
	var _disabled=false;
	
	$('#clear_field_action',scope.element).bind('click',function(e){
		if(!$('#fldSearchField',scope.element).hasClass('blur_focused')){
			on_sequence_changed({val:""});
			empty_field();
		}else{
			
		}
		
		
		// $('#fldSearchField',scope.element).trigger('keyup',[]);
		// $('#fldSearchField',scope.element).blur();
		return false;
	});
	
	    var _this=this;
	var _term="";
	
   function on_sequence_ready(event){
		_term=event.val;
        _this.raise_event("on_search_term_changed",{term:event.val});
    };

    
    function on_sequence_changed(event){
        if(event.val ==""){
		_term=event.val;
            _this.raise_event("on_search_term_empty",{term:event.val});
        }
    };


	    
	
	this.repeat_search=function(e){
		on_sequence_ready({val:_term});
	};
	
	
	function empty_field(){
		$('#fldSearchField',scope.element).val($('#fldSearchField',scope.element).attr('title'));
		$('#fldSearchField',scope.element).addClass('blur_focused');
	}
	
	function focusblurtitle(field){
		// alert(field.val());
		if(field.val() === '') {
			field.val(field.attr('title'));
			field.addClass('blur_focused');
		}
	
		field.focus(function() {
			field.val('').removeClass('blur_focused');
			if(field.val() === field.attr('title')) {
				field.val('').addClass('focused');
			}
		});
	
		field.blur(function() {
			if(field.val() === '') {
				// field.val(field.attr('title'));
				// 				field.addClass('blur_focused');
				empty_field();
			}else{
				field.removeClass('blur_focused');
			}
		});
	}
	
	$('#fldSearchField',scope.element).val("");
	focusblurtitle($('#fldSearchField',scope.element));
	
	this.disable=function(e){
		_disabled=true;
		// $('.working-pane .scroll-pane',scope.element).hide();
		$(scope.element).css('opacity','0.5');
		$('input,select',scope.element).attr('disabled','disabled');
	};
	
	this.enable=function(e){
		_disabled=true;
		// $('.working-pane .scroll-pane',scope.element).hide();
		$(scope.element).css('opacity','0.5');
		$('input,select',scope.element).attr('disabled','disabled');
	};
};
