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

$WUserID = $_SESSION['Sess_UserId'];
$WUserType = $_SESSION['Sess_UserType'];
$WUserName = $_SESSION['Sess_UserName'];

$msg_senderid=clearInput($_REQUEST['msg_senderid']);
$sender_query=mysql_query("SELECT adv_username FROM adverts WHERE adv_userid = $msg_senderid AND adv_approved='1'");
$sender_id=mysql_result($sender_query,0,0);

$block_query=mysql_query("SELECT count(*) FROM blockmail WHERE blk_receiverid = $msg_senderid AND blk_senderid = $WUserID",$link);
$block_list = mysql_result($block_query,0,0);

if ($block_list > 0) {
	echo '<table width="100%" border=0 cellpadding="5" cellspacing="0" class="white_back_t_xb">';
	echo '<tr>';
	echo '<td align="center">Sorry this hahaper has chosen not to receive further emails from you.</td>';
	echo '</tr>';
	echo '</table>';
	echo "<script type='text/javascript'>setTimeout(function() { parent.jQuery.facebox.close(); }, 1000);</script>";
	die;
	}

$query="SELECT * FROM my_friends LEFT JOIN adverts ON (friend_uid=adv_userid) WHERE uid='$WUserID' AND approved = '1' AND adv_approved='1' ORDER BY adv_username ASC";
$retval=mysql_query($query,$link) or die(mysql_error());
?>
<script type="text/javascript" src="js/hahaper_tab.js"></script>
<div id="comp_msg" style="padding:5px"><img src="images/spacer.gif"></div>
<form action="javascript:getCompose(document.getElementById('form_incoming_mail'));" name='form_incoming_mail' id='form_incoming_mail' style="padding:0; margin:0; border:0;"><table width="100%" border="0" align="left" cellpadding="5" cellspacing="0" class="white_back_t_xb">
     
	<tr>
			  <td><?=SENDMAIL_TO?>:</td>
                <td>
				<input type='text' name='username' value='<?php print(ucwords("$sender_id")); ?>' class="button" style="width:200px" readonly/>
                <input type='hidden' name='userid' id='userid' value='<?php print("$msg_senderid"); ?>' />
             <input type='hidden' name='myhandle' value='<?php print("$WUserName"); ?>' /></td>
    </tr>
	<tr>
	  <td><?=SENDMAIL_SUBJECT?>:</td>
	  <td><input id="txtSubject" name="txtSubject" type="text" class="button" style="width:400px" value="" size="50"></td>
    </tr>
	<tr>
	  <td valign="top"><?=SENDMAIL_MESSAGE?>:</td>
	  <td><textarea id="txtMessage" cols="" rows="10" style="width:400px"></textarea></td>
    </tr>
	
	<tr>
	  <td>&nbsp;</td>
	  <td><input name="Validate" type="submit" class="button" value="<?php echo BUTTON_SENDMAIL ?>" 
   onclick="javascript:getCompose(this.parentNode);"></td>
    </tr>
				  </table>
</form>
