// JavaScript Document
/**
 *
 * All-purpose Functions
 * [Begin
 **/
function getFlashMovie(movieName) {
    return document[movieName];
}
function urlencode(str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}
/**
 * ]End
 **/



 /**
 *
 * Report functions
 * The "Checker"
 * [Begin
 **/
var IFlashDisplay = new Object();

// -- write flash [
// write the flash, occupies flashUpdateButtonHolder container
IFlashDisplay.writeFlash = function() {
    var so = new SWFObject("/_FLASH/updateFlashButton.swf", "LD_InstaFlash", "295", "50", "9.115", "#FFFFFF");
    
    so.useExpressInstall('/_FLASH/expressinstall.swf');
    
    so.addParam("allowScriptAccess", "always" );
    so.addParam("wmode", "transparent");
    so.write("flashUpdateButtonHolder");
}
// -- write flash ]



// -- show [
// unhides the checker
IFlashDisplay.show = function() {
	$('flashUpdateButtonHolder').style.display = 'block';
};
// -- show ]


/**
 * ]End
 **/


/**
 *
 * Site functions
 * The "Martian"
 * [Begin
 **/
var SFlashDisplay = new Object();

SFlashDisplay.iRan = false;
SFlashDisplay.isUser = false;


// -- write flash [
// write the flash, occupies flash_div container
SFlashDisplay.writeFlash = function() {
    var so = new SWFObject("/_FLASH/LD_SiteDisplay.swf", "LD_Flash", "100%", "600", "9.115", "#FFFFFF");
    
    so.addParam("allowScriptAccess", "always" );
    so.addParam("wmode", "opaque");
    so.write("flash_div");
};
// -- write flash ]



// -- show [
// unhides the martian
SFlashDisplay.show = function() {
    $('flash_div').style.display = 'block';
};
// -- show ]



// -- hide [
// hides the martian, its the MIB!
SFlashDisplay.hide = function() {
    $('flash_div').style.display = 'none';
};
// -- hide ]



// -- save report [
// this is a backup
SFlashDisplay.saveReport = function() {
    $('LD_Wait').style.display = '';
    var sr = new Object();
    sr.xmlHttp = new XMLHttpRequest();
    var pucatcher = RFlashDisplay.pucatcherUrl + '?a=sr&r=' + $('server_key').value;
    sr.xmlHttp.open("GET", pucatcher, true);
    sr.xmlHttp.onreadystatechange = function() {
        if(sr.xmlHttp.readyState == 4) {
            if(sr.xmlHttp.status == 200) {
                alert(sr.xmlHttp.responseText);
                eval(sr.xmlHttp.responseText);
                $('LD_Wait').style.display = 'none';
            }
        }
    };
    sr.xmlHttp.send(null);
};
// -- save report ]



// -- get indexed pages [
// sends the indexed pages data string to the beast
function getIndexedPages(tgt) {
    var text = document.getElementById('indexedpages_data');
    getFlashMovie("LD_Flash").feedthemartian(text.value);
};
// -- get indexed pages ]



// -- poke the martian [
// notifies the martian data is available for its zapping
function pokeTheMartian() {
    SFlashDisplay.iRan = true;
    SFlashDisplay.show();
    getFlashMovie("LD_Flash").waketheMartian();
    
};
// -- poke martian ]


/**
 * ]End
 **/



/**
 *
 * Bandwidth getter
 * [Begin
 **/
var BWChecker = new Object();


// -- write flash [
// writes the flash
BWChecker.writeFlash = function() {
    var bwo = new SWFObject("/_FLASH/bw-calc.swf", "LD_BW", "1", "1", "9.115", "#FFFFFF");
    bwo.addParam("allowScriptAccess", "always" );
    bwo.addParam("wmode", "opaque");
    bwo.write("bw_div");
};
// -- write flash ]



// -- get bandwidth [
// asks the brave one to go to the internet gods and steal the bandwidth. be brave little one, be brave.
BWChecker.getBandwidth = function() {
    return getFlashMovie("LD_BW").getBandwidth();
}
// -- get bandwidth ]


/**
 * ]End
 **/
