// JavaScript Document
/**
 *
 * Report functions
 * The "Beast"
 * [Begin
 **/
if($('basic_output') && $('basic_output').value == 0) {
    
    
    RFlashDisplay.iRan = false;
    RFlashDisplay.isUser = false;
    RFlashDisplay.pucatcherUrl = 'pucatcher.php';
    RFlashDisplay.linkPageAge = '';
    RFlashDisplay.freed = false;
    
    RFlashDisplay.puLogin = 'login.php?r=index-lite';
    RFlashDisplay.puProjAdd = 'project.php?r=add-lite';
    RFlashDisplay.puProfAdd = 'report.php?r=add-lite';
    RFlashDisplay.puTagLink = 'link.php?r=add-lite';
    
    
    // -- show [
    // unhides the beast
    RFlashDisplay.show = function() {
    	$('flash_div').style.display = 'block';
    };
    // -- show ]
    
    
    
    // -- hide [
    // hides the beast, its the cops!
    RFlashDisplay.hide = function() {
    	$('flash_div').style.display = 'none';
    };
    // -- hide ]
    
    
    
    // -- get URL [
    // sends the report URL to the beast
    RFlashDisplay.getURLForFlash = function() {
        return HTTPRequest.QueryString("q");
    };
    // -- get ]
    
    
    
    // -- open link [
    // opens up the link in a new tab/window
    RFlashDisplay.openLink = function(url) {
        LD.DAO.openLink(url);
    };
    // -- open link ]
    
    
    
    // -- alert [
    // opens up the link in a new tab/window
    function SCREAM(str) {
        alert(str);
    };
    // -- alert ]
    
    
    
    // -- tag link array [
    // tags the link(s)
    RFlashDisplay.tagLinkArray = function(url) {
        LD.DAO.tagLinkArray(url);
    };
    // -- tag link array ]
    
    
    
    // -- get page age [
    // gets the age of the page
    RFlashDisplay.getPageAge = function(url) {
        LD.DAO.getPageAge(url);
    };
    // -- get page age ]
    
    
    
    // -- get report date [
    RFlashDisplay.getReportDate = function() {
        return LD.DAO.getReportDate();
    }
    // -- get report date ]
    
    
    
    // -- get beast tags [
    RFlashDisplay.getBeastTags = function() {
        return LD.DAO.getBeastTags();
    }
    // -- get beast tags ]
    
    
    
    // -- get share link [
    RFlashDisplay.getShareLink = function() {
        return LD.DAO.getShareLink();
    }
    // -- get share link ]
    
    
    
    // -- new report [
    // runs a new report for the url in a new tab/window
    RFlashDisplay.newReport = function(url) {
        LD.DAO.newReport(url);
    };
    // -- new report ]
    
    
    
    // -- save report [
    // saves the report
    RFlashDisplay.saveReport = function() {
        LD.DAO.saveReport();
    };
    // -- save report ]
    
    
    
    // -- create custom [
    // create a custom report
    RFlashDisplay.createCustom = function() {
        LD.DAO.createCustom();
    };
    // -- create custom ]
    
    
    
    // -- export pdf [
    // export to pdf
    RFlashDisplay.exportPDF = function(url, column, direction) {
        LD.DAO.exportPDF(url, column, direction);
    };
    // -- export pdf ]
    
    
    
    // -- export csv [
    // export to csv fronter
    RFlashDisplay.exportCSV = function(params) {
        LD.DAO.exportCSV(params);
    };
    // -- export csv ]
    
    
    
    // -- json error [
    // reload report if there is an error with json
    RFlashDisplay.jsonError = function() {
        if(HTTPRequest.QueryString("k")) {
            reload_report();
        }
        else {
            whisperUser('Something went wrong, sorry.', 30000);
        }
    };
    // -- json error ]
    
    
    
    // -- write flash [
    // write the flash, occupies flash_div container
    RFlashDisplay.writeFlash = function() {
        var so = new SWFObject("/_FLASH/LD_LinkDisplay.swf", "LD_Flash", "100%", "950", "9.115", "#FFFFFF");
        
        so.useExpressInstall('/_FLASH/expressinstall.swf');
        
        so.addParam("allowScriptAccess", "always" );
        so.addParam("wmode", "transparent");
        so.write("flash_div");
    }
    // -- write flash ]
    
    
    
    // -- get pages [
    // sends the pages json string to the beast
    function getPages(tgt) {
        var text = document.getElementById('pages_data');
        getFlashMovie("LD_Flash").sendPages(text.value);
        IndexedPages.data = eval(text.value);
    }
    // -- get pages ]
    
    
    
    // -- get links [
    // sends the links json string to the beast
    function getLinks(tgt) {
        var text = document.getElementById('links_data');
        getFlashMovie("LD_Flash").sendLinks(text.value);
        BackLinks.data = eval(text.value);
    }
    // -- get links ]
    
    
    
    // -- get links [
    // sends the links json string to the beast
    function getPermissions() {
        var perms = document.getElementById('perms_data').value.split('|');
        getFlashMovie("LD_Flash").cuffthebeast(perms);
    }
    // -- get links ]
    
    
    
    // -- get results [
    // sends the results string to the beast
    function getResults(tgt) {
        var text = document.getElementById('results_data');
        getFlashMovie("LD_Flash").feedthebeast(text.value);
    }
    // -- get results ]
    
    
    
    // -- poke the beast [
    // notifies the beast the data is available for his consumption
    function pokeTheBeast() {
        try {
            
            LD.hasExtension = true;
            if(!RFlashDisplay.iRan) {
                RFlashDisplay.iRan = true;
                RFlashDisplay.show();
            }
            getFlashMovie("LD_Flash").waketheBeast();
            getFlashMovie("LD_Flash").pattheBeast();
            if($('cache_age').value != ''){
                rallyTheBeast();
            }
        } catch(e) {
            // try again, oh please oh please oh please wake up
            setTimeout("pokeTheBeast();", 1500);
        }
        clearInterval(SplashDisplay.showProgressDisplayInterval);
        SplashDisplay.runningProgressStream = new Array();
        $('Overlay').innerHTML = "";
    }
    // -- poke the beast ]
    
    
    
    // -- rally the beast [
    // notifies the beast the data is available for his consumption
    function rallyTheBeast() {
        if(!RFlashDisplay.freed) {
            try {
                getFlashMovie("LD_Flash").freetheBeast();
                RFlashDisplay.freed = true;
            } catch(e) {
                setTimeout("rallyTheBeast();", 2000);
            }
        }
    }
    // -- rally the beast ]
    
    
    RFlashDisplay.writeFlash();
    
}
/**
 * ]End
 **/
