var emailPageHandler = function(o) {
    var callingDialog = this;
    new Ajax.Request('/listing/classListing/ajaxEmailPage',
    {
        method: 'post',
        parameters: $('emailForm').serialize(true),
        onSuccess:function(transport) {
            var responseTxt = transport.responseText;
            if (responseTxt == 'SUCCESS') {
                //Show message
                $('showmessage').replace("<div id=\"showmessage\" class=\"message\">This page has been emailed.</div>");
                $('showmessage').show();
                //Close calling Dialog
                callingDialog.cancel();
            } else {
                $('emailarea').replace(transport.responseText);
            }
        }
    });
}

function showAllDates() {
    $('showFullSchedule').hide()
    $('additionalsessions').show();
    var elements = $('additionalsessions').getElementsBySelector('tr.additionalRow')
    elements.each(function(e) {
        e.show();
    });
}

function showAllTimes() {
    $('showAdditionalClassTimes').hide()
    var elements = $('additionaltimes').childElements();
    elements.each(function(e) {
        e.show();
    });
}
function showAllRecommendations() {
    $('showAdditionalRecommendations').hide()
    var elements = $('recommendations').childElements();
    //var elements = $$('[id^="additionalRecommendation_"]');
    elements.each(function(e) {
        e.show();
    });
}

function showAllDatesListing(rowid, batchNumber) {
    $('showAdditional_'+batchNumber+'_'+ rowid).hide()
    var batchNumberPlusOne = batchNumber + 1
    if($('showAdditional_'+batchNumberPlusOne+'_'+ rowid)){
        $('showAdditional_'+batchNumberPlusOne+'_'+ rowid).show()
    }
    var elements = $$('[id^="row_'+rowid+'_'+batchNumber+'_"]');
    elements.each(function(e) {
        e.show();
    });
}

var options = {
    script:'jsonsearch?',
    varname:'className',
    json:true,
    onAjaxError: function(status) {
    },
    shownoresults:true,
    //timeout:4000,
    //maxresults:10,
    callback: function (obj) {
        this.options = {
            //url: 'search?className=' + obj.value
            url: 'detail/' + obj.value
        }
        //Redirect to results
        location.href = this.options.url
    }
};