// creates a logical map between pages in the web site and the sections of the forms.htm contents.
// this map permits the toggling of the related section of forms.htm, based on the referring page

var forms = new Object();

/*
	forms.section = new Object();
	forms.section[""]         = {name:"",                       label:""};
	forms.section["BOA"]      = {name:"assessors",              label:"Board of Assessors"};
	forms.section["BOH"]      = {name:"boh",                    label:"Board of Health"};
	forms.section["BOS"]      = {name:"bos",                    label:"Board of Selectmen"};
	forms.section["CPC"]      = {name:"cpc",                    label:"Community Preservation Committee"};
	forms.section["CONCOMM"]  = {name:"conservation",           label:"Conservation Commission Files"};
	forms.section["LIBRARY"]  = {name:"library",                label:"Library"};
	forms.section["MASTER"]   = {name:"masterplan",             label:"Master Plan"};
	forms.section["PLANNING"] = {name:"planning",               label:"Planning Board"};
	forms.section["POLICE"]   = {name:"police",                 label:"Police Department"};
	forms.section["CLERK"]    = {name:"clerk",                  label:"Town Clerk"};
	forms.section["BYLAWS"]   = {name:"bylaws",                 label:"Town of Carver"};
	forms.section["WARRANT"]  = {name:"townw",                  label:"Town Warrant"};
	forms.section["VET"]      = {name:"vet",                    label:"Veteran's Agent Files"};
	forms.section["ZONE"]     = {name:"zoning",                 label:"Zoning By Laws"};

	// map of web site pages to sections of the forms page
	forms.group = {
		"404.shtml"                                :"",
		"about.htm"                                :"",
		"agricultural_commission.html"             :"",
		"animal.htm"                               :"",
		"asfaq.htm"                                :"",
		"assessors_proposition_2.5.html"           :"BOA",
		"assessor_abatements.html"                 :"BOA",
		"assessor_boa_explained.html"              :"BOA",
		"assessor_chapterland.html"                :"BOA",
		"assessor_exemptions.html"                 :"BOA",
		"assessor_mv_excise_info.html"             :"BOA",
		"attractions.htm"                          :"",
		"ba.htm"                                   :"",
		"bag.htm"                                  :"",
		"boa.htm"                                  :"BOA",
		"boh.htm"                                  :"BOH",
		"bohfees.htm"                              :"BOH",
		"bos.htm"                                  :"BOS",
		"calendar.htm"                             :"",
		"clerksoff.htm"                            :"CLERK",
		"conform.htm"                              :"CONCOMM",
		"consagent.htm"                            :"CONCOMM",
		"conservation.htm"                         :"CONCOMM",
		"council.htm"                              :"",
		"cpc.htm"                                  :"CPC",
		"dare.htm"                                 :"",
		"dareskill.htm"                            :"",
		"directions.htm"                           :"",
		"directory.htm"                            :"",
		"dpw.htm"                                  :"",
		"dpwfaq.htm"                               :"",
		"ema.htm"                                  :"",
		"ems.htm"                                  :"",
		"fees.htm"                                 :"PLANNING",
		"fire.htm"                                 :"",
		"forms.htm"                                :"",
		"gazebo.htm"                               :"",
		"gismaps.html"                             :"",
		"harvest.htm"                              :"",
		"history.htm"                              :"BOA",
		"index.html"                               :"",
		"index2.html"                              :"",
		"inspectd.htm"                             :"",
		"inspectreq.htm"                           :"",
		"library.htm"                              :"",
		"links.htm"                                :"",
		"lunar.html"                               :"",
		"oldhomeday.htm"                           :"",
		"planning.htm"                             :"PLANNING",
		"police-fire_questionnaire.html"           :"POLICE",
		"police-fire_questionnaire.txt"            :"POLICE",
		"police-fire_questionnaire_thankyou.html"  :"POLICE",
		"police.htm"                               :"POLICE",
		"property.htm"                             :"",
		"recreation.htm"                           :"",
		"reps.htm"                                 :"",
		"schools.htm"                              :"",
		"search.htm"                               :"",
		"style.css"                                :"",
		"suggestions.htm"                          :"",
		"tindex.htm"                               :"",
		"townaccountant.htm"                       :"",
		"townadmin.htm"                            :"",
		"townmeeting.htm"                          :"WARRANT",
		"townw.htm"                                :"WARRANT",
		"townwresults.htm"                         :"WARRANT",
		"treastax.htm"                             :"",
		"vehicletran.htm"                          :"",
		"vetbenefit.htm"                           :"VET",
		"vetelig.htm"                              :"VET",
		"veteran.htm"                              :"VET",
		"vetfaq.htm"                               :"VET",
		"vth.html"                                 :"",
		"vth2.html"                                :"",
		"waste.htm"                                :"",
		"waste_marion.htm"                         :"",
		"wire.htm"                                 :"",
		"zba.htm"                                  :"ZONE",
		"zpictures.htm"                            :""
	}
*/

// map of form sections
forms.section = {
  "404.shtml"                                :"",
  "about.htm"                                :"",
  "agricultural_commission.html"             :"",
  "animal.htm"                               :"",
  "asfaq.htm"                                :"",
  "assessors_proposition_2.5.html"           :"assessors",
  "assessor_abatements.html"                 :"assessors",
  "assessor_boa_explained.html"              :"assessors",
  "assessor_chapterland.html"                :"assessors",
  "assessor_exemptions.html"                 :"assessors",
  "assessor_mv_excise_info.html"             :"assessors",
  "attractions.htm"                          :"",
  "ba.htm"                                   :"",
  "bag.htm"                                  :"",
  "boa.htm"                                  :"assessors",
  "boh.htm"                                  :"boh",
  "bohfees.htm"                              :"boh",
  "bos.htm"                                  :"bos",
  "calendar.htm"                             :"",
  "clerksoff.htm"                            :"clerk",
  "conform.htm"                              :"conservation",
  "consagent.htm"                            :"conservation",
  "conservation.htm"                         :"conservation",
  "council.htm"                              :"",
  "cpc.htm"                                  :"cpc",
  "dare.htm"                                 :"",
  "dareskill.htm"                            :"",
  "directions.htm"                           :"",
  "directory.htm"                            :"",
  "dpw.htm"                                  :"",
  "dpwfaq.htm"                               :"",
  "ema.htm"                                  :"",
  "ems.htm"                                  :"",
  "fees.htm"                                 :"planning",
  "fire.htm"                                 :"",
  "forms.htm"                                :"",
  "gazebo.htm"                               :"",
  "gismaps.html"                             :"assessors",
  "harvest.htm"                              :"",
  "history.htm"                              :"assessors",
  "index.html"                               :"",
  "index2.html"                              :"",
  "inspectd.htm"                             :"",
  "inspectreq.htm"                           :"",
  "library.htm"                              :"library",
  "links.htm"                                :"",
  "lunar.html"                               :"",
  "oldhomeday.htm"                           :"",
  "planning.htm"                             :"planning",
  "police-fire_questionnaire.html"           :"police",
  "police-fire_questionnaire.txt"            :"police",
  "police-fire_questionnaire_thankyou.html"  :"police",
  "police.htm"                               :"police",
  "property.htm"                             :"",
  "recreation.htm"                           :"",
  "reps.htm"                                 :"",
  "schools.htm"                              :"",
  "search.htm"                               :"",
  "style.css"                                :"",
  "suggestions.htm"                          :"",
  "tindex.htm"                               :"",
  "townaccountant.htm"                       :"",
  "townadmin.htm"                            :"masterplan",
  "townmeeting.htm"                          :"townw",
  "townw.htm"                                :"townw",
  "townwresults.htm"                         :"townw",
  "treastax.htm"                             :"",
  "vehicletran.htm"                          :"",
  "vetbenefit.htm"                           :"vet",
  "vetelig.htm"                              :"vet",
  "veteran.htm"                              :"vet",
  "vetfaq.htm"                               :"vet",
  "vth.html"                                 :"",
  "vth2.html"                                :"",
  "waste.htm"                                :"",
  "waste_marion.htm"                         :"",
  "wire.htm"                                 :"",
  "zba.htm"                                  :"zoning",
  "zpictures.htm"                            :""
}

function getReferrer(d) {
  if (null==d) d=document;
  ref = d.referrer;

  if ((ref=="") || (ref=="undefined")) {
    ref="bookmark";
  };

  return ref;
}

function getMappedAnchor(ref) {
  if (null==ref) ref = getReferrer();
  try {
    ref = ref.substring(ref.lastIndexOf("/")+1,ref.length);
    var anchor = forms.section[ref];
    return ((null==anchor)?"":anchor);

  } catch (e) {
    return "";
  }
}

function testPages() {
  try { if (LOG.showTrace()) LOG.trace(">>> testPages()"); } catch (e) {}
  var pages = new Array();
  for (p in forms.section) {
    pages.push(p);
  }

  for (var i=0; i<pages.length; i++) {
    var url = "http://www.carverma.org/" + pages[i]
    var ref = url.substring(url.lastIndexOf("/")+1,url.length);
    try { if (LOG.showTrace()) LOG.trace(url + " loads \"" + getMappedAnchor(ref) + "\". Toggle was found: " + toggleAnchor(getMappedAnchor(ref))); } catch (e) {}
    ;
  }
}
