var IE=/*@cc_on!@*/!1;

function contact_ajaxsend() {
	$('.capcha_form, .url, .mail, .text, .cat, .name').css('background-color', '#fff');

	//alert($("#mail").serialize());
	$.ajax({
		type: "POST",
		url: "/ajax.php",
		data: "mod=mail&" + $("#mail").serialize(),
		success: function(msg){
		   	if (msg.match(/1/)) $('.capcha_form').css('background-color', '#fee2e2');
		   	if (msg.match(/2/)) $('.text').css('background-color', '#fee2e2');
		   	if (msg.match(/3/)) $('.mail').css('background-color', '#fee2e2');
		   	if (msg.match(/4/)) $('.name').css('background-color', '#fee2e2');
		   	if (msg == '8') $('#result2').html('<div style="margin-top:15px;"><img src="/img/cookie.png" style="float:left; margin-right:5px;"><div class="red" style="font-size:11px; width:170px; float:left; margin-top:-2px;">Для отправки сообщения должны быть включены cookies!</div></div>');
			if (msg == '') $('#form').html("<div class='button4' style='margin-right:0; width:100%; margin-bottom:15px;'>Благодарим Вас за интерес, проявленный к нашим услугам! Наш сотрудник свяжется с Вами в ближайшее время.</div>");
	  	}
	});
}

function recall() {
	$('.phone').css('background-color', '#fff');

	$.ajax({
		url: "/ajax.php",
		data: "mod=recall&" + $("#recall").serialize(),
		success: function(msg){
		   	if (msg.match(/2/)) $('.capcha_form').css('background-color', '#fee2e2');
		   	if (msg.match(/1/)) $('.phone').css('background-color', '#fee2e2');
		   	if (msg == '3') $('#recall-result2').html('<div style="margin-top:15px;"><img src="/img/cookie.png" style="float:left; margin-right:5px;"><div class="red" style="font-size:11px; width:170px; float:left; margin-top:-2px;">Для отправки сообщения должны быть включены cookies!</div></div>');
			if (msg == '') $('#recall-form').html("<div class='button4' style='margin-right:0; width:100%; margin-bottom:15px;'>Благодарим Вас за интерес, проявленный к нашим услугам! Наш сотрудник свяжется с Вами в ближайшее время.</div>");
	  	}
	});
}



$(document).ready(function () {
	$('.capcha_form, .url, .mail, .text, .name, .cat, .phone').focus(function (){
		$(this).css('background-color', '#fff');
	});
	
	$('#sendd').click(function() {
		$('#senddd').slideToggle(300);
	});
	$('#recc').click(function() {
		$('#reccc').slideToggle(300);
	});
	
	$("a#single_image").fancybox();
	
	$(".iframe").fancybox({
	'autoSize': true,
    'width': 800, 
    'type': 'iframe',

	});
		


	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	$('.feedback').click(function(){
		$.ajax({
			url: '/feedback.php?mod=' + mod,
			success: function(data){
				$.fancybox({content: data,  fitToView: false});
			}
		});
	});
		$('.recall2').click(function(){
		$.ajax({
			url: '/recall.php?mod=' + mod,
			success: function(data){
				$.fancybox({content: data,  fitToView: false});
			}
		});
	});
	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	$('#try-payed, .try-payed').on("click", function(){
		$('#try-test').removeClass('active2');
		$('#try-payed').addClass('active2');
		$('.test-period').hide();
		$('.payed-period').show();
	});
	
	$('#try-test').on("click", function(){
		$('#try-payed').removeClass('active2');
		$(this).addClass('active2');
		$('.payed-period').hide();
		$('.test-period').show();
	});
	
	$('#cd1').on("click", function(){ $('#domain').slideDown(300); });
	$('#cd0').on("click", function(){ $('#domain').slideUp(300); });
	
//	$('input[name="mailbox-count"]').on("keyup", calculateMailboxesCost);
//	$('input[name="period2"]').change(calculateMailboxesCost);
});

function calculateMailboxesCost(){
	var cost = 0, count = parseInt($('input[name="mailbox-count"]').val()), period = parseInt($('input[name="period2"]:checked').val());
	
	if (count != "NaN" && period != "NaN"){
		if (count > 0 && count < 500 && period > 0){
			var price = count >= 100 ? 89 : 99;
			cost = count * period * price;
		}
	}
	
	if (cost || count >= 500) $('#total').show();
	else $('#total').hide();
	$('#total-sum').html(count >= 500 ? 'Звоните!' : cost + ' руб.');
}

function mailboxRequestSend(){
	$.ajax({
		url: "/ajax.php?mod=mailboxRequestSend&" + $('#mailboxRequest').serialize() + "&test=" + $('#try-test').hasClass('active2'),
		success: function(msg){
			if (msg.match(/1/)) $('.name').css('background-color', '#fee2e2');
		   	if (msg.match(/2/)) $('.mail').css('background-color', '#fee2e2');
		   	if (msg.match(/3/)) $('.capcha_form').css('background-color', '#fee2e2');
			
			if (msg.match(/4/)) $('#result2').html('<div id="message-nocookies"><img src="/img/cookie.png"><div>Для отправки сообщения должны быть включены cookies!</div></div>');
			if (msg == '') $('#form').html('<div id="message-success">Благодарим Вас за интерес, проявленный к нашим услугам! Наш сотрудник свяжется с Вами в ближайшее время.</div>');
		}
	});
}
