var doselect = 1;
var toggleoptions = 0;

function selectAll(theField) {
	var tempval=eval("document."+theField)
	tempval.focus()
	tempval.select()
}

function togglePage()
{
	if (toggleoptions==0)
	{
		document.getElementById('divOptions').style.display = "block";
		document.shoutbox.btnOptions.value="-";
		toggleoptions=1;
	}
	else
	{
		document.getElementById('divOptions').style.display = "none";
		document.shoutbox.btnOptions.value="+";
		toggleoptions=0;
	}
}

function addSmiley(smiley)
{
	if (doselect==1)
		document.shoutbox.txtMessage.value="";
	doselect=0;
	document.shoutbox.txtMessage.value=document.shoutbox.txtMessage.value+smiley;
	document.shoutbox.txtMessage.focus();
}

function wrap(quem){
	var larg_total,larg_carac,quant_quebra,pos_quebra, over_orig;
	var elementos,quem, pai, caracs, texto, pai_texto, display_orig, wid_orig;
    
    if(quem.nodeType==3){
		
		if(quem.nodeValue.replace('\n','').replace('\t','').trim()==''){
			return true;
		}
		
		pai = quem.parentNode;
		texto = quem.nodeValue;
		
		display_orig = pai.style.display;
		over_orig = pai.style.overflow;
		wid_orig = pai.style.width;
		pai.style.display="block";
		pai.style.overflow="hidden";
		larg_oficial = pai.offsetWidth;
		
		pai.style.display="table";
		pai.style.width = "auto";
		pai.style.overflow = "visible";
		larg_total = pai.offsetWidth;
		pai.style.overflow = over_orig;
		
		if(larg_total>larg_oficial){
			pos_quebra = 0;
			caracs = pai.textContent.length;
			
			quem.nodeValue = pai.textContent.replace(/ /g,"&Oslash;") + " ";
			larg_total = pai.offsetWidth;
			pai.style.display = display_orig;
			
			larg_carac = larg_total / caracs ;
			quant_quebra = parseInt(larg_oficial/larg_carac) - 2; 
			
			quem.nodeValue = '';
			
			while(pos_quebra<=caracs){
				quem.nodeValue += texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
				pos_quebra = pos_quebra + quant_quebra;
			}			
		}
		pai.style.display = display_orig;
		pai.style.display = over_orig;
		pai.style.width = wid_orig;
		
	}else if(quem.childNodes.length==1 && quem.childNodes[0].nodeType==3){
		texto = String(quem.innerHTML);
		display_orig = quem.style.display;
		over_orig = quem.style.overflow;
		wid_orig = quem.style.width;
		quem.style.display="block";
		quem.style.overflow="hidden";
		larg_oficial = quem.offsetWidth;
		quem.style.display="table";
		quem.style.width = "auto";
		quem.style.overflow = "visible";
		larg_total = quem.offsetWidth;
		quem.style.overflow = over_orig;
				
		if(larg_total>larg_oficial){
			pos_quebra = 0;
			caracs = texto.length;
			quem.innerHTML = quem.innerHTML.replace(/ /g,"&Oslash;");
			larg_total = quem.offsetWidth;
			larg_carac = larg_total / caracs ;
			
			quant_quebra = parseInt(larg_oficial/larg_carac) - 2; 
			quem.innerHTML = ""
			
			while(pos_quebra<=caracs){
				quem.innerHTML += texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
				pos_quebra = pos_quebra + quant_quebra;
			}
			
		}	
		quem.style.display = display_orig;
		quem.style.display = over_orig;
		quem.style.width = wid_orig;
		
	}else if(quem.childNodes.length>0){
		for(var i=0;i<quem.childNodes.length;i++){
			wrap(quem.childNodes[i]);
		}
	}
}
function wordWrap(){  
    var elementos = document.body.getElementsByTagName("*") 
 
    if(navigator.appName.indexOf("Internet Explorer")>-1){
        for(var i=0; i<elementos.length;i++){
            if(elementos[i].className.indexOf("wrapie")>-1){
			elementos[i].style.width = document.body.offsetWidth-50;
			elementos[i].style.wordWrap = "break-word";
            }
        }
    }else{
        for(var i=0; i<elementos.length;i++){
            if(elementos[i].className.indexOf("wrapff")>-1){
                wrap(elementos[i]);
            }
        }
    }
}

String.prototype.trim = function() {
   return this.replace(/^[ ]+|[ ]+$/g,"");
}
