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;
}

/*need to set var orderfilter = 'chrono' and var group = '' as global variables 
before you initiate ajax functions then change them in your radio and 
select option form elements on the page. see Hot Issues
*/


function makepages(previ,nexti,startn,endn,totn){
	var span = document.createElement('span');
	var pagination = "<";
	if (previ){
		pagination += "<a href=\"#\" onclick=\"getList('"+previ+"','"+orderfilter+"','"+group+"'); return false;\">"+pr+"</a>";
	}
	pagination += " " + startn +"-"+ endn + ' ' + of + ' ' + totn+ " ";
	
	if (nexti) {
		pagination += "<a href=\"#\" onclick=\"getList('"+nexti+"','"+orderfilter+"','"+group+"'); return false;\">"+ne+"</a>";
	}
	pagination += ">";
	span.innerHTML = pagination;
	return span;
	
	
}

function replaceChildren(myParent,newnode){
	if (myParent.hasChildNodes()){
			myParent.replaceChild(newnode,myParent.childNodes.item(0));
		} else {
			myParent.appendChild(newnode);
	}
}

function checkvalueforempty(htmlcollection){
		if(htmlcollection.item(0).hasChildNodes()){
				var thetextnodevalue = htmlcollection.item(0).firstChild.nodeValue;
			} else {
				var thetextnodevalue = "";
		}
		return thetextnodevalue;
}

function escapeHTML(str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
};

function credits(submitter_Province,submitter_Id,submitter_Name,submitter_City,submit_Date,submit_Time){
	var p = document.createElement('p');
	var pText = subby+'<br /><span class="province_abbr">'+ checkvalueforempty(submitter_Province)+'</span> <a href="'+ urlp + '?id=' + checkvalueforempty(submitter_Id) +'">' +checkvalueforempty(submitter_Name)+'</a> ';
	submitter_City = checkvalueforempty(submitter_City);
	if(submitter_City != ''){
		pText = pText +fromm+' '+ submitter_City + ', ';
	}
	
	pText = pText + submit_Date.item(0).firstChild.nodeValue+ ' ' + submit_Time.item(0).firstChild.nodeValue;
	p.innerHTML = pText;
	return p;
}



