/**
 * Author Scott Shaper
 * Copyright 2010
 * 
 */

var toggleId = "";

$(function(){
   if ($('#studentType').length !=0){$('#studentType').bind('change',function(){getRegistrationApptsTable();});}
   if ($('#semester_appt').length != 0){$('#semester_appt').bind('change',function(){displayTermSelectionAcad();});}
   if ($('#semester_DandD').length != 0){$('#semester_DandD').bind('change',function(){displayTermSelectionDandD();});}
   if ($('#semesterdd').length != 0){$('#semesterdd').bind('change',function(){selectSemester();});}
   if ($('.midsection').length != 0){$('.midsection ul li ul:gt(0)').hide();$('.midsection ul li').bind('click',function(){showHide($(this));})}
   if ($('#basetextarealarge2').length != 0)
       {$('#basetextarealarge2 h6').each(function(n){$(this).attr('id','q'+n);});
        $('#basetextarealarge2 div').each(function(n){$(this).attr('id','a'+n);});
        $('#basetextarealarge2 div').each(function(n){$(this).hide();});
        $('#basetextarealarge2 h6').bind('click',function(){showHideFAQ($(this));})
       }

});

function showHideFAQ(obj)
{
    var str = obj.attr('id');

    str = str.replace("q","a");
    $('#basetextarealarge2 div').hide();
    //toggles the answer open or closed.
    if (toggleId == str)
        {
            toggleId = "";
        }
    else
        {
           $('#'+str).show();
           toggleId = str;
        }
}


function showHide(obj)
{
    $('.midsection ul li ul').hide('slow');
    obj.children().show('slow');
}


//display Academic Calendar terms based upon the semester selected
function displayTermSelectionAcad()
{
    
    var id = $('#semester_appt').val();
    if (id == 0)
        {
            alert(" You must select a semester");
        }
    else
        {

            $.post("../admin/cma/process/display_acad_term_proc.php",{id:id},function(data){$('#appt_term').html(data);$('#term').bind('change',function(){getAcadCalendarTable();})});
        }

}

//display Academic Calendar Table based upon the term selected
function getAcadCalendarTable()
{
    var id = $('#term').val();
    if (id == 0)
        {
            alert (" You must select a term");
        }
    else
        {
             $('#acadTableId').val(id);
             $.post("../admin/cma/process/acad_calendar_table_proc.php",{id:id},function(data){$('#academicCalendar').html(data);});
        }

}

//display the registration appointments table
function getRegistrationApptsTable()
{
    var id = $('#studentType').val();
    if (id == 0)
    {
        alert(" You must select a student type");
    }
    else
    {
        $('#apptTableId').val(id);
        $.post("../admin/cma/process/get_appt_table_proc.php",{id:id},function(data){$('#appointments').html(data);});
    }


}

//display dates and deadlines terms based upon the semester selected
function displayTermSelectionDandD()
{
    var id = $('#semester_DandD').val();
    if (id == 0)
        {
            alert(" You must select a semester");
        }
    else
        {

            $.post("../admin/cma/process/display_dandd_term_proc.php",{id:id},function(data){$('#dandd_term').html(data);$('#term').bind('change',function(){getDandDTable();})});
        }

}

//display the dates and deadlines table based upon the term selected
function getDandDTable()
{
    var id = $('#term').val();
    if (id == 0)
        {
            alert (" You must select a term dandd");
        }
    else
        {
             $('#DandDTableId').val(id);
             $.post("../admin/cma/process/dandd_table_proc.php",{id:id},function(data){$('#academicCalendar').html(data);});
        }

}

//gets exam schedule for selected semester
function selectSemester()
{
    var id = $('#semesterdd').val();
    $('#examScheduleId').val(id);

    if (id == 0)
        {
            alert(' You need to select a semester')
        }
    else
        {
            $.post("../admin/cma/process/exam_display_schedule_proc.php",{id:id},function(data){$('#examSchedule').html(data);});
        }
}
