﻿// JScript 文件
// swg，2007-9-12
// 准备对象，使用top关键字保证系统只有一份__setting
if(typeof(top.__setting)!="object") 
{ 
	top.__setting = {};
	top.__setting._values = new Array();
	top.__setting.getValue = function(AName, ADefault) { var v =this._values[AName]; if (! v) v = ADefault; return v;}
	top.__setting.setValue = function(AName, AValue) { this._values[AName] = AValue;}
	top.__setting.initValue = function(AName, AValue) {if (! this._values[AName]) this._values[AName] = AValue;}
};
var _setting = top.__setting;

_setting.initValue("popupWindowTitleImage", "popwindowimages/lefttop-17work.gif");

function RemoveAll(father)
{
	while(father.childNodes.length>0)
	{
		RemoveAll(father.childNodes[0]);
		father.removeChild(father.childNodes[0]);
	}
//    for(var i=0;i<father.childNodes.length;i++)
//    {   
//        if(father.childNodes[i].tagName!=undefined)
//        {
//            RemoveAll(father.childNodes[i]);
//            father.removeChild(father.childNodes[i]);
//        }
//    }
}

var currentLeft=-1;
var currentTop=-1;
var offsetColumn = 1;
var maxColumn = 4;
var navigateWidth = 220;

var status = 0;

function PopWindow(){

	this.MinIconHeight = 24;
	this.MinIconWidth = 160;
	this.popWindowArray={};
	this.popWindowID=0;
	
	this.popWindowCallBackArray={};

	function $(_sId){
		return document.getElementById(_sId);    
	}
	
	this.setTitle = function(_sId, title){
	
		var popDiv =$('PopWindow'+_sId);
		popDiv.title=title;
		$('PopWindowTitle'+_sId).innerHTML=title;
	
	}
	
	this.getPopWindow = function(_sId){
	
		var popDiv =$('PopWindow'+_sId);
		return popDiv;
	
	}
	
	this.popRename = function(oldName,newName)
	{
		var popDiv =$('PopWindow'+oldName);
		if (popDiv) 
		{
			popDiv.id='PopWindow'+newName;
			var popChatFrame=$('ChatFrame'+oldName);
			if (popChatFrame)
			{
				popChatFrame.id='ChatFrame'+newName;
				popChatFrame.name='ChatFrame'+newName;
			}
		}
	}
	
	this.showPopWindow = function(_sId){
	
		var popDiv =$('PopWindow'+_sId);
		if(popDiv!=null){
			popDiv.style.display='';
		}
	
	}


	this.resizePopWindow = function(_sId, width, height) {
	    var popDiv = $('PopWindow' + _sId);
	    var popDivMiddle = $('PopWindowMiddle' + _sId);

	    if (width != null) {
	        popDiv.style.width = width;
	        popDivMiddle.style.width = "100%";
	    }
	    if (height != null) {
	        popDiv.style.height = height;
	        popDivMiddle.style.height = height - 82;
	    }

	    //调整子窗口
	    if (popDivMiddle.resizePopWindow != null) {
	        popDivMiddle.resizePopWindow(width - 20, height - 82);
	    }


	}

	this.createPopWindow = function(_sId, IfHidden, width)
	{
	    status++;
	    // this.popDiv = document.createElement('<DIV style="z-index:89; width:500px;cursor:default;" onMouseDown="javascript: this.setActive();new movediv().moveStart(event,\'PopWindow'+_sId+'\');" onactivate="javascript:this.style.zIndex=900;" ondeactivate="javascript:this.style.zIndex=899;" ondblclick="javascript:popWindowObj.maxPopWindow(\''+_sId+'\');">');
	    var SelfPopWindow = this;
	    this.popDiv = document.createElement("DIV");
	    if (IfHidden) this.popDiv.style.display = 'none';
	    this.popDiv.style.zIndex = 899;
	    if (width) this.popDiv.style.width = width;
	    else this.popDiv.style.width = "500px";
	    this.popDiv.style.cursor = "default";
	    //this.popDiv.onmousedown = "javascript:this.setActive();new movediv().moveStart(event,\'PopWindow'+_sId+'\');";
	    this.popDiv.onmousedown = function()
	    {
	        this.setActive();
	        new movediv().moveStart(event, 'PopWindow' + _sId);
	    };
	    //this.popDiv.onactivate = "javascript:this.style.zIndex=900;";
	    this.popDiv.onactivate = function()
	    {
	        //alert("activate!");
	        this.style.zIndex = 900;
	    };
	    //this.popDiv.ondeactivate = "javascript:this.style.zIndex=899;";
	    this.popDiv.ondeactivate = function()
	    {
	        //alert("deactivate!");
	        this.style.zIndex = 899;
	    };
	    //this.popDiv.ondblclick="javascript:popWindowObj.maxPopWindow('xxxxxx');"
	    this.popDiv.ondblclick = function()
	    {
	        if (SelfPopWindow.popDiv.showsize != "min")
	            popWindowObj.maxPopWindow(_sId);
	        else
	            popWindowObj.restorePopWindow(_sId);
	    };
	    this.popDiv.id = "PopWindow" + _sId;
	    this.popWindowArray['PopWindow' + _sId] = this.popDiv;

	    document.body.insertBefore(this.popDiv, null);

	    var divTop = '<div  style="width:100%;height:60px;" id="PopWindowTop' + _sId + '" onMouseDown="javascript: new movediv().moveStart(event,\'PopWindow' + _sId + '\');">' +
			'<table  style="width:100%;" cellpadding=0 cellspacing=0 border=0><tr><td style="width:300px;height:33px;background:url(' + _setting.getValue('popupWindowTitleImage') + ')">' +
			 '</td>' +
			'<td style="background:url(popwindowimages/topbg-1.gif);"><div style="width:48px; height:16px; position:relative;top:-5px; float:right; ">' +
			'<img id="MinIcon" src="popwindowimages/zoomout.gif"  onclick="javascript:popWindowObj.minPopWindow(\'' + _sId + '\');" style="cursor: hand; border:0;">' +
			'<img id="MaxIcon" src="popwindowimages/zoomin.gif"  onclick="javascript:popWindowObj.maxPopWindow(\'' + _sId + '\');" style="cursor: hand; border:0;">' +
			'<img src="popwindowimages/close.gif" onclick="popWindowObj.closePopWindow(\'' + _sId + '\');" style="cursor: hand; border:0; ">' +
			'</div>' +
			'</td><td style="width:10px;height:33px;background:url(popwindowimages/righttop-1.gif)">' +
			'</td></tr></table>' +
			'<table  style="width:100%;" cellpadding=0 cellspacing=0 border=0><tr><td style="width:4px;height:27px;background:url(popwindowimages/lefttop-2.gif)">' +
			 '</td>' +
			'<td style="background:url(popwindowimages/topbg-2.gif);">' +
			'<div id="PopWindowTitle' + _sId + '" style="padding-left:4px;font-size:12px;color:#fff; cursor:default;"></div>' +
			'</td><td style="width:10px;height:27px;background:url(popwindowimages/righttop-2.gif)">' +
			'</td></tr></table>' +
			'</div>';
	    this.popDiv.innerHTML = divTop;

	    var table = '<table style="width:100%" border="0" cellpadding="0" cellspacing="0"><tr>' +
							 '<td style="width:2px;font-size:2px; background:url(popwindowimages/leftcenter.jpg);">&nbsp;</td>' +
							 '<td style="background:#EBF3F6 url(popwindowimages/border-bg.gif) repeat-x" class="border-bg" align="center">' +
							 '<table border=0 cellpadding=0 cellspacing=0>' +
							 '<tr><td width=8px>&nbsp;</td><td width="100%">' +
							 '<DIV id="PopWindowMiddle' + _sId + '" style="width:100%;padding-left:0px; padding-right:0px;" ></div>' +
							 '</td><td width=8px>&nbsp;</td></tr></table>' +
							 '</td>' +
							 '<td style="width:2px;font-size:2px; background:url(popwindowimages/rightcenter.jpg);">&nbsp;</td>' +
							 '</tr></table>';

	    //var tempDiv = document.createElement('<div id="PopWindowMiddleParent'+_sId+'" style="width:100%;">');
	    var tempDiv = document.createElement("DIV");
	    tempDiv.id = "PopWindowMiddleParent" + _sId;
	    tempDiv.style.width = "100%";
	    tempDiv.innerHTML = table;

	    this.popDiv.appendChild(tempDiv);


	    //var divBottom = document.createElement('<div style="width:100%;background-color:#EBF3F6;">');
	    var divBottom = document.createElement("DIV");
	    divBottom.style.width = "100%";
	    divBottom.style.backgroundColor = "#EBF3F6";
	    divBottom.id = "PopWindowBottom" + _sId;
	    var divBottomContent = '<table style="width:100%;height:6px;" cellpadding=0 cellspacing=0 border=0><tr>' +
		'<td style="width:2px;font-size:2px; background:url(popwindowimages/leftcenter.jpg) repeat-y;">&nbsp;</td>' +
		'<td style="font-size:2px">&nbsp;</td>' +
		'<td style="width:2px;font-size:2px; background:url(popwindowimages/rightcenter.jpg) repeat-y;">&nbsp;</td>' +
		'</tr>' +
		'</table>' +
		'<table style="width:100%;height:6px;" cellpadding=0 cellspacing=0 border=0>' +
			'<tr><td style="width:6px;height:6px;background:url(popwindowimages/leftbottom.gif);" ></td>' +
			'<td style="width:auto;font-size:6px; background:url(popwindowimages/bottombg.gif);">&nbsp;</td>' +
			'<td style="width:6px;background:url(popwindowimages/rightbottom.gif);cursor:se-resize;" onmousedown="javascript:new ResizeDiv().moveStart(event,\'' + _sId + '\'); event.cancelBubble=true;">' +
			'</td></tr></table>';
	    divBottom.innerHTML = divBottomContent;
	    this.popDiv.appendChild(divBottom);
	    this.popDiv.style.position = "absolute";
	    this.popDiv.style.left = "30%";
	    this.popDiv.style.top = "30%";
	    var divMiddleId = "PopWindowMiddle" + _sId;
	    var divMiddle = document.getElementById(divMiddleId);
	    return divMiddle; //为中间窗口


	}
	
	this.setCallBack=function(_sId,callBackFunObj)
	{
		this.popWindowCallBackArray[_sId]=callBackFunObj;
	}

	this.closePopWindow = function(_sId)
	{
	    status = 0;
	    if (this.popWindowCallBackArray[_sId] && this.popWindowCallBackArray[_sId].close)
	    {
	        if (!this.popWindowCallBackArray[_sId].close()) return;
	    }
	    if ($("PopWindow" + _sId) != null)
	    {
	        var topFrames = document.frames ? top.frames["ChatFrame" + _sId] : top.document.getElementById("ChatFrame" + _sId).contentWindow;
	        //			if(top.frames["ChatFrame"+_sId] && top.frames["ChatFrame"+_sId].myclose)
	        //			{
	        //				top.frames["ChatFrame"+_sId].myclose();
	        //			}
	        if (topFrames && topFrames.myclose)
	        {
	            topFrames.myclose();
	        }
	        var divMiddleObj = $("PopWindowMiddle" + _sId);
	        if (divMiddleObj && divMiddleObj.ClosePopWindow)
	        {
	            var isClose = divMiddleObj.ClosePopWindow();
	            if (!isClose)
	            {
	                return false;
	            }
	        }
	        //RemoveAll($("PopWindow"+_sId));        
	        if ($("ChatFrame" + _sId) != null)
	        {
	            $("PopWindowMiddle" + _sId).removeChild($("ChatFrame" + _sId));
	        }

	        $("PopWindow" + _sId).removeChild($("PopWindowTop" + _sId));
	        $("PopWindow" + _sId).removeChild($("PopWindowMiddleParent" + _sId));
	        $("PopWindow" + _sId).removeChild($("PopWindowBottom" + _sId));

	        document.body.removeChild($("PopWindow" + _sId));
	    }
	    this.popWindowArray['PopWindow' + _sId] = null;
	}

	this.hidePopWindow = function(_sId)
	{
	    if ($("PopWindow" + _sId) != null)
	    {

	        $("PopWindow" + _sId).style.display = 'none';
	        $("PopWindow" + _sId).showsize = 'hidden';
	    }
	}
	
	this.IsMin = function(_sId){
		if($("PopWindow"+_sId).showsize=="min"){
			return true;
		}else{
			return false;
		}
	}


	this.minPopWindow = function(_sId)
	{

	    var isMaxNow = ($("PopWindow" + _sId).showsize == "max");

	    $("PopWindow" + _sId).showsize = "min";

	    if (!isMaxNow)
	    {
	        $("PopWindow" + _sId).x = $("PopWindow" + _sId).style.left.substring(0, $("PopWindow" + _sId).style.left.length - 2);
	        $("PopWindow" + _sId).y = $("PopWindow" + _sId).style.top.substring(0, $("PopWindow" + _sId).style.top.length - 2);
	        $("PopWindow" + _sId).w = $("PopWindow" + _sId).offsetWidth;
	        $("PopWindow" + _sId).h = $("PopWindow" + _sId).offsetHeight;
	    }
	    else
	    {
	        $("PopWindow" + _sId).x = $("PopWindow" + _sId).x.substring(0, $("PopWindow" + _sId).x.length - 2);
	        $("PopWindow" + _sId).y = $("PopWindow" + _sId).y.substring(0, $("PopWindow" + _sId).y.length - 2);
	    }

	    var divTopContent = '<div id="PopWindowTitle' + _sId + '" ondblclick="javascript:popWindowObj.restorePopWindow(\'' + _sId + '\');" style="float:left;font-size:12px;color:#FFFFFF; padding-left:22px;padding-top:6px;cursor:default;width:110px;"></div>' +
			'<div ondblclick="javascript:popWindowObj.restorePopWindow(\'' + _sId + '\');" style="float:right; width:15px; padding-top:4px; padding-right:5px;"><img id="RestoreIcon' + _sId + '" src="popwindowimages/zoomin-btn.gif"  onclick="javascript:popWindowObj.restorePopWindow(\'' + _sId + '\');" style="cursor: hand; border:0"></div>' +
			'';
	    $("PopWindowTop" + _sId).storedHTML = $("PopWindowTop" + _sId).innerHTML;
	    $("PopWindowTop" + _sId).innerHTML = divTopContent;
	    $("PopWindowTop" + _sId).style.backgroundImage = "url(popwindowimages/zoomin-bg.gif)";
	    //$("PopWindowTop"+_sId).style.backgroundColor= "red";
	    $("PopWindowTitle" + _sId).innerHTML = $("PopWindow" + _sId).title

	    BoundTagByWidth($("PopWindowTitle" + _sId), this.MinIconWidth - 22 - 15 - 13);
	    $("PopWindowTop" + _sId).style.width = this.MinIconWidth + "px"; // this.MinIconWidth;
	    $("PopWindowTop" + _sId).style.height = this.MinIconHeight + "px";

	    $("PopWindow" + _sId).style.width = this.MinIconWidth + "px"; //$("PopWindowTop" + _sId).style.width;


	    $("PopWindowMiddleParent" + _sId).style.display = 'none';
	    $("PopWindowBottom" + _sId).style.display = 'none';
	    var xy = this.getMinPosition(_sId);
	    $("PopWindow" + _sId).style.left = xy[0] + "px";
	    $("PopWindow" + _sId).style.top = (xy[1] + 100) + "px";

	    this.updateMinIcons();
	    document.body.focus();
	}

	this.restorePopWindow = function(_sId) {

	    //alert($("PopWindow"+_sId).w);
	    //alert($("PopWindow"+_sId).h);
	    $("PopWindow" + _sId).style.width = $("PopWindow" + _sId).w + "px";
	    $("PopWindow" + _sId).style.height = $("PopWindow" + _sId).h + "px";

	    $("PopWindowTop" + _sId).style.width = "100%";
	    $("PopWindowTop" + _sId).style.height = "60px";
	    $("PopWindowTop" + _sId).style.backgroundImage = "";
	    $("PopWindowTop" + _sId).innerHTML = $("PopWindowTop" + _sId).storedHTML;
	    $("PopWindow" + _sId).style.left = $("PopWindow" + _sId).x + "px";
	    $("PopWindow" + _sId).style.top = $("PopWindow" + _sId).y + "px";
	    $("PopWindowMiddle" + _sId).style.height = $("PopWindow" + _sId).h - 73;	    
	    $("PopWindowMiddleParent" + _sId).style.display = '';
	    $("PopWindowBottom" + _sId).style.display = '';

	    $("PopWindow" + _sId).showsize = "normal";
	    $('PopWindowTitle' + _sId).innerHTML = $("PopWindow" + _sId).title;
	    $('PopWindowTitle' + _sId).style.width = "300px";
	    $('PopWindowTitle' + _sId).style.height = "33px";
	    $('PopWindowTitle' + _sId).style.backgroundImage = "url(' + _setting.getValue('popupWindowTitleImage') + ')";

	    this.resizePopWindow(_sId, $("PopWindow" + _sId).w, $("PopWindow" + _sId).h);

	    this.updateMinIcons();


	}

	this.maxPopWindow = function(_sId)
	{
	    var width;
	    var height;
	    if ($("PopWindow" + _sId).showsize != "max")
	    {

	        $("PopWindow" + _sId).showsize = "max";

	        $("PopWindow" + _sId).x = $("PopWindow" + _sId).style.left;
	        $("PopWindow" + _sId).y = $("PopWindow" + _sId).style.top;
	        $("PopWindow" + _sId).w = $("PopWindow" + _sId).offsetWidth;
	        $("PopWindow" + _sId).h = $("PopWindow" + _sId).offsetHeight;


	        width = document.body.clientWidth;
	        height = document.body.clientHeight != 0 ? document.body.clientHeight : document.documentElement.clientHeight;

	        $("PopWindow" + _sId).style.left = 0;
	        $("PopWindow" + _sId).style.top = 0;
	        $("PopWindow" + _sId).style.width = width;
	        $("PopWindow" + _sId).style.height = height;
	        $("PopWindowMiddle" + _sId).style.height = height - 73;


	    } else
	    {

	        $("PopWindow" + _sId).showsize = "normal";

	        width = $("PopWindow" + _sId).w;
	        height = $("PopWindow" + _sId).h;
	        $("PopWindow" + _sId).style.width = width;
	        $("PopWindow" + _sId).style.height = height;
	        $("PopWindow" + _sId).style.left = $("PopWindow" + _sId).x;
	        $("PopWindow" + _sId).style.top = $("PopWindow" + _sId).y;
	        $("PopWindowMiddle" + _sId).style.height = $("PopWindow" + _sId).h - 73;

	    }
	    this.resizePopWindow(_sId, width, height);
	}

	this.updateMinIcons = function() {

	    var posObj = getMinWindowPosition();
	    var x = posObj.Left;
	    var y = posObj.Bottom;

	    for (var e in this.popWindowArray) {
	        if (this.popWindowArray[e] != null) {
	            if ((this.popWindowArray[e].showsize == "min")) {

	                //设置最小化图标新位置
	                this.popWindowArray[e].style.left = x;

	                this.popWindowArray[e].style.top = y + this.MinIconHeight;
	              
	                x += this.MinIconWidth;
	                if (x + this.MinIconWidth > posObj.Right) {//本行放不下则往上放一行
	                    x = posObj.Left;
	                    y = y + this.MinIconHeight;
	                   
	                }
	            }
	        }
	    }
	}
	
   this.getMinPosition =function(_sId){
		var posObj =getMinWindowPosition();
		var x=posObj.Left+2;
		var y=posObj.Bottom-this.MinIconHeight;
		for(var e in this.popWindowArray){
			if(this.popWindowArray[e]!=null){
				if((this.popWindowArray[e].showsize=="min")&&e!='PopWindow'+_sId){
					x +=this.MinIconWidth+2;
					if(x>posObj.Right){//本行放不下则往上放一行
						x =posObj.Left+2;
						y = y- this.MinIconHeight-2;
					
					}
				}
			}
		
		}
		return [x,y];
	
   
   
   } 
	
	
	 //层初始化位置
   this.divInit = function(_sId, int1, int2) {
       _sId = "PopWindow" + _sId;
       document.getElementById(_sId)['style']['display'] = '';
       document.getElementById(_sId)['style']['position'] = "absolute";
       var left;
       var top;
       if (currentLeft == -1) {
           currentLeft = document.body.clientWidth / maxColumn;
       } else {
           currentLeft += 30;
       }


       if (currentTop == -1) {
           currentTop = document.body.scrollTop + 30;
       } else {
           currentTop += 30;
       }

       if (currentLeft + document.getElementById(_sId).offsetWidth > document.body.clientWidth
			|| currentTop + document.getElementById(_sId).offsetHeight > document.body.clientHeight) {
           offsetColumn = (offsetColumn + 1) % maxColumn;
           var rnd = Math.random() * 100;
           rnd = parseInt(rnd, 10);
           currentLeft = parseInt((document.body.clientWidth - document.getElementById(_sId).offsetWidth) * offsetColumn / maxColumn, 10) + rnd;
           if (currentLeft < navigateWidth) {
               currentLeft += navigateWidth;
           }
           currentLeft = currentLeft % document.body.clientWidth;
           currentTop = document.body.scrollTop + 30;
       }
       left = currentLeft;
       top = currentTop;

       document.getElementById(_sId)['style']['left'] = (left > 0 ? left : 5) + "px";
       document.getElementById(_sId)['style']['top'] = (top > 0 ? top : 5) + "px";
   }
}

 function movediv(){
	function $(_sId){
		return document.getElementById(_sId);
	}
	this.moveStart = function(event, _sId) {
	    var oObj = $(_sId);
	    oObj.onmousemove = mousemove;
	    oObj.onmouseup = mouseup;
	    oObj.setCapture ? oObj.setCapture() : function() { if (window.captureEvents) { alert('cap'); window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP); } };
	    var oEvent = event ? event : window.event;
	    //var tempClientX = oEvent.clientX ? oEvent.clientX : oEvent.pageX;
	    //var tempClientY = oEvent.clientY ? oEvent.clientY : oEvent.pageY;

	    var tempClientX = getEvtClientX(oEvent);
	    var tempClientY = getEvtClientY(oEvent);
	   
	    var dragData = { x: tempClientX, y: tempClientY };
	    var backData = { x: parseInt(oObj.style.top), y: parseInt(oObj.style.left) };

	    function mousemove(evt) {
	        //evt = evt ? evt : (window.event ? window.event : null);
	        //var tempClientX = evt.pageX ? evt.pageX : evt.clientX;
	        //var tempClientY = evt.pageY ? evtpageY. : evt.clientY;
	        var tempClientX = getEvtClientX(evt);
	        var tempClientY = getEvtClientY(evt);
	        var iLeft = tempClientX - dragData["x"] + parseInt(oObj.style.left);
	        var iTop = tempClientY - dragData["y"] + parseInt(oObj.style.top);
	        oObj.style.left = iLeft + "px";
	        oObj.style.top = iTop + "px";
	        dragData = { x: tempClientX, y: tempClientY };
	    }

	    function mouseup(evt) {
	        //evt = evt ? evt : (window.event ? window.event : null);
	        //var tempClientX = evt.clientX ? evt.clientX : evt.pageX;
	        //var tempClientY = evt.clientY ? evt.clientY : evt.pageY;
	        var tempClientX = getEvtClientX(evt);
	        var tempClientY = getEvtClientY(evt);
	        oObj.onmousemove = null;
	        oObj.onmouseup = null;
	        if (tempClientX < 1 || tempClientY < 1 || tempClientX > document.body.clientWidth || tempClientY > document.body.clientHeight) {
	            oObj.style.left = backData.y + "px";
	            oObj.style.top = backData.x + "px";
	        }
	        oObj.releaseCapture ? oObj.releaseCapture() : function() { if (window.releaseEvents) { alert('rel'); window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP) } };
	    }
	}	
 }
 
 
//var popWindowObj =new PopWindow();///???
if (typeof(top.popWindowObj)!="object")
{
	top.popWindowObj=new PopWindow();     
}
var popWindowObj=top.popWindowObj;

  function ResizeDiv(){
	function $(_sId){
		return document.getElementById(_sId);
	}
	this.moveStart = function (event, _sId){
		var oObj = $('PopWindow'+_sId);
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		
		// if firefox or opera ... return  ...  
        if(!oObj.setCapture) 
        {
            return;
        }
		oObj.setCapture ? oObj.setCapture() : function(){if(window.captureEvents){window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP)}};
		var oEvent = window.event ? window.event : event;
		//var tempClientX = oEvent.clientX ? oEvent.clientX : oEvent.  pageX;
		//var tempClientY = oEvent.clientY ? oEvent.clientY : oEvent.pageY;
		var tempClientX = getEvtClientX(oEvent);
		var tempClientY = getEvtClientY(oEvent);
		var dragData = {x : tempClientX, y : tempClientY};
		var backData = {x : parseInt(oObj.clientWidth), y : parseInt(oObj.clientHeight)};

		function mousemove(evt)
		{
			evt = evt ? evt : (window.event ? window.event : null);
			//var tempClientX = evt.clientX ? evt.clientX : evt.pageX;
		    //var tempClientY = evt.clientY ? evt.clientY : evt.pageY;
		    var tempClientX = getEvtClientX(evt);
		    var tempClientY = getEvtClientY(evt);
			var width = tempClientX - dragData["x"] + backData.x;
			var height = tempClientY - dragData["y"] + backData.y;
			popWindowObj.resizePopWindow(_sId, width,height);
			backData = {x : parseInt(oObj.clientWidth), y : parseInt(oObj.clientHeight)};
			dragData = {x: tempClientX, y: tempClientY};			
		}
//		function mouseup(){
//			var oEvent = window.event ? window.event : event;
//			oObj.onmousemove = null;
//			oObj.onmouseup = null;
//			if(oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > document.body.clientWidth || oEvent.clientY > document.body.clientHeight){
//				
//                popWindowObj.resizePopWindow(_sId, backData.x,backData.y);
//			}
//			oObj.releaseCapture ? oObj.releaseCapture() : function(){};
//		}
	   function mouseup(evt)
	   {
			evt = evt ? evt : (window.event ? window.event : null);
			//var tempClientX = evt.clientX ? evt.clientX : evt.pageX;
		    //var tempClientY = evt.clientY ? evt.clientY : evt.pageY;
		    
		    var tempClientX = getEvtClientX(evt);
		    var tempClientY = getEvtClientY(evt);
		    
			oObj.onmousemove = null;
			oObj.onmouseup = null;
			if(tempClientX < 1 || tempClientY < 1 || tempClientX > document.body.clientWidth || tempClientY > document.body.clientHeight)
			{	
				popWindowObj.resizePopWindow(_sId, backData.x,backData.y);
			}
			oObj.releaseCapture ? oObj.releaseCapture() : function(){if(window.releaseEvents){window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP)}};
		}
	}	
 }
 
function OpenHidePopWindow(winname,url,title,width,height){
	OpenPopWindow(winname,url,title,width,height);
	popWindowObj.hidePopWindow(winname);

}

function OpenPopWindow(winname,url,title,width,height){
	
	 if(popWindowObj.getPopWindow(winname)!=null){
			if(popWindowObj.getPopWindow(winname).style.display=='none'){
				popWindowObj.showPopWindow(winname);
			
			}else if(popWindowObj.getPopWindow(winname).showsize=="min"){
				popWindowObj.restorePopWindow(winname);
			}
			
		
		}else{
		
			var popWindow = popWindowObj.createPopWindow(winname);
		  //  var chatFrame = document.createElement('<IFRAME frameBorder="0" style="background-color:#FFFFFF;z-index:999;font-size:12px;text-align:center;border:solid 1px #BED6E0;">');
			var chatFrame = document.createElement("IFRAME");
			chatFrame.frameBorder = "0";
			chatFrame.style.backgroundColor = "#FFFFFF";
			chatFrame.style.zIndex = "899";
			//chatFrame.style.fontSize
			chatFrame.style.borderStyle = "solid";
			chatFrame.style.borderWidth = "1px";
			chatFrame.style.borderColor = "#BED6E0";
			chatFrame.id='ChatFrame'+winname;
			chatFrame.name = 'ChatFrame' + winname;
			if(width!=null)
			{
				chatFrame.width=width;
			
			}else{
				chatFrame.width="100%";
			}
			if(height!=null){
				chatFrame.height=height;
			}
			chatFrame.style.display = "block";
			if (url.indexOf("?") > 0)
			    url += "&winname=" + winname;
			else
			    url += "?winname=" + winname;
			chatFrame.src=url;
			
			popWindow.appendChild(chatFrame);
			popWindow.resizePopWindow = function(width, height) {
			    chatFrame.style.width = (width > 0 ? width : 0) + "px";
			    chatFrame.style.height = (height > 0 ? height : 0) + "px";
			}
			popWindowObj.divInit(winname,0,0);
			popWindowObj.setTitle(winname,title);
			popWindowObj.resizePopWindow(winname, width+22,height+82);
		}
		window.focus();
		return false;
}


function ClosePopWindow(winname)
{
	//document.getElementById("testinput").focus();
	popWindowObj.closePopWindow(winname);
}

function ResizePopWindow(winname, width, height){
	popWindowObj.divInit(winname,0,0);
	popWindowObj.setTitle(winname,title);
	popWindowObj.resizePopWindow(winname, width,height);
}


function OpenPopWindow2(winname,title, width, height){
	
	if(popWindowObj.getPopWindow(winname)!=null){
			if(popWindowObj.getPopWindow(winname).style.display=='none'){
				popWindowObj.showPopWindow(winname);
			
			}else if(popWindowObj.getPopWindow(winname).showsize=="min"){
				popWindowObj.restorePopWindow(winname);
			}
			popWindowObj.getPopWindow(winname).setActive();
			return null;
			
		
		}else{
		
			var popWindow = popWindowObj.createPopWindow(winname);
			
			return popWindow;
			
		}
}

function RefreshPopWindow(winname)
{

    var popwin = document.getElementById("ChatFrame" + winname);
    if (popwin != null) popwin = popwin.contentWindow;
    
    if(popwin != null)
    {
		if(popwin.myreload != null)
		{
			popwin.myreload();
		}
		else
		{
			popwin.location.reload();
		}
    }  
}

