var changeSum = false;

$("#tf_s1").click(function() {


	if(document.getElementById('s1a').style.display == 'none')
	$('#s1a').show();
	else
	$('#s1a').hide();

	$('#s2a').hide();
	$('#s3a').hide();
	$('#s4a').hide();

	return false;

});
$("#tf_s1_").click(function() {


	if(document.getElementById('s1a').style.display == 'none')
	$('#s1a').show();
	else
	$('#s1a').hide();

	$('#s2a').hide();
	$('#s3a').hide();
	$('#s4a').hide();

	return false;

});





$("#tf_s2").click(function() {

	if(document.getElementById('s2a').style.display == 'none')
	$('#s2a').show();
	else
	$('#s2a').hide();

	$('#s1a').hide();
	$('#s3a').hide();
	$('#s4a').hide();
	$('#s7a').hide();

	return false;

});

$("#tf_s2_").click(function() {

	if(dontSelectVal && $('#tff7').val() != 'strah' && $('#tff7').val() != 'ip') {
		var msg = '<div style="text-align:center;font-size:17px;margin-top:30px">В настоящий момент в Беларуси частные лица могут взять кредит только в белорусских рублях</div>';
		xAlert(msg,-150,150);
		
		return false;
	}

	if(document.getElementById('s2a').style.display == 'none')
	$('#s2a').show();
	else
	$('#s2a').hide();



	$('#s1a').hide();
	$('#s3a').hide();
	$('#s4a').hide();

	return false;

});

$("#tf_s3").click(function() {

	if(document.getElementById('s3a').style.display == 'none')
	$('#s3a').show();
	else
	$('#s3a').hide();

	$('#s1a').hide();
	$('#s2a').hide();
	$('#s4a').hide();

	return false;
});

$("#tf_s3_").click(function() {

	if(document.getElementById('s3a').style.display == 'none')
	$('#s3a').show();
	else
	$('#s3a').hide();

	$('#s1a').hide();
	$('#s2a').hide();
	$('#s4a').hide();

	return false;
});

$("#tf_s4").click(function() {

	if(document.getElementById('s4a').style.display == 'none')
	$('#s4a').show();
	else
	$('#s4a').hide();

	$('#s1a').hide();
	$('#s2a').hide();
	$('#s3a').hide();

	return false;
});
$("#tf_s4_").click(function() {

	if(document.getElementById('s4a').style.display == 'none')
	$('#s4a').show();
	else
	$('#s4a').hide();

	$('#s1a').hide();
	$('#s2a').hide();
	$('#s3a').hide();

	return false;
});

$("#tf_s7").click(function() {

	alert(7);
	if(document.getElementById('s7a').style.display == 'none')
	$('#s7a').show();
	else
	$('#s7a').hide();

	$('#s1a').hide();
	$('#s2a').hide();
	$('#s4a').hide();

	return false;
});

$("#tf_s7_").click(function() {

	if(document.getElementById('s7a').style.display == 'none')
	$('#s7a').show();
	else
	$('#s7a').hide();

	$('#s1a').hide();
	$('#s2a').hide();
	$('#s4a').hide();

	return false;
});

function sp(s,e) {

	var a,v;

	var t = $('#sp'+s+e).html();


	if(s == 1) {

		if(e==5) {

			$('#lb1').html('Застраховать на');
			$('#nnna').html('Год выпуска');
		}
		else {
			$('#lb1').html('Мне нужно');
			$('#nnna').html('Сроком на');
		}


		if(e == 1) {
			dontSelectVal = 1;
			svoySrokOtmena();

			//сроки авто
			$('#sp42').hide();
			$('#sp43').hide();
			$('#sp44').show();
			$('#sp45').show();
			$('#sp46').show();
			$('#sp47').hide();
			$('#sp48').hide();
			$('#sp49').hide();
			$('#sp410').hide();
			$('#sp411').hide();
			$('#sp412').hide();
			$('#sp413').hide();
			$('#sp414').hide();
			$('#sp415').hide();


			
			
			if(!changeSum) {
				$('#tfi1').val('20 000 000');
				$('#tff2').val(20000000);
			}
			//срок по умолчанию
			$('#tf_s4').html('пока не знаю');
			$('#tff3').val(0);


			$('#tff7').val('auto');
			$('#tff12').val('0');
			a = '/kredit/auto/';
		}
		if(e == 2) {
			dontSelectVal = 1;
			svoySrokOtmena();

			//сроки потребительский
			$('#sp42').show();
			$('#sp43').show();
			$('#sp44').show();
			$('#sp45').hide();
			$('#sp46').show();
			$('#sp47').hide();
			$('#sp48').hide();
			$('#sp49').hide();
			$('#sp410').hide();
			$('#sp411').hide();
			$('#sp412').hide();
			$('#sp413').hide();
			$('#sp414').hide();
			$('#sp415').hide();


			if(!changeSum) {
			$('#tfi1').val('3 000 000');
			$('#tff2').val(3000000);
			}
			$('#tff7').val('potr');
			a = '/kredit/potr/';

			//срок по умолчанию
			$('#tf_s4').html('пока не знаю');
			$('#tff3').val(0);
		}
		if(e == 3) {
			dontSelectVal = 1;
			svoySrokOtmena();

			//сроки недвижимость
			$('#sp42').hide();
			$('#sp43').hide();
			$('#sp44').hide();
			$('#sp45').hide();
			$('#sp46').hide();
			$('#sp47').show();
			$('#sp48').show();
			$('#sp49').show();
			$('#sp410').hide();
			$('#sp411').hide();
			$('#sp412').hide();
			$('#sp413').hide();
			$('#sp414').hide();
			$('#sp415').hide();


			if(!changeSum) {
			$('#tfi1').val('100 000 000');
			$('#tff2').val(100000000);
			}
			$('#tff7').val('real');
			a = '/kredit/real/';
			//срок по умолчанию
			$('#tf_s4').html('пока не знаю');
			$('#tff3').val(0);

		}
		if(e == 6) {
			svoySrokOtmena();
			dontSelectVal = 1;

			//сроки на малый бизнес
			$('#sp42').hide();
			$('#sp43').show();
			$('#sp44').show();
			$('#sp45').show();
			$('#sp46').show();
			$('#sp47').hide();
			$('#sp48').hide();
			$('#sp49').hide();
			$('#sp410').hide();
			$('#sp411').hide();
			$('#sp412').hide();
			$('#sp413').hide();
			$('#sp414').hide();
			$('#sp415').hide();

			if(!changeSum) {
			$('#tfi1').val('30 000 000');
			$('#tff2').val(30000000);
			}

			$('#tff7').val('ip');
			a = '/kredit/ip/';

			//срок по умолчанию
			$('#tf_s4').html('пока не знаю');
			$('#tff3').val(0);
		}

		if(e == 4) {
			dontSelectVal = 0;
			svoySrokOtmena();

			//сроки депозит
			$('#sp42').hide();
			$('#sp43').hide();
			$('#sp44').hide();
			$('#sp45').hide();
			$('#sp46').hide();
			$('#sp47').hide();
			$('#sp48').hide();
			$('#sp49').hide();
			$('#sp410').show();
			$('#sp411').show();
			$('#sp412').show();
			$('#sp413').show();
			$('#sp414').show();
			$('#sp415').show();

			if(!changeSum) {
			$('#tfi1').val('1 000 000');
			$('#tff2').val(1000000);
			}
			$('#tff7').val('vklad');
			a = '/depozit/vklad/';

			//срок по умолчанию
			$('#tf_s4').html('90 дней');


		}
		if(e == 5) {
			//			svoySrokOtmena();

			//сроки страховка
			$('#sp42').hide();
			$('#sp43').hide();
			$('#sp44').hide();
			$('#sp45').hide();
			$('#sp46').hide();
			$('#sp47').hide();
			$('#sp48').hide();
			$('#sp49').hide();
			$('#sp410').show();
			$('#sp411').show();
			$('#sp412').show();
			$('#sp413').show();
			$('#sp414').show();
			$('#sp415').show();


			$('#tff7').val('strah');
			a = '/insurance/auto/';

		}

		if(e == 4) {
			$('#tft2').html('дн.');
			$('#tfi2').val(90);
			$('#tff3').val(90);
			$('#tff6').val(30);
		}
		else {
//			$('#tft2').html('мес.');
//			$('#tff3').val(12);
		}

		if(e == 5 || e == 7) {
			
			if(e==5) {
				$('#tfhidd2').show();
				$('#tfhidd1').hide();
				$('#tfhidd7').hide();
				$('#tff1').val('227');
				$('#tff2_valute').val(227);
				$('#tff0_valute').val(227);
	
				$('#tff11').val('2005');
				$('#tf_s3').html('2005');
	
	
				$('#tf00').show();
	
				//			$('#tfi1').css("margin-left", "215px");
				$('#tfs2').css("margin-left", "300px");
	
				$('#tf_s2').html('долл.')
				if(!changeSum) {
				$('#tfi1').val('10 000');
				$('#tff2').val(10000);
				}
				}
				//денежные переводы
			else {
				dontSelectVal = 0;
				
				$('#tfhidd7').show();
				$('#tfhidd2').hide();
				$('#tfhidd1').hide();
				$('#nnna').html('Куда?');
				$('#lb1').html('из Беларуси');
				if(!changeSum) {
				$('#tfi1').val(500);
				$('#tff777').val(500);
				}
				$('#tf_s2').html('долл.');
				$('#tff1').val(227);
				$('#tff0_valute').val(227);
				$('#tff2_valute').val(227);
				a = '/perevody/';

				
			}
		}
		else {
			
			
			$('#tff2_valute').val(229);
			$('#tff0_valute').val(229);
			$('#tff1').val(229);
			
			$('#tf00').show();
			//			$('#tfi1').css("margin-left", "199px");
			$('#tfs2').css("margin-left", "285px");

			$('#tf00').hide();


			$('#tf_s2').html('бел.руб.')

			//			$('#tfi1').val('2 000 000');


			$('#tfhidd1').show();
			$('#tfhidd2').hide();
			$('#tfhidd7').hide();
			//			$('#tff2').val(3000000);

			//			$('#tff1').val() = $('#tfi1').html();
		}


		$('#tff10').val(e);

		document.top_form.action =a;
		$('#tf_s1').html(t);
		$('#s1a').hide();
	}
	if(s == 2) {

		if(e == 1) v = 227;
		if(e == 2) v = 228;
		if(e == 3) v = 229;
		if(e == 4) v = 230;

		$('#tff1').val(v);



		$('#tff2_valute').val(v);
		$('#tff0_valute').val(v);


		$('#tf_s2').html(t);
		$('#s2a').hide();
	}
	if(s == 4) {

		if(e == 1) v = 0;
		if(e == 2) v = 12;
		if(e == 3) v = 24;
		if(e == 4) v = 36;
		if(e == 5) v = 48;
		if(e == 6) v = 60;

		if(e == 7) v = 120;
		if(e == 8) v = 180;
		if(e == 9) v = 240;
		if(e == 10) v = 30;
		if(e == 11) v = 60;
		if(e == 12) v = 90;
		if(e == 13) v = 120;
		if(e == 14) v = 360;
		if(e == 15) v = 95;



		$('#tff3').val(v);
		//		$('#tff2_valute').val(v);
		//		$('#tff0_valute').val(v);
		$('#tf_s4').html(t);
		$('#s4a').hide();
	}



}

tfsubmit = function() {



	if($('#tfi1_sr2').val() && type !=4) {
		$('#tff3').val($('#tfi1_sr2').val());
	}
	else {
		$('#tff6').val($('#tfi1_sr2').val());
	}


	var type = $('#tff10').val();

	if(!trim($('#tfi1').val())) {
		$('#tferr').html('заполните сумму!');
		return false
	}


	if(!validate_num_space($('#tfi1').val())) {
		$('#tferr').html('введите число!');
		return false
	}


	$('#tferr').html('');


	if(type == 1) {


		$('#tff0').remove();
		$('#tff11').remove();
		$('#tff2_valute').remove();
		$('#tff0_valute').remove();
		$('#tfff7').remove();

	}

	if(type == 2) {

		$('#tff0').val(1241);
		//		$('#tff0').remove();
		$('#tff11').remove();
		$('#tff2_valute').remove();
		$('#tff0_valute').remove();
		$('#tff9').remove();

	}


	if(type == 3) {

		$('#tff0').remove();
		$('#tff11').remove();
		$('#tff2_valute').remove();
		$('#tff0_valute').remove();
		$('#tff9').remove();
		$('#tfff7').remove();

	}


	if(type == 1 || type == 2 || type == 3) {

		if($('#tff1').val() == 229) {

			$('#tff12').remove();

		}
		$('#tff20').remove();

	}




	if(type == 4) {



		$('#tfff7').remove();
		$('#tff8').remove();

		//		return false;
		var sum = $('#tff2').val();
		var srok = $('#tff3').val();
		//
//		if(!$('#tfi1_sr2').val()) {
//			srok = srok * 30;
//		}
	


		var valut = $('#tff1').val();

		$('#tff5').val(sum);
		$('#tff6').val(srok);
		$('#tff3').val(valut);

		$('#tff0').remove();
		$('#tff1').remove();
		$('#tff11').remove();
		$('#tff12').remove();
		$('#tff2').remove();
		$('#tff2_valute').remove();
		$('#tff0_valute').remove();
		$('#tff9').remove();

	}


	if(type == 5) {





		var sum = $('#tff2').val();


		var valuta = $('#tff2_valute').val();

		if(valuta == 227)
		$('#tff12').remove();






		$('#tff2').val(sum);
		$('#tff0').val(sum);



		$('#tff1').val($('#tff11').val());




		$('#tff0').val(remSpace($('#tff0').val()));
		$('#tff2').val(remSpace($('#tff2').val()));

		$('#tff11').remove();
		$('#tff3').remove();
		$('#tfff7').remove();
		$('#tff8').remove();
		$('#tff9').remove();


	}
	
	if(type == 7) {

		$('#tff777').val($('#tfi1').val());
		$('#tff7777').val($('#tff2_valute').val());
		
		if($('#tff2_valute').val() == '227')
		$('#tff7777').val(1);
		if($('#tff2_valute').val() == '228')
		$('#tff7777').val(2);
		if($('#tff2_valute').val() == '229')
		$('#tff7777').val(3);
		if($('#tff2_valute').val() == '230')
		$('#tff7777').val(4);

		
		
		
		
		$('#tff0').remove();
    	$('#tff2_valute').remove();
    	$('#tff0_valute').remove();
    	$('#tff2').remove();
    	$('#tff1').remove();
    	$('#tff12').remove();
    	$('#tff11').remove();
    	$('#tff3').remove();
    	$('#tff5').remove();
    	$('#tff6').remove();
    	$('#tfff7').remove();
    	$('#tff9').remove();
    	$('#tff8').remove();
    	$('#tff20').remove();
	            	

	}

	wait(1,1);
	$('#top_form').submit();


}

function svoySrok() {

	$('#tfhidd1').hide();
	$('#sroka2').show();
	foc('tfi1_sr2');

	if($('#tff7').val() == 'vklad') {
		$('#nnna').html('На срок (дней)');
	}
	else {
		$('#nnna').html('На срок (месяцев)');
	}

}

function svoySrokOtmena() {
	$('#tfhidd1').show();
	$('#sroka2').hide();
	if($('#tff7').val() != 'strah')
	$('#nnna').html('Сроком на');
	$('#tfi1_sr2').val('');
	$('#tf_s4').html('пока не знаю');
	$('#tff3').val(0);
}

function chY(y) {
	$('#tf_s3').html(y);
	$('#tff11').val(y);
	$('#s3a').hide();
}


function chC(contry,c) {
	$('#tf_s7').html(contry);
	$('#tff77').val(c);
	$('#s7a').hide();
	if(c == '0')
	tfsubmit();
	
}
