﻿// JScript File
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.getElementById('selectedtextDyn').value = selectedString;
        
        if (document.form1.urlDyn) {
                if (!document.form1.urlDyn.value) {
                        if (window.location.href)
                        {
                                document.form1.urlDyn.value=window.location.href;
                        }
                        else if (document.location.href)
                        {
                                document.form1.urlDyn.value=document.location.href;
                        }
                }
        }
        
}

function copyselected()
{
    setTimeout("rsTextSelection()",50);
    return true;
}

document.onmouseup = copyselected;
document.onkeyup = copyselected;

function createForm(){
    mypara=document.getElementById("paraID");
    myform=document.createElement("form");
    myform.name = 'rs_form';
    myform.action = 'http://app.readspeaker.com/cgi-bin/rsent';
    myform.method = 'post';
    myform.target = 'rs';

    myUrl = document.createElement("input");
    myUrl.setAttribute("type", "hidden");
    myUrl.setAttribute("name", "url");
    myUrl.setAttribute("value", document.getElementById('urlDyn').value);
    
    mySelectedText = document.createElement("input");
    mySelectedText.setAttribute("type", "hidden");
    mySelectedText.setAttribute("name", "selectedtext");
    if (document.getElementById('setSelectedText').value == 'divcontent'){
        mySelectedText.setAttribute("value", document.getElementById('divTitle').innerHTML + '<br /><br />' + document.getElementById('divContent').innerHTML);
    }
    else{
        if (document.getElementById('setSelectedText').value == 'divnewsarchive'){
            mySelectedText.setAttribute("value", document.getElementById('divTitle').innerHTML + '<br /><br />' + document.getElementById('divNewsArchive').innerHTML);
        }
        else{
            mySelectedText.setAttribute("value", document.getElementById('selectedtextDyn').value);
        }
    }
    
    myCustomerId = document.createElement("input");
    myCustomerId.setAttribute("type", "hidden");
    myCustomerId.setAttribute("name", "customerid");
    myCustomerId.setAttribute("value", "85");

    myLang = document.createElement("input");
    myLang.setAttribute("type", "hidden");
    myLang.setAttribute("name", "lang");
    myLang.setAttribute("value", "nl_nl");
    
    myOutput = document.createElement("input");
    myOutput.setAttribute("type", "hidden");
    myOutput.setAttribute("name", "output");
    myOutput.setAttribute("value", "template");
    
    myReadId = document.createElement("input");
    myReadId.setAttribute("type", "hidden");
    myReadId.setAttribute("name", "readid");
    myReadId.setAttribute("value", "divcontent");

    myform.appendChild(myUrl);
    myform.appendChild(mySelectedText);
    myform.appendChild(myCustomerId);
    myform.appendChild(myLang);
    myform.appendChild(myOutput);
    myform.appendChild(myReadId);
    
    mypara.appendChild(myform);
    
    window.open('','rs','width=380,height=180,toolbar=0');
    //myform.submit();
    setTimeout("myform.submit();",500);
    setTimeout("deleteForm(myform);",4000);
}

function deleteForm(myform) {
    mypara=document.getElementById("paraID");
    mypara.removeChild(myform);
}

