/********************************************************
/ XVI.COM - Sitewide functions
/
/ While we're flattered that you're snooping our code,
/ please keep in mind that it's ours and that it should
/ not be copied without our consent.
/
/ Not that there's much going on here, these are just
/ shortcuts to open popups really. Hmmm actually,
/ that being the case, fuckit, copy away! :)
/
/ Graham
/
/********************************************************/

function dlg(u,n,w,h,scroll,resize) {
	var left=(screen.width)?(screen.width/2-w):100;
	var top=(screen.height)?(screen.height/2-h):100;
	var win=window.open(u,n,
		'top='+top+',left='+left+',width='+w+',height='+h+
		',location=no,directories=no,status=no,menubar=no,toolbar=no'+
		(resize?",resizable=yes":",resizable=no")+
		(scroll?",scrollbars=yes":",scrollbars=no")
	);
	win.opener=self;
}

// Miscellaneous dialogs
function atmf(t,m)   { dlg('/forums/atmf.php?t='+t+'&m='+m, 'atmf_'+t, 300,100); }
function friend(f,m) { dlg('/user/friendtoggle.php?f='+f+'&m=' + m, 'friend_'+f, 300,100); }
function ignore(u,m) { dlg('/user/ignoretoggle.php?u='+u+'&m=' + m, 'ignore_'+u, 300,100); }
function send(id)    { dlg('/xim/dialog.php?u='+id,'sendmsg_'+id,350,440,false,true); }
function comop(c,r,o){ dlg('/comments/commentop.php?c='+c+'&r='+r+'&o='+o,'commentop_'+c,300,100); }

// Homepage
function h(u,nw) {
	var link='/user/homepage.php?u='+u;
	if (nw)
		dlg(link,'user_'+u,650,500,true,true);
	else
		window.location.href=link;
}

// Comment operations
function commentop(func,id) {
	var ok=true;
	if(func=='d') ok=confirm("Deletion is permanent. Are you sure?");
	if(ok) dlg('/comments/op.php?f='+func+'&id='+id,'commentop_'+func+'_'+id,300,100);
}

function commentreply(id) {
	dlg('/comments/reply.php?id='+id,'commentreply_'+id,400,300,true,true);
}

function commentall(id) {
	dlg('/comments/all.php?id='+id,'commentall_'+id,650,500,true,true);
}

// Unhide the discussions members box
function showPDMembers() {
	document.getElementById("pdmembersbutton").style.display="none";
	document.getElementById("pdmembers").style.display="";
}

// Forum stuff
function rss(t,m) {
	dlg('/forums/rss.php?t='+t+'&m='+m,'rss_'+t,300,150);
}

function mod(op,id) {
	dlg('/forums/mod.php?id='+id,'mod_'+op+'_'+id,350,200,true,true);
}

function report(id) {
	dlg('/forums/report.php?id='+id,'report_'+id,440,320,true,true);
}

function wt(writetime) {
	// servertime must be set to PHP's time() in the document head
	var now=new Date();
	//if(!servertime) var servertime=now.valueOf()/1000;
	var yesterday=new Date(now.valueOf()-86400000);
	var writenow=new Date(writetime*1000+now.valueOf()-servertime*1000);
	var monthname=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

	if(writenow.getFullYear()==now.getFullYear() && writenow.getMonth()==now.getMonth() && writenow.getDate()==now.getDate())
		var datepart='Today';
	else if(writenow.getFullYear()==yesterday.getFullYear() && writenow.getMonth()==yesterday.getMonth() && writenow.getDate()==yesterday.getDate())
		var datepart='Yesterday';
	else if(writenow.getMonth()==11 && writenow.getDate()==25)
		var datepart='Xmas';
	else if(writenow.getMonth()==11 && writenow.getDate()==31)
		var datepart='NYE';
	else if(writenow.getMonth()==6 && writenow.getDate()==1)
		var datepart='CanDay';
	else
		var datepart=monthname[writenow.getMonth()]+'&nbsp;'+writenow.getDate();

	if(writenow.getFullYear()!=now.getFullYear())
		datepart+="&nbsp;'"+(writenow.getFullYear()+'').substr(2,2);

	var mins=writenow.getMinutes();
	if(mins<10) mins='0'+mins;

	if(writenow.getHours()>12)
		var timepart=(writenow.getHours()-12)+':'+mins;
	else
		var timepart=writenow.getHours()+':'+mins;
	timepart+=writenow.getHours()>11?'p':'a';

	document.write(datepart+'&nbsp;'+timepart);
}
