var opened = false;
var EMOTICON = 
{
	
	show: function(ctrId)
	{
	    path='/ImagesGUI/EmoticonOng/';
	    numberoficons= 52;
	    opened = false;
		var html = '', index = '';
		for(var i=0;i<numberoficons;i++)
		{
			index = (i<10) ? ('0' + i) : (i + '');
			html += '<div style="float:left; width:40px; height:40px; padding:10px; overflow:hidden;"><div align="center" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ path + index +'.png\'); width:30px; height:30px; cursor:pointer" onclick="EMOTICON.insert(' + index + ', this, \'' + ctrId + '\');return false;"><a href="javascript:void(0);" title="' + index + '" ><img src="' + path + index + '.png" style="filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0));" /></a></div></div>';
		}
//		var popup = document.getElementById('popupbox');
//		popup.style.display="block";
//		popup.style.zIndex="100";
showPopup('popupbox');
		document.getElementById('popupbox_content').innerHTML = html;
		window.setTimeout("GanLaiOpened()",500);
	},
	showAvatar: function(ctrId)
	{
	    path= '/ImagesGUI/AvatarComment/';
	    numberoficons= 45;
	    opened = false;
		var html = '', index = '';
		for(var i=0;i<numberoficons;i++)
		{
			index = (i<10) ? ('0' + i) : (i + '');
			html += '<div style="float:left; width:55px; height:55px; overflow:hidden;padding:5px"><div align="center" style="width:55px; height:55px; cursor:pointer" ><a href="javascript:void(0);" title="' + index + '" ><img onclick="EMOTICON.insertAvatar(\'' + path + index + '.jpg\', this, \'' + ctrId + '\');return false;" src="' + path + index + '.jpg" style="width:55px; height:55px;" /></a></div></div>';
		}
		//var popup = document.getElementById('popupbox');
		//popup.style.display="block";
		//popup.style.zIndex="100";
		showPopup('popupbox');
		
		document.getElementById('popupbox_content').innerHTML = html;
		window.setTimeout("GanLaiOpened()",500);
	},
	hide: function()
	{
	    if(opened != false && document.getElementById('popupbox')!=null)
	    {
	        document.getElementById('popupbox').style.display="none";
	    }
	},
	insert: function(index, a, ctrId)
	{
		index = '<' + index + '>';
			try
    		{
				var ctr = document.getElementById(ctrId);	            
				if (ctr != null && ctr.createTextRange && ctr.caretPos) 
				{
					var caretPos = ctr.caretPos;
					caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? index + ' ' : index;	
				}
				else 
				{
					ctr.value += index;
				}
			}
			catch(e)
			{
        		alert(e.message);
			}
		
		EMOTICON.hide();
			
			
	},
	insertAvatar: function(index, a, ctrId)
	{
		try
    		{
				var ctr = document.getElementById(ctrId);	
				           
				var URLAvatar = document.getElementById("hidenURLAvatar");
			   
				if (ctr != null && URLAvatar !=null) 
				{
				   
					ctr.src = index;
					URLAvatar.value  = index;
					
				}
				
			}
			catch(e)
			{
        		alert(e.message);
			}
		
		EMOTICON.hide();
	}
}
function GanLaiOpened()
{
    opened = true;
}




// Show popup Emoticon và Avatar cho phần reply riêng comment
var openedNew = false;
var EMOTICONReply = 
{
	
	show: function(ctrId)
	{
	    path='/ImagesGUI/EmoticonOng/';
	    numberoficons= 52;
	    openedNew = false;
		var html = '', index = '';
		for(var i=0;i<numberoficons;i++)
		{
			index = (i<10) ? ('0' + i) : (i + '');
			html += '<div style="float:left; width:40px; height:40px; padding:10px; overflow:hidden;"><div align="center" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ path + index +'.png\'); width:30px; height:30px; cursor:pointer" onclick="EMOTICONReply.insert(' + index + ', this, \'' + ctrId + '\');return false;"><a href="javascript:void(0);" title="' + index + '" ><img src="' + path + index + '.png" style="filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0));" /></a></div></div>';
		}
		var popup = document.getElementById('popupboxReply');
		popup.style.display="block";
		popup.style.zIndex="100";
		showPopup('popupboxReply');
		document.getElementById('popupbox_contentReply').innerHTML = html;
		window.setTimeout("GanLaiOpenedNew()",500);
	},
	showAvatar: function(ctrId)
	{
	    path= '/ImagesGUI/AvatarComment/';
	    numberoficons= 45;
	    openedNew = false;
		var html = '', index = '';
		for(var i=0;i<numberoficons;i++)
		{
			index = (i<10) ? ('0' + i) : (i + '');
			html += '<div style="float:left; width:55px; height:55px; overflow:hidden;padding:5px"><div align="center" style=" width:55px; height:55px; cursor:pointer" ><a href="javascript:void(0);" title="' + index + '" ><img onclick="EMOTICONReply.insertAvatar(\'' + path + index + '.jpg\', this, \'' + ctrId + '\');return false;" src="' + path + index + '.jpg" style="width:55px; height:55px;" /></a></div></div>';
		}
			var popup = document.getElementById('popupboxReply');
		//popup.style.display="block";
		//popup.style.zIndex="100";
		showPopup('popupboxReply');
		document.getElementById('popupbox_contentReply').innerHTML = html;
		window.setTimeout("GanLaiOpenedNew()",500);
	},
	hide: function()
	{
	    if(openedNew != false && document.getElementById('popupboxReply')!=null)
	    {
	        document.getElementById('popupboxReply').style.display="none";
	    }
	},
	insert: function(index, a, ctrId)
	{
		index = '<' + index + '>';
			try
    		{
				var ctr = document.getElementById(ctrId);	            
				if (ctr != null && ctr.createTextRange && ctr.caretPos) 
				{
					var caretPos = ctr.caretPos;
					caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? index + ' ' : index;	
				}
				else 
				{
					ctr.value += index;
				}
			}
			catch(e)
			{
        		alert(e.message);
			}
		
		EMOTICONReply.hide();
			
			
	},
	insertAvatar: function(index, a, ctrId)
	{
		try
    		{
				var ctr = document.getElementById(ctrId);	
				           
				var URLAvatar = document.getElementById("hidenURLAvatarReply");
			   
				if (ctr != null && URLAvatar !=null) 
				{
				   
					ctr.src = index;
					URLAvatar.value  = index;
					
				}
				
			}
			catch(e)
			{
        		alert(e.message);
			}
		
		EMOTICONReply.hide();
	}
}



function GanLaiOpenedNew()
{
    openedNew = true;
}