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

function fMoeda(Total)
{
	num3 = Total;
	num3 = num3.toString().replace(/\$|\,/g,'');

	if(isNaN(num3))
	num3 = "0";
	sign = (num3 == (num3 = Math.abs(num3)));
	num3 = Math.floor(num3*100+0.50000000001);
	cents3 = num3%100;
	num3 = Math.floor(num3/100).toString();
	if(cents3<10)
	cents3 = "0" + cents3;
	for (var i = 0; i < Math.floor((num3.length-(1+i))/3); i++)
	num3 = num3.substring(0,num3.length-(4*i+3))+''+
	num3.substring(num3.length-(4*i+3));

	Total = (num3 + ',' + cents3);
	
	return Total;
}

////RETORNA SOMENTE NUMEROS
function fSomenteNumeros(evt){
	var key_code = evt.keyCode  ? evt.keyCode  :
				   evt.charCode ? evt.charCode :
				   evt.which    ? evt.which    : void 0;
	// Habilita teclas <DEL>, <TAB>, <ENTER>, <ESC> e <BACKSPACE>
	//alert(key_code);
	if (key_code == 8  ||  key_code == 9  ||  key_code == 13  ||  key_code == 27  ||  key_code == 46 ||  key_code == 44)
	{
		return true;
	}
	// Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
	else if ((key_code >= 35)  &&  (key_code <= 40))
	{
		return true
	}
	// Habilita números de 0 a 9
	else if ((key_code >= 48)  &&  (key_code <= 57))
	{
		return true
	}
	return false;
}

// Formata valores para visualização.
function FormataValorBRA(pValor)
{
	if (pValor == "" || parseInt(pValor) == 0){
		return "";
		
	}else{
	
		var i
		var j
		var iDecimal
		var iInteiro
		var iNovoValor

		iInteiro = pValor
		iDecimal = '00'

		// Limpa formatação antiga
		for (i = 0; i < pValor.length; i++)
		{
			if (pValor.charAt(i) == ".")
			{
				pValor = pValor.substring(0,i) + pValor.substring(i + 1,pValor.length);
			}
		}
		
		// Separa a parte Inteira da parte Decimal
		i = 0
		for (i = 0; i < pValor.length; i++)
		{
			if (pValor.charAt(i) == ",")
			{
				iInteiro = pValor.substring(0,i)
				iDecimal = pValor.substring(i + 1,pValor.length)
			}
		}

		// Formata a parte decimal para duas casas no mínimo.
		if (iDecimal.length <= 1)
		{
			iDecimal = iDecimal + "0"
		}

		// Formata a parte inteira para uma casa no mínimo.
		if (iInteiro.length <= 0)
		{
			iInteiro = "0" + iInteiro
		}

		// Formata a parte Inteira.
		iNovoValor = ''
		j = 0
		for (i = iInteiro.length; i > 0; i--)
		{
			j = j + 1
			if (j == 4)
			{
				iNovoValor = iInteiro.substring(i,i-1) + '.' + iNovoValor
				j = 1
			}
			else
			{
				iNovoValor = iInteiro.substring(i,i-1) + iNovoValor
			}
		}

		// Agrega a Parte decimal ao novo valor
		iNovoValor = iNovoValor + "," + iDecimal

		return iNovoValor
	}
}

// Formata valores para visualização.
function FormataValorInteiro(pValor)
{
	if (pValor == "" || parseInt(pValor) == 0){
		return "";
		
	}else{
	
		var i
		var j
		var iDecimal
		var iInteiro
		var iNovoValor

		iInteiro = pValor
		iDecimal = '00'

		// Limpa formatação antiga
		for (i = 0; i < pValor.length; i++)
		{
			if (pValor.charAt(i) == ".")
			{
				pValor = pValor.substring(0,i) + pValor.substring(i + 1,pValor.length);
			}
		}
		
		// Separa a parte Inteira da parte Decimal
		i = 0
		for (i = 0; i < pValor.length; i++)
		{
			if (pValor.charAt(i) == ",")
			{
				iInteiro = pValor.substring(0,i)
				iDecimal = pValor.substring(i + 1,pValor.length)
			}
		}

		// Formata a parte decimal para duas casas no mínimo.
		if (iDecimal.length <= 1)
		{
			iDecimal = iDecimal + "0"
		}

		// Formata a parte inteira para uma casa no mínimo.
		if (iInteiro.length <= 0)
		{
			iInteiro = "0" + iInteiro
		}

		// Formata a parte Inteira.
		iNovoValor = ''
		j = 0
		for (i = iInteiro.length; i > 0; i--)
		{
			j = j + 1
			if (j == 4)
			{
				iNovoValor = iInteiro.substring(i,i-1) + '.' + iNovoValor
				j = 1
			}
			else
			{
				iNovoValor = iInteiro.substring(i,i-1) + iNovoValor
			}
		}

		// Agrega a Parte decimal ao novo valor
		iNovoValor = iNovoValor

		return iNovoValor
	}
}

function fFichaAnuncio(AnuncioID){
	xCaminho 		= "destaqueAnuncio.php?anuncio="+AnuncioID;
	window.location = xCaminho;
}

function fAtualizaAnuncios(xii,xCanalIDTipo,xCanalIDQTD,xTimer){
	AjaxHOME("DIV_Canal"+xii, "ajax/ajax.php", "combo=38&canalid="+xii+"&canaltipo="+xCanalIDTipo+"&canalqtd="+xCanalIDQTD);
	setTimeout("fAtualizaAnuncios('"+xii+"','"+xCanalIDTipo+"','"+xCanalIDQTD+"',"+xTimer+")",xTimer);	
}


//FUNCOES PARA CRIACAO DO DIV FLUTUANDO
var cX = 0; var cY = 0; var rX = 0; var rY = 0; var hProdID = 0; var hProdQTD = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }

function AssignPosition(d,h) {
	if(h==5 || h==6 || h==7 || h==8){
		d.style.left = parseInt(getPosicaoElemento("ButTopo"+h).left - 100) + "px";
		d.style.top = parseInt(getPosicaoElemento("ButTopo"+h).top + 29) + "px";
	}else{
		d.style.left = parseInt(getPosicaoElemento("ButTopo"+h).left - 5) + "px";
		d.style.top = parseInt(getPosicaoElemento("ButTopo"+h).top + 29) + "px";	
	}
}
function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d,h) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd,h);
	dd.style.display = "block";	
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd,h);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}
function getPosicaoElemento(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};
}
//FIM FUNCOES PARA CRIACAO DO DIV FLUTUANDO DE DICAS DE PRODUTOS	

