String.prototype.trim = function() 
{
  return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
String.prototype.specialChars = function() 
{
//  return (this.replace(/\\u003c/gi, "&lt;").replace(/\\u003e/gi, "&gt;").replace(/\\u0026/gi, "&amp;").replace(/\\r\\n/gi, "<br />").replace(/\\n/gi, "<br />").replace(/\\r/gi, "<br />"));
 return (this.replace(/\\u003c/gi, "<").replace(/\\u003e/gi, ">").replace(/\\u0026/gi, "&").replace(/\\r\\n/gi, "<br />").replace(/\\n/gi, "<br />").replace(/\\r/gi, "<br />").replace(/\\u000d\\u000a/gi, "<br />"));
}

function valor(id)
{
	return document.getElementById(id).value.trim();
}

function checaEmail(pStr)
{
	reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	return reEmail1.test(pStr) || reEmail2.test(pStr) || reEmail3.test(pStr);
}

function difEspaco(idElem) 
{
  return valor(idElem).trim() != "";
}

function difZero(idElem) 
{
  return valor(idElem).trim() != 0; 
}

function tamMax(idElem, tam) 
{
	elemento = valor(idElem).trim();
	return elemento.length <= tam;
}

function tamMin(idElem, tam) 
{
	elemento = valor(idElem).trim();
	return elemento.length >= tam
}

function Numerico(idElem) 
{
	reDigits = /^\d+$/;
	elemento = document.getElementById(idElem).value;
	return reDigits.test(elemento);
}

function addOption(idSelect, newOptValue, newOptText, newOptSelected)
{
  var obj = new Option();
  obj.text = newOptText;
  obj.value = newOptValue;
  obj.selected = newOptSelected;
  document.getElementById(idSelect).options.add(obj);
}

function addOptGroup(objId, objLabel, objOpt){
  optGroup = document.createElement('optgroup');
  var objSelect=document.getElementById(objId);
  optGroup.label = objLabel;
  for(GrupoOpcoes=0; GrupoOpcoes<objOpt.length; GrupoOpcoes++)
  {
    var objOption=document.createElement("option");
    objOption.innerHTML = objOpt[GrupoOpcoes]['texto'];
    objOption.value = objOpt[GrupoOpcoes]['valor'];
    objOption.selected = objOpt[GrupoOpcoes]['selecionado'];
    objSelect.appendChild(optGroup);
    optGroup.appendChild(objOption);
  }
}

function enter(){
	if(event.keyCode=="13"){
		if(document.getElementById('txtLogin').value==''){
			document.getElementById("divMsg").innerHTML = "Digite o login (E-Mail) no campo indicado";
			document.getElementById('txtLogin').focus();
		}
		else if(document.getElementById('pwdSenha').value==''){
			document.getElementById("divMsg").innerHTML = "Digite a senha no campo indicado";
			document.getElementById('pwdSenha').focus();
		}
		else{
			login();
		}
	}
}

function menu(valor){

	if(valor=='inbox'){
		document.getElementById("divEncaminhar").style.visibility='hidden';
		document.getElementById("divEncaminharExt").style.visibility='hidden';
		document.getElementById("divEncaminharSend").style.visibility='hidden';
		document.getElementById("divEncaminharSendExt").style.visibility='hidden';
		document.getElementById('txtAssunto').value='';
		document.getElementById('inboxmsg').style.display='block';
		document.getElementById('sendmsg').style.display='none';
		document.getElementById('outboxmsg').style.display='none';
		document.getElementById('inbox').src='../../imgs/inbox_on.gif';
		document.getElementById('compose').src='../../imgs/outbox_off.gif';
		document.getElementById('envoyer').src='../../imgs/envoyer_off.gif';
		document.getElementById('inbox_td').className='Celula_Menus_On'
		document.getElementById('compose_td').className='Celula_Menus'
		document.getElementById('envoyer_td').className='Celula_Menus'

	}
	else if(valor=='compose'){
		document.getElementById("divEncaminhar").style.visibility='hidden';
		document.getElementById("divEncaminharExt").style.visibility='hidden';
		document.getElementById("divEncaminharSend").style.visibility='hidden';
		document.getElementById("divEncaminharSendExt").style.visibility='hidden';
		document.getElementById('txtAssunto').value='';
		document.getElementById('outboxmsg').style.display='block';
		document.getElementById('inboxmsg').style.display='none';
		document.getElementById('sendmsg').style.display='none';
		document.getElementById('composeOut').src='../../imgs/outbox_on.gif';
		document.getElementById('inboxOut').src='../../imgs/inbox_off.gif';
		document.getElementById('envoyerOut').src='../../imgs/envoyer_off.gif';
		document.getElementById('inbox_td').className='Celula_Menus'
		document.getElementById('compose_td').className='Celula_Menus_On'
		document.getElementById('envoyer_td').className='Celula_Menus'
	}
	else{
		document.getElementById("divEncaminhar").style.visibility='hidden';
		document.getElementById("divEncaminharExt").style.visibility='hidden';
		document.getElementById("divEncaminharSend").style.visibility='hidden';
		document.getElementById("divEncaminharSendExt").style.visibility='hidden';
		document.getElementById('inboxmsg').style.display='none';
		document.getElementById('sendmsg').style.display='block';
		document.getElementById('outboxmsg').style.display='none';
		document.getElementById('envoyer').src='../../imgs/envoyer_on.gif';
		document.getElementById('inbox').src='../../imgs/inbox_off.gif';
		document.getElementById('compose').src='../../imgs/outbox_off.gif';
		document.getElementById('inbox_td').className='Celula_Menus'
		document.getElementById('compose_td').className='Celula_Menus'
		document.getElementById('envoyer_td').className='Celula_Menus_On'
	}
}

