﻿/// <reference path="jquery-1.2.3-intellisense.js" />



$(document).ready(function() {
    $("ul#topnav > li:last-child a").css({ "border": "none", "padding": " 0 26px 0 31px" })

    $("#inner-content .screenshot").each(function() {
        if (!$(this).find("cite").is(":first-child")) {
            var img = $(this).find("img");
            var title = $(img).attr("title");
            $(img).before("<cite>" + title + "</cite>");
        }
    })
    //validation

    //bind
    if ($("#aspnetForm")) {
        $("#aspnetForm").validate({
            errorPlacement: function(error, element) {
                error.insertAfter($(element).parent());
            }
        });

    }

    //set focus on the first input field (if exist)
    $("input:text:first").focus();

    // checks if form is valid to avoid firing onclick event.
    $("#ctl00_ContentPlaceHolder1_btnSubmit").click(function() {
        return $("#aspnetForm").valid();
    });





});

///
function calculate(turnover, patients) {

    if (!$("#aspnetForm").valid()){
        return false;
    }

    var results = do_calculate(turnover, patients);

    $("#calculator-result .bouns").each(function() { $(this).html(results['bonus']) });
    $("#calculator-result .total").html(results['total']);
    
    $("#calculator-result .days").html(results['days']);
     
    $("#calculator-result").show();
    
    return false;
}



function do_calculate(turnover, patients) {

    var bonus, days, total;
    var results = {};

    bonus = Math.round(0.02 * turnover);
    total = bonus * 2;
    results['total'] = '$' + total.toString();
    results['bonus'] = '$' + bonus.toString();
    days = Math.round((30 / patients) * 7);
    results['days'] = days.toString();

    return results;
}

