/**
 * Controller functions for newsletter page ajax requests
 * 
 * @author Garrette A. Hall <ghall@positroniks.com>
 * @copyright 2006, licensed for unrestricted use to The Vandiver Group, Inc.
 */

/**
 * Sends ajax request for a list of newletter links and inserts output into the document
 *
 * @param string name the name of the desired newsletter ('vision' or 'insight')
 * @return boolean false and inserts default links if no newletter name is passed
 */
function requestNewsletterList(name) {
    if(name == 'none') {
        var deflist = '<ul><li><a href="#" onclick="requestNewsletterList(\'vision\');">Vision</a></li><li><a href="#" onclick="requestNewsletterList(\'stratigem\');">Stratigem</a></li></ul>';
        document.getElementById('sidebar').innerHTML = deflist;
        return false;
    }
    var xhr = getXHR();
    var url = '../../script/backend.php';
    var action = '?ajax=1&request=newsletterlist&name=' + name;
    xhr.open('get', url + action, true);
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 4) {
            if(xhr.status == 200) {
                result = xhr.responseText;
                document.getElementById('sidebar').innerHTML = result;
            }
        }
    }
    xhr.send(null);
}

/**
 * Sends ajax request for formatted copy of a newsletter issue
 *
 * @param int nlid newsletter id
 */
function requestNewsletterCopy(nlid) {
    var xhr = getXHR();
    var url = '../../script/backend.php';
    var action = '?ajax=1&request=newsletter&nlid=' + nlid;
    xhr.open('get', url + action, true);
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 4) {
            if(xhr.status == 200) {
                result = xhr.responseText;
                document.getElementById('copy').innerHTML = result;
            }
        }
    }
    xhr.send(null);
}