$(function(){

    tooltip();

    if (!window.console){
       window.console = {
           log: function(msg){
               //alert(msg);
           },
           debug:function(){}
       };
    }

});


function processAdditionalInsurance(id){

    if ($('#Person-'+id+'-AddInsuranceIs').is(':checked')){

        $('#Person-'+id+'-AdditionalInsuranceBlock').show();
        $('#Person-'+id+'-AdditionalInsurance').trigger('click');
        if ($('#Person-'+id+'-AdditionalInsurance').val().split('')[0] == 'T'){
            $('#Person-'+id+'-AddInsurDailyIsBlock').hide();
            $('#Person-'+id+'-AddInsurDailyIs').removeAttr('checked');
        }else{
            $('#Person-'+id+'-AddInsurDailyIsBlock').show();
        }
    }else{

        $('#Person-'+id+'-AdditionalInsuranceBlock, #Person-'+id+'-AddInsurDailyIsBlock').hide();
        $('#Person-'+id+'-AddInsurDailyIs').removeAttr('checked');
    }
}


function check(){
    ($(".error").length > 0)
        ? $("#SubmitButton, .submit").attr({"disabled":"disabled"}).addClass("disabled")
        : $("#SubmitButton, .submit").removeAttr('disabled').removeClass("disabled");
}


function error(where, which, show)
{
    if (show)
    {
        //console.log();
        if ($("span.message").length == 0)
        {
            $("span.message").remove();
            $(where).parent().parent().addClass("error");
            if(which=="")
            {
                message = "klaidos pranešimas";
            }
            else
            {
                message = errorlist[which];
            }
            text = '<span class="message">'+message+'</span>';

            if ($(where).parent().parent().find(".message").length!=0)
            {
                $(where).parent().parent().find(".message").remove();
            }

            $(where).parent().parent().append(text);
        }
    }
    else
    {
        $(where).parent().parent().removeClass("error");
        $(where).parent().parent().find(".message").remove();
    }
}

