<?
////////////// - tinytext- /////////////////
function field_func_1 ($d, $arr, $data)
{
	mb_internal_encoding("UTF-8");
	
	$data[2]=stripslashes($data[1]);
	$data[1]=_pre($data[1]);
	
	$kol_sim=mb_strlen($data[1]);

	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form']; ?>
	<td>
	<input name="<?=$arr['field_field']?>[1]" value="<?=$data[2]?>" size="50">
	<?
	}
	
	if($d=='prov')
	{
	if (!$data[1] && $arr['field_error']) $data[0] = $arr['field_error'];
	elseif($data[1] && $arr['field_min_max_err'] && (($arr['field_min'] && $kol_sim<$arr['field_min']) || ($arr['field_max'] && $kol_sim>$arr['field_max'])))
	$data[0] = $arr['field_min_max_err'];
	return $data;
	}
	
}

//////////// - числовое - ///////////////////
function field_func_3 ($d, $arr, $data)
{
	$data[1]=_chis($data[1], 'intval');
	if(!$data[1]) $datas=''; else $datas=$data[1];
	
	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form']; ?>
	<td>
	<?
	if($arr['field_d_1'] && $arr['field_d_2'])
		{
		?>
		<select style="width: 90px" name="<?=$arr['field_field']?>[1]">
		<option value="0"> - - - </option>
		<?
		if($arr['field_d_1']<$arr['field_d_2'])
			{
			for($i=$arr['field_d_1']; $i<=$arr['field_d_2']; $i++)
				{
				?>
				<option value="<?=$i?>" <? if($data[1]==$i) echo 'selected'; ?> ><?=$i?></option>
				<?		
				}
			}
		else
			{
			for($i=$arr['field_d_1']; $i>=$arr['field_d_2']; $i--)
				{
				?>
				<option value="<?=$i?>" <? if($data[1]==$i) echo 'selected'; ?> ><?=$i?></option>
				<?		
				}
			}
		?>
		</select>
		<?
		}
	else
		{
		?>
		<input id="<?=$arr['field_field']?>" onKeyUp="parce_chis(this.value, '<?=$arr['field_field']?>')" name="<?=$arr['field_field']?>[1]" value="<?=_font($datas, $arr['field_format'])?>" size="10">
		<?
		}
	}
	
	if($d=='prov')
	{
	if (!$data[1] && $arr['field_error']) $data[0] = $arr['field_error'];
	return $data;
	}
}
//////////// - цена - ///////////////////
function field_func_31 ($d, $arr, $data)
{
	global $global_suff;
	global $rru;
	
	$data[1]=_chis($data[1], 'intval');
	if(!$data[1]) $datas=''; else $datas=$data[1];
	
	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; ?>
	<font color=green><b>
	<? echo $arr['field_form'].', '.$rru['cena_valuta']; if($arr['field_suff']) echo ' '.$arr['field_suff']; ?>
	<span id="suff_a"><?=$global_suff?></span>
	</b></font>
	<td>
	<input id="<?=$arr['field_field']?>" onKeyUp="parce_chis(this.value, '<?=$arr['field_field']?>')" name="<?=$arr['field_field']?>[1]" value="<?=_font($datas, $arr['field_format'])?>" size="10">
	<input type="hidden" name="suff_b" value="<?=$arr['field_suff']?>">
	<?
	}
	
	if($d=='prov')
	{
	if (!$data[1] && $arr['field_error']) $data[0] = $arr['field_error'];
	elseif($data[1] && $arr['field_min_max_err'] && (($arr['field_min'] && $data[1]<$arr['field_min']) || ($arr['field_max'] && $data[1]>$arr['field_max'])))
	$data[0] = $arr['field_min_max_err'];
	return $data;
	}
}

//////////// - Этаж - ///////////////////
function field_func_32 ($d, $arr, $data)
{
	$data[1]=intval($data[1]);
	$data[2]=intval($data[2]);
	$data[3]=$arr['id_field'];
	$arr['field_form']=explode("|", $arr['field_form']);
	if($arr['field_error']) $arr['field_error']=explode("|", $arr['field_error']);
	
	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form'][0]; ?>
	<td>
	<select style="width: 90px" name="<?=$arr['field_field']?>[1]">
	<option value="0"> - - - </option>
	<?
	for($i=1; $i<=30; $i++)
		{
		?>
		<option value="<?=$i?>" <? if($data[1]==$i) echo 'selected'; ?> ><?=$i?></option>
		<?		
		}
	?>
	</select>

	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form'][1]; ?>
	<td>
	<select style="width: 90px" name="<?=$arr['field_field']?>[2]">
	<option value="0"> - - - </option>
	<?
	for($i=1; $i<=30; $i++)
		{
		?>
		<option value="<?=$i?>" <? if($data[2]==$i) echo 'selected'; ?> ><?=$i?></option>
		<?		
		}
	?>
	</select>
	<?
		
	}

	
	if($d=='prov')
	{
	if (!$data[1] && $arr['field_error']) $data[0] = $arr['field_error'][0];
	if (!$data[2] && $arr['field_error']) 
		{
		if($data[0])
		$data[0] .= '<br>- ';
		$data[0] .= $arr['field_error'][1];
		}
	if($data[1] && $data[2] && $data[1] > $data[2]) $data[0] = 'Этаж не может быть больше, чем этажность дома';
	return $data;
	}
}

//////////// - числовой список - ///////////////////
function field_func_4 ($d, $arr, $data)
{
	$data[1]=_chis($data[1], 'floatval');
	if(!$data[1]) $datas=''; else $datas=$data[1];
	
	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form']; ?>
	<td>
	<?
	if($arr['field_znak'])
		{
		?>
		<input id="<?=$arr['field_field']?>" name="<?=$arr['field_field']?>[1]" value="<?=_font($datas, $arr['field_format'], 0, $arr['field_znak'])?>" size="10">
		<?
		}
	else
		{
		?>
		<input id="<?=$arr['field_field']?>" onKeyUp="parce_chis(this.value, '<?=$arr['field_field']?>')" name="<?=$arr['field_field']?>[1]" value="<?=_font($datas, $arr['field_format'])?>" size="10">
		<?
		}
	}
	
	if($d=='prov')
	{
	if (!$data[1] && $arr['field_error']) $data[0] = $arr['field_error'];
	elseif($data[1] && $arr['field_min_max_err'] && (($arr['field_min'] && $data[1]<$arr['field_min']) || ($arr['field_max'] && $data[1]>$arr['field_max'])))
	$data[0] = $arr['field_min_max_err'];
	return $data;
	}
}
/////////////// - список - /////////////////
function field_func_5 ($d, $arr, $data)
{
	global $arr_element;
	global $arr_suff;
	global $arr_element_fon;
	global $arr_element_text;

	$data[1]=intval($data[1]);

	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form']; ?>
	<td>
	<?
	if(!$arr_suff[$arr['field_spisok']])
		{
		?>
		<select <? if($arr_element_fon[$arr['field_spisok']]) echo 'id="s_'.$arr['field_spisok'].'" onchange="func5(\'s_'.$arr['field_spisok'].'\');"'; ?> style="width: 150px" name="<?=$arr['field_field']?>[1]">
		<option value="0" > - - - </option>
		<?
		foreach($arr_element[$arr['field_spisok']] as $index=>$arr_el)
			{
			?>
			<option <? if($arr_element_fon[$arr['field_spisok']][$index]) echo 'style="background-color:'.$arr_element_fon[$arr['field_spisok']][$index].'; color:'.$arr_element_text[$arr['field_spisok']][$index].';"';?> value="<?=$index?>" <? if($index==$data[1]) echo 'selected'; ?>><?=$arr_el?></option>
			<?
			}
		?>
		</select>
		<?
		}
	elseif($arr_suff[$arr['field_spisok']])
		{
		?>
		<select style="width: 150px" onChange="_suff(<?=$arr['field_spisok']?>,this.value)" name="<?=$arr['field_field']?>[1]">
		<option value="0" > - - - </option>
		<?
		foreach($arr_element[$arr['field_spisok']] as $index=>$arr_el)
			{
			?>
			<option value="<?=$index?>" <? if($index==$data[1]) echo 'selected'; ?>><?=$arr_el?></option>
			<?
			}
		?>
		</select>
		<input type="hidden" name="suff" id="suff" value="<?=$arr_suff[$arr['field_spisok']][$data[1]]?>">
		<?
		}
	}
	if($d=='prov')
	{
	if (!$data[1] && $arr['field_error']) $data[0] = $arr['field_error'];
	return $data;
	}
}
/////////////// - двойной список - /////////////////
function field_func_7 ($d, $arr, $data)
{
	global $arr_element;
	global $arr_element_two;
	$data[1]=intval($data[1]);
	$data[2]=intval($data[2]);
	$data[3]=$arr['id_field'];

	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form']; ?>
	<td>
	
	<select style="width: 150px" name="<?=$arr['field_field']?>[1]" onChange="send_element_two(this.value, <?=$arr['id_field']?>, <?=$arr['field_spisok']?>, '<?=$arr['field_field']?>', ' - - - ')">
		<option value="0" > - - - </option>
	<?
	foreach($arr_element[$arr['field_spisok']] as $index=>$arr_el)
		{
		?>
		<option value="<?=$index?>" <? if($index==$data[1]) echo 'selected'; ?>><?=$arr_el?></option>
		<?
		}
	?>
	</select>
	
		<?
		if($arr_element_two[$data[1]])	
			{
			$sel_element='<select style="width: 150px" name="'.$arr['field_field'].'[2]">';
			$sel_element .='<option value="0"> - - - </option>';
	
			foreach($arr_element_two[$data[1]] as $ind=>$el)
				{
				$sel_element .= '<option value='.$ind;
				if($ind==$data[2]) 
				$sel_element .= ' selected '; 
				$sel_element .= '>'.$el.'</option>'; 
				}
			$sel_element .='</select>';
			} 
			else 
			{
			$sel_element='';
			}

	?>
	
	<tt id="www<?=$arr['id_field']?>"><? echo $sel_element; ?></tt>
	
	<?
	}
	
	if($d=='prov')
	{

	foreach($arr_element[$arr['field_spisok']] as $index=>$arr_el)
		{
		if($arr_element_two[$index])	
		$r[$index]=1;
		else 
		$r[$index]=0;
		}

	if( ($r[$data[1]] && !$data[2] && $arr['field_error']) || (!$data[1] && $arr['field_error']) ) 
	$data[0] = $arr['field_error'];
	return $data;
	}
}
////////////// - URL - /////////////////
function field_func_9 ($d, $arr, $data)
{
	$data_tmp = doman_name($data[1]);
	$data[1]=$data_tmp[0];
	$data[2]=$data_tmp[1];
	$data[3]=$arr['id_field'];

	if($d=='add')
	{
	?>
	<tr><td width="35%">
	<? if($arr['field_error']) echo '<font size=+1 color=red>*</font> '; echo $arr['field_form']; ?>
	<td>
	<input name="<?=$arr['field_field']?>[1]" value="<?=$data[1]?>" size="50">
	<?
	}
	
	if($d=='prov')
	{
	if (!$data[1] && $arr['field_error']) $data[0] = $arr['field_error'];
	if($data[2] && !_url($data[2]) && !$data[0]) $data[0]='Укажите корректный URL';

	return $data;
	}
}

?>
