// JavaScript Document
var topX = (document.documentElement.clientWidth-10) / 2 + "px";   //设置X坐标的初始值
var topY = (document.documentElement.clientHeight-10) / 2 + "px";  //设置Y坐标的初始值

//获得鼠标位置
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 mouseMove(ev){    
    ev = ev || window.event;
    var mousePos = mousePosition(ev);
	topX = mousePos.x;
	topY = mousePos.y;
}

//获得对象
function $()
{
   return document.getElementById?document.getElementById(arguments[0]):eval(arguments[0]);
}

//关闭DIV
function closeDiv(obj)
{
   $(obj).style.display='none';
}
//显示DIV
function OpenCloseDiv(obj)
{
   //alert($(obj).style.display);
   if($(obj).style.display=='')
   {
      $(obj).style.display='none';  
   }
   else
   {
      $(obj).style.display='';
   }  
}

//弹出DIV层
var OverH,OverW,ChangeDesc,ChangeH=50,ChangeW=50;
function OpenDiv(ev,_Dw,_Dh,_Desc,Div_name)
{
	callServer(_Desc);	
	/*	
   $("Loading").innerHTML="<span class='red'>Loading...</span>";
   OverH=_Dh;
   OverW=_Dw;
   ChangeDesc=_Desc;
   $("Loading").style.display='';
   
   if(_Dw > _Dh)
   {
      ChangeH = Math.ceil((_Dh-10)/((_Dw-10)/50))
   }
   else if(_Dw < _Dh)
   {
      ChangeW = Math.ceil((_Dw-10)/((_Dh-10)/50))
   }
   
   mouseMove(ev);
   //alert("x:" + topX + "y:" + topY);
   $("Loading").style.top = (topY - 100) + "px";
   $("Loading").style.left = (topX -100) + "px";
   OpenNow()*/
}

//动态显示DIV
var Nw = 10,Nh = 10;
function OpenNow()
{
   if (Nw > OverW - ChangeW)ChangeW = 2;
   if (Nh > OverH - ChangeH)ChangeH = 2;
   Nw = Nw + ChangeW;
   Nh = Nh + ChangeH;
   if(OverW > Nw||OverH > Nh)
   {
      if(OverW > Nw)
	  {
         $("Loading").style.width = Nw + "px";
         //$("Loading").style.left = 100 + "px";
      }
      if(OverH>Nh)
      {
         $("Loading").style.height = Nh + "px";
         //$("Loading").style.top = 100 + "px"
      }
      window.setTimeout("OpenNow()",10)
   }
   else
   {
      Nw=10;Nh=10;ChangeH=50;ChangeW=50;
      AjaxGet(ChangeDesc)
   }
}

//创建XML对象
function createXMLHttps()
{
   var ret = null;
   try
   {
      ret = new ActiveXObject('Msxml2.XMLHTTP')
   }
   catch (e)
   {
      try
	  {
	     ret = new ActiveXObject('Microsoft.XMLHTTP')
	  }
	  catch (ee)
	  {
	     ret = null
	  }
   }
   if (!ret&&typeof XMLHttpRequest !='undefined') ret = new XMLHttpRequest();
   return ret;
}

//执行AJAX
function AjaxGet(URL)
{
   URL = URL + "?i="  + new Date().getTime();
   var xmlhttp = createXMLHttps();
   xmlhttp.open("get",URL,true);
   //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   xmlhttp.onreadystatechange = function()
   {
      if (xmlhttp.readyState == 4 && xmlhttp.status==404) 
	  {
	     $("Loading").innerHTML='读取页面失败,文件'+URL+'不存在!';
		 return
	  }
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
	  {
         $("Loading").innerHTML = "<div class='LoadContent'>" + xmlhttp.responseText + "</div>";
      }
   }
   xmlhttp.send(null);
}



function AjaxGet2(URL)
{
   URL = URL + "?i="  + new Date().getTime();
   var xmlhttp = createXMLHttps();
   xmlhttp.open("get",URL,true);
   //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   xmlhttp.onreadystatechange = function()
   {
      if (xmlhttp.readyState == 4 && xmlhttp.status==404) 
	  {
	     $("floatDiv").innerHTML='<div class="FFFFFF"><a href="javascript:CloseFloatDiv();" style="color:Red;">关闭</a><br />' + '读取页面失败,文件'+URL+'不存在!</div>';
		 return
	  }
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
	  {
         $("floatDiv").innerHTML = '<div class="pclass"><div class="pclass2"><a href="javascript:CloseFloatDiv();" style="color:Red;">关闭</a><br /></div>' + xmlhttp.responseText + '<br /></div>';
      }
   }
   xmlhttp.send(null);
}


//////////////////////////////////////////////////////////////////////////
function callServer(letter)
{
       var url=letter;
       Login(true,url);
}

function $(elem)
{
   return document.getElementById(elem);
}
function Login(isbackDiv,url)
{
   //alert(url);
   var a = 0;
   var b = 0;
   var c = 0;
   var d = 0;
   
   a = 500;
   b = 600;
   c = 180;
   d = 230;
             if($('floatDiv')==null)
             {
                var floatDiv = document.createElement('div');
                floatDiv.id = "floatDiv"; 
                floatDiv.style.position = "absolute";
                floatDiv.style.width = a + "px";
                floatDiv.style.height = b + "px";
                floatDiv.style.left =(document.documentElement.clientWidth/2 + document.documentElement.scrollLeft - c)+"px";
                floatDiv.style.top =(document.documentElement.clientHeight/2 + document.documentElement.scrollTop - d)+"px";
                floatDiv.style.zIndex  = 2001;
                floatDiv.innerHTML = "<span class='red'>Loading。。。</span>";
				
                //var loginText = "<iframe id=\"iframe1\" frameborder=\"0\" scrolling=\"auto\" src=\"http://192.168.1.106:100/" + url + "\" width=\"100%\" height='" + b + "'></iframe>";
                //floatDiv.innerHTML = loginText;
                document.body.appendChild(floatDiv);
             }
             else
             {
                $('floatDiv').style.display = "block";
                document.body.removeChild(document.getElementById("floatDiv"));
                var floatDiv = document.createElement('div');
                floatDiv.id = "floatDiv"; 
                floatDiv.style.position = "absolute";
                floatDiv.style.width = a + "px";
                floatDiv.style.height = b + "px";
                floatDiv.style.left =(document.documentElement.clientWidth/2 + document.documentElement.scrollLeft - c)+"px";
                floatDiv.style.top =(document.documentElement.clientHeight/2 + document.documentElement.scrollTop - d)+"px";
                floatDiv.style.zIndex  = 1001;
                floatDiv.innerHTML = "Loading。。。";
				//AjaxGet2(url);
                //var loginText = "<iframe id=\"iframe1\" frameborder=\"0\" scrolling=\"auto\" src=\"http://192.168.1.106:100/" + url + "\" width=\"100%\" height='" + b + "'></iframe>";
                //floatDiv.innerHTML = loginText;
                document.body.appendChild(floatDiv);
             }
             if($('backDiv')==null && isbackDiv ==true)
             {
                var backDiv = document.createElement('div');
                backDiv.id = "backDiv";
                backDiv.style.backgroundColor = "Black";
                backDiv.style.filter = "alpha(opacity=70)";
                backDiv.style.MozOpacity = "0.70";
                backDiv.style.position = "absolute";
                backDiv.style.left = "0px";
                backDiv.style.top = "0px";
                backDiv.style.width = Math.max(document.body.scrollWidth, document.documentElement.clientWidth) +"px";
                backDiv.style.height = Math.max(document.body.scrollHeight, document.documentElement.clientHeight)+"px";
                document.body.appendChild(backDiv);
                $('backDiv').style.zIndex = 1000;
             }
             else if(isbackDiv ==true)
             {
                $('backDiv').style.display = "block";
             }
			 AjaxGet2(url);
}
function moveDiv(event, elem)
{
            $('floatDiv').style.filter = "alpha(opacity=50)";
            var oObj = $(elem); 
            oObj.onmousemove = mousemove;
            oObj.onmouseup = mouseup;
            oObj.setCapture ? oObj.setCapture() : function(){};
            oEvent = window.event ? window.event : event;
            var dragData = {x : oEvent.clientX, y : oEvent.clientY};
            var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
          function mousemove()
          {
            var oEvent = window.event ? window.event : event;
            var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
            var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
            oObj.style.left = iLeft;
            oObj.style.top = iTop;
            dragData = {x: oEvent.clientX, y: oEvent.clientY};
          }
          function mouseup()
          {
            var oEvent = window.event ? window.event : event;
            oObj.onmousemove = null;
            oObj.onmouseup = null;
            $('floatDiv').style.filter = "";
            if(oEvent.clientX < 1 || oEvent.clientY < 1)
            {
              oObj.style.left = backData.y;
              oObj.style.top = backData.x;
            }
              oObj.releaseCapture ? oObj.releaseCapture() : function(){};
           }
}
function CloseFloatDiv()
{
            $('floatDiv').style.display = "none";
            if($('backDiv'))
            {
              $('backDiv').style.display = "none";
            }			
}