
var myResources=new Array();
myResources[0]=new Array('The Department of Veterans Affairs','http://www.va.gov');
myResources[1]=new Array('The American Legion','http://www.legion.org')
myResources[2]=new Array('National Veterans Foundation','http://www.nvf.org')
myResources[3]=new Array('Veterans of Foreign Wars','http://www.vfw.org')
myResources[4]=new Array('Vietnam Veterans of America','http://www.vva.org')
myResources[5]=new Array('AMVETS','http://www.amvets.org')
myResources[6]=new Array('Blinded Veterans Association','http://www.bva.org')
myResources[7]=new Array('National Gulf War Resource Center','http://www.ngwrc.org')
myResources[8]=new Array('Veterans Service Organization Directory','http://www.va.gov/vso/')
myResources[9]=new Array('Iraq War Veterans Organization','vwww.iraqwarveterans.org')
myResources[10]=new Array('VA Watchdog dot Org ','http://www.vawatchdog.org')
myResources[11]=new Array('Stand Up For Veterans','http://www.standup4vets.org/')
myResources[12]=new Array('National Center for PTSD','http://www.ncptsd.va.gov/')
myResources[13]=new Array('Mental Health Self-Assessment Program','http://www.mentalhealthscreening.org/military/index.aspx')
myResources[14]=new Array('TRICARE','http://www.tricare.mil/')
myResources[15]=new Array('NGWRCs Self Help Guide','http://www.gulfweb.org/bigdoc/selfhelp.cfm')
myResources[16]=new Array('Disabled American Veterans','http://www.dav.org/')
myResources[17]=new Array('Wounded Warrior Project','http://www.woundedwarriorproject.org/')
myResources[18]=new Array('Veterans Eye Care','http://www.veteranseyecare.com/')
myResources[19]=new Array('Amputee Coalition of America','http://www.amputee-coalition.org/')
myResources[20]=new Array('Blinded Veterans Association','http://www.bva.org/')
myResources[21]=new Array('Paralyzed Veterans of America','http://www.pva.org/')
myResources[22]=new Array('Lariam Action USA','http://www.lariaminfo.org/')
myResources[23]=new Array('The Military Vaccine Education Center','http://www.mvrd.org')
myResources[24]=new Array('Veterans and Families','http://www.veteransandfamilies.org/')
myResources[25]=new Array('National Center for Post-Traumatic Stress Disorder','http://www.ncptsd.va.gov/')
myResources[26]=new Array('Give an Hour','http://www.giveanhour.org/')
myResources[27]=new Array('PTSD HelpNet','http://www.ptsdhelp.net/')
myResources[28]=new Array('Vet Centers','http://www.vetcenter.va.gov/')
myResources[29]=new Array('VVA PTSD Claims Guide','http://www.vva.org/Benefits/ptsd.htm')
myResources[30]=new Array('The Coming Home Project','http://www.cominghomeproject.net/')
myResources[31]=new Array('Mental Health Self-Assessment Program','http://www.mentalhealthscreening.org/military/index.aspx')
myResources[32]=new Array('Hire Heroes USA','http://www.hireheroesusa.org/')
myResources[33]=new Array('RecruitMilitary','http://www.recruitmilitary.com/')
myResources[34]=new Array('Helmets to Hardhats','http://helmetstohardhats.org/')
myResources[35]=new Array('ESGR: Employer Support of the Guard and Reserve','http://www.esgr.org/')
myResources[36]=new Array('VetBiz','http://www.vetbiz.gov/')
myResources[37]=new Array('Veteran Job Search at Military.com','http://www.military.com/jobsearch')
myResources[38]=new Array('HireVetsFirst.gov','http://www.hirevetsfirst.gov')
myResources[39]=new Array('REALifelines','http://www.hirevetsfirst.gov/realifelines/')
myResources[40]=new Array('Career Command Post','http://www.careercommandpost.com/')
myResources[41]=new Array('VetJobs.com','http://vetjobs.com/')
myResources[42]=new Array('Return to Work','http://www.return2work.org/')
myResources[43]=new Array('National Coalition for Homeless Veterans','http://www.nchv.org/')
myResources[44]=new Array('U.S. Dept. of House and Urban Dev. Vet. Resouce Center (HUDVET)','http://www.hud.gov/offices/cpd/about/hudvet/')
myResources[45]=new Array('Department of Veterans Affairs','http://www.va.gov/')
myResources[46]=new Array('National Coalition for the Homeless','http://www.nationalhomeless.org/')
myResources[47]=new Array('GI Bill Info from the VA','http://www.gibill.va.gov/')
myResources[48]=new Array('Federal Student Aid','http://studentaid.ed.gov/') 
myResources[49]=new Array('The Fund for Veterans Education','http://www.veteransfund.org/')
myResources[50]=new Array('Federal Tuition Assistance','https://minuteman.ngb.army.mil/Benefits/')
myResources[51]=new Array('National Veterans Legal Service','http://www.nvlsp.org/')
myResources[52]=new Array('Military Law Task Force','http://www.nlgmltf.org/')
myResources[53]=new Array('The Center for Constitutional Rights','http://ccrjustice.org/')
myResources[54]=new Array('Board of Veteran Appeals','http://www.va.gov/vbs/bva/')
myResources[55]=new Array('Veterans Consortium Pro Bono Program','http://www.vetsprobono.org/')
myResources[56]=new Array('ABA Standing Committee on Legal Assist. for Mil. Personnel','http://www.abanet.org/legalservices/lamp/')
myResources[57]=new Array('National Organization of Veterans\' Affairs','http://www.navao.org/')
myResources[58]=new Array('LawHelp','http://www.lawhelp.org/')
myResources[59]=new Array('Navy Marine Corps Relief Society','http://www.nmcrs.org/')
myResources[60]=new Array('Army Emergency Relief','http://www.aerhq.org/')
myResources[61]=new Array('Air Force Aid Society','https://www.afas.org/')
myResources[62]=new Array('Coast Guard Mutual Assistance','http://www.cgmahq.org/')
myResources[63]=new Array('Minstrel Boy','http://minstrelboy.blogspot.com/')
myResources[64]=new Array('Military Spouse Resource Center','http://www.milspouse.org/')
myResources[65]=new Array('National Military Family Association','http://www.nmfa.org/')
myResources[66]=new Array('Sgt. Mom\'s','http://www.sgtmoms.com')
myResources[67]=new Array('Society of Military Widows','http://www.militarywidows.org/')
myResources[68]=new Array('TAPS (Tragedy Assistance Program for Survivors)','http://www.taps.org/')
myResources[69]=new Array('VFW National Home for Children','http://www.vfwnationalhome.org/')
myResources[70]=new Array('Women Veterans Health','http://www1.va.gov/wvhp/')
myResources[71]=new Array('Women\'s Health.gov','http://www.4woman.gov/')
myResources[72]=new Array('The Miles Foundation','http://hometown.aol.com/milesfdn/')
myResources[73]=new Array('New Directions','http://www.newdirectionsbrooklyn.com/')
myResources[74]=new Array('Swords to Plowshares','http://swords-to-plowshares.org/')
myResources[75]=new Array('Veterans Resource Central','http://www.veteransresourcecentral.org/')
myResources[76]=new Array('Project Healing Waters','http://www.projecthealingwaters.org/')

function randomResource(randomNumber){
	if(!randomNumber)
	{
		randomNumber=parseInt(myResources.length * Math.random());
	}
	return('<b>Resources for veterans </b>: <a href="'+myResources[randomNumber][1]+'" target="_blank">'+myResources[randomNumber][0]+'</a>&nbsp;&nbsp;(<a href="http://facesofcombat.us/resources/">see all</a>)');
}

function printDate(){
	var day="";
	var month="";
	var myweekday="";
	var year="";

	mydate = new Date();
	myday = mydate.getDay();
	mymonth = mydate.getMonth();
	myweekday= mydate.getDate();
	weekday= myweekday;
	myyear= mydate.getFullYear();
	year = myyear;

	if(myday == 0){
		day = " Sunday, ";
	} else if(myday == 1){
		day = " Monday, ";
	} else if(myday == 2){
		day = " Tuesday, ";
	} else if(myday == 3){
		day = " Wednesday, ";
	} else if(myday == 4){
		day = " Thursday, ";
	} else if(myday == 5){
		day = " Friday, ";
	} else if(myday == 6){
		day = " Saturday, ";
	}

	if(mymonth == 0){
		month = "January ";
	} else if(mymonth == 1){
		month = "February ";
	} else if(mymonth == 2){
		month = "March ";
	} else if(mymonth == 3){
		month = "April ";
	} else if(mymonth == 4){
		month = "May ";
	} else if(mymonth == 5){
		month = "June ";
	} else if(mymonth == 6){
		month = "July ";
	} else if(mymonth == 7){
		month = "August ";
	} else if(mymonth == 8){
		month = "September ";
	} else if(mymonth == 9){
		month = "October ";
	} else if(mymonth == 10){
		month = "November ";
	} else if(mymonth == 11){
		month = "December ";
	}

	document.write(day + month + myweekday + ", " + year);

}

function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}


// TOC //
generated_toc = {
  generate: function() {
    // Identify our TOC element, and what it applies to
    generate_from = '0';
    generate_for = 'page';
    tocparent = document.getElementById('generated-toc');
    if (tocparent) {
      // there is a div class="generated-toc" in the document
      // dictating where the TOC should appear
      classes = tocparent.className.split(/\s+/);
      for (var i=0; i<classes.length; i++) {
        // if it specifies which heading level to generate from,
        // or what level to generate for, save these specifications
        if (classes[i].match(/^generate_from_h[1-6]$/)) {
          generate_from = classes[i].substr(classes[i].length-1,1);
        } else if (classes[i].match(/^generate_for_[a-z]+$/)) {
          generate_for = classes[i].match(/^generate_for_([a-z])+$/)[1];
        }
      }
    } else {
      // They didn't specify a TOC element; exit
      return;
    }
    
    // set top_node to be the element in the document under which
    // we'll be analysing headings
    if (generate_for == 'page') {
      top_node = document.getElementsByTagName('body')[0];
    } else {
      // i.e., explicitly set to "parent", left blank (so "unset"),
      // or some invalid value
      top_node = document.getElementById('resources')[0];
    }
    
    // If there isn't a specified header level to generate from, work
    // out what the first header level inside top_node is
    // and make that the specified header level
    if (generate_from == 0) {
      first_header_found = generated_toc.findFirstHeader(top_node);
      if (!first_header_found) {
        // there were no headers at all inside top_node!
        return;
      } else {
        generate_from = first_header_found.toLowerCase().substr(1);
      }
    }
    
    // add all levels of heading we're paying attention to to the
    // headings_to_treat dictionary, ready to be filled in later
    headings_to_treat = {"h6":''};
    for (var i=5; i>= parseInt(generate_from); i--) {
      headings_to_treat["h" + i] = '';
    }
    
    // get headings. We can't say 
    // getElementsByTagName("h1" or "h2" or "h3"), etc, so get all
    // elements and filter them ourselves
    // need to use .all here because IE doesn't support gEBTN('*')
    nodes = top_node.all ? top_node.all : top_node.getElementsByTagName('*');
    
    // put all the headings we care about in headings
    headings = [];
    for (var i=0; i<nodes.length;i++) {
      if (nodes[i].nodeName.toLowerCase() in headings_to_treat) {
        // if heading has class no-TOC, skip it
        if ((' ' + nodes[i].className + ' ').indexOf('no-TOC') != -1) {
          continue;
        }
        headings.push(nodes[i]);
      }
    }
    
    // make the basic elements of the TOC itself, ready to fill into
    
    // first, check if there's a cookie defined to save the state as open
    status = generated_toc.readCookie("generated_toc_display");
    if (status && status == "open") {
      display_initially = "block";
      toggle_initially = "Hide table of contents";
    } else {
      display_initially = "none";
      toggle_initially = "Show table of contents";
    }

    cur_head_lvl = "h" + generate_from;
    cur_list_el = document.createElement('ul');
    cur_list_el.style.display = display_initially;
    p = document.createElement('p');
    span = document.createElement('span');
    span.className = 'hidden';
    a = document.createElement('a');
    a.href = '#aftertoc';
    a.appendChild(document.createTextNode('skip table of contents'));
    span.appendChild(a);
    p.appendChild(span);
    //tocparent.appendChild(p);
    p = document.createElement('p');
    p.id = 'toggle-container'; 
    a = document.createElement('a');
    a.id = 'generated_toc_d_toggle';
    a.appendChild(document.createTextNode(toggle_initially));
    p.appendChild(a);
    a.onclick = generated_toc.wrapOpenClose(a,cur_list_el);
    a.href = '#';
    tocparent.appendChild(p);
    tocparent.appendChild(cur_list_el);
    
    // now walk through our saved heading nodes
    for (var i=0; i<headings.length; i++) {
      this_head_el = headings[i];
      this_head_lvl = headings[i].nodeName.toLowerCase();
      if (!this_head_el.id) {
        // if heading doesn't have an ID, give it one
        this_head_el.id = 'heading_toc_j_' + i;
        this_head_el.setAttribute('tabindex','-1');
      }
      
      while(this_head_lvl > cur_head_lvl) {
        // this heading is at a lower level than the last one;
        // create additional nested lists to put it at the right level

        // get the *last* LI in the current list, and add our new UL to it
        var last_listitem_el = null;
        for (var j=0; j<cur_list_el.childNodes.length; j++) {
          if (cur_list_el.childNodes[j].nodeName.toLowerCase() == 'li') {
            last_listitem_el = cur_list_el.childNodes[j];
          }
        }
        if (!last_listitem_el) {
          // there aren't any LIs, so create a new one to add the UL to
          last_listitem_el = document.createElement('li');
        }
        new_list_el = document.createElement('ul');
        last_listitem_el.appendChild(new_list_el);
        cur_list_el.appendChild(last_listitem_el);
        cur_list_el = new_list_el;
        cur_head_lvl = 'h' + (parseInt(cur_head_lvl.substr(1,1)) + 1);
      }
      
      while (this_head_lvl < cur_head_lvl) {
        // this heading is at a higher level than the last one;
        // go back up the TOC to put it at the right level
        cur_list_el = cur_list_el.parentNode.parentNode;
        cur_head_lvl = 'h' + (parseInt(cur_head_lvl.substr(1,1)) - 1);
      }
      
      // create a link to this heading, and add it to the TOC
      li = document.createElement('li');
      a = document.createElement('a');
      a.href = '#' + this_head_el.id;
      a.appendChild(document.createTextNode(generated_toc.innerText(this_head_el)));
      li.appendChild(a);
      cur_list_el.appendChild(li);
    }
    
    // add an aftertoc paragraph as destination for the skip-toc link
    p = document.createElement('p');
    p.id = 'aftertoc';
    tocparent.appendChild(p);
    
    // go through the TOC and find all LIs that are "empty", i.e., contain
    // only ULs and no links, and give them class="missing"
    var alllis = tocparent.getElementsByTagName("li");
    for (var i=0; i<alllis.length; i++) {
      var foundlink = false;
      for (var j=0; j<alllis[i].childNodes.length; j++) {
        if (alllis[i].childNodes[j].nodeName.toLowerCase() == 'a') {
          foundlink = true;
        }
      }
      if (!foundlink) {
        alllis[i].className = "missing";
      } else {
        alllis[i].className = "notmissing";
      }
    }
    
  },
  
  wrapOpenClose: function(a, cur_list_el) {
    // we return a function here so that it acts as a closure;
    // in essence the inner function, which is the event handler
    // for clicking on the toggle-toc link, remembers the a and cur_list_el
    // elements as they are when they're passed in to it.
    // This is an explicit function rather than an anonymous function
    // defined where it's called so it's easier to understand.
    return function(e) {
      d = cur_list_el.style.display;
      a.firstChild.nodeValue = (d == 'block' ? 'Show' : 'Hide') + ' table of contents';
      a.className = (d == 'block' ? 'toggle-closed' : 'toggle-open'); 
      cur_list_el.style.display = d == 'block' ? 'none' : 'block';
      // set a cookie to "open" or "closed" to save the state of the TOC
      if (cur_list_el.style.display == "block") {
        generated_toc.createCookie("generated_toc_display","open",21);
      } else {
        generated_toc.createCookie("generated_toc_display","closed",21);
      }
      if (window.event) {
        window.event.returnValue = false;
        window.event.cancelBubble = true;
      } else {
        e.preventDefault();
        e.stopPropagation();
      }
    }
  },
  
  /* cookie handling: http://www.quirksmode.org/js/cookies.html */
  createCookie: function(name,value,days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  },

  readCookie: function(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) 
        return c.substring(nameEQ.length,c.length);
    }
    return null;
  },

  eraseCookie: function(name) {
    createCookie(name,"",-1);
  },  
  
  innerText: function(el) {
    return (typeof(el.innerText) != 'undefined') ? el.innerText :
          (typeof(el.textContent) != 'undefined') ? el.textContent :
          el.innerHTML.replace(/<[^>]+>/g, '');
  },
  
  findFirstHeader: function(node) {
    // a recursive function which returns the first header it finds inside
    // node, or null if there are no functions inside node.
    var nn = node.nodeName.toLowerCase();
    if (nn.match(/^h[1-6]$/)) {
      // this node is itself a header; return our name
      return nn;
    } else {
      for (var i=0; i<node.childNodes.length; i++) {
        var subvalue = generated_toc.findFirstHeader(node.childNodes[i]);
        // if one of the subnodes finds a header, abort the loop and return it
        if (subvalue) return subvalue;
      }
      // no headers in this node at all
      return null;
    }
  },

  init: function() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    generated_toc.generate();
  }
};

$(document).ready(function() {

    generated_toc.init();
});

// end TOC //
