function $(objId)
{
	return document.getElementById(objId);	
}

function P$(objId)
{
	var obj;
	if(parent)
	{
		obj=parent.document.getElementById(objId);
	}
	else
		obj=null;
	return obj;
}

// 注册事件
function AddEventHandler(oTarget,sEventType,fHandler)
{
	if(oTarget.addEventListener)
	{
		//alert('eDo1');
		oTarget.addEventListener(sEventType,fHandler,false);
	}
	else if(oTarget.attachEvent)
	{
		//alert('eDo2');
		oTarget.attachEvent('on'+sEventType,fHandler);
	}
	else
	{
		//alert('eDo3');
		oTarget['on'+sEventType]=fHandler;
	}
}

function RadioSwitchDo(elem,display,container)
{
	var ctn=document.getElementById(container);
	if(!ctn)
	{
		alert('元素'+container+'不存在');
		return;
	}
	//alert(ctn.style.display);
	if(elem.checked)
		ctn.style.display=display?"":"none";
}

function CheckBoxSwitchDo(elem,container)
{
	var ctn=document.getElementById(container);
	if(!ctn)
	{
		alert('元素'+container+'不存在');
		return;
	}
	//alert(ctn.style.display);
	ctn.style.display=elem.checked?"":"none";
}

function ImageResize(img,width,height)
{
	//alert('in');
	var oW,oH;
	oW=img.width;
	oH=img.height;
	if(img.width>width)
	{
		img.width=width;
		//alert('img.width='+img.width+'\nimg.height='+img.height);
		img.height=oH*width/oW;
		//alert('height='+img.height);
		oW=img.width;
		oH=img.height;
	}
	if(img.height>height)
	{
		img.height=height;
		img.width=oW*height/oH;
	}
//	img.width=destW;
//	img.height=destH;
}

function SelectAll(obj,name)
{
	var arrCtl=document.getElementsByName(name);
	for(var i=0;i<arrCtl.length;i++)
		arrCtl[i].checked=obj.checked;
}

function DeleteConfirm(msg)
{
	if(!msg)
		msg='是否确认删除?';
	if(window.confirm(msg))
		return true;
	else 
		return false;
}



//取元素相对于body的坐标
function ZB() 
{
 this.left=0,
 this.top=0,
 this.width=0,
 this.height=0
 };
 
function getCurrentStyle(o,style)
{
   var number=parseInt(o.currentStyle[style]);
   return isNaN(number)?0:number;
}
function getComputedStyle(o,style)
{
   return parseInt(document.defaultView.getComputedStyle(o,null).getPropertyValue(style));
}
 
function GetZB(obj)
{
	var o=obj;
	var oLTWH=new ZB();
	oLTWH.width=o.offsetWidth;
	oLTWH.height=o.offsetHeight;
	oLTWH.left=o.offsetLeft;
	oLTWH.top=o.offsetTop;
	while(true)
    {
       o=o.offsetParent;
       if(o==(document.body&&null))break;
       oLTWH.left+=o.offsetLeft;
       oLTWH.top+=o.offsetTop;
       /*
       if(document.all)
       {
           oLTWH.left+=getCurrentStyle(o,"borderLeftWidth");
           oLTWH.top+=getCurrentStyle(o,"borderTopWidth");
       }
       else
       {
		oLTWH.left+=getComputedStyle(o,"border-left-width");
        oLTWH.top+=getComputedStyle(o,"border-top-width");
       }
       */
    }
    return oLTWH;
}

function IsSingleByteChar(chr)
{
	var code=chr.charCodeAt(0);
	if(code<256)
		return true;
	return false;
}
function GetStrLen(str)
{
	var len=0;
	for(var i=0;i<str.length;i++)
		if(IsSingleByteChar(str.charAt(i)))
			len++;
		else
			len=len+2;
	return len;
}
