function mustLoginTo(to) {
		alert("You gotta be logged in to "+to+"!")
}

function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function byby() {
	document.getElementById("hidethis").style.display = 'none';
}

function SwapImage(sub_id) {
	var imgpath = "http://ispy.s3.amazonaws.com/submission/large/"+sub_id+".jpg";
	eval("document.images['sub"+sub_id+"'].src=imgpath");
}

function deleteGame() {
	var answer = confirm("This can not be undone.  Are you sure you want to delete this mission?")
	if (answer){
		document.deletegame.submit();
	}
}

function flag(type,formName) {
	var answer = confirm("If you believe this "+type+" violates our community guidelines please click OK:")
	if (answer){
		document.forms[formName].submit();
	}
}

function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
      e.style.display = 'none';
   else
      e.style.display = 'block';
}

function poppy(url,w,h){
	w = window.open(url,"","scrollbars=yes,menubar=no,toolbar=no,width="+w+",height="+h+",titlebar=no,top=40,left=80");
}

function deleteComment(comId) {
	var answer = confirm("Are you sure you want to delete this comment?")
	if (answer){
		document.forms[comId].submit();
	}
}

function prettyDate(date_str){
	//http://webdesign.onyou.ch/2010/08/04/javascript-time-ago-pretty-date/
	
	var time_formats = [
	[60, 'seconds', 1], // 60
	[120, '1 minute ago', '1 minute from now'], // 60*2
	[3600, 'minutes', 60], // 60*60, 60
	[7200, '1 hour ago', '1 hour from now'], // 60*60*2
	[86400, 'hours', 3600], // 60*60*24, 60*60
	[172800, 'yesterday', 'tomorrow'], // 60*60*24*2
	[604800, 'days', 86400], // 60*60*24*7, 60*60*24
	[1209600, 'last week', 'next week'], // 60*60*24*7*4*2
	[2419200, 'weeks', 604800], // 60*60*24*7*4, 60*60*24*7
	[4838400, 'last month', 'next month'], // 60*60*24*7*4*2
	[29030400, 'months', 2419200], // 60*60*24*7*4*12, 60*60*24*7*4
	[58060800, 'last year', 'next year'], // 60*60*24*7*4*12*2
	[2903040000, 'years', 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12
	[5806080000, 'last century', 'next century'], // 60*60*24*7*4*12*100*2
	[58060800000, 'centuries', 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100
	];
	
	
	// if time was formatted like... 2010-08-28T20:24:17Z
		//var time = ('' + date_str).replace(/-/g,"/").replace(/[TZ]/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		//if(time.substr(time.length-4,1)==".") time =time.substr(0,time.length-4);
		//var seconds = (new Date - new Date(epoch)) / 1000;
	
	// but since its in epoch
	var epoch = date_str * 1000;
	var seconds = (new Date - new Date(epoch)) / 1000;
	
	var token = 'ago', list_choice = 1;
	
	if (seconds < 0) {
		seconds = Math.abs(seconds);
		token = 'from now';
		list_choice = 2;
	}
	
	var i = 0, format;
	
	while (format = time_formats[i++])
	
		if (seconds < format[0]) {
			if (typeof format[2] == 'string')
				return format[list_choice];
			else
				return Math.floor(seconds / format[2]) + ' ' + format[1] + ' ' + token;
		}
		
	return time;
};

function loopThroughTime(){
	var links = document.getElementsByTagName("span");	
	for ( var i = 0; i < links.length; i++ )
		if ( links[i].title ) {
			var date = prettyDate(links[i].title);
			if ( date )
				links[i].innerHTML = date;
		}
};

function injectUsername(textAreaId,username){
	var thearea = document.getElementById(textAreaId);
	thearea.value = '@' + username + ' ';
}

function confirm_redirect(message,url){
	var answer = confirm(message);
	if(answer){
		window.location.href=url;
	}
}
