function objnome( obj )
{
	var ret = '';
	if( typeof( obj ) != 'object' ) return;
	var v = obj.value.trim().toLowerCase();
	var v = v.replace( '/', '/ ' );
	var a = v.split(" ");
	var prep = ['de','do','dos','da','das','e','ou','del','ltda','ltda.','apto','apto.','ap','ap.','apt','apt','conj','conj.','cj','cj.','sala','sl.','andar'];
	var ignore = ['me','sa','s/a'];
	for( i=0; i<a.length; i++ ) ret += (i>0?' ':'') + ( prep.indexOf(a[i].toLowerCase()) == -1 ? ( ignore.indexOf(a[i].toLowerCase()) == -1 ? a[i].substr(0,1).toUpperCase() + a[i].substr(1) : a[i].toUpperCase() ) : a[i].toLowerCase() );
	
	obj.value = ret;
}

function objemail( obj )
{
	valor = obj.value.toLowerCase(); retorno = ''; x = 0; arr = 0;
	for( c = 0; c < valor.length; c++ )
	{
		letra = asc( valor.substr( c, 1 ) );
		if( x == 0 ) { if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) ) { retorno = retorno + valor.substr( c, 1 ); x = 1; } }
		else {
			if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) || ( letra == 46 ) || ( letra == 95 ) || ( letra == 64 ) )
			{
				if( ( letra == 64 ) && arr == 0 ) { retorno = retorno + valor.substr( c, 1 ); arr = 1; }
				else { if( !( letra == 46 && last == 46 ) && !( letra == 95 && last == 95 ) && !( letra == 46 && last == 64 ) ) { if( x >= 1 ) retorno = retorno + valor.substr( c, 1 ); x = x + 1; }}
			}
		}
		last = letra;
	}
	valor = retorno; retorno = ''; x = 0; pto = 0;
	for( c = ( valor.length - 1 ); c >= 0; c-- )
	{
		letra = asc( valor.substr( c, 1 ) );
		if( letra == 46 ) pto = 1;
		if( x == 0 ) { if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) ) { retorno = valor.substr( c, 1 ) + retorno; x = 1; } }
		else { if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) || ( letra == 46 ) || ( letra == 95 ) || ( letra == 64 ) ) { if( x >= 1 ) retorno = valor.substr( c, 1 ) + retorno; x = x + 1; } }
	}   	
	if( arr == 0 || pto == 0 ) retorno = '';
  	obj.value = retorno; return;
}

function chkemail( obj )
{
	valor = obj.value.toLowerCase();
	retorno = '';
	x = 0;
	arr = 0;
	for( c = 0; c < valor.length; c++ )
	{
		letra = asc( valor.substr( c, 1 ) );
		if( x == 0 )
		{
			if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) )
			{
				retorno = retorno + valor.substr( c, 1 );
				x = 1;
			}
		} else {
			if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) || ( letra == 46 ) || ( letra == 95 ) || ( letra == 64 ) )
			{
				if( ( letra == 64 ) && arr == 0 )
				{
					retorno = retorno + valor.substr( c, 1 );
					arr = 1;
				} else {
					if( !( letra == 46 && last == 46 ) && !( letra == 95 && last == 95 ) && !( letra == 46 && last == 64 ) )
					{
						if( x >= 1 ) retorno = retorno + valor.substr( c, 1 );
						x = x + 1;
					}
				}
			}
		}
		last = letra;
	}
	valor = retorno;
	retorno = '';  
	x = 0;
	pto = 0;
	for( c = ( valor.length - 1 ); c >= 0; c-- )
	{
		letra = asc( valor.substr( c, 1 ) );
		if( letra == 46 ) pto = 1;
		if( x == 0 )
		{
			if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) )
			{
				retorno = valor.substr( c, 1 ) + retorno;
				x = 1;
			}
		} else {
			if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) || ( letra == 46 ) || ( letra == 95 ) || ( letra == 64 ) )
			{
				if( x >= 1 ) retorno = valor.substr( c, 1 ) + retorno;
				x = x + 1;
			}
		}
	}
   	
	if( arr == 0 || pto == 0 ) retorno = '';
  	
	obj.value = retorno;
	return;

}

function sonumero( valor )
{
	retorno = '';
	for( c = 0; c < valor.length; c++ )
	{
		letra = asc( valor.substr( c, 1 ) );
		if( letra >= 48 && letra <= 57 ) retorno = retorno + valor.substr( c, 1 );
	}
	return retorno;
}

function asc(each_char)
{
	var n = 0;
	var char_str = ' !"#$%&' + "'" + '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
	for (i = 0; i < char_str.length; i++)
	{
		if (each_char == char_str.substring(i, i+1)) break;
	}
	return i + 32;
}

function textmax( obj, max )
{
	str = obj.value;
	if( str.length > max ) obj.value = str.substring( 0, max );
}

function validaformcontato( obj )
{
	var erro = '';
	if( !erro && obj.nome.value.length <= 3 ) erro = 'Preencha corretamente o campo Nome';
	if( !erro && !obj.email.value ) erro = 'Preencha corretamente o campo E-mail';
	if( !erro && obj.telefone.value.length <= 3 ) erro = 'Preencha corretamente o campo Telefone';
	if( !erro && obj.mensagem.value.length <= 5 ) erro = 'Preencha corretamente o campo Mensagem';
	if( erro )
	{
		alert( erro );
		return false;
	}
	return true;
}

function radiovalue( btn )
{
	var cnt = -1;
	for( var i = btn.length-1; i > -1; i-- )
		if( btn[i].checked ) { cnt = i; i = -1; }
	if ( cnt > -1 ) return btn[cnt].value;
	else return null;
}

function validaformorca( obj )
{
	var erro = '';
	if( !erro && obj.nome.value.length <= 3 ) erro = 'Preencha corretamente o campo Nome';
	if( !erro && obj.endereco.value.length <= 3 ) erro = 'Preencha corretamente o campo Endereço';
	if( !erro && obj.bairro.value.length <= 3 ) erro = 'Preencha corretamente o campo Bairro';
	if( !erro && obj.cidade.value.length <= 3 ) erro = 'Preencha corretamente o campo Cidade';
	if( !erro && obj.telefone.value.length <= 3 ) erro = 'Preencha corretamente o campo Telefone';
	if( !erro && !obj.email.value ) erro = 'Preencha corretamente o campo E-mail';
	if( !erro && obj.qtdpessoas.value.length <= 1 ) erro = 'Preencha corretamente o campo Quantidade de pessoas no evento';
	if( !erro && radiovalue( obj.festa ) == null ) erro = 'Selecione o Tipo de Festa desejado';
	if( erro )
	{
		alert( erro );
		return false;
	}
	return true;
}

function validaformindica( obj )
{
	var erro = '';
	if( !erro && obj.nome.value.length <= 3 ) erro = 'Preencha corretamente o campo Seu nome';
	if( !erro && !obj.email.value ) erro = 'Preencha corretamente o campo Seu e-mail';
	if( !erro && obj.nomeamigo.value.length <= 3 ) erro = 'Preencha corretamente o campo Nome do amigo';
	if( !erro && !obj.emailamigo.value ) erro = 'Preencha corretamente o campo E-mail do amigo:';
	if( !erro && obj.mensagem.value.length <= 5 ) erro = 'Preencha corretamente o campo Mensagem';if( erro )
	{
		alert( erro );
		return false;
	} else {
		setTimeout('document.getElementById("indicaform").reset()', 3000 );
		return true;
	}	
	return true;
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
Array.prototype.unescape = function() { for(var x=0,len=this.length;x<len;x++) { this[x] = unescape(this[x]); } return this };
Array.prototype.indexOf = function(v) { var r=-1;for(var x=0,len=this.length;x<len;x++) { if( r == -1 && this[x] == v ) r = x; }; return r; };
Array.prototype.inverte = function() { var a=new Array();for(var x=0,len=this.length;x<len;x++) a[x]=this[len-x-1]; return a; };
if ( typeof Array.prototype.push == "undefined" )
	Array.prototype.push = function() { for(var x=0,len=arguments.length;x<arguments.length;x++) this[this.length] = arguments[x]; }
