   
      $.fn.clearForm = function() {
   
        this.each(function() {
   
          var type = this.type, tag = this.tagName.toLowerCase();
   
          if (tag == 'form')
   
            return $(':input',this).clearForm();
   
          if (type == 'text' || type == 'password' || tag == 'textarea')
  
            this.value = '';
  
          else if (type == 'checkbox' || type == 'radio')
  
            this.checked = false;
  
          else if (tag == 'select')
  
            this.selectedIndex = -1;
  
        });

        sel_metros();
  
      };

function update_stored() {
	$.getJSON('/ajx/stored/', 
		function(data) {
			if (data > 0) { 
				data = '('+data+')';
				} else {
				data = '';
			}
			$('.stored_count').html(data);
		}
	);
}

function store(id, sender) {
	$.getJSON('/ajx/store/'+id, 
		function(data) {
			$('.stored_count').html('('+data+')');
			$('#stored_menu_item').fadeOut('fast').fadeIn('fast');
			$('#stored_link').fadeOut('fast').fadeIn('fast');
		}
	);
//	$(sender).removeClass('store')
	$(sender).addClass('active').removeClass('store').addClass('unstore');
	$(sender).html('отмечено');
	// STR_UNSTORE_TITLE
	$(sender).attr('title', 'Запись сохранена в избранном. Нажмите, чтобы убрать её оттуда.');
	assignEvents();
	return false;
}

function unstore(id, sender) {
	$.getJSON('/ajx/unstore/'+id, 
		function(data) {
			if ($(sender).hasClass('context_stored')) {
				if (data == 0) location.reload();
			};
			$('.stored_count').html(data==0?'':'('+data+')');
			$('#stored_menu_item').fadeOut('fast').fadeIn('fast');
			$('#stored_link').fadeOut('fast').fadeIn('fast');
		}
	);
	$(sender).removeClass('active').removeClass('unstore').addClass('store');
	$(sender).html('отметить');
	if ($(sender).hasClass('context_stored')) {
		$(sender).parents('tr.apartment').fadeOut('fast').hide();
	}
	// STR_STORE_TITLE
	$(sender).attr('title', 'Запись будет сохранена в разделе &quot;Избранное&quot;');
	assignEvents();
	return false;
}


function gotoUrl(url) {
//	var s = document.location.split(/(^.+\.ru)/);
//	alert(document.location);
//	document.location = s[1] + url;
	document.location = url;
}

function assignEvents() {

		$('tr.apartment').unbind('mouseover').mouseover(
			function() {
				$(this).find('div.shadow').css({'background-image':'url(/i/shadow2.png)'});
				$(this).css({'background-color':'#F2EBDA', 'cursor':'pointer'});
			}
		);

		$('tr.apartment').unbind('mouseout').mouseout(
			function() {
				$(this).find('div.shadow').css({'background-image':'url(/i/shadow.png)'});
				$(this).css({'background-color':'white', 'cursor':'auto'});
			}
		);

		$('tr.apartment').unbind('click').click(
			function() {
				gotoUrl($(this).find('a.property_link').attr('href'));
			}
		);

		$('a.store').unbind().click(
			function() {
				store($(this).attr('href').substr(1), this);
				return false;
			}
		)

		$('a.unstore').unbind().click(
			function() {
				unstore($(this).attr('href').substr(1), this);
				return false;
			}
		)
}

function console_log(str) {
	if (window.console != null) {
		console.log(new Date()+' ' + str)
	}
}

/*Array.prototype.remove=function(s){
  for(i=0;i<this .length;i++){
    if(s==this[i]) this.splice(i, 1);
  }
} */




$(document).ready(assignEvents);

