﻿function setPosition(table, divLoader) {
    $("#" + divLoader).css($("#" + table).offset());
    $("#" + divLoader).css("width", $("#" + table).width() + "px");
    $("#" + divLoader).css("height", $("#" + table).height() + "px");
}

function coverPage(divLoader) {
    var documentHeight = document.height ? document.height : document.body.clientHeight;
    var documentWidth = document.width ? document.width : document.body.clientWidth;

    $("#" + divLoader).css("width", documentWidth + "px");
    $("#" + divLoader).css("height", documentHeight + "px");
}

function centerToCurrentView(controlId) {
    var documentHeight = document.height ? document.height : document.body.clientHeight;
    var documentWidth = document.width ? document.width : document.body.clientWidth;

    var scrollTop = $(window).scrollTop();
    var windowHeight = $(window).height();

    var control = $('#' + controlId);
    control.css("left", ((documentWidth - control.width()) / 2) + 'px');
    control.css("top", (scrollTop + (windowHeight - control.height()) / 2) + 'px');
}

function scrollToControl(control) {
    setTimeout("window.scrollTo(0, $('#" + control + "').offset().top)", 0);
}

function clearText(control, emptyText, maxlength) {
    if (control.value == emptyText) {
        control.style.textTransform = 'uppercase';
        control.style.fontStyle = 'normal';
        control.style.color = '';
        
        control.value = '';
        control.maxLength = maxlength;
    }
}

function setEmptyText(control, emptyText) {
    if (control.value == '') {
        control.style.textTransform = 'none';
        control.style.fontStyle = 'italic';
        control.style.color = '#999999';
        control.setAttribute('maxLength', emptyText.length);
        
        control.value = emptyText;
    }
}

function displayMembers(value) {
    var count = parseInt(value);
    if (count == NaN || count < 1 || count > 8) {
        value = 0;
    }
    
    for (var i = 1; i <= 8; i++) {
        var member = $('#trMember' + i);
        if (i <= count) {
            member.show();
        }
        else {
            member.hide();
        }
    }
}

function displaySmoker(id, value) {
    var age = parseInt(value);
    if(age == NaN) {
        return;
    }
    
    var smoker = $("#tableSmoker" + id);
    if (age >= 18) {
        smoker.show();
    }
    else {
        smoker.hide();
    }
}

function switchSEProfessional(senderId, targetId) {
    var senderSwitch = $('#[id $= ' + senderId + ']');
    var targetSwitch = $('#[id $= ' + targetId + ']');
    if (senderSwitch.attr('checked') == true && targetSwitch.attr('checked') == true) {
        targetSwitch.attr('checked', false).change();
    }
}