// display a warning if the browser was not compatible
    else {
      alert("<?php _e('Sorry, the Google Maps API is not compatible with this browser', 'cp');?>");
    }
    //]]>
</script>
<?php
}
function cp_timeleft($theTime)
{
	$now = strtotime("now");
	$timeLeft = $theTime - $now;
	$days_label = __('days','cp');
	$day_label = __('day','cp');
	$hours_label = __('hours','cp');
	$hour_label = __('hour','cp');
	$mins_label = __('mins','cp');
	$min_label = __('min','cp');
	$secs_label = __('secs','cp');
	$r_label = __('remaining','cp');
	$expired_label = __('Ad has expired','cp');
	if($timeLeft > 0)
	{
	$days = floor($timeLeft/60/60/24);
	$hours = $timeLeft/60/60%24;
	$mins = $timeLeft/60%60;
	$secs = $timeLeft%60;
	if($days == 01) {$d_label=$day_label;} else {$d_label=$days_label;}
	if($hours == 01) {$h_label=$hour_label;} else {$h_label=$hours_label;}
	if($mins == 01) {$m_label=$min_label;} else {$m_label=$mins_label;}
	if($days){$theText = $days . " " . $d_label;
	if($hours){$theText .= ", " .$hours . " " . $h_label;}}
	elseif($hours){$theText = $hours . " " . $h_label;
	if($mins){$theText .= ", " .$mins . " " . $m_label;}}
	elseif($mins){$theText = $mins . " " . $m_label;
	if($secs){$theText .= ", " .$secs . " " . $secs_label;}}
	elseif($secs){$theText = $secs . " " . $secs_label;}}
	else{$theText = $expired_label;}
	return $theText;
} 
function cp_cat_fees() {
	$categories = get_categories('orderby=name&order=asc&hide_empty=0');
	$i = 0;
    echo "\n<table style='border: solid 0px; padding: 0; margin: 0px auto;'>\n";
	
  foreach ($categories as $cat) {
	$cat_name = $cat->cat_name;
	$cat_id = $cat->cat_ID;
	if (($i % 2) == 0){ echo "<tr>\n";}
	
	$cat_price = get_option('cp_cat_price_'.$cat_id);
	if ($cat_price == "") {	$cat_price="0";	}
	
	echo "<td align='right' nowrap style=\"padding-bottom:10px;\">$cat_name: </td>\n";
	echo "<td nowrap style=\"color:#bbb;\"><input name='catarray[cp_cat_price_".$cat_id."]' type='text' size='10' maxlength='100' value='".$cat_price."' /> ".get_option("paypal_currency")."</td>\n";
	echo "<td cellspan='2' width='200'> </td>";
	
	if (($i % 2) != 0) { echo "</tr>\n\n"; }
	$i++;
  }
  echo "</table>";
}  
function cp_header_ad_468x60 () { 
if (!get_option('cp_adcode_468x60_checkbox')) { 
	if (get_option('cp_adcode_468x60') <> "") { 
	
	echo stripslashes(get_option('cp_adcode_468x60')); 
	} else { 
	
		if (!get_option('cp_adcode_468x60_url') || !get_option('cp_adcode_468x60_dest')) {  
		
			echo '<a href="#"><img src="'; 
			echo bloginfo("template_directory").'/images/468x60-banner.jpg" border="0" width="468" height="60" alt="" /></a>';
			
		 } else { 	
		
			echo '<a href="' . get_option("cp_adcode_468x60_dest") . '" target="_blank"><img src="' . get_option("cp_adcode_468x60_url") . '" border="0" /></a>';
			
		} 
	} 
  } 
}
function cp_single_ad_336x280 () { 
if (!get_option('cp_adcode_336x280_checkbox')) {
echo "<h3>";
echo _e('Sponsored Links','cp') . "</h3>";
echo "<div class='adsense-336'>";
	if (get_option('adsense_box') <> "") { 
	
	echo stripslashes(get_option('adsense_box')); 
	} else { 
	
		if (get_option('cp_adcode_336x280_url') || !get_option('cp_adcode_336x280_dest')) {  
		
			echo '<a href="' . get_option("cp_adcode_336x280_dest") . '" target="_blank"><img src="' . get_option("cp_adcode_336x280_url") . '" border="0" /></a>';
			
		} 
	} 
echo "</div>";	
  } 
}
function cat_img() {
	$cat = wp_dropdown_categories('orderby=id&order=ASC&hide_empty=0&echo=0');
	$cat = str_replace("\n", "", $cat);
	$cat = str_replace("\t", "", $cat);
	$cat = str_replace("<select name='cat' id='cat' class='postform' >", "", $cat);
	$cat = str_replace("<option class=\"level-0\" value=\"", "", $cat); $cat = str_replace("<option class=\"level-1\" value=\"", "", $cat);
	$cat = str_replace("<option class=\"level-2\" value=\"", "", $cat);	$cat = str_replace("<option class=\"level-3\" value=\"", "", $cat);
	$cat = str_replace("<option class=\"level-4\" value=\"", "", $cat);
	$cat = str_replace("</option></select>", "", $cat);
	$cat = str_replace("</option>", "_", $cat);
	$cat = str_replace("\">", "-", $cat);
	
	$cat = explode("_", $cat);
	foreach($cat as $category)
	{
		$category = explode("-", $category);
		$cat_number = $category[0];
		$cat_name = $category[1];
		echo "<div class=\"one_category\">";
		if (get_option("cat$cat_number") == NULL) { $nothing = ' <span class="nothing">( this category has no icon yet )</span>'; } else { $nothing = ''; }
		echo "<div class=\"one_category_name\"><b>$cat_name</b>$nothing</div><br />\n";
		for($i=1;$i<55;$i+=1){
			if (get_option("cat$cat_number") == $i) { $check = ' checked="checked"'; $selected = " style=\"background-color: #5795C3;\""; } else { $check = ''; $selected = ''; }
			echo "<div class=\"one_cat_img\"$selected>\n";
			echo "<input type=\"radio\" class=\"form-table-radio\" name=\"cat$cat_number\" id=\"$cat_number$i\" value=\"$i\"$check />";
			echo "<label for=\"$cat_number$i\">";
			echo "<img src=\"".get_bloginfo('template_url')."/images/category-icons/$i.png\" alt=\"\" />";
			echo "</label>\n";
			echo "</div>\n";
			}
		echo "<div style=\"clear: both;\"></div>";
		echo "</div>";
	} 
}
/**
 * Template tag which includes the classified ad form into the page
 * jQuery effects are used in global.js to slide the form in and
 * out of the page when the "Post a Classified" button is clicked
 */
function include_classified_form( ) {
  global $err;
  if ( get_option("permissions") == "no" ) { 
    if ( is_user_logged_in() ){
      require_once dirname( __FILE__ ) . '/post-form.php';
    } else {
      echo "<div class='clear'></div><div class='cant_post' id='formbox' style='display: none;'>";
      if (get_option("permission_err") == "") { _e('You have to register in order to add a classified.','cp');
      } else { echo get_option("permission_err"); }
      echo "<br /><a href=\"".get_bloginfo('url')."/wp-login.php?action=register\">" . __('Register','cp') . "</a></div>";
        };  
    } else { require_once dirname( __FILE__ ) . '/post-form.php'; }
}
// injects custom stylesheet into the classipress options page in WordPress
function admin_head() { 
	echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('template_directory').'/functions/admin-style.css" media="screen" />';
}
function classipress_options() {
	add_menu_page(__('ClassiPress'), __('ClassiPress','cp'), 8, basename(__FILE__), 'classipress', 'http://xmobile.yw.sk/favicon.ico');
	add_submenu_page(basename(__FILE__), __('General Configuration','cp'), __('Configure','cp'), '10', basename(__FILE__), 'classipress');
	add_submenu_page(basename(__FILE__), __('Settings','cp'), __('Settings','cp'), '10', 'settings', 'classi_settings');	
	add_submenu_page(basename(__FILE__), __('Payment Options','cp'), __('Payments','cp'), '10', 'payments', 'classi_payments');
	add_submenu_page(basename(__FILE__), __('Category Options','cp'), __('Categories','cp'), '10', 'categories', 'classi_cats');
	add_submenu_page(basename(__FILE__), __('Images','cp'), __('Images','cp'), '10', 'images', 'classi_images');
}
// changes the css file based on what is selected on the options page
function style_changer() { 
     $style = $_REQUEST[style];
     if ($style != '') {
          ?> <link href="<?php bloginfo('template_directory'); ?>/styles/default.css" rel="stylesheet" type="text/css" /><?php 
     } else { 
          $stylesheet = get_option('stylesheet');
          if($stylesheet != ''){
               ?><link href="<?php bloginfo('template_directory'); ?>/styles/<?php echo $stylesheet; ?>" rel="stylesheet" type="text/css" /><?php         
          }
     }     
}
if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'name' => __('Ads Sidebar','cp'), 
        'before_widget' => '<div class="sidebar_box">',
        'after_widget' => '</div><!--/widget-->',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
	
if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'name' => __('Page Sidebar','cp'), 
        'before_widget' => '<div class="sidebar_box">',
        'after_widget' => '</div><!--/widget-->',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
	
// hook into WordPress
add_action('wp_head', 'style_changer');
add_action('admin_head', 'admin_head');
add_action('admin_menu', 'classipress_options');
add_filter('posts_join', 'custom_search_join');
add_filter('posts_where', 'custom_search_where');
add_filter('posts_groupby', 'custom_search_groupby');
// activate support for .mo localization files
load_theme_textdomain('cp');
?>