
var wnum = 0
var fonts = new Array(
"font-size: Times New Roman, Times, Serif; ",
"font-size: Verdana,Sanserif; ",
"font-size: Verdana,Sanserif; ",
"font-size: Times New Roman, Times, Serif; ",
"font-size: Times New Roman, Times, Serif; ",
"font-size: Arial,Helvetica,Sanserif; ",
"font-size: Arial,Helvetica,Sanserif; ")

var size = new Array(
"font-size: 12pt; ",
"font-size: 15pt; ",
"font-size: 16pt; ",
"font-size: 18pt; ",
"font-size: 19pt; ")

var styles = new Array(
"font-style: italic; ",
"font-style: normal; ",
"font-style: normal; ",
"font-style: oblique; ")

var bold = new Array(
"font-weight: normal; ",
"font-weight: bold; ",
"font-weight: normal; ",
"font-weight: normal; ")

function newWindow(pic,w,size) {
	resize = size + ',resizable,scrollbars=yes'
	picWindow = window.open(pic,w,resize)
	picWindow.focus()
}

function procTXT() {
    var TXTres = document.getElementById('results');
    var t_in  = "TEXT MIXER\n\nStandard Type faces are a leftover concept from the time when typographers where using pre-fabricated lead type. \nComputerization allows for easy creation and mixing of type faces. Standard Type will eventually go where the typesetters and their machines went*.  \n\nArtware"
    var l_in  = t_in.length
    var t_out = ''
    var wrd   = ''
    var str   = '<P>'

    wnum = 0
    if(l_in ==0) {
        document.converter.txt.value = "Enter text here! \n\nType face are a leftover concept from the time when typographers where using pre-fabricated lead type. Computerization allows us to disregard type faces or easely mix them.  \n\nClick Mix Type"
    }
    else {
      for(i=0;i<l_in;i++) {
	asc = t_in.charCodeAt(i)
	if(asc <= 64) { 
		if(asc == 10) { str += '<br>'; }
		else { str += endWORD(wrd) + String.fromCharCode(asc) }
		wrd = ''
	}
	else { 	// assign type to character
		
		typedef = '<SPAN style="font-size:18pt; font-family:Arial,Helvetica,Sanserif">'
		typedef = selElem(fonts) + selElem(styles) + selElem(bold) + selElem(size)
		typedef = '<SPAN style="' + typedef + '">'
		wrd += typedef + String.fromCharCode(asc) + '</SPAN>'
//		wrd += String.fromCharCode(asc)
	}
      }
      str += endWORD(wrd)
      res = l_in + ' characters read and ' + wnum + ' words processed.'
//      document.converter.dna.value = str 
//      document.converter.res.value = res 
      TXTres.innerHTML = str + '</P>'
    }
}

function selElem(el) {
    var l_l = el.length 
    var sel = Math.floor(l_l * Math.random())
    return(el[sel])
}

function endWORD(w) {
    var l_w = w.length
    var a = w.charCodeAt(0)
    var ww  = ''

    if(l_w < 1) { return(ww) }
    ww = String.fromCharCode(a)
    if(l_w == 1) { return(ww) }

    ws = ''
    for(k=1;k<l_w-1;k++) {
	a = w.charCodeAt(k)
	ws += String.fromCharCode(a)
    }
    ww += ws

    a = w.charCodeAt(l_w -1)
    ww += String.fromCharCode(a)
    wnum += 1
    return(ww)
}



