﻿// Commenting
function intialisecomment(o, s) {
    if (s == "off" && o.value == "Leave a comment...") {
        o.value = "";
    }
    else if (s == "on" && o.value == "") {
        o.value = "Leave a comment...";
    }
}

function resethighlight() {
    document.getElementById("txtComment").className = "";
}

function addcomment(photoid, albumid, profileid, dogsaleid) {
 // Check for a comment
    if (document.getElementById("txtComment").value == "" || document.getElementById("txtComment").value == "Leave a comment...") {
        // Flash the background colour
        document.getElementById("txtComment").className = "highlight";
        window.setTimeout(resethighlight, 75);
        return false;
    }

    // Disable the form and show loading animation
    document.getElementById("txtComment").disabled = true;
    document.getElementById("btnComment").disabled = true;

    // Call ajax function
    PageMethods.Photo_Comment(photoid.toString(), albumid, profileid, dogsaleid, document.getElementById("txtComment").value, addcommentsuccess, ajaxfailure);
}

function addcommentsuccess(value, ctx, methodName) {
    // Enable the form
    document.getElementById("txtComment").disabled = false;
    document.getElementById("btnComment").disabled = false;
    // Check for errors
    if (value[0] == "error timeout") {
    	alert("Your session has timed out. Please sign in again.");
		return;
	}

    // Add the comment to the list
    var newli = document.createElement("li");
    newli.innerHTML = value[1];
    newli.className = "highlight5";
    newli.id = "comment" + value[0];

    var liarr = document.getElementById("commentslist").getElementsByTagName("LI");
    document.getElementById("commentslist").insertBefore(newli, liarr[liarr.length - 1]);

    document.getElementById("txtComment").value = "Leave a comment...";
    window.setTimeout("fade(\"comment" + value[0] + "\")", 50);

}

function fade(cid) {
    if (parseInt(document.getElementById(cid).className.replace("highlight", "")) > 1) {
        document.getElementById(cid).className = "highlight" + (parseInt(document.getElementById(cid).className.replace("highlight", "")) - 1);
        window.setTimeout("fade(\"" + cid + "\")", 50);
    }
    else {
        document.getElementById(cid).className = "";
    }
}

function removecomment(commentid) {
    if (!confirm("Are you sure you want to remove this comment?")) {
        return false;
    }
    document.getElementById("comment" + commentid).className = "highlight1";
    window.setTimeout("removefade(" + commentid + ")", 50);
}

function removefade(cid) {
    if (parseInt(document.getElementById("comment" + cid).className.replace("highlight", "")) < 5) {
        document.getElementById("comment" + cid).className = "highlight" + (parseInt(document.getElementById("comment" + cid).className.replace("highlight", "")) + 1);
        window.setTimeout("removefade(" + cid + ")", 50);
    }
    else {
        window.setTimeout("deletecomment(" + cid + ")", 250);
    }
}

function deletecomment(cid) {
    // Call ajax function
    PageMethods.Remove_Photo_Comment(cid.toString(), removecommentsuccess, ajaxfailure);
}

function removecommentsuccess(value, ctx, methodName) {
    // Check for errors
    if (value == "error timeout") {
    	alert("Your session has timed out. Please sign in again.");
		return;
	}

    // Remove the comment
    document.getElementById("commentslist").removeChild(document.getElementById("comment" + value));
    
}

function addvideocomment(videoid) {
 // Check for a comment
    if (document.getElementById("txtComment").value == "" || document.getElementById("txtComment").value == "Leave a comment...") {
        // Flash the background colour
        document.getElementById("txtComment").className = "highlight";
        window.setTimeout(resethighlight, 75);
        return false;
    }

    // Disable the form and show loading animation
    document.getElementById("txtComment").disabled = true;
    document.getElementById("btnComment").disabled = true;

    // Call ajax function
    PageMethods.Video_Comment(videoid.toString(), document.getElementById("txtComment").value, addcommentsuccess, ajaxfailure);
}

function removevideocomment(commentid) {
    if (!confirm("Are you sure you want to remove this comment?")) {
        return false;
    }
    document.getElementById("comment" + commentid).className = "highlight1";
    window.setTimeout("removevideofade(" + commentid + ")", 50);
}

function removevideofade(cid) {
    if (parseInt(document.getElementById("comment" + cid).className.replace("highlight", "")) < 5) {
        document.getElementById("comment" + cid).className = "highlight" + (parseInt(document.getElementById("comment" + cid).className.replace("highlight", "")) + 1);
        window.setTimeout("removevideofade(" + cid + ")", 50);
    }
    else {
        window.setTimeout("deletevideocomment(" + cid + ")", 250);
    }
}

function deletevideocomment(cid) {
    // Call ajax function
    PageMethods.Remove_Video_Comment(cid.toString(), removecommentsuccess, ajaxfailure);
}


