// Copyright 2001 Chad Paulson (Ghostbusters.net)
// Modified January 01, 2003

function ShowBurstAd(adcode, width, height) {
 var bN = navigator.appName;
 var bV = parseInt(navigator.appVersion);   
 var base='http://www.burstnet.com/';   
 var Tv='';   
 var agt=navigator.userAgent.toLowerCase();   
 if (bV>=4)  
 {ts=window.location.pathname+window.location.search;
  i=0; Tv=0; while (i< ts.length)
    { Tv=Tv+ts.charCodeAt(i); i=i+1; } Tv="/"+Tv;}
  else   {Tv=escape(window.location.pathname);
  if( Tv.charAt(0)!='/' ) Tv="/"+Tv; 
    else if (Tv.charAt(1)=="/")
 Tv="";     
 if( Tv.charAt(Tv.length-1) == "/")
   Tv = Tv + "_";}   
 if (bN=='Netscape'){        
  if ((bV>=4)&&(agt.indexOf("mac")==-1))  
 { document.write('<s'+'cript src="'+ 
  base+'cgi-bin/ads/'+adcode+'.cgi/RETURN-CODE/JS' 
  +Tv+'">'); 
  document.write('</'+'script>');
 }
   else if (bV>=3) {document.write('<'+'a href="'+base+'ads/' + 
  adcode + '-map.cgi'+Tv+'"target=_top>');
  document.write('<img src="' + base + 'cgi-bin/ads/' +
  adcode + '.cgi' + Tv + '" width="' + width + '" height="' + height + '"' +
  ' border="0" alt="Click Here"></a>');}   
}
if (bN=='Microsoft Internet Explorer')    
document.write('<ifr'+'ame id="BURST" src="'+base+'cgi-bin/ads/'  
+     
adcode + '.cgi' + Tv + '/RETURN-CODE" width="' + width + '" height="' + height + '"' +     
'marginwidth="0" marginheight="0" hspace="0" vspace="0" ' +     
'frameborder="0" scrolling="no"></ifr'+'ame>');  
}




/*
/
/ Insert Ghost-Icons
/
*/

function gbnghead(text) {
  text = ' ' + text + ' ';
  if (document.boardpost.body.createTextRange && document.boardpost.body.caretPos) {
    var caretPos = document.boardpost.body.caretPos;
    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    document.boardpost.body.focus();
  } else {
    document.boardpost.body.value  += text;
    document.boardpost.body.focus();
  }
}


/*
/
/ Prevent Double Posting
/
*/

var submitDone;
submitDone = 0;

function gbnpost() {

  if (document.all && document.boardpost.postit) {
    document.boardpost.postit.disabled = true;
    document.boardpost.postit.value = 'Posting... Please wait...';
  }

  if (submitDone == 0) {
    submitDone = 1;
    return true;
  } else {
    if (!document.boardpost.postit || !document.all) {
      alert("Posting... Please wait...");
    }
  return false;
  }
}




// player launch function
function gbnplayer(type,genre,id) {
  var url = "/player/?type=" + type + "&genre=" + genre + "&id=" + id;
  var name = "gbnplayer";
  var features = "width=500,height=350,scrollbars=no";
  var PlayerWin = window.open(url, name, features);
  PlayerWin.focus();
}

// mod ip address view function
function viewip(user,postid) {
  var url = "/view_ip/?user=" + user + "&postid=" + postid;
  var name = "viewip";
  var features = "width=250,height=100,scrollbars=no";
  var ViewIp = window.open(url, name, features);
  ViewIp.focus();
}

// smiley function
function gosmiley() {
  var url = "/smilies/index.html";
  var name = "smile";
  var features = "width=200,height=250,scrollbars=no";
  var gosmile = window.open(url, name, features);
  gosmile.focus();
}

// gbchat function
function gbchat() {
  var url = "http://www.ghostbusters.net/chat/index.html";
  var name = "gbchat";
  var features = "width=620,height=455,scrollbars=no";
  var gogbchat = window.open(url, name, features);
  gogbchat.focus();
}


// rank function
function rankoverview() {
  var url = "/rankoverview.html";
  var name = "rankoverview";
  var features = "width=350,height=258,scrollbars=no";
  var rankoverview = window.open(url, name, features);
  rankoverview.focus();
}

// email story pop-up function
function emailstory(url) {
  var name = "email";
  var features = "width=400,height=125,scrollbars=no";
  var gostory = window.open(url, name, features);
  gostory.focus();
}

// doom download pop-up function
function doomdownload() {
  var url = "/doom/download/";
  var name = "download";
  var features = "width=425,height=350,scrollbars=no";
  var doomdl = window.open(url, name, features);
  doomdl.focus();
}

// view image function
function gbnimage(title,image) {
  var url = "/viewimage/" + image + "/" + title + "/";
  var name = "gbnimage"
  var features = "toolbar=no,scrollbars=no,resizable=yes,menubar=no,width=1,height=1";
  var gbimagego = window.open(url, name, features);
  gbimagego.focus();
}




// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

//// Type Quietly ////

// Looks for repeated sequences of uppercase letters being keyed in;
// politely asks user to stop 'shouting'!
// At the moment it only works when the user is typing at the end of the message.
// Should catch most occurrences though.

// Maximum caps in a row (after stripping all non-alphabetical characters)
// Setting this too low may cause it to be triggered by uppercase BBCode/HTML tags
// or acronyms and the like
var TQ_MAX_CAPS = 100;

// Maximum size of text range to sample (should be >= TQ_MAX_CAPS)
var TQ_SAMPLE_SIZE = 16;

// Cutoff point; disable Type Quietly if the message gets long
var TQ_CUT_OFF_POINT = 8192;

// Message to display when user is shouting
var TQ_MESSAGE =
	'You seem to be typing in \'all capitals\'.\n\n' +
	'This is not usually a good idea: it can make\n' +
	'your message harder to read or might indicate  \n' +
	'you are \'shouting\'.\n\n' +
	'Please make sure Caps Lock is off, and type in\n' +
	'mixed or small letters. Thanks!'

// Initialisation: Leave these lines as is
var tqIsActive = true;
var tqPrevEndChars = '';
var tqPrevLength = 0;
var tqPrevElement = '';

// Main Type Quietly function
// Always return true in case some 'clever' browser decides to cancel the keypress
function typeQuietly (textEl, event) {
	// Check if active
	if (!tqIsActive) {
		return true;
	}

	// Check arguments
	if ((typeof textEl != 'object') || (typeof event != 'object')) {
		return true;
	}

	// Check string handling requirements (should be fine for IE 4+, NS 4+ etc.)
	if ((typeof RegExp != 'function') || (typeof textEl.value.substr) != 'function') {
		return true;
	}

	// Deactivate if message too long
	if (textEl.value.length > TQ_CUT_OFF_POINT) {
		tqIsActive = false;
		return true;
	}

	// Check message is long enough to trigger
	if (textEl.value.length < TQ_MAX_CAPS) {
		return true;
	}

	// Sample last characters of message
	var lastChars = '';
	var selectStart, selectLength;
	if (textEl.value.length < TQ_SAMPLE_SIZE) {
		selectStart = 0;
		selectLength = textEl.value.length;
	}
	else {
		selectStart = textEl.value.length - TQ_SAMPLE_SIZE;
		selectLength = TQ_SAMPLE_SIZE;
	}
	lastChars = textEl.value.substr(selectStart, selectLength);

	// Check we caught something
	if (lastChars.length == 0) {
		return true;
	}

	// If we're now looking at a different element, reset
	if ((tqPrevElement == '') || (tqPrevElement != textEl.name)) {
		tqPrevEndChars = lastChars;
		tqPrevLength = 0;
		tqPrevElement = textEl.name;
		return true;
	}

	// End of message must be changing
	if (lastChars == tqPrevEndChars) {
		return true;
	}
	tqPrevEndChars = lastChars;

	// Last character must itself be a capital
	if (lastChars.substr(lastChars.length - 1, 1).search(eval('/[A-Z]/')) == -1) {
		return true;
	}

	// Don't trigger when deleting or on first keypress
	if ((tqPrevLength == 0) || (textEl.value.length < tqPrevLength)) {
		tqPrevLength = textEl.value.length;
		return true;
	}
	tqPrevLength = textEl.value.length;

	// Strip non-alphabetical characters and trim to size
	lastChars = lastChars.replace(eval('/\W|\d/g'), '');
	if (lastChars.length > TQ_MAX_CAPS) {
		lastChars = lastChars.substr(lastChars.length - TQ_MAX_CAPS, TQ_MAX_CAPS);
	}

	// Show message if needed
	if (lastChars == lastChars.toUpperCase()) {
		alert (TQ_MESSAGE);
		tqIsActive = false;
	}

	return true;
}

//// [end of Type Quietly code] ////



