    function $id(id) {
      return document.getElementById(id);
    }
    function trim(str) {
      if(str) {
        return str.replace(/^\s+|\s+$/g, '');
      }
      return '';
    }

    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          if (oldonload) {
            oldonload();
          }
          func();
        }
      }
    }

    var showingUpcoming = 0;
    function showUpcoming(id) {
      if(showingUpcoming != id) {
        var oldDiv = $id("upcoming_"+showingUpcoming);
        var newDiv = $id("upcoming_"+id);
        var oldImg = $id("upcomingImg_"+showingUpcoming);
        var newImg = $id("upcomingImg_"+id);
        oldDiv.style.display = "none";
        oldImg.style.background = "none";
        newDiv.style.display = "block";
        newImg.style.background = "#FFF url(http://palgn.com.au/images08/upcoming_arrow.jpg) no-repeat bottom center";
        showingUpcoming = id;
      }
    }

  function getNow() {
    var now = new Date();
    return now.getTime();
  }

  var hasTracked = false;
  function trackPageView(url) {
    if(pageTracker) {
      if(!hasTracked) {
        pageTracker._setAllowLinker = true;
        pageTracker._trackTrans();
        hasTracked = true;
      }
      pageTracker._trackPageview(url);
    }
  }


    var docHead = null;
    function quickJSON(url) {
      if(!docHead) docHead = document.getElementsByTagName('head')[0];

      var uId = "s_"+getNow();
      var oScript = document.createElement("script");
      oScript.type = 'text/javascript';
      oScript.src = url+'&nc='+uId;
      oScript.charset = 'windows-1252';
      oScript.id = uId;
      docHead.appendChild(oScript);

      trackPageView(url);
    }

    var movePageTimer = null;
    var mainDiv = null;
    var footerDiv = null;
    var footer_spacerDiv = null;
    function movePage() {
      if(movePageTimer) window.clearTimeout(movePageTimer);

      var diff = Math.floor((pageTo - pagePos)/3);
      if(diff == 0) diff = 1;
      pagePos = pagePos + diff;

      if(!mainDiv) mainDiv = $id("main");
      mainDiv.style.top = pagePos+"px";
      if(!footerDiv) footerDiv = $id("footerDiv");
      footerDiv.style.top = (-1*pagePos)+"px";
      if(!footer_spacerDiv) footer_spacerDiv = $id("footer_spacer");
      footer_spacerDiv.style.height = (65+pagePos)+"px";

      if(pageTo != pagePos) {
        movePageTimer = window.setTimeout(movePage, 10);
      }
    }


    function searchFocus(input) {
      if(input.value == "Search PALGN...")
        input.value = "";
    }

    function searchBlur(input) {
      if(input.value == "")
        input.value = "Search PALGN...";
    }

    function IEOnlyStyle(elm, styleName) {
      // Do nothing
    }

    // For list.tpl
    function showAdv(checkbox) {
      var simple_control = $id("simple_control");
      var adv_control = $id("adv_control");
      if(checkbox.checked) {
        simple_control.style.display = "none";
        adv_control.style.display = "block";
      }
      else {
        simple_control.style.display = "block";
        adv_control.style.display = "none";
      }
    }

    // Here we almost use XMLHTTP, crazy I know!
    function doRealAJAX(url, toSend, errorHandler) {
      var req = null;
      if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
      }
      else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }

      if(req) {
        req.onreadystatechange = function() {
          if(req.readyState == 4) {
            if(req.status == 200) {
              eval(req.responseText);
            }
            else {
              errorHandler('There was an error talking to the server. Please try again.');
            }
          }
        }
        req.open("POST", url, true);
        req.setRequestHeader("content-type","application/x-www-form-urlencoded");
        req.send(toSend);
      }
      else {
        errorHandler('Sorry, your browser does not support AJAX.');
      }
    }

    function doLogin() {
      loginShown = !loginShown;
      var username = $id("username");
      var menu_right_0 = $id("menu_right_0");
      var menu_right_sep_0 = $id("menu_right_sep_0");
      if(loginShown) {
        quickJSON(toggleMyPALGN+'&show_my_palgn=1');
        menu_right_0.style.visibility = "hidden";
        menu_right_sep_0.style.visibility = "hidden";
        pageTo = 0;
        if(!isLoggedIn) {
          username.focus();
        }
      }
      else {
        quickJSON(toggleMyPALGN+'&show_my_palgn=0');
        menu_right_0.style.visibility = "visible";
        menu_right_sep_0.style.visibility = "visible";
        pageTo = -25;
      }
      movePage();
      return false;
    }

function setCheckboxes(theForm, elementName, isChecked)
{
	var chkboxes = document.forms[theForm].elements[elementName];
	var count = chkboxes.length;

	if (count)
	{
	for (var i = 0; i < count; i++)
		{
		chkboxes[i].checked = isChecked;
	}
	}
	else
	{
	chkboxes.checked = isChecked;
	}

	return true;
}

	function ImageLoadFailed(ele) {
	 ele.style.display = "none";
	}

// Corporate demands this be placed on the site ASAP!
var lastposx = 0;
var lastposy = 0;
function placeImage(code) {
	var div = document.createElement('div');
	div.style.position = 'fixed';
	
	var numType = 'px';
	var heightRandom = Math.random()*.60;
	var windowHeight = 768;
	var windowWidth = 1024;
	var height = 0;
	var width = 0;
	var de = document.documentElement;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
		windowWidth = window.innerWidth;
	} else if(de && de.clientHeight) {
		windowHeight = de.clientHeight;
		windowWidth = de.clientWidth;
	} else {
		numType = '%';
		height = Math.round( height*100 )+'%';
	}
	div.style.zIndex = 100;
	div.style.outline = 0;

	if( numType=='px' ) div.style.top = Math.round( windowHeight*heightRandom ) + numType;
	else div.style.top = height;
	div.style.left = Math.round( Math.random()*80 ) + '%';

	document.body.appendChild(div);
	div.innerHTML = code;
}

if ( window.addEventListener ) {
  var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
  var konamiDone = false;
  window.addEventListener("keydown", function(e){
    kkeys.push( e.keyCode );
    if ( kkeys.toString().indexOf( konami ) >= 0 ) {
      if(!konamiDone) {
        konamiDone = true;
        quickJSON("http://palgn.com.au/randomPic.php?r=1");
        window.addEventListener("click", function(e){
        	lastposx = 0;
        	lastposy = 0;
        	if (!e) var e = window.event;
        	if (e.pageX || e.pageY) 	{
        		lastposx = e.pageX;
        		lastposy = e.pageY;
        	}
        	else if (e.clientX || e.clientY) 	{
        		lastposx = e.clientX + document.body.scrollLeft
        			+ document.documentElement.scrollLeft;
        		lastposy = e.clientY + document.body.scrollTop
        			+ document.documentElement.scrollTop;
        	}
        	quickJSON("http://palgn.com.au/randomPic.php?r=1");
        }, true);
      }
    }
  }, true);
}

