function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}

function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

function event_popup(e) {
    // to be passed as an event listener
    // pops up a window grabbing the url from the event source's href
    link_popup(e.currentTarget);
    e.preventDefault();
}

function event_popup_features(features) {
    // generates an event listener similar to event_popup, but allowing window features
    return function(e) { link_popup(e.currentTarget, features); e.preventDefault() }
}

listen('load', window, function() {
	mlisten('click', getElementsByClass('popup','a'), event_popup );
});

/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

// EDITED slightly to allow for inputs images, too
function initRollovers() {	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = getElementsByClass('imgover');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

// adapted from suckerfish menus
var ieHover = function() {
	if (document.all&&document.getElementById) {	
		//alert('hi');
		var hoverlist = getElementsByClass('hoverme');
		for (var i=0; i<hoverlist.length; i++) {
			var elem = hoverlist[i];
			elem.onmouseover=function() {
				//alert('hi');
				this.className+=" over";
			}
			elem.onmouseout=function() {
				this.className=this.className.replace(" over", "");
			}
		}
	}
}

// NEW! To add in show/hide functionality
// for blog archives
// From Christian Heilmann, Unobtrusive JS
// http://onlinetools.org/articles/unobtrusivejavascript/demo_cssseparation.html
function collapse() {
	var blogLinks = getElementsByClass('reveal');
	for (var i = 0; i < blogLinks.length; i++) {
		var tohide = blogLinks[i].nextSibling;
		while (tohide.nodeType != 1) {
			tohide = tohide.nextSibling;
		}
		cssjs('add',tohide,'hidden');
		cssjs('add',blogLinks[i],'trigger');
		blogLinks[i].tohide = tohide;
		blogLinks[i].onmouseover = function() {
			cssjs('add',this,'hover');
		}
		blogLinks[i].onmouseout = function() {
			cssjs('remove',this,'hover');
		}
		blogLinks[i].onclick = function() {
			if(cssjs('check',this.tohide,'hidden')) {
				cssjs('swap',this,'trigger','open');
				cssjs('swap',this.tohide,'hidden','shown');
			} else {
				cssjs('swap',this,'open','trigger');
				cssjs('swap',this.tohide,'shown','hidden');
			}
		}
	}
	
	function cssjs(a,o,c1,c2) {
		switch (a) {
			case 'swap':
				o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
		}
		return null;
	}
}


function initOtherAmtBox(sel_box, oth_box) {
	sel_box = document.getElementById(sel_box);
	oth_box = document.getElementById(oth_box);
	if(sel_box.value == -1){
		oth_box.style.display = "inline";
	} else {	
		oth_box.style.display = "none";
		oth_box.value = '';	
	}
	
	sel_box.onchange = function() {
		oth_box = this.id.replace('sel_', 'oth_');
		oth_box = document.getElementById(oth_box);
		if(this.value == -1){
			oth_box.style.display = "inline";
		} else {	
			oth_box.style.display = "none";
			oth_box.value = '';	
		}
	}
	
}

function showOtherAmtBox(){

	var oabox 	= $('other_amount');
	if($('donation_amount').value == ''){
		oabox.style.display = "inline";
	} else {
		oabox.style.display = "none";
		oabox.value = '';
	}
}



// Vigil core functions
// 03 Augustt 2007

function addClass(element,name) {
  if (!element.className) {
    element.className = name;
  } else {
    element.className+= ' ';
    element.className+= name;
  }
}

function stripeTables() {
	if (!document.getElementsByTagName('table')) return;
	var tables = document.getElementsByTagName('table');
	for (var i = 0; i<tables.length; i++) {
		if (tables[i].className.match('zebra')) {
			var myTR = tables[i].getElementsByTagName('tr');
      for (var j=1; j<myTR.length; j=j+2) {
        addClass(myTR[j],'rowTint');
      }
    }
  }
}


function addEvent( obj, type, fn ) {
	if (document.getElementById && document.createTextNode) {
		if (obj.addEventListener)
			obj.addEventListener( type, fn, false );
		else if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn]( window.event ); }
			obj.attachEvent( 'on'+type, obj[type+fn] );
		}
	}
}


/*

This file contains only functions necessary for the article features
The full library code and enhanced versions of the functions present
here can be found at http://v2studio.com/k/code/lib/

*/

// ARRAY EXTENSIONS

if (!Array.prototype.push) Array.prototype.push = function() {
    for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
    return this.length;
}

Array.prototype.find = function(value, start) {
    start = start || 0;
    for (var i=start; i<this.length; i++)
        if (this[i]==value)
            return i;
    return -1;
}

Array.prototype.has = function(value) {
    return this.find(value)!==-1;
}

// FUNCTIONAL

function map(list, func) {
    var result = [];
    func = func || function(v) {return v};
    for (var i=0; i < list.length; i++) result.push(func(list[i], i, list));
    return result;
}

function filter(list, func) {
    var result = [];
    func = func || function(v) {return v};
    map(list, function(v) { if (func(v)) result.push(v) } );
    return result;
}


// DOM

function getElem(elem) {
    if (document.getElementById) {
        if (typeof elem == "string") {
            elem = document.getElementById(elem);
            if (elem===null) throw 'cannot get element: element does not exist';
        } else if (typeof elem != "object") {
            throw 'cannot get element: invalid datatype';
        }
    } else throw 'cannot get element: unsupported DOM';
    return elem;
}

function hasClass(elem, className) {
    return getElem(elem).className.split(' ').has(className);
}

function getElementsByClass(className, tagName, parentNode) {
    parentNode = !isUndefined(parentNode)? getElem(parentNode) : document;
    if (isUndefined(tagName)) tagName = '*';
    return filter(parentNode.getElementsByTagName(tagName),
        function(elem) { return hasClass(elem, className) });
}


// DOM EVENTS

function listen(event, elem, func) {
    elem = getElem(elem);
    if (elem.addEventListener)  // W3C DOM
        elem.addEventListener(event,func,false);

    else if (elem.attachEvent)  // IE DOM
        elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
        // for IE we use a wrapper function that passes in a simplified faux Event object.
    else throw 'cannot add event listener';
}

function mlisten(event, elem_list, func) {
    map(elem_list, function(elem) { listen(event, elem, func) } );
}

function W3CDOM_Event(currentTarget) {
    this.currentTarget  = currentTarget;
    this.preventDefault = function() { window.event.returnValue = false }
    return this;
}


// MISC CLEANING-AFTER-MICROSOFT STUFF

function isUndefined(v) {
    var undef;
    return v===undef;
}
