<?php

/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );

  require('includes/application_top.php');

  $command=isset($HTTP_GET_VARS["command"])?$HTTP_GET_VARS["command"]:'';
  $options_key=isset($HTTP_GET_VARS["options_key"])?$HTTP_GET_VARS["options_key"]:'';
  switch($command){
  	case 'load_details':
	echo 'load_details^'.$options_key.'^';
	load_events_instructor_option_value($options_key);
	exit;
	break;
	case 'load_option_value_details':
	echo 'load_option_value_details^';
	$options_id=isset($HTTP_GET_VARS["options_id"])?$HTTP_GET_VARS["options_id"]:'';
	echo $options_id.'^'; $instructors_options_values_array=array();
	$instructors_options_values_query=tep_db_query("select options_values_id,options_values_text,options_values_display from ".TABLE_INSTRUCTORS_OPTIONS_VALUES." where options_values_id='$options_id'");
	if(tep_db_num_rows($instructors_options_values_query)>0){
	$instructors_options_values_array=tep_db_fetch_array($instructors_options_values_query);
	}	
	?>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="openContent1">
	<tr heigth="40" class="openContent_top" onClick="javascript:close_options_values('<?php echo $options_id;?>')">
	<td width="10" valign="top" align="center">&nbsp;</td>
	<td align="left" valign="middle" width="350" class="inner_title"><?php 
		if($instructors_options_values_array['options_values_display']=='Y'){
			$value_flag='N';
			$options_values_display=tep_image(DIR_WS_IMAGES.'template/icon_active.gif','','','','onClick="javascript:disable_values(\'' . $value_flag . '\',\''. $instructors_options_values_array['options_values_id'] . '\');"');
		} else {
			$value_flag='Y';
			$options_values_display=tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','','','','onClick="javascript:disable_values(\'' . $value_flag . '\',\''. $instructors_options_values_array['options_values_id'] . '\');"');	
		}	
			
	echo '<span id="options_values_name_' .$instructors_options_values_array['options_values_id'] .'" style="cursor:hand;cursor:pointer">'. $options_values_display.'</span>&nbsp;&nbsp;'.$instructors_options_values_array["options_values_text"]; ?></td>
	<td width="100" align="left" class="main" valign="top">
		<table border="0" id="header_operation" cellspacing="0" cellpadding="0" style="height:30px;display:inline;position:relative;">
		<tr class="img_move" id="img_ids">
		<td class="cell_bg_popm_left" width="10">&nbsp;</td>
		<td width="10%" style="cursor:pointer;" OnClick="javascript:do_hover_change1(this,1);void delete_option_value(<?php echo $options_id; ?>);" onMouseOver="javascript:do_hover_change1(this,2);" onMouseOut="javascript:do_hover_change1(this,3);"><img alt="Delete" border="0" title="Delete" src="images/template/img_trash.gif"></td>
		<td class="cell_bg_popm_right" width="10">&nbsp;</td>
		</tr>
		</table>
	</td>
	<td width="400" align="right" style="cursor:hand;cursor:pointer"><?php echo tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','onClick="javascript: edit_option_value_function('.$options_id.')"').'&nbsp;&nbsp;'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','onClick="javascript:void close_options_values('.$options_id.')"').'</a>&nbsp;'; ?></td>
	</tr>
	<tr>
		<td colspan="4">
		<table width="100%" border="0" cellpadding="5" cellspacing="5">
		<tr>
		<td width="50%" class="main" align="right"><?php echo TEXT_OPTION_VALUES; ?></td>
		<td width="50%"><?php echo tep_draw_input_field('instructors_options_values_name_' . $options_id,$instructors_options_values_array['options_values_text']); ?></td>
		</tr>
		<tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','10','10');?></td></tr>
		</table>
		</td>
	</tr>
	<div class="main" id="delete_instructor" style="display:none">&nbsp;</div>
	</table>
	<?php
	
	exit;
	break;
	case 'save_new_option_value':
	$options_key=isset($HTTP_GET_VARS['options_key'])?$HTTP_GET_VARS['options_key']:'';
	$new_options_values_name=isset($HTTP_GET_VARS['new_options_values_name'])?$HTTP_GET_VARS['new_options_values_name']:'';
	tep_db_query("insert into ".TABLE_INSTRUCTORS_OPTIONS_VALUES." (options_key,options_values_text) values('$options_key','$new_options_values_name') ");
	echo 'load_details^'.$options_key.'^';
	load_events_instructor_option_value($options_key);
	exit;
	break;
	case 'edit_option_value':
	$options_id=isset($HTTP_GET_VARS["options_id"])?$HTTP_GET_VARS["options_id"]:'';
	$instructors_options_values_name=isset($HTTP_GET_VARS["instructors_options_values_name"])?$HTTP_GET_VARS["instructors_options_values_name"]:'';	
	tep_db_query("update ".TABLE_INSTRUCTORS_OPTIONS_VALUES." set options_values_text='$instructors_options_values_name' where options_values_id='$options_id'");
	$option_key_query=tep_db_query("select options_key from ".TABLE_INSTRUCTORS_OPTIONS_VALUES." where options_values_id='$options_id'");
	$option_key_array=tep_db_fetch_array($option_key_query);
	echo 'load_details^'.$option_key_array["options_key"].'^';
	load_events_instructor_option_value($option_key_array["options_key"]);
	exit;
	break;
	case 'delete_option_value':
	$options_id=isset($HTTP_GET_VARS["options_id"])?$HTTP_GET_VARS["options_id"]:'';
	$query=tep_db_query("select o.options_id, ov.options_key from " . TABLE_INSTRUCTORS_OPTIONS_VALUES . " ov, " . TABLE_INSTRUCTORS_OPTIONS . " o where o.options_key=ov.options_key and options_values_id='" . $options_id . "'");
	$result=tep_db_fetch_array($query);
	
	$option_key_query=tep_db_query("select options_key from ".TABLE_INSTRUCTORS_OPTIONS_VALUES." where options_values_id='$options_id'");
	$option_key_array=tep_db_fetch_array($option_key_query);
	tep_db_query("delete from ".TABLE_INSTRUCTORS_OPTIONS_VALUES." where options_values_id='$options_id'");
	$oquery=tep_db_query("select * from " . TABLE_INSTRUCTORS_OPTIONS_VALUES . " where options_key='" . $result['options_key'] . "'");
	
	if(tep_db_num_rows($oquery)<=0){
		echo 'load_details^'.$result['options_key'].'^';
		load_events_instructor_option_value($result['options_key']);
	}	
	else 	
	echo 'delete_option_value^'.$options_id;
	exit;
	break;
	case 'save_option_details':
		if($options_key!='') {
		
			tep_db_query("update " . TABLE_INSTRUCTORS_OPTIONS ." set options_name='" . $HTTP_POST_VARS['txt_option_name_' . $options_key] . "' where options_key='" . $options_key . "'");
			$query=tep_db_query("select options_display from " . TABLE_INSTRUCTORS_OPTIONS . " where options_key='" . $options_key . "'");
			$result=tep_db_fetch_array($query);
			if($result['options_display']=='Y') {
				//$display='<a href="javascript:disable(\'' . $result['option_display'] .'\',\''. $options_key . '\');">' . tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;</a>';
				$display= tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_active.gif','','','','onClick="javascript:disable(\'' . $result['option_display'] .'\',\''. $options_key . '\');"').'&nbsp;';
			} else {
				//$display='<a href="javascript:disable(\'' . $result['option_display'] . '\',\''. $options_key . '\');">' .tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif').'&nbsp;</a>';
				$display=tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','','','','onClick="javascript:disable(\'' . $result['option_display'] . '\',\''. $options_key . '\');"').'&nbsp;';
			}
			echo 'edit_option_details^'.$options_key.'^' . $display . tep_draw_separator('pixel_trans.gif','10','10'). $HTTP_POST_VARS['txt_option_name_' . $options_key] . '^' .tep_draw_separator('pixel_trans.gif','10','10'). $HTTP_POST_VARS['txt_option_name_' . $options_key] . '^';
		} else  {
			$exists_query=tep_db_query("select options_key from " . TABLE_INSTRUCTORS_OPTIONS . " where options_key='" . tep_db_input($HTTP_POST_VARS['txt_new_option_key']) . "'");
			if(tep_db_num_rows($exists_query)>0)
				echo 'save_option_details^'.$options_key.'^error^';
			else {
				tep_db_query("insert into " . TABLE_INSTRUCTORS_OPTIONS . " (options_name,options_key) values('" . tep_db_input($HTTP_POST_VARS['txt_new_option']). "','" . tep_db_input($HTTP_POST_VARS['txt_new_option_key']) . "')");
			echo 'save_option_details^'.$options_key.'^' ;
			load_events_instructor_option();
			}
		}
				
		
		//load_events_instructor_option_value($options_key);
		exit; 
	break;
	case 'delete_option_details':
		$query=tep_db_query("select o.options_id, ov.options_key from " . TABLE_INSTRUCTORS_OPTIONS_VALUES . " ov, " . TABLE_INSTRUCTORS_OPTIONS . " o where o.options_key=ov.options_key and ov.options_key='" . $options_key . "'");
		if(tep_db_num_rows($query)>0)			
			echo 'delete_option_details^'.$options_key.'^' . 'This option has values linked to it - it is not safe to delete it.' ;
		else{ 
			tep_db_query("delete from " . TABLE_INSTRUCTORS_OPTIONS . " where options_key='" . $options_key . "'")	;
		echo 'delete_option_details^'. $options_key . '^';
		}	
			
	exit;
	break;
	case 'set_option_display':
		$flag=(isset($HTTP_GET_VARS['flag'])?$HTTP_GET_VARS['flag']:'');
		$query=tep_db_query("select options_name from " . TABLE_INSTRUCTORS_OPTIONS . " where options_key='" . $options_key . "'");
		$result=tep_db_fetch_array($query);
		tep_db_query("update " . TABLE_INSTRUCTORS_OPTIONS . " set options_display='" . $flag . "' where options_key='" . $options_key . "'");
		if($flag=='Y') {
			//$display='<a href="javascript:disable(\'' . $flag .'\',\''. $options_key . '\');">' . tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'</a>';
			$display=tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_active.gif','','','','onClick="javascript:disable(\'' . $flag .'\',\''. $options_key . '\');"');
		} else {
			//$display='<a href="javascript:disable(\'' . $flag . '\',\''. $options_key . '\');">' .tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif').'</a>';
			$display=tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','','','','onClick="javascript:disable(\'' . $flag . '\',\''. $options_key . '\');"');
		}	
		echo 'set_option_display^'. $options_key . '^' . $display . '^' . $display . tep_draw_separator('pixel_trans.gif','10','0') . $result['options_name'] . '^' ;
	exit;	
	break;
	case 'set_option_value_display':
		$flag=(isset($HTTP_GET_VARS['flag'])?$HTTP_GET_VARS['flag']:'');
		$options_id=(isset($HTTP_GET_VARS['options_id'])?$HTTP_GET_VARS['options_id']:'');
		tep_db_query("update " . TABLE_INSTRUCTORS_OPTIONS_VALUES . " set options_values_display='" . $flag . "' where options_values_id='" . $options_id . "'");
		if($flag=='Y') {
			//$display='<a href=javascript:disable_values(\'N\',\''. $options_id . '\')>' . tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;</a>';
			$display= tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_active.gif','','','','onClick="javascript:disable_values(\'N\',\''. $options_id . '\')"').'&nbsp;';
		} else {
			//$display='<a href=javascript:disable_values(\'Y\',\''. $options_id . '\')>' .tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif').'&nbsp;</a>';
			$display=tep_draw_separator('pixel_trans.gif','10','10'). tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','','','','onClick="javascript:disable_values(\'Y\',\''. $options_id . '\')"').'&nbsp;';
		}	
		echo 'set_option_value_display^'. $options_id . '^' . $display . '^';
	exit;	
	break;
  }
  
  tep_get_last_access_file();           
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->

<!-- Ajax Works Starts -->
<table width="100%" cellpadding="5" cellspacing="4" border="0">
<tr>
<td width="100%"><?php echo tep_draw_form('option',FILENAME_INSTRUCTORS_OPTIONS,'action=update_value','post','onSubmit="return validateUpdateForm(this)"'); ?>
	<table class="main" width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td class="dataTableHeadingRow"><a style="cursor:pointer;" id="img_new" onMouseOver="do_hover_change1(this,2);" onMouseOut="do_hover_change1(this,3);"  onClick="javascript:do_hover_change1(this,1);do_page_fetch();"><?php echo tep_image('images/template/img_new.gif','New Option','22','22');?></a>
			</td>
		</tr>	
		 <tr><td><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td></tr>
		 <tr class="dataTableHeadingRow">
			<td class="dataTableHeadingContent"><?php echo HEADING_OPTION_NAME; ?></td>
		  </tr>
		  <tr><td id="ajx_details">
			<?php load_events_instructor_option(); ?>
			</td></tr>
		<tr id="new_option_details" style="display:none">
			<td>
				<table cellpadding="3" cellspacing="0" border="0" width="100%" class="openContent">	
					<tr class="openContent_top">
						<td class="pageHeading"><?php echo 'New Option';?></td>
						<td align="right"><?php echo '<a href="javascript: save_option(\'\')">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a href="javascript:close_new_option(\'\')">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>&nbsp;'; ?></td>
					</tr>	
					<tr>
						<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','10','10');?></td>
					</tr>	
					<tr>
						<td colspan="2" align="center" id="exists" class="main" style="color:#FF0000"></td>
					</tr>	
					<tr>
						<td class="main" align="right"><?php echo TEXT_OPTION_NAME . '&nbsp;' . tep_draw_input_field('txt_new_option','');?></td>
						<td class="main"><?php echo TEXT_OPTION_KEY . tep_draw_input_field('txt_new_option_key','',' maxlength="2"');?></td>
					</tr>
					<tr>
						<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','10','10');?></td>
					</tr>	
				</table>
			</td>
		</tr>				
	</table>
</td></form>
</tr>
</table>


<div id="ajax_image_load" style="display:none;">
	<?php echo tep_image(DIR_WS_IMAGES.'24-1.gif'); ?>
</div>

<!-- Ajax Works Ends -->


<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var options_id_array; var previous_options_key='';
var previous_options_values_key='';
var options_values_id_array;
var ajx_started=false;
var row_expand=false;
var option_row_expand=false;
<?php
$events_instructors_options_query=tep_db_query("select options_id from ".TABLE_INSTRUCTORS_OPTIONS." order by options_name");
?>
var display_flag=1;

	function edit_option(id){
			if(ajx_started) return;
			row_expand=true;
		document.getElementById('data_option_' + id).style.display="";
		document.getElementById('img_save').style.display="";
		//document.getElementById('img_close').style.display="none";
		if(previous_options_values_key!=''){
			document.getElementById('options_values_'+previous_options_values_key).style.display="";
			document.getElementById('ajax_options_values_'+previous_options_values_key).style.display="none";
		}
		close_new_option_value();
		document.getElementById('new_option_details').style.display="none";
		//close_new_option_value();	
		document.getElementById('err_' + id).innerHTML='';
		document.getElementById('img_delete').firstChild.src=img_src+'template/img_trash.gif';
		
	}
	
	function close_option(){
		row_expand=true;
		if(document.getElementById('img_edit'))	document.getElementById('img_edit').firstChild.src=img_src+'template/img_edit.gif';

		if(document.getElementById('data_option_'+previous_options_key))
			 document.getElementById('data_option_'+previous_options_key).style.display="none" ;
		if(document.getElementById('img_save')){
			document.getElementById('img_save').style.display="none";
			//document.getElementById('img_close').style.display="";
		}	
	}
	function save_option(id){
	//	if(id!='')
	obj=document.getElementById('txt_new_option').value;
	obj1=document.getElementById('txt_new_option_key').value;
	var error_message='';
	row_expand=true;
	if(id==''){
		if(obj=='' || str_trim(obj)=='')
			error_message+='* <?php echo ERR_OPTION_VALUE;?>\n';
		if( obj1=='' || str_trim(obj1)=='')
			error_message+='* <?php echo ERR_KEY_VALUE;?>\n';
	} else {
	obj2=document.getElementById('txt_option_name_' + id).value;
		if(obj2=='' || str_trim(obj2)=='')
			error_message+='* <?php echo ERR_OPTION_VALUE;?>';
	}		
		if(error_message!='')	{
			alert(error_message);
		}else {
			var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=save_option_details&options_key='); ?>"+id;
		do_post_command('option',command);
		}
	}
	
	function close_new_option(){
		document.getElementById('txt_new_option_key').value="";
		document.getElementById('txt_new_option').value="";
		document.getElementById('new_option_details').style.display="none";
		document.getElementById('img_new').firstChild.src=img_src+'template/img_new.gif';
	}
	function delete_option(id){
		row_expand=true;
		document.getElementById('data_option_' + id).style.display="none";
		var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=delete_option_details&options_key='); ?>"+id;
		do_get_command(command);
	}
	function do_hover_change(element,eve){
		/*if (element.mode && mode==element.mode) return;
		//alert (mode);
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
		element.mode=mode;*/
		var span_edit=document.getElementById('data_option_' + previous_options_key);
		var span_err=document.getElementById('err_' + previous_options_key);
		
		 if(element){		   		    		    
		    var img_get_src=element.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_edit.gif') { 
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && (span_edit)  && (span_edit.style.display=="none")) img_get_src.src=img_src+'template/img_edit.gif';
				if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_err && span_err.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_err.innerHTML==''){
				 img_get_src.src=img_src+'template/img_trash.gif';
				} 
		  }
		 }		 
	}
	 function do_hover_change1(element,eve){ //alert(element);
	 
		 var span_delete=document.getElementById("delete_instructor");
		// var span_new = document.getElementById('new_option_value_content');
		 var span_new = document.getElementById('new_option_details');
		
		 if(element){		   		    		    
		    var img_get_src=element.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && (span_delete)  && (span_delete.style.display=="none")) img_get_src.src=img_src+'template/img_trash.gif';
				
				if(img_get_src.src==img_src+'template/img_new.gif') { 
					if(eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_new_hover.gif';
					}  			 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_new_hover.gif' && span_new && (span_new.style.display=="none") ) img_get_src.src=img_src+'template/img_new.gif';
		  }
		 }		 
	 }  	
	
	function do_page_fetch(){
		if(previous_options_key!=''){
		//	display_flag=0;
			new_option_value_function(previous_options_key);
		}
		else 	{
			document.getElementById('new_option_details').style.display="";
		}
			//alert('<?php echo TEXT_SELECT_OPTION;?>');
	}
	function event_row_focus(options_key){
			if(ajx_started) return;
			else ajx_started=true;
			
		if(previous_options_key!='') {
			document.getElementById('events_options_'+previous_options_key).style.display="";
			document.getElementById('ajax_events_options_'+previous_options_key).style.display="none";
			document.getElementById('ajax_events_options_'+previous_options_key).innerHTML='';
			close_option();
		}	
		document.getElementById('new_option_details').style.display="none";	
		previous_options_values_key='';
		row_expand=false;
		option_row_expand=false;
		document.getElementById('ajax_events_options_'+options_key).style.display='';
		document.getElementById('ajax_events_options_'+options_key).innerHTML=document.getElementById('ajax_image_load').innerHTML;
		var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=load_details&options_key='); ?>"+options_key;
		previous_options_key=options_key;
		do_get_command(command);
	}
	function option_value_focus(options_id){ 
			if(ajx_started) return;
			else ajx_started=true;
			close_option();
			document.getElementById('new_option_details').style.display="none";
		if(previous_options_values_key!=''){
			document.getElementById('ajax_options_values_'+previous_options_values_key).style.display="none";
			document.getElementById('options_values_'+previous_options_values_key).style.display="";
		}
		
	document.getElementById('ajax_options_values_'+options_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;
	document.getElementById('ajax_options_values_'+options_id).style.display='';
	previous_options_values_key=options_id; 
	row_expand=false;
	option_row_expand=false;
	var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=load_option_value_details&options_id='); ?>"+options_id;
	do_get_command(command);
			document.getElementById('new_option_value_content').style.display='none';
	}
	function close_options_values(options_id){
	if(option_row_expand==false){
		document.getElementById('ajax_options_values_'+options_id).innerHTML='';
		document.getElementById('ajax_options_values_'+options_id).style.display='none';
		document.getElementById('options_values_'+options_id).style.display='';
	}option_row_expand=false;
	}
	function close_new_option_value(){
	document.getElementById('new_option_value_content').style.display='none';
	//document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
	document.getElementById('img_new').firstChild.src=img_src+'template/img_new.gif';
	//display_flag=1;
	}
	function close_panel(key){
		if(document.getElementById('ajax_events_options_'+key).style.display=='' && document.getElementById('ajax_events_options_'+key).innerHTML!='' && row_expand==false){
			document.getElementById('events_options_'+key).style.display="";
			document.getElementById('ajax_events_options_'+key).style.display="none";
			document.getElementById('ajax_events_options_'+key).innerHTML='';
			document.getElementById('img_new').firstChild.src=img_src+'template/img_new.gif';
			previous_options_key='';
		}
		
		row_expand=false;
	}
	function new_option_value_function(options_id){ 
	if(document.getElementById('ajax_options_values_'+options_id))
		close_options_values(options_id);
	if(previous_options_values_key!='')
			close_options_values(previous_options_values_key);
	close_option();	
	row_expand=false;
	document.getElementById('new_option_details').style.display="none";
	document.getElementById('new_option_value_content').style.display='';
	document.getElementById('new_options_values_name').value='';
	previous_options_values_key='';
	//document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
	document.getElementById('img_new').firstChild.src=img_src+'template/img_new_hover.gif';
		//display_flag=1;
	}
	function save_new_option_value(options_key){
	var new_options_values_name=document.getElementById('new_options_values_name').value;
		if(new_options_values_name=='')
			alert('<?php echo TEXT_ERR_NULL_VALUE_INSERT; ?>');
		else {
		
		var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=save_new_option_value&options_key='); ?>"+options_key+'&new_options_values_name='+new_options_values_name;
		do_get_command(command);
		}
	}
	function edit_option_value_function(options_id){
	var instructors_options_values_name=document.getElementById('instructors_options_values_name_' + options_id).value;
		if(instructors_options_values_name=='')
			alert('<?php echo TEXT_ERR_NULL_VALUE_UPDATE; ?>');
		else{
		var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=edit_option_value&options_id='); ?>"+options_id+'&instructors_options_values_name='+instructors_options_values_name;
		do_get_command(command);
		}
	}
	function delete_option_value(options_id){
	document.getElementById('delete_instructor').style.display='';
	previous_options_values_key='';
	var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=delete_option_value&options_id='); ?>"+options_id;
	do_get_command(command);
	}
	
	function disable(flag,options_id){
		row_expand=true;
		if(flag=='Y')
			flag='N';
		else 
			flag='Y'	;
		var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=set_option_display&options_key='); ?>"+options_id + '&flag=' + flag;
		do_get_command(command);
	}
	
	function disable_values(flag,options_id){
		option_row_expand=true;
		var command="<?php echo tep_href_link(FILENAME_INSTRUCTORS_OPTIONS,'command=set_option_value_display&options_id='); ?>"+options_id + '&flag=' + flag;
		do_get_command(command);
	}

	function do_result(result){ 
	var token=result.split('^');
	var options_key=token[1];
	switch(token[0]){
		case 'load_details': 
		document.getElementById('img_new').firstChild.src=img_src+'template/img_new.gif';
		document.getElementById('ajax_events_options_'+options_key).innerHTML=token[2];
		document.getElementById('events_options_'+options_key).style.display='none';
		document.getElementById('new_option_value_content').style.display='none';
		
		break;
		case 'load_option_value_details':
		var options_id=token[1]; 
		if(document.getElementById('err_' + previous_options_key)) document.getElementById('err_' + previous_options_key).innerHTML='';
		document.getElementById('options_values_'+options_id).style.display='none';
		document.getElementById('ajax_options_values_'+options_id).innerHTML=token[2];
		break;
		case 'delete_option_value':
		var options_id=token[1];
		document.getElementById('options_values_'+options_id).style.display='none';
		document.getElementById('ajax_options_values_'+options_id).style.display="none";
		var row_index=document.getElementById('tr_options_values_'+options_id).rowIndex;
		document.getElementById('options_values_table').deleteRow(row_index);
		break;
		case 'edit_option_details':
			var options_id=token[1];
			document.getElementById('events_options_' + token[1]).innerHTML= token[2];
			document.getElementById('option_name').innerHTML= token[3];
			document.getElementById('data_option_'+token[1]).style.display="none" ;
			document.getElementById('img_save').style.display="none" ;
			//document.getElementById('img_close').style.display="";
			document.getElementById('img_edit').firstChild.src=img_src+'template/img_edit.gif';
		break;
		case 'save_option_details':
			if(token[2]=='error'){
				document.getElementById('exists').innerHTML='<?php echo TEXT_EXISTS_OPTIONS_KEY;?>';
			} else {
			document.getElementById('ajx_details').innerHTML=token[2];
			document.getElementById('txt_new_option_key').value='';
			document.getElementById('txt_new_option').value='';
			document.getElementById('new_option_details').style.display="none";
			document.getElementById('img_new').firstChild.src=img_src+'template/img_new.gif';
			//document.getElementById('img_edit').firstChild.src=img_src+'template/img_edit.gif';
			}
		break;
		case 'delete_option_details':
			if(token[2]!='')	{
				document.getElementById('err_'+ token[1]).style.display="";
				document.getElementById('err_' + token[1]).innerHTML='<font color="#ff0000" class="main" >' + token[2] + "</font>";
				document.getElementById('img_edit').firstChild.src=img_src+'template/img_edit.gif';
			}else {	
				
				/*document.getElementById('events_options_' + token[1]).style.display="none";
				document.getElementById('ajax_events_options_' + token[1]).style.display="none";
				var row_index=document.getElementById('tr_options_values_'+token[1]).rowIndex;*/
				document.getElementById('options_details').deleteRow(document.getElementById('events_options_' + token[1]).parentNode.parentNode.rowIndex);
				previous_options_values_key='';
				previous_options_key='';
				//document.getElementById('options_details').deleteRow(row_index);
			}	
		break;	
	    case 'set_option_display':	
			document.getElementById('option_display_' + token[1]).innerHTML=token[2];
			document.getElementById('events_options_' + token[1]).innerHTML= token[3];
		break;
	    case 'set_option_value_display':
			document.getElementById('options_values_name_' + token[1]).innerHTML=token[2];
		break;
		
	}
	ajx_started=false;
	}
</script>
<?php 
	function load_events_instructor_option(){
	$row=0; $class_name="";
	$events_instructors_options_query=tep_db_query("select options_id,options_name,options_key, options_display from ".TABLE_INSTRUCTORS_OPTIONS." order by options_name");
	echo '<table cellpadding="0" cellspacing="0" border="0" width="100%" id="options_details">';
	while($events_instructors_options_array=tep_db_fetch_array($events_instructors_options_query)){
	 $class_name=($row%2==0)?'dataTableRowEven' :'dataTableRowOdd'; $row++;

?>
	<tr  class="<?php echo $class_name; ?>" height="25">
	<td>
	<div   onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" class="<?php echo $class_name; ?>"  id="events_options_<?php echo $events_instructors_options_array["options_key"]; ?>"  onClick="javascript: event_row_focus('<?php echo $events_instructors_options_array["options_key"]; ?>');">
	<?php 
	if($events_instructors_options_array['options_display'] =='Y')
		$options_display=tep_image(DIR_WS_IMAGES.'template/icon_active.gif');
	else 
		$options_display=tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif');	
	echo tep_draw_separator('pixel_trans.gif','10','10').$options_display.'&nbsp;&nbsp;'.$events_instructors_options_array["options_name"]; ?>
	</div>
	<div id="ajax_events_options_<?php echo $events_instructors_options_array["options_key"]; ?>" style="display:none;">
	</div>
	</td>
	</tr>
	
<?php 
	}
	echo '</table>';
	}
?>
<?php 
	function load_events_instructor_option_value($options_key){
	$instructors_options_query=tep_db_query("select options_id,options_name,options_key,options_display from ".TABLE_INSTRUCTORS_OPTIONS ." where options_key='$options_key'");
	$instructors_options_array=tep_db_fetch_array($instructors_options_query);
	$options_name=$instructors_options_array['options_name'];
	$instructors_options_values_query=tep_db_query("select * from ".TABLE_INSTRUCTORS_OPTIONS_VALUES." where options_key='$options_key'");
	
  ?>
  	<table width="100%" cellpadding="0" cellspacing="0" id="options_values_table" border="0" class="openContent">
	<tr class="openContent_top" onClick="javascript:close_panel('<?php echo $options_key;?>');">
	<td class="main" width="350"><?php 
		if($instructors_options_array['options_display'] =='Y')
			$display=tep_image(DIR_WS_IMAGES.'template/icon_active.gif','','','','onClick="javascript:disable(\'' . $instructors_options_array['options_display'] . '\',\'' . $instructors_options_array['options_key'] . '\');"');
		else 
			$display=tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','','','','onClick="javascript:disable(\'' . $instructors_options_array['options_display'] . '\',\'' . $instructors_options_array['options_key'] . '\');"')	;
			
	echo tep_draw_separator('pixel_trans.gif','10','10');?><span id="option_display_<?php echo $instructors_options_array['options_key']?>" class="main" style="cursor:hand; cursor:pointer"><?php echo $display ;?></span><span id="option_name"> <?php echo tep_draw_separator('pixel_trans.gif','10','10');?><?php echo $options_name; ?></span></td>
	<td width="350" align="left" class="main" valign="top">
	<?php // if(tep_db_num_rows($instructors_options_values_query)<=0){?>
			<table border="0" id="header_operation" cellspacing="0" cellpadding="0" style="width:50px;height:30px;display:inline;position:relative;">
			<tr class="img_move" id="img_ids">
			<td class="cell_bg_popm_left" width="10">&nbsp;</td>
			<td width="10%" id="img_edit" style="cursor:pointer;" OnClick="javascript:do_hover_change(this,1);edit_option('<?php echo $options_key; ?>');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Edit" border="0" title="Edit" src="images/template/img_edit.gif"></td>
			<td width="10%" id="img_delete" style="cursor:pointer;" OnClick="javascript:do_hover_change(this,1);delete_option('<?php echo $options_key; ?>');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Delete" border="0" title="Delete" src="images/template/img_trash.gif"></td>
			<td class="cell_bg_popm_right" width="10">&nbsp;</td>
			</tr>
			</table>
	<?php //} ?>	
	</td>
	<td  align="right" width="70">
	<span id="img_save" style="display:none;width:100; cursor:pointer;cursor:hand"><?php echo tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','onClick="javascript: save_option(\''.$options_key .'\')"').'&nbsp;&nbsp;'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','onClick="javascript:close_option(\''.$options_key.'\')"').'&nbsp;'; ?></span>
		<!--<span id="img_close" style="display:block"><?php //echo '<a href="javascript:close_panel(\''.$options_key.'\')">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>';?></span>-->

	</td>
	</tr>
	
	<tr id="data_option_<?php echo $options_key;?>" style="display:none" >
		<td colspan="3">
			<table cellpadding="2" cellspacing="2" border="0" width="80%" align="center">
				<tr>
					<td class="main"><?php echo TEXT_OPTION_KEY . '&nbsp;' . $options_key;?> </td>
					<td class="main"><?php echo TEXT_OPTION_NAME . '&nbsp;' . tep_draw_input_field('txt_option_name_' . $options_key,$options_name);?></td>
				</tr>
				
			</table>
		</td>
	</tr>
	<tr><td colspan="3"><div id="err_<?php echo $options_key;?>" class="main" align="center"></div></td></tr>					
	<tr><td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif','10','10');?></td></tr>
	<?php $cnt=0; while($instructors_options_values_array=tep_db_fetch_array($instructors_options_values_query)){ 
	 $class_name=($cnt%2==0)?'dataTableRowEven' :'dataTableRowOdd'; $cnt++;
	?>
	<tr id="tr_options_values_<?php echo $instructors_options_values_array["options_values_id"]; ?>">
	<td colspan="3">
		<table width="100%" class="main" cellpadding="0" cellspacing="0" border="0">
		<tr >
		<td width="100">&nbsp;</td>
		<td  class="dataTableRowOdd">
		<div onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" class="dataTableRowOdd" onClick="javascript: option_value_focus(<?php echo $instructors_options_values_array["options_values_id"]; ?>);" id="options_values_<?php echo $instructors_options_values_array["options_values_id"]; ?>">
		<?php 
			if($instructors_options_values_array['options_values_display']=='Y')
				$options_values_display=tep_image(DIR_WS_IMAGES.'template/icon_active.gif');
			else 
				$options_values_display=tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif');	
		echo $options_values_display.$instructors_options_values_array["options_values_text"]; ?>
		</div>
		<div id="ajax_options_values_<?php echo $instructors_options_values_array["options_values_id"]; ?>">
		</div>
		</td>
		</tr>
		</table>
	</td>
	</tr>
	<tr><td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif','10','10');?></td></tr>
	<?php }  ?>
	<tr><td colspan="3">
	<div id="new_option_value_content" style="display:none;">
	<table width="100%" class="main" cellpadding="0" cellspacing="0" border="0" >
	<tr >
		<td width="100">&nbsp;</td>
		<td width="150"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif'); ?>&nbsp;New Option Value</td>
		<td align="right"><?php echo '<a href="javascript: save_new_option_value(\''.$options_key.'\');">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save').'</a>&nbsp;&nbsp;<a href="javascript: close_new_option_value();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close').'</a>&nbsp;'; ?></td>
	</tr>
	<tr>
		<td colspan="3" align="center"><?php echo TEXT_OPTION_VALUES.'&nbsp;&nbsp;'.tep_draw_input_field('new_options_values_name'); ?></td>
	</tr>
	<tr><td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif','10','10');?></td></tr>
	</table>
</div>
	</td></tr>
		<tr><td><?php echo tep_draw_separator('pixel_trans.gif','20','20');?></td></tr>
	</table>

<?php
	}
?>