var _tabsEnabled = 2;
var _tabs = new Array();
_tabs[1] = 2;
_tabs[2] = 1;
_tabs[3] = 0;
_tabs[4] = 0;
var _childWin = null;
//_tabs[5] = 0;

var _ru = new Array();
_ru['insured'] = 'Застрахованный';
_ru['insurer'] = 'Страхователь';
_ru['beneficiary'] = 'Выгодоприобретатель';

_currentTab = 1;
_formName = 'insurance';

var months = new Array();
    months[1] = 'января';
    months[2] = 'февраля';
    months[3] = 'марта';
    months[4] = 'апреля';
    months[5] = 'мая';
    months[6] = 'июня';
    months[7] = 'июля';
    months[8] = 'августа';
    months[9] = 'сентября';
    months[10] = 'октября';
    months[11] = 'ноября';
    months[12] = 'декабря';
    
var sexes = new Array();
    sexes['m'] = 'мужской';
    sexes['f'] = 'женский';
    
    
var family = new Array();
    family['1'] = 'жена';
    family['2'] = 'муж';
    family['3'] = 'сестра';
    family['4'] = 'брат';
    family['5'] = 'дочь';
    family['6'] = 'сын';
    family['7'] = 'бабушка';
    family['8'] = 'дедушка';
    family['9'] = 'отец';
    family['A'] = 'мать';
    family['B'] = 'племянник';
    family['C'] = 'внук';
    family['D'] = 'племянница';
    family['E'] = 'тетя';
    family['F'] = 'дядя';
    family['G'] = 'внучка';
    family['H'] = 'опекун';
    
function enableTab(index)
{
    if (_tabs[index] && _tabs[index] == 1)
        return;
    _tabs[index] = 1;
   /* _tab = document.getElementById('tab'+index);
    if (!_tab || _tab == 'undefined')
        return;*/
    //_tab.className = 'tab';
}

function tryOpenTab(index)
{
    if (!_tabs[index] || _tabs[index] == 'undefined')
        return showError('Сначала заполните все данные на предыдущих закладках');   
    if (_currentTab == index)
        return;

    clearError();

    if (_tabs[index] == 1)
    {
        if (_currentTab > index)
            OpenTab(index, 1);
        else
        {
            tabIndex = _currentTab;
            result = 1;
            while (tabIndex < index)
            {
                result = result && checkInfo(tabIndex);
                if (!result)
                    break;
                tabIndex++;
            }
            if (result)
            {
                if (msg = OpenTab(index)) 
                   { }
            }
            else
                OpenTab(tabIndex);
        }
    }
    else
    {
        showError ('Сначала заполните все данные на предыдущих закладках');   
    }
}

function OpenTab(index)
{
    if (_tabs[index] && _tabs[index] == 0)
    {
        return showError(index + ' ' +_tabs[index] + ' Закладка недоступна');
        
    }
    if (index == _currentTab)
        return;
    
    if (index==2)
    {
        document.getElementById('header_text').style.display = 'none';
    }
    _tabToOpen = document.getElementById('tab'+index);
    _tabToClose = document.getElementById('tab'+_currentTab);
    _divToHide = document.getElementById('div'+_currentTab);
    _divToShow = document.getElementById('div'+index);
    if (!_tabToOpen || _tabToOpen == 'undefined' || !_tabToClose || _tabToClose == 'undefined')
        return showError('дивы не найдены');
    if (_divToHide && _divToHide != 'undefined')
        _divToHide.className += ' hidden';
    if (_divToShow && _divToShow != 'undefined')
        _divToShow.className = 'info';
    _tabToOpen.className = 'tab_selected tab_selected_'+index;
    for (i = 0; i< _tabs.length; i++)
    {
        _tabToClose = document.getElementById('tab'+i);
        if (_tabToClose && _tabToClose != 'undefined' && i != index)
            _tabToClose.className = i > index ? 'tab tab_'+i : 'tab_visited tab_visited_'+i;
    }
    //_tabToClose.className = _currentTab > index ? 'tab tab_'+_currentTab : 'tab_visited tab_visited_'+_currentTab;
    _tabs[_currentTab] = 1;
    _tabs[index] = 2;  
    _currentTab = index;
    enableTab(index+1);    
}

function checkInfo(index)
{
    switch (index)
    {
    case 1:
        msg = checkCalculatorTab();        
        break;
    case 2:
        msg = checkInsuredTab();
        if (msg == '')
            msg = checkInsurerTab();
        if (msg == '')
            msg = checkBeneficiaryTab();
        break;
    case 3:
        msg = checkPaymentTab();
        if (!msg)
            insertData();
        break;
    default:
        msg = 'Неизвестный индекс';
        break;
    }
    
   if (msg)
   {
       //showError(msg);
       return 0;
   }
   else
       return 1;
}

function checkCalculatorTab()
{    
    _result = document.getElementById('calc_result');
    if (!_result || _result == 'undefined')
       return showError('Ошибка: не найдено поле calc_result') || 1;
    
    _form = eval('document.'+_formName);
	if (!_form || _form == 'undefined')
		return showError('форма не найдена') || 1;
    
    _sex = _form.sex;
	_age = _form.age;
	_sum = _form.sum;
	
	if (!_sex || _sex == 'undefined')
		return showError('поле ввода пола не найдено') || 1;
	if (!_age || _age == 'undefined')
		return showError('поле ввода возраста не найдено') || 1;
	if (!_sum || _sum == 'undefined')
		return showError('поле ввода суммы не найдено') || 1;
    
    sexValue = _sex.value;
	ageValue = parseFloat(_age.value);
	sumValue = parseFloat(_sum.value);
	
	if (sexValue != 'm' && sexValue != 'f')
		return showError('неверное значение пола', _sex) || 1;		
	if (!ageValue || ageValue == 'NaN')
		return showError('введите возраст', _age) || 1;
	if (ageValue < 18 || ageValue > 65)
		return showError('возраст может быть от 18 до 65 лет', _age) || 1;
    
    _header = document.getElementById('age_data');
    if (_header)
    {
        text = '<table width="100%" style="font-size: 100%;" ><tr><td style="padding-left: 20px; text-align: left; width: 100px;">Возраст: <b class="data">'+ageValue+'</b></td><td style="text-align: left; width: 120px;">Пол: ';
        text += sexValue == 'm' ? '<b class="data">Мужской' : '<b class="data">Женский';
        text +='</b></td><td>Страховая сумма:<b class="data"> '+sumValue+' руб';
        text +='</b></td><td>Страховая премия:<b class="data"> '+document.getElementById('calc_result').innerHTML+'</b></td></tr></table>';
        _header.innerHTML = text;
    }
    
    return '';
}

function checkDatas(type, insured)
{
    _form = eval('document.'+_formName);
	if (!_form || _form == 'undefined')
		return showError('форма не найдена') || 1;
    
    _surName = eval('_form.'+type+'_surName');
    _firstName = eval('_form.'+type+'_firstName');
    _middleName = eval('_form.'+type+'_middleName');
    _burthDay = eval('_form.'+type+'_burthDay');
    _email = eval('_form.'+type+'_email');
    _phone = eval('_form.'+type+'_phone');
    _passportSeria = eval('_form.'+type+'_passportSeria');
    _passportNumber = eval('_form.'+type+'_passportNumber');
    _passportText = eval('_form.'+type+'_passportText');
    _passportDay = eval('_form.'+type+'_passportDay');       
    _type = eval('_form.'+type+'_type');

    if (insured)
    {
        _age = _form.age;
        _accepted = eval('_form.'+type+'_accepted');
        _accepted2 = eval('_form.rules_accepted');
    }
    
    if (!_surName || _surName == 'undefined')   return showError(_ru[type] + ': поле ввода фамилии не найдено') || 1;
    if (!_firstName || _firstName == 'undefined')   return showError(_ru[type] + ': поле ввода имени не найдено') || 1;
    if (!_middleName || _middleName == 'undefined')   return showError(_ru[type] + ': поле ввода отчества не найдено') || 1;
    if (!_burthDay || _burthDay == 'undefined')   return showError(_ru[type] + ': поле ввода дня рождения не найдено') || 1;
    if (type != 'beneficiary')
    {
        if (!_email || _email == 'undefined')   return showError(_ru[type] + ': поле ввода email не найдено') || 1;
        if (!_phone || _phone == 'undefined')   return showError(_ru[type] + ': поле ввода телефона не найдено') || 1;
        if (!_passportSeria || _passportSeria == 'undefined')   return showError(_ru[type] + ': поле ввода серии паспорта не найдено') || 1;
        if (!_passportNumber || _passportNumber == 'undefined')   return showError(_ru[type] + ': поле ввода номера паспорта не найдено') || 1;
        if (!_passportText || _passportText == 'undefined')   return showError(_ru[type] + ': поле ввода "кем выдан" не найдено') || 1;
        if (!_passportDay || _passportDay == 'undefined')   return showError(_ru[type] + ': поле ввода дня выдачи паспорта не найдено') || 1;
    }
    else
    {
        if (!_type || _type == 'undefined')   return showError(_ru[type] + ': поле ввода родственной связи не найдено') || 1;
    }
    if (insured)
    {
        if (!_accepted || _accepted == 'undefined')   return showError(_ru[type] + ': поле подтверждения не найдено') || 1;
        if (!_accepted2 || _accepted2 == 'undefined')   return showError(_ru[type] + ': поле подтверждения правил не найдено') || 1;
        if (!_age || _age == 'undefined')	return showError(_ru[type] + ': поле ввода возраста не найдено') || 1;
    }
    
    surNameValue = _surName.value;
    firstNameValue = _firstName.value;
    middleNameValue = _middleName.value;
    burthDayValue = _burthDay.value;
    if (type != 'beneficiary')
    {
        emailValue = _email.value;
        phoneValue = _phone.value;
        passportSeriaValue = _passportSeria.value;
        passportNumberValue = _passportNumber.value;
        passportTextValue = _passportText.value;
        passportDayValue = _passportDay.value;
    }
    else
        typeValue = _type.value;
    if (insured)
    {
        ageValue = parseFloat(_age.value);
        acceptedValue = _accepted.checked;
        accepted2Value = _accepted2.checked;
        
    }
    if (!checkName(surNameValue, 100))
        return showError('Неверно введена фамилия', _surName) || 1;
    if (!checkName(firstNameValue, 50))
        return showError('Неверно введено имя', _firstName) || 1;
    if (!checkName(middleNameValue, 100))
        return showError('Неверно введено отчество', _middleName) || 1;
    burthValue = checkDate(burthDayValue);
    if (burthValue == 0)
        return showError(' дата рождения неверна', _burthDay) || 1;
    if (insured)
    {
        burthDate = new Date(burthValue);
        if (!CompareBurthAndAge (burthDate, ageValue))
            return showError(' дата рождения не совпадает с возрастом', _burthDay) || 1;
    }
    if (type != 'beneficiary')
    {
        if (!checkEmail(emailValue, 0))
            return showError(' Неверно введен email', _email) || 1;
        if (!checkPhone(phoneValue, 0)) 
            return showError(' Неверно введен телефон', _phone) || 1;
        if (!checkNumber(passportSeriaValue, 4)) 
            return showError(' Неверно введена серия паспорта', _passportSeria) || 1;
        if (!checkNumber(passportNumberValue, 6)) 
            return showError(' Неверно введен номер паспорта', _passportNumber) || 1;
        if (passportTextValue.length < 10)
            return showError(' Не указано место выдачи паспорта', _passportText) || 1;
        passportValue = checkDate(passportDayValue);
        if (passportValue == 0)
            return showError(' дата выдачи паспорта неверна', _passportDay) || 1;
    }
    
    if (insured)
    {
        if (acceptedValue != true)
            return showError(' Вы должны принять Декларацию о застрахованном', _accepted) || 1;
        if (accepted2Value != true)
            return showError(' Вы должны согласиться с условиями покупки', _accepted2) || 1;
    }
    return '';
}

function checkInsuredTab()
{    
    return (checkDatas('insured', true));
}

function checkInsurerTab()
{    
    _form = eval('document.'+_formName);
	if (!_form || _form == 'undefined')
		return showError('форма не найдена') || 1;
    
    _theSame = _form.insurer_theSame;
    if (!_theSame || _theSame == 'undefined')   return showError('поле "Использовать данные застрахованного" не найдено') || 1;
    
    theSameValue = _theSame.checked;
    if (theSameValue == true)
        return '';
    else return (checkDatas('insurer', false));   
}

function checkBeneficiaryTab()
{    
    return (checkDatas('beneficiary', false));
}

function checkPaymentTab()
{    
    _form = eval('document.'+_formName);
	if (!_form || _form == 'undefined')
    {
        return showError('форма не найдена') || 1;
    }
    _deliver = _form.deliver;
    _payment = _form.payment;
    
    if (!_deliver || _deliver == 'undefined') { return showError('поле выбора способа доставки не найдено') || 1;}    
    if (!_payment || _payment == 'undefined') { return showError('поле выбора способа оплаты не найдено') || 1;}    
    
    deliverValue = 0;
    for (i=0; i<_deliver.length; i++)
        if (_deliver[i])
        {
            if (_deliver[i].checked)
               deliverValue = _deliver[i].value;
        }
            
    
    if (deliverValue == 0)
    {
        return showError('Выберите способ доставки', _deliver) || 1;
    }
    else if (deliverValue == 'курьер')
    {
        _address = _form.delivery_address;
        _phone = _form.delivery_phone;
        _time = _form.delivery_time;
        
        if (!_address || _address == 'undefined')  { return showError('поле адреса не найдено') || 1;}    
        if (!_phone || _phone == 'undefined')  { return showError('поле контактного телефона не найдено') || 1;}    
        if (!_time || _time == 'undefined')  { return showError('поле времени не найдено') || 1;}
        
        addressValue = _address.value;
        phoneValue = _phone.value;
        timeValue = _time.value;
        
        if (addressValue == '') {  return showError( 'Введите адрес доставки', _address) || 1;}   
        if (!checkPhone(phoneValue, 1))  { return showError( 'Введите контактный телефон', _phone) || 1;}   
        if (timeValue == '') {  return showError( 'Введите удобное время доставки', _time) || 1;}   
    }
    
    
    paymentValue = 0;
    for (i=0; i<_payment.length; i++)
        if (_payment[i] && _payment[i].checked)
            paymentValue = _payment[i].value;
    if (paymentValue == 0)
    {
        return showError( 'Выберите способ оплаты', _payment) || 1;
    }
    return '';
}

function checkName(value, max)
{
    var reg=eval('/^[ ]*[a-zA-Zа-яА-Я]{1,'+max+'}[ ]*$/'); 
    result=reg.test(value);
    return result;
}

function checkEmail(value, necessary)
{
    var reg=/^[ ]*[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]{2,5}[ ]*$/; 
    result=reg.test(value);
    result = result && (value.length > 8) && (value.length <= 255);    
    return result;
}

function checkPhone(value, necessary)
{
    if (value == '' && !necessary)
        return true;
    var reg=eval('/^[ ]*[0-9\ \(\)\+\-]{5,32}[ ]*$/'); 
    result=reg.test(value);  
    return result;
}

function checkNumber(value, length)
{
    var reg=eval('/^[ ]*[0-9]{'+length+'}[ ]*$/'); 
    result=reg.test(value);  
    return result;
}

function checkDate(str)
{
    parts = str.split('/');
    if (parts.length != 3){
	parts = str.split('.');
	if (parts.length != 3)
           return 0;
    }
    day = parseFloat(parts[0]);
    month = parseFloat(parts[1]);
    year = parseFloat(parts[2]);
    
    newDate = new Date(); 
    
    if (day > 31 || day < 1)
        return 0;
    if (month > 12 || month < 1)
        return 0;
    if (year > newDate.getFullYear() || year < 1900)
        return 0;
    
    newDate.setYear(year); 
    newDate.setMonth(month-1); 
    newDate.setDate(day);
    
    if (newDate.getDate() != day)
        return 0;
    else
        return newDate;
}

function CompareBurthAndAge(burthDate, ageValue)
{
    dateNow = new Date();
    age_ = dateNow.getFullYear() - burthDate.getFullYear();
	
    var d1 = parseFloat(dateNow.getMonth()) < parseFloat(burthDate.getMonth());
    var d2 = parseFloat(dateNow.getMonth()) == parseFloat(burthDate.getMonth());
    var d3 = parseFloat(dateNow.getDate()) < parseFloat(burthDate.getDate());

    if (d1 || (d2 && d3))  age_--;
    		    
    return age_ == ageValue;
}

function insertData()
{
    _form = eval('document.'+_formName);
	if (!_form || _form == 'undefined')
		return showError( 'форма не найдена') || 1;
    
    type = 'insured';
     _insured_surName = eval('_form.'+type+'_surName');
     _insured_firstName = eval('_form.'+type+'_firstName');
     _insured_middleName = eval('_form.'+type+'_middleName');
     _insured_data_sex = _form.sex;
     _insured_burthDay = eval('_form.'+type+'_burthDay');
     _insured_email = eval('_form.'+type+'_email');
     _insured_phone = eval('_form.'+type+'_phone');
     _insured_passportSeria = eval('_form.'+type+'_passportSeria');
     _insured_passportNumber = eval('_form.'+type+'_passportNumber');
     _insured_passportText = eval('_form.'+type+'_passportText');
     _insured_passportDay = eval('_form.'+type+'_passportDay');       
    
    type = 'insurer';
     _insurer_surName = eval('_form.'+type+'_surName');
     _insurer_firstName = eval('_form.'+type+'_firstName');
     _insurer_middleName = eval('_form.'+type+'_middleName');
     _insurer_burthDay = eval('_form.'+type+'_burthDay');
     _insurer_sex = eval('_form.'+type+'_sex');
     _insurer_email = eval('_form.'+type+'_email');
     _insurer_phone = eval('_form.'+type+'_phone');
     _insurer_passportSeria = eval('_form.'+type+'_passportSeria');
     _insurer_passportNumber = eval('_form.'+type+'_passportNumber');
     _insurer_passportText = eval('_form.'+type+'_passportText');
     _insurer_passportDay = eval('_form.'+type+'_passportDay');       
     _insurer_theSame = _form.insurer_theSame;
    
    type = 'beneficiary';
     _beneficiary_surName = eval('_form.'+type+'_surName');
     _beneficiary_firstName = eval('_form.'+type+'_firstName');
     _beneficiary_middleName = eval('_form.'+type+'_middleName');
     _beneficiary_burthDay = eval('_form.'+type+'_burthDay');
     _beneficiary_type = eval('_form.'+type+'_type');
     
    _deliver = new Array();
     
    _deliver = _form.deliver;
    _payment = _form.payment;
    _sum = _form.sum;
    _age = _form.age;
    
    insured_surNameValue = _insured_surName.value;
    insured_firstNameValue = _insured_firstName.value;
    insured_middleNameValue = _insured_middleName.value;
    insured_data_sexValue = _insured_data_sex.value;
    insured_burthDayArray = _insured_burthDay.value.split('/');
    if (insured_burthDayArray.length != 3)
        insured_burthDayArray = _insured_burthDay.value.split('.');
    insured_burthDayValue = parseFloat(insured_burthDayArray[0]);
    insured_burthMonthValue = parseFloat(insured_burthDayArray[1]);
    insured_burthYearValue = parseFloat(insured_burthDayArray[2]);
    insured_emailValue = _insured_email.value;
    insured_phoneValue = _insured_phone.value;
    insured_passportSeriaValue = _insured_passportSeria.value;
    insured_passportNumberValue = _insured_passportNumber.value;
    insured_passportTextValue = _insured_passportText.value;
    
    insured_passportDayArray = _insured_passportDay.value.split('/');
    if (insured_passportDayArray.length != 3)
        insured_passportDayArray = _insured_passportDay.value.split('.');
    insured_passportDayValue = insured_passportDayArray[0];
    insured_passportMonthValue = insured_passportDayArray[1];
    insured_passportYearValue = insured_passportDayArray[2];
    
    insurer_theSameValue = _insurer_theSame.checked;
    if (insurer_theSameValue == true)
    {
        insurer_surNameValue = insured_surNameValue;
        insurer_firstNameValue = insured_firstNameValue;
        insurer_middleNameValue = insured_middleNameValue;
        insurer_data_sexValue = insured_data_sexValue;
        insurer_burthDayValue = insured_burthDayValue;
        insurer_burthMonthValue = insured_burthMonthValue;
        insurer_burthYearValue = insured_burthYearValue;
        insurer_emailValue = insured_emailValue;
        insurer_phoneValue = insured_phoneValue;
        insurer_passportSeriaValue = insured_passportSeriaValue;
        insurer_passportNumberValue = insured_passportNumberValue;
        insurer_passportTextValue = insured_passportTextValue;
        insurer_passportDayValue = insured_passportDayValue;
        insurer_passportMonthValue = insured_passportMonthValue;
        insurer_passportYearValue = insured_passportYearValue;
        
    }
    else
    {
        insurer_surNameValue = _insurer_surName.value;
        insurer_firstNameValue = _insurer_firstName.value;
        insurer_middleNameValue = _insurer_middleName.value;
        insurer_data_sexValue = _insurer_sex.value;
        insurer_burthDayArray = _insurer_burthDay.value.split('/');
        if (insurer_burthDayArray.length != 3)
            insurer_burthDayArray = _insurer_burthDay.value.split('.');
        insurer_burthDayValue = parseFloat(insurer_burthDayArray[0]);
        insurer_burthMonthValue = parseFloat(insurer_burthDayArray[1]);
        insurer_burthYearValue = parseFloat(insurer_burthDayArray[2]);
        insurer_emailValue = _insurer_email.value;
        insurer_phoneValue = _insurer_phone.value;
        insurer_passportSeriaValue = _insurer_passportSeria.value;
        insurer_passportNumberValue = _insurer_passportNumber.value;
        insurer_passportTextValue = _insurer_passportText.value;
        insurer_passportDayArray = _insurer_passportDay.value.split('/');
        if (insurer_passportDayArray.length != 3)
            insurer_passportDayArray = _insurer_passportDay.value.split('.');
        insurer_passportDayValue = insurer_passportDayArray[0];
        insurer_passportMonthValue = insurer_passportDayArray[1];
        insurer_passportYearValue = insurer_passportDayArray[2];
    }
    
    beneficiary_surNameValue = _beneficiary_surName.value;
    beneficiary_firstNameValue = _beneficiary_firstName.value;
    beneficiary_middleNameValue = _beneficiary_middleName.value;
    beneficiary_burthDayArray = _beneficiary_burthDay.value.split('/');
    if (beneficiary_burthDayArray.length != 3)
        beneficiary_burthDayArray = _beneficiary_burthDay.value.split('.');
    beneficiary_burthDayValue = parseFloat(beneficiary_burthDayArray[0]);
    beneficiary_burthMonthValue = parseFloat(beneficiary_burthDayArray[1]);
    beneficiary_burthYearValue = parseFloat(beneficiary_burthDayArray[2]);
    beneficiary_typeValue = _beneficiary_type.value;
    
    
    deliverValue = 0;
    for (i=0; i<_deliver.length; i++)
        if (_deliver[i] && _deliver[i].value && _deliver[i].value != 'undefined')
        {           
            if (_deliver[i].checked)
            {
                deliverValue = _deliver[i].value;
                document.getElementById('deliver_'+i).className = '';
            }
            else
            {
                document.getElementById('deliver_'+i).className = 'hidden';
            }
        }
    if (deliverValue == 'курьер')
    {
        _delivery_address = _form.delivery_address;
        _delivery_phone = _form.delivery_phone;
        _delivery_time = _form.delivery_time;
        
        _delivery_data_address = document.getElementById('delivery_data_address');
        _delivery_data_phone = document.getElementById('delivery_data_phone');
        _delivery_data_time = document.getElementById('delivery_data_time');
        
        _delivery_data_address.innerHTML = _delivery_address.value;
        _delivery_data_phone.innerHTML = _delivery_phone.value;
        _delivery_data_time.innerHTML = _delivery_time.value;
    }
    
    for (i=0; i<_payment.length; i++)    
        if (_payment[i] && _payment[i].value && _payment[i].value != 'undefined')
            if (_payment[i].checked)
                document.getElementById('payment_'+i).className = '';
            else 
                document.getElementById('payment_'+i).className = 'hidden';
            
    sumValue = parseFloat(_sum.value);
    ageValue = parseFloat(_age.value);   
    
    _insured_data_fio = document.getElementById('insured_data_fio');
    _insured_data_sex = document.getElementById('insured_data_sex');
    _insured_data_burthday = document.getElementById('insured_data_burthday');
    _insured_data_email = document.getElementById('insured_data_email');
    _insured_data_phone = document.getElementById('insured_data_phone');
    _insured_data_passport = document.getElementById('insured_data_passport');

    _insurer_data_fio = document.getElementById('insurer_data_fio');
    _insurer_data_burthday = document.getElementById('insurer_data_burthday');
    _insurer_data_sex = document.getElementById('insurer_data_sex');
    _insurer_data_email = document.getElementById('insurer_data_email');
    _insurer_data_phone = document.getElementById('insurer_data_phone');
    _insurer_data_passport = document.getElementById('insurer_data_passport');

    _beneficiary_data_fio = document.getElementById('beneficiary_data_fio');
    _beneficiary_data_burthday = document.getElementById('beneficiary_data_burthday');
    _beneficiary_data_type = document.getElementById('beneficiary_data_type');
    
    _ins_sum = _form.ins_sum;
    _ins_sum.value = sumValue;
    
    _insured_data_fio.innerHTML = insured_surNameValue + ' ' + insured_firstNameValue + ' ' + insured_middleNameValue;
    _insured_data_sex.innerHTML = sexes[insured_data_sexValue];
    _insured_data_burthday.innerHTML = insured_burthDayValue + ' ' + months[parseFloat(insured_burthMonthValue)] + ' ' + insured_burthYearValue + ' года';
    _insured_data_email.innerHTML = insured_emailValue;
    _insured_data_phone.innerHTML = insured_phoneValue ? (insured_phoneValue + ',') : '';
    _insured_data_passport.innerHTML = 'серия ' + insured_passportSeriaValue + ' номер ' + insured_passportNumberValue + ' выдан ' + insured_passportTextValue + ' ' + insured_passportDayValue + ' ' + months[parseFloat(insured_passportMonthValue)] + ' ' + insured_passportYearValue + ' года'; 
    
    _insurer_data_fio.innerHTML = insurer_surNameValue + ' ' + insurer_firstNameValue + ' ' + insurer_middleNameValue;
    _insurer_data_sex.innerHTML = sexes[insurer_data_sexValue];
    _insurer_data_burthday.innerHTML = insurer_burthDayValue + ' ' + months[parseFloat(insurer_burthMonthValue)] + ' ' + insurer_burthYearValue + ' года';
    _insurer_data_email.innerHTML = insurer_emailValue;
    _insurer_data_phone.innerHTML = insurer_phoneValue ? (insurer_phoneValue + ',') : '';
    _insurer_data_passport.innerHTML = 'серия ' + insurer_passportSeriaValue + ' номер ' + insurer_passportNumberValue + ' выдан ' + insurer_passportTextValue + ' ' + insurer_passportDayValue + ' ' + months[parseFloat(insurer_passportMonthValue)] + ' ' + insurer_passportYearValue + ' года'; 
    
    _beneficiary_data_fio.innerHTML = beneficiary_surNameValue + ' ' + beneficiary_firstNameValue + ' ' + beneficiary_middleNameValue;
    _beneficiary_data_burthday.innerHTML = beneficiary_burthDayValue + ' ' + months[parseFloat(beneficiary_burthMonthValue)] + ' ' + beneficiary_burthYearValue + ' года';
    _beneficiary_data_type.innerHTML = '<br />'+family[beneficiary_typeValue];

}

function checkPass()
{
    _form = eval('document.'+_formName);
	if (!_form || _form == 'undefined')
    {
		showError('форма не найдена');
        return false;
    }
    
    _pass1 = _form.pass1;
    _pass2 = _form.pass2;
    
    if (!_pass1 || _pass1 == 'undefined')
    {
        showError('Ошибка: не найдено поле ввода пароля #1');
        return false;
    }
    if (!_pass2 || _pass2 == 'undefined')
    {
        showError('Ошибка: не найдено поле ввода пароля #1');
        return false;
    }
    pass1Value = _pass1.value;
    pass2Value = _pass2.value;
    
    if (pass1Value == '')
    {
        showError('пароль не может быть пустым', _pass1);   
        return false;
    }if (pass2Value == '')
    {
        showError('пароль не может быть пустым', _pass2);   
        return false;
    }
    if (pass1Value != pass2Value)
    {
        showError('пароли не совпадают', _pass2);
        return false;
    }
    
    hasDigits = pass1Value.match(/[0-9]/); 
    hasLowerLetters = pass1Value.match(/[a-z]/); 
    hasLowerRusLetters = pass1Value.match(/[а-я]/); 
    hasUpperLetters = pass1Value.match(/[A-Z]/); 
    hasUpperRusLetters = pass1Value.match(/[А-Я]/); 
    hasOtherSigns = pass1Value.match(/[^0-9a-zA-Zа-яА-Я]/); 

    var m =
      (hasDigits? 10: 0) + 
      (hasLowerLetters? 26: 0) + 
      (hasUpperLetters? 26: 0) + 
      (hasLowerRusLetters? 33: 0) + 
      (hasUpperRusLetters? 33: 0) + 
      (hasOtherSigns? 32: 0);

    var n = pass1Value.length;
    var R = Math.pow(m, n);
    result = (Math.log(R));
    
    if (result < 28)
    {
        showError('<nobr>Вы ввели слишком простой пароль, <br />старайтесь использовать прописные<br /> и строчные буквы, а также цифры <br />и символы пунктуации</nobr>', _pass1);
        return false;
    }
    fillCyberPay('fcyberpay');
    return true;
    
}

function showError(msg, obj)
{
    _error = document.getElementById('error_field');
    if (!_error || _error == 'undefined')
    {
        alert ('поле вывода ошибки не найдено');
        return;
    }
    _error.innerHTML = msg;
    _error.style.display = '';
    
    if (obj && obj != 'undefined')
    {
        _parent = obj.parentNode;
        if (_parent)
        {
            _error.style.top = '';
            _error.style.left= '';
            _parent.appendChild(_error);
        }
        else
        {
            document.body.appendChild(_error);
            _error.style.top = '50%';
            _error.style.left= '50%';
        }
        try { obj.focus(); }
        catch(err) {/* setTimeout(obj.focus, 1000);*/}
    }
    else
    {
        document.body.appendChild(_error);
        _error.style.top = '41%';
        _error.style.left= '40%';
        setTimeout(clearError, 3000);
    }
    
    return false;
}
function clearError()
{
    _error = document.getElementById('error_field');
    if (!_error || _error == 'undefined')
    {
        alert ('поле вывода ошибки не найдено');
        return;
    }
    _error.innerHTML = '';
    _error.style.display = 'none';
}

function UserWindow( pageToLoad, winName, width, height, scroll_) 
{
    xposition=200; yposition=200;
    scroll_ = scroll_ ? scroll_ : 0;
    args = "width=" + width + "," + "height=" + height + ","                             
        + "resizable=0,scrollbars=" + scroll_+ ",status=0,toolbar="+scroll_+","
        + "left=" + xposition + "," + "top=" + yposition;
    _childWin = window.open('/online-store/info/'+pageToLoad, 'renLifePopup', args);
    _childWin.focus();
}

function showPayemnt()
{
    _form = eval('document.'+_formName);
	if (!_form || _form == 'undefined')
    {
		showError('форма не найдена');
        return false;
    }
    
    _payment = _form.payment;
    
    if (!_payment || _payment == 'undefined')
    {
		showError('способы оплаты не найдены');
        return false;
    }
    
    for (i=0; i<_payment.length; i++)
        if (_payment[i])
        {
            if (_payment[i].checked)
                document.getElementById('payment'+(i+1)).className = '';
            else
                document.getElementById('payment'+(i+1)).className = 'hidden';
        }
}

function fillRosBank()
{
    if (!_childWin)
        return showError('Дочернее окно не найдено');
    
    if (!paymentResult)
        return showError('Страховая сумма не найдена');
    
    _summ1 = _childWin.document.getElementById('summ1');
    _summ2 = _childWin.document.getElementById('summ2');
    if (!_summ1)
        return showError('Поле ввода суммы на бланке 1 не найдено');
    if (!_summ2)
        return showError('Поле ввода суммы на бланке 2 не найдено');
    
    _summ1.innerHTML = paymentResult;
    _summ2.innerHTML = paymentResult;
}

