isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

var offsetX;
var offsetY;
var nowX;
var nowY;
var cfnLayer;


function ddInit(e){
  topElement=isIE ? "BODY" : "HTML";
  cfnLayer=isIE ? document.all.layer_cfn_window : document.getElementById("layer_cfn_window");  
  hotLayer=isIE ? event.srcElement : e.target;  
  while (hotLayer.id!="cfn_titleBar"&&hotLayer.tagName!=topElement){
    hotLayer=isIE ? hotLayer.parentElement : hotLayer.parentNode;
  }  
  if (hotLayer.id=="cfn_titleBar"){
    offsetX=isIE ? event.clientX : e.clientX;
    offsetY=isIE ? event.clientY : e.clientY;
    nowX=parseInt(cfnLayer.style.left);
    nowY=parseInt(cfnLayer.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  cfnLayer.style.left=(isIE ? nowX+event.clientX-offsetX : nowX+e.clientX-offsetX) + 'px'; 
  cfnLayer.style.top=(isIE ? nowY+event.clientY-offsetY : nowY+e.clientY-offsetY) + 'px';
  return false;  
}

function ddN4(whatLayer){
  if (!isN4) return;
  N4=eval(whatLayer);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function centerLayer(whatLayer) {
	whatLayer.style.width = '340px';
	whatLayer.style.height = '214px';
	var windowWidth = isIE ? (document.documentElement.clientWidth > 0 ? document.documentElement.clientWidth : document.body.clientWidth) : window.innerWidth;
	var windowHeight = isIE ? (document.documentElement.clientHeight > 0 ? document.documentElement.clientHeight : document.body.clientHeight) : window.innerHeight;
	whatLayer.style.top = (windowHeight - parseInt(whatLayer.style.height)) / 2 + document.body.scrollTop + 'px';
	whatLayer.style.left = (windowWidth - parseInt(whatLayer.style.width)) / 2 + 'px';
}				

function hideCFN(){
  if (isIE||isNN) cfnLayer.style.visibility="hidden";
  else if (isN4) document.layer_cfn_window.visibility="hide";
}

function showCFN(){
  centerLayer(cfnLayer);
  if (isIE||isNN) {
  	cfnLayer.style.visibility="visible";
  } else if (isN4) {
  	document.layer_cfn_window.visibility="show";
  }
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");
