﻿/* Element Retrieval Methods
===================================================================================== */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function getChild(startParent) {
  EndChild = startParent.firstChild ;
  while(EndChild.nodeType != 1){
    EndChild = EndChild.nextSibling ;
  }
  return EndChild;
}

/* Flash Border Removal
===================================================================================== */
function initFlashBorders() {
    if (document.body.outerHTML && (document.getElementsByTagName('object')).length) {
		var objs = document.getElementsByTagName('object') ;
		var i = objs.length - 1 ;
		do {
			if (objs[i].getAttribute('type') == 'application/x-shockwave-flash') {
				var o = objs[i] ;
				var h = o.outerHTML ;
				var params = '' ;
				var j = o.childNodes.length - 1 ;
				do {
					var p = o.childNodes[j] ;
					if (p.tagName == "PARAM") params += p.outerHTML ;
				} while (j--) ;
				var tag = h.split(">")[0] + ">" ;
				o.outerHTML = tag + params + o.innerHTML + " </object>" ;
			}
		} while (i--)
	}
}

/* Form Element Methods
===================================================================================== */
function initClearInputs() {
  inputs = document.getElementsByTagName('input') ;
  for (i = 0; i < inputs.length; i++) {
    if ((inputs[i].getAttribute('value')) && (inputs[i].getAttribute('type') == 'text')) {
            inputs[i].setAttribute('default',inputs[i].getAttribute('value'));
            inputs[i].onfocus = function() {
				if (this.value == this.getAttribute('default')) {
					this.value = '' ;
				}
			}
			inputs[i].onblur = function() {
				if (this.value == '') {
					this.value = this.getAttribute('default');
				}
			}
    }
  }
}

/* The DOM Loaded Event Queue
===================================================================================== */
var _loadQueue = new Array();

function addLoadEvent(func){
    _loadQueue.push(func);
}

/* The DOM Loaded Script */

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", processEventQueue, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    if (window.location.protocol != 'https:')
    {
        document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
        var script = document.getElementById("__ie_onload");
        script.onreadystatechange = function() {
            if (this.readyState == "complete") {
                processEventQueue(); // call the onload handler
            }
        };
    }
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            processEventQueue(); // call the onload handler
        }
    }, 10)
}

/* for other browsers */
window.onload = processEventQueue;

/* dom loaded call */
function processEventQueue() {
    // 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 (_timer) clearInterval(_timer);

    // process the event queue
    for (i = 0; i < _loadQueue.length; i++){
       setTimeout(_loadQueue[i],0);
    }
    
    // clear the event queue
    _loadQueue = new Array();
}
