/*
	Current File: inc_browser.js
	Description: DHTML function mostly for DIV operations
	Created By: Eric Schultz
	Date: 1/15/2006
*/

function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

function clone(myObj) {
	if(typeof(myObj) != 'object') return myObj;
	if(myObj == null) return myObj;

	var myNewObj = new Array();

	for(var i in myObj)
		myNewObj[i] = clone(myObj[i]);

	return myNewObj;
}


// check for valid numeric strings
function isnumeric(strString) {
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}

	return blnResult;
}


function getMouseX(e) {
    if(navigator.userAgent.search("Opera(\ |\/)6") != -1 )   //o6
        return e.clientX;
    else if(document.all)               //e4,e5,e6
        return document.body.scrollLeft+event.clientX;
    else if(document.layers || document.getElementById)    //n4,n6,n7,m1,o7,s1
        return e.pageX;
}

function getMouseY(e) {
    if(navigator.userAgent.search("Opera(\ |\/)6") != -1 )   //o6
        return e.clientY;
    else if(document.all)               //e4,e5,e6
        return document.body.scrollTop+event.clientY;
    else if(document.layers || document.getElementById)    //n4,n6,n7,m1,o7,s1
        return e.pageY;
}

function statusBar(text){
	window.status=text;
	return true;
}

function getHTMLCode(doc){
	if (isIE || isNS6 || isFF) {
		return doc.innerHTML;
	}
}

function trimPrecision(number, digits) {
	pow = 1;
	for (j = 0; j < digits; j++) pow *= 10;

	return (parseInt(number * pow))/pow;
}

function GetCurrentTime() {
	var my_current_timestamp;
	my_current_timestamp = new Date();
	return my_current_timestamp.getTime();
}

function detectRightClick(e){

    var rightclick = false;

    if(!e) var e=window.event;

    if(e.which){
          rightclick = (e.which==3);
    } else if(e.button){
          rightclick = (e.button==2);
    }

    return rightclick;
}

function getFiringElement(e){
	if (isIE) {
		return event.srcElement;
	} else {
		return e.target;
	}
}

function getDIV(name, withStyle){
	if(withStyle) {
		return document.getElementById(name).style;
	} else {
		return document.getElementById(name);
	}
}

function getObj(strName) {
	return document.getElementsByName(strName);
}


function updateContent(div, content){
	var layer = getDIV(div, false);

	if (isIE) {
		var str = "layer.innerHTML = '" + content.replace(/\\'/g, "\'").replace(/\'/g, "\\\'").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "") + "';";
		eval(str);
	} else if (isNS6) {
		hideLayer(div);
		layer.innerHTML = content;
		showLayer(div);
	} else {
		layer.innerHTML = content;
	}
}

function appendContent(div, content){
	var layer = getDIV(div, false);

	if (isIE) {
		var str = "layer.innerHTML += '" + content.replace(/\\'/g, "\'").replace(/\'/g, "\\\'").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "") + "';";
		eval(str);
	} else if (isNS6) {
		hideLayer(div);
		layer.innerHTML += content;
		showLayer(div);
	} else {
		layer.innerHTML += content;
	}
}

function appendContentASC(div, content){
	var layer = getDIV(div, false);

	if (isIE) {
		var str = "layer.innerHTML = '" + content.replace(/\\'/g, "\'").replace(/\'/g, "\\\'").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "") + "<br>" + layer.innerHTML + "';";
		eval(str);
	} else if (isNS6) {
		hideLayer(div);
		layer.innerHTML = content + "<br>" + layer.innerHTML;
		showLayer(div);
	} else {
		layer.innerHTML = content + "<br>" + layer.innerHTML;
	}
}

// toggle layer to invisible
function hideLayer(name) {
	var layer = getDIV(name, true);
	if (isIE) if (!(document.getElementById(name).filters[0] == undefined)) document.getElementById(name).filters[0].apply();

	layer.visibility = "hidden";

	if (isIE) if (!(document.getElementById(name).filters[0] == undefined)) document.getElementById(name).filters[0].play();
}

// toggle layer to visible
function showLayer(name) {
	var layer = getDIV(name, true);
	if (isIE) if (!(document.getElementById(name).filters[0] == undefined)) document.getElementById(name).filters[0].apply();

	layer.visibility = "visible";

	if (isIE) if (!(document.getElementById(name).filters[0] == undefined)) document.getElementById(name).filters[0].play();
}

//return if layer is visiable
function isLayerVisiable(name) {
	var layer = getDIV(name, true);
	return (layer.visibility == "visible");
}

// move layer to x,y
function moveLayer(name, x, y) {
	var layer = getDIV(name, true);
	if(x!=null) layer.left = parseInt(x)+"px";
	if(y!=null) layer.top  = parseInt(y)+"px";
}

// resize layer to width,height
function resizeLayer(name, width, height) {
	var layer = getDIV(name, true);
	if(width!=null) layer.width = parseInt(width)+"px";
	if(height!=null) layer.height = parseInt(height)+"px";
}

// get document width
function getWidth(thisobject) {
	var thisWidth = thisobject.innerWidth;
	if (thisWidth == null) thisWidth = thisobject.clientWidth;
	if (thisWidth == null) thisWidth = thisobject.documentElement.clientWidth;
	thisWidth = parseInt(thisWidth);
	return thisWidth;
}

//get document height
function getHeight(thisobject) {
	var thisHeight = thisobject.innerHeight;
	if (thisHeight == null) thisHeight = thisobject.clientHeight;
	if (thisHeight == null) thisHeight = thisobject.documentElement.clientHeight;
	thisHeight = parseInt(thisHeight);
	return thisHeight;
}

//Get Browser Window Width
function getWindowWidth(){
	if (isIE) {
		return document.documentElement.clientWidth;
	} else {
		return window.innerWidth;
	}
}

//Get Browser Window Height
function getWindowHeight(){
	if (isIE) {
		return document.documentElement.clientHeight;
	} else {
		return window.innerHeight;
	}
}

//get DIVs Inner width (using getWidth())
function getDIVWidth(thisDIV) {
	return(getWidth(getDIV(thisDIV, false)));
}

//get DIVs Inner height (using getHeight())
function getDIVHeight(thisDIV) {
	return(getHeight(getDIV(thisDIV, false)));
}

//get DIVs Left Position
function getDIVLeft(thisDIV) {
	return(parseInt(getDIV(thisDIV, true).left));
}

//get DIVs Top Position
function getDIVTop(thisDIV) {
	return(parseInt(getDIV(thisDIV, true).top));
}

//get DIVs Right Position
function getDIVRight(thisDIV) {
	return(parseInt(getDIV(thisDIV, true).left) + getDIVWidth(thisDIV));
}

//get DIVs Bottom Position
function getDIVBottom(thisDIV) {
	return(parseInt(getDIV(thisDIV, true).top) + getDIVHeight(thisDIV));
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function setOpacity(obj, opacity) {
	opacity = (opacity >= 100)?99.999:opacity;

	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";

	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}