
var plg_popup_sendMessage = new function(){
	
	this.receiver = null;
	var _self = this;
	
	this.init = function(receiver){
		this.receiver = receiver;
		$(".jQ_privateMessage_popup input[name='receiver']:last").val(receiver);
		$(".jQ_username").html(receiver); 	 		
	}
	
	this.send = function(form){
		majax.submitForm(form,'plg_popup_sendMessage::sendMessage',plg_popup_sendMessage.onSubmit);
	return false;		
	}
	
	this.showFor = function(receiver){
		try {
			var pop = $('.jQ_messagePopup:eq(0)').clone();
			plg_popup.show( pop );
			this.init( receiver );
		} catch( e ) {}
	}
	
	this.onSubmit = function(response){
		
		if(response.success){
			var formC = $('.jQ_privateMessage_popup:last .jQ_form:visible');
			var successM = $('.jQ_privateMessage_popup:last .jQ_success:hidden');
			
			function closePopup(){ 
				window.setTimeout(plg_popup.hide,5000) 
			}
			
			function showConfirm(){ 
				successM.fadeIn('fast', closePopup );
			}
			
			formC.slideUp('fast',showConfirm);
		} else {
			console.log(response.result);
			switch (response.result) {
				case -1:
					$('.jQ_eSubject:last').fadeIn();					
					break;

				case -2:
					$('.jQ_eBody:last').fadeIn();
					break;
				case -3:
					$('.jQ_eLimit:last p').html( $('.jQ_eLimit:last p').html().replace(/%limited%/,_self.receiver) );
					$('.jQ_eLimit:last').fadeIn();
					break;
			}

		}
		
	}
}
