function commentVote(commentID) {				
	$('comentariuBttVote'+commentID).hide();
	
	voteThanks(commentID);
	
	new Ajax.Request(pathWWW+'/getajax|comment_vote',  {
		method:'post',
		parameters: {cID: commentID },
		onSuccess: function(transport){    				    				
			var response = transport.responseText;  
			if(response > 0)   				
				updateCommentVotes(commentID,response);    					
		},
		onFailure: function(){  }
	});
}

function updateCommentVotes(commentID,votes) {
	$('voturi'+commentID).update("+"+votes);								
	$('voturi'+commentID).show();
}

function voteThanks(commentID,username) {
	showToolTipFader('Multumesc pentru VOT!',$('thanksComment'+commentID));
	return false;
}

function commentReplyShow(commentID) {				
	Effect.toggle($('commentPost'+commentID),'appear',{duration: 0.5});	
	$('bodyComentariu'+commentID).value = '';	
	if($('usernameComentariu'+commentID))
		$('usernameComentariu'+commentID).value = '';					
}

function commentPostNew(parentID,articleID) {
	if(validateCommentFields(parentID)) {
		
		if($('usernameComentariu'+parentID))
			var username = $('usernameComentariu'+parentID).value;
		else
			var username = '';
		
		var body = 	$('bodyComentariu'+parentID).value;
		
		
		new Ajax.Request(pathWWW+'/getajax|comment_add',  {
		method:'post',
		parameters: {cArticleID: articleID, cParentID: parentID, cUsername: username, cBody: body },
		onSuccess: function(transport){    				    				
			var response = transport.responseText;  
			
			if($('usernameComentariu'+parentID))
				$('usernameComentariu'+parentID).value = '';							
			$('bodyComentariu'+parentID).value = '';			
					
			if(parentID > 0) {   
				new Effect.ScrollTo($('comment'+parentID), {duration: 0.3}); 					
				$('replies'+parentID).insert({top:response});
				$('commentPost'+parentID).hide();
			} else {															
				new Effect.ScrollTo($('Hcomentarii'), {duration: 0.3});
				$('commentContainer').insert({top: response});							
			}	
			var currentVal = parseInt($('commentCounter').innerHTML);
			$('commentCounter').update(currentVal+1);
			    					
		},
			onFailure: function(){  }
		});
		
		
		
	}
	
}

function validateCommentFields(commentID) {
	if($('usernameComentariu'+commentID))
		var cUser 	= $('usernameComentariu'+commentID);

	var cText 	= $('bodyComentariu'+commentID);
	if(cUser) {
		if(Validation.get('required').test(cUser.value)) { } else {
			showToolTipFader('Completati numele dumneavostra.',cUser);
			cUser.focus();
			return false;
		}
	}

	if(Validation.get('required').test(cText.value)) {	} else {
		showToolTipFader('Adaugati comentariul',cText);
		cText.focus();
		return false;
	}
	return true;
}


function commentDelete(commentID) {
	var ok = confirm('Sterge comentariu? \n OK pentru sterge, Cancel pentru a reveni');
	if(ok==true) {
		new Ajax.Request(pathWWW+'/getajax|comment_delete',  {
		method:'post',
		parameters: {cID: commentID },
		onSuccess: function(transport){    				    				
			var response = transport.responseText;  
			if(response == 1)   				
				$('comment'+commentID).remove();    					
				
			if(response == 2) {
				$('comment'+commentID).remove();
				$('replies'+commentID).remove();
			}	
			},
			onFailure: function(){  }
		});
	} else
		return false;				
}

function commentReport(commentID) {
	var ok = confirm('Moderatorii nostri vor verifica acest comentariu.\n Doriti sa raportati comentariul ca fiind un abuz? \n OK pentru introduce, Cancel pentru a reveni');
	if(ok==true) {
		new Ajax.Request(pathWWW+'/getajax|comment_report',  {
		method:'post',
		parameters: {cID: commentID },
		onSuccess: function(transport){    				    				
			var response = transport.responseText;  
				if(response == 1) {  				
  				$('commentBttReport'+commentID).hide();	    				
  			}	
			},
			onFailure: function(){  }
		});
	} else
		return false;
}

function commentAttach(commentID) {
	var ok = confirm('Doriti sa introduceti comentariul in textul articolului? \n OK pentru introduce, Cancel pentru a reveni');
	if(ok==true) {
		new Ajax.Request(pathWWW+'/getajax|comment_attach',  {
		method:'post',
		parameters: {cID: commentID },
		onSuccess: function(transport){    				    				
			var response = transport.responseText;  
			if(response == 1) {  				
				$('commentBttAttach'+commentID).hide();
				$('commentBttDeattach'+commentID).show();
			}	
			},
			onFailure: function(){  }
		});
	} else
		return false;			
}

function commentDeattach(commentID) {
	var ok = confirm('Doriti sa scoateti comentariul din textul articolului? \n OK pentru a scoate comentariul, Cancel pentru a reveni');
	if(ok==true) {
		new Ajax.Request(pathWWW+'/getajax|comment_deattach',  {
		method:'post',
		parameters: {cID: commentID },
		onSuccess: function(transport){    				    				
			var response = transport.responseText;  
			if(response == 1)   				
				$('commentBttDeattach'+commentID).hide();
				$('commentBttAttach'+commentID).show();	    				
			},
			onFailure: function(){  }
		});
	} else
		return false;			
}



function commentBan(commentID) {
	var obj = $('commentBttBan'+commentID);
	new Ajax.Request(pathWWW+'/getajax|comment_ban',  {
		method:'post',
		parameters: {cID: commentID },
		onSuccess: function(transport){    				    				
			var response = transport.responseText;  
			showToolTipFader(response,$('commentBttBan'+commentID),1);		    				
			},
			onFailure: function(){  }
		});
}

function comment_doBan() {
	var commentID = $('banCommentID').value;
	var banType = $('comment_banType').value;
	var banObs = $('comment_banObs').value;
	
	new Ajax.Request(pathWWW+'/getajax|comment_ban',  {
		method:'post',
		parameters: {cID: commentID, cBanType: banType, cBanObs: banObs, doBan: 1},
		onSuccess: function(transport){    				    				
			var response = transport.responseText; 
			hidePopup();			
			$('comment'+commentID).remove();
			if($('replies'+commentID))
				$('replies'+commentID).remove();	
			},
			onFailure: function(){  }
	});			
	
}
var CountActive = false;

function comment_limit_on(diff) {
	if($('postCommentBottom'))
		$('postCommentBottom').hide();		
	
	if($('postCommentLimit')) {
		/*$('countDownLimit').update(diff);*/
		$('postCommentLimit').show();
		CountActive = true;	
		CountBack(diff);
	}

	if($$('a.raspunde_comentariu'))
		$$('a.raspunde_comentariu').each(function(s) {s.hide()});		
	
	
}

function comment_limit_off() {
	if($('postCommentLimit'))
		$('postCommentLimit').hide();

	if($('postCommentBottom'))
		$('postCommentBottom').show();
	
	if($$('a.raspunde_comentariu'))
		$$('a.raspunde_comentariu').each(function(s) {s.show()});
}

function insertSmiley(myField, myValue) {
		//IE support
		if (document.selection) {
			myField.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
		}
		//MOZILLA/NETSCAPE support
		else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
		} else {
			myField.value += myValue;
		}
		myField.focus();
}


