$(document).ready(function(){
        $('#mainPageSearchForm').submit(function(){
        $('.mainSearchCrit').each(function(){
           if($(this).val() == 'bez min' || $(this).val() == 'bez max' || $(this).val() == 'no min' || $(this).val() == 'no max'){
                $(this).val('');
           }
        });
    });

    $('.indexLastAdded').each(function(){
        $(this).click(function(){
            var Id = $(this).attr('rel');

            indexLastAddedClick(Id);
        });
    });
    
    $('#mainSearchButton').mousedown(function(){
		var SrcBack = $(this).attr("rel");
		$(this).attr('src', SrcBack+'_on.gif');
	});
	
	// city swap
    $("#cityPart").each(function () {

    	cityValue = $(this).val();
    	$(this).focus(function(){
      		if ($(this).val() == cityValue) {
      		$(this).val("");
      		$(this).css({color:'#757575'});
      		}
      	$(this).addClass("focus");
		}).blur(function(){
      		if ($.trim($(this).val()) == "") {
      		$(this).val(cityValue);
			$(this).css({color:'#000000'});
      		$(this).removeClass("focus");
     	 	}
		});
    });
    
    provideMinMaxInput();
});


function provideMinMaxInput(){

   // min-max numbers only
   $(".mainSearchCrit").keyup(function () {
    	this.value = this.value.replace(/[^0-9\.]/g,'');
   });

   // min-max swap
   swapValue = [];
   $(".mainSearchCrit").each(function(i){

        swapValue[i] = $(this).val();
        var ClassName = '';
        var Type = $(this).attr('rel');
            if(Type == 'min'){
                ClassName = 'searchListCriteriaInputMin';
            }else if($(this).attr('rel') == 'max'){
                ClassName = 'searchListCriteriaInputMax';
            }

      	$(this).focus(function(){
            $(this).removeClass(ClassName);
	});
        $(this).blur(function(){
            if ($.trim($(this).val()) == "" && (Type == 'min' || Type == 'max')) {
                $(this).addClass(ClassName);
            }
  	});

   });


}

function indexLastAddedClick(Id){

    $('.indexLastAddedOffersMoreRow_'+Id).hide();
    $('.indexOffersLastAddedItem_'+Id).each(function(){
        $(this).show();
    });
}

function  mainSearchSelectType(Selected){
    $('.mainSearchTypeBtn').each(function(){
        Selected.attr('style', 'font-weight: bold');
        $('#mainPageIdOrderType').val(Selected.attr('rel'));
        if(Selected.attr('rel') != $(this).attr('rel')){
            $(this).attr('style', 'font-weight: normal');
        }
    });
}

function showPopup(Message){
    if($('#mainPopupArea').is(':hidden')){
        $('#mainPopupAreaInside').html(Message);
        $('#mainPopupArea').show();
        setTimeout("$('#mainPopupArea').hide();", 30000);
    }
}

