<?php
/*
  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from Zac
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');
  require('includes/classes/split_page_results_event.php');
  $command=isset($HTTP_GET_VARS["command"])?$HTTP_GET_VARS["command"]:'';
  $option_id=isset($HTTP_GET_VARS["option_id"])?$HTTP_GET_VARS["option_id"]:'';
  $opt_id=isset($HTTP_GET_VARS["opt_id"])?$HTTP_GET_VARS["opt_id"]:'';
  $page=isset($HTTP_GET_VARS["page"])?$HTTP_GET_VARS["page"]:1;
  $services_attributes_id=isset($HTTP_GET_VARS["attributes_id"])?$HTTP_GET_VARS["attributes_id"]:'';
  $languages = tep_get_languages();
  switch($command){
  	case 'post_save_service_option':
		echo 'post_save_service_option^';
		$services_options_id=0; $services_options_sort_order=0;
		$services_options_id_query=tep_db_query("select max(services_options_id) as services_options_id, max(services_options_sort_order) as services_options_sort_order from ".TABLE_SERVICES_OPTIONS);
		if(tep_db_num_rows($services_options_id_query)>0){
			$services_options_id_array=tep_db_fetch_array($services_options_id_query);
			$services_options_id=$services_options_id_array["services_options_id"];
			$services_options_sort_order=$services_options_id_array["services_options_sort_order"]; $services_options_sort_order++;
		}
		$option_name_array=isset($HTTP_POST_VARS['option_name'])?$HTTP_POST_VARS['option_name']:'';
		
		$services_options_id++;

		for($i=0,$n=sizeof($languages);$i<$n;$i++){
		$new_languages_id=$languages[$i]['id'];
		$new_services_options_name=tep_db_prepare_input($HTTP_POST_VARS['option_name'][$new_languages_id]);
		tep_db_query("insert into ".TABLE_SERVICES_OPTIONS."(services_options_id,language_id,services_options_name,services_options_sort_order) values('$services_options_id','$new_languages_id','$new_services_options_name','$services_options_sort_order')");
		$services_options_sort_order++;
		}
	
		echo '<div style="color:#FF0000;" id="attrib_delete_flag"></div>';
		echo services_option_list();
		exit;
  	case 'page_navigation_option':
  		echo 'page_navigation_option^';
  		services_option_list();
  		exit;
  	break;
  	case 'page_navigation_attribute':
  		echo 'page_navigation_attribute^';
  		services_attributes_load_function();
  		exit;
  	break;
  	case 'load_details':
		echo 'load_details^';
		echo $option_id.'^';
	$services_options_name="";
	$attributes_query=tep_db_query("select services_options_name,services_options_sort_order from ".TABLE_SERVICES_OPTIONS." where services_options_id='$option_id' and language_id='$languages_id'");
	if(tep_db_num_rows($attributes_query)>0){
		$attributes_array=tep_db_fetch_array($attributes_query);
		$services_options_name=$attributes_array["services_options_name"];
		$services_options_sort_order=$attributes_array['services_options_sort_order'];
	}
	$services_options_values_query=tep_db_query("select sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." sov, ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS . " sovo where sov.language_id='$languages_id' and sovo.services_options_id='$option_id' and sov.services_options_values_id=sovo.services_options_values_id order by services_options_values_name");
	$function_name="";
	if(tep_db_num_rows($services_options_values_query)>0)
		$function_name=" new_service_option($option_id); ";
	else 
		$function_name=" new_service_option_value($option_id); ";
	?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="openContent">
	<tr class="openContent_top">
		<td class="main"><?php echo tep_image(DIR_WS_IMAGES . "template/icon_active.gif").'&nbsp;&nbsp;<a href="javascript: move_updown(\'services_option_row_\','.$option_id .',\'up\','.$services_options_sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_up.gif",'Up').'</a>&nbsp;&nbsp;'
			.'<a href="javascript: move_updown(\'services_option_row_\','.$option_id.',\'down\','.$services_options_sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_down.gif",'Down').'</a>&nbsp;&nbsp;'.$services_options_name; ?></td>			
		<td  width="100" align="center">
			<table style="background:#DEE4F5;cursor:pointer;" width="100%" border="0" cellpadding="0" id="header_operation_id" cellspacing="0">
				<tr id="img_ids">
					<td class="cell_bg_popm_left" width="10%"></td>
					<?php echo '<td width="10%" onClick="javascript:do_hover_change3(this,1); void attributes_edit();" onMouseOver="javascript:do_hover_change3(this,2);" onMouseOut="javascript:do_hover_change3(this,3);"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>'; ?>
					<?php echo '<td width="10%" onClick="javascript:do_hover_change3(this,1); drop_services_options(' . $option_id . ');" onMouseOver="javascript:do_hover_change3(this,2);" onMouseOut="javascript:do_hover_change3(this,3);"><img alt="Delete" title="Delete" src="images/template/img_trash.gif"></td>'; ?>
					<td class="cell_bg_popm_right" width="10%"></td>
			    </tr>
			</table>
		</td>	
		<td width="50%"  align="right"><?php echo '<a id="header_edit_display" style="display:none;" href="javascript: save_services_options('.$option_id.')">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>'.'&nbsp;&nbsp;<a href="javascript: base_service_option_close('.$option_id.');">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?>&nbsp;</td>
		<td id="header_delete_display" style="display:none" width="550" align="left">&nbsp;</td> 
	</tr>
	<tr id="edit_details_id" style="display:none;">
	<td colspan="3" class="main" align="center"><table border="0" cellpadding="1" cellspacing="1"><tr height="10"></tr><tr class="main"><td colspan="3" class="main" align="center"><?php 
	echo tep_draw_form('save_edit_option_name_form',FILENAME_SERVICES_ATTRIBUTES,'','post');
			for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
			$services_options_name='';
			$services_options_name_query=tep_db_query('select services_options_name from '.TABLE_SERVICES_OPTIONS." where services_options_id='$option_id' and language_id='".(int)$languages[$i]['id']."'");
				if(tep_db_num_rows($services_options_name_query)>0){
				$services_options_name_array=tep_db_fetch_array($services_options_name_query);
				$services_options_name=$services_options_name_array['services_options_name'];
				}			
       		echo $languages[$i]['code'].'&nbsp;&nbsp;'.tep_draw_input_field("services_option_name[" . $languages[$i]['id'] . "]",$services_options_name).'<br><br>';
      		}
	echo '</form>' ;
	//echo TABLE_HEADING_OPT_NAME.'&nbsp;&nbsp;'.tep_draw_input_field('services_options_name_'.$option_id,$services_options_name); ?>
	</td></tr></table></td>
	</tr>
	<div class="main" id="delete_option_att" style="display:none">&nbsp;</div>
	<tr><td colspan="3" class="main"><table width="100%" cellpadding="5" cellspacing="5" border="0"> 
	<tr><td width="150">&nbsp;</td> <td id="option_value_details_content">
	<?php $row=1; $class_name="";
	while($services_options_values_array=tep_db_fetch_array($services_options_values_query)){ 
		if($row%2==0) $class_name='subdataTableRowEven'; else $class_name='subdataTableRowOdd';
	?>
	<div class="main"  id="opt_row_<?php echo $services_options_values_array["services_options_values_id"]; ?>" onClick="javascript:opt_row_focus(<?php echo $services_options_values_array["services_options_values_id"]; ?>);">
	<div class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="opt_<?php echo $services_options_values_array["services_options_values_id"]; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$services_options_values_array["services_options_values_name"]; ?></div>
	</div>
	<div id="ajax_opt_row_<?php echo $services_options_values_array["services_options_values_id"]; ?>">
	<div id="ajax_opt_<?php echo $services_options_values_array["services_options_values_id"]; ?>" style="display:none;"></div>
	</div>
	<?php } ?>  </td></tr> <tr> <td>&nbsp;</td>
	<td>
	<div id="new_service_option_value_content" style="display:none;">
  <form name="save_new_option_value_form" method="post"> 
	<table width="100%" cellpadding="2" cellspacing="2" border="0">
	<tr>
		<Td class="main" width="200"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;New Service Option Value';	?></Td>
	    <td align="right"><?php echo '<a href="javascript:void save_new_service_option_value(' . $option_id .');">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a href="javascript: close_new_service_option_value();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?></td>
	</tr>
	<tr>
		<td colspan="2" class="main" align="center">
<?php //echo TABLE_HEADING_OPT_VALUE.tep_draw_input_field('new_service_option_name_value'); 
	//echo tep_draw_form('save_new_option_value_form',FILENAME_SERVICES_ATTRIBUTES,'','post');
		for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
		echo $languages[$i]['code'].'&nbsp;&nbsp;'.tep_draw_input_field("new_services_option_value[" . $languages[$i]['id'] . "]").'<br><br>';
		}
	?></td></tr>
	</table></form>
	</div>
	</td></tr>  </table>
	</td></tr>
	</table>
	<?php
	
		exit;
		break;
	 case 'save_option_name': 
	 	echo 'save_option_name^';
			for($i=0,$n=sizeof($languages);$i<$n;$i++){ 
			$language_id=$languages[$i]['id'];
			$services_options_name=tep_db_prepare_input($HTTP_POST_VARS['services_option_name'][$language_id]);

			$chk_qry=tep_db_query('select count(*) as total from '.TABLE_SERVICES_OPTIONS." where language_id='$language_id' and services_options_id='$option_id'");
			$chk_array=tep_db_fetch_array($chk_qry);			
				if($chk_array['total']>0)
			   		tep_db_query("update ".TABLE_SERVICES_OPTIONS." set services_options_name='$services_options_name' where language_id='$language_id' and services_options_id='$option_id'");
				else
					tep_db_query("insert into ".TABLE_SERVICES_OPTIONS." (services_options_id,language_id,services_options_name) values('$option_id','$language_id','$services_options_name')");
			}
		$default_services_option_query=tep_db_query('select services_options_name from '.TABLE_SERVICES_OPTIONS." where services_options_id='$option_id' and language_id='$languages_id'");
		$default_services_option_array=tep_db_fetch_array($default_services_option_query);
		$services_options_name=$default_services_option_array['services_options_name'];
		
		echo $option_id.'^';
		echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$services_options_name;
		exit;
		break;
	case 'drop_services_options':
		$services_options_values_query=tep_db_query("select sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." sov, ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS . " sovo where sovo.services_options_id='$option_id' and sov.services_options_values_id=sovo.services_options_values_id order by services_options_values_name");
		if(tep_db_num_rows($services_options_values_query)<=0){
			echo 'drop_services_options^';
			echo $option_id.'^';
			tep_db_query("delete from ".TABLE_SERVICES_OPTIONS." where language_id='$languages_id' and services_options_id='$option_id'");
		} else {
			echo 'drop_fail_services_options^';
			echo $option_id;
		}
		exit;
		break;
	case 'opt_load_details':
		echo 'load_opt_details^';
		echo $opt_id.'^'; $services_options_values_name=''; $services_options_values_id="";
		$services_options_query=tep_db_query("select services_options_values_id,services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." where language_id='$languages_id' and services_options_values_id='$opt_id'");
		if(tep_db_num_rows($services_options_query)>0)
			$services_options_array=tep_db_fetch_array($services_options_query);
		$services_options_values_name=$services_options_array["services_options_values_name"];
		$services_options_values_id=$services_options_array["services_options_values_id"];
	?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="openContent">
	<tr style="background:#DEE4F5;">
	<td colspan="3" class="main"><?php echo tep_image(DIR_WS_IMAGES . "template/icon_active.gif").'&nbsp;&nbsp;'.$services_options_values_name; ?></td>
	</tr>
	<tr>
	<td width="365">&nbsp;</td>
	<td align="center">
	<table width="100%" border="0" style="background:#DEE4F5;cursor:pointer;" cellpadding="0" cellspacing="0">
	<tr id="img_ids">
	<td  class="cell_bg_popm_left" width="10"></td>
	<?php echo '<td width="10%" onclick="javascript:do_hover_change4(this,1); drop_opt_services_options(' . $opt_id . ');" onMouseOver="javascript:do_hover_change4(this,2);" onMouseOut="javascript:do_hover_change4(this,3);"><img alt="Delete" title="Delete" src="images/template/img_trash.gif"></td>';?>
	<td  class="cell_bg_popm_right" width="10"></td> 
	</tr> 
	</table>
	</td>
	<td width="365" align="right"><?php echo '<a href="javascript: save_opt_services_options('.$opt_id.')">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;<a href="javascript:close_option_value('.$opt_id.')">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?></td>
	</tr>
	<tr>
	<td colspan="3" class="main" align="center">
	<?php 
	echo tep_draw_form('save_edit_option_value_form',FILENAME_SERVICES_ATTRIBUTES,'','post');
			for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
			$services_options_values_name='';
			$services_options_values_name_query=tep_db_query('select services_options_values_name from '.TABLE_SERVICES_OPTIONS_VALUES." where services_options_values_id='$opt_id' and language_id='".(int)$languages[$i]['id']."'");
				if(tep_db_num_rows($services_options_values_name_query)>0){
				$services_options_values_name_array=tep_db_fetch_array($services_options_values_name_query);
				$services_options_values_name=$services_options_values_name_array['services_options_values_name'];
				}			
       		echo $languages[$i]['code'].'&nbsp;&nbsp;'.tep_draw_input_field("services_options_values_name[" . $languages[$i]['id'] . "]",$services_options_values_name).'<br><br>';
      		}
	echo '</form>';
	
	//echo TABLE_HEADING_OPT_VALUE.'&nbsp;&nbsp;'.tep_draw_input_field('services_options_values_name_'.$opt_id,$services_options_values_name); 
	?>
	</td>
	</tr>
	<tr>
	<td colspan="3"><br></td>
	</tr>
	<div class="main" id="drop_service_option" style="display:none">&nbsp;</div>
	</table>
	<?php
		exit;
		break;
	case 'save_opt_values':
		echo 'save_opt_values^';
		echo $opt_id.'^';

		 for($i=0,$n=sizeof($languages);$i<$n;$i++){
		 $language_id=$languages[$i]['id'];
		 $services_options_values_name=tep_db_prepare_input($HTTP_POST_VARS['services_options_values_name'][$language_id]);
		$chk_query=tep_db_query('select count(*) as total from '.TABLE_SERVICES_OPTIONS_VALUES." where services_options_values_id='$opt_id' and language_id='$language_id'");
		$chk_array=tep_db_fetch_array($chk_query);
		if($chk_array['total']>0)	 
		 	tep_db_query("update ".TABLE_SERVICES_OPTIONS_VALUES." set services_options_values_name='$services_options_values_name' where language_id='$language_id' and services_options_values_id='$opt_id'");
		else
			tep_db_query("insert into ".TABLE_SERVICES_OPTIONS_VALUES." (services_options_values_id,services_options_values_name,language_id) values('$opt_id','$services_options_values_name','$language_id')");
		 }
		 
		 $services_options_values_name='';
		$default_query=tep_db_query('select services_options_values_name from '.TABLE_SERVICES_OPTIONS_VALUES." where services_options_values_id='$opt_id' and language_id='$languages_id' ");
			if(tep_db_num_rows($default_query)>0){
			$default_array=tep_db_fetch_array($default_query);
			$services_options_values_name=$default_array['services_options_values_name'];
			}
		
		echo '<div onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" class="subdataTableRowOdd" id="opt_'.$opt_id.'">'. tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'. $services_options_values_name.'</div>';
		exit;
		break;
	case 'save_new_service_option':
		echo 'save_new_service_option^';
		$new_service_option_name=isset($HTTP_GET_VARS["new_service_option_name"])?$HTTP_GET_VARS["new_service_option_name"]:'';
		$services_options_id=0; $services_options_sort_order=0;
		$services_options_id_query=tep_db_query("select max(services_options_id) as services_options_id, max(services_options_sort_order) as services_options_sort_order from ".TABLE_SERVICES_OPTIONS);
			if(tep_db_num_rows($services_options_id_query)>0){
			$services_options_id_array=tep_db_fetch_array($services_options_id_query);
			$services_options_id=$services_options_id_array["services_options_id"];
			$services_options_sort_order=$services_options_id_array["services_options_sort_order"]; $services_options_sort_order++;
			}
		$services_options_id++;
		tep_db_query("insert into ".TABLE_SERVICES_OPTIONS."(services_options_id,language_id,services_options_name,services_options_sort_order) values('$services_options_id','$languages_id','$new_service_option_name','$services_options_sort_order')");
		exit;
		break;
	 case 'save_new_service_option_value':
	 	echo 'save_new_service_option_value^'; 
	 	//$new_service_option_name_value=isset($HTTP_GET_VARS["new_service_option_name_value"])?tep_db_prepare_input($HTTP_GET_VARS["new_service_option_name_value"]):'';
		$new_service_option_value=isset($HTTP_POST_VARS['new_services_option_value'])?$HTTP_POST_VARS['new_services_option_value']:'';
		$opt_id=isset($HTTP_GET_VARS['opt_id'])?$HTTP_GET_VARS['opt_id']:'';
		$services_options_values_query=tep_db_query("select max(services_options_values_id) as services_options_values_id from ".TABLE_SERVICES_OPTIONS_VALUES);
		$services_options_values_array=tep_db_fetch_array($services_options_values_query);
		$services_options_values_id=$services_options_values_array["services_options_values_id"]; 
		$services_options_values_id++;
		/*for($i=1,$len=sizeof($new_service_option_value);$i<=$len;$i++){		
		$new_service_option_name_value=tep_db_prepare_input($new_service_option_value[$i]);
		tep_db_query("insert into ".TABLE_SERVICES_OPTIONS_VALUES."(services_options_values_id,language_id,services_options_values_name) values('$services_options_values_id','$i','$new_service_option_name_value') ");
		}*/
		for($i=0,$n=sizeof($languages);$i<$n;$i++){
		$language_id=$languages[$i]['id'];
		$new_service_option_name_value=tep_db_prepare_input($HTTP_POST_VARS['new_services_option_value'][$language_id]);
		tep_db_query("insert into ".TABLE_SERVICES_OPTIONS_VALUES."(services_options_values_id,language_id,services_options_values_name) values('$services_options_values_id','$language_id','$new_service_option_name_value') ");
		}
		tep_db_query("insert into ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS."(services_options_id,services_options_values_id) values('$opt_id','$services_options_values_id')");

		$services_options_values_query=tep_db_query("select sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." sov, ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS . " sovo where sovo.services_options_id='$opt_id' and sov.services_options_values_id=sovo.services_options_values_id and sov.language_id='$languages_id' order by services_options_values_name");
		?>
		
		<?php while($services_options_values_array=tep_db_fetch_array($services_options_values_query)){ ?>
		<div class="main" id="opt_row_<?php echo $services_options_values_array["services_options_values_id"]; ?>" onClick="javascript:opt_row_focus(<?php echo $services_options_values_array["services_options_values_id"]; ?>);">
		<div class="dataTableRowOdd" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="opt_<?php echo $services_options_values_array["services_options_values_id"]; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$services_options_values_array["services_options_values_name"]; ?></div>
		</div>
		<div id="ajax_opt_row_<?php echo $services_options_values_array["services_options_values_id"]; ?>">
		<div id="ajax_opt_<?php echo $services_options_values_array["services_options_values_id"]; ?>" style="display:none;"></div>
		</div>
		<?php } ?>
		<?php
		echo '^'.$services_options_values_id;

	 	exit;
		break;
	 case 'drop_service_option_value':
	 	 //$opt_id
			/*$services_option_query=tep_db_query("select services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." where services_options_values_id='$opt_id'");
			$services_option_array=tep_db_fetch_array($services_option_query);
			echo $services_option_array["services_options_values_name"];*/
		$chk_query=tep_db_query("select count(*) as total from ".TABLE_SERVICES_ATTRIBUTES." where options_values_id='$opt_id'");
		$chk_array=tep_db_fetch_array($chk_query);
			if($chk_array["total"]<=0){
			echo 'drop_service_option_value^';
			tep_db_query("delete from ".TABLE_SERVICES_OPTIONS_VALUES." where services_options_values_id='$opt_id'");
			tep_db_query("delete from ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS." where services_options_values_id='$opt_id'");
			}
			else {
			echo 'drop_fail_service_option_value^';
			}
		echo $opt_id;
	 	exit;
		break;
	 case 'load_services_attributes':
	 	echo 'load_Services_attributes^'; echo $services_attributes_id.'^';
		$services_attributes_query=tep_db_query("select sd.service_name,so.services_options_name,sov.services_options_values_name,sa.options_values_price,sa.price_prefix,sa.service_id,sa.options_id,sa.options_values_id,sa.services_options_sort_order from ".TABLE_SERVICES_DESCRIPTION." sd, ".TABLE_SERVICES_ATTRIBUTES." sa, " .
		TABLE_SERVICES_OPTIONS . " so, " . TABLE_SERVICES_OPTIONS_VALUES ." sov " .			
		" where sd.service_id=sa.service_id and sa.services_attributes_id='$services_attributes_id' and so.services_options_id=sa.options_id and sov.services_options_values_id=sa.options_values_id");
		$services_attributes_array=tep_db_fetch_array($services_attributes_query);
		//echo $services_attributes_array["service_name"].'^'.$services_attributes_array["services_options_name"].'^'.
		$services_attributes_array["services_options_values_name"];
		$service_id=$services_attributes_array["service_id"];
		$options_id=$services_attributes_array["options_id"];
		$options_values_id=$services_attributes_array["options_values_id"];
		$price_prefix=$services_attributes_array["price_prefix"];
		$options_values_price=$services_attributes_array["options_values_price"];
		$services_options_sort_order=$services_attributes_array["services_options_sort_order"];
	?>
	<div style="vertical-align:top">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="openContent_top">
		<tr>
			<td class="main" colspan="4"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;<a href="javascript: move_updown(\'service_attribute_value_\','. $services_attributes_id .',\'up\','.$services_options_sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_up.gif",'Up').
			'</a>&nbsp;&nbsp;<a href="javascript: move_updown(\'service_attribute_value_\','.$services_attributes_id.',\'down\','.$services_options_sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_down.gif",'Down').'</a>&nbsp;&nbsp;'.$services_attributes_array["service_name"]; ?></td>
			<td width="80">
			<table width="100%" style="cursor:pointer;background: rgb(222, 228, 245) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td class="cell_bg_popm_left" width="10%">&nbsp;</td>
				<?php echo  '<td width="10%" OnClick="javascript: do_hover_change2(this,1); void edit_service_attributes('.$services_attributes_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>';?>
				<?php echo	'<td width="10%" OnClick="javascript: do_hover_change2(this,1); drop_service_attribute('.$services_attributes_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);"><img alt="Delete" title="Delete" src="images/template/img_trash.gif"></td>';?>
				<td class="cell_bg_popm_right" width="10%">&nbsp;</td>
			</tr>
			</table>
			</td>
		</td>
			<td width="530" align="right"><?php echo '<a id="save_service_attributes_button" style="display:none;" href="javascript:void save_service_attributes('.$services_attributes_id .')">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a href="javascript: close_service_attribute('.$services_attributes_id.');">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?></td>
		</tr>
		</table>
	</div>
	<div id="display_details" class="openContent">
		<table width="100%" border="0" cellpadding="2" cellspacing="2">
		<tr>
		<td class="TableHeading" align="right" width="100"><?php echo TABLE_HEADING_SERVICES; ?> :</td>
		<td width="140" align="left" class="main"><?php echo $services_attributes_array["service_name"]; ?></td>
		<td width="120" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_NAME; ?> :</td>
		<td width="120" class="main" align="left"><?php echo $services_attributes_array["services_options_name"]; ?></td>
		<td width="120" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_VALUE; ?> :</td>
		<td class="main" align="left"><?php echo $services_attributes_array["services_options_values_name"]; ?></td>
		</tr>
		
		<tr>
		<td align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_PRICE; ?> :</td>
		<td class="main" align="left"><?php echo $services_attributes_array["options_values_price"]; ?></td>
		<td align="right" class="TableHeading"><?php echo TEXT_PREFIX; ?> :</td>
		<td class="main" align="left"><?php echo $services_attributes_array["price_prefix"]; ?></td>
		<td colspan="2">&nbsp;</td>
		</tr>
		<tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></td></tr>
		</table>
	</div>
	<div id="edit_details" style="display:none;">
	<?php 
	$service_description_query=tep_db_query("select service_id,service_name from ".TABLE_SERVICES_DESCRIPTION." where language_id='$languages_id' order by service_name");
	$services_options_query=tep_db_query("select services_options_id,services_options_name from ".TABLE_SERVICES_OPTIONS." where language_id='$languages_id' order by services_options_name");
	$services_options_values_query=tep_db_query("select sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." sov, ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS . " sovo where sov.language_id='$languages_id' and sov.services_options_values_id=sovo.services_options_values_id and sovo.services_options_id='$options_id' order by services_options_values_name");
	?>

		<table width="100%" border="0" cellpadding="5" cellspacing="0" class="openContent">
		<tr>
		<td class="TableHeading" align="right" width="100"><?php echo TABLE_HEADING_SERVICES; ?></td>
		<td width="100" align="left" class="main">&nbsp;
		<select id="service_id" name="service_id" style="width:100px;">
		<?php while($service_description_array=tep_db_fetch_array($service_description_query)){ ?>
		<option value="<?php echo $service_description_array["service_id"]; ?>"<?php if($service_id==$service_description_array["service_id"]) echo ' selected '; ?>><?php echo $service_description_array["service_name"]; ?></option>
		<?php } ?>
		</select>
		</td>
		<td width="120" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_NAME; ?></td>
		<td width="100" class="main" align="left">&nbsp;
		<select id="option_id" name="option_id" style="width:100px;" onChange="javascript: load_option_id(this);">
		<?php while($services_options_array=tep_db_fetch_array($services_options_query)){ ?>
		<option value="<?php echo $services_options_array["services_options_id"]; ?>"<?php if($options_id==$services_options_array["services_options_id"]) echo ' selected '; ?>><?php echo $services_options_array["services_options_name"]; ?></option>
		<?php } ?>
		</select>
		</td>
		<td width="100" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_VALUE; ?></td>
		<td width="80" class="main" align="left" id="load_option_id_td">&nbsp;
		<select id="option_id_value" name="option_id_value" style="width:100px;">
		<?php while($services_options_values_array=tep_db_fetch_array($services_options_values_query)){ ?>
		<option value="<?php echo $services_options_values_array["services_options_values_id"]; ?>"<?php if($options_values_id==$services_options_values_array["services_options_values_id"]) echo ' selected '; ?>><?php echo $services_options_values_array["services_options_values_name"]; ?></option>
		<?php } ?>
		</select>
		</td>
		</tr>
		<tr>
		<Td align="right" class="TableHeading"><?php echo TEXT_PRICE; ?></Td>
		<td class="main" align="left"><?php echo tep_draw_input_field('options_values_price',$options_values_price); ?></td>
		<td align="right" class="TableHeading"><?php echo TEXT_PREFIX; ?></td>
		<td align="left"><?php echo tep_draw_input_field('price_prefix',$price_prefix); ?></td>
		<td align="right" class="TableHeading">&nbsp;</td>
		<td align="left">&nbsp;</td>
		</tr>
		<tr><td colspan="6">&nbsp;</td></tr>
		</table>

	</div>
			<div class="cell_bg_popm_right" style="display:none" id="delete_details">&nbsp;</div>
	<?php	
		exit;
		break;
	 case 'save_service_attributes':
	 	echo 'save_service_attributes^';
	 	$services_attributes_id=isset($HTTP_GET_VARS["services_attributes_id"])?$HTTP_GET_VARS["services_attributes_id"]:'';
	 	$service_id=isset($HTTP_GET_VARS["service_id"])?$HTTP_GET_VARS["service_id"]:'';
		$option_id=isset($HTTP_GET_VARS["option_id"])?$HTTP_GET_VARS["option_id"]:'';
		$option_id_value=isset($HTTP_GET_VARS["option_id_value"])?$HTTP_GET_VARS["option_id_value"]:'';
		$options_values_price=isset($HTTP_GET_VARS["options_values_price"])?$HTTP_GET_VARS["options_values_price"]:'';
		$price_prefix=isset($HTTP_GET_VARS["price_prefix"])?$HTTP_GET_VARS["price_prefix"]:'';
			if($price_prefix=='plus') $price_prefix="+"; else $price_prefix="-";

	 	tep_db_query("update ".TABLE_SERVICES_ATTRIBUTES." set service_id='$service_id',options_id='$option_id',options_values_id='$option_id_value',options_values_price='$options_values_price',price_prefix='$price_prefix' where services_attributes_id='$services_attributes_id'");
			services_attributes_load_function();
		exit;
		break;
	case 'new_service_attribute':
		echo 'new_service_attribute^';
		$service_id=(int)isset($HTTP_GET_VARS["service_id"])?$HTTP_GET_VARS["service_id"]:'';
		$option_id=(int)isset($HTTP_GET_VARS["option_id"])?$HTTP_GET_VARS["option_id"]:'';
		$values_id=(int)isset($HTTP_GET_VARS["values_id"])?$HTTP_GET_VARS["values_id"]:'';
		$options_values_price=($HTTP_GET_VARS["options_values_price"])?$HTTP_GET_VARS["options_values_price"]:'0';
		$price_prefix=isset($HTTP_GET_VARS["price_prefix"])?$HTTP_GET_VARS["price_prefix"]:'';
			if($price_prefix=='plus') $price_prefix='+'; else $price_prefix='-';
		$services_options_sort_order=($HTTP_GET_VARS["services_options_sort_order"])?$HTTP_GET_VARS["services_options_sort_order"]:'0';
		tep_db_query("insert into ".TABLE_SERVICES_ATTRIBUTES." (service_id,options_id,options_values_id,options_values_price,price_prefix,services_options_sort_order) values(
		'$service_id','$option_id','$values_id','$options_values_price','$price_prefix','$services_options_sort_order') ");
		$services_attributes_id=tep_db_insert_id();
			services_attributes_load_function();
		echo '^'.$services_attributes_id;
		exit;
		break;
	case 'sort_service_option';
		echo 'sort_service_option^';
		$option_id=isset($HTTP_GET_VARS["option_id"])?$HTTP_GET_VARS["option_id"]:'';
		$sort_order=isset($HTTP_GET_VARS["sort_order"])?$HTTP_GET_VARS["sort_order"]:'';
		$type=isset($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type']:'';
			if($type=='up') $sort_order++; else $sort_order--;
		tep_db_query("update ".TABLE_SERVICES_OPTIONS." set services_options_sort_order='$sort_order' where services_options_id='$option_id'");
		exit;
		break;
	case 'sort_service_option_value':
		echo 'sort_service_option_value^';
		$service_attribute_id=isset($HTTP_GET_VARS["service_attribute_id"])?$HTTP_GET_VARS["service_attribute_id"]:'';
		$sort_order=isset($HTTP_GET_VARS["sort_order"])?$HTTP_GET_VARS["sort_order"]:'';
		$type=isset($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type']:'';
			if($type=='up')
				$sort_order++; else $sort_order--;
		tep_db_query("update ".TABLE_SERVICES_ATTRIBUTES." set services_options_sort_order='$sort_order' where services_attributes_id='$service_attribute_id'");
		exit;
		break;
	case 'load_option':
		echo 'load_option^';
		$options_id=isset($HTTP_GET_VARS["options_id"])?$HTTP_GET_VARS["options_id"]:'';
		$option_value_query=tep_db_query("select sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." sov, ". TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS ." sovo where sov.language_id='$languages_id' and sov.services_options_values_id=sovo.services_options_values_id and sovo.services_options_id='$options_id'");
		echo '<select id="option_id_value">';
		while($option_value_array=tep_db_fetch_array($option_value_query)){
			echo '<option value="'.$option_value_array["services_options_values_id"].'">'.$option_value_array["services_options_values_name"].'</option>';
		}
		echo '</select>';
		exit;
		break;
	case 'load_new_option_value':
		echo 'load_new_option_value^';
		$options_id=isset($HTTP_GET_VARS["options_id"])?$HTTP_GET_VARS["options_id"]:'';
		$option_value_query=tep_db_query("select sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." sov, ". TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS ." sovo where sov.language_id='$languages_id' and sov.services_options_values_id=sovo.services_options_values_id and sovo.services_options_id='$options_id'");
		echo '<select name="values_id" style="width:120px;" id="values_id">';
		while($option_value_array=tep_db_fetch_array($option_value_query)){
			echo '<option value="'.$option_value_array["services_options_values_id"].'">'.$option_value_array["services_options_values_name"].'</option>';
		}
		echo '</select>';
		exit;
		break;
	case 'drop_service_attribute':
		echo 'drop_service_attribute^';
		$attribute_id=isset($HTTP_GET_VARS["attribute_id"])?$HTTP_GET_VARS["attribute_id"]:'';
		tep_db_query("delete from ".TABLE_SERVICES_ATTRIBUTES." where services_attributes_id='$attribute_id'");
		echo $attribute_id;
		exit;
	case 'load_new_service_attribute_content':
	echo 'load_new_service_attribute_content^';
	$service_description_query=tep_db_query("select service_id,service_name from ".TABLE_SERVICES_DESCRIPTION." order by service_name");
	$services_options_query=tep_db_query("select services_options_id,services_options_name from ".TABLE_SERVICES_OPTIONS." order by services_options_name");
	?>
	<form name="attributes">
		<table width="100%" border="0" cellpadding="5" cellspacing="0" align="center" class="openContent">
		<tr>
		<td class="main" colspan="6"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;New Services Attributes'; ?></td>
		</tr>
		<tr>
			<td align="right" colspan="6"><?php echo '<a href="javascript: save_new_service_attribute();">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a href="javascript: close_new_service_attribute();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?></td>
		</tr>
		<tr>
		<td class="TableHeading" align="right" width="100"><?php echo TABLE_HEADING_SERVICES; ?> :</td>
		<td width="100" align="left" class="main">
		<select id="service_id" name="service_id" style="width:120px;">
		<?php while($service_description_array=tep_db_fetch_array($service_description_query)){ ?>
		<option value="<?php echo $service_description_array["service_id"]; ?>"><?php echo $service_description_array["service_name"]; ?></option>
		<?php } ?>
		</select>
		</td>
		<td width="120" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_NAME; ?> :</td>
		<td width="80" class="main" align="left">
		
		
	  <select name="options_id" id="option_id" style="width:120px;" onChange="javascript: load_new_option_value(this);">
	  <?php
      $options = tep_db_query("select * from " . TABLE_SERVICES_OPTIONS . " where language_id = '" . $languages_id . "' order by services_options_name");
      while($options_values = tep_db_fetch_array($options)) {
        if ($attributes_values['options_id'] == $options_values['services_options_id']) {
          echo "\n" . '<option name="' . $options_values['services_options_name'] . '" value="' . $options_values['services_options_id'] . '" SELECTED>' . $options_values['services_options_name'] . '</option>';
        } else {
          echo "\n" . '<option name="' . $options_values['services_options_name'] . '" value="' . $options_values['services_options_id'] . '">' . $options_values['services_options_name'] . '</option>';
        }
      } 
		?>
        </select>
		
		</td>
		<td width="100" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_VALUE; ?></td>
		<td width="100" class="main" id="load_new_option_value_id" align="left">
<?php
	$default_options_id=0;
	$default_options = tep_db_query("select * from " . TABLE_SERVICES_OPTIONS . " where language_id = '" . $languages_id . "' order by services_options_name");
	if(tep_db_num_rows($default_options)>0){
	$default_array=tep_db_fetch_array($default_options);
	$default_options_id=$default_array['services_options_id'];
	}
	if($default_options_id!=0){
			$option_value_query=tep_db_query("select pov.services_options_values_id,pov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." pov, ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS." povo where pov.services_options_values_id=povo.services_options_values_id and povo.services_options_id='$default_options_id' and pov.language_id='$languages_id'");
	}
?>			
		
		<select name="values_id" style="width:120px;" id="values_id">
		<?php if($default_options_id!=0){ while($option_value_array=tep_db_fetch_array($option_value_query)) {  ?>
		<option value="<?php echo $option_value_array["services_options_values_id"]; ?>"><?php echo $option_value_array["services_options_values_name"]; ?></option>
		<?php } } else { ?>
	        <OPTION selected value=""></OPTION>
		<?php } ?>
            </select>
		
		</td>
		</tr>
		<tr>
		<Td align="right" class="TableHeading"><?php echo TEXT_PRICE; ?></Td>
		<td class="main" align="left"><?php echo tep_draw_input_field('options_values_price'); ?></td>
		<td align="right" class="TableHeading"><?php echo TEXT_PREFIX; ?></td>
		<td align="left"><?php echo tep_draw_input_field('price_prefix'); ?></td>
		<td align="right" class="TableHeading">&nbsp;</td>
		<td align="left">&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		</tr>
		<tr><td colspan="6"><br></td></tr>
		</table>
	</form>
	<?php
		exit;
  }
	
  tep_get_last_access_file();                                              
  $languages = tep_get_languages();
?>
<!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/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript" src="includes/menu.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- Ajax Work Starts -->
<table border="0" width="100%" cellpadding="2" cellspacing="3">
<tr class="dataTableHeadingRow">
	<td width="100%"><?php echo HEADING_TITLE_OPT; ?></td>
</tr>
<tr>
	<td><table cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr class="dataTableHeadingRow">
			<td><?php echo '<a id="base_header_new_operation" onMouseOver="do_hover_change1(this,2)" onMouseOut="do_hover_change1(this,1);"  href="javascript: new_service_option();">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','New','22','22',' align=absmiddle').'</a>'; ?></td>
		</tr>
	</table></td>		
</tr>
<tr>
<td id="service_option_list">
<div style="color:#FF0000;" id="attrib_delete_flag"></div>
	<?php echo services_option_list();?>	
</td>
</tr>
<tr>
<td>
	<div id="new_service_option_content" style="display:none;" class="openContent">
	<table width="100%" cellpadding="2" cellspacing="2" border="0">
	<tr class="openContent_top">
		<td class="main"><?php echo tep_draw_form('save_service_option_form',FILENAME_SERVICE_ATTRIBUTES,'','post').tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;New Service Option';	?></td>
		<td align="right"><?php echo '<a  id="header_new_operation" href="javascript:void save_new_service_option();">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a href="javascript: close_new_service_option();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?></td>
	</tr>
	<tr><td colspan="2" align="center">
	<?php 
		for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
       echo $languages[$i]['code'].'&nbsp;&nbsp;'.tep_draw_input_field("option_name[" . $languages[$i]['id'] . "]").'<br>';
      }
	?>
	<?php //echo TABLE_HEADING_OPT_NAME.tep_draw_input_field('new_service_option_name'); ?></td></tr>
	<tr><td colspan="2"><br></form></td></tr>
	</table>
	</div>
	

<?php
	$services_options_values_query=tep_db_query("select services_options_values_id,services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." order by services_options_values_name");
	
?>

</tr>
	<tr><td id="services_attributes_load_id">
	<?php services_attributes_load_function(); ?>
</td></tr>
</table>

	<div id="new_service_attribute_content" style="display:none;">
	</div>
<!-- Ajax Works Ends -->


<div id="ajax_image_load" style="display:none;"><img src="images/24-1.gif" border="0"></div>
<!-- body_text_eof //-->
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
	<script language="javascript">
	<?php 
	$services_option_query=tep_db_query("select services_options_id from ".TABLE_SERVICES_OPTIONS." order by services_options_sort_order "); 
	$services_options_value_query=tep_db_query("select services_options_values_id from ".TABLE_SERVICES_OPTIONS_VALUES." order by services_options_values_id");
	$services_attributes_query=tep_db_query("select services_attributes_id from ".TABLE_SERVICES_ATTRIBUTES." order by services_attributes_id");
	?>
	var option_id_array=new Array();
	var option_id_value_array=new Array();
	var services_attributes_id_array=new Array();
	<?php $cnt=0; while($services_option_array=tep_db_fetch_array($services_option_query)){ ?>	
	option_id_array[<?php echo $cnt; ?>]=<?php echo $services_option_array["services_options_id"]; ?>;
	<?php $cnt++; } ?>

	<?php $icnt=0; while($services_options_value_array=tep_db_fetch_array($services_options_value_query)){ ?>
	option_id_value_array[<?php echo $icnt; ?>]=<?php echo $services_options_value_array["services_options_values_id"]; ?>;
	<?php $icnt++; } ?>
	<?php $cnt=0; while($services_attributes_array=tep_db_fetch_array($services_attributes_query)){ ?>
	services_attributes_id_array[<?php echo $cnt; ?>]=<?php echo $services_attributes_array["services_attributes_id"]; ?>;
	<?php $cnt++; } ?>
	</script>
<script language="javascript">
function get_installed_count(table){
					var icnt;
					var n;
					for (icnt=0,n=table.rows.length;icnt<n;icnt++){
						if (table.rows[icnt].cur_position=="inactive") break;
					}
					return icnt;
				}
function move_updown(prefix,option_id,type,sort_order){ 
					var row=document.getElementById(prefix+option_id);
					var index=row.rowIndex;
					var count=get_installed_count(row.parentNode);
					if (count<=1) return;
					if (type=="up" && index==0) return;
					if (type=="down" && index==count-1) return;

					if (type=="up"){
						row.parentNode.insertBefore(row,row.parentNode.rows[index-1]);
					} else {
						if (index==row.parentNode.rows.length-2)
							row.parentNode.appendChild(row);
						else
							row.parentNode.insertBefore(row,row.parentNode.rows[index+2]);
					}
	if(prefix=='service_attribute_value_'){
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=sort_service_option_value&service_attribute_id='); ?>"+option_id+'&sort_order='+sort_order+'&type='+type;
	do_get_command(command);
	}else{
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=sort_service_option&option_id='); ?>"+option_id+'&sort_order='+sort_order+'&type='+type;
	do_get_command(command);
	}
					//do_page_fetch("ajx_move_"+type+"_module",module,row.sort_order);
					realign_row_class(row.parentNode);
	}
	function realign_row_class(table){
					var icnt,n;
					for (icnt=0,n=table.rows.length;icnt<n;icnt++){
						if (table.rows[icnt].opened && table.rows[icnt].opened==1) {
							continue;
						}
						if (table.rows[icnt].className.indexOf("hover")!=-1) continue;

						if (icnt%2==0){
							table.rows[icnt].className="dataTableRowEven";
						} else {
							table.rows[icnt].className="dataTableRowOdd";
						}
					}
				}
</script>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var previous_attributes_id='';	 
	function opt_row_focus(opt_id){
		document.getElementById('header_operation_id').style.display='none';
		document.getElementById('edit_details_id').style.display='none';
		document.getElementById('header_edit_display').style.display='none';
		document.getElementById('header_delete_display').style.display='none';
		for(i=0,len=option_id_value_array.length;i<len;i++){
			if(option_id_value_array[i]!=opt_id && document.getElementById('ajax_opt_'+option_id_value_array[i])){
			document.getElementById('ajax_opt_'+option_id_value_array[i]).innerHTML='';
			document.getElementById('ajax_opt_'+option_id_value_array[i]).style.display='none';
			if( document.getElementById('opt_'+option_id_value_array[i]))
			document.getElementById('opt_'+option_id_value_array[i]).style.display='';
			}
		}
	document.getElementById('ajax_opt_'+opt_id).style.display='';
	document.getElementById('ajax_opt_'+opt_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=opt_load_details&opt_id='); ?>"+opt_id;
	do_get_command(command);
			document.getElementById('new_service_option_value_content').style.display='none';
		if(previous_attributes_id!=''){
		if(document.getElementById('ajax_opt_'+previous_attributes_id) && document.getElementById('opt_'+previous_attributes_id)){
		document.getElementById('ajax_opt_'+previous_attributes_id).innerHTML='';
		document.getElementById('ajax_opt_'+previous_attributes_id).style.display='none';
		document.getElementById('opt_'+previous_attributes_id).style.display='';
		}
		}
	}
	function close_option_value(opt_id){
		document.getElementById('ajax_opt_'+opt_id).innerHTML='';
		document.getElementById('opt_'+opt_id).style.display='';
		document.getElementById('header_operation_id').style.display='';
		document.getElementById('header_edit_display').style.display='none';
		document.getElementById('edit_details_id').style.display='none';
		document.getElementById('delete_option_att').style.display='none';
		var tr1=document.getElementById("img_ids");
		var imgsrc;
		var node;
		if(tr1)
		for(var j=0;j<tr1.cells.length;j++){
			td=tr1.cells[j];
			imgsrc='';
			for(var i=0;i<td.childNodes.length;i++){
				node=td.childNodes[i];
				if(node.tagName=='IMG'){
					imgsrc=node.src;
					if(imgsrc==img_src+'template/img_edit_hover.gif')
					   td.childNodes[i].src = img_src+'template/img_edit.gif';
					else if(imgsrc==img_src+'template/img_trash_hover.gif')
					   td.childNodes[i].src = img_src+'template/img_trash.gif';
					break;
				}
			}
		}
	}

	function row_focus(option_id){ 
		for(i=0,len=services_attributes_id_array.length;i<len;i++){
			if(document.getElementById('attribute_ajax_'+services_attributes_id_array[i]) && document.getElementById('attribute_'+services_attributes_id_array[i])){
			document.getElementById('attribute_ajax_'+services_attributes_id_array[i]).innerHTML='';
			document.getElementById('attribute_'+services_attributes_id_array[i]).style.display='';
			}
		}
	close_new_service_option(); close_new_service_attribute();
		for(i=0,len=option_id_array.length;i<len;i++){
			if(option_id!=option_id_array[i] && document.getElementById('ajax_'+option_id_array[i])){
			document.getElementById('ajax_'+option_id_array[i]).innerHTML='';
			document.getElementById('ajax_'+option_id_array[i]).style.display='none';
			document.getElementById('attrib_'+option_id_array[i]).style.display='';
			}
		}
	document.getElementById('ajax_'+option_id).style.display='';
	document.getElementById('ajax_'+option_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=load_details&option_id='); ?>"+option_id;
	do_get_command(command);
	}
	function save_services_options(option_id){
	var error=false,error_message='';
	document.getElementById('attrib_'+option_id).style.background="#FFFFFF";
	document.getElementById('attrib_'+option_id).style.display='';
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) { ?>
		name=document.getElementById('services_option_name[<?php echo $languages[$i]['id']; ?>]').value ;
			if(name=='' || str_trim(name)==''){
			error=true;
			error_message='<?php echo ERROR_OPTION_NAME; ?>';
			}
		<?php } ?>
	if(error==true)
		alert(error_message);
	else{	
	do_post_command('save_edit_option_name_form','<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=save_option_name&option_id='); ?>'+option_id);
	document.getElementById('ajax_'+option_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;
	}
	}
	function save_opt_services_options(opt_id){
	var error=false,error_message='';
	if(document.getElementById("header_edit_display")) document.getElementById("header_edit_display").style.display='none'; 
	if(document.getElementById("header_delete_display")) document.getElementById("header_edit_display").style.display='none'; 
	<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) { ?>
		name=document.getElementById('services_options_values_name[<?php echo $languages[$i]['id']; ?>]').value ;
			if(name=='' || str_trim(name)==''){
			error=true;
			error_message='<?php echo ERROR_OPTION_NAME; ?>';
			}
		<?php } ?>
	if(error==true)
		alert(error_message);
	else{	
	do_post_command('save_edit_option_value_form','<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=save_opt_values&opt_id='); ?>'+opt_id);
	}
	}
	function drop_services_options(option_id){
	if(document.getElementById('delete_option_att')) document.getElementById('delete_option_att').style.display='';
	if(document.getElementById('edit_details_id')) document.getElementById('edit_details_id').style.display='none';
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=drop_services_options&option_id='); ?>"+option_id;
	do_get_command(command);
	}
	
	function drop_opt_services_options(opt_id){
	if(document.getElementById('drop_service_option'))
		document.getElementById('drop_service_option').style.display ='';
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=drop_service_option_value&opt_id='); ?>"+opt_id;
	do_get_command(command);
	}
	function drop_fail(){
	document.getElementById('attrib_delete_flag').innerHTML='';
	document.getElementById('attrib_delete_flag').style.display='';
	}
	function page_navigation(arg1,agr2,agr3,agr4){
		var page_no=1;
		if(agr2==1) var obj=document.getElementById("page_1");
		else if(agr2==2) var obj=document.getElementById("page_2");
		if(agr2 && agr4){
			if(obj){
 	 			page_no=parseInt(obj.options[obj.selectedIndex].value);
 	 			if(agr4=='next') {
 	 				if(obj.length==obj.selectedIndex+1) return;
 	 				page_no+=1;
 	 			}else if(agr4=='prev') {
	 	 			if(obj.selectedIndex==0) return;
 		 			page_no-=1;
 	 			}
 	 			if(page_no<=1) page_no=1;
 	 		} 	 		
		}				
		if(agr2==1) command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=page_navigation_option'); ?>&page="+page_no;
		else if(agr2==2) command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=page_navigation_attribute'); ?>&page="+page_no;		
		if(command!="") do_get_command(command);
	}
	function load_new_option_value(that){
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=load_new_option_value&options_id='); ?>"+that.value;
	document.getElementById('load_new_option_value_id').innerHTML=document.getElementById('ajax_image_load').innerHTML;
	do_get_command(command);
	}
	function do_result(result){
	//alert(result);
	var token=result.split('^');
	var option_id=token[1]; var opt_id=token[1]; var attributes_id=token[1];
	var page_no=1;
		switch(token[0]){
		case 'post_save_service_option':
			document.getElementById('service_option_list').innerHTML=token[1];
			break;
		
		case 'load_new_option_value':
			document.getElementById('load_new_option_value_id').innerHTML=token[1];
			break;
		case 'load_details': 
			document.getElementById('attrib_'+option_id).style.display='none';
			document.getElementById('ajax_'+option_id).innerHTML=token[2]; 
			document.getElementById('base_header_new_operation').href="javascript: new_service_option_value("+option_id+");";
			break;
		case 'save_option_name':
			document.getElementById('attrib_'+option_id).innerHTML=token[2];
			document.getElementById('attrib_'+option_id).style.display='';
			document.getElementById('ajax_'+option_id).innerHTML='';
			document.getElementById('ajax_'+option_id).style.display='none';
			break;
		case 'drop_services_options':
			var row_index=document.getElementById('services_option_row_'+opt_id).rowIndex;
			document.getElementById('services_option_table').deleteRow(row_index);
			//document.getElementById('attrib_row_'+option_id).style.display='none';
			//document.getElementById('ajax_row_'+option_id).style.display='none';			
			if(document.getElementById("page_1")){
 	 			page_no=parseInt(document.getElementById("page_1").options[document.getElementById("page_1").selectedIndex].value); 	 			
 	 			if(page_no<=1) page_no=1;
 	 		}
			var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=page_navigation_option');?>&page="+page_no;
			do_get_command(command);
			break;
		case 'drop_fail_services_options':
			if(document.getElementById('attrib_delete_flag')) {
				document.getElementById('attrib_delete_flag').style.display='';
				document.getElementById('attrib_delete_flag').innerHTML='<?php echo TEXT_WARNING_OF_DELETE; ?>';			
				setTimeout('drop_fail()',2000);
			}
			break;
		case 'load_opt_details':
			document.getElementById('opt_'+opt_id).style.display='none';
			document.getElementById('ajax_opt_'+opt_id).innerHTML=token[2];
			break;
		case 'save_opt_values':
			document.getElementById('opt_row_'+opt_id).innerHTML=token[2];
			document.getElementById('ajax_opt_'+opt_id).innerHTML='';
			document.getElementById('ajax_opt_'+opt_id).style.display='none';
			break;
		case 'save_new_service_option':
			/*document.getElementById('services_option_table').innerHTML=token[1];
			option_id_array[option_id_array.length-1]=token[2]; */
			if(document.getElementById("page_1")){
 	 			page_no=parseInt(document.getElementById("page_1").options.length)+1; 	 			
 	 			if(page_no<=1) page_no=1;
 	 		}
			var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=page_navigation_option');?>&page="+page_no;
			do_get_command(command);
			break;
		case 'save_new_service_option_value': 
			close_new_service_option_value();
			document.getElementById('option_value_details_content').innerHTML=token[1];
			option_id_value_array[option_id_array.length-1]=token[2];
			break;
		case 'drop_service_option_value':
			close_new_service_option_value();
			document.getElementById('delete_option_att').style.display='none';
			document.getElementById('opt_row_'+opt_id).innerHTML='';
			document.getElementById('ajax_opt_'+opt_id).innerHTML='';
			document.getElementById('ajax_opt_'+opt_id).style.display='none';
			break;
		case 'drop_fail_service_option_value':
			document.getElementById('drop_service_option').style.display='';				
			document.getElementById('attrib_delete_flag').style.display='';
			document.getElementById('attrib_delete_flag').innerHTML='<?php echo TEXT_WARNING_OF_DELETE; ?>';
			setTimeout('drop_fail()',2000);
			//document.getElementById('ajax_opt_'+opt_id).style.display='none';
			//document.getElementById('opt_row_'+opt_id).style.display='';
			break;
		case 'load_Services_attributes':
			document.getElementById('attribute_'+attributes_id).style.display='none';
			document.getElementById('attribute_ajax_'+attributes_id).innerHTML=token[2];
			break;
		case 'save_service_attributes':
			document.getElementById('services_attributes_load_id').innerHTML=token[1];
			close_new_service_attribute();
			break;
		case 'new_service_attribute':
			/*document.getElementById('services_attributes_load_id').innerHTML=token[1];
			services_attributes_id_array[services_attributes_id_array.length-1]=token[2];*/			
			close_new_service_attribute();
			if(document.getElementById("page_2")){
 	 			page_no=parseInt(document.getElementById("page_2").options.length)+1; 	 			
 	 			if(page_no<=1) page_no=1;
 	 		}
			var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=page_navigation_attribute');?>&page="+page_no;
			do_get_command(command);
			break;
		case 'load_option':
			document.getElementById('load_option_id_td').innerHTML=token[1];
			break;
		case 'drop_service_attribute':
			var row_index=document.getElementById('service_attribute_value_'+token[1]).rowIndex;
			document.getElementById('service_attribute_table').deleteRow(row_index);
			if(document.getElementById("page_2")){
 	 			page_no=parseInt(document.getElementById("page_2").options[document.getElementById("page_2").selectedIndex].value); 	 			
 	 			if(page_no<=1) page_no=1;
 	 		}
			var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=page_navigation_attribute');?>&page="+page_no;
			do_get_command(command);
			break;
		case 'page_navigation_option':
			if(document.getElementById("service_option_list")) document.getElementById("service_option_list").innerHTML=token[1];
			break;	
		case 'page_navigation_attribute':
			if(document.getElementById("services_attributes_load_id")) document.getElementById("services_attributes_load_id").innerHTML=token[1];
			break;
		case 'load_new_service_attribute_content':
			document.getElementById('new_service_attribute_content').innerHTML=token[1];
			break;
		}
	}
	

 	var display_flag=1;	
	function do_hover_change1(element,mode){ 
	if(display_flag==1){
		if (element.mode && mode==element.mode) return;
		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 attributes_display_flag=1;	
	function attributes_do_hover_change(element,mode){ 
	if(attributes_display_flag==1){
		if (element.mode && mode==element.mode) return;
		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;
	} 
  
	 function do_hover_change2(element,eve){ 
		 var span_edit=document.getElementById("edit_details");
		 var span_delete=document.getElementById("delete_details");
		 var new_service_option_content=document.getElementById("new_service_option_content");
		 var new_service_option_value_content=document.getElementById("new_service_option_value_content");
	  	 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_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';
		  }
		 }		 
	 }  	
	
	 function do_hover_change3(element,eve){ 
		 var span_edit=document.getElementById("edit_details_id");
		 var span_delete=document.getElementById("delete_option_att");
		 var new_service_option_content=document.getElementById("new_service_option_content");
		 var new_service_option_value_content=document.getElementById("new_service_option_value_content");
		 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_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';
		  }
		 }		 
	 }
	 
	 function do_hover_change4(element,eve){ 
		 var span_delete=document.getElementById("drop_service_option");
		 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';
		  }
		 }		 
	 }  	
	
	function new_service_option(option_id){
	display_flag=0;
	close_new_service_attribute();
		if(document.getElementById('attrib_'+option_id) && document.getElementById('ajax_'+option_id) ){
			document.getElementById('ajax_'+option_id).innerHTML='';
			document.getElementById('ajax_'+option_id).style.display='none';
			document.getElementById('attrib_'+option_id).style.display='';
		}
		if(document.getElementById('new_service_option_content')) document.getElementById('new_service_option_content').style.display='';
	}
	function new_service_option_value(opt_id){
	display_flag=0;
			if(document.getElementById('opt_'+opt_id) && document.getElementById('ajax_opt_'+opt_id)){
			document.getElementById('opt_'+opt_id).style.display='';
			document.getElementById('ajax_opt_'+opt_id).innerHTML='';
			document.getElementById('ajax_opt_'+opt_id).style.display='none';
			}
		if(document.getElementById('new_service_option_value_content')) document.getElementById('new_service_option_value_content').style.display='';
	}
	function save_new_service_option(){
	change_new_image();
	var error=false,error_message='';
	
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
			nam=document.getElementById('option_name[<?php echo $languages[$i]['id']; ?>]').value
		if(nam=='' || str_trim(nam)==''){
			error=true; error_message='<?php echo ERROR_OPTION_NAME; ?>';
		}
		<?php } ?>
	if(error==true)
		alert(error_message);
	else { 
		  	do_post_command('save_service_option_form','<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=post_save_service_option'); ?>');
			close_new_service_option();
		 }			
	}
	function save_new_service_option_value(opt_id){
	change_new_image();
	var error=false,error_message='';
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
		nam=document.getElementById('new_services_option_value[<?php echo $languages[$i]['id']; ?>]').value;
		if(nam=='' || str_trim(nam)==''){
			error=true;
			error_message='<?php echo ERROR_OPTION_NAME; ?>';
		}
		<?php } ?>
	if(error==true)
		alert(error_message);
	else
		do_post_command('save_new_option_value_form','<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=save_new_service_option_value&opt_id='); ?>'+opt_id);
	}
	function change_new_image(){
	document.getElementById('base_header_new_operation').firstChild.src=document.getElementById('base_header_new_operation').firstChild.src.replace('_hover.gif','.gif');
	display_flag=1;
	}
	function close_new_service_option(){
	change_new_image();
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
			document.getElementById('option_name[<?php echo $languages[$i]['id']; ?>]').value='';
		 <?php } ?> 
	if(document.getElementById('new_service_option_content')) document.getElementById('new_service_option_content').style.display='none';
	}
	function close_new_service_option_value(){
	change_new_image();
	document.getElementById('new_service_option_value_content').style.display='none';
	//document.getElementById('new_service_option_name_value').value='';
	}
	function attributes_edit(){
	document.getElementById('edit_details_id').style.display='';
	document.getElementById('header_edit_display').style.display='';
	if(document.getElementById('delete_option_att')) document.getElementById('delete_option_att').style.display='none';
	}
	function attribute_row_focus(attributes_id){
		for(i=0,len=option_id_array.length;i<len;i++){
			if(document.getElementById('ajax_'+option_id_array[i]) && document.getElementById('attrib_'+option_id_array[i])){
			document.getElementById('ajax_'+option_id_array[i]).innerHTML='';
			document.getElementById('attrib_'+option_id_array[i]).style.display='';
			}
		}
	close_new_service_attribute(); close_new_service_option();
		for(i=0,len=services_attributes_id_array.length;i<len;i++){
			if(services_attributes_id_array[i]!=attributes_id && document.getElementById('attribute_ajax_'+services_attributes_id_array[i])){
			document.getElementById('attribute_ajax_'+services_attributes_id_array[i]).innerHTML='';
			document.getElementById('attribute_'+services_attributes_id_array[i]).style.display='';
			}
							
		}
	document.getElementById('attribute_ajax_'+attributes_id).style.display='';
	document.getElementById('attribute_ajax_'+attributes_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=load_services_attributes&attributes_id='); ?>"+attributes_id;
	do_get_command(command);
	previous_attributes_id=attributes_id;
	}
	function edit_service_attributes(attributes_id){
	document.getElementById('delete_details').style.display='none';
	document.getElementById('display_details').style.display='none';
	document.getElementById('edit_details').style.display='';
	document.getElementById('save_service_attributes_button').style.display='';
	}
	function save_service_attributes(attributes_id){
	var service_id=document.getElementById('service_id').value;
	var option_id=document.getElementById('option_id').value;
	var option_id_value=document.getElementById('option_id_value').value;
	var options_values_price=document.getElementById('options_values_price').value;
	var price_prefix=document.getElementById('price_prefix').value;
		
		error=false; error_message="";
		if(options_values_price=='' || str_trim(options_values_price)=='' || isNaN(options_values_price)){ error=true;
		error_message="<?php echo ERROR_OPTIONS_VALUES_PRICE; ?>";
		}
		//if(isNaN(options_values_price)){
		//alert ('no');
		//error_message="<?php echo 'price should be a number'; ?>";
		//}
		if (isNaN(options_values_price)){ error=true;
			error_message="Price should be a Number";			
		}
		if(option_id_value==0){ error=true;
		error_message+="\n<?php echo ERROR_OPTION_VALUE; ?>";
		}
		if(price_prefix=='' || str_trim(price_prefix)==''){ error=true;
		error_message+="\n<?php echo ERROR_PRICE_PREFIX; ?>";
		}else{
			if(price_prefix=='+' || price_prefix=='-'){ 
			}else{
			error=true;
			error_message+="\n<?php echo ERROR_PRICE_PREFIX_INDEX; ?>";
			}
		}
		if(error==true)
			alert(error_message);
		else {
			if(price_prefix=='+') price_prefix='plus';
			else price_prefix='minus';
		var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=save_service_attributes&service_id='); ?>"+service_id+'&option_id='+option_id+'&option_id_value='+option_id_value+'&options_values_price='+options_values_price+'&price_prefix='+price_prefix+'&services_attributes_id='+attributes_id;
		do_get_command(command);
		}
	}
	function change_new_attribute_image(){
	document.getElementById('new_service_attribute_button').firstChild.src=document.getElementById('new_service_attribute_button').firstChild.src.replace('_hover.gif','.gif');
	attributes_display_flag=1;
	}
	function new_service_attribute(){
	attributes_display_flag=0;
	close_new_service_option();
			for(i=0,len=services_attributes_id_array.length;i<len;i++){
			if(document.getElementById('attribute_ajax_'+services_attributes_id_array[i]))
				document.getElementById('attribute_ajax_'+services_attributes_id_array[i]).innerHTML='';
		}
	document.getElementById('new_service_attribute_content').style.display='';
	document.getElementById('new_service_attribute_content').innerHTML=document.getElementById('ajax_image_load').innerHTML;
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=load_new_service_attribute_content'); ?>";
	do_get_command(command);
	}
	<?php
	$chk_query=tep_db_query('select count(*) as total from services_attributes');
	$chk_array=tep_db_fetch_array($chk_query);
	if($chk_array['total']<=0){
	?>
	new_service_attribute();
	<?php } ?>
	
	
	function close_new_service_attribute(){
	change_new_attribute_image();
	document.getElementById('new_service_attribute_content').style.display='none';
	}
	function save_new_service_attribute(){
	change_new_attribute_image();
	var service_id=document.getElementById('service_id').value;
	var option_id=document.getElementById('option_id').value;
	var values_id=document.getElementById('values_id').value;
	var options_values_price=document.getElementById('options_values_price').value;
	var price_prefix=document.getElementById('price_prefix').value;
		
	error=false; error_message="";
		if(options_values_price=='' || str_trim(options_values_price)==''){ error=true;
		error_message="<?php echo ERROR_OPTIONS_VALUES_PRICE; ?>";
		}if(isNaN(options_values_price)){ error=true;
		error_message="Price Should be a Number";
		}if(values_id==0){ error=true;
		error_message+="\n<?php echo ERROR_OPTION_VALUE; ?>";
		}
		if(price_prefix=='' || str_trim(price_prefix)==''){ error=true;
		error_message+="\n<?php echo ERROR_PRICE_PREFIX; ?>";
		}else{
			if(price_prefix=='+' || price_prefix=='-'){ 
			}else{
			error=true;
			error_message+="\n<?php echo ERROR_PRICE_PREFIX_INDEX; ?>";
			}
		}
	
	if(error==true)
		alert(error_message);
	else{
		if(price_prefix=='+')
			price_prefix='plus'; else price_prefix='minus';
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=new_service_attribute&service_id='); ?>"+service_id+'&option_id='+option_id+'&values_id='+values_id+'&options_values_price='+options_values_price+'&price_prefix='+price_prefix;
	do_get_command(command);
	}
	}
</script>
<script language=JavaScript>

function base_service_option_close(option_id){
	document.getElementById('attrib_'+option_id).style.display='';
	document.getElementById('ajax_'+option_id).innerHTML='';
	document.getElementById('ajax_'+option_id).style.display='none';
document.getElementById('base_header_new_operation').href="javascript: new_service_option();";
}
function close_service_attribute(option_id){
document.getElementById('attribute_ajax_'+option_id).innerHTML='';
document.getElementById('attribute_ajax_'+option_id).style.display='none';
document.getElementById('attribute_'+option_id).style.display='';
}
function load_option_id(that){
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=load_option&options_id='); ?>"+that.value;
	do_get_command(command);
	document.getElementById('load_option_id_td').innerHTML=document.getElementById('ajax_image_load').innerHTML;
}
function drop_service_attribute(attribute_id){
	document.getElementById('delete_details').style.display='';
	document.getElementById('edit_details').style.display='none';
	var command="<?php echo tep_href_link(FILENAME_SERVICES_ATTRIBUTES,'command=drop_service_attribute&attribute_id='); ?>"+attribute_id;
	do_get_command(command);
}
</script>   


<?php
function services_option_list(){ 
	global $page,$languages_id;
	$services_option_query_raw="select services_options_name,services_options_id from ".TABLE_SERVICES_OPTIONS." where language_id='$languages_id' order by services_options_name, services_options_sort_order";
	$services_option_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $services_option_query_raw, $services_option_numrows);	    
    $services_option_query = tep_db_query($services_option_query_raw);
	?>
	<table id="services_option_table" width="100%" cellpadding="2" cellspacing="2" border="0">
	<?php $row=1; 	
	while($services_option_array=tep_db_fetch_array($services_option_query)){
		if($row%2==0) $class_name="dataTableRowOdd"; else $class_name="dataTableRowEven";
		$row++;
	?>
		<tr id="services_option_row_<?php echo $services_option_array["services_options_id"]; ?>">
			<td class="main">
			<div id="attrib_row_<?php echo $services_option_array["services_options_id"]; ?>" onClick="javascript:row_focus(<?php echo $services_option_array["services_options_id"]; ?>);">
			<div onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="attrib_<?php echo $services_option_array["services_options_id"]; ?>" class="<?php echo $class_name; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif') .'&nbsp;&nbsp;'. $services_option_array["services_options_name"]; ?></div>
			</div>
			<div id="ajax_row_<?php echo $services_option_array["services_options_id"]; ?>">
			<div id="ajax_<?php echo $services_option_array["services_options_id"]; ?>" style="display:none;"></div>
			</div> 
			</td>
		</tr>
	  <?php } ?>
	</table>
	<table border="0" width="100%" cellpadding="0"cellspacing="2">
		<tr>
      	<td colspan="4">
	   	   	<table border="0" width="100%" cellpadding="0"cellspacing="2">
			 <tr>
	            <td class="smallText" valign="top"><?php echo $services_option_split->display_count($services_option_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_SERVICES_OPTIONS); ?></td>
	            <td class="smallText" align="right"><?php echo $services_option_split->display_script_links($services_option_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'page_navigation(\'\'','1'); ?></td>
	         </tr>
		    </table>
	  	</td>
	  </tr>
	</table>
<?php } 

function services_attributes_load_function(){ 
  global $languages_id,$page;
 $services_attributes_query_raw="select sa.services_attributes_id,sd.service_name,options_id,options_values_id,options_values_price,price_prefix from ".TABLE_SERVICES_ATTRIBUTES." sa, ".TABLE_SERVICES_DESCRIPTION." sd where sa.service_id=sd.service_id and sd.language_id='$languages_id' order by sa.services_options_sort_order, sd.service_name";
 $services_attributes_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $services_attributes_query_raw, $services_attributes_numrows);	    
 $services_attributes_query = tep_db_query($services_attributes_query_raw);
?>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr  class="dataTableHeadingRow">
<td><?php echo HEADING_TITLE; ?></td></tr>
<tr><td>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr class="dataTableHeadingRow">
	<td colspan="5" style="vertical-align:middle;">
	<?php echo '<a id="new_service_attribute_button" onMouseOver="attributes_do_hover_change(this,2);" onMouseOut="attributes_do_hover_change(this,1);" href="javascript: new_service_attribute();">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','New','22','22'); ?></td>
	</tr>
	<tr>
	<td class="TableHeading" width="130"><?php echo TEXT_SERVICE; ?></td>
	<td class="TableHeading" width="100"><?php echo TABLE_HEADING_OPT_NAME; ?></td>
	<td class="TableHeading" width="100"><?php echo TABLE_HEADING_OPT_VALUE; ?></td>
	<td class="TableHeading" width="100"><?php echo TABLE_HEADING_OPT_PRICE; ?></td>
	<td class="TableHeading" width="50"><?php echo TEXT_PREFIX; ?></td>
	</tr>
	</table>
</td>
</tr>
</table>
<table width="100%" border="0" id="service_attribute_table" cellpadding="2" cellspacing="2">
<?php $row=1; while($services_attributes_array=tep_db_fetch_array($services_attributes_query)){ 
	if($row%2==0) $class_name='dataTableRowEven'; else $class_name='dataTableRowOdd'; 
	$options_id=$services_attributes_array["options_id"];
	$options_values_id=$services_attributes_array["options_values_id"];
	$services_options_name_query=tep_db_query("select services_options_name from ".TABLE_SERVICES_OPTIONS." where services_options_id='$options_id' and language_id='$languages_id'");
	$services_options_name_array=tep_db_fetch_array($services_options_name_query);	

	$services_options_values_query=tep_db_query("select services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." where services_options_values_id='$options_values_id'");
	$services_options_values_array=tep_db_fetch_array($services_options_values_query);

?>
<tr id="service_attribute_value_<?php echo $services_attributes_array["services_attributes_id"]; ?>">
<td class="main">
	<div class="<?php echo $class_name; ?>" id="attribute_row_<?php echo $services_attributes_array["services_attributes_id"]; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" onClick="javascript: attribute_row_focus(<?php echo $services_attributes_array["services_attributes_id"]; ?>);">
	<div id="attribute_<?php echo $services_attributes_array["services_attributes_id"]; ?>">
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td class="main" width="130"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$services_attributes_array["service_name"]; ?></td>
	<td class="main" width="100"><?php echo $services_options_name_array["services_options_name"]; ?></td>
	<td class="main" width="100"><?php echo $services_options_values_array["services_options_values_name"]; ?></td>
	<td class="main" width="100"><?php echo $services_attributes_array["options_values_price"]; ?></td>
	<td class="main" width="50"><?php echo $services_attributes_array["price_prefix"]; ?></td>
	</tr>
	</table>
	</div>
	</div>
	<div id="attribute_ajax_row_<?php echo $services_attributes_array["services_attributes_id"]; ?>">
	<div id="attribute_ajax_<?php echo $services_attributes_array["services_attributes_id"]; ?>" style="display:none;"></div>
	</div>
</td>
</tr>
<?php } ?>
	</table>
	<table border="0" width="100%" cellpadding="0"cellspacing="2">
		<tr>
      	<td colspan="4">
   	   	<table border="0" width="100%" cellpadding="0"cellspacing="2">
		 <tr>
            <td class="smallText" valign="top"><?php echo $services_attributes_split->display_count($services_attributes_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_SERVICES_ATTRIBUTES); ?></td>
            <td class="smallText" align="right"><?php echo $services_attributes_split->display_script_links($services_attributes_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,2,'page_navigation(\'\'','2'); ?></td>
          </tr>
	   </table>
	  </td>
	</tr>
	</table>
<?php } ?>

<?php function load_services_options_value($opt_id){ global $languages_id;
$services_options_values_query=tep_db_query("select sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_OPTIONS_VALUES." sov, ".TABLE_SERVICES_OPTIONS_VALUES_TO_SERVICES_OPTIONS . " sovo where sov.language_id='$languages_id' and sovo.services_options_id='$opt_id' and sov.services_options_values_id=sovo.services_options_values_id order by services_options_values_name");
		?>
		<?php while($services_options_values_array=tep_db_fetch_array($services_options_values_query)){ ?>
		<div class="main" id="opt_row_<?php echo $services_options_values_array["services_options_values_id"]; ?>" onClick="javascript:opt_row_focus(<?php echo $services_options_values_array["services_options_values_id"]; ?>);">
		<div class="dataTableRowOdd" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="opt_<?php echo $services_options_values_array["services_options_values_id"]; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$services_options_values_array["services_options_values_name"]; ?></div>
		</div>
		<div id="ajax_opt_row_<?php echo $services_options_values_array["services_options_values_id"]; ?>">
		<div id="ajax_opt_<?php echo $services_options_values_array["services_options_values_id"]; ?>" style="display:none;"></div>
		</div>
<?php } 
} ?>




