// Instant-contact

function feedback_init()
{
	// Defaults	
	jQuery("#cfMessage").css("color","#999");
	jQuery("#cfName").css("color","#999");
	jQuery("#cfEmail").css("color","#999");	

	jQuery("#cfMessage").focus(function () {
			jQuery(this).text('');
			jQuery(this).css("color", "#000");
			
    });

	jQuery("#cfName").focus(function () {
			jQuery(this).attr('value', '');
			jQuery(this).css("color", "#000");			
    });
	
	jQuery("#cfEmail").focus(function () {
			jQuery(this).attr('value', '');
			jQuery(this).css("color", "#000");		
    });	
	
	
	// Submit
	jQuery("#feedback .submit").click(function () {

		if ( jQuery("#cfName").attr('value') == 'Ваше имя' || 
				jQuery("#cfMessage").text() == 'Ваш вопрос' || 
				jQuery("#cfEmail").attr('value') == 'E-mail адрес') 
		{	
		
			if (jQuery("#cfName").attr('value') == 'Ваше имя') jQuery("#cfName").css("color", "#F00");
			if (jQuery("#cfMessage").text() == 'Ваш вопрос') jQuery("#cfMessage").css("color", "#F00");			
			if (jQuery("#cfEmail").attr('value') == 'E-mail адрес') jQuery("#cfEmail").css("color", "#F00");
		
		} else {   
      jQuery.ajax({
          type: 'POST',
          url: '/message/',
          data: jQuery('#feedback').formToArray(),
          success: function (msg,status) {
            jQuery("#inst-msg").html(msg);
            feedback_init();                      
          }      
        });
      jQuery('#feedback').css('display','none');
      jQuery('#loading').css('display','block');

		}
	});	 
}

jQuery("#instant-contact").ready(function() {
  feedback_init();
	jQuery("#instant-contact #toggle").click(function(){
				jQuery(this).next().toggle(150);
	});
});



