// JavaScript Descriptiva

var mi=0; 
var ci=0;
var ti=0;
var di=0;
var gi=0;
var ao=0;
var bo=0;
var co=0;
var fo=0;
var bc=0;
var cc=0;
var dc=0;
var ds=0;
var pi=0;
var ui=0;
var mo=0;
var so=0;
var ar=0;

function ClearForm(form){
   form.xi.value="";
   form.ni.value="";
   form.mi=0;
   form.ci=0;
   form.ti=0;
   form.di=0;
   form.gi=0;
   form.ao=0;
   form.bo=0;
   form.co=0;
   form.fo=0;
   form.bc=0;
   form.cc=0;
   form.dc=0;
   form.ds=0;
   form.pi=0;
   form.ui=0;
   form.mo=0;
   form.so=0;
   form.ar=0;
   form.result.value="";
   form.result1.value="";
   form.result2.value="";
   form.result3.value="";
   form.result4.value="";
   form.result5.value="";
   form.result6.value="";
   form.result7.value="";
   form.result8.value="";
   form.result9.value="";
   

}


function checkNum(toCheck) {
  var isNum=true;
  if ((toCheck == null) || (toCheck == "")){
  return isNum;
}

for (j=0; j < toCheck.length; j++){
  if ((toCheck.substring(j,j+1) !="0") &&
      (toCheck.substring(j,j+1) !="1") &&
      (toCheck.substring(j,j+1) !="2") &&
      (toCheck.substring(j,j+1) !="3") &&
      (toCheck.substring(j,j+1) !="4") &&
      (toCheck.substring(j,j+1) !="5") &&
      (toCheck.substring(j,j+1) !="6") &&
      (toCheck.substring(j,j+1) !="7") &&
      (toCheck.substring(j,j+1) !="8") &&
      (toCheck.substring(j,j+1) !="9") &&
      (toCheck.substring(j,j+1) !=".") &&
      (toCheck.substring(j,j+1) !="-")) {
    isNum=false;
  }
}

return isNum;
 
}

function checkFieldNum(field){
  if (!checkNum(field.value)) {
   alert("­Por favor introduzca un numero en el campo!");
  }
}
function checkFormNum(form) {
  var isNum=true;

  for (field=0; field<=1; field ++){
    if(!checkNum(form.elements[field].value)) {
      isNum=false;
    }
  }
  
  if (!isNum) {
    alert("­Deben de estar introducidos ambos periodos!");
  }

  return isNum;
}

function calculate(form){



   if (checkFormNum(form)) {
    with(form) {
    mi=(eval(xi.value) * eval(ni.value)) + eval (mi);
    ui=(eval(mi) + eval(ui));
    ci=(eval(xi.value) * eval(xi.value) * eval(ni.value)) + eval(ci);
    ti=(eval(xi.value) * eval(xi.value) * eval(xi.value) * eval(ni.value)) + eval(ti);
    di=(eval(xi.value) * eval(xi.value) * eval(xi.value) * eval(xi.value) * eval(ni.value)) + eval(di);
    gi=(eval(ni.value)) + (eval(gi));
    pi=(eval(gi) + eval(pi));
    ar=(1 / eval(xi.value)) * eval(ni.value) + eval(ar);
    ao=(eval(mi)) / (eval(gi));
    bo=(eval(ci)) / (eval(gi));
    co=(eval(ti)) / (eval(gi));
    fo=(eval(di)) / (eval(gi));
    bc=(eval(bo)) - (eval(ao) * eval(ao));
    cc=(eval(co)) - 3 * (eval(bo) * eval(ao)) + 2 * (eval(ao) * eval(ao) * eval(ao));
    dc=(eval(fo)) - 4 * (eval(co) * eval(ao)) + 6 * (eval(bo) * eval(ao) * eval(ao)) - 3 * (eval(ao) * eval(ao) * eval(ao) * eval(ao));
    ds=Math.sqrt(eval(bc));

    if(eval(ni.value) > so) {
     mo=eval(xi.value);
     so=eval(ni.value);
    }


    form.xi.value="";
    form.ni.value="";
  
  

   

    
    }
  }
}
function computer(form){
  if (checkFormNum(form)) {
    with(form) {
    var media = (eval(ao));
    
    result.value = " " + media;
    }
  }
}
function computer1(form){
  if(checkFormNum(form)) {
    with(form) {
    var moda = (eval(mo));

    result1.value= " " + moda;
    }
  }
}



function computer2(form){
  if (checkFormNum(form)) {
    with(form) {
    var varianza = (eval(bc));
    
    result2.value = " " + varianza;
    }
  }
}

function computer3(form){
  if (checkFormNum(form)) {
    with(form) {
    var desviacion = (eval(ds));
    
    result3.value = " " + desviacion;
    }
  }
}

function computer4(form){
  if (checkFormNum(form)) {
    with(form) {
    var variacion = (eval(ds) / eval(ao));
    
    result4.value = " " + variacion;
    }
  }
}

function computer5(form){
  if (checkFormNum(form)) {
    with(form) {
    var simetriaf = (eval(cc) / (eval(ds) * eval(ds) * eval(ds)));
    
    result5.value = " " + simetriaf;
    }
  }
}

function computer8(form){
  if (checkFormNum(form)) {
    with(form) {
    var simetriap = (eval(ao) - eval(mo)) /  eval(ds);
    
    result8.value = " " + simetriap;
    }
  }
}



function computer6(form){
  if (checkFormNum(form)) {
    with(form) {
    var apuntamientof = (eval(dc) / (eval(ds) * eval(ds) * eval(ds) * eval(ds))) - 3;
    
    result6.value = " " + apuntamientof;
    }
  }
}

function computer7(form){
  if (checkFormNum(form)) {
    with(form) {
    var gini =((eval(pi) / eval(gi)) - (eval(ui) / eval(mi))) / ((eval(pi) / eval(gi)) - 1);
        
    result7.value = " " + gini;
    }
  }
}

function computer9(form){
  if (checkFormNum(form)) {
    with(form) {
    var armonica =(eval(gi) / eval(ar));
        
    result9.value = " " + armonica;
    }
  }
}
function irAPagina(form){
  location.href="http://www.estadisticaparatodos.es/software/javascript/misjavascript/javascript_descriptiva.html"
}

