


//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------

function Browser() {

	var ua, s, i;

	this.isIE    = false;  // Internet Explorer
	this.isOP    = false;  // Opera
	this.isNS    = false;  // Netscape
	this.version = null;
    
	ua = navigator.userAgent;

	s = "Opera";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isOP = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	// Treat any other "Gecko" browser as Netscape 6.1.

	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}

	s = "MSIE";
	if ((i = ua.indexOf(s))) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	// DMD TESTING
    this.versionInfo = s + " v." + this.version;
};


// Go ahead and instantiate the browser object.
var browser = new Browser();

// Determine whether this is an older browser that might not support all functionality.
var isOlderBrowser;

// dmd 071409 - changing to < v.6
// dmd 052009 - modified...
if ((browser.isIE && parseInt(browser.version) < 6)) { // || (browser.isNS && parseInt(browser.version) < 7)) {
    isOlderBrowser = true;
} else {
    isOlderBrowser = false;
}


// Display an error and return false.
function global_displayError(message, functionName, objectName) {
    
    var errorText = "";
    
    if (message == null) {message = "(unknown)";}
    if (functionName == null) {functionName = "";}
    if (objectName == null) {objectName = "";}
    
    errorText = "Error in ";
    if (objectName != "") {errorText += objectName;}
    if (functionName != "") {errorText += "." + functionName + "()";}
    errorText += " - " + message + "!";
    
    alert(errorText);
    
    return false;
};


// Get the X coordinate of the mouse's current location.
function getMouseX(e) {
  
    var mouseX;
    
    // Make sure the correct event is used.
    if (e == null) {
        e = window.event;
    }

    if (browser.isIE == true) {
        mouseX = e.clientX + document.body.scrollLeft;
    } else {
        mouseX = e.pageX;
    }
 
    // Catch possible negative values (NS4?).
    if (mouseX < 0){mouseX = 0}; 
 
    return mouseX;
};


// Get the Y coordinate of the mouse's current location.
function getMouseY(e) {

    var mouseY;
    
    // Make sure the correct event is used.
    if (e == null) {e = window.event;}

    if (browser.isIE == true) {
        mouseY = e.clientY + document.body.scrollTop;
    } else {
        mouseY = e.pageY;
    }
 
    // Catch possible negative values (NS4?).
    if (mouseY < 0){mouseY = 0};  
 
    return mouseY;
};


// Get the name of the current page.
function getPageName() {

    var fullPath; 
    var pageName; 
    
    fullPath = window.location.pathname;
    pageName = fullPath.substring(fullPath.lastIndexOf('/') + 1);
    
    return pageName;
};


// Get the id of the Element that initiated the event.
function getSrcElementID(e) {
    
    var webControl;
    
	// Make sure the correct event is used.
    if (e == null) {e = window.event;}
    
	if (e.target) { webControl = e.target; }
	else if (e.srcElement) { webControl = e.srcElement; }
	
	if (webControl.nodeType == 3) {
	    // Avoid Safari bug
		webControl = webControl.parentNode;
	}

    return webControl.getAttribute("id");
};


// Is this value null, an empty string, or zero?
function isEmpty(value) {
    if (value == null) {
        return true;
    } else if (typeof(value) == "string" && value == "") {
        return true;
    } else if (typeof(value) == "number" && value == 0) {
        return true;
    } else {
        return false;
    }
};

// Generate a random number having a specific upper limit.
function getRandomNumber(upperLimit) {
    if (typeof(upperLimit) != "number") {alert("not a number!");}
    return Math.floor(Math.random()*upperLimit);
}


// From http://www.quirksmode.org/js/xmlhttp.html.
var XMLHttpFactories = [
    function () {return new XMLHttpRequest()},
    function () {return new ActiveXObject("Msxml2.XMLHTTP")},
    function () {return new ActiveXObject("Msxml3.XMLHTTP")},
    function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];