﻿function addPageTranslate() {

    var t = document.createElement('form');

    t.setAttribute('id', '__t');
    t.setAttribute('method', 'get');
    t.setAttribute('action', 'http://www.microsofttranslator.com/BV.aspx?ref=AddIn');

    var tLANG = document.createElement('select');

    tLANG.setAttribute('id', '__tLANG');
    tLANG.setAttribute('name', 'lp');
    tLANG.setAttribute('style', 'vertical-align: middle;');

    function addLang(value, desc, sel) {

        var opn = document.createElement('option');

        opn.setAttribute('value', 'en_' + value);
        opn.appendChild(document.createTextNode(desc));

        if (sel === true) {
            opn.setAttribute('selected', 'selected');
        }

        tLANG.appendChild(opn);

    }

    addLang('ar', 'ترجمة هذه الصفحة');
    addLang('zh-CHS', '翻译此页');
    addLang('zh-CHT', '翻譯此網頁');
    addLang('nl', 'Deze pagina vertalen');
    addLang('en', 'Translate this page', true);
    addLang('fr', 'Traduire cette page');
    addLang('de', 'Diese Seite übersetzen');
    addLang('it', 'Traduci questa pagina');
    addLang('ja', 'このページを翻訳します');
    addLang('ko', '번역 보기');
    addLang('pl', 'Przetłumacz tę stronę');
    addLang('pt', 'Traduzir esta página');
    addLang('ru', 'Перевести эту страницу');
    addLang('es', 'Traducir esta página');

    t.appendChild(tLANG);

    var tURI = document.createElement('input');

    tURI.setAttribute('id', '__tURI');
    tURI.setAttribute('type', 'hidden');
    tURI.setAttribute('name', 'a');
    tURI.setAttribute('value', document.location.href);

    t.appendChild(tURI);

    var tSUB = document.createElement('a');
    tSUB.setAttribute('href', 'http://www.microsofttranslator.com/BV.aspx?ref=AddIn&lp=en_en&a=' + document.location.href);
    tSUB.onclick = function (e) {

        document.getElementById('__t').submit();
        return false;

    };

    var tIMG = document.createElement('img');

    tIMG.setAttribute('alt', 'Translate this page');
    tIMG.setAttribute('style', 'vertical-align: middle;');
    tIMG.setAttribute('src', '/images/translate.gif');

    tSUB.appendChild(tIMG);
    t.appendChild(tSUB);

    document.getElementById('translator').appendChild(t);

}

registerLoad('script/translate.js', addPageTranslate);