function GetAllVideos(page) {
    xmlhttpPost("getallvideos.jsp","content","page="+page);
}

function removefavouritevideo(videoid) {
    xmlhttpPost("removefavouritevideo.jsp","content","videoid="+videoid);
    
}

function GetVideoCategories() {
    xmlhttpPost("getlistcategories.jsp","content","");
}

function GetVideosByCategory(category,page) {
    //window.alert("category: "+category);
    
    xmlhttpPost("getcategory.jsp","content","category="+category+"&page="+page);
}

function GetTopX(page, category, genre) {
    //window.alert("category: "+category);
    
    xmlhttpPost("gettopx.jsp","content","page="+page+"&category="+category+"&genre="+genre);
}

function GetMrBigX(page) {
    //window.alert("category: "+category);
    
    xmlhttpPost("getmrbigtopx.jsp","content","page="+page);
}


function GetFreshX(page, category, genre) {
    //window.alert("category: "+category);
    xmlhttpPost("getfreshx.jsp","content","page="+page+"&category="+category+"&genre="+genre);
}

function GetVideoFavourites(page) {
    
    xmlhttpPost("getvideofavourites.jsp","content","page="+page);
}

function GetComments(index, page) {
    
    document.getElementById("overlay").style.display="block";
    xmlhttpPost("getvideocomments.jsp","commentBox","index="+index+"&page="+page);
    document.getElementById("commentBox").style.display="block";
}



function GetSearchPage() {
    //window.alert("category: "+category);
    
    xmlhttpPost("getsearch.jsp","content","");
}

function callGetSearchResults() {
    
    var title = document.getElementById("txttitle").value;
    var artist = document.getElementById("txtartist").value;
    var category = document.getElementById("drpcategory").value;
    var genre = document.getElementById("drparea").value;
    
    GetSearchResults(0,title,artist,category,genre);
}

function GetSearchResults(page,title,artist,category,genre) {
    
    xmlhttpPost("getsearchresults.jsp","content","page="+page+"&title="+title+"&artist="+artist+"&category="+category+"&genre="+genre);
}


function GetInformation(videoid) {
    
    var h = document.getElementById("contentRight").scrollHeight;
    document.getElementById("overlay").style.height = h+"px";
    
    document.getElementById("overlay").style.display="block";
    document.getElementById("divinfo").style.display="block";
    xmlhttpPost("getinfo.jsp?index="+videoid,"divinfo","");
}

function GetInformationfavourite(videoid) {
    //alert("a");
    var h = document.getElementById("contentRight").scrollHeight;
    document.getElementById("overlay").style.height = h+"px";
    
    document.getElementById("overlay").style.display="block";
    document.getElementById("divinfo").style.display="block";
    xmlhttpPost("getinfo.jsp?index="+videoid,"divinfo","favourite=true");
}

function loadPlayVideoDivLayout(videoid) {
   
    document.getElementById("divplay").innerHTML="";
    document.getElementById("divplay").innerHTML="<div class=\"rateApBut\"><a href=\"#\" onclick=\"getrating("+videoid+"); return false;\"><img src=\"../images/Close.gif\" width=\"80\" height=\"21\" border=\"0\" /></a></div><div class=\"videoContainer\" id=\"vidcontainter\"><img src=\"../images/GenericRating.jpg\" width=\"280\" height=\"234\" /></div><div id=\"playinformation\"></div>";
    document.getElementById("divplay").style.display="block";
    document.getElementById("divplay").className = "play video";
}


function GetPlayVideo(index, videoid, videourl) {
    
    var h = document.getElementById("contentRight").scrollHeight;
    document.getElementById("overlay").style.height = h+"px";
    document.getElementById("overlay").style.display="block";
    loadPlayVideoDivLayout(index);
    
    var so = new SWFObject('../javascript/mediaplayer.swf','mpl','250','234','8', "#000000");
    so.addParam('allowscriptaccess','always');
    so.addParam('allowfullscreen','true');
    so.addVariable('width','250');
    so.addVariable('height','234');
    var url = 'http://196.212.135.42:83/gridstar_media/videos/'+videoid+'.flv';
    if (videourl.length>0) {
        url = videourl;
    }
    so.addVariable('file',url);
    so.addVariable("enablejs","true");
    so.addVariable("javascriptid","mpl");
    so.write('vidcontainter');
    xmlhttpPost("getplayvideo.jsp","playinformation","index="+index);    
}

function getrating(videoid){
    document.getElementById("vidcontainter").innerHTML="";
    var h = document.getElementById("divplay");
    h.className = "play rate";
   xmlhttpPost("getrate.jsp","divplay","index="+videoid);
}

function setrating(videoid, score){
  var rating = score;  
  //add rating function
  xmlhttpPost("setrating.jsp","divplay","index="+videoid+"&rating="+rating);
}

function getmrbigcomment(videoid){
 
  //add rating function
  xmlhttpPost("getmrbigcomment.jsp","divplay","index="+videoid);
}

function getvideooptions(videoid){
    
    var h = document.getElementById("divplay");
    h.className = "options";
    xmlhttpPost("getvideooptions.jsp","divplay","index="+videoid);
}

function addvideotofavorites(videoindex){
    
    xmlhttpPost("addvideotofavourites.jsp","divResult","index="+videoindex);
}

function addartisttofavorites(videoindex){
    
    xmlhttpPost("addartisttofavourites.jsp","divResult","index="+videoindex);
}

function addcomment(videoindex){
    
    var comment = "";
    comment = document.getElementById("textarea").value;
    
    document.getElementById("textarea").value = "";
    if (comment!="") {
    xmlhttpPost("addvideocomment.jsp","divComments","index="+videoindex+"&comment="+comment);
    } else {
        window.alert("Comment field is empty.");
    }
}


function sendtobuddy(videoindex){
    //document.getElementById("divplay").style.display="none";
    document.getElementById("divplay").innerHTML = "";
    document.getElementById("divplay").className="artistChat sendtobuddy";
    xmlhttpPost("getsendtobuddy.jsp","divplay","index="+videoindex);
}


function refertofriend(videoindex){
    var message  = document.getElementById("txtmessage").value;
    //var username = document.getElementById("friendname").value;
    var cellno1   = document.getElementById("friendnumber1").value;
    var cellno2   = document.getElementById("friendnumber2").value;
    var cellno3   = document.getElementById("friendnumber3").value;
    var cellno4   = document.getElementById("friendnumber4").value;
    var cellno5   = document.getElementById("friendnumber5").value;
    if (message.length==0) {
        window.alert("No message entered.");
    } else if (cellno1.length==0) {
        window.alert("Please enter a username or cell number.");
    }else {
        xmlhttpPost("sendvideotobuddy.jsp","divplay","index="+videoindex+"&message="+message+"&cellno1="+cellno1+"&cellno2="+cellno2+"&cellno3="+cellno3+"&cellno4="+cellno4+"&cellno5="+cellno5);
    }
}

function commenttoartist(videoindex){
    
// add comment to artist function
    document.getElementById("divplay").innerHTML = "";
    document.getElementById("divplay").className="artistChat sendtobuddy";
    xmlhttpPost("getartistcomments.jsp","divplay","index="+videoindex);
}


function sendartistcomment(videoindex,userid,artistid){
    
// add comment to artist function
    var message = document.getElementById("textarea").value;
    if (message.length>0) {
        document.getElementById("divplay").innerHTML = "";
        document.getElementById("divplay").className="artistChat sendtobuddy";
        xmlhttpPost("sendartistcomment.jsp","divplay","index="+videoindex+"&message="+message+"&userid="+userid+"&artistid="+artistid);
    } else {
        window.alert("Please type a message for the artist");
    }
}





function closeinfo() {
    closediv("overlay");
    closediv("divinfo");
    
}

function closeoptions() {
    closediv("overlay");
    closediv("divplay");
    
}

function loadVideo() {
    
}


function closeComment() {
    closediv("overlay");
    closediv("commentBox");
}



