
 var isIE=(document.all)?true:false;
 
 /*
 隐藏select对象，因在IE里会显示在DIV上面。
 */
function move_msg_setSelectState(state)
{
	var objl=document.getElementsByTagName('select');
	for(var i=0;i<objl.length;i++)
	{	
		objl[i].style.visibility=state;
	}
}



//关闭窗口半透明窗口
function move_msg_closeWindow()
{
	if(document.getElementById('move_back')!=null)
	{
		document.getElementById('move_back').parentNode.removeChild(document.getElementById('move_back'));
	}
	
	if(isIE){
		move_msg_setSelectState('');
	}
}

function remove_msg_box()
{
	if(document.getElementById('_msg_show_div_')!=null)
	{
		document.getElementById('_msg_show_div_').parentNode.removeChild(document.getElementById('_msg_show_div_'));
	}

}

/*
将原窗口设置为不可用，并将它变灰
*/
function move_msg_opa_back()
{
 var bWidth=parseInt(document.documentElement.scrollWidth)-3;
 var bHeight=parseInt(document.documentElement.scrollHeight)<592?592:parseInt(document.documentElement.scrollHeight);
 if(isIE){
 move_msg_setSelectState('hidden');}

  var back=document.createElement("div");
 back.id="move_back";
 var styleStr="top:0px;left:0px;z-index:100;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
 styleStr+=(isIE)?"filter:alpha(opacity=40);":"opacity:0.40;";
 back.style.cssText=styleStr;
 document.body.appendChild(back);
	
}

function create_move_show_div()
{
	remove_msg_box();//创建之前先清掉
  var show_div=document.createElement("div");
 show_div.id="_msg_show_div_";
 var styleStr="display:block;z-index:111;filter:alpha(opacity=100);opacity:1;";
// styleStr+=(isIE)?"filter:alpha(opacity=40);":"opacity:0.40;";
 show_div.style.cssText=styleStr;
 show_div.className="msg_move_show_div";
 
 var div_html = "<div class='title_move_msg' id='_msg_title_div'>";
 div_html += " <a href='#' class='move_msg_a' onclick = 'move_msg_closeed();return false;'> 关 闭 </a>";
 div_html += " <div class='title_context_move_msg' id='_msg_tittleup'></div></div>";
 div_html += "<div class='content_move_msg' id='_msg_contentup'></div>";
 
 show_div.innerHTML=div_html;
 document.body.appendChild(show_div);
	
}
/*
fix_flag -- 是否固定高度，默认是不固定,true或false
pos -- 位置，分：中间-0，左下-1，右下-2，默认是0
sh_flag --- 是否将原窗口变灰，默认变灰，true或false
close_time --- 开始自动关闭时间，为0就是不关闭，默认不关
*/
var m_pos=0;
var m_sh_flag = true;
var m_close_time = 0;
var to_id;
var do_times = 0; //执行逐渐关闭的次数，最大为20次

function show_move_msg_box(content,title,width,height,fix_flag,pos,sh_flag,close_time)
{
	if(pos!=undefined)
		m_pos = pos;
	if(sh_flag != undefined)
		m_sh_flag = sh_flag;
	if(close_time != undefined)
		m_close_time = close_time;
	
	//if(to_id!=undefined)
	 	window.clearTimeout(to_id);
   // if(cl_id!=undefined)
		window.clearInterval(cl_id);
	do_times = 0;
		
	 move_msg_closeWindow();
	
	if(m_sh_flag)
		move_msg_opa_back();//将原窗口设置为不可用，并将它变灰
	
	create_move_show_div();

	var con_div = document.getElementById("_msg_contentup");
	if(con_div!=null)
	{
		con_div.innerHTML = content;
	}
	
	var title_div = document.getElementById("_msg_tittleup");
	if(title_div!=null)
	{
		title_div.innerHTML = title;
	}
	msg_move_show(width,height,fix_flag,pos,sh_flag,close_time);
	
	//alert(m_close_time);
	if(m_close_time>0)
	{
		
		to_id = window.setTimeout(step_close,m_close_time);
	}
}

/*--打开--*/
function msg_move_show(width,height,fix_flag,pos,sh_flag,close_time)
{
	
 	if(pos!=undefined)
		m_pos = pos;
	if(sh_flag != undefined)
		m_sh_flag = sh_flag;
	if(close_time != undefined)
		m_close_time = close_time;
 
	 var bWidth=parseInt(document.documentElement.scrollWidth);
 	var bHeight=parseInt(document.documentElement.scrollHeight)<592?592:parseInt(document.documentElement.scrollHeight);


	var bodyfrm = ( document.compatMode.toLowerCase()=="css1compat" ) ? document.documentElement : document.body;

	var o_div = document.getElementById("_msg_show_div_");
	//alert(o_div.innerHTML);
	o_div.style.display = "block";
	o_div.style.width = width+"px";
	if(fix_flag)
		o_div.style.height=height+"px";
	
	//google浏览器不支持scrollTop,用以下方式GG,FF，IE都可用
	var tt_top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
	//alert(tt_top);
	//alert(document.compatMode.toLowerCase());
	var ll = ((bWidth/2) -250) +"px";
	o_div.style.left=ll;
	
	var o_top = "";
	var tttt = "";
	//alert("m_pos:"+m_pos+",m_sh_flag:"+m_sh_flag+",m_close_time:"+m_close_time);
	if(m_pos == 0)
	{
		tttt = "0";
		o_top=( tt_top + bodyfrm.clientHeight/2 - height/2) + "px"; //滚动条的上沿高度＋窗口高度的一半 － DIV的一半
	}
	else if(m_pos == 1)
	{
		tttt = "1";
		o_div.style.left=0 + "px";;
		o_top=(tt_top + bodyfrm.clientHeight - height) + "px";;
	}	
	else
	{
		tttt = "2";
		o_div.style.left=(bWidth - width -25) + "px";;
		o_top=(tt_top + bodyfrm.clientHeight - height -25) + "px";;
	}
	//alert(tt_top + ", "+bodyfrm.clientHeight + ", "+height + ", "+ tttt);
	o_div.style.top = o_top;
		
	var title_div = document.getElementById("_msg_title_div");
	//alert(title_div.innerHTML);
	/*设置鼠标事件*/
	if (window.attachEvent)
	 {
		title_div.attachEvent("onmousedown",move_msg_readyMove);
		document.attachEvent("onmousedown",move_msg_doc_mousedown);
		document.attachEvent("onmouseup",move_msg_doc_mouseup);
		document.attachEvent("onmousemove",move_msg_doc_mousemove);
	 }
	 else
	 {
		 
		 title_div.addEventListener("mousedown",move_msg_readyMove,true);
		 document.addEventListener("mousedown",move_msg_doc_mousedown,true);
		 document.addEventListener("mouseup",move_msg_doc_mouseup,true);
		 document.addEventListener("mousemove",move_msg_doc_mousemove,true);
	 }
}    
	
    
/*--关闭--*/
var cl_id ;
function move_msg_closeed(){

	if(m_close_time>0)
	{
		window.clearInterval(cl_id);
	 	window.clearTimeout(to_id);
	}
     var o_div = document.getElementById("_msg_show_div_");
	
		move_msg_closeWindow(); //关闭关透明层

	     if(o_div != undefined && o_div.style.display == "block")
	     {
	     	o_div.innerHTML="";
			o_div.style.display="none";
	                
	     }        
		remove_msg_box(); //移除显示层
	
}    


//逐渐关闭
function step_close()
{
	//alert("star step close");
	do_times = 0;
	cl_id = window.setInterval(step_move_msg_close,50) ;
	
}

function step_move_msg_close()
{
	 var o_div = document.getElementById("_msg_show_div_");
	if(o_div!= undefined)
	{
		do_times = do_times +1;
		 if(do_times>=20)
		 {
		 	window.clearInterval(cl_id);
		 	window.clearTimeout(to_id);
		 	m_close_time = 0;
		 	move_msg_closeed();
		 	//alert("close ok");
		 }
		// styleStr+=(isIE)?"filter:alpha(opacity=40);":"opacity:0.40;";
		
		if(!isIE)
		{
			var opa = o_div.style.opacity;
			var opastep = 0.03;//计算每步增加的透明度
			 var nopa = Number(opa) - Number(opastep);//当前透明度
			o_div.style. opacity = nopa;
		}
		else
		{
		 var opa = o_div.style.filter.split("=")[1].split(")")[0]//获取目标div的透明度数值
		 var opastep = 4;//计算每步增加的透明度
		 var nopa = Number(opa) - Number(opastep);//当前透明度
		 if (nopa<20){o_div.style.filter = 'Alpha(opacity=' + 20 + ')';}
		 else{o_div.style.filter = 'Alpha(opacity=' + String(nopa) + ')';}//给div透明度赋值
		 }
	}

}
//逐渐关闭结束


/*-------------------------鼠标拖动---------------------*/    
   
    var  mouseD;
    var odrag;

	function move_msg_doc_mousedown(e)
	{
		if(m_close_time>0)
		{
			window.clearInterval(cl_id); //取消逐渐关闭功能
		}
		 var e;
        if(e)
        {
        	e = e;
        }
        else
        {
        	if(isIE)
        	{
        		e = event;
        	}
        	else
        	{
        		return;
        	}
        }
        
        if(e.button == (document.all ? 1 : 0))
        {
            mouseD = true;            
        }
    }
	
	function move_msg_doc_mouseup()
	{
	
		if(m_close_time>0)
		{
			window.clearTimeout(to_id);
			to_id = window.setTimeout(step_close,m_close_time);
		}
		
	
		 var od = document.getElementById("_msg_show_div_");    
        mouseD = false;
        odrag = "";
		if(od!=null)
		{
			if(isIE)
			{
				od.releaseCapture();
			}
			else
			{
				od.removeEventListener("MOUSEMOVE",this.show,false);
				od.style.opacity = 1;
			}    
		}
    }
    
    
    function move_msg_readyMove(e) 
	{
		 var od = document.getElementById("_msg_show_div_");    
        odrag = this;
        var e = e ? e : event;
        if(e.button == (document.all ? 1 : 0))
        {
            mx = e.clientX;
            my = e.clientY;
            od.style.left = od.offsetLeft + "px";
            od.style.top = od.offsetTop + "px";
            if(isIE)
            {
                od.setCapture();
                od.style.filter = 'Alpha(opacity=100)';
				//od.style.opacity = 0.5;
            }
            else
            {
				window.addEventListener("mousemove",move_msg_doc_mousemove,true);
                od.style.opacity = 0.5;
            }
        } 
    }
    
	function move_msg_doc_mousemove(e)
	{
        var e;
        if(e)
        {
        	e = e;
        }
        else
        {
        	if(isIE)
        	{
        		e = event;
        	}
        	else
        	{
        		return;
        	}
        }
       // e = e ? e : event;
         var od = document.getElementById("_msg_show_div_");    
        if(mouseD==true && odrag && od!=null)
        {        
            var mrx = e.clientX - mx;
            var mry = e.clientY - my;    
            od.style.left = parseInt(od.style.left) +mrx + "px";
            od.style.top = parseInt(od.style.top) + mry + "px";            
            mx = e.clientX;
            my = e.clientY;
            
        }
    }
	
