////////////////////////
//Start Ajax Shit
////////////////////////

function ajaxFunction(URL, DIV)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (error1)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (error2)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.getElementById(DIV).innerHTML = xmlHttp.responseText;
        }
      };
    xmlHttp.open("GET",URL,true);
    xmlHttp.send(null);
  }

////////////////////////
//End Ajax Shit
////////////////////////


function displayNewPrompt(){
var title=prompt("Please enter a title for this room:","");
var people=prompt("If you want this chat to be for all people to join, then leave this blank, otherwise, just enter in all of the names of the people that you want to be in the Chat. (Separate the names by commas.)  You do not need to put in your own name.","");

ajaxFunction('chatAjax.php?do=newChat&people=' + people + '&title=' + title, 'hiddenDIV');
setTimeout("CheckWorked()",2000);
}

function displayInvitePrompt(){
var people=prompt("Please enter the names of the people to invite.  (Separate the names by commas.) ","");

ajaxFunction('chatAjax.php?do=invitePeople&people=' + people, 'hiddenDIV');
setTimeout("CheckWorked()",2000);
}


function displayKickPrompt(){
var person=prompt("Please enter the name of the person to kick:","");

ajaxFunction('chatAjax.php?do=kickUser&person=' + person, 'hiddenDIV');
setTimeout("CheckWorked()",2000);
}

function displayBanPrompt(){
var person=prompt("Please enter the name of the person to ban:","");

ajaxFunction('chatAjax.php?do=banUser&person=' + person, 'hiddenDIV');
setTimeout("CheckWorked()",2000);
}

function CheckWorked(){
var hidden = document.getElementById('hiddenDIV').innerHTML;
alert(hidden);
}


////////////////////////
//Start Ajax Shit
////////////////////////

function titleFunction(URL)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (error1)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (error2)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.title = xmlHttp.responseText;
        }
      };
    xmlHttp.open("GET",URL,true);
    xmlHttp.send(null);
  }
////////////////////////
//End Ajax Shit
////////////////////////


	function checkEnter(e) {
		var characterCode;

		// Good Browsers
		if(e && e.which) {
			e = e;
			characterCode = e.which;
		}

		// IE
		else {
			e = event;
			characterCode = e.keyCode;
		}

		if (characterCode == 13) {
			ajaxFunction('chatAjax.php?do=shout&message=' + escape(document.getElementById('message').value), 'chatCurrentUsers');
document.getElementById('message').value='';
		}
	}



////////////////////////
//Start Do the Popup
////////////////////////

function doThePopUp(theUrl) {
reWin = window.open(theUrl,'determined','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=575,height=250,top=100,left=100');
}

////////////////////////
//End Do the Popup
////////////////////////



////////////////////////
//Start BBCode
////////////////////////

//Old BBCode
/*function writeBold (form) {
    TestVar =form.post.value;
    form.post.value = TestVar + " [b]Text Here[/b] ";
}

function writeItalic (form) {
    TestVar =form.post.value;
    form.post.value = TestVar + " [i]Text Here[/i] ";
}

function writeUnderline (form) {
    TestVar =form.post.value;
    form.post.value = TestVar + "  [u]Text Here[/u] ";
}

function writeImage (form) {
    TestVar =form.post.value;
    form.post.value = TestVar + " [img]Image Link Here[/img] ";
}

function writeSmilie (test) {
    Test = test;
    TestVar = document.post.post.value;
    document.post.post.value = TestVar + " " + Test + " ";
}*/


//New BBCode
var clientInfo = navigator.userAgent.toLowerCase();
var isIE = ( clientInfo.indexOf("msie") != -1 );
var isWin = ( (clientInfo.indexOf("win")!=-1) || (clientInfo.indexOf("16bit") != -1) );

function createBBtag( openerTag , closerTag , areaId ) {
	if(isIE && isWin) {
		createBBtag_IE( openerTag , closerTag , areaId );
	}
	else {
		createBBtag_nav( openerTag , closerTag , areaId );
	}
	return;
}

function createBBtag_IE( openerTag , closerTag , areaId ) {
	var txtArea = document.getElementById( areaId );
	var aSelection = document.selection.createRange().text;
	var range = txtArea.createTextRange();

	if(aSelection) {
		document.selection.createRange().text = openerTag + aSelection + closerTag;
		txtArea.focus();
		range.move('textedit');
		range.select();
	}
	else {
		var oldStringLength = range.text.length + openerTag.length;
		txtArea.value += openerTag + closerTag;
		txtArea.focus();
		range.move('character',oldStringLength);
		range.collapse(false);
		range.select();
	}
	return;
}

function createBBtag_nav( openerTag , closerTag , areaId ) {
	var txtArea = document.getElementById( areaId );
	if (txtArea.selectionEnd && (txtArea.selectionEnd - txtArea.selectionStart > 0) ) {
		var preString = (txtArea.value).substring(0,txtArea.selectionStart);
		var newString = openerTag + (txtArea.value).substring(txtArea.selectionStart,txtArea.selectionEnd) + closerTag;
		var postString = (txtArea.value).substring(txtArea.selectionEnd);
		txtArea.value = preString + newString + postString;
		txtArea.focus();
	}
	else {
		var offset = txtArea.selectionStart;
		var preString = (txtArea.value).substring(0,offset);
		var newString = openerTag + closerTag;
		var postString = (txtArea.value).substring(offset);
		txtArea.value = preString + newString + postString;
		txtArea.selectionStart = offset + openerTag.length;
		txtArea.selectionEnd = offset + openerTag.length;
		txtArea.focus();
	}
	return;
}


////////////////////////
//End BBCode
////////////////////////


////////////////////////
//Start Checkboxes
////////////////////////

	function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }

////////////////////////
//End Checkboxes
////////////////////////


function ShouldContinueForm(text) {
	if(confirm(text)==true){
		return true;
	}
	return false;
}

function UpdateLastRefresh(){
	ajaxFunction("ajax.php", "stats");
}