var currentMoveObj = null;    //当前拖动对象
var relLeft;    //鼠标按下位置相对对象位置
var relTop;

//最后一个显示的窗口ID
var lastShowDivWinID = null;

//最后一个显示的窗口是否要彻底关闭（下次重新加载）
var lastShowDivWinIsReload = "false";


function divBoxDown(obj){
    /**
	先不让拖动
	currentMoveObj = obj;        //当对象被按下时，记录该对象
    currentMoveObj.style.position = "absolute";
    relLeft = event.x - currentMoveObj.style.pixelLeft;
    relTop = event.y - currentMoveObj.style.pixelTop;
	currentMoveObj.style.filter = "Alpha(opacity=60)"; //按下时对象透明
	currentMoveObj.style.opacity = "0.6"; //firfox有效
	**/
}

function divBoxUp(obj){
	/**
	先不让拖动
	currentMoveObj = obj; //当鼠标被释放时，记录该对象
    currentMoveObj.style.filter = "Alpha(opacity=100)"; //恢复
	currentMoveObj = null;    //当鼠标释放时同时释放拖动对象
	**/
}

function divBoxMove(obj){
	/**
	先不让拖动
    if(currentMoveObj != null){
        currentMoveObj.style.pixelLeft=event.x-relLeft;
        currentMoveObj.style.pixelTop=event.y-relTop;
    }
	**/
}



//关闭窗口
function closeDivWindow(){

	//显示select控件
	DispalySelect(1);
	
	//隐藏遮罩
	hideMask();
	
	//隐藏窗口
	hideDivWindow(lastShowDivWinID,lastShowDivWinIsReload);
	
}

//页面遮罩对象
var MaskObj = null;

//显示遮罩
function showMask(){
	var Maskw,Maskh,Openw,Openh;
	
	Maskw = document.body.offsetWidth;
	Maskh = window.screen.height; //document.body.scrollHeight;
	Maskh = document.body.scrollHeight;
	
	//设置遮罩层
	
	//只有第一次才创建这个遮罩层
	if(null == MaskObj){
		MaskObj = document.createElement("windowMask"); 
	}
	
	MaskObj.id = "windowMask";
	MaskObj.className = "div_window_mask";
	
	MaskObj.style.width = Maskw + "px";
	MaskObj.style.height = Maskh + "px";
	
	document.body.appendChild(MaskObj);
	
}

//隐藏遮罩
function hideMask(){
	var maskObj = document.getElementById("windowMask");
	if(null != maskObj){
		maskObj.style.width = "0px";
		maskObj.style.height = "0px";
	}
}

//隐藏窗口
function hideDivWindow(winID,isReload){
	var winObj = document.getElementById(winID);
	
	if(null != winObj){
	
		//如果是需要下载重新加载，则在关闭窗口时，彻底删除窗口对象
		if(isReload == "true"){
			winObj.removeNode(true);	//移除窗口，以及所有子节点
		}else{
			winObj.style.display = "none";
		}
		
	}
}

//显示窗口，使用AJAX方法动态读取某URL中的输出内容做为窗口的内容
function showDivWindowForURL(winID,width,height,isReload,title,url){
	lastShowDivWinID = winID;
	lastShowDivWinIsReload = isReload;
	
	var contentObj = showDivWindow(winID,width,height,isReload,title,"窗口加载中..");
	
	var ajax=new AJAXRequest;
	
	//使用这种方法，可以直接将输出innerhtml某对象
	//ajax.get('../../getmodule?ajax=true&module=' + url,contentObj);
	
	//由于要支持在innerHTML中，支持JS，所以用了一个 setInnerHTML 方法
	ajax.get('../../getmodule?ajax=true&module=' + url,function(obj){setInnerHTML(contentObj, obj.responseText);});
	
}



/**
* 显示窗口
**/
function showDivWindow(winID,width,height,isReload,title,content){

	//隐藏select控件
   	DispalySelect(0); 

	//显示遮罩
   	showMask();
   
   
   	var PopObj = null;
   	if(!document.getElementById(winID)){	//如果没有winID，则创建
		PopObj = document.createElement(winID); 
		PopObj.id = winID;
		PopObj.className = "div_window_box";
		
		PopObj.onselectstart = function(){return false;};
		
		PopObj.style.left = (window.screen.width - width) / 2 + "px";
		PopObj.style.top = (-160 + window.screen.height - height) / 2 +"px";
		
		PopObj.style.width = width+10 + "px";
		PopObj.style.height = height+20 + "px";

		
		document.body.appendChild(PopObj);
		
		
		
		//开始
		var popObjHTML = "<div class='div_window_box_border' onMouseDown='divBoxDown(this.parentNode)' onMouseUp='divBoxUp(this.parentNode)' onMouseMove='divBoxMove(this.parentNode)'>";
		
		//标题行
		popObjHTML = popObjHTML + "<div class='div_window_box_oper_bar'><div class='div_window_box_oper_bar_title'>"+title+"</div><div class='div_window_box_oper_bar_button'><div class='div_window_box_oper_bar_button_close' onclick='closeDivWindow();'>&nbsp;</div></div></div>";
		
		//内容
		popObjHTML = popObjHTML + "<div class='div_window_box_content' id='div_window_box_content'>"+content+"</div>";
	
		//结束
		popObjHTML = popObjHTML + "</div>";
		
		PopObj.innerHTML = popObjHTML;
		
		//设置内容区的高度
		//document.getElementById("div_window_box_content").style.height = (height) + "px";
		
		
	}else{		//如果有，则直接获得
		PopObj = document.getElementById(winID); 
		
		//关闭时，设置为了隐藏，这时，又要显示，所以再设置为显示
		PopObj.style.display="block";
	}
	
	//返回内容容器对象
	return document.getElementById("div_window_box_content");
}

//显示和隐藏select控件
function DispalySelect(val){ 
	var dispalyType;
	var arrdispalyType=["hidden","visible"];
	var arrObjSelect=document.getElementsByTagName("select");
	for (i=0;i<arrObjSelect.length;i++){
		arrObjSelect[i].style.visibility=arrdispalyType[val];
	}
}
