﻿function playFile(beatid, rowid) {

    try { document.getElementById('lblPlayFile').innerHTML = '<a href="javascript:stopFile(' + beatid + ');"><img border=0 src="images/img_stop.png"></a>'; } catch (Err) { } //Support for Stopping on Details Page

    //loadXMLDoc('ajaxfunctions.aspx?m=1&id=' + beatid);
    //alert(req.responseText);
    document.getElementById('filePlayer').innerHTML = writeWimpyButton(beatid, 'uploads/' + beatid + '_audition.mp3', '0', '0', '&autoplay=yes', '121212');

}

var currentRowID;
var timer;
function playListingFile(beatid, randomid) {


    //loadXMLDoc('ajaxfunctions.aspx?m=1&id=' + beatid);
    //alert(writeWimpyButton('uploads/' + beatid + '_audition.mp3', '65', '65', '&autoplay=yes', ''));
    document.getElementById('filePlayer').innerHTML = writeWimpyButton(beatid, 'uploads/' + beatid + '_audition.mp3', '0', '0', '&autoplay=yes', '121212');
    if (currentRowID != randomid) { try { document.getElementById('ply' + currentRowID).innerHTML = '<img border=0 src="images/img_play.png">'; } catch (Err) { } currentRowID = randomid; document.getElementById('ply' + randomid).innerHTML = '<img border=0 src="images/img_stop.png">'; clearTimeout(timer); timer = setTimeout('stopPlaying()', 60000); }
    else { currentRowID = null; document.getElementById('filePlayer').innerHTML = ''; document.getElementById('ply' + randomid).innerHTML = '<img border=0 src="images/img_play.png">'; clearTimeout(timer); }

    
}

function stopPlaying() {
    document.getElementById('filePlayer').innerHTML = ''; document.getElementById('ply' + currentRowID).innerHTML = '<img border=0 src="images/img_play.png">'; currentRowID = null;
    clearTimeout(timer);
}



function stopFile(beatid) {
    document.getElementById('filePlayer').innerHTML = '';
    document.getElementById('lblPlayFile').innerHTML = '<a href="javascript:playFile(' + beatid + ');"><img border=0 src="images/img_play.png"></a>';
}

function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}

var d = new Date();
function loadXMLDoc(url) {
    req = false;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } catch (e) {
            req = false;
        }
        // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                req = false;
            }
        }
    }
    if (req) {
        req.onreadystatechange = processReqChange;
        req.open("GET", url + '&t=' + d.getMinutes() + d.getSeconds() + d.getMilliseconds(), false);
        req.send("");
    }
}

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...

        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}


function writeWimpyButton(uploadid, theFile, wimpyWidth, wimpyHeight, wimpyConfigs, backgroundColor) {

    //try to stop all others
    var d = new Date;
    theFile = theFile + '?d=' + d.getMilliseconds();
    var wimpyReg = "NG5ONCU1RElFNnYlN0UlMjQ3RzhteEdhJTNCOFZMbXNQck9Iakw4Y2Rw";
    var defaultWidth = 35;
    var defaultHeight = 35;
    var defaultConfigs = "";
    var baseURL = "";
    var wimpySwf = "http://www.BudgetBeats.com/swf/wimpy_button.swf";
    var wimpyWidth = (wimpyWidth == null) ? defaultWidth : wimpyWidth;
    var wimpyHeight = (wimpyHeight == null) ? defaultHeight : wimpyHeight;
    var wimpyConfigs = (wimpyConfigs == null) ? defaultConfigs : wimpyConfigs;
    var backgroundColor = (backgroundColor == null) ? false : backgroundColor;
    var myid = "wimpybutton" + Math.round((Math.random() * 1000) + 1);
    //wimpyButtonIDs[wimpyButtonIDs.length] = myid;
    var flashCode = "";
    var newlineChar = "\n";
    var backgroundColor = (backgroundColor == null) ? false : backgroundColor;
    if (typeof (backgroundColor) == "string") {
        var Astring = backgroundColor.split("");
        if (Astring[0] == "#") {
            Astring.shift();
            backgroundColor = Astring.join("");
        }
    }
    if (backgroundColor == false) {
        tptParam = '<param name="wmode" value="transparent" />' + newlineChar;
        tptEmbed = ' wmode="transparent"';
    } else {
        tptParam = '<param name="bgcolor" value="#' + backgroundColor + '" />' + newlineChar;
        tptEmbed = ' bgcolor="#' + backgroundColor + '"';
    }
    flashCode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + wimpyWidth + '" height="' + wimpyHeight + '" id="' + myid + '">' + newlineChar;
    flashCode += '<param name="movie" value="' + wimpySwf + '" />' + newlineChar;
    flashCode += '<param name="loop" value="false" />' + newlineChar;
    flashCode += '<param name="menu" value="false" />' + newlineChar;
    flashCode += '<param name="quality" value="high" />' + newlineChar;

    flashCode += '<param name="wmode" value="transparent" />' + newlineChar;
    flashCode += '<param name="flashvars" value="theFile=' + baseURL + theFile + wimpyConfigs + '&wimpyReg=' + wimpyReg + '&myid=' + myid + '" />' + newlineChar;
    flashCode += '<embed src="' + wimpySwf + '" width="' + wimpyWidth + '" height="' + wimpyHeight + '" flashvars="theFile=' + baseURL + theFile + wimpyConfigs + '&wimpyReg=' + wimpyReg + '&myid=' + myid + '"' + tptEmbed + ' loop="false" menu="false" quality="high" name="' + myid + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>' + newlineChar;
    flashCode += '<img src="audition.aspx?id=' + uploadid + '" height="1" width="1">';
    //document.write('<br>'+myid+'<br><textarea name="textarea" cols="40" rows="3">'+flashCode+'</textarea><br>')+newlineChar;
    return flashCode;
}


function trim11(str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
}


