    jQuery.validator.setDefaults({

        success: "valid"
    });
    $(document).ready(function(){
    /*
    // Investitionsaufwand
    line1=[[0, 2145],[1, 2340],
           [2, 2535],[3, 2730],
           [4, 2925],[5, 3120]];
    // Return on Invest
    line_rio=[[0,  960],[1, 1920],
           [2, 2880],[3, 3840],
           [4, 4800],[5, 5760]];
    //Kosten / Gewinn
    line_kog=[[0,  720],[1, 1440],
           [2, 2160],[3, 2880],
           [4, 3600],[5, 4320]];
    */
    line1=[[0, 1950],
	   [1, 2145],[2, 2340],
           [3, 2535],[5, 2730],
           [5, 2925],[6, 3120],
           [7, 3315],[8, 3510],
           [9, 3705],[10, 3900],
           [11, 4095],[12, 4290]
           ];
    // Return on Invest
    line_rio=[[0, 0],
	   [1,  960],[2, 1920],
           [3, 2880],[4, 3840],
           [5, 4800],[6, 5760],
           [7, 6720],[8, 7680],
           [9, 8640],[10, 9600],
           [11, 10560],[12, 11520]
           ];
    //Kosten / Gewinn
    line_kog=[[0, 0],
	   [1,  720],[2, 1440],
           [3, 2160],[4, 2880],
           [5, 3600],[6, 4320],
           [7, 5040],[8, 5760],
           [9, 6480],[10, 7200],
           [11, 7920],[12, 8640]
           ];

    line_sp=[[2.5,500],[2.5, 5500]]

    xticks = [[0, '0.'], [1, '1. Monat'], [2, '2. Monat'], [3, '3. Monat'], [4, '4. Monat'], [5, '5. Monat'],
              [6, '6. Monat'], [7, '7. Monat'], [8, '8. Monat'], [9, '9. Monat'], [10, '10. Monat'], [11, '11. Monat'],  [12, '12.']];
    //xticks = [[0, '1. Monat'], [1, '2. Monat'], [2, '3. Monat'], [3, '4. Monat'], [4, '5. Monat'], [5, '6. Monat']];
    yticks = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000];


        plot1 = $.jqplot('chart4', [line1, line_rio,line_kog, line_sp], {
            legend:{show:true},
            title:'Aufwand / Rückfluß / Gewinn akkumuliert',
            grid: {background:'#f3f3f3', gridLineColor:'#accf9b'},// accf9b
            series:[
                {label:'Aufwand', markerOptions:{style:'square'}},
                {label:'Rückfluß'},
                {label:'Gewinn'},
                {label:'Amortisationspunkt'}
            ],
            axes:{
                xaxis:{ticks:xticks},
                yaxis:{ticks:yticks
                  ,tickOptions:{formatString:' %i'}
                }
            },
            cursor: {tooltipLocation:'sw'}

        });
                    // check form calculator
                    $("#calculator").validate({
                                        submitHandler:function(form) {
                                        SubmittingForm();
                                    },

                                      rules: {
                                        sto: {
                                          required: true,
                                          number: true
                                        },
                                        abr: {
                                          required: true,
                                          number: true
                                        },
                                        ores: {
                                          required: true,
                                          number: true
                                        },
                                        blz: {
                                          required: true,
                                          number: true
                                        },
                                          required: true,
                                          number: true
                                        }
                                      });
        SubmittingForm=function() {

                    // Return on Invest
                    cwCost = 6;
                    var line_rio = new Array();
                    //Kosten / Gewinn
                    var line_kog = new Array();
                    $('#sto').val( $('#sto').val().replace(',','.'));
                    $('#abr').val( $('#abr').val().replace(',','.'));
                    $('#ores').val( $('#ores').val().replace(',','.'));
                    $('#blz').val( $('#blz').val().replace(',','.'));
                    $('#plu').val( $('#plu').val().replace(',','.'));

                    var sto = ( $('#sto').val() / 100 ) + 1;
                    var abr = ( $('#abr').val() / 100 ) + 1;
                    var ores = ( $('#ores').val() / 100 ) + 1;
                    var blz = ( $('#blz').val() / 100 ) + 1;
                    var plu = $('#plu').val();
                    var plupm = plu / 12;
                    plupm = roundNumber(plupm, 2);
                    var ppm = $('#ppm').val();
                    ge = ( sto * abr * ores * blz  );
                    ge = roundNumber(ge, 2);
                    ge = ge * 100 - 100;
                    ne = ge - cwCost;

                    ge = roundNumber(ge, 1);
                    ne = roundNumber(ne, 1);

                    $('[name=ne]').val(ne);
                    $('[name=ge]').val(ge);
                    ge_money = plu / 100 * ne;
                    ge_money = roundNumber(ge_money,2);

                    $('[name=ge_money]').val(ge_money);
                    var ge = $('#ge').val() / 100;
                    var ne = $('#ne').val()/ 100;
                    var obu_p = $('#obu_p').val();
                    var obu_c = $('#obu_c').val();
                    amo = obu_p / (ge * plupm - ppm)


                    //alert(obu_p +"/ ("+ ge+" * "+plupm+" - "+ppm+")");
                    //amo = roundNumber(amo,1);
                    amo = amo.toFixed(1);
                    $('[name=amo]').val(amo);

                    //alert( ' sto [' + sto + ']  abr [' + abr + ']  ores [' + ores + ']  blz [' + blz + ']  ge [' + ge + '] ne [' + ne + '] ');
                    // res = sto abr ores blz

		    line_rio[0] = new Array(0, 0);
		    line_kog[0] = new Array(0, 0);
                    for (i=1;i<13;i++) {
                        // rio
                        rio = ge * plupm * i;
                        kog = plupm * ne * i;
                        rio = roundNumber(rio,0);
                        kog = roundNumber(kog,0);

                        line_rio[i] = new Array (i , rio);
                        line_kog[i] = new Array (i , kog);
                          $('#line_rio_'+i).html( rio + ' € &nbsp;');
                          $('#line_kog_'+i).html( kog + ' € &nbsp;');

                    }
                    //line_sp = [[(amo-1),500],[(amo-1),5000]]
                    line_sp = [[amo,500],[amo,5500]]

                    plot1 = $.jqplot('chart4', [line1, line_rio,line_kog,line_sp], {
                        legend:{show:true},

                            title:'Aufwand / Rückfluß / Gewinn akkumuliert',
                            grid: {background:'#f3f3f3', gridLineColor:'#accf9b'},// accf9b
                            series:[
                                {label:'Aufwand', markerOptions:{style:'square'}},
                                {label:'Rückfluß'},
                                {label:'Gewinn'},
                                {label:'Amortisationspunkt'}
                            ],


                        axes:{
                            xaxis:{ticks:xticks},
                            yaxis:{ticks:yticks
                              ,tickOptions:{formatString:'%d'}
                            }
                        }
                    });
                  };

    });

    function roundNumber(num, dec) {
        var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
        return result;
    }

