//Funções de movimentação e criacão da Popup
function closeDiv() {
	document.getElementById('floatLayer').style.display = "none";
	return false;
}

window.onerror = null;
var topMargin = 100;
var slideTime = 5000;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);

function layerObject(id,left) {
	if (ns6) {
		this.obj = document.getElementById(id).style;
		this.obj.left = left;
		return this.obj;
	}
	else if(ie4) {
		this.obj = document.all[id].style;
		this.obj.left = left;
		return this.obj;
	}
	else if(ns4) {
		this.obj = document.layers[id];
		this.obj.left = left;
		return this.obj;
	}
}

function layerSetup() {
	floatLyr = new layerObject('floatLayer', pageWidth * .4);
	window.setInterval("main()", 10)
}

function floatObject() {
	if (ns4 || ns6) {
		findHt = window.innerHeight;
		
	} else if(ie4) {
		findHt = document.body.clientHeight;
	}
}
function main() {
	if (ns4) {
		this.currentY = document.layers["floatLayer"].top;
		this.currentX = document.layers["floatLayer"].left;
		this.scrollTop = window.pageYOffset;
		mainTrigger();
		}
	else if(ns6) {
		this.currentY = parseInt(document.getElementById('floatLayer').style.top);
		this.currentX = parseInt(document.getElementById('floatLayer').style.left);
		this.scrollTop = scrollY;
		mainTrigger();
	} else if(ie4) {
		this.currentY = floatLayer.style.pixelTop;
		this.currentX = floatLayer.style.pixelLeft;
		this.scrollTop = document.body.scrollTop;
		mainTrigger();
	}
}

function mainTrigger() {
	var newTargetY = this.scrollTop + this.topMargin;
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			floatStart();
		}
		animator();
		}
}

function floatStart() {
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 1 * this.slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt) {
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}
	else {
		this.D = this.currentY;
	}
}

function animator() {
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
	if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
	if ( ns4 )document.layers["floatLayer"].top = newY;
	if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
	}
}

function start() {
	if(ns6||ns4) {
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		layerSetup();
		floatObject();
		}
	else if(ie4) {
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		layerSetup();
		floatObject();
	}
}
//Fim funções do Popup

function popupFoto(Tipo, Tipo_Codigo, Foto_Codigo, Origem){
	var winEmail = AbreJanela("../site/" + Tipo + "_fotos.asp?tipo_codigo=" + Tipo_Codigo + "&foto_codigo=" + Foto_Codigo + "&origem=" + Origem + "", + Tipo + "_foto", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=450,height=400");
	winEmail.focus();
	return false;
}

function setLocation(Url){
	window.location.href = Url;
}

function setStatusBar(texto){
	window.status=texto;
}

function statusBarIn(obj){
	var texto = "";
	if (obj.title!=""){
		texto = obj.title;
	}
	setStatusBar(texto);
	return true;
}

function statusBarOut(){
	setStatusBar("");
	return true;
}

function LembreteSenha(objForm){
	objForm.acao.value = "LEMBRETE_SENHA";
	objForm.submit();
}

function AbreJanela(Url, Nome, Opcoes){
	var Janela = window.open(Url,Nome,Opcoes);
	return Janela;
}

function openWebTrendsWindow(url){
	var winWebTrends = AbreJanela(url,"popWebTrends","toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=575,height=405");
	winWebTrends.focus();
	return false;
}

function SomenteNumero(e){
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else 
		if(document.layers) // Nestcape
			var tecla = e.which;
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else{
			if (tecla != 8) // backspace
				return false;
			else
				return true;
			}
}

function Confirma(strTexto, strURL){
	if (confirm(strTexto)){
		setLocation (strURL);
		return true;
	}
	else{
		return false;
	}
}

function AdmImagens(caminho, retorno){
	var winEmail = AbreJanela("arquivo_upload.asp?tipo=IMGS&caminho=" + caminho + "&retorno=" + retorno + "","popArquivoUpload","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=500,height=520");
	winEmail.focus();
	return false;
}

function AdmDocumentos(caminho, retorno){
	var winEmail = AbreJanela("arquivo_upload.asp?tipo=DOCS&caminho=" + caminho + "&retorno=" + retorno + "","popArquivoUpload","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=500,height=520");
	winEmail.focus();
	return false;
}

function CheckAll(objForm, acao){
	var cont = 0;
	for (cont = 0; cont < objForm.elements.length; cont++){
		var obj = objForm.elements(cont);
		if (obj.type == "checkbox"){
			obj.checked = acao;
		}
	}
}

function Selecionar(objForm, objRetorno){
	var cont = 0;
	var aux = "";
	objRetorno.value = "";
	for (cont = 0; cont < objForm.elements.length; cont++){
		var obj = objForm.elements(cont);
		if (obj.type == "checkbox"){
			if (obj.checked && obj.name!="all"){
				objRetorno.value += aux + obj.email;
				aux = ";";
			}
		}
	}
}

function setImagem(src, objImg, hidden){
	objImg		= document.getElementById(objImg);
	objHidden	= document.getElementById(hidden);
	objImg.src	= src;
	objHidden.value = src;
}

function Mapa(){
	var winEmail = AbreJanela("mapa.htm","Mapa","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=475,height=340");
	winEmail.focus();
	return false;
}