$(document).ready(function(){

/* Работа с категориями и подкатегориями */
	var question_subcategory = $("#question_subcategory");
	var question_category = $("#question_category");

	if (question_category.val()) question_subcategory.removeAttr("disabled");

	question_category.change(function(){
		$.ajax({
			url: "/netcat/modules/ajax/get_subcategory.php?category_id=" + $(this).val(),
			beforeSend: function(){
				question_subcategory.attr("disabled", "disabled");
				question_subcategory.after("<span id='ajax_loader'><img src='/i/ajax_loader.gif'/></span>");
			},
			cache: false,
			success: function(html){
				question_subcategory.html(html);
				$("#ajax_loader").remove();
				question_subcategory.removeAttr("disabled");
			}
		});
	});

	var question_cc = $("#question_cc");
	var question_sub = $("#question_sub");

	question_subcategory.change(function(){
		$.ajax({
			url: "/netcat/modules/ajax/get_subcategory_subclass.php?category_id=" + $(this).val(),
			cache: false,
			success: function(html){
				question_cc.val(html);
			}
		});
		question_sub.val($(this).val());
		
	});	

/* //Работа с категориями и подкатегориями */


/* Подсчет числа символов в текстовом блоке */
$("#question_text").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#limit_count"),
	descending: true
});

$("#answer_text_top").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#limit_count_top"),
	descending: true
});

$("#answer_text_bottom").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#limit_count_bottom"),
	descending: true
});
$("#question_text_top").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#limit_count_top"),
	descending: true
});
$("#question_text_bottom").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#limit_count_bottom"),
	descending: true
});
$("#realty_text").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#realty_limit_count"),
	descending: true
});
$("#equipment_text").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#equipment_limit_count"),
	descending: true
});
$("#store_text").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#store_limit_count"),
	descending: true
});
$("#debt_text").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#debt_limit_count"),
	descending: true
});
$("#info_text").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#info_limit_count"),
	descending: true
});
$("#assets_text").char_limit({
	limit: 5000,
	speed: "slow",
	limit_block: '',
	limit_count: $("#assets_limit_count"),
	descending: true
});
/* //Подсчет числа символов в текстовом блоке */


/* Показать/скрыть блок добавления голосования */
	var add_poll_link = $("#add_poll_link");
	var add_poll_link_block = $("#add_poll_link_block");
	var add_poll_block = $("#add_poll_block");
	var hide_poll_link = $("#hide_poll_link");

	add_poll_link.click(function(){
		add_poll_link_block.toggle();
		add_poll_block.toggle();
		return false;
	});

	hide_poll_link.click(function(){
		add_poll_block.toggle();
		add_poll_link_block.toggle();
		return false;
	});
/* //Показать/скрыть блок добавления голосования */


/* Добавить вариант ответа на опрос */
	var add_poll_answer = $("#add_poll_answer");
	var poll_answers = $("#poll_answers");
	var poll_answers_limit = 10;
	
	add_poll_answer.click(function() {
		var poll_answers_count = $("#poll_answers input").length + 1;
		
		poll_answers.append("<input name='f_PollAnswer" + poll_answers_count + "' type='text' class='i added_answer' style='display:none;' />");
		$("#poll_answers input.added_answer").removeClass('added_answer').toggle();

		if (poll_answers_count >= poll_answers_limit) {
			add_poll_answer.toggle();
		}
		return false;
	});
/* //Добавить вариант ответа на опрос */


/* Отображение форм ответа на вопрос */
	$("#answer_top_button").click(function(){
		$("#answer_top_form").toggle();
		$("#answer_text_top").focus();
		return false;
	});


	$("#answer_bottom_button").click(function(){
		$("#answer_bottom_form").toggle();
		$("#answer_text_bottom").focus();
		return false;
	});
/* //Отображение форм ответа на вопрос */


/* Отправка нарушения */
	$(".abuse").click(function(){
		$(this).parent().submit();
		return false;
	});
/* //Отправка нарушения */


/* Подписка на ответы на вопросы */
	$("#subscribe").click(function(){
		$(this).parent().submit();
		return false;
	});
/* //Подписка на ответы на вопросы */


/* Голосование за вопрос/объявление */
	$("#ball1").click(function(){
		$("#question_vote_value").val('10');
		$("#announcement_vote_value").val('10');
		$(this).parent().submit();
		return false;
	});


	$("#ball2").click(function(){
		$("#question_vote_value").val('5');
		$("#announcement_vote_value").val('5');
		$(this).parent().submit();
		return false;
	});


	$("#ball3").click(function(){
		$("#question_vote_value").val('0');
		$("#announcement_vote_value").val('0');
		$(this).parent().submit();
		return false;
	});


	$("#ball4").click(function(){
		$("#question_vote_value").val('-5');
		$("#announcement_vote_value").val('-5');
		$(this).parent().submit();
		return false;
	});
/* //Голосование за вопрос/объявление */


/* Голосование за ответ */
	$(".good").click(function(){
		var id = $(this).attr("id").replace(/[a-zA-Z]+/, "");
		$("#answer_vote_value" + id).val('1');		
		$(this).parent().ajaxSubmit({
			complete: function(msg) {
				$("#vote" + id).replaceWith(msg.responseText);
			}
		});
		return false;
	});


	$(".bad").click(function(){
		var id = $(this).attr("id").replace(/[a-zA-Z]+/, "");
		$("#answer_vote_value" + id).val('-1');		
		$(this).parent().ajaxSubmit({
			complete: function(msg) {
				$("#vote" + id).replaceWith(msg.responseText);
			}
		});
		return false;
	});
/* //Голосование за ответ */

/* Голосование за вопрос */
	$("#voteAnswers input:radio").click(function(){
		$("#submit_poll").removeAttr('disabled');
	});
	$("#voteAnswers input:checkbox").click(function(){
		var checked = false;
		$("#voteAnswers input:checkbox").each(function(){
			if ($(this).attr('checked')) checked = true;
		});
		if (checked) {
			$("#submit_poll").removeAttr('disabled');
		} else {
			$("#submit_poll").attr('disabled', 'true');
		}
	});
/* //Голосование за вопрос */

/* Подписка на ответы на вопросы */
	$("#private_message").click(function(){
		$(this).parent().submit();
		return false;
	});
/* //Подписка на ответы на вопросы */




/* Примеры для полей */
	var announcement_container = $("#announcement_container");
	var banner_form = $("#banner_form");

	if (!announcement_container.length && !banner_form.length) {
		$("input:text").example(function(){
			return $(this).attr('title'); 
		}, { className: 'example_text' });
		$("textarea").example(function(){
			return $(this).attr('title'); 
		}, { className: 'example_text' });
	}
/* //Примеры для полей */


/* Подгрузка формы объявлений */
	var announcement_select = $("#announcement_select");
	announcement_select.change(function(){
		var param = $(this).val();
		if (param) {
			$.ajax({
				url: param + "?isNaked=1",
				beforeSend: function(){
					announcement_select.attr("disabled", "disabled");
					announcement_select.after("<span id='ajax_loader'><img src='/i/ajax_loader.gif'/></span>");
				},
				cache: false,
				success: function(html){
					announcement_container.html(html);
					$("#ajax_loader").remove();
					announcement_select.removeAttr("disabled");
					/* Смена валюты у объявления */
					var currency_select = $("#currency_select");
					var currencies = $(".currency");
					currency_select.change(function(){
						switch($(this).val()) {
							case '1':
								currency = 'рублей';
								break;
							case '2':
								currency = 'долларов';
								break;
							case '3':
								currency = 'евро';
								break;
							default:
								currency = 'рублей';
								break;
						}
						currencies.text(currency);
					});
					/* Смена валюты у объявления */
					/* Примеры для полей */
					$("input:text").example(function(){
						return $(this).attr('title'); 
					}, { className: 'example_text' });
					$("textarea").example(function(){
						return $(this).attr('title'); 
					}, { className: 'example_text' });
					/* //Примеры для полей */
					/* Подсчет числа символов в текстовом блоке */
					$("#realty_text").char_limit({
						limit: 5000,
						speed: "slow",
						limit_block: '',
						limit_count: $("#realty_limit_count"),
						descending: true
					});
					$("#equipment_text").char_limit({
						limit: 5000,
						speed: "slow",
						limit_block: '',
						limit_count: $("#equipment_limit_count"),
						descending: true
					});
					$("#store_text").char_limit({
						limit: 5000,
						speed: "slow",
						limit_block: '',
						limit_count: $("#store_limit_count"),
						descending: true
					});
					$("#debt_text").char_limit({
						limit: 5000,
						speed: "slow",
						limit_block: '',
						limit_count: $("#debt_limit_count"),
						descending: true
					});
					$("#info_text").char_limit({
						limit: 5000,
						speed: "slow",
						limit_block: '',
						limit_count: $("#info_limit_count"),
						descending: true
					});
					$("#assets_text").char_limit({
						limit: 5000,
						speed: "slow",
						limit_block: '',
						limit_count: $("#assets_limit_count"),
						descending: true
					});
					/* //Подсчет числа символов в текстовом блоке */
				}
			});
		}
	});
/* //Подгрузка формы объявлений */

/* Изменение картинки в объявлении */
	$(".pics_preview a").click(function(){
		var path = $(this).attr('href');
		$('#photo').animate({opacity: 0},1000,function(){
			$(this).attr("src", path).bind('load',function(){
				$(this).animate({opacity: 1},1000);
			});
		});
		return false;
	});
/* Изменение картинки в объявлении */

/* Отображение форм вопроса к объявлению */
	$("#question_top_button").click(function(){
		$("#more_top_button img").attr('src', '/i/but_more.gif');
		$("#call_back_top_button img").attr('src', '/i/but_call_back.gif');

		button = $(this).children().attr('src');
		if (button == '/i/but_question_orange.gif') {
			$(this).children().attr('src', '/i/but_question.gif');
			$("#announcement_top_info").show();
		} else {
			$(this).children().attr('src', '/i/but_question_orange.gif');	
			$("#announcement_top_info").hide();
		}
		$("#more_top_block").hide();
		$("#call_back_top_block").hide();
		$("#question_top_form").toggle();
		$("#question_text_top").focus();
		return false;
	});

	$("#question_bottom_button").click(function(){
		$("#more_bottom_button img").attr('src', '/i/but_more.gif');
		$("#call_back_bottom_button img").attr('src', '/i/but_call_back.gif');

		button = $(this).children().attr('src');
		if (button == '/i/but_question_orange.gif') {
			$(this).children().attr('src', '/i/but_question.gif');
			$("#announcement_bottom_info").show();
		} else {
			$(this).children().attr('src', '/i/but_question_orange.gif');
			$("#announcement_bottom_info").hide();	
		}
		$("#more_bottom_form").hide();
		$("#call_back_bottom_form").hide();
		$("#question_bottom_form").toggle();
		$("#question_text_bottom").focus();
		return false;
	});
/* //Отображение форм вопроса к объявлению */

/* Отображение форм запроса подробной информации к объявлению */
	$("#more_top_button").click(function(){
		$("#question_top_button img").attr('src', '/i/but_question.gif');
		$("#call_back_top_button img").attr('src', '/i/but_call_back.gif');

		button = $(this).children().attr('src');
		if (button == '/i/but_more_orange.gif') {
			$(this).children().attr('src', '/i/but_more.gif');
			$("#announcement_top_info").show();
			if ($("#more_top_block_unauth")) $("#more_top_block").hide();
		} else {
			$(this).children().attr('src', '/i/but_more_orange.gif');
			$("#announcement_top_info").hide();
			if ($("#more_top_block_unauth")) $("#more_top_block").show();
		}
		$("#question_top_form").hide();
		$("#call_back_top_block").hide();
		$("#more_top_form").ajaxSubmit({
			complete: function(msg) {
				$("#more_top_block").show();
				$("#more_top_button").replaceWith("<img src='/i/but_more_gray.gif' alt='Подробнее?'>");
			}
		});
		$("#more_top_request_form").ajaxSubmit();
//		$("#more_top_text_top").focus();
		return false;
	});

	$("#more_bottom_button").click(function(){
		$("#question_bottom_button img").attr('src', '/i/but_question.gif');
		$("#call_back_bottom_button img").attr('src', '/i/but_call_back.gif');

		button = $(this).children().attr('src');

		if (button == '/i/but_more_orange.gif') {
			$(this).children().attr('src', '/i/but_more.gif');
			$("#announcement_bottom_info").show();
		} else {
			$(this).children().attr('src', '/i/but_more_orange.gif');	
			$("#announcement_bottom_info").hide();
		}
		$("#question_bottom_form").hide();
		$("#call_back_bottom_form").hide();
		$("#more_bottom_form form").ajaxSubmit({
			complete: function(msg) {
				$("#more_bottom_form").show();
			}
		});
		$("#more_bottom_text_top").focus();
		return false;
	});
/* //Отображение форм запроса подробной информации к объявлению */

/* Отображение форм запроса обратного звонка по объявлению */
	$("#call_back_top_button").click(function(){
		$("#question_top_button img").attr('src', '/i/but_question.gif');
		$("#more_top_button img").attr('src', '/i/but_more.gif');

		button = $(this).children().attr('src');
		if (button == '/i/but_call_back_orange.gif') {
			$(this).children().attr('src', '/i/but_call_back.gif');
			$("#announcement_top_info").show();
		} else {
			$(this).children().attr('src', '/i/but_call_back_orange.gif');	
			$("#announcement_top_info").hide();
		}
		$("#question_top_form").hide();
		$("#more_top_block").hide();
		$("#call_back_top_block").show();
		$("#call_back_top_submit").click(function(){
			$("#call_back_top_request_form").ajaxSubmit(
//				complete: function(msg) {
//					$("#call_back_bottom_form").show();
//				}
			);
//			return false;
		});
//		$("#call_back_top_form").ajaxSubmit({
//			complete: function(msg) {
//				$("#call_back_top_block").show();
//				$("#call_back_top_button").replaceWith("<img src='/i/but_call_back_gray.gif' alt='Подробнее?'>");
//			}
//		});
//		$("#call_back_top_request_form").ajaxSubmit();
		$("#call_back_top_text_top").focus();
		return false;
	});

	$("#call_back_bottom_button").click(function(){
		$("#question_bottom_button img").attr('src', '/i/but_question.gif');
		$("#more_bottom_button img").attr('src', '/i/but_more.gif');

		button = $(this).children().attr('src');
		if (button == '/i/but_call_back_orange.gif') {
			$(this).children().attr('src', '/i/but_call_back.gif');
			$("#announcement_bottom_info").show();
		} else {
			$(this).children().attr('src', '/i/but_call_back_orange.gif');	
			$("#announcement_bottom_info").hide();
		}
		$("#question_bottom_form").hide();
		$("#more_bottom_form").hide();
		$("#call_back_bottom_block").show();
		$("#call_back_bottom_submit").click(function(){
			$("#call_back_bottom_request_form").ajaxSubmit();
		});
//		$("#call_back_bottom_form form").ajaxSubmit({
//			complete: function(msg) {
//				$("#call_back_bottom_form").show();
//			}
//		});
		$("#call_back_bottom_text_bottom").focus();
		return false;
	});
/* //Отображение форм запроса обратного звонка по объявлению */

	$(".question_answer").click(function(){
		$(this).next().toggle();
		return false;
	});



/* Работа с категориями и подкатегориями */
	var announcement_subject = $("#announcement_subject");
	var announcement_type = $("#announcement_type");

	var announcement_cc = $("#announcement_cc");
	var announcement_sub = $("#announcement_sub");
	var announcement_class = $("#announcement_class");

	announcement_subject.change(function(){
		if ($(this).val() == 128 || $(this).val() == 129) {
			announcement_type.removeAttr("disabled");
		} else {
			announcement_type.attr("disabled", "disabled");
		}

		$.ajax({
			url: "/netcat/modules/ajax/get_subject_class.php?category_id=" + $(this).val(),
			cache: false,
			success: function(html){
				announcement_class.val(html);
			}
		});
		$.ajax({
			url: "/netcat/modules/ajax/get_subject_subclass.php?category_id=" + $(this).val(),
			cache: false,
			success: function(html){
				announcement_cc.val(html);
			}
		});
		announcement_sub.val($(this).val());
	});
/* //Работа с категориями и подкатегориями */

/* Оплата объявлений по sms на 7 дней */
	var sms7_info = $("#sms7_info");
	var select_country7 = $("#select_country7");
	var providers7 = $("#providers7");
	var select_provider7 = $("#select_provider7");
	var instructions7 = $('#instructions7');
	var publish7 = $('#publish7');
	
	SERVICE7 = 218021;

	function show_instructions7(data) {
		$('#message_text7').empty().text((data.rewrite==""?[data.prefix, SERVICE7]:[data.rewrite]).join(' '));
		$('#shortcode7').empty().text(data.number);
		$('#message_cost7').empty().text([data.price, data.currency, (parseInt(data.vat)? '(включая НДС)': '(без учета НДС)')].join(' '));
		instructions7.show();

		if (data.special) {
			$("#notes7").empty().text(data.special).show();
		} else {
			$("#notes7").empty().hide();
		}
	}

	$.ajax({
		type: 'GET',
		url: '/netcat/modules/money/smscoin7/popup/data/local.js',
		dataType: 'script',
		success: function(){
			json7 = JSONResponse;
			for (var i = 0; i < json7.length; ++i) {
				select_country7.append("<option value='" + i + "'>" + json7[i].country_name + "</option>");
			}
		}
	});

	if ($(".payments").val() == 'sms7') sms7_info.show();
	$(".payments").change(function(){
		if ($(this).val() == 'sms7') {
			sms7_info.show();
		} else if ($(this).val() == 'webmoney7') {
			publish7.click(function(){
				$('#merchant_form7').submit();
				return false;
			});
		} else {
			sms7_info.hide();
		}
	});
	
	select_country7.change(function(){
		select_provider7.empty();
		select_provider7.append("<option value='-'>Выберите оператора</option>");
		DATA7 = json7[$(this).val()];
		if ($(this).val() == '-') {
			providers7.hide();		
		} else {
			if (DATA7.providers && DATA7.providers.length) {
				providers7.show();
				instructions7.hide();
				for (var j = 0; j < DATA7.providers.length; ++j) {
					select_provider7.append("<option value='" + j + "'>" + DATA7.providers[j].name + "</option>");
				}
			} else {
				providers7.hide();
				show_instructions7(DATA7);
			}
		}
	});

	select_provider7.change(function(){
		if ($(this).val() == '-') {
			instructions7.hide();		
		} else {
			show_instructions7(DATA7.providers[$(this).val()]);
		}
	});

/* //Оплата объявлений по sms на 7 дней */

/* Оплата объявлений по sms на 180 дней */
	var sms180_info = $("#sms180_info");
	var select_country180 = $("#select_country180");
	var providers180 = $("#providers180");
	var select_provider180 = $("#select_provider180");
	var instructions180 = $('#instructions180');
	var publish180 = $('#publish180');
	
	SERVICE180 = 215768;

	function show_instructions180(data) {
		$('#message_text180').empty().text((data.rewrite==""?[data.prefix, SERVICE180]:[data.rewrite]).join(' '));
		$('#shortcode180').empty().text(data.number);
		$('#message_cost180').empty().text([data.price, data.currency, (parseInt(data.vat)? '(включая НДС)': '(без учета НДС)')].join(' '));
		instructions180.show();

		if (data.special) {
			$("#notes180").empty().text(data.special).show();
		} else {
			$("#notes180").empty().hide();
		}
	}

	$.ajax({
		type: 'GET',
		url: '/netcat/modules/money/smscoin180/popup/data/local.js',
		dataType: 'script',
		success: function(){
			json180 = JSONResponse;
			for (var i = 0; i < json180.length; ++i) {
				select_country180.append("<option value='" + i + "'>" + json180[i].country_name + "</option>");
			}
		}
	});

	if ($(".payments").val() == 'sms180') sms180_info.show();
	$(".payments").change(function(){
		if ($(this).val() == 'sms180') {
			sms180_info.show();
		} else if ($(this).val() == 'webmoney180') {
			publish180.click(function(){
				$('#merchant_form180').submit();
				return false;
			});
		} else {
			sms180_info.hide();
		}
	});
	
	select_country180.change(function(){
		select_provider180.empty();
		select_provider180.append("<option value='-'>Выберите оператора</option>");
		DATA180 = json180[$(this).val()];
		if ($(this).val() == '-') {
			providers180.hide();		
		} else {
			if (DATA180.providers && DATA180.providers.length) {
				providers180.show();
				instructions180.hide();
				for (var j = 0; j < DATA180.providers.length; ++j) {
					select_provider180.append("<option value='" + j + "'>" + DATA180.providers[j].name + "</option>");
				}
			} else {
				providers180.hide();
				show_instructions180(DATA180);
			}
		}
	});

	select_provider180.change(function(){
		if ($(this).val() == '-') {
			instructions180.hide();		
		} else {
			show_instructions180(DATA180.providers[$(this).val()]);
		}
	});

/* //Оплата объявлений по sms на 180 дней */

/* Оплата объявлений через robokassa на 180 дней */
	var robokassa_info = $("#robokassa_info");
	var publish = $("#publish");
	
	if ($(".payments").val() == 'robokassa') $("#robokassa_info").show();
	$(".payments").change(function(){
		if ($(this).val() == 'robokassa') {
			robokassa_info.show();
			publish.hide();
		} else {
			robokassa_info.hide();
			publish.show();
		}
	});
/* Оплата объявлений через robokassa на 180 дней */

/* Объявление №1 */
	$(".announcement_select").change(function(){

		$(this).parent().submit();

//		$.ajax({
//			url: "/netcat/modules/robokassa/first.php?val=" + $(this).val(),
//			cache: false,
//			success: function(html){
//				$("#sms_first").html(html);
//			}
//		});


//		$("#sms_first iframe").load("/netcat/modules/robokassa/first.php?val=" + $(this).val(), function(response, status, xhr){
//			if (status == "error") {
//				var msg = "Sorry but there was an error: ";
//				alert(msg + xhr.status + " " + xhr.statusText);
//			}
//		});

	});
	var make_first_container = $("#make_first_container");
	$(".make_first_link").click(function(){
		var l = Math.round($(document).width()/2) - Math.round(make_first_container.width()/2) + $(window).scrollLeft();
		var t = Math.round($(window).height()/2) - Math.round(make_first_container.height()/2) + $(window).scrollTop();
		$("#fancy_overlay").css('opacity', 0.3).show();
		make_first_container.css({'left':l, 'top':t}).fadeIn("slow");
//		$("#sms_first").show();
		return false;
	});
	$("#close_make_first_container").click(function(){
		make_first_container.fadeOut("slow");
		$("#fancy_overlay").css('opacity', 0.3).hide();
		return false;
	});
	$("#make_first_submit").click(function(){
		$("#make_first_form").ajaxSubmit({
			complete: function(msg) {
				if (msg.responseText) {
					$("#make_first_attention").remove();
					$("#make_first_form").before("<div class='attention' id='make_first_attention'>" + msg.responseText + "</div>");
				} else {
					window.location.href='/';
				}
			}
		});
		return false;
	});
/* //Объявление №1 */

/* Вопрос №1 */
	var make_second_container = $("#make_second_container");
	$(".make_second_link").click(function(){
		var l = Math.round($(document).width()/2) - Math.round(make_second_container.width()/2) + $(window).scrollLeft();
		var t = Math.round($(window).height()/2) - Math.round(make_second_container.height()/2) + $(window).scrollTop();
		$("#fancy_overlay").css('opacity', 0.3).show();
		make_second_container.css({'left':l, 'top':t}).fadeIn("slow");
		$("#sms_second").show();
		return false;
	});
	$("#close_make_second_container").click(function(){
		make_second_container.fadeOut("slow");
		$("#fancy_overlay").css('opacity', 0.3).hide();
		return false;
	});
	$("#make_second_submit").click(function(){
		$("#make_second_form").ajaxSubmit({
			complete: function(msg) {
				if (msg.responseText) {
					$("#make_second_attention").remove();
					$("#make_second_form").before("<div class='attention' id='make_second_attention'>" + msg.responseText + "</div>");
				} else {
					window.location.href='/';
				}
			}
		});
		return false;
	});
/* //Вопрос №1 */


/* fancybox */
	$("a.article_img").fancybox({
		zoomOpacity			:	true,
		zoomSpeedIn			:	500,
		zoomSpeedOut		:	500,
		zoomSpeedChange		:	300
	});
/* //fancybox */

	/* Платные баннеры */
	$(".show_banner").click(function(){
//		$("label").hide();
//		$(".show_banner").hide();
//		$("#title_question").hide();
		if ($(this).val() == 'image') {
			$("#image_banner").show();
			$("#text_banner").hide();
//			$("#submit_banner").show();
			$("#banner_type").val('image');
		}
		if ($(this).val() == 'text') {
			$("#image_banner").hide();
			$("#text_banner").show();
//			$("#submit_banner").show();
			$("#banner_type").val('text');
		}
	});
	/* //Платные баннеры */

	/* Загрузка файла через Ajax */
	$("#loading").ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	var options = {
		beforeSubmit:  showRequest,
		success:       showResponse,
		url:       '/netcat/modules/upload/upload4jquery.php',  // your upload script
		dataType:  'json'
	};
	$('#Form1').change(function() {
		document.getElementById('message').innerHTML = '';
		$(this).ajaxSubmit(options);
		return false;
	});
	$('#url1').keyup(function(){
		$('#url_link').attr('href', $(this).val());
		$('#url').val($(this).val());
	});

	var handler = function() {

	};

	$('#url2').keyup(function(){
		url = $(this).val();
		$('#b_title a').attr('href', url);
		$('#b_text1 a').attr('href', url);
		$('#b_text2 a').attr('href', url);
		$('#b_text3 a').attr('href', url);
		$('#url').val(url);
		$("#text_block").unbind('click');
		$("#text_block").click(function(){
			window.open(url);
		});
//		$("#text_block").('click', function(){
//			window.open($(this).val());
//		});
	});

	$('#i_title').keyup(function(){
		$('#b_title a').text($(this).val());
	});
	$('#i_text1').keyup(function(){
		$('#b_text1 a').text($(this).val());
	});
	$('#i_text2').keyup(function(){
		$('#b_text2 a').text($(this).val());
	});
	$('#i_text3').keyup(function(){
		$('#b_text3 a').text($(this).val());
	});
	
	$("#submit_banner").click(function(){
		$("#banner_form").submit();
		return false;
	});

//	$('#i_title, #i_text1, #i_text2, #i_text3').ColorPicker({
//		onSubmit: function(hsb, hex, rgb, el) {
//			target1 = $(el).attr('rel');
//			target2 = $(el).attr('color');
//			$(el).css('color', '#' + hex);
//			$('#' + target1 + ' a').css('color', '#' + hex);
//			$('#' + target2).val(hex);
//			$(el).ColorPickerHide();
//		},
//		onBeforeShow: function () {
//			$(this).ColorPickerSetColor(this.value);
//		}
//	})
//	.bind('keyup', function(){
//		$(this).ColorPickerSetColor(this.value);
//	});
	var height = $('.paid_img_banner img').height();

	$('.paid_img_banner a').css({display: 'block', position: 'relative', top: '50%', height: height + 'px', 'margin-top': - height/2 + 'px'});
//	$('.paid_img_banner a').css("display: block; position: relative; top: 50%; height: " + height + "px; margin-top: -" + height/2 + "px;");
	/* Загрузка файла через Ajax */
});


function showRequest(formData, jqForm, options) {
	var fileToUploadValue = $('input[@name=Image]').fieldValue();
	if (!fileToUploadValue[0]) {
		document.getElementById('message').innerHTML = 'Please select a file.';
		return false;
	}
	$('#Form1').hide();

	return true;
} 

function showResponse(data, statusText)  {
	if (statusText == 'success') {
		if (data.img != '') {
			url = document.getElementById('url').value;
			document.getElementById('result').innerHTML = '<b>Предварительный просмотр</b><br/><a target="_blank" href="' + url + '" id="url_link"><img src="/netcat/modules/upload/banner/'+data.img+'" /></a>';
			document.getElementById('message').innerHTML = data.error;
			document.getElementById('uploaded_image').value = data.img;
		} else {
			document.getElementById('message').innerHTML = data.error;
		}
	} else {
		document.getElementById('message').innerHTML = 'Unknown error!';
	}
	$('#Form1').show();
	$("#submit_banner").show();
	$("#message").show();
	$("#result").show();
}
