//--------------------------------------------
// EMOTICONS
//--------------------------------------------
var myVersion = parseInt(navigator.appVersion);
var myAgent   = navigator.userAgent.toLowerCase();
var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var contf = 200;  // Total de carateres nas mensagens


function emoticon(theSmilie)
{
	if (document.frmshoutbox.msg.value == 'mensagem') { document.frmshoutbox.msg.value = ''; }
	if ((document.frmshoutbox.msg.value.length + theSmilie.length + 2) <= contf){ 
		doInsert(" " + theSmilie + " ", "", false);
	}
	else
	{
		alert('O número de caracteres é maior que o permitido.');
	}
}


function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = document.frmshoutbox.msg;

	if ( (myVersion >= 4) && is_ie && is_win) // Ensure it works for IE4up / Win only
	{
		if(obj_ta.isTextEdit){ // this doesn't work for NS, but it works for IE 4+ and compatible browsers
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null){
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;
	
				rng.text = ibTag;
			}
		}
		else{
			if(isSingle)
				isClose = true;
	
			obj_ta.value += ibTag;
		}
	}
	else
	{
		if(isSingle)
			isClose = true;

		obj_ta.value += ibTag;
	}

	obj_ta.focus();

	return isClose;
}	
// EMOTICONS FIM
//
//conta o tamanho das palavras
function palavra (str) {
var tampalavra = 35;
var espaco = true;
 var tamanho = str.length;
var tamanho2 = 0;
for(i=0; i<tamanho; i++) {
if (str.charAt(i)==" ") { tamanho2 =0; }
if (tamanho2 >= tampalavra) { espaco = false;}
tamanho2++ ;
}
return espaco;
 }

//verifica se os campos foram preenchidos corretamente
function Validar_Form(){
	if (document.frmshoutbox.nome.value == "nome") {
		alert("Por favor indique o seu nome.");
		document.frmshoutbox.nome.focus();
		return false;
	}
				
	if (document.frmshoutbox.msg.value == 'mensagem')
	{
		alert("Por favor complete o campo mensagem.");
		document.frmshoutbox.msg.focus();
		return false;
	}
	
	if (palavra(document.frmshoutbox.msg.value) == false)
	{
		alert("O campo Mensagem possui uma palavra muito grande.");
		document.frmshoutbox.msg.focus();
		return false;
	}
	
	return true;
}

function mostra_emoticons() {
  var element = document.getElementById('emoticons');
  if (element.style.display=='none') {
   element.style.display='';
   document.getElementById('bticons').value = '-';
  } else { element.style.display='none'; document.getElementById('bticons').value = '+'; }
}

function perde_focus(ni, vl)
{ if (ni.value == '') { ni.value = vl; } }

function ganha_focus(ni, vl)
{ if (ni.value == vl) { ni.value = ''; } }