function limitaCaracter(obj, max){
  var str = obj.value;

  if(str.length > max)
    obj.value = str.substring(0,str.length -1);
}

//retira espaços das extremidades da string
function trim(valor) {

	if ((valor == "")||(valor == undefined)) {
		return "";
	}
	var i = 0;

	if (valor.toString()) {
		valor = valor.toString();
	}

	while (valor.charAt(i) == " ") {
		i++;
		valor = valor.substr(i,valor.length - 1);
	}

	var i = valor.length - 1;

	while (valor.charAt(i) == " ") {
		valor = valor.substr(0,i);
		i--;
	}

	return valor;
}

//retira todos os espacos de uma string
function allTrim(s){

	var cRet = "";

	for ( var i=0;i<s.length;i++ ){
		if ( s.substring(i,i+1) != " ")
	   		cRet += s.substring(i,i+1);
	}
	return( cRet );
}


//valida email
function checkMail(mail)
{
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	
	if(typeof(mail) == "string"){
		if(er.test(mail))
		{
			return true;
		}
  }
	else
	{
		if(typeof(mail) == "object")
		{
    	if(er.test(mail.value))
			{
      	return true;
      }
    }
		else
		{
    	return false;
    }
  }
}

function pegarObj(idObjeto) {

	if (!idObjeto.tagName) {
	
		return document.getElementById(idObjeto);
	
	}
	else {
	
		return idObjeto;
	
	}

}