
var tabela_over_cor = '#F1F1F1';
// ----------------------------------------------------------------------------
function SNconfirm(txt){
	return typeof(suporteVBscript)=="undefined"?confirm(txt):VBconfirm(txt)==6
}
function closeMe() {
	setTimeout("self.close()",500); 
} 
function AlterarUser(user, id, session_id) {
	if (id == session_id) {
		alert("Você está logado com o usuário ["+user+"], a alteraração é feita pelo link 'Configurações' ao topo.");
		window.location = "default.asp?menu_cod=T1";
	} else {
		AbreJanela("config_user/config_listar_alterar.asp?id="+id, '683', '356', 'user_detalhes', 'no');
	}
}
function Tabela_Lista_Over(obj) {
	if (obj.className != "entrada-tr-over2-1" || obj.className != "entrada-tr-over2-2") {
		if (obj.className == "entrada-tr-1") {
			obj.className = "entrada-tr-over-1";
		} else if (obj.className == "entrada-tr-2") {
			obj.className = "entrada-tr-over-2";
		}
	}
}
function Tabela_Lista_Out(obj) {
	if (obj.className != "entrada-tr-over2-1" || obj.className != "entrada-tr-over2-2") {
		if (obj.className == "entrada-tr-over-1") {
			obj.className = "entrada-tr-1";
		} else if (obj.className == "entrada-tr-over-2") {
			obj.className = "entrada-tr-2";
		}
	}
}
function ExcluirSel_onClick(n) {
	if (n == 0) {
		alert('Nenhum registro selecionado para exclusão.');
	} else if (n == 1) {
		if (SNconfirm("Você deseja realmente excluir ["+n+"] registro?")) {
		window.history.go(0);
		}
	} else if (n > 1) {
		if (SNconfirm("Você deseja realmente excluir ["+n+"] registros?")) {
		window.history.go(0);
		}
	}
}
function OpcaoAtalho(menu, opcao, query, modelo) {
	if (modelo == "") {
		window.location = "opcao.asp?m="+menu+"&op="+opcao+""+query+"";
	} else if (modelo == "alert") {
		alert(""+opcao+"...");
		window.location = "opcao.asp?m="+menu+"&op="+opcao+""+query+"";
	} else if (modelo == "confirm") {
		if (SNconfirm("Você deseja realmente "+opcao+"?")) {
			window.location = "opcao.asp?m="+menu+"&op="+opcao+""+query+"";
		}
	}
}
function ExcluirReg(ref, tipo) {
	if (SNconfirm("Você deseja realmente excluir o imóvel ["+ref+"]?")) {
		window.location = "listar_excluir.asp?tipo="+tipo+"&ref="+ref+"";
	}
}
function ExcluirUser(user, id, session_id) {
	if (id == session_id) {
		alert("Você está logado com o usuário ["+user+"], exclusão bloqueada.");
		return false;
	} else {
		if (SNconfirm("Você deseja realmente excluir o usuário ["+user+"]?")) {
			window.location = "config_user/config_excluir.asp?id="+id;
		}
	}
}
function mudaTrColor(x){
actualColor = document.getElementById("tr_"+x)
actualCheck = document.getElementById(x)
regExp = /[0-9]{1,}/
idTr = actualColor.id
y = regExp.exec(idTr)
y -= 1
	if (actualColor.className == "cont-cont-tr-over" && actualCheck.checked == false) {
		actualColor.className = "cont-cont-tr"
	} else {
		actualColor.className = "cont-cont-tr-over"
	}
}

function SubmitCad2() {
	if (form_cadastro2.ref1.value == "") {
		alert('A referência é requerida, por favor preencha-a.');
		form_cadastro2.ref1.focus();
		form_cadastro2.ref2.value = "";
		return false;
    }
}
function SubmitInfo(v_ref) {
	if (form_alterar.ref.value == "") {
		alert('Referência é requerida na alteração de dados do imóvel, por favor preencha-a.');
		form_alterar.ref.focus();
		return false;
    } else if (v_ref != document.form_alterar.ref.value && document.form_alterar.ref.value != "") {
		if (SNconfirm("A referência do imóvel ["+v_ref+"] esta sendo alterada para ["+document.form_alterar.ref.value+"], isso fará com que as fotos desse imóvel deixem de aparecer corretamente no site, se realmente desejar fazer essa alteração, comunique imediatamente a Rolloutnet para que seja normalizada a exibição das fotos, deseja continuar?")) {
			return true;
		} else {
			form_alterar.ref.value = v_ref;
			form_alterar.ref.focus();
			return false;
		}
	}	
}
function SubmitConfigNew() {
	if (form_config.usuario.value == "") {
		alert('Seu login[usuário] é requerido na alteração de dados do usuário, por favor preencha-o.');
		form_config.usuario.focus();
		return false;
	} else if (form_config.email.value == "") {
		alert('Seu e-mail é requerido na alteração de dados do usuário, por favor preencha-o.');
		form_config.email.focus();
		return false;
	} else if (form_config.nome.value == "") {
		alert('Seu nome é requerido na alteração de dados do usuário, por favor preencha-o.');
		form_config.nome.focus();
		return false;
    } else if (form_config.email.value != "") {
		form_config.email.value = form_config.email.value.toLowerCase();
		if (form_config.email.value.indexOf('@') == -1) {
			alert('E-mail inválido, preencha corretamente (falta o @)');
			form_config.email.focus();
			return false;
		} else if (form_config.email.value.indexOf('.') == -1) {
			alert('E-mail inválido, preencha corretamente (falta o .)');
			form_config.email.focus();
			return false;
		}
	}
	if (document.form_config.senha_n.value.length < 4 && document.form_config.senha_n.value != "") {
		alert('Sua senha deve conter 4 ou mais caracteres.');
		document.form_config.senha_c.value = ""
		document.form_config.senha_n.select();
		return false;
	} else if (document.form_config.senha_n.value == "") {
		alert('Senha em branco por favor preencha.');
		document.form_config.senha_c.value = ""
		document.form_config.senha_n.focus();
		return false;
	} else if (document.form_config.senha_n.value != document.form_config.senha_c.value) {
		alert('As senhas novas não conferem, por favor redigite novamente.');
		document.form_config.senha_c.value = ""
		document.form_config.senha_n.select();
		return false;
	}
	
}
function EnviarSenha() {
	if (form_email_senha.email.value == "") {
		alert('Seu e-mail está em branco, por favor preencha-o.');
		form_email_senha.email.focus();
		return false;
    } else if (form_email_senha.email.value != "") {
		form_email_senha.email.value = form_email_senha.email.value.toLowerCase();
		if (form_email_senha.email.value.indexOf('@') == -1) {
			alert('E-mail inválido, preencha corretamente (falta o @)');
			form_email_senha.email.focus();
			return false;
		} else if (form_email_senha.email.value.indexOf('.') == -1) {
			alert('E-mail inválido, preencha corretamente (falta o .)');
			form_email_senha.email.focus();
			return false;
		}
	}
}
function SubmitConfig() {
	if (form_config.email.value == "") {
		alert('Seu e-mail é requerido na alteração de dados do usuário, por favor preencha-o.');
		form_config.email.focus();
		return false;
    } else if (form_config.email.value != "") {
		form_config.email.value = form_config.email.value.toLowerCase();
		if (form_config.email.value.indexOf('@') == -1) {
			alert('E-mail inválido, preencha corretamente (falta o @)');
			form_config.email.focus();
			return false;
		} else if (form_config.email.value.indexOf('.') == -1) {
			alert('E-mail inválido, preencha corretamente (falta o .)');
			form_config.email.focus();
			return false;
		}
	}
	if (document.form_config.senha_n.value.length < 4 && document.form_config.senha_n.value != "") {
		alert('Sua senha deve conter 4 ou mais caracteres.');
		document.form_config.senha_c.value = ""
		document.form_config.senha_n.select();
		return false;
	} else if (document.form_config.senha_n.value != document.form_config.senha_c.value) {
		alert('As senhas novas não conferem, por favor redigite novamente.');
		document.form_config.senha_c.value = ""
		document.form_config.senha_n.select();
		return false;
	}
	
}
function Deslogar() {
	if (SNconfirm("Você deseja realmente deslogar-se da administração?")) {
		window.location = 'deslogar.asp'
	}
}
function Senha_onFocus() {
	document.form_login.senha.select();
}
// ----------------------------------------------------------------------------
function BuscaRefFoto() {
	if (document.form_busca_ref.txt_ref.value == "") {
		alert('Campo em branco, por favor preencha-o.');
		document.form_busca_ref.txt_ref.focus();
		return false;
	} else if (document.form_busca_ref.txt_ref.value.length < 3) {
		alert('Escreva corretamente a referência!');
		document.form_busca_ref.txt_ref.select();
		return false;
	} else {
		window.location='default.asp?menu_cod=LF2&ref='+document.form_busca_ref.txt_ref.value;
		return false;
	}
}
function BuscaRef(v_menu) {
	if (document.form_busca_ref.txt_ref.value == "") {
		alert('Campo em branco, por favor preencha-o.');
		document.form_busca_ref.txt_ref.focus();
		return false;
	} else if (document.form_busca_ref.txt_ref.value.length < 3) {
		alert('Escreva corretamente a referência!');
		document.form_busca_ref.txt_ref.select();
		return false;
	} else {
		v_menu = v_menu.toUpperCase();
		window.location='default.asp?menu_cod='+v_menu+'&ref='+document.form_busca_ref.txt_ref.value;
		return false;
	}
}
function BuscaPaginaFoto() {
	window.location='default.asp?menu_cod=LF2&pagina='+document.form_busca_pg.txt_pagina.value;
	return false;
}
function BuscaPagina(v_tipo) {
	v_tipo = v_tipo.toLowerCase();
	window.location='default.asp?menu_cod=L&tipo='+v_tipo+'&pagina='+document.form_busca_pg.txt_pagina.value;
	return false;
}
function BuscaPagina_onBlur() {
	if (isNaN(document.form_busca_pg.txt_pagina.value)) {
		alert('Este campo só pode conter números.');
		document.form_busca_pg.txt_pagina.focus();
		document.form_busca_pg.txt_pagina.value = "";
		return false;
	}
}
function BuscaPagina_onFocus() {
	document.form_busca_pg.txt_pagina.select();
	return false;
}
// ----------------------------------------------------------------------------
function AbreJanelaFullScreen(url) {
	v_width = (screen.width)-10;
	v_height = (screen.height)-67;
	window.open(url, '','width='+v_width+',height='+v_height+',scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=no,left=0,top=0');
}
function AbreJanela(url, width, height, nome, scrollbars, modo) {
	var porcento = 0;
	v_width = screen.width;
	v_height = screen.height;
	var top; var left;
	if (v_width >= 1024 && v_height >= 768 && modo == "sim") {
		porcento = height*0.15;
		height = Number(height)+porcento;
	}
	top = ( (v_height/2) - (height/1.75) )
	left = ( (v_width/2) - (width/2) )
	window.open(url, nome,'width='+width+',height='+height+',scrollbars='+scrollbars+',toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}
function FecharJanela() {
	window.close();
}
function Voltar() {
	history.back();
}
function TabelaOver(src,color) {
	ExCL = src.style.backgroundColor;
	src.style.backgroundColor = color;
	src.style.cursor = 'pointer';
}
function TabelaOut(src) {
	src.style.backgroundColor = ExCL;
}
function TabelaOverLista(src, valor) {
	ExCL = "cont-cont-tr";
	src.className = "cont-cont-tr-over";
	if (valor == "sim") {
		src.style.cursor = 'pointer';
	} else if (valor == "nao") {
		src.style.cursor = 'default';
	}
}
function TabelaOutLista(scr) {
	scr.className = ExCL;
}
function TabelaSelectID(src) {
	document.src.className = "cont-cont-tr-over";
}
function TabelaDeselectID(src) {
	document.src.className = "cont-cont-tr";
}
function MostraFoto(pict) {
	foto.src=escape(pict);
}
function Imprimir(){
if (!window.print){
	alert("Use o Netscape ou Internet Explorer nas versões 4.0 ou superior!")
	return;
}
	window.print()
}
function ImprimirForm(v_id){
	document.v_id.print()
}
function Limpar() {
	if (SNconfirm("Você deseja limpar todos os campos do formulário?")) {
		return true;
	} else {
		return false;
	}
}
// ----------------------------------------------------------------------------
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// ----------------------------------------------------------------------------

function escolhe_nova_foto(){
	form_cadastro_enviar.foto.disabled = true;
	form_cadastro_enviar.foto.style.visibility = 'hidden';
	nota.style.visibility = 'hidden';
	form_cadastro_enviar.arquivo_foto.disabled = true;
	form_cadastro_enviar.arquivo_foto.style.visibility = 'hidden';
	form_cadastro_enviar.bt_salva.disabled = true;
	form_cadastro_enviar.bt_salva.style.visibility = 'hidden';
}

// ----------------------------------------------------------------------------


function isValidDate(campo) {

if (campo.value != ""){
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = campo.value.match(datePat); 
if (matchArray == null) {
alert("Data Inválida! (dd/mm/aaaa)")
campo.focus();
campo.value = "";
return false;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Mês Inexistente!");
campo.focus();
campo.value = "";
return false;
}
if (day < 1 || day > 31) {
alert("Dia Inexistente!");
campo.focus();
campo.value = "";
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Dia inválido! (Não existe dia 31)");
campo.focus();
campo.value = "";
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("Dia Inexistente! (Ano Bissesto)");
campo.focus();
campo.value = "";
return false;
   }
}
return true;  // date is valid
}
}

//--------------------------------------------

function somente_numeros(eventObj){

var keyCode;

// Verifica o Browser
	if (document.all){ 
		keyCode=eventObj.keyCode;
	}else{
		keyCode=eventObj.which;
	}
	
	//alert(keyCode);	
	
	if((keyCode >= 48 && keyCode <= 58) || keyCode == 44){ 
		return true;
	}else{
		return false;
	}
}
function Checa_Email(email_texto) {
	/*var varResult = email_texto.search(/\./i) - (email_texto.search(/@/i) + 1)*/
	if ((email_texto.search(/;/i) == -1) &&
	    (email_texto.search(/,/i) == -1) &&
	    (email_texto.indexOf("..") == -1) &&
	    (email_texto.indexOf(".@") == -1) &&
	    (email_texto.indexOf("@.") == -1) &&
	    (email_texto.search(/ /i) == -1) &&
	    (email_texto.search(/"/i) == -1) &&
	    (email_texto.search(/'/i) == -1) &&
	    (email_texto.indexOf("^") == -1) &&
	    (email_texto.search(/`/i) == -1) &&
	    (email_texto.search(/~/i) == -1) &&
	    (email_texto.search(/ç/i) == -1) &&
	    (email_texto.indexOf("#") == -1) &&
		(email_texto.indexOf("%") == -1) &&
		(email_texto.indexOf("+") == -1) &&
		(email_texto.indexOf("*") == -1) &&
		(email_texto.indexOf("@@") == -1) &&
		(email_texto.indexOf("/") == -1) &&
		(email_texto.indexOf("\\") == -1) &&
		(email_texto.indexOf(".") > -1) && /*Tem que ter pelo menos 1 ponto*/
	    (email_texto.length != 0) &&
	    (email_texto.search(/@/i) >= 1) &&
	    (email_texto.substr(0,1) != ".") && /*Não pode começar com ponto*/
	    (email_texto.substr(email_texto.length-1) != ".") && /*Não pode terminar com ponto*/
	    (email_texto.indexOf("hotmail.com.br") == -1) &&
	    (email_texto.indexOf("@aol.com.br") == -1)) {
		return true;
	} else if (email_texto.indexOf("hotmail.com.br") >= 0) {
		alert("Atenção: O E-mail HOTMAIL não termina com .BR\nEle será automaticamente corrigido.");
		document.form.tt_email.value = email_texto.replace("hotmail.com.br", "hotmail.com");
		document.form.tt_email.focus();
		return false;
	} else if (email_texto.indexOf("aol.com.br") >= 0) {
		alert("Atenção: O E-mail AOL não termina com .BR\nEle será automaticamente corrigido.");
		document.form.tt_email.value = email_texto.replace("aol.com.br", "aol.com");
		document.form.tt_email.focus();
		return false;
	} else if (email_texto.indexOf(" ") >= 0) {
		alert("Atenção: O E-mail não deve conter espaços em branco\nEle será automaticamente corrigido.");
		while(email_texto.indexOf(" ") >= 0) {
			email_texto = email_texto.replace(" ", "");
		}
		document.form.tt_email.value = email_texto;
		document.form.tt_email.focus();
		return false;
		} else {
		alert("Atenção: Endereço de E-mail está inválido! Por favor verifique-o.");
		document.form.tt_email.select();
		document.form.tt_email.focus();
		return false; 
    }
}
function Muda_Foco(caracteres,foco_atual,novo_foco) {
	if (foco_atual.value.length == caracteres) {
		novo_foco.focus();	
		novo_foco.select();
	}
}
function So_Numeros(obj, e) {
    if (obj.length ==0)
		obj.value=0;  
	var key;
	var keychar;
    if (window.event)
    	key = window.event.keyCode;
    else if (e)
    	key = e.which;
    else
    	return true;
	keychar = String.fromCharCode(key);
    if ((key==null) || (key==0) || (key==8) || 
		      (key==9)|| (key==13)|| (key==27) )
    return true;
    else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
	return false;
}
function Formata_Valor(objeto,teclapres,tammax,decimais) 
{
	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;
	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}
    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{
		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}
		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}

				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}
