function checkMessage()
{
	$(".star").hide();
	
	if (document.getElementById("telephone").value != "")
	{
		str = checkForm('message-2');
		if (str) 
			$.post("/classes/ajax/sendMessage.php", str, sendSuccessMessageForm);
	}
	else
	{
		str = checkForm('message-1');
		if (str) 
			$.post("/classes/ajax/sendMessage.php", str, sendSuccessMessageForm);
	}
	return false;
}

function sendSuccessMessageForm(data) 
{
	if (data == "ok") 
	{
		document.forms.message.reset();
		$("#mainMessage").hide();
		$("#alertwindow").show();
	}
	else
		alert("На стороне сервера произошла ошибка, извиняемся за причиненные неудобства, попробуйте послать еще раз. Спасибо за понимание!");
}

function checkFaq()
{
	str = checkForm('faq');
	if (str) 
		$.post("/classes/ajax/sendFaq.php", str, sendSuccessFaqForm);
	return false;
}
function sendSuccessFaqForm(data) {
//	$("#faqForm").html(data);
	$("#alertwindow").show();
	}

function checkForm(name)
{
	flag = true;
	str = {};
	$('.need-' + name).each(
	function()
	{
		if (this.value == "") 
		{
			flag = false;
			this.nextSibling.nextSibling.style.display = "block";
		}
		else 
			this.nextSibling.nextSibling.style.display = "none";
	}
	);
	if (flag)
	{
		$(".need-"+name).each(function()
		{
			str[this.name] = this.value;
		});
		$(".not-need-"+name).each(function()
		{
			str[this.name] = this.value;
		});
		$(".alert-"+name).hide();
		return str;
	}
	else
	{
		$(".alert-"+name).show();
		return false;
	}
	return false;
}

function showSubPageLeftMenu(t)
{
	if (t.className == "plus")
	{
		t.className = "minus";
		$('#p_'+t.id).show();
	}
	else
	{
		t.className = "plus";
		$('#p_'+t.id).hide();
	}
	return false;
}

function showCatalogTable(id)
{
	if (document.getElementById("catalog_table_" + id + "_0").style.display == "none") 
	{
		$(".catalog_table_" + id).fadeIn();
		$("#catalog_table_h_" + id).fadeIn();
	}
	else 
	{
		$("#catalog_table_h_" + id).fadeOut();
		$(".catalog_table_" + id).fadeOut();
	}
	return false;
}
var thisId = 0;
function showMap(id)
{
	if (document.getElementById("map_"+id).style.display == "none")
		$("#map_"+id).fadeIn();
	else
		$("#map_"+id).fadeOut();

	return false;
}

function showQuestion(id)
{
	thisId = id;

		$("#question_"+thisId).addClass("big");
		$("#question_answer_" + id).slideDown(400);
}
function hideBigClassName(){$("#question_"+thisId).removeClass("big");}

function showMessage()
{
	if (document.getElementById("mainMessage").style.display == "none")
		$("#mainMessage").fadeIn();
	else
		$("#mainMessage").fadeOut();

	return false;
}
function showTelOnMessageForm()
{
	if (document.getElementById("tel_on_message_form_off").style.display == "block") 
	{
		$("#tel_on_message_form_off").hide();
		$("#tel_on_message_form_on").show();
		document.getElementById("mainMessage").style.height = '354px'
	}
	else 
	{
		$("#tel_on_message_form_off").show();
		$("#tel_on_message_form_on").hide();
		document.getElementById("mainMessage").style.height = '457px'
	}
	return false;
}

$().ready(
	function() 
	{
		$(".accordion").accordion({
			autoheight: false, 
			active: ".current", 
			header: "a.tab"
		});

		$('.light').lightBox();
		$('.light-once').lightBox();
	}
);