// Forces a confirmation before allowing any link to take you outside of the current site
function blockExternalLinks(){
	var anchors = $$('a');
	for(i=0;i<anchors.length;i++){
		anchors[i].addEvent('click', function(){
			if(!this.href.match(document.domain) && this.href.match('http')){
				var ext_bg = new Element('div', {'id' : 'extNotify'});
				ext_bg.set('opacity', 0);
				ext_bg.addEvent('click', function(){
					fader = new Fx.Tween(ext_bg);
					fader.addEvent('onComplete', function(){ext_bg.dispose();});
					fader.start('opacity', 0);
				});
				ext_bg.innerHTML = 
				'<table id="ext_table" cellpadding="0" cellspacing="0" height="100%" width="100%"><tr>'+
				'<td id="ext_container" align="center" valign="middle"></td></tr></table>';
				var ext_confirm = new Element('div');
				ext_confirm.innerHTML = 
				'<table id="ext_content" cellpadding="20" cellspacing="0"><tr>'+
				'<td  valign="middle">'+
				'<h1>Notice:</h1>'+
				'You have clicked on a link that will take you outside of this site.<br>'+
				'Here is the URL:<br>'+
				'<a onClick="location.href=this.href;" href="'+this.href+'">'+this.href.replace('http://','').slice(0, -1)+'</a><br>'+
				'If you would like to continue, please click the URL above.<br>'+
				'Click outside this box to cancel.'+
				'</td></tr></table>';
				ext_bg.inject(document.body);
				ext_confirm.injectInside($('ext_container'));
				$('ext_content').addEvent('click', function(){return false});
				ext_bg.fade(0, 0.9);
				return false;
			}
		});
	}
}
function rss_load(){
	var request = new Request({
		method : 'post',
		url : '/ajax_control.php',
		async : true,
		onSuccess : function(responseTree){
			var nfl_news = responseTree;
			if(nfl_news){
				var news = $('nfl_news');
				fader = new Fx.Tween(news);
				fader.addEvent('onComplete', function(){
					news.innerHTML = nfl_news;
					news.fade('in');
				});
				fader.start('opacity', 0);
			}
		}
	});
	request.send('action=load_nfl_news');
	
	var request = new Request({
		method : 'post',
		url : '/ajax_control.php',
		async : true,
		onSuccess : function(responseTree){
			var nfl_tweets = responseTree;
			if(nfl_tweets){
				var tweets = $('nfl_tweets');
				fader = new Fx.Tween(tweets);
				fader.addEvent('onComplete', function(){
					tweets.innerHTML = nfl_tweets;
					tweets.fade('in');
				});
				fader.start('opacity', 0);
			}	
		}
	});
	request.send('action=load_nfl_tweets');
}
function ajax(action, data){
	var request = new Request({
		method : 'post',
		url : '/ajax_control.php',
		async : false,
		onSuccess : function(responseTree){
			result = responseTree;
		}
	});
	request.send('action='+action+(data?'&'+data:''));
	return(result);
}

function purify(data){
	data = data.replace(/&/g, 'amp;');
	data = data.replace(/%/g, 'perc;');
	return data;
}
function is_numeric(value){
	if ((isNaN(value)) || (value.length == 0))
		return 0;
	else
		return 1;
}
function imposeMaxLength(Object, MaxLen){
  return (Object.value.length <= MaxLen);
}

function team_vote(m, t, d){
	$('vs-' + m).className = 'vs ' + d;
	$each($$('#' + m + ' .name'), function(i){
		i.className = 'name';
	});
	$('name-' + m + '-' + t).className = 'name active';
	$('vote-' + m).value = t;
}

function weeks_slider(){
	$each($$('.weeks_name'), function(i){
		if( i.className != 'weeks_name yellow' ){
			var slider = new Fx.Slide($('matches-' + i.id));
			slider.hide();
		}
		i.addEvent('click', function(){
			var x = $('matches-' + this.id);
			if( !this.retrieve('status') ){
				if( this.className == "weeks_name yellow" ){
					x.slide('out');
					this.store('status', 'closed');
				}
				else{
					x.slide('in');
					this.store('status', 'open');
				}
			}
			else{
				if( this.retrieve('status') == 'closed' ){
					x.slide('in');
					this.store('status', 'open');
				}
				else{
					x.slide('out');
					this.store('status', 'closed');
				}
			}
		});
	});
}