<?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"]:'';
	$page=isset($HTTP_GET_VARS["page"])?$HTTP_GET_VARS["page"]:1;
	$opt_id=isset($HTTP_GET_VARS["opt_id"])?$HTTP_GET_VARS["opt_id"]:'';
	$services_attributes_id=isset($HTTP_GET_VARS["attributes_id"])?$HTTP_GET_VARS["attributes_id"]:'';
	$category_id=isset($HTTP_GET_VARS["category_id"])?$HTTP_GET_VARS["category_id"]:'';
	$product_id=isset($HTTP_GET_VARS["product_id"])?$HTTP_GET_VARS["product_id"]:'';
	
	$languages = tep_get_languages();
	switch($command){
		case 'load_products':
			echo 'load_products^';	
			$get_products_query=tep_db_query("select products_id,products_name from products_description where products_id in ( select products_id from products_to_categories where categories_id= '$category_id' )");
			if(tep_db_num_rows($get_products_query)>0){
				$products=array();
				$products[]=array('id'=>0,'text'=>TEXT_ALL_PRODUCT);
				while($products_result=tep_db_fetch_array($get_products_query)){
					$products[]=array('id'=>$products_result['products_id'],'text'=>$products_result['products_name']);
				}
				echo 'Select Product :'.'&nbsp;&nbsp;'.tep_draw_pull_down_menu('products_menu',$products,$products[1]['id'],'id="products_menu" onchange="javascript:call_attribute_details(this)"');	
			} else echo 'No products available^empty';
			exit;
		break;
		case 'load_attribute_details':
			echo 'load_attribute_details^';		
			echo $product_id . '^';
			if(isset($HTTP_GET_VARS['cmd'])=='load_by_category') products_attributes_load_function($category_id,'category');
			else products_attributes_load_function($product_id,'product');
			exit; 	  
		break;
		case 'post_save_product_option_form':
			echo 'post_save_product_option_form^';
			$products_options_id=0; $products_options_sort_order=0;
			$products_options_id_query=tep_db_query("select max(products_options_id) as products_options_id, max(products_options_sort_order) as products_options_sort_order from ".TABLE_PRODUCTS_OPTIONS);
			if(tep_db_num_rows($products_options_id_query)>0){
				$products_options_id_array=tep_db_fetch_array($products_options_id_query);
				$products_options_id=$products_options_id_array["products_options_id"];
				$products_options_sort_order=$products_options_id_array["products_options_sort_order"]; $products_options_sort_order++;
			}
			$products_options_id++;
			for($i=0,$n=sizeof($languages);$i<$n;$i++){
				$new_languages_id=$languages[$i]['id'];
				$new_products_options_name=tep_db_prepare_input($HTTP_POST_VARS['option_name'][$new_languages_id]);
				tep_db_query("insert into ".TABLE_PRODUCTS_OPTIONS."(products_options_id,language_id,products_options_name,products_options_sort_order) values('$products_options_id','$new_languages_id','$new_products_options_name','$products_options_sort_order')");
				$products_options_sort_order++;
			}
			
			echo '<div style="color:#FF0000;" id="attrib_delete_flag"></div>';
			echo products_options_value_list();
			exit;
		break;
		case 'page_navigation_option':
			echo 'page_navigation_option^';
			products_options_value_list();
		exit;
		break;
		case 'page_navigation_attribute':
			echo 'page_navigation_attribute^';
			products_attributes_load_function($product_id);
			exit;
		break;
		case 'load_details':
			echo 'load_details^';
			echo $option_id.'^';
			$products_options_name="";
			$attributes_query=tep_db_query("select products_options_name,products_options_sort_order from ".TABLE_PRODUCTS_OPTIONS." where products_options_id='$option_id'");
			if(tep_db_num_rows($attributes_query)>0){
				$attributes_array=tep_db_fetch_array($attributes_query);
				$products_options_name=$attributes_array["products_options_name"];
				$products_options_sort_order=$attributes_array['products_options_sort_order'];
			}
			$products_options_values_query=tep_db_query("select sov.products_options_values_id,sov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." sov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " sovo where sov.language_id='$languages_id' and sovo.products_options_id='$option_id' and sov.products_options_values_id=sovo.products_options_values_id order by products_options_values_name");
			$function_name="";
			if(tep_db_num_rows($products_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" class="openContent" cellspacing="0" width="100%">
				<tr class="openContent_top">
					<td class="main" width="350" Onclick="javascript:bsoclose(<?php echo $option_id?>)">
						<?php echo tep_image(DIR_WS_IMAGES . "template/icon_active.gif").'&nbsp;&nbsp;<a href="javascript: move_updown(\'services_option_row_\','.$option_id .',\'up\','.$products_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\','.$products_options_sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_down.gif",'Down').'</a>&nbsp;&nbsp;'.$products_options_name; ?>
					</td>	
					<td  width="100" align="left">
						<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_products_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 class="main" with="550" Onclick="javascript:bsoclose(<?php echo $option_id?>)">&nbsp;</td>
					<td width="65"  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" 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"><td></td></tr>
							<tr class="main">
								<td colspan="3" class="main" align="center">
								<?php 
									echo tep_draw_form('save_edit_option_name_form',FILENAME_PRODUCTS_ATTRIBUTES,'','post');
									for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
									$products_options_name='';
									$products_options_name_query=tep_db_query('select products_options_name from '.TABLE_PRODUCTS_OPTIONS." where products_options_id='$option_id' and language_id='".(int)$languages[$i]['id']."'");
									if(tep_db_num_rows($products_options_name_query)>0){
									$products_options_name_array=tep_db_fetch_array($products_options_name_query);
									$products_options_name=$products_options_name_array['products_options_name'];
									}			
									echo $languages[$i]['code'].'&nbsp;&nbsp;'.tep_draw_input_field("products_option_name[" . $languages[$i]['id'] . "]",$products_options_name).'<br><br>';
									}echo tep_draw_hidden_field('source','',"id='source'");
									echo tep_draw_hidden_field('work_values','',"id='work_values'");
									echo '</form>';
									?>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<div class="main" id="delete_option_att" style="display:none">&nbsp;</div>
				<?php
				$options_values=array();
				while($products_options_values_array=tep_db_fetch_array($products_options_values_query)){ 
					$options_values[]=array('id'=>$products_options_values_array["products_options_values_id"],'text'=>$products_options_values_array["products_options_values_name"]);
				}
				?>
				<tr>
					<td colspan="3">
						<table width="100%" cellpadding="5" cellspacing="5" border="0">
						<tr>
							<td width="33%" align="right"><?php echo tep_draw_pull_down_menu('options_values',$options_values,$options_values[0]['id'],' size="7" style="width:300px;" id="options_values" onClick="do_opt_value_select(\'select\');"'); ?></td>
							<td>
								<table cellpadding="3" cellspacing="0" border="0">
									<tr><td><img src="images/template/img_new.gif" alt="<?php echo IMAGE_ADD;?>" title="<?php echo IMAGE_ADD;?>"  style="cursor:pointer;cursor:hand;" onClick="javascript:do_opt_value_select('add');" onMouseOver="do_breaks_hover_change('img_new',1,this);" id="img_add" onMouseOut="do_breaks_hover_change('img_new',2,this)" /></td></tr>
									<tr><td><img src="images/template/img_edit.gif" alt="<?php echo IMAGE_UPDATE;?>" title="<?php echo IMAGE_UPDATE;?>" style="cursor:pointer;cursor:hand;" onClick="javascript:do_opt_value_select('update');" onMouseOver="do_breaks_hover_change('img_edit',1,this);" id="img_update" onMouseOut="do_breaks_hover_change('img_edit',2,this)" /></td></tr>
									<tr><td><img src="images/template/img_trash.gif" alt="<?php echo IMAGE_DELETE;?>" title="<?php echo IMAGE_DELETE;?>" style="cursor:pointer;cursor:hand;" onClick="javascript:do_opt_value_select('delete');" onMouseOver="do_breaks_hover_change('img_trash',1,this);" id="img_trash" onMouseOut="do_breaks_hover_change('img_trash',2,this)" /></td></tr>
								</table>
							</td>
						</tr>
						<tr>
							<td colspan="2" class="main"><?php echo tep_draw_separator('pixel_trans.gif',45,1).'Option Value :'.tep_draw_separator('pixel_trans.gif',10,1).tep_draw_input_field('opt_val_name',$options_values[0]['text'],"size='15' id='opt_val_name' "); ?></td>
						</tr>
						</table>
					</td>
				</tr>
				<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($products_options_values_array=tep_db_fetch_array($products_options_values_query)){ 
									if($row%2==0) $class_name='subdataTableRowEven'; else $class_name='subdataTableRowOdd';
									?>
									<div class="main"  id="opt_row_<?php echo $products_options_values_array["products_options_values_id"]; ?>" onClick="javascript:opt_row_focus(<?php echo $products_options_values_array["products_options_values_id"]; ?>);">
										<div class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="opt_<?php echo $products_options_values_array["products_options_values_id"]; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$products_options_values_array["products_options_values_name"]; ?></div>
									</div>
									<div id="ajax_opt_row_<?php echo $products_options_values_array["products_options_values_id"]; ?>">
										<div id="ajax_opt_<?php echo $products_options_values_array["products_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;" style="background:#DEE4F5;">
								<form name="new_product_option_value_form" method="post"> 
								<table width="100%" align="right" 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 Product 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'); 
								for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
								echo $languages[$i]['code'].'&nbsp;&nbsp;'.tep_draw_input_field("products_option_value[" . $languages[$i]['id'] . "]").'<br>';
								}
								?></td>
								</tr>
								</table>
								</form>
								</div>-->
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<?php
			exit;
		break;
		case 'save_option_name':
			echo 'save_option_name^';
			$source=isset($HTTP_POST_VARS['source'])?$HTTP_POST_VARS['source']:'';
			$work_values=isset($HTTP_POST_VARS['work_values'])?$HTTP_POST_VARS['work_values']:'';
			if($work_values=='exists'){
				if($source!=''){
					for($i=0,$lcnt=sizeof($languages);$i<$lcnt;$i++){
						$language_id=$languages[$i]['id'];
						//take options_values from db
						$get_options_vaues_query=tep_db_query("select pov.products_options_values_id,pov.products_options_values_name from products_options_values pov,products_options_values_to_products_options popo where" .
									" popo.products_options_id='" . $option_id ."' and pov.language_id='". $language_id ."' and popo.products_options_values_id= pov.products_options_values_id");
						if(tep_db_num_rows($get_options_vaues_query)>0){
							while($options_values_array=tep_db_fetch_array($get_options_vaues_query)){
								$original_array[$options_values_array['products_options_values_id']]=$options_values_array['products_options_values_name'];
							}
						}//print_r($original_array);
						$source=substr($source,0,-1);
						$rows=explode('#',$source);
						$n= count($rows);
						for($icnt=0;$icnt<$n;$icnt++){
							$onerow=explode('^',$rows[$icnt]);
							$source_array[$onerow[0]]=$onerow[1];
						}				//print_r($source_array);
						reset($source_array);
						if(count($original_array)>0){
							while(list($key,$value)=each($source_array)){
								if(array_key_exists($key,$original_array)){
									tep_db_query("update ". TABLE_PRODUCTS_OPTIONS_VALUES ." set products_options_values_name = '". tep_db_input($value)."' where  products_options_values_id='$key' and language_id='$language_id' ");
								}else if($key){
									$get_options_values_id_query=tep_db_query("select max(products_options_values_id) as products_options_values_id from ". TABLE_PRODUCTS_OPTIONS_VALUES );
									if(tep_db_num_rows($get_options_values_id_query)){
										$get_options_values_id_result=mysql_fetch_row($get_options_values_id_query);
										$options_values_id = $get_options_values_id_result[0]+1;
										tep_db_query("Insert into ". TABLE_PRODUCTS_OPTIONS_VALUES . " values('$options_values_id','$language_id','". tep_db_input($value) ."' )");
										if($i==0) tep_db_query("Insert into ". TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " values(Null,'$option_id','$options_values_id') ");
									}	
								}
							}
							reset($original_array);
							while(list($key,$value)=each($original_array)){
								if(!array_key_exists($key,$source_array)){
									tep_db_query("delete from ". TABLE_PRODUCTS_OPTIONS_VALUES ." where products_options_values_id='$key' and products_options_values_name='". tep_db_input($value) ."'");
									tep_db_query("delete from ". TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS ." where products_options_values_id='$key' and products_options_id='$option_id' ");
								}
							}
						}else{
							while(list($key,$value)=each($source_array)){
								if($key){
									$get_options_values_id_query=tep_db_query("select max(products_options_values_id) as products_options_values_id from ". TABLE_PRODUCTS_OPTIONS_VALUES );
									if(tep_db_num_rows($get_options_values_id_query)){
										$get_options_values_id_result=mysql_fetch_row($get_options_values_id_query);
										$options_values_id = $get_options_values_id_result[0]+1;
										tep_db_query("Insert into ". TABLE_PRODUCTS_OPTIONS_VALUES . " values('$options_values_id','$language_id','". tep_db_input($value) ."' )");
										if($i==0) tep_db_query("Insert into ". TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " values(Null,'$option_id','$options_values_id') ");
									}	
								}	
							}
						} 
					} //for loop ends	
				} else{
					//source is empty, we delete all option values from the option id if exists
					$find_options_values_id_query=tep_db_query("select products_options_values_id from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS ." where products_options_id='$option_id'");
					if(tep_db_num_rows($find_options_values_id_query)>0){
						while($row=tep_db_fetch_array($find_options_values_id_query)){
							$values_id .= $row['products_options_values_id'].',';
						}
						$values_id = substr($values_id,0,-1);
						tep_db_query("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS ." where products_options_id = '$option_id'");
						if($values_id!='') tep_db_query("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES  ." where products_options_values_id in (" . $values_id .")");
					}
				}
			}	
			for($i=0,$n=sizeof($languages);$i<$n;$i++){
				$language_id=$languages[$i]['id'];
				$products_options_name=tep_db_prepare_input($HTTP_POST_VARS['products_option_name'][$language_id]);
				
				$chk_qry=tep_db_query('select count(*) as total from '.TABLE_PRODUCTS_OPTIONS." where language_id='$language_id' and products_options_id='$option_id'");
				
				$chk_array=tep_db_fetch_array($chk_qry);			
				if($chk_array['total']>0){
					tep_db_query("update ".TABLE_PRODUCTS_OPTIONS." set products_options_name='$products_options_name' where language_id='$language_id' and products_options_id='$option_id'");
					}
				else {
					tep_db_query("insert into ".TABLE_PRODUCTS_OPTIONS." (products_options_id,language_id,products_options_name) values('$option_id','$language_id','$products_options_name')");
					}
			}
			$default_products_option_query=tep_db_query('select products_options_name from '.TABLE_PRODUCTS_OPTIONS." where products_options_id='$option_id' and language_id='$languages_id'");
			$default_products_option_array=tep_db_fetch_array($default_products_option_query);
			$products_options_name=$default_products_option_array['products_options_name'];
			
			echo $option_id.'^';
			echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$products_options_name;
			exit;
		break;
		case 'drop_products_options':
			$products_options_values_query=tep_db_query("select sov.products_options_values_id,sov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." sov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " sovo where sovo.products_options_id='$option_id' and sov.products_options_values_id=sovo.products_options_values_id and language_id='$languages_id'");
			if(tep_db_num_rows($products_options_values_query)<=0){
				echo 'drop_products_options^';
				echo $option_id.'^';
				tep_db_query("delete from ".TABLE_PRODUCTS_OPTIONS." where language_id='$languages_id' and products_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.'^'; $products_options_values_name=''; $products_options_values_id="";
			$products_options_query=tep_db_query("select products_options_values_id,products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." where language_id='$languages_id' and products_options_values_id='$opt_id'");
			if(tep_db_num_rows($products_options_query)>0)
				$products_options_array=tep_db_fetch_array($products_options_query);
			$products_options_values_name=$products_options_array["products_options_values_name"];
			$products_options_values_id=$products_options_array["products_options_values_id"];
			?>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr style="background:#DEE4F5;">
					<td colspan="3" class="main"><?php echo tep_image(DIR_WS_IMAGES . "template/icon_active.gif").'&nbsp;&nbsp;'.$products_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);">'.tep_image(DIR_WS_IMAGES.'template/img_trash.gif','Delete').'</td>'; ?>
								<td  class="cell_bg_popm_right" width="10"></td>
							</tr>
						</table>
					</td>
					<td width="50%" 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_PRODUCTS_ATTRIBUTES,'','post');
						for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
						$products_options_values_name='';
						$products_options_values_name_query=tep_db_query('select products_options_values_name from '.TABLE_PRODUCTS_OPTIONS_VALUES." where products_options_values_id='$opt_id' and language_id='".(int)$languages[$i]['id']."'");
						if(tep_db_num_rows($products_options_values_name_query)>0){
						$products_options_values_name_array=tep_db_fetch_array($products_options_values_name_query);
						$products_options_values_name=$products_options_values_name_array['products_options_values_name'];
						}			
						echo $languages[$i]['code'].'&nbsp;&nbsp;'.tep_draw_input_field("products_options_values_name[" . $languages[$i]['id'] . "]",$products_options_values_name).'<br><br>';
						}
						echo '</form>';
					?>
					</td>
				</tr>
				<tr><td colspan="3"></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'];
				$products_options_values_name=tep_db_prepare_input($HTTP_POST_VARS['products_options_values_name'][$language_id]);
				$chk_query=tep_db_query('select count(*) as total from '.TABLE_PRODUCTS_OPTIONS_VALUES." where products_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_PRODUCTS_OPTIONS_VALUES." set products_options_values_name='$products_options_values_name' where language_id='$language_id' and products_options_values_id='$opt_id'");
				else
					tep_db_query("insert into ".TABLE_PRODUCTS_OPTIONS_VALUES." (products_options_values_id,products_options_values_name,language_id) values('$opt_id','$products_options_values_name','$language_id')");
			}
			
			$products_options_values_name='';
			$default_query=tep_db_query('select products_options_values_name from '.TABLE_PRODUCTS_OPTIONS_VALUES." where products_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);
				$products_options_values_name=$default_array['products_options_values_name'];
			}
			echo '<div class="subdataTableRowOdd" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="opt_'.$opt_id.'">'.tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$products_options_values_name.'</div>';
			exit;
		break;
		case 'save_new_service_option':
			echo 'save_new_service_option^';
			$new_product_option_name=isset($HTTP_GET_VARS["new_service_option_name"])?$HTTP_GET_VARS["new_service_option_name"]:'';
			$products_options_id=0; $products_options_sort_order=0;
			$products_options_id_query=tep_db_query("select max(products_options_id) as products_options_id, max(products_options_sort_order) as products_options_sort_order from ".TABLE_PRODUCTS_OPTIONS);
			if(tep_db_num_rows($products_options_id_query)>0){
				$products_options_id_array=tep_db_fetch_array($products_options_id_query);
				$products_options_id=$products_options_id_array["products_options_id"];
				$products_options_sort_order=$products_options_id_array["products_options_sort_order"];
			}
			$products_options_id++;
			tep_db_query("insert into ".TABLE_PRODUCTS_OPTIONS."(products_options_id,language_id,products_options_name,products_options_sort_order) values('$products_options_id','$languages_id','$new_product_option_name','$products_options_sort_order')");
			exit;
		break;
		case 'save_new_service_option_value':
			echo 'save_new_service_option_value^'; 
			
			$products_options_values_query=tep_db_query("select max(products_options_values_id) as products_options_values_id from ".TABLE_PRODUCTS_OPTIONS_VALUES);
			$products_options_values_array=tep_db_fetch_array($products_options_values_query);
			$products_options_values_id=$products_options_values_array["products_options_values_id"]; $products_options_values_id++;
			
			for($i=0,$n=sizeof($languages);$i<$n;$i++){
				$language_id=$languages[$i]['id'];
				$new_product_option_name_value=tep_db_prepare_input($HTTP_POST_VARS['products_option_value'][$language_id]);
				tep_db_query("insert into ".TABLE_PRODUCTS_OPTIONS_VALUES."(products_options_values_id,language_id,products_options_values_name) values('$products_options_values_id','$language_id','$new_product_option_name_value') ");
			}		
			
			tep_db_query("insert into ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS."(products_options_id,products_options_values_id) values('$opt_id','$products_options_values_id')");
			
			$products_options_values_query=tep_db_query("select sov.products_options_values_id,sov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." sov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " sovo where sovo.products_options_id='$opt_id' and sov.language_id='$languages_id' and sov.products_options_values_id=sovo.products_options_values_id order by products_options_values_name");
			
			while($products_options_values_array=tep_db_fetch_array($products_options_values_query)){ ?>
				<div class="main" id="opt_row_<?php echo $products_options_values_array["products_options_values_id"]; ?>" onClick="javascript:opt_row_focus(<?php echo $products_options_values_array["products_options_values_id"]; ?>);">
					<div class="dataTableRowOdd" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="opt_<?php echo $products_options_values_array["products_options_values_id"]; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$products_options_values_array["products_options_values_name"]; ?></div>
				</div>
				<div id="ajax_opt_row_<?php echo $products_options_values_array["products_options_values_id"]; ?>">
					<div id="ajax_opt_<?php echo $products_options_values_array["products_options_values_id"]; ?>" style="display:none;"></div>
				</div>
			<?php } 
			echo '^'.$products_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_PRODUCTS_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_PRODUCTS_OPTIONS_VALUES." where products_options_values_id='$opt_id'");
				tep_db_query("delete from ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS." where products_options_values_id='$opt_id'");
			}
			else {
				echo 'drop_fail_service_option_value^';
			}	
			echo $opt_id;
			exit;
		break;
		case 'load_services_attributes': $products_attributes_id=$services_attributes_id;
			echo 'load_Services_attributes^'; echo $products_attributes_id.'^';
			$products_attributes_query=tep_db_query("select sd.products_name,so.products_options_name,sov.products_options_values_name,sa.options_values_price,sa.price_prefix,sa.products_id,sa.options_id,sa.options_values_id,sa.products_options_sort_order from ".TABLE_PRODUCTS_DESCRIPTION." sd, ".TABLE_PRODUCTS_ATTRIBUTES." sa, " .
			TABLE_PRODUCTS_OPTIONS . " so, " . TABLE_PRODUCTS_OPTIONS_VALUES ." sov " .			
			" where sd.products_id=sa.products_id and sa.products_attributes_id='$products_attributes_id' and so.products_options_id=sa.options_id and sov.products_options_values_id=sa.options_values_id");
			$products_attributes_array=tep_db_fetch_array($products_attributes_query);
			//$services_attributes_array["services_options_values_name"];
			$products_id=$products_attributes_array["products_id"];
			$options_id=$products_attributes_array["options_id"];
			$options_values_id=$products_attributes_array["options_values_id"];
			$price_prefix=$products_attributes_array["price_prefix"];
			$options_values_price=$products_attributes_array["options_values_price"];
			$products_options_sort_order=$products_attributes_array["products_options_sort_order"];
			?>
			<div style="vertical-align:top">
				<table width="100%" border="0" cellpadding="0" cellspacing="0" class="openContent_top">
					<tr  >
						<td valign="top" Onclick="javascript:o_close(<?php echo $products_attributes_id?>)" 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_\','. $products_attributes_id .',\'up\','.$products_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_\','.$products_attributes_id.',\'down\','.$products_options_sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_down.gif",'Down').'</a>&nbsp;&nbsp;'. $products_attributes_array["products_name"]; ?>
						</td>
												
						<td width="80" valign="top">
							<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 Onclick="javascript:do_hover_change2(this,1);void edit_service_attributes('.$products_attributes_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_edit.gif').'</td>
										<td Onclick="javascript:do_hover_change2(this,1);delete_product_attributes('.$products_attributes_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);" >'.tep_image(DIR_WS_IMAGES.'template/img_trash.gif').'</td>'; ?>
									<td class="cell_bg_popm_right" width="10">&nbsp;</td>
								</tr>
							</table>
						</td>
						<td width="555" valign="top" style="cursor:pointer;cursor:hand;" Onclick="javascript:o_close(<?php echo $products_attributes_id?>)">&nbsp;</td>
						<td width="50" align="right" valign="top"><?php echo '<a id="save_service_attributes_button" style="display:none;" href="javascript:void save_service_attributes('.$products_attributes_id .')">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a href="javascript: close_service_attribute('.$products_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="90%" border="0" cellpadding="2" cellspacing="2" align="center">
					<tr>
						<td class="TableHeading" align="left" width="100"><?php echo TEXT_PRODUCT; ?> :</td>
						<td width="140" align="left" class="main"><?php echo $products_attributes_array["products_name"]; ?></td>
						<td width="120" align="left" class="TableHeading"><?php echo TABLE_HEADING_OPT_NAME; ?> :</td>
						<td width="120" class="main" align="left"><?php echo $products_attributes_array["products_options_name"]; ?></td>
						<td width="120" align="left" class="TableHeading"><?php echo TABLE_HEADING_OPT_VALUE; ?> :</td>
						<td class="main" align="left"><?php echo $products_attributes_array["products_options_values_name"]; ?></td>
					</tr>
					<tr>
						<td align="left" class="TableHeading"><?php echo TEXT_PRICE; ?> :</td>
						<td class="main" align="left"><?php echo $products_attributes_array["options_values_price"]; ?></td>
						<td align="left" class="TableHeading"><?php echo TEXT_PREFIX; ?></td>
						<td align="left" class="main"><?PHP echo $products_attributes_array["price_prefix"] ?></td>
						<td colspan="2">&nbsp;</td>
					</tr>
					<tr><td colspan="6">&nbsp;</td></tr>
				</table>
			</div>
			<div id="edit_details" style="display:none;" class="openContent">
				<?php 
				$product_description_query=tep_db_query("select products_id,products_name from ".TABLE_PRODUCTS_DESCRIPTION." where language_id='$languages_id' order by products_name");
				$products_options_query=tep_db_query("select products_options_id,products_options_name from ".TABLE_PRODUCTS_OPTIONS." where language_id='$languages_id' order by products_options_name");
				$products_options_values_query=tep_db_query("select pov.products_options_values_id,pov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." pov, " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " povo where pov.language_id='$languages_id' and pov.products_options_values_id=povo.products_options_values_id and povo.products_options_id='$options_id' order by products_options_values_name");
				?>
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
					<tr><input type="hidden" name="service_id" id="service_id" value="<?php echo $products_id ?>">
					<!--<td class="TableHeading" align="right" width="100"><?php echo TEXT_PRODUCTS; ?></td>
					<td width="100" align="left" class="main">&nbsp;
					<select id="service_id" name="service_id" style="width:100px;">
					<?php while($product_description_array=tep_db_fetch_array($product_description_query)){ ?>
					<option value="<?php echo $product_description_array["products_id"]; ?>"<?php if($products_id==$product_description_array["products_id"]) echo ' selected '; ?>><?php echo $product_description_array["products_name"]; ?></option>
					<?php } ?>
					</select>
					</td>-->
						<td width="15%" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_NAME; ?></td>
						<td width="25%" class="main" align="left">&nbsp; <!-- populateOptions(document.attributes,document.attributes.options_id.options[document.attributes.options_id.selectedIndex].value) -->
						<select id="option_id" name="option_id" style="width:100px;" onChange="javascript: load_option(this);">
						<?php while($products_options_array=tep_db_fetch_array($products_options_query)){ ?>
						<option value="<?php echo $products_options_array["products_options_id"]; ?>"<?php if($options_id==$products_options_array["products_options_id"]) echo ' selected '; ?>><?php echo $products_options_array["products_options_name"]; ?></option>
						<?php } ?>
						</select>
						</td>
						<td width="15%" align="right" class="TableHeading"><?php echo TABLE_HEADING_OPT_VALUE; ?></td>
						<td  class="main" align="left" id="load_option_id_td">
						<select id="option_id_value" name="option_id_value" style="width:100px;">
						<?php while($products_options_values_array=tep_db_fetch_array($products_options_values_query)){ ?>
						<option value="<?php echo $products_options_values_array["products_options_values_id"]; ?>"<?php if($options_values_id==$products_options_values_array["products_options_values_id"]) echo ' selected '; ?>><?php echo $products_options_values_array["products_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" width="35%">&nbsp;
						<select name="price_prefix" id="price_prefix" style="width:60px">
						<option value="+" "<?php if($price_prefix=='+') echo "selected"; ?>">+</option>
						<option value="-" "<?php if($price_prefix=='-') echo "selected"; ?>">-</option></select>
						<?php //echo tep_draw_input_field('price_prefix',$price_prefix); ?></td>
					</tr>
					<tr><td colspan="4">&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"]:'';
			$products_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="-";
			$option_query=tep_db_query("select products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $products_id . "' and options_id='" . $option_id . "' and options_values_id='" . $option_id_value . "' and products_attributes_id!='" . $services_attributes_id. "'");
			if(tep_db_num_rows($option_query)>0) {
				echo 'error';
			}else {
				//$services_options_sort_order=isset($HTTP_GET_VARS["services_options_sort_order"])?$HTTP_GET_VARS["services_options_sort_order"]:'';
				tep_db_query("update ".TABLE_PRODUCTS_ATTRIBUTES." set products_id='$products_id',options_id='$option_id',options_values_id='$option_id_value',options_values_price='$options_values_price',price_prefix='$price_prefix' where products_attributes_id='$services_attributes_id'");
				products_attributes_load_function($products_id);
			}
			exit;
		break;
		case 'new_service_attribute':
			echo 'new_service_attribute^'; 
			$products_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"]:'';
			$values_id=isset($HTTP_GET_VARS["values_id"])?$HTTP_GET_VARS["values_id"]:'';
			$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='-';
			
			$option_query=tep_db_query("select products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $products_id . "' and options_id='" . $option_id . "' and options_values_id='" . $values_id . "'");
			if(tep_db_num_rows($option_query)>0) {
				echo 'error';
			} else {	
				tep_db_query("insert into ".TABLE_PRODUCTS_ATTRIBUTES." (products_id,options_id,options_values_id,options_values_price,price_prefix) values(
				'$products_id','$option_id','$values_id','$options_values_price','$price_prefix') ");
				$services_attributes_id=tep_db_insert_id();
				products_attributes_load_function($products_id);
				echo '^'.$services_attributes_id;
			}	
			exit;
		break;
		case 'sort_product_option';
			echo 'sort_product_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=='down') $sort_order--; else $sort_order++;
			tep_db_query("update ".TABLE_PRODUCTS_OPTIONS." set products_options_sort_order='$sort_order' where products_options_id='$option_id'");
			exit;
		break;	
		case 'sort_product_option_value':
			echo 'sort_product_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=='down')
				$sort_order--;
			if($type=='up')
				$sort_order++;
			tep_db_query("update ".TABLE_PRODUCTS_ATTRIBUTES." set products_options_sort_order='$sort_order' where products_attributes_id='$service_attribute_id'");
			exit;
		break;
		case 'delete_product_attributes':
			echo 'delete_product_attributes^';
			$attribute_id=isset($HTTP_GET_VARS["attribute_id"])?$HTTP_GET_VARS["attribute_id"]:'';
			$attrib_query=tep_db_query("select options_id,options_values_id,products_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_attributes_id='" . $attribute_id . "'");
			$attrib_result=tep_db_fetch_array($attrib_query);
				$attrib_array.= $attrib_result['options_id'] . '{' . $attrib_result['options_values_id']  . '}';
				$exists=false;
			//$attrib_array=$attrib_result['products_id'] . $attrib_array;
			$stock_query=tep_db_query('select * from ' . TABLE_PRODUCTS_STOCK . " where products_id='" . $attrib_result['products_id'] . "'");
			while($stock_result=tep_db_fetch_array($stock_query)) {
				$stock_array=split('-',$stock_result['attributes_id']);
				
				for($scnt=0,$stcnt=count($stock_array);$scnt<$stcnt;$scnt++) {
					if($stock_array[$scnt]==$attrib_array) {
						$exists=true;
						continue 2;
					}
				}
			}
			if($exists)
				echo 'error';
			else {	
				tep_db_query("delete from ".TABLE_PRODUCTS_ATTRIBUTES." where products_attributes_id='$attribute_id'");
				//services_attributes_load_function();
				//echo $attribute_id . '^';
				//echo $attrib_result['products_id'] . '^';
				products_attributes_load_function($attrib_result['products_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 pov.products_options_values_id,pov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." pov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS." povo where pov.products_options_values_id=povo.products_options_values_id and povo.products_options_id='$options_id' and pov.language_id='$languages_id'");
			echo '<select name="option_id_value" style="width:100px;" id="option_id_value">';
			while($option_value_array=tep_db_fetch_array($option_value_query)){
			?>
				<option value="<?php echo $option_value_array["products_options_values_id"]; ?>"><?php echo $option_value_array["products_options_values_name"]; ?></option>
			<?php
			}
			echo '</select>';
			exit;
		break;
		case 'load_option_value':
			echo 'load_option_value^';
			$options_id=isset($HTTP_GET_VARS["options_id"])?$HTTP_GET_VARS["options_id"]:'';
			$option_value_query=tep_db_query("select pov.products_options_values_id,pov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." pov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS." povo where pov.products_options_values_id=povo.products_options_values_id and povo.products_options_id='$options_id' and pov.language_id='$languages_id'");
			echo '<select name="values_id" style="width:120px;" id="values_id">';
			while($option_value_array=tep_db_fetch_array($option_value_query)){
			?>
				<option value="<?php echo $option_value_array["products_options_values_id"]; ?>"><?php echo $option_value_array["products_options_values_name"]; ?></option>
			<?php
			}
			echo '</select>';
			exit;
		break;
		case 'new_product_attribute_content_value':
			echo 'new_product_attribute_content_value^';
			$product_description_query=tep_db_query("select products_id,products_name from ".TABLE_PRODUCTS_DESCRIPTION." order by products_name");
			$products_options_query=tep_db_query("select products_options_id,products_options_name from ".TABLE_PRODUCTS_OPTIONS." order by products_options_name");
			
			?>
			<form name="attributes">
				<table width="100%" border="0" cellpadding="5" cellspacing="0" align="center" class="openContent">
					<tr class="openContent_top">
						<td class="main" colspan="3"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;New Product Attributes'; ?></td>		
						<td align="right" colspan="3"><?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>
					
					<input type="hidden" id="service_id" name="service_id" value="<?php echo $product_id;?>">
					<!--<td class="TableHeading" align="right" width="100"><?php echo TEXT_PRODUCT; ?> :</td>
					<td width="100" align="left" class="main">-->
					<!--<select id="service_id" name="service_id" style="width:100px;">
					<?php //while($product_description_array=tep_db_fetch_array($product_description_query)){ ?>
					<option value="<?php //echo $product_description_array["products_id"]; ?>"><?php //echo $product_description_array["products_name"]; ?></option>
					<?php //} ?>
					</select>
					</td>-->
					
					<tr>
						<td align="right" width="15%" class="TableHeading"><?php echo TABLE_HEADING_OPT_NAME; ?> :</td>
						<td class="main" width="25%" align="left">
						<select name="options_id" id="option_id" style="width:100px;" onChange="javascript: load_option_value(this);">
							<?php
							$options = tep_db_query("select * from " . TABLE_PRODUCTS_OPTIONS . " where language_id = '" . $languages_id . "' order by products_options_name");
							while($options_values = tep_db_fetch_array($options)) {
								if ($attributes_values['options_id'] == $options_values['products_options_id']) {
									echo "\n" . '<option name="' . $options_values['products_options_name'] . '" value="' . $options_values['products_options_id'] . '" SELECTED>' . $options_values['products_options_name'] . '</option>';
								} else {
									echo "\n" . '<option name="' . $options_values['products_options_name'] . '" value="' . $options_values['products_options_id'] . '">' . $options_values['products_options_name'] . '</option>';
								}
							} 
							?>
						</select>
						<?php
						$default_options_id=0;
						$default_options = tep_db_query("select * from " . TABLE_PRODUCTS_OPTIONS . " where language_id = '" . $languages_id . "' order by products_options_name");
						if(tep_db_num_rows($default_options)>0){
							$default_array=tep_db_fetch_array($default_options);
							$default_options_id=$default_array['products_options_id'];
						}
						if($default_options_id!=0){
							$option_value_query=tep_db_query("select pov.products_options_values_id,pov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." pov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS." povo where pov.products_options_values_id=povo.products_options_values_id and povo.products_options_id='$default_options_id' and pov.language_id='$languages_id'");
						}
						?>		
						</td>
						<td align="right" class="TableHeading" width="15%"><?php echo TABLE_HEADING_OPT_VALUE; ?> :</td>
						<td class="main" id="load_values_id" align="left">
						<select name="values_id" id="values_id" style="width:100px;">
							<?php if($default_options_id!=0){ 
									while($option_value_array=tep_db_fetch_array($option_value_query)){ ?>
									<option value="<?php echo $option_value_array["products_options_values_id"] ?>"><?php echo $option_value_array["products_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'); ?><select name="price_prefix" id="price_prefix" style="width:60px">
							<option value="+">+</option><option value="-">-</option></select> 
						</td>
					</tr>
					<tr><td colspan="4"><br></td></tr>
				</table>
			</form>
			<?php
			exit;
		break;
	}
	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="3" cellspacing="3">
		<tr><td><?php echo tep_draw_separator('pixel_trans.gif','1','1');?></td></tr>
		<tr>
			<td width="100%" class="dataTableHeadingRow"><?php echo HEADING_TITLE_OPT; ?></td>
		</tr>
		<tr>
			<td><table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr  class="dataTableHeadingRow">
					<td valign="bottom"><?php echo '<a onMouseOver="do_hover_change1(this,2);" onMouseOut="javascript: do_hover_change1(this,1);" id="base_header_new_operation" href="javascript: new_service_option();">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','Product Option','22','22').'</a>'; ?></td>
				</tr>
			</table></td>
		</tr>
		<tr>
			<td id="main_options_value_table">
				<?php echo products_options_value_list();?>			
			</td>
			<?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 class="dataTableHeadingRow"><?php echo HEADING_TITLE; ?></td>
		</tr>
		<tr>
			<td><table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr class="dataTableHeadingRow">
					<td valign="bottom"><?php echo '<a id="new_attribute_button" onMouseOver="attrib_do_hover(this,2)" onMouseOut="attrib_do_hover(this,1);" onclick="javascript: new_service_attribute();" style="cursor:pointer">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','Products Attributes','22','22').'</a>'; ?></td>
				</tr>
			</table></td>
		</tr>
		<?php
				//Load default products
			   $products_list=array();
			   if($command=='from_products_setup'){
				$get_products ="select products_id,products_name from products_description where products_id in(select products_id from products_to_categories where categories_id='$category_id') and language_id='". (int)$languages_id ."'";
			
			   }else{
			  	 $get_category= tep_db_query("select distinct categories_id from products_to_categories where products_id=(select min(products_id) as products_id from products_attributes) limit 1");	
			  	 $get_category_result=mysql_fetch_row($get_category);
			   	 $default_category=$get_category_result[0];
				 $get_products = "select products_id,products_name from products_description where products_id in(select products_id from products_to_categories where categories_id='$default_category') and language_id='". (int)$languages_id ."'";
				}
				$products_list[]=array('id'=>0,'text'=>TEXT_ALL_PRODUCT);
				$prd_fill='no';
				$get_products_query=tep_db_query($get_products);
				while($products=tep_db_fetch_array($get_products_query)){
					$products_list[]=array('id'=>$products['products_id'],'text'=>$products['products_name']);
					if($prd_fill=='no') $default_product=$products['products_id'];
					$prd_fill='yes';
			  }
			  if($command=='from_products_setup'){
				  $default_category=$category_id;
				 $default_product=$product_id;
			  }
		?>	
		<tr>
			<td><table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr class="dataTableHeadingRow">
				<td valign="bottom" class="dataTableHeadingRow" width="30%">Select Category :<?php echo '&nbsp;&nbsp;'. tep_draw_products_select_menu1('category_selection',$products_array,$default_category,' id="category_selection" onchange="javascript:call_products_load(this)"'); ?></td>
				<td class="dataTableHeadingRow"><div id="products_menu_div">Select Product :<?php echo '&nbsp;&nbsp;'.tep_draw_pull_down_menu('products_menu',$products_list,$default_product,'id="products_menu" onchange="javascript:call_attribute_details(this)"');?></div></td>
				</tr>
			</table></td>
		</tr>
		<tr>
			<td>
				<table width="100%" cellpadding="0" cellspacing="0" border="0">
					<tr class="dataTableHeadingRow">
						<td class="TableHeading" nowrap="nowrap" width="25%"><?php echo TEXT_PRODUCT; ?></td>
						<td class="TableHeading" nowrap="nowrap" width="25%"><?php echo TABLE_HEADING_OPT_NAME; ?></td>
						<td class="TableHeading" nowrap="nowrap" width="20%"><?php echo TABLE_HEADING_OPT_VALUE; ?></td>
						<td class="TableHeading" nowrap="nowrap" width="20%"><?php echo TABLE_HEADING_OPT_PRICE; ?></td>
						<td class="TableHeading" nowrap="nowrap" width="10%"><?php echo TEXT_PREFIX; ?></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td id="services_attributes_load_id">
			<?php if($command=='from_products_setup') $passing_product_id=$default_product;
				  else  $passing_product_id=$products_list[1]['id'];
				  products_attributes_load_function($passing_product_id,'product'); ?>
			</td>
		</tr>
	</table>
	<div id="new_service_attribute_content" style="display:none;"></div>

<!-- Ajax Works Ends -->

	<div id="sample"></div>
	<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">
	var display_flag=1;	
    var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";

	function  call_products_load(obj){
		var category_id='',command='';
		var products_menu = document.getElementById('products_menu');
		category_id=obj.options[obj.selectedIndex].value;
		if(category_id<0){
			alert('Category should be selected');
			return false;
		 }//if ALl Categories selected, v call call_attribute_details()
		 if(category_id==0){
			 var menu_length=document.getElementById('products_menu').length;
			for(jcnt=menu_length;jcnt>0;jcnt--){
				if(products_menu.options[jcnt]) products_menu.remove(jcnt);
			}
			 call_attribute_details(obj);	
			  return false;
		 }
		command="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=load_products&category_id='); ?>"+category_id; 
		do_get_command(command);
	}
	function call_attribute_details(obj){
		var product_id='',command='';
		var products_menu=document.getElementById('products_menu');
		var category_selection=document.getElementById('category_selection');
		product_id=obj.options[obj.selectedIndex].value;
		if(product_id<0){
			alert('Product should be selected');
			return false;
		 }
		// alert (products_menu.options[products_menu.selectedIndex].value);
		 if(products_menu.options[products_menu.selectedIndex].value==0 && category_selection.options[category_selection.selectedIndex].value!=0){
			category_id=category_selection.options[category_selection.selectedIndex].value;
				  	var cmd='&cmd=load_by_category&category_id='+category_id;
					
		 } else {
		 category_id=category_selection.options[category_selection.selectedIndex].value;
				  	var cmd='&cmd=load_by_category&category_id='+category_id;
					
		 
		 }
		 
		command="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=load_attribute_details&product_id='); ?>"+product_id+cmd; 
		do_get_command(command);
	}
	 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 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_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_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 attrib_display_flag=1;	
	function attrib_do_hover(element,mode){ 
	if(attrib_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 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_PRODUCTS_ATTRIBUTES,'command=sort_product_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_PRODUCTS_ATTRIBUTES,'command=sort_product_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">
	<?php 
	$products_option_query=tep_db_query("select products_options_id from ".TABLE_PRODUCTS_OPTIONS." order by products_options_sort_order "); 
	$products_options_value_query=tep_db_query("select products_options_values_id from ".TABLE_PRODUCTS_OPTIONS_VALUES." order by products_options_values_id");
	//$products_attributes_query=tep_db_query("select products_attributes_id from ".TABLE_PRODUCTS_ATTRIBUTES." order by products_attributes_id");
	$products_attributes_query=tep_db_query($get_products. " limit 1");
	$products_attributes_array=tep_db_fetch_array($products_attributes_query);
	$pro_attrib_query=tep_db_query("select products_attributes_id from ".TABLE_PRODUCTS_ATTRIBUTES."  where products_id='" . $products_attributes_array['products_id'] . "' order by products_attributes_id");
	
	?>
	var option_id_array=new Array();
	var option_id_value_array=new Array();
	var services_attributes_id_array=new Array();
	var productsid='<?php echo $products_attributes_array['products_id'];?>';
	
	<?php $cnt=0; while($products_option_array=tep_db_fetch_array($products_option_query)){ ?>	
	option_id_array[<?php echo $cnt; ?>]=<?php echo $products_option_array["products_options_id"]; ?>;
	<?php $cnt++; } ?>

	<?php $icnt=0; while($products_options_value_array=tep_db_fetch_array($products_options_value_query)){ ?>
	option_id_value_array[<?php echo $icnt; ?>]=<?php echo $products_options_value_array["products_options_values_id"]; ?>;
	<?php $icnt++; } ?>
	
	<?php $cnt=0; while($pro_attrib_result=tep_db_fetch_array($pro_attrib_query)){ ?>
	services_attributes_id_array[<?php echo $cnt; ?>]=<?php echo $pro_attrib_result["products_attributes_id"]; ?>;
	<?php $cnt++; } ?>
	</script>
	<script language="javascript">
	var previous_option_id='',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';
		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='';
			}
		}
	if(document.getElementById('ajax_opt_'+opt_id)){	
		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_PRODUCTS_ATTRIBUTES,'command=opt_load_details&opt_id='); ?>"+opt_id;
	do_get_command(command);
			document.getElementById('new_service_option_value_content').style.display='none';
	}
	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='';
		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='';
			}
		}
		if(document.getElementById('ajax_'+option_id)){
		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_PRODUCTS_ATTRIBUTES,'command=load_details&option_id='); ?>"+option_id;
	do_get_command(command);
	previous_option_id=option_id;
	}
	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 ++) { ?>
		obj=document.getElementById('products_option_name[<?php echo $languages[$i]['id']; ?>]').value;
		//alert (obj);
			if(obj=='' || str_trim(obj)==''){
			error=true;
			error_message='<?php echo EMPTY_OPTION_NAME; ?>';
			}
		<?php } ?>
	if(check_flag){
		var length=document.getElementById('options_values').length;
		var listbox=document.getElementById('options_values');
		var source = '';
		for(icnt=0;icnt<length;icnt++){
			//alert('id:'+listbox.options[icnt].value+'text:'+listbox.options[icnt].text);
			source += listbox.options[icnt].value+'^'+listbox.options[icnt].text +'#';
		}
		document.getElementById('source').value=source;
		document.getElementById('work_values').value="exists";
	}	
		
	if(error==true)
		alert(error_message);
	else{	
	 
	 do_post_command('save_edit_option_name_form','<?php echo tep_href_link(FILENAME_PRODUCTS_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='';
		/*document.getElementById('opt_'+opt_id).style.background="#FFFFFF";
		document.getElementById('opt_'+opt_id).style.display=''; 
		document.getElementById('ajax_opt_'+opt_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;*/
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) { ?>
		name=document.getElementById('products_options_values_name[<?php echo $languages[$i]['id']; ?>]').value ;
			if(name=='' || str_trim(name)==''){
			error=true;
			error_message='<?php echo EMPTY_OPTION_NAME; ?>';
			}
		<?php } ?>
	if(error==true)
		alert(error_message);
	else{	
	do_post_command('save_edit_option_value_form','<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=save_opt_values&opt_id='); ?>'+opt_id);	
	}
	}
	function drop_products_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_PRODUCTS_ATTRIBUTES,'command=drop_products_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_PRODUCTS_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_PRODUCTS_ATTRIBUTES,'command=page_navigation_option'); ?>&page="+page_no;
		else if(agr2==2) command="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=page_navigation_attribute'); ?>&page="+page_no + '&product_id=' + productsid;		
		if(command!="") do_get_command(command);
	}	
	function load_option_value(that){
	var command="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=load_option_value&options_id='); ?>"+that.value;
	document.getElementById('load_values_id').innerHTML=document.getElementById('ajax_image_load').innerHTML;
	do_get_command(command);
	}
	function do_result(result){
	//alert (result);
	var token=result.split('^');
	var page_no=1;
	var option_id=token[1]; var opt_id=token[1]; var attributes_id=token[1];
		switch(token[0]){
		case 'load_products':
			  document.getElementById('products_menu_div').innerHTML=token[1];
			  if(token[2] && token[2]=='empty')
			  	document.getElementById('services_attributes_load_id').innerHTML='<table cellpadding="0" cellspacing="0" width="100%"><tr><td align="center" class="main">No Attribute Details Found</td></tr></table>';
  			  else 	{
			  	if(document.getElementById('products_menu') && document.getElementById('products_menu').options[document.getElementById('products_menu').selectedIndex].value)
			  		 call_attribute_details(document.getElementById('products_menu'));
			  }	 
			  break;
		case 'load_attribute_details':
				productsid=token[1];
			  document.getElementById('services_attributes_load_id').innerHTML=token[2];
			 if(document.getElementById('attrib_id_list')){
				  if(document.getElementById('attrib_id_list').value!='') {
					services_attributes_id_array=''; 
					services_attributes_id_array=document.getElementById('attrib_id_list').value.split(',');
					acnt=0;
					//for(scnt=0,stcnt=spl.length;scnt<stcnt;scnt++){ //alert(spl[scnt]);
					//	services_attributes_id_array[acnt]=spl[scnt];alert(services_attributes_id_array[scnt]); acnt++;
					//}
				  }	
				}  
			  break;		  
		case 'post_save_product_option_form':
			document.getElementById('main_options_value_table').innerHTML=token[1];
			break;
		case 'load_option_value': 
			document.getElementById('load_values_id').innerHTML=token[1];
			break;
		case 'new_product_attribute_content_value':
			document.getElementById('new_service_attribute_content').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();";
			break;
		case 'save_option_name':
			document.getElementById('attrib_'+option_id).style.display='';
			document.getElementById('attrib_'+option_id).innerHTML=token[2];
			document.getElementById('ajax_'+option_id).style.display='none';
			document.getElementById('ajax_'+option_id).innerHTML='';
			document.getElementById('base_header_new_operation').href="javascript: new_service_option();";
			break;
		case 'drop_products_options':
			var row_index=document.getElementById('services_option_row_'+option_id).rowIndex;
			document.getElementById('base_header_new_operation').href="javascript: new_service_option();";
			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_PRODUCTS_ATTRIBUTES,'command=page_navigation_option');?>&page="+page_no;
			do_get_command(command);
			break;
		case 'drop_fail_services_options':
			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;
 	 		}
			command="<?php echo tep_href_link(FILENAME_PRODUCTS_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];
			document.getElementById('header_operation_id').style.display='';
			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':
			if(token[1]=='error'){
				alert("* Attributes already exists for the selected product");
			} else {
				document.getElementById('services_attributes_load_id').innerHTML=token[1];
				close_new_service_attribute();
			}
			break;
		case 'new_service_attribute': 
			if(token[1]=='error') {
				alert('* Attributes already exists for the selected product');
			} else {	
				document.getElementById('services_attributes_load_id').innerHTML=token[1];
				//services_attributes_id_array[services_attributes_id_array.length-1]=token[2];
				services_attributes_id_array[services_attributes_id_array.length]=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_PRODUCTS_ATTRIBUTES,'command=page_navigation_attribute');?>&page="+page_no;
				//do_get_command(command);
			}	
			break;
		case 'delete_product_attributes':
			//document.getElementById('services_attributes_load_id').innerHTML=token[1];
			if(token[1]=='error') {
				alert('* This attibute is linked with this products.');
				return;
			} else {	
				close_new_service_attribute();
				document.getElementById('services_attributes_load_id').innerHTML=token[1];
				/*var row_index=document.getElementById('service_attribute_value_'+token[1]).rowIndex;
				document.getElementById('service_attribute_table').deleteRow(row_index);*/		
				
			  if(document.getElementById('attrib_id_list') && (document.getElementById('attrib_id_list').value!='')) {
			    services_attributes_id_array=''; 
				services_attributes_id_array=document.getElementById('attrib_id_list').value.split(',');
			 }	
				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_PRODUCTS_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 'page_navigation_option':			
			document.getElementById('main_options_value_table').innerHTML=token[1];
			break;	
		case 'page_navigation_attribute':
			  if(document.getElementById('attrib_id_list') && (document.getElementById('attrib_id_list').value!='')) {
			    services_attributes_id_array=''; 
				services_attributes_id_array=document.getElementById('attrib_id_list').value.split(',');
			}	
			document.getElementById('services_attributes_load_id').innerHTML=token[1];
		break;
		}
	}
	
	function do_hover_change(element,mode){
		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 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){
			/*if(document.getElementById('opt_'+opt_id) && document.getElementById('ajax_opt_'+opt_id)){
			display_flag=0;
			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(){
	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 EMPTY_OPTION_NAME; ?>";
			}
		<?php } ?>
		if(error==true)
			alert(error_message);
		else{
		change_new_image();
		do_post_command('save_product_option_form','<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=post_save_product_option_form'); ?>');
		close_new_service_option();
		}
	}
	function save_new_service_option_value(opt_id){
	error=false; error_message="";
		<?php for($i=0,$n=sizeof($languages);$i<$n;$i++){ ?>
		   nam=document.getElementById('products_option_value[<?php echo $languages[$i]['id']; ?>]').value;
			if(nam=='' || str_trim(nam)==''){
			error=true; error_message="<?php echo ERROR_OPTION_VALUE; ?>";
			}
		<?php } ?>
	
		if(error==true)
			alert(error_message);
		else{
		change_new_image();
		do_post_command('new_product_option_value_form','<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=save_new_service_option_value&opt_id='); ?>'+opt_id);
		close_new_service_option_value();
		}
	}
	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();
	if(document.getElementById('new_service_option_content')) document.getElementById('new_service_option_content').style.display='none';
			<?php for($i=0,$n=sizeof($languages);$i<$n;$i++){ ?>
			document.getElementById('option_name[<?php echo $languages[$i]['id']; ?>]').value='';
			<?php } ?>
	}
	function close_new_service_option_value(){
	change_new_image();
	document.getElementById('new_service_option_value_content').style.display='none';
		<?php for($i=0,$n=sizeof($languages);$i<$n;$i++){ ?>
		document.getElementById('products_option_value[<?php echo $languages[$i]['id']; ?>]').value='';
		<?php } ?>
	}
	function attributes_edit(){
	document.getElementById('edit_details_id').style.display='';
	if(document.getElementById('delete_option_att')) document.getElementById('delete_option_att').style.display='none';
	document.getElementById('header_edit_display').style.display='';
	}
	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_PRODUCTS_ATTRIBUTES,'command=load_services_attributes&attributes_id='); ?>"+attributes_id;
	do_get_command(command);
	}
	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)==''){ 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(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_PRODUCTS_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 new_attribute_image_change(){
	document.getElementById('new_attribute_button').firstChild.src=document.getElementById('new_attribute_button').firstChild.src.replace('_hover.gif','.gif');
	attrib_display_flag=1;
	}
	function new_service_attribute(attribute_id){
	attrib_display_flag=0;
	var product_id='',category_id='';
	
	if(document.getElementById('products_menu'))  product_id=document.getElementById('products_menu').options[document.getElementById('products_menu').selectedIndex].value;
	if(document.getElementById('category_selection'))  category_id=document.getElementById('category_selection').options[document.getElementById('category_selection').selectedIndex].value;
	if(category_id<1 && product_id<1){
		alert('Category and Product must be selected');
		return false;
	}else if(category_id<1){
		alert('category must be selected');
		return false;
	}else if(product_id<1){
		alert('Product must be selected');
		return false;
	}
			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='';
		}
	if(document.getElementById('attribute_'+attribute_id))
		document.getElementById('attribute_'+attribute_id).style.display='';
	document.getElementById('new_service_attribute_content').style.display='';
	document.getElementById('new_service_attribute_content').innerHTML=document.getElementById('ajax_image_load').innerHTML;
		close_new_service_option();
	// check whether categories and products menu are selected
	
	var command="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=new_product_attribute_content_value&product_id='); ?>"+product_id;
	do_get_command(command);
		if(previous_option_id!=''){
		document.getElementById('ajax_'+previous_option_id).innerHTML='';
		document.getElementById('ajax_'+previous_option_id).style.display='none';
		document.getElementById('attrib_'+previous_option_id).style.display='';
		document.getElementById('base_header_new_operation').href="javascript: new_service_option();";
		}
	}
	function close_new_service_attribute(){
	//new_attribute_image_change();
	document.getElementById('new_service_attribute_content').style.display='none';
	}
	function save_new_service_attribute(){ 
	//new_attribute_image_change();
	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=='' || str_trim(values_id)==''){ 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_PRODUCTS_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);
		}
	}
	function delete_product_attributes(attribute_id){
	document.getElementById('delete_details').style.display='';
	document.getElementById('edit_details').style.display='none';
	var command="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES,'command=delete_product_attributes&attribute_id='); ?>"+attribute_id;	
	do_get_command(command);
	}

	</script>
	<script language=JavaScript>
	check_flag=false;
	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(that){
		//document.getElementById('option_ids').length=0;
		var command="<?php echo tep_href_link(FILENAME_PRODUCTS_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 do_breaks_hover_change(action,mode,obj){
		if(mode==1){
			obj.src=img_src+"template/" + action + "_hover.gif";
		} else if(mode==2){
			obj.src=img_src+"template/" + action + ".gif";
		}
	}
	function do_opt_value_select(mode){
		var optionElement = document.getElementById('options_values');
		var pos=optionElement.length;
	  if(mode=='update' || mode=='add' || mode=='delete'){
		 document.getElementById('header_edit_display').style.display='';
	  }
	  switch(mode){
			 case "select" :
							sIndex=document.getElementById('options_values').selectedIndex;
							if(sIndex<0) return;
							var text=document.getElementById('options_values').options[sIndex].text;
							document.getElementById('opt_val_name').value=text;
							break;
			 case "update":
			 case "add":
							var option = document.createElement('OPTION'); 
							option.text = document.getElementById('opt_val_name').value;
							option.value = document.getElementById('opt_val_name').value;
							var new_input = document.getElementById('opt_val_name').value;
							sIndex=document.getElementById('options_values').options.selectedIndex;
							if(check_dublicate(new_input,mode)){
								if (mode=="update") { 
									if(sIndex<0) return;
									document.getElementById('options_values').options[sIndex].text=new_input;
									 optionElement.remove(sIndex);	
									check_flag=true;
									//break;
								}	
								if(optionElement.add.length==2){
								optionElement.add(option,null);
								}	else {
								 optionElement.add(option,pos);
								}check_flag=true;
								 document.getElementById('opt_val_name').value='';
							} 
							
							 
							break;
			case "delete":
						  sIndex=optionElement.selectedIndex;
						  if(sIndex<0) return;
						  optionElement.remove(sIndex);	
						  if(optionElement.length==0) break;
						  sIndex=sIndex-1;
						  if(sIndex==-1) sIndex=0; 
						  if(  (optionElement.options[sIndex].text) && sIndex>0 )
							 optionElement.selectedIndex=sIndex;
						  else  optionElement.selectedIndex=sIndex;	
						  document.getElementById('opt_val_name').value='';
						  check_flag=true;
				 }
	}
	function check_dublicate(value,mode){ 
	 var selectbox=document.getElementById('options_values');
	 var length = document.getElementById('options_values').length;
	 var sIndex=-1;
	 if(mode=='update')
		 sIndex=document.getElementById('options_values').options.selectedIndex;
	 var error_msg='';
	 if(value==''){
		alert('* Give Valid Option Value');
		return false;
	  }
	 
	 if(length>0){
		for(j=0;j<length;j++){
			if(value==selectbox.options[j].text && sIndex!=j) error_msg='* Option Values already exists';
		}
		if(error_msg==''){ return true;
		}else{
		  alert(error_msg);
		  return false;
		 }
	  }else return true
	}
	
	function o_close(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 bsoclose(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();";
	}
	</script>   

	<?php
	function products_options_value_list(){  
		global	$languages_id,$page,$languages;	
		$products_option_raw="select products_options_name,products_options_id from ".TABLE_PRODUCTS_OPTIONS." where language_id='$languages_id' order by products_options_sort_order";
		$products_options_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $products_option_raw, $products_option_numrows);	    
		$products_option_query = tep_db_query($products_option_raw);	
		$row_count=0;	
		?>
		<div style="color:#FF0000;" id="attrib_delete_flag"></div>   	
		<table id="services_option_table" width="100%" cellpadding="2" cellspacing="2" border="0">
		<?php $row=1; 
		while($products_option_array=tep_db_fetch_array($products_option_query)){ 
			if($row%2==0) $class_name="dataTableRowEven"; else $class_name="dataTableRowOdd";
			$row++;
		?>
			<tr id="services_option_row_<?php echo $products_option_array["products_options_id"]; ?>">
				<td class="main">
					<div id="attrib_row_<?php echo $products_option_array["products_options_id"]; ?>" onClick="javascript:row_focus(<?php echo $products_option_array["products_options_id"]; ?>);">
						<div onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="attrib_<?php echo $products_option_array["products_options_id"]; ?>" class="<?php echo $class_name; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif') .'&nbsp;&nbsp;'. $products_option_array["products_options_name"]; ?></div>
					</div>
					<div id="ajax_row_<?php echo $products_option_array["products_options_id"]; ?>">
						<div id="ajax_<?php echo $products_option_array["products_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 $products_options_split->display_count($products_option_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_PRODUCTS_OPTIONS); ?></td>
						<td class="smallText" align="right"><?php echo $products_options_split->display_script_links($products_option_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'page_navigation(\'\'','1'); ?></td>
					  </tr>
				   </table>
			  </td>
		</tr>
		</table>
		<div id="new_service_option_content" style="display:none;" class="openContent">
		<?php echo tep_draw_form('save_product_option_form',FILENAME_SERVICE_ATTRIBUTES,'','post'); ?>
			<table width="100%" cellpadding="2" cellspacing="2" border="0">
			<tr class="openContent_top">
				<td class="main"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;New Product Option';	?></td>
				<td align="right"><?php echo '<a href="javascript:void save_new_service_option();">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a id="close_new_service_option_id" 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>';
				}
			?>
			</td></tr>
			<tr><td colspan="2"><br></td></form></td></tr>
			</table>
		</div>
<?php }

	function products_attributes_load_function($product_id,$mode='product'){ 
		global $languages_id,$page;
	 	
	 	if($mode=='category'){ 
			$get_products_id=tep_db_query("select products_id from products_to_categories where categories_id='$product_id'");
		   if(tep_db_num_rows($get_products_id)>0){	
				while($get_products=tep_db_fetch_array($get_products_id)){
					$products_id .= $get_products['products_id'].',';
			 }$products_id = substr($products_id,0,-1);
		 
		   if($products_id !='') $products_attributes_query_raw="select sa.products_attributes_id,sd.products_name,options_id,options_values_id,options_values_price,price_prefix from ".TABLE_PRODUCTS_ATTRIBUTES." sa, ".TABLE_PRODUCTS_DESCRIPTION." sd where sa.products_id=sd.products_id and sa.products_id in ( $products_id ) and sd.language_id='$languages_id' order by sa.products_options_sort_order";
		
		//if($product_id<1) $products_attributes_query_raw="select sa.products_attributes_id,sd.products_name,options_id,options_values_id,options_values_price,price_prefix from ".TABLE_PRODUCTS_ATTRIBUTES." sa, ".TABLE_PRODUCTS_DESCRIPTION." sd where sa.products_id=sd.products_id and sd.language_id='$languages_id' order by sa.products_options_sort_order";

		}//echo $products_attributes_query_raw;
		}else{
			if($product_id<1) $products_attributes_query_raw="select sa.products_attributes_id,sd.products_name,options_id,options_values_id,options_values_price,price_prefix from ".TABLE_PRODUCTS_ATTRIBUTES." sa, ".TABLE_PRODUCTS_DESCRIPTION." sd where sa.products_id=sd.products_id and sd.language_id='$languages_id' order by sa.products_options_sort_order";
			else $products_attributes_query_raw="select sa.products_attributes_id,sd.products_name,options_id,options_values_id,options_values_price,price_prefix from ".TABLE_PRODUCTS_ATTRIBUTES." sa, ".TABLE_PRODUCTS_DESCRIPTION." sd where sa.products_id=sd.products_id and sa.products_id='$product_id' and sd.language_id='$languages_id' order by sa.products_options_sort_order";
		}
		$products_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $products_attributes_query_raw, $products_query_numrows);
		$products_attributes_query = tep_db_query($products_attributes_query_raw); 
	?>
		<table width="100%" border="0" id="service_attribute_table" cellpadding="2" cellspacing="2">
		<?php $row=1; 
			if(tep_db_num_rows($products_attributes_query)>0){
				while($products_attributes_array=tep_db_fetch_array($products_attributes_query)){ 
					if($row%2==0) $class_name='dataTableRowEven'; else $class_name='dataTableRowOdd';
					$row++; 
					$options_id=$products_attributes_array["options_id"];
					$options_values_id=$products_attributes_array["options_values_id"];
					$products_options_name_query=tep_db_query("select products_options_name from ".TABLE_PRODUCTS_OPTIONS." where products_options_id='$options_id' and language_id='$languages_id'");
					$products_options_name_array=tep_db_fetch_array($products_options_name_query);	
					$products_options_values_query=tep_db_query("select products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." where products_options_values_id='$options_values_id'");
					$products_options_values_array=tep_db_fetch_array($products_options_values_query);
				?>
				<tr id="service_attribute_value_<?php echo $products_attributes_array["products_attributes_id"]; ?>">
				<td width="100%" class="main">
					<div class="<?php echo $class_name; ?>" id="attribute_row_<?php echo $products_attributes_array["products_attributes_id"]; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" onClick="javascript: attribute_row_focus(<?php echo $products_attributes_array["products_attributes_id"]; ?>);">
						<div id="attribute_<?php echo $products_attributes_array["products_attributes_id"]; ?>">
							<table width="100%" cellpadding="0" cellspacing="0" border="0">
								<tr>
									<td class="main" nowrap="nowrap" width="25%"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$products_attributes_array["products_name"]; ?></td>
									<td class="main" width="25%"><?php echo $products_options_name_array["products_options_name"]; ?></td>
									<td class="main" width="20%"><?php echo $products_options_values_array["products_options_values_name"]; ?></td>
									<td class="main" width="20%"><?php echo $products_attributes_array["options_values_price"]; ?></td>
									<td class="main" width="10%"><?php echo $products_attributes_array["price_prefix"]; ?></td>
								</tr>
							</table>
						</div>
					</div>
					<div id="attribute_ajax_row_<?php echo $products_attributes_array["products_attributes_id"]; ?>">
						<div id="attribute_ajax_<?php echo $products_attributes_array["products_attributes_id"]; ?>" style="display:none;"></div>
					</div>
				</td>
				</tr>
			<?php } 
		 }else{?>
			<tr><td class="main" align="center">No Attribute Details Found</td></tr>
		<?php  }?>
		</table>
		<?php $id_list='';
			$pro_attrib_query=tep_db_query("select products_attributes_id from ".TABLE_PRODUCTS_ATTRIBUTES."  where products_id='" . $product_id . "' order by products_attributes_id");
			if(tep_db_num_rows($pro_attrib_query) >0) {
				while($pro_attrib_result=tep_db_fetch_array($pro_attrib_query)){
					$id_list.=$pro_attrib_result['products_attributes_id'] . ',';
				}
				$id_list=substr($id_list,0,-1);
			}//echo $id_list;
		?>
		<input type="hidden" id="attrib_id_list" value="<?php echo $id_list;?>">
		<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 $products_split->display_count($products_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_PRODUCTS_ATTRIBUTES); ?></td>
							<td class="smallText" align="right"><?php echo $products_split->display_script_links($products_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,2,'page_navigation(\'\'','2'); ?></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
<?php 
	} 
	
	function load_services_options_value($opt_id){
		global $languages_id;
		$products_options_values_query=tep_db_query("select sov.products_options_values_id,sov.products_options_values_name from ".TABLE_PRODUCTS_OPTIONS_VALUES." sov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " sovo where sov.language_id='$languages_id' and sovo.products_options_id='$opt_id' and sov.products_options_values_id=sovo.products_options_values_id order by products_options_values_name");
		?>
		<?php while($products_options_values_array=tep_db_fetch_array($products_options_values_query)){ ?>
			<div class="main" id="opt_row_<?php echo $products_options_values_array["products_options_values_id"]; ?>" onClick="javascript:opt_row_focus(<?php echo $products_options_values_array["products_options_values_id"]; ?>);">
				<div class="dataTableRowOdd" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" id="opt_<?php echo $products_options_values_array["products_options_values_id"]; ?>"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.$products_options_values_array["products_options_values_name"]; ?></div>
			</div>
			<div id="ajax_opt_row_<?php echo $products_options_values_array["products_options_values_id"]; ?>">
				<div id="ajax_opt_<?php echo $products_options_values_array["products_options_values_id"]; ?>" style="display:none;"></div>
			</div>
	<?php } 
} ?>
<?php
	function tep_get_products_output_tree1($parent_id = '0',&$content,$default,$product_category_id=0,$level='0') {
		global $customer_group_id,$customer_id,$languages_id,$selected_name,$login_id,$login_groups_type;
	
		// iterate with nested category
		
		$products_where = "";
		if($product_category_id>0)  $products_where = " and c.categories_id='" . $product_category_id . "' ";
		if($parent_id>0) { 
			$space='';
			for($j=0;$j<$level;$j++)
			 $space .= '&nbsp;&nbsp;';	
		}else{
		   $level=0;			
		}
		$categories_sql = "select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' " . $products_where . " order by c.sort_order, cd.categories_name";
		$categories_query = tep_db_query($categories_sql);
		while ($products_category = tep_db_fetch_array($categories_query)) {
			$content.= '<option style="color:#0000FF" ' . (($default==$products_category['categories_id'])?'SELECTED':''). ' value="' . $products_category['categories_id'] .'">'. $space. tep_output_string($products_category['categories_name'], array('"' => '&quot;', '\'' => '&#039;', '<' => '&lt;', '>' => '&gt;')) ;
	
			tep_get_products_output_tree1($products_category['categories_id'],$content,$default,'',$level+1);
		}
	}
	function tep_draw_products_select_menu1($name, $values,$selected_vals,  $parameters = '', $required = false,$initial_category_id=0,$need_all=true,$initial_parent_id=0) {
		global $selected_name;
		
		$field = '<select name="' . tep_output_string($name) . '"';
	
		if (tep_not_null($parameters)) $field .= ' ' . $parameters;
		$field.=' class="inputNormal" onBlur="javascript:toggle_focus(this,1);" onFocus="javascript:toggle_focus(this,2);"';
		$field .= '>';
		if($need_all)
		$field .= '<option style="color:#000000" value="0">' . TEXT_ALL_CATEGORIES . '</option>';
		if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);
		$content="";
		tep_get_products_output_tree1($initial_parent_id,$content,$selected_vals,$initial_category_id,'0');
		$field.=$content;
		$field .= '</select>';
		
		if ($required == true) $field .= TEXT_FIELD_REQUIRED;
		return $field;
	}
	?>