﻿function popupDialog(id,title,content,width,height)
{
    alert(id);
	var objDiv = document.createElement("div");
	objDiv.id= id;
	objDiv.style.width = width;
	objDiv.style.height = height;
	objDiv.innerHTML = "<div class=\"divPosition\"><div class=\"m_moveTopLeft\">"+title+"到</div><div style=\"float:right; height:20px; margin-top:5px; margin-right:5px;\"><a href=\"javascript:;\" onclick=\"remove_Div('"+id+"')\">×</a></div><div style=\"width:99%;\">"+content+"<div></div>";
	document.body.appendChild(objDiv);
}
/*

	删除Div
	*/
function remove_Div(u)
{
    var obj = document.getElementById(u);
    document.body.removeChild(obj);
    closeWindow();
}

/*

	移动层
	*/
function startMove(objDiv)
{
	document.attachEvent("onmousemove",m_moveDiv);
	document.attachEvent("onmouseup",m_endMove);
	document.attachEvent("onselectstart",m_selectNo);
	document["moveDiv"] = objDiv;
	document["startX"] = event.x;
	document["startY"] = event.y;
	document["oldX"] = objDiv.getBoundingClientRect().left;
	document["oldY"] = objDiv.getBoundingClientRect().top;
}
/*

	鼠标点下事件
	*/
function m_moveDiv()
{
	var obj = document["moveDiv"];
	if(obj)
	{
		var l = document["oldX"];
		var t = document["oldY"];
		obj.style.position = "absolute";
		obj.style.left = l +(event.x-document["startX"]) < 900 ? l + (event.x-document["startX"]) : 900;
		obj.style.top = t + (event.y-document["startY"]) < 360 ? t + (event.y-document["startY"]) : 360;
		
	}
}
/*

	鼠标结束事件
	*/
function m_endMove()
{
	document.detachEvent("onmousemove",m_moveDiv);
	document.detachEvent("onmouseup",m_endMove);
	document.detachEvent("onselectstart",m_selectNo);
	document["moveDiv"] = null;
	document["startX"] = null;
	document["startY"] = null;
}
function m_selectNo(){ return false; }

var isIe=(document.all)?true:false;
//设置select的可见状态
function setSelectState(state)
{
    var objl=document.getElementsByTagName('select');
    for(var i=0;i<objl.length;i++)
    {
    objl[i].style.visibility=state;
    }
    }
    function mousePosition(ev)
    {
    if(ev.pageX || ev.pageY)
    {
    return {x:ev.pageX, y:ev.pageY};
    }
    return {
    x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
//弹出方法
function showMessageBox(wTitle,content,ev,wWidth)
{
    closeWindow();
    var bWidth=parseInt(document.documentElement.scrollWidth);
    var bHeight=parseInt(document.documentElement.scrollHeight);
    if(isIe){
    setSelectState('hidden');}
    var back=document.createElement("div");
    back.id="back";
    var styleStr="top:0px;left:0px;position:absolute;FILTER: alpha(opacity=85);background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
    styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
    back.style.cssText=styleStr;
    document.body.appendChild(back);
    showBackground(back,50);
    var mesW=document.createElement("div");
    mesW.id="mesWindow";
    mesW.className="mesWindow";
    mesW.innerHTML="<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:1px;'><input type='button' onclick='closeWindow()' title='关闭窗口' class='close' value='关闭' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
    //styleStr="left:"+(bWidth / 2 - wWidth/2)+"px;top:"+((bHeight+document.documentElement.scrollTop) / 2 - 150)+"px;position:absolute;width:"+wWidth+"px;";
    styleStr="left:"+(((ev.clientX-wWidth)>0)?(ev.clientX-wWidth):ev.clientX)+"px;top:"+(ev.clientY+document.documentElement.scrollTop)+"px;position:absolute;width:"+wWidth+"px;";   
    
    mesW.style.cssText=styleStr;
    document.body.appendChild(mesW);
}

//lastScrollY=0;
//function heartBeat(){
//	var diffY;
//	if (document.documentElement && document.documentElement.scrollTop)
//	{
//		diffY = document.documentElement.scrollTop;
//	}
//	else if (document.body)
//	{
//		diffY = document.body.scrollTop
//	}
//	else
//	{
//		percent=.1*(diffY-lastScrollY);
//		if(percent>0)
//		{
//			percent=Math.ceil(percent);
//		}
//		else
//		{
//			percent=Math.floor(percent);
//			document.getElementById("mesWindow").style.top=parseInt(document.getElementById("mesWindow").style.top)+percent+"px";
//		}
//		lastScrollY=lastScrollY+percent;
//	}
//}

//window.setInterval("heartBeat()",1);

function openMask()
{
	closeWindow();
	var bWidth=parseInt(d.documentElement.scrollWidth);
	var bHeight=parseInt(d.documentElement.scrollHeight);
	if(isIe){
	setSelectState('hidden');}
	var back=d.createElement("div");
	back.id="back";
	var styleStr="top:0px;left:0px;position:absolute;background:#F0F0F0;width:"+bWidth+"px;height:"+bHeight+"px;";
	styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
	back.style.cssText=styleStr;
	d.body.appendChild(back);
	showBackground(back,50);
}

function showBackground(obj,endInt)
{
    if(isIe)
    {
    obj.filters.alpha.opacity+=1;
    if(obj.filters.alpha.opacity<endInt)
    {
    setTimeout(function(){showBackground(obj,endInt)},5);
    }
    }else{
    var al=parseFloat(obj.style.opacity);al+=0.01;
    obj.style.opacity=al;
    if(al<(endInt/100))
    {setTimeout(function(){showBackground(obj,endInt)},5);}
    }
}
function closeWindow()
{
    if(document.getElementById('back')!=null)
    {
    document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    if(document.getElementById('mesWindow')!=null)
    {
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }
    if(isIe){
    setSelectState('');}
}