﻿var d=document;
var dGetID = new Function('obj','return document.getElementById(obj);');
var isIe=(d.all)?true:false;
function setSelectState(state)
{
var objl=d.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 + d.body.scrollLeft - d.body.clientLeft,y:ev.clientY + d.body.scrollTop - d.body.clientTop
};
}
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(d.getElementById('back')!=null)
	{
	d.getElementById('back').parentNode.removeChild(d.getElementById('back'));
	}
	if(document.getElementById('mesWindow')!=null)
    {
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }
if(isIe){
setSelectState('');}
}
var m_width,m_height;
function popupDialog(id,title,content,width,height)
{
	var objDiv = d.createElement("div");
	objDiv.id= id;
	var cLeft= d.body.clientWidth / 2 -(width/2);
	var cTop = d.body.clientHeight / 2 -(height/2) < 200 ?200:d.body.clientHeight / 2 -(height/2);
	objDiv.innerHTML = "<div id=\""+id+"Div\" style=\"position:absolute; left:"+cLeft+"px;top:"+cTop+"px; border:1px solid #ccc; width:"+width+"px; height:"+height+"px; z-index:12; background-color:#FFFFFF;\"><div class=\"DialogHand\"><div class=\"DialogTitle_left\" onmousedown=\"StartMove(this,'"+id+"Div',"+width+","+height+")\">"+title+"</div><div class=\"DialogTitle_right\"><a href=\"javascript:;\" onclick=\"remove_Div('"+id+"')\">×</a></div></div><div style=\"text-align:center;clear:both;\">"+content+"</div></div>";
	m_width = width;
	m_height = height;
	d.body.appendChild(objDiv);
}


function popupLoadLayer()
{
	var obj = d.createElement("div");
	obj.id="obj";
	obj.innerHTML = "<div id=\"loadDiv\" style=\"left: 53%; top: 47%;\"><img src=\"http://www.99pan.com/images/files/loading.gif\" alt=\"\"/> &nbsp;正在提交，请稍侯...</div>";
	d.body.appendChild(obj);
}


function getEvent() {
    return window.event || arguments.callee.caller.arguments[0];
}

function closeSetTimeout(r)
{
	clearTimeout(r);
}

var requestSetTime;
function malert(title)
{
	if(dGetID("alertObj") != null)
	{
		d.body.removeChild(dGetID("alertObj"));
		closeSetTimeout(requestSetTime);
	}
	var obj = d.createElement("div");
	obj.id="alertObj";
	obj.innerHTML = "<div id=\"malert\">"+title+"</div>";
	var cLeft= d.body.clientWidth / 2;
	var cTop = d.body.clientHeight / 2 < 200 ?200:d.body.clientHeight / 2;
	d.body.appendChild(obj);
	dGetID("malert").style.left = cLeft+"px";
	dGetID("malert").style.top = cTop+"px";
	requestSetTime = setTimeout(function()
	{
		dGetID("malert").style.display = "none";
	},2000);
}


function StartMove(obj,objDiv, w, h) {
    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;
    var doMoveEvent = document.onmousemove;
    var doUpEvent = document.onmouseup;
    objDiv = dGetID(objDiv);
    obj.onmousedown = function() {
        var evt = getEvent();
        moveBool = true;
        moveX = evt.clientX;
        moveY = evt.clientY;
        moveTop = parseInt(objDiv.style.top);
        moveLeft = parseInt(objDiv.style.left);
		
        document.onmousemove = function(){
            if (moveBool) {
                var evt = getEvent();
                var x = moveLeft + evt.clientX - moveX;
                var y = moveTop + evt.clientY - moveY;
				objDiv.style.left = x + "px";
				objDiv.style.top = y + "px";
            }
        };
        document.onmouseup = function() {
            if (moveBool) {
                document.onmousemove = doMoveEvent;
                document.onmouseup = doUpEvent;
                moveBool = false;
                moveX = 0;
                moveY = 0;
                moveTop = 0;
                moveLeft = 0;
            }
        };
    }
}
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);
}