﻿var style = 'gray_pohydeli.css';
/* chizh */
var loadingLinesInterval = undefined;
var loadingPercentInterval = 0;
var loadingPercentNum = [];
var loadingPercentStopNum = 0;
var loadingPercentStep = 0;
var loadingPercentElem = 0;
var form_default_value = new String();

statusLines = [];


var menuArray = [
	'Первый день',
		'Первый день',
			'Первый день',
	'Второй день',
	'Второй день',
		'Второй день',
'Третий день',
'Третий день',
'Третий день',
'Четвертый день',
'Четвертый день',
'Четвертый день',

'Пятый день',
'Пятый день',
'Пятый день',

'Шестой день',
'Шестой день',
'Шестой день',

'Седьмой день',
'Седьмой день',
'Седьмой день'

];
var daysArray = [
'сухарик с чаем или черным кофе',	
'2 яйца, сваренных вкрутую, 80 г, заправленного ложечкой масла, шпината и помидор',	
'одна котлета и 150 г салата из помидоров и зеленого лука с небольшим количеством масла',	
'чай или кофе',	
'200 г морковки варенной и одно яйцо, сваренное вкрутую',	
'250 г салата из мандарина, груши, яблока, банана или иных фруктов',	
'стакан яблочного сока натурального',	
'250 г рыбы, отварной или жаренной, 1 яблоко, 1 помидор',	
'одна мясная котлета с гарниром',	
'стакан сока морковного',	
'100 г салата из зелени, 200 г жареной курицы',	
'2 яйца сваренных вкрутую, 100 г, заправленной маслом, тертой морковки',
'сухарик с чаем без сахара',
'200 г жареного мяса и 150 г, заправленного лимонным соком, салата из капусты',	
'150 г сыра и 100 г, заправленной маслом, тертой моркови',	
'стакан сока морковного',
'200 г курицы, отварной или жареной',	
'300 г различных фруктов'	
	
];


nextStatusLine = function( SLIndex ){
	var next = Math.round( Math.random() * statusLines[SLIndex].array.length );
	jQuery( statusLines[SLIndex].elem ).text( statusLines[SLIndex].array[next] );
}

startStatusLine = function( element, actArray ){
	statusLines.push({
		elem: element,
		array: actArray,
		interval: false
	});
	var statusLineIndex = statusLines.length - 1;
	statusLines[statusLineIndex].interval = setInterval( function(){ nextStatusLine(statusLineIndex); }, 30 );
	
	return statusLineIndex;
}
stopStatusLine = function( SLIndex ){
	jQuery( statusLines[SLIndex].elem ).hide(0);
	clearInterval( statusLines[SLIndex].interval );
}
pauseStatusLine = function( SLIndex ){
	clearInterval( statusLines[SLIndex].interval );
}

function loadingLineMove( loadingLines ){
	if (!jQuery.browser.msie){
		var posXBg = parseInt( jQuery(loadingLines).css('backgroundPosition') );
		if ( posXBg < -27 ){
			jQuery(loadingLines).css({'backgroundPosition':'-3px 4px'});
		}else{
			jQuery(loadingLines).css({'backgroundPosition':posXBg-2+'px 4px'});
		}
	}
	//jQuery(loadingLines).animate( { 'backgroundPosition': '27px 4px' }, 1000, 'linear', function(){ loadingLineMove( loadingLines ); } );
}
function loadingPercentSet(indexLPN){
	loadingPercentNum[indexLPN].num++;
	if ( loadingPercentNum[indexLPN].stopNum <= loadingPercentNum[indexLPN].num ){
		clearInterval(loadingPercentNum[indexLPN].interval);
		jQuery(loadingPercentNum[indexLPN].elem).text(loadingPercentNum[indexLPN].stopNum);
	}else{
		jQuery(loadingPercentNum[indexLPN].elem).text(loadingPercentNum[indexLPN].num);
	}
}
function loadingPercentStart(elem, startNum, stopNum, delay){
	//clearInterval(loadingPercentInterval);
	loadingPercentNum.push({
		elem: elem,
		startNum: startNum,
		stopNum: stopNum,
		interval: false,
		num: startNum
	});
	var indexLPN = loadingPercentNum.length - 1;
	var nums = stopNum - startNum;
	var loadingPercentStep = Math.round( delay / nums );
	
	loadingPercentNum[indexLPN].interval = setInterval( function(){ loadingPercentSet(indexLPN) }, loadingPercentStep );
	return indexLPN;
}
function makeDietAnimate(){
	var loadingLines = jQuery('#afterTestScene .loadingLine .line');
	jQuery('#afterTestScene .loadingLine').css({'overflow': 'hidden'});
	loadingLinesInterval = setInterval( function(){ loadingLineMove( loadingLines ); }, 50 );
	var elem = jQuery('#afterTestScene>div.step1>div.loadingPercent>span.num');
	var elem2 = jQuery('#afterTestScene>div.step2>div.loadingPercent>span.num');
	var elem3 = jQuery('#afterTestScene>div.step3>div.loadingPercent>span.num');
	
	loadingPercentStart(elem, 7, 15, 500);
	jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'15%'}, 500, 'linear');
	
	
	setTimeout( function(){ //Сколько килограмм Вы хотели бы потерять
		var inputVal = parseInt( jQuery('input:checked[name="dinamikavesa"]').attr('value') );
		switch( inputVal ){
			case 1:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Ваш излишний вес: <strong>до 3кг</strong></p>');
			break;
			case 2:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Ваш излишний вес: <strong>до 5 кг</strong></p>');
			break;
			case 3:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Ваш излишний вес: <strong>до 10 кг</strong></p>');
			break;
			case 4:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Ваш излишний вес: <strong>до 20 кг</strong></p>');
			break;
			case 5:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Ваш излишний вес: <strong>до 30 кг</strong></p>');
			break;
			case 6:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Ваш излишний вес: <strong>до 30 кг</strong></p>');
			break;
		}
		loadingPercentStart(elem, 15, 23, 500);
		jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'23%'}, 500, 'linear');
	}, 500 );

	setTimeout( function(){ //Ваш пол
		var inputVal = parseInt( jQuery('input:checked[name="pol"]').attr('value') );
		switch( inputVal ){
			case 1:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный пол: <strong>женский</strong></p>');
			break;
			case 2:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный пол: <strong>мужской</strong></p>');
			break;
		}
		loadingPercentStart(elem, 23, 30, 500);
		jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'30%'}, 500, 'linear');
	}, 1000 );

	setTimeout( function(){ //Ваш возраст
		var inputVal = parseInt( jQuery('select[name="vozrast"]').attr('value') );
		switch( inputVal ){
			case 17:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный возраст: <strong>менее 18 лет</strong></p>');
			break;
			case 71:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный возраст: <strong>более 70 лет</strong></p>');
			break;
			default:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный возраст: <strong>'+inputVal+' лет</strong></p>');
		}
		loadingPercentStart(elem, 30, 35, 500);
		jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'35%'}, 500, 'linear');
	}, 1500 );

	setTimeout( function(){ //Ваш вес на данный момент
		var inputVal = parseInt( jQuery('select[name="ves"]').attr('value') );
		switch( inputVal ){
			case 39:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный вес: <strong>менее 40 кг</strong></p>');
			break;
			case 121:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный вес: <strong>более 120 кг</strong></p>');
			break;
			default:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный вес: <strong>'+inputVal+' кг</strong></p>');
		}
		loadingPercentStart(elem, 35, 40, 500);
		jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'40%'}, 500, 'linear');
	}, 2000 );

	setTimeout( function(){ //Ваш рост (см)
		var inputVal = parseInt( jQuery('select[name="visota"]').attr('value') );
		switch( inputVal ){
			case 149:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный рост: <strong>менее 150 см</strong></p>');
			break;
			case 201:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный рост: <strong>более 200 см</strong></p>');
			break;
			default:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранный рост: <strong>'+inputVal+' см</strong></p>');
		}
		loadingPercentStart(elem, 40, 45, 500);
		jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'45%'}, 500, 'linear');
	}, 2500 );

	setTimeout( function(){ //Ваша группа крови
		var inputVal = parseInt( jQuery('input:checked[name="gruppakrovi"]').attr('value') );
		switch( inputVal ){
			case 0:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранная группа крови: <strong>не известна</strong></p>');
			break;
			default:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Выбранная группа крови: <strong>'+inputVal+' группа</strong></p>');
		}
		loadingPercentStart(elem, 45, 50, 500);
		jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'50%'}, 500, 'linear');
	}, 3000 );

    setTimeout( function(){ //Страдаете ли Вы от аллергических реакций на пищу
        var inputVal = parseInt( jQuery('input:checked[name="allerg"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Есть ли пищевые аллергии: <strong>есть, незначительная</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Есть ли пищевые аллергии: <strong>есть</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Есть ли пищевые аллергии: <strong>есть, много на что</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Есть ли пищевые аллергии: <strong>нет</strong></p>');
        }
        loadingPercentStart(elem, 50, 55, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'55%'}, 500, 'linear');
    }, 3500 );

    setTimeout( function(){ //Как часто Вы занимаетесь спортом
        var inputVal = parseInt( jQuery('input:checked[name="rabota"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы занимаетесь спортом: <strong>часто</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы занимаетесь спортом: <strong>иногда</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы занимаетесь спортом: <strong>редко</strong></p>');
            break;
            case 4:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы занимаетесь спортом: <strong>никогда</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы занимаетесь спортом: <strong>никогда</strong></p>');
        }
        loadingPercentStart(elem, 55, 60, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'60%'}, 500, 'linear');
    }, 4000 );

    setTimeout( function(){ //Страдают ли от лишнего веса Ваши родственники
        var inputVal = parseInt( jQuery('input:checked[name="vesrod"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Страдают ли от лишнего веса Ваши родственники: <strong>да, многие</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Страдают ли от лишнего веса Ваши родственники: <strong>да, некоторые</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Страдают ли от лишнего веса Ваши родственники: <strong>нет</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Страдают ли от лишнего веса Ваши родственники: <strong>нет</strong></p>');
        }
        loadingPercentStart(elem, 60, 65, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'65%'}, 500, 'linear');
    }, 4500 );

    setTimeout( function(){ //Испытываете ли Вы непреодолимую тягу к сладкому, жирному, мучному
        var inputVal = parseInt( jQuery('input:checked[name="eda"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Испытываете ли Вы непреодолимую тягу к сладкому, жирному, мучному: <strong>да, не могу удержаться</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Испытываете ли Вы непреодолимую тягу к сладкому, жирному, мучному: <strong>да, иногда</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Испытываете ли Вы непреодолимую тягу к сладкому, жирному, мучному: <strong>нет</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Испытываете ли Вы непреодолимую тягу к сладкому, жирному, мучному: <strong>нет</strong></p>');
        }
        loadingPercentStart(elem, 65, 70, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'70%'}, 500, 'linear');
    }, 5000 );

    setTimeout( function(){ //Сколько раз в день Вы едите
        var inputVal = parseInt( jQuery('input:checked[name="em"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Сколько раз в день Вы едите: <strong>2 раза</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Сколько раз в день Вы едите: <strong>3 раза</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Сколько раз в день Вы едите: <strong>4 раза</strong></p>');
            break;
            case 4:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Сколько раз в день Вы едите: <strong>5 и более раз</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Сколько раз в день Вы едите: <strong>5 и более раз</strong></p>');
        }
        loadingPercentStart(elem, 70, 75, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'75%'}, 500, 'linear');
    }, 5500 );

    setTimeout( function(){ //Соблюдаете ли Вы режим питания или перекусываете по мере возможности
        var inputVal = parseInt( jQuery('input:checked[name="rejim"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Соблюдаете ли Вы режим питания или перекусываете по мере возможности: <strong>ем в одно и то же время</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Соблюдаете ли Вы режим питания или перекусываете по мере возможности: <strong>не всегда удаётся</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Соблюдаете ли Вы режим питания или перекусываете по мере возможности: <strong>«как придётся»</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Соблюдаете ли Вы режим питания или перекусываете по мере возможности: <strong>«как придётся»</strong></p>');
        }
        loadingPercentStart(elem, 75, 80, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'80%'}, 500, 'linear');
    }, 6000 );

    setTimeout( function(){ //Какие блюда Вы употребляете чаще
        var inputVal = parseInt( jQuery('input:checked[name="bluda"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Какие блюда Вы употребляете чаще: <strong>варёные</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Какие блюда Вы употребляете чаще: <strong>тушёные</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Какие блюда Вы употребляете чаще: <strong>запечённые</strong></p>');
            break;
            case 4:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Какие блюда Вы употребляете чаще: <strong>жареные</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Какие блюда Вы употребляете чаще: <strong>жареные</strong></p>');
        }
        loadingPercentStart(elem, 80, 85, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'85%'}, 500, 'linear');
    }, 6500 );

    setTimeout( function(){ //Как часто Вы употребляете свежие овощи
        var inputVal = parseInt( jQuery('input:checked[name="svej"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы употребляете свежие овощи: <strong>каждый день</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы употребляете свежие овощи: <strong>2-3 раза в неделю</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы употребляете свежие овощи: <strong>раз в неделю</strong></p>');
            break;
            case 4:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы употребляете свежие овощи: <strong>крайне редко</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Как часто Вы употребляете свежие овощи: <strong>крайне редко</strong></p>');
        }
        loadingPercentStart(elem, 85, 90, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'90%'}, 500, 'linear');
    }, 7000 );

    setTimeout( function(){ //Часто ли у Вас случаются стрессы
        var inputVal = parseInt( jQuery('input:checked[name="stress"]').attr('value') );
        switch( inputVal ){
            case 1:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Часто ли у Вас случаются стрессы: <strong>часто, сильные</strong></p>');
            break;
            case 2:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Часто ли у Вас случаются стрессы: <strong>часто</strong></p>');
            break;
            case 3:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Часто ли у Вас случаются стрессы: <strong>иногда</strong></p>');
            break;
            case 4:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Часто ли у Вас случаются стрессы: <strong>нет</strong></p>');
            break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Часто ли у Вас случаются стрессы: <strong>нет</strong></p>');
        }
        loadingPercentStart(elem, 90, 95, 500);
        jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'95%'}, 500, 'linear');
    }, 7500 );

	setTimeout( function(){ //Курите ли Вы
		var inputVal = parseInt( jQuery('input:checked[name="kur"]').attr('value') );
		switch( inputVal ){
			case 1:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Курите ли Вы: <strong>да</strong></p>');
			break;
			case 2:
				jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Курите ли Вы: <strong>нет</strong></p>');
			break;
            default:
                jQuery('#afterTestScene .step1 .infoOfStage').append('<p>Курите ли Вы: <strong>нет</strong></p>');
		}
		loadingPercentStart(elem, 95, 100, 500);
		jQuery('#afterTestScene>div.step1>div.loadingLine>div.line').animate({'width':'100%'}, 500, 'linear');
	}, 8000 );	
	
	setTimeout( function(){ 
		jQuery('#afterTestScene .step1 .loadingLine').slideUp(100);
		jQuery('#afterTestScene .step1 .loadingPercent').slideUp(100);
		jQuery('#afterTestScene .step2').slideDown(300);
		loadingPercentStart(elem2, 0, 20, 2000);
		jQuery('#afterTestScene>div.step2>div.loadingLine>div.line').animate({'width':'20%'}, 2000, 'linear');
	}, 8000 );
	setTimeout( function(){ 
		jQuery('#afterTestScene .step2 .infoOfStage').append('<p>Подбор конкретных продуктов питания.........<font color="#78CD14">OK</font></p>');
		loadingPercentStart(elem2, 21, 40, 2000);
		jQuery('#afterTestScene>div.step2>div.loadingLine>div.line').animate({'width':'40%'}, 2000, 'linear');
	}, 10000 );
	setTimeout( function(){ 
		jQuery('#afterTestScene .step2 .infoOfStage').append('<p>Подбор подходящего режима питания...........<font color="#78CD14">OK</font></p>');
		loadingPercentStart(elem2, 40, 66, 2000);
		jQuery('#afterTestScene>div.step2>div.loadingLine>div.line').animate({'width':'60%'}, 2000, 'linear');
	}, 12000 );
	setTimeout( function(){ 
		jQuery('#afterTestScene .step2 .infoOfStage').append('<p>Расчет интервалов приёма пищи...............<font color="#78CD14">OK</font></p>');
		loadingPercentStart(elem2, 66, 83, 2000);
		jQuery('#afterTestScene>div.step2>div.loadingLine>div.line').animate({'width':'70%'}, 2000, 'linear');
	}, 14000 );
	setTimeout( function(){ 
		jQuery('#afterTestScene .step2 .infoOfStage').append('<p>Подбираем оптимальный срок диеты............<font color="#78CD14">OK</font></p>');
		loadingPercentStart(elem2, 83, 88, 2000);
		jQuery('#afterTestScene>div.step2>div.loadingLine>div.line').animate({'width':'88%'}, 2000, 'linear');
	}, 16000 );
		setTimeout( function(){ 
		jQuery('#afterTestScene .step2 .infoOfStage').append('<p><b>Составление рациона на основе всех данных...<font color="#78CD14">OK</font></b></p>');
		loadingPercentStart(elem2, 88, 100, 2000);
		jQuery('#afterTestScene>div.step2>div.loadingLine>div.line').animate({'width':'100%'}, 2000, 'linear');
	}, 19000 );
	setTimeout( function(){
		var elem3 = jQuery('#afterTestScene>div.step3>div.loadingPercent>span.num');
		
		// Заполнение верхней полосы
		var time1 = 8000;
		
		// Заполнение второй полосы
		var time2 = Math.floor( time1 / 3 );
		
		// Заполнение 3-ей полосы, начинается после второй полосы
		var time3 = 3500;
		
		jQuery('#afterTestScene .step2 .loadingLine').slideUp(100);
		jQuery('#afterTestScene .step2 .loadingPercent').slideUp(100);
		jQuery('#afterTestScene .step3').slideDown(300);
		
		loadingPercentStart(elem3, 0, 100, time1);
		jQuery('#afterTestScene>div.step3>div.loadingLine>div.line').animate({'width':'100%'}, time1, 'linear');
		
		jQuery('#afterTestScene>div.step3 div.subInfo2').hide();
		stLineElem1 = jQuery('#afterTestScene>div.step3 div.subInfo1 span.stateText:first');
		var stLine1Int = startStatusLine( stLineElem1, menuArray );
		setTimeout( function(){
			jQuery('#afterTestScene>div.step3 div.subInfo1').hide();
			jQuery('#afterTestScene>div.step3 div.subInfo2').show();
			stopStatusLine(stLine1Int);
			stLineElem2 = jQuery('#afterTestScene>div.step3 div.subInfo2 span.stateText:first');
			stLine2Int = startStatusLine( stLineElem2, daysArray );
		}, time2 );
		
		setTimeout( function(){
			jQuery('#afterTestScene>div.step3 div.subInfo2').hide();
			stopStatusLine(stLine2Int);
			jQuery('#afterTestScene .step3>.loadingLine').slideUp(100);
			jQuery('#afterTestScene .step3>.loadingPercent').slideUp(100);
			jQuery('#afterTestScene .step3>.subInfoOfStage').slideUp(100);
			jQuery('#afterTestScene .step3 .hiddened').show(300);
		}, time1 );
	}, 21000 );
    setTimeout( function(){ 
        jQuery('#afterTestScene .step3 .loadingLine').slideUp(100);
        jQuery('#afterTestScene .step3 .loadingPercent').slideUp(100);
        jQuery('#afterTestScene .step3 .hiddened').show(300);
    }, 29000 );
}
/* chizh */
function ctestname()
{
	var testname = 'locationpath';
	testname = testname.substr(testname.lastIndexOf('/')+1);
	testname = testname.substr(testname.lastIndexOf('-')+1);
	testname = testname.substr(0,testname.lastIndexOf('.'));
	return testname;
}
//alert(ctestname());
var i=0; var max=0;
            function next_q() {
                $('div.question#'+(i-1)).hide();
                $('div.question#'+i).show();
                $('#qcurrent').text(i);
				savedata(i-1);
                i++;
                if(i == max) {
                    $('div.next').hide();
                    //$('div.next').remove();
                    $('#q_current_place').text('закончились...');
					//alert('!');
					//window.scrollTo(0,0);
					makeDietAnimate();
                    /*setTimeout( function(){
                        op=1;
                        $('div.question').each(function() {
                            setCookie('_' + op, '', -7);
                            op++;
                        });
                        init();
                    }, 35000 );*/

                }
            }

function wanna_more() {
    op=1;
    $('div.question').each(function() {
        setCookie('_' + op, '', -7);
        op++;
    });
    $('div.alltest').html(form_default_value);
    init();
}            

function init() {
			//makeDietAnimate();
			
            $('div.question').hide();
			$('div.question select').each(function(){if (this.id!='country_select') this.selectedIndex=-1});
            max=1;
            $('div.question').each(function() {
                this.id = max;
                max++;
            });
            $('#qmax').text(max-2);
            i=1;
			i=loadall(i);

            next_q();
            
            $('#test_next_image').click(pressbtn);
	        $('#country_select').change(function() {
            var id = $('#country_select').val();
            if(!id) $('#sms_inp').hide();
            else $('#sms_inp').show();
            });

			}
    
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	//alert(c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()));
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function isselected()
{
	var a=false;
	if ($('input', $('div.question#'+(i-1))).length>0) $('input', $('div.question#'+(i-1))).each(
	function(){
		if((this.type=='checkbox')||(this.type=='radio'))a|=this.checked;
		if((this.type=='text'))a|=(this.value.length > 0);
	});
	if ($('select', $('div.question#'+(i-1))).length>0) a = ($('select', $('div.question#'+(i-1)))[0].selectedIndex!=-1);
	if ($('textarea', $('div.question#'+(i-1))).length>0) $('textarea', $('div.question#'+(i-1))).each(function(){
		a|=(this.value.length > 0);
	});
	return a;
}

function pressbtn()
{
	if (isselected()){
		next_q();
	} else {
		alert('Нет выбранного ответа!');
	}
}

function savedata(idx)
{
	var vls='';
	if ($('input', $('div.question#'+(idx))).length>0) $('input', $('div.question#'+(i-1))).each(
	function(){
		vls = ";"+this.checked?'1':'0';
	});
	if ($('select', $('div.question#'+(idx))).length>0) vls = ";"+this.selectedIndex;
	if ($('textarea', $('div.question#'+(idx))).length>0) $('textarea', $('div.question#'+(i-1))).each(function(){
		vls = ";"+this.value;
	});	
	//alert(ctestname()+'_'+i.toString()+' : '+vls.substr(1));
	setCookie(ctestname()+i.toString(),vls.substr(1),7);
}

function savedata(idx)
{
	if (idx==0) return;
	var vls='';
	if ($('input', $('div.question#'+(idx))).length>0) $('input', $('div.question#'+(idx))).each(
	function(){
		if ((this.type=='checkbox')||(this.type=='radio'))
		{
			vls += "_"+(this.checked?'1':'0');
		} else if ((this.type=='text')){
			vls += "_"+this.value;
		}
	});
	if ($('select', $('div.question#'+(idx))).length>0) vls = ";"+$('select', $('div.question#'+(idx)))[0].selectedIndex;
	if ($('textarea', $('div.question#'+(idx))).length>0) $('textarea', $('div.question#'+(idx))).each(function(){
		vls = ";"+this.value;
	});	
	//alert(ctestname()+'_'+idx.toString()+' : '+vls.substr(1));
	setCookie(ctestname()+'_'+idx.toString(),vls.substr(1),7);
}

function loaddata(idx)
{
	if (idx==0) return;
	var vls = getCookie(ctestname()+'_'+idx.toString());
	if ($('input[type=text]', $('div.question#'+(idx))).length>0)
	{
		$('input[type=text]', $('div.question#'+(idx)))[0].value = vls;
	}
	if ($('textarea', $('div.question#'+(idx))).length>0)
	{
		$('textarea', $('div.question#'+(idx)))[0].value = vls;
	}
	if ($('input[type=radio]', $('div.question#'+(idx))).length+$('input[type=checkbox]', $('div.question#'+(idx))).length>0){
			 
		vls = vls.split('_');
		var items = $('input', $('div.question#'+(idx)));
		for (var j=0; j<vls.length; j++)
		{
			 items[j].checked = parseInt(vls[j])!=0;
		}
	}
	
	if ($('select', $('div.question#'+(idx))).length>0) {
		$('select', $('div.question#'+(idx)))[0].selectedIndex = vls;
	}
	
	//alert(ctestname()+'_'+idx.toString()+' : '+vls.substr(1));
}

function loadall(i)
{
	while (getCookie(ctestname()+'_'+i.toString()) && (getCookie(ctestname()+'_'+i.toString())!=''))
	{
		loaddata(i);
		i++;
	}
	return i;
}

$(document).ready(function(){
    form_default_value = $('div.alltest').html();
	init();
});