<?php
// This file is only for cyprus-hotel.com

$remotehost = $_SERVER['REMOTE_ADDR'];
$date_now = date("Y-m-d", time());
$after1month  = date("Y-m-d",mktime(0, 0, 0, date("m")+1 ,date("d"), date("Y")));
$after3months  = date("Y-m-d",mktime(0, 0, 0, date("m")+3 ,date("d"), date("Y")));
if(isset($catdom_id) && intval($catdom_id)>0){
	$catdom_id_adv = $catdom_id;
}
else {
	$catdom_id_adv = $domain_id;
	$catdom_id = $domain_id;
}




// Get town friendly url
/*
$town_friendly_url = "";
if($catdom_id_adv != $domain_id) {
	$q = "select * from domaincategories where catdom_id='$catdom_id_adv';";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		$row = mysql_fetch_assoc($r);
		$town_friendly_url = trim($row['friendly_url']) . "/";
	}
}
*/


$domain_idx2 = sprintf("%04.0f", $catdom_id_adv);


$root_host = $_SERVER['HTTP_HOST'];
if(str_replace('www.', '', $root_host) != str_replace('www.', '', $ultra_domainname)) {
	$root_host .= "/$ultra_addonname";
}

$is_hotel = false;
if(str_replace('www.', '', $ultra_domainname) == "cyprus-hotel.com") {
	$is_hotel = true;
}


include($general_path . "queries.php");

$short_invoice_types = array(
	"999999"		=> array("short_name"=>"Complim.", "color"=>"#F02FFF"),
	"888888"		=> array("short_name"=>"Filler", "color"=>"#09AF00"),
	"777777"		=> array("short_name"=>"Featured", "color"=>"#FFD100"),
	"555555"		=> array("short_name"=>"Friends", "color"=>"#39424B"),
	"444444"		=> array("short_name"=>"Link Exch.", "color"=>"#800000")
);

$bind_types =  array(
	//"invoice"		=> "Payable",
	"t_upgrade"			=> "Temp.Upgrade",
	"t_complimentary"	=> "Temp.Complim",
	"t_filler"			=> "Temp.Filler"
);

$optres['css'][] = $path . "css/company_dialog/jquery-ui-1.8.23.custom.css";
//$optres ['css'][] = $path . "css/smoothness/jquery-ui-1.8.19.custom.css";
$optres['js'][] = $path . "js/jquery-ui-1.8.23.custom.min.js";

$optres ['css'][] = $path . "client_stand.css";
$optres ['css'][] = $path . "css/prettyPhoto.css";
$optres ['js'][] = $path . "js/jquery.prettyPhoto.js";

$have_featured = "no";
$microdata_domain = str_replace("www.", "", $ultra_domainname);
$microdata_host = $_SERVER['HTTP_HOST'];
if(str_replace('www.', '', $microdata_host) != str_replace('www.', '', $ultra_domainname)) $microdata_host .= "/" . $ultra_addonname;

$result_categtop = mysql_query ($query_categtop) or die(mysql_error());
if (mysql_num_rows($result_categtop) > 0){
	$have_featured = "yes";
	?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td> 
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td><img src="<?php echo $path;?>images/navigation/featured_box/featured_left.gif" width="14" height="29" alt="css-img" /></td>
									<td class="featuredHeader"><span style="margin: 0; padding: 0;color: #006699;font-size: 12px;font-weight: bold;"><?php echo $recomented_value_en;?></span></td>
									<td><img src="<?php echo $path;?>images/navigation/featured_box/featured_cor.gif" width="29" height="29" alt="css-img"/></td>
								</tr>
							</table>
						</td>
						<td align="right">&nbsp;</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table border="0" cellpadding="0" cellspacing="0" width="100%">
					<tr> 
						<td height="10" width="10"><img height="10" src="<?php echo $path;?>images/navigation/featured_box/box_1.gif" width="10" alt="css-img"/></td>
						<td background="<?php echo $path;?>images/navigation/featured_box/box_top.gif"></td>
						<td width="10"><img height="10" src="<?php echo $path;?>images/navigation/featured_box/box_2.gif" width="12" alt="css-img"/></td>
					</tr>
					<tr> 
						<td background="<?php echo $path;?>images/navigation/featured_box/box_left.gif"></td>
						<td align="center" valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="3">
								<tr align="center" valign="top"> 
								<?php
								$count_categtop = 1;
								$total_adverts = mysql_num_rows($result_categtop);
								$num_adverts = 1;
								while($line_categtop = mysql_fetch_assoc($result_categtop)){
									
									$use_town_dir = false;
									$show_website = intval($line_categtop['show_website']);
									//echo '<pre>', print_r($line_categtop),'</pre>';
									//die();
									//Theodosis modification
									$display_name = str_replace('"','',$line_categtop["short_title_en"]);
									$shortNameURL = $line_categtop["title_tr"];
									$shortNameALT = str_replace('"','',$line_categtop["short_title_en"]);
									
									$params = $line_categtop['params'];
									if($params != "") {
										$params = unserialize(base64_decode($params));
										if(is_array($params) && count($params)>0) {
											if(isset($params['display_name']) && trim($params['display_name']) != "") {
												$qt = "select * from advertisment_tradenames where tradename_id='{$params['display_name']}';";
												//echo $qt;
												$rt = @mysql_query($qt);
												if($rt && mysql_num_rows($rt) == 1) {
													$rowt = mysql_fetch_assoc($rt);
													$display_name = stripslashes(trim($rowt['tradename']));
													//echo $display_name;
													$shortNameALT = $display_name;
													$shortNameURL = $rowt['friendly_url'];
												}
											}
											
											if(isset($params['locations']) && is_array($params['locations']) && count($params['locations']) > 0) {
												$use_town_dir = true;
											}
											
										}
									}
									
									//if($use_town_dir) $shortNameURL = $town_friendly_url . $shortNameURL;
									
									
									?>
									<td width="20%">
										<div class="adv_unit">
										<?php 
										if (!isset($_SESSION['user_id'])){
											mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$line_categtop['advertisment_id']}'") or die (mysql_error());
											count_views('adverts_stats_views', 'advertisment_id', $line_categtop['advertisment_id'], $domain_id, $catdom_id_adv, 'top');
											
											$_adverts_views [] = array(
												"adv_code"				=> $line_categtop['adv_code'],
												"advertisment_id"		=> $line_categtop['advertisment_id'],
												"domain_id"				=> $domain_id,
												"catdom_id"				=> $catdom_id_adv,
												"domainname"			=> $ultra_domainname,
												"date_short"			=> date("Y-m-d"),
												"date_long"				=> date("Y-m-d H:i:s"),
												"views"					=> 1,
												"view_from"				=> 'topjs'
											);
											
										}
										
										// top = category top

										echo '<div class="advert_logo">';
                                            if($show_website == 1) {
											    echo '<a href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_categtop['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=top&amp;catdom_id='.$catdom_id_adv.'" target="_blank" rel="nofollow" class="click-count">';
                                            }
												if($line_categtop['advertisment']<>""){
													?><img src="<?php echo $path;?>images/advertisments/<?php echo $line_categtop["advertisment"];?>" width="85" height="74" border="0" alt="<?php echo $shortNameALT;?>"/><?php 
												}
												else{
													?><img src="<?php echo $path;?>images/navigation/no_pic.gif" width="85" height="74" border="0" alt="No picture"/><?php 
												}
                                            if($show_website == 1) {
											    echo '</a>';
                                            }
										echo '</div>';
										

										// Get the eventual rate
										$min_price = 0;
										$q_rates = "select a.* from hotel_affiliates_adverts a, hotel_affiliates r where a.aff_code=r.aff_code and r.aff_status='1' and a.adv_code='{$line_categtop['adv_code']}' and a.aff_hotel_status='1' order by a.low_rate asc;";
										
										$r_rates = @mysql_query($q_rates);
										if($r_rates && mysql_num_rows($r_rates) > 0) {
											while ($row_rates = mysql_fetch_assoc($r_rates)) {
												if($min_price == 0 && floatval($row_rates['low_rate']) > 0 ) {
													$min_price = floatval($row_rates['low_rate']);
												}
												if(floatval($row_rates['low_rate']) < $min_price) $min_price = floatval($row_rates['low_rate']);
											}
										}
										
										if($min_price > 0) {
											?>
											<div class="rate-bubble">
												<a href="<?php echo 'http://',$microdata_host . '/' . $shortNameURL; ?>" target="_blank" class="rate-bubble-a"><span class="rate-bubble-text">From</span> &euro; <?php echo number_format($min_price, 0);?></a>
											</div>
											<?php
										}
										else {
											?>
											<div class="rate-bubble">
												<a href="<?php echo 'http://',$microdata_host . '/' . $shortNameURL; ?>" target="_blank" class="rate-bubble-a"><span class="rate-bubble-text">Check Availability</span></a>
											</div>
											<?php
										}
										
										/*
											?>
											<a href="<?php echo 'http://',$microdata_host . '/' . $shortNameURL; ?>" target="_blank" class="org-info"><img src="<?php echo $path. 'images/navigation/org_info.png';?>" alt="<?php echo $shortNameALT;?> Info"></a>
											<?php
										*/
										?>
										<a class="advert-js" <?php
                                            if($show_website == 1) {
											    echo ' href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_categtop['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=top&amp;catdom_id='.$catdom_id_adv.'"';
                                            }
											echo ' rel="nofollow" target="_blank" ';
											?>
											title="<?php echo $shortNameALT;?>">
											<?php echo $shortNameALT;?>
										</a>
										
										<?php 
										if (isset($_SESSION['user_id'])){
											
											$invoice_no = trim($line_categtop["invoice_no"]);
											$bind_type = trim($line_categtop["bind_type"]);
											$t_active_from = (trim($line_categtop["active_from"]) != "" && trim($line_categtop["active_from"]) != "0000-00-00") ? strtotime(trim($line_categtop["active_from"])) : "null";
											$t_active_to = (trim($line_categtop["active_to"]) != "" && trim($line_categtop["active_to"]) != "0000-00-00") ? strtotime(trim($line_categtop["active_to"])) : "null";
											$cur_timestamp = time();
											echo '<br/><a href="../admin/advert_manager.php?advert_action=advert_edit_main&advertisment_id=',$line_categtop['advertisment_id'],'" target="_blank">Edit</a>';
											echo '<div style="margin: 3px 0px;clear:both;">';
											if($invoice_no != "") {
												$inv_details = "";
												$qinv = "select i.details from advertisment_invoice i where i.adv_code='{$line_categtop["adv_code"]}' and i.in_use='1' and i.invoice='{$line_categtop["invoice_no"]}';";
												$rinv = mysql_query($qinv);
												if($rinv && mysql_num_rows($rinv)>0) {
													$rowinv = mysql_fetch_assoc($rinv);
													$inv_details = stripslashes($rowinv['details']);
												}
												
												if(array_key_exists($invoice_no, $short_invoice_types)) {
													echo '<span style="color:'.$short_invoice_types[$invoice_no]['color'].';">'.$short_invoice_types[$invoice_no]['short_name'].'</span>';
												}
												else {
													echo '<span style="color: #0000EE; font-weight: bold; text-decoration: none; ">'.$invoice_no.'</span>';
												}
												
												if($inv_details != "") {
													$inv_details = "Invoice Note ::: &raquo; " . $inv_details;
													?>
													<a href="javascript:;" class="tooltip_views" rel="<?php echo $inv_details;?>"><img src="/images/class_info_red.gif" border="0" align="middle" alt="css-img"/></a>
													<?php
												}
												
											}
											else {
												echo '<span style="color:#ff0000;">[ <strong>NO_INVOICE</strong> ]</span>';
											}
											
											if($t_active_to != "null") {
												$active_from = $t_active_from != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
												$active_to = $t_active_to != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';

												if($cur_timestamp > intval($t_active_to)) {
													echo '<br style="clear:both;"/><div style="color:#ff0000;" title="EXPIRED!!!">',$active_from, ' - ', $active_to,'</div>';
												}
												elseif(intval($t_active_to) < (strtotime("+2 month",$cur_timestamp))) {
													echo '<br style="clear:both;"/><div style="color:#0000EE;" title="EXPIRES IN LESS THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
												}
												else {
													echo '<br style="clear:both;"/><div style="color:#000000;" title="EXPIRES IN MORE THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
												}
											}
											else {
												$active_from = trim($t_active_from) != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
												$active_to = trim($t_active_to) != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';
												echo '<br style="clear:both;"/><div style="color:#ff0000;" title="No Expiration Date">',$active_from, ' - ', $active_to,'</div>';
											}
											if($bind_type != "") {
												echo '<div style="clear: both; height: 16px; color:#ff0000; background-color: #FFE900;">',($bind_types[$bind_type]),'</div>';
											}
											
											
											if($line_categtop["member_id"]>0){
												$qha = "SELECT a.name, a.surname, a.user_id FROM auth a, members m WHERE m.member_id='{$line_categtop['member_id']}' AND a.user_id=m.salesman_id";
												$rha = @mysql_query($qha);
												if($rha && mysql_num_rows($rha) > 0) {
													$line_member = mysql_fetch_assoc($rha);
													echo '<div style="clear: both; height: 16px;">';
													echo '<strong>SP:</strong> ' . $line_member["name"] . ' ' . $line_member["surname"];
													echo '</div>';
												}
												else {
													echo '<div style="clear: both; height: 16px;">NO_SALESMAN</div>';
												}
											}
											else {
												echo '<div style="clear: both; height: 16px;">NO_CUSTOMER</div>';
											}
											echo '</div>';
										}
										?>
										</div>
										
									</td>
									<?php 
									$count_categtop++;
									
									if($count_categtop>5){
										$count_categtop = 1;
										if($total_adverts > $num_adverts) {
											echo '</tr>';
											echo '<tr align="center" valign="top">';
										}
									} 
									
									$num_adverts ++;
								}
	?>
	</tr>
	</table></td>
	<td background="<?php echo $path;?>images/navigation/featured_box/box_right.gif"></td>
	</tr>
	<tr> 
	<td height="12" width="10"><img height="12" src="<?php echo $path;?>images/navigation/featured_box/box_3.gif" width="10" alt="css-img"/></td>
	<td background="<?php echo $path;?>images/navigation/featured_box/box_bot.gif"></td>
	<td><img height="12" src="<?php echo $path;?>images/navigation/featured_box/box_4.gif" width="12" alt="css-img"/></td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<?php 
}
?>
<?php //$query_adverts - loaded from ../general/queries.php

//if (isset($_SESSION['user_id'])){
//	echo $query_adverts;
//}

if(isset($_REQUEST['debugadv'])) {
	echo '<br/>' . $query_adverts;
}

$result_adverts = mysql_query ($query_adverts);
if (mysql_num_rows($result_adverts) <> 0){
	$total_adverts = mysql_num_rows($result_adverts);
	?>
	<table border="0" cellspacing="0" width="100%" align="center" cellpadding="0">
			<?php
			if($catdom_id_adv != $domain_id && $have_featured=="no") {
				?>
				<tr>
					<td>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td> 
									<table border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td><img src="<?php echo $path;?>images/navigation/featured_box/featured_left.gif" width="14" height="29" alt="css-img"/></td>
											<td class="featuredHeader"><span style="margin: 0; padding: 0;color: #006699;font-size: 12px;font-weight: bold;"><?php echo $recomented_value_en;?></span></td>
											<td><img src="<?php echo $path;?>images/navigation/featured_box/featured_cor.gif" width="29" height="29" alt="css-img"/></td>
										</tr>
									</table>
								</td>
								<td align="right">&nbsp;</td>
							</tr>
						</table>
					</td>
				</tr>
				<?php
			}
			else {
				?>
		        <tr> 
		          <td height="8"></td>
		        </tr>
		        <?php
			}
	        ?>
	        
			<tr> 
				<td>
					<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
						<tbody>
							<tr> 
								<td width="10" height="10"><img width="10" height="10" alt="css-img" src="<?php echo $path;?>images/navigation/featured_box/box_1.gif"/></td>
								<td background="<?php echo $path;?>images/navigation/featured_box/box_top.gif"></td>
								<td width="10"><img width="12" height="10" alt="css-img" src="<?php echo $path;?>images/navigation/featured_box/box_2.gif"/></td>
							</tr>
							<tr> 
								<td background="<?php echo $path;?>images/navigation/featured_box/box_left.gif"></td>
								<td valign="top" align="center">
									<table width="100%" cellspacing="0" cellpadding="3" border="0">
										<tr align="center" valign="top"> 
											<?php 
											$count_adverts=1;
											$num_adverts = 1;
											while($line_adverts = mysql_fetch_assoc($result_adverts)){
												$use_town_dir = false;
												//Ioan modification
												//echo $line_adverts['order_seq'];
                                                $show_website = intval($line_adverts['show_website']);
												$display_name = str_replace('"','',$line_adverts["short_title_en"]);
												$shortNameURL = $line_adverts["title_tr"];
												$shortNameALT = str_replace('"','',$line_adverts["short_title_en"]);
												
												$params = $line_adverts['params'];
												if($params != "") {
													$params = unserialize(base64_decode($params));
													//print_r($params);
													if(is_array($params) && count($params)>0) {
														if(isset($params['display_name']) && trim($params['display_name']) != "") {
															$qt = "select * from advertisment_tradenames where tradename_id='{$params['display_name']}';";
															$rt = @mysql_query($qt);
															if($rt && mysql_num_rows($rt) == 1) {
																$rowt = mysql_fetch_assoc($rt);
																$display_name = stripslashes(trim($rowt['tradename']));
																$shortNameALT = $display_name;
																$shortNameURL = $rowt['friendly_url'];
															}
														}
													}
													if(isset($params['locations']) && is_array($params['locations']) && count($params['locations']) > 0) {
														$use_town_dir = true;
													}
												
												}
												
												
												//if($use_town_dir) $shortNameURL = $town_friendly_url . $shortNameURL;
												
												?>
												<td width="20%" valign="top">
												
												<div class="adv_unit">
												<?php
												if (!isset($_SESSION['user_id'])){
													mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$line_adverts['advertisment_id']}'") or die (mysql_error());
													count_views('adverts_stats_views', 'advertisment_id', $line_adverts['advertisment_id'], $domain_id, $catdom_id_adv, 'sel');
													
													$_adverts_views [] = array(
													"adv_code"				=> $line_adverts['adv_code'],
													"advertisment_id"		=> $line_adverts['advertisment_id'],
													"domain_id"				=> $domain_id,
													"catdom_id"				=> $catdom_id_adv,
													"domainname"			=> $ultra_domainname,
													"date_short"			=> date("Y-m-d"),
													"date_long"				=> date("Y-m-d H:i:s"),
													"views"					=> 1,
													"view_from"				=> 'seljs'
													);
												
												}
												
												// sel = selected adverts
												
												echo '<div class="advert_logo">';
                                                if($show_website == 1) {
												    echo '<a href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_adverts['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=sel&amp;catdom_id='.$catdom_id_adv.'" target="_blank" rel="nofollow" title="'.$shortNameALT.'" class="click-count">';
                                                }
												if($line_adverts['advertisment']<>""){
													?><img src="<?php echo $path;?>images/advertisments/<?php echo $line_adverts["advertisment"];?>" width="85" height="74" border="0" alt="<?php echo $shortNameALT;?>"/><?php 
												}
												else{
													?><img src="<?php echo $path;?>images/navigation/no_pic.gif" width="85" height="74" border="0" alt="No picture"/><?php 
												}
                                                if($show_website == 1) {
												    echo '</a>';
                                                }
												echo '</div>';
												
												// Get the eventual rate
												$min_price = 0;
												$q_rates = "select a.* from hotel_affiliates_adverts a, hotel_affiliates r where a.aff_code=r.aff_code and r.aff_status='1' and a.adv_code='{$line_adverts['adv_code']}' and a.aff_hotel_status='1' order by a.low_rate asc;";
												
												$r_rates = @mysql_query($q_rates);
												if($r_rates && mysql_num_rows($r_rates) > 0) {
													while ($row_rates = mysql_fetch_assoc($r_rates)) {
														if($min_price == 0 && floatval($row_rates['low_rate']) > 0 ) {
															$min_price = floatval($row_rates['low_rate']);
														}
														if(floatval($row_rates['low_rate']) < $min_price) $min_price = floatval($row_rates['low_rate']);
													}
												}
												
												if($min_price > 0) {
													?>
													<div class="rate-bubble">
														<a href="<?php echo 'http://',$microdata_host . '/' . $shortNameURL; ?>" target="_blank" class="rate-bubble-a"><span class="rate-bubble-text">From</span> &euro; <?php echo number_format($min_price, 0);?></a>
													</div>
													<?php
												}
												else {
													?>
													<div class="rate-bubble">
														<a href="<?php echo 'http://',$microdata_host . '/' . $shortNameURL; ?>" target="_blank" class="rate-bubble-a"><span class="rate-bubble-text">Check Availability</span></a>
													</div>
													<?php
												}
												/*
												
													?>
													<a href="<?php echo 'http://',$microdata_host . '/' . $shortNameURL; ?>" target="_blank" class="org-info"><img src="<?php echo $path. 'images/navigation/org_info.png';?>" alt="<?php echo $shortNameALT;?> Info"></a>
													<?php
												*/
												
												echo '<a class="advert-js" ';
                                                if($show_website == 1) {
												    echo ' href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_adverts['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=sel&amp;catdom_id='.$catdom_id_adv.'"';
                                                }
												echo ' rel="nofollow" target="_blank" ';
												echo ' title="' . $shortNameALT . '">';
												echo $shortNameALT;
												echo '</a>';

												
												if (isset($_SESSION['user_id'])){
													$invoice_no = trim($line_adverts["invoice_no"]);
													$bind_type = trim($line_adverts["bind_type"]);
													$t_active_from = (trim($line_adverts["active_from"]) != "" && trim($line_adverts["active_from"]) != "0000-00-00") ? strtotime(trim($line_adverts["active_from"])) : "null";
													$t_active_to = (trim($line_adverts["active_to"]) != "" && trim($line_adverts["active_to"]) != "0000-00-00") ? strtotime(trim($line_adverts["active_to"])) : "null";
													$cur_timestamp = time();
													echo '<br/><a href="../admin/advert_manager.php?advert_action=advert_edit_main&advertisment_id=',$line_adverts['advertisment_id'],'" target="_blank">Edit</a>';
													echo '<div style="margin: 3px 0px;clear:both;">';
													if($invoice_no != "") {
														$inv_details = "";
														$qinv = "select i.details from advertisment_invoice i where i.adv_code='{$line_adverts["adv_code"]}' and i.in_use='1' and i.invoice='{$line_adverts["invoice_no"]}';";
														$rinv = mysql_query($qinv);
														if($rinv && mysql_num_rows($rinv)>0) {
															$rowinv = mysql_fetch_assoc($rinv);
															$inv_details = stripslashes($rowinv['details']);
														}
														
														if(array_key_exists($invoice_no, $short_invoice_types)) {
															echo '<span style="color:'.$short_invoice_types[$invoice_no]['color'].';">'.$short_invoice_types[$invoice_no]['short_name'].'</span>';
														}
														else {
															echo '<span style="color: #0000EE; font-weight: bold; text-decoration: none; ">'.$invoice_no.'</span>';
														}
														
														if($inv_details != "") {
															$inv_details = "Invoice Note ::: &raquo; " . $inv_details;
															?>
															<a href="javascript:;" class="tooltip_views" rel="<?php echo $inv_details;?>"><img src="/images/class_info_red.gif" border="0" align="middle" alt="css-img"/></a>
															<?php
														}
													
													}
													else {
														echo '<span style="color:#ff0000;">[ <strong>NO_INVOICE</strong> ]</span>';
													}
													
													if($t_active_to != "null") {
														$active_from = $t_active_from != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
														$active_to = $t_active_to != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';
														
														if(intval($t_active_to) < $cur_timestamp) {
															echo '<br style="clear:both;"/><div style="color:#ff0000;" title="EXPIRED!!!">',$active_from, ' - ', $active_to,'</div>';
														}
														elseif(intval($t_active_to) > $cur_timestamp && intval($t_active_to) < (strtotime("+2 month",$cur_timestamp))) {
															echo '<br style="clear:both;"/><div style="color:#0000EE;" title="EXPIRES IN LESS THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
														}
														else {
															echo '<br style="clear:both;"/><div style="color:#000000;" title="EXPIRES IN MORE THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
														}
													}
													else {
														$active_from = trim($t_active_from) != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
														$active_to = trim($t_active_to) != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';
														echo '<br style="clear:both;"/><div style="color:#ff0000;" title="No Expiration Date">',$active_from, ' - ', $active_to,'</div>';
													}
													if($bind_type != "") {
														echo '<div style="clear: both; height: 16px; color:#ff0000; background-color: #FFE900;">',($bind_types[$bind_type]),'</div>';
													}
													
													
													if($line_adverts["member_id"]>0){
														$qha = "SELECT a.name, a.surname, a.user_id FROM auth a, members m WHERE m.member_id='{$line_adverts['member_id']}' AND a.user_id=m.salesman_id";
														$rha = @mysql_query($qha);
														if($rha && mysql_num_rows($rha) > 0) {
															$line_member = mysql_fetch_assoc($rha);
															echo '<div style="clear: both; height: 16px;">';
															echo '<strong>SP:</strong> ' . $line_member["name"] . ' ' . $line_member["surname"];
															echo '</div>';
														}
														else {
															echo '<div style="clear: both; height: 16px;">NO_SALESMAN</div>';
														}
													}
													else {
														echo '<div style="clear: both; height: 16px;">NO_CUSTOMER</div>';
													}
													echo '</div>';
												}
												?>
												</div>
												
												</td>
												<?php 
												$count_adverts++;
												if($count_adverts>5){
													$count_adverts=1;
													if($total_adverts > $num_adverts) echo '</tr>';
													/*
													<tr>
														<td>&nbsp;</td>
													</tr>
													*/
													if($total_adverts > $num_adverts) echo '<tr>';
												}
												
												$num_adverts ++;
											}
											?>
											</tr>
									</table>
								</td>
								<td background="<?php echo $path;?>images/navigation/featured_box/box_right.gif"></td>
							</tr>
							<tr> 
								<td width="10" height="12"><img width="10" height="12" src="<?php echo $path;?>images/navigation/featured_box/box_3.gif" alt="css-img"/></td>
								<td background="<?php echo $path;?>images/navigation/featured_box/box_bot.gif"></td>
								<td><img width="12" height="12" src="<?php echo $path;?>images/navigation/featured_box/box_4.gif" alt="css-img"/></td>
							</tr>
						</tbody>
					</table>
	          
	            
				</td>
			</tr>
		</table>
		<div id="loading_page" style="display: none; height: 220px;">
			<div style="top:110px;">
				<p style="font-size: 14px; font-weight: bold; text-align: center;">Please wait. Loading page..</p>
			</div>
		</div>
		<br/>
	<?php
	$curl_path = "http://" . $_SERVER['HTTP_HOST'] . "/curl.php";
	if(str_replace('www.', '', $_SERVER['HTTP_HOST']) != str_replace('www.', '', $ultra_domainname)) {
		$curl_path = "http://" . $_SERVER['HTTP_HOST'] . "/$ultra_addonname/curl.php";
	}
}
?>
<script type="text/javascript">
//<![CDATA[
	$(document).ready(function(){
		<?php
		if (isset($_SESSION['user_id'])){
			?>
			// Tooltips
			$(".tooltip_views").tooltip({
				showURL: false,
				track: true,
			    bodyHandler: function() {
			    	var vs  = this.rel;
			    	var title = "";
			    	var body = vs;
			    	var ps = vs.split(" ::: ");
			    	if(ps.length>1) {
			    		title = ps[0];
			    		body = ps[1];
			    	}
			    	if(title != "") {
			    		return $("<div></div>").append($("<h3></h3>").append(title)).append(body);
			    	}
			    	else {
			        	return $("<div></div>").append(vs);
			    	}
			    },
			    fade: 10
			});
			
			<?php
		}
		?>
	});
//]]>
</script>