

var _active;
var _activeForm;
var _activeType;
function ShowForm (name) {
	if (_active != null)
		_HideActive ();
	_ShowForm(name);
}


function _HideActive() {
	/*_active.effect('height',{
		duration: 1000,
		transition: Fx.Transitions.bounceOut
	}).start(300,0);*/
	_active.height=0;
	_active.style.display='none';
}


function _ShowForm (name) {
	_activeType = name;
	var tab = $(name+"_TABLE");
	_activeForm = $("FORM_" + name);
	
	tab.style.display='block';	
	/*tab.effect('height',{
		duration: 1000
//		,transition: Fx.Transitions.bounceOut
	}).start(0,500);*/
	_active=tab;
	
	StepActivated(1);	
}


var _pregnantValue;
function ChangePregnant(type, value) {
	var pregnantVisible = false;
	var plannedVisible = false;
	if (value == 'yes')
		pregnantVisible = true;
	if (value == 'planned')
		plannedVisible = true;
	var pregnantVisibleNow = ($(type+"_PREGNANT_YES").style.display=='block');
	var plannedVisibleNow = ($(type+"_PREGNANT_PLANNED").style.display=='block');
	height = (type == "m") ? 138 : 65;
	if (pregnantVisibleNow != pregnantVisible)
		ChangeDivVisible (type+"_PREGNANT_YES", pregnantVisible, height);
	if (plannedVisibleNow != plannedVisible) {
		ChangeDivVisible (type+"_PREGNANT_PLANNED", plannedVisible, 30);
		
	}
	_pregnantValue = value;		
}

function ChangeConceivingExact(type, value) {
	ChangeDivVisible (type + "_CONCEIVING_DATE", value, 30);
}


function ChangeDivVisible (divId, visible, height) {
	height+=25;
	var div=$(divId);
	if (visible) {
		div.style.display='block';
		div.height=0;
		
		var fx = new Fx.Styles(divId);
		fx.start({
			'width':[0,305],
			'height':[0,height]});
		
		//div.effect('height',{
//			duration: 500
	//	}).start(0,height);
	} else {
		div.style.display='none';
	}
}

function CheckForm (form) {
	if (form.birth_date_year.value == "" || form.birth_date_month.value == "" || form.birth_date_day.value == "")
	{
		if (form.type.value=="mother")
			alert("Укажите Вашу дату рождения");			
		else
			alert("Укажите дату рождения будущей мамы");
		return false;
	}
	
	pregnant = getCheckedValue (form.pregnant);
	
	if (pregnant == "yes") {
		if (form.type.value == "mother" && (form.last_menstr_date_year.value == "" || form.last_menstr_date_month.value == "" || form.last_menstr_date_day.value == ""))
		{
			alert("Укажите первый день последней менструации (хотя-бы примерно)");
			return false;
		}
		if (form.type.value != "mother" && (form.conceiving_date_year.value == "" || form.conceiving_date_month.value == "" || form.conceiving_date_day.value == ""))
		{
			alert("Укажите дату зачатия (хотя-бы примерно)");
			return false;
		}
	}
	
	return true;
}





function getCheckedValue(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 "";
}

function LinkedDateSelected(obj, linked, type) {
	if(obj.form.elements[linked + "_" + type].value == "")
		obj.form.elements[linked + "_" + type].value = obj.value;
}

function FinishStep(stepNo) {
	if (stepNo == 1) {
		if (!CheckForm(_activeForm))
			return false;
		/*_activeForm.submit ();
		return;*/
		$("STEP_1").style.display = "none";
		$("kwick").style.display = "none";
		new Fx.Style('STEP_2', 'height',{duration: 500}).start(0,500);
	} else if (stepNo == 2) {
		if (_pregnantValue == "yes") {
			$("thirdPregnantYes").style.display = "block";
			$("thirdPregnantPlanned").style.display = "none";
			//$("thirdPregnantNo").style.display = "none";
		} else {
			$("thirdPregnantYes").style.display = "none";
			$("thirdPregnantNo").style.display = "block";
		}
		$("thirdPregnantPlanned").style.display = (_activeType == "MOTHER" && _pregnantValue == "planned") ? "block" : "none";
		
		new Fx.Style('STEP_2', 'height').start(0);
		new Fx.Style('STEP_3', 'height',{duration: 500}).start(0,500);
	} else if (stepNo == 3) {
		_activeForm.submit ();
		return;
	}
	StepActivated(stepNo+1);
}

function BackStep(stepNo) {
	if (stepNo == 2) {
		new Fx.Style('STEP_2', 'height',{duration: 500}).start(0);
		setTimeout('$("STEP_1").style.display = "block";', 500);
		setTimeout('$("kwick").style.display = "block";', 500);		
	} else if (stepNo == 3) {
		new Fx.Style('STEP_3', 'height',{duration: 500}).start(0);
		new Fx.Style('STEP_2', 'height',{duration: 500}).start(0,500);
	}
	StepActivated(stepNo-1);
}

function StepActivated (stepNo) {
	if (stepNo > 3)
		stepNo = 3;
	var title = "Шаг " + stepNo + " из 3";
	title = "";
	var titleText = "";
	if (_activeType == "MOTHER")
		titleText = "Тест для будущей мамы";
	else if (_activeType == "FATHER")
		titleText = "Тест для будущего папы";
	else if (_activeType == "OTHER")
		titleText = "Общий тест";
	
	$("StepTitle").innerHTML = titleText + ". " + title;
}
