﻿function checkLength(o,updatecontrol)
{
    if ((o != null) && (typeof o != "Undefined")) 
    {
        var len = o.value.length;
        if (document.getElementById(updatecontrol) != null)
            document.getElementById(updatecontrol).innerHTML = 333 - len;  //+ " remaining.";
        if (gid("dvThankyou").style.display == "block")
            gid("dvThankyou").style.display = "none";
    }  
    
}

function doReply(oid, namePrefix)
{
    var c = document.getElementById("complaint");
    var nm = document.getElementById(namePrefix + oid);
    c.value = "@" + nm.innerHTML;

    scroll(0, 0);
}

function doReshriek(oid, namePrefix, contentPrefix)
{
    var c = document.getElementById("complaint");
    var nm = document.getElementById(namePrefix + oid);
    var cn = document.getElementById(contentPrefix + oid);
    c.value = "RS @" + nm.innerHTML + " " + cn.innerHTML;
    scroll(0, 0);
}


function doVideoEmbed(videoURL,id)
{
    vidholder = document.getElementById("vid_" + id);
    if (vidholder.innerHTML == "")
    {
        var modVideoURL = videoURL;
        if (modVideoURL.indexOf("watch?v=") > -1)
            modVideoURL = modVideoURL.replace("watch?v=", "v/") + "&hl=en";

        if (videoURL.toLowerCase().indexOf("youtube") > -1)
        {
            modVideoURL = "http://www.youtube.com/v/" + modVideoURL.substring(modVideoURL.lastIndexOf("/") + 1);
        }
        var tmpstr = "<object width=\"620\" height=\"440\"><param name=\"movie\" value=\"" + modVideoURL + "\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"" + modVideoURL + "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"620\" height=\"440\"></embed></object>";
        document.getElementById("vid_" + id).innerHTML = tmpstr;
        vidholder.style.display = "block";
    }
    else
    {
        vidholder.style.display = vidholder.style.display == "none" ? "block" : "none";
    }
}

function getVideoURL(o)
{
    var estring = o.value;
    if (estring.indexOf("watch?v=") > -1)
    {
        o.value = estring.replace("watch?v=", "v/") + "&hl=en";
        //http://youtube.com/watch?v=W53W_zOwG4k
        //http://www.youtube.com/v/fCcCZOSAtxA&hl=en
    }
    else
    {
        var start = estring.indexOf("http://");
        if (start > -1)
        {
            var end = estring.indexOf("\"", start);
            var sub = estring.substring(start, end);
            o.value = sub;
        }
    }

}

function getVideoObject(videoURL)
{
    var modVideoURL = videoURL;
    if (modVideoURL.indexOf("watch?v=") > -1)
        modVideoURL = modVideoURL.replace("watch?v=", "v/") + "&hl=en";

    if (videoURL.toLowerCase().indexOf("youtube") > -1)
    {
        modVideoURL = "http://www.youtube.com/v/" + modVideoURL.substring(modVideoURL.lastIndexOf("/") + 1);
    }
    var tmpstr = "<object width=\"620\" height=\"440\"><param name=\"movie\" value=\"" + modVideoURL + "\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"" + modVideoURL + "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"620\" height=\"440\"></embed></object>";
    return tmpstr;
}
