var ing = {};

ing.init = function(){
    evt = $.browser.msie ? "click" : "change";
    
    $("tbody#forTeacher").hide();
    $("input.otherDesc").hide();       
    $("input.otherHear").hide();
    
    ing.toggleSchoolInfo(evt);
    ing.toggleOtherOption(evt);

    $("input:radio:checked").each(function(){
        $(this).trigger(evt);
    });
    
    $("select.howHearSelect").change(ing.toggleHowHearOtherOption);
    ing.toggleHowHearOtherOption();
    
};

ing.toggleSchoolInfo = function(evt){
    var checkboxesThatHide = "input[value='Parent']," + 
                             "input[value='Home-Schooling Parent']," +
                             "input[value='Other (please describe)']";
                             
    var checkboxesThatShow = "input[value='Teacher']," +
                             "input[value='School Administrator']," +
                             "input[value='School Volunteer'],";
                                                             
    $(checkboxesThatHide).bind(evt, function(){
        $("tbody#forTeacher").hide();
    });    
    
    $(checkboxesThatShow).bind(evt, function(){
        $("tbody#forTeacher").show();
    });
};

ing.toggleOtherOption = function(evt){
    $("input[value='Other (please describe)']").bind(evt, function(){
        $("input.otherDesc").show();
        $("form#aspnetForm").submit(function(){
            if($("input[value='Other (please describe)']:checked").val() == "Other (please describe)" && $("input.otherDesc").val() == "") 
            {    
                $("span#otherDescValidationMsg").remove();
                $("input.otherDesc").after("<span style='color: Red; display: inline;' id='otherDescValidationMsg'>Please describe your role in the text box.</span>");  
                return false;
            }            
        });  
        
    });
    
    $("input[value!='Other (please describe)']:radio").bind(evt, function() {
        $("input.otherDesc").hide();        
        $("span#otherDescValidationMsg").remove();
    });
};

ing.toggleHowHearOtherOption = function(){
  
    if ($("select.howHearSelect option:selected").val() == "Other")
    {
        $("input.otherHear").show();
        $("form#aspnetForm").submit(function(){
            if($("select.howHearSelect option:selected").val() == "Other" && $("input.otherHear").val() == "") 
            {
                $("span#otherHearValidationMsg").remove();
                $("input.otherHear").after("<span style='color: Red; display: inline;' id='otherHearValidationMsg'>Please enter how you heard of Planet Orange in the text box.</span>");  
                return false;
            }
        });  
    }
    else
    {
        $("input.otherHear").hide();
        $("span#otherHearValidationMsg").remove();
    }

};

$(document).ready(ing.init);                                    

