// JavaScript Document


$(document).ready(function(){

    
     $("div.buttons > div.actions > a.rating").click(function(){
     
        $("iframe#rating-form-body").attr({
            src :   $(this).attr('href')
        });
        
        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        parent.rateAdvertiser("", function () {
            window.location.href = '';
        });
        
        return false;
        
    });
    
    $("a.testimonial-link").click(function(){
     
        $("iframe#testimonial-form-body").attr({
            src :   $(this).attr('href')
        });
        
        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        parent.createTestimonial("", function () {
            window.location.href = '';
        });
        
        return false;
        
    });
});


function rateAdvertiser(message, callback) {
    $('div#rating').modal({
            close:false,
            overlayId:'generalModalOverlay',
            containerId:'ratingModalContainer',
            onShow: function (dialog) {
                dialog.data.find('.message').append(message);

                // if the user clicks "yes"
                dialog.data.find('.yes').click(function () {
                    // call the callback
                    if ($.isFunction(callback)) {
                        callback.apply();
                    }
                    // close the dialog
                    $.modal.close();
                });

                //if the user clicks "no"
                dialog.data.find('.no').click(function() {
                    //close the dialog
                    $.modal.close();
                });
            }
    });
}

function createTestimonial(message, callback) {
    $('div#testimonial').modal({
            close:false,
            overlayId:'generalModalOverlay',
            containerId:'testimonialModalContainer',
            onShow: function (dialog) {
                dialog.data.find('.message').append(message);

                // if the user clicks "yes"
                dialog.data.find('.yes').click(function () {
                    // call the callback
                    if ($.isFunction(callback)) {
                        callback.apply();
                    }
                    // close the dialog
                    $.modal.close();
                });

                //if the user clicks "no"
                dialog.data.find('.no').click(function() {
                    //close the dialog
                    $.modal.close();
                });
            }
    });
}
