﻿var EventUtil = new Object;
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};
        
EventUtil.removeEventHandler = function (oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else { 
        oTarget["on" + sEventType] = null;
    }
};

EventUtil.formatEvent = function (oEvent) {
    if (document.all) {
        oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
        oEvent.eventPhase = 2;
        oEvent.isChar = (oEvent.charCode > 0);
        oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
        oEvent.pageY = oEvent.clientY + document.body.scrollTop;
        oEvent.preventDefault = function () {
            this.returnValue = false;
        };

        if (oEvent.type == "mouseout") {
            oEvent.relatedTarget = oEvent.toElement;
        } else if (oEvent.type == "mouseover") {
            oEvent.relatedTarget = oEvent.fromElement;
        }

        oEvent.stopPropagation = function () {
            this.cancelBubble = true;
        };

        oEvent.target = oEvent.srcElement;
        oEvent.time = (new Date).getTime();
    }
    return oEvent;
};

EventUtil.getEvent = function() {
    if (window.event) {
        return this.formatEvent(window.event);
    } else {
        return EventUtil.getEvent.caller.arguments[0];
    }
};



 //移动层；
    var iDiffX = 0;
    var iDiffY = 0;               
    function handleMouseMove() {
        var oEvent = EventUtil.getEvent();       
        var oDiv = document.getElementById("divIframe"); 
        oDiv.style.left = oEvent.clientX-iDiffX + "px" ;
        oDiv.style.top = oEvent.clientY- iDiffY + "px";
    }
               
    function handleMouseDown() {
        var oEvent = EventUtil.getEvent();
        var oDiv = document.getElementById("divIframe");       
        iDiffX = oEvent.clientX - oDiv.offsetLeft;
        iDiffY = oEvent.clientY - oDiv.offsetTop; 
        EventUtil.addEventHandler(document.body, "mousemove", handleMouseMove);               
        EventUtil.addEventHandler(document.body, "mouseup", handleMouseUp);        
    }
    
    function handleMouseUp() {
        EventUtil.removeEventHandler(document.body, "mousemove", handleMouseMove);              
        EventUtil.removeEventHandler(document.body, "mouseup", handleMouseUp);
    }
    
    
    
    //首页
function widLoginWelcome(url,widWidth,widHeight, userId) // 相对路径
{ 
    SetDefineModuleIsShow('none');
	//record 
    var hideiframe = document.createElement('iframe');
    hideiframe.name = 'GarnishCount';
    hideiframe.id = 'GarnishCount';
    hideiframe.style.width=0;
    hideiframe.style.hight=0;
    hideiframe.style.top = '20px';
	hideiframe.style.left ='0px';
	
    hideiframe.src= "/UserControls/GarnishCount.aspx?userid=" + userId;
    document.body.appendChild(hideiframe);
    document.getElementById("GarnishCount").style.display = "none";
  window.scrollTo(0, 0);
  var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	var height = document.documentElement.clientHeight + document.documentElement.scrollTop;

  var layer = document.createElement('div');
  layer.style.zIndex = 22;
  layer.id = 'layer';
  layer.style.position = 'absolute';
  layer.style.top = '0px';
  layer.style.left = '0px';
  layer.style.height = document.documentElement.scrollHeight + 'px'; //window.screen.availHeight; 
  layer.style.width = width + 'px';
  layer.style.backgroundColor = 'black';
  layer.style.opacity = '.4';
  layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=40)");
  document.body.style.position = 'static';
  document.body.appendChild(layer);  
  
  var size = { 'height': widHeight, 'width': widWidth };
  var divIframe = document.createElement('div');
  divIframe.id = 'divIframe';
  divIframe.style.position = 'absolute'
  divIframe.style.zIndex = 32;
  var top = ((height + document.documentElement.scrollTop) / 2) - (size.height / 2) ;
	if(top <0){
	    top = 0;
 }
 divIframe.style.top = top + 'px';
  //divIframe.style.top =  ((height + document.documentElement.scrollTop) / 2) - (size.height / 2) + 'px';
  divIframe.style.left = (width / 2) - (size.width / 2) + 'px';
  
  divIframe.style.width = size.width + 'px';
  divIframe.style.height = '524px';
  divIframe.style.backgroundColor = 'transparent';  
  
  if(document.all){  
    divIframe.onmousedown  = function() {
        handleMouseDown(event);
    }
  
  }else{
    divIframe.setAttribute("onmousedown","handleMouseDown(event)");
  }
  //iframe
   var iframe = document.createElement('iframe');
    iframe.name = 'WidgetEditor';
    iframe.id = 'WidgetEditor';
	iframe.src = url + "&d=" + (new Date()).getTime();
	iframe.style.height = size.height + 'px';
	iframe.style.width = size.width + 'px';
	iframe.style.position = 'absolute';
	iframe.style.zIndex = 33;
	iframe.style.backgroundColor = 'transparent';
	iframe.allowTransparency = 'true';
	iframe.style.border = '0';
	iframe.frameborder = '0';	
	
	iframe.style.top = '42px';
	iframe.style.left ='0px';
	
	iframe.setAttribute("frameborder", "0", 0); 
	divIframe.innerHTML ="<div class='Landing-top' id='DivTitle' style='font-size:14px;height:27px;cursor:move;border:7px solid #808080;border-bottom:none;font-weight:bold;padding:9px 0 0 15px;'><span></span>选择空间风格和装饰</div><div id='dataLoading' style='border:7px solid #808080;border-top:none;padding:10px;background:#fff;text-align:center;'><img  src='http://si.yaolanimage.cn/images/loading.gif' alt=''/><br/><br/>加载中...</div>";
		
	document.body.appendChild(divIframe);
	document.getElementById("divIframe").appendChild(iframe);
}

function closeDiv()
{
    document.body.removeChild(document.getElementById('divIframe'));
 // document.body.removeChild(document.getElementById('WidgetEditor'));
  document.body.removeChild(document.getElementById('layer'));
  document.body.style.position = '';
}
