// JavaScript Document

function showBox(a) {
	document.getElementById(a).style.visibility='visible';
}

function hideBox(a) {
	document.getElementById(a).style.visibility='hidden';
}

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_clearField(theField) { //v1.0
  varObj = MM_findObj(theField)
  varObj.value="";
}

function clearTxt(id) {
	document.getElementById(id).value="";
}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser una direccion de email valida.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' debe ser unicamente numeros.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; 
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
    } if (errors) alert('Se presentan los siguientes errores:\n'+errors);
    document.MM_returnValue = (errors == '');
} }


function calcular()
	{
		if (document.fcalc.largo.value=="")
			{
		    	alert('Ingrese el Largo por favor');
				return;
			}
		if (document.fcalc.ancho.value=="")
			{
		    	alert('Ingrese el Ancho por favor');
				return;
			}
		if (document.fcalc.alto.value=="")
			{
		    	alert('Ingrese el Alto por favor');
				return;
			}
		if (document.fcalc.peso.value=="")
			{
		    	alert('Ingrese el Peso por favor');
				return;
			}
		if (isNaN(document.fcalc.alto.value))
			{
				alert('Error en datos de entrada');
				document.fcalc.alto.focus();
				return;
			}
		if (isNaN(document.fcalc.ancho.value))
			{
				alert('Error en datos de entrada');
				document.fcalc.ancho.focus();
				return;
			}
		if (isNaN(document.fcalc.largo.value))
			{
				alert('Error en datos de entrada');
				document.fcalc.largo.focus();
				return;
			}
		if (isNaN(document.fcalc.peso.value))
			{
				alert('Error en datos de entrada');
				document.fcalc.peso.focus();
				return;
			}
		if (isNaN(document.fcalc.peso.value))
			{
				alert('Error en el peso');
				document.fcalc.peso.focus();
				return;
			}
		var r1=document.fcalc.largo.value*document.fcalc.ancho.value*document.fcalc.alto.value;
		if (document.fcalc.tipo.value==0)
			{
				var pc=r1/1728;
				document.fcalc.total.value='Los Pies Cubicos de su envio Maritimo son de '+(pc);
			}
		if (document.fcalc.tipo.value==1)
			{
				var libvol=r1/166;
				if (libvol>document.fcalc.peso.value)
					{
						document.fcalc.total.value='Para el envio aereo debe tomar en cuenta las Libras volumetricas las cuales son '+(libvol);
					}
				if (libvol<document.fcalc.peso.value)
					{
						document.fcalc.total.value='Para el envio aereo debe tomar en cuenta las Libras en peso las cuales son '+(document.fcalc.peso.value);
					}
			}
	}
