window.addEvent('domready', function() {
	// variable for the list status
	var listStatus = 'closed';
	// setup var that holds our opened list's id
	var listOpen;
	
	var hideDelay;

	// show list function
	var showList = function(lid) {
		$clear(hideDelay);
		var listId = lid.replace(/For/g, '');
		// need to check if there is an open list
		if (listStatus == 'open') {
			// check if the open list is the same
			// as toggled list. If not, then we hide it
			if (listId != listOpen) {
				hideList();
			}
		} 
		if (listStatus == 'closed') {
			// set our list status
			listStatus = 'open';
			// set the curent open list id
			listOpen = listId;
			// show our list with a little effects
			/*
			new Fx.Style(listOpen, 'opacity', {duration: 500}).custom(0, 1);
			new Fx.Style(listOpen, 'height', {duration: 300}).custom(20, 40);
			new Fx.Style(listOpen, 'width', {duration: 300}).custom(20, 131);
			*/
			$(listOpen).setStyle('visibility', 'visible');
			// we add a timeout so the sublist goes away
			// if the user doesn't click/mouseover another 
			// menu item
			//hideDelay = (hideList).delay(15000);
		}
	};
	
	// hide list function
	var hideList = function() {
		$clear(hideDelay);
		/*
		menu = $$('a.navbutton');
		total = menu.length;
		for (i=0; i<total;i++) {
			item = menu[i];
			if (item.hasClass('hasSubNav')) {
				var listOpen = item.id.replace(/For/g, '');
				if($(listOpen).getStyle('visibility') == 'visible') {
			    	$(listOpen).setStyle('visibility', 'hidden');
				}
				// set our list status
				listStatus = 'closed';
				// reset open list id
				listOpen = '';
			}
		}
		*/
		
		if (listOpen) {
			// check if our list is shown already - if so run the effects to hide list
			if($(listOpen).getStyle('visibility') == 'visible') {
				$(listOpen).setStyle('visibility', 'hidden');
				/*
			    new Fx.Style(listOpen, 'opacity', {duration: 500}).custom(1, 0);
			    new Fx.Style(listOpen, 'height', {duration: 300}).custom(40, 20);
			    new Fx.Style(listOpen, 'width', {duration: 300}).custom(131,20);
				*/
			}
			// set our list status
			listStatus = 'closed';
			// reset open list id
			listOpen = '';
		}
	};
	
	$$('a.navbutton').addEvent('mouseover', function(){
		hideList();													 
	    oImage = this.getFirst();
	    // add mouseover action to change image
		oImage.src = oImage.src.replace(/_off/g, '_on');
		// optional effect for mouseover
		this.effect('opacity').custom(.3,1);
		// check if element has our flag for having a drop menu
		if (this.hasClass('hasSubNav')) {
		    var listId = this.id.replace(/For/g, '');
			// have to do it this way.
			// for some reason this.firstChild.getTag() won't work
			var yOffset = oImage.height + 1;
			// set the styles of your list
			// to position it (relatively) correctly
			$(listId).setStyles({
			    top: oImage.getTop() + yOffset,
			    left: oImage.getLeft()
			});
		    // pass the id of the mouseover, so we can determine 
			// which list to show
			showList(this.id);
			hideDelay = (hideList).delay(3000);
		} else {
			// if the button moused over does not have a list
			// then we close the list since we are obviously
			// on another button now
			if (listStatus == 'open') {
				hideList();
			}
		}
	});
	
	$$('a.navbutton').addEvent('mouseout', function(){
	    oImage = this.getFirst();
	    // switch mouseout button
		oImage.src = oImage.src.replace(/_on/g,'_off');
		// optional effect for mouseout
		this.effect('opacity').custom(.3,1);
	});
	
	$$('.subNav a').addEvent('mouseover', function(){
		$clear(hideDelay);
	});
	
	$$('.subNav a').addEvent('mouseout', function(){
		hideDelay = (hideList).delay(1000);
	});

});

function openWindow(theURL, winName, features) {
  window.open(theURL, winName, features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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 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_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 calculo_peso() {
	calculo = "peso";
	if ($('peso_opaco').getProperty('checked') == true) {
		peso_tipo = "opaco";
	}
	if ($('peso_transparente').getProperty('checked') == true) {
		peso_tipo = "transparente";
	}
	peso_largura =  $('peso_largura').getProperty('value');
	peso_diametro_interno =  $('peso_diametro_interno').getProperty('value');
	peso_diametro_externo =  $('peso_diametro_externo').getProperty('value');
	peso_quantidade =  $('peso_quantidade').getProperty('value');
	if (peso_tipo && peso_largura && peso_diametro_interno && peso_diametro_externo && peso_quantidade) {
		$('peso_peso').setHTML("Calculando");
		url = "calculo.asp";
		querystring = {
			"calculo": calculo,
			"tipo": peso_tipo,
			"largura":peso_largura,
			"diametro_interno":peso_diametro_interno,
			"diametro_externo":peso_diametro_externo,
			"quantidade":peso_quantidade
		};
  		new Ajax(url, {
			method: 'get',
			data: querystring,
			update: $('peso_peso')
		}).request();

	} else {
		alert("Você deve preencher todos os campos para calcular o peso.");
	}
}

function calculo_diametro() {
	calculo = "diametro";
	if ($('diametro_opaco').getProperty('checked') == true) {
		diametro_tipo = "opaco";
	}
	if ($('diametro_transparente').getProperty('checked') == true) {
		diametro_tipo = "transparente";
	}
	diametro_largura =  $('diametro_largura').getProperty('value');
	diametro_diametro_interno =  $('diametro_diametro_interno').getProperty('value');
	diametro_peso =  $('diametro_peso').getProperty('value');
	if (diametro_tipo && diametro_largura && diametro_diametro_interno && diametro_peso) {
		$('diametro_diametro').setHTML("Calculando");
		url = "calculo.asp";
		querystring = {
			"calculo": calculo,
			"tipo": diametro_tipo,
			"largura":diametro_largura,
			"diametro_interno":diametro_diametro_interno,
			"peso":diametro_peso
		};
  		new Ajax(url, {
			method: 'get',
			data: querystring,
			update: $('diametro_diametro')
		}).request();

	} else {
		alert("Você deve preencher todos os campos para calcular o diâmetro.");
	}
}

function calculo_quantidade() {
	calculo = "quantidade";
	if ($('quantidade_opaco').getProperty('checked') == true) {
		quantidade_tipo = "opaco";
	}
	if ($('quantidade_transparente').getProperty('checked') == true) {
		quantidade_tipo = "transparente";
	}
	quantidade_largura =  $('quantidade_largura').getProperty('value');
	quantidade_diametro_interno =  $('quantidade_diametro_interno').getProperty('value');
	quantidade_diametro_externo =  $('quantidade_diametro_externo').getProperty('value');
	quantidade_peso =  $('quantidade_peso').getProperty('value');
	if (quantidade_tipo && quantidade_largura && quantidade_diametro_interno && quantidade_diametro_externo && quantidade_peso) {
		$('quantidade_quantidade').setHTML("Calculando");
		url = "calculo.asp";
		querystring = {
			"calculo": calculo,
			"tipo": quantidade_tipo,
			"largura":quantidade_largura,
			"diametro_interno":quantidade_diametro_interno,
			"diametro_externo":quantidade_diametro_externo,
			"peso":quantidade_peso
		};
  		new Ajax(url, {
			method: 'get',
			data: querystring,
			update: $('quantidade_quantidade')
		}).request();

	} else {
		alert("Você deve preencher todos os campos para calcular a quantidade.");
	}
}

function calculo_comprimento() {
	calculo = "comprimento";
	comprimento_espessura =  $('comprimento_espessura').getProperty('value');
	comprimento_diametro_interno =  $('comprimento_diametro_interno').getProperty('value');
	comprimento_diametro_externo =  $('comprimento_diametro_externo').getProperty('value');
	if (comprimento_espessura && comprimento_diametro_interno && comprimento_diametro_externo) {
		$('comprimento_comprimento').setHTML("Calculando");
		url = "calculo.asp";
		querystring = {
			"calculo": calculo,
			"espessura":comprimento_espessura,
			"diametro_interno":comprimento_diametro_interno,
			"diametro_externo":comprimento_diametro_externo
		};
  		new Ajax(url, {
			method: 'get',
			data: querystring,
			update: $('comprimento_comprimento')
		}).request();

	} else {
		alert("Você deve preencher todos os campos para calcular o comprimento.");
	}
}