/*
 * UrComment PRO - Advance Article Comments System For Joomla!
 * @version 	1.0
 * @package		UrComment Pro
 * @website		http://joomla.comdevweb.com
 * @copyright	Copyright (C) 2009 Comdev Software, Joomla@Comdevweb.com. All rights reserved.
 * @license		GPL, Commercial Software
 * 
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 *
*/

// Simple Pop out DIV
var viewport = {
    o: function() {
        if (self.innerHeight) {
			this.pageYOffset = self.pageYOffset;
			this.pageXOffset = self.pageXOffset;
			this.innerHeight = self.innerHeight;
			this.innerWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			this.pageYOffset = document.documentElement.scrollTop;
			this.pageXOffset = document.documentElement.scrollLeft;
			this.innerHeight = document.documentElement.clientHeight;
			this.innerWidth = document.documentElement.clientWidth;
		} else if (document.body) {
			this.pageYOffset = document.body.scrollTop;
			this.pageXOffset = document.body.scrollLeft;
			this.innerHeight = document.body.clientHeight;
			this.innerWidth = document.body.clientWidth;
		}
		return this;
    },
    init: function(el) {
    	jQuery(el).css("display","");
        jQuery(el).css("left",Math.round(viewport.o().innerWidth/2) + viewport.o().pageXOffset - Math.round(jQuery(el).width()/2));
        jQuery(el).css("top",Math.round(viewport.o().innerHeight/2) + viewport.o().pageYOffset - Math.round(jQuery(el).height()/2));
    }
};// End Simple Pop out DIV
//Get X and Y position of an element
var elementPos = {
	init: function(el)
	{
		xPos = document.getElementById(el).offsetLeft;
		tempEl = document.getElementById(el).offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
		
		yPos = document.getElementById(el).offsetTop;
		tempEl = document.getElementById(el).offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		yPos = yPos - 250;
		window.scroll(xPos,yPos); 
  }
};//End Get X and Y position of an element
jQuery.fn.reset = function () { //Reset Form
  jQuery(this).each (function() { this.reset(); });
}

$(function() {
	//Article Rating 
	/*jQuery('.auto-submit-star').rating({
		callback: function(value, link){
		contentid = jQuery(this).attr('id'); 
		jQuery.ajax({
			type: "POST",
				data: "option=com_urcomment&task=articlerating&contentid="+contentid+"&rating="+value,
				url: WebsitePath+"index2.php",
				success: function(responseText)
				{
					jQuery(".rateMsg_inner").remove();
					var ratingDiv = "<div class='rateMsg_inner'>"+responseText+"</div>";
					jQuery(".rateMsg").html(ratingDiv);
					setTimeout(function(){
						jQuery(".rateMsg_inner").fadeOut();
						jQuery(".rateMsg_inner").remove();
					}, 5000);			
				}
			});
		}
	});//End Article Rating
	*/
	// Ajax Verify and Add Comment
  	jQuery(".submitClass").click(function() { 
	var ur_contentid = jQuery("#contentid").val();
	if (ur_contentid == "") {
      	jQuery('#errorMessage').html("Comment Must have article!!");
      	return false;
    }
	var ur_parentid = jQuery("#parentid").val();
	if (ur_parentid == "") {
		ur_parentid = "-1";
    }
    
	var ur_userid = jQuery("#ur_userid").val();
	if(ur_userid==0){
		var ur_name = jQuery("input#ur_name").val();
		if (ur_name == "") {
	      	jQuery('#errorMessage').html("Please Fill in Your Name!");
	      	jQuery("input#ur_name").focus();
	      	return false;
	    }
		var ur_email = jQuery("input#ur_email").val();	
		if(validateEmail(ur_email)){			
	 		jQuery('#errorMessage').html("Please Enter A Valid Email Address.");
	  		jQuery("input#ur_email").focus();
	  		return false;
		}
	}
	if( jQuery("#ur_title").length > 0 ){ 	
		var ur_title = jQuery("input#ur_title").val();
		if (ur_title == "") {
	     	jQuery('#errorMessage').html("Please Fill in Comment Title!");
	      	jQuery("input#ur_title").focus();
	      	return false;
	    }
	}else{
		var ur_title = "";
	}
	var ur_comment = jQuery("#ur_comment").val();
	if (ur_comment == "") {
     	jQuery('#errorMessage').html("Please Fill in Your Comment!");
      	jQuery("#ur_comment").focus();
      	return false;
    }
	var ur_captchacode = "";
    if( jQuery("#ur_verify").length > 0 ){ 
		ur_captchacode = jQuery("#ur_verify").val();
		if (ur_captchacode=="") {
	      	jQuery('#errorMessage').html("Please Fill in Verify Code!");
      		jQuery("#ur_verify").focus();
	      	return false;
	    }
	}  
    if( jQuery("#ur_agreement").length > 0 ){ 
		var ur_agreement = jQuery("#ur_agreement").attr("checked");
		if (!ur_agreement) {
	      	jQuery('#errorMessage').html("Please Read and Accept Term and Agreement!");
	      	return false;
	    }
	}  
    var ur_notify;
	if(jQuery("#ur_notify").attr("checked")){ ur_notify = '1'; }else { ur_notify = '0'; }
	var ur_website = jQuery("input#ur_website").val();
	var dataString = 'option=com_urcomment&task=saveUrComment&ur_contentid=' + ur_contentid + '&ur_parentid=' + ur_parentid + '&ur_name='+ ur_name + '&ur_email=' + ur_email + '&ur_website=' + ur_website + '&ur_title=' + ur_title + '&ur_comment=' + ur_comment + '&ur_notify=' + ur_notify + '&ur_userid=' + ur_userid + '&ur_captchacode=' + ur_captchacode;
	jQuery.ajax({
    	type: "POST",
    	url: WebsitePath+"index2.php",
    	data: dataString,
    	success: function(responseText, responseStatus) {
	    	jQuery('#errorMessage').html("");
    		jQuery('#allcomments').html(responseText);
    		if( jQuery("#newcomment").length > 0 ){ 
	    		elementPos.init('newcomment');
	    		jQuery('#newcomment').fadeIn();
	            setTimeout(function(){
	                jQuery('#newcomment').fadeOut();
	            }, 5000);		
	            var randomnumber=Math.floor(Math.random()*1001);
	            jQuery('#captchacode').attr("src",WebsitePath+"components/com_urcomment/fonts/captchaimage.php?randomnumber="+randomnumber);		
				jQuery("#form").reset();
			}
        }
     });
	}); //End Ajax Add Comment
	//Refresh Captcha
    jQuery(".refreshcaptcha").click(function(e){
		e.preventDefault();
		jQuery.ajax({
	    	type: "POST",
	    	url: WebsitePath+"index2.php",
	    	data: "option=com_urcomment&task=refreshcaptcha",
    		success: function(responseText, responseStatus) {
				var randomnumber=Math.floor(Math.random()*1001);
				jQuery('#captchacode').attr("src",WebsitePath+"components/com_urcomment/fonts/captchaimage.php?randomnumber="+randomnumber);
	        }
	     });
    });	     
	//Counting Comment Character 
	var countdown = {
        init: function() {
            countdown.countchar = jQuery(countdown.obj).val().length;
            if (countdown.countchar > countdown.max) {
                jQuery(countdown.obj).val(jQuery(countdown.obj).val().substring(0,countdown.max));
            	jQuery(".commentcount").html("<span style='color:#FF0000;font-weight:bold;'>"+countdown.countchar+"</span>");
            }else{	            
            	jQuery(".commentcount").html(countdown.countchar);
        	}
        },
        max: null,
        countchar: null,
        obj: null
    };
    jQuery(".countdown").each(function() {
        jQuery(this).focus(function() {
            var c = jQuery(this).attr("class");
            countdown.max = parseInt(c.match(/limit_[0-9]{1,}_/)[0].match(/[0-9]{1,}/)[0]);
            countdown.obj = this;
            iCount = setInterval(countdown.init,1000);
        }).blur(function() {
            countdown.init();
            clearInterval(iCount);
        });
    });// End Counting Comment Character    
	
    // Popup Agreement
    jQuery("#agreementDIV").each(function(){
        jQuery(this).css("display","none");
        jQuery("#popup_agreement").click(function(e){
			e.preventDefault();
            jQuery(".popup_inner").remove();
            windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><b> Term and Agreement </b></div><div class='popup_content'>"+jQuery("#agreementDIV").html()+"</div><div class='popup_footer'></div></div>";  
            jQuery("#popupdiv").append(windowDiv);
            viewport.init("#popupdiv");
            jQuery(".popup_close").click(function(){
                jQuery(".popup_inner").remove();   	                
	        	jQuery("#popupdiv").css("display","none");             
                return false;
            });
        });
    });// End Popup Agreement 
    
    // Email This 
    jQuery(".emailThis").click(function(e){
		e.preventDefault();
        //Sending to ajax get the email form
    	var content_id = jQuery(this).attr("id");
    	jQuery.ajax({
	    	type: "POST",
	    	url: WebsitePath+"index2.php?option=com_urcomment&task=emailthis&contentid="+content_id,
	    	data: "",
	    	success: function(responseText, responseStatus) {
				windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><img src='"+WebsitePath+"components/com_urcomment/images/emailthis.gif' alt='Email This'><b> Email This </b></div><div class='popup_content'>"+responseText+"</div><div class='popup_footer'></div></div>";  
	            jQuery("#popupdiv").html(windowDiv);
	            viewport.init("#popupdiv");
	            jQuery(".popup_close").click(function(){
	                jQuery(".popup_inner").remove(); 	                
	        		jQuery("#popupdiv").css("display","none");               
	                return false;
	            });	             
	            jQuery("#emailForm").submit(function(e){ // Share This Article
					e.preventDefault();
					var contentid = jQuery("#contentid").val();
					var ur_name = jQuery("input#yourname").val();
					if (ur_name == "") {
				      	jQuery('#errorEmail').html("Please Fill in Your Name!");
				      	jQuery("input#yourname").focus();
				      	return false;
				    }
					var ur_email = jQuery("input#youremail").val();	
					if(validateEmail(ur_email)){			
				 		jQuery('#errorEmail').html("Please Enter Your Valid Email.");
				  		jQuery("input#youremail").focus();
				  		return false;
					}
					var ur_friendemail = jQuery("input#friendemail").val();	
					if(validateEmail(ur_friendemail)){			
				 		jQuery('#errorEmail').html("Please Enter Your Friend Valid Email.");
				  		jQuery("input#friendemail").focus();
				  		return false;
					}
					var ur_subject = jQuery("input#subject").val();	
					if(ur_subject == ""){			
				 		jQuery('#errorEmail').html("Please Fill in Email Subject.");
				  		jQuery("input#subject").focus();
				  		return false;
					}
					var dataString = 'option=com_urcomment&task=sendemail&contentid=' + contentid + '&ur_name=' + ur_name + '&ur_email='+ ur_email + '&ur_friendemail=' + ur_friendemail + '&ur_subject=' + ur_subject;
					jQuery.ajax({
				    	type: "POST",
				    	url: WebsitePath+"index2.php",
				    	data: dataString,
				    	success: function(responseText, responseStatus) {
	                		jQuery(".popup_content").html(responseText);
				        }
				     });
    			});// End Email This  
	        }
	     });
    }); 
    
	// Bookmark Pop out DIV
    jQuery(this).css("display","none");
    jQuery(".bookmark").click(function(e){
 		e.preventDefault();  
    	content_id = jQuery(this).attr("id");
    	jQuery.ajax({
	    	type: "GET",
	    	url: WebsitePath+"index2.php?option=com_urcomment&task=bookmarking&contentid="+content_id,
	    	data: "",
	    	success: function(responseText, responseStatus) {
				windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><img src='"+WebsitePath+"components/com_urcomment/images/bookmark.gif' alt='Bookmark'><b> Bookmark </b></div><div class='popup_content'>"+responseText+"</div><div class='popup_footer'></div></div>";  
	            jQuery("#popupdiv").html(windowDiv);
	            viewport.init("#popupdiv");
	            jQuery(".popup_close").click(function(){
	                jQuery(".popup_inner").remove(); 	                
	        		jQuery("#popupdiv").css("display","none");               
	                return false;
	            });
	        }
	     });
    });// End Bookmark Pop out DIV
    
	jQuery().ajaxSend(function(r,s){
	  jQuery("#loading").show();
	});
	
	jQuery().ajaxStop(function(r,s){
	  jQuery("#loading").fadeOut("fast");
	});	
	
});
	//Delete Comment by Moderator at Website
	function deleteComment(the_id,contentid){
		
		var deletecontent = document.getElementById('deletediv').innerHTML;
        jQuery(".popup_inner").remove();
    	windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><b>Delete Comment</b></div><div class='popup_content'>"+deletecontent+"</div><div class='popup_footer'></div></div>";  
    	jQuery("#popupdiv").html(windowDiv);
    	viewport.init("#popupdiv");
		jQuery('.popup_inner').fadeIn();
	    jQuery(".popup_close").click(function(){
	        jQuery(".popup_inner").remove();      
	        jQuery("#popupdiv").css("display","none");                
	        return false;
    	});	
		jQuery(".confirmNot").click(function(){
	        jQuery(".popup_inner").remove();      
	        jQuery("#popupdiv").css("display","none");  
		});
		jQuery(".confirmDelete").click(function(){ //update content value
			jQuery(".popup_inner").remove();      
			jQuery("#popupdiv").css("display","none"); 
			jQuery.ajax({
				type: "POST",
				data: "option=com_urcomment&task=deletecomment&commentid="+the_id+"&contentid="+contentid,
				url: WebsitePath+"index2.php",
				success: function(responseText)
				{
	    			jQuery('#allcomments').html(responseText);
				}
			});
		});//End Confirm Delete
	};
	//Publish/Unpublish Comment by Moderator at Website
	function publishComment(the_id,contentid,caction){
		
		jQuery.ajax({
			type: "POST",
			data: "option=com_urcomment&task=publishcomment&commentid="+the_id+"&contentid="+contentid+"&caction="+caction,
			url: WebsitePath+"index2.php",
			success: function(responseText)
			{	
    			jQuery('#allcomments').html(responseText);
			}
		});
	};
    	
	//Edit Comment in Website 
	function editComment(the_id){
		
    	var divname = "#content-"+the_id;
    	var textareaname = "textarea-"+the_id;
    	var textareaid = "#textarea-"+the_id;
    	var buttonname = "button-"+the_id;
    	var cancel = "cancel-"+the_id;
    	var text = jQuery(divname).html();    	
    	if(jQuery(textareaid).length==0){
    		jQuery(divname).html("<textarea id=\""+textareaname+"\" name=\"commentarea\" style=\"width:90%\" rows=\"3\">"+text+"</textarea><br/><input type=\"button\" class=\"editButton\" id=\""+buttonname+"\" value=\"Edit\">&nbsp;<input type=\"button\" class=\"cancelButton\" id=\""+cancel+"\" value=\"Cancel\">");
		}
    	
		jQuery(".cancelButton").click(function(){
	    	jQuery(divname).html(text);
		});
		jQuery(".editButton").click(function(){ //update content value
			var button_id = jQuery(this).attr('id');
			
			var mySplit = button_id.split("-");
			var text_id = "#textarea-"+mySplit[1];
	    	var editcontent = jQuery(text_id).val();
	    	
			jQuery.ajax({
				type: "POST",
				data: "option=com_urcomment&task=editcomment&editcontent="+editcontent+"&commentid="+mySplit[1],
				url: WebsitePath+"index2.php",
				success: function(responseText)
				{
		            jQuery(".popup_inner").remove();
	            	windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><b>Edit Comment</b></div><div class='popup_content'>"+responseText+"</div><div class='popup_footer'></div></div>";  
	            	jQuery("#popupdiv").html(windowDiv);
	            	viewport.init("#popupdiv");
		    		jQuery('.popup_inner').fadeIn();
				    jQuery(".popup_close").click(function(){
				        jQuery(".popup_inner").remove();      
				        jQuery("#popupdiv").css("display","none");                
				        return false;
			    	});	
		            
	    		var divname = "#content-"+mySplit[1];
	    		jQuery(divname).html(editcontent);
				}
			});
		});
	}//End Edit Comment in Website
	
//Reply Comment 
function replyComment(the_id){
	document.getElementById('parentid').value = the_id;
	if (document.getElementById('ur_title') != null) {
		document.getElementById('ur_title').value = "#Reply Comment ";
	}
}//End Reply Comment

//Report Abuse on Comment 
function reportComment(the_id){
	jQuery.ajax({
		type: "POST",
		data: "option=com_urcomment&task=report&commentid="+the_id,
		url: WebsitePath+"index2.php",
		success: function(responseText)
		{
            jQuery(".popup_inner").remove();
        	windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><b>Report </b></div><div class='popup_content'>"+responseText+"</div><div class='popup_footer'></div></div>";  
        	jQuery("#popupdiv").append(windowDiv);
        	viewport.init("#popupdiv");
    		jQuery('.popup_inner').fadeIn();
            jQuery(".popup_close").click(function(){
                jQuery(".popup_inner").remove(); 	                
        		jQuery("#popupdiv").css("display","none");                 
                return false;
            });

		}
	});
}//End Report Abuse on Comment
	
//Voting Good for Comment
function goodVote(the_id){
	jQuery.ajax({
		type: "POST",
		data: "option=com_urcomment&task=voting_good&commentid="+the_id,
		url: WebsitePath+"index2.php",
		success: function(responseText)
		{
            jQuery(".popup_inner").remove();
        	windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><b>Voting </b></div><div class='popup_content'>"+responseText+"</div><div class='popup_footer'></div></div>";  
        	jQuery("#popupdiv").html(windowDiv);
        	viewport.init("#popupdiv");
    		jQuery('.popup_inner').fadeIn();
            jQuery(".popup_close").click(function(){
                jQuery(".popup_inner").remove();   	                
        		jQuery("#popupdiv").css("display","none");             
                return false;
            });
            
			jQuery.ajax({
				type: "POST",
				data: "option=com_urcomment&task=get_votegood&commentid="+the_id,
				url: WebsitePath+"index2.php",
				success: function(responseText)
				{
				jQuery("#vote_good"+the_id).html(responseText);
				jQuery("#vote_good"+the_id).fadeIn();
				}
			});
		}
	});
}//End Voting Good for Comment

//Voting Bad for Comment 
function badVote(the_id){
	jQuery.ajax({
		type: "POST",
		data: "option=com_urcomment&task=voting_bad&commentid="+the_id,
		url: WebsitePath+"index2.php",
		success: function(responseText)
		{
            jQuery(".popup_inner").remove();
        	windowDiv = "<div class='popup_inner'><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><b>Voting </b></div><div class='popup_content'>"+responseText+"</div><div class='popup_footer'></div></div>";  
        	jQuery("#popupdiv").html(windowDiv);
        	viewport.init("#popupdiv");
    		jQuery('.popup_inner').fadeIn();
            jQuery(".popup_close").click(function(){
                jQuery(".popup_inner").remove();   	                
        		jQuery("#popupdiv").css("display","none");             
                return false;
            });
			jQuery.ajax({
				type: "POST",
				data: "option=com_urcomment&task=get_votebad&commentid="+the_id,
				url: WebsitePath+"index2.php",
				success: function(responseText)
				{
				jQuery("#vote_bad"+the_id).html(responseText);
				jQuery("#vote_bad"+the_id).fadeIn();
				}
			});
		}
	});
}//End Voting Bad for Comment
	
//Show Comment Navigation Pagin
function navigate(nopagin, contentid){
	
		jQuery.ajax({
			type: "POST",
			data: "option=com_urcomment&task=pagincomment&startpagin="+nopagin+"&contentid="+contentid,
			url: WebsitePath+"index2.php",
			success: function(responseText)
			{
				jQuery("#allcomments").html(responseText);
			}
		});		
}//Show Comment Navigation Pagin
//View You Tube
function viewYouTube(id){  		
		windowDiv = "<div class=\"popup_inner\"><div class='popup_header'><div style='float:right;'><a href='#' class='popup_close'>[ Close ]</a></div><b>You Tube Video</b></div><div class=\"video\"><object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+id+"\"></param><param name=\"wmode\"></param><embed src=\"http://www.youtube.com/v/"+id+"\" type=\"application/x-shockwave-flash\" width=\"425\" height=\"350\"></embed></object></div><div class='popup_footer'></div></div>";
	    jQuery("#popupdiv").html(windowDiv);  
	    viewport.init("#popupdiv");
	    jQuery(".popup_close").click(function(){
	        jQuery(".popup_inner").remove();      
	        jQuery("#popupdiv").css("display","none");                
	        return false;
    	});	
}//End View You Tube
    
//function Validate Email contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
function validateEmail(email){
	if(! /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email)){
	      	return true;
		}
}//End Validate Email

// Add Emoticon to Textarea
function addEmoticon(icon, form_id, text_id) {
	
	var textarea = $(text_id);
	if (!isNaN(textarea.selectionStart))//for firefox
	{
		var sel_start = textarea.selectionStart;
		var sel_end = textarea.selectionEnd;
		
		var selLength = textarea.textLength;
		var selStart = textarea.selectionStart;
		var selEnd = textarea.selectionEnd;
		var scrollTop = textarea.scrollTop;
	
		if (selEnd == 1 || selEnd == 2) 
		{
			selEnd = selLength;
		}
	
		var s1 = (textarea.value).substring(0,selStart);
		var s2 = (textarea.value).substring(selStart, selEnd);
		
		textarea.value = s1 + s2 + icon;
		textarea.selectionStart = selEnd + icon.length;
		
		textarea.selectionEnd = $(text_id).selectionStart;
		textarea.focus();
		textarea.scrollTop = scrollTop;
		textarea.selectionStart = sel_start + icon.length;
		textarea.selectionEnd = sel_end + icon.length;
	}
	else if (textarea.createTextRange && textarea.caretPos)//before insert have word (IE)
	{
		if (baseHeight != textarea.caretPos.boundingHeight) 
		{
			textarea.focus();
			storeCaret(textarea);
		}
		var caret_pos = textarea.caretPos;
		caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + icon + ' ' : caret_pos.text + icon;
	}
	else //before insert is blank (IE)
	{
		textarea.value = textarea.value + icon; 
	}
	textarea.focus();
}// End Add Emoticon to Textarea

// BBCode and Emoticon Mouseover and Mouseout
function dropShadow(id) {
	return false;
}

function blurShadow(id) {
	return false;
}

function overEmoticon(id) {
	return false;
}

function blurEmoticon(id) {
	return false;
}
// End BBCode and Emoticon Mouseover and Mouseout
