               function reset_data() { 
                    for(var i=1; i<=10; i++) {
                        document.all["tab"+i].value = i;
                        document.all["div"+i].value = "0.0";
                        document.all["outlay"+i].value = 0;
                        document.all["return"+i].value = 0;
                        document.all["profit"+i].value = 0;                                                                                                
                    }
                    document.all["total_outlay"].value = 0;
                    document.all["amount"].value = 200;
                }
  
                function clear_results() {
                    for(var i=1; i<=10; i++) {
                        document.all["outlay"+i].value = 0;
                        document.all["return"+i].value = 0;
                        document.all["profit"+i].value = 0;                                                                                                
                    }
                    document.all["total_outlay"].value = 0;
                }
                
                function check_results_validity() { 
                    for(var i=1; i<=10; i++) 
                      if((document.all["div"+i].value > 0.0) &&
                         ((document.all["outlay"+i].value < 0.0) ||
                          (document.all["return"+i].value < 0.0) ||
                          (document.all["profit"+i].value < 0.0)))
                            return 0;                                                                                                
                    
                    return (document.all["total_outlay"].value < 0.0) ? 0 : 1;
                }
  
                function calculate() {
                
                    // check input data validity (numeric values)
                    for(var i=1; i<=10; i++) 
                      if((new Number(document.all["div"+i].value)).toString() == "NaN") {
                          alert("Invalid dividend value number format for tab "+document.all["tab"+i].value);
                          return;
                      }
                    if((new Number(document.all["amount"].value)).toString() == "NaN") {
                        alert("Invalid amount value number format");
                        return;
                    }

                    // check input data validity (general)
                    var total_valid_rows = 0;
                    for(var i=1; i<=10; i++) 
                        if((document.all["div"+i].value > 0.0) && 
                           (document.all["div"+i].value <= 1.0)) {

                            alert("Invalid dividend value for tab "+document.all["tab"+i].value);
                            return;

                        } else if(document.all["div"+i].value > 0.0)
                            total_valid_rows++;
                            
                    // return if nothing to calculate
                    if(total_valid_rows == 0) {
                        alert("No valid data found!");
                        return;
                    }

                    // clear resulting fields
                    clear_results();
                    
                    // choose necessary calculation method
                    if(document.getElementById("opt1").checked) 
                        calculate_bet();
                        
                    else if(document.getElementById("opt2").checked)
                        calculate_return();
                        
                    else if(document.getElementById("opt3").checked)
                        calculate_profit();
                        
                    else {
                        alert("Please select calculation option");
                        return;
                    }
                    
                    if(check_results_validity() == 0) {
                        clear_results();
                        alert("Could not obtain a valid results with the amount you gave.\nPlease try again.");
                        return;
                    }
                }

                function calculate_bet() {

                    // get total sum of all expected dividends
                    var total_divs = 0;
                    for(var i=1; i<=10; i++) 
                        total_divs += (document.all["div"+i].value*1);
                    
                    // calculate weight coefficients
                    var coefficients = new Array();
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0) 
                        coefficients[i-1] = total_divs / document.all["div"+i].value;
                      else
                        coefficients[i-1] = 0;
                      
                    // get total sum of coefficients
                    var total_sum = 0;
                    for(var i=0; i<coefficients.length; i++)
                        total_sum += coefficients[i];
                    
                    // calculate weight coefficients in scape [0..1]
                    for(var i=0; i<coefficients.length; i++)
                        coefficients[i] = coefficients[i] / total_sum;
                                        
                    // calculate outlay & return values
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0.0) {
                        document.all["outlay"+i].value = Math.round(document.all["amount"].value * coefficients[i-1]);
                        document.all["return"+i].value = Math.round(document.all["outlay"+i].value * document.all["div"+i].value);
                      }
                      
                    // calculate total outlay
                    for(var i=1; i<=10; i++) 
                        document.all["total_outlay"].value = (document.all["total_outlay"].value*1) + (document.all["outlay"+i].value*1);
                
                    // calculate profit values
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0.0)
                        document.all["profit"+i].value = (document.all["return"+i].value*1) - (document.all["total_outlay"].value*1);
                }

                function calculate_return() {

                    // calculate outlay & return values                    
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0.0) {
                        document.all["outlay"+i].value = Math.round(document.all["amount"].value / document.all["div"+i].value);
                        document.all["return"+i].value = Math.round(document.all["outlay"+i].value * document.all["div"+i].value);
                      }
                    
                    // calculate total outlay
                    for(var i=1; i<=10; i++) 
                        document.all["total_outlay"].value = (document.all["total_outlay"].value*1) + (document.all["outlay"+i].value*1);
                    
                    // calculate profit values
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0.0)
                        document.all["profit"+i].value = (document.all["return"+i].value*1) - (document.all["total_outlay"].value*1);
                }
                
                function calculate_profit() {

                    // calculate main coefficient
                    var coefficient = 0;
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0) 
                        coefficient += 1 / document.all["div"+i].value;
                    
                    coefficient = (1-coefficient) / coefficient;
                    coefficient = 1 / coefficient;
                    
                    // calculate planned return
                    var planned_return = document.all["amount"].value * (coefficient+1);

                    // calculate outlay & return values                    
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0.0) {
                        document.all["outlay"+i].value = Math.round(planned_return / document.all["div"+i].value);
                        document.all["return"+i].value = Math.round(document.all["outlay"+i].value * document.all["div"+i].value);
                      }
                    
                    // calculate total outlay
                    for(var i=1; i<=10; i++) 
                        document.all["total_outlay"].value = (document.all["total_outlay"].value*1) + (document.all["outlay"+i].value*1);
                    
                    // calculate profit values
                    for(var i=1; i<=10; i++) 
                      if(document.all["div"+i].value > 0.0)
                        document.all["profit"+i].value = (document.all["return"+i].value*1) - (document.all["total_outlay"].value*1);
                }