SITE_URL='http://www.alean.ru/';

function ceo_toggle_tbl (id, tmpl)
{
var srpt = SITE_URL+'lib/'+tmpl+'.php';
	if ($('#tbldiv'+id).children().html()) {
		if ($('#triger'+id).attr('src')==SITE_URL+'/img/minus.gif') {
			$('#tbldiv'+id).hide();
			$('#triger'+id).attr('src',SITE_URL+'/img/plus.gif');
		}
		else {
			$('#tbldiv'+id).show();
			$('#triger'+id).attr('src',SITE_URL+'/img/minus.gif');
		} 
	}
	else {
		$('#tbldiv'+id).append('<img src="'+SITE_URL+'/img/loading.gif"/>');
		$('#tbldiv'+id).load(srpt,{'id':id}, function() {
			$('#tbl'+id).tablesorter();	 	
			})
		$('#triger'+id).attr('src',SITE_URL+'/img/minus.gif');
	}
}

function initGrid (id)
{
$('#list'+id).load(SITE_URL+'lib/get_grid_v1.php',{'id':id})
};
function toggle_tbl (id, tmpl)
{
 var srpt = 'http://www.alean.ru/lib/'+tmpl+'.php';
 if ($('#tbldiv'+id).children().html()){
	if ($('#triger'+id).attr('src')== '/img/minus.gif'){
            $('#tbldiv'+id).hide();
            $('#triger'+id).attr('src','/img/plus.gif');
            }
  	else{
            $('#tbldiv'+id).show();
            $('#triger'+id).attr('src','/img/minus.gif');
         } 
}
 else{
	$('#tbldiv'+id).append('<img src="/img/loading.gif"/>');
	$('#tbldiv'+id).load(srpt,{'id':id}, function(){
	$('#tbl'+id).tablesorter();	 	
	})
	$('#triger'+id).attr('src','/img/minus.gif');
}
};
function toggle_tbl_e (id, tmpl, cid)
{
 if($('#ex_'+cid).attr('class')=='tbl_linc_activ'){
	$('#tbldiv'+id).hide();	
	$('#ex_'+cid).attr('class','tbl_linc');
	$('#et_'+cid).attr('class','tbl_td');
}
 else{
	var mn_pasiv = $('#exs_'+id);
	$('#tbldiv'+id).show();
	$('span',mn_pasiv).attr('class','tbl_linc');
	$('td',mn_pasiv).attr('class','tbl_td_fon');
	$('#ex_'+cid).attr('class','tbl_linc_activ');
	$('#et_'+cid).attr('class','tbl_td_act');
 	var srpt = 'lib/'+tmpl+'.php';
	$('#tbldiv'+id).load(srpt,{'id':cid}, function(){
		$('#tbl'+cid).tablesorter();	 	
	})
}
};

function initClientBox (arr)
{
	initGrids (arr);
	//initialise the docking boxes manager
     manager= new dbxManager('main'); 	//session ID [/-_a-zA-Z0-9/]
	 content_bar= new dbxGroup(
		'content_bar', 'vertical', '7', 'no', '10', 'yes', 	'closed',
		'раскрыть', 'свернуть', 'нажмите кнопку мыши и переместите вверх или вниз',
		'нажмите чтобы %toggle% ', 'use the arrow keys to move this box',
		', or press the enter key to %toggle% it', '%mytitle%  [%dbxtitle%]'
		);
}
function initGrids (arr){
	for (i=0;i<arr.length;i++){
		initGrid(arr[i]);
	}
}


function initMediaGo(id, cont_h)
{
	$('#media').load('lib/get_media_go.php',{'id':id,'width':width,'height':height},function(){
 	$('#media_content').innerfade({ speed: 'slow', timeout: 5000, type: 'sequence', containerheight: cont_h });
	$('#media').css('display','block');
	});	
}
function initMedia(id, cont_h)
{
	$('#media').load('lib/get_media.php',{'id':id,'width':width,'height':height},function(){
 	$('#media_content').innerfade({ speed: 'slow', timeout: 3000, type: 'sequence', containerheight: cont_h });
	$('#media').css('display','block');
	});	
}
function initMenu (id)
{
$('#menu').load('lib/init_menu.php',{'id':id,'width':width,'height':height });
}
function initLink (id)
{
$('#links').load('lib/init_link.php',{'id':id});
}

function initBaners (id)
{
$('#baners').load('lib/init_baners.php',{'id':id,'width':width,'height':height });
}

function initNews (id)
{
$('#news').load('lib/init_news.php',{'id':id},	function(){
//         $('.new_head').each(function (){
//		 $(this).toggle(
//          function(event) {
//            $(this).children().children().show();
//          },
//          function(event) {
//            $(this).children().children().hide();
//          }
//        );}
//		);
//		$('.new_body').hide();
    
      }
)
};



function initCatalog(eid)
    {
		tree = $('#catalog').load('lib/init_catalog.php',{id: eid});			
}
function activCatalog(ths)
{
subbranch = $('ul', ths.parentNode).eq(0);
if (subbranch.css('display') == 'none') {
	subbranch.show();
	ths.src = 'img/minus.gif';
} else {
	subbranch.hide();
	ths.src = 'img/plus.gif';
	}
}

 	function getContent(id)
 	{
 		$('#content').load('lib/get_content.php',{id:id,width:width,height:height,sid:php_session_id});
 		$('#fly').load('lib/get_flylnk.php',{id:id,width:width,height:height});
 		content_id = id;
 	}
	
 	function getWeather(id)
 	{
	$('#weather').load('lib/init_weather.php',{id:id});
 	} 	







//--------------------------------------------------------------------
//--------------  Функции интерфейса расчета цен по размещению -------
//--------------------------------------------------------------------

function eventer_price(code,hotel)
{
pageID = code;
var strrr = "lib/ksb1.php?id="+code+"&ksb=nal";
HotelName = hotel;
tb_show(hotel+" - для расчета стоимости выберите начальную и конечную ячейку с наличием номеров",strrr);
}



//--------------------------------------------------------------------
//--------------  Функция отправки формы заказа тура -----------------
//----------------------------------------------------------------------
function sendForm ()
{
 var email = $("#email").val();
 var fio = $("#fio").val();
 var residing_info = $("#residing_info").val();
 var phone = $("#phone").val();
 var date_s = $("#date_s").val();
 var date_e = $("#date_e").val();
 var region = $("#reg").html();
 var object = $("#object").html();

 $.post("lib/post_form.php", { email: email, fio: fio, residing_info: residing_info, phone: phone,  date_s: date_s, date_e: date_e,  region: region, object: object}, tb_remove);	
}


//--------------------------------------------------------------------
//--------------  Функция отправки формы заказа Авиа Билетов ---------
//----------------------------------------------------------------------
function sendFormAB (opt1,opt2)
{
 var n1,d1,p1,user;
 var tickol=1;
 if ($("#user_ab").attr('checked')) user = 1;
 else user = 0;
 var jname = $("#jname_ab").val();
 var jface = $("#jface_ab").val();
 var fname = $("#fname_ab").val();
 var phone = $("#phone_ab").val();
 var mail = $("#mail_ab").val();
 var dt_in = $("#in_ab").val();
 var dt_out = $("#out_ab").val();

for (i=0;i<opt1.length;i++){
	if(opt1[i].selected)tickol = opt1[i].value;
}
for (i=0;i<opt2.length;i++){
	if(opt2[i].selected)city = opt2[i].value;
}

for (i=1;i<=tickol;i++){
 	n1=$("#ab_n"+i).val();
 	d1=$("#ab_d"+i).val();
 	p1=$("#ab_p"+i).val();
	$.post("lib/post_form_ab.php", { n1: n1, d1: d1, p1: p1, tickets: tickol,  city: city, user: user,  jname: jname, jface: jface, fname: fname, phone: phone, mail: mail, dt_in: dt_in, dt_out: dt_out});	
 }
tb_remove();
}


function chq(n){
var s="";
var i=0;
for(i=1;i<=n;i++){
s+="<tr><td><input type=text name='n"+i+"' id='ab_n"+i+"' style='width:100%'></td><td><input type=text id='ab_d"+i+"' name='d"+i+"' style='width:100%'></td><td><input type=text id='ab_p"+i+"' name='p"+i+"' style='width:100%'></td></tr>";
}
var html="<table width=100% cellpadding=0 cellspacing=0 border=0>"+
"<tr class='dest'><td>Фамилия, Имя, Отчество</td><td align='center'>Дата рождения</td><td align='center'>№ паспорта</td></tr>"+s+"</table>";
$("#dot").children().remove();
$("#dot").append(html);
}

//-------------------------------------------------------------------------------
//--------------  Функции отправки формы заявки от тур агенства ----------------
//------------------------------------------------------------------------------
function sendFormTA ()
{
 var nalog,parol;
 var valid = true;
 var errmsg ="Внимание: ";
 if ($("#nalog1").attr('checked')) nalog = $("#nalog1").val();
 if ($("#nalog2").attr('checked')) nalog = $("#nalog2").val();
 if ($("#nalog3").attr('checked')) nalog = $("#nalog3").val();
 if ($("#nalog4").attr('checked')) nalog = $("#nalog4").val();
 if ($("#parol1").attr('checked')) parol = $("#parol1").val();
 if ($("#parol2").attr('checked')) parol = $("#parol2").val(); 
 var fname = $("#fname").val();
if (fname.length < 1){valid=false; errmsg +="не заполнено поле правовой формы";}
var email = $("#email").val();
if (email.length < 1){valid=false;errmsg +=" не заполнено поле с e-mail,"}
else if (!emailCheck(email)){valid=false;errmsg +=" не правильно заполнено поле с e-mail,";}
var sname = $("#sname").val();
if (sname.length < 1){valid=false;errmsg +="  кароткого названия," }
var phone = $("#phone").val();
if (phone.length < 1){valid=false;errmsg +=" номера телефона,";}
var uadres = $("#uadres").val();
if (uadres.length < 1){valid=false;errmsg +="юридического адреса,";}
var padres = $("#padres").val();
if (padres.length < 1){valid=false;errmsg +=" почтового(фактического) адреса,";}
var fax = $("#fax").val();
if (fax.length < 1){valid=false;errmsg +="  поле с Fax,";}
var inn = $("#inn").val();
if (inn.length < 1){valid=false;errmsg +="  с INN,";}
var rs = $("#rs").val();
if (rs.length < 1){valid=false;errmsg +=" расчетного счета,";} 
var bank = $("#bank").val();
if (bank.length < 1){valid=false;errmsg +="  наименования банка,";} 
var ks = $("#ks").val();
if (ks.length < 1){valid=false;errmsg +="  корреспонденсткого счета,";}
var bik = $("#bik").val();
if (bik.length < 1){valid=false;errmsg +=" поле с БИК,";} 
var okpo = $("#okpo").val();
if (okpo.length < 1){valid=false;errmsg +=" с ОКПО,";} 
var fio_prezident = $("#fio_prezident").val();
if (fio_prezident.length < 1){valid=false;errmsg +=" ФИО раководителя";}  
var fio_worker = $("#fio_worker").val();
if (fio_worker.length < 1){valid=false;errmsg +=" ФИО сотрудника,оствественного по работе с КСБ и его ICQ";}  
var email_worker = $("#email_worker").val();
if (email_worker.length < 1){valid=false;errmsg +=" E-mail ТА в базу рассылки";}
 
if (valid)
 $.post("lib/post_form_ta.php", {fname: fname, email: email, sname: sname, phone: phone, uadres: uadres, padres: padres, fax: fax, inn: inn, rs: rs,  bank: bank, ks: ks, bik: bik,  okpo: okpo,nalog: nalog, fio_prezident: fio_prezident, fio_worker: fio_worker, email_worker: email_worker, parol: parol}, function(data){
	$("#hiden_form_ta").css('display', 'none'); document.write(data);
});	
else alert(errmsg);
}

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/;
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
return false;
}
return true;
}

function changeContents (field, value)
{
	$.post('lib/exe.php',{field:field,value:value},function(data){if(data!=""){ alert(data);}});
}
function remPass()
{
	$("#hiden_form_ta").css({display:"none"});
	$("#remPassF").css({display:"block",align:"center"});
}
function sendEmail()
{
 var email1=$("#emailRem").val(); 
 var valid=true;
 var errmsg ="Внимание: ";
 if (email1.length < 1){valid=false;errmsg +=" не заполнено поле с e-mail,"}
 else if (!emailCheck(email1)){valid=false;errmsg +=" не правильно заполнено поле с e-mail,";}
 if (valid){
 $.post("lib/check_form_ta.php", {email:email1}, function(data){
alert(data);})
 }
 else {alert(errmsg)}
}

$(document).ready(function() {
 

   var valid=true;
$('form :input').blur(function() {
$(this).parents('td:first').removeClass('warning')
.find('span.error-message').remove(); 
var $listItem = $(this).parents('td:first');
if (this.value == '') {
 valid=false;
var errorMessage = '*';
$('<span></span>')
.addClass('error-message')
.text(errorMessage)
.appendTo($listItem);
$('form :input').addClass('warning');
}

})} )
//-------------------------------------------------------------------------------
//--------------  Функция отправки формы подписки на рассылку ----------------
//------------------------------------------------------------------------------
function sendFormRASS ()
{
 var name_r = $("#name_r").val();
 var email_r = $("#email_r").val();
 var phone_r = $("#phone_r").val();
 var city_r = $("#city_r").val();
 
 $.post("lib/post_form_rass.php", { name_r: name_r, email_r: email_r, phone_r: phone_r, city_r: city_r}, function(){
	$("#rass_form_div").css('display', 'none');
});	
}


//-------------------------------------------------------------------------------
//--------------  Функция отправки формы заявки на совместную рекламу ---------------
//------------------------------------------------------------------------------
function sendFormPP ()
{
 var name = $("#name").val();
 var email = $("#email").val();
 var city = $("#city").val();
 var adress_k = $("#adress_k").val();
 var metro = $("#metro").val();
 var phones = $("#phones").val();
 var dates = $("#dates").val();
 var cont_face = $("#cont_face").val();
 var tel_fax = $("#tel_fax").val();
 var shirota = $("#shirota").val();
 var dolgota = $("#dolgota").val();


 $.post("lib/pp_wb.php", { name: name, city: city, adress_k: adress_k, metro: metro, phones: phones, dates: dates, cont_face: cont_face, tel_fax: tel_fax, shirota: shirota,  dolgota: dolgota, email:email}, function(){
	$("#pp_wb_div").css('display', 'none');
});	
}

//-------------------------------------------------------------------------------
//--------------  Функции вывода конктента в всплывающее окно  ---------------
//------------------------------------------------------------------------------

function callback_article(id,ttl){
	if(ttl == 'brn')init_bron(id);
	else if(ttl == 'prc')init_price(id);
		 else init_article(id,ttl)
}

function init_article(id,ttl)
{
var alean_url="http://www.alean.ru/";
if(ttl != "Фотогалерея") $('#alean_article').load(alean_url+'lib/get_opisan.php',{id:id});
else $('#alean_article').load(alean_url+'lib/get_photo.php',{id:id});
var mn_pasiv = $('#top_menu');
$('td',mn_pasiv).attr('class','a_menu_passiv');
$('#art'+id).attr('class','a_menu_activ');

//alert('testing');
init_print(id, 'article');
thickbox_select();
$('#art'+id+' td').attr('class','a_menu_activ');
}


function init_price(id)
{
var alean_url="http://www.alean.ru/";
$('#alean_article').load(alean_url+'lib/ksb_price.php?',{id:id},function() {
	$('table.entry').wrap('<div style="margin:10px; width:98%; overflow-x:scroll;"></div>');																		 
});
var mn_pasiv = $('#top_menu');
$('td',mn_pasiv).attr('class','a_menu_passiv');
$('#prc').attr('class','a_menu_activ');

init_print(id, 'price');
thickbox_select();
$('#prc td').attr('class','a_menu_activ');
}

function init_price1(id)
{
var alean_url="http://www.alean.ru/";
$('#alean_article').load(alean_url+'lib/ksb_prc_x.php?id='+id+'&date1='+start_price+'&date2='+stop_price);
var mn_pasiv = $('#top_menu');
$('td',mn_pasiv).attr('class','a_menu_passiv');
$('#prc').attr('class','a_menu_activ');
}


//function init_bron(id)
//{
// alert(id);
//pageID = id;
//HotelName = name;
//$.ajax({url:'lib/ksb11.php',type:'POST',dataType:"xml",data:{id:id,date1:start_date,date2:stop_date},complete:function(xml){getWS(xml.responseXML);}});
//var mn_pasiv = $('#top_menu');
//$('td',mn_pasiv).attr('class','a_menu_passiv');
//$('#brn').attr('class','a_menu_activ');
//}
/*

function openBdx(num)
{
	//$("#categories").each().(function ()
	
	//{
		
	  var classn= $('#categories').attr('class')

	  alert(classn) ;	
	 	
	//});
}
*/

function openBdxx(num)
{
var ddd;
ddd=$('.dbx-box');
//alert(ddd);
ddd.each(function ()
  {
//   alert(num);
  	var $element=$(this);  	
  	var reId=$element.attr('class');  	
  	var brokenstring=reId.split(" "); 
  	var toToggle=(brokenstring[2]).split("-");			
	var toToggle1=parseInt(toToggle[1]);
	//alert(toToggle1);
  	var list=$("a",$element).attr("name");
  	var str=brokenstring[1];
	if (str=="dbx-box-closed")
	{		
		if (list==num)
		{		     	
		  content_bar.toggle(toToggle1);	
		}
	}
	else
	if (list!=num)
	{	
	content_bar.toggle(toToggle1);
//	alert(list);
//	alert(num);
	}	
  });
  window.location.href="http://www.alean.ru#"+num;

  
}

function toggle_tbl_v1(id, tmpl)
{
 var srpt = '../lib/'+tmpl+'.php';
 
 
 $('#tbldiv'+id).append('<img src="/img/loading.gif"/>');
	$('#tbldiv'+id).load(srpt,{'id':id}, function(){
	$('#tbl'+id).tablesorter();	 	
	})
	$('#triger'+id).attr('src','/img/minus.gif');
 //if ($('#tbldiv'+id).children().html()){
	if ($('#triger'+id).attr('src')== '/img/minus.gif'){
            $('#tbldiv'+id).hide();
            $('#triger'+id).attr('src','/img/plus.gif');
            }
  	else{
            $('#tbldiv'+id).show();
            $('#triger'+id).attr('src','/img/minus.gif');
         } 
//}
 //else{
	//$('#tbldiv'+id).append('<img src="/img/loading.gif"/>');
	//$('#tbldiv'+id).load(srpt,{'id':id}, function(){
	//$('#tbl'+id).tablesorter();	 	
	//})
	//$('#triger'+id).attr('src','/img/minus.gif');
//}
};

// thickbox view block {
function thickbox_view() {
	if(!$('table#top_menu').attr('count')) {
		var count;
		var on_click;
		var tmp_txt;
		$('td#brn').remove(); // important!
		$('table#top_menu').removeAttr('style');
		$('table#top_menu').addClass('general');
		$('table#top_menu').css('height','30px');
		$('table#top_menu').after('<table border="0" cellspacing="0" cellpadding="0" class="general" id="jaw_bottom"><col width="10" /><col width="*" /><col width="10" /><tr><td id="top_menu_bottom_1"></td><td id="top_menu_bottom_2"></td><td id="top_menu_bottom_3"></td></tr></table>');
		$('table#top_menu tr td').before('<td></td>');
		$('table#top_menu tr td:last').after('<td></td>');
		count=$('table#top_menu tr td').size();
		for(i=0;i<count;i++) {
			$('table#top_menu tr td:eq('+i+')').attr('count',i);
		}
		
		$('table#top_menu tr td:first').before('<td id="top_menu_left"></td>');
		$('table#top_menu tr td:last').after('<td id="top_menu_right"></td>');
		$('table#top_menu').attr('count',count);
	
		for(i=1;i<count-1;i+=2) {
			tmp_txt=$('table#top_menu td[count='+i+']').text();
			$('table#top_menu td[count='+i+'] span').attr('id','menu_click_area');
			$('table#top_menu td[count='+i+'] span').html('<table border="0" cellSpacing="0" cellPadding="0" width="100%">'+
														  '<tr><td align="center" valign="middle" height="33">'+tmp_txt+'</td></tr>'+
														  '</table>');			
		}
	}
	thickbox_select();
}
function thickbox_select() {
	var count;
	var last_element;
	var first_count;
	var last_count;
	var pointer;
	var left;
	var right;
	
	$('table#top_menu').attr('cellSpacing',0);
	$('table td#top_menu_left, table tr td#top_menu_right').removeClass();
	count=parseInt($('table#top_menu').attr('count'));
	$('table#top_menu tr td[count]:eq(0)').attr('class','first_passiv');
	last_element=count-1;
	$('table#top_menu tr td[count]:eq('+last_element+')').attr('class','last_passiv');
	for(i=2;i<count-2;i+=2) {
		$('table#top_menu td[count='+i+']').attr('class','general_passiv');
	}

	first_count=1;
	last_count=count-2;
	pointer=parseInt($('table#top_menu td[class="a_menu_activ"]').attr('count'));
	left=pointer-1;
	right=pointer+1;
	if(pointer==first_count) {
		$('table#top_menu tr td[count='+left+']').attr('class','first_activ');
		$('table#top_menu tr td[count='+right+']').attr('class','general_activ_right');
	}
	else if(pointer==last_count) {
		$('table#top_menu tr td[count='+left+']').attr('class','general_activ_left');
		$('table#top_menu tr td[count='+right+']').attr('class','last_activ');
	}
	else {
		$('table#top_menu tr td[count='+left+']').attr('class','general_activ_left');
		$('table#top_menu tr td[count='+right+']').attr('class','general_activ_right');		
	}
}
// } enblock

// print block {
function init_print(id, type) {
	var back_button;
	if($('body').attr('last_action')) {
		back_button='<img style="cursor:pointer;"'
			+' border="0" src="'+SITE_URL+'images/printer/icon_back.gif"'
			+' onClick="'+$('body').attr('last_action')+'" />';
	}
	else back_button='';
	
	if(type == 'article') print_link = 'http://www.alean.ru/lib/print.php?id='+id;
	else if(type == 'svod_price') print_link = 'http://www.alean.ru/lib/svod_prices_print.php?id='+id;
	else if(type == 'price') print_link = 'http://www.alean.ru/lib/ksb_price.php?id='+id;
	else print_link = '#';
	
	$('#alean_print_tag').html('<table width="100%" border="0" cellPadding="0" cellSpacing="0">'
		+'<tr>'
			+'<td align="left" width="15%">'
				+'<a href="'+print_link+'" target=_blank>'
				+'<img src="'+SITE_URL+'images/printer/icon-printer.jpg"/></a>'
			+'</td>'
			+'<td width="70%" id="groups_out" align="center"></td>'
			+'<td align="right" width="15%">'+back_button+'</td>'
		+'</tr></table>');
	
	var dummy;
	if($('#TB_ajaxContent').css('height')) {
		dummy = parseInt($('#TB_ajaxContent').css('height').replace('px',''))-145;
		$('#alean_article').css('height',dummy+'px');
	}
	
	$('#groups_out').load('../lib/groups_view.php?key='+id);
}
// } endblock