// JScript source code
var LastClick = null;
var DblClickDelay = 3000;

function IsDoubleClick()
{
	var TimeNow = new Date();
	if (LastClick == null)
	{
		LastClick = TimeNow;
		return false;
	}
	if (LastClick.getTime() + DblClickDelay < TimeNow.getTime())
	{
		LastClick = TimeNow;
		return false;
	}
	return true;
}

function ClickNotDouble()
{
	return !IsDoubleClick();
}

function ConfirmCancel()
{
    if (confirm("Are you sure you would like to cancel your order?  If you would like to cancel the order click the 'OK' button, otherwise click the 'Cancel' button."))
        window.location = "default.aspx?cancelorder=true";
    else
        return false;
}

function NotImplemented()
{
    alert("Sorry, this is not implemented yet!");
}

function checkInput(elementId, defaultValue)
{
    if (document.getElementById(elementId).value == defaultValue || document.getElementById(elementId).value == "")
    {
        alert("You must enter some text to search for before clicking the search button!");
        return false;
    }
}

function onShowHelp(page)
{
    window.showModalDialog(page, null, "dialogWidth: 500px; dialogHeight: 300px; center: yes;");
}

// Clears the value property of the target element.  The target is intended
// to be a textbox.
function SetupContentOption(option)
{
    if (option)
    {
        if (option.value == "Disk")
        {
            document.getElementById("UsersName").value = "";
            document.getElementById("DiskName").value = "";
            ValidatorEnable(document.getElementById("ValUserName"), true);
            ValidatorEnable(document.getElementById("ValDiskName"), true);
            ValidatorEnable(document.getElementById("rfvDownload"), false);
            document.getElementById("rowTarget").innerHTML = document.getElementById("newDiskDetails").innerHTML;
        }
        else if (option.value == "Download")
        {
            document.getElementById("DownloadName").value = "";
            ValidatorEnable(document.getElementById("ValUserName"), false);
            ValidatorEnable(document.getElementById("ValDiskName"), false);
            ValidatorEnable(document.getElementById("rfvDownload"), true);
            document.getElementById("rowTarget").innerHTML = document.getElementById("newDownloadDetails").innerHTML;
        }
        else if (option.value == "Hardware")
        {
            ValidatorEnable(document.getElementById("ValUserName"), false);
            ValidatorEnable(document.getElementById("ValDiskName"), false);
            ValidatorEnable(document.getElementById("rfvDownload"), false);
            document.getElementById("rowTarget").innerHTML = "";
        }
    }
}

// Sets the target's inner Html to that of the source.  The target is intended
// to be a DIV.
function SetDIVContent(source_ID, targetDIV_ID)
{
    document.getElementById(targetDIV_ID).innerHTML = document.getElementById(source_ID).innerHTML;
}

function expandCollapse(element) {
    if (!element)
        return;
    for (var i = 0; i < element.childNodes.length; i++)
    {
        if (element.childNodes[i].className == "fdTracksWrapper") {
            if (element.childNodes[i].style.display == "block" || element.childNodes[i].style.display == "") {
                element.childNodes[i].style.display = "none";
            }
            else if (element.childNodes[i].style.display == "none") {
                element.childNodes[i].style.display = "block";
            }
            return;
        }
    }
}

function removeLastItemBorder(element)
{
    if (!element)
        return;
    for (var i = 0; i < element.childNodes.length; i++)
    {
        if (element.childNodes[i].className == "diskwrap")
        {
            if (element.childNodes[i].style.display == "block" || element.childNodes[i].style.display == "")
	        {
		        element.childNodes[i].style.display = "none";
	        }
	        else if (element.childNodes[i].style.display == "none")
	        {
		        element.childNodes[i].style.display = "block";
	        }
	        return;
        }
    }
}

function downloadCount(downloadButtonId)
{
    var c_count = parseInt(document.getElementById("pCounter").downloadCount);
    if (c_count >= 2)
    {
        document.getElementById("pCounter").style.color = "#ff0000";
        document.getElementById("pCounter").innerText = "You have downloaded this content the maximum number of times permitted.  Please contact support@easykaraoke.com if you are having problems.";
        //document.getElementById(downloadButton).style.visibility = "hidden";
        return false;
    }
    else
    {
        c_count++;
        document.getElementById("pCounter").downloadCount = c_count;
        document.getElementById("pCounter").innerText = "You have downloaded this content " + c_count + " times (you are allowed to download content 2 times).";
    }
}

// Scripts for sample playing
function PlaySample(sampleID) {
    var ThemePlayer = document.getElementById("WMPTheme");
    if (ThemePlayer != null) 
    {
        ThemePlayer.controls.stop();
    }
    var playerdiv = document.getElementById("PlayDiv");
    var titleDiv = document.getElementById("SampleTitle");
    var playerTop;
    if (document.getElementById("content") != null)
        playerTop = document.getElementById("content").style.top + 82;
    else
        playerTop = document.getElementById("positionwrap").style.top + 82;
    titleDiv.innerText= "Please wait a moment - preparing sample";
    var wmp = document.getElementById("WMP");
    playerdiv.style.top = playerTop + "px";
    if (document.getElementById("content") != null)
        playerdiv.style.left = document.getElementById("content").offsetParent.offsetLeft;
    else
        playerdiv.style.left = document.getElementById("positionwrap").offsetParent.offsetLeft;
    wmp.URL = "PlaySample.aspx?ContentID=" + sampleID;
    wmp.controls.play();
}
function HidePlayer()
{
    var playerdiv = document.getElementById("PlayDiv");
    var wmp = document.getElementById("WMP");
    wmp.controls.stop();
    playerdiv.style.top = "-10000px";
}
function DisplaySampleTitle()
{
    var titleDiv = document.getElementById("SampleTitle");
    var wmp = document.getElementById("WMP");
    var media = wmp.currentMedia;
    var author = media.getItemInfo("Author");
    var title = media.getItemInfo("Title");
    titleDiv.innerText= "Sample of: " + title + " by " + author;
}
function offsetY(obj, value) 
{
    if (obj.offsetParent)
    {
        value += obj.offsetTop;
        return offsetY(obj.offsetParent, value);  
    }
    else
    {
        return value;
    }
}

function offsetYToDiv(obj, DivName)
{
    if (obj.id == DivName)
    {
        alert('found ' + DivName);
        return 0;
        }
    if (!obj.offsetParent)
        return 0;
    return offsetYToDiv(obj.offsetParent, DivName) + obj.offsetTop;
}
// End of scripts for sample playing