

function recordOutboundLink(element, category, triedaction) {
//setup to record outbound links in Google Analytics
  try {
    var pageTracker=_gat._getTracker("UA-2700203-1");
    pageTracker._trackEvent(category, triedaction);
    setTimeout('document.location = "' + element.href + '"', 100)
  }catch(err){}
}

function mw_setupCustomDonation(buttonID) {
	//This function is designed to customize the default Convio donation form to be more usable.
	//Specifically by changing how honor and memorial gifts are handled and how credit card type is collected.
	//The function checks to see if the expect Convio form elements are present before executing any setup. If Convio has changed their output, the function will not fire, and leave the form untouched. This will assure that when Convio changes their output users will still be able to use the form.
	window._mwCustom_buttonID = buttonID;
	
	$j('#'+buttonID).addClass('mw_off')
		
	if ($j('#tribute_notify_recip_namename') && $j('#tribute_show_honor_fieldsname') && $j('#tribute_honoree_deceasedname') && $j('#tribute_honoree_namename')) {
		$j('#tribute_show_honor_fields_Row').addClass('mw_hide');
		$j('#mw_custom_toggles').removeClass('mw_off');
	}
	if ($j('#payment_typecc_numbername') && $j('#payment_typecc_type')) {
		$j('#payment_typecc_type_Row').addClass('mw_hide');
		
		$j('#payment_typecc_numbername').keyup(function() {
			cardID = $j('#payment_typecc_numbername').val().substring(0,1);;
			if (cardID == 3) {
				newClass = 'amex-card';
				selectVal = 3;
			}
			else if (cardID == 4) {
				newClass = 'v-card';
				selectVal = 1
			}
			else if (cardID == 5) {
				newClass = 'mc-card';
				selectVal = 4
			} 
			else if (cardID == 6) {
				newClass = 'disc-card';
				selectVal = 2
			}	
			else {
				newClass = 'notacard'
				selectVal = 0
			} 
			if ($j('#payment_typecc_numbername').hasClass(newClass) && newClass != 'notacard') {
				return;
			}
			else {
				actualSelector = $j('#payment_typecc_type');
				actualSelector.selectedIndex = selectVal;
				$j('#payment_typecc_numbername').removeClass('amex-card');
				$j('#payment_typecc_numbername').removeClass('v-card');
				$j('#payment_typecc_numbername').removeClass('mc-card');
				$j('#payment_typecc_numbername').removeClass('disc-card')
				$j('#payment_typecc_numbername').addClass(newClass);
			}
		});
	}
}	
	
function mw_custom_changeReceiptName() {
	//I'd rather do this as an anonymous function but Prototype doesn't like that for stopObserving
	$j('#tribute_notify_recip_namename').val($j('#tribute_honoree_namename').val());
}
	
function mw_custom_honorMemorial(type) {
	//This takes over the work of the built in show/hide checkbox and does some extra humanizing of the output.
	
	var realToggle = $j('#tribute_show_honor_fieldsname');
	var infoCap = $j('#mw_recipeint_cap');
	var hName = $j('tr#tribute_honoree_name_Row td.FormLabel label span.FormLabelText');
	var isDeadCheck = $j('#tribute_honoree_deceasedname');
	
	$j('tr#tribute_honoree_deceased_Row td').addClass('mw_hide');
	
	if (type == 'honor') {
		niceRequest = 'Honoree\'s Name:'
		notType = 'memorial'
		isDeadCheck = false;
		niceCap = 'We\'ll notify your honoree about your gift. Please let us know how to contact them'
		$j('#tribute_notify_recip_name_Row').addClass('mw_hide');
		$j('#tribute_notify_recip_namename').val($j('#tribute_honoree_namename').val);
		$j('#tribute_honoree_namename').change(mw_custom_changeReceiptName);
	}
	else {
		niceRequest = 'This gift is in memory of:'
		notType = 'honor'
		isDeadCheck = true;
		niceCap = '<b>Who to notify about this Memorial Gift:</b>'
		$j('#tribute_notify_recip_namename').val('');
		$j('#tribute_notify_recip_name_Row').removeClass('mw_hide');
		$j('#tribute_notify_recip_namename').addClass('mw_iefix');
		$j('#tribute_honoree_namename').unbind('change');
	}
	
	var offType = $j('#custom_'+notType+'_check')
	if (!offType.checked) {
		//Simulating this click is what shows all the fields, simulating a click is a bit ghetto but effective
		realToggle.click();
		$j(window._mwCustom_buttonID).toggleClass('mw_off')
		$j(infoCap).toggleClass('mw_off');
	}
	else {
		offType.checked = false;
	}
	
		infoCap.innerHTML = niceCap;
		hName[0].innerHTML = niceRequest;
}

$j(document).ready(function() {
	
	//------------------------------------------------------------//
	//this code can go once the re-alignment launches
	MM_preloadImages('../images/wrpr/btnDonateOn.gif');
	
	image1 = new Image();
	image1.src = "../mw/omoh/2009/14323_promo_home.jpg";
	image2 = new Image();
	image2.src = "../images/content/pagebuilder/12349.jpg";
	image3 = new Image();
	image3.src = "../images/content/pagebuilder/11956.jpg";
	var img_links = new Array(
		{pic:"../mw/omoh/2009/14323_promo_home.jpg", lnk:"http://www.ugm.org/site/PageNavigator/One_Meal_One_Hope/homeless_at_christmas?s_subsrc=L09KFH00Z"},
		{pic:"../images/content/pagebuilder/12349.jpg", lnk:"http://www.hopeplace.org"},
		{pic:"../images/content/pagebuilder/11956.jpg", lnk:"http://www.ugm.org/programs_men"}
	)
	
	function randomImg(){
		var now = new Date();
		var num = (now.getSeconds())%eval(img_links.length);
		var place = document.getElementById("place");
		place.innerHTML = "<a href='" + img_links[num]["lnk"] + "'><img src='" + img_links[num]["pic"] + "' border=0></a>";
		setTimeout("randomImg()", 5000);
	}		
	if(document.getElementById("place")) {
		randomImg();
	}
	//------------------------------------------------------------//
	
	//legacy code for nav function
	var sfEls = document.getElementById("pmenu").getElementsByTagName("LI");
   	for (var i=0; i<sfEls.length; i++) {
      	sfEls[i].onmouseover=function() {
         	this.className+=" sfhover";
      	}
      	sfEls[i].onmouseout=function() {
        	this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
      	}
   	}
	
	
	//finds full story lists to add "read more" link
	if ($j('div.mw-sb-full')) {
	 $j('div.mw-sb-full a.NewsHeadlineList').each(function() {
		 $j(this).parent().append('<a href="'+$j(this).attr('href')+'">Read more&hellip;</a>');
		});
	}
	
	//adds a class to the sidebar and inserts a heading on the related stories (both of which Convio shoudl do by default)
	if ($j('body').hasClass('convio-app-id-95')) {
		$j('body.convio-app-id-95 td[width=20%]').addClass('sb-sidebar')
		$j('td.sb-sidebar table').prepend('<h3>Related Stories</h3>');
		
	}
});

