//Confirms submissions, especially for deleting things
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
	return true ;
else
	return false ;
}
//Highlight table row on hover
//usage onmouseover="mark_row(this)" onmouseout="unmark_row(this)"
function mark_row(t) {
t.style.backgroundColor = '#F6ECE2';
}
function unmark_row(t) {
t.style.backgroundColor = 'transparent';
}

//this nice javascript will open external links in a new window - http://www.sitepoint.com/article/standards-compliant-world/3
//usage rel="external"

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rev") == "external") 
     {anchor.target = "_blank";
		 anchor.title = anchor.title+" in a new window";}
	 else
	 	 {anchor.title = anchor.title;} 
 } 
} 
window.onload = externalLinks;

// for textareas to not get too long
// the markup is: onkeyup="textLimit(this.form.fieldid, 250);"
function textLimit(field, maxlen) {
if (field.value.length > maxlen + 1)
alert('Your input has been truncated!');
if (field.value.length > maxlen)
field.value = field.value.substring(0, maxlen);
}
//also for textareas to not get too long and adds a little box showing how many characters are left
// markup - onKeyDown="textCounter(this.form.fieldname,this.form.remLen,125);" onKeyUp="textCounter(this.form.fieldname,this.form.remLen,125);
// markup for little box - <input type="readonly" type="text" name="remLen" size="3" maxlength="3" value="125" /><br /> characters left
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

//for checking and unchecking boxes - usage <input type="checkbox" name="checkall" onclick="checkUncheckAll(this, del);"> where
// del is the name of the field to check/uncheck 
function checkUncheckAll(checkAllState, cbGroup)
{
	for (i = 0; i < cbGroup.length; i++)
	{
		cbGroup[i].checked = checkAllState.checked;
	}
}




	
//this allows all things in the list to be checked/unchecked
function checkAll(chkid)
{ 
for (i = 0; i < chkid.length; i++)
	chkid[i].checked = true ;
	
}

function uncheckAll(chkid)
{
for (i = 0; i < chkid.length; i++)
	chkid[i].checked = false ;
}

//this is probably a better version of the above
function selectAll(obj) { 
var checkBoxes = document.getElementsByTagName('input'); 
for (i = 0; i < checkBoxes.length; i++) { 
if (obj.checked == true) { 
checkBoxes[i].checked = true; // this checks all the boxes 
} else { 
checkBoxes[i].checked = false; // this unchecks all the boxes 
} 
} 
} 
//this is from alistapart and prints footer links for those with js turned on http://www.alistapart.com/articles/improvingprint/
    /*------------------------------------------------------------------------------
    Function:       footnoteLinks()
    Author:         Aaron Gustafson (aaron at easy-designs dot net)
    Creation Date:  8 May 2005
    Version:        1.3
    Homepage:       http://www.easy-designs.net/code/footnoteLinks/
    License:        Creative Commons Attribution-ShareAlike 2.0 License
                    http://creativecommons.org/licenses/by-sa/2.0/
    Note:           This version has reduced functionality as it is a demo of 
                    the script's development
    ------------------------------------------------------------------------------*/
    function footnoteLinks(containerID,targetID) {
      if (!document.getElementById || 
          !document.getElementsByTagName ||
          !document.createElement) return false;
      if (!document.getElementById(containerID) ||
          !document.getElementById(targetID)) return false;
      var container = document.getElementById(containerID);
      var target    = document.getElementById(targetID);
      var h2        = document.createElement('h2');
      addClass.apply(h2,['printOnly']);
      var h2_txt    = document.createTextNode('Links');
      h2.appendChild(h2_txt);
      var coll = container.getElementsByTagName('*');
      var ol   = document.createElement('ol');
      addClass.apply(ol,['printOnly']);
      var myArr = [];
      var thisLink;
      var num = 1;
      for (var i=0; i<coll.length; i++) {
        var thisClass = coll[i].className;
        if ( coll[i].getAttribute('href') ||
             coll[i].getAttribute('cite') ) { 
          thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
          var note = document.createElement('sup');
          addClass.apply(note,['printOnly']);
          var note_txt;
          var j = inArray.apply(myArr,[thisLink]);
          if ( j || j===0 ) {
            note_txt = document.createTextNode(j+1);
          } else {
            var li     = document.createElement('li');
            var li_txt = document.createTextNode(thisLink);
            li.appendChild(li_txt);
            ol.appendChild(li);
            myArr.push(thisLink);
            note_txt = document.createTextNode(num);
            num++;
          }
          note.appendChild(note_txt);
          if (coll[i].tagName.toLowerCase() == 'blockquote') {
            var lastChild = lastChildContainingText.apply(coll[i]);
            lastChild.appendChild(note);
          } else {
            coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
          }
        }
      }
      target.appendChild(h2);
      target.appendChild(ol);
      addClass.apply(document.getElementsByTagName('html')[0],['noted']);
      return true;
    }
    window.onload = function() {
      footnoteLinks('content','content');
    }

//part duex of the above
    /*------------------------------------------------------------------------------
    Excerpts from the jsUtilities Library
    Version:        2.1
    Homepage:       http://www.easy-designs.net/code/jsUtilities/
    License:        Creative Commons Attribution-ShareAlike 2.0 License
                    http://creativecommons.org/licenses/by-sa/2.0/
    Note:           If you change or improve on this script, please let us know.
    ------------------------------------------------------------------------------*/
    if(Array.prototype.push == null) {
      Array.prototype.push = function(item) {
        this[this.length] = item;
        return this.length;
      };
    };
    // ---------------------------------------------------------------------
    //                  function.apply (if unsupported)
    //           Courtesy of Aaron Boodman - http://youngpup.net
    // ---------------------------------------------------------------------
    if (!Function.prototype.apply) {
      Function.prototype.apply = function(oScope, args) {
        var sarg = [];
        var rtrn, call;
        if (!oScope) oScope = window;
        if (!args) args = [];
        for (var i = 0; i < args.length; i++) {
          sarg[i] = "args["+i+"]";
        };
        call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
        oScope.__applyTemp__ = this;
        rtrn = eval(call);
        oScope.__applyTemp__ = null;
    	return rtrn;
      };
    };
    function inArray(needle) {
      for (var i=0; i < this.length; i++) {
        if (this[i] === needle) {
          return i;
        }
      }
      return false;
    }
    function addClass(theClass) {
      if (this.className != '') {
        this.className += ' ' + theClass;
      } else {
        this.className = theClass;
      }
    }
    function lastChildContainingText() {
      var testChild = this.lastChild;
      var contentCntnr = ['p','li','dd'];
      while (testChild.nodeType != 1) {
        testChild = testChild.previousSibling;
      } 
      var tag = testChild.tagName.toLowerCase();
      var tagInArr = inArray.apply(contentCntnr, [tag]);
      if (!tagInArr && tagInArr!==0) {
        testChild = lastChildContainingText.apply(testChild);
      }
      return testChild;
    }
//this styling is necessary!
/*
<style type="text/css" media="screen">
    .printOnly {
      display: none;
    }
  </style>
  <style type="text/css" media="print">
    a:link:after,
    a:visited:after {
      content: " (" attr(href) ") ";
      font-size: 90%;
    }
    html.noted a:link:after,
    html.noted a:visited:after {
      content: '';
    }
  </style>
 */