
// these all utilize the jQuery library - http://docs.jquery.com/

var clonedList;

// toggle stage visibilty on portfolio-availability page 
function fieldsetswitcher(visiblefieldset) {
    $('.contenttholder fieldset').each(function(i,o) {
		if (i != visiblefieldset) {
			$(this).hide();
		} else {
			$(this).show();
		}
	});
}

// recalculate fields on compute-requirements page 
function CP_change_plane() {
	planetype = $('#bb option:selected').val();
	
	// hide all elements whose class begins with optg
	$('[class^=optg]').hide(); // doesnt work in IE
	$('[class^=optg]').css({ color:"#EEEEEE", fontWeight:"normal" });
	// show all elements whose class matches optg_$planetype
	$('.optg_' + planetype).show(); // doesnt work in IE
	$('.optg_' + planetype).css({ color:"#000000", fontWeight:"bolder" });
	
	// make sure that an incorrect one is not still selected
	// $('#cc').attr("selectedIndex", 0); // causes problems in IE
	
	// update thrust rating (actual calculation/value range was not provided)
	$('#dd').val( parseInt((planetype * 1000)) + 1000 );
	
	// update year list
	myYear = parseInt( $('#ee').val() );
	if (myYear) {
		$('#ff').val( myYear );
		$('#gg').val( myYear + 1 );
		$('#hh').val( myYear + 2 );
		$('#ii').val( myYear + 3 );
		$('#jj').val( myYear + 4 );
	} else {
		$('#ff').val( '' );
		$('#gg').val( '' );
		$('#hh').val( '' );
		$('#ii').val( '' );
		$('#jj').val( '' );
	}
	
	// and so on ...
	
}

$(document).ready(function(){

	clonedList = $('#cc').clone();

	// toggle default on/off status for portfolio-availability stages
	var visiblefieldset = 0;
	fieldsetswitcher(visiblefieldset);
	
	// show the "Next" buttons 
    $('.buttonnext').show();
	
	// handle the click event on "Next" buttons 
    $('.buttonnext').click(function(){ 
		// extract the X from togglefield_X - this is the fieldset we need to display 
		visiblefieldset = $(this).attr("id").substr(12,1);
		// alert(visiblefieldset);
		fieldsetswitcher(visiblefieldset);
		return false; 
	});
	
	// --- 
	
	// trigger compute-requirements recalculation
	$('#bb').change(function(){
		CP_change_plane();
	});
	$('#cc').change(function(){
		CP_change_plane();
	});
	$('#ee').change(function(){
		CP_change_plane();
	});
	
	CP_change_plane();
	
});


