<?php
require_once($general_path . "microdata_pool.php");

$left_pool_empty = true;

$authorized_advert = false;
$paying_advert = false;

// New Seo
$seo = false;

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

$adv_code = trim($linePopup['adv_code']);
$webpage_title_en = stripslashes($linePopup['short_title_en']);
$meta_params = array(
	"company"	=> stripslashes($linePopup['short_title_en']),
	"location"	=> "",
	"category"	=> stripslashes(trim($line_catdom_id["title_en"]))
);

$meta['keywords'] = stripslashes($linePopup['short_title_en']) . ', ' . $meta['keywords'];

$meta_replacements = array(
	'[COMPANY]',
	'[LOCATION]',
	'[CATEGORY]'
);

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

$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";


$meta_loc = "";

$meta_phrase = "[COMPANY] is a Cyprus business located in [LOCATION]. It is operating in the field of [CATEGORY]";
$advert_meta_description = trim(stripslashes($linePopup["meta_description"]));
$advert_meta_keywords = trim(stripslashes($linePopup["meta_keywords"]));
$advert_use_meta = intval($linePopup["use_meta"]);

$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;
	
	require_once("../general/functions.php");
}
else {
	require_once($general_path . "functions.php");
}
$have_microdata = (isset($microdata_domains) && in_array($microdata_domain, $microdata_domains));

// Get domain catdoms
$catdoms = array();
$catdoms_idx = array();
$wb_uid = "";
$catdoms [] = $domain_id;
$catdoms_idx [] = "'" . sprintf("%04.0f", $domain_id) . "'";
$result_sub = mysql_query ("SELECT * FROM  domaincategories WHERE parent_id='$domain_id';");
if (mysql_num_rows($result_sub) <> 0){			  
	while($line_sub = mysql_fetch_array($result_sub)){ 
		$catdoms [] = intval($line_sub["catdom_id"]);
		$catdoms_idx [] = "'" . sprintf("%04.0f", $line_sub["catdom_id"]) . "'";
		
		if(isset($town_friendly_url) && $town_friendly_url == $line_sub['friendly_url']) {
			$town_catdom_id = intval($line_sub['catdom_id']);
		}
		
	}
}

// Get domain category
$q = "select * from wb_categories_domains where wb_domainname='".(str_replace("www.", "", $ultra_domainname))."';";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) == 1) {
	$row = mysql_fetch_assoc($r);
	$wb_uid = $row['wb_uid'];
}


// Check if advert belongs to this category
if(isset($wb_uid) && strlen($wb_uid) == 16) {
	$q = "select * from wb_categories_adverts where wb_uid='$wb_uid' and wb_advert_uid='{$linePopup['adv_code']}';";
	if(isset($_REQUEST['debug'])) echo "<br/>$q";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) == 1) {
		$row = mysql_fetch_assoc($r);
		$wb_status = intval($row['wb_status']);
		
		if($wb_status == 1) $authorized_advert = true;
	}
}

// Get Main category and filter values *******************************************/
if($fm_uid == "") {
	$q = "select * from wb_filters_adverts_categs where adv_code='$adv_code';";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) == 1) {
		$row = mysql_fetch_assoc($r);
		$fm_uid = trim($row['fm_uid']);
	}
}

$fmains = array();
$fcategs = array();
$felems = array();
$elms = array();

$q = "select * from wb_filters_mains where wb_uid='$wb_uid' order by pos asc;";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) > 0) {
	while ($row = mysql_fetch_assoc($r)) {
		$fmains [$row['fm_uid']] = array_map('stripslashes', $row);
	}
}


if($fm_uid != "") {

	$q = "select * from wb_filters_categs where wb_uid='$wb_uid' and fm_uid='$fm_uid' order by pos asc;";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		while ($row = mysql_fetch_assoc($r)) {
			if(!isset($fcategs[$row['fm_uid']])) {
				$fcategs[$row['fm_uid']] = array();
				$fcategs[$row['fm_uid']][$row['fc_uid']] = array_map('stripslashes', $row);
			}
			else {
				$fcategs[$row['fm_uid']][$row['fc_uid']] = array_map('stripslashes', $row);
			}
			
		}
	}
	
	$q = "select * from wb_filters_elems where wb_uid='$wb_uid'  and fm_uid='$fm_uid' order by fc_uid asc, pos asc;";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		while ($row = mysql_fetch_assoc($r)) {
			$elms[$row['e_name']] = array(
				'wb_uid'	=> $row['wb_uid'],
				'fm_uid'	=> $row['fm_uid'],
				'fc_uid'	=> $row['fc_uid'],
				'fe_uid'	=> $row['fe_uid'],
			);
			
			if(!isset($felems [$row['fc_uid']])) {
				$felems [$row['fc_uid']] = array();
				$felems [$row['fc_uid']][] = array_map('stripslashes', $row);
			}
			else {
				$felems [$row['fc_uid']][] = array_map('stripslashes', $row);
			}
		}
	}



	// Get already existing values
	$fvalues = array();
	
	$q = "select * from wb_filters_adverts where wb_uid='$wb_uid' and fm_uid='$fm_uid' and adv_code='$adv_code';";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		while ($row = mysql_fetch_assoc($r)) {
			if(isset($fvalues [$row['fe_uid']])) {
				$fvalues [$row['fe_uid']][] = stripslashes(trim($row['f_value']));
			}
			else {
				$fvalues [$row['fe_uid']] = array();
				$fvalues [$row['fe_uid']][] = stripslashes(trim($row['f_value']));
			}
		}
	}
}

/****************************************************/

$specific_locations = array();

// Check if advert is supposed to show because of active bindings
$q = "select * from domain_advertisment where advertisment_id='{$linePopup['advertisment_id']}' and catdom_id IN (".implode(",", $catdoms).");";
if(isset($_REQUEST['debug'])) echo "<br/>$q";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) > 0) {
	$authorized_advert = true;
	while ($row = mysql_fetch_assoc($r)) {
		
		if($row['params'] != "") {
			$adv_params = unserialize(base64_decode($row['params']));
			if(isset($adv_params['locations']) && is_array($adv_params['locations']) && count($adv_params['locations']) > 0) {
				$specific_locations [$row['catdom_id']] = $adv_params['locations'];
			}
		}
		
		if($row['category_top'] == "yes" || $row['active'] == "yes") {
			$paying_advert = true;
		}
	}
}

if(str_replace('www.', '', $ultra_domainname) == "cyprusnet.com") $authorized_advert = true;

if(isset($_REQUEST['debug'])) echo "<br/>authorized_advert=" . var_dump($authorized_advert);

if($authorized_advert){
	$advertisment_id = $linePopup['advertisment_id'];
	$active = ($linePopup['active'] == "yes") ? "yes" : "no";
	$website = trim($linePopup['website']);
	$shortNameURL = trim($linePopup['title_tr']);
	
	$protocol = "http://";
	if(strpos($website, "https://") !== false) $protocol = "https://";
	$website = str_replace("$protocol", "", $website);
	if($website != "") {
		$website = $protocol . $website;
	}
	
	if(!isset($_SESSION['user_id']) && $paying_advert) {
		mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$linePopup['advertisment_id']}'") or die (mysql_error());
		// e stands for search engine
		count_views('adverts_stats_views', 'advertisment_id', $linePopup['advertisment_id'], $domain_id, '', 'e');
		
		$_adverts_views [] = array(
			"adv_code"				=> $linePopup['adv_code'],
			"advertisment_id"		=> $linePopup['advertisment_id'],
			"domain_id"				=> $domain_id,
			"catdom_id"				=> $domain_id,
			"domainname"			=> $ultra_domainname,
			"date_short"			=> date("Y-m-d"),
			"date_long"				=> date("Y-m-d H:i:s"),
			"views"					=> 1,
			"view_from"				=> 'e'
		);
		
	}
	// get locations
	$locations = array();
	$disp_loc = array();
	
	if(isset($town_catdom_id) && isset($specific_locations[$town_catdom_id])) {
		
		if(isset($town_friendly_url)) {
			$webpage_title_en .= " - " . ucwords(str_replace('-', ' ', $town_friendly_url));
		}
		
		$locs_str = implode(",", $specific_locations[$town_catdom_id]);
		$q = "select * from advertisment_locations where location_id in ($locs_str) and advertisment_id='$advertisment_id' and active='1' order by main_location desc;";
	}
	else {
		$q = "select * from advertisment_locations where advertisment_id='$advertisment_id' and active='1' order by main_location desc;";
	}
	//echo $q;
	
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r)>0) {
		while ($row = mysql_fetch_assoc($r)) {
			$locations [$row['location_id']] = $row;
		}
	}
	
	if(count($locations)>0) {
		$disp_loc = $locations;
	}
	
	if($paying_advert) {
		$click_count_path = "click_count.php?link={$linePopup["title_tr"]}&amp;type=www&amp;id={$linePopup['advertisment_id']}&amp;domain={$ultra_domainname}&amp;domain_id=$domain_id&amp;window=stand&amp;click_from=e&amp;cc=1";
	}
	else {
		$click_count_path = "click_count.php?link={$linePopup["title_tr"]}&amp;type=www&amp;id={$linePopup['advertisment_id']}&amp;domain={$ultra_domainname}&amp;domain_id=$domain_id&amp;window=stand&amp;click_from=e";
	}
	/*
	?>
	<div <?php echo ($have_microdata) ? 'itemscope="itemscope" itemtype="http://schema.org/'.$microdata_types[$microdata_domain]['adverts']['type'].'"' : '';?>>
	<?php
	*/
	?>
	<div id="popup" <?php echo ($have_microdata) ? 'itemscope="itemscope" itemtype="' . $microdata_types[$microdata_domain]['adverts']['type'] . '"' : '';?>>
		<h1 <?php echo ($have_microdata) ? 'itemprop="name"': '';?>><?php 
			if($seo) {
				?>
				<a href="<?php echo $linePopup["title_tr"];?>" target="_self" title="<?php echo stripslashes($linePopup['short_title_en']);?>" class="h1-link"><?php echo stripslashes($linePopup['short_title_en']);?></a>
				<?php

			}
			else {
				echo stripslashes($linePopup['short_title_en']); 
			}
			?></h1>
		<p id="website">
			
			<?php
			if($website != ""){ 
				echo ($have_microdata) ? '<meta itemprop="url" content="'.$website.'">': '';
				if($active == "yes" && $paying_advert) {
					?>
					<a href="click_count.php?link=<?php echo $linePopup["title_tr"];?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id'];?>&amp;domain=<?php echo $ultra_domainname;?>&amp;domain_id=<?php echo $domain_id;?>&amp;window=stand&amp;click_from=e" target="_blank" rel="nofollow" class="click-count" title="<?php echo stripslashes($linePopup['short_title_en']);?>">visit website</a>
					<?php 
					
				}
				else {
					?>
					<a href="<?php echo $website;?>" target="_blank" rel="nofollow" class="click-count" title="<?php echo stripslashes($linePopup['short_title_en']);?>">visit website</a>
					<?php
				}
				
				
			}
			
			if($website != "" && trim($linePopup['email']) != "") echo " | "; 
			if($linePopup['email']){
				echo ($have_microdata) ? '<meta itemprop="email" content="'.$linePopup['email'].'">': '';
				?><a href="javascript:;" class="mailto" rel="<?php echo str_replace('@', '[ at ]', $linePopup['email']); ?>">send email</a><?php 
			} 
			?>
		</p>
		
		<div id="description">
			
			<div id="img"><?php
				if($website != "") {
					if($active == "yes" && $paying_advert) {
						?>
						<a href="click_count.php?link=<?php echo $linePopup["title_tr"];?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id'];?>&amp;domain=<?php echo $ultra_domainname;?>&amp;domain_id=<?php echo $domain_id;?>&amp;window=stand&amp;click_from=e" rel="nofollow" class="click-count" target="_blank" title="<?php echo stripslashes($linePopup['short_title_en']);?>">
							<img src="http://simple.thumbshots.com/image.pxf?cid=843&amp;v=1&amp;w=200&amp;h=150&amp;url=<?php echo $website;?>" width="200" height="150" border="0" alt="<?php  echo $linePopup['short_title_en']; ?>" />
						</a>
						<?php
					}
					else {
						?>
						<a href="<?php echo $website;?>" target="_blank" rel="nofollow" class="click-count" title="<?php echo stripslashes($linePopup['short_title_en']);?> website">
							<img src="http://simple.thumbshots.com/image.pxf?cid=843&amp;v=1&amp;w=200&amp;h=150&amp;url=<?php echo $website;?>" width="200" height="150" border="0" alt="<?php  echo $linePopup['short_title_en']; ?> website" />
						</a>
						<?php
					}
				}
				?>
			</div>
			<?php
				$description_class = 'adv-desc';
				$advert_desc_text = stripslashes(trim($linePopup['description_en']));
				$qv = "select * from advertisment_versions where advertisment_id='$advertisment_id' and domainname='$ultra_domainname';";
				if(isset($_REQUEST['debugv'])) {
					echo "<br/>$qv";
				}
				$rv = @mysql_query($qv);
				if($rv && mysql_num_rows($rv) == 1) {
					$rowv = mysql_fetch_assoc($rv);
					
					$description_class = 'adv-vdesc';
					
					$advert_desc_text = trim(stripslashes($rowv['description_en']));
					if(trim($rowv['meta_description_en']) != "") $advert_meta_description = stripslashes($rowv['meta_description_en']);
					if(trim($rowv['meta_keywords_en']) != "") $advert_meta_keywords = stripslashes($rowv['meta_keywords_en']);
				}
				
				
				
				
				$advert_desc_text = str_replace(array('<br />', '<br>', '<br/>', '<br >'), '<p></p>', nl2br($advert_desc_text));
				$advert_desc_text = str_replace(array('Â'), '', nl2br($advert_desc_text));
				
				
				
			?>
			<div id="description_content" class="<?php echo $description_class;?>" <?php echo ($have_microdata) ? 'itemprop="description"': '';?>>
				<?php
				$advert_desc_text = str_replace('<p>&nbsp;</p>', '', $advert_desc_text);
				
				$pattern = "/<p[^>]*><\\/p[^>]*>/"; 
				$advert_desc_text = trim(preg_replace($pattern, '', $advert_desc_text)); 
				
				echo $advert_desc_text;
				?>
			</div>
		</div>
		<div rel="description:200" class="company_dialog read-more-expand" style="display: block;"><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-carat-2-n-s"></span> <span class="read-more-text">show more</span></div>
		<div style="clear: both;"><br/></div>
		
		<?php
		if($fm_uid != "") {
			?>
			<div id="org-details">
				<?php
				foreach ($fcategs[$fm_uid] as $fc_uid=>$fc) {
					if(isset($felems[$fc_uid])) {
						foreach ($felems[$fc_uid] as $i=>$fe) {
							$req = intval($fe['required']) == 1 ? true : false;
							$e_label_admin = $fe['e_label_display'];
							$e_type = $fe['e_type'];
							$e_name = $fe['e_name'];
							$e_id = $fe['e_id'];
							$e_class = $fe['e_class'];
							$e_style = $fe['e_style'];
							$e_db = $fe['e_db'];
							$e_def = $fe['e_def'];
							$fe_uid = $fe['fe_uid'];
							
							// Get the options
							$have_options = false;
							$elem = array();
							$elem['e_db'] = array();
							$options = trim($e_db);
							if($options != "") {
								$opts = unserialize(base64_decode($options));
								if(is_array($opts)) {
									$opts = array_map('stripslashes', $opts);
									$have_options = true;
								}
							}
							
							if($have_options) $elem['e_db'] = $opts;
							
							if($have_options) {
								$show_advert_amenity_content = false;
								ob_start();
								//echo '<pre>', var_export($elem['e_db'], true),'</pre>';
								?>
								<div style="clear: both"></div>
								<?php
								if($fc['friendly_url'] != "default") {
									?>
									<h2><?php echo $fc['title'];?></h2>
									<?php
								}
								?>
								<h2 class="wb_h2"><?php echo $e_label_admin;?></h2>
								<ul class="wb_ul" id="<?php echo $e_name;?>">
									<?php
									foreach ($elem['e_db'] as $val=>$label) {
										if(isset($fvalues[$fe_uid]) && in_array($val, $fvalues[$fe_uid])) {;
											echo '<li>';
											echo $label;
											echo '</li>';
											$show_advert_amenity_content = true;
										}
									}
									?>
									<div style="clear: both;"></div>
								</ul>
								<div class="clear-all"></div>
								<?php
								
								$advert_amenity_content = ob_get_contents();
								ob_end_clean();
								
								if($show_advert_amenity_content) echo $advert_amenity_content;
							}
							
							
						}
					}
					?>
				</div>
				<?php
			}
		}
		
		// Get images if it has 
		$gallery = array();
		$gallery_folder = $path . "images/advertisments/gallery/$advertisment_id";
		$gallery_folder_th = $path . "images/advertisments/gallery/$advertisment_id/thumbs";
		
		$q = "select * from advertisment_gallery where advertisment_id='$advertisment_id' order by pos asc;";
		$r = @mysql_query($q);
		if($r && mysql_num_rows($r) > 0) {
			while ($row = mysql_fetch_assoc($r)) {
				$gallery [] = array_map("stripslashes", $row);
			}
		}
		
		if(count($gallery) > 0) {
			?>
			<div id="org-images">
				<h2 class="wb_h2">Image Gallery</h2>
				<div class="normal_photos" id="advert_gallery">
				
					<?php
					if(is_array($gallery) && count($gallery) > 0) {
						$photo_path = $path . "images/advertisments/gallery/" . $advertisment_id . "/";
						$cnt = 0;
						foreach ($gallery as $i=>$photo) {
							$photo_location = $photo_path . $photo['filename'] . '';
							$photo_location_th = $photo_path . "thumbs/" . $photo['filename'];
							echo '<a href="', $photo_location, '" rel="prettyPhotoClient[]" class="advert_gall" title="',stripslashes($photo['title']),'">';
							if($cnt == 0) {
								echo '<meta itemprop="image" content="' . $photo_location . '">';
								
							}
							echo '<img src="',$photo_location_th,'" alt="',stripslashes($photo['title']),'" width="',(intval($photo['iwt'])>0 ? $photo['iwt'] : '120'),'" height="',(intval($photo['iht'])>0 ? $photo['iht'] : '90'),'">';				
							
							echo '</a>';
							$cnt++;
						}
						echo '<div style="clear: both;"></div>';
					}
					?>
				</div>
				<div rel="advert_gallery:210" class="company_dialog read-more-expand" style="display: block;"><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-carat-2-n-s"></span> <span class="read-more-text">show more</span></div>
				<div style="clear: both;"><br/></div>
			</div>
			<?php
		}
		
		
		?>
		
		
		<div style="margin: 5px;">
		<?php
		if(trim($linePopup['YearOfEstablishment']) != "" || trim($linePopup['Directors']) != "" 
			|| trim($linePopup['NumberOfEmployees']) != "" || trim($linePopup['MemberOf']) != "") { 
			?>
			<table cellpadding="1" cellspacing="1" width="100%" border="0">
				<tr>
					<th colspan="2">Company Information</th>
				</tr>
				<?php 
			 
				if(trim($linePopup['YearOfEstablishment']) != ""){ 
					?>
					<tr>
						<td class="label" nowrap>Year of Establishment</td>
						<td width="70%"><?php echo $linePopup['YearOfEstablishment']; ?></td>
					</tr>
					<?php 
				} 
				if(trim($linePopup['Directors']) != ""){ 
					?>
					<tr>
						<td class="label" nowrap>Directors</td>
						<td width="70%"><?php echo $linePopup['Directors']; ?></td>
					</tr>
					<?php 
				} 
				if(trim($linePopup['MemberOf']) != ""){ 
					?>
					<tr>
						<td class="label" nowrap>Member of</td>
						<td width="70%"><?php echo $linePopup['MemberOf']; ?></td>
					</tr>
					<?php 
				} 
				if(trim($linePopup['NumberOfEmployees']) != ""){ ?>
					<tr>
						<td class="label" nowrap>Number of Employees</td>
						<td width="70%"><?php echo $linePopup['NumberOfEmployees']; ?></td>
					</tr>
					<?php 
				}
				?>
			</table>
			<?php
		}

		//echo '<pre>', print_r($disp_loc), '</pre>';
		
		
		
		
		if(count($disp_loc) > 0) {
			$cnt = 1;
			foreach ($disp_loc as $location_id=>$data) {
				$location_title = trim(stripslashes($data['location_title']));
				if($location_title == "") {
					$location_title = "Address $cnt";
				}
				else {
					if($location_title == "Address Details") $location_title .= " #$cnt";
				}
				
				$have_map = false;
				if(isset($data['lat']) && floatval($data['lat']) > 0) $have_map = true;
				
				ob_start();
				echo ($have_microdata) ? '<div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress">': '';
				?>
				<table cellpadding="1" cellspacing="1" border="0" width="100%">
					<tr>
						<th colspan="2"><?php echo $location_title;?></th>
					</tr>
					<?php
					if(trim($data['street']) != "") {
						?>
						<tr>
							<td class="label" width="30%" nowrap>Street</td>
							<td align="left" width="70%">
								<span <?php echo ($have_microdata) ? 'itemprop="streetAddress"':'';?>>
								<?php
								echo stripslashes($data['street']), ' ', $data['street_no'];
								?>
								</span>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['building_name']) != "") {
						?>
						<tr>
							<td class="label" nowrap>Building</td>
							<td align="left" width="70%">
								<?php
								echo stripslashes($data['building_name']);
								?>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['floor']) != "") {
						?>
						<tr>
							<td class="label" nowrap>Floor</td>
							<td align="left" width="70%">
								<?php
								echo stripslashes($data['floor']);
								?>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['flat']) != "") {
						?>
						<tr>
							<td class="label" nowrap>Flat</td>
							<td align="left" width="70%">
								<?php
								echo stripslashes($data['flat']);
								?>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['city']) != "") {
						?>
						<tr>
							<td class="label" nowrap>Location</td>
							<td align="left" width="70%">
								<span <?php echo ($have_microdata) ? 'itemprop="addressLocality"':'';?>>
								<?php
								echo stripslashes($data['city']);
								if($cnt == 1) {
									$meta_loc = trim(stripslashes($data['city']));
								}
								?>
								</span>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['area']) != "" && $data['lcode'] == "") {
						?>
						<tr>
							<td class="label" nowrap>Area</td>
							<td align="left">
								<?php
								echo stripslashes($data['area']);
								if($cnt == 1) {
									if($meta_loc == "") {
										$meta_loc = trim(stripslashes($data['area']));
									}
								}
								?>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['postalcode']) != "") {
						?>
						<tr>
							<td class="label" nowrap>Postal Code</td>
							<td align="left">
								<span <?php echo ($have_microdata) ? 'itemprop="postalCode"':'';?>>
								<?php
								echo stripslashes($data['postalcode']);
								?>
								</span>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['district']) != "") {
						?>
						<tr>
							<td class="label" nowrap>District</td>
							<td align="left" width="70%">
								<span <?php echo ($have_microdata) ? 'itemprop="addressRegion"':'';?>>
								<?php
								echo stripslashes($data['district']);
								if($cnt == 1) {
									if($meta_loc == "") {
										$meta_loc = trim(stripslashes($data['district']));
									}
									elseif($meta_loc != trim(stripslashes($data['district']))) {
										$meta_loc .= ", " . trim(stripslashes($data['district']));
									}
								}
								?>
								</span>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['country']) != "") {
						?>
						<tr>
							<td class="label" nowrap>Country</td>
							<td align="left" width="70%">
								<span <?php echo ($have_microdata) ? 'itemprop="addressCountry"':'';?>>
								<?php
								echo "CYPRUS";
								?>
								</span>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['pobox']) != "") {
						?>
						<tr>
							<td class="label" nowrap>P.o. Box</td>
							<td align="left" width="70%">
								<?php
								echo stripslashes($data['pobox']);
								?>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['pobox_postalcode']) != "") {
						?>
						<tr>
							<td class="label" nowrap>P.o. Box Postal Code</td>
							<td align="left" width="70%">
								<?php
								echo stripslashes($data['pobox_postalcode']);
								?>
							</td>
						</tr>
						<?php
					}
					
					if(trim($data['contact_name']) != "" || trim($data['tel1']) != "") {
						?>
						<tr>
							<th colspan="2" align="left"><?php echo $location_title , ' - ', 'Contact';?></td>
						</tr>
						<?php
						
						if(trim($data['contact_name']) != "") {
							?>
							<tr>
								<td class="label" nowrap>Contact Name</td>
								<td align="left">
									<?php
									echo stripslashes($data['contact_name']);
									if(trim($data['contact_title']) != "") echo '&nbsp;(', stripslashes($data['contact_title']), ')';
									?>
								</td>
							</tr>
							<?php
						}
						
						if(trim($data['email']) != "") {
							?>
							<tr>
								<td class="label" nowrap>E-mail</td>
								<td align="left">
									<span class="email-str">
									<?php
									echo str_replace('@', '[ at ]', stripslashes($data['email']));
									?>
									</span>
								</td>
							</tr>
							<?php
						}
						
						if($website != "") {
							?>
							<tr>
								<td class="label" nowrap>Website</td>
								<td align="left">
									<?php
									if($seo) {
										/*
										if($active == "yes") {
											if($paying_advert) {
												if($seo) {
													?>
													<span class="click-link"><?php echo $website;?></span>
													<?php
												}
												else {
													?>
													<a href="click_count.php?link=<?php echo $linePopup["title_tr"];?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id'];?>&amp;domain=<?php echo $ultra_domainname;?>&amp;domain_id=<?php echo $domain_id;?>&amp;window=stand&amp;click_from=e" class="click-count" target="_blank" title="<?php echo $website;?>"><?php echo $website;?></a>
													<?php 
												}
											}
											else {
												echo $website;
											}
										}
										else {
											echo $website;
										}
										*/
										echo wordwrap($website, 33, "\n", true); 
									}
									else {
										echo wordwrap($website, 33, "\n", true); 
									}
									?>
								</td>
							</tr>
							<?php
						}
						
						if(trim($data['mobile1']) != "" || trim($data['mobile2']) != "") {
							?>
							<tr>
								<td class="label" nowrap>Mobile #</td>
								<td align="left">
									<span <?php echo ($have_microdata) ? 'itemprop="telephone"':'';?>>
									<?php
									if($data['mobile1'] != "") {
										echo '(+357) ' . number_format($data['mobile1'], null, null, ' ');
										if($data['mobile2'] != "") echo '; '. '(+357) ' . number_format($data['mobile2'], null, null, ' ');
									}
									else {
										if($data['mobile2'] != "") echo '(+357) ' . number_format($data['mobile2'], null, null, ' ');
									}
									?>
									</span>
								</td>
							</tr>
							<?php
						}
						
						if(trim($data['tel1']) != "" || trim($data['tel2']) != "") {
							?>
							<tr>
								<td class="label" nowrap>Phone #</td>
								<td align="left">
									<span <?php echo ($have_microdata) ? 'itemprop="telephone"':'';?>>
									<?php
									if($data['tel1'] != "") {
										echo '(+357) ' . number_format($data['tel1'], null, null, ' ');
										if($data['tel2'] != "") echo '; '. '(+357) ' . number_format($data['tel2'], null, null, ' ');
									}
									else {
										if($data['tel2'] != "") echo '(+357) ' . number_format($data['tel2'], null, null, ' ');
									}
									?>
									</span>
								</td>
							</tr>
							<?php
						}
						
						if(trim($data['fax']) != "") {
							?>
							<tr>
								<td class="label" nowrap>Fax #</td>
								<td align="left">
									<span <?php echo ($have_microdata) ? 'itemprop="faxNumber"':'';?>>
									<?php
									echo '(+357) ' . number_format($data['fax'], null, null, ' ');
									?>
									</span>
								</td>
							</tr>
							<?php
						}
						
					}
					?>
				</table>
				
				<?php
				echo ($have_microdata) ? '</div>' : '';
				$location_details = ob_get_contents();
				ob_end_clean();
				
				
				
				?>
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
					<tr>
						<td width="70%" align="left" valign="top">
							<?php echo $location_details; ?>
						</td>
						<td width="30%" align="right" valign="top">
							<?php
							if($have_map) {
								?>
								<table cellpadding="0" cellspacing="0" border="0">
									<tr>
										<th align="center">&nbsp;</th>
									</tr>
									<tr>
										<td align="left" valign="top">
											<div class="map-container" style="text-align: center;">
												<div class="map_canvas_static" style="width: 320px; height: 240px;">
													<?php
													if(isset($_REQUEST['page']) && intval($_REQUEST['page']) == 1) {
														?>
														<a href="http://<?php echo $_SERVER['HTTP_HOST'];?>/modules/adverts_map/map_enlarge.php?location_id=<?php echo $location_id;?>&amp;domain_id=<?php echo $domain_id;?>" target="_self">
														<?php
													}
													else {
														?>
														<a href="javascript:;" class="map_enlarge_link" rel="<?php echo $location_id; ?>">
														<?php
													}
													?>
													
														<?php
														$lat = $data['lat'];
														$lng = $data['lng'];
														$zoom = $data['zoom'];
														
														$static_map_url = 'http://maps.google.com/maps/api/staticmap?' . ('center=' . $lat . ',' . $lng .'&zoom='.$zoom.'&size=320x240&markers=%7C'.$lat . ',' . $lng.'&sensor=false');
														echo '<img src="', $static_map_url,'" border="0" style="width: 320px; height:240px;">';				
														
														?>
														
													</a>
												</div>
												
											</div>
											<?php
											if(isset($_REQUEST['page']) && intval($_REQUEST['page']) == 1) {
												?>
												<a href="http://<?php echo $_SERVER['HTTP_HOST'];?>/modules/adverts_map/map_directions.php?location_id=<?php echo $location_id;?>&amp;domain_id=<?php echo $domain_id;?>" target="_self">Driving Directions</a>
												<?php
											}
											else {
												?>
												<a href="javascript:;" class="map_directions_link" rel="<?php echo $location_id;?>">Driving Directions</a>
												<?php
											}
											
											echo ' | ';
											?>
											
											<?php
											if(isset($_REQUEST['page']) && intval($_REQUEST['page']) == 1) {
												?>
												<a href="http://<?php echo $_SERVER['HTTP_HOST'];?>/modules/adverts_map/map_enlarge.php?location_id=<?php echo $location_id;?>&amp;domain_id=<?php echo $domain_id;?>" target="_self">Enlarge Map</a>
												<?php
											}
											else {
												?>
												<a href="javascript:;" class="map_enlarge_link" rel="<?php echo $location_id; ?>">Enlarge Map</a>
												<?php
											}
											?>
										</td>
									</tr>
								</table>
								<?php
							}
							else {
								echo '<div style="width: 320px; height: 240px;">&nbsp;</div>';
							}
							?>
						</td>
					</tr>
					
				</table>
				
				<br/>
				<?php
				$cnt++;
			}
		}
		?>
		
	</div>
	</div>
	<?php
	
	
	
	if($meta_loc != "") {
		$meta_params['location'] = $meta_loc;
		$meta_description_temp = str_replace($meta_replacements, $meta_params, $meta_phrase);
		/*
		$meta_description_count = mb_strlen(trim($meta_description_temp), 'UTF-8');
		if($meta_description_count < 10) {
			$meta['description'] = $meta_description_temp . '. ' . mb_substr(trim(strip_tags($advert_meta_description)), 0, (150 - $meta_description_count));
		}
		else {
			$meta['description'] = $meta_description_temp;
		}
		*/
		
		if($advert_use_meta == 1 && trim($advert_meta_description) != "") {
			$meta['description'] = $advert_meta_description;
			$meta['keywords'] = $advert_meta_keywords;
		}
		else {
			$meta['description'] = $meta_description_temp;
		}
	}
	
	?>
	<script type="text/javascript">
	var map_gmap = null;
	var myLatlng = null;
	var infoWindow = null;
	var markerArray = [];
	var infowindows = [];
	
	function openDirections(loc_id) {
		var $directions_dialog = $('<div id="directions_dialog"></div>');
		$directions_dialog.dialog({
			autoOpen: false,
			position: 'top',
			modal: true,
			dialogClass: "company_dialog",
			title: 'Get Map Directions',
			width: $(document).width() - 20,
			height: <?php echo ( isset($_REQUEST['page']) ? '$(window.parent).height()-20' : '$(window).height()-20'); ?>,
			open: function(event, ui) {
				//$('#stamp').val(new Date.getTime());
				var $frm = $('<iframe id="process_frm" name="process_frm"></iframe>');
				$frm.attr('src', '<?php echo $path;?>modules/adverts_map/map_directions.php?location_id=' + loc_id);
				$frm.attr('width', '100%');
				$frm.attr('height', '98%');
				$frm.css('border', '1px solid #000000');
				$frm.css('overflow-y', 'hidden');
				$('#directions_dialog').append($frm);
				
			},
			close: function(event, ui) {
				$('#process_frm').remove();
				$directions_dialog.dialog('destroy');
				$directions_dialog.remove();
			},
			buttons: {
				'Close': function(event, ui) {
					$(this).dialog('close');
				}
			}
		});
		$directions_dialog.dialog('open');
	}
	
	function openBigMap(loc_id) {
		var $directions_dialog = $('<div id="directions_dialog"></div>');
		$directions_dialog.dialog({
			autoOpen: false,
			position: 'top',
			modal: true,
			dialogClass: "company_dialog",
			title: 'Get Map Directions',
			width: $(document).width() - 20,
			height: <?php echo ( isset($_REQUEST['page']) ? '$(window.parent).height()-20' : '$(window).height()-20'); ?>,
			open: function(event, ui) {
				//$('#stamp').val(new Date.getTime());
				var $frm = $('<iframe id="process_frm" name="process_frm"></iframe>');
				$frm.attr('src', '<?php echo $path;?>modules/adverts_map/map_enlarge.php?location_id=' + loc_id);
				$frm.attr('width', '100%');
				$frm.attr('height', '98%');
				$frm.css('border', '1px solid #000000');
				$frm.css('overflow-y', 'hidden');
				$('#directions_dialog').append($frm);
				
			},
			close: function(event, ui) {
				$('#process_frm').remove();
				$directions_dialog.dialog('destroy');
				$directions_dialog.remove();
			},
			buttons: {
				'Close': function(event, ui) {
					$(this).dialog('close');
				}
			}
		});
		$directions_dialog.dialog('open');
	}
	
	
	function init_gmap(lat, lng, zoom) {

		myLatlng = new google.maps.LatLng(lat * 1, lng * 1);
	    var myOptions = {
	      zoom: zoom * 1 - 1,
	      center: myLatlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
		map_gmap = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
		
		
		// Creating a marker and positioning it on the map
		var marker = new google.maps.Marker({
			position: myLatlng,
			map: map_gmap
		});
		
		markerArray.push(marker);
		
		google.maps.event.trigger(map_gmap, 'resize');
		map_gmap.setZoom( map_gmap.getZoom() );
		//AutoCenter();
	}
	
	function AutoCenter() {
		//  Create a new viewpoint bound
		var bounds = new google.maps.LatLngBounds();
		//  Go through each...
		$.each(markerArray, function (index, marker) {
			bounds.extend(marker.position);
		});
		//  Fit these bounds to the map
		map_gmap.fitBounds(bounds);
	}

	
	
	function resizeMap(){
		google.maps.event.trigger(map_gmap, "resize");
		map_gmap.setCenter(myLatlng);
	}
	
	function init_gmap_null() {
		return true;
	}
	
	
	function appendBootstrap() {
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.src = "http://maps.google.com/maps/api/js?v=3.4&sensor=false&callback=init_gmap_null&language=en&region=CY";
		//document.body.appendChild(script);
		$('head').append(script);
	}
	
	function makeMarker(options, info_content){
		var pushPin = new google.maps.Marker({map:map_gmap});
		pushPin.setOptions(options);
		markerArray.push(pushPin);
		google.maps.event.addListener(pushPin, 'click', function(){
			var infowindow = new google.maps.InfoWindow({
			    content: info_content
			});
			
			infowindows.push(infowindow);
			infowindow.open(map_gmap, pushPin);
		});
		
		
		return pushPin;
	}
	
	function showMarker(i){
		google.maps.event.trigger(markerArray[i], 'click');
	};
	
	$(document).ready(function(){
		
		var click_link = '<?php echo $click_count_path;?>';
		$('.click-link').each(function(){
			var sub_content = '<a href="' + click_link + '" target="_blank">' + $(this).html() + '</a>';
			$(this).replaceWith(sub_content);
		});
		
		appendBootstrap();
		
		$('a.mailto').each(function(){
			var email = $(this).attr('rel');
			email = email.replace('[ at ]', '@');
			$(this).attr('href', 'mailto:' + email);
		});
		
		$('.email-str').each(function(){
			var email = $(this).html();
			email = email.replace('[ at ]', '@');
			$(this).html(email);
		});
		
		
		$("a[rel^='prettyPhotoClient']").prettyPhoto({
			modal: false,
			deeplinking: false,
			social_tools: false
		});
		
		$('.pp_pic_holder').css('top', '50px');
		
		
		$('.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;
		});
		
		$('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');
			}
		});
		
		$('.read-more-expand').each(function(){
			var $this = $(this);
			var rel = $this.attr('rel');
			var c = rel.split(":");
			var $cel = $('#' + c[0]);
			var ch = c[1];
			var chpx = c[1] + 'px';
			
			
			if($cel.height() > ch) {
				$cel.css({height:chpx, overflow:'hidden'});
				if(typeof equalHeight != "undefined") {
					equalHeight($('.site-col'));
					//$('#page').css('height', 'auto');
				}
			}
			
			$this.click(function(e){
				if($cel.height() <= ch) {
					$cel.css({height:'auto', overflow:'visible'});
					$('.read-more-text', $this).html('show less');
					if(typeof equalHeight != "undefined") {
						equalHeight($('.site-col'));
						//$('#page').css('height', 'auto');
					}
				}
				else {
					$cel.css({height:chpx, overflow:'hidden'});
					$('.read-more-text', $this).html('show more');
					if(typeof equalHeight != "undefined") {
						equalHeight($('.site-col'));
						//$('#page').css('height', 'auto');
					}
				}
			});
			
			/*
			
			if($cel.height() > ch) {
				$cel.css({height:chpx, overflow:'hidden'});
				if(typeof equalHeight != "undefined") {
					//equalHeight($('.site-col'));
					$('#page').css('height', 'auto');
					$('#nav-left').css('height', 'auto');
					$('#nav-right').css('height', 'auto');
					equalHeight($('.site-col'));
					$('#page').css('height', 'auto');
				}
			}
			
			$this.click(function(e){
				if($cel.height() <= ch) {
					$cel.css({height:'auto', overflow:'visible'});
					$('.read-more-text', $this).html('show less');
					if(typeof equalHeight != "undefined") {
						$('#page').css('height', 'auto');
						$('#nav-left').css('height', 'auto');
						$('#nav-right').css('height', 'auto');
						equalHeight($('.site-col'));
						equalHeight($('.site-col'));
						$('#page').css('height', 'auto');
					}
				}
				else {
					$('.read-more-text', $this).html('show more');
					$('#page').css('height', 'auto');
					$('#nav-left').css('height', 'auto');
					$('#nav-right').css('height', 'auto');
					equalHeight($('.site-col'));
					equalHeight($('.site-col'));
					$('#page').css('height', 'auto');
				}
			});
			
			*/
		});
		
		
	});
	</script>
	<?php
}
else{
	$send404 = true;
	require_once(dirname(__FILE__) . "/../404/404.php");
}

?>