<?php
include("includes/site_info.php");
include('session_handler.inc');

$WUserID = $_SESSION['Sess_UserId'];
$WUsername = $_SESSION['Sess_UserName'];

if ($_REQUEST['bid']) { $bid = $_REQUEST['bid']; }
else { $bid = 0; }

$blogitem_query=mysql_query("SELECT *, UNIX_TIMESTAMP(blg_datetime) as blgdate FROM blogs WHERE blg_userid = '$WUserID' AND blg_approved='Y' AND blg_id='$bid'") or die(mysql_error());
$blogitem_TOTAL = mysql_num_rows($blogitem_query);
if ($blogitem_TOTAL >0) {
	$blog = mysql_fetch_object($blogitem_query) or die(mysql_error());
} else {
?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
        <tr>
          <td align="center"><div class="padding_10">Can't find a blog to edit.</div></td>
        </tr>
      </table></td>
  </tr>
</table>
<?php
	die;
}

?>
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#edit_delete").submit(function(){

	 	jQuery('#loading').show();
	 	jQuery('#right_loading_c').show();

	var str = 'Submit=edit_delete&' + jQuery(this).serialize();

   		jQuery.ajax({
   		type: "POST",
   		url: "blog_submit.php",
   		data: str,
		dataType: 'json',
   		success: function(result){
		jQuery('#loading').hide();	
	 	jQuery('#right_loading_c').hide();
				if (result.error){
		 		jQuery("#msg_content_error").fadeIn('slow');
	 			jQuery('#msg_content_error').html('Ops! Error, please try again!');
				if (jQuery.isArray(result.error)==true){
				jQuery.each(result.error, function(key, value) { 
 					jQuery('#msg_content_error').append('<br>'+value);
				});
				} else {
 					jQuery('#msg_content_error').append('<br>'+result.error);
				}
				}
				if (result.success){
 				jQuery("#msg_content_done").fadeIn('slow');
 				jQuery('#msg_content_done').html('Wow, Your request was done!');
				if (jQuery.isArray(result.success)==true){
				jQuery.each(result.success, function(key, value) { 
 					jQuery('#msg_content_done').append('<br>'+value);
				});
				} else {
 					jQuery('#msg_content_done').append('<br>'+result.success);
				}
				if(result.status == '1') { 
						window.top.location.href='#cblog?tab=media';
						jQuery.facebox.close();
			} 
				}
		}

 });
return false;
    });
});
   </script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
        <tr>
          <td valign="top" width="100%"><div id="msg_content_error" style="display:none;"></div>
            <div id="msg_content_done" style="display:none;"></div>
            <div id="sub_content">
              <form id="edit_delete" name="edit_delete" method="post" style="padding:0; margin:0; border:0;">
                <input name="userid" type="hidden" value="<?=$WUserID?>" />
                <input type="hidden" name="blogid" value="<?=$blog->blg_id?>">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="10">
                        <tr>
                          <td valign="top" align="left" width="100%"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
                              <tr>
                                <td align="center" valign="top">Are you sure you want to delete this blog? <br /><br/>
                                  <strong><?=$blog->blg_title?></strong>
                                  </td>
                              </tr>
                              <tr>
                                <td valign="top">&nbsp;</td>
                              </tr>
                            </table></td>
                        </tr>
                      </table></td>
                  </tr>
                  <tr>
                    <td align="center"><input name="delete" type="submit" class="button" id="delete" value="Delete"/>
                      <input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: jQuery.facebox.close(); return false;"/></td>
                  </tr>
                  <tr>
                    <td align="center">&nbsp;</td>
                  </tr>
                </table>
              </form>
            </div></td>
        </tr>
      </table></td>
  </tr>
</table>
