function jsonCall(url){
	var newelem = document.createElement("script");
	newelem.setAttribute("type","text\/javascript");
	var t=new Date();
	//t.getTime();
	//url +="&t=" + t ;
	newelem.setAttribute("src",url);
	document.getElementsByTagName("head")[0].appendChild(newelem);
}


var GenericComments={
	ajaxCommUrl:"http://eksenim.mynet.com/~Ajax/genericCommentHandler.ashx?url="+encodeURIComponent(window.location.href) ,	
	getCommUrl:"http://eksenim.mynet.com/ep/GetComments.aspx?url="+encodeURIComponent(window.location.href) ,	
	containerDiv:'',
	lockAdd:0,
	commentText :'',
	processTitle:'',
	//processTitle:'Yorumlar getiriliyor...',
	AddComment:function (JSON)
	{
		var COMMENT=document.getElementById('txtComment').value;
		if(COMMENT.length>500){
			this.CommentAlert( '500 karakterden fazla giremezsin.','error');
			return ;
		}


		if(this.lockAdd==0){
			this.lockAdd=1;
			document.getElementById('lnkCommentMain').innerHTML = '<span>Gönderiliyor...</span>';
			var addurl=  this.MakeUrl('add',JSON) + '&comment=' + COMMENT ;
			jsonCall(addurl);
		}


	},
	DeleteComment:function (JSON){ 

		var counts=parseInt(document.getElementById('commentcount').innerHTML);
		
		try{
			document.getElementById('commentcount').innerHTML=counts-1; //id generic değil!!!
			document.getElementById('commentDiv'+ JSON.cid).style.display = 'none';
		}catch(e){}
		
		//if(counts==1){
		//	document.getElementById('countSection').innerHTML="İçeriğe ait yorum yok.";
		//}

		var delurl= this.MakeUrl('del',JSON);
		jsonCall(delurl);
	},
	GetComments:function(JSON){ //cdiv ch mcid contentowner cn subcn p psize
		this.commentText='';
		document.getElementById(JSON.cdiv).innerHTML = '<p class="picinfo">'+ this.processTitle +'</p>';
		this.containerDiv=JSON.cdiv;
		var getUrl = this.MakeUrl('get',JSON);
		jsonCall(getUrl);
	},
	ApproveComment:function (JSON){ 

		var appUrl = this.MakeUrl('app',JSON);
		jsonCall(appUrl);
		document.getElementById('lnkAppComment'+ JSON.cid).innerHTML="<span>Onaylanıyor...</span>";
	},
	ShowResult:function(JSON){ 

		if(JSON.issuccess){
			
			if(JSON.action=='add'){
			
					document.getElementById('writeCommentDiv').style.display  = 'none';
					document.getElementById('lnkCommentMain').style.display  = 'none';

					if(document.getElementById('commentEmpty')!=null){
						document.getElementById('commentEmpty').style.display = 'none';
					}

					document.getElementById('commentResult').style.display  = 'block';	
					this.lockAdd=0;
			}else if(JSON.action=='del'){

					document.getElementById('commentDiv'+ JSON.commentid).style.display = 'none';

			}else if(JSON.action=='app'){

					document.getElementById('lnkAppComment'+ JSON.commentid).style.display = 'none';
			}
		}
	},
	CommentAlert:function(msg,type){
		alert(msg);
	},
	GetCharsLeft:function (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ısaltmalısın. </p>';
		}
	},
	SetComments:function(COMMENT){ //pageoutputa sığmadığı zaman birden fazla kez çağrılır!!!
		this.commentText += COMMENT;
		document.getElementById(this.containerDiv).innerHTML = this.commentText;
	},
	MakeUrl:function(action,JSON){
		var BaseUrl=this.ajaxCommUrl;
		if(action=='get'){
			BaseUrl=this.getCommUrl;
		}
		var url= BaseUrl + '&action=' + action + '&ch='+ encodeURIComponent(JSON.ch) + '&mcid=' + JSON.mcid + '&cn=' + JSON.cn + '&subcn='  + JSON.subcn + '&contentowner=' + JSON.contentowner + '&commentowner=' + JSON.commentowner + '&cid=' + JSON.cid  + '&cdiv=' + JSON.cdiv + '&p=' + JSON.p + '&psize=' + JSON.psize;
		return url;
	}
}