<?php
include("includes/site_info.php");
include("session_handler.inc");
include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

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

if (isset($_REQUEST['msg_senderid']) && isset($_REQUEST['msg_title']))  {
$msg_senderid=$_REQUEST['msg_senderid'];
$msg_title=$_REQUEST['msg_title'];
$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);
}

$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());
?>

<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 p5">
		<tr>
			<td colspan="2" class="grey_12 orange_row_back solid_line_separator">
					<div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10"></div>
					Compose Message					</td>
		</tr>
		<tr>
			<td>
				<?=SENDMAIL_TO?>
				:</td>
			<td><?php if (isset($sender_id)) { ?>
					<input type='text' name='username' value='<?php print(ucwords("$sender_id")); ?>' class="button" style="width:200px"/>
					<input type='hidden' name='userid' id='userid' value='<?php print("$msg_senderid"); ?>' />
					<?php } else { ?>
					<select id='userid' class="button" style="width:150px">
						<option value='' selected>- <?php echo GENERAL_CHOOSE?> -</option>
						<?php
				while($arr_frdlist = mysql_fetch_object($retval)) {
	               print("<option value='$arr_frdlist->friend_uid'>".ucwords($arr_frdlist->adv_username)."</option>");
				}
				?>
					</select>
					<?php } ?>
				<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="<?php if (isset($msg_title)) { echo "RE: ".$msg_title; }?>" 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>
		<tr>
			<td>&nbsp;</td>
			<td><div id="comp_msg"><img src="images/spacer.gif"></div></td>
		</tr>
	</table>
</form>
