/**
 * Displays a dialog box explaining that a show has been licensed
 * @param episodeId The specific episodeId of the show being downloaded
 */
function showLicensingDialog(episodeId){
    loadAlertBox();
    var message = new Element('div');
    var titleElement = new Element('h1');
    titleElement.setAttribute("style", "float: left; margin-bottom: 2px; font-size: 16px;");
    titleElement.appendText("Sorry, but this show has been licensed");
    message.adopt(titleElement);
    message.adopt(new Element('h2',{'style':'clear: both'}).appendText("What does this mean?"));
    message.appendText("The company that owns the rights to this anime has asked " +
        "us to remove it from the site and we are legally obligated to do so");
    message.adopt(new Element('h2').appendText("Where else can I download this show?"));
    message.appendText("We're currently working on a list, but you should try ");
    var linkUrl = "http://www.amazon.com/s/ref=nb_ss_atv?url=search-alias%3Damazontv&tag=bluelagunasme-20&field-keywords=" + escape(animeTitle) + "&x=0&y=0";
    var linkElement = new Element('a',{'href':linkUrl,'target':'new'});
    linkElement.appendText("Amazon's Video On Demand Service");
    message.adopt(linkElement);
    message.adopt(new Element('h2').appendText("What else should I download in the meantime?"));
    message.appendText("We are working on a list of this as well.  In the meantime, check out the Recommendations button on the full episodes page");
    showInfoDialog(message,null);
}

/**
 * Remind people that they should puchase subscriptions :-)
 * @param href The download url being passed
 * @return boolean - Whether download should continue or block
 */
function showDownloadTip(href){
    if(href.indexOf('fastclick') > -1){
        return true;
    }
    if(userId == 0){
        loadCaptcha();
        register(href);
        return false;
    }
    var downloads = parseInt(readCookie('dlcount'));
    var lastCheck = readCookie('lastcheck');
    if(lastCheck == null){
        lastCheck = 0;
    }
    else{
        lastCheck = parseInt(lastCheck);
    }
    if(downloads != null && (downloads - lastCheck >= 10)){
        if(downloads < 20){
            return true;
        }
        else{
            createCookie('lastcheck', downloads, 365);
            showHoursWasted(href);
            return false;
        }
    }
    return true;
}
/**
 * Let users know how much time they've wasted by not having SpeedPass
 */
function showHoursWasted(href){
    var downloads = readCookie('dlcount');
    var hours = Math.round(downloads / 4);
    var message = new Element('div');
    var titleElement = new Element('h1');
    titleElement.setAttribute("style", "float: left; margin-bottom: 2px; font-size: 16px;");
    titleElement.appendText("How much is");
    titleElement.adopt(new Element('i').appendText(' your '));
    titleElement.appendText("time worth?");
    message.adopt(titleElement);
    message.adopt(new Element('h2',{'style':'clear: both'}).appendText("Time is money"));
    message.appendText("Yet you've wasted at least " + hours + " hours waiting for files to download");
    message.adopt(new Element('h2').appendText("Why wait?"));
    message.appendText("The longer you wait for files to download, the less time you have to enjoy them");
    message.adopt(new Element('h2').appendText("Make up for lost time!"));
    var linkUrl = "/members/renew.php?service=speedpass";
    var linkElement = new Element('a',{'href':linkUrl});
    linkElement.appendText("Sign up for SpeedPass today!");
    message.adopt(linkElement);
    showInfoDialog(message.innerHTML,function(){ window.location = href});
}
function showFTPDialog(hasSpeedPass){
    var message = new Element('div');
    //Message header changes depending on speedpass subscription
    var header = new Element('h1');
    var service = '';
    if(hasSpeedPass){
        header.appendText("Get FTP Access for only $1 per month!");
        service = 'ftp';
    }
    else{
        header.appendText("Get Access to FTP Servers with SpeedPass!");
        service = 'speedpass';
    }
    message.adopt(header);
//    message.appendText("With a subscription to the FTP service, you'll be able to use RealityLapse.com's FTP Servers to:");
//    var featureList = new Element('ul');
//    var clientTutorial = new Element('a',{'href':'#','target':'new'});
//    clientTutorial.adopt(new Element('li').appendText('-Access files using your favorite FTP client'));
//    featureList.adopt(clientTutorial);
//    var driveTutorial = new Element('a',{'href':'#','target':'new'});
//    driveTutorial.adopt(new Element('li').appendText('-Use the RealityLapse servers like a hard drive'));
//    featureList.adopt(driveTutorial);
//    featureList.adopt(new Element('li').appendText('...and much more'));
//    message.adopt(featureList);
    var request = new Request.HTML({
        url:'/members/renew.php?ajax=true&addons=ftp&service='+service,
        method: 'post',
        onSuccess:function(responseTree, responseElements, responseHTML, responseJavaScript){
            var box = new Element('div');
            box.innerHTML = responseHTML;
            message.adopt(box);
            showConfirmDialog(message,function(){$('renewalForm').submit()});
            $('renewButton').destroy();
            $('renewalForm').setAttribute("onsubmit", "return false;");
            $('renewalForm').setAttribute("action", "/members/renew.php?service="+service);
            if(!target){
              target = window.location;
            }
            $('targetPage').setAttribute('value', target);
        }});
    request.send();
}