$(document).ready(function(){

/*
	var response_el = $("#ajax_response").html().split(",");
	if (response_el[0] != "" && response_el[1] != "") {
		$("#ajax_response").html([["Просмотров: "]]+response_el[1]+[[", сегодня - "]]+response_el[0]);
	} else {
		$("#ajax_response").html("");
	}
*/
	//MENU
	$('.nav li').click(function() {

		});
		$('.topnav>li').hover(function() {
			//$('.topnav>li').removeClass('sfhover');
			$(this).addClass('sfhover');
		}, function() {
		 	$(this).removeClass('sfhover');
		});
		$('.topnav>li').hover(function() {
			$('#out').addClass('hoveredmenu');
			$('marquee').css("visibility","hidden");
			$('.topnav>li').removeClass('thisselected');
		  $(this).addClass('thisselected');
		}, function() {
		  //$(this).removeClass('hvr');
		});
		$('.topnav').hover(function() {
			//$('.topnav>li').removeClass('sfhover');
			//$(this).addClass('sfhover');
		}, function() {
		 //alert('we r out');
		$('#out').removeClass('hoveredmenu');
		$('.topnav>li').removeClass('sfhover');
		$('.topnav>li').removeClass('thisselected');
		$('marquee').css("visibility","visible");
		});
	$('.q h3').click(function(){
		$(this).closest('h3').next().slideToggle();
		$(this).closest('.q').toggleClass('qopened');
	});

	//FAQ LIST
	$('.t-link').each(function(element){
		$(this).click(function(){
			$(this).next().toggle();
		});
	});
	//BLOCK TABS
	$('.art-tab-link').each(function(element){
		$(this).click(function(){
			$('.art-tab-link').each(function(element){
				$(this).parent().attr("class", "res");
			});
			$(this).parent().attr("class", "here");
			$('.art-tab-info').each(function(element){
				$(this).css("display", "none");
			});
			$('#tab_' + $(this).attr("id").substr(5)).css("display", "block");			
		});			
	});				
	$('.art-tab-link-media').each(function(element){
		$(this).click(function(){
			$('.art-tab-link-media').each(function(element){
				$(this).parent().attr("class", "res");
			});
			$(this).parent().attr("class", "here");
			$('.art-tab-info-media').each(function(element){
				$(this).css("display", "none");
			});
			$('#tab_' + $(this).attr("id").substr(5)).css("display", "block");			
		});			
	});

	//REG
	if ($('#hidden_monitor').val()==1){
		$('#subs_div').hide();
	}
	$('#arrow').addClass('turn');
	
	
	$('#subs').toggle(function(){ 
		if ($('#hidden_monitor').val()==1){
			$('#subs_div').show();
			$('#arrow').removeClass('turn');
			$('#arrow').addClass('turnedon');
			$('#hidden_monitor').val(2);
		}else{
			$('#subs_div').hide();
			$('#arrow').removeClass('turnedon');
			$('#arrow').addClass('turn');
			$('#hidden_monitor').val(1);
		}
	},function(){
		if ($('#hidden_monitor').val()==1){
			$('#subs_div').show();
			$('#arrow').removeClass('turn');
			$('#arrow').addClass('turnedon');
			$('#hidden_monitor').val(2);
		}else{
			$('#subs_div').hide();
			$('#arrow').removeClass('turnedon');
			$('#arrow').addClass('turn');
			$('#hidden_monitor').val(1);
		}
	});

	$('#passwd_toggle').toggle(function(){ 
		if ($('#hidden_pass').val()==1){
			$('#passwd').show();
			$('#hidden_pass').val(2);
		}else{
			$('#passwd').hide();
			$('#hidden_pass').val(1);
		}
	},function(){
		if ($('#hidden_pass').val()==1){
			$('#passwd').show();
			$('#hidden_pass').val(2);
		}else{
			$('#passwd').hide();
			$('#hidden_pass').val(1);
		}
	});
	if ($('#hidden_pass').val()==1){
		$('#passwd').hide();
	}
	
	
	
/*
	$('#subs').toggle(function(){ 
		$('#subs_div').show();
		$('#arrow').removeClass('turn');
		$('#arrow').addClass('turnedon');
		$('#hidden_monitor').val(2);
	},function(){
		$('#subs_div').hide();
		$('#arrow').removeClass('turnedon');
		$('#arrow').addClass('turn');
		$('#hidden_monitor').val(1);
	});

	$('#passwd').hide();
	$('#passwd_toggle').toggle(function(){ 
		$('#passwd').show();
	},function(){
		$('#passwd').hide();
	});
*/

	//BLOCK MEDIA TABS
	$('.t-blank').each(function(element){
		$(this).attr('target', '_blank');
	});
	
	var elem = document.getElementById("q");
	if (elem!=null){
		keyup(document.getElementById("q"));
	}
	$('#advance_s_link').toggle(function(){
		$('#advanced_search').show();
		$('#is_advanced').val(1);
		$('#arrow').removeClass('turn');
		$('#arrow').addClass('turnedon');
	}, function(){
		$('#advanced_search').hide();
		$('#is_advanced').val(0);
		$('#arrow').removeClass('turnedon');
		$('#arrow').addClass('turn');
	});
	
});



maxKeys = 1000;
var IE = (document.all) ? 1 : 0;
var DOM = 0;
if (parseInt(navigator.appVersion) >=5) {DOM=1};

function txtshow( txt2show ) {
// Detect Browser
	if (DOM) {
		var viewer = document.getElementById("txtmsg");
		viewer.innerHTML=txt2show;
	}
	else if(IE) {
		document.all["txtmsg"].innerHTML=txt2show;
	}
}

function keyup(what)
{
	var str = new String(what.value);
	var count = maxKeys - str.length;
	var showstr = "Осталось " + count + " символов";
	if (count < 0) 
		showstr += '<br>Превышено значение. Информация может быть утеряна!';
	txtshow( showstr );
}


function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
 
function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*
Event.observe(window, 'load', function() { 
	//FAQ LIST
	$$('a.t-link').each(function(element){
		Event.observe(element, 'click', function(event){ 
			element.next().toggle();
		});
	});
	//BLOCK TABS
	$$('a.art-tab-link').each(function(element){
		Event.observe(element, 'click', function(event){ 
			$$('a.art-tab-link').each(function(element){
				element.up().className = 'res';
			});
			element.up().className = 'here';
			$$('dl.art-tab-info').each(function(element){
				element.style.display= 'none';
			});
			$('tab_' + element.id.substr(5)).style.display = 'block';
		});
	});
	$$('a.art-tab-link-media').each(function(element){
		Event.observe(element, 'click', function(event){ 
			$$('a.art-tab-link-media').each(function(element){
				element.up().className = 'res';
			});
			element.up().className = 'here';
			$$('dl.art-tab-info-media').each(function(element){
				element.style.display= 'none';
			});
			$('tab_' + element.id.substr(5)).style.display = 'block';
		});
	});
	//BLOCK MEDIA TABS
	$$('a.t-blank').each(function(element){
		element.setAttribute('target', '_blank');
	});
});

function r_submit() {
	if ($('ff1').value.empty()) {
		alert('Пожалуйста, заполните поле «Email», что бы зарегистрироваться.');
		return false;
	}
	if ($('ff2').value.empty()) {
		alert('Пожалуйста, заполните поле «Пароль», что бы зарегистрироваться.');
		return false;
	}
	if ($('ff3').value.empty()) {
		alert('Пожалуйста, заполните поле «Подтвердите пароль», что бы зарегистрироваться.');
		return false;
	}
	if ($('ff4').value.empty()) {
		alert('Пожалуйста, заполните поле «Имя», что бы зарегистрироваться.');
		return false;
	}
	
	return true;
}
*/


function login_me() {
	var link = '/login/?check=1';
	if (lang_alias==undefined)
		var lang_alias = 'ru';
	$.ajax({
		url: '/' + lang_alias + link,
		type: "GET",
		processData: false,
		cache: false,
		success: onSuccessLogin,
		error: errorFunction,
		dataType: "json"
	});
}

function errorFunction(XMLHttpRequest, textStatus, errorThrown){
//    alert(textStatus);
}

function onSuccessLogin(oReq){

	var json = oReq;
	$('#login_content').html(json.login);
//alert(json.cookie);
//alert(json.login);
	if (json.rate_history_send_excel==1){
		$('.rate_history_pdf').each(function(){
			var href = $(this).next().html();
			href = href.replace(/['"]/g,'');
			$(this).attr('href', href);
			$(this).attr('target', '_blank');
		});
		
		$('#rate_history_send_excel_log').css('display', 'inline');
		$('#rate_history_send_excel_nlog').css('display', 'none');
		$('#company_send_excel_log').css('display', 'inline');
		$('#company_send_excel_nlog').css('display', 'none');
		//$('#rate_history_pdf_log').css('display', 'inline');
		//$('#rate_history_pdf_nlog').css('display', 'none');
		$('.rate_history_pdf_log').css('display', 'inline');
		$('.rate_history_pdf_nlog').css('display', 'none');
		$('#monitor_subsribe_form_log').css('display', 'inline');
		$('#monitor_subsribe_form_nlog').css('display', 'none');
	}else{
		$('#rate_history_send_excel_log').css('display', 'none');
		$('#rate_history_send_excel_nlog').css('display', 'inline');
		$('#company_send_excel_log').css('display', 'none');
		$('#company_send_excel_nlog').css('display', 'inline');
		//$('#rate_history_pdf_log').css('display', 'none');
		//$('#rate_history_pdf_nlog').css('display', 'inline');
		$('.rate_history_pdf_log').css('display', 'none');
		$('.rate_history_pdf_nlog').css('display', 'inline');
		$('#monitor_subsribe_form_log').css('display', 'none');
		$('#monitor_subsribe_form_nlog').css('display', 'inline');
	}
	
}

$(document).ready(function(){
	login_me();
});

