// JavaScript Document


function validateContactForm(frm){
	var todo=true;//se mantiene true si todos los campos estan correctos
	var msg="";

  var nombre = frm.nombre.value;
  var apellido = frm.apellido.value;
  var direccion = frm.direccion.value;
  var email = frm.email.value;
  var consulta = frm.consulta.value;
  
  if(!validateNotEmpty(nombre)){	
     todo=false;
	 msg += "Introduzca su nombre\n";
  }
  
   if(!validateNotEmpty(apellido)){	
     todo=false;
	 msg += "Introduzca su apellido\n";
  }
  if(!validateNotEmpty(direccion)){	
     todo=false;
	 msg += "Introduzca su direccion\n";
  }
  
  if(!validateNotEmpty(email)){	
     todo=false;
	 msg += "Introduzca su email\n";
  }
  else if(!validateEmail(email)){
	 todo=false;
	 msg += "El formato del email esta incorrecto\n";
  }
  if(!validateNotEmpty(consulta)){	
     todo=false;
	 msg += "Introduzca su comentario\n";
  }
   
  
  if(todo==false)
	window.alert(msg);  
	
  return todo;
}


function validateCuentaForm(frm){
	var todo=true;//se mantiene true si todos los campos estan correctos
	var msg="";

  var username = frm.username.value;
  var firstname = frm.firstname.value;
  var lastname = frm.lastname.value;
  var empresa = frm.empresa.value;
  var cargo = frm.cargo.value;
  var tel = frm.tel.value;
  var fax = frm.fax.value;
  var pais = frm.pais.value;
  var ciudad = frm.ciudad.value;
  var direccion = frm.direccion.value;
  
  var email = frm.email.value;


  
  if(!validateNotEmpty(username)){	
     todo=false;
	 msg += "Introduzca el username\n";
  }
   if(!validateNotEmpty(firstname)){	
     todo=false;
	 msg += "Introduzca su nombre\n";
  }
   if(!validateNotEmpty(lastname)){	
     todo=false;
	 msg += "Introduzca su apellido\n";
  }
   if(!validateNotEmpty(empresa)){	
     todo=false;
	 msg += "Escriba el nombre de la empresa\n";
  }
   if(!validateNotEmpty(cargo)){	
     todo=false;
	 msg += "Escriba el cargo que ocupa en esa empresa\n";
  }
   if(!validateNotEmpty(tel)){	
     todo=false;
	 msg += "Introduzca el teléfono\n";
  }
   if(!validateNotEmpty(fax)){	
     todo=false;
	 msg += "Introduzca el fax\n";
  }
   if(pais=="0"){	
     todo=false;
	 msg += "Escoja el país\n";
  }
   if(!validateNotEmpty(ciudad)){	
     todo=false;
	 msg += "Introduzca la ciudad\n";
  }
   if(!validateNotEmpty(direccion)){	
     todo=false;
	 msg += "Escriba su dirección\n";
  }
  
  if(!validateNotEmpty(email)){	
     todo=false;
	 msg += "Introduzca su email\n";
  }
  else if(!validateEmail(email)){
	 todo=false;
	 msg += "El formato del email esta incorrecto\n";
  }
  
  var passwd = frm.passwd.value
		var passwd2 = frm.passwd2.value 
		
		if(!isEmpty(passwd) || !isEmpty(passwd2)) {
				if(passwd!=passwd2) {
						//alert ("Las Contraseñas no Cinciden") ;
						msg += "Las Contraseñas no Cinciden";
						frm.passwd.focus () ;
				}
		}		

   
  
  if(todo==false)
	window.alert(msg);  
	
  return todo;
}

//Función que limpia las casillas
function clearCasilla(frm){
	  frm.fob.value="";
	  frm.flete.value="";
}

//Función que redondea un numero a 2 decimales
function redondear(num){
  return Math.round(num*100)/100;	
}

//Función que calcula la suma asegurada
function getTotalAse(frm){
	var fob=0.00;
	var flete=0.00;
	if(validateNumeric(frm.fob.value)){
	  fob = parseFloat(frm.fob.value);
	  flete = parseFloat(frm.flete.value);
     
	  var total = fob + (fob*(flete/100));
	  total=redondear(total);
	  frm.total_asegurada.value=total;
	}
	else if(!validateNotEmpty(frm.fob.value)){
		frm.total_asegurada.value="";
	}
}

//Función que calcula el total de tarifa
function getTarifa(frm){
   var tarifa=0.00;
   var prima=0.00;
   var itbm=0.00;
   if(validateNumeric(frm.tarifa.value)&&validateNumeric(frm.prima.value)){
	   tarifa=parseFloat(frm.tarifa.value);
	   prima=parseFloat(frm.prima.value);
	   //Se calcula el 5% de la tarifa
	   frm.itbm.value=(tarifa*0.05);
	   itbm=parseFloat(frm.itbm.value);
	   var total = tarifa + (tarifa*(prima/100))+itbm;
	   total=redondear(total);
	  frm.total.value=total;
   }
   else if(!validateNotEmpty(frm.tarifa.value)||!validateNotEmpty(frm.prima.value)){
	     frm.total.value="";
		 //frm.prima.value="";
   }
}
