jQuery(document).ready(function(){
    jQuery('#csn_form').submit(function(e){
        jQuery('#csn_alert').fadeIn();
        e.preventDefault();
        jQuery.post(
            'wp-content/plugins/CSNPlus/CSNPlus.php',
            {
                _wpnonce: jQuery('#_wpnonce').val(),
                _wp_http_referer: jQuery("input[name='_wp_http_referer']").val(),
                csn_user_name: jQuery("#csn_user_name").val(),
                csn_user_email: jQuery("#csn_user_email").val(),
                csn_user_title: jQuery("#csn_user_title").val(),
                csn_user_story: jQuery("#csn_user_story").val(),
                csn_captcha_code: jQuery("#csn_captcha_code").val(),
                csn_user_categories_code: jQuery("#csn_user_categories").val()
            },
            function(e){
				jQuery('#csn_alert').fadeOut();
                if(e.length != 0 && e != 'The Post has been published. You may now edit it from Edit Posts page'){
                    jQuery('#csn_user_submission').before(e);
                }
                else{
                    jQuery('#csn_form').html('<p>Thank you for submitting your post.</p><p>If you\'re not a registered user of this site, you will receive an e-mail inviting you to become one (check your spam folder, just in case it got delivered there).  Click the link provided in that e-mail to activate your account and for us to start reviewing your submitted post.  Only registered users are permitted to post messages on this site.</p><p>Click <a href="'+window.location.href+'" id="csn_reload_form">here</a> to submit another post.</p>');
                    //jQuery('#csn_form').html('<p>Thank your for your submission. Click <a href="'+window.location.href+'" id="csn_reload_form">here</a> to sumbit another story</p>');
                    jQuery('#csn_msg').show();
                }
				
            }
        );
    });
  jQuery('#csn_form').ajaxError(function(e, xhr, settings, exception){
        alert(xhr);
    });

    jQuery('a#csn_reload_form').click(function(event){
        event.preventDefault();
        alert(';stiuf');
        jQuery('#csn_form').text('[csnplus]')
    });

    jQuery('#csn a').click(function(event){
        if(this.className == 'publish' || this.className == 'delete'|| this.className == 'confirm'){
            event.preventDefault();
            jQuery.post(
                '../wp-content/plugins/CSNPlus/CSNPlus.php',
                {
                    action: this.className,
                    id: this.id
                },
                function(e){
                    jQuery('#csn_msg').html(e);
                    jQuery('#csn_msg').show();
                    var row = jQuery(event.target).parents('tr');
                    row.each(function(){
                        jQuery(this).fadeOut('slow', function(e){
                            jQuery(this).remove();
                        });
                    });
                    jQuery(row).fadeOut('slow', function(e){
                        jQuery(row).remove();
                    });
                    setTimeout(function(e){
                        jQuery('#csn_msg').fadeOut('slow');
                    }, 5000);
                }
            );
        }
    });
});
