function checaEmail(strEmail) {
   var strTemp=new String(strEmail);
   var arroba=strTemp.indexOf('@');
   var ponto=strTemp.lastIndexOf('.');
   var espaco=strTemp.lastIndexOf(' ');

   if (arroba<1)	// O '@' esta na posicao zero ou não existe
      return (false);

   strAux=strTemp.substring(arroba,strTemp.length);		   // A primeira ocorrência do '.' depois da arroba nao deve ser imediatamente posterior

   if (strAux.indexOf('.')+arroba<=(arroba+1))
      return (false);

   if (espaco!=-1)		   // Não deve existir espaço
      return (false);

   if (strTemp.length-1==ponto)		   // Não deve terminar um email com ponto
      return (false);
 
   return (true);
}

function showEspecialidade(oComboSel, oCombo) {
	var critTipoProfile
	critTipoProfile = oComboSel.options[oComboSel.selectedIndex].value;
	
	//var oCombo = document.frmBusca.especialidade;	
	oCombo.options.length = 1;

	for ( i = 0; i < oCombo.options.length; i++  ) {
		oCombo.options.remove(i--);
	}	

	var oOption

	oOption = document.createElement("OPTION");
	oCombo.options.add(oOption);
	oOption.innerText = 'Selecione a Especialidade';
	oOption.value = '';

	if ( oComboSel.selectedIndex != null ) {
		if ( oComboSel.options[oComboSel.selectedIndex].value  != "" ) {
			var counter = 0;
			for ( i = 0; i < aEsps.length; i++  ) {
				if (( critTipoProfile == aEsps[i][0] ) ) {
					counter = counter + 1;
					oOption = document.createElement("OPTION");
					oCombo.options.add(oOption);
					oOption.innerText = aEsps[i][2];
					oOption.value = aEsps[i][1];
				}
			}
			if (counter == 0) {
				oCombo.disabled = true;
				oOption.innerText = 'Não há especialidade disponível';
				oOption.value = '';
			}
			else
				oCombo.disabled = false;
		}
	}
}

function validaHomeCare(){
	if (document.homeCare.categoria.value == "" && document.homeCare.especialidade.value == "" && document.homeCare.bairro.value == "" && document.homeCare.nome_medico.value == document.homeCare.nome_medico.defaultValue) {
		alert('Por favor, escolha a Categoria, a Especialidade, o Bairro ou o Nome do Profissional que procura.');
		return false;
	}
	if (document.homeCare.nome_medico.value == document.homeCare.nome_medico.defaultValue)
		document.homeCare.nome_medico.value = "";
	return true;
}

function validaDrCall(tipo){
	if(tipo=="normal"){
	form = document.busca
	}else if(tipo=='drCall'){
	form = document.drCall
	}else{
	form = document.busca_avancada
	}
	
	if (form.categoria.value == "" || form.estado.value == "") {
		alert('Por favor, selecione o estado e a categoria que deseja pesquisar.');
		return false;
	}else{
		return true;	
	}

}

function validaBusca(form) {
	var msg ="";
	/*if (form.keyword.value == "" || form.keyword.value == " Nome do profissional" || form.keyword.value == "Nome do profissional") {
		msg = msg + 'Digite algo para buscar. \n';
	}
	*/
	if (form.keyword.value==" Nome do profissional")
	{
		form.keyword.value = "";
	}
	/*if (form.categoria.value == "") {
		msg = msg + 'Escolha uma categoria. \n';
	}
	*/
	
	if (form.estado.value == "") {
		msg = msg + 'Escolha um estado. \n';
	}
	
	if(msg==""){
	return true;		
	}else{
	alert(msg);
	return false;	
	}
	
	
}

function validaFiltro(form) {
	
	if (form.estado.value == "") {
		alert('Escolha um estado.');
		form.estado.focus();
		return false;
	}

	
	if (form.categoria.value == "" && (form.keyword.value == " Palavra chave" || form.keyword.value =="" || form.keyword.value.length<2)) {
		alert('Para buscar digite pelo menos duas letras no campo "Palavra chave".');
		form.keyword.focus();
		return false;
	}
	
	/*if (form.especialidade.value == "") {
		alert('Por favor, escolha uma especialidade.');
		return false;
	}
	*/
	return true;
}

function viewDrcall(id, urlDr) {
	if (urlDr != '') {
		self.location = urlDr;
	}
	else {
		self.location = "drcall_view.php?especialidade=" + document.forms["drCallList"].especialidade.value + "&id=" + id;
	}
}

function nomeProfissional(obj) {
	if (obj.defaultValue == obj.value)
		obj.value = '';
	else if (obj.value == '')
		obj.value = obj.defaultValue;
}

function validaCadastro(){
	if (document.cadastro.nome.value == "") {
		alert('Por favor, preencha o campo Nome.');
		document.cadastro.nome.focus();
		return false;
	}
	if (document.cadastro.email.value == "") {
		alert('Por favor, preencha o campo E-mail.');
		document.cadastro.email.focus();
		return false;
	}		
	if (document.cadastro.email.value != "" && !checaEmail(document.cadastro.email.value)) {
		alert('E-mail inválido!');
		document.cadastro.email.focus();
		return false;		
	}
	if (!document.cadastro.aceito.checked) {
		alert('É necessário ler e aceitar o contrato!');
		return false;		
	}
	return true;
}

function validaDuvidas(){
	if (document.duvidas.nome.value == "") {
		alert('Por favor, preencha o campo Nome.');
		document.duvidas.nome.focus();
		return false;
	}
	if (document.duvidas.email.value == "") {
		alert('Por favor, preencha o campo E-mail.');
		document.duvidas.email.focus();
		return false;
	}		
	if (document.duvidas.email.value != "" && !checaEmail(document.duvidas.email.value)) {
		alert('E-mail inválido!');
		document.duvidas.email.focus();
		return false;		
	}
	if (document.duvidas.duvida.value == "") {
		alert('Por favor, preencha o campo Dúvida.');
		document.duvidas.duvida.focus();
		return false;
	}
	return true;
}

function validaMural(){
	if (document.mural.nome.value == "") {
		alert('Por favor, preencha o campo Nome.');
		document.mural.nome.focus();
		return false;
	}
	if (document.mural.email.value == "") {
		alert('Por favor, preencha o campo E-mail.');
		document.mural.email.focus();
		return false;
	}		
	if (document.mural.email.value != "" && !checaEmail(document.mural.email.value)) {
		alert('E-mail inválido!');
		document.mural.email.focus();
		return false;		
	}
	if (document.mural.titulo.value == "") {
		alert('Por favor, preencha o campo Título.');
		document.mural.titulo.focus();
		return false;
	}
	if (document.mural.mensagem.value == "") {
		alert('Por favor, preencha o campo Mensagem.');
		document.mural.mensagem.focus();
		return false;
	}
	return true;
}

function popminuto(url,a,l) { 
a = a;
l = l;
popupWin = window.open(url,'new_page','width=' + l + ',height=' + a + ',scrollbars=no')}

function showPhoto(descricao, foto) {
	imgObj = parent.window.document.getElementById("foto");
	txtObj = parent.window.document.getElementById("foto_txt");

	imgObj.src = "img/carregando.gif";
	imgObj.src = foto;
	imgObj.style.display = "block";
	txtObj.innerHTML = "";
	txtObj.innerHTML += descricao;
	var strLocation = new String(top.location);
	top.location = strLocation.replace('#top','') + "#top";
}

var auxObj = "";
function listPhotos(areaid, id) {
	var objIframe, objName;
	objName = "photo"+id;
	objIframe = document.getElementById(objName);
	objIframe.src = "projetos_listPhotos.php?areaid="+areaid+"&id="+id;
	if (auxObj != "")
		auxObj.style.display = "none";
	objIframe.style.display = "block";
	auxObj = objIframe;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}




/* Preload*/
function imgPreload() {
	if(!document.images) return;
    if (typeof(document.objImg) == 'undefined') document.objImg = new Object();
    document.objImg.loadedImages = new Array();
    for(i = 0; i < arguments.length; i++)
    {
		document.objImg.loadedImages[i] = new Image();
		document.objImg.loadedImages[i].src = arguments[i];
    }
}

function imgSwap(strImg, strPath){
  var objStr,obj;
  /*
    troca o caminho da imagem
    chamada:
    <a href="#" onmouseover="imgSwap('nome_da_imagem', 'caminho_da_imagem_on');" onmouseout="imgSwap('nome_da_imagem', 'caminho_da_imagem_off');"><img name="nome_da_imagem"...
  */
	if(!document.images) return;
    if (typeof(strImg) == 'string') {
      objStr = 'document.' + strImg;
      obj = eval(objStr);
      obj.src = strPath;
    } else if ((typeof(strImg) == 'object') && strImg && strImg.src) {
      strImg.src = strPath;
    }
}


/* DHTML do menu */
var timerID
var tempo = 1 		// tempo, em segundos, q o menu deve permanecer aberto depois do MouseOut
var numMenus = 0 	// numero de menus existentes no mundo (todos devem se chamar menuX)
var lastmenu = "menu0";

function liga(param) { //acende o menu q eh mandado
	if (document.layers) { // netscape
		objeto = eval("document.layers."+param)
		objeto.display = "block";
		lastmenu = param;
	}
	else { // todos os outros
		objeto = eval("document.all."+param);
		objeto.style.display = "block";
		lastmenu = param;
	}
}

function desliga(param) { // apaga o menu q eh mandado
	if (document.layers) {
		objeto = eval("document.layers."+param);
		timerID = setTimeout("objeto.display = 'none'", tempo*1000);
	}
	else {
		objeto = eval("document.all."+param);
		timerID = setTimeout("objeto.style.display= 'none'", tempo*1000);
	}

}

function limpatempo() {
	if (timerID>0) clearTimeout(timerID);
}

function desligatudo() {
	clearTimeout(timerID);
	for (i=0; i<=numMenus; i++) {
		param = "menu"+i
		if (document.layers) {
			objeto = eval("document.layers."+param);
			objeto.display = 'none';
		}
		else {
			objeto = eval("document.all."+param);
			objeto.style.display = 'none';
		}
	}
}

function nivel0(param) {desligatudo();liga(param);}
function nivel1(param) {limpatempo(); liga(param);}

function openPopup(url,n,w,h,other,c, r){
	l=18;t=18
	if(c){l=(screen.availWidth-w)/2;t=(screen.availHeight-h)/2}
	url=url.replace(/[ ]/g,'%20')
	popup=window.open(url,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=1'+((other)?','+other:''))
	other=other||''
	if(is.ie&&other.indexOf('fullscreen')!=-1){popup.moveTo(0,0);popup.resizeTo(screen.width,screen.height)}
	popup.focus()
	if (r) return popup;
}

function winpop(url,w,h,s) {
	window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' +s+ ',resizable=no,menubar=no,left=20,top=20,width='+w+',height='+h);
}

var lastMenuName;
function showMenu (objRel, name) {
	if (lastMenuName) {
		document.getElementById(lastMenuName).style.display = "none";
	}
	document.forms['drCall'].categoria.style.visibility = "hidden";
	document.forms['drCall'].especialidade.style.visibility = "hidden";
	document.forms['drCall'].convenio.style.visibility = "hidden";
	document.forms['drCall'].bairro.style.visibility = "hidden";

	if (document.forms['homeCare']) {
		document.forms['homeCare'].especialidade.style.visibility = "hidden";
		document.forms['homeCare'].bairro.style.visibility = "hidden";
	}

	document.getElementById("transp").style.display = "block";
	document.getElementById(name).style.display = "block";
	document.getElementById(name).style.pixelLeft = (objRel.offsetLeft + ( (document.body.clientWidth-740)/2 ));
	document.getElementById(name).style.pixelTop = (objRel.offsetTop + 179);
	lastMenuName = name;
}

function hideMenu() {
	document.forms['drCall'].categoria.style.visibility = "visible";
	document.forms['drCall'].especialidade.style.visibility = "visible";
	document.forms['drCall'].convenio.style.visibility = "visible";
	document.forms['drCall'].bairro.style.visibility = "visible";

	if (document.forms['homeCare']) {
		document.forms['homeCare'].especialidade.style.visibility = "visible";
		document.forms['homeCare'].bairro.style.visibility = "visible";
	}

	document.getElementById("transp").style.display = "none";
	document.getElementById(lastMenuName).style.display = "none";
}

function validaCadastroNew(){
	var strMsg =""
	var boolErro=false
	if(document.cadastro.step.value==2 || document.cadastro.step.value==3){
			total = document.cadastro.elements('cep[]').length;
			if(total!=undefined){
			for(x=0;x<total;x++){
				if(document.cadastro("cep[]")[x].value==""){
					strMsg = strMsg + "- Endereço "+parseInt(x+1) +": Cep\n";
					boolError = true;
				}
				
				if(document.cadastro("endereco[]")[x].value==""){
					strMsg = strMsg + "- Endereço "+parseInt(x+1) +": Endereço\n";
					boolError = true;
				}
				if(document.cadastro("numero[]")[x].value==""){
					strMsg = strMsg + "- Endereço "+parseInt(x+1) +": Número\n";
					boolError = true;
				}
				if(document.cadastro("bairro[]")[x].value==""){
					strMsg = strMsg + "- Endereço "+parseInt(x+1) +": Bairro\n";
					boolError = true;
				}
				if(document.cadastro("cidade[]")[x].value==""){
					strMsg = strMsg + "- Endereço "+parseInt(x+1) +": Cidade\n";
					boolError = true;
				}
				if(document.cadastro("estado[]")[x].value==""){
					strMsg = strMsg + "- Endereço "+parseInt(x+1) +": Estado\n";
					boolError = true;
				}
				if(document.cadastro("telefone1[]")[x].value==""){
					strMsg = strMsg + "- Endereço "+parseInt(x+1) +": Telefone\n";
					boolError = true;
				}
				strMsg = strMsg + "\n";
			}
			
			}
			else{
				
				if(document.cadastro("cep[]").value==""){
					strMsg = strMsg + "- Cep\n";
					boolError = true;
				}
				
				if(document.cadastro("endereco[]").value==""){
					strMsg = strMsg + "- Endereço\n";
					boolError = true;
				}
				if(document.cadastro("numero[]").value==""){
					strMsg = strMsg + "- Número\n";
					boolError = true;
				}
				if(document.cadastro("bairro[]").value==""){
					strMsg = strMsg + "- Bairro\n";
					boolError = true;
				}
				if(document.cadastro("cidade[]").value==""){
					strMsg = strMsg + "- Cidade\n";
					boolError = true;
				}
				if(document.cadastro("estado[]").value==""){
					strMsg = strMsg + "- Estado\n";
					boolError = true;
				}
				if(document.cadastro("telefone1[]").value==""){
					strMsg = strMsg + "- Telefone\n";
					boolError = true;
				}
			
			}
			
			strMsg = strMsg + "\n";
	}
	
	if(document.cadastro.step.value==1){
		if(document.cadastro.nome_assinante.value==""){
			strMsg = strMsg + "- Nome\n";
			boolError = true;
		}
		if(document.cadastro.email.value==""){
			strMsg = strMsg + "- Email\n";
			boolError = true;
		}else if (document.cadastro.email.value.indexOf("@")==-1||document.cadastro.email.value.indexOf(".")==-1){
			strMsg = strMsg + "- Informe um endereço de Email válido\n";
			boolError = true;
		}else if (document.cadastro.existeEmail.value=="true"){
			strMsg = strMsg + "- O endereço de email informado já foi cadastrado no site, se você esqueceu sua senha entre em contato pelo email atendimento@almanaquesaude.com.br. \n";
			boolError = true;
		}
		
		
		if(document.cadastro.planoId.value == ""){
			strMsg = strMsg + "- Escolha um plano\n";
			boolError = true;
		}
		if(document.cadastro.aceito2.checked==false){
			strMsg = strMsg + "- Leia e aceite o contrato.\n";
			boolError = true;
		}
		
	}
	
	if(document.cadastro.step.value==2 ){
		if(parseInt(document.cadastro.planoE.value)>1){
		
			
		}else{
			if(document.cadastro.nome.value==""){
				strMsg = strMsg + "- Nome\n";
				boolError = true;
			}else if(document.cadastro.email.value==""){
				strMsg = strMsg + "- Email\n";
				boolError = true;
			}
			if (document.cadastro.email.value.indexOf("@")==-1||document.cadastro.email.value.indexOf(".")==-1){
				strMsg = strMsg + "- Informe um endereço de Email válido\n";
				boolError = true;
			}
			
			if(document.cadastro.nascimento.value==""){
				strMsg = strMsg + "- Data de nascimento\n";
				boolError = true;
			}
		}
	}
	
	
	if(document.cadastro.step.value==3){
		
		if(parseInt(document.cadastro.planoE.value)==2){
		
			var marcado=""
			total=parseInt(document.cadastro.totCategorias.value)
			for(x=0;x<total;x++){
				if(document.getElementById(eval("'cat"+x+"'")).checked){
						marcado=true;
						break;
					}
				
			}
			
			if(marcado!=true){
				strMsg = strMsg + "- Você precisa escolher a(s) área(s) em que atúa.\n";
				boolError = true;
			}

			if(document.cadastro.url.value==""){
				strMsg = strMsg + "- Informe o endereço do seu site\n";
				boolError = true;
			}
			
			if(document.cadastro.elements['cep[]'].value=="undefined"){
			total = document.cadastro.elements['cep[]'].length;
			}else{
			total = 0;
			}
			
		}else if(parseInt(document.cadastro.planoE.value)==3){
			
			if(document.cadastro.formacao.value==""){
				strMsg = strMsg + "- Formação\n";
				boolError = true;
			}
			if(document.cadastro.universidade.value==""){
				strMsg = strMsg + "- Universidade\n";
				boolError = true;
			}
			
			var marcado=""
			total=parseInt(document.cadastro.totCategorias.value)
			for(x=0;x<total;x++){
				if(document.getElementById(eval("'cat"+x+"'")).checked){
						marcado=true;
						break;
					}
				
			}
			
			if(marcado!=true){
				strMsg = strMsg + "- Você precisa escolher a(s) área(s) em que atúa.\n";
				boolError = true;
			}

			if(document.cadastro.registro.value==""){
				strMsg = strMsg + "- Registro Profissional\n";
				boolError = true;
			}
			if(document.cadastro.formatura.value==""){
				strMsg = strMsg + "- Formatura\n";
				boolError = true;
			}
			if(document.cadastro.elements['cep[]'].value=="undefined"){
			total = document.cadastro.elements['cep[]'].length;
			}else{
			total = 0;
			}
			
		}else{
			var marcado=""
			total=parseInt(document.cadastro.totCategorias.value)
			for(x=0;x<total;x++){
				if(document.getElementById(eval("'cat"+x+"'")).checked){
						marcado=true;
						break;
					}
				
			}
			
			if(marcado!=true){
				strMsg = strMsg + "- Você precisa escolher a(s) área(s) em que atúa.\n";
				boolError = true;
			}
			
			
			
		}
	}
	
	if (boolError) {
		alert("Os seguintes campos são obrigatórios:\n\n" + strMsg);
		boolError = false;
		return false;
	}
	else {

		return true;
	}


}



// a funcao abaixo pega a versao mais nova do xmlhttp do ie.
function createXMLHTTP() 
{
try 
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} 
catch(e) 
{
try 
{
ajax = new ActiveXObject("Msxml2.XMLHTTP");
alert(ajax);
}
catch(ex) 
{
try 
{
ajax = new XMLHttpRequest();
}
catch(exc) 
{
alert("Esse browser não tem recursos para uso do Ajax");
ajax = null;
}
}
return ajax;
}

var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"];
for (var i=0; i < arrSignatures.length; i++) {
try {
var oRequest = new ActiveXObject(arrSignatures[i]);
return oRequest;
} catch (oError) {
}
}
throw new Error("MSXML is not installed on your system.");
}

function completaEndereco(cep,camada,n)
{

if(cep.length>=9){
var oHTTPRequest = createXMLHTTP(); 
oHTTPRequest.open("post", "admin/getCep.php", true);
oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oHTTPRequest.onreadystatechange=function() {
if (oHTTPRequest.readyState==4){

eval("document.all." + camada + ".innerHTML = oHTTPRequest.responseText;");
}
}
oHTTPRequest.send("cep=" + cep+"&camada="+n);
}

}

function mascaraData(campoData){
	if(campoData.value!=""){
		if(campoData.value.length==2){
			campoData.value = campoData.value + "/";
			return true;
		}
		if(campoData.value.length==5){
			campoData.value = campoData.value + "/";
			return true;
		}
	}
}

function mascaraTelefone(campoTel){
	if(campoTel.value!=""){
		if(campoTel.value.length==1){
			campoTel.value = "("+campoTel.value  ;
			return true;
		}
		if(campoTel.value.length==3){
			campoTel.value = campoTel.value + ") ";
			return true;
		}

		if(campoTel.value.length==9){
			campoTel.value = campoTel.value + "-";
			return true;
		}
	}else{
		campoTel.value = campoTel.value + "(";
	}
}

function contaPalavras(campo,maxPalavras,msg){ // Campo para contagem, max de palavras, div para mostrar quanto falta
if(event.keyCode== 8 || event.keyCode==46){
 document.getElementById(msg).innerHTML=parseInt(maxPalavras-campo.value.length)
 event.returnValue=true;	
}else if(campo.value.length<=maxPalavras){
		document.getElementById(msg).innerHTML="Restam: " + parseInt(maxPalavras-campo.value.length)+ " caracteres."
		
		return true;
	}else{
		 event.keyCode=0; 
		 event.returnValue=false;
	}
}



function uploadFoto(num){
	document.getElementById('addFoto').style.display="block";
	document.getElementById('iframeFoto').src="add_foto.php?foton="+num;
}

function fechaUploadFoto(num,caminhoFoto){
	parent.window.document.getElementById('foto'+num).src=caminhoFoto;
}






// Verifica se o email existe
function statusEmail(valor){
	
	if(valor!=""){
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", "admin/getStatusEmail.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					eval("document.cadastro.existeEmail.value="+oHTTPRequest.responseText);
				}
			}
		oHTTPRequest.send("email=" + valor);
	}
}

function buscaAvancada(){
	if(document.getElementById("buscaAvancada").style.display=="none" || document.getElementById("buscaAvancada").style.display==""){
	document.getElementById("buscaAvancada").style.display="block";
	document.getElementById("sombra").style.display="block";
	}else{
	document.getElementById("buscaAvancada").style.display="none";
	document.getElementById("sombra").style.display="none";
	}
}

function getBairrosBusca(valor){
	if(valor!=""){
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", "admin/getBairrosBusca.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById('buscaBairro').innerHTML=oHTTPRequest.responseText;
				}
			}
		oHTTPRequest.send("seq=" + valor);
	}
}

function getCidadesBusca(valor){
	if(valor!=""){
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", "admin/getCidadesBusca.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById('buscaCidade').innerHTML=oHTTPRequest.responseText;
					document.getElementById('buscaBairro').innerHTML="<select name='bairro' id='bairro' style='width:165px'><option value=''>Todos</option></select>";
				}
			}
		oHTTPRequest.send("uf=" + valor);
	}
}


function getCatergoriasBusca(valor){
	if(valor!=""){
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", "admin/getEspecialidadeBusca.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById('buscaEspecialidades').innerHTML=oHTTPRequest.responseText;
				}
			}
		oHTTPRequest.send("id=" + escape(valor));
	}
}

function removerFoto(n){
	document.upload.apagarFoto.value=n;
	document.upload.submit();
}

function fecharI(){
	parent.document.getElementById('addFoto').style.display="none";
}

function insertField(strPlace, strField) {
	document.getElementById(strPlace).insertAdjacentHTML('beforeEnd', strField);
	//alert(document.cadastro.elements('cep[]').length);
}


function removePhotoFields(camada,numero) {
	document.getElementById("pcep"+numero).value="";
	document.getElementById("pbairro"+numero).value="";
	document.getElementById("pcidade"+numero).value="";
	document.getElementById("pnumero"+numero).value="";
	document.getElementById("pestado"+numero).value="";
	document.getElementById("pcomplemento"+numero).value="";
	document.getElementById("pendereco"+numero).value="";
	document.getElementById("ptelefone1"+numero).value="";
	document.getElementById("ptelefone2"+numero).value="";
	document.getElementById("pfax"+numero).value="";
	
	document.getElementById(camada).style.display="none";
	if(n<=4){document.getElementById('adicionarAddress').style.display='block'}else{document.getElementById('adicionarAddress').style.display='none'}

	n--;
	
}

function mudaSeta(obj,img){
	if(img==1){
		document.getElementById(obj).src="images/seta_select2.gif";
		document.getElementById("select"+obj).style.display='block';
		}else{
		document.getElementById(obj).src="images/seta_select.gif";
		document.getElementById("select"+obj).style.display='none';
	}
}

function filtroBusca(){
	if(document.getElementById('filtroBusca').style.display=="block"){
	document.getElementById('filtroBusca').style.display='none';
	}
	else{
	document.getElementById('filtroBusca').style.display='block';	
	}
}

function paginacao(pg){
	document.form1.pagina.value=pg;
	document.form1.submit();
}

function verificaNickname(campo){
	if(campo.value!=""){
	document.getElementById("btVerificar").style.display="block";
	//document.getElementById("btVerificar").disabled="false";
	//document.getElementById("btVerificar").value="verificando...";
	}
}

function verificaNicknameClick(campo,uf){

	if(uf==""){
		alert("Antes de escolher como vai ficar o endereço(URL) de sua página personalizada, você precisa selecionar seu estado.");
		document.getElementById('selectUf').focus();
	}else{

		if(campo.value!=""){
		document.getElementById("btVerificar").disabled=true;
		document.getElementById("btVerificar").value="verificando...";

		verNickname(campo.value,uf)
		}
	}
}

function ocultaBotaoVerificar(){
	document.getElementById("btVerificar").value="Verificar disponibilidade";
	document.getElementById("btVerificar").style.display="none";
	document.getElementById("btVerificar").disabled=false;
}

function verNickname(valor,uf)
{
// criacao do objeto XMLHTTP
var oHTTPRequest = createXMLHTTP(); 
// Abrindo a solicitacao HTTP. o primeiro parametro informa o metodo post/get
// o segundo parametro informa o arquivo solicitado que pode ser asp, php, txt, xml, etc
// o terceiro parametro informa que a solicitacao nao assincrona, 
// para solicitacao sincrona o parametro deve ser false
oHTTPRequest.open("post", "admin/getStatusNickCadastro.php", true);
// para solicitacoes utilizando o metodo post deve ser acrescentado 
// este cabecalho HTTP
oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// a funcao abaixo e executada sempre que o estado do objeto muda (onreadystatechange)
oHTTPRequest.onreadystatechange=function() {
// o valor 4 significa que o objeto ja completou a solicitacao
if (oHTTPRequest.readyState==4){
// abaixo o texto do gerado no arquivo executa.asp e colocado no div

	if(oHTTPRequest.responseText==0){
		document.getElementById("nickname").focus();
		document.getElementById("resultNickname").innerHTML='<img src="images/false.png" border=0 alt="O nome informado já existe!">';
		document.getElementById("btVerificar").value="Tente outro nome";
		document.getElementById("btVerificar").style.display="block"
		}
	}else{
		document.getElementById("resultNickname").innerHTML='<img src="images/true.png" border=0 alt="O nome informado foi aceito!">';
		ocultaBotaoVerificar();
	}
}
// abaixo e enviada a solicitacao. Note que a configuracao
// do evento onreadystatechange deve ser feita antes do send.
oHTTPRequest.send("valores=" + valor+"-"+uf);
}

function enviaSelectBusca(){
	if(validaFiltro(document.form1)){document.form1.submit();}
}


// ------------------------------------------
// NOVAS FUNCOES
// --------------------------------------------
function validaContrato(form){
	if (!document.contrato.aceito.checked) {
		alert('É necessário ler e aceitar o contrato!');
		return false;		
	}
	return true;
}

