var window_width = 0;
var window_height = 0;

/***************************************************************************
* purpose:                                                  
* Clicks link elements.
****************************************************************************/
function fireOnclick(objID) {

var target = document.getElementById(objID);

if(! target) return false;

if(document.dispatchEvent) { // W3C
    var oEvent = document.createEvent( "MouseEvents" );
    oEvent.initMouseEvent("click", true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
    target.dispatchEvent( oEvent );
    }
else if(document.fireEvent) { // IE
    target.fireEvent("onclick");
    }    
}

/***************************************************************************
* purpose:                                                  
* Return true if this is a trash browser.
****************************************************************************/
function garbage_browser(){

return (
           navigator.userAgent.toLowerCase().indexOf('msie 6') != -1 
        || navigator.userAgent.toLowerCase().indexOf('msie 7') != -1
       );
}

/**********************************************************
* Shows the menu a user must fill out.                        
**********************************************************/
function show_menu(element){

element.show();

element.animate({ opacity: '1' }, 'slow');
}

/**********************************************************
* Cancels a user's choice and hides the menu.                          
**********************************************************/
function hide_menu(element){

element.animate({ opacity: '0' }, 'slow', 'linear', element.hide());
}

/***********************************************************
* Fixes a getElementById and getElementByName bug in IE6.
************************************************************/
if (/msie/i.test (navigator.userAgent)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.attributes['id'].value == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++)
				{
					if(document.all[id][i].attributes['id'].value == id)
					{
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}


function setVal(objID, selIndex) {

var obj = document.getElementById(objID);

obj.selectedIndex = selIndex;
}


/***********************************************************
* Retrieve the size of the window and apply it to global 
* variables.
************************************************************/
function set_size() {

var myWidth = 0, myHeight = 0;

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }


window_width  = myWidth;
window_height = myHeight;
}

/***********************************************************
* Uses jquery to replace all title tags.
************************************************************/
function generate_tips(tip_id){

if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1)
  return false;

$(document).ready(function() {

//Only append if it doesn't already exist.
if(! document.getElementById(tip_id))
 $("body").append("<div id='"+tip_id+"'></div>");

 $("[title]").each(function() {

    $(this).hover(function(e) {
      $(this).mousemove(function(e) {

        set_size();

        if(parseInt(window_height) < parseInt(e.pageY) + 300)
          {
          var tipY = e.pageY + - 50;
          }
        else
          var tipY = e.pageY + 24;

        if(parseInt(window_width) < parseInt(e.pageX) + 200)
          { 
          var tipX = e.pageX - 250;
          }
        else
          var tipX = e.pageX + 24;

        $("#"+tip_id).css({'top': tipY, 'left': tipX});
      });

      if($(this).attr('title').length > 1)
        $("#"+tip_id).html($(this).attr('title'));

      $("#"+tip_id)
        .stop(true,true)
        .fadeIn("fast");
      $(this).attr("title", "");
    }, function() {

      $("#"+tip_id)
        .stop(true,true)
        .fadeOut("fast");

      $(this).attr('title', $("#"+tip_id).html());
    });
  });
});
}


/***********************************************************
* http://v2.easy-designs.net/articles/replaceSelect/
************************************************************/
function selectReplacement(obj) {

if(! obj.options)
  return false;

// append a class to the select
obj.style.display="none";

// create list for styling
var ul = document.createElement('ul');

ul.id = "dp_" + obj.id;

ul.className = 'selectReplacement';

var opts = obj.options;

for (var i=0; i<opts.length; i++) 
    {
    var selectedOpt;

    if (opts[i].selected)
        {
        selectedOpt = i;
        break;
        } 
    else 
        {
        selectedOpt = 0;
        }
    }

for (var i=0; i<opts.length; i++) 
    {
    var li = document.createElement('li');

    var txt = document.createTextNode(opts[i].text);

    li.appendChild(txt);

    li.selIndex = opts[i].index;

    li.selectID = obj.id;

    li.onclick = function() 
                         {
                         selectMe(this);
                         }

    if (i == selectedOpt) 
       {
       li.className = 'selected';

       li.onclick = function() 
                            {
                            this.parentNode.className += ' selectOpen';
                            this.onclick = function() {
                            selectMe(this);
                            }
       }
    }

    if (window.attachEvent)
       {
       li.onmouseover = function() {
       this.className += ' hover';
       }

    li.onmouseout = function() 
                            {
                            this.className = 
                            this.className.replace(new RegExp(" hover\\b"), '');
                            }
        }
      ul.appendChild(li);
      }

// add the input and the ul
obj.parentNode.appendChild(ul);
}

function selectMe(obj) {

var lis = obj.parentNode.getElementsByTagName('li');

for (var i=0; i<lis.length; i++) 
    {
    if (lis[i] != obj) 
       { 
       // not the selected list item
       lis[i].className='';

       lis[i].onclick = function() 
                                {
                                selectMe(this);
                                 }
       } 
    else 
       {
       setVal(obj.selectID, obj.selIndex);

       obj.className='selected';

       obj.parentNode.className = obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');

       obj.onclick = function() 
                             {
                             obj.parentNode.className += ' selectOpen';

                             this.onclick = function() {
                                                       selectMe(this);
                                                       }
                             }
        }
      }
}

/***************************************************************
* purpose:
* Fetch an AJAX XMLhttp object and return it.
***************************************************************/
function fetch_http(){

var http_object;

if (window.XMLHttpRequest)
   {
   // code for IE7+, Firefox, Chrome, Opera, Safari
   http_object = new XMLHttpRequest();
   }
else 
if (window.ActiveXObject)
   {
   // code for IE6, IE5
   http_object = new ActiveXObject("Microsoft.XMLHTTP");
   }
else
  return false;

return http_object;
}

/***************************************************************
* purpose:
* Used by suckerfish for IE compatibility.
***************************************************************/
sfHover = function() {
        if(! document.getElementById("top_menu"))
           return false;

	var sfEls = document.getElementById("top_menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/***************************************************************
* purpose:
* turn buttons red when hovered over(function red) and 
* blue when hovered away(function blue).
***************************************************************/
function red(number){

var button = document.getElementById("b"+number);

if(number < 10){
  number = 0 + string(number);
}

var image  = "images/menu/button" + number + "-r.png";

button.src = image;
}

function blue(number){

var button = document.getElementById("b"+number);

if(number < 10){
  number = 0 + string(number);
}

var image  = "images/menu/button" + number + ".png";

button.src = image;
}

/******************************************************************
* purpose:
* forward the staff member to the edit page.
*
******************************************************************/
function edit_post(post){

document.shop_form.selected_news.value = post;
document.shop_form.news_change.value   = "edit news";
document.shop_form.action="news_editor.php";
document.shop_form.submit();

return;
}

/****************************************************************
* purpose:
* delete a staff members post. 
*
*****************************************************************/
function delete_post(post){

document.shop_form.selected_news.value = post;
document.shop_form.news_change.value   = "delete news";
document.shop_form.action="news_editor.php";
document.shop_form.submit();

return;
}

/*****************************************************************
* purpose:                            
* receive and submit news chosen by   
* the user.                          
*****************************************************************/
function news_choice(news_selected){

document.shop_form.selected_news.value = news_selected;

document.shop_form.submit();
}

/*****************************************************************
* purpose:                                                
* receive and submit story news chosen by  
* the user.                                
*****************************************************************/
function story_news_choice(news_selected){

document.shop_form.selected_story_news.value = news_selected;

document.shop_form.submit();
}

/*****************************************************************
* purpose:                                                
* full credit for the following script goes to...
* john john at:
* http://www.planet-source-code.com
*
* my modification:
* 1. gets element by its identification number.
* 2. has a last else for any other browsers.
*****************************************************************/
function opacity_change(objectid, opacity){

imageobject = document.getElementById(objectid);

if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4)
   imageobject.filters.alpha.opacity=opacity
else
   imageobject.style.opacity=opacity/100
}

/*****************************************************************
* purpose:                                                
* Shifts input focus to chosen box.
*****************************************************************/
function turn_focus(id_box){

chat = document.getElementById(id_box);

if(! chat)
      return false;

chat.focus();

return true;
}

/*****************************************************************
* purpose:                                                
* Start a timer and set off when the number 
* of users online should display.
*****************************************************************/
function online_user_time(){

var ot;

var http_object = fetch_http();

http_object.onreadystatechange = function()
{
if(http_object.readyState==4)
  {
  switch(http_object.status)
        {
        case 200:
                 document.getElementById("online_users").innerHTML = http_object.responseText;
                 break;
        default:
                 document.getElementById("online_users").innerHTML = 0;
                 break;
        }
  }
}

http_object.open("GET", "/game_extensions/updater.php?choice=online_count", true);
http_object.send(null);

ot = setTimeout("online_user_time()", 200000);
}

/*****************************************************************
* purpose:                                                
* Detect if only worthless white space or nothing was entered.
*
* Author: Zoya
* http://www.codetoad.com/javascript/isempty.asp
*****************************************************************/
function empty_field(aTextField){

var re = /\s/g;

var str = aTextField.replace(re, "");

if (str.length == 0)
    return true;
else 
    return false;
} 

/**
 * @description setSelection - sets an selection for end input from start to end- index
 * $Id: range_selection.js 2 2009-03-17 19:25:27Z dinnerout $
 * @param node DOM-Node/String - DOM-Node or Id of Node to set selection in
 * @param startIndex Int - Startindex od selection
 * @param length Int - length of selection
 */

function setSelection( node, startIndex, length ){
var dNode = (typeof node == 'string')?$(node):node;

	dNode.focus();
	// IE
	if(document.selection){
		var range = document.selection.createRange();
		range.move('character',-10000000); // reset cursor position
		range.moveStart('character',startIndex);
		range.moveEnd('character',startIndex+length);
		range.select();
	}
	// Mozilla
	if(dNode.selectionStart){
		dNode.selectionStart = startIndex;
		dNode.selectionEnd = startIndex + length;
	}
}

/*****************************************************************
* purpose:                                                
* Return true if the enter key was pressed, false otherwise.
*****************************************************************/
function enter_key_pressed(e){

if(window.event)
   keyPressed = window.event.keyCode; // IE hack
else
   keyPressed = e.which; 

if(keyPressed && keyPressed == 13)
  return true;
else
  return false;
}

/*****************************************************************
* Assign information to be displayed.
*****************************************************************/
function display_info(message, this_id){

document.getElementById("output").innerHTML = message;
}

/*****************************************************************
* purpose:                                                
* hide an area
*****************************************************************/
function hide_area(area){

document.getElementById(area).style.visibility = "hidden";
}

/*****************************************************************
* purpose:                                                
* Display an area.
*****************************************************************/
function show_area(area){

document.getElementById(area).style.visibility = "visible";
}

/*****************************************************************
* Resize the journal.
*****************************************************************/
function resize_journal(id){

var element = document.getElementById(id);

if(! element.style.display || element.style.display == "none") 
        element.style.display = "list-item";
else
        element.style.display = "none";
}

/*****************************************************************
* Hide the taskbar from the user.
*****************************************************************/
function hide_taskbar(){

update_chat(5, 0);

document.getElementById('open').style.display            = "inline";
document.getElementById('info_display').style.display    = "none";

sh_taskbar();
}

/*****************************************************************
* Hide the taskbar from the user.
*****************************************************************/
function show_taskbar(){

document.getElementById('open').style.display         = "none";
document.getElementById('info_display').style.display = "table";

sh_taskbar();
}

/*****************************************************************
* Hide taskbar at server level.
*****************************************************************/
function sh_taskbar(){

var http_object = fetch_http();

http_object.open("GET", "game_extensions/updater.php?choice=alter_bar", true);
http_object.send(null);
}

/***************************************
* purpose:                           
* change user being viewed by admin
***************************************/
function user_view(){

var this_form = document.getElementById('us_option');

while(1){
var view_name = prompt("What is the name of the user you wish to view?");

if(! view_name)
             return false;

else if(view_name.length >= 3 && view_name.length <= 12)
            break;
else 
     alert("A user name must be between 3 and 12 characters.");
}

this_form.action="/player_status.php?user=" + view_name;
this_form.submit();
}


/*****************************************************************
* purpose:                                                
* Display an area.
*****************************************************************/
function output_element_html(element, output_id){   
                  
if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1 || navigator.userAgent.toLowerCase().indexOf('msie 7') != -1)   
   var text = element.options[element.selectedIndex].className;
else      
   var text = element.options[element.selectedIndex].getAttribute("class");

if(text.length < 1) 
    text = "No information is available.";

document.getElementById(output_id).innerHTML = text;
}

/*****************************************************************
* purpose:                                                
* Alerts user to a new message.
*****************************************************************/
function browser_alert(message, dis) {

if(dis == 1)
  {
  this_alert = document.getElementById("alerted");

  if(this_alert.value == true)
     return false;

  this_alert.value = 1;
  }

var oldTitle = document.title;
var msg = message;



var timeoutId = 
     setInterval(function(){ 
                           document.title = document.title == msg ? ' ' : msg;
                           }, 1000);

    document.onmousemove = function() {
        clearInterval(timeoutId);
        document.title = oldTitle;
        window.onmousemove = null;

        if(dis == 1)
          {
          this_alert.value = 0;
          }
    };

    document.onkeydown = function() {
        clearInterval(timeoutId);
        document.title = oldTitle;
        document.onkeydown = null;

        if(dis == 1)
          {
          this_alert.value = 0;
          }
    };
}

generate_tips('tip_1');

<!-- Project Wonderful Ad Box Loader -->
<!-- Put this after the <body> tag at the top of your page -->
   (function(){function pw_load(){
      if(arguments.callee.z)return;else arguments.callee.z=true;
      var d=document;var s=d.createElement('script');
      var x=d.getElementsByTagName('script')[0];
      s.type='text/javascript';s.async=true;
      s.src='//www.projectwonderful.com/pwa.js';
      x.parentNode.insertBefore(s,x);}
   if (window.attachEvent){
    window.attachEvent('DOMContentLoaded',pw_load);
    window.attachEvent('onload',pw_load);}
   else{
    window.addEventListener('DOMContentLoaded',pw_load,false);
    window.addEventListener('load',pw_load,false);}})();
<!-- End Project Wonderful Ad Box Loader -->
