function init() {
  //preparing the form. this is mostly necessary for when they come from
  //behind... when they hit BACK on the browser, you pervert!
  hoh_childrenf()
  hoh_spousef()
  switch_generic(0, 'hoh_is_employed', 'hoh_is_training')
  switch_generic(0, 'hoh_is_employed', 'hoh_salary_thisyear')
  switch_generic(1, 'hoh_is_employed', 'hoh_salary')	
  switch_generic(1, 'otherincome', 'otherincome_hf')
  
	//starting the questionnaire
	//Event.stopObserving doesn't seem to like anonymous functions
	function _f() {
		Effect.BlindDown('about_wrap');
		Event.stopObserving('start_questionnaire', 'click', _f)
		Event.stopObserving('header_about', 'click', _f)
		$('start_questionnaire').innerHTML = 'You have started the survey.'
	}
	Event.observe('start_questionnaire', 'click', _f)
	Event.observe('header_about', 'click', _f)


  //each onto-the-next-section header 
  Event.observe('about_next', 'click', function() {switch_section('family')})
  Event.observe('family_next', 'click', function() {switch_section('money')} )
  Event.observe('money_next', 'click', function() {
                write_theend(); switch_section('theend')} )
  Event.observe('submit_button', 'click', submit)
  
	
  //about
  Event.observe('hoh_spouse', 'blur', hoh_spousef)
	Event.observe('hoh_citizenship', 'blur', function() {
		if ($('hoh_citizenship').value <= 3) {Effect.BlindDown('filing_status_hf') }
		else {Effect.BlindUp('filing_status_hf') }
	})
		
	//family			
  Event.observe('hoh_children', 'change', hoh_childrenf)
  Event.observe('has_children_under5', 'blur',
	      function() {
            switch_generic(0, 'has_children_under5', 'has_children_under13_hf') })
  
  //money
  Event.observe('hoh_is_employed', 'blur',
	      function() {
			switch_generic(0, 'hoh_is_employed', 'hoh_is_training')
	      	switch_generic(0, 'hoh_is_employed', 'hoh_salary_thisyear')
			switch_generic(1, 'hoh_is_employed', 'hoh_salary')})
  
  Event.observe('spouse_is_employed', 'blur', function() {
	if ($('hoh_spouse').value == 1) {
	  switch_generic(0, 'spouse_is_employed', 'spouse_is_training')
	  switch_generic(1, 'spouse_is_employed', 'spouse_salary')
	}})
	
  Event.observe('otherincome', 'blur', function() {
		switch_generic(1, 'otherincome', 'otherincome_hf')})
  
  //var a = document.getElementsByClassName('family', 'family_wrap')[0].id
}

function switch_section(sectionId) {

  if (global_active_section != sectionId) {
	
	//validate the one we want to switch off
	try {
	  var error = eval('validate_' + global_active_section + '()')
	}
	catch (e) {}
	
	if (!error) {
	//** the actual switching
	  Effect.BlindUp(global_active_section + '_wrap')
	  Effect.BlindDown(sectionId + '_wrap')
	  global_active_section = sectionId
	  
	  //if the synopsis field is visible, hide it
	  try {
		synField = sectionId + '_synopsis'
		if ($(synField).style.display != 'none') {Effect.BlindUp(synField)}
	  }
	  catch (e) {}
	}
  }
}

function switch_section_goback(sectionId) {
  //this one will be attached to each synopsis field.
  //the difference is that it handles the error validate() returns, and
  //lets you fold the active section even with it.
  //this doesn't happen with the "go to the next section" buttons (if there's
  //an error, you are not going anywhere on those)
  
  if (global_active_section != sectionId) {
	
	
	//validate the one we want to switch off
	try {
	  var error = eval('validate_' + global_active_section + '()')
	}
	catch (e) {}
	
	if (error) {
	  var synField = global_active_section + '_synopsis'
		var e = document.createElement('div')
		e.className = 'synopsis_error'
	  e.innerHTML = 'You did not answers all the questions in this \n\
					section. Please do so before submitting the questionnaire.'
	  $(synField).appendChild(e)
	
	  Effect.BlindDown(synField)
	  global_error = 1
	}

  //** the actual switching
	Effect.BlindUp(global_active_section + '_wrap')
	Effect.BlindDown(sectionId + '_wrap')
	global_active_section = sectionId
	
	//if the synopsis field is visible, hide it
	try {
	  var synField = sectionId + '_synopsis'
	  if ($(synField).style.display != 'none') {Effect.BlindUp(synField)}
	}
	catch (e) {}
  }
}


function switch_generic(valueMustBe, fieldToCheck, fieldToSwitch) {
  //if (eval('$('TheForm').'+fieldToCheck+'.value') == valueMustBe) {
  if ($(fieldToCheck).value == valueMustBe) {
    if (document.getElementById(fieldToSwitch).style.display == 'none') {
      Effect.BlindDown(fieldToSwitch)
    }
  }
  else {
    if (document.getElementById(fieldToSwitch).style.display != 'none') {
      Effect.BlindUp(fieldToSwitch)
    }
  }
}

//**** some non-generic switch functions
function hoh_childrenf() {
  if ($('TheForm').hoh_children.value > 0) {
    if ($('has_children_under5_hf').style.display == 'none') {
      Effect.Appear('has_children_under5_hf')
    }
    if ($('has_children_under13_hf').style.display == 'none') {
      Effect.Appear('has_children_under13_hf')
    }
    if ($('hoh_citizenship').value == 4 &&
        $('children_citizenship_hf').style.display == 'none') {
      Effect.Appear('children_citizenship_hf')
    }
  }
  else {
    if ($('has_children_under5_hf').style.display != 'none') {
      Effect.SwitchOff('has_children_under5_hf')
    }
    if ($('has_children_under13_hf').style.display != 'none') {
      Effect.SwitchOff('has_children_under13_hf')
    }
    if ($('children_citizenship_hf').style.display != 'none') {
      Effect.SwitchOff('children_citizenship_hf')
    }
  }
}

function hoh_spousef() {
  if ($('hoh_spouse').value == 0) {
	//hide everything
	if ($('spouse_is_employed_hf').style.display != 'none') {
	  Effect.BlindUp('spouse_is_employed_hf') }
	if ($('spouse_salary').style.display != 'none') {
	  Effect.BlindUp('spouse_salary') }
	if ($('spouse_is_training').style.display != 'none') {
	  Effect.BlindUp('spouse_is_training') }
  }
  else {
	//show "is spouse employed"
	if ($('spouse_is_employed_hf').style.display == 'none') {
	  Effect.BlindDown('spouse_is_employed_hf') }
	//check the spouse_is_employed valud and display salary/training accordingly
	switch_generic(0, 'spouse_is_employed', 'spouse_is_training')
	switch_generic(1, 'spouse_is_employed', 'spouse_salary')
  }
} 

function write_theend() {
  
	if ($('hoh_citizenship').value == 4 || $('filing_status').value <= 0) {
    $('hoh_salary_thisyear_hf').style.display = 'none'
    $('spouse_salary_thisyear_hf').style.display = 'none'
	}
  else {
    //show hoh_salary_thisyear?
    if ($('hoh_is_employed').value == 0) {
      $('hoh_salary_thisyear_hf').style.display = 'none'
    }
    else {$('hoh_salary_thisyear_hf').style.display = 'none' }
    
    //show spouse_salary_thisyear?
    if ( ($('hoh_spouse').value == 1 && $('spouse_is_employed').value == 0) ||
         ($('hoh_spouse').value == 0 && $('filing_status').value == 'joint') ) {
      $('spouse_salary_thisyear_hf').style.display = 'none' 
    }
    else {$('spouse_salary_thisyear_hf').style.display = 'none'}
  }
  

    //... and what will we say
//  if ($('hoh_salary_thisyear_hf').style.display == 'block' ||
//      $('spouse_salary_thisyear_hf').style.display == 'block') {
//    msg = 'You may still be able to get a tax credit if you (or your spouse) \n\
//           had any earned income in 2007, and are filing a tax return.<br/> \n\
//           Answer the question(s) below and we will tell you \n\
//          (you can ignore it otherwise).<br/><br/>'
//  }
//  else {
	msg = 'Please review your answers for each section to make sure they \n\
       reflect your current situation. Then click on the button below.'
//  }
  
  var e = document.createElement('div')
  e.id = 'theend_text'
  $('theend_text').innerHTML = msg
  
  $('submit').style.display = 'block'
}

function toggleProgramParagraph(whichDiv) {
	//the header id, which has the arrow as a background img
	h2_id = $(whichDiv).id.split('__')[0] + '__h2'
	
	if ($(whichDiv).style.display == 'none') {		
		$(h2_id).style.background = 'url(/static/img/h2_bullet_rotated.gif) no-repeat 0px'
		$(whichDiv).style.display = 'block'
  }
	else {
		$(h2_id).style.background = 'url(/static/img/h2_bullet.gif) no-repeat 0px'
		$(whichDiv).style.display = 'none'
	}
}

function showProgramParagraph(whichDiv) {
  if ($(whichDiv).style.display == 'none') {
		h2_id = $(whichDiv).id.split('__')[0] + '__h2'
		$(h2_id).style.background = 'url(/static/img/h2_bullet_rotated.gif) no-repeat 0px'
		$(whichDiv).style.display = 'block'		
	}
}