
function submitRatingForm(frm,articlename,parentCateg,parent)
{
	 var count = 0;
	 for (var i = 0; i < frm.opinion.length; i++)
	 {
		if (frm.opinion[i].checked) { count = 1; articleRate = frm.opinion[i].value;  }
	 }
	 if(count == 0){alert("Rate this article");return false;}	
	 http.open('get', 'rateArticle.php?name='+articlename+'parentCateg='+parentCateg+'parent='+parent+'articleRate='+articleRate); 
     http.onreadystatechange = handleResponse; 
     http.send(null); 

}
//------------------------------------------------------------------------------
function submitRatingForm2(frm,cat_id,rated,rating)
{
	if(rated == 1)
	{
		frm.opinion[rating-1].checked = true;
		alert("You have already rated this article");
		return false;
	}
	var count = 0;
	for (var i = 0; i < frm.opinion.length; i++)
	{
		if (frm.opinion[i].checked) {count = 1; articleRate = frm.opinion[i].value;break;}
	}
	if(count == 0){alert("Rate this article");return false;}	

	process		=	'ratethearticle';
	output		=	'text';
	url			=	getURL() + "/rateArticle/";
	
	fields		=	new Array();

	responseHandler	=	"processRatetheArticleResponse";

	fields.push("cat_id="+cat_id);
	fields.push("articleRate="+articleRate);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}

//------------------------------------------------------------------------------

function processRatetheArticleResponse(responseText)
{

	content = responseText.split('++++'); 	
	
	document.getElementById("popmidcont").innerHTML		=	content[0];	
	document.getElementById("currentRating").innerHTML	=	content[1];	
	//setTimeout("tooltips_onmouseout()",2000); 
}

//------------------------------------------------------------------------------
function loadComments(CURRENT_URL)
{	
	process		=	'commentthearticle';
	output		=	'text';
	url			=	CURRENT_URL+"?act=comments";
	responseHandler	=	"processCommentontheArticleResponse";	
	ajaxGetRequest(url);
}
//------------------------------------------------------------------------------

function processCommentontheArticleResponse(responseText)
{
	//alert(responseText);
	content = responseText.split('++++++++++'); 
	document.getElementById("tabMenu").innerHTML  =	content[0];	
	document.getElementById("leftCont").innerHTML = content[1];	

}
//------------------------------------------------------------------------------

function check(form,CURRENT_URL)
{
	if(isEmpty(form.author)){ alert("Please enter your name"); form.author.focus();return false;	}
	if(isEmpty(form.email)){ alert("Please enter your email"); form.email.focus();return false;	}
	if(!isValidEmail(form.email)){alert(form.email.value + " is not a valid Email ID");form.email.focus();return false;}		
	if(isEmpty(form.comment)){ alert("Please enter your comments"); form.comment.focus();return false;	}
	
	process		=	'commentthearticle';
	output		=	'text';
	url			=	CURRENT_URL; 
	fields		=	new Array();
	author   = (form.author.value);
	email    = (form.email.value);
	comment  = (form.comment.value); 
	act      = (form.act.value); 
	cat_id      = (form.cat_id.value); 

	responseHandler	=	"processCommentontheArticleResponse";
	fields.push("author="+author);
	fields.push("email="+email);
	fields.push("comment="+comment);
	fields.push("act="+act);
	fields.push("cat_id="+cat_id);
	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url,ajaxParams);
	return false;

}
//------------------------------------------------------------------------------
function doRating(url)
{
	document.getElementById("tabForm").act.value = "changeRating";
	//alert(document.tabForm.act.value);
	//document.getElementById("middleCont").style.display	=	"block";	
	//document.getElementById("middleCont2").style.display=	"none";	
	document.getElementById("tabForm").action = url + "#rating";
	document.getElementById("tabForm").submit();
}
//------------------------------------------------------------------------------

function Vote()
{
	var count = 0;
	for (var i = 0; i < document.pollform.poll.length; i++)
	{
		if (document.pollform.poll[i].checked) {count = 1; option = document.pollform.poll[i].value;}
	}
	if(count == 0){alert("Choose one of the poll options");return false;}	

	process		=	'poll';
	output		=	'text';
	url			=	getURL() + "/poll/";
	
	fields		=	new Array();
	responseHandler	=	"processPollResponse";

	fields.push("pollid="+document.pollform.pid.value);
	fields.push("category="+document.pollform.category.value);
	fields.push("optionid="+option);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processPollResponse(responseText)
{
	document.getElementById("pollinfo").innerHTML	=	responseText;	

}
//------------------------------------------------------------------------------
function nxtQuiz(currentQuiz,qid)
{
	var num = 0;
	var len = document.quizForm.elements.length;
	for(i=0;i<len;i++)
	{
		var e = document.quizForm.elements[i];
		if (e.name == qid)
		{
			if(e.checked==true)	
			{
				num=1;
			}
			
		}
	}
	if (num == 0)
	{
		alert("Please select one of the options");
		e.focus();
		return false;
	}
	obj = document.getElementById("quiz_"+currentQuiz);
	var nxtQuiz = currentQuiz + 1;
	obj.style.display = "none";
	obj1 = document.getElementById("quiz_"+nxtQuiz)
	obj1.style.display  = "block";
}
//--------------------------------------------------------------------------------------------------------------
var counterValue;
function submitQuiz(url,counter,qid)
{
	process		=	'quiz';
	output		=	'text';
	url			=	getURL() + "/quiz/";
	counterValue = counter;
	fields		=	new Array();
	responseHandler	=	"processQuizOnArticle";
	//alert(document.quizForm.category.value);
	var num = 0;
	var len = document.quizForm.elements.length;
	for(i=0;i<len;i++)
	{
		var e = document.quizForm.elements[i];
		if (e.name == qid)
		{
			if(e.checked==true)
			{
				num=1;
			
			}
		}
		if(e.checked==true)
		{
				fields.push(e.name+"="+e.value);
		}

	}
	if (num == 0)
	{
		alert("Please select one of the options");
		e.focus();
		return false;
	}
	fields.push("quizid="+document.quizForm.quizid.value);
	fields.push("category="+document.quizForm.category.value);
	fields.push("action=save");
	ajaxParams	=	fields.join('&');
	ajaxPostRequest(url, ajaxParams);
	return false;
}
//---------------------------------------------------------------------------------------------------------------
function processQuizOnArticle(responseText)
{

	obj1 = document.getElementById("quiz_"+counterValue);
	obj1.style.display = "none";
	counterValue = parseInt(counterValue)+1
	obj		= document.getElementById("quiz_"+counterValue);
	obj.style.display ="block";
	obj2		= document.getElementById("result");
	obj2.innerHTML = responseText;
	
}


//===============================================================================
	// AJAX Calls
//===============================================================================
var req,process,output,responseHandler,ajaxParams;
//------------------------------------------------------------------------------
function noCache(url)
{
	var sep = (-1 < url.indexOf("?")) ? "&" : "?"	
	url = url + sep + "__=" + encodeURIComponent((new Date()).getTime());	
	return url;
}
//------------------------------------------------------------------------------
function ajaxPostRequest(url,postData)
{
	if(window.XMLHttpRequest) 
	{
		req = new XMLHttpRequest;
	}
	else if (window.ActiveXObject)
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	req.open("POST",noCache(url),true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
	
	req.onreadystatechange = getData_Callback;	
	req.send(postData);
}
//------------------------------------------------------------------------------
function ajaxGetRequest(url)
{
	if(window.XMLHttpRequest) 
	{
		req = new XMLHttpRequest;
	}
	else if (window.ActiveXObject)
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	req.open("GET",noCache(url),true);
	//req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
	
	req.onreadystatechange = getData_Callback;	
	req.send(null);
}
//------------------------------------------------------------------------------
function getData_Callback()
{
	if(req.readyState==4)
	{		
		if(req.status==200)
		{
			if(output == 'text')
			{
				eval(responseHandler + '(req.responseText)');
			}
			else if(output == 'xml')
			{
				eval(responseHandler + '(req.responseXML)');
			}
		}
	}
}
//------------------------------------------------------------------------------