function validaLogin (frm) {
	if ((frm.login.value == "") || (frm.senha.value == "")) {
		alert("Digite o login e senha corretamente.");
		return false;
	}
	else {
		return true;
	}
}

function confirma(msg,url) {
	if (confirm(msg)) {
		document.location.href = url;
	}
}

function format(value,format)
{
	value = value.replace(/\D/g,"");
	var result="";
	
	if(format.length < value.length)
		return value;
	
	for(i=0,j=0;(i<format.length)&&(j<value.length);i++)
	{
		var ch = format.charAt(i) ;
		if(ch == '#')
		{
			result += value.charAt(j++);
			continue;
		}
		result += ch;
	}
	return result;
}

/*
	função para remover espaços no inicio e fim da string
*/
function trim(str){
	return str.replace(/^\s*|\s*$/g,"");
}

/*
	funcao de validação de email
*/
function validaEmail(email){
	//validar email(verificao de endereco eletrônico)
	parte1 = email.indexOf("@");
	parte2 = email.indexOf(".");
	parte3 = email.length;
	if (!(parte1 >= 3 && parte2 >= 3 && parte3 >= 9))
		return false;
	else
		return true;
}

/*
	funcao de validação de data no formato 99/99/9999
*/
function validaData(data){
	var reDate = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
	
	if (reDate.test(data))
		return true;
	else
		return false;
}
	
/*
	funcao de validação de hora no formato 99:99
*/
function validaHora(hora){
	var reTime = /^([0-1]\d|2[0-3]):[0-5]\d$/;
	
	if (reTime.test(hora))
		return true;
	else
		return false;
}


function popupDetalhe(theURL,winName,features, myWidth, myHeight, isCenter) {
    if(window.screen)if(isCenter)if(isCenter=="true"){
	   var myLeft = (screen.width-myWidth)/2;
	   var myTop = (screen.height-myHeight)/2;
	   features+=(features!='')?',':'';
	   features+=',left='+myLeft+',top='+myTop;
    }
    window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function Detalhes(codigo) {
	popupDetalhe('http://www.netimoveis.com/login/index_detalhes.asp?codigo='+codigo,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes','622','582','true');
}


// formata moeda
function FormataMoeda(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
}

}

function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
} 
