// JScript File

function ConfReg()
{
    var self = this;
    $(document).ready(function () {

        if ($(".Occupation").find(":selected").text() == "Other") {
            $(".OccupationOther").show();
        }
        else {
            $(".OccupationOther").hide();
            $(".txtOccupationOther").val("");
        }


        if ($(".ddlCountry").find(":selected").val() == "") {
            $(".ddlState").hide();
            $(".ddlCanada").hide();
            $(".txtState").show();
        }
        else if ($(".ddlCountry").find(":selected").val() == "USA") {
            $(".ddlCanada").hide();
            $(".ddlState").show();
            $(".txtState").hide();
        }
        else if ($(".ddlCountry").find(":selected").val() == "Canada") {
            $(".ddlCanada").show();
            $(".ddlState").hide();
            $(".txtState").hide();
        }
        else {
            $(".ddlState").hide();
            $(".ddlCanada").hide();
            $(".txtState").show();
        }

        self.ToggleWorkshop();

        $(".RegistrationIntensives").find("input[type='checkbox']").each(function () {

        });

        self.DisableWorkshop();
        self.DisableWorkshopOption();
    });
    
    this.ToggleOccupationOther = function()
    {
        if($(".Occupation").find(":selected").text() == "Other")
        {
            $(".OccupationOther").show();
        }
        else
        {
            $(".OccupationOther").hide();
            $(".txtOccupationOther").val("");
        }
    }
    
    this.GetInternationalRegions = function()
    {        
        if($(".ddlCountry").find(":selected").val() == "USA")
        {
            $(".ddlCanada").hide();
            $(".ddlState").show();
            $(".txtState").hide();
        }   
        else if($(".ddlCountry").find(":selected").val() == "Canada")
        {
            $(".ddlCanada").show();
            $(".ddlState").hide();
            $(".txtState").hide();
        }     
        else
        {
            $(".ddlCanada").hide();
            $(".txtState").show();
            $(".ddlState").hide();
        }   
    }
    
    this.ToggleWorkshop = function()
    {
    	
        $(".Workshops").each(function(i)
        {
            $(this).hide();
        });
        
        $(".FullTime").each(function(i)
        {
            $(this).find("input[type='radio']").each(function() {
                if($(this).attr("checked") == true)
                {
                    var myClasses = $(this).parent().attr("class");                    
                    myClasses = myClasses.replace('FullTime ', '').replace('Option', '');
                    
                    $(".Workshops."+myClasses).each(function(i)
                    {
                        $(this).show();
                        if($(this).find(".WorkshopChbx input[type='checkbox']").hasClass("required"))
                        {
                            $(this).find(".WorkshopChbx input[type='checkbox']").each(function(i)
                            {
                                this.checked = true;
                                //this.disabled = "disabled";
                                var cell = $(this).parent().parent().next().next();                
                                cell.find(".WorkshopOption").show();
                            });
                            
                        }
                    });
                }
            });
        }); 
            
        $(".PartTime").each(function(i) 
        {        
            $(this).find("input[type='checkbox']").each(function(){                    
                if($(this).attr("checked") == true)
                {
                    var myClasses = $(this).parent().attr("class");
                    myClasses = myClasses.replace('PartTime PartTime', '');

                    $(".Workshops."+myClasses).each(function(i)
                    {
                        $(this).show();
                        if($(this).find(".WorkshopChbx input[type='checkbox']").hasClass("required"))
                        {
                            $(this).find(".WorkshopChbx input[type='checkbox']").each(function(i)
                            {
                                this.checked = true;
                                //this.disabled = "disabled";
                                var cell = $(this).parent().parent().next().next();                
                                cell.find(".WorkshopOption").show();
                            });
                            
                        }
                    });
                }                
            });
        }); 
        
        $(".Workshops").each(function(i)      
        {
            if($(this).is(':hidden'))
            {
                $(this).find(".WorkshopChbx input[type='checkbox']").each(function(i) 
                {                            
                    if(this.checked)
                    {                        
                        this.checked = false;
                        var cell = $(this).parent().parent().next().next();                
                        cell.find(".WorkshopOption").hide();
                    }
                });
            }
            
        });        
    }

    this.DisableWorkshop = function () {

        $(".workshopConflictDisabled").each(function () {
            if ($(this).parent().hasClass('Full') == false && $(this).parent().hasClass('Closed') == false) {
                $(this).removeAttr('disabled').removeClass('workshopConflictDisabled');
            }
        });

        $('.WorkshopChbx input:checked').each(function () {
            
            var disableFunc = String($(this).attr('onclick'));

            if (disableFunc != null && disableFunc.length > 0 && disableFunc.indexOf("ConfReg.DisableWorkshop") > -1) {
                disableOp = disableFunc.replace("function onclick()", "").replace("\r", "").replace("\n", "").replace("{", "").replace("}", "").replace("Workshops.Toggle();", "").replace(" ConfReg.DisableWorkshop('", "").replace("');", "").split(',');

                for (i = 0; i < disableOp.length; i++) {
                    op = $('#' + $.trim(disableOp[i]) + ' input');

                    op.attr('class', 'workshopConflictDisabled');
                    op.attr('disabled', true);

                }
            }


        });
    }

    this.DisableWorkshopOption = function (obj, e) {
	
        $(".workshopOptionConflictDisabled").each(function () {
            if ($(this).parent().hasClass('capacity') == false) {
                $(this).removeAttr('disabled').removeClass('workshopOptionConflictDisabled');
            }
        });

        $('.WorkshopOption input:checked').each(function () {
            if (!$(this).parent().hasClass("Waitlist")) {
                var disableFunc = String($(this).attr('onclick'));
      
                if (disableFunc != null && disableFunc.length > 0 && disableFunc.indexOf("ConfReg.DisableWorkshopOption") > -1){
                    disableOp = disableFunc.replace("function onclick()","").replace("\r","").replace("\n","").replace("{","").replace("}","").replace("ConfReg.DisableWorkshopOption(", "").replace(");", "").split(',');
                    
                    for (i = 0; i < disableOp.length; i++) {                                         
                        var op = document.getElementById($.trim(disableOp[i]));
                        
                        if(op != null && op.className.indexOf('Waitlist') < 0){ 
                            op = $('#' + $.trim(disableOp[i]) + ' input');

                            op.attr('class', 'workshopOptionConflictDisabled');
                            op.attr('disabled', true);
                        }
                    }
                }
            }
        });
    }
    
    this.ToggleAttendance = function(e)
    {
        if(e == "PartTime")
        {            
            $(".FullTime").each(function(i)
            {
                $(this).find("input[type='radio']").each(function() {
                   if($(this).attr("checked") == true)
                    $(this).attr("checked", false);
                });
            });         
        }
        else if(e == "FullTime")
        {
            $(".PartTime").each(function(i) 
            {        
                $(this).find("input[type='checkbox']").each(function(){                    
                    if($(this).attr("checked") == true)
                    $(this).attr("checked", false);
                });
            });
        }
    }
    
    this.Intensives = function(e)
    {
        $(".RegistrationIntensives").find("input[type='checkbox']").each(function() {
           
        });
    }
    
    this.Uncheckable = function(e)
    {                
        e.checked = true;
        var cell = $(e).parent().parent().next().next();                
        cell.find(".WorkshopOption").show();
    }
}

var ConfReg = new ConfReg();
