//CEP = onkeyup=formatar(this, '##.###-###')
function formatar(src, mask)
{
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if(texto.substring(0,1) != saida)
		src.value += texto.substring(0,1);
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth - 18;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


// usado para campos checkbox na abertura e fechamento de div
//obj = nome do campo cheked
//div = div que abre ou fecha
//campo = caso feche ele zera
function Div(obj,div,campo)
{
	if ($(obj).checked == true)
	{
		$(div).style.display='block';
	}
	else if ($(obj).checked == false)
	{
		$(campo).value ='';
		$(div).style.display='none';
	}
}


//administra a janela que mostra os DETALHES DO IMÓVEL
//-------------------------------------------------------------------------------------//
var Win = 
{
	'_openNews': function() 
	{
			document.getElementById('divNewsletter').style.display = 'block';
			document.getElementById('divNewsletter').focus();
			//if (document.all)
			//var pos = evt.clientY;
			//else
			// var pos = window.pageYOffset;
			
			var pageSize = getPageSize();
			
			var objScroll = getPageScroll();
			
			//alert(objScroll[1]);
			
			var winW = pageSize[0];
			var winY = screen.availHeight;
			
			var w = (winW - 365) / 2;
			var y = (winY - 327) / 2;
			
			document.getElementById('divNewsletter').style.left = w + 'px';
			document.getElementById('divNewsletter').style.top = objScroll[1] + 20 + 'px';
			
			var iframeEl = document.createElement("IFRAME");
			
			iframeEl.setAttribute('id','overlay');
			iframeEl.style.top = 0;
			iframeEl.style.left = 0;
			iframeEl.frameBorder = 0;
			iframeEl.style.width = pageSize[0]+'px';
			iframeEl.style.height = pageSize[1]+'px';
			iframeEl.style.zIndex = 1000;
			iframeEl.src = "about:blank";
			iframeEl.style.display = "block";
			iframeEl.style.position = "absolute";
			iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=60)";
			iframeEl.style.backgroundColor = "#FFF";
			iframeEl.style.opacity = 0.6;
			iframeEl.style.KhtmlOpacity = 0.6;
			iframeEl.style.MozOpacity = 0.6;
			
			document.body.style.overflowX = 'hidden';
			
			document.getElementById('container').parentNode.insertBefore(iframeEl, document.getElementById('container'));
			
			document.getElementById('divNewsletter').style.zIndex = 1001;
			
			//loadAjax('mais_detalhes.php?ID=' + id_imovel, 'divWindow');
			
			//ajax
			//$("#divNewsletter").load('mais_detalhes.php?ID=' + id_imovel);
	},
	
	'_close': function(id)
	{
		document.getElementById(id).style.display = 'none';
		document.getElementById('overlay').parentNode.removeChild(document.getElementById('overlay'));
	}

}


function posicionaFooter() {
	var pos = getPageSize();
	$('container').style.height = pos[1] + 'px';
	$('content').style.height = (pos[1] - 302) + 'px';


}


//CENTRALIZADA
function openWin(url, name, w, h, s) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+s+',resizable=yes';
//	winprop = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes';
	
	win = window.open(url, name, winprops);
	if(parseInt(navigator.appVersion) >= 4) {
		win.window.focus(); 
	}
}


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_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_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];}
}

function novaJanela(caminho) {
	window.open(caminho);
}

function inputNumber(valor) {
	if(valor.value >= 0 && valor.value <= 9999)
	{
		
	}
	else
	{
		var tamanho = valor.value.length - 1;
		valor.value = valor.value.substr(0,tamanho);
	}
}

/*function teste(evt) {
	
	//var el = Event.element('onclick');
	
	alert(evt);
	
}
*/

function verificaTipo(tipo)
{
		if(tipo != "menu")
		{
		$('bgSubmenuContainerInstitucional').style.display='none';
		$('bgSubmenuContentInstitucional').style.display='none'; 
		$('SubmenuInstitucional').style.display='none';
		$('institucional').style.backgroundColor ='transparent';
		
		$('bgSubmenuContainerPublicacoes').style.display='none';
		$('bgSubmenuContentPublicacoes').style.display='none'; 
		$('SubmenuPublicacoes').style.display='none';
		$('publicacoes').style.backgroundColor ='transparent';
		}
}

function imprimir()
{
	window.print();
	history.go(-1);
}

var artigos =
{
	'autor' : function ()
	{
		$('artigo').style.display = 'none';
		$('autor').style.display = 'block';
	}
}

//--------------------------------------------------------------------------------------//
//administra a janela que mostra os DETALHES EM CLIPAGEM
//-------------------------------------------------------------------------------------//
var Window = {
	
	'_open': function(id,pos) {
		
		
		$('divWindow').style.display = 'block';
		$('divWindow').focus();
		//if (document.all)
			//var pos = evt.clientY;
		//else
		//	var pos = window.pageYOffset;
		
		var pageSize = getPageSize();
		
		var objScroll = getPageScroll();
		
		//alert(objScroll[1]);
			
		var winW = pageSize[0];
		var winY = screen.availHeight;
		
		var w = (winW - 760) / 2;
		var y = (winY - 570) / 2;
		
		$('divWindow').style.left = w + 'px';
		$('divWindow').style.top = 40 + 'px';

		
		var iframeEl = document.createElement("IFRAME");
		
		iframeEl.setAttribute('id','overlay');
		iframeEl.style.top = 0;
		iframeEl.style.left = 0;
		iframeEl.frameBorder = 0;
		iframeEl.style.width = pageSize[0]+'px';
		iframeEl.style.height = pageSize[1]+'px';
		iframeEl.style.zIndex = 1000;
		iframeEl.src = "about:blank";
		iframeEl.style.display = "block";
		iframeEl.style.position = "absolute";
		iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=60)";
		iframeEl.style.backgroundColor = "#FFFFFF";
		iframeEl.style.opacity = 0.6;
		iframeEl.style.KhtmlOpacity = 0.6;
		iframeEl.style.MozOpacity = 0.6;
		
		document.body.style.overflowX = 'hidden';
		
		$('all').parentNode.insertBefore(iframeEl, $('overlay'));
		
		$('divWindow').style.zIndex = 1001;
		
		new Ajax.Updater('divWindow', 'detalhesclipagem.php?id=' + id);
		
	},
	
	'_close': function(id)
	{
		$(id).style.display = 'none';
		$('overlay').parentNode.removeChild($('overlay'));
	}
	
}

var contato =
{
	'validar': function()
	{
		if($('nome').value == '')
		{
			$('seta').style.marginTop = "38px";
			$('seta').style.display = "block";
			$('nome').style.backgroundColor = '#F9F9F9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('nome').focus();
			return false;
			
		}
		
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('formContato').email.value))
		{
		}else
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "68px";
			}
			else
			{
				$('seta').style.marginTop = "66px";
			}
			$('email').style.backgroundColor = '#F9F9F9';
			$('nome').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('email').focus();
			alert("Digite um e-mail valido");
			return false;
						
		}

		if($('mensagem').value == '')
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "158px";
			}
			else
			{
				$('seta').style.marginTop = "150px";
			}
			$('mensagem').style.backgroundColor = '#F9F9F9';
			$('nome').style.backgroundColor = '#F5CFC9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').focus();
			return false;
			
		}
	},
	

	'limparForm' : function(id)
	{
		$(id).reset();
		$('seta').style.display = "none";
		$('nome').style.backgroundColor = '#F5CFC9';
		$('email').style.backgroundColor = '#F5CFC9';
		$('mensagem').style.backgroundColor = '#F5CFC9';
	},
	
	'sucesso' : function(id)
	{
		$(id).style.color = "#568856";
		$(id).innerHTML = "A mensagem foi enviada com sucesso.";
	},

	'erro' : function(id)
	{
		$(id).style.color = "#AA0000";
		$(id).innerHTML = "A mensagem não pode ser enviada.";
	}



}


var Associese =
{
	'validar': function()
	{
		if($('nome').value == '')
		{
			$('seta').style.marginTop = "72px";
			$('seta').style.display = "block";
			$('nome').style.backgroundColor = '#F9F9F9';
			$('telefone').style.backgroundColor = '#F5CFC9';
			$('dd').style.backgroundColor = '#F5CFC9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('vencimento').style.backgroundColor = '#F5CFC9';
			$('nome').focus();
			return false;
			
		}
		
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('formContato').email.value))
		{
		}else
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "103px";
			}
			else
			{
				$('seta').style.marginTop = "101px";
			}
			$('email').style.backgroundColor = '#F9F9F9';
			$('nome').style.backgroundColor = '#F5CFC9';
			$('telefone').style.backgroundColor = '#F5CFC9';
			$('dd').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('vencimento').style.backgroundColor = '#F5CFC9';
			$('email').focus();
			alert("Digite um e-mail valido");
			return false;
						
		}
		
		if($('dd').value == '')
		{
			$('seta').style.marginTop = "126px";
			$('seta').style.display = "block";
			$('nome').style.backgroundColor = '#F5CFC9';
			$('telefone').style.backgroundColor = '#F5CFC9';
			$('dd').style.backgroundColor = '#F9F9F9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('vencimento').style.backgroundColor = '#F5CFC9';
			$('dd').focus();
			return false;
			
		}		
		
		if($('telefone').value == '')
		{
			$('seta').style.marginTop = "126px";
			$('seta').style.display = "block";
			$('nome').style.backgroundColor = '#F5CFC9';
			$('telefone').style.backgroundColor = '#F9F9F9';
			$('dd').style.backgroundColor = '#F5CFC9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('vencimento').style.backgroundColor = '#F5CFC9';
			$('telefone').focus();
			return false;
			
		}
		
		if($('mensagem').value == '')
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "198px";
			}
			else
			{
				$('seta').style.marginTop = "190px";
			}
			$('vencimento').style.backgroundColor = '#F5CFC9';
			$('nome').style.backgroundColor = '#F5CFC9';
			$('telefone').style.backgroundColor = '#F5CFC9';
			$('dd').style.backgroundColor = '#F5CFC9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F9F9F9';
			$('mensagem').focus();
			return false;
			
		}

		if($('vencimento').value == '')
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "288px";
			}
			else
			{
				$('seta').style.marginTop = "280px";
			}
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('nome').style.backgroundColor = '#F5CFC9';
			$('telefone').style.backgroundColor = '#F5CFC9';
			$('dd').style.backgroundColor = '#F5CFC9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('vencimento').style.backgroundColor = '#F9F9F9';
			$('vencimento').focus();
			return false;
			
		}
	},
	

	'limparForm' : function(id)
	{
		$(id).reset();
		$('seta').style.display = "none";
		$('nome').style.backgroundColor = '#F5CFC9';
		$('email').style.backgroundColor = '#F5CFC9';
		$('mensagem').style.backgroundColor = '#F5CFC9';
	},
	
	'sucesso' : function(id)
	{
		$(id).style.color = "#568856";
		$(id).innerHTML = "A mensagem foi enviada com sucesso.";
	},

	'erro' : function(id)
	{
		$(id).style.color = "#AA0000";
		$(id).innerHTML = "A mensagem não pode ser enviada.";
	},
	
	'Valida2': function()
	{
			//alert(document.getElementById('ON').checked+' - '+document.getElementById('OFF').checked)
		if (document.getElementById('ON').checked == false && document.getElementById('OFF').checked == false)
		{
			alert("Você tem que escolher entre pessoa física ou jurídica para seguir com o cadastro");
			return false;
		}
	}
}




var preInscricao =
{
	'validar': function()
	{
		if($('nome').value == '')
		{
			
			if(document.all)
			{
				$('seta').style.marginTop = "53px";
			}
			else
			{
				$('seta').style.marginTop = "65px";
			}
			$('seta').style.display = "block";
			$('nome').style.backgroundColor = '#F9F9F9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('nome').focus();
			return false;
			
		}
		
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('formPreInscricao').email.value))
		{
		}else
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "85px";
			}
			else
			{
				$('seta').style.marginTop = "94px";
			}
			$('email').style.backgroundColor = '#F9F9F9';
			$('nome').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('email').focus();
			return false;
						
		}

		if($('mensagem').value == '')
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "175px";
			}
			else
			{
				$('seta').style.marginTop = "175px";
			}
			$('mensagem').style.backgroundColor = '#F9F9F9';
			$('nome').style.backgroundColor = '#F5CFC9';
			$('email').style.backgroundColor = '#F5CFC9';
			$('mensagem').focus();
			return false;
			
		}
	},
	

	'limparForm' : function(id)
	{
		$(id).reset();
		$('seta').style.display = "none";
		$('nome').style.backgroundColor = '#F5CFC9';
		$('email').style.backgroundColor = '#F5CFC9';
		$('mensagem').style.backgroundColor = '#F5CFC9';
	},
	
	'sucesso' : function(id)
	{
		$(id).style.color = "#568856";
		$(id).innerHTML = "Pré-inscrição enviada com sucesso.";
	},

	'erro' : function(id)
	{
		$(id).style.color = "#AA0000";
		$(id).innerHTML = "A pré-inscrição não pode ser enviada.";
	}



}

var recomende =
{
	'validar': function()
	{
		if($('seu_nome').value == '')
		{
			
			if(document.all)
			{
				$('seta').style.marginTop = "53px";
			}
			else
			{
				$('seta').style.marginTop = "53px";
			}
			$('seta').style.display = "block";
			$('seu_nome').style.backgroundColor = '#F9F9F9';
			$('seu_email').style.backgroundColor = '#F5CFC9';
			$('nome_amigo').style.backgroundColor = '#F5CFC9';
			$('email_amigo').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('seu_nome').focus();
			return false;
			
		}
		
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('formRecomende').seu_email.value))
		{
		}else
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "83px";
			}
			else
			{
				$('seta').style.marginTop = "81px";
			}
			$('seu_email').style.backgroundColor = '#F9F9F9';
			$('seu_nome').style.backgroundColor = '#F5CFC9';
			$('nome_amigo').style.backgroundColor = '#F5CFC9';
			$('email_amigo').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('seu_email').focus();
			return false;
						
		}

		if($('nome_amigo').value == '')
		{
			
			if(document.all)
			{
				$('seta').style.marginTop = "112px";
			}
			else
			{
				$('seta').style.marginTop = "107px";
			}
			$('seta').style.display = "block";
			$('nome_amigo').style.backgroundColor = '#F9F9F9';
			$('seu_email').style.backgroundColor = '#F5CFC9';
			$('seu_nome').style.backgroundColor = '#F5CFC9';
			$('email_amigo').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('nome_amigo').focus();
			return false;
			
		}
		
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('formRecomende').email_amigo.value))
		{
		}else
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "143px";
			}
			else
			{
				$('seta').style.marginTop = "134px";
			}
			$('email_amigo').style.backgroundColor = '#F9F9F9';
			$('seu_nome').style.backgroundColor = '#F5CFC9';
			$('nome_amigo').style.backgroundColor = '#F5CFC9';
			$('seu_email').style.backgroundColor = '#F5CFC9';
			$('mensagem').style.backgroundColor = '#F5CFC9';
			$('email_amigo').focus();
			return false;
						
		}

		if($('mensagem').value == '')
		{
			$('seta').style.display = "block";
			if(document.all)
			{
				$('seta').style.marginTop = "173px";
			}
			else
			{
				$('seta').style.marginTop = "165px";
			}
			$('mensagem').style.backgroundColor = '#F9F9F9';
			$('seu_nome').style.backgroundColor = '#F5CFC9';
			$('nome_amigo').style.backgroundColor = '#F5CFC9';
			$('seu_email').style.backgroundColor = '#F5CFC9';
			$('email_amigo').style.backgroundColor = '#F5CFC9';
			$('mensagem').focus();
			return false;
			
		}
	},
	

	'limparForm' : function(id)
	{
		$(id).reset();
		$('seta').style.display = "none";
		$('seu_nome').style.backgroundColor = '#F5CFC9';
		$('seu_email').style.backgroundColor = '#F5CFC9';
		$('nome_amigo').style.backgroundColor = '#F5CFC9';
		$('email_amigo').style.backgroundColor = '#F5CFC9';
		$('mensagem').style.backgroundColor = '#F5CFC9';
	},
	
	'sucesso' : function(id)
	{
		$(id).style.color = "#568856";
		$(id).innerHTML = "Email de recomendação enviado com sucesso.";
	},

	'erro' : function(id)
	{
		$(id).style.color = "#AA0000";
		$(id).innerHTML = "O email de recomendação não pode ser enviado.";
	}
}

var Cliente = 
{
	'Delete': function(ID,img)
	{
	   if (confirm('Tem certeza que deseja excluir ? '))
	   document.location = 'main.php?cmd=excluir&file='+ img +'&ID=' + ID;
	},
	
	'DeletaFoto': function(ID,img)
	{
	   if (confirm('Tem certeza que deseja excluir ? '))
	   document.location = 'registro.php?cmd=ExcluirFoto&file='+ img +'&ID=' + ID;
	},
	
	// Mascara data tamanho,nome
	'Data': function(tamanho,id)
	{
		if (tamanho == 2)
			document.getElementById(id).value += "/";
		if (tamanho == 5)
			document.getElementById(id).value += "/"; 
	}, 
	
	// Mascara telefone tamanho,nome
	'Telefone': function(tamanho,id)
	{
		if (tamanho == 1)
			document.getElementById(id).value = '('+ document.getElementById(id).value; 
		if (tamanho == 3)
			document.getElementById(id).value += ") ";
		if (tamanho == 9)
			document.getElementById(id).value += '-'; 
	},
	'loadCidades': function(uf,complemento,div) {
		//alert(uf);
		loadAjax('load-cidades.php?uf=' + uf +'&complemento=' + complemento, div, null, null);		
	},
	
	//serve para acrecentar para pessoa juridica outro local para cobrança
	'Tipo': function(cobranca)
	{
		if (cobranca == "O")
		{
			$('cobranca').style.display = "block";
			$('acessorio').style.display = "none";
		}
		else if (cobranca == "E")
		{
		$('cobranca').style.display = "none";
		$('acessorio').style.display = "block";
		}
	},
	
	
	//validacao de cadastro simplificado
	'validaInscSimplificado': function()
	{
		if($('nome_cliente').value==""){
			alert('Você precisa digitar seu nome completo ! ')
			$('nome_cliente').focus();
			return false;
		}
		
		if($('telefonecontato').value==""){
			alert('Você precisa digitar seu telefone de contato ! ')
			$('telefonecontato').focus();
			return false;
		}
		
		if($('ufres').value==""){
			alert('Você precisa escolher seu estado ! ')
			$('ufres').focus();
			return false;
		}
		
		if($('cidaderes').value==""){
			alert('Você precisa escolher sua cidade ! ')
			$('cidaderes').focus();
			return false;
		}
		
		if($('emailpessoal').value == '' || $('emailpessoal').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('emailpessoal').focus();
			return false;
		}
		
		if($('senha').value.length < 4){
			alert('Você precisa digitar sua senha sem espaço em branco e com no mínimo 4 digitos! ');			
			$('senha').focus();
			return false;
		}		
	},
	
	//usado no login se ja cadastrado
	'valida1': function()
	{
		
		if($('email1').value == '' || $('email1').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('email1').focus();
			return false;
		}
		
		if($('senha').value==""){
			alert('Você precisa digitar sua senha ! ')
			$('senha').focus();
			return false;
		}
	},
	
	//usado no login se esquaceu a senha
	'valida2': function()
	{		
		if($('email2').value == '' || $('email2').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('email2').focus();
			return false;
		}
	},
	
	//usado no login se esquaceu a senha
	'validaNewsletter': function()
	{
	
		if($('nome').value==""){
			alert('Você precisa digitar seu nome! ')
			$('nome').focus();
			return false;
		}
		
		if($('email').value == '' || $('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('email').focus();
			return false;
		}
	},
		
	
	//verifica os campos de pessoa fisica para cadastro 
	'validaFisica': function(pago)
	{
			
		// 0 = gratuito
		// 1 = pago
		// 2 = 

			if($('cpf').value == "" || $('cpf').value == 0)
			{
				alert('Você precisa digitar seu CPF e RG ! ')
				$('cpf').focus();
				return false;
			}
			
			//valida o CPF digitado
			if($('cpf').value != "")
			{
				
				var CPF = $('cpf').value;
				exp = /\.|\-/g
				CPF = CPF.toString().replace( exp, "" );
				
				// Aqui começa a checagem do CPF
				var POSICAO, I, SOMA, DV, DV_INFORMADO;
				var DIGITO = new Array(10);
				DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
				
				// Desemembra o número do CPF na array DIGITO
				for (I=0; I<=8; I++)
				{
				  DIGITO[I] = CPF.substr( I, 1);
				}
				
				// Calcula o valor do 10º dígito da verificação
				POSICAO = 10;
				SOMA = 0;
				   for (I=0; I<=8; I++)
				   {
					  SOMA = SOMA + DIGITO[I] * POSICAO;
					  POSICAO = POSICAO - 1;
				   }
				DIGITO[9] = SOMA % 11;
				   if (DIGITO[9] < 2) 
				   {
						DIGITO[9] = 0;
					}
				   else
				   {
					   DIGITO[9] = 11 - DIGITO[9];
					}
				
				// Calcula o valor do 11º dígito da verificação
				POSICAO = 11;
				SOMA = 0;
				   for (I=0; I<=9; I++) 
				   {
					  SOMA = SOMA + DIGITO[I] * POSICAO;
					  POSICAO = POSICAO - 1;
				   }
				DIGITO[10] = SOMA % 11;
				   if (DIGITO[10] < 2) 
				   {
						DIGITO[10] = 0;
				   }
				   else {
						DIGITO[10] = 11 - DIGITO[10];
				   }
				
				// Verifica se os valores dos dígitos verificadores conferem
				DV = DIGITO[9] * 10 + DIGITO[10];
				   if (DV != DV_INFORMADO)
				   {
					  alert('CPF inválido');
					  $('cpf').value = '';
					  $('cpf').focus();
					  return false;
				   } 
			   }
		
		if($('nome_cliente').value==""){
			alert('Você precisa digitar seu nome completo ! ')
			$('nome_cliente').focus();
			return false;
		}
		
		if($('ufres').value==""){
			alert('Você precisa escolher seu estado ! ')
			$('ufres').focus();
			return false;
		}
		
		if($('cidaderes').value==""){
			alert('Você precisa escolher sua cidade ! ')
			$('cidaderes').focus();
			return false;
		}
		
		if($('enderecores').value==""){
			alert('Você precisa digitar seu endereço ! ')
			$('enderecores').focus();
			return false;
		}
		
		if($('bairrores').value==""){
			alert('Você precisa digitar seu bairro ! ')
			$('bairrores').focus();
			return false;
		}
		
		if($('cepres').value==""){
			alert('Você precisa digitar seu CEP ! ')
			$('cepres').focus();
			return false;
		}
		
		if($('formacao').value==""){
			alert('Você precisa digitar sua formação ! ')
			$('formacao').focus();
			return false;
		}
		
		if($('telefonecontato').value==""){
			alert('Você precisa digitar seu telefone de contato ! ')
			$('telefonecontato').focus();
			return false;
		}
		
		if($('emailpessoal').value == '' || $('emailpessoal').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('emailpessoal').focus();
			return false;
		}
		
		if($('teste_email'))
		{
			if($('teste_email').value != $('emailpessoal').value){
				alert('Você deve digitar  e-mail e a confirmação iguais  ! ')
				$('emailpessoal').focus();
				return false;
			}
		}
		
		if($('senha').value.length < 4){
			alert('Você precisa digitar sua senha sem espaço em branco e com no mínimo 4 digitos! ');			
			$('senha').focus();
			return false;
		}
		
	},
	
	//verifica os campos de pessoa fisica para cadastro 
	'validaJuridica': function(pago)
	{
			
			if($('cnpj').value == "" || $('cnpj').value == 0){
				alert('Você precisa digitar seu CNPJ ! ')
				$('cnpj').focus();
				return false;
			}	
			
				if($('cnpj').value!="") 
				{
					CNPJ = $('cnpj').value;
					erro = new String;
					if (CNPJ.length < 18)
					{
						erro += "CNPJ inválido! \n\n";
					}
					if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
					{alert(CNPJ.charAt(2));
						if (erro.length == 0) erro += "CNPJ inválido! \n\n";
					}
					//substituir os caracteres que não são números
					if(document.layers && parseInt(navigator.appVersion) == 4)
					{
						x = CNPJ.substring(0,2);
						x += CNPJ.substring (3,6);
						x += CNPJ.substring (7,10);
						x += CNPJ.substring (11,15);
						x += CNPJ.substring (16,18);
						CNPJ = x;
					} 
					else 
					{
						CNPJ = CNPJ.replace (".","");
						CNPJ = CNPJ.replace (".","");
						CNPJ = CNPJ.replace ("-","");
						CNPJ = CNPJ.replace ("/","");
					}
					var nonNumbers = /\D/;
					if (nonNumbers.test(CNPJ)) erro += "CNPJ inválido! \n\n";
					var a = [];
					var b = new Number;
					var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
					for (i=0; i<12; i++)
					{
						a[i] = CNPJ.charAt(i);
						b += a[i] * c[i+1];
					}
					if ((x = b % 11) < 2) 
					{ 
						a[12] = 0 
					} 
					else 
					{ 
						a[12] = 11-x 
					}
					b = 0;
					for (y=0; y<13; y++) 
					{
						b += (a[y] * c[y]);
					}
					if ((x = b % 11) < 2) 
					{ 
						a[13] = 0; 
					} 
					else 
					{ 
						a[13] = 11-x; 
					}
					if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
					{
						erro +="CNPJ inválido!";              
					}
					if (erro.length > 0)
					{
						alert(erro);
						$('cnpj').focus();
						return false;
					}
					//return true;
				}
		
		
		if($('empresa').value==""){
			alert('Você precisa digitar seu empresa ! ')
			$('empresa').focus();
			return false;
		}
		
		if($('nome_cliente').value==""){
			alert('Você precisa digitar o nome do responsável ! ')
			$('nome_cliente').focus();
			return false;
		}
		
		if($('uf_com').value==""){
			alert('Você precisa escolher seu estado ! ')
			$('uf_com').focus();
			return false;
		}
		
		if($('cidade_com').value==""){
			alert('Você precisa escolher sua cidade ! ')
			$('cidade_com').focus();
			return false;
		}
		
		if($('email_com').value == '' || $('email_com').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('email_com').focus();
			return false;
		}
		
		if($('senha').value.length < 4){
			alert('Você precisa digitar sua senha sem espaço em branco e com no mínimo 4 digitos! ');			
			$('senha').focus();
			return false;
		}
				
		if($('cep_com').value==""){
			alert('Você precisa digitar seu CEP ! ')
			$('cep_com').focus();
			return false;
		}
		
		if($('cargo').value==""){
			alert('Você precisa digitar seu cargo ! ')
			$('cargo').focus();
			return false;
		}
		
		if($('cnpj').value==""){
			alert('Você precisa digitar seu CNPJ ! ')
			$('cnpj').focus();
			return false;
		}
		
		
		if($('endereco_com').value==""){
			alert('Você precisa digitar seu endereço ! ')
			$('endereco_com').focus();
			return false;
		}
		
		if($('telefone_com1').value==""){
			alert('Você precisa digitar seu telefone ! ')
			$('telefone_com1').focus();
			return false;
		}
		
		if($('teste_email'))
		{
			if($('teste_email').value != $('email_com').value)
			{
				alert('Você deve digitar  e-mail e a confirmação iguais  ! ')
				$('email_com').focus();
				return false;
			}
		}
	},
	
	//verifica os campos de pessoa fisica e curso gratuito
	'validafisicagratuito': function()
	{
		if($('nome_cliente').value==""){
			alert('Você precisa digitar seu nome ! ')
			$('nome_cliente').focus();
			return false;
		}
		
		if($('email').value == '' || $('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('email').focus();
			return false;
		}
		
		if($('rg').value==""){
			alert('Você precisa digitar seu RG ! ')
			$('rg').focus();
			return false;
		}
		if($('telefoneres').value==""){
			alert('Você precisa digitar seu telefone residencial ! ')
			$('telefoneres').focus();
			return false;
		}
		if($('nome_cracha').value==""){
			alert('Você precisa digitar seu nome para crachá ! ')
			$('nome_cracha').focus();
			return false;
		}
		if($('celular').value==""){
			alert('Você precisa digitar seu celular ! ')
			$('celular').focus();
			return false;
		}
		if($('formacao').value==""){
			alert('Você precisa digitar seu formação ! ')
			$('formacao').focus();
			return false;
		}
		if($('profissao').value==""){
			alert('Você precisa digitar sua profissão ! ')
			$('profissao').focus();
			return false;
		}
		if($('emailpessoal').value==""){
			alert('Você precisa digitar seu e-mail ! ')
			$('emailpessoal').focus();
			return false;
		}
		if($('senha').value==""){
			alert('Você precisa digitar seu senha ! ')
			$('senha').focus();
			return false;
		}
		if($('empresa').value==""){
			alert('Você precisa digitar seu empresa ! ')
			$('empresa').focus();
			return false;
		}
		if($('cargo').value==""){
			alert('Você precisa digitar seu cargo ! ')
			$('cargo').focus();
			return false;
		}
		if($('telefone_com').value==""){
			alert('Você precisa digitar o telefone de sua empresa! ')
			$('telefone_com').focus();
			return false;
		}
		
	},
	
	'validaFinalizar': function(cont,t)
	{
		var resposta = 0;
		
		if (t == 'N')
		{
			if($('tipo1').checked == false && $('tipo2').checked == false && $('tipo3').checked == false)
			{
				alert('Você precisa escolher um tipo de pagamento ! ')
				return false;
			}
		}
		
		for (ind = 1;ind <= cont;ind++)
		{	
			if($('id_parcela'+ind).checked == true)
			{
				resposta = 1;
			}
		}
		
		if(resposta == 0)
		{
			alert('Você precisa escolher uma forma de pagamento ! ')
			return false;
		}
	},
	
	
	'validaFinalizarBeneficiente': function()
	{
		if($('doacao').checked == false && $('contribuicao').checked == false)
		{
			alert('Você precisa escolher uma forma de pagamento ! ')
			return false;
		}				
	},
	
	//serve para ver se tem pelo menos um participante inscrito
	'validaParticipante': function()
	{
		var cont = 0;
		
		for(cont = 1;cont<=10;cont++)
		{
			
			if ($('nome_func'+cont).value != "")
			{
				var n = cont;
			}
		}
		
		if (n >= 1)
		{
			return true;
		}
		else
		{
			alert('Você precisa inscrever pelo menos um participante! ')
			$('nome_func1').focus();
			return false;
	    }
	}
	
}

var resMinima =
{
	'organizar': function()
	{
		var w  = screen.availWidth;
		
		if(w <= 800)
		{
			$('all').style.width = '776px';
			$('container').style.width = '776px';
			$('container').style.backgroundImage = 'none';
			$('container').style.backgroundColor = '#FFFFFF';
		}
		
	}
}


var Finalizar =
{
	'Pagamento': function(tipo)
	{
		if (tipo == 1)
		{
			$('deposito').style.display='none';	
			$('cheque').style.display='none';
			$('boleto').style.display='block';
		}
		else if (tipo == 2)
		{
			$('deposito').style.display='none';
			$('boleto').style.display='none';
			$('cheque').style.display='block';
		}
		else
		{
			$('boleto').style.display='none';
			$('cheque').style.display='none';
			$('deposito').style.display='block';
		}
	}
}



//-------------------------------------------------------------------------------------------------------------------//

//AJAX GERAL
var reqs = new Array();

function uncache(url)
{
	var d = new Date();
	var time = d.getTime();

	if (new String(url).indexOf("?") < 0)
		strurl = "?";
	else
		strurl = "&";

	url = url + strurl + 'timecache='+time;
	return url;
} 

function CXMLReq(type, xmlhttp, target, func)
{
	this.type = type;
	this.xmlhttp = xmlhttp; 
	this.target = target;
	this.func = func;
}

function mostraLog(msg)
{
	if ($('logErros'))
		$('logErros').innerHTML += msg + '<BR>';
}

function loadAjax(url, target, func, msg) {
	
	//mostraLog('jah: url->' + url + ', target->' + target + ', func->' + func + ', msg->' + msg);
	var xhr = false;
	// native XMLHttpRequest object
	if(msg !== null){
		if(msg)
			mensagem = '<div id="loading"><img src="img/loading.gif" align="absmiddle">&nbsp;' + msg + '</div>';
		else
			mensagem = '<div id="loading"><img src="img/loading.gif" align="absmiddle">&nbsp;Aguarde, carregando...</div>';
	document.getElementById(target).innerHTML = mensagem;
	}
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
		xhr.onreadystatechange = function() {jahDone();};
		xhr.open("GET", url, true);
		xhr.send(null);
		// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
		if (xhr) {
			xhr.onreadystatechange = function() {jahDone();};
			xhr.open("GET", uncache(url), true);
			xhr.send();
		}
	}
	
	var xmlreq = new CXMLReq('', xhr, target, func);
	reqs.push(xmlreq);
}    

function jahDone() {
	if (typeof(window['reqs']) == "undefined") return;
	// only if req is "loaded"
	for (var req=0; req<reqs.length; req++)
	{
		if (reqs[req].xmlhttp.readyState == 4) {
			// only if "OK"
			results = reqs[req].xmlhttp.responseText;
			target = reqs[req].target;
			func = reqs[req].func;
			statusText = reqs[req].xmlhttp.statusText;
			if (reqs[req].xmlhttp.status == 200 || reqs[req].xmlhttp.status == 304) {
				reqs.splice(req,1); req --;
				var o = document.getElementById(target);
				o.innerHTML = results;
				if (haveJS(o))
					execJS(o);
				if (func)
					eval(func);
			} else {
				$(target).innerHTML="jah erro:\n" + statusText;
				reqs.splice(req,1); req --;
			}
		}
	}
}

var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
var bMoz = (navigator.appName == 'Netscape');

function haveJS(node)
{
  var st = node.getElementsByTagName('SCRIPT');
  if (st.length > 0)
  	return true;
  else
    return false;
}

function execJS(node) 
{
  var st = node.getElementsByTagName('SCRIPT');
  var strExec;
  for(var i=0;i<st.length; i++) {
	if (bSaf) {
	  strExec = st[i].innerHTML;
	}
	else if (bMoz) {
	  strExec = st[i].textContent;
	}
	else {
	  strExec = st[i].text;
	}
	try {
	  //mostraLog('chamando isso:' + strExec);
	  eval(strExec);
	} catch(e) {
	  alert(strExec);
	  if (window.ActiveXObject)
		  alert(e.description);
	  else
	  	  alert(e);
	}
  }
}


//original
//valida o CPF digitado
/*function ValidarCPF(Objcpf){
    var cpf = Objcpf.value;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" );
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
    
    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }    
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
    
    var digitoGerado=(soma1*10)+soma2;
    if(digitoGerado!=digitoDigitado)    
        alert('CPF Invalido!');        
}


function validaCNPJ(objeto) 
{
	CNPJ = objeto;
	erro = new String;
	if (CNPJ.length < 18)
	{
		erro += "É necessario preencher corretamente o número do CNPJ! \n\n";
	}
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
	{
		if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
	}
	//substituir os caracteres que não são números
	if(document.layers && parseInt(navigator.appVersion) == 4)
	{
		x = CNPJ.substring(0,2);
		x += CNPJ. substring (3,6);
		x += CNPJ. substring (7,10);
		x += CNPJ. substring (11,15);
		x += CNPJ. substring (16,18);
		CNPJ = x;
	} 
	else 
	{
		CNPJ = CNPJ. replace (".","");
		CNPJ = CNPJ. replace (".","");
		CNPJ = CNPJ. replace ("-","");
		CNPJ = CNPJ. replace ("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n";
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++)
	{
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) 
	{ 
		a[12] = 0 
	} 
	else 
	{ 
		a[12] = 11-x 
	}
	b = 0;
	for (y=0; y<13; y++) 
	{
		b += (a[y] * c[y]);
	}
	if ((x = b % 11) < 2) 
	{ 
		a[13] = 0; 
	} 
	else 
	{ 
		a[13] = 11-x; 
	}
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
	{
		erro +="Dígito verificador com problema!";              
	}
	if (erro.length > 0)
	{
		alert(erro);
		$('cnpj').focus();
		return false;
	} 
	else 
	{                       
		alert("CNPJ valido!");
	}
	//return true;
}*/
