function toggle(id)
{
	if (document.layers)
	{
		current = (document.layers[id].display == 'none') ? 'block' : 'none';
		document.layers[id].display = current;
	}
	else if (document.all)
	{
		current = (document.all[id].style.display == 'none') ? 'block' : 'none';
		document.all[id].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
		document.getElementById(id).style.display = vista;
	}
}

function toggle_open(id)
{
	if (document.layers)
	{
		document.layers[id].display = 'block';
	}
	else if (document.all)
	{
		document.all[id].style.display = 'block';
	}
	else if (document.getElementById)
	{
		document.getElementById(id).style.display = 'block';
	}
}

function toggle_close(id)
{
	if (document.layers)
	{
		document.layers[id].display = 'none';
	}
	else if (document.all)
	{
		document.all[id].style.display = 'none';
	}
	else if (document.getElementById)
	{
		document.getElementById(id).style.display = 'none';
	}
}

function open_div(to_open,to_close,aux1,aux2)
{

	toggle_open(to_open); 
	height1 = document.getElementById(to_open+"_inner").offsetHeight; 
	if (to_open == "stage_2_active") { height1 = "350"; }
	height2 = document.getElementById(to_close+"_inner").offsetHeight; 
	toggle_close(to_close); 
	document.getElementById(to_open+"_inner").style.height = height2 + "px"; 
	var target = to_open + "_inner"; ;
	open_height(target,height1,height2,aux1,aux2); 

}

function open_height(target,height1,height2,aux1,aux2)
{
document.getElementById(target).style.height = height2 + "px"; 

	if(height2 < height1)
	{ 
	height2 = parseInt(height2 * 1.1); 
	setTimeout("open_height('"+target+"',"+height1+","+height2+",'"+aux1+"','"+aux2+"')", 10); 
	}
	else
	{
	height2 = height1; 
	document.getElementById(target).style.height = height2 + "px"; 
	
		if(aux1 != "" && aux2 != "")
		{ close_div(aux1,aux2,"",""); }
	
	}

}

function close_div(to_open,to_close,aux1,aux2)
{

	toggle_open(to_open); 
	height1 = document.getElementById(to_open+"_inner").offsetHeight; 
	height2 = document.getElementById(to_close+"_inner").offsetHeight; 
	toggle_close(to_close); 
	document.getElementById(to_open+"_inner").style.height = height2 + "px"; 

	var target = to_open + "_inner"; 
	close_height(target,height1,height2,aux1,aux2); 

}

function close_height(target,height1,height2,aux1,aux2)
{
document.getElementById(target).style.height = height2 + "px"; 

	if(height2 > height1)
	{ 
	height2 = parseInt(height2 / 1.1); 
	setTimeout("close_height('"+target+"',"+height1+","+height2+",'"+aux1+"','"+aux2+"')", 10); 
	}
	else
	{
	height2 = height1; 
	document.getElementById(target).style.height = height2 + "px"; 

		if(aux1 != "" && aux2 != "")
		{ open_div(aux1,aux2,"",""); }

	}

}

function set_content(id,content)
{ document.getElementById(id).innerHTML = content; }


function check_stage_1()
{
error_message = ""; 

	check_percentages(); 
	if(percent != 100)
	{ error_message = "percent"; }


	if(error_message != "")
	{
	
		if(error_message == "percent")
		{ set_content('error_choices','Your chosen percentages must equal 100%<br><br>'); }
	}
	else
	{ 
		set_content('error_choices',''); 
		close_div('stage_1_inactive','stage_1_active','stage_2_active','stage_2_inactive'); 
	}

}


function return_stage_2()
{
close_div('stage_2_inactive','stage_2_active','stage_1_active','stage_1_inactive'); 
}


function check_stage_2()
{
document.getElementById('stage_2_active_inner').style.height = "auto"; 
error_message = ""; 

	if(document.profile_form.form_firstname.value == "")
	{ 
	error_message = "error"; 
	set_content('error_firstname','Please add your first name'); 
	}
	else
	{
	set_content('error_firstname',''); 
	}

	if(document.profile_form.form_email.value == "" || document.profile_form.form_email2.value == "")
	{ 
	error_message = "error"; 
	set_content('error_email','Please enter and confirm your email address'); 
	}
	else if(document.profile_form.form_email.value.search(/@/) < 1 || document.profile_form.form_email2.value.search(/@/) < 1)
	{ 
	error_message = "error"; 
	set_content('error_email','Please confirm your email address is a valid format'); 
	}
	else if(document.profile_form.form_email.value != document.profile_form.form_email2.value)
	{ 
	error_message = "error"; 
	set_content('error_email','Please confirm your email addresses match'); 
	}
	else
	{
	set_content('error_email',''); 
	}

	if(document.profile_form.form_password1.value == "" || document.profile_form.form_password2.value == "")
	{ 
	error_message = "error"; 
	set_content('error_password','Please enter and confirm your password'); 
	}
	else if(document.profile_form.form_password1.value != document.profile_form.form_password2.value)
	{ 
	error_message = "error"; 
	set_content('error_password','Please confirm your passwords match'); 
	}
	else
	{
	set_content('error_password',''); 
	}

	if(document.profile_form.form_postcode.value == "")
	{ 
	error_message = "error"; 
	set_content('error_postcode','Please enter your postcode'); 
	}
	else
	{
	set_content('error_postcode',''); 
	}

	if(error_message != "")
	{

	}
	else
	{ 
	close_div('stage_2_inactive','stage_2_active','stage_3_active','stage_3_inactive'); 
	}

}


function return_stage_3()
{
close_div('stage_3_inactive','stage_3_active','stage_2_active','stage_2_inactive'); 
}


function check_stage_3()
{
document.getElementById('stage_3_active_inner').style.height = "auto"; 
error_message = ""; 

	close_div('stage_3_inactive','stage_3_active','stage_4_active','stage_4_inactive'); 

}


function return_stage_4()
{
	close_div('stage_4_inactive','stage_4_active','stage_3_active','stage_3_inactive'); 
}


function check_stage_4()
{
document.getElementById('stage_4_active_inner').style.height = "auto"; 
error_message = ""; 

	if(document.profile_form.form_agree.checked != true)
	{ 
	error_message = "error"; 
	set_content('error_confirm','You must agree to our Terms &amp; Conditions'); 
	}
	else
	{
	set_content('error_confirm',''); 
	}

	if(error_message != "")
	{

	}
	else
	{ 
		document.profile_form.submit(); 
	}

}
