/***********************************************************************/
var currentstep = 0;

var dropdowncallback = false;

var running_callback = false;

Ajax.Responders.register(
{
	onComplete: function() {
		oncompleted();
	}

});

function editStep(stepval)
{
	if(running_callback)
	{
		return;
	}
	running_callback = true;
	currentstep = stepval;

	$('currentstep').value = currentstep;
	if( $('action') )
	{
		$('action').value = 'step';
	}

	var form = $('mainAreaForm');
	var params = Form.serialize(form);
	new Ajax.Updater({ success: 'mainAreaInternal'}, 'brafinder.phtml?rp=1&edit=1', {method: 'post', parameters: params, evalScripts: true, encoding: 'UTF-8'});


}

function nextStep()
{
	if(running_callback)
	{
		return;
	}

	
	currentstep++;
	
	if($('bandbust'))
	{
		if( ($('bandbust').value != '') && currentstep ==1)
		{
			currentstep = 2;
		}
	}
	
	var goahead = false;
	var bandbust = false;
	if(currentstep == 2)
	{
		if($('bandbust').value != '')
		{
			goahead = true;
			bandbust = true;
		}
		else if($('bandsize').value != '' && $('bustsize').value != '')
		{
			goahead = true;
		}
		else
		{
			alert('Please select your band size and cup size.');
			currentstep--;
		}
	}
	else if (currentstep == 4)
	{
		var sel = false;
		
		$$('div.step3selection').each(function(item) {
			// find the checkbox inside the div
			var cb = item.down('input.cbox');
			if(cb.checked == true)
			{
				sel = true;
			}
		});
		
		if(sel == true)
		{
			goahead = true;
		}		
		else
		{
			alert('Please select at least one style');
			currentstep--;
		}
	}
	else
	{
		goahead = true;
	}

	if(goahead)
	{

		running_callback = true;

		$('currentstep').value = currentstep;
		if( $('action') )
		{
			if(bandbust)
			{
				$('action').value = 'bandbustselection';
			}
			else
			{
				$('action').value = 'step';
			}
		}

		var form = $('mainAreaForm');
		var params = Form.serialize(form);
		new Ajax.Updater({ success: 'mainAreaInternal'}, 'brafinder.phtml?rp=1', {method: 'post', parameters: params, evalScripts: true, encoding: 'UTF-8'});
	}

}


function oncompleted()
{

	if(dropdowncallback)
	{
		dropdowncallback = false;
		running_callback = false;
		return;
	}

	running_callback = false;

}