var ratq1 = 0;
var ratq2 = 0;
var ratq3 = 0;
var ratq4 = 0;
var gcid=0;
var cOffset=0;
var gcom = '';
function getHTTPObject()
{
        var xmlhttp;
        /*@cc_on
        @if(@_jscript_version >=5)
        try
        {
                xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
                try
                {
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(E)
                {
                        xmlhttp=false;
                }
        }
        @else
                xmlhttp=false;
        @end @*/
        if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
                try
                {
                        xmlhttp=new XMLHttpRequest();
                }
                catch(e)
                {
                        xmlhttp=false;
                }
        }
        return xmlhttp;
}
function handleRatingResults()
{
        if(http.readyState == 4)
        {
//alert(http.responseText);
                //eval(http.responseText);
		document.getElementById('ratresult').innerHTML = 'Thankyou for your vote';
        }
}
function updateRating(post,user,rating)
{
	if(post == 0) return false;
	var ratpct = rating *20;
	ratstr = ratpct + '%';
	document.getElementById('rating').style.width = ratstr;
        var url="/updateratings.php?user=" + user + "&post=" + post + "&rat=" + rating;
//alert(url);
        http.open("GET",url, true);
        http.onreadystatechange=handleRatingResults;
        http.send(null);
}
function handleCommentResponse()
{
        if(http.readyState == 4)
        {
                //alert(http.responseText);
                document.getElementById('commentresult').innerHTML=http.responseText;
                document.getElementById('commentadd').innerHTML='Comment Added<br><b>Your comment will be added to the site after being approved.</b>';
                document.getElementById('nocom').innerHTML='';
        }
}
function addComment(vidid,user)
{
        commentstr = escape(document.getElementById('thecomment').value);
        if(commentstr.length < 3) return false;
        var url="/addcomment.php?vidid=" + vidid + "&user=" + user + "&comment=" + commentstr;

        http.open("GET",url, true);
        http.onreadystatechange=handleCommentResponse;
        http.send(null);
}
function handleMoreCommentResponse()
{
        if(http.readyState == 4)
        {
        //        alert(http.responseText);
                document.getElementById('commentsbox').innerHTML=http.responseText;
        }
}
function getMoreComments(vidid)
{
        cOffset = cOffset + 5;
        var url="/getcomments.php?vidid=" + vidid + "&offset=" + cOffset;
//alert(url);
        http.open("GET",url, true);
        http.onreadystatechange=handleMoreCommentResponse;
        http.send(null);
}
function handleAppResponse()
{
        if(http.readyState == 4)
        {
                //alert(http.responseText);
                document.getElementById('as'+gcid).innerHTML=http.responseText;
        }
}
function App(cid)
{
	gcid = cid;
        var url="/approvecomment.php?cid=" + cid;

        http.open("GET",url, true);
        http.onreadystatechange=handleAppResponse;
        http.send(null);
}
function handleDelResponse()
{
        if(http.readyState == 4)
        {
        //        alert(http.responseText);
                document.getElementById('commentresult').innerHTML='Comment deleted';
        }
}
function delcom(cid)
{
        var url="/deletecomment.php?cid=" + cid;

        http.open("GET",url, true);
        http.onreadystatechange=handleDelResponse;
        http.send(null);
}
function handleAdminDelResponse()
{
        if(http.readyState == 4)
        {
        //        alert(http.responseText);
                document.getElementById('cm'+gcid).innerHTML='Comment deleted';
        }
}
function delcomAdmin(cid)
{
	gcid = cid;
        var url="/deletecomment.php?cid=" + cid;

        http.open("GET",url, true);
        http.onreadystatechange=handleAdminDelResponse;
        http.send(null);
}
function editcom(cid)
{
	document.getElementById('cdiv'+cid).style.display = 'none';
	document.getElementById('ediv'+cid).style.display = '';
}
function handleEditResponse()
{
        if(http.readyState == 4)
        {
		var cid = gcid;
		//alert(http.responseText);
		document.getElementById('cdiv'+cid).innerHTML = unescape(gcom);
		document.getElementById('cdiv'+cid).style.display = '';
		document.getElementById('ediv'+cid).style.display = 'none';
        }
}
function goEdit(cid)
{
	gcid = cid;
	var comment = escape(document.getElementById('ncom'+cid).value);
	gcom = comment;
        var url="/editcomment.php?cid=" + cid + "&comment=" + comment;
//alert(url);
        http.open("GET",url, true);
        http.onreadystatechange=handleEditResponse;
        http.send(null);
}
