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_showHideLayers()
{ //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function isNum(caractere)
{
	var strValidos = "0123456789";
	if (strValidos.indexOf(caractere) == -1 )
	{
		return false;
	}
	return true;
}

function validaTecla(campo, event)
{
	var BACKSPACE = 8, key, tecla, CheckTAB = true;
	if(navigator.appName.indexOf("Netscape")!= -1)
		tecla = event.which;
	else
		tecla = event.keyCode;
	key = String.fromCharCode(tecla);
	if (tecla == 13)
		return false;
	if (tecla == BACKSPACE)
		return true;
	return (isNum(key));
}

function destrava()
{
	var cor_lib='#00FFFF';
	with (document.form1)
	{
		text_ce.readOnly = false;
		text_ce.style.background = cor_lib;
		text_ce.focus();
		text_eg1.readOnly = false;
		text_eg1.style.background = cor_lib;
		text_eg2.readOnly = false;
		text_eg2.style.background = cor_lib;
		text_cce.readOnly = false;
		text_cce.style.background = cor_lib;
		text_d.readOnly = false;
		text_d.style.background = cor_lib;
		text_capacidade.readOnly = false;
		text_capacidade.style.background = cor_lib;
		text_cgca.readOnly = false;
		text_cgca.style.background = cor_lib;
		text_cga.readOnly = false;
		text_cga.style.background = cor_lib;
		text_ea.readOnly = false;
		text_ea.style.background = cor_lib;
		text_pa.readOnly = false;
		text_pa.style.background = cor_lib;
		text_cgc5.readOnly = false;
		text_cgc5.style.background = cor_lib;
	}
}

function trava()
{
	var cor_trav='#FFFFFF';
	with (document.form1)
	{
		text_ce.readOnly = true;
		text_ce.style.background = cor_trav;
		text_ce.focus();
		text_eg1.readOnly = true;
		text_eg1.style.background = cor_trav;
		text_eg2.readOnly = true;
		text_eg2.style.background = cor_trav;
		text_cce.readOnly = true;
		text_cce.style.background = cor_trav;
		text_d.readOnly = true;
		text_d.style.background = cor_trav;
		text_capacidade.readOnly = true;
		text_capacidade.style.background = cor_trav;
		text_cgca.readOnly = true;
		text_cgca.style.background = cor_trav;
		text_cga.readOnly = true;
		text_cga.style.background = cor_trav;
		text_ea.readOnly = true;
		text_ea.style.background = cor_trav;
		text_pa.readOnly = true;
		text_pa.style.background = cor_trav;
		text_cgc5.readOnly = true;
		text_cgc5.style.background = cor_trav;
	}
}

function vr(nerr, object1)
{
	var cfundo = '#FFFFC4', cfundo2='#FFFFFF';
	if(object1.value.length<1)
	{
		object1.style.background=cfundo;
		nerr++;
	}
	else
	{
		object1.style.background=cfundo2;
	}
	return nerr;
}

// verificação dos campos
function validar()
{
	var cfundo = '#FFFFC4', erros = 0;
	with (document.form1)
	{
		erros = vr(erros, text_ce);
		erros = vr(erros, text_eg1);
		erros = vr(erros, text_eg2);
		erros = vr(erros, text_cce);
		erros = vr(erros, text_d);
		erros = vr(erros, text_capacidade);
		erros = vr(erros, text_cgca);
		erros = vr(erros, text_cga);
		erros = vr(erros, text_ea);
		erros = vr(erros, text_pa);
		if(erros > 0)
		{
			alert('Informe os campos em evidência para que o cálculo possa ser efetuado!');
		}
		else
		{
			getCalcular();
		}
	}
}

// Funções para ajax:

function getModeloEmpilhadeira(valor)
{
	x_getModeloEmpilhadeira(valor, returnModeloEmpilhadeira);
}

function returnModeloEmpilhadeira(valor)
{
	document.getElementById('selecioneModeloEmpilhadeira').innerHTML = valor;
}

function getDadosEmpilhadeira(valor)
{
	document.getElementById('mostreMCE').innerHTML = "";
	document.getElementById('mostreMCG').innerHTML = "";
	document.getElementById('mostreMCA').innerHTML = "";
	eval("document.form1.text_ceq1.value='';");
	eval("document.form1.text_ceq2.value='';");
	eval("document.form1.text_ceq3.value='';");
	eval("document.form1.text_ceq4.value='';");
	eval("document.form1.text_ceq5.value='';");
	eval("document.form1.text_cre1.value='';");
	eval("document.form1.text_cre2.value='';");
	eval("document.form1.text_cre3.value='';");
	eval("document.form1.text_cre4.value='';");
	eval("document.form1.text_cre5.value='';");
	x_getDadosEmpilhadeira(valor, returnDadosEmpilhadeira);
}

function returnDadosEmpilhadeira(valor)
{
	var aux = '', aux2 = '', cont = 1, tamanho = valor.length;
	for (var i=0; i<=valor.length; i++)
	{
		if ((valor.charAt(i)==";") || (i==tamanho))
		{
			if (cont=="1")
				aux2 = aux;
			if (cont=="2")
				document.getElementById('marcaModeloEmpilhadeira').innerHTML = aux2 + " / " + aux;
			if (cont=="3")
				eval("document.form1.text_cce.value='"+aux+"';");
			if (cont=="4")
				eval("document.form1.text_ce.value='"+aux+"';");
			if (cont=="5")
				eval("document.form1.text_d.value='"+aux+"';");
			if (cont=="6")
				eval("document.form1.text_eg1.value='"+aux+"';");
			if (cont=="7")
				eval("document.form1.text_eg2.value='"+aux+"';");
			if (cont=="8")
				document.getElementById('mostreISO').innerHTML = aux;
			if (cont=="9")
				eval("document.form1.text_lg.value='"+aux+"';");
			if (cont=="10")
				eval("document.form1.text_hg.value='"+aux+"';");
			if (cont=="11")
				eval("document.form1.text_d1.value='"+aux+"';");
			if (cont=="12")
				eval("document.form1.text_d2.value='"+aux+"';");
			if (cont=="13")
				eval("document.form1.text_d3.value='"+aux+"';");
			aux = '';
			cont++;
		}
		else
		{
			aux += valor.charAt(i);
		}
	}
}

function getDadosEquipamento(valor)
{
	document.getElementById('mostreMCE').innerHTML = "";
	document.getElementById('mostreMCG').innerHTML = "";
	document.getElementById('mostreMCA').innerHTML = "";
	eval("document.form1.text_ceq1.value='';");
	eval("document.form1.text_ceq2.value='';");
	eval("document.form1.text_ceq3.value='';");
	eval("document.form1.text_ceq4.value='';");
	eval("document.form1.text_ceq5.value='';");
	eval("document.form1.text_cre1.value='';");
	eval("document.form1.text_cre2.value='';");
	eval("document.form1.text_cre3.value='';");
	eval("document.form1.text_cre4.value='';");
	eval("document.form1.text_cre5.value='';");
	x_getDadosEquipamento(valor, returnDadosEquipamento);
}

function returnDadosEquipamento(valor)
{
	var aux = '', aux = '', cont = 1, tamanho = valor.length;
	for (var i=0; i<=valor.length; i++)
	{
		if ((valor.charAt(i)==";") || (i==tamanho))
		{
			if (cont=="1")
				aux2 = aux;
			if (cont=="2")
				document.getElementById('nomeModeloEquipamento').innerHTML = aux2 + " / " + aux;
			if (cont=="3")
				eval("document.form1.text_pa.value='"+aux+"';");
			if (cont=="4")
				eval("document.form1.text_cga.value='"+aux+"';");
			if (cont=="5")
				eval("document.form1.text_ea.value='"+aux+"';");
			if (cont=="6")
				eval("document.form1.text_cgc1.value='"+aux+"';");
			if (cont=="7")
				eval("document.form1.text_cgc2.value='"+aux+"';");
			if (cont=="8")
				eval("document.form1.text_cgc3.value='"+aux+"';");
			if (cont=="9")
				eval("document.form1.text_cgc4.value='"+aux+"';");
			if (cont=="10")
				eval("document.form1.text_capacidade.value='"+aux+"';");
			if (cont=="11")
				eval("document.form1.text_cgca.value='"+aux+"';");
			aux = '';
			cont++;
		}
		else
		{
			aux += valor.charAt(i);
		}
	}	
}

function getCalcular()
{
	ce = document.form1.text_ce.value;
	cce = document.form1.text_cce.value;
	cga = document.form1.text_cga.value;
	cgca = document.form1.text_cgca.value;
	d = document.form1.text_d.value;
	d1 = document.form1.text_d1.value;
	d2 = document.form1.text_d2.value;
	d3 = document.form1.text_d3.value;
	eg1 = document.form1.text_eg1.value;
	eg2 = document.form1.text_eg2.value;
	hg = document.form1.text_hg.value;
	lg = document.form1.text_lg.value;
	pa = document.form1.text_pa.value;
	ea = document.form1.text_ea.value;
	cgc1 = document.form1.text_cgc1.value;
	cgc2 = document.form1.text_cgc2.value;
	cgc3 = document.form1.text_cgc3.value;
	cgc4 = document.form1.text_cgc4.value;
	cgc5 = document.form1.text_cgc5.value;
	capacidade = document.form1.text_capacidade.value;
	x_getCalcular(cce,d,d1,d2,ce,eg1,eg2,hg,lg,cga,d3,pa,ea,cgc1,cgc2,cgc3,cgc4,cgc5,capacidade,cgca, returnCalcular);
}

function returnCalcular(valor)
{
	var aux = '', cont = 1, tamanho = valor.length, verde = "#008000", vermelho = "#FF2424";
	for (var i=0; i<=valor.length; i++)
	{
		if ((valor.charAt(i)==";") || (i==tamanho))
		{
			if (cont=="1")
			{
				document.getElementById('mostreMCE').innerHTML = "<strong>M.Empilhadeira: </strong>"+aux;
			}
			if (cont=="2")
			{
				document.getElementById('mostreMCG').innerHTML = "<strong>M.Garfos: </strong>"+aux;
			}
			if (cont=="3")
			{
				document.getElementById('mostreMCA').innerHTML = "<strong>M.Equipamento: </strong>"+aux;
			}
			if (cont=="4")
			{
				eval("document.form1.text_cre1.value='"+aux+"';");
			}
			if (cont=="5")
			{
				eval("document.form1.text_cre2.value='"+aux+"';");
			}
			if (cont=="6")
			{
				eval("document.form1.text_cre3.value='"+aux+"';");
			}
			if (cont=="7")
			{
				eval("document.form1.text_cre4.value='"+aux+"';");
			}
			if (cont=="8")
			{
				eval("document.form1.text_ceq1.value='"+aux+"';");
				eval("document.form1.text_ceq1.style.color='"+verde+"';");
			}
			if (cont=="9")
			{
				eval("document.form1.text_ceq2.value='"+aux+"';");
				eval("document.form1.text_ceq2.style.color='"+verde+"';");
			}
			if (cont=="10")
			{
				eval("document.form1.text_ceq3.value='"+aux+"';");
				eval("document.form1.text_ceq3.style.color='"+verde+"';");
			}
			if (cont=="11")
			{
				eval("document.form1.text_ceq4.value='"+aux+"';");
				eval("document.form1.text_ceq4.style.color='"+verde+"';");
			}
			if (cont=="12")
			{
				eval("document.form1.text_cre5.value='"+aux+"';");
			}
			if (cont=="13")
			{
				eval("document.form1.text_ceq5.value='"+aux+"';");
				eval("document.form1.text_ceq5.style.color='"+verde+"';");
			}
			if (cont=="14")
			{
				if (aux=="vermelho")
				{
					eval("document.form1.text_cre1.style.color='"+vermelho+"';");
				}
				if (aux=="verde")
				{
					eval("document.form1.text_cre1.style.color='"+verde+"';");
				}
			}
			if (cont=="15")
			{
				if (aux=="vermelho")
				{
					eval("document.form1.text_cre2.style.color='"+vermelho+"';");
				}
				if (aux=="verde")
				{
					eval("document.form1.text_cre2.style.color='"+verde+"';");
				}
			}
			if (cont=="16")
			{
				if (aux=="vermelho")
				{
					eval("document.form1.text_cre3.style.color='"+vermelho+"';");
				}
				if (aux=="verde")
				{
					eval("document.form1.text_cre3.style.color='"+verde+"';");
				}
			}
			if (cont=="17")
			{
				if (aux=="vermelho")
				{
					eval("document.form1.text_cre4.style.color='"+vermelho+"';");
				}
				if (aux=="verde")
				{
					eval("document.form1.text_cre4.style.color='"+verde+"';");
				}
			}
			if (cont=="18")
			{
				if (aux=="vermelho")
				{
					eval("document.form1.text_cre5.style.color='"+vermelho+"';");
				}
				if (aux=="verde")
				{
					eval("document.form1.text_cre5.style.color='"+verde+"';");
				}
			}
			aux = '';
			cont++;
		}
		else
		{
			aux += valor.charAt(i);
		}
	}
	//window.alert(valor);
}