function toggleSection( section )
{
	
	if( $(section).visible() )
	{
		new Effect.SlideUp( section, {
			queue: 'end',
			afterFinish: function(){
				$(section + '_link').innerHTML = "[Display]";
			}
		});
	}
	else
	{
		new Effect.SlideDown( section, {
			queue: 'end',
			afterFinish: function(){
				$(section + '_link').innerHTML = "[Hide]";				
			}
		});
		
	}
}

function checkEducation( )
{
	var displayEducation = false;
	var homestudy = false;
	var boxes = $$('input.purchase_types');
	for(var i = 0; i < boxes.length; ++i){
		if( boxes[i].checked )
		{
			if( boxes[i].value != 'cont_ed' )
				displayEducation = true;
			if( boxes[i].value == 'home_study' )
				var homestudy = true;
		}
	}

	if( homestudy )
	{
		$('training_question').style.display = 'none';
		$('education_section').style.display = 'none';
		
		$('base_emp_message').style.display = "none";
		$('home_study_emp_message').style.display = "";
		
		$('education_training').style.display = '';
		$('employment_section').style.display = '';	
	}
	else{
	
		$('training_question').style.display = '';
		
		if( $('trainingY').checked )
			$('education_section').style.display = '';
		else
			$('education_section').style.display = 'none';
			
		if( $('experienceY').checked )
			$('employment_section').style.display = '';	
		else
			$('employment_section').style.display = 'none';	
			
				
		$('base_emp_message').style.display = "";
		$('home_study_emp_message').style.display = "none";
		
		if( displayEducation )
			$('education_training').style.display = '';
		else
			$('education_training').style.display = 'none';
	}
}

function updateStudyGuides( row )
{
	if( row.checked )
	{
		if( $('exam_location_' + row.value ) )
			$('exam_location_' + row.value ).style.display="";
	}
	else
	{
		if( $('exam_location_' + row.value ) )
			$('exam_location_' + row.value ).style.display="none";
	}
	
	if( $('wizard_form' ) )
	{
	
		var url = 'ajax/ajax.update_study_guides.php';
		var div = 'study_guide_options';
		
		var params = $('wizard_form').serialize();
		
		var ajax = new Ajax.Updater( 
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
}

function updateCEPrice( which, mult_price, base_price, reinstate_price )
{
	var base = parseFloat( base_price );
	var mult = parseFloat( mult_price );
	var reinstate = parseFloat( reinstate_price );
	
	if( which == 'missing' )
	{
		if( $('missed_extra_numb').value )
			var numb_certs = parseInt($('missed_extra_numb').value);
		else
			var numb_certs = 0;

		var new_total = 0;	
		if( $('missed_single_cert').checked )
			new_total += base;
		if( $('missed_multiple_cert').checked )
			new_total += ( mult * numb_certs );	
		
		var mult_total = mult * numb_certs;
		
		if( $('missed_reinstatement').checked )
		{
			new_total = new_total + reinstate;
		}
		
		mult_total = mult_total.toFixed( 2 );	
		new_total = new_total.toFixed( 2 );
		
		$('missed_ce_total').innerHTML = "$" + new_total;
		
		$('missed_mutliple_cert_total').innerHTML = "$" + mult_total;
		
		if( !$('missed_multiple_cert').checked && numb_certs > 0 )
		{
		//	$('missed_multiple_cert').checked = true;
		}
		
		$('extra_numb').value = "";
		$('reinstatement').checked = false;
		$('ce_total').innerHTML = "$0.00";
		$('mutliple_cert_total').innerHTML = "$0.00";
		$('single_cert').checked = false;
		$('multiple_cert').checked = false;
	}
	else
	{
		var numb_certs = $('extra_numb').value;
		
		var new_total = 0;	
		if( $('single_cert').checked )
			new_total += base;
		if( $('multiple_cert').checked )
			new_total += ( mult * numb_certs );	
		
		var mult_total = mult * numb_certs;
		
		if( $('reinstatement').checked )
		{
			new_total = new_total + reinstate;
		}
		
		mult_total = mult_total.toFixed( 2 );	
		new_total = new_total.toFixed( 2 );
		
		$('ce_total').innerHTML = "$" + new_total;
		$('mutliple_cert_total').innerHTML = "$" + mult_total;
		
		if( !$('multiple_cert').checked && numb_certs > 0 )
		{
		//	$('multiple_cert').checked = true;
		}
		
		$('missed_extra_numb').value = "";
		$('missed_reinstatement').checked = false;
		$('missed_ce_total').innerHTML = "$0.00";
		$('missed_mutliple_cert_total').innerHTML = "$0.00";
		$('missed_single_cert').checked = false;
		$('missed_multiple_cert').checked = false;
	}
}

function checkSSN( box, number )
{
	if( box.value.length == number )
	{
		if( number == '3' )
			$('ssn_2').focus();
		if( number == '2' )
			$('ssn_3').focus();
	}
}

function checkTraining( box )
{
	if( box.value == 'Y' )
		$('education_section').style.display = "";
	else
		$('education_section').style.display = "none";
}

function checkEmployement( box )
{
	if( box.value == 'Y' )
		$('employment_section').style.display = "";
	else
		$('employment_section').style.display = "none";
}

function updateLocation( row, li )
{
	var name = row.id;
	
	var parts = name.split('_');
	
	var name = parts[0];
	var cert = parts[1];
	
	
	$('code_' + cert ).value = li.id;
}

function updateLocations( param_var, numb )
{
	eval( param_var + "=" + '"which=' + numb + '&state=' + $('state_' + numb).value +'&country=' + $('country_val').value + '";');
	
	eval( 'var auto_' + numb + ' = new Ajax.Autocompleter("location_' + numb + '", "autocomplete_choices", "ajax/ajax.search_sites.php", {parameters: params_' + numb + ', afterUpdateElement: updateLocation, minChars: 2} );' );
}

function checkComplete( row, numb )
{
	if (row.value=='Enter Exam Location')
	{ row.value = ''; }
	
	if( $('state_' + numb).selectedIndex == 0 )
	{
		alert('Please choose a state before entering a location');
		$('state_' + numb).focus();
	}
}

function checkCountry( country, which, counter )
{
	if( country.value == 'USA' )
	{
		if( which == 'education')
		{
			$('education_state_' + counter).style.display = "";
		}
		else if( which == 'personal' )
		{
			$('personal_state').style.display = "";
		}
		else if( which == 'employment' )
		{
			$('employment_state').style.display = "";
		}
	}
	else
	{
		if( which == 'education')
		{
			$('education_state_' + counter).style.display = "none";
		}
		else if( which == 'personal' )
		{
			$('personal_state').style.display = "none";
		}
		else if( which == 'employment' )
		{
			$('employment_state').style.display = "none"
		}
	}
}

function addEducationRow( id )
{
	var url = 'ajax/ajax.add_education_row.php';
	var div = 'blank_education_' + id;
	
	var params = $('wizard_form').serialize();
	params = params + "&new_id=" + id;
	var ajax = new Ajax.Updater( 
		div,
		url,
		{
			parameters: params,
			method: 'post',
			evalScripts: true
		}
	);
}

function checkDate( id )
{
	if( $('no_date_' + id ).checked )
	{
		$('text_id_info[exams][' + id + '][date]' ).disabled = true;
		$('anchor'+id).style.display = "none";
	}
	else
	{
		$('text_id_info[exams][' + id + '][date]' ).disabled = false;
		$('anchor'+id).style.display = "";
	}
}

function checkLocation( id )
{
	if( $('no_location_' + id ).checked )
	{
		$('location_' + id ).disabled = true;
		$('location_' + id ).value = "Not Sure";
	}
	else
	{
		$('location_' + id ).disabled = false;
		$('location_' + id ).value = "";
	}
}

function updateCardPrice( div, price )
{
	var qtys = $$('input.card_qty');
	var total_exams = 0;
	var total_price = 0;
	for( var i = 0; i < qtys.length; i++ )
	{
		if( qtys[i].value && parseInt(qtys[i].value) > 0 )
			total_exams = parseInt( total_exams ) + parseInt( qtys[i].value );
	}
	
	total_price = total_exams * parseInt( price );
	
	$(div).innerHTML = "$" + total_price + ".00";
}

function updateCustomTotal()
{
	var numb_credits = parseInt( $('numb_credits').value );
	var price_per_credit = parseFloat( $('price_per_credit').value );
	var numb_certs = parseInt( $('numb_certs').value );
	var extra_cert_fee = parseFloat( $('extra_cert_fee').value );
	var reinstatement_fee = parseFloat( $('reinstatement_fee').value );
	
	var total = 0;
	
	if( numb_credits && price_per_credit )
	{
		total += numb_credits * price_per_credit;
	}
	if( numb_certs && extra_cert_fee )
	{
		total += numb_certs * extra_cert_fee;
	}
	if( reinstatement_fee )
	{
		total += reinstatement_fee;
	}
	
	new_total = total.toFixed( 2 );
	
	$('total').innerHTML = "$" + total;
	$('total_amt').value = total;
}