// JavaScript Document

//浮动窗口的宽度
var popWinWidth = 220;

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

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

//关闭窗口
function closeDivWindow(){
	//隐藏窗口
	hideDivWindow(lastShowDivWinID,lastShowDivWinIsReload);
}

//隐藏窗口
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,isReload,title,url){
	lastShowDivWinID = winID;
	lastShowDivWinIsReload = isReload;
	
	//隐藏其它关键字相关文章窗口
	var winObjs = document.getElementsByTagName("div");
	for(var a=0;a<winObjs.length;a++){
		var winObjID = winObjs[a].id;
		if(winObjID.indexOf("keywordWin_")==0){
			hideDivWindow(winObjID,"false");
		}
	}
	
	//只有第一次点击时才会去加载相关内容
	var popObj = document.getElementById(winID); 
	if(popObj){		//如果有，则直接获得
		PopObj = document.getElementById(winID); 
		//关闭时，设置为了隐藏，这时，又要显示，所以再设置为显示
		PopObj.style.display="block";
		return;
	}
	
	var contentObj = showDivWindow(winID,isReload,title,"窗口加载中..");
	var ajax=new AJAXRequest;

	var action = '../../GetPageContent?ajax=true&page_url=' + url;
	ajax.get(action,function(obj){setInnerHTML(contentObj, obj.responseText)});
}



/**
* 显示窗口
**/
function showDivWindow(winID,isReload,title,content){
   	var PopObj = null;
   	if(!document.getElementById(winID)){	//如果没有winID，则创建
		PopObj = document.createElement("div"); 
		PopObj.id = winID;
		PopObj.className = "div_window_box";
		
		PopObj.onselectstart = function(){return false;};
		
		PopObj.style.left = window.event.screenX + "px";
		PopObj.style.top = window.event.clientY +"px";
		
		//alert(window.event.screenX+" "+PopObj.style.left + " " + window.event.screenY + " "+PopObj.style.top);
		
		PopObj.style.width = popWinWidth + "px";
		
		document.body.appendChild(PopObj);
		
		//开始
		var popObjHTML = "<div class='div_window_box_border'>";
		
		//标题行
		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_"+winID+"'>"+content+"</div>";
	
		//结束
		popObjHTML = popObjHTML + "</div>";
		
		PopObj.innerHTML = popObjHTML;
		
	}
	
	//返回内容容器对象
	return document.getElementById("div_window_box_content_"+winID);
}
