var mskwrap;
var otherwrap;
var otherSel=false;

function validateInput(event){
    if($(event.target).is(".inputerr") && $(event.target).val()!='') {
        $(event.target).removeClass("inputerr");
    }
}
function collectwrappers(){
    otherwrap=$("tr.cls1,tr.cls2");
    mskwrap=$("tr.cls2,tr.cls0");
    
    $('<span style="color:red;">*</span>').insertAfter(".bounden");
    $("tr.cls1,tr.cls2,tr.cls0").remove();
    $("#bsk").submit(function(event){
        var hasClear=false;
        if(otherSel)
            otherwrap.find(".bounden[value='']").each(function(){
                hasClear=true;
                $(this).addClass("inputerr");
            });
        else
            mskwrap.find(".bounden[value='']").each(function(){
                hasClear=true;
                $(this).addClass("inputerr");
            });
        if(hasClear){
            alert("Заполните обязательные поля!");
            return false;
        }
        else return true;
    })
    $('input:radio').click(function(event){
        if($(this).val()=='msk'){
            otherSel=false;
            otherwrap=otherwrap.remove();
            mskwrap.insertAfter("#firstrow");
            mskwrap.find(".bounden").removeClass("inputerr");
        }
        else{
            otherSel=true;
            mskwrap=mskwrap.remove();
            otherwrap.insertAfter("#firstrow");
            otherwrap.find(".bounden").removeClass("inputerr");
        }
    });
    $('#send_request').click(function(){
        $("#bsk").submit();
    });
    $("#msk").attr("checked", "checked").click();
}
$(collectwrappers);
$(otherwrap).bind('keyup',validateInput);
$(mskwrap).bind('keyup',validateInput);

