function getAbsoluteOffset(obj) {
	//returns collection [x,y]
	x=0;y=0;
	while (obj.offsetParent!=null) {
		x+=obj.offsetLeft;
		y+=obj.offsetTop;
		obj=obj.offsetParent;
	}
	var retVal = new Array();
	retVal['x']=x;retVal['y']=y;
	return retVal;
}
function getYpos(obj) {
	var pos = getAbsoluteOffset(obj);
	return pos['y'];
}
function getXpos(obj) {
	var pos = getAbsoluteOffset(obj);
	return pos['x'];
}
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 ResizeDivScroll(){

		var divScroll = document.getElementById('divScroll');
		var divPost = document.getElementById('divPostScroll');
		var divPre = document.getElementById('divPreScroll');
		var divFooter = document.getElementById('divFooter');
		var pageDiv = document.getElementById("pageDiv");
		try {
			if (divScroll != null && pageDiv != null && divPost != null && divFooter != null) {
				var h = getViewportHeight() - findPosY(divScroll) - divPost.offsetHeight - divFooter.offsetHeight    ;
				var w = getViewportWidth() - findPosX(divScroll);
				//alert(findPosY(divScroll));
				divScroll.style.height = h + "px";
				divScroll.style.setExpression("width", w );
			}else alert('no');
		} catch (e) {
			//alert(e.message);
			//alert('error in resizing div');
		}
		
}
function fnGetHeight(obj){
    alert('x=' + findPosY(obj));
    var x = getViewportHeight() - findPosY(obj);
    return x;
}
function fnNewEntry(entry1,entry2){
	if(entry1 != "") return entry1;
	return entry2;
}
function setBackground(obj,color){
	if(obj==null) return;
	obj.style.backgroundColor = color;
}
function SelectValueInDropDown(value,ddObj){
    if(ddObj != null){
        for(i=0;i<ddObj.options.length;i++){
            if(ddObj.options[i].value == value){
             ddObj.options[i].selected = true;
             return;
            }
        }
        ddObj.selectedIndex = 0;
    }
}

//Progressive Type Select Box Code
// Must be presorted alphabetical list
// <select onkeydown="return selectKey();">
var keyBufferTimeOut = null;

function selectKey() {

	var keyCode=event.keyCode;
	if (keyCode<65 || keyCode>122) {return true;}
	if (keyCode>90 && keyCode<97) {return true;}
	clearTimeout(keyBufferTimeOut);
		
	var key=String.fromCharCode(keyCode).toLowerCase();
	keyBuffer+=key;
	
	event.srcElement.selectedIndex=findValPos(event.srcElement,keyBuffer,0,event.srcElement.options.length-1);
	
	// alert( "selectKey buffer: " + keyBuffer + ", keyCode: " + keyCode ) ;
	 
	keyBufferTimeOut=window.setTimeout("keyBuffer='';",4000);
	return false;
}
function findValPos(obj, val,startPos,endPos) {

	midPos=Math.ceil(startPos+(endPos-startPos)/2);
	if ((startPos==endPos)||(startPos==midPos)||(midPos==endPos)) {
	   alert('what');
		return midPos;
	}
	
	midStr =obj.options[midPos].innerHTML.toLowerCase().slice(0,val.length+10);
			
	if (!confirm((val+'          ') + '=' + midStr + '\nstart=' + startPos + ', midPos=' + midPos + ', endPos=' + endPos)) return 0;
	window.status=(val+'          ') + '=' + midStr + '\nstart=' + startPos + ', midPos=' + midPos + ', endPos=' + endPos;

	if ((val+'          ')<midStr) {
		return findValPos(obj,val,startPos,midPos);
	} else if ((val+'          ')>midStr) {
		return findValPos(obj,val,midPos,endPos);
	} else {
		return midPos;
	}
}	

function fnMatchWidths(tblHeadID,tblBodyID){
    if(document.getElementById(tblHeadID) == null)return null;
    if(document.getElementById(tblBodyID) == null)return null;
    var tblHead = document.getElementById(tblHeadID);
    var tblBody = document.getElementById(tblBodyID);
    var lastRow = tblHead.rows.length - 1;
    if(tblBody.rows.length == 0) return null;
    for(var iInd = 0;iInd < tblHead.rows[lastRow].cells.length;iInd++){
      var cellObj = tblHead.rows[lastRow].cells[iInd];
      if(cellObj.style.width != ""){
        if(cellObj==null)return;
        if(tblBody.rows[0].cells[iInd]==null) break;
        tblBody.rows[0].cells[iInd].style.width = cellObj.style.width;
      }
    } 
  }





