
function inviteFriend()
{
	// get all email
	var email = core.trim(core.getObject("txtInviteFriend").value);
	if (email=="")
	{
	    //alert("Bạn hãy nhập vào danh sách tối đa 20 địa chỉ email.");
	    core.getObject("txtInviteFriend").focus();
	    return;
	}
	var email_list = email.replace(new RegExp( ";", "g" ),",").replace(new RegExp( "\r", "g" ),"").replace(new RegExp( "\n", "g" ),",");
	email_list = email_list.split(",");
    var iElement = 0;	
    for (var iRun = 0; iRun <email_list.length; iRun++)
    {
        if (core.trim(email_list[iRun]) != "" && core.isValidEmail(email_list[iRun]))
        {
            iElement++;
        }
    }
	if (iElement>LIMIT_INVITE_EMAIL)
	{
	    //email_list.splice(0,LIMIT_INVITE_EMAIL);
	    core.getObject("txtInviteFriend").focus();
	    showMessage("Bạn đã nhập nhiều hơn " + LIMIT_INVITE_EMAIL + " email.","tblInviteFriend","lblInviteFriend");
	    //alert("Bạn hãy nhập vào danh sách địa chỉ Email");
	    return;
	}
	// Disable btnSend
    disableControl("btnSendInvite",true);
    //
    var emailAfter = implode(",",email_list);
	var strRequest = strRequest = "?act="+ACT_INVITE_FRIEND+"&email="+emailAfter;

	var ajax = new Ajax(METHOD_GET);
	// 
	ajax.SendRequestToServerWithCustomMsg("invite_friend.php" + strRequest, null, inviteFriend_OnCallBack, true, MSG_AJAX_FETCHING_VN,null,true);
}

function inviteFriend_OnCallBack(xmlHTTPRequest)
{
	if(xmlHTTPRequest.readyState == 4) 
	{
		if(xmlHTTPRequest.status == 200) 
		{	
		    var strRespond = xmlHTTPRequest.responseText.split(SEP_RESPONSE);
		    showMessage(strRespond[1],"tblInviteFriend","lblInviteFriend");
		    if (strRespond[0]==1)
		    {
		        core.getObject("txtInviteFriend").value = "";
		    }
			core.getObject("txtInviteFriend").focus();
			disableControl("btnSendInvite",false);
		}
	}
}