
/**
 * Set this the same as the base tag in template.php
 */
var url_base = 'http://www.umass.edu/giving/';

/**
 * Toggles the details for named chairs and professorships
 */
function toggle(id) {

	thisdt = document.getElementById(id);
	thisdd = document.getElementById(id + 'desc');
	thislink = document.getElementById(id + 'more');
	state = thisdd.style.display;
	thisdd.style.display = (state == 'block') ? 'none' : 'block';
	thislink.innerHTML = (state == 'block') ? 'Show details' : 'Hide details';
	img = (state == 'block') ? 'collapsed' : 'expanded';
	thislink.style.background = 'url(/giving/img/arrow_' + img + '.gif) center left no-repeat';

}

/**
 * toggles the "change of address" fields in the contact form
 */
function toggle_address() {
		
	var check_address = document.getElementById('check_change');
	var donorid = document.getElementById('donorid');
	var changed = document.getElementById('changed');
	
	if (check_address.checked) {
		donorid.disabled = false;
		changed.disabled = false;
	} else {
		donorid.disabled = true;
		changed.disabled = true;
	}
	
}

/**
 * Toggles the "contact me" fields in the contact form
 */
function toggle_contactme() {
	
	var check_contactme = document.getElementById('check_contactme');
	var phone = document.getElementById('phone');
	
	if (check_contactme.checked) {
		phone.disabled = false;
	} else {
		phone.disabled = true;
	}
	
}

/**
 * Sets up the contact form
 */
function setup_contact_form() {
	toggle_address();
	toggle_contactme();
}

/**
 * document.write(lastMod())
 * Outputs last modified date.
 */
function lastMod() {
	var x = new Date (document.lastModified);
	Modif = new Date(x.toGMTString());
	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730) 	{
		daysago = Math.floor(daysago/365);
		unit = 'years';
	}
	else if (daysago > 60) {
		daysago = Math.floor(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14) {
		daysago = Math.floor(daysago/7);
		unit = 'weeks'
	}
	var towrite = 'This page was last modified: ';
	if (daysago == 0) towrite += 'today';
	else if (daysago == 1) towrite += 'yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite;
}

/** 
 * Helper function for lastMod
 */
function takeYear(theDate) {
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}
