function $(_sId)
{return document.getElementById(_sId);}
 

function top$(_sId)
{return top.$(_sId);}

  
function moveDiv(event, _sId)
{
	var oObj = top$(_sId);	

	oEvent = window.event ? window.event : event;
 
	
	var scrollTop = top.document.body.scrollTop;
	var scrollLeft = top.document.body.scrollLeft;
	
	var startX = oEvent.clientX + parseInt(oObj.style.left,10);// + scrollLeft;
	var startY = oEvent.clientY + parseInt(oObj.style.top,10);// + scrollTop;
 
 	var dragData = {x : startX, y : startY};
 
 	 
 	oObj.setCapture ? oObj.setCapture() : function(){};

	oObj.onmousemove = mousemove;
	oObj.onmouseup = mouseup;
 
	function mousemove()
	{
		var oEvent = window.event ? window.event : event;
 
 
 
					
		var scrollTop = top.document.body.scrollTop;
		var scrollLeft = top.document.body.scrollLeft;
			 
		var iLeft = oEvent.clientX + scrollLeft - dragData["x"] + parseInt(oObj.style.left,10);
		var iTop = oEvent.clientY + scrollTop - dragData["y"]+ parseInt(oObj.style.top,10);
	
		oObj.style.left = iLeft;
		oObj.style.top = iTop;
 
 

		var startX = oEvent.clientX + scrollLeft;
		var startY = oEvent.clientY + scrollTop;
		
		dragData = {x: startX, y: startY};  
		
	}
   
	function mouseup()
	{
		oObj.onmousemove = null;
		oObj.onmouseup = null;
  
		
		var scrollTop = top.document.body.scrollTop;
		var scrollLeft = top.document.body.scrollLeft;
				
		if(parseInt(oObj.style.top,10)<scrollTop)
		{
 
 
			 oObj.style.top = scrollTop;
		} 
		
		if(parseInt(oObj.style.left,10)<scrollLeft)
		{
			oObj.style.left = scrollLeft; 		
		}	
		
		oObj.releaseCapture ? oObj.releaseCapture() : function(){};
	
	}
}

function closeTip(_sID)
{
	var oObj = $(_sID);

	oObj.innerHTML = "";
	oObj.style.display = "none";	
}


var bShowDiv = false;
//var 

function closeDiv(_sID)
{
	var oObj = $(_sID);

	oObj.innerHTML = "";
	oObj.style.display = "none";	
	
	var overlay = $("overlay");	
	if(overlay != null)
	{
		overlay.outerHTML = "";
	}
	
	bShowDiv = false;
 
	document.body.scroll= "yes"
 ;

}

function showDiv(_sID,which,event,bInner,bShadow)
{			
	var arraySize;
	if(bInner==null)
		arraySize = getTopPageSize();
	else
		arraySize = getPageSize();
		
	var oObj = top.document.getElementById(_sID);
	oObj.innerHTML = which;
	
	if(event==null)
	{
		oObj.style.left = arraySize[0] / 2 - 150 ;
		oObj.style.top =  arraySize[3] + 200;
	
	}
	else
	{
		var iEvent= window.event ? window.event : event;	
		
		//oObj.style.left = arraySize[0] / 2 - 400 ;
		//oObj.style.top = arraySize[1] / 2 - 150 ;
		var arrayScroll = getPageScroll();
		
		
	    oObj.style.left = arraySize[0]/2-400 + arrayScroll[0];
	    oObj.style.top =  arrayScroll[1]+300;

 

	}
		
	//创建一个DIV,改名为 overlay 这个是透明的层	
	if(bShadow==null)
	{
		var oDiv = top.document.createElement("div");	
		oDiv.id = "overlay";	
		top.document.body.appendChild(oDiv);

		var overlay = top.document.getElementById("overlay");
		
		overlay.style.height = arraySize[1];
		overlay.style.width = arraySize[0] + 20;
 	 // 此处加20是因为不显示滚动条后宽度就增加了20，需要用此层遮蔽
		
		overlay.style.display = "block";		
		overlay.style.zindex = oObj.style.zindex - 1;		
	}	
	
	oObj.style.display = "block";
	
	bShowDiv = true;
	//scrollMoveDiv(_sID,bInner);
	
	document.body.scroll="no"
}

function scrollMoveDiv(_sID,bInner)
{	
	if(bShowDiv)
	{
		var arraySize;
		if(bInner==null)
			arraySize = getTopPageSize();
		else
			arraySize = getPageSize();
			
		var oObj = top.document.getElementById(_sID);

		oObj.style.left = arraySize[0] / 2 - 150 ;
		oObj.style.top =  arraySize[3] + 200;
	}
	
	// 此处是写死了，因为目前调用showdiv函数时	bInner值都是没有的	
	setTimeout("scrollMoveDiv('"+_sID+"')",1);
}

function getTopPageScroll()
{
	var xScroll, yScroll;
	
	if(top.window.innerHeight && top.window.scrollMaxY) 
	{	
		xScroll = top.document.body.scrollWidth;
		yScroll = top.window.innerHeight + top.window.scrollMaxY;
	} 
	else if(top.document.body.scrollHeight > top.document.body.offsetHeight)
	{ 
		xScroll = top.document.body.scrollWidth;
		yScroll = top.document.body.scrollHeight;
	} 
	else 
	{ 
		xScroll = top.document.body.offsetWidth;
		yScroll = top.document.body.offsetHeight;
	}
	
	var	scrollParam = new Array(xScroll,yScroll) 

	return scrollParam;
}







function getTopPageSize()
{
	var xScroll, yScroll;
	
	if(top.window.innerHeight && top.window.scrollMaxY) 
	{	
		xScroll = top.document.body.scrollWidth;
		yScroll = top.window.innerHeight + top.window.scrollMaxY;
	} 
	else if(top.document.body.scrollHeight > top.document.body.offsetHeight)
	{ 
		xScroll = top.document.body.scrollWidth;
		yScroll = top.document.body.scrollHeight;
	} 
	else 
	{ 
		xScroll = top.document.body.offsetWidth;
		yScroll = top.document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if(top.self.innerHeight) 
	{	
		windowWidth = top.self.innerWidth;
		windowHeight = top.self.innerHeight;
	} 
	else if(top.document.documentElement && top.document.documentElement.clientHeight) 
	{
		windowWidth = top.document.documentElement.clientWidth;
		windowHeight = top.document.documentElement.clientHeight;
	} 
	else if(top.document.body) 
	{
		windowWidth = top.document.body.clientWidth;
		windowHeight = top.document.body.scrollTop;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else 
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	} 
	else 
	{
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;	
}

function getPageSizebak()

{      

    var pageWidth = document.documentElement.clientWidth;

    var pageHeight = document.documentElement.clientHeight;

    

    var windowWidth = document.body.clientWidth;

    var windowHeight = document.body.clientHeight;

              

    // when the page is on the top ,pageWidth=windowWidth and pageHeight=windowHeight

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

 

    return arrayPageSize;    

}

function getPageScroll()

{

    var xScroll = document.documentElement.scrollLeft;

    var yScroll = document.documentElement.scrollTop;

    
     var nScrollLeft=document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft;
	var nScrollTop=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
	var nClientWidth=document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
	var nClientHeight=document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;



    var arrayScroll = new Array(nScrollLeft,nScrollTop);
 
   
    
    

    return arrayScroll;

}



//取得页面大小
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

