﻿/**
 *<p>Title:常用方法</p>
 *<p>Description: 调用XML文档，以及定位元素等</p>
 *<p>Copyright:Copyright(c)2008</p>
 *<p>Company:Null</p>
 *@author：宋雷鸣 QQ:10522779
 *@version：0.1
 */

//获取元素的纵坐标
function getTop(e){
var offset=e.offsetTop;
if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
return offset;
}
//获取元素的横坐标
function getLeft(e){
var offset=e.offsetLeft;
if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
return offset;
}
//获取鼠标的位置
function getMouseX()
{
	return document.documentElement.scrollLeft+event.clientX; //获取当前鼠标位置的X坐标
}
//获取鼠标的位置
function getMouseY()
{
	return document.documentElement.scrollTop+event.clientY; //获取当前鼠标位置的X坐标
}
//生成随机数
function getRandom()
{
	return Math.round(Math.random()*10000);
}
//将指定节点插入到父节点的第一个位置
//parent:父节点
//child:当前子节点
function insertFirst(parent,child)
{
	if(parent.firstChild==null)
	{
		parent.appendChild(child);
	}else
	{
		parent.insertBefore(child,parent.firstChild);
	}
	return parent;
};

//打开窗式窗口
function mini_window(page,w,h)
{
	return showModalDialog(page, "", "dialogWidth:"+w+"px; dialogHeight:"+h+"px; status:0;scroll:0;help:0");
}
//弹出指定模式窗口，这里用于锁屏
function lockScreen(page,w,h)
{
	showScreenMask();
	var arr = showModalDialog(page, "", "dialogWidth:"+w+"px; dialogHeight:"+h+"px; status:0;scroll:0;help:0");
	
	//当退出锁屏时
	if(arr == "unLock") 
	{
		hiddenScreenMask();
		//当前页面重新加载；
	  	//window.location.reload();
	 }else
	 {
		 //当用户直接关闭窗口时，重新加载
		 if(arr = "reFresh")
			lockScreen(page,w,h);
	 }
}

//获取屏幕遮罩的对象
function getScreenMask(ScreenMaskAlpha,ScreenMaskColor)
{
	//屏幕遮罩的透明度
	ScreenMaskAlpha=ScreenMaskAlpha!=null ? ScreenMaskAlpha : 30;
	//屏幕遮罩的颜色
	ScreenMaskColor=ScreenMaskColor!=null ? ScreenMaskColor : "#000000";
	var mask=document.getElementById("ScreenMask");
	if(mask==null)
	{
		var mask=document.createElement("div");
		mask.setAttribute("id","ScreenMask");
		document.body.appendChild(mask);	
		mask.style.position="absolute";
		mask.style.zIndex=1000;
		//设定宽高与位置
		var winWidth=document.documentElement.clientWidth;
		var winHeight=document.documentElement.clientHeight;
		mask.style.width=winWidth;
		mask.style.height=winHeight;
		mask.style.left=0;
		mask.style.top=0;
		//默认遮罩不显示
		mask.style.display="none";		
	}
	//设置遮罩颜色与透明度
	mask.style.backgroundColor=ScreenMaskColor;
	//mask.style.filter="Alpha(Opacity="+ScreenMaskAlpha+")";
	mask.style.filter="Alpha(Opacity="+ScreenMaskAlpha+", FinishOpacity=80, Style=2, StartX=0, StartY=0, FinishX=100, FinishY=100)";
	return mask;
}
//显示屏幕遮罩
function showScreenMask()
{	
	var mask=getScreenMask();
	mask.style.display="block";
}
//去除屏幕遮罩
function hiddenScreenMask()
{
	var mask=getScreenMask();
	mask.style.display="none";
}
//动态加载css文件或js文件
function attachFile(iframeId,filename, filetype)
{ 
	var head = window.frames[iframeId].document.getElementsByTagName('head').item(0);
	if (filetype=="css"){ //判断文件类型 
	  var fileref=window.frames[iframeId].document.createElement("link"); 
	  fileref.setAttribute("rel", "stylesheet") ;
	  fileref.setAttribute("type", "text/css");
	  fileref.setAttribute("href", filename);
	} 
	if (filetype=="js"){ //判断文件类型 
	  var fileref=window.frames[iframeId].document.createElement('script');//创建标签 
	  fileref.setAttribute("type","text/javascript");//定义属性type的值为text/javascrip
	  fileref.setAttribute("language","JavaScript"); 	  
	  fileref.setAttribute("src", filename);//文件的地址 
	} 	
if (typeof fileref!="undefined")   
  //head.appendChild(fileref);
  insertFirst(head,fileref);
}  
//加载所需的css与js文件，该方法仅供managePanle.html页面使用
function attachCssOrJs(iframeId)
{		
	
	if(iframeId==null)iframeId="workArea";
	//去除等待信息
	var pageLoad_Waiting=window.frames[iframeId].document.getElementById("pageLoad_Waiting");
	if(pageLoad_Waiting!=null)pageLoad_Waiting.style.display="none";
	/*
	//加载css文件
	var cssPath="../Console/Style/";	
	var cssFile=new Array("Public");
	cssFile.reverse();
	for(var i=0;i<cssFile.length;i++)
	{
		attachFile(iframeId,cssPath+cssFile[i]+".css", "css");
	}
	
	//*
	//加载javascript文件
	var jsPath="../Console/JavaScript/";
	var jsFile=new Array("Parameter","Utilities","XmlHelper","Node","Menu","Drop","Tree","Context","Accordion","MenuEvent");
	jsFile.reverse();
	for(var i=0;i<jsFile.length;i++)
	{
		//attachFile(iframeId,jsPath+jsFile[i]+".js", "js");
	}//*/
}
//当还未加载完成时
function attachWait(iframeId)
{
	if(iframeId==null)iframeId="workArea";
	var head = window.frames[iframeId].document.body;
	//获取等待信息的div
	var pageLoad_Waiting=window.frames[iframeId].document.getElementById("pageLoad_Waiting");
	if(pageLoad_Waiting==null)
	{		
		pageLoad_Waiting=window.frames[iframeId].document.createElement("div");
		pageLoad_Waiting.setAttribute("id","pageLoad_Waiting"); 
		pageLoad_Waiting.innerHTML="正在加载，请等待…………";
		insertFirst(head,pageLoad_Waiting);
	}else
	{
		pageLoad_Waiting.style.display="";
	}
	
}