/home/mip/public_html_/old_mip/admin/func_select_codes.php
<?
/* List of functions that make select for the dates. */
 
  function datebox($name,$val,$formname,$month,$day,$year) {
	
		list ($year1, $month1, $day1) = @split ('[-]', $val);
								
		$code = "<input type=text name='$name' value='".convertToTextDate($val)."' size='11' maxlength='10' 
					 onFocus=\"javascript:vDateType='1'\" onKeyUp=\"DateFormat(this,this.value,event,false,'1')\" onBlur=\"DateFormat(this,this.value,event,true,'1')\" onchange=\"splitDate(this,this.value,document.$formname.$month,document.$formname.$day,document.$formname.$year)\">
					 <font size=1>(MM/DD/YYYY)</font>";
		$code.="<input type=hidden name='$month' value='$month1'>
					  <input type=hidden name='$day' value='$day1'>
					  <input type=hidden name='$year' value='$year1'>
						";			
		return $code;
		break;

}// end of function dateselect()


function dateselect($name,$date,$val,$from,$to,$noday=0) {
		switch ($date){

 		case "month" : 
				 				 	 if($val == '00') $val = '';  
				 				 	 $code = "<input type=text name='$name' value='$val' size=2 maxlength=2 onKeyUp=\"return autoTab(this, 2, event);\" onfocus='select()'>/";
   								 return $code;
									 break;

 		case "day"   : 
				 				 	 if($val == '00') $val = '';
									 $code = "<input type=text name='$name' value='$val' size=2 maxlength=2 onKeyUp=\"return autoTab(this, 2, event);\" onfocus='select()'>/";
							  	 return $code;
							  	 break;
								
 		case "year" :	
				 					 if($noday) $com = "(MM/YYYY)";
				 				   else$com = "(MM/DD/YYYY)";
									 if($val == '0000') $val = '';
				 				   $code = "<input type=text name='$name' value='$val' size=4 maxlength=4 onfocus='select()' > <font size=1>$com</font>";
									 return $code;
									 break;
	 }// end of switch statement
}// end of function dateselect()

  function dateselect1($name,$date,$val,$from,$to) {
  ?>
  <font size=1>
  <?
		switch ($date){

 		case "month" : $code = "<select name='$name'>";
				 				 	 $code.= "<option value=''>MM";
									 $months=array(1=>Jan,2=>Feb,3=>Mar,4=>April,5=>May,6=>June,7=>July,8=>Aug,9=>Sept,10=>Oct,11=>Nov,12=>Dec);
									 foreach ($months as $key => $value){
									     $key = str_pad($key, 2, "0", STR_PAD_LEFT);
									 		 if($val == "$key"){ $code.= "<option value='$key' selected>$value"; }
									 		 else $code.= "<option value='$key'>$value";
	 									}          
									 $code.= "</select>";  		 
   								 return $code;
									 break;

 		case "day"   : $code = "<select name='$name'>";
				 				 	 $code.= "<option value=''>DD";
									 for ($i=1; $i<=31; $i++){
									     $i = str_pad($i, 2, "0", STR_PAD_LEFT);
		  				  	 		 if($val == "$i"){ $code.= "<option value='$i' selected>$i"; }
									 		 else $code.= "<option value='$i'>$i";
	 						  		} 
   						  		$code.= "</select>";
							  		return $code;
							  		break;
								
 		case "year" :	$code = "<select name='$name'>";
				 					$code.= "<option value=''>YYYY";								
									
									$from_this_year = date("Y")-$from; // set the year with respect to the current year
									$to_this_year = date("Y")+ $to;
									
									if($val < $from_this_year && $val != 0){
									     $diff = $from_this_year - $val ;
									     $from_this_year = $from_this_year - $diff;
									}  
																		
   					 			for ($i=$to_this_year; $i>=$from_this_year; $i--){
	    								if($val == $i){ $code.= "<option value=$i selected>$i"; }
											else $code.= "<option value=$i>$i";
	 								}
	 								$code.= "</select>";
									return $code;
									break;
	 }// end of switch statement
	?> 
</font>	
<?
}// end of function dateselect()

// Function for the form select (array, the selected value, the field, the field where the description is)
function selectcode($array1,$val,$name1="",$name2="")
{   
		for ($i=1; $i<=count($array1); $i++)
		{
		  			
			$name1_val = $array1[$i]["$name1"];
			if($name1_val=="") $name1_val=0;
			if($val == $name1_val)
			{
			?> <option value='<?echo $name1_val?>' selected> <?echo $array1[$i]["$name2"]?> &nbsp; <?;
			}
			else
			{ 
			?> <option value='<?echo $name1_val?>'> <?echo $array1[$i]["$name2"]?> &nbsp; <?; 
			}
  	}							
}// end of function

// Function for the form select (array, the selected value, the field, the field where the description is)
// if the 1st key is 0
function selectcode1($array1,$val,$name1="",$name2="")
{   
		for ($i=0; $i<=count($array1); $i++)
		{
		  			
			$name1_val = $array1[$i]["$name1"];
			if($name1_val=="") $name1_val=0;
			if($val == $name1_val)
			{
			?> <option value='<?echo $name1_val?>' selected> <?echo $array1[$i]["$name2"]?> &nbsp; <?;
			}
			else
			{ 
			?> <option value='<?echo $name1_val?>'> <?echo $array1[$i]["$name2"]?> &nbsp; <?; 
			}
  	}							
}// end of function

function selectcode2($array1,$val)
{
		foreach($array1 as $value){
		       if($value==$val) echo "<option value='$value' selected>$value";
		    	 else echo "<option value='$value'>$value";
	  }
									
}// end of function

?>