/* Attachments toggle */
function toggleAttachments() {
$j("#open").toggle();
$j("#close").toggle();
$j("#attachments-outline").toggle();
$j("#attachments-details").toggle("fast");
return false;
}
/* Setup attach form */
function setupAttach(lId,cId,type){
var html = "
"+
"
"+
"
"+
"
"+
"
"+
" "+
" "+
" "+
"
"+
"
"+
"
"+
"
";
var html1= "
"+
"
"+
"
"+
"
"+
"
"+
" "+
" "+
" "+
"
"+
"
"+
"
"+
"
"+
"
(tùy chọn)
"+
"
"+
"
"+
"
";
if (type=='media') {
$j("#attach-form" + cId).html(html1);
} else {
$j("#attach-form" + cId).html(html);
}
$j("#attach-form" + cId).css("display","block");
return false;
}
function cancelAttach(cId) {
$j("#aloading-" + cId).remove();
$j("#attach-form" + cId).html("");
$j("#attach-form" + cId).css("display","none");
return false;
}
/* Attach to Comment */
function getAttachmentData(lId,cId,media) {
query = "act=add&media="+media+"&link="+lId+"&comment="+cId;
var attachment = $j("#attachment" + cId).val();
query += "&attachment=" + encodeURIComponent(attachment);
var embedded = $j("#embedded" + cId).val();
query += "&embedded=" + encodeURIComponent(embedded);
var cmt_type = parseInt($j("input#foreign_type_user").val());
query += "&cmt_type=" + encodeURIComponent(cmt_type);
return query;
}
function attach2Comment(lId,cId,media) {
var query = getAttachmentData(lId,cId,media);
var loading = "
"
+ ""
+ "
"
$j("#attachments"+cId).append(loading);
$j("#attachments"+cId).css("display","block");
toggleButton("sattachment"+cId);
$j.post(my_base_url+my_pligg_base+"/ajaxAttachment", query,
function(result) {
ajaxAttach2CommentCallback(result,cId);
}
);
return false;
}
function ajaxAttach2CommentCallback(result,cId) {
if (/ERROR:/.test(result)) {
result = result.substring(7, result.length);
$j("#aloading-" + cId).remove();
toggleButton("sattachment"+cId);
window.alert(result);
} else {
$j("#attachments"+cId).append(result);
$j("#attachments"+cId).css("display","block");
$j("#aloading-" + cId).remove();
toggleButton("sattachment"+cId);
cancelAttach(cId);
}
}
function ajaxManageComment(action,cID){
if(confirm('Are you sure ?')){
var query = "action="+action+"&comment_id="+cID;
$j.post(my_base_url+my_pligg_base+"/ajaxCommentManage", query,
function(result) {
ajaxManageCommentCallback(result,cID);
}
);
return false;
}
}
function ajaxRemoveAttachmentCallback(result,str){
$j("#"+str).html("");
}
function ajaxManageCommentCallback(result,cID){
$j("#c-toggle-" + cID).html(result);
}
function ajaxRemoveAttachment(aID,cID,str){
if(confirm('Are you sure ?')) {
var query = "act=remove&attachment_id="+aID+"&comment_id="+cID;
$j.post(my_base_url+my_pligg_base+"/ajaxAttachment", query,
function(result) {
ajaxRemoveAttachmentCallback(result,str);
}
);
return false;
}
}
/* Setup edit attachment */
function setupEditAttachment(hash,cId){
$j("#label-"+hash+"-"+cId).css("display","none");
$j("#form-"+hash+"-"+cId).css("display","inline");
return false;
}
function cancelEditAttachment(hash,cId) {
$j("#form-"+hash+"-"+cId).css("display","none");
$j("#label-"+hash+"-"+cId).css("display","inline");
return false;
}
function updateAttachment(hash,cId) {
$j("#ajaxLoading").show();
var newLabel = $j("#text-"+hash+"-"+cId).val();
query = "act=edit&hash=" + hash + "&comment=" + cId + "&label=" + encodeURIComponent(newLabel);
var cmt_type = parseInt($j("input#foreign_type_user").val());
query += "&cmt_type=" + encodeURIComponent(cmt_type);
$j.post(my_base_url+my_pligg_base+"/ajaxAttachment", query,
function(result) {
if (/ERROR/.test(result)) {
result = result.substring(7, result.length);
window.alert(result);
} else {
$j("#label-" + hash + "-" + cId).text(result);
cancelEditAttachment(hash,cId)
}
}
);
$j("#ajaxLoading").hide();
return false;
}
function removeAttachment(hash,cId) {
$j("#ajaxLoading").show();
query = "act=del&hash=" + hash + "&comment=" +cId;
var cmt_type = parseInt($j("input#foreign_type_user").val());
query += "&cmt_type=" + encodeURIComponent(cmt_type);
$j.post(my_base_url+my_pligg_base+"/ajaxAttachment", query,
function(result) {
$j("#" + hash + "-" + cId).remove();
}
);
$j("#ajaxLoading").hide();
return false;
}
/* Show/Hide attachment's embedded/thumb */
function showAEmbed(aId){
var toggler = $j("#a-show-embedded-"+aId);
var embedDiv = $j("#a-embedded-"+aId);
var content = $j(embedDiv).html();
if(content==null||content==""){
var loading = "
"
+ ""
+ "
"
$j(embedDiv).html(loading);
$j(embedDiv).css('display','block');
var embedVideo="";
$j.post(my_base_url+my_pligg_base+"/ajaxAttachment", "act=getEmbedded&id="+aId,
function(result) {
$j(embedDiv).html(result);
$j(toggler).html("");
$j(toggler).attr('title','Đóng');
}
);
} else {
$j(embedDiv).html("");
$j(embedDiv).css('display','none');
$j(toggler).html("");
$j(toggler).attr('title','Mở');
}
return false;
}
/* Setup comment form */
function setupComment() {
$j.scrollTo('#c0-form', 500, {onAfter:function() {$j("textarea#ccontent").focus();}});
return false;
}
function setupCommentReply(cId,lId,status,date,link_url){
var cForm = $j("#c" + cId + "-form");
var cFooter = $j("#c" + cId + "-foot");
var html="