function cambio(src, trg) { 
  trg.value = valida.Redondeo(eval(src.options[src.selectedIndex].value),4);
}

/************************/
function Calculos(forma) {
  this.forma 		= eval(forma);
  this.roll_off		= "";
  this.vel_simb 	= "";
  this.reed_solomon	= "";
  this.vel_trans	= "";
  this.vel_info		= "";
  this.modulacion	= "";
  this.ancho_banda	= "";
  this.seleccion	= "";

  this.get_roll_off 	= get_roll_off;
  this.set_roll_off	= set_roll_off;
  this.get_vel_trans	= get_vel_trans;
  this.set_vel_trans	= set_vel_trans;
  this.get_vel_info	= get_vel_info;
  this.set_vel_info	= set_vel_info;
  this.get_vel_simb	= get_vel_simb;
  this.set_vel_simb	= set_vel_simb;
  this.get_reed_solomon = get_reed_solomon;
  this.set_reed_solomon = set_reed_solomon;
  this.reed_solomon_checked = reed_solomon_checked;
  this.get_fec		= get_fec;
  this.set_fec		= set_fec;
  this.get_modulacion	= get_modulacion;
  this.set_modulacion	= set_modulacion;
  this.get_ancho_banda	= get_ancho_banda;
  this.set_ancho_banda	= set_ancho_banda;
  this.get_seleccion	= get_seleccion;

  this.chg_vel_trans    = chg_vel_trans;
  //this.chg_vel_info	= chg_vel_info;
  //this.chg_roll_off	= chg_roll_off;
}

function get_seleccion() {
  for (m=0;m<this.forma.seleccion.length;m++) {
    if (this.forma.seleccion[m].checked) return m;
  }
}
function get_roll_off() {
  return this.roll_off;
}
function set_roll_off(valor) {
   if (valor <= 512) roll_off = 51;
   else roll_off = 40;
  this.roll_off = roll_off/100;
}
function get_vel_trans() {
  return this.vel_trans;
}
function set_vel_trans() {
  reed_solomon = this.get_reed_solomon();
  vel_info = this.get_vel_info();
  fec = this.get_fec();
  modulacion = this.get_modulacion();
  roll_off = this.get_roll_off();
  ancho_banda = this.get_ancho_banda();
  seleccion = this.get_seleccion();
  if(seleccion==0) vel_trans = ancho_banda / (modulacion * (1 + roll_off));
  if(seleccion==1) vel_trans = vel_info / (fec * reed_solomon);
  if(seleccion==2) vel_trans = this.forma.vel_trans.value;
  if(seleccion==3) vel_trans = vel_simb / modulacion;
  this.vel_trans=vel_trans;
}
function get_vel_info() {
  return this.vel_info;
}
function set_vel_info() {
  reed_solomon = this.get_reed_solomon();
  vel_trans = this.get_vel_trans();
  vel_simb = this.get_vel_simb();
  fec = this.get_fec();
  modulacion = this.get_modulacion();
  roll_off = this.get_roll_off();
  ancho_banda = this.get_ancho_banda();
  seleccion = this.get_seleccion();
  if(seleccion==0) vel_info = ancho_banda / ((1 + roll_off) * modulacion) * (fec * reed_solomon);
  if(seleccion==1) vel_info = this.forma.vel_info.value;
  if(seleccion==2) vel_info = vel_trans * fec * reed_solomon;
  if(seleccion==3) vel_info = vel_simb / modulacion * (fec * reed_solomon);
  
  this.vel_info=vel_info;
}
function get_reed_solomon() {
  return this.reed_solomon;
}
function set_reed_solomon() {
  if (this.reed_solomon_checked()) this.reed_solomon=188/204;
  else this.reed_solomon=1;  
}
function reed_solomon_checked() {
  if (this.forma.reed_check.checked) return true;
  return false;
}
function get_fec() {
  return this.fec;
}
function set_fec() {
  this.fec = this.forma.fec.value;
}
function get_modulacion() {
  return this.modulacion;
}
function set_modulacion() {
  this.modulacion = this.forma.fac_mod.value;
}
function set_vel_simb() {
  reed_solomon = this.get_reed_solomon();
  vel_info = this.get_vel_info();
  vel_trans = this.get_vel_trans();
  fec = this.get_fec();
  modulacion = this.get_modulacion();
  roll_off = this.get_roll_off();
  ancho_banda = this.get_ancho_banda();
  seleccion = this.get_seleccion();
  if(seleccion==0) vel_simb = ancho_banda / (1 + roll_off);
  if(seleccion==1) vel_simb = vel_info / (fec * reed_solomon) * modulacion;
  if(seleccion==2) vel_simb = vel_trans * modulacion;
  if(seleccion==3) vel_simb = this.forma.vel_simbolos.value;
 
  this.vel_simb = vel_simb;
}

function get_vel_simb() {
  return this.vel_simb;
}

function set_ancho_banda() {
  reed_solomon = this.get_reed_solomon();
  vel_info = this.get_vel_info();
  fec = this.get_fec();
  modulacion = this.get_modulacion();
  roll_off = this.get_roll_off();
  ancho_banda = this.get_ancho_banda();
  seleccion = this.get_seleccion();
  vel_simb = this.get_vel_simb();
  vel_trans = this.get_vel_trans();
  if(seleccion==0) ancho_banda = this.forma.ancho_banda.value;
  if(seleccion==1) ancho_banda = (vel_info / (fec * reed_solomon) * modulacion) * (1 + roll_off);
  if(seleccion==2) ancho_banda = vel_trans * modulacion * (1 + roll_off);
  if(seleccion==3) ancho_banda = vel_simb * (1 + roll_off);

  this.ancho_banda = ancho_banda;
}
function get_ancho_banda() {
  return this.ancho_banda;
}

function chg_rool_off(obj1, obj2) {
  obj1=eval(this.forma+"obj1");
  obj2=eval(this.forma+"obj2");
  valor = eval(obj1.options[obj1.selectedIndex].value);
  roll_off = this.get_roll_off();
  roll_off = roll_off * 100;
  this.set_roll_off(roll_off);
  obj2.value = this.get_roll_off();
}

function chg_vel_trans(trg) {
  vel_info = get_vel_info();
  fec = get_fec();
  vel_trans = get_vel_trans(vel_info, fec);
  trg.value = vel_trans;
}

function chg_vel_simb(trg) {
  vel_simb = this.get_vel_simb();
  trg.value = vel_simb;
}

/***************************/
function Azim_Dist(forma) {
  this.forma = forma;
  this.latitude = 0;
  this.longitud = 0;
  this.longitud_sat = 0;
  this.azimuth = 0;
  this.elevacion = 0;
  this.distancia = 0;
  this.gamma = 0;
  this.delta = 0;
  this.A = 0;
  this.Pi = 3.1416;
  this.D = 42164.2
  this.r = 6378.155;

  this.set_latitude = set_latitude;
  this.get_latitude = get_latitude;
  this.set_longitud = set_longitud;
  this.get_longitud = get_longitud;
  this.set_longitud_sat = set_longitud_sat;
  this.get_longitud_sat = get_longitud_sat;
  this.set_azimuth = set_azimuth;
  this.get_azimuth = get_azimuth;
  this.set_elevacion = set_elevacion;
  this.get_elevacion = get_elevacion;
  this.set_distancia = set_distancia;
  this.get_distancia = get_distancia;  
  this.set_gamma = set_gamma;
  this.get_gamma = get_gamma;
  this.set_delta = set_delta;
  this.get_delta = get_delta;
  this.set_A = set_A;
  this.get_A = get_A; 
}
  function set_latitude() {
    this.latitude = this.forma.latitud.value;
  }
  function get_latitude() {
    return this.latitude;
  }
  function set_longitud() {
    this.longitud = this.forma.longitud.value;
  }
  function get_longitud() {
    return this.longitud;
  }
  function set_longitud_sat() {
    this.longitud_sat = this.forma.longitud2.value;
  }
  function get_longitud_sat() {
    return this.longitud_sat;
  }
  function set_azimuth() {
    A = this.A;
    lat  = this.get_latitude();
    longitud_sat  = this.get_longitud_sat();
    longitud  = this.get_longitud();
   if (lat > 0) {
    if (parseInt(longitud) > parseInt(longitud_sat)) 
      azimuth = 180 - A;
    else
      azimuth = 180 + A;
   }
   else {
    if (parseInt(longitud) > parseInt(longitud_sat)) 
      azimuth = A;
    else
      azimuth = 360 - A;
   }
   this.azimuth = azimuth;
  }
  function get_azimuth() {
    return this.azimuth;
  }
  function set_elevacion() {
    delta=this.get_delta();
    gamma=this.get_gamma();
    this.elevacion=delta-gamma;
  }
  function get_elevacion() {
    return this.elevacion;
  }
  function set_distancia() {
    D = this.D;
    r = this.r;
    elevacion = this.get_elevacion();
    distancia_sat = Math.sqrt(Math.pow(D,2) + Math.pow(r,2) - (2 * D * r * Math.sin(Rad(elevacion) + Math.asin(r/D) * Math.cos(Rad(elevacion))))) * Math.pow(10,3);
    this.distancia = distancia_sat;
  }
  function get_distancia() {
    return this.distancia;
  }
  function set_gamma() {
    Pi=this.Pi;
    lat  = this.get_latitude();
    longitud_sat  = this.get_longitud_sat();
    longitud  = this.get_longitud();
    gamma = Deg(Math.acos(Math.cos(Rad(lat)) * Math.cos(Math.abs(Rad(longitud_sat) - Rad(longitud)))));
    this.gamma = gamma;
  }
  function get_gamma() {
    return this.gamma;
  }
  function set_delta(){
    Pi = this.Pi;
    D = this.D;
    r = this.r;
    gamma=this.get_gamma();
    delta = Deg(Math.atan((D - r * Math.cos(Rad(gamma))) / (r * Math.sin(Rad(gamma)))));
    this.delta = delta;
  }
  function get_delta(){
    return this.delta;
  }
  function set_A() {
    lat  = this.get_latitude();
    longitud_sat  = this.get_longitud_sat();
    longitud  = this.get_longitud();
    A = Deg(Math.atan(Math.tan(Math.abs(Rad(longitud_sat) - Rad(longitud))) / Math.sin(Math.abs(Rad(lat)))));
    this.A = A;
  }
  function get_A() {
    return this.A;
  }
  function Rad(Degrees) {
    Pi=this.Pi;
    Radianes = Degrees * Pi / 180;
    return Radianes;
  }
  function Deg(Radians) {
    Pi=this.Pi;
    Degrees = Radians * 180 / Pi;
    return Degrees;
  }


/***************************/
