	var fields_list = new Array('reg_husband', 'reg_wife', 'lastname2', 'firstname2', 'patronymic_name2', 'gender2', 'education2', 'profession2', 'dob2_day', 'dob2_month', 'dob2_year', 'passport2_series', 'passport2_number', 'passport2_give', 'passport2_give_date', 'phone2_mobile1', 'email2');
	
function change_registration_method(registration_method) {

	//alert(fields_list.length);
	switch (registration_method) {
		case "1":	// register one distributor
			processing_fields_list('hide');
			break;

		case "2":	// register 2 distributors (famaly)
			processing_fields_list('show');		
			break;		
	}

}


function processing_fields_list(action) {

	for (var i=0; i<fields_list.length; i++) {
		if (action == 'show') {
			document.getElementById(fields_list[i]).style.display = 'block';
		} else {
			document.getElementById(fields_list[i]).style.display = 'none';			
		}
	}
	
}



function check_registration_data_step0(oForm) {

	var sponsor_id = oForm.sponsor_id;
	if (sponsor_id.value.length !== 8) {
		alert('Введите правильный ID спонсора, он должен состоять только из 8-и цифр.');
		document.getElementById('sponsor_id').focus();	
		return false;		
	}

	return true;

}



function check_registration_data_step1(oForm) {

	var sub_sponsor = oForm.sub_sponsor;
	if (sub_sponsor == undefined) {
		// sponsor is single distributor
		// no check
	} else {
		var sub_sponsor_value = check_radio_value(sub_sponsor);
		if (sub_sponsor_value == '1' || sub_sponsor_value == '2') {
			// all right
		} else {
			alert('Выберите супруга, под которым Вы будете зарегистрированы.');
			document.getElementById('sub_sponsor').focus();	
			return false;
		}		
	}

	return true;

}




function check_registration_data_step2(oForm) {

	var registration_method_element = oForm.registration_method;	// radio form element
	var checked_value = '';											// current checked value of form field
	
	// get registration mode: 1-single distributor, 2-famaly of distributors
	registration_method_value = check_radio_value(registration_method_element);
	if (registration_method_value == '1' || registration_method_value == '2') {
		// all right
	} else {
		alert('Выберите метод регистрации - один дистрибьютор или семья дистрибьюторов.');
		document.getElementById('registration_method').focus();	
		return false;
	}


	// array contain checked field list for registration one distributor
	var checked_fields_list_one = [
			['lastname1', 'Фамилия'],
			['firstname1', 'Имя'],
		//	['patronymic_name1', 'Отчество'],
			['gender1', 'Пол'],
			['dob1_day', 'Дата рождения, день'],
			['dob1_month', 'Дата рождения, месяц'],			
			['dob1_year', 'Дата рождения, год'],
			['nickname', 'Ник'],			
			['passport1_series', 'Серия паспорта'],
			['passport1_number', 'Номер паспорта'],
			['passport1_give', 'Кем выдан паспорт'],
			['passport1_give_date', 'Дата выдачи паспорта'],			
			['address_street', 'Улица, дом, квартира'],
			['address_town', 'Город'],
			['address_region', 'Область'],			
			['address_country', 'Страна'],
		//	['address_zip', 'Почтовый индекс'],
			['phone1_mobile1', 'Номер мобильного телефона'],			
			['email1', 'e-mail'],
			['email_public', 'e-mail публичный'],			
			['password', 'Пароль'],
			['password_verify', 'Пароль повторно'],			
		];

	// array contain checked field list for registration famaly of distributors
	var checked_fields_list_famaly_add = [
			['lastname2', 'Фамилия второго супруга'],
			['firstname2', 'Имя второго супруга'],
		//	['patronymic_name2', 'Отчество второго супруга'],
			['gender2', 'Пол второго супруга'],
			['dob2_day', 'Дата рождения, день второго супруга'],
			['dob2_month', 'Дата рождения, месяц второго супруга'],			
			['dob2_year', 'Дата рождения, год второго супруга'],
			['passport2_series', 'Серия паспорта второго супруга'],
			['passport2_number', 'Номер паспорта второго супруга'],
			['passport2_give', 'Кем выдан паспорт второго супруга'],
			['passport2_give_date', 'Дата выдачи паспорта второго супруга']			
		//	['phone2_mobile1', 'Номер мобильного телефона второго супруга'],			
		];


	// check data first distributors
	for (var i=0; i<checked_fields_list_one.length; i++) {
		//checked_value = document.getElementById(checked_fields_list_one[i][0]).value;		
		checked_value = document.getElementById(checked_fields_list_one[i][0]).value;		
		if (checked_value == '') {
			alert('Пожалуйста, заполните поле [' + checked_fields_list_one[i][1] + ']')	
			document.getElementById(checked_fields_list_one[i][0]).focus();
			return false;
		}
	}

	// check data second distributors
	if (registration_method_value == '2') {
		for (var i=0; i<checked_fields_list_famaly_add.length; i++) {
			//checked_value = document.getElementById(checked_fields_list_famaly_add[i][0]).value;		
			checked_value = document.getElementById(checked_fields_list_famaly_add[i][0]).value;	
			if (checked_value == '') {
				alert('Пожалуйста, заполните поле [' + checked_fields_list_famaly_add[i][1] + ']')	
				document.getElementById(checked_fields_list_famaly_add[i][0]).focus();
				return false;
			}
		}
	}

	return true;

}



// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function check_radio_value(radioObj) {

	if(!radioObj)
		return "";
	var radioLength = radioObj.length;

	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";

	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	
	return "";

}


// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}



// проверить пароль на регистрацию дистрибьютора
function check_registration_password() {


	var password = document.getElementById('password').value;
	var password_verify = document.getElementById('password_verify').value;	

//	alert(password);

	if (password.length > 20) {
		alert('Превышена допустимая длина пароля - 20 знаков. Исправьте его.');
		return false;		
	}
	
	if (password != password_verify) {
		alert('Два пароля не равны межу собой. Исправьте их.');
		return false;		
	}
	
//	alert(password);

	return true;		
	
}


