
$(document).ready(function() {
	
	bindSendPM();
	
	
	function bindSendPM() {
		
		$('.send_pm').each(function(i) {
			$(this).click(function(){
				
				$.blockUI({
					message: '<p>Please wait..</p>'					
				})
				
				uID = $(this).parent().children('.user_id').attr('value')
				$('#td_send_to_user_name').html(uID)
				loadPMForm(uID)
				$.blockUI({ 
					message: $('#user_send_pm'),
					css: {  
						cursor: 'pointer',
						border: '0px',
						width:'auto'
				    },
				    overlayCSS:  {  
		        		backgroundColor:'#379bcc',  
		        		opacity:'0.6'  
		    		}
				});
			})
		})
		
		
		function loadPMForm(uID) {
			$.ajax({
				type: 'POST',
				url: 'http://www.funhax.com/index.php?m=1&c=user&f=loadSendPMForm&uID='+uID,
				dataType: 'html',
				success: function(data) {
					$('#user_send_pm').html(data);
					bindFormBtns(uID);
				}
			})
		}
		
		function submitPMForm(uID) {
			message = $('#pm_message').val();
			subject = $('#FupSubject').val();
			$.ajax({
				type: 'POST',
				url: 'http://www.funhax.com/index.php?m=1&c=user&f=sendUserPm',
				dataType: 'html',
				data: 'uID='+uID+'&message='+message+'&FupSubject='+subject
			})
		}
		
		function bindFormBtns() {
			$('#btn_cancel_pm').click(function() {
				$.unblockUI()
			})
			$('#btn_send_pm').click(function() {
				submitPMForm(uID)
				$('#sendPMForm').remove();
				$("#user_send_pm").html('<p style="padding:20px;">Message has been sent</p>')
				$("#user_send_pm").oneTime("2s", function() {
					$.unblockUI();
				});
				
			})
		}
		
	}	// end bindSendPM
	
})
