stepElements = new Object;
stepElements['first'] = 1;
stepElements['last'] = 4;

function switchStep(step, i)
{
	var fx;

	$$('.step'+i).each(function(e) 
	{
		if(i == step) // show current element
		{
			fx = new Fx.Style(e, 'opacity', {'duration': 1000});
			fx.start(0, 1);

			e.style.position = 'static';
			e.style.left = '0';
			e.style.width = 'auto';			
		}
		else // hide
		{
			fx = new Fx.Style(e, 'opacity', {'duration': 1});
			fx.start(1, 0);


			e.style.position = 'absolute';
			e.style.left = '-2000px';
			e.style.width = '100px';
		}
	});
}

function setProgressBar(step)
{
	var rightElementSrc, r1 = $('progress_repeat_1'), r2 = $('progress_repeat_2');
	r2.style.display = 'inline';
	rightElement(false);

	switch(step)
	{
		case 1:
		r1.style.width = '10px';
		r2.style.width = '85px';
		break;

		case 2:
		r1.style.width = '40px';
		r2.style.width = '55px'
		break;

		case 3:
		r1.style.width = '70px';
		r2.style.width = '25px'
		break;

		case 4:
		r1.style.width = '95px';
		r2.style.display = 'none';
		rightElement(true);
		break;
	}
}

function rightElement(showDark)
{
	rightElementSrc = $('progress_right').src;
	if(showDark == true)
		rightElementSrc = rightElementSrc.replace(/_light/, '_dark');
	else
		rightElementSrc = rightElementSrc.replace(/_dark/, '_light');
	$('progress_right').src = rightElementSrc;
}


function switchRegistrationStep(step, validate)
{
	var checkUserNameAjax = false;
	
	for(var i = stepElements['first']; i <= stepElements['last']; i++)
	{
		switchStep(step, i);
	}
	setProgressBar(step);
	
	if(validate)
	{
		if(step == 2) { checkUserNameAjax = true; }
		else { checkUserNameAjax = false; }	
		
		checkRequired(step, checkUserNameAjax);
	}
}

function prepareOnStart()
{
	var e = $$(".step2, .step3");
	e.each( function(step) {
		fx = new Fx.Style(step, 'opacity');
		fx.start(1, 0);
	});
}

function quickRegistration()
{
    if ( $('checkboxGTC').checked ) {        
        $('registrationForm').submit();
    }
    else {
        OpenGTCWindow();
    }
}

window.onload = prepareOnStart;
