<?php
/*

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

Copyright (c) 2005 osCommRes

Released under the GNU General Public License

Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
  require('includes/application_top.php');
  require(DIR_WS_CLASSES . 'split_page_results_event.php');
  require('includes/languages/'.$language.'/subscriptions_create.php');
  require('includes/functions/categories_description.php');  	
  require('includes/languages/'.$language.'/subscriptions_mainpage.php');
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
  require('subscriptions_create_ajax.php');
  $command=(isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'');
  $page=(isset($HTTP_GET_VARS['page'])?$HTTP_GET_VARS['page']:'1');
  $cID=(isset($HTTP_GET_VARS['cID'])?$HTTP_GET_VARS['cID']:0);
  $level=(isset($HTTP_GET_VARS['level'])?$HTTP_GET_VARS['level']:0);
  $show_order=(isset($HTTP_GET_VARS['show_order'])?$HTTP_GET_VARS['show_order']:'AN');
  $open_ids=isset($HTTP_GET_VARS["open_ids"])?$HTTP_GET_VARS["open_ids"] . ",":'';
  
  if($command!=''){
  $commands[]=$command;
	for($icnt=0;$icnt<count($commands);$icnt++){
	switch($commands[$icnt]){
		case 'fetch_sub_list':
		case 'fetch_sub_list_open':
			echo 'command||fetch_sub_list{}category||' . $cID . '{}page||' . $page . '{}result||';
			echo output_sub_result($cID,$page,$show_order,$level,$open_ids);
			break;
		case 'fetch_all_list':
			$cID=substr($open_ids,0,strpos($open_ids,","));
			if($cID=='') $cID=str_replace(",","",$open_ids);
			if($icnt==1) $cID=0;
			echo 'command||' . $command . '{}category||' . $cID . '{}page||' . $page . '{}result||';
			echo output_sub_result($cID,$page,$show_order,$level,$open_ids);
			break;
		case 'do_sort_list':	
			do_sort($show_order,$level);
			$commands[]="fetch_all_list";
			break;
		case 'fetch_sub_products':
			echo 'command||fetch_sub_products{}category||' . $cID . '{}page||' . $page . '{}result||';
			echo output_products_result($cID,$page,$show_order);
			break;
		case 'subscription_search':
			echo 'subscription_search^';
			global $languages_id,$global_categories_id;	
			$subscription_search=isset($HTTP_GET_VARS['subscription_search'])?tep_db_prepare_input($HTTP_GET_VARS['subscription_search']):'';
			
			$global_categories_id=0;
			$categories_sql = tep_db_query("select c.subscription_categories_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " c, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " cd where c.subscription_categories_id = cd.subscription_categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = 0 and cd.subscription_categories_name like '%" . tep_db_input($subscription_search) . "%' order by c.sort_order, cd.subscription_categories_name");

			if(tep_db_num_rows($categories_sql)>0){
				$categories_array=tep_db_fetch_array($categories_sql);
				$global_categories_id=$categories_array['subscription_categories_id'];				
			}
			output_sub_result(0,1,'A',0,'',1,$subscription_search);
			//output_subscription_search_result($subscription_search);
			echo '<div align="right"><a href="javascript: reset_search();">'. tep_image_button('button_reset.gif', IMAGE_RESET).'</a></div>';
			break;
		case 'reset_search':
			echo 'reset_search^';
			output_sub_result(0,1,'A',0,'',1);
			break;
	}
  }
	exit;  
  }  
	tep_get_subscription_cat_ajax_list(0,0,"open_ids",$jmp_results,$jmp_open_ids);
	tep_get_last_access_file();
	$pro_id=isset($HTTP_GET_VARS['sID'])?$HTTP_GET_VARS['sID']:0;	
	$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
	$tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
	while ($tax_class = tep_db_fetch_array($tax_class_query)) {
	  $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
								 'text' => $tax_class['tax_class_title']);
	} 

?>
<!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>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/editor.js"></script> 
<script language="javascript" src="includes/aim.js"></script>
<script>
var cat_expand;
var count = 0;
var id = new Array();
var category_list = new Array();
var default_category = '';
var panel_expand;
var panel_expand_id;
var ids = new Array();
var page='<?php echo $page;?>';
var order='<?php echo $order;?>';
var prev_value;
 
function getdetails(page,orders){
	order=orders;
	if(document.getElementById("load_details")) document.getElementById("load_details").style.display="";
	command="<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'command=fetch_details');?>&page="+ page + "&panel="+panel_expand+ '&cID='+panel_expand_id + '&order=' +order;
	
	do_get_command(command);
}
	
	function get_details(type,cID,sID,page,params){
		//if(type=='CAT')
		//	command="<?php //echo tep_href_link(FILENAME_CATEGORIES,'command=fetch_details');?>&page="+ page + "&panel="+panel_expand+ '&cID='+panel_expand_id+'&sID='+sID + params;
		//else
			if(document.getElementById("load_details")) document.getElementById("load_details").style.display="";
		 if(type=='PM')
			command="<?php echo tep_href_link(FILENAME_CATEGORIES,'command=fetch_details');?>&page="+ page + "&panel="+panel_expand+ '&cID='+panel_expand_id+'&sID='+sID ;
		do_get_command(command);
	}
	function display_popup(){
		if(document.getElementById("display_menu"))document.getElementById("display_menu").style.display = "";
	}
	function display_null(){
		if(document.getElementById("display_menu"))document.getElementById("display_menu").style.display = "none";
	}

</script>
</head>
<body marginwidth="0"  marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">

<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php 
	  $file_name=FILENAME_SUBSCRIPTIONS_MAINPAGE;
	  require(DIR_WS_INCLUDES . 'header.php');
	  require('includes/date_format_js.php');
	  require(DIR_WS_INCLUDES . 'mainpage.js.php');
	   require(DIR_WS_INCLUDES . 'subscriptions.js.php');
 ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr>
	<!-- body_text //-->
		<td width="100%" valign="top">
			<table border="0" width="100%" cellspacing="0" cellpadding="2">
				<tr>
					<td>
					<table border="0" width="100%" cellspacing="0" cellpadding="0">
						<tr>
							<td>
							<!--<table border="0" width="100%" cellspacing="0" cellpadding="0">
								<tr class="dataTableHeadingRow">
								<td colspan="3"><table width="100%" cellpadding="0" cellspacing="0" border="0">
								<tr style="height:26px">
								<td width="30"><?php echo '<a onMouseOver="javascript:change_class(this,2);" onMouseOut="javascript:change_class(this,3);" alt="New Subscription" title="New Subscription" id="img_new" href="javascript:expand_category(0,2);">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif').'</a>'; ?></td>
								<td class="main" width="50"> -->
								
								<table width="100%" cellpadding="0" cellspacing="0" border="0">
										<!--<tr class="dataTableHeadingRow" style="height:25">
										<td width="30"><?php  echo '<a onMouseOver="javascript:change_class(this,2);" onMouseOut="javascript:change_class(this,3);" alt="New Subscription" title="New Subscription" id="img_new" href="javascript:expand_category(0,2);">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif').'</a>'; ?></td>
										<td valign="middle" width="530" class="dataTableHeadingContent" align="right"><?php echo tep_draw_form('search_form',FILENAME_SUBSCRIPTIONS_MAINPAGE,'','post','onSubmit="javascript: return search_subscription();"').'&nbsp;'.TEXT_SEARCH.tep_draw_input_field('subscription_search').'&nbsp;';?></td>
										 <td  valign="middle"  width="60"><input  type="image" src="<?php echo DIR_WS_IMAGES.'template/img_search.gif';?>" alt="Search" title="Search"></form></td>
										 <td  valign="middle"  width="60" align="right" class="dataTableHeadingContent"><?php echo TEXT_JUMP_TO; ?></td>
										 <td valign="middle"  width="60" class="dataTableHeadingContent"><?php echo '&nbsp;&nbsp;'.tep_draw_pull_down_menu("cbo_jumpto",$jmp_results,'',' style="width:100px;" onChange="javascript:do_jump_list(this.value)"'); ?></td>
										</tr> -->
										 <tr class="dataTableHeadingRow" style="height:25px">
                 	<td colspan="5">
                 		<table border="0" cellspacing="0" cellpadding="0" width=100%>	
                 			<tr>
                 				<td valign="bottom" class="pageHeading" align="left" width="500" ><?php  echo '<a onMouseOver="javascript:change_class(this,2);" onMouseOut="javascript:change_class(this,3);" alt="New Subscription" title="New Subscription" id="img_new" href="javascript:expand_category(0,2);">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif').'</a>'; ?></td>
			                	<td class="dataTableHeadingContent" align="right" valign="bottom" width="300"><?php echo tep_draw_form('search_form',FILENAME_SUBSCRIPTIONS_MAINPAGE,'','post','onSubmit="javascript: return search_subscription();"').'&nbsp;'.TEXT_SEARCH.tep_draw_input_field('subscription_search').'&nbsp;';?>
								<input  type="image"  align="absbottom" src="<?php echo DIR_WS_IMAGES.'template/img_search.gif';?>" alt="Search" title="Search"></form></td>	
								<td valign="bottom" class="dataTableHeadingContent" align="right" width="300"><?php echo TEXT_JUMP_TO.'&nbsp;&nbsp;'.tep_draw_pull_down_menu("cbo_jumpto",$jmp_results,'',' style="width:100px;" onChange="javascript:do_jump_list(this.value)"'); ?></td>
								
                 			</tr>
                 		</table>
                 	</td>                 	
               </tr>
										<tr class="dataTableHeadingRow" style="height:25">
											<td width="10%" class="main">
											<?php 
												echo tep_image(DIR_WS_IMAGES . 'template/icon_ascending.gif',IMAGE_ASCENDING,'','',' id="pop_common_sort_display_con" onMouseOver="javscript:javascript:show_cpopup(\'sort_display\',0,20);"');
												echo '<input type="hidden" name="show_sort_order" id="show_sort_order" value="AN">';
												echo "<div id='pop_common_sort_display' style='position:absolute;display:none;width:110px;height:70px;z-index:999;border:1px solid;border-color:#6883CA;background-color:#FFFFFF;padding:3px;'>";
												echo tep_draw_separator('pixel_trans.gif','10','5');
												echo '<br><table class="main" cellpadding="0" cellspacing="0">';
												$popup=array(array("img"=>'icon_ascending.gif',"txt"=>TEXT_ASCENDING,'id'=>'AN'),array("img"=>'icon_descending.gif',"txt"=>TEXT_DESCENDING,'id'=>'DN'),array('img'=>'icon_active.gif',"txt"=>TEXT_SHOW_AVAILABLE,"id"=>'AV'));
												for ($icnt=0,$n=count($popup);$icnt<$n;$icnt++){
													echo '<tr height="20" class="tableMenuItem" onMouseOver="javascript:rowOverEffect(this)" onMouseOut="javascript:rowOutEffect(this)"><td valigm="middle" width="18">' . tep_image(DIR_WS_IMAGES . "template/" .$popup[$icnt]["img"],$popup[$icnt]["txt"],'','','align=absmiddle') . '</td><td>';
													echo '<a style="color:#000000;text-decoration:none" href="javascript:do_page_fetch(\'fetch_all_list\',\'' . $popup[$icnt]["id"] . '\');">' . $popup[$icnt]["txt"] . '</a></td></tr>';
													echo '<tr height="3"><td></td></tr>';
												}
												echo "</td></tr></table></div>";
											?>
										</td>
										<td colspan="4" class="dataTableHeadingContent" width="90%"><?php echo TABLE_HEADING_CATEGORIES_SUBSCRIPTIONS;?></td>
										</tr>
										</table></td>
										</tr>											
						<tr>
							<td valign="top">
							<table border="0" width="100%" cellspacing="0" cellpadding="2">
								<tr><td class="dataTableHeadingContent" colspan="2" id="res_display" style="display:none"></td></tr>
								<tr>
									<td id="get_details" colspan="2">
									    <?php 
										set_time_limit(5);
										echo tep_draw_form('new_product', FILENAME_SUBSCRIPTIONS_MAINPAGE, 'action=file_upload', 'post', ' onSubmit="javascript:return AIM.submit(document.new_product, {\'onStart\' : startCallback_subscription, \'onComplete\' : completeCallback_subscription});" enctype="multipart/form-data"'); 
							 		  	?>												 													
										<input type='hidden' name='product_id' id='product_id'>
										<input type="hidden" name="sort_order" id="sort_order">
										<input type="hidden" name="action_type" id="action_type">
										<input type="hidden" name="image_type" id="image_type">
										<span id="new_category"></span>
										<span id="search_result_details"><?php output_sub_result(0,1,'A',0,'',1);?></span>
									 </form>
									</td>
								</tr>	
							</table>
							</td>
						</tr>
						<tr>
				<table border="0" width="100%" cellspacing="0" cellpadding="0">
					<tr>
						<td>
						<table border="0" width="100%" cellpadding="0" cellspacing="0">
						<tr><td></td></tr> <tr><td></td></tr> <tr><td></td></tr>
							<tr>
								<td>
								<table cellpadding="0" cellspacing="0" border="0" width="100%">
									<tr class="product_title">
										<td colspan="2"><?php echo '<b>' . TABLE_SUBSCRIPTION_MANAGEMENT . '</b>'; ?></td>
									</tr>
									<tr height="7"></tr>	
									<tr>
										<td width="7%">
										<table border="0" cellpadding="0" cellspacing="0">
											<tr>
												<td><?php echo tep_image(DIR_WS_IMAGES . 'subscriptions_management.png', 'Subscriptions');?></td>
											</tr>
										</table>
										</td>
										<td width="93%" valign="top">
											<table width="100%" class="info_content">												
												<tr><td class="info_content"><?php echo '<a id="link_categories" href="javascript:expand_category(0,2);">' . IMAGE_NEW_CATEGORY . '</a>'; ?></td></tr>
												<tr><td class="info_content"><?php echo '<a id="link_product" href="javascript:expand_category(0,6);">' . IMAGE_NEW_SUBSCRIPTION . '</a>';?></td></tr>	  											
<!-- 											<tr><td class="info_content"><?php echo '<a href="' . tep_href_link(FILENAME_FEATURED,'page=1&action=new') . '">' . LIST_ITEM . '</a>'; ?></td></tr>
												<tr><td class="info_content"><?php echo '<a href="' . tep_href_link(FILENAME_SPECIALS,'page=1&action=new') . '">' . LIST_ITEM . '</a>'; ?></td></tr>
-->											</table>
										</td>
									</tr>	
								</table>
												</td>
												<td>
													
												</td>
											</tr><tr><td></td></tr><tr><td></td></tr>
											
											<tr><td></td></tr><tr><td></td></tr>
											<tr>
												<td>
													<table cellpadding="0" cellspacing="0" width="100%" border="0">
														<tr class="product_title">
															<td colspan="2"><?php echo '<b>' . TABLE_SUBSCRIPTION_REPORTS . '</b>'; ?></td>
														</tr>
														<tr height="7"></tr>	
													<tr>
													<td width="7%">
														<tr><td valign="top"><?php echo tep_image(DIR_WS_IMAGES . 'subscriptions_reports.png', 'Subscriptions Reports','53','55');?></td>
																
														<td width="93%" valign="top">
														<table  class="info_content">
															<tr><td class="info_content"><?php echo '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_RENEWALS,'top=1') . '">' . IMAGE_RENEWALS . '</a>'; ?></td></tr>
															<tr><td class="info_content"><?php echo '<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_NON_RENEWALS,'top=1') . '">' . IMAGE_NON_RENEWALS . '</a>'; ?></td></tr>
															<tr><td class="info_content"><?php echo '<a href="' . tep_href_link(FILENAME_STATS_SUBSCRIPTION_VIEWED,'top=1') . '">' . SUBSCRIPTIONS_VIEWED . '</a>'; ?></td></tr>
															<tr><td class="info_content"><?php echo '<a href="' . tep_href_link(FILENAME_PACKING_SLIP,'top=1') . '">' . IMAGE_PACKING_SLIP . '</a>'; ?></td></tr>
													</td>	</tr></table>
												 </td>
												<td height="5"></td>
											</tr>
										</table>
										</td>
									</tr>
								</table>
								
								</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<div id="ajax_load_img" style="display:none">
	<?php echo tep_image(DIR_WS_IMAGES . '24-1.gif') ;?>
</div>
<!-- body_text_eof //-->
<!-- body_eof //-->

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

	function tep_get_subscription_cat_ajax_list($parent_id,$level=0,$value_assign_type='default',&$results,&$open_ids){
		global $languages_id;
		
		$categories_sql = "select c.subscription_categories_id as categories_id, cd.subscription_categories_name as categories_name, c.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " c, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " cd where c.subscription_categories_id = cd.subscription_categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "'  order by c.sort_order, cd.subscription_categories_name";

		$categories_query = tep_db_query($categories_sql);
		if (tep_db_num_rows($categories_query)<=0) return;
		while ($category_result = tep_db_fetch_array($categories_query)) {
			$open_ids.="," . $category_result["categories_id"];
			switch($value_assign_type){
				case 'open_ids':
					$id=substr($open_ids,1);
					break;
				default:
					$id=$category_result["categories_id"];
			}
			$name=$category_result["categories_name"];
			$style="";
			if ($level>0) $style='padding-left:' . ($level*10) . "px";
			
			$results[]=array('id'=>$id,'text'=>$name,'style'=>$style);
			tep_get_subscription_cat_ajax_list($category_result["categories_id"],$level+1,$value_assign_type,$results,$open_ids);
			$open_ids=substr($open_ids,0,strrpos($open_ids,","));
		}
	}
	function assign_sort_order($parent_id,$show_order){
		global $languages_id,$selected_name,$login_id,$login_groups_type,$HTTP_GET_VARS,$page,$command;
		$order_by='ASC';
		if($show_order=='DN') 	$order_by='DESC';
		$categories_sortorder_sql = "select c.subscription_categories_id as categories_id,c.sort_order, cd.subscription_categories_name as categories_name, c.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " c, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " cd where c.subscription_categories_id = cd.subscription_categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' ".$subscription_search_criteria."  order by  cd.subscription_categories_name $order_by";
		//echo $categories_sortorder_sql;
		$old_subscription_sort_array=array();
			$old_sort_array_assign=array();			
			$check_query=tep_db_query($categories_sortorder_sql);
			while($check_products=tep_db_fetch_array($check_query))	{			//print_r($check_products);
				$old_subscription_sort_array[$check_products['categories_id']]=$check_products['sort_order'];	
				}															
			$std_array=&$old_subscription_sort_array;			

			$old_sort_array_assign=$old_subscription_sort_array;
			
			$sort_order=SORT_ASC;
			//if($show_order=='DN') $sort_order=SORT_DESC;
			array_multisort($old_sort_array_assign,$sort_order);
			$i=0;
			while(list($key,)=each($std_array)){
					tep_db_query("update ". TABLE_SUBSCRIPTION_CATEGORIES ." set sort_order='".(int)$old_sort_array_assign[$i]."' where subscription_categories_id='".(int)$key."'");
					$i++;
			}

	}
	function do_sort($show_order,$level){
		global $languages_id,$selected_name,$login_id,$login_groups_type,$HTTP_GET_VARS,$page,$command;
		
		$sort_by='ASC';
		if($show_order=='DN') 	$sort_by='DESC';
		$categories_sort_sql = "select c.subscription_categories_id as categories_id,c.sort_order, cd.subscription_categories_name as categories_name, c.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " c, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " cd where c.subscription_categories_id = cd.subscription_categories_id and cd.language_id = '" . (int)$languages_id . "' ". $search_criteria ." order by c.parent_id,cd.subscription_categories_name $sort_by ";		

		$categories_sort_query = tep_db_query($categories_sort_sql);
		$sort_orders=array();
		
		while($categories_sort=tep_db_fetch_array($categories_sort_query)){
			if (!$sort_orders[$categories_sort["parent_id"]]) $sort_orders[$categories_sort["parent_id"]]=1;
				tep_db_query("UPDATE subscription_categories set sort_order= ". $sort_orders[$categories_sort["parent_id"]] ." where subscription_categories_id= ". $categories_sort['categories_id']);
				$sort_orders[$categories_sort["parent_id"]]++;
		}
		$subscriptions_sql = "select pd.subscription_name as subscriptions_name,pd.subscription_id as subscriptions_id,s.subscription_status  from " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " pd, " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " pcd, " . TABLE_SUBSCRIPTIONS ." s  where  pd.subscription_id=pcd.subscription_id and s.subscription_id=pcd.subscription_id and pd.language_id = '" . (int)$languages_id . "'" .$prd_where . " ORDER BY pd.subscription_name $sort_by ";
		$subscriptions_query=tep_db_query($subscriptions_sql);
		if(tep_db_num_rows($subscriptions_query)>0){
			$i=1;
			while($result=tep_db_fetch_array($subscriptions_query)){
				tep_db_query("update ".TABLE_SUBSCRIPTIONS." set subscriptions_sort_order='".$i."' where subscription_id='". (int)$result['subscriptions_id']."'");	
				$i++;													 																																
			}
		}
		
	}
	function output_sub_result($parent_id,$page,$show_order,$level,$open_ids,$start_up=0,$subscription_search='') {
		global $languages_id,$selected_name,$login_id,$login_groups_type,$HTTP_GET_VARS,$page;
		output_category_details($parent_id);
		echo '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr style="height:10"><td></td></tr></table>';
		$subscription_search_criteria="";
			if($subscription_search!='')
				$subscription_search_criteria=" and cd.subscription_categories_name like '%" . tep_db_input($subscription_search) . "%' ";
		$open_ids="," . $open_ids;
		if ($parent_id>0){
			// first fetch the products in this category
			output_products_result($parent_id,$page,$show_order);
		}
		$order='asc';
		if($show_order=='DN')
		$order='desc';
		$categories_sql = "select c.subscription_categories_id as categories_id,c.sort_order, cd.subscription_categories_name as categories_name, c.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " c, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " cd where c.subscription_categories_id = cd.subscription_categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' ".$subscription_search_criteria."  order by  c.sort_order,cd.subscription_categories_name";
		$categories_query = tep_db_query($categories_sql);
		if (tep_db_num_rows($categories_query)<=0) return;
		else $category_ids = tep_db_fetch_array(tep_db_query($categories_sql));
		echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" id="parent_'.$category_ids['categories_id'].'">';
		// fetch the sub category
		// iterate with nested category
		$icnt=0; $toggle_flag=0;
		while ($category_result = tep_db_fetch_array($categories_query)) {
			$show=false;
			if (($open_ids!='' && strpos($open_ids,"," . $category_result["categories_id"] . ",")!==false) || $start_up) {
				if ($start_up){
					echo '<script language="javascript">prev_category='. $category_result["categories_id"] . ';open_ids[0]=' . $category_result["categories_id"] . ';</script>';
				}
				$start_up=false;
				$show=true;
			}
			tep_category_title_top($category_result['categories_name'],$category_result['categories_id'],$show,$level);			
			if ($show) 		output_sub_result($category_result['categories_id'],$page,$show_order,$level+1,$open_ids);			
			tep_category_title_bottom();
		}
		echo '</table>';
	}
	
	function output_subscription_search_result($search_item){
	global $languages_id,$global_categories_id;  
		if($search_item!='')
			$search_criteria=" and sd.subscription_name like '%" . tep_db_input($search_item) . "%' ";
	$subscription_query=tep_db_query('select sd.subscription_id,sd.subscription_name,s.subscription_status,s.subscription_type from '.TABLE_SUBSCRIPTIONS.' s, '.TABLE_SUBSCRIPTIONS_DESCRIPTION." sd where s.subscription_id=sd.subscription_id and sd.language_id='$languages_id'".$search_criteria." order by subscription_name");


		echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">';			
			if (tep_db_num_rows($subscription_query)>0){
				$i=0;												
				while ($subscription = tep_db_fetch_array($subscription_query)){
				$subscription_id=$subscription['subscription_id'];
				$categories_query=tep_db_query('select subscription_categories_id as categories_id from '.TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES." where subscription_id='$subscription_id'");
				
				while($categories_array=tep_db_fetch_array($categories_query)){
				$categories_id=$categories_array['categories_id'];

				if($categories_id!=$global_categories_id){					
					$class="dataTableRowEven";
					if($i%2==0) $class="dataTableRowOdd";					
					echo '<tr class="'.$class.'" height="18" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$subscription['subscription_id'].'_'.$categories_id.'\').style.display==\'none\') expand_category('.$subscription['subscription_id'].',1,'.$categories_id.');"><td class="main"><div id="data_'.$subscription['subscription_id'].'_'.$categories_id.'">';
					echo  ($subscription['subscription_status']==1)?tep_image(DIR_WS_IMAGES  . 'template/icon_active.gif', '') . tep_draw_separator('pixel_trans.gif', '5', '10'):tep_image(DIR_WS_IMAGES  . 'template/icon_inactive.gif', '') . tep_draw_separator('pixel_trans.gif', '5', '10');
					echo  $subscription['subscription_name'] . '&nbsp;<font color="green">' . ($subscription['subscription_type']=="M"?'(' . TEXT_SUBSCRIPTION_MEMBERSHIP . ')':'') . '</font></div><div class="openContent" id="head_'.$subscription['subscription_id'].'_'.$categories_id.'" style="display:none"></div></td></tr>';					
					$i++;	
				}
				}		// while categories loop
				} 	
			}
		 echo '</table>';
	}
	
	function output_products_result($categories_id,$page,$show_order){
		global $languages_id,$command;
			$result="";
			$prd_where="";
			$prd_order=" ASC ";
			if (substr($show_order,1,1)=="V") $prd_where=" AND s.subscription_status=1 ";
			$subscriptions_sql = "select pd.subscription_name as subscriptions_name,pd.subscription_id as subscriptions_id,s.subscription_status,s.subscription_type  from " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " pd, " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " pcd, " . TABLE_SUBSCRIPTIONS ." s  where pcd.subscription_categories_id='" . $categories_id . "' and pd.subscription_id=pcd.subscription_id and s.subscription_id=pcd.subscription_id and pd.language_id = '" . (int)$languages_id . "'" .$prd_where . " ORDER BY s.subscriptions_sort_order " . $prd_order;
			$query_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $subscriptions_sql, $query_split_numrows);
			$subscriptions_query=tep_db_query($subscriptions_sql);

			if ($command!='fetch_sub_products'){
				echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
				
				if($query_split_numrows>MAX_DISPLAY_SEARCH_RESULTS){
					echo '<tr>
							<td align="right">
								<table border="0" cellspacing="0" cellpadding="2">
									<tr> 
										<td class="smallText" align="left">'.													
											$query_split->display_script_links($query_split_numrows, MAX_DISPLAY_SEARCH_RESULTS, REPORT_MAX_LINKS_PAGE, $page,'cID=' . $categories_id,'do_page_fetch(\'fetch_sub_products\'',$categories_id).
										'</td>
									</tr>
								</table>
							</td>
						</tr>';
				} 
				echo '</table><div id="panel_' . $categories_id . '_contentp">';
			}
			echo '<table cellpadding="0" cellspacing="0" border="0" width="100%" id="id_product_list_'.$categories_id.'">';
			
			if (tep_db_num_rows($subscriptions_query)>0){
				$i=0;
				while ($subscriptions = tep_db_fetch_array($subscriptions_query)){
				    $class="dataTableRowEven";
					if($i%2==0) $class="dataTableRowOdd";
					echo '<tr class="'.$class.'" height="18" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$subscriptions['subscriptions_id'].'_'.$categories_id.'\').style.display==\'none\') expand_category('.$subscriptions['subscriptions_id'].',1,'.$categories_id.');"><td class="main"><div id="data_'.$subscriptions['subscriptions_id'].'_'.$categories_id.'">';
					echo  ($subscriptions['subscription_status']==1)?tep_image(DIR_WS_IMAGES  . 'template/icon_active.gif', '') . tep_draw_separator('pixel_trans.gif', '5', '10'):tep_image(DIR_WS_IMAGES  . 'template/icon_inactive.gif', '') . tep_draw_separator('pixel_trans.gif', '5', '10');
					echo  $subscriptions['subscriptions_name'] . '&nbsp;<font color="green">' . ($subscriptions['subscription_type']=="M"?'(' . TEXT_SUBSCRIPTION_MEMBERSHIP . ')':'') . '</font></div><div class="openContent" style="display:none" id="head_'.$subscriptions['subscriptions_id'].'_'.$categories_id.'"></div></td></tr>';									
					$i++;						
				} 	
			}
			echo '</table>';
	}
function output_category_details($cID){

	global $languages_id,$search_criteria;
	$product_sql = "select c.parent_id,date_format(c.date_added,'%Y-%m-%d') as date_added,date_format(c.last_modified,'%Y-%m-%d') as last_modified,cd.subscription_categories_id,cd.subscription_categories_name,c.sort_order,c.subscription_categories_image from ".TABLE_SUBSCRIPTION_CATEGORIES ." c,".TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION." cd where c.subscription_categories_id=cd.subscription_categories_id and cd.language_id='".(int)$languages_id."' and c.subscription_categories_id='".(int)$cID."'";

	$product_categories=tep_db_query($product_sql);
	if(tep_db_num_rows($product_categories)>0){
		$category_check_sql = "select count(*) as count from " . TABLE_SUBSCRIPTION_CATEGORIES . " where parent_id=" . $cID;
		$category_check_query = tep_db_query($category_check_sql);
		$category_check_result = tep_db_fetch_array($category_check_query);
		$check_sql = "select count(*) as count from " . TABLE_SUBSCRIPTIONS . " s," . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " ssc," . TABLE_SUBSCRIPTION_CATEGORIES . " sc where s.subscription_id=ssc.subscription_id and sc.subscription_categories_id=ssc.subscription_categories_id and sc.subscription_categories_id=" . $cID;
		$check_query = tep_db_query($check_sql);
		$check_result = tep_db_fetch_array($check_query);
		echo tep_draw_hidden_field('has_subscriptions_' . $cID,$check_result['count']+$category_check_result['count']);
	
		$product=tep_db_fetch_array($product_categories);
	?>
		<table width='100%' border='0' cellspacing='0' cellpadding='0' class="openContent_top" id="category_details_<?php echo $product['subscription_categories_id'];?>">
			<tr heigth='40' class='openContent_top'>
				  <td width='10'></td>
				  <td align='left' valign='middle' width='350' class='main'><?php echo $product['subscription_categories_name'];?></td>
				  <td width='470' align='left' style="cursor:pointer;" class='main' valign='top'>
				  	<table border='0' cellspacing='0' cellpadding='0' style='height:30px;display:inline;position:relative;'>
				  	 <tr class='img_move' id='img_ids'>
						 <td class='cell_bg_popm_left' width='10'>&nbsp;</td>						 
						 <td width='10%' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);' onclick='javascript:change_class(this,1);expand_category(<?php echo $product['subscription_categories_id'];?>,3);'><img alt='Edit Category' title='Edit Category' src='images/template/img_edit.gif'></td>
						 <td width='10%' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);' onclick='javascript:change_class(this,1);expand_category(<?php echo $product['subscription_categories_id'];?>,4);'><img alt='Delete Category' title='Delete Category' src='images/template/img_trash.gif'></td>						 
						 <td width='10%' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);' onclick='javascript:change_class(this,1);expand_category(<?php echo $product['subscription_categories_id'];?>,5);'><img alt='Move Category' title='Move Category' src='images/template/img_move.gif'></td>
						 <td class='cell_bg_popm_right' width='10'>&nbsp;</td>
				  	 </tr>
				  	</table>
				  </td>
				  <td width='240' align='right' id='img_save_<?php echo $product['subscription_categories_id'];?>' style='display:none'>
					  <input id="save_button_<?php echo $product['subscription_categories_id'];?>" type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;
					  <a href='javascript:expand_category(<?php echo $product['subscription_categories_id'];?>,1)'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;
				  </td>
				  </tr>
			  <tr style='height:10'><td id='loading' style='display:none' colspan='5'><img src='images/24-1.gif' alt='Loading...' title='Loading...'></td></tr>
			  <tr>
				  	<td colspan="8" class="main">
				  	<input type="hidden" name="cPath" id="cPath" value="<?php echo $product['subscription_categories_id'];?>">
				  		<span id="span_details_<?php echo $product['subscription_categories_id'];?>">
							<?php echo get_category_details($product);?>							
						</span>
					</td>
			  </tr>				   
		</table>
<?php } 
	}
	function get_category_details($product){
?>
	<table width='100%' border='0' cellspacing='0' cellpadding='0' class='openContent'>
	  <tr>
		<td colspan='2' valign='top'>
			<table width='50%' border='0' cellspacing='5' cellpadding='3'>
				<tr>
					<td width="30"><?php echo (($product['subscription_categories_image']!="")?tep_image(HTTP_SERVER.DIR_WS_CATALOG.'images/'.$product['subscription_categories_image'],$product['subscription_categories_image'],'100','100'):'');?></td>
					<td width='500' valign='top'>
						<table width='80%' border='0' cellspacing='5' cellpadding='0' class='main'>
							<tr>
								<td align='left' width='50%' valign='top' nowrap="true"><?php echo TEXT_DATE_ADDED;?></td>
								<td align='left' width='50%' valign='top' nowrap="true"><?php echo format_date($product['date_added']);?></td>
							</tr>
							<tr>
								<td align='left' width='50%' nowrap="true"><?php echo TEXT_LAST_MODIFIED;?></td>
								<td align='left' width='50%' nowrap="true"><?php echo format_date($product['last_modified']);?></td>
							</tr>													
						</table>
				</tr>
			</table>
		</td>
	</tr>
  </table>
<?php } ?>
 <script language="javascript">
 	function search_subscription(){
	var subscription_search=document.getElementById('subscription_search').value;
	//|| str_trim(subscription_search)==''
		if(subscription_search!='' ){
		//alert (subscription_search);
		do_get_command('<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'command=subscription_search&subscription_search='); ?>'+subscription_search);
		document.getElementById('search_result_details').innerHTML=document.getElementById('ajax_load_img').innerHTML;
		}
	return false;
	}
	function reset_search(){
	document.getElementById('search_result_details').innerHTML=document.getElementById('ajax_load_img').innerHTML;
	do_get_command('<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'command=reset_search'); ?>');
	document.getElementById('subscription_search').value="";
	}
 
 	function do_jump_list(nopen_ids){
	if(document.getElementById('subscription_search').value) document.getElementById('subscription_search').value="";
		if (open_ids.join(",")==nopen_ids) return;
		nopen_idsb=nopen_ids.split(",");
		nopen_ids=nopen_ids.split(",");
		for (icnt=0,n=nopen_ids.length;icnt<n;icnt++){
			if(icnt>=open_ids.length || nopen_ids[icnt]!=open_ids[icnt]){
				open_cat=nopen_ids[icnt];
				nopen_ids=nopen_ids.slice(icnt);
				break;
			}
			
		}
		if (open_ids[icnt]) hide_cat_panel(open_ids[icnt]);
		if(icnt<=open_ids.length && open_ids[nopen_ids.length-1]==nopen_ids[nopen_ids.length-1]) {
			hide_cat_panel(open_ids[nopen_ids.length]);
			open_ids=nopen_idsb;
			
		} else {
			open_ids=nopen_idsb;
			show_cat_panel(open_cat);
			do_page_fetch('fetch_sub_list_open','',open_cat,1,icnt);
		}
	}
  	function do_page_fetch(cmd,params,category,page,level){
		command="<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'do=1');?>&command="+cmd;
		if(document.getElementById("img_new") && category) {
			document.getElementById("img_new").href="javascript:expand_category("+category+",2);";
			if(document.getElementById("link_category")) document.getElementById("link_category").href="javascript:expand_category("+category+",2);";
			if(document.getElementById("link_product")) document.getElementById("link_product").href="javascript:expand_category(0,6,"+category+");";
		}		
		if(cmd=="fetch_sub_list" && document.getElementById("cPath") && document.getElementById("product_id")) {
			c_ids=document.getElementById("cPath").value;
			p_ids=document.getElementById("product_id").value;
			if(document.getElementById("data_"+p_ids+"_"+c_ids)) document.getElementById("data_"+p_ids+"_"+c_ids).style.display="";
			if(document.getElementById("head_"+p_ids+"_"+c_ids)) document.getElementById("head_"+p_ids+"_"+c_ids).style.display="none";			
			if(c_ids && document.getElementById("category_details_"+c_ids)) document.getElementById("category_details_"+c_ids).style.display="none";						
		}	
		if(document.getElementById("cPath")) document.getElementById("cPath").value=category;
		show_order=document.getElementById("show_sort_order");
		if (cmd=="fetch_sub_list" || cmd=="fetch_sub_list_open"){
			if(document.getElementById('new_category'))document.getElementById('new_category').innerHTML = "";
			command=command+"&cID="+category+"&level="+ level+"&show_order="+show_order.value;
			if (cmd=="fetch_sub_list_open") command=command+"&open_ids="+open_ids.join(",");
			if(document.getElementById("panel_"+category+"_content")) document.getElementById("panel_"+category+"_content").innerHTML=document.getElementById("ajax_load_img").innerHTML;
		} else if (cmd=="fetch_all_list"){
			show_order.value=params;
			command=command+"&cID=-1&page=1&level=1&open_ids="+open_ids.join(",")+"&show_order="+params;
			hide_cpopup(true);
			if(!document.getElementById("panel_"+open_ids[0]+"_content")) {
				cmd = "do_sort_list" ;
				command="<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'do=1');?>&command="+cmd;
				command=command+"&cID=-1&page=1&level=1&open_ids="+open_ids.join(",")+"&show_order="+params;
				//document.getElementById("search_result_details").innerHTML=document.getElementById("ajax_load_img").innerHTML;
			}else
				document.getElementById("panel_"+open_ids[0]+"_content").innerHTML=document.getElementById("ajax_load_img").innerHTML;
		} else {
			if (page=='next') {
				pgCombo=document.getElementById("page_"+category);
				selIndex=pgCombo.selectedIndex+1;
				if (selIndex>=pgCombo.options.length) return;
				pgCombo.selectedIndex=selIndex;
			} else if (page=='previous'){
				pgCombo=document.getElementById("page_"+category);
				selIndex=pgCombo.selectedIndex-1;
				if (selIndex<0) return;
				pgCombo.selectedIndex=selIndex;
			} 
			page=document.getElementById("page_"+category).value;
			command=command+'&page='+page+'&'+params+"&show_order="+show_order.value;
			document.getElementById("panel_"+category+"_contentp").innerHTML=document.getElementById("ajax_load_img").innerHTML;
		}
		do_get_command(command);
	}
	function do_result(result){ 
	//alert (result);
	var token=result.split('^');
	if(token[0]=='edit'){

	}
		if (result=="") return; 
		if(result.substr(0,7)=='command'){
			result_splt=result.split("{}");
			command="";
			category_id="";
			for (icnt=0;icnt<result_splt.length;icnt++){
				command_splt=result_splt[icnt].split("||");
				switch (command_splt[0]){
					case 'category':
						category_id=command_splt[1];
						break;
					case 'command':
						command=command_splt[1];
						break;
					case "page":
						if(document.getElementById("panel_"+category_id+"_pgno"))
							document.getElementById("panel_"+category_id+"_pgno").value=command_splt[1];
						break;
					case "result": 
						if (command=="fetch_sub_products"){
							document.getElementById("panel_"+category_id+"_contentp").innerHTML=command_splt[1];
						} else {
							if(!document.getElementById("panel_"+category_id+"_content"))
								document.getElementById("search_result_details").innerHTML=command_splt[1];
							else
							document.getElementById("panel_"+category_id+"_content").innerHTML=command_splt[1];
						}
				}
			}
	 	 }else if(result!=""){ 
		 	var res_display=document.getElementById("res_display");
		 	var span_product="";
		 	var span_category="";
		 	var action_type="";
		 	if(document.getElementById("cPath")) var category_id=document.getElementById("cPath").value;		 			 			 	
		 	if(document.getElementById("product_id").value) var pID=document.getElementById("product_id").value;
		 	if(document.getElementById("action_type"))  action_type=document.getElementById("action_type").value;
		 	if(document.getElementById("span_details_"+category_id)) span_category=document.getElementById("span_details_"+category_id);
		 	if(document.getElementById("span_details")) span_product=document.getElementById("span_details");// && !document.getElementById("search_result_details").childNodes[1] 
		 	//alert('action_type:'+action_type+'search:'+document.getElementById("search_result_details")+'category:'+document.getElementById("new_category"));
			if(action_type=='new_category' && document.getElementById("search_result_details")&&  result!="" && document.getElementById("new_category")){
			//	alert('1:'+result.indexOf("^")+'2:'+result.indexOf("{}")+'3:'+result.indexOf("||")+'4:'+document.getElementById("span_details_"+category_id));
				if(result.indexOf("^")>0 || result.indexOf("{}")>0 || result.indexOf("||")>0 || document.getElementById("span_details_"+category_id)){
				}else{ 
					document.getElementById("new_category").innerHTML=result;
					document.getElementById("new_category").style.display = "";
				}
			}
			//Added line 731- 746 by sobi
			if(result.indexOf("#")>0)
			{
				result_splt=result.split('#'); 
				res1=result_splt[0];
				res2=res1.split('^');
				if(res2[0]=="change_prev_subs")
				{
					if(res2[1]!='' && document.getElementById(res2[1]))
					{
					  temp=document.getElementById(res2[1]).innerHTML;
					  temp=temp.replace('(<?php echo TEXT_SUBSCRIPTION_MEMBERSHIP?>)','');
					  document.getElementById(res2[1]).innerHTML=temp;
					}
					result=result_splt[1];
				}
			}
		 	result_split=result.split('^');
		 	res=result;
		 	splt="";

		 	 if(result_split.length>1){
		 		splt=result_split[0];
			 	res=result_split[1];
		 	 }
			 if(splt=='get_details') print_details('get_details',res);
			 else if(splt=='subscription_search' || splt=='reset_search') document.getElementById('search_result_details').innerHTML=res;
			 else if(splt=='new_main_category') print_details('new_main_category',res);
			 else if(splt=='new_category') print_details('new_category',res);
			 else if(splt=='edit_category') print_details('edit_category',res);			 	
			 else if(splt=='move_category_success') print_details('move_category_success',res);
			 else if(splt=='sort_order_success') print_details('sort_order_success',res);
			 else if(splt=='delete_category_success') print_details('delete_category_success',res);		 	
			 else if(splt=='sort_order_error') print_details('sort_order_error',res);
			 else if(splt=='new_product') print_details('new_product',res);			 				 
			 else if(splt=='copy_details') print_details('copy_details',res);
			 else if(splt=='move_success') print_details('move_success',res);
			 else if(splt=='delete_success') print_details('delete_success',res);
			 else if(splt=='copy_error') print_details('copy_error',res);
			 else if(splt=='copy_success') print_details('copy_success',res);	
			 else if(splt=='move_category_failure') print_details('move_category_failure',res);
			 		
			 else if(splt=='diff_category') {
	 	 			result_splt=res.split('#'); 	 			
	 	 			if(result_splt[0]>0)  toggle_category_panel(result_splt[0],0,true);
	 	 	}else if(res!="" && (action_type=='new' && !document.getElementById("data_"+pID+"_"+category_id)) || action_type=='new_category' || action_type=='edit_category' || action_type=='delete_category' || action_type=='move_category') {
					// For Subscription Present on Category
					
					if(document.getElementById('save_button_'+category_id))
					if(action_type == 'delete_category' && document.getElementById('has_subscriptions_'+category_id) && document.getElementById('has_subscriptions_'+category_id).value >0)document.getElementById('save_button_'+category_id).style.display = 'none';
					else document.getElementById('save_button_'+category_id).style.display = '';
					
					span_category.innerHTML=res;
					
					if(document.getElementById("img_save_"+category_id))
						document.getElementById("img_save_"+category_id).style.display='';
					if(splt=='new') {
						if(document.getElementById("action_type")) document.getElementById("action_type").value='new';
						else if(document.getElementById("img_save_"+category_id)) document.getElementById("img_save_"+category_id).style.display="";
					}					
	 	 	}else if(action_type=='new' || action_type=='edit' || action_type=='delete' || action_type=='copy' || action_type=='move'){
			    
					// For Subscription Present on Category
					span_product.innerHTML=res;
					if(document.getElementById("img_save")) document.getElementById("img_save").style.display="";
					if(action_type=='edit') {
						updateGross();
						do_subscription_type();
						do_subscription_date_type();
					}
			}  
			if(action_type=='new' || action_type=='edit' || splt=='new'){ 
				if(action_type=='edit') do_subscription_type();
					<?php $languages = tep_get_languages();
					    if (HTML_AREA_WYSIWYG_DISABLE=='Enable') {
						 for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
						 	if(document.getElementById("subscription_description["+<?php echo $languages[$i]['id']; ?>+"]"))					 		
					 		if(splt!='new_product') initEditor('subscription_description[<?php echo $languages[$i]['id']; ?>]');
			  	   <?php }
					  }?>
					toggle_panel('Fees','false','','0');
					toggle_panel('Conditions','false','','0');
			 }
		 }
	}
</script>
<?php if(isset($HTTP_GET_VARS['create_category']) && $HTTP_GET_VARS['create_category']=='new'){ ?>
	<script langauge="javascript">
	if(document.getElementById("action_type")) document.getElementById("action_type").value='new_category';
	if(document.getElementById("cPath")){
			var cPath=document.getElementById("cPath").value;
			toggle_category_panel(cPath,0);
	}

	do_get_command('<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'action=edit_category&return=menu');?>');
	</script>
<?php } ?>
<?php if(isset($HTTP_GET_VARS['create_subscription']) && $HTTP_GET_VARS['create_subscription']=='new'){ ?>
	<script langauge="javascript">
	if(document.getElementById("action_type")) document.getElementById("action_type").value='new';
	do_get_command('<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'action=edit_product&return=menu');?>');
	</script>
<?php } ?>
