//change picture
function pictureChange(pictureName, pictureObject) {
document.images[pictureName].src = pictureObject.src;
}

//Upload Form
function uploadFormFile() {
$("div#attachment_div").html("<input id='attachment1' type='file' name='attachment1' size='30'>");
}

function uploadFormUrl() {
$("div#attachment_div").html("<input id='url' type='text' name='url' size='36'>");
}

//confirm delete of a video
function confirmdelete(confirmlocation) {
Check = confirm("Willst du dieses Video wirklich löschen?");
if (Check == true) {
window.location = confirmlocation;
}
}

//confirm to award a video
function confirmaward(confirmawardlocation) {
Check = confirm("Dieses Video als [tru:] Tipp kennzeichnen?");
if (Check == true) {
window.location = confirmawardlocation;
}
}

//confirm to delete a award
function confirmawarddelete(confirmawarddeletelocation) {
Check = confirm("Markierung entfernen?");
if (Check == true) {
window.location = confirmawarddeletelocation;
}
}

//send rating to script
function sendRating(rating) {
$("input#rating").val(rating);
document.ratingForm.submit();
}

//close confirmation text of rating
function closeConfirmRating() {
$("div#confirmRating").css('display','none');
}

function makeGETRequest(url) {
   //disable confirmRating
   $("div#confirmRating").css('display','none');
   //set cursor
   $("div#category").css('cursor','wait');
   $("#category a").click(function() { return false; });
   $("#category a").css('cursor','wait');
   
   if(!$("div#no_videos")) {
   $("img.category_preview_image").css('cursor','wait');
   }
    
   $.get(url, '',
     function(data){
         categoryContent = data.split('[CATEGORY_CONTENT]');
         $("div#category").html(categoryContent[1]);
         //set cursor
         $("div#category").css('cursor','auto');
         $("#category a").css('cursor','pointer');
         
         if(!document.getElementById('no_videos')) {
         $("img.category_preview_image").css('cursor','pointer');
         }
       }
    );
}

function makePOSTRequest(url,poststr) {
   var poststr = "rating=" + encodeURI($("input#rating").val());
   $.post(url, poststr,
     function(data){
         result = data;
         starsContent = result.split('[STARS_CONTENT]');
         $("div#stars").html(starsContent[1]);
         ratingFailed = result.split('[RATING_FAILED]');
         if(ratingFailed[1] == 'RATING_FAILED') {
         $("div#confirmRating").html('Du hast dieses Video bereits bewertet!<br><a href="javascript:closeConfirmRating()">Schlie&szlig;en</a>');
         $("div#confirmRating").css('display','block');
         } else {
         $("div#confirmRating").html('Video erfolgreich bewertet!<br><a href="javascript:closeConfirmRating()">Schlie&szlig;en</a>');
         $("div#confirmRating").css('display','block');
         }
     });
}

//path to highlighted star
function setHighlightPath(path) {
highlight = new Image();
highlight.src = path;
highlightpath = path;
}

//color or uncolor stars
function starsColor(number) {
srcstar1 = document.images["star1"].src;
srcstar2 = document.images["star2"].src;
srcstar3 = document.images["star3"].src;
srcstar4 = document.images["star4"].src;
srcstar5 = document.images["star5"].src;

starnormal = highlightpath.replace(/\?rating\=\d/g,"");

switch (number) {
case 1:
document.images["star1"].src = highlight.src;

document.images["star2"].src = starnormal;
document.images["star3"].src = starnormal;
document.images["star4"].src = starnormal;
document.images["star5"].src = starnormal;
break;
case 2:
document.images["star1"].src = highlight.src;
document.images["star2"].src = highlight.src;

document.images["star3"].src = starnormal;
document.images["star4"].src = starnormal;
document.images["star5"].src = starnormal;
break;
case 3:
document.images["star1"].src = highlight.src;
document.images["star2"].src = highlight.src;
document.images["star3"].src = highlight.src;

document.images["star4"].src = starnormal;
document.images["star5"].src = starnormal;
break;
case 4:
document.images["star1"].src = highlight.src;
document.images["star2"].src = highlight.src;
document.images["star3"].src = highlight.src;
document.images["star4"].src = highlight.src;

document.images["star5"].src = starnormal;
break;
case 5:
document.images["star1"].src = highlight.src;
document.images["star2"].src = highlight.src;
document.images["star3"].src = highlight.src;
document.images["star4"].src = highlight.src;
document.images["star5"].src = highlight.src;
break;
}
}

function starsUncolor(number) {
document.images["star1"].src = srcstar1;
document.images["star2"].src = srcstar2;
document.images["star3"].src = srcstar3;
document.images["star4"].src = srcstar4;
document.images["star5"].src = srcstar5;
}