$(document).ready(function(){
	/* PHONE SELECT */

	$("#name li:nth(0)").addClass("current_name");
	$("#phone li:nth(0)").addClass("current_phone");
	var hide = function() {
		$("#name").removeClass("active");
		$(".name").css("display","none");
		$(".current_name").css("display","block");
	}
	$("#name").hover(function() {
		$("#name").addClass("active");
		$(".name").css("display","block");
		$(".name").click(function() {
			if (!$(this).hasClass("current_name")) {
				$(".current_name").removeClass("current_name");
				$(this).addClass("current_name");
				new_phone = $(this).attr("id")+"_p";
				$(".current_phone").removeClass("current_phone");
				$("#"+new_phone).addClass("current_phone");
				hide();
			}
			else {
				hide();
			}
			return false;
		});
	},function() {
		hide();
	});
	/* END PHONE SELECT */

	$("#hormenu a, #navigation a, #nav a").hover(function() {
		if ($(this).find(".hover").length!=0) {
			$(this).find("img:first").css("display","none");
			$(this).find("img:last").css("display","block");
		}
	},function() {
		if ($(this).find(".hover").length!=0) {
			$(this).find("img:first").css("display","block");
			$(this).find("img:last").css("display","none");
		}
	});

	$("#parts li").each(function() {
		var a_length = $(this).find("span").get(0).offsetWidth;
		var li_width = a_length + 38 + "px";
		$(this).css("width",li_width).css("overflow","hidden");
	});

	if ($("#news").length != 0) { /* Automatically set height to "header" */
		news_height = document.getElementById("news_container").clientHeight;
		document.getElementById("header").style.height = news_height + 343 + "px";
		if (document.getElementById("header").clientHeight>557) {
			$("#header").css("height","557px");
			$("#news").css("height","178px").css("overflow","hidden");
		}

		$("#parts li.cur").next().css("background","url(../images/news_cur_next.jpg) left top no-repeat");
	}

	if ($("#vertmenu").length != 0) { /* Automatically set height to "container" */
		footer_height = document.getElementById("footer").clientHeight;
		header_height = document.getElementById("header").clientHeight;
		content_height = document.getElementById("sitemap").clientHeight + document.getElementById("content").clientHeight - 45;

		vertmenu_height = document.getElementById("vertmenu").clientHeight;
		if ($("#banners").length!=0) {
			inform_height = document.getElementById("banners").clientHeight;
			$("#vertmenu_container").css("height",(vertmenu_height + inform_height + 50)+"px");
		}

		if ($("#calendar").length!=0 && $("#s_news").length!=0) {
			calend_height = document.getElementById("calendar").offsetHeight;
			snews_height = document.getElementById("s_news").offsetHeight;
			$("#vertmenu_container").css("height",(vertmenu_height + calend_height + snews_height + 50)+"px");
		}
		vert_height = document.getElementById("vertmenu_container").clientHeight;
		body_height = document.body.clientHeight;
		body_width = document.body.clientWidth;

		container_height = Math.max((body_height - header_height - footer_height - 45),Math.max(vert_height,content_height))+ "px";
		$("#sitemap_content").css("width",(body_width-296-350)+"px");

		$("#container").get(0).style.minHeight = container_height;

		if ((navigator.appName=="Microsoft Internet Explorer"))
			{
      		$("#container").css("height",container_height);
			}



	}

	/* TEXT */

	$("#articles .pos:last").css("border","0");
	$("#text_block ol li").each(function() {
		var ol_html = $(this).html();
		ol_html = "<p>"+ol_html+"</p>";
		$(this).html(ol_html);
	});
	$("#text_block ol li li").each(function() {
		var ol_html = $(this).html();
		ol_html = "<p>"+ol_html+"</p>";
		$(this).html(ol_html);
	});

	// TABLE 1
	$("#text_block table").attr("cellspacing","0").attr("cellpadding","0");

	//$("#text_block .table1 th").css("border-right","1px solid #507aa2").css("border-top","1px solid #05417a").css("border-bottom","1px solid #1d5387");
	//$("#text_block .table1 th:last").css("border-right","0");

//	$("#text_block .table2 th").css("border-right","1px solid #507aa2").css("border-top","1px solid #05417a").css("border-bottom","1px solid #1d5387");
//	$("#text_block .table2 th:last").css("border-right","0");

	$(".table1 tr:nth-child(even)").css("background","#e5ecf2");
	$(".table1 tr:nth(1) td").each(function() {
		if (($(this).text() != "") && ($(this).text() != "&nbsp;") ) $(this)
									.css("background","#4e84ae url(/images/th_sub_1.gif) left top repeat-x")
									.css("height","10px")
									.css("padding","10px 6px 8px 11px")
									.css("font-weight","bold")
									.css("color","#fff");
		else $(this).css("background","url(/images/th_sub_0.gif) left top repeat-x").css("height","33px");
	});
	$(".table1 td").css("border-right","1px solid #295d8d");
	$(".table1 tr td:first-child").css("border-left","1px solid #295d8d");
	$(".table1 tr:last td").css("border-bottom","1px solid #295d8d");

	$(".table2 tr:nth-child(odd)").css("background","#e5ecf2");
	$(".table2 td").css("border-right","1px solid #295d8d");
	$(".table2 tr td:first-child").css("border-left","1px solid #295d8d");	$(".table4 tr:nth-child(odd)").css("background","#e5ecf2");	$(".table4 td").css("border-right","1px solid #295d8d");	$(".table4 tr td:first-child").css("border-left","1px solid #295d8d");	$(".table4 tr:last td").css("border-bottom","1px solid #295d8d");
	//$(".table2 tr:last td").css("border-bottom","1px solid #295d8d");

	$(".table3 tr:nth-child(odd)").css("background","#e5ecf2");

	$("#text_block form .submit").mousedown(function() { $(this).css("background","#0c467e url(../images/submit_b.gif) left top no-repeat"); });
	$("#text_block form .submit").mouseup(function() { $(this).css("background","#0c467e url(../images/submit.gif) left top no-repeat"); });
	$("#text_block form .submit").mouseout(function() { $(this).css("background","#0c467e url(../images/submit.gif) left top no-repeat"); });

	$("#text_block form #yes").mousedown(function() { $(this).css("background","#0c467e url(../images/yes_b.jpg) left top no-repeat"); });
	$("#text_block form #yes").mouseup(function() { $(this).css("background","#0c467e url(../images/yes.jpg) left top no-repeat"); });
	$("#text_block form #yes").mouseout(function() { $(this).css("background","#0c467e url(../images/yes.jpg) left top no-repeat"); });

	$("#text_block form #no").mousedown(function() { $(this).css("background","#0c467e url(../images/no_b.jpg) left top no-repeat"); });
	$("#text_block form #no").mouseup(function() { $(this).css("background","#0c467e url(../images/no.jpg) left top no-repeat"); });
	$("#text_block form #no").mouseout(function() { $(this).css("background","#0c467e url(../images/no.jpg) left top no-repeat"); });

	$("#text_block form #new_q").mousedown(function() { $(this).css("background","#0c467e url(../images/qa_b.gif) left top no-repeat"); });
	$("#text_block form #new_q").mouseup(function() { $(this).css("background","#0c467e url(../images/qa.gif) left top no-repeat"); });
	$("#text_block form #new_q").mouseout(function() { $(this).css("background","#0c467e url(../images/qa.gif) left top no-repeat"); });

	$("#text_block form #list_submit").mousedown(function() { $(this).css("background","#0c467e url(../images/filter_b.jpg) left top no-repeat"); });
	$("#text_block form #list_submit").mouseup(function() { $(this).css("background","#0c467e url(../images/filter.jpg) left top no-repeat"); });
	$("#text_block form #list_submit").mouseout(function() { $(this).css("background","#0c467e url(../images/filter.jpg) left top no-repeat"); });

	$("#text_block form #yes").click(function() { document.forms.yes.submit() });
	$("#text_block form #no").click(function() { document.forms.no.submit() });
	$("#text_block form #new_q").click(function() { document.forms.new_quest.submit() });
	$("#text_block form #list_submit").click(function() { document.forms.list_submit.submit() });

	if ($("#calendar").length!=0) $("#text_block .pos:last").css("border","0");

	/* END TEXT */

});


function f_checkEmail(str){
//alert(str);
    var reg=/[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i;
    if (reg.test(str)) {
        return true;
    }
    return false;
 }

function trade_suscribe(){

	var error = new Array();
	var str = '';

	if(document.getElementById('fio').value == '') error[0] = '�� ��������� ���� �.�.�.';
	if(document.getElementById('email').value == '') error[1] = '�� ��������� ���� E-mail';
	else {
		if(!f_checkEmail(document.getElementById('email').value)) error[3] = '������� ��������� ���� E-mail';
	}
	if(!document.getElementById('anons').checked && !document.getElementById('result').checked && !document.getElementById('info').checked) error[2] = '�� ������ ��� ��������';



	for(var i=0;i<error.length; i++){
		if(error[i] != undefined) str += '<b style="color: red">' + error[i] + '</b><br>';
	}

	if(str != '') document.getElementById('error_field').innerHTML = str;
	else document.forms.trade_ss.submit();
}

