<?
@session_start();
$base_path='../';
$bp='../';

$name_stranica='add';

$tree_cat[0]=0;
$tree_reg[0]=0;
$opis_a = '';

$no_form=0;

if($_POST)
	{
	if(!$_POST['j_enabled'])
	$err .= '- В Вашем браузере не включен Java Script<br>';
	
	if(!$_SESSION['ID_Glob'] && !$_SESSION['ID_P'])
		{
		$cap_a = trim($_POST['cap']);
		if(!$cap_a)
		$err .= '- Не указан защитный код<br>';
		else
			{
			if($_SESSION['real_code'] != $cap_a)
			$err .= '- Неверно указан защитный код<br>';
			else
				{
				$cap_a = number_format($cap_a,0,"",",");
				$cap_b = $_POST['ip_address'];
				if($cap_a!=$cap_b) $err .= '- Неверно указан защитный код<br>';
				}
			}
		if(isset($_SESSION['real_code'])) unset($_SESSION['real_code']);
		}
	}

require_once('../connect/connect.php');
include_once('../lib/lib.php');

include_once($base_path.'cashe_catalog/_svod_catalog.php'); // дерево каталогов
if(file_exists($base_path.'cashe_region/_svod_region_0.php'))
include_once($base_path.'cashe_region/_svod_region_0.php'); // регионы первого уровня

if(file_exists($base_path.'cashe_n/_svod_rayon.php'))
include_once($base_path.'cashe_n/_svod_rayon.php'); // регионы первого уровня

$title='Добавление объявления';

if($_POST['add'])
	{
	for($i=0; $i<4; $i++)
		{
		if($_POST['razdel_'.$i])
			{
			$id_catalog=intval($_POST['razdel_'.$i]);
			}
		}

	if($arr_razdel[intval($id_catalog)]) $err .= '- Не указан раздел<br>';


	if($id_catalog)
		{
		include_once('../cashe_catalog/_svod_catalog_'.$id_catalog.'.php');
		
		if(file_exists('../plugin/board/index.php'))
		include_once('../plugin/board/index.php');

		if(file_exists('../plugin/board/func_add.php'))
		include_once('../plugin/board/func_add.php');

		if(file_exists('../plugin/board/func_view.php'))
		include_once('../plugin/board/func_view.php');

		if($arr_sp)
			{
			foreach($arr_sp as $ars)
				{
				if(file_exists('../cashe_n/_svod_element_'.$ars[0].'.php'))
				include_once('../cashe_n/_svod_element_'.$ars[0].'.php');

				if(file_exists('../cashe_n/_svod_element_two_'.$ars[1].'.php'))
				include_once('../cashe_n/_svod_element_two_'.$ars[1].'.php');
				}
			}
			
		for($i=1; $i<count($tree_cat); $i++)
			{
			$data['razdel_'.($i-1)][1] = $tree_cat[$i];
			$data['razdel'][1] = $arr_razdel[$tree_cat[($i-1)]][$tree_cat[$i]];
			}
			
		}
	
	for($i=0; $i<4; $i++)
		{
		if(isset($_POST['region_'.$i]))
			{
			$id_region_real=intval($_POST['region_'.$i]);
			if(!$i)
				{
				if(!$id_region_real)
					{
					$err .= '- Не указан регион<br>';
					break;
					}
				else
					{
					$glob_region = intval($_POST['region_'.$i]);
					$tree_reg[($i+1)] = intval($_POST['region_'.$i]);
					$data['region_'.$i][1]=intval($_POST['region_'.$i]);
					}
				}
			else
				{
				if(!$id_region_real)
					{
					if(!$arr_rayon_yes || ($arr_rayon_yes && (!in_array($id_region, $arr_rayon_yes) || (in_array($id_region, $arr_rayon_yes) && $arr_catalog['rayon_obyaz']))))
					$err .= '- Не указан город или район<br>';
					break;
					}
				else
					{
					$tree_reg[($i+1)] = intval($_POST['region_'.$i]);
					$data['region_'.$i][1]=intval($_POST['region_'.$i]);
					}
				}
			$id_region=$id_region_real;
			}
		}
	
	
	if($glob_region && file_exists($base_path.'cashe_region/_svod_region_'.$glob_region.'.php'))
	include_once($base_path.'cashe_region/_svod_region_'.$glob_region.'.php'); // наш регион
	
	if(count($tree_reg)>1)
		{
		for($i=1; $i<count($tree_reg); $i++)
			{
			if($arr_rayon && in_array($tree_reg[$i], $arr_rayon))
				{
				$rayon = $arr_regions[$tree_reg[($i-1)]][$tree_reg[$i]];
				break;
				}
			$gorod = $arr_regions[$tree_reg[($i-1)]][$tree_reg[$i]];
			$id_gorod = $tree_reg[$i];
			}
				
		if($gorod) $data['gorod'][1]=$gorod;
		if($id_gorod) $data['id_gorod'][1]=$id_gorod;
		if($rayon) $data['rayon'][1]=$rayon; else $data['rayon'][1]='';
		}


	$opiss=_pre2($_POST['opis_a']);
	$opis_a=$opiss[1];
	
	$data['pols'][1]=$_POST['pols'][1];
	$data['contakt'][1]=_pre($_POST['contakt'][1]);
	
	if(!$data['contakt'][1])
	$err .= "- Не указано контактное лицо<br>";

	$data['email'][1]=trim($_POST['email'][1]);
	if($data['email'][1] && !_email($data['email'][1]))
	$err .= "- Некорректный e-mail<br>";

	$data['tel'][1]=_pre($_POST['tel'][1]);
	
	if(!$data['email'][1] && !$data['tel'][1])
	$err .= "- Укажите e-mail либо телефон<br>";


	$data['video_link'][1]=trim($_POST['video_link'][1]);
	$data['video_item'][1]='';
	$data['video_host'][1]='';
	

	if($data['video_link'][1])
		{
		$v1=video_add($data['video_link'][1]);
		if($v1[0])
			$err .= $v1[0]."<br>";
		elseif($v1[1])
			$err .= $v1[1]."<br>";
		else
			{
			$data['video_item'][1]=$v1[2];
			$data['video_host'][1]=$v1[3];
			}
		}

	if($_POST['map_x'][1] && $arr_catalog['map'])
		{
		$data['map_x'][1]=floatval($_POST['map_x'][1]);
		$data['map_y'][1]=floatval($_POST['map_y'][1]);
		}
	else
		{
		$data['map_x'][1]=0;
		$data['map_y'][1]=0;
		}

	$data['suff'][1]=_pre($_POST['suff']);
	$global_suff=$data['suff'][1];
	if(!$data['suff'][1])
	$data['suff'][1]=_pre($_POST['suff_b']);

	$auto_zagolovok='';
	
	if($arr_field)  
		{
		foreach($arr_field as $ar_fi) 
			{
			if($ar_fi['spec']=='st' || $ar_fi['spec']=='sp')
				{
				// получение данных из формы и проверка 
				eval ("\$data['".$ar_fi['field_field']."']=field_func_".$ar_fi['field_typ']." ('prov', \$ar_fi, \$_POST[\$ar_fi['field_field']] );");
				if($data[$ar_fi['field_field']][0])
				$err .= "- ".$data[$ar_fi['field_field']][0]."<br>";
			
			/////////////////// opis
				if($data[$ar_fi['field_field']][1])
					{
					eval ("\$data['opis'][1] .= field_func_view_".$ar_fi['field_typ']." ('opis', \$ar_fi, \$data[\$ar_fi['field_field']][1], \$data[\$ar_fi['field_field']][2]);");
					$data['opis'][1] .= "\n";
					if($ar_fi['field_zag'])
					eval ("\$auto_zagolovok .= \$ar_fi['field_zag_pref'].field_func_view_".$ar_fi['field_typ']." ('zag', \$ar_fi, \$data[\$ar_fi['field_field']][1], \$data[\$ar_fi['field_field']][2], \$data['suff'][1]).\$ar_fi['field_zag_suff'].' ';");
					}
				}
			}
		}

	$auto_zagolovok=trim($auto_zagolovok);
	if($auto_zagolovok)
	$data['zag'][1]=$auto_zagolovok;
	elseif(!$arr_zagg)
		{
		$data['zag'][1]=_pre_zag($_POST['zag'][1]);
		$data['zag'][1]=trim(obrez($data['zag'][1], 70));
		if(!$data['zag'][1])
		$err .= "- Не указан заголовок объявления<br>";
		}
	$data['zag_url'][1]=cpu($data['zag'][1], $rru['url_type']);
	$data['opis'][1] = $data['zag'][1]."\n".$data['opis'][1];
	$data['comment'][1]=intval($_POST['comment'][1]);
	
	if ($data  && !$err) //запрос на добавление
		{
		$data['opis'][1] .= "<hr>".trim($opis_a);
		$data['opis'][1] .= "<hr>".$data['gorod'][1];
		$data['opis'][1] .= "<hr>";
		if($data['email'][1])
		$data['opis'][1] .= " ".$data['email'][1];
		if($data['tel'][1])
		$data['opis'][1] .= " ".preg_replace('/[^0-9]/u', '', $data['tel'][1]);
		
		///// проверка на повторяемость записей
			$data['id_spam'][1]=0;
			$spam=povtor($data['opis'][1],'opis');
			$q_spam="SELECT id FROM board WHERE 
			email='".$data['email'][1]."' 
			AND id_spam = 0
			AND ".$spam."
			ORDER BY id DESC LIMIT 1";

			$r_spam = mysql_query ($q_spam) or die(mysql_error());
			if($r_spam)
				{
				$rr_spam=mysql_fetch_array($r_spam);
				$data['id_spam'][1]=intval($rr_spam['id']);
				}
		///// конец проверки на повторяемость	
	
		//////////////////////////////////////////////////////
		if($rru['moder'] > 0 && !$_SESSION['ID_Glob'])
		$data['moder'][1]=1;
		//////////////////////////////////////////////////////
	
		$data['id_akk'][1]=intval($_SESSION['ID_P'][1]);
		$data['data'][1]=date("Y-m-d H:i:s", time());
		$data['data1'][1]=date("Y-m-d H:i:s", (time()+intval($rru['srok'])*24*60*60));

		$data['vip_data'][1]=$date_null;
		$data['pass'][1]=md5($data['zag'][1].time());
	
		$q_into='id_catalog';
		$q_values="'".$id_catalog."'";
		foreach($data as $index=>$dt)
			{
			if(!is_array($dt[1]))
				{
				$q_into .= ','; 
				$q_values .= ',';
				$q_into .= $index;
				$q_values .= "'".$dt[1]."'";
				if($arr_field[$dt[3]]['field_field_two'])
					{
					$q_into .= ','; 
					$q_values .= ',';
					$q_into .= $arr_field[$dt[3]]['field_field_two'];
					$q_values .= "'".$dt[2]."'";
					}
				}
			else
				{
				$q_into .= ','; 
				$q_values .= ',';
				$q_into .= $index;
				$q='';
				foreach($dt[1] as $d)
					{
					$q .= ' '.$d; 
					}
				$q .= ' '; 
				$q_values .= "'".$q."'";
				}
			}
		
		$query = "INSERT INTO board (".$q_into.") VALUES (".$q_values.")";	
		if(mysql_query($query))
			{
			$ins=mysql_insert_id();
			
			$papka = '../tmp_file/'.ip2long($_SERVER['REMOTE_ADDR']);
			if(file_exists($papka))
				{
				$dir = opendir($papka);
				while(($file = readdir($dir)))
					{
					if (is_file ($papka."/".$file))
						{
						$f=explode('_', $file);
						if($f[1]=='s')
						$arr_tmp[$f[0]]['s']=$papka.'/'.$file;
						elseif($f[1]=='b')
						$arr_tmp[$f[0]]['b']=$papka.'/'.$file;
						}
					}
				closedir ($dir);
				
				if($arr_tmp)
					{
					foreach($arr_tmp as $index=>$a_tmp)
						{
						if(!file_exists($a_tmp['s']) || !file_exists($a_tmp['b']))
						unset($arr_tmp[$index]);
						}
						
					if($arr_tmp)
						{
						$i=0;
						$cou_tmp=count($arr_tmp);
						
						if($cou_tmp)
							{
							ksort($arr_tmp);

							foreach($arr_tmp as $index=>$a_tmp)
								{
								mysql_query("INSERT INTO foto (id) VALUES ('".$ins."')");                    
								$id_foto=mysql_insert_id();
						
								$pap=$id_foto%100; 
								if(!$pap) $pap=100;
						
								$big = "foto/".$pap."/".$id_foto."b.jpg";
  								$small = "foto/".$pap."/".$id_foto."s.jpg";
						
								mysql_query("UPDATE foto SET papka='".$pap."' WHERE id_foto='".$id_foto."'"); 
						
								if(!$i)
								mysql_query("UPDATE board SET small='".$small."', kol_foto='".$cou_tmp."' WHERE id='".$ins."'"); 
					
								copy($a_tmp['s'], "../".$small);
								copy($a_tmp['b'], "../".$big);

								$i++;
								}
							}
						}
					}
				full_del_dir($papka);
				} 
	
			if(!$_SESSION['ID_Glob'] && !$_SESSION['ID_P'] && $data['email'][1] && !$data['moder'][1])
			include_once('em.php');
	
			echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=../items/".$data['zag_url'][1]."_".$ins."'></HEAD></HTML>";
			exit();
			}
		else 
			{
			//echo 'Неверный запрос:<br>';
			//echo $query;	
			}
		}
	}

elseif (!$_POST['add'])
	{
	if($_SESSION['ID_P'])
		{
		$z_cont=mysql_query("SELECT contakt, email, tel FROM akk WHERE id_akk='".intval($_SESSION['ID_P'][1])."'");
		$rz_cont=mysql_fetch_array($z_cont);
		$data['contakt'][1]=$rz_cont['contakt'];
		$data['email'][1]=$rz_cont['email'];
		$data['tel'][1]=$rz_cont['tel'];
		}
	}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<HEAD><TITLE><? echo $title; ?></TITLE>
<META http-equiv=content-type content="text/html; charset=utf-8">
<meta name="robots" content="nofollow" />
<link rel="stylesheet" href="../style/style.css" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../style/jquery.fancybox.css" media="screen" />

<script type="text/javascript" charset="utf-8" src="../js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="../js/jquery.fancybox-1.2.1.pack.js"></script>
<script type="text/javascript" src="../js/fancy.js"></script>
<script type="text/javascript" src="../js/ajaxfileupload.js"></script>
<![if !IE]>
<script type="text/javascript" src="../js/jquery.corner.js"></script>
<?
if($rru['round'])
{
?>
<script type="text/javascript">
$(document).ready(function(){
$(".imground").corner("round");
$(".submit").corner("round");
$(".str").corner("round");
});
</script>
<?
}
?>
<![endif]>

<?
if($rru['map']=='y')
	{
	?>
	<script type="text/javascript" src="../js/showAddressY.js"></script>
	<?
	}
elseif($rru['map']=='g')
	{
	?>
	<script type="text/javascript" src="../js/showAddressG.js"></script>
	<?
	}
?>

<script type="text/javascript">
	function alles()
		{
		$.ajax({
			type: "GET",
			url: "upload_result_add.php?tim="+Math.floor(new Date().getTime() / 1000),
			success: function(html) {
				$("#len").empty();
				$("#len").append(html);
                }
        	});
		}
	
	
	function dels(del)
		{
		$.ajax({
			type: "GET",
			url: "upload_result_add.php?del="+del+"&tim="+Math.floor(new Date().getTime() / 1000),
			success: function(html) {
				$("#len").empty();
				$("#len").append(html);
                }
        	});
		}
	
	
	
	function ajaxUpload()
	{
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
			document.getElementById('foto').disabled=1;
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
	
	
	
		$.ajaxFileUpload
		(
			{
				url:'upload_file_add.php',
				secureuri:false,
				fileElementId:'foto',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
						document.getElementById('foto').disabled=0;
						alert(data.error);
						}
						else
						{
						alles();
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}

</script>


</HEAD>
<BODY 
style="MARGIN: 0px auto; POSITION: inherit; width: 1000px">
<?
include_once($base_path."blok/top_form.php"); 
?>
<table cellpadding="10" cellspacing="10" width="100%"><tr><td valign="top">

<?
if($err) echo '<p><font color=red>ОШИБКА:<br>'.$err.'</font></p>';

?>

<form enctype="multipart/form-data" action="add.php" method="post" name="form_edit" >
<table cellpadding="1" cellspacing="1" width="100%">
	
	
		<?
		for ($i=0; $i<4; $i++)
		{
		?>
<tr>
	<td>
	<? if(!$i) echo '<font size=+1 color=red>*</font> Регион, город, район'; ?>
		<td  id="reg_<?=$i?>">
			<?
			if(count($arr_regions[$tree_reg[$i]]))
			{
			?>
			<select style="width: 150px" name="region_<?=$i?>" 
				<?
				if(!$i)
					{
					?>
					onChange="search_reg(<?=$i?>, this.value, this.value, 0); return false">
					<?
					}
				else
					{
					?>
					onChange="search_reg(<?=$i?>, this.value, <?=$glob_region?>, <?=$tree_reg[$i]?>); return false">
					<?
					}
				?>
			<option value="0"> - - - </option>
			<?
			foreach($arr_regions[$tree_reg[$i]] as $index=>$arr_region)
				{
				?>
				<option value="<?=$index?>" <? if($tree_reg[($i+1)]==$index) echo 'selected'; ?> ><?=$arr_region?></option>
				<?
				}
				?>
			</select>
			<input type="hidden" name="name_reg_<?=$i?>" id="name_reg_<?=$i?>" value="<?=$arr_regions[$tree_reg[$i]][$tree_reg[($i+1)]]?>">
			<?
			
			}
			?>
		</td>
		<?
		}
		?>
	
	<tr><td></td><td id="reg_4"></td></tr>

	
		<?
		for ($i=0; $i<4; $i++)
		{
		?>
<tr>
	<td>
	<? if(!$i) echo '<font size=+1 color=red>*</font> Раздел'; ?>
		<td  id="cat_<?=$i?>">
			<?
			if(count($arr_razdel[$tree_cat[$i]]))
			{
			?>
			<select style="width: 150px" name="razdel_<?=$i?>" onChange="search_cat(<?=$i?>, this.value); return false">
			<option value="0"> - - - </option>
			<?
			foreach($arr_razdel[$tree_cat[$i]] as $index=>$raz)
				{
				?>
				<option value="<?=$index?>" <? if($tree_cat[($i+1)]==$index) echo 'selected'; ?> ><?=$raz?></option>
				<?
				}
				?>
			</select>
			<?
			}
			?>
		</td>
		<?
		}
		?>
	
	<tr>
		<td></td>
		<td id="cat_4"></td></tr>
	

	<tr>
		<td id="param" colspan=2 >
			<table cellpadding="1" cellspacing="1" width=100%>
			<?
			if($arr_field)
				{
				foreach($arr_field as $ar_fi)
					{
					if($ar_fi['spec']=='st' || $ar_fi['spec']=='sp')
						{
						eval("field_func_".$ar_fi['field_typ']." ('add', \$ar_fi, \$data[\$ar_fi['field_field']]);");
						}
					}
				}
			?>
			</table>
		</td>

<tr id="zagg">
	<td width="35%">
	<font size=+1 color=red>*</font> Заголовок
	<td>
	<input name="zag[1]" value="<?=stripslashes($data['zag'][1])?>" size="50">

<tr>
	<td width="35%">
	<font size=+1 color=red>*</font> Описание
	<td>
	<textarea cols="50" rows="15" name="opis_a"><?=stripslashes(htmlspecialchars_decode($opis_a))?></textarea>

<tr>
	<td>
	<font size=+1 color=red>*</font> Податель
	<td>
	<input name="pols[1]" type="radio" value="1" <? if($data['pols'][1]==1 || !$data['pols'][1]) echo 'checked'; ?> > частное лицо
	<input name="pols[1]" type="radio" value="2" <? if($data['pols'][1]==2) echo 'checked'; ?> > компания
	
<tr>
	<td>
	<font size=+1 color=red>*</font> Контактное лицо
	<td>
	<input name="contakt[1]" value="<?=stripslashes($data['contakt'][1])?>" size="50">

<tr>
	<td>
	E-mail
	<td>
	<input name="email[1]" value="<?=$data['email'][1]?>" size="50">

<tr>
	<td>
	Телефон
	<td>
	<input name="tel[1]" value="<?=stripslashes($data['tel'][1])?>" size="50">

<tr>
	<td>
	Видео
	<td>
	<input value="<?=stripslashes($data['video_link'][1])?>" name="video_link[1]" size="50">


<tr id="str_map">
	<td>
	Карта
	<td>

<a href="javascript:map_add()">Местоположение объекта на карте</a><br><br>

<input type="hidden" name="map_x[1]" id="map_x" value="<?=floatval($_POST['map_x'][1])?>">
<input type="hidden" name="map_y[1]" id="map_y" value="<?=floatval($_POST['map_y'][1])?>">
<input type="hidden" name="adr" id="adr" value="<?=$_POST['adr']?>">

<tr>
	<td>
	Фотографии (не более <?=$rru['limit_foto']?> штук)
	<td><input onChange="return ajaxUpload();" id="foto" type="file" name="foto" class="input"> <img id="loading" src="../icon/ajax-loader2.gif" style="display:none;">			
			
<tr>
	<td>
	
	<td id="len">
	<? 
	include_once('upload_result_add.php');
	?>


<?
if(!$_SESSION['ID_Glob'] && !$_SESSION['ID_P'])
{
?>
<tr>
	<td>
	<font size=+1 color=red>*</font> Введите код цифрами
	<td>
	<? 
	$font_name[] = array(18, "../blok/new1.ttf"); 
	$font_name[] = array(18, "../blok/new2.ttf"); 
	$font_name[] = array(20, "../blok/new3.ttf"); 
	$font_name[] = array(22, "../blok/new4.ttf"); 
	shuffle($font_name);
	
	$m_rand1=1005;
	$m_rand2=9991;
	$cap_img='../tmp_capcha/'.ip2long($_SERVER['REMOTE_ADDR']).'.jpg';
	@mt_srand(time());
	
			$cap_int=mt_rand($m_rand1,$m_rand2);
			$_SESSION['real_code']=$cap_int;
			if($typ_captcha && function_exists('cifr'))
			cifr($cap_int, $cap_img);
			else
				{
				$cap_str=code($cap_int);
				$im=imagecreate(470, 26);
				imagecolorallocate($im,255,255,255);
				$color=imagecolorallocate($im,100,100,100);
				@imagettftext($im, $font_name[0][0], 0, 0, 19, $color, $font_name[0][1], $cap_str);
				imagejpeg($im, $cap_img);
				imagedestroy($im);
				}
	
	echo '<img border="0" src="'.$cap_img.'?id='.time().'"><br>';
	?>

<input type="text" size=10 name="cap" id="cap" value="">
<?
}
?>

<?
if($_SESSION['ID_P'][1] && $rru['comment'])
{
?>
<tr>
	<td width="35%">
	Комментарии к объявлению
	<td>
	<input type="radio" name="comment[1]" value="0" <? if($data['comment'][1]==0) echo 'checked'; ?>> Комментарии не разрешены<br>
	<input type="radio" name="comment[1]" value="1" <? if($data['comment'][1]==1) echo 'checked'; ?>> Комментарии разрешены<br>
	<input type="radio" name="comment[1]" value="2" <? if($data['comment'][1]==2) echo 'checked'; ?>> Комментарии разрешены, но будут опубликованы только после Вашего одобрения
<?
}
?>

<tr>
<td colspan="2">
<input type="hidden" name="ip_address" id="ip_address" value="<?=$_SERVER['REMOTE_ADDR']?>">
<input type="hidden" name="id_catalog" value="<?=$id_catalog?>">
<input type="hidden" name="add" value="1">
<input type="hidden" name="j_enabled" id="j_enabled" value="">
<input name="submit" class="submit" type="submit" onclick="j_enab(); return true" value="Добавить">

</table>
</form>

<script language="javascript">
$("#str_map").hide();
<?
if($arr_catalog['map'])
	{
	?>
	$("#str_map").show();
	<?
	}
?>

			function search_cat(w, id_cat)
			{
			$.ajax({
					type: "GET",
					url: "<?=$bp.'add/'?>search_cat_two.php?w="+w+"&id_cat="+id_cat,
					success: function(html) {
					var v=w+1;
					for(var i=v; i<5; i++)
						{
						$("#cat_"+i).empty();
						}
					$("#param").empty();
					$("#cat_"+v).append(html);
                	}
        		});
			}
			
			function search_reg(w, id_reg, glob, m)
			{
			$.ajax({
					type: "GET",
					url: "<?=$bp.'add/'?>search_reg_two.php?w="+w+"&id_reg="+id_reg+"&glob="+glob+"&m="+m,
					success: function(html) {
					var v=w+1;
					for(var i=v; i<5; i++)
						{
						$("#reg_"+i).empty();
						}
					$("#reg_"+v).append(html);
                	}
        		});
			}
			
			function search_param(w, id_catalog)
			{
			$.ajax({
					type: "GET",
					url: "<?=$bp.'add/'?>search_param.php?w="+w+"&id_catalog="+id_catalog,
					success: function(html) {
					//$("#param").empty();
					//$("#param").append(html);
					$("#param").html(html);
                	}
        		});
			}
			
			
			function send_element_two(car, id, two, field, viv)
			{
			$.ajax({
					type: "GET",
					url: "<?=$bp.'blok/'?>el_two.php?car="+car+"&id="+id+"&two="+two+"&field="+field+"&viv="+viv,
					success: function(html) {
						$("#www"+id).empty();
						$("#www"+id).append(html);
                	}
        		});
			}
			
			
			function _suff(id, idd)
			{
			$.ajax({
					type: "GET",
					url: "<?=$bp.'blok/'?>suff.php?id="+id+"&idd="+idd,
					success: function(html) {
						$("#suff_a").empty();
						$("#suff_a").append(html);
                	}
        		});
			}

			function func5(a)
			{
			var d=window.document.getElementById(a).options.length;
			for(i=0;i<d;i++)
				{
				if(document.getElementById(a).options[i].selected) 
					{
					document.getElementById(a).style.backgroundColor = document.getElementById(a).options[i].style.backgroundColor;
					document.getElementById(a).style.color = document.getElementById(a).options[i].style.color;
					}
				}
			}

			function j_enab()
			{
			document.getElementById('j_enabled').value = '1'; 
			}
			
			
			function parce_chis (x, id) 
			{
			x = x.replace(/(\D+)/g, '');
			x = x.replace(/(\d)(?=(?:\d\d\d)+$)/g, "$1 ");
			document.getElementById(id).value = x; 
			}
        </script>  

			
<script type="text/javascript" charset="utf-8" src="../js/tb.js"></script>
<?
if($arr_element_fon)
	{
	?>
	<script type="text/javascript">
	<?
	foreach($arr_element_fon as $index=>$arr_fo)
		{
		echo " func5('s_".$index."'); ";
		}
	?>
	</script>
	<?
	}
	
if(!$arr_zagg)
	{
	?>
	<script language="javascript">
	$("#zagg").show();
	</script>
	<?
	}
else
	{
	?>
	<script language="javascript">
	$("#zagg").hide();
	</script>
	<?
	}
?>
</td>
<td valign="top">
Реклама
</td>
</tr></table>
<?
include_once($base_path."blok/bottom_form.php"); 
?>

</body>
</html>