<?
$md=$_REQUEST['md'];
$fld=$_REQUEST['fld'];
$fld3=$_REQUEST['fld3'];
$vl=$_REQUEST['vl'];
$dvalue=$_REQUEST['dvalue'];
$mslf=$fslct[$fld][$vl];

if($md=='slct1'){slct1();}
if($md=='slct2'){slct2();}
if($md=='slct3'){slct3();}
 
exit;

function slct2()
{
global $md, $fld, $fld3, $vl, $dvalue, $mslf, $fslct, $firsr_sel, $choose_one1,$hs_header,
       $hs_header_sch,$hs_header_top, $hs_footer, $res;
$choose_one1="<option>";
$hs_header=$hs_header_sch;
slct1();
}

function slct1()
{
global $md, $fld, $fld3, $vl, $dvalue, $mslf, $fslct, $firsr_sel, $choose_one1,$hs_header,
       $hs_header_sch,$hs_header_top, $hs_footer, $res;

$listopt="";
if (($mslf!="") and ($mslf!='text_field')){
foreach ($mslf as $key){$listopt=$listopt."<option value='$key'>$key";}

if ($dvalue!=""){
$slc_val="<option value='$dvalue'>$dvalue<checked>";}
else {$slc_val=$choose_one1;}

$res="<select id='t$fld3' name='$fld3'   class=formst 
onChange=\"window.parent.document.getElementById('t$fld3').value=this.value;\">
$slc_val $listopt</select>
";
}
else {$res="&nbsp;<font FACE='ARIAL, HELVETICA' COLOR='#777777' size='-2'><b>$firsr_sel </b></font>
<input type='hidden' id='tcity' name='city'>";}

if ($mslf=='text_field')
{
$res="<input type='text' id='t$fld3' name='$fld3' value='$dvalue'  class=formst
onChange=\"window.parent.document.getElementById('t$fld3').value=this.value;\"
>"; 
 
}

echo print_res();
exit;
}

function print_res()
{
global $md, $fld, $fld3, $vl, $dvalue, $mslf, $fslct, $firsr_sel, $choose_one1,$hs_header,
       $hs_header_sch,$hs_header_top, $hs_footer, $res, $hs_ldinf;

if ($res==""){$res="$hs_ldinf <input type='hidden' id='tcity' name='city'>"; }
$result= "$hs_header
$res 
<script language='JavaScript'><!--
window.parent.document.getElementById('t$fld3').value=document.getElementById('t$fld3').value;
--></script>
$hs_footer";
return $result;
}

function slct3()
{
global $md, $fld, $fld3, $vl, $dvalue, $mslf, $fslct, $firsr_sel, $choose_one1,$hs_header,
       $hs_header_sch,$hs_header_top, $hs_footer, $res, $citdrdwn;

$hs_header=$hs_header_top;
$res="";

if(($md='slct3') and ($mslf!="")){
$lnbmass=cityradsnumb();

if ($citdrdwn=='yes'){

$listopt="";
if (($mslf!="") and ($mslf!='text_field')){
foreach ($mslf as $key){
if ($lnbmass[$key]==''){$lnbmass[$key]='0';}  
$listopt=$listopt."<option value='$key'>$key (".$lnbmass[$key].")";}

if ($dvalue!=""){
$slc_val="<option value='$dvalue'>$dvalue<checked>";}
else {$slc_val=$choose_one1;}

$res="&nbsp;<select id='t$fld3' name='$fld3'   class=formst2 
onChange=\"window.parent.document.getElementById('t$fld3').value=this.value; window.parent.document.forms['ctcity'].submit();\">
$slc_val $listopt</select>
";
}
else {$res="&nbsp;<font FACE='ARIAL, HELVETICA' COLOR='#777777' size='-2'><b>$firsr_sel </b></font>
<input type='hidden' id='tcity' name='city'>";}



}

else {
 $res="
 <p style='line-height: 1.8'>
<font FACE='ARIAL, HELVETICA' COLOR='$tbclr_4' size='-1'>";
foreach ($mslf as $key)
{
if ($lnbmass[$key]==''){$lnbmass[$key]='0';} 
$key2=slctgetstr2($key);
 $res=$res."
<br>&nbsp;<a href='index.php?city=$key2&country=$vl' target=_top>$key</a>  
<font size=-2><b>(".$lnbmass[$key].")</b></font> 
";
}
$res= $res."<input type='hidden' id='tcity' name='city'></font>";
}

}

echo print_res();
exit;
}

function slctgetstr2($value)
{
$value=ereg_replace(' ', '+', $value);
$value=ereg_replace('@', '%40', $value);
$value=ereg_replace('!', '%21', $value);
return $value;
}

function cityradsnumb()
{ 
global $table_ads, $schopt, $host_name, $db_user, $db_password, $db_name;
mysql_connect("$host_name","$db_user","$db_password");
mysql_select_db("$db_name");
$sql_query="select city, count(idnum) from $table_ads  where visible=1 group by city ";
$sql_res=mysql_query("$sql_query"); 
while ($row = mysql_fetch_row($sql_res))
{$loct=$row[0];  
$lmass[$loct]=$row[1];
}
return $lmass;
}

?>