$(document).ready(function() {
    // Mandatory fields
    $('label.mandatory').append(' <sup class="req">*</sup>');
    // Tooltips
    $("td.cellTip img").tooltip({
        track: true, delay: 0, fixPNG: true, fade: 200, showURL: false, showBody: " - ", left: -19
    }); 
    $("td.cellTipMergedTop img").tooltip({
        track: true, delay: 0, fixPNG: true, fade: 200, showURL: false, showBody: " - ", left: -19
    });
    $("td.cellTipMergedBottom img").tooltip({
        track: true, delay: 0, fixPNG: true, fade: 200, showURL: false, showBody: " - ", left: -19
    });
    $("#sectorIndicatorsToolTip").tooltip({
        track: true, delay: 0, fixPNG: true, fade: 200, showURL: false, showBody: " - ", left: -19
    });
    $("#envoiromentImpactIndicatorToolTip").tooltip({
        track: true, delay: 0, fixPNG: true, fade: 200, showURL: false, showBody: " - ", left: -19
    });
    $(".measureRow th.title img").tooltip({
        track: true, delay: 0, fixPNG: true, fade: 200, showURL: false, showBody: " - ", left: -19
    });
    $(".grid td.loggedIn").tooltip({
        track: true, delay: 0, fixPNG: true, fade: 200, showURL: false, showBody: " - ", left: -19
    });
    $("td.cellTip img").hover(function(){
        $(this).css('cursor', 'help');
        $(this).attr('src', '../images/icoInfo0.png');
    }, function(){
        $(this).attr('src', '../images/icoInfo1.png');
    });
    $("td.cellTipMergedTop img").hover(function(){
        $(this).css('cursor', 'help');
        $(this).attr('src', '../images/icoInfo0.png');
    }, function(){
        $(this).attr('src', '../images/icoInfo1.png');
    });
    $("td.cellTipMergedBottom img").hover(function(){
        $(this).css('cursor', 'help');
        $(this).attr('src', '../images/icoInfo0.png');
    }, function(){
        $(this).attr('src', '../images/icoInfo1.png');
    });
    $("#sectorIndicatorsToolTip").hover(function(){
        $(this).css('cursor', 'help');
        $(this).attr('src', '../images/icoInfo0.png');
    }, function(){
        $(this).attr('src', '../images/icoInfo1.png');
    });
    $("#envoiromentImpactIndicatorToolTip").hover(function(){
        $(this).css('cursor', 'help');
        $(this).attr('src', '../images/icoInfo0.png');
    }, function(){
        $(this).attr('src', '../images/icoInfo1.png');
    });
    $(".measureRow th.title img").hover(function(){
        $(this).css('cursor', 'help');
        $(this).attr('src', '../images/icoInfo0.png');
    }, function(){
        $(this).attr('src', '../images/icoInfo1.png');
    });

    // Show/Hide Contacts
    $('#contacts').hide(); 
    $('#contactLink a').click(function() {
        $('#contacts').toggle(400);
        $.scrollTo('+=100px', 800);
        return false;
    });

    <!--Disable input form buttons after submit-->
    var forms = document.getElementsByTagName('form');
    if (forms) {
        for (var i = 0; i < (forms.length); i++) {
            var form = document.getElementsByTagName('form')[i];
            if (form) {
                if(!form.onsubmit){
                    form.onsubmit = function() {
                        for (var j = 0; j < (form.getElementsByTagName('input').length); j++) {
                            if (form.getElementsByTagName('input')[j].type == 'button') {
                                form.getElementsByTagName('input')[j].disabled = true;
                            } else if (form.getElementsByTagName('input')[j].type == 'submit') {
                                var hiddenSubmit = document.createElement('input');
                                hiddenSubmit.setAttribute('type', 'hidden');
                                hiddenSubmit.setAttribute('name', form.getElementsByTagName('input')[j].name);
                                form.appendChild(hiddenSubmit);
                                form.getElementsByTagName('input')[j].disabled = true;
                            }
                        }
                    };
                }
            }
        }
    }

});

// Cancel button
function goTo(whereTo, page, sort, dir){
    whereTo += "?page="+page+"&sort="+sort+"&dir="+dir;
    location.href= decodeURIComponent(whereTo);
}
function goTo(whereTo){
    location.href= decodeURIComponent(whereTo);
}

//noinspection FunctionWithInconsistentReturnsJS
function onkeyPressFileInput(e) {
    var key = window.event ? e.keyCode : e.which;
    if (key != null && key != '')
        return false;
}

// Dialog confirm
function dialogConfirm(question) {
    return confirm(question);
}

