// JavaScript Document
var ultimo = new Array(2);
ultimo[0] = -1;

var ultimoCBO = "";

function init()
{	initAbas();
	mudarMoeda();
	initFotos();
}

/*****************************************************************************************************
*****							   DETALHES E BUCA POR REFERÊNCIA								 *****
*****************************************************************************************************/
function janelaPopUp(pagina, ref)
{	var url = pagina + "?ref=" + ref;

	switch (pagina)
	{	case "interesse.aspx":
			h = "390";
			break;
		case "indique.aspx":
			h = "470";
			break;
	}
		
	if (ref != "")
		var det = window.open(url, "", "width=500, height=" + h + ", scrollbars=no");
	
	return false;
}

function cboCidade(obj)
{	if (ultimoCBO != "")
	{	var elem = ultimoCBO;
		elem.style.position = "absolute";
		elem.style.visibility = "hidden"; }
		
	if (obj.value == "") return;
	
	var elem = document.getElementById("div" + obj.value);
	elem.style.position = "";
	elem.style.visibility = "visible";
	ultimoCBO = elem;
}

function localizarReferencia(elem)
{	if (elem.value == "")
	{	alert("Digite a referência do imóvel.")
		elem.select();
		return false; }
		
	return true;
}


/*****************************************************************************************************
*****								  	 ÁREA ADMINISTRATIVA									 *****
*****************************************************************************************************/
function salvarTexto(obj)
{	obj.txttexto.value = document.getElementById('field_body').contentWindow.document.body.innerHTML;
	return true;
}

function editarTexto()
{	var rte = document.getElementById('field_body');
	var conteudo = document.getElementById('txttexto').value;
	
	rte.contentWindow.document.body.innerHTML = conteudo
}


/*****************************************************************************************************
*****								  		 	PROPRIETÁRIOS									 *****
*****************************************************************************************************/
function proprietarios()
{	var w = 700;
	var h = 600;
	var top = (screen.height - h) / 2;
	var left = (screen.width - w) / 2;
	
	var prop = window.open('proprietarios.aspx','','width=' + w + ', height=' + h +
						   ', scrollbars=yes, status=yes, top=' + top +', left=' + left);	}

function limpaProp(idProp)
{	with (document.Form1)
	{	hdpropid.value = idProp;
		txtnome.value = "";
		txtnacionalidade.value = "";
		txtcpf.value = "";
		txtrg.value = "";
		txtnascimento.value = "";
		cbocivil.options[0].selected = true;
		txtconjuge.value = "";
		txtendereco.value = "";
		txtcidade.value = "";
		cboestadoprop.options[24].selected = true;
		txtcep.value = "";
		txtfoneres.value = "";
		txtfonecom.value = "";
		txtfonecel.value = "";
		txtfonefax.value = "";
		txtemail.value = "";
	}
}

function muda(obj, lin)
{	var elem = document.getElementById("datagrid1_linha"+lin);

	if (ultimo[0] >= 0)
	{	document.getElementById("datagrid1_linha"+ultimo[0]).style.backgroundColor = ultimo[1];
		document.getElementById("datagrid1_linha"+ultimo[0]+"_chksele").checked = false;
	}

	if (obj.checked)
	{	ultimo[1] = elem.style.backgroundColor;
		elem.style.backgroundColor = "#e4e4e4";	}
	else
	{	elem.style.backgroundColor = ultimo[1];	}
		
	ultimo[0] = lin;
	
	var checks = document.getElementsByTagName("input")
	
	for (x=0; x < checks.length - 1; x++)
	{	try 
		{	if (checks[x].checked)
			{	document.getElementById("botok").disabled = false;
				return; }
			else
			{	document.getElementById("botok").disabled = true; }
		}
		catch (e) {}
	}
}


/*****************************************************************************************************
*****								  		 		ABAS										 *****
*****************************************************************************************************/
function seleAba(aba, sender)
{	var objs = document.getElementsByTagName("div");

	for (x=0; x <= objs.length; x++)
	{	try
		{	if (objs[x].lang == aba)
			{	with (objs[x].style)
				{	visibility = "visible";
					position = "static";
					overflow = "visible";
					height = ""; }
			}
			else if (objs[x].id == "aba")
			{	with (objs[x].style)
				{	visibility = "hidden";
					position = "absolute";
					height = "1px";
					overflow = "hidden"; }
			}
		}
		catch (e) {}
	}
	
	//Restaura o css dos botões
	var botoes = document.getElementsByTagName("a");
	
	for (x=0; x <= botoes.length; x++)
	{	try
		{	if (botoes[x].id == "botao")
				botoes[x].className = "menu";
		}
		catch (e) {}
	}
	
	sender.className = sender.className + "-sele"; 
	sender.blur();
	
	document.cookie = "aba=" + aba;
}

function zerarAbas()
{	document.cookie = "aba=1"; }

function initAbas()
{	var botoes = document.getElementsByTagName("a");
	var y = 0

	for (x=0; x <= botoes.length; x++)
	{	if (botoes[x].id == "botao")
		{	y++;
			
			if (y == verCookie("aba"))
			{	seleAba(verCookie("aba"), botoes[x]);	
				return; }
		}
	}
}


/*****************************************************************************************************
*****								  	 		AJAX											 *****
*****************************************************************************************************/
function favoritos(elem, foto)
{	var caminho =  elem.src.substr(0, elem.src.lastIndexOf("/") + 1);

	for (x = 0; x < 16; x++)
	{	var limpa = document.getElementById("datalistfotos_ctl" + ((x<10) ? '0' : '') + x +"_fav");

		try {
			limpa.src = caminho + "nk.gif";
		} catch (e) { }			
	}
	
	var ref = foto.substr(0, foto.indexOf("_")).replace("imovel", "");
	
	elem.src = caminho + "ok.gif";
	
	var resposta = func_ajax.atualiza(ref, foto).value;

	if (!resposta)
		alert("Houve um erro na atualização da referencia " + resposta + ".");
}

function apagarFoto(tabfoto, chk)
{	var tabelas = document.getElementsByTagName("table")

	for (x = 0; x <= tabelas.length - 1; x++)
	{	with (tabelas[x])
		{	if (id == "datalistfotos__ctl" + tabfoto + "_tabela" + tabfoto ||
				id == "datalistfotos__ctl" + tabfoto + "_tabfoto")
			{	if (chk.checked)
				{	className = className + "-sele"; }
				else
				{	className = "tabela-foto"; }
			}
		}
	}
}

function checarRef(obj)
{	var resposta = func_ajax.checarRef(obj.value).value;
	
	if (resposta)
	{	alert("Esta referência já existe. Por favor selecione outra.");
		obj.select(); }
}

function addFavoritos(imovelID)
{	var resposta = func_ajax.addFavoritos(imovelID).value;
	
	if (resposta)
		alert("Imóvel adicionado aos meus imóveis favoritos com sucesso!.");
	else
		alert("Imóvel já adicionado aos meus imóveis favoritos.");
}

function legendaFoto(idImovel, foto, legenda)
{	var resposta = func_ajax.alteraLegendaFotos(idImovel, foto, legenda); }

/*****************************************************************************************************
*****										   DATA E HORA										 *****
*****************************************************************************************************/
function data()
{	var mdata, mdiasemana, diasemana, ano, mmes, mes, dia;
	
	mdata = new Date();
	mdiasemana = mdata.getDay();
	mmes = mdata.getMonth();
	dia = mdata.getDate();
	ano = mdata.getFullYear();
	
	// Escolhendo dia semana
	switch (mdiasemana)
	{	case 0 :	diasemana = "Domingo";	break;
		case 1 :	diasemana = "Segunda";	break;
		case 2 :	diasemana = "Terça";	break;
		case 3 :	diasemana = "Quarta";	break;
		case 4 :	diasemana = "Quinta";	break;
		case 5 :	diasemana = "Sexta";	break;
		case 6 :	diasemana = "Sábado";	break;
	}

	// Escolhendo mês
	switch (mmes)
	{	case 0 :	mes = "Janeiro";	break;
		case 1 :	mes = "Fevereiro";	break;
		case 2 :	mes = "Março";		break;
		case 3 :	mes = "Abril";		break;
		case 4 :	mes = "Maio";		break;
		case 5 :	mes = "Junho";		break;
		case 6 :	mes = "Julho";		break;
		case 7 :	mes = "Agosto";		break;
		case 8 :	mes = "Setembro";	break;
		case 9 :	mes = "Outubro";	break;
		case 10 :	mes = "Novembro";	break;
		case 11 :	mes = "Dezembro";	break;
	}
	
	// Arrumando dia
	if (dia < 10)
		dia = "0" + dia;
	
	document.write(diasemana + ", " + dia + " de " + mes + " de " + ano);
}

function hora(objeto)
{	var hora, minuto, segundos, controle;

	mdata = new Date();
	hora = mdata.getHours();
	minuto = mdata.getMinutes();
	segundos = mdata.getSeconds();
 
	// Acertando hora
	if (hora < 10)
		{ hora = "0" + hora; }
 
	// Acertando minutos
	if (minuto < 10)
		{ minuto = "0" + minuto; }
  
	// Acertando segundos
	if (segundos < 10)
		{ segundos = "0" + segundos; }
  
	thetime = window.setTimeout("hora()", 1000);
	var elem = document.getElementById("hora")
	elem.innerHTML = "Hora certa &raquo; " + hora + ":" + minuto + ":" + segundos
}


/*****************************************************************************************************
*****											   MÁSCARAS										 *****
*****************************************************************************************************/
function mascaraReal(campo)
{	ie =  document.all ? true : false;

	if (ie)
		FormataValorIE(campo);
      else
		FormataValorNS(campo);
}

function FormataValorNS(campo)
{	campo.value = FiltraCampo(campo);
	
	vr = campo.value;
			
	if (vr.length == 0)
	{	campo.value = "0,00";	}
	
	while (vr.substr(0, 1) == 0)
	{	if (vr == "0,00")
			break;
		vr = vr.substr(1, campo.value.length - 1);	}
	
	campo.value = vr;
	tam = vr.length;

	if ( tam <= 2 ) 
		campo.value = tam == 1 ? "0,0" + vr.substr(tam - 1, 1) : "0," + vr.substr(tam - 2, 2); 
 	if ( (tam > 2) && (tam <= 5) ) 
 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; 
 	if ( (tam >= 6) && (tam <= 8) ) 
 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, 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 - 2, 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 - 2, 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 FormataValorIE(campo)
{	var tecla = window.event.keyCode;

	if (tecla < 48 || tecla > 57 && tecla < 96 || tecla > 105)
		if (tecla != 8 && tecla != 46)
			return false;
	vr = campo.value;
			
	if (vr == "")
	{	campo.value = "0,00";
		vr = campo.value;	}
	
	while (vr.substr(0, 1) == 0)
	{	if (vr == "0,00" || vr == "")
			break;

	vr = vr.substr(1, campo.value.length - 1);	}
	
	campo.value = vr;
	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 <= 2 )
	{	campo.value = tam == 1 ? "0,0" + vr.substr(tam - 1, 1) : "0," + vr.substr(tam - 2, 2); }
	if ( (tam > 2) && (tam <= 5) )
	{	campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) )
	{	campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, 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 - 2, 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 - 2, 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 );	}
}

//Formatação de M
function mascaraKm(campo)
{	var tecla = window.event.keyCode;

	if (tecla < 48 || tecla > 57 && tecla < 96 || tecla > 105)
		if (tecla != 8 && tecla != 46)
			return false;
	vr = campo.value;
			
	campo.value = vr;
	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 > 3) && (tam <= 6) )
	{	campo.value = vr.substr( 0, tam - 3 ) + '.' + vr.substr( tam - 3, tam ); }
	if ( (tam >= 7) && (tam <= 10) )
	{	campo.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ); }
}

function mascaraData(t)
{	var tecla = window.event.keyCode;

	if (tecla < 48 || tecla > 57 && tecla < 96 || tecla > 105)
			return false;
	
	tam = t.value.length;
	
	if (tecla != 8 && tecla != 46)
	{	if (tam == 2)
			t.value = t.value + '/';
		if (tam == 5 )
			t.value = t.value + '/';
	}
}

function mascaraFone(t)
{	var tecla = window.event.keyCode;

	if (tecla < 48 || tecla > 57 && tecla < 96 || tecla > 105)
			return false;
	
	tam = t.value.length;
	
	if (tecla != 8 && tecla != 46)
	{	if (tam == 1)
			t.value =  '(' + t.value;
		if (tam == 3 )
			t.value = t.value + ') ';
		if (tam == 9 )
			t.value = t.value + '-';
	}
}

function mascaraCEP(t)
{	var tecla = window.event.keyCode;

	if (tecla < 48 || (tecla > 57 && tecla < 96) || tecla > 105)
			return false;
			
	if (tecla != 8 && tecla != 46)
	{	if (t.value.length == 5)
			t.value = t.value + '-';
	}
}

function mascaraCPF(t)
{	var tecla = window.event.keyCode;

	if (tecla != 8 && tecla != 46)
	{	if (t.value.length == 3)
			t.value = t.value + '.';
		else if (t.value.length == 7)
			t.value = t.value + '.';
		else if (t.value.length == 11)
			t.value = t.value + '-';
	}
}


/*****************************************************************************************************
*****									VALIDAÇÕES E BLOQUEIOS									 *****
*****************************************************************************************************/
function checaCPF(source, arguments)
{	var elem = document.getElementById("txtcpf");
	
	if (validaCPF(elem.value))
	{	arguments.IsValid = true;	}
	else
	{	arguments.IsValid = false;	}
}

function validaCPF(CPF)
{	var charinvalidos = '-/,.() ';	

	for (var i=0; i<=6; i++)
	{	while (( cx = CPF.indexOf(charinvalidos.substring(i, i + 1) )) != -1)
		{	CPF = CPF.substring(0,cx) + CPF.substring(cx+1);	}
	}
	
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
	{	return false;	}		
		
	soma = 0;
	
	for (i=0; i < 9; i ++)
	{	soma += parseInt(CPF.charAt(i)) * (10 - i);	}
	
	resto = 11 - (soma % 11);
	
	if (resto == 10 || resto == 11)
	{	resto = 0;	}
	
	if (resto != parseInt(CPF.charAt(9)))
	{	return false;	}
	
	soma = 0;
	
	for (i = 0; i < 10; i ++)
	{	soma += parseInt(CPF.charAt(i)) * (11 - i);	}
	
	resto = 11 - (soma % 11);
	
	if (resto == 10 || resto == 11)
	{	resto = 0;	}
	
	if (resto != parseInt(CPF.charAt(10)))
	{	return false;	}
	
	return true;

 }

function soNumeros()
{	var tecla = window.event.keyCode;

	if (tecla < 48 || tecla > 57)
	{	window.event.returnValue = false;	}
}


/*****************************************************************************************************
*****											DIVERSOS										 *****
*****************************************************************************************************/
function verCookie(labelName)
{	var labelLen = labelName.length

	// read cookie property only once for speed
	var cookieData = document.cookie
	var cLen = cookieData.length
	var i = 0
	var cEnd
	
	while (i < cLen)
	{	var j = i + labelLen
	
		if (cookieData.substring(i,j) == labelName)
		{	cEnd = cookieData.indexOf(";",j)
			
			if (cEnd == -1)
			{	cEnd = cookieData.length	}
			
			return unescape(cookieData.substring(j + 1, cEnd))
		}
		
		i++
	}
	
	return ""
}

function preencheLocalidade(vetor, obj)
{	var elem = document.getElementById(obj.replace("$", "_"));
	var tag = null;
	var ultimaCidade = null;

	elem.options.add(new Option("Localidade", ""));
	elem.options.add(new Option("Indiferente", ""));

	for (x=0; x < vetor.length; x++)
	{	if (vetor[x][0] != ultimaCidade)
		{	/*if (elem.length > 0)
			{	tag = document.createElement("optgroup");
				tag.label = "";
				elem.appendChild(tag);
			}*/
			
			tag = document.createElement("optgroup");
			tag.label = vetor[x][0];
			elem.appendChild(tag);
			ultimaCidade = vetor[x][0];
		}

		var newOpt = document.createElement("option");
		newOpt.innerHTML = vetor[x][1];
		newOpt.title = vetor[x][1];
		newOpt.value = vetor[x][2];
		tag.appendChild(newOpt);
	}
	
	//elem.options[2].selected = true;
}

function detalheBairro(bairro)
{	var elem = document.getElementById(bairro);
	
	with (elem.style)
	{	if (position == "absolute" || position == "")
		{	position = "static";
			visibility = "visible"; }
		else
		{	position = "absolute";
			visibility = "hidden"; }
	}
}


/*****************************************************************************************************
*****									CALENDÁRIO E VALIDAÇÃO									 *****
*****************************************************************************************************/
function calendario(campo)
{	var w = 300;
	var h = 230;
	var left = (screen.width - w) / 2;
	var top = (screen.height - h) / 2;
	
	var cdr = window.open("", "", "width=" + w + ", height=" + h + ", scrollbars=no, top=" + top + ", left=" + left);
	cdr.document.location.href = "calendario.aspx?campo=" + campo + "&data=" + document.getElementById(campo).value;
}

function checarDatas()
{	var dataInicial = document.getElementById("txtdatainicial").value;
	var dataFinal = document.getElementById("txtdatafinal").value;
	
	if (dataInicial != "" && dataFinal != "")
	{	if (parseInt(dataFinal.split("/")[2].toString() +
				 dataFinal.split("/")[1].toString() +
				 dataFinal.split("/")[0].toString()) <
			parseInt(dataInicial.split("/")[2].toString() +
				 dataInicial.split("/")[1].toString() +
				 dataInicial.split("/")[0].toString()))
		{	alert("Atenção!\nA data inicial é maior que a data final, por favor insira um período válido.");
			
			with (document.Form1)
			{	txtdatainicial.value = "";
				txtdatafinal.value = ""; }
		}
		else
		{	document.Form1.botadicionardata.disabled = false; }
	}
}


/*****************************************************************************************************
*****									  PACOTE E VALIDAÇÃO									 *****
*****************************************************************************************************/
function pacote()
{	with (document.Form1)
	{	if (txtnomepacote.value != "" &&
			txtprecopacote.value != "" &&
			txtprecopacote.value != "0,00" &&
			txtdiapacote.value != "" &&
			txtpessoapacote.value != "")
		{	document.Form1.botadicionapacote.disabled = false; }
	}
}

function mudarMoeda()
{	var obj = document.getElementsByTagName("span");
	var moeda = "";
	var sender = document.getElementById("cbomoeda");

	switch (sender.value)
	{	case "real" :
			moeda = "R$";
			break;
		case "dolar" :
			moeda = "U$";
			break;
	}

	for (x = 0; x <= obj.length-1; x++)
	{	if (obj[x].id == "moeda")
		{	obj[x].innerText = moeda; }
	}
}


/*****************************************************************************************************
*****									  PACOTE E VALIDAÇÃO									 *****
*****************************************************************************************************/
function checarPlanta(botao)
{	var elem = document.getElementsByName("botadicionaplanta");

	if (document.getElementById("txtplantanome").value != "" && document.getElementById("txtplantamedida").value != "")
	{	elem[0].disabled = false; }
	else
	{	elem[0].disabled = true; }
}


/*****************************************************************************************************
*****									 		 FOTOS											 *****
*****************************************************************************************************/
function verFoto(foto)
{	var w = 500;
	var h = 375;
	var pic = window.open('','','width=' + w + ',height=' + h);
	var fotoStr = '';

	if (foto.src.indexOf("aspx") > 0)
	{	var inicio = foto.src.indexOf("=") + 1;
		var fim = foto.src.indexOf("&");
		foto = foto.src.substr(inicio, fim - inicio)
		fotoStr = '<img src="../thumb.aspx?foto=' + foto + '&w=' + w + '&h=' + h + '" border="0" alt="Fechar Janela">';
	}
	else
	{	fotoStr = '<img src="' + foto.src.replace('mini/','') + '" border="0" alt="Fechar Janela">';	}
	
	pic.document.write('<html><body topmargin=0 leftmargin=0>');
	pic.document.write('<a href="javascript:window.close()">');
	pic.document.write(fotoStr);
	pic.document.write('</a></body></html>');
}

function initFotos()
{	var checks = document.getElementsByTagName("input")

	for (x = 0; x <= checks.length - 1; x++)
	{	with (checks[x])
		{	//var tab = document.getElementById("datalistfotos__ctl" + x + "_tabela" + x)

			try
			{	if (checks[x].id.indexOf("chkfoto") >= 0)
				{	var y = checks[x].id.substring(checks[x].id.indexOf("ctl")+3, checks[x].id.lastIndexOf("_"))
					var tab = document.getElementById("datalistfotos__ctl" + y + "_tabfoto");

					if (checks[x].checked)
					{	tab.className = tab.className + "-sele"; }
					else
					{	tab.className = "tabela-foto"; }
				}
			}
			catch (e) { }
			
		}
	}
}


function validarExtensao(obj)
{	var retorno = 0;
	var arrImagens = new Array(1);
	arrImagens[0] = '.JPG'; //aki vc coloca as extensões que o arquivo pode aceitar
	//arrImagens[1] = '.GIF'; //aki vc coloca as extensões que o arquivo pode aceitar

	var extensao = null;
      
	if (obj.value == '')	//document.forms[0].elements[campo].value == '')
	{	return false; }
	else
	{	extensao = obj.value.substring(obj.value.lastIndexOf(".")).toUpperCase();
		//extensao = document.forms[0].elements[campo].value.substring(document.forms[0].elements[campo].value.lastIndexOf(".")).toUpperCase();
	
		for(i = 0; i < arrImagens.length; i++)
		{	if (extensao == arrImagens)
				retorno += 1;
		}     
                                 
  		if (retorno == 0)
		{	alert("Utilize imagens com extensão .JPG");
			obj.select();
			return false; }
		else
		{	return true; }
	}     
}

