var winList=new Array();
function popup(url,target,w,h,callback,toolbar){
	//alert(url+'/'+w+'/'+h);
	//check to see if target window already exists
	var tmp=window.open('',target);
	try{
		if(tmp.document.body.innerHTML==''){
			if(navigator.userAgent.toLowerCase().indexOf('safari')==-1) tmp.close();
		} else {
			winList[target]=tmp;
		}
	}catch(err){}
	
	//focus on window that was found
	if(winList[target] && !winList[target].closed){
		if(callback) callback(url,target);
		else winList[target].location.href=url;
		return winList[target].focus();
	}
	
	//create a new window
	if(!w) w = 600;
	if(!h) h= 400;
	var l = (screen.width-w)/2;
	var t = (screen.height-h)/2;
	var widthHeight = "width="+w+",height="+h+",left="+l+",top="+t+",menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar="+(toolbar?'yes':'no')+",location=no";
	winList[target]=window.open(url,target,widthHeight);
	
	return true
}

function test(url,target){
	var doc = winList[target].document;
	var pjirc = doc.pjirc;
	var pos=url.indexOf('channel');
	if(pos!=-1){
		pos+=8;
		var c=url.substr(pos).split('&');
		if(c[0]) pjirc.sendString('/join #'+c[0].replace(',',',#'));
	}
}