//弹出可拖动对话窗口
/*firefox*/ 
function __firefox(){ 
HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style); 
window.constructor.prototype.__defineGetter__("event", __window_event); 
Event.prototype.__defineGetter__("srcElement", __event_srcElement); 
} 
function __element_style(){ 
return this.style; 
} 
function __window_event(){ 
return __window_event_constructor(); 
} 
function __event_srcElement(){ 
return this.target; 
} 
function __window_event_constructor(){ 
if(document.all){ 
return window.event; 
} 
var _caller = __window_event_constructor.caller; 
while(_caller!=null){ 
var _argument = _caller.arguments[0]; 
if(_argument){ 
var _temp = _argument.constructor; 
if(_temp.toString().indexOf("Event")!=-1){ 
return _argument; 
} 
} 
_caller = _caller.caller; 
} 
return null; 
} 
if(window.addEventListener){ 
__firefox(); 
} 
/*end firefox*/


function $(_sId)
{
var sId = _sId;
return document.getElementById(_sId);
}


function moveDivForDrag2(_sId)
{
	var event;
	var oEvent = window.event ? window.event : event;
	if (oEvent==null)
		oEvent=__window_event_constructor();
	
	var oObj = document.getElementById(_sId);
	//alert(oObj.style.top);
	oObj.onmousemove = mousemove;
	oObj.onmouseup = mouseup;
	oObj.setCapture ? oObj.setCapture() : function(){};
	
	var dragData = {x : oEvent.clientX, y : oEvent.clientY};
	var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
	function mousemove()
	{
		//alert("mousemove");
		var oEvent = window.event ? window.event : event;
		if (oEvent==null)
			oEvent=__window_event_constructor();
		//alert(oObj.style.left);
		var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
		var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
		//alert(iTop);
		oObj.style.left = iLeft+"px";
		oObj.style.top = iTop+"px";
		dragData = {x: oEvent.clientX, y: oEvent.clientY};
	}

	function mouseup()
	{
		//alert("mouseup");
		var oEvent = window.event ? window.event : event;
		if (oEvent==null)
			oEvent=__window_event_constructor();
		oObj.onmousemove = null;
		oObj.onmouseup = null;
		if(oEvent.clientX < 1 || oEvent.clientY < 1)
		{
			oObj.style.left = backData.y+"px";
			oObj.style.top = backData.x+"px";
		}
		oObj.releaseCapture ? oObj.releaseCapture() : function(){};
	}
}


function moveDivForDrag(_sId)
{
	var ie = (navigator.appVersion.indexOf("MSIE")!=-1);//IE
	var ff = (navigator.userAgent.indexOf("Firefox")!=-1);//Firefox

	var event;
	var oEvent = window.event ? window.event : event;
	if (oEvent==null)
		oEvent=__window_event_constructor();
	
	var oObj = document.getElementById(_sId);
	//alert(oObj.style.top);
	if (ie)
	{
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		oObj.setCapture ? oObj.setCapture() : function(){};
		
		var dragData = {x : oEvent.clientX, y : oEvent.clientY};
		var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
	}
	
	function mousemove()
	{
		//alert("mousemove");
		var oEvent = window.event ? window.event : event;
		if (oEvent==null)
			oEvent=__window_event_constructor();
		//alert(oObj.style.left);
		var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
		var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
		//alert(iTop);
		oObj.style.left = iLeft+"px";
		oObj.style.top = iTop+"px";
		dragData = {x: oEvent.clientX, y: oEvent.clientY};
	}

	function mouseup()
	{
		//alert("mouseup");
		var oEvent = window.event ? window.event : event;
		if (oEvent==null)
			oEvent=__window_event_constructor();
		oObj.onmousemove = null;
		oObj.onmouseup = null;
		if(oEvent.clientX < 1 || oEvent.clientY < 1)
		{
			oObj.style.left = backData.y+"px";
			oObj.style.top = backData.x+"px";
		}
		oObj.releaseCapture ? oObj.releaseCapture() : function(){};
	}

}

function closeDivForDrag(_sID)
{
	var oObj = $("floatDiv");
	var overlay = $("overlay");
	if(overlay != null)
	{
		overlay.style.display = "none";
		overlay.outerHTML = "";
	}
	oObj.style.display = "none";
}

function showDiv(_sID)
{
	var ie = (navigator.appVersion.indexOf("MSIE")!=-1);//IE
	var ff = (navigator.userAgent.indexOf("Firefox")!=-1);//Firefox
	
	var event;
	var iEvent = window.event ? window.event : event;
	if (iEvent==null)
		iEvent=__window_event_constructor();
	
	var arrySize = getPageSize();
	var oObj = $(_sID);
	//创建一个DIV,改名为 overlay 这个是透明的层
	if ($("overlay")==null)
	{
		var oDiv =document.createElement("div");
		oDiv.id = "overlay";
		document.body.appendChild(oDiv);
	}
	var overlay = $("overlay");
	overlay.style.height = arrySize[1] + "px";
	overlay.style.width = arrySize[0] + "px";
	if(iEvent == null)
	{
		if(oObj.style.left == "")
		{
			oObj.style.left = arrySize[0] / 2 - 150 ;
		}

		if(oObj.style.top == "")
		{
			oObj.style.top =  arrySize[3] / 2 - 100 ;
		}
	}
	else
		{
			var arrayScroll = getPageScroll();
			//alert("上下移动了："+arrayScroll[1]);
			oObj.style.left = arrySize[0] / 2 - 150 + arrayScroll[0] + "px" ; // iEvent.clientX;
			oObj.style.top = arrayScroll[1]+150 + "px" ;// iEvent.clientY;
		}

		oObj.style.display = "block";
		overlay.style.display = "block";
		overlay.style.zindex = oObj.style.zindex - 1;
	}

//取得页面大小ȡ�����С
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 Macwould 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;
}

function getPageScroll()

{
    var xScroll = document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft; 
    var yScroll = document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;
    
    if(yScroll==0)
    {
    		yScroll = 	parent.document.body.scrollTop?parent.document.body.scrollTop:parent.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,yScroll);
 
    return arrayScroll;
}