
function newTitle(msg){ document.title = msg;}

function callback(serverData, serverStatus) {       // Called automatically when we get data back from server
   msg = serverData.match("<!-- TITLE: (.+?) -->", "g");
   x = msg[0].replace("<!-- TITLE: ", "");
   y = x.replace(" -->", "");
   z = y.replace("<span (.+?)>", "");

   if( msg[0] == document.title ) { return true; }
   else {
   document.getElementById('chatterBox').innerHTML = serverData;
   newTitle(z);
   }
}

function ajaxRequest() {
   var AJAX = null;                                 // Initialize the AJAX variable.
   if (window.XMLHttpRequest) {                     // Does this browser have an XMLHttpRequest object?
      AJAX=new XMLHttpRequest();                    // Yes -- initialize it.
   } else {                                         // No, try to initialize it IE style
      AJAX=new ActiveXObject("Microsoft.XMLHTTP");  //  Wheee, ActiveX, how do we format c: again?
   }                                                // End setup Ajax.
   if (AJAX==null) {                                // If we couldn't initialize Ajax...
      alert("Your browser doesn't support AJAX.");  // Sorry msg.                                               
      return false                                  // Return false, couldn't set up ajax
   }
   AJAX.onreadystatechange = function() {                      // When the browser has the request info..
      if (AJAX.readyState==4 || AJAX.readyState=="complete") { //  see if the complete flag is set.
         callback(AJAX.responseText, AJAX.status);             // Pass the response to our processing function
      }                                                        // End Ajax readystate check.
   }
   var url='boards/index.php?act=chat&do=showMSG'; // This is the URL we will call.
   AJAX.open("GET", url, true);                                  // Open the url this object was set-up with.  
   AJAX.send(null);                                              // Send the request.
}

function clearForm()
{
	document.getElementById('content').value = document.getElementById('writeInput').value;
	document.getElementById('writeInput').value = '';
	document.getElementById('chatForm').submit();
}

var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var is_mac    = (myAgent.indexOf("mac")!=-1);


	function mkBold(where)
	{ var add = prompt("Enter text to be set as Bold", "");
		add = "[b]" + add + "[/b]";
		where.Post.value = where.Post.value + add;
	}
	function mkUnderline(where)
	{ var add = prompt("Enter text to be set as Underline", "");
		add = "[u]" + add + "[/u]";
		where.Post.value = where.Post.value + add;
	}
	function mkItalic(where)
	{ var add = prompt("Enter text to be set as Italic", "");
		add = "[i]" + add + "[/i]";
		where.Post.value = where.Post.value + add;
	}
	function postImg(where)
	{ var add = prompt("Enter Image Link", "http://");
		add = "[img=" + add + "]";
		where.Post.value = where.Post.value + add;
	}

	function insertAtCursor(myField, myValue)
	{

		//IE support
		if (document.selection)
		{
			alert("if");
			myField.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
		}

		//MOZILLA/NETSCAPE support
		else if (myField.selectionStart || myField.selectionStart == "0")
		{
			alert("elseif");
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
		} else {
			alert("else: " + myField.value);
			zzz = myField.value + myValue;
			alert(zzz);
		}
	}

function emoticon(theSmilie)
{
	doInsert(" " + theSmilie + " ", "", false);
}


function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = document.chatForm.writeInput;

	if ( (myVersion >= 4) && is_ie && is_win) // Ensure it works for IE4up / Win only
	{
		if(obj_ta.isTextEdit){ // this doesn't work for NS, but it works for IE 4+ and compatible browsers
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null){
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;
	
				rng.text = ibTag;
			}
		}
		else{
			if(isSingle)
				isClose = true;
	
			obj_ta.value += ibTag;
		}
	}
	else
	{
		if(isSingle)
			isClose = true;

		obj_ta.value += ibTag;
	}

	obj_ta.focus();
	
	// clear multiple blanks
//	obj_ta.value = obj_ta.value.replace(/  /, " ");

	return isClose;
}

	function showPOpts(id) 
	{ 
		if ( document.getElementById(id).style.display == "none")
		{
			document.getElementById(id).style.display = "";

		} else { document.getElementById(id).style.display = "none" }
	}


function callback2(serverData, serverStatus) {       // Called automatically when we get data back from server

   var oList = document.getElementById('onlinepallet').innerHTML;
   if( serverData == oList ) { return true; }
   else {
   document.getElementById('onlinepallet').innerHTML = serverData;

   }
}

function ajaxRequest2() {
   var AJAX = null;                                 // Initialize the AJAX variable.
   if (window.XMLHttpRequest) {                     // Does this browser have an XMLHttpRequest object?
      AJAX=new XMLHttpRequest();                    // Yes -- initialize it.
   } else {                                         // No, try to initialize it IE style
      AJAX=new ActiveXObject("Microsoft.XMLHTTP");  //  Wheee, ActiveX, how do we format c: again?
   }                                                // End setup Ajax.
   if (AJAX==null) {                                // If we couldn't initialize Ajax...
      alert("Your browser doesn't support AJAX.");  // Sorry msg.                                               
      return false                                  // Return false, couldn't set up ajax
   }
   AJAX.onreadystatechange = function() {                      // When the browser has the request info..
      if (AJAX.readyState==4 || AJAX.readyState=="complete") { //  see if the complete flag is set.
         callback2(AJAX.responseText, AJAX.status);             // Pass the response to our processing function
      }                                                        // End Ajax readystate check.
   }
   var url2='boards/index.php?act=chat&do=showUsers'; // This is the URL we will call.
   AJAX.open("GET", url2, true);                                  // Open the url this object was set-up with.  
   AJAX.send(null);                                              // Send the request.
}
setInterval('ajaxRequest()', '1000');
//setInterval('ajaxRequest2()', '3000');
