function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return false;
}

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		
		// Internet Explorer
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			catch (e) {
		        alert("Your browser does not support AJAX!");
		        return false;
			}
		}
	}
	return xmlHttp;
	
}

function objId(element) { if (document.getElementById(element)) { return document.getElementById(element); } else { return null; } }
function createDiv(id) { temp = document.createElement('div'); temp.id = id; return temp;}

function addDOMLoadEvent(func) {
   if (!window.__load_events) {
      var init = function () {
          // quit if this function has already been called
          if (arguments.callee.done) return;
      
          // flag this function so we don't do the same thing twice
          arguments.callee.done = true;
      
          // kill the timer
          if (window.__load_timer) {
              clearInterval(window.__load_timer);
              window.__load_timer = null;
          }
          
          // execute each function in the stack in the order they were added
          for (var i=0;i < window.__load_events.length;i++) {
              window.__load_events[i]();
          }
          window.__load_events = null;
      };
   
      // for Mozilla/Opera9
      if (document.addEventListener) {
          document.addEventListener("DOMContentLoaded", init, false);
      }
      
      // for Internet Explorer
      /*@cc_on @*/
      /*@if (@_win32)
          document.write("<scr"+"ipt id=__ie_onload defer src=//0><\/scr"+"ipt>");
          var script = document.getElementById("__ie_onload");
          script.onreadystatechange = function() {
              if (this.readyState == "complete") {
                  init(); // call the onload handler
              }
          };
      /*@end @*/
      
      // for Safari
      if (/WebKit/i.test(navigator.userAgent)) { // sniff
          window.__load_timer = setInterval(function() {
              if (/loaded|complete/.test(document.readyState)) {
                  init(); // call the onload handler
              }
          }, 10);
      }
      
      // for other browsers
      window.onload = init;
      
      // create event function stack
      window.__load_events = [];
   }
   
   // add function to event stack
   window.__load_events.push(func);
}

var mouse_pos_y;
var mouse_pos_x;
function mouseY(e) {
	mouse_pos_y = 0;
	if (!e) {e = window.event;}
	if (e.pageY) 	{
		mouse_pos_y = e.pageY;
	}
	else if (e.clientY) 	{
		mouse_pos_y = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return mouse_pos_y;
}

function mouseX(e) {
	mouse_pos_x = 0;
	if (!e) {e= window.event;}
	if (e.pageX) 	{
		mouse_pos_x = e.pageX;
	}
	else if (e.clientX) 	{
		mouse_pos_x = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
	}
	return mouse_pos_x;
}

/* XML Traversal */
function get_firstchild(n)
{
	var x=n.firstChild;
	while (x.nodeType!=1)
	{
		x=x.nextSibling;
	}
	return x;
}

String.prototype.trim=function(){ return this.replace(/^\s*|\s*$/g,''); }

function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
	if(re.test(els[i].className))a.push(els[i]);
	return a;
}


