// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
//
// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject

function switchIfDone(the_form, this_div, next_div)
{

  var complete = true;
  for (var loop=0; loop < the_form.elements.length; loop++)
  {
    if (the_form.elements[loop].value == "")
    {
      complete = false;
    }
  }
  if ((complete == true) && (next_div == "finished")) 
  {
    submitTheInfo();
  } 
  else if (complete == true) 
  {
    switchDiv(this_div, next_div);
  } else {
    alert('please complete the form before moving on');
  }
}

function switchDiv(this_div, next_div)
{
  if (getStyleObject(this_div) && getStyleObject(next_div)) {
    changeObjectVisibility("group1", "hidden");
    changeObjectVisibility("group2", "hidden");
    changeObjectVisibility("group3", "hidden");
    changeObjectVisibility("group4", "hidden");
    changeObjectVisibility("group5", "hidden");
    changeObjectVisibility("group6", "hidden");
    changeObjectVisibility("group7", "hidden");
    changeObjectVisibility("group8", "hidden");
    changeObjectVisibility("group9", "hidden");
    changeObjectVisibility("group10", "hidden");
    changeObjectVisibility("group11", "hidden");
    changeObjectVisibility(next_div, "visible");
    setDivsByAttribute('notesGroup', 'hidden', document)
    setDivsByAttribute2('donationsGroup', 'hidden', document)
  }
}

function switchNotesDiv(this_div)
{
  setDivsByAttribute('notesDiv', 'hidden', document);
  if (getStyleObject(this_div)) 
  {
    changeObjectVisibility(this_div, "visible");
  }  
}

function switchDonationsDiv(this_div)
{
  setDivsByAttribute('donationsDiv', 'hidden', document);
  if (getStyleObject(this_div)) 
  {
    changeObjectVisibility(this_div, "visible");
  }  
}

function setDivsByAttribute(inputName,val,container)
{
container = container||document
var y = 1;
var all = container.all||container.getElementsByTagName('*')
var arr = []
for(var k=0;k<all.length;k++)
if(all[k].id.substr(0,10) == 'notesGroup')
{
  y++;
  all[k].style.visibility = val;
}
}

function setDivsByAttribute2(inputName,val,container)
{
container = container||document
var y = 1;
var all = container.all||container.getElementsByTagName('*')
var arr = []
for(var k=0;k<all.length;k++)
if(all[k].id.substr(0,14) == 'donationsGroup')
{
  y++;
  all[k].style.visibility = val;
}
}

function makeVisibleDiv(this_div)
{
  if (getStyleObject(this_div)) {
    changeObjectVisibility(this_div, "visible");
  }
}

function submitTheInfo()
{
  var submission_string="";
  for (var form_loop=0; form_loop<document.forms.length; form_loop++) 
  {
    for (var elems=0; elems<document.forms[form_loop].length;elems++)
    {
      if (document.forms[form_loop].elements[elems].name != "")
      {
        submission_string += document.forms[form_loop].name + "_" +
          document.forms[form_loop].elements[elems].name + "=" +
          document.forms[form_loop].elements[elems].value + "\n";
      }
    }
  }
  document.hiddenform.the_text.value = submission_string;

  // the next two lines are written for debugging - 
  // to put the script into action
  // comment out the changeObjectVisibility() line
  // and uncomment the document.hidden.form.submit() line
  //

  //document.hiddenform.submit(); 
  changeObjectVisibility("hiddenstuff","visible");
}