// JavaScript Document
function Trimt(str){ return str.replace(/^\s*|\s*$/g,""); }
function giveRate(newsid,rateval)
{
	//alert(newsid);alert(rateval);
	
	if(myId=="")
	{
			alert("Please Login to give vote");return false;
	}
/*	if(Flag==false) { return false; }
	Flag=false;*/
	try { 
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	 } 
	 catch (e) 
	 { 
		// browser doesn't support ajax. handle however you want
	 }
	 xmlhttp.onreadystatechange = function()
	 {
	 	if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			rval=xmlhttp.responseText;
			rvalarr=rval.split("~");
			if(rvalarr[0]==1)
			{
				//window.location.replace("../functions/news_rat_cmt.php");
				newsratcnt=rvalarr[1];
				document.getElementById("ratediv").innerHTML=newsratcnt;
				document.getElementById("ratediv1").innerHTML=newsratcnt;
			}
			else
			{
				alert(rvalarr[1]);return false;
			}
			Flag=true;
		}
		else
		{
				document.getElementById("ratediv").innerHTML='<img src="../images/loader.gif">';
				document.getElementById("ratediv1").innerHTML='<img src="../images/loader.gif">';
		}
	 } 
	 //The following will send the request to the PHP file using the POST method:
	 xmlhttp.open('post',  "../functions/news_rate_cmt.php");
	 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	 xmlhttp.send('mode=rate&newsid='+newsid+"&rateval="+rateval); 
}

function giveRate_desc(newsid,rateval,way)
{
	//alert(newsid);alert(rateval);
	if(myId=="")
	{
			alert("Please Login to give vote");return false;
	}
	/*if(Flag==false) { return false; }
	Flag=false;*/
	try { 
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	 } 
	 catch (e) 
	 { 
		// browser doesn't support ajax. handle however you want
	 }
	 xmlhttp.onreadystatechange = function()
	 {
	 	if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			rval=xmlhttp.responseText;
			rvalarr=rval.split("~");
			if(rvalarr[0]==1)
			{
				//window.location.replace("../functions/news_rat_cmt.php");
				newsratcnt=rvalarr[1];
				if(way==1)//Random News
				{
					document.getElementById("ratediv").innerHTML=newsratcnt;
				}
				if(way==2)//Breaking News List
				{
					document.getElementById("ratediv"+newsid).innerHTML=newsratcnt;
				}
			}
			else
			{
				alert(rvalarr[1]);return false;
			}
			//Flag=true;
		}
		else
		{
			if(way==1)//Random News
			{
				document.getElementById("ratediv").innerHTML='<img src="../images/loader.gif">';
			}
			if(way==2)//Breaking News List
			{
				document.getElementById("ratediv"+newsid).innerHTML='<img src="../images/loader.gif">';
			}	
		}
	 }
	 //The following will send the request to the PHP file using the POST method:
	 xmlhttp.open('post',  "../functions/news_rate_cmt.php");
	 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	 xmlhttp.send('mode=rate&newsid='+newsid+"&rateval="+rateval); 
}
function giveCmnt_desc(newsid)
{
	if(myId=="")
	{
		alert("Please Login to give comment");return false;
	}
	if(Flag==false) { return false; }
	Flag=false;
	if(document.getElementById("news_description").value=="")
	{
		alert("Enter Comment");Flag=true;
		document.getElementById('news_description').focus();return false;
	}
	comment=Trimt(document.getElementById("news_description").value);
	if(comment=="")
	{
		alert("Enter Comment");Flag=true;
		 document.getElementById('news_description').focus();return false;	
	}
	try { 
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	 } 
	 catch (e) 
	 { 
		// browser doesn't support ajax. handle however you want
	 }
	 xmlhttp.onreadystatechange = function()
	 {
	 	if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);	
			//window.location.replace(newsurl);	
			document.getElementById('news_description').value='';
			document.getElementById("comment_spn").innerHTML=xmlhttp.responseText;
			Flag=true;
		}
		else {document.getElementById("comment_spn").innerHTML='<img src="../images/loader.gif">'; } 
	 } 
	 comment=encodeURIComponent(comment);
	 //The following will send the request to the PHP file using the POST method:
	 xmlhttp.open('post',  "../functions/news_rate_cmt.php");
	 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	 xmlhttp.send('mode=comment&newsid='+newsid+"&comment_val="+comment); 
}
function delCmnt(recid,newsid)
{
	if(myId=="")
	{
		alert("Please Login to delete comment");return false;
	}	
	if(confirm("Are you sure to delete this comment?"))
	{
		try { 
			xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
		 } 
		 catch (e) 
		 { 
			// browser doesn't support ajax. handle however you want
		 }
		 xmlhttp.onreadystatechange = function()
		 {
			if(xmlhttp.readyState==4)
			{
				//alert(xmlhttp.responseText);	
				document.getElementById("comment_spn").innerHTML=xmlhttp.responseText;
				//window.location.replace(newsurl);	
				Flag=true;
			}else {document.getElementById("comment_spn").innerHTML='<img src="../images/loader.gif">'; } 
		 } 
		 //The following will send the request to the PHP file using the POST method:
		 xmlhttp.open('post',  "../functions/news_rate_cmt.php");
		 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		 xmlhttp.send('mode=delcomment&recid='+recid+'&newsid='+newsid); 	
	}
}
