/***************************************
*  всякая ajax-овая фигня...
*
*
***************************************/

/**
*  добавление зявки, компании, объявления в избранное
*
*/
$(function(){

	/*$('#load_indicator')
			.bind('ajaxStart', function(){
				$(this).show();
			})
			.bind('ajaxComplete', function(){
				$(this).hide();
			});*/


	$('#searchsample').click(function(){
		$('#top_search_hint').val($(this).text());
		//alert($(this).text());
	});
	// отправляем ajax-запрос на добавление в базу
	// ответ выводим во временный div
	$('a.add_to_favorite').click(function(){
		a = $(this);
		$.ajax({
			type: 'GET',
			url:  $(this).attr('href'),
			dataType: 'html',

			success: function(html, textStatus){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(html)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								   a.hide();
								   $('a.dell_from_favorite').show();
								 });
			},
			error:  function(xhr,err){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(xhr.responseText)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								 })
			}

		});

		return false;
	});

	$('a.add_to_archive').click(function(){
		a = $(this);
		$.ajax({
			type: 'GET',
			url:  $(this).attr('href'),
			dataType: 'html',

			success: function(html, textStatus){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(html)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								   a.hide();
								   a.next('a.dell_from_archive').show();
								 });
			},
			error:  function(xhr,err){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(xhr.responseText)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								 })
			}

		});

		return false;
	});

	// отпарвляем запрос на удаление из базы
	$('a.dell_from_favorite').click(function(){
		a = $(this);

		$.ajax({
			type: 'GET',
			url:  $(this).attr('href'),
			dataType: 'html',

			success: function(html, textStatus){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(html)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								   a.hide();
								   $('a.add_to_favorite').show();
								 });
			},
			error:  function(xhr,err){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(xhr.responseText)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								 })
			}

		});

		return false;
	});

	$('a.dell_from_archive').click(function(){
		a = $(this);

		$.ajax({
			type: 'GET',
			url:  $(this).attr('href'),
			dataType: 'html',

			success: function(html, textStatus){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(html)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								   a.hide();
								   a.prev('a.add_to_archive').show();
								 });
			},
			error:  function(xhr,err){
				$('div#ajax_status', a.parent())
				  .html('')
				  .css('float', 'right')
				  .append(xhr.responseText)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								 })
			}

		});

		return false;
	});


	// ссылка удалить из избранного в списке избранного
	// надо удалить и tr
	$('a.dell_from_favorite_tr_cat').click(function(){
		a = $(this);
		if(confirm('Удалить заявку из избранного?')){

		$.ajax({
			type: 'GET',
			url:  $(this).attr('href'),
			dataType: 'html',
			success: function(html, textStatus){
				// удаляем строку таблицы с id равным id объекта
				$('tr#'+a.attr('id')).remove();
			},
			error:  function(xhr,err){
				$('div#ajax_status', a.parent())
				  .html('')
				  .append(xhr.responseText)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								 })
			}
		});
	    } // if
		return false;
	});
	$('a.dell_from_favorite_tr_com').click(function(){
		a = $(this);
		if(confirm('Удалить компанию из избранного?')){

		$.ajax({
			type: 'GET',
			url:  $(this).attr('href'),
			dataType: 'html',
			success: function(html, textStatus){
				// удаляем строку таблицы с id равным id объекта
				$('tr#'+a.attr('id')).remove();
			},
			error:  function(xhr,err){
				$('div#ajax_status', a.parent())
				  .html('')
				  .append(xhr.responseText)
				  .fadeOut(2400, function(){
					               $(this).text('').show();
								 })
			}
		});
	    } // if
		return false;
	});

});
function BanShow(place, searchStr, file){
	addstr = "";
	if (place == "kk") {
		filen = "getb";
	}
	else{
		filen = "getbStation";
		addstr = "&zone="+file;
		}
	var dataString = 'searchstr='+searchStr;
	$.getJSON('http://www.hotmetal.ru/modules/banners/'+filen+'.php?'+dataString+addstr+'&jsoncallback=?', function(data){
	allert(place,data);
	});
}

function allert(place,data){
//alert(data['1']);
 $("#"+place).append(data['B']);
}


