// Classificados Index
function classificadosIndex(getArea) {
if(document.getElementById) {
	var classificadosElement = document.getElementById(getArea);
	var classificadosArray = document.getElementById("classificadosIndexList").getElementsByTagName("div");

	for (var i=0; i<classificadosArray.length-1; i++) {
		if (classificadosArray[i].className = "classificadosIndexOn")
			classificadosArray[i].className = "classificadosIndexOff";
		}
			classificadosElement.className = "classificadosIndexOn";
		} else {
			classificadosElement.className = "classificadosIndexOff";
	}
}

// anúncio drop
function anuncioDrop(getObj) {
if(document.getElementById) {
	var el = document.getElementById(getObj);
	var ar = document.getElementById("classificadosIndexListBox").getElementsByTagName("DIV");
	if(el.style.display != "block") {
		for (var i=0; i<ar.length; i++) {
			if (ar[i].className=="anuncioDropInfo")
				ar[i].style.display = "none";
			}
				el.style.display = "block";
			}else{
				el.style.display = "none";
		}
	}
}

// conta caracteres
function charCount(counterID,counterValue) {
if (document.getElementById) {
	var exibeResultado = document.getElementById(counterID);
		exibeResultado.innerHTML = "<b>" +counterValue+"</b> caracteres disponíveis";
	}
}

// padroniza telefone
function phoneStd(getTelefone){
	getTelefone=getTelefone.replace(/\D/g,"")                 
//	getTelefone=getTelefone.replace(/^(\d\d)(\d)/g,"($1) $2") 
	getTelefone=getTelefone.replace(/^(\d\d)(\d)/g,"$1 $2") 
	getTelefone=getTelefone.replace(/(\d{4})(\d)/,"$1-$2")    
	return getTelefone
}

// switch identification
function IdSwitch(getTelefone,getEmail,getSite) {
var checkId = document.classificadosForm.checkID;
if(checkId.checked==true) {
	document.classificadosForm.anTelefone.value=phoneStd(getTelefone);
	document.classificadosForm.anEmail.value=getEmail;
	document.classificadosForm.anSite.value=getSite;
} else if (checkId.checked==false) {
	document.classificadosForm.anTelefone.value='';
	document.classificadosForm.anEmail.value='';
	document.classificadosForm.anSite.value='';
	}
}

// valida formulário
function classificadosSave() {
var mailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\!\ \\\/\'\"\[\]]/

var anTitulo = document.classificadosForm.anTitulo;
var anDescricao = document.classificadosForm.anDescricao;
var anTelefone = document.classificadosForm.anTelefone;
var anEmail = document.classificadosForm.anEmail;
var anSite = document.classificadosForm.anSite;

if (anTitulo.value=='') {
	document.getElementById("CLASSEB").style.display = 'block';
	document.getElementById("CLASSEBText").innerHTML = 'Por favor, preencha o campo título.';
	anTitulo.style.backgroundColor='#ffffcd';
	window.self.location = '#CLASSEB';
	anTitulo.focus();
	return false;
	} else {
		document.getElementById("CLASSEB").style.display = 'none';
		document.getElementById("CLASSEBText").innerHTML = '';
		anTitulo.style.backgroundColor='';
	}
if (anDescricao.value=='') {
	document.getElementById("CLASSEB").style.display = 'block';
	document.getElementById("CLASSEBText").innerHTML = 'Por favor, preencha o campo texto do anúncio.';
	anDescricao.style.backgroundColor='#ffffcd';
	window.self.location = '#CLASSEB';
	anDescricao.focus();
	return false;
	} else {
		document.getElementById("CLASSEB").style.display = 'none';
		document.getElementById("CLASSEBText").innerHTML = '';
		anDescricao.style.backgroundColor='';
	}
if (anTelefone.value=='' && anEmail.value=='' && anSite.value=='') {
	document.getElementById("CLASSEB").style.display = 'block';
	document.getElementById("CLASSEBText").innerHTML = 'Por favor, preencha ao menos um dos campos de contato.';
	window.self.location = '#CLASSEB';
	anTelefone.style.backgroundColor='#ffffcd';
	anEmail.style.backgroundColor='#ffffcd';
	anSite.style.backgroundColor='#ffffcd';
	anTelefone.focus();
	return false;
	} else {
		if (!(mailFilter.test(anEmail.value)) || anEmail.value.match(illegalChars)) {
			document.getElementById("CLASSEB").style.display = 'block';
			document.getElementById("CLASSEBText").innerHTML = 'Por favor, informe corretamente o seu email.';
			anEmail.style.backgroundColor='#ffffcd';
			anEmail.focus();
			return false;
			}
	document.getElementById("CLASSEB").style.display = 'none';
	document.getElementById("CLASSEBText").innerHTML = '';
	anTelefone.style.backgroundColor='';
	anEmail.style.backgroundColor='';
	anSite.style.backgroundColor='';
	}
	document.classificadosForm.submit();
}