﻿/* The expanding function */

function readspeaker(rs_call) {
    /* AAK: selected text is not used */
    /*if (selectedString.length > 0) {
        rs_call = rs_call.replace("/cgi-bin/rsent?", "/enterprise/rsent_wrapper.php?");
    }*/
    savelink = rs_call + "&save=1";
    start_rs_table = "<table style='border:1px solid #aeaeae; font-size: 10px;'><tr><td>";
    rs_embed = "<object type='application/x-shockwave-flash' data='http://media.readspeaker.com/flash/readspeaker20.swf?mp3=" + escape(rs_call) + "&autoplay=1&rskin=bump' height='20' width='250'><param name='movie' value='http://media.readspeaker.com/flash/readspeaker20.swf?mp3=" + escape(rs_call) + "&autoplay=1&rskin=bump' /><param name='quality' value='high' /><param name='SCALE' value='exactfit' /><param name='wmode' value='transparent' /><embed wmode='transparent' src='http://media.readspeaker.com/flash/readspeaker20.swf?mp3=" + escape(rs_call) + "&autoplay=1&rskin=bump' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwaveflash' scale='exactfit' height='20' width='250' /></embed></object>";
    rs_downloadlink = "<br />Speech-enabled by <a href='http://www.readspeaker.com'>ReadSpeaker</a><br /><a href='" + savelink + "'>Download audio</a>";
    close_rs = "<br /><a href='#' onclick='close_rs_div(); return false;'>Close window</a>";
    end_rs_table = "</td></tr></table>";

    var x = document.getElementById('rs_div');

    x.innerHTML = start_rs_table + rs_embed + rs_downloadlink + close_rs + end_rs_table;
}

function close_rs_div() {
    var x = document.getElementById('rs_div');
    x.innerHTML = "";
}

function rsTextSelection()
{
        if (document.getSelection) // older Mozilla versions
        {
                var selectedString = document.getSelection();
        }
        else if (document.all) // MSIE 4+
        {
                var selectedString=document.selection.createRange().text;
        }
        else if (window.getSelection) // recent Mozilla versions
        {
                var selectedString=window.getSelection();
        }
        document.rs_form.selectedtext.value = selectedString;
        if (document.rs_form.url) {
                if (!document.rs_form.url.value) {
                        if (window.location.href)
                        {
                                document.rs_form.url.value=window.location.href;
                        }
                        else if (document.location.href)
                        {
                                document.rs_form.url.value=document.location.href;
                        }
                }
        }
}

function copyselected()
{
        setTimeout("rsTextSelection()",50);
        return true;
}

function openAndRead() {
        window.open('','rs','width=310,height=120,toolbar=0');
        setTimeout("document.rs_form.submit();",500);
}

document.onmouseup = copyselected;
document.onkeyup = copyselected;

