// POP UP
// usage: popuplink(['js-only url',] this[, w[, h[, scroll[, extras]]]])
// basic usage: <a href="popup.html" target="_blank" onclick="return(popuplink(this));">new pop</a>
// advanced usage: <a href="popup_nojs.html" target="_blank" onclick="return(popuplink('popup_yesjs.html', this, 200, 100, false));">new pop</a>
// site-wide defaults:
POPUP_W = 400;
POPUP_H = 300;
POPUP_SCROLL = true;
POPUP_EXTRAS = 'location=0,statusbar=0,menubar=0';
function popuplink() {
	var undef, i=0, args=popuplink.arguments;
	var url = (typeof(args[i])=='string') ? args[i++] : args[i].getAttribute('href');
	var target = args[i++].getAttribute('target') || '_blank';
	var w = args[i++];
	var h = args[i++];
	var s = (args[i]===undef) ? POPUP_SCROLL : args[i++];
	var features = 'width=' + (w || POPUP_W)
				 + ',height=' + (h || POPUP_H)
				 + ',scrollbars=' + (s ? 'yes,' : 'no,')
				 + (args[i] || POPUP_EXTRAS);
	var win = window.open(url, target, features);
	win.focus();
	return false;
}
// END POP UP
var DonationDropDown = {
      initialize: function(dropDownId, otherDonationFieldId){          
      //console.log("test");

            // define dropdown and field vars
            this.dropDown = document.getElementById(dropDownId);
            this.otherDonationField = document.getElementById(otherDonationFieldId);
           
            // hide field on load
            this.__dropDownChange();

            // attach "onchange" event handler to dropdown
            $pop.event.add(this.dropDown, "change", this.__dropDownChange, this);
      },

      __dropDownChange: function(){

            if(this.dropDown.value == "Other"){
                  this.otherDonationField.style.display = "block";
            } else {
                  this.otherDonationField.style.display = "none";
            }
      }
} //END DONATION DROP DOWN


/**
 * Manages the display of items associated with specific checkboxes. The state of the content
 * element will always match the state of the checkbox
 * Usage:
 *  checkBoxContentToggler.add('cb_Securities','fs_Securities');
 *  checkBoxContentToggler.add('cb_Gift','fs_Gift');
 *  checkBoxContentToggler.add('cb_Honor','fs_Honor');
 *  checkBoxContentToggler.add('cb_Installments','fs_InstallmentsInner');
 */
var checkBoxContentToggler = {
    _registry: {},
    
    /**
     * Add a checkbox, content element pair to be toggled together
     * @param {String} sCheckBoxId The id of the Checkbox
     * @param {String} sElementId The id of the associated content element
     * @param {bool} bInvert If the element should be the opposite of the state of the checkbox or not
     * @return void
     */
    add: function(sCheckBoxId, sElementId, bInvert) {
        bInvert = (bInvert == 'undefined') ? false : bInvert ;
        var cb = $dom.getById(sCheckBoxId);
        var el = $dom.getById(sElementId);
        
        if (!cb || !el) { return; }
        
        this._registry[cb.id] = {
            el: el,
            inverted: bInvert
        }

        $pop.event.add(cb,'click',this.__cb_Click, this);
        
        this.updateToggle(cb.id);
    },
    
    __cb_Click: function(evt) {
        var el = $pop.event.getTarget(evt);
        this.updateToggle(el);
    },
    
    /**
     * Updates the state of the content element to match the checked state of the checkbox
     * @param {String/DOMElement} mCheckBoxOrCheckBoxId The id of the Checkbox or the CheckBox element itself
     * @return void
     */
    updateToggle: function(mCheckBoxOrCheckBoxId) {
        var cb = (typeof mCheckBoxOrCheckBoxId == 'string') ? $dom.getById(mCheckBoxOrCheckBoxId) : mCheckBoxOrCheckBoxId ;
        var state = (this._registry[cb.id].inverted) ? !cb.checked : cb.checked;
        
        this._registry[cb.id].el.style.display = (state) ? '' : 'none' ;
    }
}
