﻿
// ctl可以是控件对象或者是控件的ID
function ApexControl(ctl)
{
    if (ctl.id) {
        this.control = ctl;
    }
    else {
        this.control = document.getElementById(ctl);
    }
}

// 获取X坐标的值
ApexControl.prototype.getX = function()
{
	var obj = this.control;
	var curleft = 0;
	if(obj.offsetParent)
	{
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	}
	else if(obj.x)
	{
		curleft += obj.x;
	}
	
	return curleft;
}

// 获取Y坐标的值
ApexControl.prototype.getY = function()
{
	var obj = this.control;
	var curtop = 0;
	if(obj.offsetParent)
	{
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
			{
				break;
			}
			obj = obj.offsetParent;
		}
	}
	else if(obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

// 链接到另外的控件。
ApexControl.prototype.linkTo = function(ctl)
{
    if (ctl.id) {
        this.control = ctl;
    }
    else {
        this.control = document.getElementById(ctl);
    }
}