function IMULogin2(u){ var a = 'Status=no,scrollbars=on,resizable=yes,width=350,height=400,top=100,left=250'; window.open(u,'',a);}


//////////////////////redrain//////////////////////

function IMULogin1(u){ 

	var hWindow = aWindowManager.isRegisted(talkWith);
	if(hWindow != null){
		if(hWindow.hDialog != null && hWindow.hDialog.open && !hWindow.hDialog.closed){
			hWindow.hDialog.focus();
			return;
		}
	}
	
	var a = 'Status=no,scrollbars=on,resizable=yes,width=350,height=400,top=100,left=250'; 
	var w = window.open(u,'',a);	
	aWindowManager.RegisterWindow( talkWith, w ) ;
}


var refuseTalk = "对不起，该用户不接受对话请求";
var versionTooLow = "对不起，您的IE版本不支持此功能";


function Queue() {
    var items = new Array();
    var first = 0;
    var count = 0;
    this.Count = function() { return count; } ;
    this.Peek = function(last)
    {
        ;
        var result = null;

        if (count > 0) {
            if (null != last && true == last) {
                result = items[first + (count - 1)];
            } else {
                result = items[first];
            }
        }

        return result;
    };

    this.Enqueue = function(x)
    {
        items[first + count] = x;
        count++;
        return x;
    };

    this.Dequeue = function()
    {
        ;
        var result = null;

        if (count > 0) {
            result = items[first];
            delete items[first];
            first++;
            count--;
        }

        return result;
    };
}

function WindowInfo(f, w)
{
	this.FriendCode = f;
	this.hDialog = w;
	this.msgQueue = new Queue();
	this.isCreating = false;
	this.inAudio = false;
	this.inVideo = false;
	return this;
}

function WindowManager()
{
	this.count=0;
	this.WindowArray = new Array();
	
	this.FindDialog = function(f){
		for(var i=0;i<this.count;i++){
			if(this.WindowArray[i].FriendCode == f){
				return i;
			}
		}
		return -1;
	}

	this.RegisterWindow = function (f, w){		
		var hi = this.FindDialog(f);
		//alert("RegisterWindow : hi=" + hi);
		if(hi == -1){
			this.WindowArray[this.count] = new WindowInfo(f,w);
			this.count++;
			//alert("add:"+this.count+":"+f);
		}
		else{
			this.WindowArray[hi].hDialog = w;
			//alert("reuse:"+f);
		}
	}
	
	this.RemoveDialog = function(f){
		var hi = this.FindDialog(f);
		if(hi != -1){
			this.WindowArray[hi].hDialog = null;
			this.WindowArray[hi].isCreating = false;
			//alert("remove:"+f);
			if(this.WindowArray[hi].inAudio){
				closeAudioChannel(f);
			}
			if(this.WindowArray[hi].inVideo) {
			}
		}
	}
	
	this.isRegisted = function(f){
		var hi = this.FindDialog(f);
		if( hi != -1 ) 
			return this.WindowArray[hi];
		else 
			return null;
	}

	this.isThereAnyActive = function(){
		for(var i=0; i<this.count;i++){
			var w = this.WindowArray[i].hDialog;
			if( w != null && w.open && !w.closed) return true;
		}
		return false;
	}

	this.setInAudio = function(f, b){
		try{
			var hw = this.isRegisted(f);
			hw.inAudio = b;
		}
		catch(e){
			//alert(e);
		}
	}

	this.isInAudio = function(f){
		var inAudio = false;
		try{
			var hw = this.isRegisted(f);
			inAudio = hw.inAudio;
		}
		catch(e){
			;
		}
		return inAudio;
	}

	this.setInVideo = function(f, b){
		try{
			var hw = this.isRegisted(f);
			hw.inVideo = b;
		}
		catch(e){
			;
		}
	}

	this.isInVideo = function(f){
		var inVideo = false;
		try{
			var hw = this.isRegisted(f);
			inVideo = hw.inVideo;
		}
		catch(e){
			;
		}
		return inVideo;
	}
	
}

var aWindowManager = new WindowManager();

function closeDialog(h)
{
	if(h != null && h.open && !h.closed) {
		h.opener=null; 
		h.close();
		return true;
	}
	return false;
}

function IMULogin(u, talkWith){

        var hWindow = aWindowManager.isRegisted(talkWith);
//alert("embed.js : " + u) ;
//alert("talkwith :" + talkWith + "window: " + hWindow ) ;
        if(hWindow != null){
                if(hWindow.hDialog != null && hWindow.hDialog.open && !hWindow.hDialog.closed){
                        hWindow.hDialog.focus();
                        return;
                }
        }

       var a = 'Status=no,scrollbars=on,resizable=yes,width=350,height=400,top=100,left=250'; 
	var w = window.open(u,'',a);
        //alert("em.js :w=" + w) ;
        aWindowManager.RegisterWindow( talkWith, w ) ;
        //alert("em.js : regusterwindow ok");
}

function ReturnNumberAndLogout()
{
	do{
			//parent.friend.location.replace(PrefixURL+'chat_www/ReturnNumberAndLogout.jsp?myImuCode='+MyImuCode);
			//window.open(PrefixURL+'chat_www/ReturnNumberAndLogout.jsp','','width=1,height=1,left=5000,top=5000');
			try{
				var xmlHttp = null;
				if (window.XMLHttpRequest) {
					xmlHttp = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				var url = PrefixURL+'chat_www/ReturnNumberAndLogout.jsp?myImuCode='+myImuCode+"&referer="+vp+"&prefix="+PrefixURL+"&type=FLOAT";
				xmlHttp.open("GET", url, false);
				xmlHttp.send();					
				;
				;
				;
				;
				while(xmlHttp.readyState != 4);
				dump(xmlHttp.responseText);
			}
			catch (exception){
				;
			}
	}while(false);
	
}

function test()
{
	alert("test") ;
}

//window.onunload = ReturnNumberAndLogout;


