﻿var xmlHttp;

function SubmitRating(r)
{
    //alert(r + ":" + p + ":" + v);
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="ratevideo.aspx";
    url=url+"?r="+r+"&p="+p+"&c="+c+"&v="+v+"&sid="+Math.random();
    //prompt("url:", url)
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    document.getElementById("div_rating_list").innerHTML="<b>Ratings updated.</b>";
    
}

function PostComment()
{
    var t = document.getElementById("tb_comment").value;
    //alert (t);
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="postcomment.aspx";
    url=url+"?p="+p+"&c="+c+"&v="+v+"&t="+t+"&sid="+Math.random();
    xmlHttp.onreadystatechange=postComplete;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function postComplete()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
        document.getElementById("div_comments").innerHTML=xmlHttp.responseText;
        }
}

function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
        document.getElementById("div_rating").innerHTML=xmlHttp.responseText;
        }
}
  
function GetXmlHttpObject()
{
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}

function DisplayUploading()
{
    document.getElementById("div_uploading").style.display="block";
    document.getElementById("btn_upload").style.display="none";
    document.getElementById("div_uploadform").style.display="none";
}

function SwitchImage(id)
{
for (i=1;i<=5;i++)
    {
    if (i <= id)
        {
        var star = document.getElementById("rating_" + i);
        star.src = "images/star_on.gif";
        }
    else
        {
        var star = document.getElementById("rating_" + i);
        star.src = "images/star_off.gif";
        }
    }
}
    
function validate_form(thisform)
{
    with (thisform)
    {
        var error_msg = "";
        if (tb_title.value == "")
        {
            error_msg += "Please enter a title\n";
        }
        if (tb_description.value == "")
        {
            error_msg += "Please enter a desciption\n";
        }
        if (tb_keywords.value == "")
        {
            error_msg += "Please enter some tags for your video\n";
        }
        if (f_video.value == "")
        {
            error_msg += "Please select a file to upload\n";
        }
        if (error_msg != "")
        {
            document.getElementById("div_uploading").style.display="none";
            document.getElementById("btn_upload").style.display="block";
            alert(error_msg);
            return false;
        }
    }
    return true;
}



