PopUpWindowClass = function(){
	this.init();
}

PopUpWindowClass.prototype.init = function(){
	this.popupArray = new Array();
}

/*PopUpWindowClass.prototype.addWindows = function(winName){
	if(winName){
		this.popupArray.push(winName);
	}
}

PopUpWindowClass.prototype.killWindows = function(winName){
	var temp = this.popupArray;
	var tempName = winName;
	tempName = tempName.split(",");
	if(temp.length > 1){
		for(var count=0; count<tempName.length; count++){
			for(var count2=0; count<temp.length; count2++){
				if(tempName[count] == temp[count2]){
					this.closeWindow(temp[count2]);
					temp = temp.slice(count2,count2);

				}
			}
		}
	}
	this.popupArray = temp;
}
*/
PopUpWindowClass.prototype.closeWindow = function(winName){
	var tempWinName = winName;
	if(!tempWinName.closed){
		tempWinName.close();
	}
}

PopUpWindowClass.prototype.setFocus = function(winName){
	var tempWinName = winName;
	tempWinName.focus();
}

PopUpWindowClass.prototype.setBlur = function(winName){
	var tempWinName = winName;
	tempWinName.blur();
}

PopUpWindowClass.prototype.openWindow = function(winName, URLStr, left, top, width, height, focusIt, html){
	var tempWinName = winName;
	var styles = "<style type='text/css'><!--@import url(/nppd_styles/master_style.css);@import url(/nppd_styles/content.css);--></style>";
	var tempDelim = new RegExp("_", ["g"]);
	var title = tempWinName.replace(tempDelim, " ");
	this.openIt = function(){
		window[tempWinName] = open(URLStr, winName, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
		if(html != null){
			window[tempWinName].document.write("<HTML><HEAD>"+styles+"<TITLE>"+title+"</TITLE></HEAD>"+html+"</HTML>");
		}
		if(focusIt == "up"){
			this.setFocus(window[tempWinName]);
		}else if(focusIt == "under"){
			this.setBlur(window[tempWinName]);
		}
	}
	this.closeIt = function(){
		this.closeWindow(window[tempWinName]);
	}
	switch (window[tempWinName]) {
	case null: 
		this.openIt();
  		break
	case undefined: 
		this.openIt();
 		break
	default:
		if(window[tempWinName].closed){
			this.openIt();
		}else{
			this.closeIt();
			window[tempWinName] = null;
		}
	}
}

//nppdPopUpWin.openWindow(name, url, left, top, width, height, focus["up","under","blank"], html);
//nppdPopUpWin.setFocus(name);
//nppdPopUpWin.setBlur(name);
//nppdPopUpWin.closeWindow(name);
nppdPopUpWin = new PopUpWindowClass();

