<?php

function TextInput($value,$name,$title='',$options='',$div=true,$id_name='',$ss=false)
{	global $_SYSTEM,$THIS_array, $border, $tabs, $forceFieldName;
	if(Preferences('HIDDEN')!='Y')
		$div = false;
	if((AllowEdit() && !$_REQUEST['CREATEPDF']))
	{
		$value1 = is_array($value) ? $value[1] : $value;
		$value = is_array($value) ? $value[0] : $value;
                //if(strpos($options,'size=')===true && $value!='')
  //              echo "opt => ".$options."<br />";
//                echo "value => ".$value."<br />";
                if(strpos($options,'size=')===1 && $value!=='')
                {
                        if(intval(substr($options,strpos(strtolower($options),'size=')+5,2))<50)
                            $options .= ' size='.substr($options,strpos(strtolower($options),'size=')+5,2);
                        else
                            $input_style = ' style=\"width:99%;\"';
                }
		elseif(strpos($options,'size')===false && $value!='' && strlen($value)<35)
                {
                    $options .= ' size='.ceil(strlen($value)*.85);
                }
		elseif(strpos($options,'size')===false && $value!='')
                {

			$options .= ' size=30';
                }
		elseif(strpos($options,'size')===false && $_REQUEST['servicemod'])
                {
                    
			$options .= ' size=10';
                }
		elseif(strpos($options,'size')===false)
                {
			$options .= ' size=30';
                }
                if(strpos($options,'size=')===false && $value!='')
                {
			$options .= ' size='.substr($options,strpos(strtolower($options),'size='),2);
                }
                if(strpos($options,'size=')===false && $value!='')
                {
                        $options .= ' size=30';
                }
                
		if(strpos($name, '[SORT_ORDER]') !==false) 
			$options .= ' class="numeric" onkeyup="return check_numeric(this);" onchange="return check_numeric(this);" ';
		$comment = '<!-- '.$value.' -->';
                //var_dump($input_style);
		if (!$border) $border = array();
		if(in_array($name, $border))
			$style = 'class = errorTextField style=width:200px'; 

		if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
		foreach ($_SYSTEM['fieldNames'] as $fName)
		{
			if(!$_SYSTEM[$fName]) $_SYSTEM[$fName] = array();
			if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
			{
				$value = $_SYSTEM[$fName][$name];
				$div = false;
			}
		}	
		if($forceFieldName)
		{
			foreach($forceFieldName as $forceItem)
			{
				foreach ($forceItem as $fKey => $fValue)
				{
					if($fKey.'['.$fValue.']' == $name)
						if(array_key_exists($fValue, $_SESSION['_REQUEST_vars'][$fKey]))
						{
							$value = $_SESSION['_REQUEST_vars'][$fKey][$fValue];
							$div = false;
						}
				}
			}
		}
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
		//var_dump($input_style);
		if(((trim($value)=='' && $div!=='force') || $div==false))
			return $comment."$title <INPUT type=text  $onchange $style name=$name id=input".(($id_name=='')?$name:$id_name)." ".(($value || $value==='0')?"value=\"".str_replace('"','\"',$value)."\"":'')." $input_style $options onblur = getFieldsInit(this);>".(($title!='')?"":'');
		else
			return $comment."<DIV id='div$name'><div id='innerdiv$name' $style onclick='addHTML(\"".str_replace("'","&rsquo;",$title)." <INPUT type=text $onchange id=input".(($id_name=='')?$name:$id_name)." $input_style name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value))."\\\"":'')." ".str_replace('"','\"',$options)." onblur = getFieldsInit(this);>".(($title!='')?"":'')."\",\"div$name\",true);if(document.getElementById(\"input".(($id_name=='')?$name:$id_name)."\")){document.getElementById(\"input".(($id_name=='')?$name:$id_name)."\").value = replaceAll(document.getElementById(\"input".(($id_name=='')?$name:$id_name)."\").value,\"``\",\"\\\"\");dOr();document.getElementById(\"input".(($id_name=='')?$name:$id_name)."\").focus();}'>$title <span class='clickable'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
//			return $comment."<DIV id='div$name'><div id='innerdiv$name' $style onclick='addHTML(\"<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value))."\\\"":'')." ".str_replace('"','\"',$options)." onblur = getFieldsInit(this);>".(($title!='')?"<small>".str_replace("'","&rsquo;",$title)."</small>":'')."\",\"div$name\",true);if(document.getElementById(\"input$name\")){document.getElementById(\"input$name\").value = replaceAll(document.getElementById(\"input$name\").value,\"``\",\"\\\"\");dOr();document.getElementById(\"input$name\").focus();}'>$title&nbsp;<span class='clickable'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
	}
	else
		return "$title ".(((is_array($value)?$value[1]:$value)!='')?(is_array($value)?$value[1]:$value):'-').(($title!='')?"":'');

}

function TextAreaInput($value,$name,$title='',$options='',$div=true)
{	global $_SYSTEM, $border, $tabs, $forceFieldName;
	//die('test hello');
	if(Preferences('HIDDEN')!='Y')
		$div = false;
	//echo "value=".$value."<br> name=".$name."<br>title =".$title."<br>options =".$options."<br>div = ".$div;die;
	if(!$border) $border = array();
	if(in_array($name, $border))
	{
		$style = 'class = errorTextField style=width:250px';
		
	}
	
	if(!$_SYSTEM['fieldNames']){
		$_SYSTEM['fieldNames'] = array();

		foreach ($_SYSTEM['fieldNames'] as $fName)
		{
			if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
			{
				$value = $_SYSTEM[$fName][$name];
				$div = false;
			}
		}
	}

		
	
	if($forceFieldName)
	{
		foreach($forceFieldName as $forceItem)
		{
			foreach ($forceItem as $fKey => $fValue)
			{
				if($fKey.'['.$fValue.']' == $name)
					if(array_key_exists($fValue, $_SESSION['_REQUEST_vars'][$fKey]))
					{
						$value = $_SESSION['_REQUEST_vars'][$fKey][$fValue];
						$div = false;
					}
			}
		}
	}
//return "$value";//die;

	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{   
		$comment = '<!-- '.$value.' -->';
		$value = str_replace("\n","\r",str_replace("\r\n","\r",$value));
     
		//$value = str_replace("'","&rsquo;",str_replace('"','&rdquo;',$value));
		//$value = str_replace("'","&rsquo;",str_replace('"', get_magic_quotes_gpc() ? '\"' : '"' ,$value));
		//$value = str_replace("'","&rsquo;",str_replace('"','' , '"' ,$value));   // commented by rakesh
		//return $value;
		if(strpos($options,'cols')===false)
			$options .= ' cols=30';
		if(strpos($options,'rows')===false)
			$options .= 'rows=4';
		$rows = substr($options,strpos($options,'rows')+5,2)*1;		
		$cols =preg_replace('[^0-9]','',substr($options,strpos($options,'cols')+5,3))*1;
		
		
				//		str_replace(("'","&rsquo;",$value))."</TEXTAREA>"."\",\"div$name\",true);
//				padding-right: 16px;" class="clickable">'.nl2br(str_replace('\"','"',str_replace('"','\"',$value))).'</DIV>':'<DIV style="overflow:auto; width:'.($cols*7).'; 		
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
   //die;
		if(($value=='' && $div!=='force') || $div==false)
			return $comment."<TEXTAREA $style id=textarea$name $onchange name=$name $options onblur = getFieldsInit(this);>".$value."</TEXTAREA>".(($title!='')?"$title":'');
		else
			return $comment."<DIV id='div$name'><div id=innerdiv$name $style onclick='addHTML(".
			"<TEXTAREA id=textarea$name name=$name $onchange >".
				"$options onblur = getFieldsInit(this);>".preg_replace("[\n\r]",'\u000D\u000A',str_replace("\r\n",'\u000D\u000A',
				str_replace('"','\"',str_replace("'","&rsquo;",$value))))."</TEXTAREA>"."\",\"div$name\",true);".
				" //alert(jQuery(\"textarea#textarea$name\").val()); ".
				//"value=unescape(document.getElementById(\"textarea$name\").value);".

                                "".
                                // " alert(document.forms.student.textarea".str_replace(array('[',']'),array('\\\[','\\\]'),$name)."); ".
                                "dOr();document.getElementById(\"textarea$name\").focus();'>".
				"<TABLE class=GridOutput_fieldint height=100%><TR><TD>".((true)?'<DIV style="overflow:auto; height:'.(15*$rows).'px; width:'.($cols*7).'; ".
				"padding-right: 16px;" class="clickable">'.nl2br(str_replace('"','"',$value)).'</DIV>':'<DIV style="overflow:auto; width:'.($cols*7).'; ".
				"padding-right: 16px;" class="clickable">'.nl2br(str_replace('\"','"',$value)).'</DIV>').'</TD></TR></TABLE>'."</div></DIV>".(($title!='')?"".
				$title."":'');

/*
			return "<DIV id='div$name'><div id='innerdiv$name' $style onclick='addHTML(\"<TEXTAREA id=textarea$name name=$name 
				$options onblur = getFieldsInit(this);>".preg_replace("[\n\r]",'\u000D\u000A',str_replace("\r\n",'\u000D\u000A',
				str_replace("'","&rsquo;",$value)))."</TEXTAREA>"."\",\"div$name\",true);
				 document.getElementById(\"textarea$name\").
				value=unescape(document.getElementById(\"textarea$name\").value);dOr();document.getElementById(\"textarea$name\").focus();'>
				<TABLE class=GridOutput_fieldint height=100%><TR><TD>".((true)?'<DIV style="overflow:auto; height:'.(15*$rows).'px; width:'.($cols*7).'; 
				padding-right: 16px;" class="clickable">'.nl2br(str_replace('"','\"',$value)).'</DIV>':'<DIV style="overflow:auto; width:'.($cols*7).'; 
				padding-right: 16px;" class="clickable">'.nl2br(str_replace('\"','"',$value)).'</DIV>').'</TD></TR></TABLE>'."</div></DIV>".(($title!='')?"".
				$title."":'');

*/
	}
	elseif($_REQUEST['CREATEPDF'])
	{   
		$value = str_replace("\r",'<BR>',str_replace("\n","\r",str_replace("\r\n","\r",$value)));
		return (($value!='')?$value:'-').(($title!='')?"$title":'');
	}
	else
		
    	return (($value!='')?$value:'-').(($title!='')?"$title":'');
}

function CheckboxInput($value,$name,$title='',$checked='',$new=false,$yes='Yes',$no='No',$div=true,$addition='')
{	global $_SYSTEM, $border, $tabs, $advRep;

	if($yes=='Yes')
		$yes = _('Yes');
	if($no=='No')
		$no = _('No');

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	if($div==false || $new==true)
	{
		if($value && $value!='N')
			$checked = 'CHECKED';
		else
			$checked = '';
	}
	
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = "style = 'border: 3px solid #FF0000; outline: 3px solid #FF0000;'";
		
	if(in_array($advRep, $border))
	{
		unset($style);
		$divStyle =  "style = 'border: 1px solid #FF0000; outline: 1px solid #FF0000;'";
	}

	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			if($value == 'Y')
			{
				$checked = 'CHECKED';	
				$div = false;
			}
			else 
			{
				$checked = '';	
			}
		}
	}
	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
//		$comment = '<!-- '.$options[$value].' -->';
		$innerdivid = !($_SYSTEM['no_inner_ids']===true)?"id='innerdiv$name'":"";
		
		$checkboxid = !($_SYSTEM['no_inner_ids']===true)?"id=\"input$name\"":'';
		
		$titleforcheckbox = ($title!='')?($checkboxid!=""?"<label for=\"input$name\">$title</label>":$title):"";
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
		if($new || $div==false)
			return $comment.$titleforcheckbox." <INPUT type=hidden name=$name value=\"\" onchange = getFieldsInit(this);><INPUT type=checkbox name=$name value=Y $checkboxid $checked $addition $style onchange = getFieldsInit(this); $onchange>";
		else
			return $comment."<DIV id='div$name'><div id='innerdiv$name' $divStyle onclick=".
			    "'addHTML(\"<INPUT type=hidden input$name name=$name value=\\\"\\\" onchange".
			    " = getFieldsInit(this);>".str_replace("'","&rsquo;",$title)." <INPUT type=checkbox id=input$name name=$name ".
			    (($value && $value!='N')?'checked':'')." value=Y ".str_replace('"','\"',$addition).
			    " onchange = getFieldsInit(this); $onchange>".(($title!='')?"".
			    "":'')."\",\"div$name\",true);dOr();'>".str_replace("'","&rsquo;",$title).
			    " <span class='clickable'>".(($value && $value!='N')?$yes:$no).'</span>'.
			    (($title!='')?"":'')."</div></DIV>";

	}
	elseif($_REQUEST['CREATEPDF'])
		return (($value && $value!='N')?_('Y'):_('N'));
	else
		return "$title ".(($value && $value!='N')?$yes:$no).(($title!='')?"":'');
				
}

function makeCheckbox($value,$name,$title='',$checked='',$new=false,$yes='Yes',$no='No',$div=true,$addition='',$java='')
{	global $_SYSTEM, $border, $tabs, $advRep;

	if($yes=='Yes')
		$yes = _('Yes');
	if($no=='No')
		$no = _('No');

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	if($div==false || $new==true)
	{
		if($value && $value!='N')
			$checked = 'CHECKED';
		else
			$checked = '';
	}
	
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = "style = 'border: 3px solid #FF0000; outline: 3px solid #FF0000;'";
		
	if(in_array($advRep, $border))
	{
		unset($style);
		$divStyle =  "style = 'border: 1px solid #FF0000; outline: 1px solid #FF0000;'";
	}

	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			if($value == 'Y')
			{
				$checked = 'CHECKED';	
				$div = false;
			}
			else 
			{
				$checked = '';	
			}
		}
	}
	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
//		$comment = '<!-- '.$options[$value].' -->';
		$innerdivid = !($_SYSTEM['no_inner_ids']===true)?"id='innerdiv$name'":"";
		
		$checkboxid = !($_SYSTEM['no_inner_ids']===true)?"id=\"input$name\"":'';
		
		$titleforcheckbox = ($title!='')?($checkboxid!=""?"<label for=\"input$name\">$title</label>":$title):"";
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
		if($new || $div==false)
			return $comment.$titleforcheckbox." <INPUT type=hidden name=$name value=\"\" onchange = getFieldsInit(this);><INPUT type=checkbox name=$name value=Y $checkboxid $checked $addition $style onchange = getFieldsInit(this); $onchange $java>";
		else
			return $comment."<DIV id='div$name'><div id='innerdiv$name' $divStyle onclick=".
			    "'addHTML(\"<INPUT type=hidden input$name name=$name value=\\\"\\\" onchange".
			    " = getFieldsInit(this);>".str_replace("'","&rsquo;",$title)." <INPUT type=checkbox id=input".str_replace('[','_',str_replace(']','_',$name))." name=$name ".
			    (($value && $value!='N')?'checked':'')." value=Y ".str_replace('"','\"',$addition).
			    " onchange = getFieldsInit(this); $onchange $java>".(($title!='')?"".
			    "":'')."\",\"div$name\",true);dOr();'>".str_replace("'","&rsquo;",$title).
			    " <span class='clickable'>".(($value && $value!='N')?$yes:$no).'</span>'.
			    (($title!='')?"":'')."</div></DIV>";

	}
	elseif($_REQUEST['CREATEPDF'])
		return (($value && $value!='N')?_('Y'):_('N'));
	else
		return "$title ".(($value && $value!='N')?$yes:$no).(($title!='')?"":'');
				
}

function SelectInput($value,$name,$title='',$options='',$allow_na='',$addition='',$div=true,$js_options_title='', $showOnchange = true)
{	global $_SYSTEM, $border, $tabs, $forceFieldName,$_Config;

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	// mab - support array style $option values
	// mab - append current val to select list if not in list
	//$value = str_replace("'","&rsquo;",str_replace('"', get_magic_quotes_gpc() ? '\"' : '"' ,$value));
	
	$value = str_replace("'","&rsquo;",str_replace('"', '"' ,$value));
	
	
	if ($value!='' && is_array($options) && in_array($value, $options))
		$options += array($value=>array($value,'<FONT color=#FF0000>'.$value.'</FONT>'));
//echo "8888>".$value;
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = 'class = errorTextFieldSelect style=width:200px'; 
		
		
	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{ 
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}
	
	if($forceFieldName)
	{
		foreach($forceFieldName as $forceItem)
		{
			foreach ($forceItem as $fKey => $fValue)
			{
				if($fKey.'['.$fValue.']' == $name)
					if(array_key_exists($fValue, $_SESSION['_REQUEST_vars'][$fKey]))
					{
						$value = $_SESSION['_REQUEST_vars'][$fKey][$fValue];
						$div = false;
					}
			}
		}
	}

	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{	
		if($options && in_array($value, $options))
		$comment = '<!-- '.$options[$value].' -->';
		$return = $comment;
		if(($value!='' || $div==='force') && $div)
		{
			$innerdivid = !($_SYSTEM['no_inner_ids']===true)?"id='innerdiv$name'":"";
			$return .= "<DIV id='div$name'><div $innerdivid $style onclick='addHTML(\"";
			$addition = str_replace('"','\"',$addition);
		}
		
//		if($showOnchange)
//			$onChangeExtra = "onchange = getFieldsInit(this);";
			$onChangeExtra = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
                        /*if($onChangeExtra<>'')
                            $onChangeExtra = ($showOnchange == '' && $showOnchange === true)?"":substr($onChangeExtra,0,-1).' '.$showOnchange.' \"';
                        else
                            $onChangeExtra = ($showOnchange == '' && $showOnchange === true)?"":"onchange=\" ".$showOnchange." \"";*/
		$return .= "$title <SELECT name=$name id=input$name $style $addition $onChangeExtra>";
		if($allow_na!==false)
		{
			if(!$allow_na)
				$allow_na = _('N/A');
			if(($value!='' || $div==='force') && $div)
				$return .= '<OPTION value=\"\">'.$allow_na;
			else
				$return .= '<OPTION value="">'.$allow_na;
		}
//                foreach($_Config['integral_replace_from'] as $integralcharacter=>$htmlcharacter)
  //                                          $value = (string) str_replace($htmlcharacter,$integralcharacter,$value);
             
//                foreach($_Config['integral_replace'] as $integralcharacter=>$htmlcharacter)
  //                  $value = str_replace($integralcharacter,$htmlcharacter,$value);
                //var_dump($value);
                //
                if(is_array($options))
                {
                    foreach($options as $keyrep=>$valrep)
                    {
                        foreach($_Config['integral_replace'] as $integralcharacter=>$htmlcharacter)
                        {
                            $keyrep = str_replace($integralcharacter,$htmlcharacter,$keyrep);
                        }
                        $new_option[$keyrep] = $valrep;
                    }
                }
                $option = $new_option;
		if(!$_SYSTEM[$js_options_title])
		{
			if(is_array($options))
			{
				foreach($options as $key=>$val)
				{
                                        foreach($_Config['integral_replace'] as $integralcharacter=>$htmlcharacter)
                                            $key = (string) str_replace($integralcharacter,$htmlcharacter,$key);
                                       /* var_dump($val);
                                        echo '===========>';
                                        foreach($_Config['integral_replace'] as $integralcharacter=>$htmlcharacter)
                                        {
                                            if(is_array($val))
                                                $val[0] = (string) str_replace($integralcharacter,$htmlcharacter,$val[0]);
                                            else
                                                $val = (string) str_replace($integralcharacter,$htmlcharacter,$val);
                                        }
                                        var_dump($val);
                                        echo '<hr>';*/
                                      /*  var_dump($value);
                                        echo '=========>';
                                        var_dump($key);
                                        echo '<hr>';*/
                                        

					if(($value!='' || $div==='force') && $div)
				{
					if($_GET)
							$return .= "<OPTION value=\\\"".str_replace("'",'&rsquo;',str_replace(array('"',"'"),array('&mytwoquote;','&myonequote;'),$key))."\\\" ".((str_replace("'",'&rsquo;',str_replace(array('"',"'"),array('&mytwoquote;','&myonequote;'),$value))==$key && (!($value==false && ($value!==$key)) || ($value==='0' && $key===0)))?'SELECTED':'').">".str_replace('"','\"',str_replace("'",'&rsquo;',(is_array($val)?$val[0]:$val)));                    	
                    else
                    
							$return .= "<OPTION value=\\\"".str_replace("'",'&rsquo;',$key)."\\\" ".(($value==$key && (!($value==false && ($value!==$key)) || ($value==='0' && $key===0)))?'SELECTED':'').">".str_replace("'",'&rsquo;',(is_array($val)?$val[0]:$val));
					}
					else
//						$return .= "<OPTION value=\"".$key."\" ".(($value==$key && !($value==false && $value!==$key))?'SELECTED':'').">".(is_array($val)?$val[0]:$val);
						$return .= "<OPTION value=\"".str_replace('"','\"',str_replace(array('"',"'"),array('&mytwoquote;','&myonequote;'),$key))."\" ".((str_replace("'",'&rsquo;',str_replace(array('"',"'"),array('&mytwoquote;','&myonequote;'),$value))==$key && !($value==false && $value!==$key))?'SELECTED':'').">".(is_array($val)?$val[0]:$val);
				}
			}
		}
		else
		{
			$return .= '"+'.$_SYSTEM[$js_options_title].'+"';
			$js .= "setSI(\"input".$name."\",\"".$value."\");";
		}

		$return .= "</SELECT>";
                
                //var_dump($options);
                //echo '<hr>';
                //var_dump($options[$value]);
                //echo '<hr>';
                //var_dump($value);
                //echo '<hr>';
		if($title!='')
			$return .= "";
		if(($value!='' || $div==='force') && $div)
//			if(!get_magic_quotes_gpc())
				$return .="\",\"div$name\",true);".$js."dOr();'>$title <span class='clickable'>".(((is_array($options[$value])?str_replace('"','"',$options[$value][1]):$options[$value])!='')?(is_array($options[$value])?str_replace('"','"',$options[$value][1]):str_replace('"','"',$options[$value])):'-').'</span>'.(($title!='')?"":'').'</div></DIV>';
			else
				if ($value!='' && in_array($value, $options))
				$return .="\",\"div$name\",true);".$js."dOr();'>$title <span class='clickable'>".(((is_array($options[$value])?$options[$value][1]:$options[$value])!='')?(is_array($options[$value])?$options[$value][1]:$options[$value]):'-').'</span>'.(($title!='')?"":'').'</div></DIV>';
//	    htmlspecialchars($return);
//	    die();
	}
	else
		$return = "$title ".(((is_array($options[$value])?$options[$value][1]:$options[$value])!='')?(is_array($options[$value])?$options[$value][1]:$options[$value]):'-').(($title!='')?"":'');

	return ''.$return;


}

function make_select_box($value,$name,$title='',$options='',$allow_na='',$addition='',$div=true,$js_options_title='', $showOnchange = true)
{	global $_SYSTEM, $border, $tabs, $forceFieldName;

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	$bad_value = false;
	if ($options) {
		foreach($options as $opt_key=>$opt)
		{
			if(!$opt[$value])
			        $bad_value = true;
			else
			{
			        $comment = '<!-- '.$opt[$value].' -->';		    
			        $bad_value = false;
			        break;
			}
		}
	}
	if ($value!='' && is_array($options) && $bad_value === true)
		$options += array($value=>array($value,'<FONT color=#FF0000>'.$value.'</FONT>'));

//var_dump($options);
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = 'class = errorTextFieldSelect style=width:200px'; 
		
	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{ 
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}
	
	if($forceFieldName)
	{
		foreach($forceFieldName as $forceItem)
		{
			foreach ($forceItem as $fKey => $fValue)
			{
				if($fKey.'['.$fValue.']' == $name)
					if(array_key_exists($fValue, $_SESSION['_REQUEST_vars'][$fKey]))
					{
						$value = $_SESSION['_REQUEST_vars'][$fKey][$fValue];
						$div = false;
					}
			}
		}
	}

	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
//		$comment = '<!-- '.$options[$value].' -->';
//		$comment = '<!-- '.$options[key($options)][$value].' -->';		    
		$return = $comment;
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
		if(($value!='' || $div==='force') && $div)
		{
			$innerdivid = !($_SYSTEM['no_inner_ids']===true)?"id='innerdiv$name'":"";
			$return .= "<DIV id='div$name'><div $innerdivid $style onclick='addHTML(\"";
			$addition = str_replace('"','\"',$addition);
		}
		
		if($showOnchange)
			$onChangeExtra = "onchange = getFieldsInit(this);";
		$onchange = $onChangeExtra;
		$return .= "$title <SELECT name=$name id=input$name $style $addition $onChangeExtra>";
		if($allow_na!==false)
		{
			if(!$allow_na)
				$allow_na = _('N/A');

			if(($value!='' || $div==='force') && $div)
				$return .= '<OPTION value=\"\">'.$allow_na;
			else
				$return .= '<OPTION value="">'.$allow_na;
		}

		if(!$_SYSTEM[$js_options_title])
		{
			if(is_array($options))
			{	
				$old_options = $options;
				foreach($options as $key=>$vals)
				{
					if(($value!='' || $div==='force') && $div)				
						$return .= '<OPTGROUP LABEL=\"'._($key).'\">';
					else
						$return .= '<OPTGROUP LABEL="'._($key).'">';
					foreach($vals as $key=>$val)
					{
						$key = (string) $key;
						if(($value!='' || $div==='force') && $div)
						{
		//				echo "$value = $key = $val<BR>";
							$return .= "<OPTION value=\\\"".str_replace("'",'&rsquo;',$key)."\\\" ".(($value==$key && (!($value==false && ($value!==$key)) || ($value==='0' && $key===0)))?'SELECTED':'').">".str_replace("'",'&rsquo;',(is_array($val)?$val[0]:$val));
						}
						else
							$return .= "<OPTION value=\"$key\" ".(($value==$key && !($value==false && $value!==$key))?'SELECTED':'').">".(is_array($val)?$val[0]:$val);
					}
					$return .= '</OPTGROUP>';
					
				}
			}
			
		}		
		else
		{
			$return .= '"+'.$_SYSTEM[$js_options_title].'+"';
			$js .= "setSI(\"input".$name."\",\"".$value."\");";
		}

		$return .= "</SELECT>";
		if($title!='')
			$return .= "";

		if(($value!='' || $div==='force') && $div)
		{
//		var_dump($options);
//			$return .="\",\"div$name\",true);".$js."dOr();'>$title <span class='clickable'>".(((is_array($options[key($options)][$value])?$options[key($options)][$value][1]:$options[key($options)][$value])!='')?(is_array($options[key($options)])?$options[key($options)][$value]:$options[key($options)][$value]):'-').'</span>'.(($title!='')?"":'').'</div></DIV>';
			$return .="\",\"div$name\",true);".$js."dOr();'>$title <span class='clickable'>".(((is_array($options[$opt_key][$value])?$options[$opt_key][$value][1]:$options[$opt_key][$value])!='')?(is_array($options[$opt_key])?$options[$opt_key][$value]:$options[$opt_key][$value]):'-').'</span>'.(($title!='')?"":'').'</div></DIV>';
//			echo htmlspecialchars($return);
		}
	}
	else
	//	$return = "$title ".(((is_array($options[key($options)][$value])?$options[key($options)][$value][1]:$options[key($options)][$value])!='')?(is_array($options[key($options)])?$options[key($options)][$value]:$options[key($options)][$value]):'-').(($title!='')?"":'');
		$return = "$title ".(((is_array($options[$opt_key][$value])?$options[$opt_key][$value][1]:$options[$opt_key][$value])!='')?(is_array($options[$opt_key])?$options[$opt_key][$value]:$options[$opt_key][$value]):'-').(($title!='')?"":'');
//			echo htmlspecialchars($return);
	return ''.$return;

}


function SelectOneInput($value,$name,$title='',$options='',$allow_na='',$addition='',$div=true, $translate=false,$columns=2)
{	global $_SYSTEM, $border, $tabs;

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	/*
		check, if we already have a value for this field, we will display it
		Used in the New Student, School, User Pages
	*/	
	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}
	
	/*
 		used for displaying red border on the input field
	*/
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = "style = 'border: 3px solid #FF0000; outline: 3px solid #FF0000;'";
	
	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
		if(($value!='' || $div==='force') && $div)
			$return .= "<DIV id='div$name'><div onclick='addHTML(\"<INPUT type=hidden name=$name value=\\\"\\\">";
		$return .= '<TABLE border=0 cellpadding=3>';
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
		if(count($options)>12 && $title)
		{
			$return .= '<TR><TD colspan='.$columns.'>';
			$return .= '<small><b>'.$title.'<b></small>';
			if(($value!='' || $div==='force') && $div)
				$return .= '<TABLE width=100% height=7 style=\"border-width:1;border-style: solid solid none solid;\"><TR><TD></TD></TR></TABLE>';
			else
				$return .= '<TABLE width=100% height=7 style="border-width:1;border-style: solid solid none solid;"><TR><TD></TD></TR></TABLE>';

			$return .= '</TD></TR>';
		}
		$return .= '<TR>';
		$i = 0;
		foreach($options as $option)
		{
			if($i%$columns==0)
				$return .= '</TR><TR>';
			if(($value!='' || $div==='force') && $div)
				{
					if($translate === false)
						$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$option)).'\"'.(($value==$option)?' CHECKED':'').'><small><label for=\"'.$name.$option.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',$option)).'</label></small></TD>';
					else
						$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',_($option))).'\"'.(($value==$option)?' CHECKED':'').'><small><label for=\"'.$name.$option.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',_($option))).'</label></small></TD>';
				}
			else 
			{
				if($translate === false)
					$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value="'.$option.'"'.(($value==$option)?' CHECKED':'').'><small><label for="'.$name.$option.'">'.$option.'</label></small></TD>';
				else
					$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value="'._($option).'"'.(($value==$option)?' CHECKED':'').'><small><label for="'.$name.$option.'">'._($option).'</label></small></TD>';
			}
			$i++;
		}
		$return .= '</TR>';
		
		if($title)
		{
			$return .= '<TR><TD colspan='.$columns.'>';
			if(($value!='' || $div==='force') && $div)
				$return .= '<TABLE width=100% height=7 style=\"border-width:1;border-style: none solid solid solid;\"><TR><TD></TD></TR></TABLE>';
			else
				$return .= '<TABLE width=100% height=7 style="border-width:1;border-style: none solid solid solid;"><TR><TD></TD></TR></TABLE>';
			$return .= '</TD></TR>';
		}

		$return .= '</TABLE>';

		if(($value!='' || $div==='force') && $div)
			$return .= "\",\"div$name"."\",true);' ><span class='clickable'>".(($value!='')?$value:'-')."</span></div></DIV>";
	}
	else
		$return .= (($value!='')?$value:'-');

	if($title)
		$return .= '<small><b>'.$title.'<b></small>';

	return $return;
}



function make_radiobutton($value,$name,$title='',$options=array(),$allow_na='',$addition='',$div=true, $translate=false)
{	global $_SYSTEM, $border, $tabs;

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}
	
	/*
 		used for displaying red border on the input field
	*/
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = "style = 'border: 3px solid #FF0000; outline: 3px solid #FF0000;'";
	
	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
		if(($value!='' || $div==='force') && $div)
			$return .= "<DIV id='div$name'><div onclick='addHTML(\"<INPUT type=hidden name=$name value=\\\"\\\">";
		$return .= '<TABLE border=0 cellpadding=3>';
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
		$i = 0;
		foreach($options as $option)
		{
			if($i%2==0)
				$return .= '</TR><TR>';
			if(($value!='' || $div==='force') && $div)
				{
					if($translate === false)
						$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$option)).'\"'.(($value==$option)?' CHECKED':'').'><small><label for=\"'.$name.$option.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',$option)).'</label></small></TD>';
					else
						$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',_($option))).'\"'.(($value==$option)?' CHECKED':'').'><small><label for=\"'.$name.$option.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',_($option))).'</label></small></TD>';

//					$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value="'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$option)).'"'.'>';
				}
			else 
			{
				if($translate === false)
					$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value="'.$option.'"'.(($value==$option)?' CHECKED':'').'><small><label for="'.$name.$option.'">'.$option.'</label></small></TD>';
				else
					$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$option.' name='.$name.' value="'._($option).'"'.(($value==$option)?' CHECKED':'').'><small><label for="'.$name.$option.'">'._($option).'</label></small></TD>';
				
//				$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value="'.$option.'">';
			}
//			$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value=\"'.$option.'\">';
			$i++;
		}
		$return .= '</TR>';
		
		if($title)
		{
			$return .= '<TR><TD colspan=2>';
			if(($value!='' || $div==='force') && $div)
				$return .= '<TABLE width=100% height=7 style=\"border-width:1;border-style: none solid solid solid;\"><TR><TD></TD></TR></TABLE>';
			else
				$return .= '<TABLE width=100% height=7 style="border-width:1;border-style: none solid solid solid;"><TR><TD></TD></TR></TABLE>';
			$return .= '</TD></TR>';
		}

		$return .= '</TABLE>';

		if(($value!='' || $div==='force') && $div)
			$return .= "\",\"div$name"."\",true);' ><span class='clickable'>".(($value!='')?$value:'-')."</span></div></DIV>";
	}
	else
		$return .= (($value!='')?$value:'-');

	if($title)
		$return .= '<small><b>'.$title.'<b></small>';

	return $return;
}

function SelectMultipleInput($value,$name,$title='',$options='',$allow_na='',$addition='',$div=true,$columns=2)
{	global $_SYSTEM, $border, $tabs, $advRep;

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	/*
		check, if we already have a value for this field, we will display it
		Used in the New Student, School, User Pages
	*/	
	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value  = '||';
			foreach ($_SYSTEM[$fName][$name] as $item)
			{
				$value .= $item.'||';	
			}
			$div = false;
		}
	}
	/*
 		used for displaying red border on the input field
	*/
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = "style = 'border: 3px solid #FF0000; outline: 3px solid #FF0000;'";
	if(in_array($advRep, $border))
	{
		unset($style);
		$divStyle = 'class = errorTextFieldSelect'; 
	}
	
	if((AllowEdit() && !$_REQUEST['CREATEPDF'] && $div!='none')|| ($_REQUEST['servicemod']=='applicants_online'))
	{
		if(($value!='' || $div==='force') && $div)
			$return .= "<DIV id='div$name'><div id='innerdiv$name' $divStyle onclick='addHTML(\"<INPUT type=hidden name=$name value=\\\"\\\">";
		$return .= '<TABLE border=0 cellpadding=3>';
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
		if($options && count($options)>12 && $title && $div!='force') // this isn't really needed any more since OtherInfo defaults to displaying fields in 1 column.  Only display if $div!='force' so this won't appear in StuFieldsProperties.php
		{
			$return .= '<TR><TD colspan='.$columns.'>';
			$return .= '<small><b>'.$title.'<b></small>';
			if(($value!='' || $div==='force') && $div)
				$return .= '<TABLE width=100% height=7 style=\"border-width:1;border-style: solid solid none solid;\"><TR><TD></TD></TR></TABLE>';
			else
				$return .= '<TABLE width=100% height=7 style="border-width:1;border-style: solid solid none solid;"><TR><TD></TD></TR></TABLE>';

			$return .= '</TD></TR>';
		}
		$return .= '<TR>';
		$i = 0;
		if($options===0)
		{
			foreach($options as $option)
			{
				if($i%$columns==0)
					$return .= '</TR><TR>';
				if(($value!='' || $div==='force') && $div)
					$return .= '<TD width='.round(100/$columns).'% style=\"white-space:nowrap;\"><INPUT type=checkbox '.$style.' name='.$name.'[] id=input'.$name.'['.$i.'] value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$option)).'\"'.((strpos($value,'||'.str_replace('"','&quot;',str_replace("'",'&rsquo;',$option)).'||')!==false)?' CHECKED':'').'><small><label for=input'.$name.'['.$i.']>'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',$option)).'</label></small></TD>';
				else
					$return .= '<TD width='.round(100/$columns).'% style=\"white-space:nowrap;\"><INPUT type=checkbox '.$style.' name='.$name.'[] id=input'.$name.'['.$i.'] value="'.$option.'"'.((strpos($value,'||'.str_replace('"','&quot;',str_replace("'",'&rsquo;',$option)).'||')!==false)?' CHECKED':'').'><small><label for=input'.$name.'['.$i.']>'.$option.'</label></small></TD>';
				$i++;
			}
			$selected_title = (($value!='')?str_replace('||',', ',substr($value,2,-2)):'-');
		}
		else
		{ 
			if ($options) {
				foreach($options as $val=>$option)
				{
					if($i%$columns==0)
						$return .= '</TR><TR>';
					if(($value!='' || $div==='force') && $div)
						$return .= '<TD width='.round(100/$columns).'% style=\"white-space:nowrap;\"><INPUT type=checkbox '.$style.' name='.$name.'[] id=input'.$name.'['.$i.'] value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$val)).'\"'.((strpos($value,'||'.str_replace('"','&quot;',str_replace("'",'&rsquo;',$val)).'||')!==false)?' CHECKED':'').'><label for=input'.$name.'['.$i.']>'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',$option)).'</label></TD>';
					else
						$return .= '<TD width='.round(100/$columns).'% style=\"white-space:nowrap;\"><INPUT type=checkbox '.$style.' name='.$name.'[] id=input'.$name.'['.$i.'] value="'.$val.'"'.((strpos($value,'||'.str_replace('"','&quot;',str_replace("'",'&rsquo;',$val)).'||')!==false)?' CHECKED':'').'><label for=input'.$name.'['.$i.']>'.$option.'</label></TD>';
					if(strpos($value,'||'.str_replace('"','&quot;',str_replace("'",'&rsquo;',$val)).'||')!==false)
						$selected_title .= ', '.(($_REQUEST['servicemod'] == 'mod_users/Users.php')?'<br>':'').$option;
					$i++;
				}
			}
			$selected_title = substr($selected_title,2);
		}
		if(!$selected_title)
			$selected_title = '-';
		$return .= '</TR>';
		
		if($title)
		{
			$return .= '<TR><TD colspan='.$columns.'>';
			if(($value!='' || $div==='force') && $div)
				$return .= '<TABLE width=100% height=7 style=\"border-width:1;border-style: none solid solid solid;\"><TR><TD></TD></TR></TABLE>';
			else
				$return .= '<TABLE width=100% height=7 style="border-width:1;border-style: none solid solid solid;"><TR><TD></TD></TR></TABLE>';
			$return .= '</TD></TR>';
		}

		$return .= '</TABLE>';

		if(($value!='' || $div==='force') && $div)
			$return .= "\",\"div$name"."\",true);$addition' ><span class='clickable'>".$selected_title."</span></div></DIV>";
	}
	else
	{ 
	    if(!$options) $options = array();
		if(key($options)===0)
			$return .= (($value!='')?str_replace('||',', ',substr($value,2,-2)):'-');
		else
		{
			foreach($options as $val=>$option)
			{
				if(strpos($value,'||'.str_replace('"','&quot;',str_replace("'",'&rsquo;',$val)).'||')!==false)
					$selected_title .= ', '.$option;
			}
			$selected_title = substr($selected_title,2);
			if(!$selected_title || $selected_title == '') $selected_title = '-';
			$return .= $selected_title."";
		}
	}

	if($title && $div!='force')
		$return .= '<b>'.$title.'</b>';
	elseif($title) // since the bold looks bad in StuFieldsProperties.php
	{
		if(get_user('PROFILE') == 'teacher')
		    $return .= ''.$title.'';
		else
		    $return .= ''.$title.'';
	}	

	return $return;
}



function DateInput($value,$name,$title='',$div=true,$allow_na=true,$format='postgres',$short=false)
{	global $_SYSTEM, $border, $style, $tabs, $forceFieldName;

	if(Preferences('HIDDEN')!='Y')
		$div = false;
	if($value==get_db_date() || $format=='postgres')
		$this_big_year_range = true;
	else
		$this_big_year_range = false;

	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = 'class = errorTextFieldSelect';
	else 
		$style = '';
	
	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}
	
	if($forceFieldName)
	{
		foreach($forceFieldName as $forceItem)
		{
			foreach($forceItem as $fKey => $fValue)
			{
				if($fKey.'['.$fValue.']' == $name)
				{
					if(array_key_exists($fValue, $_SESSION['_REQUEST_vars'][$fKey]))
					{
						$value = $_SESSION['_REQUEST_vars'][$fKey][$fValue];
						$div = false;
					}
				}
			}
		}
	}
	
	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
		if(($value=='' && $div!=='force') || $div==false) 
		{
			return "$title ".PrepareDate($value,"_$name",$allow_na,array('big_year_range'=>$this_big_year_range,'format'=>$format,'short'=>$short))."";
		}
		else
		{
			if(strlen($value)==19 || strlen($value)==23) // truncate off the timestamp portion, leaving just the 10-character date.  Timestamp is only returned by mssql.  Requires php.ini mssql.dateconvert = Off
				$value = substr($value,0,10);

			if($DBType=='mssql' || strlen($value)==18)
			{
				if(strlen($date)==18) $date = substr($date,0,4).' '.substr($date,4);
				$year = substr($date,7,4);
				$month = $months_number[strtoupper(substr($date,0,3))];;
				$day = substr($date,4,2);
				$comment = '<!-- '.$year.$month.$day.' -->';
			}
			elseif($value && strlen($value)==9)
			{
				$year = substr($value,7);
				$year = (($year<50)?20:19).$year;
				$month = $months_number[strtoupper(substr($value,3,3))];
				$day = substr($value,0,2)*1;
				$comment = '<!-- '.(($year<50)?20:19).$year.MonthNWSwitch(substr($value,3,3),'tonum').(substr($value,0,2)).' -->';
			}
			elseif($value && strlen($value)==10)
			{
				$year = substr($value,0,4);
				$month = substr($value,5,2)*1;
				$day = substr($value,8)*1;
				$comment = '<!-- '.$year.substr($value,5,2).(substr($value,8)).' -->';
			}
			elseif($value && strtotime($value))
			{
				$value = date('Y-m-d',strtotime($value));
				$year = substr($value,0,4);
				$month = substr($value,5,2)*1;
				$day = substr($value,8)*1;
				$comment = '<!-- '.$year.substr($value,5,2).(substr($value,8)).' -->';
			}
			$PrepareDateOptions = array('Y'=>1,'M'=>1,'D'=>1,'big_year_range'=>$this_big_year_range,'format'=>$format,'short'=>$short);
			return $comment."<DIV id='div$name'><div id='innerdiv$name' $style onclick='addHTML(\"$title ".str_replace('"','\"',PrepareDate($value,"_$name",true,$PrepareDateOptions))."\",\"div$name\",true);dOr();Calendar.setup({
			        monthField     :    \"monthSelect".$_SYSTEM['DateInput']."\",
			        dayField       :    \"daySelect".$_SYSTEM['DateInput']."\",
			        yearField      :    \"yearSelect".$_SYSTEM['DateInput']."\",
			        ifFormat       :    \"%d-%b-%y\",
			        button         :    \"trigger".$_SYSTEM['DateInput']."\",
			        align          :    \"Tl\",
			        format         :    \"".$format."\",
			        singleClick    :    true
			        });'>$title <span class='clickable'>".(($value!='')?ProperDate($value):'-')."</span></div></DIV>";
			        
			        
		}
	}
	else
	{
		return "$title ".(($value!='')?ProperDate($value):'-')."";
	}
}
function TimejQueryInput($value,$name,$idi,$title='',$onchange='',$div=true)
{	global $_SYSTEM,$THIS_array, $border, $tabs, $forceFieldName;

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	if($border && in_array($name, $border))
	{
		$style = 'class = errorTextField style=width:200px';
	}

if($_SYSTEM['fielsNames']){
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}
}
	if($forceFieldName)
	{
		foreach($forceFieldName as $forceItem)
		{
			foreach ($forceItem as $fKey => $fValue)
			{
				if($fKey.'['.$fValue.']' == $name)
					if(array_key_exists($fValue, $_SESSION['_REQUEST_vars'][$fKey]))
					{
						$value = $_SESSION['_REQUEST_vars'][$fKey][$fValue];
						$div = false;
					}
			}
		}
	}

	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
		$value1 = is_array($value) ? $value[1] : $value;
		$value = is_array($value) ? $value[0] : $value;
		if(Preferences('LOGIN_DATE_FORMAT') == '12')
		{
		if(substr($value1,0,2)>12)
			$value1 = (substr($value1,0,2)-12).substr($value1,2);
		else
			$value1 = (substr($value1,0,2)*1).substr($value1,2);
		}

		$comment = '<!-- '.$value.'['.$name.']['.$idi.'] -->';

		if(((trim($value)=='' && $div!=='force') || $div==false))
		{
			$_SYSTEM['PrepareTime'][] = 'input'.$idi;
			$_SYSTEM['PrepareTimeonchange'][] = $onchange;
//			echo htmlspecialchars($comment."$title <INPUT type=text name=$name id=input$idi onchange=\"$onchange\" ".(($value || $value==='0')?"value=\"".str_replace('"','\"',$value)."\"":'')." size=4 ".str_replace('"','\"',$options)."></div>".(($title!='')?"":'')).'<BR><BR>';
			return $comment."$title <INPUT type=text name=$name id=input$idi onchange=\"$onchange\" ".(($value || $value==='0')?"value=\"".str_replace('"','\"',$value)."\"":'')." size=4 ".str_replace('"','\"',$options)."></div>".(($title!='')?"":'');
		}
		else
		{
			$_SYSTEM['TimeInput']++;
			//return $comment."<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".str_replace("'","&rsquo;",$title)."<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value))."\\\"":'')." ".str_replace('"','\"',$options)." size=4 ".str_replace('"','\"',$options)."><a href=# id=ctime_toggle".$_SYSTEM['TimeInput']."></a><div id=ctime_div".$_SYSTEM['TimeInput']." class=time_picker_div></div>".(($title!='')?"":'')."\",\"div$name\",true);document.getElementById(\"input$name\").value = replaceAll(document.getElementById(\"input$name\").value,\"``\",\"\\\"\");if(document.getElementById(\"GridScalex_layer\")) dOr(); var tp".$_SYSTEM['TimeInput']." = new TimePicker(\"ctime_div".$_SYSTEM['TimeInput']."\",\"input$name\",\"ctime_toggle".$_SYSTEM['TimeInput']."\",{format24:".((Preferences('LOGIN_DATE_FORMAT')=='12')?'false':'true').",onChange:function(){".$onchange.";}});document.getElementById(\"input$name\").focus();'>$title <span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
                        //return $comment."<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".str_replace("'","&rsquo;",$title)."<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value))."\\\"":'')." ".str_replace('"','\"',$options)." size=4 ".str_replace('"','\"',$options)."><a href=# id=ctime_toggle".$_SYSTEM['TimeInput']."></a><div id=ctime_div".$_SYSTEM['TimeInput']." class=time_picker_div></div>".(($title!='')?"":'')."\",\"div$name\",true);document.getElementById(\"input$name\").value = replaceAll(document.getElementById(\"input$name\").value,\"``\",\"\\\"\");if(document.getElementById(\"GridScalex_layer\")) dOr(); var tp".$_SYSTEM['TimeInput']." = new TimePicker(\"ctime_div".$_SYSTEM['TimeInput']."\",\"input$name\",\"ctime_toggle".$_SYSTEM['TimeInput']."\",{format24:".((Preferences('LOGIN_DATE_FORMAT')=='12')?'false':'true').",onChange:function(){".$onchange.";}});document.getElementById(\"input$name\").focus();'>$title <span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";

//    echo htmlspecialchars($comment."<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".str_replace("'","&rsquo;",$title).
//                    		    "<INPUT type=text id=input$idi name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value)).
//                    		    "\\\"":'')." ".str_replace('"','\"',$options)." onChange=\\\"".str_replace('"','\\"',$onchange)."\\\" size=8 ".str_replace('"','\"',$options).">".(($title!='')?"":'')."\",\"div$name\",true);jQuery(\"#input$idi\").mask(\"H9:M9".((Preferences('LOGIN_DATE_FORMAT') == '12')?'gTL':'')."\");jQuery(\"#input$idi\").focus();'>$title <span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>")."<BR><BR>";

                        /*ok*/return $comment."<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".str_replace("'","&rsquo;",$title).
                    		    "<INPUT type=text id=input$idi name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value)).
                    		    "\\\"":'')." ".str_replace('"','\"',$options)." onChange=\\\"".str_replace('"','\\"',$onchange)."\\\" size=8 ".">".
                    		    (($title!='')?"":'')."\",\"div$name\",true);jQuery(\"#input$idi\").mask(\"H9:M9".((Preferences('LOGIN_DATE_FORMAT') == '12')?'gTL':'').
                    		    "\");jQuery(\"#input$idi\").focus();'>$title <span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
                        //document.getElementById(\"input$idi\").value = replaceAll(document.getElementById(\"input$idi\").value,\"``\",\"\\\"\");if(document.getElementById(\"GridScalex_layer\")) dOr();document.getElementById(\"input$idi\").focus();
                        //return "<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".(($title!='')?"":'')."\",\"div$name\",true);>".$title ."<span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
                        
//                    		    "<INPUT type=text id=input$idi name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value)).
                        //                    		    "\\\"":'')." ".str_replace('"','\"',$options)." onChange=\\\"".str_replace('"','\\"',$onchange)."\\\" size=8 ".str_replace('"','\"',$options).">".
		}
	}
	else
		return "$title ".(((is_array($value)?$value[1]:$value)!='')?(is_array($value)?$value[1]:$value):'-').(($title!='')?"":'');
}

function TimeInput($value,$name,$title='',$onchange='',$div=true,$id=false)
{	global $_SYSTEM,$THIS_array, $border, $tabs, $forceFieldName;

        if(!$id)
            $id = $name;
	if(Preferences('HIDDEN')!='Y')
		$div = false;

	if(in_array($name, $border))
	{
		$style = 'class = errorTextField style=width:200px'; 
	}
		
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}
		
	if($forceFieldName)
	{
		foreach($forceFieldName as $forceItem)
		{
			foreach ($forceItem as $fKey => $fValue)
			{
				if($fKey.'['.$fValue.']' == $name)
					if(array_key_exists($fValue, $_SESSION['_REQUEST_vars'][$fKey]))
					{
						$value = $_SESSION['_REQUEST_vars'][$fKey][$fValue];
						$div = false;
					}
			}
		}
	}
	
	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
		$value1 = is_array($value) ? $value[1] : $value;
		$value = is_array($value) ? $value[0] : $value;
		if(Preferences('LOGIN_DATE_FORMAT') == '12')
		{
		if(substr($value1,0,2)>12)
			$value1 = (substr($value1,0,2)-12).substr($value1,2);
		else
			$value1 = (substr($value1,0,2)*1).substr($value1,2);
		}
		
		$comment = '<!-- '.$value.' -->';
		if(((trim($value)=='' && $div!=='force') || $div==false))
		{
			$_SYSTEM['PrepareTime'][] = 'input'.$name;
			$_SYSTEM['PrepareTimeonchange'][] = $onchange;
			return $comment."$title <INPUT type=text name=$name id=input$id ".(($value || $value==='0')?"value=\"".str_replace('"','\"',$value)."\"":'')." size=4 ".str_replace('"','\"',$options)."><a href=# id='time_toggle".count($_SYSTEM['PrepareTime'])."'></a><div id='time_div".count($_SYSTEM['PrepareTime'])."' class='time_picker_div'></div>".(($title!='')?"":'');
		}
		else
		{
			$_SYSTEM['TimeInput']++;
			//return $comment."<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".str_replace("'","&rsquo;",$title)."<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value))."\\\"":'')." ".str_replace('"','\"',$options)." size=4 ".str_replace('"','\"',$options)."><a href=# id=ctime_toggle".$_SYSTEM['TimeInput']."></a><div id=ctime_div".$_SYSTEM['TimeInput']." class=time_picker_div></div>".(($title!='')?"":'')."\",\"div$name\",true);document.getElementById(\"input$name\").value = replaceAll(document.getElementById(\"input$name\").value,\"``\",\"\\\"\");if(document.getElementById(\"GridScalex_layer\")) dOr(); var tp".$_SYSTEM['TimeInput']." = new TimePicker(\"ctime_div".$_SYSTEM['TimeInput']."\",\"input$name\",\"ctime_toggle".$_SYSTEM['TimeInput']."\",{format24:".((Preferences('LOGIN_DATE_FORMAT')=='12')?'false':'true').",onChange:function(){".$onchange.";}});document.getElementById(\"input$name\").focus();'>$title <span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
                        //return $comment."<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".str_replace("'","&rsquo;",$title)."<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value))."\\\"":'')." ".str_replace('"','\"',$options)." size=4 ".str_replace('"','\"',$options)."><a href=# id=ctime_toggle".$_SYSTEM['TimeInput']."></a><div id=ctime_div".$_SYSTEM['TimeInput']." class=time_picker_div></div>".(($title!='')?"":'')."\",\"div$name\",true);document.getElementById(\"input$name\").value = replaceAll(document.getElementById(\"input$name\").value,\"``\",\"\\\"\");if(document.getElementById(\"GridScalex_layer\")) dOr(); var tp".$_SYSTEM['TimeInput']." = new TimePicker(\"ctime_div".$_SYSTEM['TimeInput']."\",\"input$name\",\"ctime_toggle".$_SYSTEM['TimeInput']."\",{format24:".((Preferences('LOGIN_DATE_FORMAT')=='12')?'false':'true').",onChange:function(){".$onchange.";}});document.getElementById(\"input$name\").focus();'>$title <span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
                        return $comment."<DIV id='div$name'><div id='innerdiv$name' onclick='addHTML(\"".str_replace("'","&rsquo;",$title)."<INPUT type=text id=input$id name=$name ".(($value || $value==='0')?"value=\\\"".str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$value))."\\\"":'')." ".str_replace('"','\"',$options)." size=4 ".str_replace('"','\"',$options)."><a href=# id=ctime_toggle".$_SYSTEM['TimeInput']."></a><div id=ctime_div".$_SYSTEM['TimeInput']." class=time_picker_div></div>".(($title!='')?"":'')."\",\"div$name\",true);document.getElementById(\"input$name\").value = replaceAll(document.getElementById(\"input$name\").value,\"``\",\"\\\"\");if(document.getElementById(\"GridScalex_layer\")) dOr(); jQuery(\"#input$name\").mask(\"H9:M9\");document.getElementById(\"input$name\").focus();'>$title <span class='clickable' style='white-space: nowrap;'>".(($value!='')?$value1:'-').'</span>'.(($title!='')?"":'')."</div></DIV>";
		}
	}
	else
		return "$title ".(((is_array($value)?$value[1]:$value)!='')?(is_array($value)?$value[1]:$value):'-').(($title!='')?"":'');
}


function NoInput($value,$title='')
{
	return $title.'&nbsp;'.($value!=''?$value:'-').($title!=''?'':'');
}

function CheckBoxOnclick($name,$title)
{
	return '<INPUT type=checkbox name="'.str_replace('"','',$name).'" id="'.str_replace('"','',$name).'" value=Y'.($_REQUEST[str_replace('"','',$name)]=='Y'?" CHECKED onclick='document.location.href=\"".SetRequestOptions(null,array(str_replace('"','',$name)))."\";'":" onclick='document.location.href=\"".SetRequestOptions(null,array(str_replace('"','',$name)))."&amp;".str_replace('"','',$name)."=Y\";'").'><label for="'.str_replace('"','',$name).'">'.$title.'</label>';
}

function CheckBoxAjaxOnclick($name,$title,$onclick)
{
	return '<INPUT type=checkbox name="'.str_replace('"','',$name).'" id="'.str_replace('"','',$name).'" value=Y onclick="'.$onclick.'"><label for="'.str_replace('"','',$name).'">'.$title.'</label>';
}
function make_ajax_tos_radio($value,$inputname='',$name,$title='',$options='',$allow_na='',$addition='',$div=true,$translate=false,$id=false,$show_empty=false)
{   global $_SYSTEM, $border, $tabs;

        //var_dump($value,$name,$inputname,$title,$options,$allow_na,$addition,$div,$translate,$id,$show_empty);
	if(Preferences('HIDDEN')!='Y')
		$div = false;

	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}

	/*
 		used for displaying red border on the input field
	*/
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = "style = 'border: 3px solid #FF0000; outline: 3px solid #FF0000;'";

	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
		if(($value!='' || $div==='force') && $div)
			$return .= "<DIV id='div$inputname' ".(($show_empty==true)?" style='display:none;' ":"фыв")."><div onclick='addHTML(\"<INPUT type=hidden name=$name value=\\\"\\\">";
		$return .= '<TABLE border=0 cellpadding=3>';
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=run_rb_submit();":"";
                $onchange .= "if(document.getElementById('inputstudents[CFIELD_74]')){document.getElementById('inputstudents[CFIELD_74]')='Y';}";
		$i = 0;
                if($options)
                {
                    foreach($options as $id=>$option)
                    {
    			if($i%2==0)
    				$return .= '</TR><TR>';
                            if(($value!='' || $div==='force') && $div)
                                    {
                                            if($translate === false)
                                                    $return .= '<TD><INPUT type=radio test1 '.$style.' '.$onchange.' id='.$inputname.$id.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$id)).'\"'.(($value==$id)?' CHECKED':'').'><small><label for=\"'.$inputname.$id.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',get_tos_title($option))).'</label></small></TD>';
                                            else
                                                    $return .= '<TD><INPUT type=radio test2 '.$style.' '.$onchange.' id='.$inputname.$id.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',_($id))).'\"'.(($value==$id)?' CHECKED':'').'><small><label for=\"'.$inputname.$id.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',_(get_tos_title($option)))).'</label></small></TD>';

    //					$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value="'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$option)).'"'.'>';
                                    }
                            else
                            {
                                    if($translate === false)
                                            $return .= '<TD><INPUT type=radio test3 '.$style.' '.$onchange.' id='.$inputname.$id.' name='.$name.' value="'.$id.'"'.(($value==$id)?' CHECKED':'').'><small><label for="'.$inputname.$id.'">'.get_tos_title($option).'</label></small></TD>';
                                    else
                                            $return .= '<TD><INPUT type=radio test4 '.$style.' '.$onchange.' id='.$inputname.$id.' name='.$name.' value="'.$id.'"'.(($value==$id)?' CHECKED':'').'><small><label for="'.$inputname.$id.'">'._(get_tos_title($option)).'</label></small></TD>';

    //				$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value="'.$option.'">';
                            }
    //			$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value=\"'.$option.'\">';
                            $i++;
                    }
                }
		$return .= '</TR>';

		if($title)
		{
			$return .= '<TR><TD colspan=2>';
			if(($value!='' || $div==='force') && $div)
				$return .= '<TABLE width=100% height=7 style=\"border-width:1;border-style: none solid solid solid;\"><TR><TD></TD></TR></TABLE>';
			else
				$return .= '<TABLE width=100% height=7 style="border-width:1;border-style: none solid solid solid;"><TR><TD></TD></TR></TABLE>';
			$return .= '</TD></TR>';
		}

		$return .= '</TABLE>';

		if(($value!='' || $div==='force') && $div)
			$return .= "\",\"div$inputname"."\",true); openline(\"$id\");' ><span class='clickable'>".(($value!='')?get_tos_title($value):'-')."</span></div></DIV>";
	}
	else
		$return .= (($value!='')?get_tos_title($value):'');

	if($title)
		$return .= '<small><b>'.$title.'<b></small>';

	return $return;
}
function make_tos_radio($value,$name,$title='',$options='',$allow_na='',$addition='',$div=true, $translate=false)
{	global $_SYSTEM, $border, $tabs;

	if(Preferences('HIDDEN')!='Y')
		$div = false;

	if(!$_SYSTEM['fieldNames']) $_SYSTEM['fieldNames'] = array();
	foreach ($_SYSTEM['fieldNames'] as $fName)
	{
		if(array_key_exists($name, $_SYSTEM[$fName]) AND !$tabs)
		{
			$value = $_SYSTEM[$fName][$name];
			$div = false;
		}
	}

	/*
 		used for displaying red border on the input field
	*/
	if(!$border) $border = array();
	if(in_array($name, $border))
		$style = "style = 'border: 3px solid #FF0000; outline: 3px solid #FF0000;'";

	if(AllowEdit() && !$_REQUEST['CREATEPDF'])
	{
		if(($value!='' || $div==='force') && $div)
			$return .= "<DIV id='div$name'><div onclick='addHTML(\"<INPUT type=hidden name=$name value=\\\"\\\">";
		$return .= '<TABLE border=0 cellpadding=3 class="tablein">';
		$onchange = $_SYSTEM['set_js_onchange']?"onchange=\"run_rb_submit();\"":"onchange=\"";
//                $onchange = 'onchange=\'document.getElementById("inputstudents_faculty").value = "Y";\'';
                $onchange .= "document.getElementById('inputstudents_faculty').value='Y';\"";//if(document.getElementById('inputstudents_faculty')){.....}
		$i = 0;
		foreach($options as $id=>$option)
		{
			if($i%1==0)
				$return .= '</TR><TR>';
			if(($value!='' || $div==='force') && $div)
				{
					if($translate === false)
						$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$id.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$id)).'\"'.(($value==$id)?' CHECKED':'').'><small><label for=\"'.$name.$id.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',$option)).'</label></small></TD>';
					else
						$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$id.' name='.$name.' value=\"'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',_($id))).'\"'.(($value==$id)?' CHECKED':'').'><small><label for=\"'.$name.$id.'\">'.str_replace("'",'"+single_quote+"',str_replace('"','"+"\""+"',_($option))).'</label></small></TD>';

//					$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value="'.str_replace("'",'"+single_quote+"',str_replace('"','"+double_quote+"',$option)).'"'.'>';
				}
			else
			{
				if($translate === false)
					$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$id.' name='.$name.' value="'.$id.'"'.(($value==$id)?' CHECKED':'').'><small><label for="'.$name.$id.'">'.$option.'</label></small></TD>';
				else
					$return .= '<TD><INPUT type=radio '.$style.' '.$onchange.' id='.$name.$id.' name='.$name.' value="'.$id.'"'.(($value==$id)?' CHECKED':'').'><small><label for="'.$name.$id.'">'._($option).'</label></small></TD>';

//				$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value="'.$option.'">';
			}
//			$return .= '<INPUT type=hidden id='.$name.$option.'_hidden name='.$name.'_hidden value=\"'.$option.'\">';
			$i++;
		}
		$return .= '</TR>';

		if($title)
		{
			$return .= '<TR><TD colspan=2>';
			if(($value!='' || $div==='force') && $div)
				$return .= '<TABLE width=100% height=7 style=\"border-width:1;border-style: none solid solid solid;\"><TR><TD></TD></TR></TABLE>';
			else
				$return .= '<TABLE width=100% height=7 style="border-width:1;border-style: none solid solid solid;"><TR><TD></TD></TR></TABLE>';
			$return .= '</TD></TR>';
		}

		$return .= '</TABLE>';

		if(($value!='' || $div==='force') && $div)
			$return .= "\",\"div$name"."\",true);' ><span class='clickable'>".(($value!='')?$value:'-')."</span></div></DIV>";
	}
	else
		$return .= (($value!='')?$value:'');

	if($title)
		$return .= '<small><b>'.$title.'<b></small>';

	return $return;
}


?>