function ById(id){return document.getElementById(id);}
/* ====================================================== */
//Contador de caracteres nos campos de inserção de novo anuncio
function passFormFilter(vrPassRegiao,vrPassTipo,vrPassFase)
{
	document.frmBuscaImov.Regiao.value = vrPassRegiao;
	document.frmBuscaImov.Tipo.value = vrPassTipo;
	document.frmBuscaImov.Fase.value = vrPassFase;
	document.frmBuscaImov.submit();
}
/* ====================================================== */


/* ====================================================== */
//Contador de caracteres nos campos de inserção de novo anuncio
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
else
	cntfield.value = "  "+(maxlimit - field.value.length);
}
/* ====================================================== */


/* ====================================================== */
var cell
var colorCell

// funções pera hover das ceculas
function CellOver(cell,colorCell){
eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
function CellOut(cell,colorCell){
eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
/* ====================================================== */


/* ====================================================== */
var Layer
// funções pera exibição dos submenus
function showLayer(Layer){
eval("document.all."+Layer+".style.visibility='visible'")
}
function hideLayer(Layer){
eval("document.all."+Layer+".style.visibility='hidden'")
}
/* ====================================================== */

/* ====================================================== */
function deleteAnuncio(num){
if(confirm('Você tem certeza que deseja excluir este anúncio?')){
	eval("window.location.href='meus.anuncios.asp?deletar=ok&idAnuncio="+num+"';");
	}
else{
	return false;
	}
}
/* ====================================================== */



/*
Função de MouseOver e Pre-Load
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
function overImage(image){
eval("document.all."+image+".src='images/"+image+"_h.gif';");
}
function outImage(image){
eval("document.all."+image+".src='images/"+image+".gif';");
}

function preImages(images){
var pImages = images.split(",");
for(i=0;i<pImages.length;i++){
	image = new Image();
	eval("image.src = 'images/"+pImages[i]+"';");
	}
}
/*
Fim da Função de MouseOver e Pre-Load
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/


/*
Função para validação de CPF
*/
function isCPF(st) {
if (st == "")
return (false);
l = st.length;

//aleterado para se usuário não digitar os zeros na frente do CPF, completar sozinho
if ((l == 9) || (l == 8))
{
for (i = l ; i < 10; i++)
{
st = '0' + st
}
}
l = st.length;
st2 = "";
for (i = 0; i < l; i++) {
caracter = st.substring(i,i+1);
if ((caracter >= '0') && (caracter <= '9'));
st2 = st2 + caracter;
}
if ((st2.length > 11) || (st2.length < 10))
return (false);
if (st2.length==10)
st2 = '0' + st2;
digito1 = st2.substring(9,10);
digito2 = st2.substring(10,11);
digito1 = parseInt(digito1,10);
digito2 = parseInt(digito2,10);
sum = 0; mul = 10;
for (i = 0; i < 9 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10) * mul;
sum += tproduct;
mul--;
}
dig1 = ( sum % 11 );
if ( dig1==0 || dig1==1 )
dig1=0;
else
dig1 = 11 - dig1;
if (dig1!=digito1)
return (false);
sum = 0;
mul = 11;
for (i = 0; i < 10 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10)*mul;
sum += tproduct;
mul--;
}
dig2 = (sum % 11);
if ( dig2==0 || dig2==1 )
dig2=0;
else
dig2 = 11 - dig2;
if (dig2 != digito2)
return (false);
return (true);
}
/*
Fim da Função para validação do CPF
*/


/*
Função para validação de e-mail
*/
function eh_email(mail){
var ret = false;
if (typeof(mail) != "undefined"){
mail = mail.match(/(\w+)@(.+)\.(\w+)$/);
if (mail != null){
if ((mail[3].length==2) || (mail[3].length==3))
ret = true;
}
}
return ret;
}
/*
Fim da função de validação de e-mail
*/


/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Função para validação de preenchimento dos campos do formulário de cadastro
*/
function enviar(){

var NOME = document.all.nome.value;
var EMAIL = document.all.email.value;
var MENSAGEM = document.all.mensagem.value;


if(NOME == ""){
alert("E necessário o preenchimento de campo [ Nome ]. ");
document.all.nome.focus();
}else if(EMAIL == ""){
alert("E necessário o preenchimento de campo [ E-mail ]. ");
document.all.email.focus();
}else if(!eh_email(EMAIL)){
alert("E-mail inválido!");
document.all.email.focus();
}else if(MENSAGEM == ""){
alert("E necessário o preenchimento de campo [ Mensagem ]. ");
document.all.mensagem.focus();
}else{
//alert("Tudo Ok!")
document.contato.submit();
}
}

function check_cadastro(){

var PRIMEIRO_NOME = document.all.primeiro_nome.value;
var SEGUNDO_NOME = document.all.segundo_nome.value;
var EMAIL = document.all.email.value;

if(PRIMEIRO_NOME == ""){
alert("E necessário o preenchimento de campo [ Primeiro Nome ]. ");
document.all.PRIMEIRO_NOME.focus();
}if(SEGUNDO_NOME == ""){
alert("E necessário o preenchimento de campo [ Segundo Nome ]. ");
document.all.SEGUNDO_NOME.focus();
}else if(EMAIL == ""){
alert("E necessário o preenchimento de campo [ E-mail ]. ");
document.all.email.focus();
}else if(!eh_email(EMAIL)){
alert("E-mail inválido!");
document.all.email.focus();
}else{
alert("Tudo Ok!")
//document.enviar_cadastro.submit();
}
}

/*
Fim da função de validação de preenchimento dos campos do formulário de cadastro
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/

/*
Função Auto Completa Cep
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
function MascaraCep(objeto){
	if (objeto.value.indexOf(".") == -1 && objeto.value.length > 2){ objeto.value = ""; }
	if (objeto.value.length == 2){
		objeto.value += ".";
	}
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 6){ objeto.value = ""; }
	if (objeto.value.length == 6){
		objeto.value += "-";
	}
}
/*
Fim da Função Auto Completa Cep
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/


/*
Função Auto Completa Fone
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/

function MascaraTel(objeto){
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 2){ objeto.value = ""; }
	if (objeto.value.length == 2){
		objeto.value += "-";
	}
	if (objeto.value.indexOf(".") == -1 && objeto.value.length > 7){ objeto.value = ""; }
	if (objeto.value.length == 7){
		objeto.value += ".";
	}
}
/*
Fim da Função Auto Completa Cep
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/





//Checa se uma data é válida

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2078;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("O formato da data terá de ser: dd/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Entre com um mês válido!")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Entre com um dia válido!")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Entre com um ano de quatro dígitos válido entre  "+minYear+" e "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Entre com uma data válida!");
		return false
	}
return true
}


//Função Para Replace!
function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );

    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }

    return str;
}