var LURL = "";
var STL = "http://stl.drawbbs.com/";
var DATE = new Date();
var TS = Math.round((DATE.getTime()-Date.UTC(1970,0,1))/1000);
var TD = 0;
function TM(tmax){
	var dif = TS-tmax;
	if(dif<0){TD=-dif;}
}
function iereplyfix(){
document.getElementById('stylesheet').href = document.getElementById('stylesheet').href;
}
function IEbugs(){//do actions that will realign things thrown off by IE rendering bugs
	document.getElementById('stylesheet').href = document.getElementById('stylesheet').href;
}
function changeStyle(style, styles) {
var styleCookie = getCookie('style'); 
//alert(styleCookie);
var newStyle = ':s:'+styles+':s:'+style+':e:';
if(styleCookie.match(':s:'+styles+':s:')){//if this styleset is already in the cookie, update it
	styleCookie = styleCookie.replace(new RegExp(':s:'+styles+':s:[^&]+:e:','i'),newStyle);
	//alert('1a');
}else{//otherwise append it to the cookie
	//alert('1b');
	styleCookie += newStyle;
}
document.cookie="style="+styleCookie+";path=/";//save the selection for the given style set
document.getElementById('lockstyle').innerHTML = '<a href="#" onclick="lockStyle(\''+style+'\');return false;" title="Lock Style">&#60;3</a>';
loadStyle(styles);
}
function loadStyle(styles){
		//alert('a');
	var styleCookie = getCookie('style'); 
		//alert('match '+':s:'+styles+':s:'+' in '+styleCookie);
	if(styleCookie.match(':s:'+styles+':s:')){//if we have a definition for this styleset
		//alert('b');
		var style = styleCookie.replace(new RegExp('.*:s:'+styles+':s:([^:]+):e:.*','i'),'$1');//parse out the style name from the definition for this set
		//alert('st: '+style);
		document.getElementById('stylesheet').href = STL+'styles/'+style+'/'+style+'.css';
	}//otherwise do nothing
}
function allStyles(t,sset,list){
//alert('a');
if(list==undefined){list="Vegeta:GBPoke:GBPokeNite:Mudkipz:Sonichu:terran:d2";}
	var styles = list.split(':');
	var picker = " <a href=\"#\" onclick=\"this.parentNode.innerHTML='';\" title=\"close\">X</a> ";
//alert('b');
	for(var i = 0;i < styles.length;i++){
		picker +="| <a href=\"#\" onclick=\"changeStyle('"+styles[i]+"','"+sset+"');return false;\">"+styles[i]+"</a> ";
	}
//alert('c');
	t.parentNode.innerHTML = picker;
//alert('d');
}
function lockStyle(style) {
document.cookie="style-lock="+style+";path=/";//lock the style by cookie
document.getElementById('lockstyle').innerHTML = '<a href="#" onclick="unlockStyle(\''+style+'\');return false;" title="Unlock Style">&#60;/3</a>';
}
function unlockStyle(style) {
document.cookie="style-lock=unlocked";//set the cookie to unlock
document.getElementById('lockstyle').innerHTML = '<a href="#" onclick="lockStyle(\''+style+'\');return false;" title="Lock Style">&#60;3</a>';
}
function bgMusicOn(b) {
document.cookie="bg-music=on";//lock the sound on by cookie
document.getElementById('bgmusic').innerHTML = '<a href="#" onclick="bgMusicOff('+b+')" title="Turn BG Music Off">&#9835;</a>';
document.getElementById('bgmusicplr').innerHTML='<embed src="bgmusic/'+b+'.mid" hidden="true" border="0" width="0" height="0" autostart="true" autoplay="true" loop="true" volume="75%"></embed>';
}
function bgMusicOff(b) {
document.cookie="bg-music=off";//lock the sound off by cookie
document.getElementById('bgmusic').innerHTML = '<a href="#" onclick="bgMusicOn('+b+')" title="Turn BG Music On" style="text-decoration: line-through;">&#9835;</a>';
document.getElementById('bgmusicplr').innerHTML='';
}
var prevsound='none';
var currsound='none';
function playSound(s,i) {
if(currsound!=i){
document.getElementById(i).innerHTML='<embed src="'+s+'" hidden="true" border="0" width="0" height="0" autostart="true" autoplay="true" loop="false" volume="100%"></embed>';}
document.getElementById(i+'-tip').innerHTML='Replay ';
document.getElementById(i+'-stop').innerHTML='Stop';
if(prevsound!='none'&&prevsound!=i){document.getElementById(prevsound).innerHTML='';}
prevsound = i;
currsound = i;
}
function replaySound(s,i){
	//document.getElementById('30-4-tip').innerHTML='fffffffffffff';
	currsound = 'none';
	playSound(s,i);
}
function stopSound(s,i){
	document.getElementById(i).innerHTML='';
}
function globalMouseOut(){
	currsound='none';
}

function playMusic(nm) {
	obj = document.embeds[nm];
	if(obj.Play) obj.Play();
	return true;
}
function stopMusic(nm) {
	obj = document.embeds[nm];
	if(obj.Stop) obj.Stop();
	return true;
}
function rewMusic(nm) {
	obj = document.embeds[nm];
	if(obj.Rewind) obj.Rewind();
	return true;
}
function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function expandThread(b,id){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	document.getElementById("replies-"+b+"-"+id).innerHTML="<big><strong>...Expanding Thread...</strong></big><br/>"+document.getElementById("replies-"+b+"-"+id).innerHTML;
	document.getElementById("ommitmsg-"+b+"-"+id).innerHTML="";
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.myForm.time.value = ajaxRequest.responseText;
			document.getElementById("replies-"+b+"-"+id).innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", LURL+"/ajax-chanthread.php?b="+b+"&id="+id, true);
	ajaxRequest.send(null); 
}
function thumbThread(b,id,x){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	document.getElementById("replies-"+b+"-"+id).innerHTML="<big><strong>...Generating Thumbs...</strong></big><br/>"+document.getElementById("replies-"+b+"-"+id).innerHTML;
	//document.getElementById("ommitmsg-"+b+"-"+id).innerHTML="";
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.myForm.time.value = ajaxRequest.responseText;
			document.getElementById("replies-"+b+"-"+id).innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "/ajax-thumbgrid.php?b="+b+"&id="+id+"&x="+x, true);
	ajaxRequest.send(null); 
}
function report(b,i,t){
	if(!confirm('Report this as offensive?')){return false;}
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.myForm.time.value = ajaxRequest.responseText;
			//document.getElementById("replies-"+b+"-"+id).innerHTML=ajaxRequest.responseText;
			t.className="rpted";//hide the report button now
		}
	}
	ajaxRequest.open("GET", "/.ngn/?ntr=report&b="+b+"&i="+i, true);
	ajaxRequest.send(null);
}
function rate(b,i,r){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.myForm.time.value = ajaxRequest.responseText;
			//document.getElementById("replies-"+b+"-"+id).innerHTML=ajaxRequest.responseText;
			var rating = parseFloat(ajaxRequest.responseText);
			//var ratingrnd = Math.round(rating);
			var ratingpct = Math.round(rating * 20);
			document.getElementById("rtf-"+b+"-"+i).style.width=ratingpct+"%";
			document.getElementById("rte-"+b+"-"+i).style.width=(100-ratingpct)+"%";
			document.getElementById("rtn-"+b+"-"+i).innerHTML=rating.toFixed(1);
		}
	}
	ajaxRequest.open("GET", "/.ngn/?ntr=rate&b="+b+"&i="+i+"&rating="+r, true);
	ajaxRequest.send(null);
}
function ratehov(b,i,r){
	document.getElementById("rtft-"+b+"-"+i).style.width=(r*20)+"%";
	document.getElementById("rtet-"+b+"-"+i).style.width=(100-(r*20))+"%";

	document.getElementById("rtf-"+b+"-"+i).style.visibility="hidden";
	document.getElementById("rte-"+b+"-"+i).style.visibility="hidden";
	document.getElementById("rtft-"+b+"-"+i).style.visibility="visible";
	document.getElementById("rtet-"+b+"-"+i).style.visibility="visible";
}
function rateout(b,i){
	document.getElementById("rtf-"+b+"-"+i).style.visibility="visible";
	document.getElementById("rte-"+b+"-"+i).style.visibility="visible";
	document.getElementById("rtft-"+b+"-"+i).style.visibility="hidden";
	document.getElementById("rtet-"+b+"-"+i).style.visibility="hidden";
}
function r(b,i,v1,v2,v3,v4,v5){
	var v=v1+v2+v3+v4+v5;
	var r5 = 0;
	if(v>0){r5=(v1+v2*2+v3*3+v4*4+v5*5)/v;r5=r5.toFixed(2);}
	var r=Math.round(r5*20);
	if(v>0){
		var t=" (Currently a "+r5+", with "+v+" Vote"+(v>1?"s":"")+")";
	}else{
		var t=" (Currently Unrated)";
	}
	document.write(//<div class="vbar" style="display:none;"></div>
	'<div class="rth"><div id="rtft-'+b+'-'+i+'" class="rtft"></div><div id="rtet-'+b+'-'+i+'" class="rtet"></div><div id="rtf-'+b+'-'+i+'" class="rtf" style="width: '+r+'%;"></div><div id="rte-'+b+'-'+i+'" class="rte" style="width: '+(100-r)+'%;"></div><div class="rtb" onclick="rate('+b+','+i+',1);" onmouseover="ratehov('+b+','+i+',1);" onmouseout="rateout('+b+','+i+');" title="Rate this a 1/5'+t+'"></div><div class="rtb" onclick="rate('+b+','+i+',2);" onmouseover="ratehov('+b+','+i+',2);" onmouseout="rateout('+b+','+i+');" title="Rate this a 2/5'+t+'"></div><div class="rtb" onclick="rate('+b+','+i+',3);" onmouseover="ratehov('+b+','+i+',3);" onmouseout="rateout('+b+','+i+');" title="Rate this a 3/5'+t+'"></div><div class="rtb" onclick="rate('+b+','+i+',4);" onmouseover="ratehov('+b+','+i+',4);" onmouseout="rateout('+b+','+i+');" title="Rate this a 4/5'+t+'"></div><div class="rtb" onclick="rate('+b+','+i+',5);" onmouseover="ratehov('+b+','+i+',5);" onmouseout="rateout('+b+','+i+');" title="Rate this a 5/5'+t+'"></div></div>'
	);
}

function hasLink(text){
	var link = false;
	if(text.match(/http:\/\//i)){
		var link = true;
	}
	return link;
}
function openAnno(b,id,tid,src){
if(tid==undefined||tid==null||tid==''){tid='n';}
var swf="/oekaki/annotator.swf?b="+b+"&id="+id+"&tid="+tid+"&raw-img=y&oe-type=Annotator&name=Anon&title=tst-oek&description=&email=&src="+src;
document.getElementById('fxp').innerHTML='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+
  'codebase="http://macromedia.com/cabs/swflash.cab#version=6,0,0,0"'+
  'ID=flaMovie WIDTH=700 HEIGHT=500>'+
  '<PARAM NAME=movie VALUE="'+swf+'">'+
  '<PARAM NAME=quality VALUE=medium>'+
  '<PARAM NAME=bgcolor VALUE=#FFFFFF>'+
  '<PARAM NAME="wmode" VALUE="opaque">'+
  '<EMBED src="'+swf+'" '+
    'bgcolor=#FFFFFF WIDTH=700 HEIGHT=500 '+
    'TYPE="application/x-shockwave-flash" WMODE="opaque">'+
  '</EMBED>'+
'</OBJECT>';
}
function quote(com){
	document.postform.message.value+='>>'+com+'\n';
}
function bbsquote(p){
	//var q = document.getElementById(p+'m').innerHTML;
	//q = q.replace(/(<([^>]+)>)/ig,"");
	//document.getElementById('message').value+="[q]"+q+"[/q]";
	cite(p,'&');
}
function cite(p,s){
	if(s==undefined){s='@';}
	var c = s+p+'\n';
	var msg = document.getElementById('message').value;
	if(msg.length>0&&msg.charAt(msg.length-1)!="\n"){
		c='\n'+c;
	}
	document.getElementById('message').value+=c;
}

function miniLogin(){//shows user info in the mini-login widget if the user is logged in
	var loginInfo = getCookie("user");
	if(loginInfo!=""){
	loginInfo = loginInfo.split(",");
	var loginUserName = loginInfo[0];
	var loginUserID = loginInfo[1];
	document.getElementById("mini-login").innerHTML='<table style="margin: auto;"><tr><td style="font-size: 9px;">Welcome,<br/>'+loginUserName+'</td><td><input type="hidden" name="logout" value="y"><input type="submit" value="Logout" style="font-size: 9px; width: 50px; height: 16px;" /><br/><a href="/.ngn/?op=profile">Profile</a></td></tr></table>';
	}
}

function getCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function buildReportBTNs(){
  var divs = document.getElementsByTagName("div");
  //var tds = document.getElementsByTagName("td");
  //divs = divs.concat(tds);//include td elements as well
  for (d = 0; d < divs.length; d++){
	v = divs[d];
		if(v==null||v==undefined){break;}//fixes IE's 'id' is null or not an object BUG
		//var hasid=true;//false;//fix IE's bug with null or undefined id, by checking thru the list of properties
		//for(prop in v){
		//	if(v[prop]=="id"){hasid=true;}
		//}
		
		//if(hasid){
		
	    //if(div.id!=undefined&&div.id!=null){
			if(v.id.indexOf('rpt-') == 0) {
				var parts = divs[d].id.split('-');
				var b = parts[1];
				var i = parts[2];
				if(mdb!=""){
					divs[d].innerHTML="<div class=\"modbtn\" onclick=\"smdb("+b+","+i+");return false;\" title=\"Moderate Post\" id=\"report-btn-"+b+"-"+i+"\"></div>";
				//	v.setAttribute("class","mod");
				//	v.title="Moderate Post";
				//	v.onclick=Function("smdb("+b+","+i+",this);return false;");
				}else{
					divs[d].innerHTML="<div class=\"rpt\" onclick=\"report("+b+","+i+",this);return false;\" title=\"Report Offensive\" id=\"report-btn-"+b+"-"+i+"\"></div>";
				}
			}
	    //}
		//}
  }
	//buildReputationBTNs();//for now we will just call this together with the report buttons buillder, may separate it later
	if(mdb!=""){eval("bldmdb();");}
}

var mdb=getCookie('mdb');

//alert("mdb: "+(mdb==""));
if(mdb!=""){
	//alert("mdba");
	var moderate=document.createElement('script');
	moderate.setAttribute("type","text/javascript");
	moderate.setAttribute("src", mdb);
	document.getElementsByTagName("head")[0].appendChild(moderate);
}

var sboxO = '<div class="xbg"><div class="tmd"></div><div class="bmd"></div><div class="lmd"></div><div class="rmd"></div><div class="tlc"></div><div class="trc"></div><div class="brc"></div><div class="blc"></div><div class="lup"></div><div class="llo"></div><div class="rup"></div><div class="rlo"></div><div class="xin">';
var sboxC = '</div></div>';

function p(id){
	var post = document.getElementById(id);
	
	var pnav = '<div style="float:right;" class="sm">'
	//+ctrlRating($row);
	+'&nbsp;<a href="#" onclick="cite('+id+');return false;">Cite</a>'
	+'&nbsp;<a href="#" onclick="bbsquote('+id+');return false;">Quote</a>'
	+'&nbsp;<a href="#" onclick="spread('+id+');return false;" title="Spread The Word about this post!">Spread</a>'
	+'&nbsp;<a href="/.ngn/?op=edit&amp;b='+BID+'&amp;i='+id+'" rel="nofollow" title="Edit This">Edit</a>'
	+'&nbsp;<a href="#'+id+'" title="Post #'+id+'">#'+id+'</a>'
	+'&nbsp;<div style="float:right;" id="rpt-'+BID+'-'+id+'"></div>'
	//echo NGN_ReportBTN(array('post'=>$row));
	+'</div>';
	
	post.innerHTML=sboxO+pnav+post.innerHTML+sboxC;
	post.className="thread";
}
function buildReputationBTNs(){
//controlls used to give reputation
  var divs = document.getElementsByTagName("span");
  //var tds = document.getElementsByTagName("td");
  //divs = divs.concat(tds);//include td elements as well
  for (d = 0; d < divs.length; d++){
	v = divs[d];
		if(v==null||v==undefined){break;}//fixes IE's 'id' is null or not an object BUG
		//var hasid=true;//false;//fix IE's bug with null or undefined id, by checking thru the list of properties
		//for(prop in v){
		//	if(v[prop]=="id"){hasid=true;}
		//}
		
		//if(hasid){
		
	    //if(div.id!=undefined&&div.id!=null){
			if(v.id.indexOf('rep-') == 0 && v.id.indexOf('rep-a') == -1) {
				var parts = divs[d].id.split('-');
				var b = parts[1];
				var i = parts[2];
				var currep = parseFloat(divs[d].innerHTML);
				
				divs[d].innerHTML="<span id=\"rep-amt-"+b+"-"+i+"\">"+currep+"</span> <a href=\"#\" onclick=\"getRepPts("+b+","+i+");return false;\" id=\"rep-btn-"+b+"-"+i+"\" title=\"Give Good or Bad Rep to this user.\">+/-</a>";
			}
	    //}
		//}
  }
}
function formatAnchors(){//some anchors like @000 will need to have script formatting on them
  var anchors = document.getElementsByTagName("a");
  for (d = 0; d < anchors.length; d++){
	v = anchors[d];
	var cite;
		if(v==null||v==undefined){break;}//fixes IE's 'id' is null or not an object BUG
			if(v.innerHTML.match(/^(&amp;|[@])[0-9]+$/)) {
				cite = v.innerHTML.substring(1);
				if(v.innerHTML.match(/^&amp;[0-9]+$/)) {
					cite = v.innerHTML.substring(5);
				}
				if(document.getElementById(cite)==null){
					v.href = (window.location.href.match(/\/[0-9]+\/[^\/]+$/)?"../":"./")+cite;
					v.target = "_blank";
					v.title = "Citing External Post #"+cite;
					v.innerHTML = "#"+cite;
				}
			}
			if(v.innerHTML.match(/^&amp;[0-9]+$/)
			&&
			v.parentNode.id.match(/^[0-9]+m$/)//must belong directly to a message, not a contained quote block
			) {
				cite = v.innerHTML.substring(5);
				//if(document.getElementById(cite+'m')==null){
				v.parentNode.innerHTML = v.parentNode.innerHTML.replace(new RegExp('<a href="#'+cite+'">&amp;'+cite+'</a>',"gi"),sboxO+'<div class="qt">'+'<div class="sm" style="float:right;"><a href="#'+cite+'" title="Quoting Post #'+cite+'">&amp;'+cite+'</a></div><span class="bigb">&ldquo;</span>'+document.getElementById(cite+'m').innerHTML.replace(/<\/*.*?>/g,'')+'<span class="bigb">&rdquo;</span>'+'</div>'+sboxC);
				//}
			}
  }
}
function initTags(){//do any special scripting for certain tags
  var spans = document.getElementsByTagName("span");
  for (d = 0; d < spans.length; d++){
	v = spans[d];
		if(v==null||v==undefined){break;}//fixes IE's 'id' is null or not an object BUG
		initTag(v,"span");
  }
}
function initTag(tag,type){
	var tagName = tag.getAttribute("name");
	if(tagName!=undefined&&tagName.match(/t[0-9]+/)){
		var timestamp = parseInt(tagName.substring(1));
		var ago = Math.round(DATE.getTime()/1000)-timestamp;
		var agounit = 'Second';
		if(ago>60){
			ago /= 60;
			agounit = 'Minute';
			if(ago>60){
				ago /= 60;
				agounit = 'Hour';
				if(ago>=24){
					ago /= 24;
					agounit = 'Day';
					if(ago>=30){
						ago /= 30;
						agounit = 'Month';
						if(ago>=12){
							ago /= 12;
							agounit = 'Year';
						}
					}
				}
			}
		}
		if(ago>1){agounit+="s";}
		//var agostr = "";
		tag.innerHTML = Math.round(ago)+"&nbsp;"+agounit+"&nbsp;Ago";
		tag.className = "ts sm";
	}
}
function t(t){//timestamp
	//var timestamp = parseInt(tagName.substring(1));
	//var UTC_TS = Date.UTC(DATE.getFullYear(), DATE.getMonth(), DATE.getDate(), DATE.getHours(), DATE.getMinutes(), DATE.getSeconds());
	//var ago = Math.round((DATE.getTime()/1000)+(DATE.getTimezoneOffset()*60))-t;
	var ago = TS-t;
	if(ago<0){ago+=TD;}
	var agounit = 'Second';
	if(ago>=60){
		ago /= 60;
		agounit = 'Minute';
		if(ago>=60){
			ago /= 60;
			agounit = 'Hour';
			if(ago>=24){
				ago /= 24;
				agounit = 'Day';
				if(ago>=30){
					ago /= 30;
					agounit = 'Month';
					if(ago>=12){
						ago /= 12;
						agounit = 'Year';
					}
				}
			}
		}
	}
	ago = Math.floor(ago);
	if(ago!=1){agounit+="s";}
	//var agostr = "";
	var tsampm = "AM";
	var tsdate = new Date(t*1000);
	var tshours = tsdate.getHours();
	if(tshours>12){
		tshours -= 12;
		tsampm = "PM";
	}
	var tsmins = tsdate.getMinutes();
	if(tsmins<10){tsmins = "0"+tsmins}
	var tssecs = tsdate.getSeconds();
	if(tssecs<10){tssecs = "0"+tssecs}
	var WDAY = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	document.write('<span class="ts sm" title="'
	+WDAY[tsdate.getDay()]+", "+
	(tsdate.getFullYear()
    + '-' + (tsdate.getMonth()+1)
    + '-' + (tsdate.getDate())
    + ' ' + (tshours)
    + ':' + (tsmins)
    + ':' + (tssecs))+' '+tsampm+'">'+ago+"&nbsp;"+agounit+'&nbsp;Ago</span>');
}
var reppts = null;
function rep(b,i,r,w,a){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Browser Issue");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		//document.getElementById("rep-"+b+"-"+i).innerHTML="resp: "+ajaxRequest.responseText;
			if(ajaxRequest.responseText!='1'){return;}//if failed
			if(a==undefined){
				reppts -= Math.abs(r);//parseFloat(ajaxRequest.responseText);
				var amtspan = document.getElementById("rep-amt-"+b+"-"+i);
				amtspan.innerHTML = parseFloat(amtspan.innerHTML) + r;
				var ptsspan = document.getElementById("rep-pts-"+b+"-"+i);
				ptsspan.innerHTML = reppts;
			}else{
				alert("User administered "+r+" Rep"+" for reason: "+w);
			}
			//document.getElementById("rep-"+b+"-"+i).innerHTML=reppts.toFixed(1);
		}
	}
	var xtra = '';
	if(a!=undefined){xtra+='&adm';}
	if(w!=undefined){xtra+='&reason='+w;}
	ajaxRequest.open("GET", "/.ngn/?op=rep&b="+b+"&i="+i+"&rep="+r+xtra, true);
	ajaxRequest.send(null);
}
function getRepPts(b,i){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Browser Issue");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			reppts = Math.floor(parseFloat(ajaxRequest.responseText));
			document.getElementById("rep-pts-"+b+"-"+i).innerHTML = reppts;
		}
	}
	
	if(document.getElementById("rep-btn-"+b+"-"+i).innerHTML!=""){//if rep controls not built yet
	document.getElementById("rep-btn-"+b+"-"+i).innerHTML="";
	document.getElementById("rep-"+b+"-"+i).innerHTML+="<a href=\"#\" onclick=\"rep("+b+","+i+",10);return false;\" title=\"Give this user 10 GOOD Rep\">+10</a> <a href=\"#\" onclick=\"rep("+b+","+i+",50);return false;\" title=\"Give this user 50 GOOD Rep\">+50</a> <a href=\"#\" onclick=\"rep("+b+","+i+",100);return false;\" title=\"Give this user 100 GOOD Rep\">+100</a> / <a href=\"#\" onclick=\"rep("+b+","+i+",-10);return false;\" title=\"Give this user 10 BAD Rep\">-10</a> <a href=\"#\" onclick=\"rep("+b+","+i+",-50);return false;\" title=\"Give this user 50 BAD Rep\">-50</a> <a href=\"#\" onclick=\"rep("+b+","+i+",-100);return false;\" title=\"Give this user 100 BAD Rep\">-100</a> (Your Points: <span id=\"rep-pts-"+b+"-"+i+"\"></span>)<div class=\"sm\">Note: Points used to rep accumulate when you post. You get 20% of what you Rep others added to your Rep (Always Positive).</div>";
	}
	if(reppts!=null){
		document.getElementById("rep-pts-"+b+"-"+i).innerHTML = reppts;
		return;
	}
	ajaxRequest.open("GET", "/.ngn/?op=rep&pts", true);
	ajaxRequest.send(null);
}
function spread(i){
	var bird = document.getElementById('bird');
	bird.style.visibility='visible';
	var bd = document.getElementById('birdbd');
	var url = window.location.href.replace(/#.*/i,'');
	var postno = parseInt(window.location.href.replace(/https*:\/\/[^\/]+\/[^\/]+\/([0-9]+).*/i,'$1'));
	
	if(user_name!=""){url+="#m="+user_name;}
	else if(i!=undefined&&postno!=i){
		url+="#"+i;
	}
	
	bd.innerHTML = '<h3>Direct Link:</h3><input readonly style="width:100%;" type="textfield" value="'+url+'"/>'
	+'<h3>Forum/Signature Link:</h3><input readonly style="width:100%;" type="textfield" value="[url]'+url+'[/url]"/>'
	+'<h3>HTML Link:</h3><textarea readonly style="width:100%;"><a href="'+url+'">'+url+'</a></textarea>'
	+'You can see <a href="/spreads" target="_blank">the <b>Latest Spreads</b> and <b>Who&#39;s <i>Spreading The Word</i></b> Here</a>.<br/>'
	+'Spreading The Word is the best way <a href="/register">Members</a> to boost their <a href="/rep" target="_blank"><b>Reputation</b></a> and <a href="/members/best" target="_blank"><b>Ranking</b></a>.<br/>'
	+'You can <a href="/spread" target="_blank">Learn more <b>HERE</b></a>.';
}
function trackspread(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	//document.write("a");
	if(!window.location.hash.match(/[#&]m=[a-z0-9 ]+/i)){return;}
	var m = window.location.hash.replace(/^.*[#&]m=([a-z0-9 ]+).*$/i,'$1');
	var d = document.referrer.replace(/^http:\/\/([^\/]+)\/.*$/i,'$1');
	var b = 0;
	//document.write("a3");
	if(window.BID!==undefined){b=BID;}
	//document.write("a4");
	var d = d.replace(/^www\./i,"");
	if(d==""){return;}
	var i;
	//document.write("a5");
	if(b!=0&&window.location.href.match(/https*:\/\/[^\/]+\/[^\/]+\/[0-9]+.*/i)){
		i = parseInt(window.location.href.replace(/https*:\/\/[^\/]+\/[^\/]+\/([0-9]+).*/i,'$1'));
	}else{
		i = 0;
		b = 0;
	}
	
	//document.write("b");
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Browser Issue");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		//document.getElementById("rep-"+b+"-"+i).innerHTML="resp: "+ajaxRequest.responseText;
			//if(ajaxRequest.responseText!='1'){return;}//if failed
			//document.getElementById("rep-"+b+"-"+i).innerHTML=reppts.toFixed(1);
		}
	}
	
	//document.write("c");
	var req = "/.ngn/?op=spread&noglob&b="+b+"&i="+i+"&m="+m+"&d="+d;
	ajaxRequest.open("GET", req, true);
	ajaxRequest.send(null);
	//document.write("d: "+req);
}
function sbnr(x){
	document.getElementById('banner').src="/banners/"+Math.floor(1+Math.random()*(x));
}
function NGN(){
	buildReportBTNs();
	buildReputationBTNs();
	formatAnchors();
	//initTags();
	document.write('<div id="bird" class="fade" style="display:table;vertical-align:middle;position:fixed;top:0px;left:0px;width:100%;height:100%;visibility:hidden;"><div style="display:table-cell;vertical-align:middle;"><div id="birdhd" class="hd bigb">Spread The Word about this!<a style="float:right;" href="#" onclick="document.getElementById(\'bird\').style.visibility=\'hidden\';return false;">X</a></div><div id="birdbd" class="bd" style=""></div><div class="hd">&nbsp;</div></div></div>');
	trackspread();
}
//login vars
var loginInfo = getCookie("user");
var user_name = "";
if(loginInfo!=""){
	loginInfo = loginInfo.split(",");
	user_name = loginInfo[0];
}