//created by Rob C

//detects browser capabilities for CSS movements, etc
function CssUtils_setLeft(obj, newLeft) {
	if (obj.style.pixelLeft) {
		obj.style.pixelLeft = newLeft;
		return 0;
	} else if (obj.style.left) {
		if (obj.style.left.indexOf("px") > -1) {
			obj.style.left = newLeft + "px";
		} else {
			obj.style.left = newLeft;
		}
		return 1;
	} else {
		return -1;
	}
}

function CssUtils_getLeft(obj) {
	if (obj.style.pixelLeft) {
		return obj.style.pixelLeft;
	} else if (obj.style.left) {
		if (obj.style.left.indexOf("px") > -1) {
			return parseInt(obj.style.left.substring(0,obj.style.left.length - 2));
		} else {
			return obj.style.left;
		}
	} else {
		return -1;
	}
}

function CssUtils_setTop(obj, newTop) {
	if (obj.style.pixelTop) {
		obj.style.pixelTop = newTop;
		return 0;
	} else if (obj.style.top) {
		if (obj.style.top.indexOf("px") > -1) {
			obj.style.top = newTop + "px";
		} else {
			obj.style.top = newTop;
		}
		return 1;
	} else {
		return -1;
	}
}

function CssUtils_getTop(obj) {
	if (obj.style) {
		if (obj.style.pixelTop) {
			return obj.style.pixelTop;
		} else if (obj.style.top) {
			if (obj.style.top.indexOf("px") > -1) {
				return parseInt(obj.style.top.substring(0,obj.style.top.length - 2));
			} else {
				return obj.style.top;
			}
		} else {
			return -1;
		}
	} else {
		return -1;
	}
}

function CssUtils_showDiv(divObj) {
	if (typeof(divObj.style.visibility) == "string") {
		divObj.style.visibility = "visible";
		return 0;
	} else {
alert("fail");
		return -1;
	}
}
//todo: function that sets visibility to inherit

function CssUtils_hideDiv(divObj) {
	if (typeof(divObj.style.visibility) == "string") {
		divObj.style.visibility = "hidden";
		return 0;
	} else {
		return -1;
	}
}


function CssUtils_getWidthNum(obj) {
	if (obj.style.pixelWidth) {
		return obj.style.pixelWidth;
	} else if (obj.style.width){
		return parseFloat(obj.style.width);
	} else if (obj.offsetWidth) {
		return obj.offsetWidth;
	} else if (document.defaultView) {
		return document.defaultView.getComputedStyle(obj,"").getPropertyValue("width");
	} else {
		return -1;
	}
}

function CssUtils_getHeightNum(obj) {
	if (obj.style.pixelHeight) {
		return obj.style.pixelHeight;
	} else if (obj.style.height){
		return parseFloat(obj.style.height);
	} else if (obj.offsetHeight) {
		return obj.offsetHeight;
	} else if (document.defaultView) {
		return document.defaultView.getComputedStyle(obj,"").getPropertyValue("height");
	} else {
		return -1;
	}
}

function CssUtils_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 CssUtils_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 CssUtils_getIframeContent(frameObjName) {
//expects there to be only one frame by this name
	var dataFrameObjArray = document.getElementsByName("frameObjName");
	var frameObj = frameObjArray[0];

	if (frameObj.contentWindow) {
		return frameObj.contentWindow;
	} else if (frameObj.contentDocument.defaultView) {
		return frameObj.contentDocument.defaultView;
	} else if (frameObj.contentDocument) {
		return frameObj.contentDocument;
	} else {
		return -1;
	}
}

function CssUtils_getDocHeight() {
	if (document.body) {	
		if (document.body.scrollHeight) {
			return document.body.scrollHeight;
		} else if (document.body.clientHeight) {
			return document.body.clientHeight;
		} else return - 1;
	} else return -1;
}
