$(document).ready(function () {
	var $inputs = $('#cform :input');
	$inputs.each(function() {
        if ($(this).attr('value') != ''){ $(this).parent().addClass('press'); }
    });
	if ($('#cform textarea').val() != ''){ $(this).parent().addClass('press'); }
	$('.form input').focus(function() { $(this).parent().addClass('focus'); });
	$('.form input').focusout(function() { $(this).parent().removeClass('focus'); });
	$('.form textarea').focus(function() { $(this).parent().addClass('focus'); });
	$('.form textarea').focusout(function() { $(this).parent().removeClass('focus'); });
	$('.form input').keypress(function() {
		$(this).parent().removeClass('focus');
		$(this).parent().addClass('press');
	});
	$('.form input').change(function() {
		if ($(this).attr('value') == ''){
			$(this).parent().removeClass('focus');
			$(this).parent().removeClass('press');
		}
	});
	$('.form textarea').keypress(function() {
		$(this).parent().removeClass('focus');
		$(this).parent().addClass('press');
	});
	$('.form textarea').change(function() {
		if ($(this).val() == ''){
			$(this).parent().removeClass('focus');
			$(this).parent().removeClass('press');
		}
	});
	$('a.showpopup').click(function() { 
		if ($('div.more').css('display') == 'block'){ $('div.more').slideUp(); }
		else { $('div.more').slideDown(); }
		return false;
	});
	$('#cform').submit(function() {		
		$('#cmessage').fadeIn('fast');
		var allowed = false;
		$("#cform input:text, #cform textarea").each(function(){
			if($(this).val())
				allowed = true;
		})
		if(allowed)
			$.post("/index_mess.php", $("#cform").serialize(), function(data){			
				$('#cmessage p').html(data);
				$("#cform input:text, #cform textarea").val('').parent().removeClass('focus').removeClass('press');
				//$('#cmessage').fadeIn('fast');
				setTimeout(function(){$('#cmessage').fadeOut('fast');},5000);
			});
		else {
			$('#cmessage p').html("Перед отправкой необходимо заполнить поля формы.");
		}
			
		return false;
	});
	$('body').click(function() { 
		$('#cmessage').fadeOut();
	});
	$('a.close').click(function() { 
		$('div.more').slideUp(); 
		return false;
	});
	$('#cform').append('<input type="hidden" name="feedback[js_chk]" value="1"/>');


	var $zinputs = $('#zform :input');
	$zinputs.live('each', function() {
        if ($(this).attr('value') != ''){ $(this).parent().addClass('press'); }
    });
	$('.formajax input').live('focus', function() { $(this).parent().addClass('focus'); });
	$('.formajax input').live('focusout', function() { $(this).parent().removeClass('focus'); });
	$('.formajax input').live('keypress', function() {
		$(this).parent().removeClass('focus');
		$(this).parent().addClass('press');
	});

	$('.formajax input').live('change', function() {
		if ($(this).attr('value') == ''){
			$(this).parent().removeClass('focus');
			$(this).parent().removeClass('press');
		}
	});

	$('#zform').live('submit', function() {		
//		$('#zform').live('append', '<input type="hidden" name="feedback[js_chk]" value="1"/>');
		$('#zmessage').fadeIn('fast');
		var allowed = false;
		if (($("#z_name").val()!="") && ((($("#z_phone").val()!=""))||(($("#z_email").val()!=""))) ) allowed = true;
		if(allowed){
			$('#zmessage p').html("Спасибо за отправку.");
			gaq_event('Send', $("#z_id").val());
			$("#z_from").val($("#z_id").val());
			$.post("/index_zmess.php", $("#zform").serialize(), function(data){	
				$('#zmessage p').html(data);
				$("#zform input:text, #zform textarea").val('').parent().removeClass('focus').removeClass('press');
				//$('#cmessage').fadeIn('fast');
				setTimeout(function(){$('#zmessage').fadeOut('fast');},5000);
			});}
		else {
			$('#zmessage p').html("Перед отправкой необходимо заполнить имя и хотя бы один контакт.");
		}
		return false;
	});
//	$('#liveTex_logoAnim').live('css', function(){("background-image", "http://yandex.st/lego/_/X31pO5JJJKEifJ7sfvuf3mGeD_8.png")});
});
