//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 = 250;
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 popupFotoProduto(Produto_Codigo){
	var winEmail = AbreJanela("../site/produto_fotos.asp?produto_foto_codigo=" + Produto_Codigo + "","popProdutoFoto","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=374,height=530");
	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 goComboCategorias(objCombo){
		Categoria_Codigo = objCombo.options[objCombo.options.selectedIndex].value;
		if (Categoria_Codigo != "")
			setLocation("produtos_lista.asp?categoria_codigo=" + Categoria_Codigo);
}

function voltar(){
	window.history.back();
}

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 setLojaFoto(objForm, Sequencia){
	objForm.loja_foto_sequencia.value = Sequencia;
	objForm.submit();
}

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 FiltroProdutos(objForm){
	try{
		objForm.categoria_codigo.options.selectedIndex = 0;
	}
	catch(e){}
	objForm.submit();
}

function AdmImagens(caminho, retorno){
	var winEmail = AbreJanela("arquivo_upload.asp?tipo=IMGS&caminho=" + caminho + "&retorno=" + retorno + "","popArquivoUpload","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=500,height=520");
	winEmail.focus();
	return false;
}

function setImagem(src, img, hidden){
	objImg		= document.getElementById(img);
	objHidden	= document.getElementById(hidden);
	objImg.src	= src;
	objHidden.value = src;
}

function AbrirFiltroClientes(CampoRetorno){
	AbreJanela("clientes_emails_send_filtro.asp?camporetorno=" + CampoRetorno, "popFiltroClientes", "menubar=0,scrollbars=yes,width=460,height=400,top=5,left=5");
}

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 changeFoto(src, txt){
	obj = document.getElementById("foto_produto");
	obj2 = document.getElementById("foto_produto_texto");
	obj.src = src;
	obj2.innerHTML = txt;
}

function AbrirLojaFoto(Loja_Foto_Codigo){
	var w = 460;
	var h = 360;	
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	AbreJanela("loja_foto.asp?loja_foto_codigo=" + Loja_Foto_Codigo, "popLojaFoto", "menubar=0,scrollbars=no,width=" + w + ",height=" + h + ",top=" + TopPosition + ",left=" + LeftPosition + "");
}

function changePagina(e, objForm){
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else
		if(document.layers) // Nestcape
			var tecla = e.which;
	objForm.submit();
}

function getElementPosition(elemID){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

function ValidaNovoAtributo(objCombo){
	Atributo_Codigo = objCombo.options[objCombo.options.selectedIndex].value;
	if(Atributo_Codigo == ""){
		alert("Escolha um atributo para adicionar algum valor.");
		return false;
	}
	else{
		setLocation('config_atributos_valores_dados.asp?cmd=ADD&atributo_codigo=' + Atributo_Codigo);
		return true;
	}
}

function LembreteSenha(objForm){
	objForm.acao.value = "LEMBRETE_SENHA";
	objForm.submit();
}
