function PopupsWidget()
{
	this.reqWidgetQueue= new Array();//queue with the widgets that made a request through this controller object
	
	var self=this;
	
	this.popupsIndex = 0;
	this.popupsArray = new Array();
	
	/**
	 * @param The manager index of the request 
	 * @desc This method is a handler for the completition of one request
	 */

	/**
	 * @param the index of the request 
	 * @desc Remove widget from the queue
	 */
	this.removeWidget=function (managerIndex)
	{
		RequestManager.getInstance().removeRequest(managerIndex);		
		self.reqWidgetQueue[managerIndex]=null;
	}
	
	this.createPopup = function (title,content,objReff)
	{
		var newpopup = document.createElement("div");
		
		newpopup.className = "the_popup";
		newpopup.setAttribute("class","the_popup");
		
		
		var morestyle = "";
		if(Config.browserName == "msie")
		{
			morestyle = "bottom:13px;";
		}
		else
		{
			morestyle = "";
		}
		
		newpopup.innerHTML = "<div class='title'>&nbsp;&nbsp;&nbsp;"+title+"</div><div class='content'>"+content+"<img class='arrow' src='"+Config.IMAGES_URL+"ro/popup_arrow.gif' style='"+morestyle+"'><a href='#' onclick='PopupsWidget.getInstance().closePopup("+this.popupsIndex+");return false;'><img src='"+Config.IMAGES_URL+"ro/popup_close.gif' class='close' border=0></a></div>";
		
		document.getElementsByTagName("body")[0].appendChild(newpopup);
		
		newpopup.style.left = (getLeft(objReff)+20)+"px";
		newpopup.style.top = (getTop(objReff)-10 - newpopup.offsetHeight)+"px";
		
		newpopup.id = "popup_window_"+this.popupsIndex;
		
		this.popupsArray[this.popupsIndex] = newpopup;
		
		this.popupsIndex++;
		
		return newpopup;
	}
	
	this.showPopup = function (objReff)
	{
		
	}

	this.closePopup = function (popup_id)
	{
		var pReff = _e("popup_window_"+popup_id);
		
		this.popupsArray[popup_id] = null;
		
		pReff.parentNode.removeChild(pReff);
		return true;
	}	
	
	this.showIfLogged = function (title,content,objReff)
	{
		if(userIsLogged>0)
		{
			this.createPopup(title,content,objReff);
		}
		else
		{
			this.createPopup("Error!",PopupsWidget.NOT_LOGGED,objReff);
		}
	}
	
	this.closeAllPopups = function ()
	{
		for(var i=0;i<this.popupsIndex;i++)
		{
			if(this.popupsArray[i] != null)
			try {
			this.popupsArray[i].parentNode.removeChild(this.popupsArray[i]);
			}catch(err){}
		}
	}
}

PopupsWidget.NOT_LOGGED = "Pentru aceasta actiune trebuie sa fi logat!<br>Daca nu ai inca un cont iti poti crea unul chiar <a href='"+Config.APP_URL+"cont_nou.html' >aici</a>.<br>Daca ai deja un cont, <a href='"+Config.APP_URL+"autentificare.html'>autentifica-te</a>";
PopupsWidget.ADD_COMMENT = "Adauga un comentariu la acest profil :<br><form><textarea id='comment_body'></textarea><br><a href='#' class='button' onclick=\"UserProfile.getInstance().addProfileComment(otherProfileId,_e('comment_body'));return false;\">Adauga comentariu!</a></form>";
PopupsWidget.ADD_AS_FRIEND = "Adauga acest utilizator la prietenii tai.<br><br><a href='#' class='button' onclick=\"UserProfile.getInstance().addToFriends(otherProfileId);return false;\">Adauga ca si prieten</a></form>";
PopupsWidget.ADD_IMAGE_COMMENT = "Adauga un comentariu la acesta imagine :<br><form><textarea id='comment_body'></textarea><br><a href='#' class='button' onclick=\"UserProfile.getInstance().addImageComment(thisImageId,_e('comment_body'));return false;\">Adauga comentariu!</a></form>";
PopupsWidget.NO_IMAGES = "Ne pare nespus de rau, dar acest utilizator nu si-a adaugat nici o imagine.";

PopupsWidget.showBaloon = function (text)
{
	alert(text);
}

PopupsWidget.__instance__=null;

PopupsWidget.getInstance=function()
{
	if(PopupsWidget.__instance__==null)
	{
		PopupsWidget.__instance__=new PopupsWidget();
	}
	return PopupsWidget.__instance__;
}
