String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function isEmail(s){
	//var em = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var em = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	return em.test(s);
}

$(document).ready(function() {
	$('#presentations .files a').click(function(){
		try {
			var paper = $(this).text();
			_gaq.push(['_trackEvent', 'File', 'Download', paper]);
		}
		catch(err){}
	});


    $('.meetings tbody tr:even td, .meetings tbody tr:even th').addClass('even');
	
	$('.btnBack').click(function(){
		history.back();
	});
	
	$('#boxWho').hover(function(){
		$('#boxWho p').show();
	},function(){
		$('#boxWho p').hide();
	});
	
	$('#listEvents').each(function(){
		var e = '';
		$.ajax({
			type: 'get',
			url: "/common/include/feed.php",
			cache: false,
			dataType: 'xml',
			error: function(){
				$('#listEvents').append('<p>There has been an error accessing event data. Please try again later.</p>');
			},
			success: function(data){
				$('item', data).each(function(){
					var d = $('title', this).text();
					var s = $('description', this).text();
					var t = s.slice(s.indexOf('event: ') + 7, s.indexOf(', location:'));
					var l = s.slice(s.indexOf('location: ') + 10, s.indexOf(', provider:'));
					var p = s.slice(s.indexOf('provider: ') + 10, s.indexOf(', information:'));
					if (s.indexOf('information: ') > -1) {
						var h = s.slice(s.indexOf('information: ')+13);
						if(isEmail(h)){
							var t = '<a href="mailto:'+h+'" class="email">'+t+'</a>';
						} else if(h.indexOf('www.')==0) {
							var t = '<a href="http://'+h+'" target="_blank">'+t+'</a>';
						} else {
							var t = '<a href="'+h+'" target="_blank">'+t+'</a>';
						}
					}
					
					e += '<tr><td class="date">'+d+'</td><td class="event">'+t+'</td><td class="loc">'+l+'</td><td class="provider">'+p+'</td></tr>';
				});
				$('#listEvents tbody').empty().append(e);
				$('#listEvents tbody tr:even').addClass('even');
			}
		});
	
	});
});
