$(document).ready(function() {

	$('.formz-send').click(function() {
		var seo = ($('.checkBx_seo').attr('checked') == 'checked') ? 'SEO' : '';
		var smm = ($('.checkBx_smm').attr('checked') == 'checked') ? 'SMM' : '';
		var ppc = ($('.checkBx_ppc').attr('checked') == 'checked') ? 'PPC' : '';
		var copy = ($('.checkBx_copy').attr('checked') == 'checked') ? 'Copy' : '';
		var other = ($('.checkBx_other').attr('checked') == 'checked') ? 'Other' : '';
		var str = '';
		if(seo != '') {
			str = str + seo;
		}
		if(smm != '') {
			str = (str != '') ? (str + ', ' + smm) : (str + smm);
		}
		if(ppc != '') {
			str = (str != '') ? (str + ', ' + ppc) : (str + ppc);
		}
		if(copy != '') {
			str = (str != '') ? (str + ', ' + copy) : (str + copy);
		}
		if(other != '') {
			str = (str != '') ? (str + ', ' + other) : (str + other);
		}
		if(str == '') {
			str = 'Нужна помощь менеджера (услуги не выбраны)';
		}

		_gaq.push(['_trackEvent', 'Заявка', 'Отправление заявки', str]);
	});
	
	// Всплывающие подсказки
	$('.servicesItem').hover(
		function() {					
			$(this).addClass('open');
			$('.open .servicesBoxHelp').fadeIn("fast");
			$(this).removeClass('open');
		},			
		function(){
			$(this).addClass('close');
			$('.close .servicesBoxHelp').fadeOut("fast")
			$(this).removeClass('close');
		}
	);
	
	// Меню услуг
	$('#order_help span').click(function() {
		$('#order_menu').hide();
		$('#order_text').fadeIn('normal');
	});
	
	$('#order_text span').click(function() {
		$('#order_text').hide();
		$('#order_menu').fadeIn('normal');
	});
	
	// Селекты
	$(".checkBx_seo").change(function() {
		if($(this).is(":checked")) {  
			$('#seo_select').fadeIn('normal');
		}
		else {
			$('#seo_select').hide();
		}
	});
	
	$(".checkBx_other").change(function() {
		if($(this).is(":checked")) {  
			$('#other_select').fadeIn('normal');
		}
		else {
			$('#other_select').hide();
		}
	});

	// Очистка полей
	var Form_block = '.netpeak-form';
	if(Form_block == '') {
		Form_block = '*'
	};
	$(Form_block).find(':text').each(function(i){
		var inputLabel = $(this).val();
        $(this).focus(function(){if ($(this).val() == inputLabel) {$(this).val('')}});
        $(this).blur(function(){if ($(this).val() == '') {$(this).val(inputLabel)}})
	});
	$(Form_block).find(':password').each(function(i){
		var inputLabel=$(this).val(),inputClass=$(this).attr('class'),inputId=$(this).attr('id'),inputTitle=$(this).attr('title'),inputStyle=$(this).attr('style');
		$(this).after('<input type="text" />').hide(0);
		$(this).next().val(inputLabel);
		if (inputClass) {$(this).next().addClass(inputClass)};
		if (inputId) {
			$(this).removeAttr('id');
			$(this).next().attr('id',inputId)
		};
		if (inputTitle) {$(this).next().attr('title',inputTitle)};
		if (inputStyle) {$(this).next().attr('style',inputStyle)};
		$(this).next().focus(function(){
			if ($(this).val() == inputLabel) {
				$(this).hide(0);
				if (inputId) {
					$(this).removeAttr('id');
					$(this).prev().attr('id',inputId)
				};
				$(this).prev().val('').attr('id',inputId).show(0).focus();
			}
		});
		$(this).blur(function(){
			if ($(this).val() == '') {
				if (inputId) {
					$(this).removeAttr('id');
					$(this).next().attr('id',inputId)
				};
				$(this).val(inputLabel).hide(0);
				$(this).next().show(0)
			}
		})
	});
	$(Form_block).find('textarea').each(function(i){
		var textareaLabel=$(this).val();
		$(this).focus(function(){if ($(this).val() == textareaLabel) {$(this).val('')}});
		$(this).blur(function(){if ($(this).val() == '') {$(this).val(textareaLabel)}})
	});
	
});

