var over_mainarea = 1;

function gourl(utype, uid, unum) {
  $.get('/getStat.php',{ 'FID': fid,'TYPE': utype,'ID': uid,'NUM': unum });
}
function branding(url){alert('click '+over_mainarea);if(!over_mainarea){location.href=url;}}
var isIE = (navigator.appName == "Microsoft Internet Explorer");
var inline = 'table-row';
if (isIE) {
	inline = 'inline';
	if(document.documentMode==5){alert('Пожалуйста отключите режим совместимости!\r\nВ противном случаем страница будет отображаться некорректно!');}
}
function sh_contact(mcid) {
	document.getElementById('contact').style.display = 'block';
	document.getElementById('cont').innerHTML = mcid;
}
function hotkeys(e) {
  var d;
  if (!e) e = window.event;
  var k = e.keyCode;
  if (k == 27) {
		$('#err').hide();
		$('#femail').hide();
		$('#msg').hide();
		$('#contact').hide();
		$('#myall').hide();
		$('#myallcopy').hide();
		$('#mask').hide();
		$('#mask1').hide();
		$('#wlogin').hide();
		$('#poll_div').hide();
		$('.allresp').hide();
		$('.hidebyesc').hide();
		if($('#floatBox').css('display')=='block') { hideBox('#floatBox'); }
		if($('#region_select').css('display')!='none'){$('#region_select').fadeOut('fast');}
		if(sendErr.display){ sendErr.closeBox(); }

  } // Esc?
  if (e.ctrlKey) {
    if (k == 37) { d = document.getElementById('prev_page'); } // Ctrl+Left
    if (k == 39) { d = document.getElementById('next_page'); } // Ctrl+Right
    if (k == 13) { sendErr.openErrorMsg(0,0,''); return false;  } // Ctrl+Enter
  }
  if (d) location.href = d.href;
}

function closeFloatDiv()
	{
	if($('#regionsearch').css('display')!='none'){$('#regionsearch').fadeOut('fast');}
	if($('#floatBox').css('display')=='block') { hideBox('#floatBox'); }
	if(sendErr.display){ sendErr.closeBox(); }
	}

//usage w/ smoothscroll
$(document).ready(function() {
/* ---- Top Scroll BEGIN ---- */
//plugin
jQuery.fn.topLink = function(settings) {
  settings = jQuery.extend({
    min: 1,
    fadeSpeed: 200
  }, settings);
  return this.each(function() {
    //listen for scroll
    var el = $(this);
    el.hide(); //in case the user forgot
    $(window).scroll(function() {
      if($(window).scrollTop() >= settings.min)
      {
        el.fadeIn(settings.fadeSpeed);
      }
      else
      {
        el.fadeOut(settings.fadeSpeed);
      }
    });
  });
};
  //set the link
  $('#top-scroll').topLink({
    min: 400,
    fadeSpeed: 600
  });
  //smoothscroll
  $('#top-scroll').click(function(e) {
    e.preventDefault();
    $.scrollTo(0,300);
  });
});

function supports_input_placeholder(){
	var i = document.createElement('input');
	return 'placeholder' in i;
}

/* ---- Top Scroll END ---- */

$(document).ready(function(){
$('body').click(function(e){
	if (e.target) {targ = e.target;} else {if (e.srcElement) {targ = e.srcElement;}};
	if(targ.tagName!="A" && targ.tagName!="INPUT" && targ.tagName!="TEXTAREA" && targ.tagName!="SELECT" && targ.tagName!="BUTTON") {
	var url=$('#branding_link').val();
	$('.globmenu').fadeOut('fast');
	if(!over_mainarea && url) {window.open(url,"_blank","");}
	}
});
var i = document.location.hash;

switch(i)
	{
	case '#reg':openFloatBox('reg');  break;
	case '#rec':openFloatBox('rec');  break;
	case '#log':openFloatBox('log');  break;
	case '#plog':openFloatBox('plog');  break;
	case '#pass':openFloatBox('pass');  break;
	case '#activ':openFloatBox('activ');  break;
	case '#openstat':showStatistic('rubr',0,parentID,fid); break;
	case '#msg':openFloatBox('msg');  break;
	default: break;
	}

$(document).bind('keydown',function(event){hotkeys(event);});
/* ------ $(document).ready BEGIN ------ */
$('#about_header a').click(function(e){
	$('#about_header a').removeClass('sel');
	$(this).addClass('sel');
	$('#aboutus article').hide();
	$($(this).attr('rel')).fadeIn('fast');
});
$('#press_header a').click(function(e){
	$('#press_header a').removeClass('sel');
	$(this).addClass('sel');
	$('#pressbox .article').hide();
	$($(this).attr('rel')).fadeIn('fast');
});
$('.nBox header a').click(function(e){
	$('.nBox header a').removeClass('sel');
	$(this).addClass('sel');
	$('.nBox .article').hide();
	$($(this).attr('rel')).fadeIn('fast');
});

if(!supports_input_placeholder()) {  }
$('input, textarea').each(function(){if($(this).attr('placeholder')!=''){if($(this).attr('placeholder')==$.trim($(this).val())){$(this).css({color: '#a4a4a4'});}else{$(this).css({color: 'black'});}}});
$('input, textarea').bind('focus',function(){if($(this).attr('placeholder')!=''){if($(this).attr('placeholder')==$.trim($(this).val())){$(this).val('')}$(this).css({color: 'black'});}});
$('input, textarea').bind('blur',function(){if($(this).attr('placeholder')!=''){if($.trim($(this).val())==''){$(this).val($(this).attr('placeholder'));$(this).css({color: '#a4a4a4'});}}});

$('#mainarea,#toolbar,#top-scroll,footer').bind('mouseenter',function(){over_mainarea=1;});
$('#mainarea,#toolbar,#top-scroll,footer').bind('mouseleave',function(){over_mainarea=0;});

/* ---- LOGIN FloatBox Reactions BEGIN ---- */
$('#formMask').click(function(){hideBox('#floatBox');});

$("#openRegForm").click(function(){openFloatBox('reg');});
$("#regMail").blur(function(e){mailCheck(this,'reg');});
$("recMail").blur(function(e){mailCheck(this,'rec');});
$("#regPass1,#passPass1,#regPass2,#passPass2,#logPass,#mlogPass,#plogPass").focus(function(){var val = $.trim($(this).val());if(val=='') {$(this).css({'background':'#ffffff','color':'#000000'});}});
$("#regPass1").blur(function(e){regFirstPassCheck(this,'reg');});
$("#regPass2").blur(function(e){regConfPassCheck('#regPass1','#regPass2','reg');});
$("#passPass1").blur(function(e){regFirstPassCheck(this,'pass');});
$("#passPass2").blur(function(e){regConfPassCheck('#passPass1','#passPass2','pass');});
$("#logPass").blur(function(e){regFirstPassCheck(this,'log');});

$('#logPass').css({'background':'url(/img/logform_input_pass.jpg) white no-repeat','color':'#000'});
$('#regPass1,#passPass1').css({'background':'url(/img/logform_input_pass1.jpg) white no-repeat','color':'#000'});
$('#regPass2,#passPass2').css({'background':'url(/img/logform_input_pass2.jpg) white no-repeat','color':'#000'});


$('#reg_captcha').keyup(function(e){if(e.keyCode==13){goReg();}});
$('#goReg').click(function(){goReg();});
$("#logMail").blur(function(e){var nImg = new Image();var email=$("#logMail").val();if(logMailCheck(email)){nImg.src = '/img/loginform_successicon.png';$('#s_logMail').html(' ');}else{nImg.src = '/img/loginform_wrongicon.png';$('#s_logMail').html('Электронная почта или ИНН введен неверно!');} $('#logMail_state').attr('src',nImg.src).css('display','block');});

$("#logPass").keyup(function(e){if(e.keyCode==13){goLog();}});
$('#goLog').click(function(){goLog();});

$("#recMail").blur(function(e){mailCheck(this,'rec');});
$("#openLogForm").click(function(){openFloatBox('log');});

$("#rec_captcha").keyup(function(e){if(e.keyCode==13){goRec();}});
$("#goRec").click(function(){goRec();});

$('#pass_captcha').keyup(function(e){if(e.keyCode==13){goPass();}});
$('#goPass').click(function(){goPass();});

$("#openPLogForm").click(function(){openFloatBox('plog');});
$("#plogMail").blur(function(e){var nImg = new Image();var email=$("#plogMail").val();if(logContractCheck(email)){nImg.src = '/img/loginform_successicon.png';$('#s_plogMail').html(' ');}else{nImg.src = '/img/loginform_wrongicon.png';$('#s_plogMail').html('Электронная почта или ИНН введен неверно!');} $('#plogMail_state').attr('src',nImg.src).css('display','block');});
$('#goPLog').click(function(){goPLog();});

$('#mlogMail').blur(function(){mailCheck(this,'mlog');});
$('#goMLog').click(function(){goMLog();});

$('#goOrg').click(function(){Org2MyAll.addorg($('#add_org_id').val(),$('#macWr').val(),$('#addCategory_i').val());});

$("#mlogPass").keyup(function(e){if(e.keyCode==13){goMLog();}});
$("#plogPass").keyup(function(e){if(e.keyCode==13){goPLog();}});

/* ---- LOGIN FloatBox Reactions END ---- */
$('#choose_region').click(function(){ if($('#regionsearch').css('display')=='none'){ closeFloatDiv(); $('#regionsearch').fadeIn('fast'); }else{ $('#regionsearch').fadeOut('fast'); } });
$('#regSearch').keyup(function(){
	var s=$.trim($(this).val()).toLowerCase();
	if(s.length>0)
		{
		$('#regionList a').each(function(){
			var n = ($(this).text()).toLowerCase();
			var m =  n.split(' ');
			var d = 0;
			for(var i in m) { if(m[i].indexOf(s)==0) { d=1;break; }  }
			$(this).parent('li').css('display',(d?'block':'none'));
			});
		}else{ $('#regionList li').css('display','block'); }
	});
$('#banner_promo').click(function(){ openFloatBox('poll'); });

$('#advfields, #advfields_l').click(function(){ var state=$('#advfields').attr('checked');$.cookie('advfields', state, { expires: 30 }); if(state) { $('.additional').slideDown('fast'); }else{ $('.additional').slideUp('fast'); } });


$('#org_results article').bind('mouseenter',function(){$(this).find('.moveLink').stop(true,true).fadeIn('fast');});
$('#org_results article').bind('mouseleave',function(){$(this).find('.moveLink').stop(true,true).fadeOut('fast');});

// More list func
$('ul.morelist').each(function(){
	var pp=10; // number of display <li> elements
	var mlc=0; // li tag counter
	var mlc_=0;
    $(this).attr('rel',pp);
	$(this).find('li').each(function(){
    	if((mlc%pp)==0){mlc_++;}
    	mlc++;
    	if($(this).hasClass('morelist_last'))
    		{
            $(this).attr('rel',1);
    		$(this).find('.morelist_down').css('display','block').attr('rel',1);
    		$(this).find('.morelist_up').css('display','none');
    		$(this).find('a.morelist_down').click(function(){
    			var p=$(this).parent('li').parent('ul'); // Parent block
    			var pc=eval($(this).attr('rel')+'+1');
    			var pc_=pc+1;
                if($(p).find('li[rel="'+pc_+'"]').attr('rel')==undefined)
	                {
                    $(p).find('.morelist_down').css('display','none');
    				$(p).find('.morelist_up').fadeIn('fast');
	    			}
    			$(p).find('li[rel="'+pc+'"]').slideDown();
    			$(this).attr('rel',pc);
    			});
    		$(this).find('a.morelist_up').click(function(){
    			var p=$(this).parent('li').parent('ul'); // Parent block
    			$(p).find('li[rel!="1"]').slideUp('fast');
    			$(p).find('.morelist_down').attr('rel',1);
				$(p).find('.morelist_up').css('display','none');
				$(p).find('.morelist_down').fadeIn();
    			});

    		}else{
    		$(this).attr('rel',mlc_);
    		if(mlc>pp) { $(this).css('display','none'); }
    		}
	});
	if(mlc<=pp) { $(this).find('li.morelist_last').css('display','none'); }
});
/* ---- $(document).ready END ----*/
});

/* -- NEW LOGIN BEGIN p2 -- */
function logMailCheck(s)
	{
	if(mailChecker(s) || logContractCheck(s)) { return true; }else{ return false; }
	}
function logContractCheck(s)
	{
	var reg = /^(\d{3}-\d{3,6}-\d{1,5})$/i;
	if(reg.test(s)) { return true; }else{ return false; }
	}
function openFloatBox(type)
	{
    closeFloatDiv();
	var box = '#floatBox';
	var title = 'Непонятное окошко';
	if(type!='log')
    	{
		var nImg = new Image();
		nImg.src = '/inc/captcha.php?'+(Math.random()*Math.pow(10,6).toFixed(0));
	    $('#captcha_'+type).attr('src',nImg.src).css('display','block');
	    }

    document.location.replace('#'+type);
    $(box).width('375px').css('position','fixed');
    switch (type)
    	{
    	case 'log': title = 'Вход в личный кабинет'; break;
    	case 'rec': title = 'Восстановление пароля'; break;
    	case 'reg': title = 'Форма регистрации'; break;
    	case 'pass': title = 'Установка нового пароля'; break;
    	case 'activ': title = 'Активация учетной записи'; break;
    	case 'mlog': title = 'Вход в Личный Кабинет'; break;
    	case 'plog': title = 'Вход в сервис "Подписка"'; break;
    	case 'mac': title = 'Добавить в Избранное'; break;
    	case 'poll': title = 'Опрос'; $(box).width('500px').css('position','absolute'); break;
    	case 'authtimeout': title = 'Внимание!'; break;
    	case 'msg': title = ''; break;
    	}
	//if(type == 'log') { title = 'Вход в личный кабинет'; }else if(type=='rec') { title = 'Восстановление пароля'; }else if(type=='reg') { title = 'Форма регистрации'; }else if(type=='pass') { title = 'Установка нового пароля'; }else if(type=='activ') { title = 'Активация учетной записи'; }else if(type=='mlog') { title = 'Вход в Личный Кабинет'; }else if(type=='mac') { title = 'Сохрание компании'; }
	$('#floatBox .title').text(title);
	$(box).removeClass();
	$(box).addClass(type+'Box');
	$(box+' .fDiv').css('display','none');
	$(box+' #'+type+'Layer').css('display','block');

    var winH = $(window).height();
	var winW = $(window).width();
	if($(box).css('display')!="block")
		{
		$('#formMask').css('opacity','0.25');
		$('#formMask').fadeIn('fast');
		$(box).css({left: winW/2-$(box).width()/2, top: eval("-"+$(box).height()),display:"block"});
		$(box).animate({ top: (type=='poll'?'50':winH/2-$(box).height()/2), opacity: '1' }, "fast");
		}else{ $(box).animate({ top: winH/2-$(box).height()/2, opacity: '1' }, "fast"); }
	}

function hideBox(box)
	{
	$('#formMask').fadeOut('fast');
	$(box).animate({ top: '-'+$(box).height(),opacity: '0' }, "fast").css('display','none');
	document.location.replace('#');
	}
function mailChecker(mail)
	{
	var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
	if(reg.test(mail)) { return true; }else{ return false; }
	}
function mailCheck(obj,type)
	{
	var val = $(obj).val();
	if(val!='' && val!=$(obj).attr('default'))
		{
		if(mailChecker(val))
			{
			//alert('val: '+val+' - '+type);
			$.getJSON("/xp_ajax_client.php?section=checkmail",
			{ mail: val, type: type },
			function(data){
				var nImg = new Image();
				if(type=='reg')
				{
				if(data.code == '1')
			  		{
					nImg.src = '/img/loginform_successicon.png';
					$('#s_'+type+'Mail').html(' ');
					}else{
					$('#s_'+type+'Mail').html(data.msg);
					nImg.src = '/img/loginform_wrongicon.png';
					}
				}else{
					var nImg = new Image();
					if(data.code == '0')
				  		{
						nImg.src = '/img/loginform_successicon.png';
						$('#s_'+type+'Mail').html(' ');
						}else{
						$('#s_'+type+'Mail').html(data.msg);
						nImg.src = '/img/loginform_wrongicon.png';
						}
					}
            $('#'+type+'Mail_state').attr('src',nImg.src).css('display','block');
			});
		    $('#s'+type+'Mail').html(''); //$('#goReg').fadeIn();
		    return true;
			}else{
			var nImg = new Image();
			nImg.src = '/img/loginform_wrongicon.png';
		    $('#'+type+'Mail_state').attr('src',nImg.src).css('display','block');
		    $('#s_'+type+'Mail').html('E-Mail введён неверно!');
		    $('#'+type+'Mail').focus();//$('#goReg').fadeOut();
		    return false;
			}
 		}
	}
function regFirstPassCheck(obj,type)
	{
	var val=$.trim($(obj).val());
	var nImg = new Image();
	nImg.src = '/img/loginform_wrongicon.png';
	if(val=='')
		{
		if(type=='log')
			{
			$(obj).css('background','url(/img/logform_input_pass.jpg) white no-repeat');
			}else{ $(obj).css('background','url(/img/logform_input_pass1.jpg) white no-repeat'); }
		}else{
		if(val.length<6)
			{
			$(obj).focus();
			$('#s_'+type+'Pass1').html('Пароль должен быть больше 6-ти символов');
			}else if(val.length>20){
				$(obj).focus();
				$('#s_'+type+'Pass1').html('Пароль должен быть меньше 20-ти символов');
				}else{
					nImg.src = '/img/loginform_successicon.png';
		    		$('#s_'+type+'Pass1').html(' ');
		    		$('#'+type+'Pass1_state').attr('src',nImg.src).css('display','block');
		    		return true;
		    		}
		}
	$('#'+type+'Pass1_state').attr('src',nImg.src).css('display','block');
	return false;
	}
function regConfPassCheck(firstObj,confObj,type)
	{
	var nImg = new Image();
	nImg.src = '/img/loginform_wrongicon.png';
	if($(confObj).val()=='')
		{
		$('#'+type+'Pass2').css('background','url(/img/logform_input_pass2.jpg) white no-repeat');
		//$('#s_'+type+'Pass2').html('Введенные пароли не совпадают!');
		}else{
		if($(firstObj).val()==$(confObj).val())
			{
			nImg.src = '/img/loginform_successicon.png';
			$('#s_'+type+'Pass2').html(' ');
			$('#'+type+'Pass2_state').attr('src',nImg.src).css('display','block');
			return true;
			}else{
            $('#s_'+type+'Pass2').html('Введенные пароли не совпадают!');
			}
		}
	$('#'+type+'Pass2_state').attr('src',nImg.src).css('display','block');
	return false;
	}
function authTimeout(sec)
	{
	sec--;
	if($('#floatBox').css('display')=='none'){ return false; }
	if(sec>0)
		{
        a_min = parseInt(sec/60);
        a_sec = sec-(a_min*60);
        var out_str = '';
        if(a_min) out_str+=a_min+' мин.';
        out_str=out_str+' '+a_sec+' сек. ';
        $('#authtimeout').html(out_str);
        setTimeout('authTimeout('+sec+')',1000);
			}else{
			var i = document.location.hash;
			switch(i)
				{
				case '#log':openFloatBox('log');  break;
				case '#plog':openFloatBox('plog');  break;
                case '#mlog':openFloatBox('mlog');  break;
				default: break;
				}
			}
	}
function goLog()
	{
	var email = $("#logMail").val();
	var pass = $("#logPass").val();
	var rememb=$("#logRemember").attr('checked');
	if(logMailCheck(email))
		{
		if(pass==''){$('#s_logPass').text('Введите пароль!');return false;}else if(pass.length<6){$('#s_logPass').text('Пароль должен быть не менее 6 символов!');return false;}else if(pass.length>20){$('#s_logPass').text('Пароль должен быть не более 20 символов!');return false;}else{ $('#s_logPass').text(''); }
		$.getJSON("/xp_ajax_client.php?section=login",
		 { mail: email, pass: pass, rememb: rememb },
		  function(data){
		  if(data.code == '1')
		  	{
	    	$("#logLayer").slideUp();
	    	$("#msgDone").html(data.msg);
	    	var u_name='';
	    	if(data.m_name!='') { u_name='('+data.m_name+') '; }
	    	var html=u_name+'<a class="lk" href="/clients" >Личный кабинет</a>   &nbsp; <span style="color:#999;">|</span> &nbsp;  <a class="lk" href="xp_exit.php">Выйти</a>';
	    	$("#right_top_link").html(html);
	    	document.location.replace('#');
	    	$.cookie('lastlog', $('#logMail').val(), { expires: 30 });
            if($('#logRemember').attr('checked'))
	            {
				$.cookie('lk_logn', data.mail, { expires: 30 });
	            $.cookie('lk_pass', data.pass, { expires: 30 });
			  		}else{
			  		//document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=" + path + "; domain=" + domain;
			  		$.cookie('lk_logn', ' ',{ expires: 0 });
			  	    $.cookie('lk_pass', ' ', { expires: 0 });
			  	    }
		  	}else if(data.code == '2')
		  		{
	            $("#s_logMail").html(data.msg);
		  		}else if(data.code == '4')
		  			{
					$('#authtimeoutLayer').html(data.msg);
					authTimeout(data.timeout);
					openFloatBox('authtimeout');
		  			}else if(data.code == '5')
		  				{
						document.location.replace('#');
						hideBox('#floatBox');
			  			}
		  });
	 	}else{
	 		var nImg = new Image();
			nImg.src = '/img/loginform_wrongicon.png';
		    $('#lMail_state').attr('src',nImg.src).css('display','block');
		    $('#s_logMail').html('Электронная почта или ИНН введен неверно!');
		    $("#logMail").focus();
	 	}
	}

function goMLog()
	{
	var email = $("#mlogMail").val();
	var pass = $("#mlogPass").val();
	//alert(email);
	if(mailChecker(email))
		{
		//alert('Проверка мыла прошла!');
		if(pass==''){$('#s_mlogPass').text('Введите пароль!');return false;}else if(pass.length<6){$('#s_mlogPass').text('Пароль должен быть не менее 6 символов!');return false;}else if(pass.length>20){$('#s_mlogPass').text('Пароль должен быть не более 20 символов!');return false;}else{ $('#s_mlogPass').text(''); }
		//alert('Проверка пароля прошла!\n Отправляем запрос ...');
		$.getJSON("/xp_ajax_client.php?section=favlogin",
		 { mail: email, pass: pass },
		  function(data){
		  if(data.code == '1')
		  	{
	    	//$("#mlogLayer").slideUp();
	    	//$("#msgDone").html(data.msg);
	    	document.location.reload();
		  	}else if(data.code == '2')
		  		{
	            $("#s_mlogMail").html(data.msg);
		  		}else if(data.code == '4')
		  			{
					$('#authtimeoutLayer').html(data.msg);
					authTimeout(data.timeout);
					openFloatBox('authtimeout');
					}else if(data.code == '5')
			  			{
						document.location.replace('#');
						hideBox('#floatBox');
			  			}
		  });
		}else{
			var nImg = new Image();
			nImg.src = '/img/loginform_wrongicon.png';
		    $('#mlogMail_state').attr('src',nImg.src).css('display','block');
		    $('#s_mlogMail').html('Электронная почта введена неверно!');
		    $("#mlogMail").focus();
		}
	}

function goPLog()
	{
	var email = $("#plogMail").val();
	var pass = $("#plogPass").val();
	if(logContractCheck(email))
		{
		if(pass==''){$('#s_plogPass').text('Введите пароль!');return false;}else if(pass.length<6){$('#s_plogPass').text('Пароль должен быть не менее 6 символов!');return false;}else if(pass.length>20){$('#s_plogPass').text('Пароль должен быть не более 20 символов!');return false;}else{ $('#s_plogPass').text(''); }
		$.getJSON("/xp_ajax_client.php?section=login",
		 { mail: email, pass: pass },
		  function(data){
		  if(data.code == '1')
		  	{
	    	document.location.reload();
		  	}else if(data.code == '2')
		  		{
	            $("#s_plogMail").html(data.msg);
		  		}else if(data.code == '4')
		  			{
					$('#authtimeoutLayer').html(data.msg);
					authTimeout(data.timeout);
					openFloatBox('authtimeout');
					}else if(data.code == '5')
			  			{
						document.location.replace('#');
						hideBox('#floatBox');
			  			}
		  });
		}else{
			var nImg = new Image();
			nImg.src = '/img/loginform_wrongicon.png';
		    $('#plogMail_state').attr('src',nImg.src).css('display','block');
		    $('#s_plogMail').html('Номер договора введен неверно!');
		    $("#plogMail").focus();
		}
	}

function goRec()
	{
	var capcha=$("#rec_captcha").val();
	var email=$("#recMail").val();
	if(mailCheck('#recMail','rec'))
		{
        if(capcha==""||capcha.length!=5) { $("#s_recCaptcha").html("введите защитный код"); return false; }else{ $("#s_recCaptcha").html(' '); }

        $.getJSON("/xp_ajax_client.php?section=recovery",
		 { mail: email, capcha: capcha },
		  function(data){
		  if(data.code == '1')
		  	{
	    	$('#msgDone').html(data.msg);
	    	$('#recLayer').slideUp();
	    	document.location.replace('#');
		  	}else if(data.code == '2')
		  		{
		  		$("#s_recMail").html(data.msg);
		  		$('#msgDone').html(' ');
		  		}
		  });

		}else{ $("#msgRec").html("Почта введена неверно!").fadeIn("fast"); }
	}
function goPass()
	{
	var capcha=$("#pass_captcha").val();
	var uid = $("#recovery_id").val();
	var pass = $('#passPass1').val();
	if(regFirstPassCheck('#passPass1','pass') && regConfPassCheck('#passPass1','#passPass2','pass'))
		{
		if(capcha==""||capcha.length!=5) { $("#s_passCaptcha").html("введите защитный код"); return false; }else{ $("#s_passCaptcha").html(' '); }
		$.getJSON("/xp_ajax_client.php?section=passchange",
		 { pass: pass, capcha: capcha, uid: uid },
		  function(data){
		  if(data.code == '1')
		  	{
	    	$('#msgDone').html(data.msg);
	    	document.location.replace('#');
	    	$('#passLayer').slideUp();
		  	}else if(data.code == '2')
		  		{
		  		$("#s_passCaptcha").html(data.msg);
		  		$('#msgDone').html(' ');
		  		}
		  });
		}
	}
function goReg()
	{
	if(mailCheck('#regMail','reg') && regFirstPassCheck("#regPass1",'reg') && regConfPassCheck("#regPass1","#regPass2",'reg'))
		{
        var email=$("#regMail").val();
		var pass=$("#regPass1").val();
		var captcha = $("#reg_captcha").val();
		$.getJSON("/xp_ajax_client.php?section=reg",
		 { mail: email, pass: pass, capcha: captcha },
		  function(data){
		  if(data.code == '1')
		  	{
	    	$("#regLayer").slideUp();
	    	$("#msgDone").html(data.msg);
	    	document.location.replace('#');
		  	}else if(data.code == '2')
		  		{
	            $("#msgDone").html(data.msg);
		  		}
		  });
		}
	}
function sendActivate(mail)
	{
	$.getJSON("/xp_ajax_client.php?section=sendactive",
		 { mail: mail },
		  function(data){
		  if(data.code == '1')
		  	{
	    	$("#recLayer").slideToggle();
	    	$("#msgDone").html(data.msg);
	    	document.location.replace('#');
		  	}else if(data.code == '2')
		  		{
	            $("#msgDone").html(data.msg);
		  		}
		  });
	}
function reCaptcha(imgObj)
	{
	var nImg = new Image();
	nImg.src = '/inc/captcha.php?'+(Math.random()*Math.pow(10,6)).toFixed(0);
    $(imgObj).attr('src',nImg.src);
	}
function loginReport(id)
	{
	$.getJSON("/xp_ajax_client.php?section=support&do=contract_login",
		 { id: id },
		  function(data){
		  if(data.code == '1')
		  	{
	    	$("#logLayer,#mlogLayer,#plogLayer").slideUp();
	    	$("#msgDone").html(data.msg);
	    	document.location.replace('#');
		  	}else if(data.code == '2')
		  		{
	            $("#msgDone").html(data.msg);
		  		}
		  });
	}
/* -- NEW LOGIN END p2 -- */

function regionPage(p)
	{
	$('.regionspage').hide();
	$('#rpage'+p).fadeIn('fast');
	}
/* -- Rubricator BEGIN -- */
var rubr = {
	display_section: 0,
	display_subsection: 0,
	show: function(type)
		{

			if(type=='tem')
				{
				if($('#temrubrikator').css('display')=='none')
					{
					$('#temrubrikator').slideToggle();
					}
				$('#rubr_link_alf').removeClass('sel');
				$('#rubr_link_tem').addClass('sel');
				$('#rubr_alf').fadeOut('fast');
				}
			if(type=='alf')
				{
				if($('#temrubrikator').css('display')!='none')
					{
					$('#temrubrikator').slideToggle();
					}
				$('#rubr_link_tem').removeClass('sel');
				$('#rubr_link_alf').addClass('sel');
				$('#rubr_alf').fadeIn('fast');
				}

		},
	section: function(tid)
		{
        if(this.display_subsection)
        	{
        	$('#category'+this.display_subsection).slideUp();
        	$('#subsection_l'+this.display_subsection).removeClass('selected');
        	this.display_subsection=0;
        	}
		if(this.display_section)
			{
			$('#section_l'+this.display_section).removeClass('selected');
			$('#subsection'+this.display_section).css('display','none');
			$('#subsection'+tid).fadeIn('fast');
			}else{ $('#subsection'+tid).slideDown(); }
		$('#section_l'+tid).addClass('selected');
		this.display_section=tid;
		},
	subsection: function(subid)
		{
        if(this.display_subsection)
        	{
        	$('#category'+this.display_subsection).css('display','none');
        	$('#category'+subid).fadeIn('fast');
        	$('#subsection_l'+this.display_subsection).removeClass('selected');
        	}else{ $('#category'+subid).slideDown(); }
        $('#subsection_l'+subid).addClass('selected');
        this.display_subsection=subid;
		}
}
/* -- Rubricator END -- */

/* -- Org 2 Category BEGIN -- */

var Org2MyAll = {
	mode: 0,
	changeMode: function(nm)
		{
		if(nm) { $('#selCatWr').hide();$('#addCatWr').fadeIn('fast'); }else{ $('#addCatWr').hide();$('#selCatWr').fadeIn('fast'); }
		this.mode=nm;
		},
	addorg: function(org_id,mac_id,mac_name)
		{
		$('#add_org_id').val(org_id);
        $('#addCat_err').fadeOut('fast');
		if(this.mode)
			{
			this.addcat(mac_name);
			return ;
			}else{
			if(mac_id==''){ mac_id=0; }	mac_name='';
		    }

		$.getJSON("/xp_ajax_client.php?section=Categories&do=addcompany",
		 { org_id: org_id, mac_id: mac_id, mac_name: mac_name, mode: this.mode  },
		  function(data){
		  if(data.code == '1')
		  	{
	    	$('#msgDone').html(data.msg);
	    	$('#macLayer').slideUp();
		  	}else if(data.code == '2')
		  		{
	            $('#addCat_err').html(data.msg).fadeIn();
		  		}else if(data.code == '4')
			  		{
			  		$('#macWr').html(' ');
	                for(var i=0;i<(data.mac_ids).length;i++)
	                	{
	                	html_str='<a class="macChoice" href="javascript:void(0);" onclick="javascript:Org2MyAll('+data.org_id+','+data.mac_ids[i]+')">'+data.mac_names[i]+'</a>';
	                	html_str='<option value="'+data.mac_ids[i]+'">'+data.mac_names[i]+'</option>';
	                	$(html_str).appendTo('#macWr');
	                	}
	              	$('#mac .psevdo').css('display','inline');
	                if((data.mac_ids).length>49) { $('#addCatWr').html(' '); }
	                openFloatBox('mac');
			  		}else if(data.code == '3')
				  		{
							openFloatBox('mlog');
				  		}else if(data.code == '5')
				  			{
							$('#addCat_err').html(data.msg).fadeIn();
				  			}else if(data.code == '6')
					  			{
								openFloatBox('mac');
								Org2MyAll.changeMode(1);
								$('#macLayer .info').html(data.msg);
								$('#macLayer .psevdo').css('display','none');
					  			}
		  });
		}
		,
	addcat: function(name)
		{
		var newname=name;
		newname=$.trim(newname);
		$('#addCat_err').html(' ').fadeOut();
		if(newname!='')
			{
			$.getJSON("/xp_ajax_client.php?section=Categories&do=add",
			 { name: newname },
			  function(data){
			  	if(data.code == '1')
				  	{
				  	//html_str='<a class="macChoice" href="javascript:void(0);" onclick="javascript:Org2MyAll('+$('#add_org_id').val()+','+data.mac_id+')">'+data.name+'</a>';
				  	//$(html_str).appendTo('#macWr');
	                Org2MyAll.mode=0;
	                Org2MyAll.addorg($('#add_org_id').val(),data.mac_id,'');
				  	}else{ $('#addCat_err').html(data.msg).fadeIn(); }
			  	});
			}
		}
};

/* -- Org 2 Category END -- */

function showStatistic(type,orgID,parentID,fid)
	{
 	if($('#statbox').css('display')!='none') { $('#statbox').fadeOut(); return false; }
	$.getJSON("/xp_ajax_stat.php?type="+type,
		 { orgID: orgID, parentID: parentID, fid: fid },
		  function(data){
		  if(data.code == '1')
		  	{
            $("#statbox").html('Текущий месяц: '+data.cntrsum+' <br /> Прошлый месяц: '+data.cntrlast).fadeIn();
		  	}else if(data.code == '2')
		  		{
                alert(data.msg);
		  		}else if(data.code == '3')
			  		{
	                location.reload();
			  		}
		  });
	}

/* -- Send Error Message BEGIN -- */

var sendErr = {
	box: '#errMsgBox',
	fid: 0,
	orgid: 0,
	uid: 0,
	display: false,
	openErrorMsg: function(fid,org_id,org_name)
		{
		if(fid)
			{
			this.fid = fid;
			this.orgid = org_id;
	        $(this.box+' .comp').css('display','inline');
	        $(this.box+' .name').html(org_name);
			}else{
			this.fid = 0;
			this.orgid = 0;
			$(this.box+' .comp').css('display','none');
			$(this.box+' .name').html(location.href);
			}

        this.uid = $(this.box+' .uid').val();
		var winH = $(window).height();
		var winW = $(window).width();
		$(this.box+" .errMail,"+this.box+" .errSend,"+this.box+" .errText").show();
		$(this.box+' .sendState').hide();
		$(this.box+' .close').click(function(){ });

		$(this.box).css({left: winW/2-$(this.box).width()/2, top: eval("-"+$(this.box).height()),display:"block"});
		$(this.box).animate({ top: winH/2-$(this.box).height()/2 }, "fast").css("position", 'fixed');
		this.display=true;
		},
	sendErrorMsg: function(){
        var mail = $(this.box+' .errMail').val();
        var text = $(this.box+' .errText').val();
        var error = '';
        if($.trim(mail)!='')
	        {
	        if(!mailChecker(mail)) { error = error + 'Введен неверный E-Mail!'; }
	    	}else{ error = error + 'Введите ваш E-Mail!'; }
        if($.trim(text)=='' || text==$(this.box+' .errText').attr('default')) { error = error + '<br />Введите текст сообщения!'; }

        if(error!='') { $(this.box+' .sendState').css('color','#ff0000').html(error).slideDown('fast'); return false; }

        $(this.box+' .errSend').attr('disabled',true);
        $.getJSON('http://'+location.host+'/xp_ajax_client.php?section=senderror',
		 { mail: mail, text: text, fid: this.fid, orgid: this.orgid, uid: this.uid  },
		function(data){
			var winW = $(window).width();
			var box = '#errMsgBox';
			if(data.code == '1')
		  		{
		  		$(box+' .errMail,'+box+' .errSend,'+box+' .errText').hide();

		  		$(box+' .sendState').html(data.msg).css('color','green').slideDown('fast');
            	setTimeout("$('"+box+"').animate({ left: "+winW+"+$('"+box+"').width()}, 'fast'); ",3000);
            	$(box+' .errSend').attr('disabled',0);
				}else if(data.code == '2'){ $(box+' .sendState').css('color','#ff0000').html(data.msg).slideDown('fast'); $(box+' .errSend').attr('disabled',0); }else if(data.code == '3') { location.reload(); }
		  });
		},
	closeBox: function(){  $(this.box).animate({ top: eval(0+"-"+$(this.box).height()) }, "fast"); this.display=false; }
}

/* -- Org Card Show BEGIN -- */
var thisLoadORG=0;
function fullcard(org_id,parentID)
	{
	if($('#orgcard'+org_id+'_loader').css('display')=='none')
		{
		thisLoadORG=org_id;
		$('#orgcard'+org_id+'_loader').css('display','inline');
		if($('#orgcard'+org_id+'_full').html()=='')
			{
			$.get('/xp_orgcard_full.php',{o: org_id, p: parentID},function(data){
				$('#orgcard'+thisLoadORG).css('display','none');
				$('#orgcard'+thisLoadORG+'_full').html(data).height('auto').slideDown();
				onLoadMapFunc(thisLoadORG);
				$('#socneth_'+thisLoadORG+', #socnetf_'+thisLoadORG+', #printcard'+thisLoadORG+', #mapcont'+thisLoadORG).css('display','none');
				$('#maptoggle'+thisLoadORG+', #cardtoggle'+thisLoadORG).css('display','block');
				// $('#orgcard'+thisLoadORG+'_full').prepend('<div style="text-align:right;"><a href="javascript:void();" onclick="javascript:hide_fullcard('+thisLoadORG+')" >&larr; Свернуть </a></div>').slideDown();
				$('#orgcard'+thisLoadORG+'_loader').css('display','none');
				$('#orgcard'+thisLoadORG+'_full h1.org').css({'fontSize': '17px', 'color': '#128AFB','lineHeight': '1.5em','cursor':'pointer','margin':'0px 0px 7px 0px','fontWeight':'normal'});
				eval('$("#orgcard'+thisLoadORG+'_full h1.org").click(function(){hide_fullcard('+thisLoadORG+')});');
			},'html');

			}else{  $('#orgcard'+thisLoadORG+'_loader').css('display','none'); $('#orgcard'+org_id).css('display','none'); $('#orgcard'+org_id+'_full').height('auto').slideDown(); }
		}
	}

function hide_fullcard(org_id)
	{
	$('#orgcard'+org_id+'_full').slideUp('fast');
	$('#orgcard'+org_id).fadeIn('fast');
	$('#orgcard'+org_id+' .moveLink').hide();
	}
/* -- Org Card Show END -- */

function pollCheck(){
	var t=new Array();
	var a=$('#pollLayer').find('article');
	for(var j=0;a.length>j;j++)
		{
	    if($(a[j]).find('input:checked').length==0 || ($(a[j]).find('input.my:checked').length==1 && $.trim($(a[j]).find('textarea').val())=='')) { alert('Вы ответили не на все вопросы!'); return false; }
	    }
	return true;
}

function showMap(a,id)
	{
	var h,s;
	if($('#mapcont'+id).css('display')=="none")
		{
		h='0';
		s='1';
		}else{
			h='1';
			s='0';
			}
	$(a).find('.map_show_'+h).hide();
	$(a).find('.map_show_'+s).show();
	$('#mapcont'+id).slideToggle();
	}
var pathnav_timer=0;
function co_list_stop() { if(pathnav_timer){clearTimeout(pathnav_timer);pathnav_timer=0;} }
function co_list(o) // Show
	{
	var i=$(o).attr('rel');
	co_list_stop();
	$('.morelist').fadeOut('fast');
	if($('#co_'+i+'_list').css('display')=="none")
		{
        var p=$(o).offset();
        $('#co_'+i+'_list').css({'left': p.left, 'top': eval(p.top+'+8+'+$(o).css('font-size').replace('px','')) });
        $('#co_'+i+'_list').fadeIn('fast');
		}
	}
function co_list_start(o)
	{
    if(o.tagName=='A')
	    {
	    var i=$(o).attr('rel');
	    var perf="co_list_hide('#co_"+i+"_list');";
	    }else{
	    var i=$(o).attr('id');
	    var perf="co_list_hide('#"+i+"');";
	    }
    pathnav_timer=setTimeout(perf,1000);	}
function co_list_hide(o)
	{	$(o).fadeOut('fast');	}

