//******************************************************************************


function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}


////////////////////////////////////////FOR AJAX COMMENT ING ON News Detail PAGE//////////////////////////


var xmlHttp;
var divId="";
var txt='';

//*****************************************************************************
function htmlData(url,did)
{
	divId=did;	
  document.getElementById(divId).innerHTML="<img src='images/load.gif' border='0'>";

	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url=url;

	xmlHttp.onreadystatechange=stateChanged1 ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged1()
{ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	
	 document.getElementById(divId).innerHTML="";
	    msg=xmlHttp.responseText ;
		msg1=	msg.split("-");
		if(msg1[0]=='no'){
			document.getElementById(divId).style.display="block"
			document.getElementById(divId).innerHTML=msg1[1] ;
			document.getElementById("submitimage").disabled=true;
			document.getElementById('lastresponse').value='0';
		}else{
			document.getElementById(divId).style.display="block"
			document.getElementById(divId).innerHTML=msg1[1] ;
			document.getElementById("submitimage").disabled=false;
		}
		
	}
} 





function addCommentOnNews(url,nid,path,did)
{	
	divId=did;	
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url=path+url+"?action=addCommentOnNews&comment="+document.getElementById('cmnt').value+"&nid="+nid;	
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged22 ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged22()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
	   
		alert(xmlHttp.responseText);
		document.getElementById(divId).innerHTML=xmlHttp.responseText ;
	}
} 

////////////////////////////////////////FOR AJAX Image set ON member profile PAGE//////////////////////////


function SetImage(imgID,siteurl)
{	
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	//var url=url+"?action=SetImage&imgID="+imgID;	
	var url99=siteurl+"setimage.php?imagId="+imgID;
	xmlHttp.onreadystatechange=stateChanged123 ;
	xmlHttp.open("GET",url99,true);
	xmlHttp.send(null);
} 

function stateChanged123()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		//document.getElementById("propic").innerHTML=xmlHttp.responseText ;
	}
}


////////////////////////////////////////FOR AJAX Image Delete ON member profile PAGE//////////////////////////
function DelImage(imgID)
{	
	//alert(imgID);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url='action.php?action=DelImage&imgID='+imgID;	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response = xmlHttp.responseText;
			window.location.href='usersettings_profilepic.php';
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function show1(path,nid,comment,did,newstitle,catname)
{	
	divId=did;	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url12=path+"getcomment.php?nid="+nid+"&comment="+comment;
	alert(url12)
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		alert(xmlHttp.responseText)	
		//document.getElementById(did).innerHTML=xmlHttp.responseText;
			window.location.href=path+catname+"/"+newstitle;
			//window.location.href='itempage_comments.php?nid='+nid;
		}
	}
	xmlHttp.open("GET",url12,true);
	xmlHttp.send(null);
}	


/*	function stateChangeded()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
	   alert(nid)
		document.getElementById("Textresult").innerHTML=xmlHttp.responseText ;
		displayresult(nid);
	}
}
*/ 

function showcomment(nid)
{
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp1==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var uelcomment="showcomment.php?nid="+nid;
	xmlHttp1.onreadystatechange=function(){
		if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete")
		{		
			document.getElementById(divId).innerHTML=xmlHttp.responseText ;
		}	
	}
	xmlHttp.open("GET",uelcomment,true);
	xmlHttp.send(null);
}

function stateChanged12()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
	    alert(xmlHttp.responseText)
		document.getElementById("Textresult").innerHTML=xmlHttp.responseText ;
	}
} 


function votetoplug(val)
{	
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='action.php?action=plugtovote&id='+val;
	
	xmlHttp.onreadystatechange=function(){
		var vote	=	xmlHttp.responseText;
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 			
			document.getElementById('voted'+val).innerHTML=vote;
			document.getElementById('vote'+val).style.display='none';
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function makefriend1(id)
{	
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='action.php?action=makefriend&friendid='+id;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response	=	xmlHttp.responseText;
			if(response=='1'){
				alert("Kendiniz arkadas olarak ekleyemezsiniz.");
			}else if(response=='2'){
				alert("Bu kullanici zaten arkadas listenizde mevcut.");
			}else{
				alert("Seçili kullanici arkadas listenize eklendi.");
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function displayresult(nid,did)
{ 
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='showcomment.php?nid='+nid;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			document.getElementById(did).innerHTML=xmlHttp.responseText ;
			window.location.href='itempage_comments.php?nid='+nid;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function displayresultcomment(nid,did,commentid)

{
	//alert(did);
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='getchildcomment.php?nid='+nid+'&commentid='+commentid;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			//results=xmlHttp.responseText.split("DEEP");
			
			//document.getElementById(did).innerHTML="";
			//document.getElementById(did).innerHTML=results[0] ;
			//for(i=1; i<results[1]; i++)
			//{
				//var col="collapse"+i;
				//alert(col);
			 //col=new animatedcollapse('showdiv'+i, 1000, false)	
						
			//}
			//alert(xmlHttp.responseText)
			document.getElementById(did).innerHTML+=xmlHttp.responseText ;
			window.location.href='itempage_comments.php?nid='+nid;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}
function votetocomment(cid,nid,type)
{	
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="action.php?action=voteComment&newsid="+nid+"&cid="+cid+"&type="+type;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			//document.getElementById("votedComm"+cid).innerHTML=xmlHttp.responseText ;
			document.getElementById("voteComm"+cid).innerHTML=xmlHttp.responseText;
			document.getElementById("beforevote"+cid).style.display='none';
			document.getElementById("aftervote"+cid).style.display='block';
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function show2(path,nid,comment,commentid,did,i)
{	
	divId=did;	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url12=path+"savecomment.php?nid="+nid+"&comment="+comment+"&commentid="+commentid;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			if(document.getElementById(did).innerHTML=="")
			{ alert(xmlHttp.responseTex)
				document.getElementById(did).innerHTML=	xmlHttp.responseTex;
				window.location.href='itempage_comments.php?nid='+nid;s
			}
			else{
				    var col="collapse"+i;
				    col=new animatedcollapse(did, 1000, true)
	                document.getElementById(did).style.display="block";
					var reslt=(xmlHttp.responseText+ document.getElementById(did).innerHTML);
					document.getElementById(did).innerHTML=reslt;
					window.location.href='itempage_comments.php?nid='+nid;
			}
		}
	}
	xmlHttp.open("GET",url12,true);
	xmlHttp.send(null);
}


/*function checkemailforvote(email,newsid)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url12="action.php?nid="+newsid+"&email="+email+"&action=checkemail";
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response	=	xmlHttp.responseText;
			if(response==2){
				alert("Kullandiginiz e-posta adresi bir buzla kullanicisi tarafindan kullaniliyor. Lütfen buzlamakiçin giris yapin.");
			}else{
				if(response==1){
					alert("This email is already used for this address");
				}else{
					window.location.href="votebyemail.php?to="+email+"&id="+newsid;
				}
			}
		}
	}
	xmlHttp.open("GET",url12,true);
	xmlHttp.send(null);
}*/

function banthis(newsid)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url12="action.php?nid="+newsid+"&action=banthisnews";
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
				document.getElementById("ban123"+newsid).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url12,true);
	xmlHttp.send(null);
}

function bannAdminNews(nid)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url12="action.php?nid="+nid+"&action=banthisAdminNews";
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response	=	xmlHttp.responseText;
			document.getElementById("bann_id"+nid).style.display='none';
			document.getElementById("banned_id"+nid).innerHTML=response;
		}
	}
	xmlHttp.open("GET",url12,true);
	xmlHttp.send(null);
}

function answer(id)
{
	if(document.getElementById("ques_ans"+id).style.display=='none'){
		document.getElementById("ques_ans"+id).style.display='block';
	}else{
		document.getElementById("ques_ans"+id).style.display='none';
	}

}


function friendsort(decide,userid)
{   var addwho=document.getElementById("addwho").value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url13="action.php?decide="+decide+"&action=sortuser&userid="+userid+"&addwho="+addwho;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response	=	xmlHttp.responseText;
			if(addwho==1)
				document.getElementById("frnds2").innerHTML=response;
			else	
				document.getElementById("frnds1").innerHTML=response;
		}
	}
	xmlHttp.open("GET",url13,true);
	xmlHttp.send(null);
}

function selectTopic(catid)
{	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url12="action.php?cid="+catid+"&action=top10_selected";
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
				document.getElementById("displayButton").innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url12,true);
	xmlHttp.send(null);
}

function popular(val)
{	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url12="action.php?id="+val+"&action=top10_popular";
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
				document.getElementById("displayButton").innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url12,true);
	xmlHttp.send(null);
}

function btnType(id)
{ 
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url = "action.php?action=getscript&id="+id;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			document.getElementById('btype').innerHTML=xmlHttp.responseText;
			//document.getElementById('btype2').innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}
