var C={
	showChangeCityArr: function(){
		U.gbi('changeCityArr').style.display='block';
	},

	hideChangeCityArr: function(){
		try{
			U.gbi('changeCityArr').style.display='none';
		}
		catch(e){/*alert(e)*/}
	},

	showCheckplugCityArr: function(){
		U.gbi('checkplugCityArr').style.display='block';
	},

	hideCheckplugCityArr: function(){
		try{
			U.gbi('checkplugCityArr').style.display='none';
		}
		catch(e){/*alert(e)*/}
	},

	setChangeCity: function(id,title){
		jQuery('#changeCityOne b').empty().append(title);
		jQuery('#changeCityArr b').empty().append(title);
		jQuery('#changeCityArr .invsbl').removeClass('invsbl');
		jQuery('#changeCityArr .city'+id).parent().addClass('invsbl');
	},

	setCheckplugCity: function(id,title){
		if(id.indexOf('http')==0){
			location.href=id;
		}else{
			document.forms['checkplugForm'].elements['city_id_js'].value=id;
			jQuery('#checkplugCityOne b').empty().append(title);
			jQuery('#checkplugCityArr b').empty().append(title);
			jQuery('#checkplugCityArr .invsbl').removeClass('invsbl');
			jQuery('#checkplugCityArr .city'+id).parent().addClass('invsbl');
		}
	},

	showHideFaqctg: function(id){
		var ctg=U.gbi('faqctg'+id);
		if(ctg.offsetHeight){
			jQuery(ctg).hide('normal');
			U.gbi('faqctg'+id+'link').className='rarr';
		}else{
			jQuery(ctg).show('normal');
			U.gbi('faqctg'+id+'link').className='darr';
 		}
	},

	showHideVacanciesctg: function(id){
		var ctg=U.gbi('vacanciesctg'+id);
		if(ctg.offsetHeight){
			jQuery(ctg).hide('normal');
			U.gbi('vacanciesctg'+id+'link').className='rarr';
		}else{
			jQuery(ctg).show('normal');
			U.gbi('vacanciesctg'+id+'link').className='darr';
 		}
	},

	ajaxSubscribe: function(){
		jQuery('#ajaxSubscribe .loader').css('visibility','visible');
		var req=new JsHttpRequest();
		req.onreadystatechange=function(){
			if(req.readyState==4){
				if(req && req.responseText){alert(req.responseText);return;}
				if(req.responseJS.code){
					jQuery('#ajaxSubscribe').empty();
					jQuery('#ajaxSubscribe').append(req.responseJS.code);
					jQuery('#ajaxSubscribe .loader').css('visibility','hidden');
				}
			}
		}
		req.open(null,'./?ajax=1',true);
		req.send({form:U.gbi('subscribeForm')});
	},

	showFormscForm: function(id){
		jQuery('#formsc'+id+'successful').hide("normal",function(){
			jQuery('#formsc'+id+'box').show("normal");
		})
	},

	showHideBlockById: function(block_id){
		var block=U.gbi(block_id);
		if(block.offsetHeight){
			jQuery(block).hide('normal');
			U.gbi(block_id+'Link').className='rarr';
		}else{
			jQuery(block).show('normal');
			U.gbi(block_id+'Link').className='darr';
 		}
	},

	tariffsPrepare: function(){
		/*
			функция осуществляет подготовку ЦЕЛОГО блока тарифов к анимации - 
			ей необходимо увеличить высоту блока тарифов таким образом, чтобы 
			поместился самый высокий по контенту блок тарифов, когда он будет показан

			у каждого тарифа есть заголовок и цены 
			высота ЦЕЛОГО БЛОКА складывается из высот заголовков ВСЕХ тарифов 
			ПЛЮС высота самого высокого блока цен

			чтобы яваскрипт определил высоты всех тарифов нужно чтобы все они были display:block
			ТАКИМ ОБРАЗОМ ДЕЛАЕМ ВОТ ЧТО:
			1. после показа всех заголовков и первого развернутого тарифа нужно определить текущую 
			   высоту ЦЕЛОГО блока, зафиксировать ее в стилях и добавить свойство overflow:hidden
			2. наделить блоки с ценами (все кроме первого) свойствами position:absolute; visibility:hidden; display:block 
			   и измерить их высоту, 
			3. определить самый высокий блок цен, затем поменять свойства не прежние 
			4. вычислить высоту ЦЕЛОГО БЛОКА, установить ее
			5. изменить высоты всех остальных блоков (включающих название тарифа и цены), 
			   доведя ее до максимальной
		*/
		//action 1
			var alltariffs_block=jQuery('#tariffsOverview .alltariffs').get(0);
			var alltariffs_block_height=jQuery(alltariffs_block).height();
			jQuery(alltariffs_block).height(alltariffs_block_height);
			jQuery(alltariffs_block).css('overflow','hidden');
		//action 2
			var tariffs_arr_except_first=jQuery('.tariff',alltariffs_block).gt(0);
			jQuery('.price',tariffs_arr_except_first).css('position','absolute');
			jQuery('.price',tariffs_arr_except_first).css('visibility','hidden');
			jQuery('.price',tariffs_arr_except_first).css('display','block');
		//action 3
			C.max_height=0;
			jQuery(tariffs_arr_except_first).each(function(){
				var current_height=jQuery('.price',this).height();
				if(current_height>C.max_height){
					C.max_height=current_height;
				}
			});
			jQuery('.price',tariffs_arr_except_first).height(0);
			jQuery('.price',tariffs_arr_except_first).css('display','');
			jQuery('.price',tariffs_arr_except_first).css('visibility','');
			jQuery('.price',tariffs_arr_except_first).css('position','');
		//action 4
			var first_tariff_height=jQuery('.price',alltariffs_block).eq(0).height();
			var new_height=alltariffs_block_height - first_tariff_height + C.max_height;
			jQuery(alltariffs_block).height(new_height);
		//action 5
			var tariff_first=jQuery('.tariff',alltariffs_block).get(0);
			jQuery('.price',tariff_first).height(C.max_height);
			jQuery(alltariffs_block).css('overflow','visible');
	},

	showTariff: function(id_to_show){
		if(C.tariff_moving){
			return;
		}
		//определяем, является ли блок цен текущего тарифа скрытым,
		//если да, то определяем текущий видимый блок и запускаем C.showTariffUni()
		if(jQuery('#'+id_to_show+' .price').height()==0){
			var all_tariffs=jQuery('#tariffsOverview .tariff').get();
			for(var i=0; i<all_tariffs.length; i++){
				if(jQuery('.price',all_tariffs[i]).height()>0){
					var id_to_hide=jQuery(all_tariffs[i]).attr('id');
					break;
				}
			}
			C.tariff_moving=true;
			C.showTariffUni(id_to_show,id_to_hide);
		}
	},

	showTariffUni: function(id_to_show,id_to_hide){
		var price_to_show=jQuery('#'+id_to_show+' .price');
		var price_to_hide=jQuery('#'+id_to_hide+' .price');
		jQuery(price_to_show).height(0);
		jQuery(price_to_show).css('display','block');
		setTimeout('C.animateTariff("'+id_to_show+'","'+id_to_hide+'","0")',25);
	},

	animateTariff: function(id_to_show,id_to_hide,time){
		var time=parseInt(time)+25;
		var duration=100;
		if(time<=duration){
			var id_to_show_height=jQuery.easing.linearTween(null,time,0,C.max_height,duration);
			jQuery('#'+id_to_show+' .price').height(id_to_show_height);
			jQuery('#'+id_to_hide+' .price').height((C.max_height-id_to_show_height));
			setTimeout('C.animateTariff("'+id_to_show+'","'+id_to_hide+'","'+time+'")',25);
		}else{
			jQuery('#'+id_to_show+' h5').removeClass('closed');
			jQuery('#'+id_to_show+' h5').addClass('opened');
			jQuery('#'+id_to_hide+' h5').removeClass('opened');
			jQuery('#'+id_to_hide+' h5').addClass('closed');
			C.tariff_moving=false;
		}
	},

	try2sendCheckplugForm: function(form,hash){
		var form=(form || document.forms['checkplugForm']);
		if(!hash){
			var hash={};
			//передана форма; вытаскиваем параметры, какие уже имеются
			var es=form.elements;
			if(es['street_like'])
				hash.street_like=es['street_like'].value;
			if(es['street_name'])
				hash.street_name=es['street_name'].value;
			if(es['city_id'])
				hash.city_id=es['city_id'].value;
		}
		if(hash.city_id.indexOf('http')==0){
			location.href=hash.city_id;
		}
		$.get('./?ajax=2', hash,
			function(data){
				//alert(data);
				jQuery('#plugBlock').parent().empty().append(data);
			}
		);
		if(hash.house_id){
			jQuery('#houseloadergif').empty();
		}else if(hash.street_id || hash.street_like || hash.street_like_bak){
			jQuery('#streetloadergif').empty();
		}else{
			jQuery('#cityloadergif').empty();
		}
		return false;
	},

	try2sendFinalForm: function(form){
		var hash=jQuery('#plugFinalForm').formToArray();
		$.post('./?ajax=2', hash,
			function(data){
				jQuery('#plugBlock').parent().empty().append(data);
				if(jQuery('#finalformloadergif').length){
					//неудачная отправка формы, прокручиваем страницу к сообщению о возникшей ошибке
					var y=U.layerY('finalformloadergif');
					window.scrollTo(0,y);
				}else{
					//удачаня отправка формы, пишем напоминание не забыть распечатать или сохранить 
					jQuery('#dontforget').append('<p>Обязательно <a class="ora" href="javascript:C.putUsersData(\'save\')">сохраните</a>, <a class="ora" href="javascript:C.putUsersData(\'print\')">распечатайте</a> или перепишите данные вашего заказа.</p>');
				}
			}
		);
		jQuery('#finalformloadergif').empty();
		return false;
	},

	putUsersData: function(method){
		var users_data=jQuery('#usersDataBlock').html();
		var ticket=jQuery('#usersTicket').text();
		var instruction=(method=='save')
			?'<p class="instruction"><small>Для того, чтобы сохранить страницу, выберите в меню опции <b>Файл &rarr; Сохранить как&hellip;<\/b> (<b>File &rarr; Save as&hellip;<\/b>)<br>Затем выберите папку, в которой файл будет сохранен.<\/small><\/p>'
			:'';
		var win=window.open('','_blank');
		try{
			win.focus();
			win.document.open("text/html");
			win.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 //EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=Windows-1251"><title>Заявка на интернет-подключение №'+ticket+'<\/title>');
			win.document.writeln('<style type="text/css">body{padding:20px;}td{padding:0 100px 0 0;}.instruction{float:left;padding:10px;background-color:#ccc;}<\/style>');
			win.document.writeln('<\/head><body><h4>Заявка на подключение успешно создана!<\/h4>'+users_data+instruction+'<\/body><\/html>');
			win.document.close();
			if(method=='print')
				win.print();
		}catch(e){}
	},

	_f: function(){
	}

}

U.addEvent(document,'click',C.hideChangeCityArr);
U.addEvent(document,'click',C.hideCheckplugCityArr);