<?php
ini_set("register_globals", "On");
$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";
}


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;
$have_microdata = in_array($microdata_domain, $microdata_domains);

$result_categtop = mysql_query ($query_categtop) or die(mysql_error());
if (mysql_num_rows($result_categtop) > 0){
	$have_featured = "yes";
	?>
	<div class="adverts-box">
	<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
		<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"><?php echo $recomented_value_en;?> </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 align=center 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="0">
								<tr align="center" valign="top"> 
								<?php
								$count_categtop = 1;
								while($line_categtop = mysql_fetch_assoc($result_categtop)){
									
									$use_town_dir = false;
									
									//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%">
										<?php
										if($have_microdata) {
											echo '<div itemscope="itemscope" itemtype="http://schema.org/LocalBusiness">';
										}
										?>
										<div class="adv_unit" <?php echo ($have_microdata) ? 'itemscope="itemscope" itemtype="' . $microdata_types[$microdata_domain]['adverts']['type'] . '"' : '';?>>
										<?
										//echo 'open_window=',$line_categtop['open_window'] , " / ", $line_categtop['website'], "<br/>";
										if($line_categtop['open_window']!="yes" && $line_categtop['open_window']!="relative"){
											?>
											<div class="advcont" onMouseOver="document.getElementById('adv<?php echo $line_categtop["advertisment_id"];?>').style.visibility = 'visible';" onMouseOut="document.getElementById('adv<?php echo $line_categtop['advertisment_id'];?>').style.visibility = 'hidden';">
												<div id="adv<?php echo $line_categtop["advertisment_id"];?>" class="moreadv">
													<a href="<?php echo $shortNameURL;?>" link="click_count.php?link=<?php echo $line_categtop["title_tr"];?>&amp;type=adv&amp;id=<?php echo $line_categtop['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=top&amp;catdom_id=<?php echo $catdom_id;?>&amp;cc=1" title="<?php echo $shortNameALT;?>: More Info" target="_blank" class="featured_adv_linkage">more info</a>
												</div>
											</div>
												<?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, 'top');
										}
										// top = category top
										?>
											<?php
											echo '<a ';
											if($line_categtop['open_window']=="yes" && $line_categtop['website']!=""){
												?>
												href="http://<?php echo "{$line_categtop['website']}";?>"
												<?php 
											}
											elseif($line_categtop['open_window']=="relative" && $line_categtop['website']!=""){
												?>
												href="<?php echo "{$line_categtop['website']}";?>"
												<?php 
											}
											else {
												?>
												href="click_count.php?link=<?php echo $shortNameURL;?>&amp;type=www&amp;id=<?php echo $line_categtop['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=top&amp;catdom_id=<?php echo $catdom_id;?>" target="_blank" class="click-count" 
												<?php 
											}
											
											if($line_categtop['open_window']=="yes" && $line_categtop['website']!=""){
												?>
												onclick="window.open('click_count.php?link=<?php echo $shortNameURL;?>&amp;type=adv&amp;id=<?php echo $line_categtop['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=top&amp;catdom_id=<?php echo $catdom_id;?>&amp;cc=1','',''); return false;" 
												<?php 
											}
											
											echo  ' title="' . $shortNameALT . ': Homepage">';
											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 echo ($have_microdata) ? 'itemprop="image"' : '';?>/><?php 
											}
											else{
												?><img src="<?php echo $path;?>images/navigation/no_pic.gif" width="85" height="74" border="0" alt="No picture"/><?php 
											}
											echo '</a>'
											?>
											
											<br>
										
											<strong><a class="advert" <?php 
												/*Theodosis addition*/ 
												if($line_categtop['open_window']=="yes" && $line_categtop['website']<>""){
													?>
													href="http://<?php echo "{$line_categtop['website']}";?>" 
													<?php 
												}
												elseif($line_categtop['open_window']=="relative" && $line_categtop['website']<>""){
													?>
													href="http://<?php echo "{$line_categtop['website']}";?>" 
													<?php 
												}
												else {
													
													/*
													href="click_count.php?link=<?php echo $line_categtop["title_tr"];?>&amp;type=www&amp;id=<?php echo $line_categtop['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=top&amp;catdom_id=<?php echo $catdom_id;?>" target="_blank" OnMouseover="window.status='http://<?php echo $line_categtop["website"];?>';return true;" OnMouseout="window.status=' ';" 
													*/
													echo 'href="http://',$microdata_host . '/' . $shortNameURL,'" ';
													?>
													onclick="javascript:this.href='click_count.php?link=<?php echo $shortNameURL;?>&amp;type=www&amp;id=<?php echo $line_categtop['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=top&amp;catdom_id=<?php echo $catdom_id;?>&amp;cc=1';"
													<?php
												}
												
												if($line_categtop['open_window']=="yes" && $line_categtop['website']<>""){
													?>
													onclick="window.open('click_count.php?link=<?php echo $shortNameURL;?>&amp;type=adv&amp;id=<?php echo $line_categtop['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=top&amp;catdom_id=<?php echo $catdom_id;?>&amp;cc=1','',''); return false;" 
													<?php 
												}
												echo ($have_microdata) ? 'itemprop="url"' : '';
												?>
												target="_blank"
												title="<?php echo $shortNameALT;?>"
												>
												<span <?php echo ($have_microdata) ? 'itemprop="name"' : ''; ?>><?php echo $shortNameALT;?></span>
												</a>
											</strong>
										<?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"/></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>
										<?php
										if($have_microdata) {
											echo '</div>';
										}
										?>
									</td>
									<?php 
									$count_categtop++;
									
									if($count_categtop>5){
										$count_categtop = 1;
										echo '</tr>', '<tr align="center" valign="top">', '<td>&nbsp;</td>','</tr>';
										echo '<tr align="center" valign="top">';
									} 
								}
	?>
	</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"/></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"/></td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	</div>
	<?php 
}
?>
<?php //$query_adverts - loaded from ../general/queries.php

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

$result_adverts = mysql_query ($query_adverts);
if (mysql_num_rows($result_adverts) <> 0){
	
	?>
	<div class="adverts-box">
<table border=0 cellspacing=0 width="98%" align="center" cellpadding="2">
		<?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"><?php echo $recomented_value_en;?> </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 align="center"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="FeturedAdTd">
              <tr align="center" valign="top"> 
                <td colspan="5"><img src="<?php echo $path;?>images/navigation/spacer.gif" width="1" height="8" alt="css-img"/></td>
              </tr>
              <tr align="center" valign="top"> 
				<?php 
				$count_adverts=1;
				while($line_adverts = mysql_fetch_array($result_adverts)){
					$use_town_dir = false;
					//Ioan modification
					//echo $line_adverts['order_seq'];
					$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%">
	<?php
	if($have_microdata) {
		echo '<div itemscope="itemscope" itemtype="http://schema.org/LocalBusiness">';
	}
	?>
	<div class="adv_unit" <?php echo ($have_microdata) ? 'itemscope="itemscope" itemtype="' . $microdata_types[$microdata_domain]['adverts']['type'] . '"' : '';?>>
		<?
		if($line_adverts['open_window']!="yes" && $line_adverts['open_window']!="relative"){
			?>
			<div class="advcont" onMouseOver="document.getElementById('adv<?php echo $line_adverts['advertisment_id'];?>').style.visibility = 'visible';" onMouseOut="document.getElementById('adv<?php echo $line_adverts['advertisment_id'];?>').style.visibility = 'hidden';">
				<div id="adv<?php echo $line_adverts['advertisment_id'];?>" class="moreadv">
					<a href="<?php echo $shortNameURL;?>" link="click_count.php?link=<?php echo $line_adverts["title_tr"];?>&amp;type=adv&amp;id=<?php echo $line_adverts['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=sel&amp;catdom_id=<?php echo $catdom_id;?>" title="<?php echo $shortNameALT;?>: More Info" target="_blank" class="featured_adv_linkage click-count">more info</a>
				</div>
			</div>
			<?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, 'sel');
		}
		// sel = selected adverts
		?>
			<?php 
			echo '<a onMouseOver="document.getElementById(\'adv' . $line_adverts["advertisment_id"] .'\').style.visibility = \'visible\';" onMouseOut="document.getElementById(\'adv' .$line_adverts['advertisment_id'] .'\').style.visibility = \'hidden\';"';
			if($line_adverts['open_window']=="yes" && $line_adverts['website']<>""){
				?>
				href="http://<?php echo "$line_adverts[website]";?>" 
				<?php 
			} 
			elseif($line_adverts['open_window']=="relative" && $line_adverts['website']<>""){
				?>
				href="<?php echo "$line_adverts[website]";?>" 
				<?php 
			}
			else {
				?>
				href="click_count.php?link=<?php echo $shortNameURL;?>&amp;type=www&amp;id=<?php echo $line_adverts['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=sel&amp;catdom_id=<?php echo $catdom_id;?>" target="_blank" class="click-count" 
				<?php 
			}
			
			if($line_adverts['open_window']=="yes" && $line_adverts['website']<>""){
				?> 
				onclick="window.open('click_count.php?link=<?php echo $shortNameURL;?>&amp;type=adv&amp;id=<?php echo $line_adverts['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=sel&amp;catdom_id=<?php echo $catdom_id;?>&amp;cc=1','',''); return false;" 
				<?php 
			}
			
			echo ' title="'.$shortNameALT.': Homepage">';
			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 echo ($have_microdata) ? 'itemprop="image"': '';?>/><?php 
			}
			else{
				?><img src="<?php echo $path;?>images/navigation/no_pic.gif" width="85" height="74" border="0" alt="No picture"/><?php 
			}
			echo '</a>';
			?>
		<br>
		<strong>
			<a class="advert" <?php 
				/*Theodosis addition */ 
				if($line_adverts['open_window']=="yes" && $line_adverts['website']<>""){
					?>
					href="http://<?php echo "$line_adverts[website]";?>" 
					<?php 
				} 
				elseif($line_adverts['open_window']=="relative" && $line_adverts['website']<>""){
					?>
					href="<?php echo "{$line_adverts['website']}";?>" 
					<?php 
				}
				else{
					echo 'href="http://',$microdata_host . '/' . $shortNameURL,'" ';
					?>
					onclick="javascript:this.href='click_count.php?link=<?php echo $shortNameURL;?>&amp;type=www&amp;id=<?php echo $line_adverts['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=sel&amp;catdom_id=<?php echo $catdom_id;?>&amp;cc=1';" target="_blank" 
					<?php 
				}
				
				if($line_adverts['open_window']=="yes" && $line_adverts['website']<>""){
					?> 
					onclick="window.open('click_count.php?link=<?php echo $shortNameURL;?>&amp;type=adv&amp;id=<?php echo $line_adverts['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=sel&amp;catdom_id=<?php echo $catdom_id;?>&amp;cc=1','',''); return false;" 
					<?php 
				}
				echo ($have_microdata) ? 'itemprop="url"': '';
				?>
			title="<?php echo $shortNameALT;?>">
			<span <?php echo ($have_microdata) ? 'itemprop="name"': '';?>><?php echo $shortNameALT;?></span>
			</a>
		</strong>
		<?php
		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>';
		}
		/*
		if($line_adverts['open_window']!="yes" && $line_adverts['open_window']!="relative"){
		?>
		</div>
		<?php 
		} 
		*/
?>
</div>
<?php
if($have_microdata) {
	echo '</div>';
}
?>
</td><?php $count_adverts++;
		if($count_adverts>5){$count_adverts=1;echo '</tr><tr align="center" valign="top">
                      <td>&nbsp;</td>
                    </tr>
<tr align="center" valign="top">';
} 
}?>
              </tr>
              <tr align="center"> 
                <td colspan="5"><img src="<?php echo $path;?>images/navigation/spacer.gif" width="1" height="8" alt="css-img"/></td>
              </tr>
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td bgcolor="#E6E6E6"><img src="<?php echo $path;?>images/navigation/spacer.gif" width="1" height="3" alt="css-img"/></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      </div>
		<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>
      	<script type="text/javascript">
			$(document).ready(function(){
				
				$('a.click-count').each(function(i){
					var field = "cc";
					var href = $(this).attr('href');
					var cc_type = -1;
					
					
					if(href.indexOf('?' + field + '=') != -1) {
					    cc_type = 1;
					}
					else if(href.indexOf('&' + field + '=') != -1) {
					    cc_type = 2;
					}
					else if(href.indexOf('?') != -1) {
					    cc_type = 0;
					    $(this).attr('href', href + '&cc=1');
					}
					else {
						cc_type = -1;
					    $(this).attr('href', href + '?cc=1');
					}
				});
				
				<?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
				}
				?>
				
				/*
				var $diag = $('<div></div>')
							.dialog({
								autoOpen: false,
								modal: true,
								width: $(document).width()-50,
								height: $(window).height()-20,
								title: 'Some Title',
								dialogClass: "company_dialog",
								buttons: {
									"Close": function() {
										$diag.dialog('close');
									}
								},
								position: 'top',
								open: function (event, ui) {
								}
							});
				
				//$diag.parent().addClass('company_dialog');
				var fix_class = $diag.parent().attr('class');
				fix_class = 'company_dialog ' + fix_class.replace('company_dialog', '');
				$diag.parent().attr('class', fix_class);
				//alert($diag.parent().attr('class'));
							
				$('.featured_adv_linkage').live('click', function(ev){
						ev.preventDefault();
						$diag.html('');
						var $lnk = $(this);
						var info_link = $lnk.attr('link');
						//alert(info_link);
						var info_title = $lnk.attr('title');
						
						var $frm = $('<iframe id="process_frm" name="process_frm"></iframe>');
						//$frm.attr('src', 'http://<?php echo $_SERVER['HTTP_HOST'];?>/modules/adverts_map/map_directions.php?location_id=' + loc_id);
						$frm.attr('src', info_link + '&page=1');
						$frm.attr('width', '100%');
						$frm.attr('height', '100%');
						$frm.css('border', '1px solid #000000');
						$frm.css('overflow-y', 'auto');
						
						$diag.append($frm);
						$diag.dialog("option", "title", info_title);
						$diag.dialog("option", "width", $(document).width()-50);
						$diag.dialog("option", "height", $(window).height()-20);
						
						
						$diag.dialog("open");
						
						return false;
					
				});
				
				$('.map_directions_link').live('click', function(e){
					e.preventDefault();
					var loc_id = $(this).attr('rel');
					openDirections(loc_id);
					return false;
				});
				
				$('.map_enlarge_link').live('click', function(e){
					e.preventDefault();
					var loc_id = $(this).attr('rel');
					openBigMap(loc_id);
					return false;
				});
				
				*/
				
			});
		
		</script>
		<?php 
	
}
?>