﻿//PM-Message Send
YAHOO.namespace("SendMessage.container");
function PmBox_init() {
	
	// Define various event handlers for Dialog
	var handleSubmit = function() {
		this.submit();
	};
	var handleCancel = function() {
		this.cancel();
	};
	var handleSuccess = function(o) {
		//var response = o.responseText;
		//response = response.split("<!")[0];
		//document.getElementById("resp").innerHTML = response;
		alert(o.responseText);
	};
	var handleFailure = function(o) {
		alert("Lỗi trong quá trình xử lý: " + o.status);
	};

	// Instantiate the Dialog
	YAHOO.SendMessage.container.pmBox = new YAHOO.widget.Dialog("pmBox", 
							{ width : "400px",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"Gửi", handler:handleSubmit, isDefault:true },
								      { text:"Không gửi", handler:handleCancel } ]
							});

	// Validate the entries in the form to require that both first and last name are entered
	YAHOO.SendMessage.container.pmBox.validate = function() {
		var data = this.getData();
		if (data.pm_username == "") {
			alert("Nhập tên của người nhận");
			return false;
		} 
		else if(data.pm_title==""){
		    return confirm("Tiêu đề của tin nhắn chưa có, bạn có muốn gửi tin không?");
		}
		else {
			return true;
		}
	};

	// Wire up the success and failure handlers
	YAHOO.SendMessage.container.pmBox.callback = { success: handleSuccess,
						     failure: handleFailure };
	
	// Render the Dialog
	YAHOO.SendMessage.container.pmBox.render();

	//YAHOO.util.Event.addListener("show", "click", YAHOO.SendMessage.container.pmBox.show, YAHOO.SendMessage.container.pmBox, true);
	//YAHOO.util.Event.addListener("hide", "click", YAHOO.SendMessage.container.pmBox.hide, YAHOO.SendMessage.container.pmBox, true);
	document.getElementById("pmBox").style.display="";
}
function sendMail(userName){
    pm_username = document.getElementById('pm_username');
    pm_username.value = userName;
    YAHOO.SendMessage.container.pmBox.show();
}
YAHOO.util.Event.onDOMReady(PmBox_init);

