function open_center(url, name, params, Wwidth, Wheight) {	
	var Swidth 	= 0;
	var Sheight = 0;
	var Wleft 	= 0;
	var Wtop 	= 0;
	if(window.navigator.appName.toString().indexOf('Micro') == 0)	{
		Swidth = screen.Width;
		Sheight = screen.Height;
		Wleft = (parseInt(Swidth) / 2) - (Wwidth / 2);
		Wtop = (parseInt(Sheight) / 2) - (Wheight / 2);
	} else {
		Swidth = window.innerWidth;
		Sheight = window.innerHeight;
		Wleft = (parseInt(Swidth) / 2) - (Wwidth / 2);
		Wtop = (parseInt(Sheight) / 2) - (Wheight / 2) + 80;
	}
	var params = params+",left="+Wleft+",top="+ Wtop+",width="+Wwidth+",height="+Wheight;
	var popup = window.open(url, name, params);
	if(!window.focus())
	{
		popup.focus();
	}
}

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 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 validaformvisitas( 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.texto.value.length <= 5 ) erro = 'Preencha o campo Mensagem';
	if( erro )
	{
		alert( erro );
		return false;
	}
	return true;
}
