/**************************************************************************************
  Description: Class related to content popups
		 Author: Roarke Lynch
		   Date: 20-Apr-05
		  Notes: none
 Dependencies: none
**************************************************************************************/

/* Constructor */
Popup = function(url, name, width, height) {
	this.url = url;
	this.name = name;
	this.width = width;
	this.height = height;
	this.params = new Object();
}

/* Class Methods */
Popup.show = function(url, name, width, height) {
	var thePopup = new Popup(url, name, width, height);
	thePopup.show();
}

Popup.showQuiz = function(quizId) {
	var thePopup = new Popup("http://www.netsmartz.org/services/NSXMLQuizPage/QuizRequest.aspx", "NetSmartz_Quiz", 800, 600);
	
	thePopup.setScrollbars("yes");
	thePopup.setParam("quiz", quizId);
	thePopup.show();
};

/* Instance Methods */
Popup.prototype.show = function() {
	propertyString = ('width=' + this.getWidth() + ',height=' + this.getHeight() + ',scrollbars=' + this.getScrollbars() + ',resizable=no,location=no,directories=no,status=no');
	pup = window.open( this.getQualifiedUrl(), this.getName(), propertyString );
	pup.focus();
}

/* Instance Properties */
Popup.prototype.getQualifiedUrl = function () {
	burl = this.getUrl();
	qstr = this.paramNameValuePairs();
	if(qstr.length == 0)
		return burl;
	return (burl + "?" + qstr);
}

Popup.prototype.getUrl = function() { 
	return this.url; 
}
Popup.prototype.setUrl = function( value ) { 
	this.url = value; 
}

Popup.prototype.getName = function() { 
	return this.name; 
}
Popup.prototype.setName = function( value ) { 
	this.name = value; 
}

Popup.prototype.getWidth = function() { 
	return this.width; 
}
Popup.prototype.setWidth = function( value ) { 
	this.width = value; 
}

Popup.prototype.getHeight = function() { 
	return this.height; 
}
Popup.prototype.setHeight = function( value ) { 
	this.height = value; 
}

Popup.prototype.getScrollbars = function() {
	if(this.scrollbars)
		return this.scrollbars;
	return "no";
}
Popup.prototype.setScrollbars = function( value ) { 
	this.scrollbars = value; 
}

Popup.prototype.setParam = function(name, value) {
	if(value == null)
		delete this.params[name];
	else 
		this.params[name] = value;
}

Popup.prototype.getParam = function(name) {
	return this.params[name];
}

Popup.prototype.numberOfParams = function() {
	return this.params.length;
}

Popup.prototype.paramNameValuePairs = function () {
	str = "";
	for(i in this.params) {
		if(str.length > 0)
			str += "&";
			
		str += (i + "=" + escape(this.params[i]));
	}
	
	return str;
}