var is_ie=false;
var ie6=false;
var ie7=false;
var ie8=false;

var rt='1'; // главная ли
var jsnlfr=5; // при запросе новостей - с какой
var jsnlkv=5; // при запросе новостей - сколько

var ctmenu = false;

tmp = document.location.href;
var mass_param = tmp.split("/");
var cur_lang = mass_param[3];



if (document.all && !window.opera) {
	is_ie=true;
	if (navigator.userAgent.indexOf("MSIE 6") >= 0) {ie6=true;}
	if (navigator.userAgent.indexOf("MSIE 7") >= 0) {ie7=true;}
	if (navigator.userAgent.indexOf("MSIE 8") >= 0) {ie8=true;}
}


    window.yandex_metrika_callback = function() {
        window.yaCounter1132549 = new Ya.Metrika(1132549);
    }
    jQuery(document).ready(function() {
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = ((document.location.protocol=='https:')?'https:':'http:') + '//mc.yandex.ru/metrika/watch.js';
        s.setAttribute('async', 'true');
        document.documentElement.firstChild.appendChild(s);    
    });




$(function(){
	
	if (cur_lang=='kz'&&ie6) {
		$("#hmenu1 li a, #m li a, .ni2, #blog_menu li a").css({fontFamily:"Times New Roman",fontSize:"19px"});
		$("#b1").width("50%");
	}


	$(".wmali").each(function(){
		targ = $(this).text(); tmp = targ.split('~');
		$(this).text(tmp[0]+"@"+tmp[2]).attr("href","mailto:"+tmp[0]+"@"+tmp[2]);
	});

	
	
	
	if (mass_param[4]=='zakupki') { $("#c2").addClass("zakuph"); }
	
	if ($(".searchh2").length) {
		$("#m").remove();
		$("#c2").css("marginLeft","5%");
	}
	
	eubur();
	map_react();
	faq_react();
	gallery_react();
	search_react();
	forecast_react();
	mark_table();
	zakupki_react();
	opros();
	settime();
	mark_main_menu();
	user_form_react();
	comment_form_react();
	news_root_hover();
	
	
	
	
	
	
	$("#hpsk form").attr("action",'/'+cur_lang+'/search/');
	$("#hpsk a").click(function(){
		$(this).parent().find("form")[0].submit();
		return false;
	});
	
	
	
	
	
	
	
	if ($("#fp1").length) { rnd = myrnd(1,4);  $("#fp1").attr("id","fp"+rnd); 	}
	
	if ($("#rzd_pic").length) { rnd = myrnd(1,4);  $("#rzd_pic div").css({backgroundImage:"url('/design/rp"+rnd+".gif')"});}
	
	
	
	
	
	
	if ($("#nt").length>0) {rt='1';jsnlfr=3;jsnlkv=3;} else {rt='0';} 
	
	$(".tr_next_page").click(function(){
		
		$(".tr_next_page").parent().hide();
		$(".tr_next_page").parent().before("<div class='tmp_al2'> <img src='/design/al.gif' alt='' /></div>");		
		
		$.post("/system/plugins/news.php",{l:cur_lang, a:"ajax_get_news",rt:rt,from:jsnlfr,kolvo:jsnlkv,href:$(this).attr("href")},function(data){
			
			if ($(data).find("error").length) { alert( $(data).find("error").text() ); return true; }
			
			$(".tr_next_page").parent().before($(data).find("html").text());
			$(".tr_next_page").parent().show();
			$(".tmp_al2").remove();
			jsnlfr = jsnlfr + jsnlkv;
			
			if ($(data).find("mp").text()=='false') {
				$(".tr_next_page").parent().remove();
			}
			
		},"xml");

		return false;
	});
	
	
	
	
	tmpimg1 = document.createElement("img"); tmpimg1.src='/design/w2.png';
	tmpimg2 = document.createElement("img"); tmpimg2.src='/design/al.gif';
	
	$(".setka").css("opacity","0.15");
	$("#talg").css("left","1100px").animate({left:0},10000);
	
	
	$("#do4ki a").hover(function(){
		dd($("#do4ki a").index($(this)));
	},function(){
		dd2($("#do4ki a").index($(this)));
	});

	$("#do4ki_logos a").hover(function(){
		dd($("#do4ki_logos a").index($(this)));
	},function(){
		dd2($("#do4ki_logos a").index($(this)));
	});
	
	$("#w").hover(function(){
		$(this).css('backgroundImage',"url('/design/w2.png')");
		$(document).pngFix();
	},function(){
		$(this).css('backgroundImage',"url('/design/w1.png')");
		$(document).pngFix();
	});
	
	
	
	$(".news_more_cont").live("click",function(){
		hrf = $(this).find(".news_more").attr("href");
		document.location.href = hrf;
	});
	
	
	$(".more_news_cont1 a:first").click(function(){
		$(".more_news_cont1").parent().hide();
		$(".more_news_cont1").parent().before("<div class='tmp_al' style='margin-left:31%'><img src='/design/al.gif' alt='' /></div>");		
		
		$.post("/system/plugins/news.php",{l:cur_lang, a:"ajax_get_news",rt:rt,from:jsnlfr,kolvo:jsnlkv},function(data){
			$(".more_news_cont1").parent().before($(data).find("html").text());
			$(".more_news_cont1").parent().show();
			$(".tmp_al").remove();
			jsnlfr = jsnlfr + jsnlkv;
			
			$("#b1").width("100%");
			news_root_hover();
			
			if ($(data).find("mp").text()=='false') {
				$(".more_news_cont1").parent().remove();
			}
			
		},"xml");
		return false;
	});
	
	// $(".ni3").hover(function(){$(this).css("background","url('/design/bgn.jpg') center");});

});






function eubur() {
	
	$("#eubur input:button").click(function(){



	pars = {
		a:"edit_user",
		name: $("#eubur input:eq(0)").val(),
		mail: $("#eubur input:eq(1)").val(),
		p1: $("#eubur input:eq(2)").val(),
		p2: $("#eubur input:eq(3)").val()
	};
	
	$.post("/system/plugins/pp.php",pars,function(data){
		if ( $(data).find("error").length ) { alert( $(data).find("error").text() ); return }
		if ( $(data).find("mess").length ) { alert( $(data).find("mess").text() ); $("#eubur").hide(); return }
		alert("Сохранено");
	},"xml");




	
	});
	
	
	
}






var marsh_loading_id = 0;

var cts = [["Алматы",879,498],["Шымкент",600,547],["Караганда",738,246],["Астана",685,191],["Павлодар",822,126],["Усть-Каменогорск",960,210],["Семипалатинск",830,205],["Актобе",308,212],["Уральск",125,160],["Костанай",486,108],["Петропавловск",628,40],["Кызылорда",528,457],["Актау",92,450],["Атырау",146,312],["Кокшетау",632,110],["Жезказган",588,336]];
var cts_kz = [["Алматы",879,498],["Шымкент",600,547],["Қарағанды",738,246],["Астана",685,191],["Павлодар",822,126],["Өскемен",960,210],["Семей",870,205],["Ақтөбе",308,212],["Орал",125,160],["Қостанай",486,108],["Петропавловск",628,40],["Қызылорда",528,457],["Ақтау",92,450],["Атырау",146,312],["Көкшетау",632,110],["Жезқазған",588,336]];



function map_react() {
	
	if (cur_lang=='kz') { cts = cts_kz; }
	
	if (mass_param[4]!='map') { return true; }
	
	

	$("#m").hide();
	$("#c2").css({margin:"50px 0 100px 0",width:"100%",overflow:"hidden"});
	$("#c2 h1").css({marginLeft:"5%"});
	q='"';
	
	$("#c2").append("<div id='mapcont' style="+q+"width:100%; height:685px; background:url('/design/smap.jpg') #e5e5e5 no-repeat center;position: relative;"+q+"></div>");
	
	$("#mapcont").append("<div id='map_cities' style="+q+"position: absolute; top:0; left:0; width: 100%; height: 645px;"+q+"></div>");
	
	$(cts).each(function(k,v){
		$('#map_cities').append("<a id='map_city_"+k+"' href='' style='position:absolute'>"+this[0]+"</a>");
		//alert(this[0]);
	});
	
	$("#map_cities a").click(function(){
		
		$(".marsh_selected").removeClass("marsh_selected");
		$(this).addClass("marsh_selected");
		
		$(".old_marsh").fadeOut(600,function(){
			$(this).remove();
		});
		marsh_loading_id = $("#map_cities a").index(this);
		marsh = document.createElement("img");
		$(marsh).load(function(){
			$("#mapcont").prepend("<div class='new_marsh' style="+q+"display:none; position: absolute; left:0; top:20px; width:100%; height: 645px; background:url('/design/map/"+(marsh_loading_id+1)+".gif') no-repeat center;"+q+"></div>");
			$(".new_marsh").fadeIn(600,function(){
				$(this).attr("class","old_marsh")
			});
		});
		marsh.src = "/design/map/"+(marsh_loading_id+1)+".gif";
		
		
		return false;
	});
	
	
	fix_cities_pos();
	
	
}





function fix_cities_pos() {
	
	if (mass_param[4]!='map') { return true; }
	
	tmp = getClientWidth();
	popr = Math.ceil((tmp-1130)/2);

	$(cts).each(function(k,v){
		$('#map_city_'+k).css({top:(v[2]+10)+'px',left:(v[1] + 10 + popr)+'px'});
		//alert(this[0]);
	});
	
	
}




function faq_react() {
	
	if (mass_param[5]!='faq') { return true; }
	
	$("#c2 *").not("h1").hide();
	
	ob = ''; ah2co = 0;
	$("#c2 h2").each(function(){
		ob = ob + "<li><a href='' id='fccon"+ah2co+"' class='a_lev_h2'>"+$(this).text()+"</a></li>";
		$(this).hide().attr('id','fccon'+ah2co+'h2').addClass("a_lev_samh2");
		ah2co++;
	});
	$("#c2 h1").after("<ul style='margin-bottom: 40px;'>"+ob+"</ul>");

	$("#c2 h3").each(function(){
		$(this).after("<p style='display:none' class='a_lev_h3'><a href=''>"+$(this).text()+"</a></p>");
		$(this).remove();
	});
	
	$(".a_lev_h2").show();
	
	$(".a_lev_h2").click(function(){
		$(".faq_selected2").removeClass("faq_selected2");
		$(".faq_selected").removeClass("faq_selected");
		$(this).addClass("faq_selected");
		
		showing_start = $("#"+this.id+"h2");
		$(".showed_question, .showed_question2").hide();
		// показываем все элементы начиная от showing_start и заканчивая следующим a_lev_h2
		while ($(showing_start).next().length) {
			no = $(showing_start).next();
			if (!$(no).hasClass("a_lev_samh2")) {
				if ($(no).hasClass("a_lev_h3")) {
					$(no).show().addClass("showed_question");
				}
				showing_start = no;
			} else {
				break;
			}
		}
		
		return false;
	});
	
	
	$(".a_lev_h3").click(function(){
		
		$(".faq_selected2").removeClass("faq_selected2");
		$(this).addClass("faq_selected2");
		
		showing_start = this;
		$(".showed_question2").hide();

		while ($(showing_start).next().length) {
			no = $(showing_start).next();
			if (!$(no).hasClass("a_lev_h3") && !$(no).hasClass("a_lev_samh2")) {
				$(no).show().addClass("showed_question2");
				showing_start = no;
			} else {
				break;
			}
		}
		
		return false;
		
		
		
	});
	
	
	
}












var bst = 0;
var closemess = {"ru":"нажмите на изображение для возврата","en":"press on image to return","kz":"Қайтаруға арналған суретке басыңыз"};
var galtitle = '';

function gallery_react() {
	
	if (mass_param[5] == 'gallery' && mass_param.length > 7 && mass_param[6]!='') {
		
		if (cur_lang == 'kz') {
			$("h1").before("<h2 style='margin: 30px 0 40px 0'><a href='/kz/'>Басты бет</a> » <a href='/kz/press_center/'>Баспасөз орталығы</a> » <a href='/kz/press_center/gallery/'>Фотогалерея</a> » "+$("h1").text()+"</h2>").hide();
		} else {
			$("h1").before("<h2 style='margin: 30px 0 40px 0'><a href='/ru/'>Главная</a> » <a href='/ru/press_center/'>Пресс-центр</a> » <a href='/ru/press_center/gallery/'>Фотогалерея</a> » "+$("h1").text()+"</h2>").hide();
		}
		
		$("#h, #rzd2,#m").hide();
		$("#c2").css({marginTop: "20px", marginLeft:"5%",width:"90%"});
	}
	
	
	
	
$("a[rel=wzoom]").live("click",function(){
	
	if ($(".loadingdiv").length > 0) {return false;}
	
	galtitle = $(this).find("img").attr("title");
	
	$(this).parent().append("<div class='loadingdiv'><img src='/design/al.gif' /></div>");
	$(".loadingdiv").css("opacity","0.5");
	
	tmpimg = document.createElement("img");
	$(tmpimg).load(function(){
		bst = getBodyScrollTop();
		$(".gal_cont").hide();
		window.scrollTo(0,0);
		$("h1").after("<div class='bigimg'><img src='"+this.src+"' /><p style='margin-top:30px;'>"+galtitle+"</p><p><a href=''>"+closemess[cur_lang]+"</a></p></div>");
		
		$(".bigimg").fadeIn("500",function(){$("#b1").css("height","101%"); });
		
	});
	
	tmpimg.src=this.href;
	
	return false;
});
	
	


$(".bigimg img, .bigimg a:first").live("click",function(){
	$(".bigimg").fadeOut(500,function(){
		$(".bigimg, .loadingdiv").remove();
		$(".gal_cont").show();
		
		$("#b1").css("height","101%"); $("#b1").css("height","100%"); // fix ie6 bag		

		window.scrollTo(0,bst);
	});
	return false;

});
	
	
	
	
}






function myrnd(x,y) { return Math.floor( Math.random( ) * (y - x + 1) ) + x; }






function getBodyScrollTop(){
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}















var srcpfrom = 30;
var srcpkolvo = 30;

function search_react() {

	$(".srcnextpgs a").click(function(){
		
		k2 = srcpkolvo; if ($(".srcnextpgs a:last")[0] == this) { k2 = 0; }
		
		$("#search_cont").append("<div class='tmp_al' style='margin-top: 30px;'><img src='/design/al.gif' /></div>");
		$(".srcnextpgs").hide();
		
		$.post("/system/plugins/search.php",{l:cur_lang, a:"search", s:srcpfrom, k:k2, t: $(".search_psk_txt strong").text()},function(data){
			
			$(".tmp_al").remove();
			$("#search_cont").append($(data).find("text").text());
			if ($(data).find("mp").text()=='true') { $(".srcnextpgs").show(); }
			
			
			srcpfrom = srcpfrom + srcpkolvo;
			
		},"xml");
		
		return false;
		
	});
	
	
	
}












function set_forecast(date_for, temp, desc, loc) {
	$(".ctlst_cont_sel").removeClass("ctlst_cont_sel");
	$("#ctlst_"+loc).addClass("ctlst_cont_sel");
	
	if (cur_lang=='kz') {
		$("#hpgd a").text($("#ctlst_"+loc).text() + " қ. ▼");
	} else {
		$("#hpgd a").text("г. "+ $("#ctlst_"+loc).text() + " ▼");
	}
	$("#hpgd strong").text(temp);
	$("#hpgd div:last").text(desc);
	
	$("#hpgd div:eq(1), #hpgd div:eq(2)").attr("title",date_for).fadeIn(1000);
	
	
	
	
}


function forecast_react() {
	
	$("body").click(function(){
		if (ctmenu) {
			ctmenu = false;
			$("#ctlst_cont").hide();
		}
	});
	
	$("#hpgd a").click(function(){
		pos = $(this).offset();
		$("#ctlst_cont").css({top: (pos.top-10) + "px", left: (pos.left-3) + "px",opacity:0.95}).show();
		ctmenu = true;
		
		//$.post("/system/plugins/pp.php", {a: "getweather"},function(data){
		//	alert(' '+$(data).find("city").text());
		//},"xml");
		return false;
	});
	
	$("#ctlst_cont a").click(function(){
		$(".ctlst_cont_sel").removeClass("ctlst_cont_sel");
		$(this).addClass("ctlst_cont_sel");
		$("#ctlst_cont").hide();
		
		$("#hpgd div:eq(1), #hpgd div:eq(2)").hide();
		$.post("/system/plugins/pp.php", {l:cur_lang, a: "getweather",ct:this.id},function(data){
			set_forecast($(data).find("date_for").text(), $(data).find("tempr").text(), $(data).find("desc").text(), $(data).find("loc").text());
		},"xml");

		return false;
	});
	
	
	// если сервак подставил данные о погоде, то ставим их, если их нет, то запрашиваем
	if ($("#dtwts").length) {
		set_forecast($("#dtwts div:eq(0)").text(),$("#dtwts div:eq(1)").text(),$("#dtwts div:eq(2)").text(),$("#dtwts div:eq(3)").text());
	} else {
		$("#hpgd div:eq(1), #hpgd div:eq(2)").hide();
		$.post("/system/plugins/pp.php", {l:cur_lang, a: "getweather"},function(data){
			set_forecast($(data).find("date_for").text(), $(data).find("tempr").text(), $(data).find("desc").text(), $(data).find("loc").text());
		},"xml");
	}
	
	
	
}












function mark_table() {
	$(".marked_table").each(function(){
		//alert('mt');
		$(this).find("tr:last td").css("borderBottom","3px solid #f0f0f0");
	});
	
	//tr:last td").css("borderBottom","3px solid #f0f0f0");
	
	$(".marked_table tr:odd").css("backgroundColor","#ffffff");
	$(".marked_table tr:even").css("backgroundColor","#f1f1f1");
}












var zkp = 2; var dno;
function zakupki_react() {
	
	$(".znextpage").click(function(){
		$(this).parent().hide();
		$(this).parent().before("<div style='margin-top: 50px;' class='tmp_al'><img src='/design/al.gif' /></div>");
		$.post("/system/plugins/zakupki.php",{l:cur_lang, a:'get_zakup_page',p:zkp, r:$(".znextpage").parent().attr("id")},function(data){
			
			$(".tmp_al").remove();
			$(".znextpage").parent().before($(data).find("html").text());
			
			if ($(data).find("mp").text()=='true') {
				$(".znextpage").parent().show();
			}
			
			
			zkp = zkp+1;
			
		},'xml');
		
		return false;
	});
	
	
	
	
	$(".getfilespis").click(function(){
		dno = this; 
		$.post("/system/plugins/zakupki.php",{l:cur_lang, a:"skachali",fnh:$(this).attr("id")},function(data){
			
			
			$(".skackali_yo").remove();
			
			extended = ($(data).find("rnn").length>0)?true:false;
			
			ob="<table class='skackali_yo' width='100%' cellpadding='5'>";
			
			$(data).find("row").each(function(){
				if (extended) {
					ob = ob + "<tr><td valign='top'>"+$(this).find("name").text()+"</td><td valign='top'>"+$(this).find("adr").text()+"</td><td valign='top'>"+$(this).find("rnn").text()+"</td><td valign='top'>"+$(this).find("ceo").text()+"</td><td valign='top'>"+$(this).find("tel").text()+"</td><td valign='top'>"+$(this).find("time").text()+"</td></tr>";
				} else {
					ob = ob + "<tr><td valign='top'>"+$(this).find("name").text()+"</td><td valign='top'>"+$(this).find("adr").text()+"</td><td valign='top'>"+$(this).find("ceo").text()+"</td><td valign='top'>"+$(this).find("time").text()+"</td></tr>";
				}
			});
			ob = "<h2 class='skackali_yo'>Список получивших документацию</h2>" + ob + "</table>";
			
			obj = get_c2_child(dno);
			$(obj).after(ob);
			
		},"xml");
		
		
		return false;
	});
	
	
	
	$(".getfile").click(function(){
		dno = this;
		
		please_login = {'ru':'Для загрузки документов необходимо войти под своим именем или пройти регистрацию пользователя.','kz':'Файлды алу үшін өз атымен кіру немесе тіркелу қажет'}
		please_fill = {'ru':'Пожалуйста, заполните форму!','kz':'Форманы толтырыңыз!'}
		
		if (!logined) { alert(please_login[cur_lang]); return false; }
		
		if ($("#ofniresu span:last").text()=='') { 
		
			if ($("#additional_info_form").length) { alert(please_fill[cur_lang]); return false; }
			
			
			obj = get_c2_child(this);
			
			if (cur_lang == 'kz') {
				$(obj).after("<div id='additional_info_form'><h2>Қосымша деректер</h2><p>Конкурстық құжаттарды алу үшін және конкурсқа қатысу үшін форманы толтырыңыз. Ақпаратты дұрыс енгізіңіз, әйтпесе сіз конкурсқа қатыса алмайсыз.</p><div>Есептiк жазу:</div><div><input disabled='true' size='40' value='"+$("#ofniresu span:first").text()+"'></div><div class='mt13'>Заңды тұлғаның атауы:</div><div><input size='40'></div><div class='mt13'>Заңды мекенжайы:</div><div><input size='40'></div><div class='mt13'>СТН:</div><div><input size='40'></div><div class='mt13'>Директордың аты-жөнi:</div><div><input size='40'></div><div class='mt13'>Байланыс телефондары:</div><div><input size='40'></div><div class='mt13'><input type='button' value='Жіберу'> <input type='button' value='Жою'></div></div>");
			} else {
				$(obj).after("<div id='additional_info_form'><h2>Дополнительные данные</h2><p>Для того, чтобы получить конкурсную документацию и принять участие в конкурсе, заполните форму. Пожалуйста, вводите достоверную информацию, поскольку в противном случае Вы не сможете принять участие в конкурсе.</p><div>Учётная запись:</div><div><input disabled='true' size='40' value='"+$("#ofniresu span:first").text()+"'></div><div class='mt13'>Наименование юр. лица:</div><div><input size='40'></div><div class='mt13'>Юридический адрес:</div><div><input size='40'></div><div class='mt13'>РНН:</div><div><input size='40'></div><div class='mt13'>ФИО директора:</div><div><input size='40'></div><div class='mt13'>Контактный телефон:</div><div><input size='40'></div><div class='mt13'><input type='button' value='Отправить'> <input type='button' value='Отмена'></div></div>");
			}
			
			$("#additional_info_form input:button:last").click(function(){ $("#additional_info_form").remove(); });
			
			$("#additional_info_form input:button:first").click(function(){
			
				$.post("/system/plugins/zakupki.php", {l:cur_lang, a:"acc_extend", name:$("#additional_info_form input:eq(1)").val(),adr:$("#additional_info_form input:eq(2)").val(),rnn:$("#additional_info_form input:eq(3)").val(),fio:$("#additional_info_form input:eq(4)").val(),cont:$("#additional_info_form input:eq(5)").val()},function(data){
					if ($(data).find("error").length) {alert($(data).find("error").text()); return false;}
					//alert('qz');
					$("#ofniresu span:last").text('ext');
					$("#additional_info_form").remove();
					document.location.href = dno.href;
				},"xml");
			
			
			});
			
			
			

			return false;
		}
		
	});
	
	


	
	
}





function get_c2_child(obj) { // находит элемент родословной ссылки который является ребенком с2
	x=0; enf = false;
	while (!enf) {
		x++; if (x>50) { enf = true; return false;}
		obj0 = obj;
		obj = $(obj).parent();
		if ($(obj).attr('id')=='c2') { enf = true; return $(obj0); }
	}	
}









function news_root_hover(){


	//$(".news_more").parent().addClass('news_more_cont').hover();
	
	
	$(".news_more").each(function(){
		
		if (!$(this).parent().hasClass("news_more_cont")) {
			$(this).parent().addClass("news_more_cont");
			$(this).parent().hover(function(){
				$(this).css({background:"url('/design/bgn.jpg') center",cursor:"pointer"});
				$(this).find(".news_more").css("textDecoration","underline");
			},function(){
				$(this).css({background:"none",cursor:"default"});
				$(this).find(".news_more").css("textDecoration","none");
			});
		}
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	


}












cpage = 2;

function comment_form_react() {
	
	
	if ($(".one_comment").length) { // если уже есть коменты, занчит это страница со всеми коментами, то генерируем рекацию
		$("#c_blog h2:eq(1)").text( $("#c_blog h2:eq(1)").text() + " (" + $(".one_comment").length + ")" );
		parse_comments_react();
	}
	
	
	// опказать форму
	$("#comments_links a:last").click(function(){
		

		$("#comments_links").after( $("#post_comment_form") );
		$("#post_comment_form input:eq(3)").val('0');

		comment_form_show();
		return false;


	});
	
	$("#comments_links a:first").click(function(){

		$("#comments_links").hide();
		$("#comments_links").before("<div style='margin-top: 40px;' class='tmp_al'><img src='/design/al.gif' /></div>");
		
		$.post("/system/plugins/blog.php",{l:cur_lang, a:"get_comments", id:$("#post_comment_form input:eq(2)").val(),p:cpage},function(data){
			//parse_comments(data);
			$(".tmp_al").remove();
			$("#comments_links").show();

			$("#comments_cont").append( $(data).find("html").text() );
			if ($(data).find("mp").text()=='false') {	$("#comments_links a:eq(0),#comments_links a:eq(1)").remove(); 	}
			parse_comments_react();
			cpage++;
		},"xml");
		return false;
	});
	
	
	
	
	// спрятать форму
	$("#post_comment_form input:button:last").click(function(){
		comment_form_hide();
	});
	
	
	$("#post_comment_form input:button:first").click(function(){
		
		$.post("/system/plugins/blog.php",{l:cur_lang, a:"post_comment",f1:$("#post_comment_form input:eq(0)").val(),f2:$("#post_comment_form input:eq(1)").val(),f3:$("#post_comment_form input:eq(2)").val(),f4:$("#post_comment_form textarea").val(),f5:$("#post_comment_form input:eq(3)").val(),f6:$("#c_blog h2:first").text()},function(data){
			
			if ($(data).find("error").length) { alert( $(data).find("error").text() );  return false; }
			comment_form_hide();
			alert( $(data).find("mess").text());
			
			
		},"xml");
	
	});
	
	
	
	
	if ($("#comments_links a:visible").length>2) {
		
		$("#comments_links").hide();
		$("#comments_links").before("<div style='margin-top: 40px;' class='tmp_al'><img src='/design/al.gif' /></div>");
		
		$.post("/system/plugins/blog.php",{l:cur_lang, a:"get_comments", id:$("#post_comment_form input:eq(2)").val(),p:"1"},function(data){
			$(".tmp_al").remove();
			$("#comments_links").show();
			$("#comments_cont").append( $(data).find("html").text() );
			$("#c_blog h2:eq(1)").text( $("#c_blog h2:eq(1)").text() + " (" + $(data).find("ttl").text() + ")" );
			parse_comments_react();
			$("#b1").width("100%");
		},"xml");
	}
	
	

/*
<a class='js_link comment_control_link' href='' style='color: green; right: 160px;'>утвердить</a>
<a class='js_link comment_control_link' href='' style='color: blue; right: 80px;'>ответить</a>
<a class='js_link comment_control_link' href='' style='color: red; right: 10px;'>удалить</a>
*/


	
	
	
}




function parse_comments_react() {


	$(".one_comment p .js_link").click(function(){
	//alert('qaz');
		$(this).parent().parent().find(".comment_podcut").show();
		$(this).parent().remove();
		return false;
	});

	if ($(".use_interface").length) {		
		
		$(".one_comment").removeClass("one_comment").addClass("one_comment2").each(function(){
			$(this).hover(function(){
				
				if ($(this).hasClass("tmp_comment")) {
					utv = "<a class='js_link ccl0' href='' style='color: green;'>утвердить</a>";
				} else {
					utv="<a class='js_link ccl4' href=''>спрятать</a>";
				}
				
				//$(this).append(utv+"<a class='js_link comment_control_link ccl1' href='' style='color: #107EA5; right: 80px;'>ответить</a><a class='js_link comment_control_link ccl2' href='' style='color: red; right: 10px;'>удалить</a>");
				$(this).append("<div class='comment_control_link'>" + utv + "<a class='js_link ccl3' href=''>изменить</a> <a class='js_link ccl1' href=''>ответить</a><a class='js_link ccl2' href='' style='color: red;'>удалить</a></div>");
				
			},function(){
				$(this).find(".comment_control_link").remove();
			});
		});
		
	}

}










$(".comment_control_link a").live("click",function(){

	if ($(this).hasClass("ccl2")) { // удаление
		di = $(this).parent().parent().attr("id");
		if (confirm("Удалить данное сообщение?")) {
			$.post("/system/plugins/blog.php",{l:cur_lang, a:"delete_comment",di:di},function(data){
				if ($(data).find("error").length) { alert( $(data).find("error").text() );  return false; }
					$("#"+di).slideUp();
			},"xml");
		}
	}


	if ($(this).hasClass("ccl0")) { // утверждение
		di = $(this).parent().parent().attr("id");
		if (confirm("Утвердить данное сообщение?")) {
			$.post("/system/plugins/blog.php",{l:cur_lang, a:"aprove_comment",di:di},function(data){
				if ($(data).find("error").length) { alert( $(data).find("error").text() );  return false; }
				$("#"+di).removeClass("tmp_comment");
			},"xml");
		}
	}


	if ($(this).hasClass("ccl4")) { // РАЗутверждение
		di = $(this).parent().parent().attr("id");
		if (confirm("Спрятать данное сообщение?")) {
			$.post("/system/plugins/blog.php",{l:cur_lang, a:"hide_comment",di:di},function(data){
				if ($(data).find("error").length) { alert( $(data).find("error").text() );  return false; }
				$("#"+di).addClass("tmp_comment");
			},"xml");
		}
	}



	if ($(this).hasClass("ccl1")) { // ответ
		di = $(this).parent().parent().attr("id");
		$(this).parent().after( $("#post_comment_form") );
		$("#post_comment_form input:eq(3)").val(di);
		comment_form_show();
	}



	if ($(this).hasClass("ccl3")) { // редактировать комент
		di = $(this).parent().parent().attr("id");
		$.post("/system/plugins/blog.php",{l:cur_lang, a:"get_raw_comment",di:di},function(data){
			if ($(data).find("error").length) { alert( $(data).find("error").text() );  return false; }
			$("#"+di+" p:visible").addClass("tmp_hidden_p").hide();
			$("#"+di).find(".blog_user").after("<div class='faq_edit_text'><textarea style='width:100%; height:400px; font-size:14px'></textarea><div><input type='button' value='ok'> <input type='button' value='отмена'></div></div>");
			$("#"+di+" textarea").val($(data).find("text").text());
		},"xml");
	}
	return false;
});






// редактирование комента - сохранить
$(".faq_edit_text input:first").live("click",function(){
	di = $(this).parent().parent().parent().attr("id");

	$.post("/system/plugins/blog.php",{l:cur_lang, a:"save_comment",di:di,mess:$(this).parent().parent().find("textarea").val()},function(data){
		if ($(data).find("error").length) { alert( $(data).find("error").text() );  return false; }
		//$("#"+di+" p").remove();
		$("#"+di+" p").add("#"+di+" textarea").add("#"+di+" input").remove();
		$("#"+di+" div:first").after($(data).find('mess').text());
		
		//$("#"+di).find(".blog_user").after("<div class='faq_edit_text'><textarea style='width:100%; height:400px; font-size:14px'></textarea><div><input type='button' value='ok'> <input type='button' value='отмена'></div></div>");
		//$("#"+di+" textarea").val($(data).find("text").text());
		//alert('saved');
	},"xml");

});

// редактирование комента - отмена
$(".faq_edit_text input:last").live("click",function(){
	$(this).parent().parent().parent().find(".tmp_hidden_p").show();
	$(this).parent().parent().remove();
});








function set_logined(p) {
	logined = p;
	if ($("#comments_links a:last").hasClass("blog_user_gray")) {
		comment_form_show();
	}
}







function comment_form_show() {
	if (logined) {
		$("#post_comment_form input:eq(1)").parent().hide();
		$("#post_comment_form input:eq(1)").parent().prev().hide();
		$("#post_comment_form input:eq(0)")[0].disabled = true;
		$("#post_comment_form input:eq(0)").val( $("#part a:first").text() );
	} else {
		$("#post_comment_form input:eq(1)").parent().show();
		$("#post_comment_form input:eq(1)").parent().prev().show();
		$("#post_comment_form input:eq(0)")[0].disabled = false;
		$("#post_comment_form input:eq(0)").val("");
	}
	$("#comments_links a:last").addClass("blog_user_gray");
	$("#post_comment_form").show();
}


function comment_form_hide() {
	$("#comments_links a:last").removeClass("blog_user_gray");
	$("#post_comment_form").hide();
}










var logined = false;
function user_form_react() {
	
	
	$(".regform1 a:first").click(function(){
		$(".regform1 .blackbold").removeClass("blackbold");
		$(this).addClass("blackbold");
		$(".register_form, .reset_form").hide();
		$(".login_form").show();
		if (ie6) { $("#b1").width("50%"); }
		return false;
	});


	$(".regform1 a:last").click(function(){
		$(".regform1 .blackbold").removeClass("blackbold");
		$(this).addClass("blackbold");
		$(".login_form, .reset_form").hide();
		$(".register_form").show();
		if (ie6) { $("#b1").width("50%"); }
		return false;
	});

	$(".login_form a").click(function(){
		$(".regform1 .blackbold").removeClass("blackbold");
		$(".login_form, .register_form").hide();
		$(".reset_form").show();
		if (ie6) { $("#b1").width("50%"); }
		return false;
	});
	
	$(".register_form input:button:last, .login_form input:button:last, .reset_form input:button:last").click(function(){
		$(".regform1 .blackbold").removeClass("blackbold");
		$(".login_form, .reset_form, .register_form").hide();
		if (ie6) { $("#b1").width("50%"); }
	});
	
	
	// изначальная остановка пользователя
	if ($("#part").length) {
		if ($(".nouserindex").length==0) {
			tmp = $("#ofniresu").attr("class");
			ui = tmp.substr(9,(tmp.length-9));
			$("#part a:first").removeClass("blog_user_gray").text($("#ofniresu span:first").text()).attr("href","/user/id"+ui+'/');
			$(".regform1").hide();
			$(".regform2").show();
			$(".regform2 a:last").attr("href","/user/id"+ui+'/');
			
			if (ie6) { $("#b1").width("50%"); }
			set_logined(true);
		}
		
	}


	// регистрация юзера
	$(".register_form input:button:first").click(function(){
		
		$(".register_form").hide();
		$(".register_form").before("<div style='margin-top:15px;' class='tmpal'><img src='/design/al.gif' /></div>");
		$.post("/system/plugins/pp.php",{l:cur_lang, a:"register_user", username:$(".register_form input:eq(0)").val(),useremail:$(".register_form input:eq(1)").val(),userpass1:$(".register_form input:eq(2)").val(),userpass2:$(".register_form input:eq(3)").val()},function(data){
		
			$(".tmpal").remove();
			if ($(data).find("error").length) { $(".register_form").show(); if (ie6) { $("#b1").width("50%"); } alert( $(data).find("error").text() );  return false; }

			//$("#part a:first").removeClass("blog_user_gray").text($(data).find("n").text()).attr("href","/user/id"+$(data).find("i").text()+'/');
			//$(".regform1").hide();
			//$(".regform2").show();
			
			alert( $(data).find("mess").text() );
			
			
			
		},"xml")
		
		//alert( $(".register_form input:eq(0)").val() );
		
		
	});
	
	
	// логаут
	$(".regform2 a:first").click(function(){
		
		$(".regform2").hide();

		$(".register_form").before("<div style='margin-top:15px;' class='tmpal'><img src='/design/al.gif' /></div>");
		$.post("/system/plugins/pp.php",{l:cur_lang, a:"logoutuser"},function(data){
		
			$(".tmpal").remove();
			
			if ($(data).find("error").length) { $(".regform2").show(); alert( $(data).find("error").text() ); return false; }
			
			$(".regform1 .blackbold").removeClass("blackbold");
			
			$(".regform1").show();
			$(".regform2").hide();
			$("#part a:first").addClass("blog_user_gray").text( $(data).find("mess").text() ).attr("href","/");
			$(".regform2 a:last").attr("href","/user/id"+ui+'/');
			set_logined(false);
			if (ie6) { $("#b1").width("50%"); }
			
		},"xml")
		
		return false;
	
	});





	// логин юзера
	$(".login_form input:button:first").click(function(){
		
		$(".login_form").hide();
		$(".login_form").before("<div style='margin-top:15px;' class='tmpal'><img src='/design/al.gif' /></div>");
		$.post("/system/plugins/pp.php",{l:cur_lang, a:"login_user", useremail:$(".login_form input:eq(0)").val(),userpass:$(".login_form input:eq(1)").val()},function(data){
		
			$(".tmpal").remove();
			
			if ($(data).find("error").length) { $(".login_form").show(); if (ie6) { $("#b1").width("50%"); alert( $(data).find("error").text() );  }  return false; }
			
			$(".regform1").show();

			$("#part a:first").removeClass("blog_user_gray").text($(data).find("n").text()).attr("href","/user/id"+$(data).find("i").text()+'/');
			
			// указываем расширенный ли аккаунт
			$("#ofniresu span:first").text($(data).find("n").text());
			$("#ofniresu span:last").text($(data).find("ext").text());
			
			$(".regform1").hide();
			$(".regform2").show();
			$(".regform2 a:last").attr("href","/user/id"+$(data).find("i").text()+'/');
			
			set_logined(true);
			if (ie6) { $("#b1").width("50%"); }
			
			
		},"xml")
		
		//alert( $(".register_form input:eq(0)").val() );
		
		
	});








	// сброс пароля юзера
	$(".reset_form input:button:first").click(function(){
		
		$(".reset_form").hide();
		$(".reset_form").before("<div style='margin-top:15px;' class='tmpal'><img src='/design/al.gif' /></div>");
		$.post("/system/plugins/pp.php",{l:cur_lang, a:"reset_user_password", useremail:$(".reset_form input:eq(0)").val()},function(data){
		
			$(".tmpal").remove();
			if ($(data).find("error").length) { $(".reset_form").show(); alert( $(data).find("error").text() );  return false; }

			//$("#part a:first").removeClass("blog_user_gray").text($(data).find("n").text()).attr("href","/user/id"+$(data).find("i").text()+'/');
			//$(".regform1").hide();
			//$(".regform2").show();
			
			alert( $(data).find("mess").text() );
		},"xml")
		
		//alert( $(".register_form input:eq(0)").val() );
		
	});
	
	
	// непосредственно сброс
	$("#reset_password_inputs input:button").click(function(){
	
		$.post("/system/plugins/pp.php",{l:cur_lang, a:"reset_user_password2", userpass1:$("#reset_password_inputs input:eq(0)").val(), userpass2:$("#reset_password_inputs input:eq(1)").val(), code:$("#reset_password_inputs input:eq(2)").val()},function(data){
		
			if ($(data).find("error").length) { $(".reset_form").show(); alert( $(data).find("error").text() );  return false; }
			alert( $(data).find("mess").text() );
			
		},"xml")
	
	});
	
	




	
}









function opros() {
	
	
	$(".opr a").click(function(){
		
		if ($(this).attr("id")=="opsel") {
			$(this).attr("id","");
			$("#opros_send").hide();
			return false;
		}
		
		$("#opsel").attr("id","");
		$(this).attr("id","opsel");
		$("#opros_send").show();
		
		return false;
	});
	
	$("#opros_send").click(function(){
		this.disabled = true;

		$.post("/system/plugins/votes.php",{l:cur_lang, a:"send_vote",n:"1",v:$(".opr a").index($("#opsel"))},function(data){
			//if ($(data).find("error").length>0)  { alert($(data).find("error").text()); return; }
			$("#opros_send")[0].disabled = false;
			$("#opros_send").hide();
			$("#opsel").attr("id","");
			
			alert($(data).find("mess").text());
		},"xml");

	});
	
	
}














var servertime = new Date();
var localtime = new Date();


function settime() {
	tmp = $("#hltm").attr("class");
	tmp2 = tmp.split("_");
	
	servertime.setTime(parseInt(tmp2[1])+21600000);
	updatetime();
}



function updatetime() {
	var newtime = new Date();
	//razn = newtime.getTime() - localtime.getTime();
	//alert('razn '+newtime.getTime() - localtime.getTime());
	//console.log(newtime.getTime() - localtime.getTime());
	newtime.setTime(servertime.getTime() + (newtime.getTime() - localtime.getTime()));
	
	$("#hltm div").html(newtime.getUTCHours() + '<strong>:</strong>'+ addnull(newtime.getUTCMinutes()))
	$("#hltm").toggleClass("dvoeto");
	tmr_t = setTimeout(updatetime,500);

	
	//alert(newtime.getHours() + ':'+ newtime.getMinutes());
}


function addnull(p) { p2 = parseInt(p,10); if (p2<10) return '0'+p; else return p; }






function mark_main_menu() {
	tmp = document.location.href; tmp2 = tmp.split('/');
	if (tmp2.length>5) {
		
		if (tmp2[4]=='company') { $("#hmenu1 a:eq(1)").attr("id","msel"); }
		if (tmp2[4]=='hr') { $("#hmenu1 a:eq(2)").attr("id","msel"); }
		if (tmp2[4]=='map') { $("#hmenu1 a:eq(3)").attr("id","msel"); }
		if (tmp2[4]=='press_center') { $("#hmenu1 a:eq(4)").attr("id","msel"); }
		if (tmp2[4]=='for_partners') { $("#hmenu1 a:eq(5)").attr("id","msel"); }
		if (tmp2[4]=='zakupki') { $("#hmenu1 a:eq(6)").attr("id","msel"); }
		if (tmp2[4]=='blog') { $("#hmenu1 a:eq(7)").attr("id","msel"); }
		
		if (tmp2[4]=='blog') {
			if (tmp2[5]=='post_16')  { $("#blog_menu li:eq(0)").attr("id","mselb"); }
			if (tmp2[5]=='post_222') { $("#blog_menu li:eq(1)").attr("id","mselb"); }
			if (tmp2[5]=='post_223') { $("#blog_menu li:eq(2)").attr("id","mselb"); }
			if (tmp2[5]=='post_224') { $("#blog_menu li:eq(3)").attr("id","mselb"); }
			if (tmp2[5]=='post_15')  { $("#blog_menu li:eq(4)").attr("id","mselb"); }
			
			
		}
		
		
	}
	
	if ($("#msel").length>0) {
		x = $("#msel").parent().width();
		$("#msel").parent().append("<div id='msel_div'><div id='msel1'></div><div id='msel2'></div><div id='msel3'></div></div>");
		$("#msel_div").width(x+34+"px");
		$("#msel2").width(x+24+"px");
		$("#msel3").css("left",(x+29)+"px");
		
		$("#msel_div").click(function(){
			document.location.href = $(this).parent().find("a").attr("href");
		});
		
	}
	
	
}









function dd(i){
	
	$("#do4ki a:eq("+i+")").attr('id','do4kisel');
	$("#do4ki_logos a:eq("+i+")").find("span").stop().fadeTo(200,0);
	
}


function dd2(i) {
	
	$("#do4kisel").attr('id','');
	$("#do4ki_logos a:eq("+i+")").find("span").stop().fadeTo(500,1);


	
}



$(window).load(function(){
	
	fixbg();
	$(document).pngFix();
});

$(window).resize(function(){
	fixbg();
	
	fix_cities_pos();
	
	$(document).pngFix();
	
});


function fixbg(){
	
	//$("#mseli").css("opacity","0.5");

	if ($("#rzd").length>0) {
		ro  = $("#rzd").offset(); x = ro.top-383; $("#b1").css("backgroundPosition","center "+x+"px");
		tmp = getClientWidth();
		if (tmp<1075) {
			tmp2 = Math.ceil((1075-tmp)/2);
			if (tmp2<37) { $("#rzdf").css({margin:"",marginLeft:"-"+tmp2+"px"}); }
		} else {
			$("#rzdf").css({margin:"0 auto"});
		}
	}

	if (ie6) {
		tmp = getClientWidth();
		if (tmp < 1000) {$("#b1").css("width","1000px");}
		else if (tmp>1400) {$("#b1").css("width","1400px");}
		else { $("#b1").css("width","100%"); }
	}

	
	if ($("#rzd2").length>0) {
		ro  = $("#rzd2").offset(); x = ro.top-450; $("#b1").css("backgroundPosition","center "+x+"px");
	}
	
	if ($("#c2").length>0) {
		
		pos={top:100}; popr = 0;
		// ищем первый li p или table чтобы по ним выровнять меню
		$("#c2").children().each(function(){
			tag = this.tagName; tag = tag.toLowerCase();
			if (tag == 'p' || tag == 'ul' || tag == 'table') {
				pos = $(this).position();
				return false;
			}
		});

	
		// смотрим не начинается ли меню с заголовка h2, чтобы сделать на него поправку
		if ($("#m").find("*:first").length) {
			firsttag = $("#m").find("*:first")[0].tagName;
			if (firsttag.toLowerCase() == 'h2') { popr=-70; }
		}
		
		pos2 = pos.top+popr;
		if (pos2>220) {pos2 = 100;}
		
		$("#m").css({marginTop:pos2+"px"});
		


	}
	

}










































function getClientWidth() { return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth; }
function getClientHeight() { return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight; }

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) 
      break;
  }
  return null;
}


function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function DeleteCookie(name) {
  var exp = new Date();
  FixCookieDate (exp); 
  exp.setTime (exp.getTime() - 1);  
  var cval = GetCookie (name);
  if (cval != null)
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


