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

$option_manager = new OptionManager();
$currencysym = $option_manager->GetValue('currency_symbol');
$currency = $option_manager->GetValue('currency');
$currencypoint = $option_manager->GetValue('currency_point');

$WUserID = $_SESSION['Sess_UserId'];

$now = getdate();
$initial_date = date ("F d, Y", mktime (0,0,0,1,1,$now['year']));
$today_date = date ("F d, Y", mktime (0,0,0,$now['mon'],$now['mday'],$now['year']));

	switch ($_REQUEST["mode"]) {
	case "active"; 
		active($WUserID);
		break;
	case "inactive"; 
		inactive($WUserID);
		break;
	case "hotPost"; 
		hotPost($WUserID);
		break;
	case "hotPostLoad"; 
		hotPostLoad($WUserID);
		break;
	case "social"; 
		social($WUserID);
		break;
	case "socialLoad"; 
		socialLoad($WUserID);
		break;
	case "marketer"; 
		marketer($WUserID);
		break;
	case "marketerLoad"; 
		marketerLoad($WUserID);
		break;
	case "recentPost"; 
		recentPost($WUserID);
		break;
	case "recentPostLoad"; 
		recentPostLoad($WUserID);
		break;
	default; 
		echo "";
		break;
	}

function ago($datefrom,$dateto=-1)
{
        // Defaults and assume if 0 is passed in that
        // its an error rather than the epoch
   
        if($datefrom==0) { return "A long time ago"; }
        if($dateto==-1) { $dateto = time(); }
       
        // Make the entered date into Unix timestamp from MySQL datetime field

        $datefrom = strtotime($datefrom);
   
        // Calculate the difference in seconds betweeen
        // the two timestamps

        $difference = $dateto - $datefrom;

        // Based on the interval, determine the
        // number of units between the two dates
        // From this point on, you would be hard
        // pushed telling the difference between
        // this function and DateDiff. If the $datediff
        // returned is 1, be sure to return the singular
        // of the unit, e.g. 'day' rather 'days'
   
        switch(true)
        {
            // If difference is less than 60 seconds,
            // seconds is a good interval of choice
            case(strtotime('-1 min', $dateto) < $datefrom):
                $datediff = $difference;
                $res = ($datediff==1) ? $datediff.' second ago' : $datediff.' seconds ago';
                break;
            // If difference is between 60 seconds and
            // 60 minutes, minutes is a good interval
            case(strtotime('-1 hour', $dateto) < $datefrom):
                $datediff = floor($difference / 60);
                $res = ($datediff==1) ? $datediff.' minute ago' : $datediff.' minutes ago';
                break;
            // If difference is between 1 hour and 24 hours
            // hours is a good interval
            case(strtotime('-1 day', $dateto) < $datefrom):
                $datediff = floor($difference / 60 / 60);
                $res = ($datediff==1) ? $datediff.' hour ago' : $datediff.' hours ago';
                break;
            // If difference is between 1 day and 7 days
            // days is a good interval               
            case(strtotime('-1 week', $dateto) < $datefrom):
                $day_difference = 1;
                while (strtotime('-'.$day_difference.' day', $dateto) >= $datefrom)
                {
                    $day_difference++;
                }
               
                $datediff = $day_difference;
                $res = ($datediff==1) ? 'yesterday' : $datediff.' days ago';
                break;
            // If difference is between 1 week and 30 days
            // weeks is a good interval           
            case(strtotime('-1 month', $dateto) < $datefrom):
                $week_difference = 1;
                while (strtotime('-'.$week_difference.' week', $dateto) >= $datefrom)
                {
                    $week_difference++;
                }
               
                $datediff = $week_difference;
                $res = ($datediff==1) ? 'last week' : $datediff.' weeks ago';
                break;           
            // If difference is between 30 days and 365 days
            // months is a good interval, again, the same thing
            // applies, if the 29th February happens to exist
            // between your 2 dates, the function will return
            // the 'incorrect' value for a day
            case(strtotime('-1 year', $dateto) < $datefrom):
                $months_difference = 1;
                while (strtotime('-'.$months_difference.' month', $dateto) >= $datefrom)
                {
                    $months_difference++;
                }
               
                $datediff = $months_difference;
                $res = ($datediff==1) ? $datediff.' month ago' : $datediff.' months ago';

                break;
            // If difference is greater than or equal to 365
            // days, return year. This will be incorrect if
            // for example, you call the function on the 28th April
            // 2008 passing in 29th April 2007. It will return
            // 1 year ago when in actual fact (yawn!) not quite
            // a year has gone by
            case(strtotime('-1 year', $dateto) >= $datefrom):
                $year_difference = 1;
                while (strtotime('-'.$year_difference.' year', $dateto) >= $datefrom)
                {
                    $year_difference++;
                }
               
                $datediff = $year_difference;
                $res = ($datediff==1) ? $datediff.' year ago' : $datediff.' years ago';
                break;
               
        }
        return $res;
	}

function active($WUserID) {
global $initial_date, $today_date;
$active_query=mysql_query("SELECT postID, case when char_length(title) > 250 then concat(LEFT(title,250), '...') else title end as title, price, DATE_FORMAT(expDate, '%M %d, %Y at %h:%i%p') as expDateNew, forTitle, dataName, IFNULL(clickTotal,'0') as clickTotal, IFNULL(ImpTotal,'0') as ImpTotal FROM market_Post LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN market_category_data on (subCat=dataID) LEFT JOIN market_Post_click USING ( postID ) where mem_userid=$WUserID and approve=1 and expDate > now() order by expDate desc") or die(mysql_error());
$activeTotal = mysql_num_rows($active_query);

$first_query=mysql_query("SELECT DATE_FORMAT(postDate, '%M %d, %Y') as postDate, DATE_FORMAT(repostDate, '%M %d, %Y') as repostDate FROM market_Post where mem_userid=$WUserID and approve=1 and expDate > now() order by postDate asc limit 1") or die(mysql_error());
$firstTotal = mysql_num_rows($first_query);

$last_query=mysql_query("SELECT DATE_FORMAT(postDate, '%M %d, %Y') as postDate, DATE_FORMAT(repostDate, '%M %d, %Y') as repostDate FROM market_Post where mem_userid=$WUserID and approve=1 and expDate > now() order by postDate desc limit 1") or die(mysql_error());
$lastTotal = mysql_num_rows($last_query);
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="white_back_t_xb">
	<tr>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td><div class="light_orang_h">
				<div style="width:10px; height:10px; float:left; margin-top:3px; margin-right:5px; background: #6600FF;"><img src="images/spacer.gif" width="10" height="10" /></div>
				<span class="red_b">All Active Listings</span> </div>
			<div class="dot_line"><img src="images/spacer.gif" width="1" height="1" /></div>
			<div class="solid_line"><img src="images/spacer.gif" width="1" height="1" /></div></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
	<?php if($activeTotal>0) {?>
	<tr>
		<td><table width="100%" border="0" cellpadding="5" cellspacing="1" id="structureTable2">
				<tr>
					<th width="100%" align="left"> <?php if($firstTotal > 0) {
								$first = mysql_fetch_object($first_query);
								if (!empty($first->repostDate)) echo $first->repostDate; else echo $first->postDate;} else echo $initial_date;
								
								/*if($lastTotal > 0) {
								$last = mysql_fetch_object($last_query);
								echo " - ".$last->postDate;} else */echo " - ".$today_date;
							?>
					</th>
					<th width="1%" align="left" nowrap="nowrap">Clicks</th>
					<th width="1%" align="left" nowrap="nowrap">Impressions</th>
					<th width="1%" align="left" nowrap="nowrap">Comments</th>
					<th width="10%" align="left"> Expiration </th>
					<th width="1%" align="left">Action</th>
				</tr>
				<?php
						while ($sql = mysql_fetch_object($active_query) ) {
						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						?>
				<tr id="post<?=$sql->postID?>">
					<td><strong>
						<?=$sql->forTitle?>
						: </strong><a href="#cshowPost?tab=active&postID=<?=$sql->postID?>" class="blue_b" onclick="javascript: callpage(this.href);"><?php echo ucwords($sql->title); if(!empty($sql->price)) echo " for ".strtoupper($sql->price);?></a> in
						<?=$sql->dataName?></td>
					<td align="center"><?=$sql->clickTotal?></td>
					<td align="center"><?=$sql->ImpTotal?></td>
					<td align="center"><?=$comment->CommentTotal?></td>
					<td nowrap="nowrap"><?=$sql->expDateNew?></td>
					<td nowrap="nowrap"><a href="#ceditPost?tab=post&postID=<?=$sql->postID?>" onclick="javascript: callpage(this.href);"><span class="black_b">Edit</span> </a>| <a href="javascript: void(null)" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/postDelete.php?postID=<?=$sql->postID?>'}, 'Delete&nbsp;Post', 'deletePost'); return false;" rel="facebox"><span class="red_b">Delete</span></a> </td>
				</tr>
				<?php } ?>
			</table></td>
	</tr>
	<?php } else {?>
	<tr>
		<td><?php  print(NO_RECORDS_SECTION_NAME); ?>
			!</td>
	</tr>
	<?php }?>
</table>
<?php
}


function inactive($WUserID) {
global $initial_date, $today_date;

$inactive_query=mysql_query("SELECT postID, case when char_length(title) > 250 then concat(LEFT(title,250), '...') else title end as title, price, status, IF(expDate< now(),'Expired','null') AS expired, forTitle, dataName, IFNULL(clickTotal,'0') as clickTotal, IFNULL(ImpTotal,'0') as ImpTotal FROM market_Post LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN market_category_data on (subCat=dataID) LEFT JOIN market_Post_click USING ( postID ) where mem_userid=$WUserID and (approve=0 or expDate< now()) order by expDate desc") or die(mysql_error());
$inactiveTotal = mysql_num_rows($inactive_query);

$first_query=mysql_query("SELECT DATE_FORMAT(postDate, '%M %d, %Y') as postDate, DATE_FORMAT(repostDate, '%M %d, %Y') as repostDate FROM market_Post where mem_userid=$WUserID and (approve=0 or expDate< now()) order by postDate desc limit 1") or die(mysql_error());
$firstTotal = mysql_num_rows($first_query);

$last_query=mysql_query("SELECT DATE_FORMAT(postDate, '%M %d, %Y') as postDate, DATE_FORMAT(repostDate, '%M %d, %Y') as repostDate FROM market_Post where mem_userid=$WUserID and (approve=0 or expDate< now()) order by postDate asc limit 1") or die(mysql_error());
$lastTotal = mysql_num_rows($last_query);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="white_back_t_xb">
	<tr>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td><div class="light_orang_h">
				<div style="width:10px; height:10px; float:left; margin-top:3px; margin-right:5px; background: #6600FF;"><img src="images/spacer.gif" width="10" height="10" /></div>
				<span class="red_b">All InActive Listings</span> </div>
			<div class="dot_line"><img src="images/spacer.gif" width="1" height="1" /></div>
			<div class="solid_line"><img src="images/spacer.gif" width="1" height="1" /></div></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
	<?php if($inactiveTotal>0) {?>
	<tr>
		<td><table width="100%" border="0" cellpadding="5" cellspacing="1" id="structureTable2">
				<tr>
					<th width="100%" align="left"> <?php if($firstTotal > 0) {
								$first = mysql_fetch_object($first_query);
								if (!empty($first->repostDate)) echo $first->repostDate; else echo $first->postDate;} else echo $initial_date;
								
								/*if($lastTotal > 0) {
								$last = mysql_fetch_object($last_query);
								echo " - ".$last->postDate;} else */echo " - ".$today_date;
							?>
					</th>
					</th>
					<th width="1%" align="left" nowrap="nowrap">Clicks</th>
					<th width="1%" align="left" nowrap="nowrap">Impressions</th>
					<th width="1%" align="left" nowrap="nowrap">Comments</th>
					<th width="10%" align="left"> Reason </th>
					<th width="1%" align="left">Action</th>
				</tr>
				<?php
						while ($sql = mysql_fetch_object($inactive_query) ) {
						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						?>
				<tr>
					<td><strong>
						<?=$sql->forTitle?>
						: </strong><a href="#cshowInPost?tab=inactive&postID=<?=$sql->postID?>" class="blue_b" onclick="javascript: callpage(this.href);"><?php echo ucwords($sql->title); if(!empty($sql->price)) echo " for ".strtoupper($sql->price);?></a> in
						<?=$sql->dataName?></td>
					<td align="center"><?=$sql->clickTotal?></td>
					<td align="center"><?=$sql->ImpTotal?></td>
					<td align="center"><?=$comment->CommentTotal?></td>
					<td nowrap="nowrap"><?php if(!empty($sql->status)) echo $sql->status; else echo $sql->expired; ?></td>
					<td nowrap="nowrap"><?php if(!empty($sql->expired)) echo "<a href=\"javascript: void(null)\" onclick=\"javascript: jQuery.facebox({ajax:'$CONST_LINK_ROOT/postContinue.php?postID=$sql->postID'}, 'RePost', 'rePost'); return false;\" rel=\"facebox\"><span class=\"black_b\">Repost</span> </a>| "; ?>
						<a href="#ceditPost?tab=post&postID=<?=$sql->postID?>" onclick="javascript: callpage(this.href);"><span class="black_b">Edit</span> </a> | <a href="javascript: void(null)" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/postDelete.php?postID=<?=$sql->postID?>'}, 'Delete&nbsp;Post', 'deletePost'); return false;" rel="facebox"><span class="red_b">Delete</span></a> </td>
				</tr>
				<?php } ?>
			</table></td>
	</tr>
	<?php } else {?>
	<tr>
		<td><?php  print(NO_RECORDS_SECTION_NAME); ?>
			!</td>
	</tr>
	<?php }?>
</table>
<?php
}

function hotPost($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$start = 0;

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate,  location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDate, why, description, IFNULL(clickTotal,'0') as clickTotal2, IFNULL(ImpTotal,'0') as ImpTotal2, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() order by ImpTotal desc, clickTotal desc limit 0, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
<div id="search_result" class="result_box padding_5" rel="hotPostLoad">
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { $desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					} elseif ($encode=="ASCII") { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					} else { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-
		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal2?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal2?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDate?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-hot"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-hot').appendChild(e);
		  
      }());
</script>
	<?php 
	} ?>
<div class="clear"><img src="images/spacer.gif" /></div>
<?php if ($active_total==10){?>
<div id="loadMore"><a href="javascript: void(null)" onclick="javascript: last_msg_funtion(); return false;" ><div class="paging" align="center">NEXT<div id="paginate_loading"><img src="images/spacer.gif"></div></div></a></div>
<div id="noMore" align="center"><img src="images/spacer.gif" /></div>
<?php } else {?>
<div id="noMoreShow" align="center">There are no more items to show at the moment</div>
<?php } ?>
</div>
<?php
						} else {
						 print(NO_RECORDS_SECTION_NAME."!");
						} 
}

function hotPostLoad($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$j = explode('_',$_REQUEST['lastID']);
$start = $j[0];

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate, location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDate, why, description, IFNULL(clickTotal,'0') as clickTotal2, IFNULL(ImpTotal,'0') as ImpTotal2, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() order by ImpTotal desc, clickTotal desc limit $start, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
					$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { $desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					} elseif ($encode=="ASCII") { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					} else { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-

		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal2?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal2?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDate?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-hot"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-hot').appendChild(e);
		  
      }());
</script>
	<?php 
	} ?>
<?php
						} else {
						echo "There are no more items to show at the moment";
						}
}

function social($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$start = 0;

$myhahaper_query=mysql_query("SELECT mem_userid FROM my_friends LEFT JOIN members ON (friend_uid=mem_userid) WHERE uid='$WUserID' and approved='1'") or die(mysql_error());
$myhahaper_TOTAL = mysql_num_rows($myhahaper_query);
if( $myhahaper_TOTAL > 0) {
$friends = array();
while ($hahaper_pic = mysql_fetch_object($myhahaper_query)) {
$friends[] = $hahaper_pic->mem_userid;
}
$friends = implode(',', $friends);

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate, location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDateNew, why, description, IFNULL(clickTotal,'0') as clickTotal, IFNULL(ImpTotal,'0') as ImpTotal, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() and mem_userid in ($friends) order by expDate desc limit 0, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
<div id="search_result" class="result_box padding_5" rel="socialLoad">
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
					$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { $desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					} elseif ($encode=="ASCII") { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					} else { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-
		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDateNew?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-social"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-social').appendChild(e);
		  
      }());
</script>
	<?php } ?>
<div class="clear"><img src="images/spacer.gif" /></div>
<?php if ($active_total==10){?>
<div id="loadMore"><a href="javascript: void(null)" onclick="javascript: last_msg_funtion(); return false;" ><div class="paging" align="center">NEXT<div id="paginate_loading"><img src="images/spacer.gif"></div></div></a></div>
<div id="noMore" align="center"><img src="images/spacer.gif" /></div>
<?php } else {?>
<div id="noMoreShow" align="center">There are no more items to show at the moment</div>
<?php } ?>
</div>
<?php
						} else {
						 print(NO_RECORDS_SECTION_NAME."!");
						} 
}else {
 print(NO_RECORDS_SECTION_NAME."!");
}
}

function socialLoad($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$j = explode('_',$_REQUEST['lastID']);
$start = $j[0];

$myhahaper_query=mysql_query("SELECT mem_userid FROM my_friends LEFT JOIN members ON (friend_uid=mem_userid) WHERE uid='$WUserID' and approved='1'") or die(mysql_error());
$myhahaper_TOTAL = mysql_num_rows($myhahaper_query);
if( $myhahaper_TOTAL > 0) {
$friends = array();
while ($hahaper_pic = mysql_fetch_object($myhahaper_query)) {
$friends[] = $hahaper_pic->mem_userid;
}
$friends = implode(',', $friends);

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate, location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDateNew, why, description, IFNULL(clickTotal,'0') as clickTotal, IFNULL(ImpTotal,'0') as ImpTotal, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() and mem_userid in ($friends) order by expDate desc limit $start, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
					$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { $desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					} elseif ($encode=="ASCII") { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					} else { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-
		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDateNew?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-social"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-social').appendChild(e);
		  
      }());
</script>
	<?php } ?>
<?php
} else {
						echo "There are no more items to show at the moment";
						}
}else {
 print(NO_RECORDS_SECTION_NAME."!");
}
}

function marketer($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$start = 0;

$myhahaper_query=mysql_query("SELECT mem_userid FROM my_friends LEFT JOIN members ON (friend_uid=mem_userid) WHERE uid='$WUserID' and approved='1'") or die(mysql_error());
$myhahaper_TOTAL = mysql_num_rows($myhahaper_query);
if( $myhahaper_TOTAL > 0) {
$friends[] = $WUserID;
while ($hahaper_pic = mysql_fetch_object($myhahaper_query)) {
$friends[] = $hahaper_pic->mem_userid;
}
$friends = implode(',', $friends);

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate, location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDateNew, why, description, IFNULL(clickTotal,'0') as clickTotal, IFNULL(ImpTotal,'0') as ImpTotal, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() and mem_userid not in ($friends) order by expDate desc limit 0, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
<div id="search_result" class="result_box padding_5" rel="marketerLoad">
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
					$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { $desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					} elseif ($encode=="ASCII") { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					} else { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-
		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDateNew?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-market"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-market').appendChild(e);
		  
      }());
</script>
	<?php } ?>
<div class="clear"><img src="images/spacer.gif" /></div>
<?php if ($active_total==10){?>
<div id="loadMore"><a href="javascript: void(null)" onclick="javascript: last_msg_funtion(); return false;" ><div class="paging" align="center">NEXT<div id="paginate_loading"><img src="images/spacer.gif"></div></div></a></div>
<div id="noMore" align="center"><img src="images/spacer.gif" /></div>
<?php } else {?>
<div id="noMoreShow" align="center">There are no more items to show at the moment</div>
<?php } ?>
</div>
<?php
						} else {
						 print(NO_RECORDS_SECTION_NAME."!");
						} 
}else {
 print(NO_RECORDS_SECTION_NAME."!");
}
}

function marketerLoad($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$j = explode('_',$_REQUEST['lastID']);
$start = $j[0];

$myhahaper_query=mysql_query("SELECT mem_userid FROM my_friends LEFT JOIN members ON (friend_uid=mem_userid) WHERE uid='$WUserID' and approved='1'") or die(mysql_error());
$myhahaper_TOTAL = mysql_num_rows($myhahaper_query);
if( $myhahaper_TOTAL > 0) {
$friends[] = $WUserID;
while ($hahaper_pic = mysql_fetch_object($myhahaper_query)) {
$friends[] = $hahaper_pic->mem_userid;
}
$friends = implode(',', $friends);

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate, location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDateNew, why, description, IFNULL(clickTotal,'0') as clickTotal, IFNULL(ImpTotal,'0') as ImpTotal, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() and mem_userid not in ($friends) order by expDate desc limit $start, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
					$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { $desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					} elseif ($encode=="ASCII") { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					} else { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-
		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDateNew?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-market"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-market').appendChild(e);
		  
      }());
</script>
	<?php } ?>
<?php
						}   else {
						echo "There are no more items to show at the moment";
						}
}else {
 print(NO_RECORDS_SECTION_NAME."!");
}
}

function recentPost($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$start = 0;

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate, location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDate, expDate as expDateori, why, description, IFNULL(clickTotal,'0') as clickTotal2, IFNULL(ImpTotal,'0') as ImpTotal2, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() order by expDateori desc limit 0, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
<div id="search_result" class="result_box padding_5" rel="recentPostLoad">
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
					$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { 
					
					$desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); 					if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					
					} elseif ($encode=="ASCII") { 
					$desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); 
					if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					
					} else { 
					$desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); 
					if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-
		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal2?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal2?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDate?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-recent"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-recent').appendChild(e);
		  
      }());
</script>
	<?php 
	} ?>
<div class="clear"><img src="images/spacer.gif" /></div>
<?php if ($active_total==10){?>
<div id="loadMore"><a href="javascript: void(null)" onclick="javascript: last_msg_funtion(); return false;" ><div class="paging" align="center">NEXT<div id="paginate_loading"><img src="images/spacer.gif"></div></div></a></div>
<div id="noMore" align="center"><img src="images/spacer.gif" /></div>
<?php } else {?>
<div id="noMoreShow" align="center">There are no more items to show at the moment</div>
<?php } ?>
</div>
<?php
						} else {
						 print(NO_RECORDS_SECTION_NAME."!");
						} 
}

function recentPostLoad($WUserID) {
global $SITE_MAIN_WWW_ROOT,$CONST_LINK_ROOT,$currencypoint;

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$j = explode('_',$_REQUEST['lastID']);
$start = $j[0];

$active_query=mysql_query("SELECT postID, case when char_length(A.title) > 250 then concat(LEFT(A.title,250), '...') else A.title end as title, forTitle, price, IFNULL(repostDate,postDate) as postDate, location as Location, DATE_FORMAT(expDate, '%M %d, %Y') as expDate, expDate as expDateori, why, description, IFNULL(clickTotal,'0') as clickTotal2, IFNULL(ImpTotal,'0') as ImpTotal2, mem_userid, mem_username, mem_profileid, status, IF(expDate< now(),'Expired',NULL) AS expired, IFNULL(E.dataName,D.dataName) as Category, price2, commision FROM market_Post A LEFT JOIN market_category_for on (optionFor=forID) LEFT JOIN members USING (mem_userid) LEFT JOIN Geo_Countries C on (A.Country=C.CountryId) LEFT JOIN market_Post_click USING ( postID ) LEFT JOIN market_category_data D on (subCat=D.dataID) LEFT JOIN market_category_data E on (subCatsub=E.dataID) where approve=1 and expDate > now() order by expDateori desc limit $start, 10") or die(mysql_error());
$active_total = mysql_num_rows($active_query);

if($active_total>0) {?>
	<?php
					
						while ($sql = mysql_fetch_object($active_query) ) {
	$start++;
					$encode = mb_detect_encoding(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")));
					if($encode=="UTF-8") { $desc = str_replace("&", "&amp;", mb_substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 190, "UTF-8")); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>190) $desc.="...";
					} elseif ($encode=="ASCII") { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					} else { $desc = str_replace("&", "&amp;", substr(strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")), 0, 250)); if (strlen (strip_tags(html_entity_decode($sql->description, ENT_QUOTES, "UTF-8")))>250) $desc.="...";
					}
					$photo_query=mysql_query("SELECT photoMed FROM market_PostPhoto where mem_userid=$sql->mem_userid and postID=$sql->postID order by photoID asc limit 1") or die(mysql_error());
					$photoTotal = mysql_num_rows($photo_query);
					if($photoTotal>0) {
					$sqlPhoto = mysql_fetch_object($photo_query);
					if(!empty($sqlPhoto->photoMed)) $url = $sqlPhoto->photoMed; 
					else $url = "images/noimage.jpg";
					}
					else $url = "images/noimage.jpg";

						$comment_query = mysql_query("SELECT COUNT(comment_id) AS CommentTotal FROM market_Post_comment where postID=$sql->postID") or die(mysql_error());
						$comment = mysql_fetch_object($comment_query);
						
if ($WUserID==$sql->mem_userid) {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$pic_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$sql->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($pic_query);
$aPicture = mysql_fetch_object($pic_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$sql->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($sql->mem_userid);
}
if ($sql->mem_profileid != null) { $male1_name1= $sql->mem_profileid; }
else { $male1_name1= $sql->mem_username; }

$price = number_format(ceil($sql->price/$currencypoint),0);
$price2 = number_format(ceil($sql->price2/$currencypoint),0);
						?>
	<div class="content4 border-1px-light<?php if(!empty($sql->status) || !empty($sql->expired)) echo " redlight_row_back";?>" id="<?=$start?>_post<?=$sql->postID?>"><div class="delete"><a href="javascript:;" onclick="javascript:hidePost('<?=$start?>_post<?=$sql->postID?>');">x</a></div>
		<div class="share"><fb:like href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" send="true" layout="box_count" show_faces="false"></fb:like><a class="email" href="javascript:;" onclick="STTAFFUNC.cw(this, {id:'2010091044975-2', link: '<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>', title: '<?php echo ucwords($sql->title); if(!empty($price)) echo " for ".$price;?>' }); return false;">Email</a></div>
		<div class="content5">
		<div class="image_w100h1003"><a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;"><img src="<?=$url?>" width="170" height="170" border="0" /></a></div>
		<span class="rightContent5"><strong>
		<?=$sql->forTitle?>
		:</strong> <a href="<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mshowlistPop.php?tab=categories&postID=<?=$sql->postID?>&uID=<?=$sql->mem_userid?>'}, '<?=$sql->forTitle?>', 'hotpost'); return false;" class="blue_b"> <?php echo ucwords($sql->title); if(!empty($price)) echo " for <img src=\"images/iconPA_o.gif\" border=\"0\" align=\"absmiddle\" />".$price;?></a> <br />
		<span class="rightContent6">
		<?php /*if(!empty($sql->why)) { echo ucwords($sql->why); } else*/ echo ucfirst($desc);?>
		</span> </span><span class="image_w50h50"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><img src="<?=$male1_picture1?>" title="Name:&nbsp;<?=ucwords($sql->mem_username)?>"/></a></span><span class="rightContent3 lightgrey_10">
		<span class='grey_10'><?=$sql->Category?></span><br />
		<?=ucwords($sql->Location)?><div class="clear"><img src="images/spacer.gif" height="5" /></div><span class="lightgrey_10">
		<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"<?php /*?> onclick="javascript: callprofileInfo(<?=$sql->mem_userid?>);"<?php */?>><span class="lightgrey_10"><?=ucwords($sql->mem_username)?></span></a>
		-

		<?=ago($sql->postDate)?>
		</span>
		</span>
		
		<div class="clear"><img src="images/spacer.gif" height="3" /></div>
		<span class="grey_10"> <span class="orangeBackp3">Clicks: <strong>
		<?=$sql->clickTotal2?>
		</strong></span> <span class="orangeBackp3">Impressions: <strong>
		<?=$sql->ImpTotal2?>
		</strong></span> <span class="orangeBackp3">Comments: <strong>
		<?=$comment->CommentTotal?>
		</strong></span> <span class="orangeBackp3">Expiration: <strong>
		<?=$sql->expDate?>
		</strong></span> <span class="orangeBackp3">Promo Link: <strong>
		<?=$CONST_LINK_ROOT."/MKT".$sql->postID?>
		</strong></span> </span> </div></div>
		<div id="fb-root-recent"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '132880206758943',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root-recent').appendChild(e);
		  
      }());
</script>
	<?php 
	} ?>
<?php
						} else {
						echo "There are no more items to show at the moment";
						}
}

?>
