<?
require("config.php");
require("funcs1.php");
require("favrt.php");
require("search.php");
require("adshtm.php");

$javastl="
<script language='JavaScript'>
<!--
 function displ(nmdiv){if (document.getElementById){
if (document.getElementById(nmdiv).style.display=='none') document.getElementById(nmdiv).style.display ='block';
else document.getElementById(nmdiv).style.display ='none';} else if (document.all)
{ if(document.all[nmdiv].style.display=='none') document.all[nmdiv].style.display ='block';
else document.all[nmdiv].style.display ='none';}}
-->
</script>
";
 

$msgs_fl="msg1_".$intlang.".php"; require("$msgs_fl");
if (($md!="details") and ($md!="") and ($md!="browse"))
{$msgs_fl="msg2_".$intlang.".php"; require("$msgs_fl");} 

if($prphscr == 'yes') {$incl_prevphoto='no';}
 
if ($md=="rmbloc"){include("rmbloc.php"); }
if (($ct=="") and ($HTTP_GET_VARS['city']=="") and ($HTTP_COOKIE_VARS['kcity']!='') and ($HTTP_COOKIE_VARS['city']==''))
{$HTTP_GET_VARS['city']=$HTTP_COOKIE_VARS['kcity'];}
if ($_REQUEST['allc']=='1'){setcookie ("kcity"); setcookie ("$schopt"); $HTTP_GET_VARS[$schopt]=''; $_REQUEST[$schopt]='';}
if (($HTTP_GET_VARS[$schopt]!="") and ($ct=="") and ($mds==""))
{$_REQUEST[$schopt]=$HTTP_GET_VARS[$schopt]; setcookie ("$schopt", $HTTP_GET_VARS[$schopt]);} 
if (($HTTP_GET_VARS[$schopt]=="")  and (($mds=="") or (adsordtp!=""))){$HTTP_GET_VARS[$schopt]=$_REQUEST[$schopt];}
$rmmbrloc="";
if (($HTTP_COOKIE_VARS['kcity']!=$_REQUEST[$schopt]) and ($_REQUEST[$schopt]!=""))
{$rmmbrloc=" &nbsp; &nbsp;  <a href='#' onclick=\"n=window.open('index.php?md=rmbloc&lc=".$HTTP_GET_VARS[$schopt]."',
 'n', 'toolbar=no, status=no, width=400, height=200');\">".$msg['rememb_loc']."</a>";}

start();

if (($md=="details") and ($mbac_second=="m"))
{
$msgs_fl="msg2_".$intlang.".php"; require("$msgs_fl");
include("mb_check.php"); check_mb_login("details&id=$id");}

if ((($md=="add_form") or ($md=="submitad")) and ($mbac_addad=="m"))
{include("mb_check.php"); check_mb_login("add_form");}
if ((($md=="privacy_mail") or ($md=="send_mail")) and ($mbac_sndml=="m"))
{include("mb_check.php"); check_mb_login("privacy_mail&idnum=$idnum");}
if ($md=="forgmbpassw"){include("mb_check.php"); forgot_mb_passw();}
if ($md=="sendmbps"){include ("mb_conf.php"); include("mb_check.php"); send_mb_passw($ps_email);}
if ($md=="mblogout"){include("mb_check.php"); mb_log_out();}
if ($cook_login!=''){include_once("mb_lginf.php"); insert_log_welc();}
 
if (($md=="") and ($ct=="") ){include("top.php"); print_categories();} 
if (($md=="browse") or ($md=="")){browse_ads();} 

if ($flattchext!=""){include("flattch.php");}

if ($md=="details"){include("details.php"); ad_details();} 

get_tm_tags($titleclpg,"");

if ($md=="add_form") {include("forms.php"); print_add_form();} 
if ($md=="editlogin"){ include("forms.php"); edit_login(" ");}
if ($md=="editform"){ include("forms.php");   edit_form();}
if ($md=="forgotpassw"){include("forms.php"); forgotpassw($ps_email);}
if ($md=="sendpassw"){include("funcs2.php");sendpassw($ps_email);}
if ($md=="privacy_mail"){include("forms.php"); privacy_form($idnum);}
if ($md=="send_mail"){include("funcs2.php"); send_mail($idnum);}
if ($md=="submitad") {include("submit.php"); submit_ad();}
if ($md=="edit") {include("submit.php"); edit_ad();}
if ($md=="adsvtrate"){include("funcs2.php"); adsvtrate();} 

 
function getlink_topads()
{
global $plcntdtl, $plcntpml, $ct, $voterate, $HTTP_GET_VARS, $topcmmnt, $msg,
$pltopratedln, $pltopcontln, $pltopvisitln, $reply_catg;

if (($plcntpml=="yes") and ($pltopcontln=='yes')){$most_cnt=" &nbsp;&nbsp;
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=pml'>[".$msg['top_contacted_ads']."]</a>";}

if (($topcmmnt=="yes") and ($reply_catg[$ct]!="")){$most_cmmnt=" &nbsp;&nbsp;
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=cmmnt'>[".$msg['top_commented_ads']."]</a>";}

if (($plcntdtl=="yes") and ($pltopvisitln=='yes')){$most_vst=" &nbsp;&nbsp;
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=vis'>[".$msg['top_visited_ads']."]</a>";}

if (($plcntdtl=="yes") and ($pltopratedln=='yes')){$most_vrt="  
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=vote'>[".$msg['top_rated_ads']."]</a>";}

$res_link="
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'  size=-2>
<b> $most_vrt $most_cmmnt $most_cnt $most_vst </b></font>
";

if (($HTTP_GET_VARS['idemail']!="") or ($HTTP_GET_VARS['mblogin'] != ""))
{$res_link="";}
return $res_link;
}

function category_name()
{
global $categories, $ct, $ratedads, $HTTP_GET_VARS, $schresinfo, $fntclr_1, $msg;
if ((($ct!="") and ($ratedads!="")) or  ($HTTP_GET_VARS['mds']=='search'))
{
$cat1_name="
<a href='index.php?ct=$ct'>".$categories[$ct][0]."</a>
";
 
$txtinf1="Search results:";
if ($HTTP_GET_VARS['adsordtp']=='pml'){$txtinf1=$msg['top_contacted_ads'].":";}
if ($HTTP_GET_VARS['adsordtp']=='vis'){$txtinf1=$msg['top_visited_ads'].":";}
if ($HTTP_GET_VARS['adsordtp']=='vote'){$txtinf1=$msg['top_rated_ads'].":";}
if ($HTTP_GET_VARS['adsordtp']=='cmmnt'){$txtinf1=$msg['top_commented_ads'].":";}
$schresinfo="
<font FACE='ARIAL, HELVETICA' COLOR='#000000' size=-2>
&nbsp;&nbsp; &nbsp; <b>$txtinf1</b>
</font>
";
}
else
{
$cat1_name=$categories[$ct][0];
}
return $cat1_name;
}

function nb_best_ads()
{
global $cat_fields, $table_ads, $ct, $page, $adsonpage, $ratedads, $idemail,$plhltads,$msg; 

if ($plhltads=="2"){

if ($ratedads=="1")
{$res_mess="
<font FACE='ARIAL, HELVETICA' color='#990000' size='-1'><b>
".$msg['ads_rated_by_admin']."
</b>
</font>
";}
else { 
if ($ct!=""){$qy_ct="catname='$ct' and "; } else {$qy_ct="";}
$sql_query="select count(idnum) from $table_ads where 
 $qy_ct adrate > 0";
$sql_res=mysql_query("$sql_query");
$row=mysql_fetch_row($sql_res);
$count=$row[0];
if ($count > 0)
{
$res_mess="
<font FACE='ARIAL, HELVETICA' size='-2'><b>
<a href='index.php?ct=$ct&md=browse&ratedads=1'><font color='#990000'>".$msg['Best_Ads']."</font></a> 
<font size='-2'>[$count]</font>
</b>
</font>
";
}
}
}
if ($idemail!=""){$res_mess="";}
return $res_mess;
}

function check_row($row)
{
global $cat_fields, $select_text,$real_format;

if($row['homeurl']=='http://'){$row['homeurl']="--";}
foreach ($cat_fields as $key => $value) 
{
if (($row[$key]=="") or ($row[$key]==$select_text) or ($row[$key]=='http://')
or ($row[$key]=='NULL') or ($row[$key]=='null')) 
{$row[$key]="--";}
else {
if ($cat_fields[$key][6]=='real') {$row[$key]=sprintf($real_format, $row[$key]);}
}

if ($cat_fields[$key][4] == 'date'){
$row[$key]=get_date_f($row[$key]);
}

if($key=='moredetails'){$row[$key]="&nbsp;".preg_replace("/\n/", "<br>",$row[$key]);}
}

return $row;
}

function get_tm_tags($title,$row)
{
global $mtg_keywrds, $mtg_descr,$html_header,$mtfldkwrs,$ct;

if($row=="")
{
if ($mtg_descr[$ct]!="") {$descr=$mtg_descr[$ct];} else {$descr=$mtg_descr['all'];}
if ($mtg_keywrds[$ct]!="") {$keywrds=$mtg_keywrds[$ct];} else {$keywrds=$mtg_keywrds['all'];}
}
else {
$row['title']=ereg_replace('\"', '\'',$row['title']);
$row['brief']=ereg_replace('\"', '\'',$row['brief']);


$rwmss = preg_split ("/[\W]+/", $row['title']); 
foreach ($rwmss as $value){if (strlen($value) > 3) {$vlkw=$vlkw.$value.", ";}}

foreach ($mtfldkwrs as $value){if ($row[$value]!="" and $row[$value]!="--"){$vlkw=$vlkw.$row[$value].", ";}}

if ($mtg_keywrds[$ct]!="") {$keywrds=$mtg_keywrds[$ct];} else {$keywrds=$mtg_keywrds['all'];}
$keywrds=$vlkw." almclsfds, ".$keywrds;
$descr=$row['brief'];

}

$mtgvl="
<title>$title</title>
<meta name=\"keywords\" content=\"$keywrds\">
<meta name=\"description\" content=\"$descr\">
";
$html_header=ereg_replace('<!--title_meta_tags-->', $mtgvl, $html_header);
}  

 
?>