
//Pig Latin Translator
function trans(word1) {
    var y=0;
    var outword='';
    while (++y<=word1.length) {
        ch = word1.substring(y-1, y);
        if ( ('AEIOU'.indexOf(ch.toUpperCase()) > -1 ) || ((ch.toUpperCase()=='Y')&&(y>1))) {
            if (outword=='') {
                outword = document.plForm.dialect.options[document.plForm.dialect.selectedIndex].value;
            }
            else {
                if (((word1.substring(y-2, y-1)).toUpperCase()=='Q')&&(ch.toUpperCase()=='U')) {
                    outword = outword + ch;
                    y++;
                }
            }
            if (document.plForm.hyph.options[document.plForm.hyph.selectedIndex].value==1) {
                outword = word1.substring(y-1, word1.length) + '-' + outword + 'ay';
            }
            else{
                outword = word1.substring(y-1, word1.length) + outword + 'ay';
            }
            y = word1.length;
        }
        else {
            outword = outword + ch;
        }
    }
    if ((word1.substring(0,1)).toUpperCase()==word1.substring(0,1)) {
        outword = ((outword.substring(0,1)).toUpperCase()
                        + (outword.substring(1,outword.length+1)).toLowerCase());
    }
    return outword;
}
function transToPL(text) {
    var fulltrans = '';
    var word = '';
    var ch = '';
    var x = 0;
    text = text + ' ';
    for (x=1; x<=text.length; x++) {
        ch = text.substring(x-1, x);
        if (' ,.<>[]{}!@#$%^&*()-=+_\|`~/?";:'.indexOf(ch) > -1) {
            fulltrans = fulltrans + trans(word) + ch;
            word = '';
        }
        else {
            if ((ch=='\r')||(ch=='\n')) {
                fulltrans = fulltrans + trans(word) + ch;
                word = '';
            }
            else {
                word = word + ch;
            }
        }
    }
    return fulltrans;
}
function process() {
    document.plForm.output.value = transToPL(document.plForm.inputarea.value);
}
//-->