﻿var filterWord = "đụ,cức,cuc,cc,vkl,vcl,vãi lều,fuck,shit,ifastnet,sitesled,buồi,nứng,lồn,fucking,cock,bitch,cặc,cặt,kặc,suck,vcl,bullshit,minh râu,việt cộng,Nông Thị Xuân,triều đình cộng sản,vương triều cộng sản,vương triều Hà Nội,đảng trị,đả đảo cộng sản,đả đảo XHCN,cộng sản bán nước,tội ác cộng sản,tội ác của chế độ CSVN,tội ác của chế độ cộng sản,cộng sản độc tài,độc tài cộng sản,cộng sản thối nát,cộng sản mị dân,cộng sản mỵ dân,địt mẹ mày,lồn mẹ,lỗ đít,ăn lồn,liếm lìn,mặt lìn,con phò,con kặc,Minh Râu,việt minh,việt cộng,lịt mẹ,tiên sư bố,tổ sư bố,mả mẹ mày,mả cha mày,mả bố mày,mả tổ mày,mả mẹ chúng mày,mả cha chúng mày,mả bố chúng mày,mả tổ chúng mày,lỗ đít,mặt lìn,liếm lìn,móc lìn,ăn lìn,liếm đít,con phò,con đĩ,con điếm,đĩ đực,điếm đực,đồ chó,đồ lợn,cứt,ăn kặc,bú kặc,củ kặc,con kặc,mút kặc,ăn kẹc,bú kẹc,củ kẹc,con kẹc,bú dái,bú dzái,mút zái,bú cu,bú ku,con ku,kứt,ngứa dzái,bán dzâm,ngứa zdái,cờ ba sọc,cờ 3 sọc,nguoi-viet.com,bỏ mẹ,MINH RÂU,LỒN,ĐỴT,dizz,diz,dis,dit,lol,dis mẹ,nhu lon,lon`,phim sex,film sex,djs,zú bự,zu' bu,zu' bự,khoe hang`,KHOE HÀNG,KHOE HANG`,Minh Trị,Minh trị,minh trị,MINH TRỊ,MINH TRI,minh tri,CỜ VÀNG BA SỌC ĐỎ,Cờ Vàng Ba Sọc Đỏ,cờ vàng ba sọc đỏ,CỜ VÀNG 3 SỌC ĐỎ,Cờ Vàng 3 Sọc Đỏ,cờ vàng ba sọc đỏ,đàn áp tôn giáo,ĐÀN ÁP TÔN GIÁO,Đàn Áp Tôn Giáo,Thăng Tiến Việt Nam,THĂNG TIẾN VIỆT NAM,thăng tiến việt nam,thăng tiến Việt Nam,Cụ Hồ,Cu Hồ,mất dạy,ngứa,dis,hot^. le.,hột le,cleversky.net,deo',liem^',cho',cut',hiep',trYm,Cộng sản Quốc tế,Việt Nam Cộng Hòa,VN CH,CS VN,Trung cộng,Viêt Cộng,TRung Cong,Viet COng,TRung COng,Thanh Minh Thiền viện,chó,trYm,ỈA,BUỒI,hãm,CPVNTD,sjp,BUỒI,LO^`N,BUÔ`i,d!ck,trYm,cặc,ỈA,loZ,lÒl,mẹ mày,má mày,MẤT DẠY,mất dạy,f.u.c.k,F.U.C.K,f u c k,MÁ MÀY,MẸ MÀY,F U C K,vú,dú,vãi,dY~,diE^n,cH0,cH0',mE.,zú,djs,ch.ó,F*ck,mie,mịe,miẹ,moa,móa,đái,địt,đỊT,lÒl,đít,ĐỴT,ĐỊT,đéo,đít ghẻ,đỉ,đĩ,chó đẻ,đỊT,đéo,ĐÝT,fản động,phản động,Đỵt mẸ,đĩ,ĐỴT,đéo,ĐỊT,địt tổ,Địt,đỵt mẹ,đỵt,Đỵt mẹ,Đỵt,đỴt,ĐỊT,ĐĨ,ĐỈ,đỉ,loz`,đĨ,Địt mẹ,đis mẹ,đIs mẹ,đỤ mẸ,ĐỊT MẸ,DIT ME,Đy~ chó,Đĩ chó,đéo,Đĩ,đù má,đéo mẹ,địt mẹ mày,đù má mày,đéo mẹ mày,địt mẹ chúng mày,đù má chúng mày,đéo mẹ chúng mày,đéo mẹ,địt,đéo,địt mẹ,.tk,giacmotuoiteen,Dịzz,PHÂN,lz,lỳn,kon kac,Đjz,con di~,eo',Eo',vai~,thang con ket,lo`n,chó ghẻ,lonz,FPT,lapmang_fpt_hn,lapmangfpt.so1.in,04.2239.6116,0974.997.123,OLA,8749";

var zme_avatar_width = 50;
var zme_avatar_heigth = 50;
var lastTotalRecord = 0;
var noRefresh=0;
var loginAcc = $('#loginAccountName').val();
var uploadUserName = $('#uploadUserName').val();
var strCommentInitialText = 'Viết bình luận ...';
var currentPage = 0;
var pageSize = 10;	
Init();
var isFirstLoad = 1;
var url = "http://nhac.zing.vn/nhac/ajax/badword.html";
function Init(){	
	isFirstLoad = 0;
	if (!document.getElementById('zCommentID')) {
		return;
	}
	var Interaction_Comment = document.getElementById('zCommentID');
	Interaction_Comment.setAttribute('class','Interaction_Comment');						
	Interaction_Comment.setAttribute('productid',5);
	Interaction_Comment.setAttribute('orderby',"commentdate");
	Interaction_Comment.setAttribute('sortby',"desc");        
	Interaction_Comment.setAttribute('url',window.location.href);	
	Interaction_Comment.setAttribute('page',1);		
	Interaction_Comment.setAttribute('pagesize',pageSize);			
	Interaction_Comment.setAttribute('captcha','0');				
	Interaction_Comment.setAttribute('autoapproved','1');				
	Interaction_Comment.setAttribute('filtermod','1');				
	Interaction_Comment.setAttribute('loginmod','1');				
	Interaction_Comment.setAttribute('responsetype','json');				
	Interaction_Comment.setAttribute('userid','-1');					
	Interaction_Comment.setAttribute('displayname',getAccountName());					
	Interaction_Comment.setAttribute('viewtype','');					
	Interaction_Comment.setAttribute('message_comment_added','');						
	Interaction_Comment.setAttribute('message_comment_add_short_time','Mỗi comment cách nhau 15 giây');					
	Interaction_Comment.setAttribute('message_comment_exception','Có lỗi trong quá trình đăng bình luận. Mong bạn thông cảm thử lại');					
	Interaction_Comment.setAttribute('message_comment_sso','Bạn cần đăng nhập đề bình luận');						
	Interaction_Comment.setAttribute('message_comment_add_not_allow','Bạn không thể gởi thêm bình luận trong cùng một mục');				
	Interaction_Comment.setAttribute('callback_init','Comment_Init');						
	Interaction_Comment.setAttribute('callback_post','Comment_Post');						
	Interaction_Comment.setAttribute('callback','Comment_Init');						
	Interaction_Comment.setAttribute('limit','0');			
}
function Comment_Post(jData){
	var totalPage = jData.CPaging.TotalPage;
	var totalRecord = jData.CPaging.TotalRecord;	
	if(totalRecord%pageSize==0){
		totalPage=totalPage+1;
	}
	/*
	else{
		if((currentPage==totalPage) && (totalRecord>lastTotalRecord)){
			noRefresh =1;
		}
	}
	setTimeout('Interaction_Comment.GoPage('+totalPage+',\'zCommentID\')',1000);
	*/
	setTimeout('Interaction_Comment.GoPage('+1+',\'zCommentID\')',1000);
	$('#txtcomment').val(strCommentInitialText);
}			

function Comment_Paging(jData){
	var size = 7;
	var page = '';
	var totalPage = jData.CPaging.TotalPage;
	currentPage = jData.CPaging.CurrentPage;
	var totalRecord = jData.CPaging.TotalRecord;
//	var startPage = currentPage-((currentPage-1)%size);
	var startPage = currentPage-(Math.floor(size/2));	
	if(startPage<1){
		startPage = 1;
	}
	
	var endPage = startPage+size-1;
    var list = ''; 
	if(endPage>totalPage){
		endPage=totalPage; 
	}
	if(totalPage>1){
		list = '';
		for(i=startPage; i<=endPage; i++){
			if(i==currentPage){
				list+= '<li><b>'+i+'</b></li>';					
			}else{
				list+= '<li><a onClick="Interaction_Comment.GoPage(\''+ i + '\',\'zCommentID\');return false;" href="#">'+i+'</a></li>';
			}
		}
		if(currentPage-1>0){
			// Go To First Page
			page += '<ul> <a onclick="Interaction_Comment.GoPage(\''+1+'\',\'zCommentID\');return false;" href="#" onclick="" >Trang đầu</a> ';
			page += '  <a onclick="Interaction_Comment.GoPage(\''+(currentPage-1)+'\',\'zCommentID\');return false;" href="#" onclick="" >Trước<img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/icon-previus.png" width="8" height="10" border="0" /></a> ';
			//page += '<ul> <a onclick="Interaction_Comment.GoPage(\''+(currentPage-1)+'\',\'zCommentID\');return false;" href="#" onclick="" >Trước<img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/icon-previus.png" width="8" height="10" border="0" /></a> ';
		}else{
			page +='<ul>  ';
		}
		page += list;
		if(currentPage+1<=totalPage){
			//page +=' <a onclick="Interaction_Comment.GoPage(\''+ (currentPage+1) + '\',\'zCommentID\');return false;" href="#"><img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/icon-next.png" width="8" height="10" border="0" />Sau</a></ul>';
			page +=' <a onclick="Interaction_Comment.GoPage(\''+ (currentPage+1) + '\',\'zCommentID\');return false;" href="#"><img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/icon-next.png" width="8" height="10" border="0" />Sau</a>';
			// Go To End Page
			page +='  <a onclick="Interaction_Comment.GoPage(\''+ totalPage + '\',\'zCommentID\');return false;" href="#">Trang cuối</a></ul>';
		}else{
			page +=' </ul>';			
		}
	}
	return page;
}				  
function Comment_Init(jData){
	$('#spanTotalItem').html('('+jData.CPaging.TotalRecord+')');
	var totalPage = jData.CPaging.TotalPage;
	var totalRecord = jData.CPaging.TotalRecord;
	lastTotalRecord = totalRecord;
	var strItem = '';	
	if(jData && jData.CItem.length>0){ 
		if(noRefresh==1){
			noRefresh=0;
			strItem = document.getElementById('divListComment').innerHTML;
			strItem=strItem.replace(/ZMEA_/g,'ZMEA111_');						
			var last=jData.CItem.length-1;
			strItem += Comment_Item_Render((jData.CItem[last]));			
		}else{
			for(i =0; i< jData.CItem.length; i++){
				strItem += Comment_Item_Render(jData.CItem[i]);			
			}		
		}
		document.getElementById('divListComment').innerHTML = strItem;
		document.getElementById('spanPageNav').innerHTML = Comment_Paging(jData);			
		ZME_widget_mix();	
		if((loginAcc) & (uploadUserName==loginAcc)){
			$(".deleteComment").show();
		}
		$('#txtcomment').css('color','#BEBEBE');		
	}
}
function Comment_Item_Render(jItem){
	var comment = jItem.Comment;
	var pattern1 =/<script[^>]*>.*?<\/script>/ig;
	var pattern2 =/<iframe[^>]*>.*?<\/iframe>/ig;
	var pattern3 =/<style[^>]*>.*?<\/style>/ig;
	var pattern4 =/<link[^>]*>.*?\/>/ig;
	var pattern5 =/<a[^>]*>.*?<\/a>/ig;
	var pattern6 =/http:\/\//ig;
	
	comment=comment.replace(pattern1, '').replace(pattern2, '').replace(pattern3, '').replace(pattern4, '').replace(pattern5, '').replace(pattern6, '');
	var tplItem = $('#tplCommentItem').html();
	tplItem=tplItem.replace(/ZMEA111_{DISPLAY_NAME}/g,'ZMEA_{DISPLAY_NAME}');
	tplItem=tplItem.replace(/ZMED222_{DISPLAY_NAME}/g,'ZMED_{DISPLAY_NAME}');
	tplItem=tplItem.replace(/%7BDISPLAY_NAME%7D/g,jItem.DisplayName);
	tplItem=tplItem.replace(/{DISPLAY_NAME}/g,jItem.DisplayName);
	tplItem=tplItem.replace(/{COMMENT_DATE}/g,jItem.CommentDate);
	tplItem=tplItem.replace(/{COMMENT_TIME}/g,jItem.CommentTime);
	tplItem=tplItem.replace(/{COMMENT}/g,comment);
	tplItem=tplItem.replace(/{COMMENT_ITEM_ID}/g,jItem.CommentItemID );
	tplItem=tplItem.replace(/{MESSAGE_ID}/g,jItem.MessageID );
	tplItem=tplItem.replace(/{ITEM_ID}/g,jItem.ItemID );
	tplItem=tplItem.replace(/{CATEGORY_ID}/g,jItem.CategoryID );
	return tplItem;
}
$('#txtcomment').keyup(function(){
	limitChars('txtcomment',600,'spanCharRemain');
})
$('#txtcomment').click(function(){
	if(!checkLogin()){
		$(this).blur();
		loadLogin();
	}
})

$('#btnAddComment').click(function(){
	if(($('#txtcomment').val()=='') || ($('#txtcomment').val()==strCommentInitialText) ){
		jAlert('warning', 'Bạn vui lòng nhập lời bình.', 'Lưu ý');
		$('#txtcomment').focus();
		return false;
	}
    $.getJSON(url + '?call=?', function(data) {
        var txtcomment = $('#txtcomment').val();
        txtcomment = removeDoubleLine(txtcomment);
        txtcomment = removeDoubleSpace(txtcomment);
        txtcomment = txtcomment.filter(data.badwords.split(','), '*');
        var arrStr = new Array();
        arrStr = txtcomment.split(' ');
        for (var i = 0; i < arrStr.length; i++) {
            var strText = arrStr[i].toLowerCase();
            if(strText.search('<a') != -1 || strText.search('www') != -1 || strText.search('http://') != -1 || strText.search('.com') != -1 || strText.search('.info') != -1 || strText.search('.org') != -1 || strText.search('.net') != -1 || strText.search('.vn') != -1 ){
                arrStr[i] = strText.replace(strText, ''.repeat(strText.length));
            }
        }
        txtcomment = arrStr.join(' ');
        $('#txtcomment').val(txtcomment);

		if (!checkLogin()) {
			loadLogin();
			return false;
		} else {
			// push feed and notification
			var itemid 	= 0;
			var type	= "";
			if($("#songID").length > 0) {
				itemid  = $("#songID").val();
				type	= "song";
			} else if($("#nghealbum_id").length > 0) {
				itemid  = $("#nghealbum_id").val();
				type	= "album";
			} else if($("#hidVideoID").length > 0) {
				itemid 	= $("#hidVideoID").val();
				type	= "video";
			}
			$.post("/includes/NewFace_Push_Feed_Notification.php", {itemid: itemid, type: type, content: txtcomment, userName: getAccountName()});
			Interaction_Comment.Post(0,'zCommentID');
		}
        return false;

		/*
		if(isWordTooLong(txtcomment)){
			jAlert('error', 'Bình luận chứa từ quá dài.', 'Lưu ý');
			return false;
		}
		*/
    });
})

function removeDoubleSpace(string){
    string = string.trim();
    var splits = string.split('  ');
    var result = '';
    for(var i=0;i<splits.length;i++){
        if(splits[i]!=''){
            if(i!=splits.length-1){
                result += splits[i].trim()+' ';
            }else{
                result += splits[i].trim();
            }
        }
    }
    return result;
}

function isWordTooLong(str){
	var arrAtr = str.split(' ');
	for(i=0;i<arrAtr.length;i++){
		if(arrAtr[i].trim().length>30){
			return 1;
		}
	}
	return 0;
}

function removeDoubleLine(str) {
   //IE
   while(str.indexOf("\r\n\r\n") >= 0) {
      str = str.replace(/\r\n\r\n/g, "\r\n")
   }
   //FF
   while(str.indexOf("\n\n") >= 0) {
      str = str.replace(/\n\n/g, "\n")
   }
	return str;
}

function txtcomment_Click(obj){
	if(obj.value==strCommentInitialText){
		obj.value='';
		$('#txtcomment').css('color','#000000');
	}
}
function txtcomment_Blur(obj){
	if(obj.value==''){
		obj.value=strCommentInitialText;
		$('#txtcomment').css('color','#BEBEBE');		
	}
}
function deleteComment(CommentItemID, MessageID, ItemID, CatogoryID){
	url = "/includes/NewFace_DeleteComment.php";
	$.post(url ,{commentID:CommentItemID, messageID:MessageID, itemID: ItemID, catogoryID: CatogoryID},
	function(data){
		  setTimeout('Interaction_Comment.GoPage(currentPage,\'zCommentID\')',500);
		  return false;
	});
	return false;

}
if(isFirstLoad){
 	setTimeout('Interaction_Comment.GoPage(1,\'zCommentID\')',500);
}
