// JavaScript Document
function abreenvio(n){
	jan=window.open("envio.asp?id="+n,"x","width=200, height=150")	
}

function abre(){
	jan=window.open("selectimagens.asp?popup=1","x","width=600, height=400, scrollbars=1")	
}

function tlimpa(n){
	if(n!=""){
		Str = '<Select name="'+n+'" id="'+n+'" class="inputs">' +
					'<option value="">[Selecione]</option>' + 
					'</Select>'
		document.getElementById(n).outerHTML=Str;		
	}
}

function ttbairro(n){
	if(n!=''){
		document.getElementById("ifrmfilter").innerHTML=('<iframe src="carrega.asp?c='+n+'" width="1" height="1" frameborder="0"></iframe>');
	}else{
		document.getElementById("ifrmfilter").innerHTML='';
		}
}
	
	
function ttoper(n){
	if(n!=''){
		document.getElementById("ifrmfilter").innerHTML=('<iframe src="carrega.asp?b='+n+'" width="1" height="1" frameborder="0"></iframe>');
	}else{
		document.getElementById("ifrmfilter").innerHTML='';
		}
}

function tttipo(n){
	if(n!=''){
		cc=document.getElementById('Cidade').options[document.getElementById('Cidade').selectedIndex].value;
		bb=(document.getElementById('Bairro').options[document.getElementById('Bairro').selectedIndex].value);
		document.getElementById("ifrmfilter").innerHTML=('<iframe src="carrega.asp?o='+n+'&bb='+bb+'&cc='+cc+'" width="1" height="1" frameborder="0"></iframe>');
	}else{
		document.getElementById("ifrmfilter").innerHTML='';
		}
}


function ttquartos(n){
	if(n!=''){
		bb=(document.getElementById('Bairro').options[document.getElementById('Bairro').selectedIndex].value);
		cc=(document.getElementById('Cidade').options[document.getElementById('Cidade').selectedIndex].value);
		oo=(document.getElementById('Transacao').options[document.getElementById('Transacao').selectedIndex].value);
		document.getElementById("ifrmfilter").innerHTML='<iframe src="carrega.asp?tp='+n+'&oo='+oo+'&bb='+bb+'&cc='+cc+'" width="1" height="1" frameborder="0"></iframe>';
	}else{
		document.getElementById("ifrmfilter").innerHTML='';
		}
}


// Limpa os <OPTION> do <SELECT> antes de inserir os novos <OPTION>
function limpaSelect(obj_select) {
  qtd = obj_select.length;
  for (j = qtd; j > 0 ; j--) {
    obj_select.remove(j);
  }
}

// Insere um novo <OPTION> no <SELECT>
function insereOption(obj_select, nome, valor) {
  oNewOption = new Option();
  oNewOption.value = valor;
  oNewOption.text = nome;
  //obj_select.add(oNewOption, 1);
	obj_select.options[obj_select.options.length] = new Option(nome,valor);
}

function mascara_data(data,objeto){ 
		var mydata = '';
		var bjeto=objeto;
		mydata = mydata + data;
		if (!e) var e = window.event
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
	
		if(code !=8 && ((code>95 && code<106)||(code>47 && code < 58))){
			if (mydata.length == 2){ 
					mydata = mydata + '/'; 
					document.getElementById(objeto).value = mydata; 
			} 
			if (mydata.length == 5){ 
					mydata = mydata + '/'; 
					document.getElementById(objeto).value = mydata; 
			} 
			if (mydata.length == 10){ 
					verifica_data(document.getElementById(objeto).id); 
			} 
		}
} 


function verifica_data (objeto) { 

	dia = (document.getElementById(objeto).value.substring(0,2)); 
	mes = (document.getElementById(objeto).value.substring(3,5)); 
	ano = (document.getElementById(objeto).value.substring(6,10)); 

	situacao = ""; 
	if(ano<2000) { datacomp=1900; }else{datacomp=0;}
	tdata=new Date(ano, (mes-1), dia)

	if( tdata.getDate()!=dia ||tdata.getMonth()!=(mes-1) || (tdata.getYear()+datacomp)!=ano) {	situacao = "falsa"; }
	
// verifica o dia valido para cada mes 
//	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
//			situacao = "falsa"; 
//	} 
// verifica se o mes e valido 
//	if (mes < 01 || mes > 12 ) { 
//			situacao = "falsa"; 
//	} 
// verifica se e ano bissexto 
//	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
//			situacao = "falsa"; 
//	} 

	if (document.getElementById(objeto).value == "") { situacao = "falsa"; } 

	if (situacao == "falsa") { 
		 //document.getElementById(objeto).value='';
		 //document.getElementById(objeto).className="red";
		 //document.getElementById(objeto).focus();
		 document.getElementById(objeto).select();
	} else {
		 document.getElementById(objeto).className="inputs";
	}
} 

function confirma(){
	if(confirm("Deseja realmente excluir esse item?")==false){
			return false;
	}	
}
function confirma2(){
	if(confirm("Deseja realmente excluir os itens selecionados?")==false){
			return false;
	}	
}
function troca(n){
		if(document.getElementById(n).className=="mostra"){
			document.getElementById(n).className="esconde";
		}else{
			document.getElementById(n).className="mostra";
		}
}
function alterastatus(n,p,j){
		document.getElementById("faction").action="analisecredito.asp?pp="+p+"&t="+n+"&id="+j;
		document.getElementById("faction").method="POST";
		document.getElementById("faction").submit();
}