﻿function deletePlayer() {
    swfobject.removeSWF('player1');
    swfobject.removeSWF('rotator1');
    var tmp = document.getElementById('playerWrapper');
    if (tmp) { tmp.innerHTML = "<div id='playerPlaceHolder'></div>"; }
}
function createRotator() {
    var flashvars = {
        'file': 'Media/js/Ads.xml',
        'enablejs': 'true',
        'autostart': 'true',
        'shownavigation': 'false',
        'lightcolor': "0xffffff",
        'frontcolor': "0xd1ff00",
        'backcolor': "0x000000",
        'shuffle': "false",
        'rotatetime': '4',
        'width': '270',
        'height': '219'
    }
    var params = {
        allowfullscreen: "false",
        allowscriptaccess: "always",
        wmode: "opaque"
    }
    var attributes = {
        id: "rotator1",
        name: "rotator1"
    }
    swfobject.embedSWF("Media/js/rotator.swf", "playerPlaceHolder", '270', '219', "9.0.115", false, flashvars, params, attributes);
}
function createPlayer(theFile, theImage, theLogo) {
    var flashvars = {
        'file': theFile,
        'image': theImage,
        'logo.file': theLogo,
        'logo.position': "top-left",
        'logo.hide': "false",
        'autostart': "true",
        'bufferlength': "3",
        'abouttext': "LatinosUnidosOnline.net",
        'aboutlink': "http://www.latinosunidosonline.net",
        'author': "LatinosUnidosOnline.net",
        'lightcolor': "ffffff",
        'frontcolor': "fed701",
        'backcolor': "000000"
    }
    var params = {
        allowfullscreen: "false",
        allowscriptaccess: "always",
        wmode: "opaque"
    }
    var attributes = {
        id: "player1",
        name: "player1"
    }
    swfobject.embedSWF("Media/js/player5.swf", "playerPlaceHolder", '270', '219', "9.0.115", false, flashvars, params, attributes);
}
function playVid(id) {
    deletePlayer();
    createPlayer('http://www.latinosunidosonline.net/Media/Video/' + id + '.flv', 'Media/Images/video_' + id + '.jpg', '');
}
function playAudio(id) {
    deletePlayer();
    createPlayer('Media/Audio/' + id + '.mp3', '', 'Media/js/luplayer.png');
}
function sayAlert() {
    if (!jConfirm('You must be a member, and logged-in to download audio or video.  Would you like to be redirected to the Login/Signup page?', 'Logged-In Members Only', function (r) { if (r) { window.location.href = '../Default.aspx' } else { return false; } })) return false;
}
function directVideo(videoId, posted) {
    $('#hdnVideoId').attr('value', videoId);
    var pm = $("[id$='hdnIsPM']");
    var userId = $("[id$='hdnUserId']");
    var va = $("[id$='hdnIsVA']");
    var bl = $("[id$='hdnBacklog']");
    var b = $("[id$='hdnBL']");
    var sDate = new Date(bl.val());
    var pDate = new Date(posted);

    if (userId.val() == 0) {
        sayAlert();
        return false;
    }
    if (pm.val() == 'False') {
        sayAlert();
        return false;
    }
    if (va.val() == 'False') {
        jAlert("Your account does not have access to download video files.  If you have any questions, please feel free to contact us.", "Download Access Denied");
        return false;
    }
    if (pDate < sDate) {
        jAlert("Your account does not have access to download backlog files beyond " + b.val() + " months old.  If you have any questions or would like to upgrade your backlog access, please feel free to contact us.", "Download Access Denied");
        return false;
    }

    var dlOptions = {
        type: "POST",
        url: "Controls/Download.ashx?section=Video",
        data: "{'mediaId':" + videoId + "}",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false
    };
    var returnDl = $.ajax(dlOptions).responseText;
    if (returnDl == 1) {
        jAlert("You have already downloaded this video 3 times.  To prevent account sharing we limit the number of times a single video can be downloaded and log all IP address, computer, and location information, among others.  If you have any questions, please feel free to contact us.", "Download Limit Exceeded");
        return false;
    } else if (returnDl == 2) {
        var orderform = '../Public/SubscriptionPlan.aspx?userId=M' + userId.val() + '-97857432';
        if (!jConfirm('You have used up all your free trial downloads.  Please click the OK button to be redirected to the subscription signup page to get full access.', 'Free Download Limit Exceeded', function (r) { if (r) { window.location.href = orderform; } else { return false; } })) return false;
    } else {
        window.location.replace(returnDl);
        return false;
    }
}

function directAudio(audioId, posted) {
    var pm = $("[id$='hdnIsPM']");
    var userId = $("[id$='hdnUserId']");
    var aa = $("[id$='hdnIsAA']");
    var bl = $("[id$='hdnBacklog']");
    var b = $("[id$='hdnBL']");
    var sDate = new Date(bl.val());
    var pDate = new Date(posted);
    if (userId.val() == 0) {
        sayAlert();
        return false;
    }
    if (pm.val() == 'False') {
        sayAlert();
        return false;
    }
    if (aa.val() == 'False') {
        jAlert("Your account does not have access to download audio files.  If you have any questions, please feel free to contact us.", "Download Access Denied");
        return false;
    }
    if (pDate < sDate) {
        jAlert("Your account does not have access to download backlog files beyond " + b.val() + " months old.  If you have any questions or would like to upgrade your backlog access, please feel free to contact us.", "Download Access Denied");
        return false;
    }
    var dlOptions = {
        type: "POST",
        url: "Controls/Download.ashx?section=Audio",
        data: "{'mediaId':" + audioId + "}",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false
    };
    var returnDl = $.ajax(dlOptions).responseText;
    if (returnDl == 1) {
        jAlert("You have already downloaded this track 3 times.  To prevent account sharing we limit the number of times a single track can be downloaded and log all IP address, computer, and location information, among others.  If you have any questions, please feel free to contact us.", "Download Limit Exceeded");
        return false;
    } else if (returnDl == 2) {
        var orderform = '../Public/SubscriptionPlan.aspx?userId=M' + userId.val() + '-97857432';
        if (!jConfirm('You have used up all your free trial downloads.  Please click the OK button to be redirected to the subscription signup page to get full access.', 'Free Download Limit Exceeded', function (r) { if (r) { window.location.href = orderform; } else { return false; } })) return false;
    } else {
        window.location.replace(returnDl);
        return false;
    }
}
