$(document).ready(function() {
    $().prettyPhoto({callback: get_gallery_form});
    $("a.sellers_gallery_link").click(function() { open_gallery(); });
});
function get_gallery_form() {
    $.get('indy/sellers/ListingGalleryForm.aspx', function(data){
        var request_form = $(data);
        gallery_form_init(request_form);
        $(request_form).dialog({width: 695, height: 435, modal: true, draggable: false, resizable: false,
            title: ''});
    });
}
function gallery_form_init(request_form) {
    $(request_form).find('#sellers_gallery_form').bind("keypress", function(e) {
        if (e.keyCode == 13) return false;
    });
    $(request_form).find('#sellers_gallery_submit').click(function(){
        var post = $(request_form).find('#sellers_gallery_form')
                .find("input,textarea,select,hidden")
                .not("#__VIEWSTATE,#__EVENTVALIDATION")
                .serialize();
        $.post('indy/sellers/ListingGalleryForm.aspx', post,
            function(data) {
                $(request_form).html(data);
                if ($(request_form).find('#hiddenSuccess').val() == 'Yes') {
                    location.href = 'mThanks.aspx'
//                    var url = 'indy/sellers/ListingGalleryThanks.aspx';
//                    $(request_form).load(url, function() {
//                        $(request_form).find(":button[value='Close']").click(function(){
//                            $(request_form).dialog("close");
//                        });
//                        $.get('indy/googleconversion.htm', function(data) {
//                            alert(data);
//                            $(request_form).find('#thanks_misc').html(data);
//                        });
//                    }); 
                } else {
                    gallery_form_init(request_form);
                }
            });
    });
}