function ShowWin(url,x,y,name,isscrollbars) {
	cx=screen.width/2- (x/2);
	cy=screen.height/2-(y/2);
    isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}
function getAbsolutePosition(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}
function spo(id){
    ShowWin("/ru/protected/spo/?id="+id, 500, 600, 'spo' + id, 'yes');
    return false;
}
$.fn.overlay=function() {
	var el=$(this);
	$('body').prepend('<div id="overlay"></div>');
	$('#overlay').click(function(){el.hide();$('tr').removeClass('gr_tr');$('#overlay').remove();});
	$('#overlay').show('slow');
	return this;
}
$(document).ready(function(){
	/* popups */
	$('.close_pp,.pp-small-gray h3').click(function(){
		$(this).parents("div.popup").hide(); //предполагается, что родительский div только один
		$('#overlay').remove();
		return false;
	});
	$('#link-other-pro').click(function(){
		$('#pp-other-pro').overlay().css({top:0,left:getAbsolutePosition(this).x-10}).show();
		return false;
	});
	$('.tpassport-login .enter').click(function(){
		$("#pp-login").overlay().css({left:getAbsolutePosition(this).x-190}).show();
		return false;
	});
	$('.tpassport-login .logo').click(function(){
		$('#pp-login-about').overlay().css({left:getAbsolutePosition(this).x-230}).show();
		return false;
	});
	$('#link-video').click(function(){
		$('#pp-video').overlay().css({left:getAbsolutePosition(this).x-8,top:getAbsolutePosition(this).y-6}).show();
		return false;
	});
	$('.ti_popup').click(function(){
		$('#ti_pp').overlay().show().centering(1,1);
		return false;
	});
	$('#link-phone').click(function(){
		$('#pp-offices').overlay().css({right:5,top:getAbsolutePosition(this).y}).show();
		return false;
	});
	$('.autocomplete').click(function(){
		$('#pp-auto').overlay().css({left:getAbsolutePosition(this).x-300,top:getAbsolutePosition(this).y-30}).show();
		return false;
	});
	$('#pp-auto p').click(function(){
		$(this).siblings().removeClass('active').end().addClass('active');
	});
	$('.coditions a').click(function(){
		$('#pp-coditions').overlay().css({right:20,top:getAbsolutePosition(this).y-6}).show();
		return false;
	});
	$('#pp-coditions input:radio').click(function(){
		$('#pp-coditions .field-block').hide().eq($('#pp-coditions input:radio').index(this)).show();
	});
	$('.help').click(function(){
		$('#pp-help').overlay().css({left:getAbsolutePosition(this).x-8,top:getAbsolutePosition(this).y-7}).show();
		return false;
	});
	$('#pp-help h3').click(function(){
		$(this).parents("div").hide(); //предполагается, что родительский div только один
		$('#overlay').remove();
		return false;
	});
	$('.stop').click(function(){
		$('#pp-stop').overlay().show().centering(1,1);
		var This_Tr = $(this).parent().parent();
		This_Tr.addClass('gr_tr');	
		$('#pp-stop input.no,.close_pp').click(function(){This_Tr.removeClass('gr_tr');});
		numrow=$('.stop').index(this);
		return false;
	});
	$('#pp-stop input.yes').click(function(){
		$(this).parents("div.pp-warning").hide();
		$('#overlay').remove();
		$('table.comissions tr').eq(numrow+1).hide();
		return false;
	});
	$('#pp-stop input.no').click(function(){
		$(this).parents("div.pp-warning").hide();
		$('#overlay').remove();
		return false;
	});
	
	
	$('.delete').click(function(){
		$('#pp-del').overlay().show().centering(1,1);
		var This_Tr = $(this).parent().parent();
		This_Tr.addClass('gr_tr');	
		$('#pp-del input.no,.close_pp').click(function(){This_Tr.removeClass('gr_tr');});
		numrow=$('.delete').index(this);
		return false;
	});	
	
	$('#pp-del input.yes').click(function(){
		$(this).parents("div.pp-warning").hide();
		$('#overlay').remove();
		$('table.comissions tr').eq(numrow+1).hide();
		return false;
	});
	$('#pp-del input.no').click(function(){
		$(this).parents("div.pp-warning").hide();
		$('#overlay').remove();
		return false;
	});
	
	$('#link-add-email').click(function(){
		$('#pp-add-email').overlay().show().centering(1,1);
		return false;
	});
	
	$('.allspo_popup').click(function(){
		$('#allspo-pp').overlay().show().centering(1,1);
		return false;
	});
	
	/* menu */
	$('.leftmenu>li>a').click(function(){
		$(this).parent().toggleClass('active').end().next('ul').slideToggle();
		return false;
	});	
	
	/* select */
	$('#year').change(function(){
		$('.hide_ny').show();
		return false;
	});
	$('#country').change(function(){
		$('.page-tabs').show();
		$('.page-tabs li:first').addClass('active');
		$('.page-tab:first').show();
		return false;
	});
	
	/* tabs */
	$('.page-tabs li').click(function(){
		$(this).siblings().removeClass('active').end().addClass('active');
		$('.page-tab').hide().eq($('.page-tabs li').index(this)).show();
	});
	
	/* toggle */
	$('.table_news tr:not(.gray) a.active img').toggle(
		function(){$(this).attr('alt','Неактивно').attr('title','Неактивно').parents('tr').toggleClass('gray');return false;},
		function(){$(this).attr('alt','Активно').attr('title','Активно').parents('tr').toggleClass('gray');return false;}
	);
	$('.table_news tr.gray a.active img').toggle(
		function(){$(this).attr('alt','Активно').attr('title','Активно').parents('tr').toggleClass('gray');return false;},
		function(){$(this).attr('alt','Неактивно').attr('title','Неактивно').parents('tr').toggleClass('gray');return false;}
	);
	
	$('#s_rep').click(function(){
		$('#s_rep_row').toggle();
	});
	$('.com-tbl input:checkbox').click(function(){
		$(this).parent().siblings().andSelf().toggleClass('disabled').find('big input').each(function(){this.disabled = this.disabled ? false : true; this.value='';});
	});
	$('#spo-column').click(function(){
		$('.table_content input:checkbox, .tbl-resorts input:checkbox').each(function(){this.checked = $('#spo-column').attr('checked') ? true : false;});
	});
	
	$('.reset a').click(function(){
		$('.tbl-resorts input:checkbox').each(function(){this.checked = $('#spo-column').attr('') ? true : false;});
		return false;
	});
	
	$('.link-toggle').click(function(){
		$('.block-toggle').eq($('.link-toggle').index(this)).toggle();
		return false;
	});
	$('#email3').change(function(){
		$('#email4').toggleClass('view');
	});

	
	$('.add_ta_city[@value="1"]:option').change(function(){
		$(this).siblings('.add_ta_city').show();
	if ( $(this).val() != 1 )
		$(this).siblings('.add_ta_city').hide();
		return false;
	});		
	$('.spo_type[@value="1"]:option').change(function(){
		$(this).siblings('.spo_price').show();
	if ( $(this).val() != 1 )
		$(this).siblings('.spo_price').hide();
		return false;
	});
	
	/* Множественное удаление СПО  */
	$('#del_chk').toggle(function(){
		$('a.delete').hide(); 
		$('input.comi').show();
		$('#comi_del').show();
	}, function(){
		$('a.delete').show(); 
		$('input.comi').hide();
		$('#comi_del').hide();
		$('.comissions tr').removeClass('gr_tr');		
		$('.comissions input').attr('checked','');		
	});
	
	$('input.comi').change(function(){
		$(this).parent().parent().toggleClass('gr_tr');
	});
	$('tr.lst span.show_flt').click(function(){
		$('#exc_cnt_main').toggle();
		$('#id703').toggleClass('exc_cnt_spc');
		$('.show_flt').toggleClass('show_flt_opn');
	});
	
	/*$('.arrow_ico a').click(function(){
		if ($(this).parents('.line_head_group').next().css('display')=='none') {
			$(this).parents('.line_head_group').next().show();
			$(this).parent('.arrow_ico').addClass('arrow_ico_btm');
		} else {
			$(this).parents('.line_head_group').next().hide();
			$(this).parent('.arrow_ico').removeClass('arrow_ico_btm');
		}
	});*/
	
	$('.arrow_ico a').click(function(){
		var ss = $(this).parents('.line_head_group').next();
		while (!(ss.is('.line_head_group'))) {
			//ss.toggle(); 
			if (ss.css('display')=='none') {
				ss.show();
				$(this).parent('.arrow_ico').addClass('arrow_ico_btm');
			} else {
				ss.hide();
				$(this).parent('.arrow_ico').removeClass('arrow_ico_btm');
			}
			ss=ss.next();
		}
		return false;
	});
	
	$('.open_turagency_info').click(function(){
		$("#turagency_info").css({left:getAbsolutePosition(this).x-360,top:getAbsolutePosition(this).y-5}).show();
		return false;
	});
	
	$('.open_turagency_info2').click(function(){
		$("#turagency_info").css({left:getAbsolutePosition(this).x-5,top:getAbsolutePosition(this).y-5}).show();
		return false;
	});
	
	$('.open_info_photo').click(function(){
		$("#info_photo").show().centering(1,1);
		return false;
	});
	
	$('.event_close_turagency_info').click(function(){
		$("#turagency_info").hide();
		$("#info_photo").hide();
		return false;
	});
	
	$('.quest_kurs').click(function(){
		$('#own_kurs').overlay().css({left:getAbsolutePosition(this).x-5,top:getAbsolutePosition(this).y-12}).show();
		return false;
	});
	
	

});