function findObject(n, d) 
{
  var p,i,x;  
  if(!d) d=document; 
  
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d = parent.frames[n.substring(p+1)].document; 
	n = n.substring(0,p);
  }
  
  if(!(x=d[n])&&d.all) 
  	x = d.all[n]; 
  
  for (i=0;!x&&i<d.forms.length;i++) 
  	x = d.forms[i][n];
  
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
  	x = MM_findObj(n,d.layers[i].document);
  
  if(!x && d.getElementById) 
  	x = d.getElementById(n); 
  
  return x;
}

function findPosX(obj) 
{
    var curleft = 0;

    if (obj.offsetParent) {
        while (obj.offsetParent) {

            //alert(obj.style.left);
        
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x) {
        curleft += obj.x;
    }

    // If it is IE plus body margin
    if (document.all) {
        curleft += parseInt(document.body.currentStyle.marginLeft.replace(/px/, "").replace(/PX/, ""));
    }
    else {

    }
    
    //alert(curleft);
        
    return curleft;
}

function findPosY(obj) 
{
    var curtop = 0;
    // If it is IE plus body margin
    if (document.all)
        curtop = parseInt(document.body.currentStyle.marginTop.replace(/px/, "").replace(/PX/, ""));

    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y) {
        curtop += obj.y;
    }
        
    return curtop;
}

// Functions for tooltip control
function showTip(id, inputId, visibility) 
{
    var toolTipPanel = findObject(id);
    var inputField = findObject(inputId);

    //positioning
    toolTipPanel.style.position = 'absolute';
    var width = inputField.style.width.toString() != "" ? inputField.style.width.toString() : inputField.clientWidth.toString();
    var height = inputField.style.height.toString() != "" ? inputField.style.height.toString() : inputField.clientHeight.toString();

    var posX = findPosX(inputField);
    var posY = findPosY(inputField);

    posX += parseInt(width.replace(/px/, "").replace(/PX/, "")) - 27;
    posX = posX + 'px';

    posY += parseInt(height.replace(/px/, "").replace(/PX/, "")) + 12;
    posY = posY + 'px';

    toolTipPanel.style.left = posX;
    toolTipPanel.style.top = posY;

    // show/hide tool tip layer
    if (visibility == 'h') 
    {
        toolTipPanel.style.display = 'none';
    }
    else 
    {
        toolTipPanel.style.display = 'block';
    }
}

function restoreValue(object, initialValue, isFocus)
{
	var tb = object;
		
	if(isFocus)
	{
		if(tb.value == initialValue)
		{
				tb.value = '';
		}
	}
	else
	{
		if(tb.value == '')
		{
			tb.value = initialValue;
		}
	}
}