var jComments = jQuery.noConflict();

function commentAlertMessage(msg,type){
	alert(msg);
}

function GetContentComments(mDiv, mcId, url, pg, enc, owner, ps)
{
	window.onload = function (){ ChangeCommentPage(mDiv, mcId, url, pg, enc, owner, ps); };
}


function ChangeCommentPage(mDiv, mcIdx, url, pg, enc, owner, ps)
{
	
	document.getElementById(mDiv).innerHTML = '<p class="picinfo">Yorumlar getiriliyor...</p>';
	commentText = '';
	var comUrl = 'http://eksenim.mynet.com/ep/Comments.aspx?mcidcontent=' + mcIdx + '&mDiv=' + mDiv + '&p=' + pg + '&url=' + url;

	s=0;
	
	if (enc != null){
		comUrl += '&enc=' + enc;
	}
	
	if (owner != null && ps != null){
		comUrl += '&owner=' + owner + '&ps=' + ps;
	}else if(owner != null ){
		comUrl += '&owner=' + owner ;
	}


 	jsonCall(comUrl);
}



var commentText = '';
function SetComments(text, mDiv)
{
	//alert(text);
	commentText += text;
	document.getElementById(mDiv).innerHTML = commentText;

}


function AddCommentToContent(m, comment, commentId,commentTopic,enckey,contentowner,isdetail) 
{
	if(m.substring(0,10)>=3000000000)
    {
		if (commentId == 0)//yeni yorum
		{
			if(commentTopic.length=="0" )
			{
				commentAlertMessage( 'Yorumunuza Başlık Girmediniz!','Hata');
				return;
			}
		}

		if (commentTopic == null)
		{
			commentTopic = "";
		}
    }
	

	if(comment.length>2000){
		commentAlertMessage('Hata', '2000 karakterden fazla giremezsin.');
		return ;
	}

	if (commentId == null)
	{
		commentId = 0;
	}

	if (commentId == 0)
	{
		document.getElementById('lnkCommentMain').innerHTML = '<span>Gönderiliyor...</span>';
	}


	addCommUrl='http://eksenim.mynet.com/~AjaxNew/commentHandler.ashx?cf=showAddResult&f=add&mcid=' +m + '&c='+comment+'&cid='+commentId + '&ctpc=' + commentTopic + '&encx='+ encodeURIComponent( enckey) + '&owner=' + contentowner;
	jsonCall(addCommUrl);
}



function showAddResult(issuccess,commentid){
	
	/*
	if (commentId != 0)
	{
		document.getElementById('answerDiv' + commentId).innerHTML = '<p>'+tNotComment+'</p>';
		document.getElementById('answerDiv' + commentId).style.display = 'block';
	}
	else
	{

	}*/

	if(issuccess){
		document.getElementById('writeCommentDiv').style.display  = 'none';	
		if(document.getElementById('commentEmpty')!=null){
			document.getElementById('commentEmpty').style.display = 'none';
		}
		document.getElementById('commentResult').style.display  = 'block';	
	}
}

function GetCommentsCharsLeft(length)
{
	if(isNaN(length)){
	 length=500;
	}

	var chrLeft = length - document.getElementById('txtComment').value.length;
	if(chrLeft >= 0){
		document.getElementById('charsLeft').innerHTML = '<p>' + chrLeft + ' karakter kaldı</p>';
	}else{
		document.getElementById('charsLeft').innerHTML = '<p>' + (-chrLeft) + ' karakter fazladan yazmışsın. Yorumunu kısalt. </p>';
	}
}


var openCommentDiv = 0;
function ShowCommentAnswerPanel(commentId)
{
	if (IsAuthenticated)
	{
		try{
			if (openCommentDiv != 0 && openCommentDiv != commentId)
			{
				document.getElementById('answerDiv' + openCommentDiv).style.display = 'none';
			}
			
			if (document.getElementById('answerDiv' + commentId).style.display == 'none')
			{
				document.getElementById('answerDiv' + commentId).style.display= 'block';
				openCommentDiv = commentId;
			}
			else
			{
				document.getElementById('answerDiv' + commentId).style.display= 'none';
			}
		}catch(e){

		}
	}
}


function DeleteComment(mcid, commentId,enckey,owner){

	delCommUrl='http://eksenim.mynet.com/~AjaxNew/commentHandler.ashx?cf=showDeleteResult&f=del&mcid=' +mcid + '&cid='+commentId + '&encx='+ encodeURIComponent( enckey) + '&owner=' + owner;
	jsonCall(delCommUrl);
}



function showDeleteResult(issuccess,commentId){
	if(issuccess){
		document.getElementById('commentDiv'+ commentId).style.display = 'none';
	}
}


function ApproveComment(mcid, commentId,enckey,owner){

	delCommUrl='http://eksenim.mynet.com/~AjaxNew/commentHandler.ashx?cf=showApproveResult&f=app&mcid=' +mcid + '&cid='+commentId + '&encx='+ encodeURIComponent( enckey) + '&owner=' + owner;
	jsonCall(delCommUrl);
	document.getElementById('lnkAppComment'+ commentId).innerHTML="<span>Onaylanıyor...</span>";
}


function showApproveResult(issuccess,commentId){
	if(issuccess){
		document.getElementById('lnkAppComment'+ commentId).style.display = 'none';
	}
}                    