// DynClick
// Copyright 2002 AgênciaClick
// http://www.agenciaclick.com.br
// Versão 1.02 - 25/02/2002


d=document


// Basics

function isDef(S){return(eval('typeof('+S+')')!='undefined'&&eval('typeof('+S+')')!='unknown')}

function getElm(id){return (is.ie4)?d.all[id]:d.getElementById(id)}

function toId(S){
	S=S.toLowerCase()
	S=S.replace(/[áàãâ]/g,'a')
	S=S.replace(/[éèêë&]/g,'e')
	S=S.replace(/[íìîï]/g,'i')
	S=S.replace(/[óòõôö]/g,'o')
	S=S.replace(/[úùûü]/g,'u')
	S=S.replace(/[ç]/g,'c')
	S=S.replace(/[ \.:,\+\-\*\'\"\\\/<>]/g,'')
	if(S.indexOf('?')!=-1)S=S.substring(0,S.indexOf('?'))
	return S
}

function openPopup(url,w,h,other){
	url=url.replace(/[ ]/g,'%20')
	popup=window.open(url,'popup_'+toId(url),'left=18,top=18,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()
}

function openBlank(url){window.open(url)}

function checkBrowser(){
	T=this
	b=navigator.appName
	v=navigator.appVersion
	u=navigator.userAgent
	if(b=='Netscape')T.b='ns'
	else if(b=='Microsoft Internet Explorer')T.b='ie'
	else T.b=b
	T.v=parseInt(v)
	T.ns=(T.b=='ns'&&T.v>=4)
	T.ns4=(T.b=='ns'&&T.v==4)
	T.ns5=(T.b=='ns'&&T.v==5)
	T.ns6=(T.b=='ns'&&T.v==5)
	T.ie=(T.b=='ie'&&T.v>=4)
	T.ie4=(u.indexOf('MSIE 4')>0)
	T.ie5=(u.indexOf('MSIE 5.0')>0)
	T.ie55=(u.indexOf('MSIE 5.5')>0)
	T.ie6=(u.indexOf('MSIE 6.0')>0)
	if(T.ie5)T.v=5
	if(T.ie55)T.v=5.5
	if(T.ie6)T.v=6
	T.min=(T.ns||T.ie)
	T.dom=(T.v>=5)
	T.win=(u.indexOf('Win')>0)
	T.mac=(u.indexOf('Mac')>0)
}
is=new checkBrowser()


// Page Dimensions

function docW(){return(is.ie?(d.body.scrollWidth):(d.width))}
function docH(){return(is.ie?(d.body.scrollHeight):(d.height))}
function winW(){return(is.ie?(d.body.clientWidth):(window.innerWidth))}
function winH(){return(is.ie?(d.body.clientHeight):(window.innerHeight))}


// Images

function pI(src){
	obj=src.substring(src.lastIndexOf('/')+1,src.lastIndexOf('.'))
	eval(obj+'=new Image()')
	eval(obj+'.src="'+src+'"')
}

function cI(id,obj,lyr){
	id=(is.ns4&&lyr)?'d.layers.'+lyr+'.document.images.'+id:'d.images[\''+id+'\']'
	if(isDef(id)&&isDef(obj))eval(id).src=eval(obj).src
}


// Layers

function newLyr(id,l,t,w,h,ct,z,v,bg,n,makeDL){
	if(is.ns4){
		if(n)var lyr=eval('d.layers.'+n+'.document.layers.'+id+'=new Layer('+w+',d.layers.'+n+')')
		else var lyr=d.layers[id]=new Layer(w)
		lyr.name=id
		lyr.left=l
		lyr.top=t
		if(h)lyr.clip.height=h
		if(ct){lyr.document.open();lyr.document.write(ct);lyr.document.close()}
		if(z)lyr.zIndex=z
		lyr.visibility=(v=='hidden')?'hide':'show'
		if(bg)lyr.bgColor=bg
	}
	else {
		if(n){
			index=n.lastIndexOf(".")
			var nestlyr=(index!=-1)?n.substr(index+1):n
		}
		if(is.dom){
			lyr=d.createElement('DIV')
			lyrS=lyr.style
			lyrS.position='absolute'
			lyrS.left=l+'px'
			lyrS.top=t+'px'
			if(w)lyrS.width=w+'px'
			if(h)lyrS.height=h+'px'
			else if(is.ie&&is.mac)lyrS.height='none'
			if(z)lyrS.zIndex=z
			if(v)lyrS.visibility=v
			if(bg)lyrS.backgroundColor=bg
			if(ct)lyr.innerHTML=ct+((is.ie&&is.mac)?'<span></span>':'')
			lyr.id=id
			if(n)d.getElementById(nestlyr).appendChild(lyr)
			else d.body.appendChild(lyr)
		}
		else{
			var S='\n<DIV id='+id+' style="position:absolute;left:'+l+';top:'+t
			if(w)S+=';width:'+w
			else S+=';width:1'
			if(h!=null)S+=';height:'+h
			if(z!=null)S+=';z-index:'+z
			if(v)S+=';visibility:'+v
			if(bg!=null)S+=';background:'+bg
			S+='">'+((ct)?ct:'')+'</DIV>'
			if(n)d.all[nestlyr].insertAdjacentHTML("BeforeEnd",S)
			else d.body.insertAdjacentHTML("BeforeEnd",S)
		}
	}
	if(makeDL)eval(id.substring(0,id.lastIndexOf('Div'))+'DL=new DL(\''+id+'\''+((n)?',\''+n+'\'':'')+')')
}


// Reloads the window if Nav4 resized

function BUG_ns4_reloadOnResize(){
	if(!d.pgW){d.pgW=innerWidth;d.pgH=innerHeight;onresize=BUG_ns4_reloadOnResize}
	else if(innerWidth!=d.pgW||innerHeight!=d.pgH)location.reload()
}
if(d.layers)BUG_ns4_reloadOnResize()


// Objects Constructor

var DOA=new Array()
function DO(parent){this.arguments=DO.caller.arguments;this.newDO=newDO;this.parent=parent;this.itens=new Array()}
function newDO(){return (this.itens)?this.itens[this.itens.length]=new DO(this):DOA[DOA.length]=new DO()}


// DynLayer
// Copyright 1999 Dan Steinman
// http://www.dansteinman.com/dynapi/

function DL(id,n1,n2){
	var T=this
	if(is.ns4){
		if(n1){
			if(n2)T.elm=d.layers[n2].document.layers[n1].document.layers[id]
			else T.elm=d.layers[n1].document.layers[id]
		}
		else T.elm=d.layers[id]
		T.css=T.elm
		T.doc=T.elm.document
		T.l=T.css.left
		T.t=T.css.top
		T.w=T.css.clip.width
		T.h=T.css.clip.height
	}
	else{
		T.elm=T.event=(is.ie4)?d.all[id]:d.getElementById(id)
		T.css=T.elm.style
		T.doc=document
		T.l=T.elm.offsetLeft
		T.t=T.elm.offsetTop
		T.w=T.elm.offsetWidth
		T.h=T.elm.offsetHeight
		if(!T.w)T.w=T.css.pixelWidth
		if(!T.h)T.h=T.css.pixelHeight
	}
	T.obj=id+'DL'
	eval(T.obj+'=T')
	T.sh=DLsh
	T.hd=DLhd
	T.mTo=DLmTo
	T.mBy=DLmBy
	T.rTo=DLrTo
	T.rBy=DLrBy
	T.write=DLwrite
}

function DLsh(){this.css.visibility=(is.ns4)?'show':'visible'}
function DLhd(){this.css.visibility=(is.ns4)?'hide':'hidden'}

function DLmTo(l,t){
	if(l!=null){
		this.l=l
		if(!is.ie)this.css.left=this.l
		else this.css.pixelLeft=this.l
	}
	if(t!=null){
		this.t=t
		if(!is.ie)this.css.top=this.t
		else this.css.pixelTop=this.t
	}
}
function DLmBy(l,t){this.mTo(this.l+l,this.t+t)}

function DLrTo(w,h){
	if(w!=null){
		this.w=w
		if(is.ns4)this.css.clip.width=this.w
		else this.css.width=this.w
	}
	if(h!=null){
		this.h=h
		if(is.ns4)this.css.clip.height=this.h
		else this.css.height=this.h
	}
}
function DLrBy(w,h){this.rTo(this.w+w,this.h+h)}

function DLwrite(S){
	if(is.ns4){this.doc.close();this.doc.open();this.doc.write(S);this.doc.close()}
	else this.elm.innerHTML=S
}

function convertSpaces(str, campo) {
var out = "", flag = 0;
for (i = 0; i < str.length; i++) {
if (str.charAt(i) != ",") {
out += str.charAt(i);
flag = 0;
}
else {
if(flag == 0) {
out += ".";
flag = 1;
      }
   }
}

if (campo == "1")
{
	document.frm.expr.value = out;
}
if (campo == "2")
{
	document.frm.expr2.value = out;
}
if (campo == "3")
{
	document.frm.expr3.value = out;
}

return "Calcular";
}

//Calculo do Primeiro campo
function calc(numero) {
if (document.frm.expr.value == "")
{
	return false;
}

if (numero < 0.0001 || 75 < numero)
{
	alert("Número inválido, por favor insira um número entre 0.0001 e 75.");
	document.frm.expr.focus;
	return false;
}
	if (document.frm.expr.focus){
		for (var i = 0; i < numero.length; i++) 
		{
			var ch = numero.substring(i, i + 1);
			if ((ch < "0" || "9" < ch)) 
			{
				if ((ch == ","))
				{

					alert("\Só aceita números.");
					document.frm.expr.focus;
					return false;
				}
			}
		}
		with(Math) {
			frm.result1.value=round((1.46734  - (0.0263554 * log10(numero)) - (0.0762669 * pow(log10(numero), 2)) - (0.168814 * pow(log10(numero), 3)))*100)/100;
			frm.result2.value=round((1.17388  - (0.0210843 * log10(numero)) - (0.0610135 * pow(log10(numero), 2)) - (0.135051 * pow(log10(numero), 3)))*100)/100;
			frm.result3.value=round((2.44557  - (0.0439257 * log10(numero)) - (0.127112 * pow(log10(numero), 2))  - (0.281356 * pow(log10(numero), 3)))*100)/100;
		}
	}
}
//Calculo do Segundo campo
function calc2(numero) {
if (document.frm.expr2.value == "")
{
	return false;
}

if (numero < 0.0001 || 75 < numero)
{
	alert("Número inválido, por favor insira um número entre 0.0001 e 75.");
	document.frm.expr.focus;
	return false;
}
	if (document.frm.expr2.focus){
		for (var i = 0; i < numero.length; i++) 
		{
			var ch = numero.substring(i, i + 1);
			if ((ch < "0" || "9" < ch)) 
			{
				if ((ch == ","))
				{

					alert("\Só aceita números.");
					document.frm.expr2.focus;
					return false;
				}
			}
		}
		with(Math) {
			frm.result4.value=round((0.711748 - (0.183856 * log10(numero)) - (0.0300907 * pow(log10(numero), 2)) - (0.0414608 * pow(log10(numero), 3)))*100)/100;
			frm.result5.value=round((0.569398 - (0.147085 * log10(numero)) - (0.0240726 * pow(log10(numero), 2)) - (0.0331686 * pow(log10(numero), 3)))*100)/100;
			frm.result6.value=round((1.18625  - (0.306427 * log10(numero)) - (0.0501512 * pow(log10(numero), 2)) - (0.0691013 * pow(log10(numero), 3)))*100)/100;
		}
	}
}
//Calculo do terceiro campo
function calc3(numero) {
if (document.frm.expr3.value == "")
{
	return false;
}
if (numero < 0.0001 || 75 < numero)
{
	alert("Número inválido, por favor insira um número entre 0.0001 e 75.");
	document.frm.expr.focus;
	return false;
}
	if (document.frm.expr3.focus){
		for (var i = 0; i < numero.length; i++) 
		{
			var ch = numero.substring(i, i + 1);
			if ((ch < "0" || "9" < ch)) 
			{
				if ((ch == ","))
				{

					alert("\Só aceita números.");
					document.frm.expr3.focus;
					return false;
				}
			}
		}
		
		with(Math) {
			frm.result7.value=round((0.452591 - (0.212061 * log10(numero)) + (0.0203056 * pow(log10(numero), 2)) - (0.0075936 * pow(log10(numero), 3)))*100)/100;
			frm.result8.value=round((0.362072 - (0.169649 * log10(numero)) + (0.0162445 * pow(log10(numero), 2)) - (0.0060749 * pow(log10(numero), 3)))*100)/100;
			frm.result9.value=round((0.754318 - (0.353435 * log10(numero)) + (0.0338426 * pow(log10(numero), 2)) - (0.012656 * pow(log10(numero), 3)))*100)/100;
		}
	}
}

function log10(numero) {
	return Math.log(numero) / Math.log(10);
}
 
function popup(url) {
	window.open(url,"contrate","left=0,width=430,height=400,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no");
}
function popup2(url) {
	window.open(url,"contrate","left=0,width=620,height=400,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no");
}
function popup3(url) {
	window.open(url,"imprimir","left=0,width=650,height=400,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no");
}
function popup4(url) {
	window.open(url,"gráfico2","left=0,width=610,height=340,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,menubar=no");
}
function popup5(url) {
	window.open(url,"gráfico1","left=0,width=410,height=300,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,menubar=no");
}
