<?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'];
$WUserLastVisit = $_SESSION['Sess_LastVisit'];
$WUsername = $_SESSION['Sess_UserName'];
$result=mysql_query("SELECT * FROM members LEFT JOIN adverts ON (mem_userid=adv_userid) WHERE mem_userid=$WUserID",$link);
$sql_array = mysql_fetch_object($result);

$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql_array->adv_userid' and pic_default='Y'") or die(mysql_error());
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_pb.".$aPicture->ext;
	$male1_picture1 = "members/$sql_array->adv_username/picture/$medium";
             }else{
$male1_picture1=$picture->GetPicFull($sql_array->adv_userid);
}

?>
<script type="text/javascript" src="js/jquery.upload-1.0.2.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
    $("#file").change(function(){
    var file = $('input[name=file]').val(); 
	 
     /* Checking empty input file */
   if (!file) { 
        alert('No file to upload!'); 
        return false; 
    } 
    /* Checking file type */
    var re_text = /\.jpeg|\.jpg|\.gif|\.png|\.JPG|\.GIF|\.PNG/i; 

	if (file!=''){
		if (file.search(re_text) == -1)
    	{
        	alert(file + " is not a valid file. Please select a file with JPEG / GIF / PNG  format!"); 
        	return false;
    	}
	}
	
	jQuery('#loadingBox').show();

	$('#fields').upload('profile_account_submit.php', function(result) {
/*		alert (result);
*/		jQuery('#loadingBox').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!');
 				jQuery("#file").val('');
 				jQuery("#profile_pic img").attr("src", '<?php echo $CONST_LINK_ROOT."/members/".$sql_array->adv_username."/picture/";?>'+result.src);
				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);
				}
				}
/*    }, 'html');
*/    }, 'json');


/*   jQuery('#fields').upload('profile_account_submit.php', function(res) {
	jQuery("#msg_content").html(result);
		jQuery("#msg_content").fadeIn('slow');
		jQuery("#sub_content").hide();
 		jQuery("#result_content").fadeIn('slow');
 		jQuery('#result_content').html(res);
   }, 'json');
*/
	return false;
    });
});
</script>

<div class="right mrt_5"><a href="<?=$CONST_LINK_ROOT?>/profile_update.php#add_account" class="a_button">Next</a></div><div class="grey_12 white_back solid_line_separator pageHeading"><img src="images/icon-profile.gif" width="30" height="22" align="absmiddle">  Add Your Profile Picture </div>
<div id="middle_panel" style="width:776px;">
	<table width="100%" border="0" cellpadding="5" cellspacing="0" class="white_back_t_xb">
		<tr>
			<td valign="top" width="100%"><div id="msg_content_error" class="none"></div>
				<div id="msg_content_done" class="none"></div>
				<div id="sub_content">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td width="10">&nbsp;</td>
							<td><table width="100%" border="0" cellpadding="5" cellspacing="0" class="white_back_t_xb p5">
												<tr>
													<td valign="top"><div id="profile_pic"><img src='<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>' border='0' title='<?=ucwords($sql_array->adv_username)?>'/></div></td>
													<td valign="middle"><div id="loadingBox" class="none"><img src="images/loader.gif"><br />
															<br />
														</div>
														<div id="fields">
															<input name="Submit" type="hidden" id="Submit" value="profile_picture" />
															<input name="user_id" type="hidden" value="<?=$WUserID?>" />
															<input name="file" id="file" type="file" size="30" />
														</div>
														<p> <span class="red_10">Allowed&nbsp;file&nbsp;format 
															(JPG,&nbsp;GIF&nbsp;or&nbsp;PNG&nbsp;) <br />
															The file size limit 4 MB. <br />
															If your upload does not 
															work, 
															try   uploading a smaller picture.</span> </p>
														<p>By uploading a file you certify and accept responsibility of all the  file that you have submitted in <a href="http://www.wowdoyou.com/terms.html">Terms of Use</a>.</p></td>
												</tr>
											</table></td>
						</tr>
						<tr>
							<td align="right">&nbsp;</td>
							<td align="right">&nbsp;</td>
						</tr>
						<tr>
							<td align="center">&nbsp;</td>
							<td align="center">&nbsp;</td>
						</tr>
					</table>
				</div></td>
		</tr>
	</table>
</div>
