	var bbCount =0;
 
	function bbText(txtName,txtFill){
		bbCount++;
		document.write('<div class="bbBin"><div id="bbMenu'+bbCount+'" class="bbMenu"><button>B</button><button>i</button><button>U</button><button>Quote</button><button>Photo</button><button>Link</button><select class="sxy" name="fontSize"><option value="9">(9) Smaller</option><option value="10">(10) Small</option><option value="11">(11) Medium</option><option selected value="12">(12) Normal Size</option><option value="13">(13) Large</option><option value="14">(14) Larger</option></select><br clear="all"></div><textarea id="bbMsg'+bbCount+'" class="bbTxt" name="'+txtName+'"></textarea><br/><div id="bbLabel'+bbCount+'" class="bbLabel">&nbsp;</div></div>');
		gei('bbMsg'+bbCount).innerHTML=txtFill.innerHTML;
		initBBMenu(bbCount);

	}

	/* bbText Initializer */
	function initBBMenu(bbMenu){
		if(gei('bbMenu'+bbMenu)){
			x = gei('bbMenu'+bbMenu).getElementsByTagName("button");
			for(i=0;i<x.length;i++){
				if(x[i].innerHTML=='B')x[i].className='bold';
				if(x[i].innerHTML=='i')x[i].className='italic'
				if(x[i].innerHTML=='U')x[i].className='underline';

				x[i].onclick = new Function('bbAction(this.innerHTML,\''+bbMenu+'\');return false;');
				x[i].onmouseover = new Function('bbActionLabel(this.innerHTML,\''+bbMenu+'\');');
				x[i].onmouseout = new Function('bbActionLabel(0,\''+bbMenu+'\');');

			}
			x = gei('bbMenu'+bbMenu).getElementsByTagName("select");
			for(i=0;i<x.length;i++){
				x[i].onkeyup = new Function('bbAction(this.name,\''+bbMenu+'\');');
				x[i].onchange = new Function('this.onkeyup();');
				x[i].onmouseover = new Function('bbActionLabel(this.name,\''+bbMenu+'\');');
				x[i].onmouseout = new Function('bbActionLabel(0,\''+bbMenu+'\');');
			}
		}


	}

	/* helper labels onmouseover */
	function bbActionLabel(lbl,ele){
			var lblr = '';
			switch(lbl){
				case 0: lblr = '&nbsp;'; break;
				case 'B': lblr = '<span>[b]</span> bold text <span>[/b]</span>'; break;
				case 'i': lblr = '<span>[i]</span> italic text <span>[/i]</span>'; break;
				case 'U': lblr = '<span>[u]</span> underlined text <span>[/u]</span>'; break;
				case 'Quote': lblr = '<span>[quote]</span> quoted text <span>[/quote]</span>'; break;
				case 'Photo': lblr = '<span>[img]</span> http://image-url/ <span>[/img]</span>'; break;
				case 'Link': lblr = '<span>[url]</span> http://your-url/ <span>[/url]</span>'; break;
				case 'fontSize': lblr='<span>[size=12]</span> size 12 text <span>[/size]</span>'; break;
				default: lblr = 'Label not defined...'; break;
			}
			gei('bbLabel'+ele).innerHTML = ((lblr != '&nbsp;')?'Usage: ':'')+lblr;
	}

	/* execute bb action based on type */
	function bbAction(act,ele){
		switch(act){
			case 'B': bbInsert('[b]','[/b]',ele); break;
			case 'i': bbInsert('[i]','[/i]',ele); break;
			case 'U': bbInsert('[u]','[/u]',ele); break;
			case 'Quote': bbInsert('[quote]','[/quote]',ele); break;
			case 'Photo': bbInsert('[img]','[/img]',ele); break;
			case 'Link': bbInsert('[url]','[/url]',ele); break;
			case 'fontSize':
				ez = gei('bbMenu'+ele).getElementsByTagName("select")[0];
				sz = ez.options[ez.selectedIndex].value;
				bbInsert('[size='+sz+']','[/size]',ele);
			break;
		}
	}

	/* perform insert based on open & close */
	function bbInsert(o,c,ele){cPoint = bbPoint(ele);eleI = ele;ele = gei('bbMsg'+ele);ele.value = ele.value.substring(0,cPoint['start'])+o+cPoint['selText']+c+ele.value.substring(cPoint['start']+cPoint['selText'].length);if(!cPoint['selText']){ setSelRange(gei('bbMsg'+eleI),(cPoint['start']+o.length),(cPoint['start']+o.length));}}
	function setSelRange(inputEl, selStart, selEnd) { if (inputEl.setSelectionRange) { inputEl.focus(); inputEl.setSelectionRange(selStart, selEnd); } else if (inputEl.createTextRange) { var range = inputEl.createTextRange(); range.collapse(true); range.moveEnd('character', selEnd); range.moveStart('character', selStart); range.select(); }} /* �webmasterworld.com forums*/
	function bbPoint(ele){var textarea = gei("bbMsg"+ele);textarea.focus();if (typeof(textarea.selectionStart) == 'number'){var cP = new Array();cP['start'] = textarea.selectionStart;cP['selText'] = textarea.value.substring(textarea.selectionStart,textarea.selectionEnd);return cP;}else if(document.selection){var selection_range = document.selection.createRange().duplicate();if (selection_range.parentElement() == textarea) {var before_range = document.body.createTextRange();before_range.moveToElementText(textarea);before_range.setEndPoint("EndToStart", selection_range);var after_range = document.body.createTextRange();after_range.moveToElementText(textarea);after_range.setEndPoint("StartToEnd", selection_range);var before_finished = false, selection_finished = false, after_finished = false;var before_text, untrimmed_before_text, selection_text, untrimmed_selection_text, after_text, untrimmed_after_text;before_text = untrimmed_before_text = before_range.text;selection_text = untrimmed_selection_text = selection_range.text;after_text = untrimmed_after_text = after_range.text;do {if (!before_finished) {if (before_range.compareEndPoints("StartToEnd", before_range) == 0) {before_finished = true;} else {before_range.moveEnd("character", -1);if (before_range.text == before_text) {untrimmed_before_text += "\r\n";} else {before_finished = true;}}}if (!selection_finished) {if (selection_range.compareEndPoints("StartToEnd", selection_range) == 0) {selection_finished = true;} else {selection_range.moveEnd("character", -1);if (selection_range.text == selection_text) {untrimmed_selection_text += "\r\n";} else {selection_finished = true;}}}if (!after_finished) {if (after_range.compareEndPoints("StartToEnd", after_range) == 0) {after_finished = true;} else {after_range.moveEnd("character", -1);if (after_range.text == after_text) {untrimmed_after_text += "\r\n";} else {after_finished = true;}}}} while ((!before_finished || !selection_finished || !after_finished));var untrimmed_text = untrimmed_before_text + untrimmed_selection_text + untrimmed_after_text;var untrimmed_successful = false;if (textarea.value == untrimmed_text) {untrimmed_successful = true;}var startPoint = untrimmed_before_text.length;var cP = new Array();cP['start'] = startPoint;cP['selText'] = selection_text;return cP;}}} /* �dedestruct.com */


	function showResults(){
		
		$('#showResults1a').show();
		$('#showResults2a').show();
		$('#showResults3a').show();
		$('#showResults4a').show();
		
		
		$('#showResults1b').show();
		$('#showResults2b').show();
		$('#showResults3b').show();
		$('#showResults4b').show();
	
	}

	function submitVote(tid){
		var vote = $("input[name='myVote']:checked").val();
		if(!vote) alert("Please select your answer then click this button.");
		else $.post("/action.html",{'act':'forum.poll.vote','tid':tid,'vote':vote},function(){alert('Your vote has been submitted.');});
	}

	function goPreview(){
		$('#newPost > input[name=act]').val('preview');
		$('#newPost').submit();
	}
	function goPost(){
		$('#newPost > input[name=act]').val('new');
		$('#newPost').submit();
	}
	
	
	
	
	function goPostReply(){
		if($('#msgReplyTxt').val() < 3) alert('Message is too short.');
		else $('#postReply').submit();

	}
	
	
	
	function showType(x){
		$('#msgType1').hide();
		$('#msgType2').hide();
		$('#msgType3').hide();
		$('#msgType4').hide();
		$('#msgType'+x).slideDown('slow',function(){
			switch(x){
				case "1": case 1: makeCK('messageNormalTxt'); break;
				case "2": case 2: makeCK('messagePictureTxt'); break;
				case "3": case 3: makeCK('messageVideoTxt'); break;
				case "4": case 4: makeCK('messagePollTxt'); break;				
			}
		});
	}
	function showPicType(x){
		$('#picType1').hide();
		$('#picType2').hide();
		$('#picType'+x).slideDown('slow');
	}

	
	
	

	
/* FORUMS */

function toggleSticky(id){
	obj = gei('stickyIcon');
	m =(obj.src.indexOf('/guild/static/images/icons/sticky.png')>0)? 0:1;
	$("#stickyIcon").attr({
		'src':(m==0)?'/guild/static/images/icons/stickyOff.png':'/guild/static/images/icons/sticky.png',
		'title':(m==0)?'Thread is not a sticky, click to make it sticky.':'Thread is sticky, click to unstick.'
	});
	$.getJSON("/forums.html?show=actions&toggle=sticky&id="+id);
}

function toggleLocked(id){
	obj = gei('lockedIcon');
	m =(obj.src.indexOf('/guild/static/images/icons/locked.png')>0)? 0:1;
	$("#lockedIcon").attr({
		'src':(m==0)?'/guild/static/images/icons/lockedOff.png':'/guild/static/images/icons/locked.png',
		'title':(m==0)?'Thread is locked, click to unlock.':'Thread is unlocked, click to lock.'
	});
	$.getJSON("/forums.html?show=actions&toggle=locked&id="+id);
}





function toggleDelete(id,fid,jid){
	if(confirm((jid)?"Are you sure you wish to delete this reply?":"Are you sure you wish to delete this post and all replies?")) $.getJSON("/forums.html?show=actions&toggle=delete&id="+id,function(){if(jid) $("#thread_"+id).slideUp('slow');else window.location='/forums.html?show=threads&forum='+fid;});		
}

function quoteThread(threadId){
	$.getJSON("/action.html?cln=1&act=forum.quote&thread="+threadId,function(f){
		var boxes = {"1":"messageNormalTxt","2":"messagePictureTxt","3":"messageVideoTxt","4":"messagePollTxt"};
		box = boxes[$('select[name=type]').val()];
		if(box){
		
		//tinyMCE.execInstanceCommand(box,"mceInsertContent",false,f.msg);
		
		myCK[box].insertHtml(f.msg);
		window.location='#postReply';
		}});	
}















/* GENERAL */
function whosOnline(){
	$.getJSON("/action.html?cln=1&act=whos.online",function(f){$("#whosOnline").html(f.list)});
}












/* NEWS */
var APP = [];
function launchApp(app,appName){
	APP[app] = 'appDoc'+app;
	document.write('<div id="'+APP[app]+'"><i>Loading '+appName+'... </i></div>');
	$.getJSON("/apps/"+app+"/",function(f){
		$("#appDoc"+app).html(f.html);
		if(f.js) eval(f.js);
		if(f.jsfile) $("head").append($('<script></script>').attr({'type':'text/javascript','src':f.jsfile}));
	});
}



function autoRankMe(cid){
	if(!cid) cid = '';
	$.getJSON("/?json=autoRankMe&cid="+cid,function(f){
		if(f.err) alert(f.err);
		if(f.good){
			alert('You have been ranked, refreshing the page to upgrade your access!');
			autoRankAlertDisable();
			window.location=window.location;
			return true;
		}
		if(f.character){
			alert("Before you can use this auto ranking tool you need to verify ownerhsip of your character using the Confirm Character tools on the 'My Characters' page.");
			return false;
		}
		if(f.password){
			var pass = prompt("Enter the auto ranking password:");
			if(!pass) return false;
			else {
				pass = $.base64Encode(pass);
				$.getJSON("/?json=autoRankMe-pass&cid="+cid+"&pass="+pass,function(f){
					if(f.good){
						alert('You have been ranked, refreshing the page to upgrade your access!');
						autoRankAlertDisable();
						window.location=window.location;
						return true;						
					} else {
						if(f.err) alert(f.err);
						else alert('Invalid password.');
					}
				})
			}
		}
	});
}
function autoRankAlertDisable(){
	$.getJSON("/?json=hideAutoRankPrompt");
	$("#autoRankAlert").slideUp('slow');
}