var popupSizes = {
	alert_popup: [290]
}

var popupUrls = {
	alert_popup: "../popup/alert.php"
}

var popups = new Array();

var popupsObj = new Array();

function Popup(popupName, parameters,  functionCallback) {
	if (popupSizes[popupName] != null && popupUrls[popupName] != null) {

		this.popSize    = popupSizes[popupName];
		this.popUrl     = popupUrls[popupName];
		this.id 	    = "popupId_" + popupsObj.length;
		this.name 	    = popupName;
		this.parameters = parameters == null ? new Object() : parameters;		

		if (this.popSize[1] != null)
			addPopHeight = popupSizes[popupName][1] + document.documentElement.scrollTop + 75;
		else
			addPopHeight = document.documentElement.scrollTop + 75;
		
		showScreenLocker();
		
		popupsObj.push(this);
		
		$("<div id=\"" + this.id + "\" style=\"display:none;\"></div>").prependTo("body");
		
		this.objPop  = document.getElementById(this.id);
		
		var sizes = getPageSize();
		
		this.objPop.style.width = this.popSize[0] + "px";
		
		if (this.popSize[1] != null)
			this.objPop.style.height = this.popSize[1] + "px";
			
		this.objPop.style.top = (document.documentElement.scrollTop + 150) + "px";
		this.objPop.style.left = (document.documentElement.offsetWidth - this.popSize[0])/2 + "px";
		this.objPop.style.position = "absolute";
		this.objPop.style.zIndex = parseInt(popupsObj.length == 1 ? 1000 : popupsObj[popupsObj.length-2].objPop.style.zIndex) + 2;


		var $this = this;
		var callback = function() { 
			$this.objPop.style.display  = "block"; 
			if (functionCallback){
				functionCallback();
			}
		}
		
		$(this.objPop).load(this.popUrl + "?random=" + getIdRandom(), this.parameters, callback);
		
	} else
		alert("Unknown popup name");
}

Popup.prototype.close = function() {
	for (var i = 0; i < popupsObj.length; i++) {
		if (popupsObj[i].name == this.name) {
			popupsObj[i].objPop.style.display = "none";
			$(popupsObj[i].objPop).remove();
			popupsObj.splice(i,1);
			hideScreenLocker();
			break;
		}
	}	
}

	
Popup.prototype.reload = function() {
		var callback = function() {}
		$(this.objPop).load(this.popUrl + "?random=" + getIdRandom(), this.parameters, callback);
}	

function closeLastPopup() {

	if (popupsObj.length > 0) 
 		popupsObj[popupsObj.length-1].close();
 		
}
