<?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
*/
  define( '_FEXEC', 1 );
  require('includes/application_top.php');
  $languages = tep_get_languages();
 $command=isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'';
 if($command!=''){
 $page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
 	switch($command){
	case 'main_page_fetch_details':
		echo 'main_page_fetch_details^';
		echo $page_id.'^';
		main_page_fetch_details($page_id);
		break;
	case 'level2_page_fetch_details':
		echo 'level2_page_fetch_details^';
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$parent_page_id=isset($HTTP_GET_VARS['parent_page_id'])?(int)$HTTP_GET_VARS['parent_page_id']:'';
		echo $page_id.'^';
		level2_page_fetch_details($page_id);
		
		break;
	case 'fetch_edit_details':
		echo 'fetch_edit_details^'.$page_id.'^';
		fetch_edit_details($page_id);
		break;
	case 'level2_fetch_edit_details':
		echo 'level2_fetch_edit_details^'.$page_id.'^';
		fetch_edit_details($page_id);
		break;
	case 'save_edit_page':
		$page_id=isset($HTTP_POST_VARS['page_id'])?(int)$HTTP_POST_VARS['page_id']:'';
	
		for($i=0,$n=sizeof($languages);$i<$n;$i++){
		$language_id=$languages[$i]['id'];
		$page_name=tep_db_prepare_input($HTTP_POST_VARS['page_name'][$language_id]);
		$page_description=tep_db_prepare_input($HTTP_POST_VARS['page_description'][$language_id]);
		$page_description = tep_db_input($page_description);
		$chk_query=tep_db_query('select count(*) as total from '.TABLE_MAINPAGE_DESCRIPTIONS." where page_id='$page_id' and language_id='" . (int)$language_id . "'");
		$chk_array=tep_db_fetch_array($chk_query);
		if($chk_array['total']>0)
			tep_db_query('update '.TABLE_MAINPAGE_DESCRIPTIONS." set page_name='$page_name',description='$page_description' where page_id='$page_id' and language_id='" . (int)$language_id . "'");
		else 
			tep_db_query("insert into ".TABLE_MAINPAGE_DESCRIPTIONS." (page_id,page_name,description,language_id) values('$page_id','$page_name','$page_description','" . (int)$language_id . "') ");
		}
		/*echo 'load_main_page^';
		load_main_page(0);*/
		$chk_query=tep_db_query('select parent_id from '.TABLE_MAINPAGE." where page_id='$page_id'");
		$chk_array=tep_db_fetch_array($chk_query);
			if($chk_array['parent_id']==0){
			echo 'main_page_fetch_details^';
			echo $page_id.'^';
			main_page_fetch_details($page_id);
			}
			else{
			echo 'level2_page_fetch_details^';
			echo $page_id.'^';
			level2_page_fetch_details($page_id);
			}
		break;
	case 'new_static_page':
		echo 'new_static_page^';
		new_static_page();
		break;
	case 'save_new_level1_page':
		$sort_order=0;
		$sort_order_query=tep_db_query('select max(sort_order) as sort_order from '.TABLE_MAINPAGE." where parent_id=0");
			if(tep_db_num_rows($sort_order_query)){
			$sort_order_array=tep_db_fetch_array($sort_order_query);
			$sort_order=$sort_order_array['sort_order'];
			}
		
		tep_db_query('insert into '.TABLE_MAINPAGE." (parent_id,date_created,date_modified,sort_order,page_status) values('0',now(),now(),'$sort_order','1') ");
		$page_id=tep_db_insert_id();
			for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
			$language_id = $languages[$i]['id'];
			$new_page_name=$HTTP_POST_VARS['new_page_name'][$language_id];
			$new_page_description=$HTTP_POST_VARS['new_page_description'][$language_id];
			tep_db_query('insert into '.TABLE_MAINPAGE_DESCRIPTIONS." (page_id,page_name,description,language_id) values('$page_id','" . tep_db_input(tep_db_prepare_input($new_page_name)) . "','" . tep_db_input(tep_db_prepare_input($new_page_description)) . "','$language_id') ");
			}
		echo 'load_main_page^';
		load_main_page(0);
		break;
	case 'save_new_level2_page';
		$parent_id=isset($HTTP_GET_VARS['parent_id'])?(int)$HTTP_GET_VARS['parent_id']:'';
		$sort_order=0;
		/*$sort_order_query=tep_db_query('select max(sort_order) as sort_order from '.TABLE_MAINPAGE." where parent_id='$parent_id'");
			if(tep_db_num_rows($sort_order_query)){
			$sort_order_array=tep_db_fetch_array($sort_order_query);
			$sort_order=$sort_order_array['sort_order'];
			}*/
		
		tep_db_query('insert into '.TABLE_MAINPAGE." (parent_id,date_created,date_modified,sort_order,page_status) values('$parent_id',now(),now(),'$sort_order','1') ");
		$page_id=tep_db_insert_id();
			for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
			$language_id = $languages[$i]['id'];
			$new_page_name=$HTTP_POST_VARS['new_page_name'][$language_id];
			$new_page_description=$HTTP_POST_VARS['new_page_description'][$language_id];
			tep_db_query('insert into '.TABLE_MAINPAGE_DESCRIPTIONS." (page_id,page_name,description,language_id) values('$page_id','" . tep_db_input(tep_db_prepare_input($new_page_name)) . "','" . tep_db_input(tep_db_prepare_input($new_page_description)) . "','$language_id') ");
			}
		echo 'main_page_fetch_details^';
		echo $parent_id.'^';
		main_page_fetch_details($parent_id);
		break;
	case 'page_status':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$status=isset($HTTP_GET_VARS['status'])?tep_db_prepare_input($HTTP_GET_VARS['status']):'';
		tep_db_query('update '.TABLE_MAINPAGE." set page_status='$status',date_modified=now() where page_id='$page_id'");
		$page_name_query=tep_db_query('select page_name from '.TABLE_MAINPAGE_DESCRIPTIONS." where page_id='$page_id' and language_id='$languages_id'");
		$page_name='';
				if(tep_db_num_rows($page_name_query)>0){
				$page_name_array=tep_db_fetch_array($page_name_query);
				$page_name=$page_name_array['page_name'];
				}
		echo 'page_status^'.$page_id.'^';
		 echo (($status==1)?tep_image(DIR_WS_IMAGES.'template\icon_active.gif','Active'):tep_image(DIR_WS_IMAGES.'template\icon_inactive.gif')).'&nbsp;&nbsp;'.$page_name.'^';
		 
		main_page_fetch_details($page_id);
		break;
	case 'copy_main_page':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$copying_parent_id=isset($HTTP_GET_VARS['copying_parent_id'])?(int)$HTTP_GET_VARS['copying_parent_id']:'';
		echo copy_main_page($page_id,$copying_parent_id);
		echo 'load_main_page^';
		load_main_page(0);
		break;	
	case 'level2_copy_main_page':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$copying_parent_id=isset($HTTP_GET_VARS['level2_copying_parent_id'])?(int)$HTTP_GET_VARS['level2_copying_parent_id']:'';
		echo copy_main_page($page_id,$copying_parent_id);
			if($copying_parent_id==0){
			echo 'load_main_page^';
			load_main_page(0);
			} else {
			echo 'level2_page_fetch_details^';
			echo $page_id.'^';
			level2_page_fetch_details($page_id);
			}
		break;
	case 'move_main_page':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$move_parent_id=isset($HTTP_GET_VARS['move_parent_id'])?(int)$HTTP_GET_VARS['move_parent_id']:'';
		tep_db_query('update '.TABLE_MAINPAGE." set parent_id='$move_parent_id' where page_id='$page_id'");
		echo 'load_main_page^';
		load_main_page(0);
		break;
	case 'level2_save_move_main_page':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$level2_move_parent_id=isset($HTTP_GET_VARS['level2_move_parent_id'])?(int)$HTTP_GET_VARS['level2_move_parent_id']:'';
		tep_db_query('update '.TABLE_MAINPAGE." set parent_id='$level2_move_parent_id' where page_id='$page_id'");
		echo 'load_main_page^';
		load_main_page(0);
		break;
	case 'level2_main_page_delete':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$parent_id_query=tep_db_query("select parent_id from ".TABLE_MAINPAGE." where page_id='$page_id'");
		$parent_id_array=tep_db_fetch_array($parent_id_query);
		$parent_id=$parent_id_array['parent_id'];
		tep_db_query('delete from '.TABLE_MAINPAGE." where page_id='$page_id'");
		tep_db_query('delete from '.TABLE_MAINPAGE_DESCRIPTIONS." where page_id='$page_id'");
		echo 'main_page_fetch_details^';
		echo $parent_id.'^';
		main_page_fetch_details($parent_id);
		break;
	case 'main_page_delete':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		tep_db_query('delete from '.TABLE_MAINPAGE." where page_id='$page_id'");
		tep_db_query('delete from '.TABLE_MAINPAGE_DESCRIPTIONS." where page_id='$page_id'");
		echo 'load_main_page^';
		load_main_page(0);
		break;
	case 'new_level2_page':
		echo 'new_level2_page^'.$page_id.'^';
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		echo new_static_page();
		break;
	case 'main_page_sort_order':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$sort_order=isset($HTTP_GET_VARS['sort_order'])?$HTTP_GET_VARS['sort_order']:'';
		$type=isset($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type']:'';
			if($type=='up' && $sort_order!=0){
			$sort_order--;
			}
			if($type=='down'){
			$sort_order++;
			
			}
		tep_db_query('update '.TABLE_MAINPAGE." set sort_order='$sort_order' where page_id='$page_id'");
		break;
	case 'level2_sort_order':
		$page_id=isset($HTTP_GET_VARS['page_id'])?(int)$HTTP_GET_VARS['page_id']:'';
		$sort_order=isset($HTTP_GET_VARS['sort_order'])?(int)$HTTP_GET_VARS['sort_order']:'';
		$type=isset($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type']:'';
			if($type=='up' && $sort_order!=0){
			$sort_order--;
			}
			if($type=='down'){
			$sort_order++;
			
			}
		tep_db_query('update '.TABLE_MAINPAGE." set sort_order='$sort_order' where page_id='$page_id'");
		break;
	case 'search':
   		$cms_search=isset($HTTP_GET_VARS['cms_search'])?tep_db_prepare_input($HTTP_GET_VARS['cms_search']):'';
		echo 'search^';
		load_main_page(0,'',$cms_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 'load_main_page^';
		load_main_page(0);
		break;
	}
   
 exit;
 }
 
 	tep_get_last_access_file();      
	
	function copy_main_page($page_id,$copying_parent_id){
		global $languages_id;
		$sort_order=0;
		$sort_order_query=tep_db_query("select max(sort_order) as sort_order from " .TABLE_MAINPAGE. " where parent_id='$copying_parent_id'");
			if(tep_db_num_rows($sort_order_query)>0){
			$sort_order_array=tep_db_fetch_array($sort_order_query);
			$sort_order=$sort_order_array['sort_order'];
			}
		
		tep_db_query('insert into '.TABLE_MAINPAGE." (parent_id,date_created,page_status) values ('$copying_parent_id',now(),'1') ");
		$insert_page_id=tep_db_insert_id();
		$fetch_query=tep_db_query("select page_name,description,language_id from ".TABLE_MAINPAGE_DESCRIPTIONS." where page_id='$page_id'");
		while($fetch_array=tep_db_fetch_array($fetch_query)){
		$page_name=$fetch_array['page_name']; $description=$fetch_array['description']; $language_id=$fetch_array['language_id'];
		tep_db_query('insert into '.TABLE_MAINPAGE_DESCRIPTIONS." (page_id,page_name,description,language_id) values('$insert_page_id','$page_name','$description','$language_id')");		
		}
	}  
  
	$action		= isset($HTTP_GET_VARS['action'])?$HTTP_GET_VARS['action']:''; 
	$parent_id	= isset($HTTP_GET_VARS['sPath'])?$HTTP_GET_VARS['sPath']:0;
	$page_id	= isset($HTTP_GET_VARS['pID'])?$HTTP_GET_VARS['pID']:0;
	$search		= isset($HTTP_GET_VARS['find'])?$HTTP_GET_VARS['find']:'';
	$page 		= isset($HTTP_GET_VARS['page'])?$HTTP_GET_VARS['page']:1;
	$level = isset($HTTP_GET_VARS['level'])?$HTTP_GET_VARS['level']:1;
	if(isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action']==""))$action = '';
	if(isset($HTTP_GET_VARS['sPath']) && ($HTTP_GET_VARS['sPath']==""))$parent_id = 0;
	if(isset($HTTP_GET_VARS['pID']) && ($HTTP_GET_VARS['pID']==""))$page_id = 0;
	if(isset($HTTP_GET_VARS['page']) && ($HTTP_GET_VARS['page']==""))$page = 1;

	$confirm_time_switch=false;
	$has_childs = false;
	$has_pages = false; 

		$check_sql = "select page_name from " . TABLE_MAINPAGE_DESCRIPTIONS . " where page_id=" . (int)$parent_id;
		$check_query = tep_db_query($check_sql);
		$check_result = tep_db_fetch_array($check_query);
?>
 	<?php
 	function load_main_page($parent_id=0,$level='',$search=''){
	global $languages_id; $search_criteria="";
		if($search!='')
			$search_criteria=" and mpd.page_name like '%" . tep_db_input($search) . "%' ";
	if($level=='')
	$main_pages_query=tep_db_query("select mp.page_id,mp.page_status,mpd.page_name from ".TABLE_MAINPAGE." mp, ".TABLE_MAINPAGE_DESCRIPTIONS." mpd where mp.page_id=mpd.page_id and mpd.language_id='$languages_id' and mp.parent_id='$parent_id'".$search_criteria." order by mp.sort_order");
	else
	$main_pages_query=tep_db_query("select mp.page_id,mp.page_status,mpd.page_name from ".TABLE_MAINPAGE." mp, ".TABLE_MAINPAGE_DESCRIPTIONS." mpd where mp.page_id=mpd.page_id and mpd.language_id='$languages_id' and mp.parent_id!='$parent_id' order by mp.sort_order");
	
	echo '<br><table width="100%" id="load_main_page_table" cellpadding="0" cellspacing=0" border="0">';
		if(tep_db_num_rows($main_pages_query)<=0)
			echo '<tr><td class="main" align="center">No Records Found</td></tr>';
	$cnt=0;
	while($main_pages_array=tep_db_fetch_array($main_pages_query)){
	
	 $class="dataTableRowEven";
  				 if($rows%2==0) $class="dataTableRowOdd"; 					
  				 $rows++;
	$page_id=$main_pages_array['page_id'];
	?>
	<tr id="load_main_page_<?php echo $page_id; ?>">
	<td width="10">&nbsp;</td>
	<td >
		<div   onClick="javascript: main_page_fetch_details(<?php echo $main_pages_array['page_id']; ?>);" id="main_page_<?php echo $main_pages_array['page_id']; ?>" class="<?php echo $class; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);">
		<?php echo (($main_pages_array['page_status']==1)?tep_image(DIR_WS_IMAGES.'template/icon_active.gif','Active'):tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','InActive')).'&nbsp;&nbsp;'.$main_pages_array['page_name']; ?>
		</div>
		<div id="ajax_main_page_<?php echo $main_pages_array['page_id']; ?>" style="display:none;">
		</div>
		
	</td>
	</tr>
	<?php
	}	
	echo '</table>';
	}
	
	function main_page_fetch_details($page_id){ global $languages_id;
	$main_page_details_query=tep_db_query('select mp.parent_id,mp.page_status,mpd.page_name,mpd.description,mp.sort_order from '.TABLE_MAINPAGE.' mp, '.TABLE_MAINPAGE_DESCRIPTIONS." mpd where mp.page_id=mpd.page_id and mp.page_id='$page_id' ");
	$main_page_details_array=tep_db_fetch_array($main_page_details_query);
	$sort_order=$main_page_details_array['sort_order'];
	?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="openContent">
	<tr class="openContent_top">
	
	<!--<td class="main" width="5"  onClick="javascript: close_level1_main_page(<?php echo $page_id ;?>);"> &nbsp;</td>-->
	<td class="main" align="center" width="1" nowrap="nowrap" ><?php echo (($main_page_details_array['page_status']==1)?'<a href="javascript: page_status('.$page_id.',0);">'.tep_image(DIR_WS_IMAGES . "template/icon_active.gif",'Active').'</a>':'<a href="javascript: page_status('.$page_id.',1);">'.tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','InActive').'</a>');?> </td>
	<td class="main" width="175" nowrap="nowrap" onClick="javascript: close_level1_main_page(<?php echo $page_id ;?>);"><?php echo'&nbsp;&nbsp;'.$main_page_details_array['page_name'];  ?></td>
	<td class="main" width="35" valign="top"   nowrap="nowrap"><?php echo '&nbsp;&nbsp;<a href="javascript: move_updown(\'load_main_page_\','. $page_id .',\'up\','.$sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_up.gif",'Up').'</a>&nbsp;&nbsp;<a href="javascript: move_updown(\'load_main_page_\','.$page_id.',\'down\','.$sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_down.gif",'Down').'</a>';
	?></td>			
	<td  width="100%" align="center" valign="top" >
		<table style="background:#DEE4F5;cursor:pointer;" width="100%" border="0" cellpadding="0" id="cms_level_header_operation" cellspacing="0">
		<tr>
		<td class="cell_bg_popm_left" width="10">&nbsp;</td>
		<td><?php 
		$delete_check_query=tep_db_query("select count(*) as total from ".TABLE_MAINPAGE." where parent_id='$page_id'");
		$delete_check_array=tep_db_fetch_array($delete_check_query);
		echo '<td width=10% onclick="javascript:do_hover_change(this,1); edit_main_page('.$page_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_edit.gif','Edit').'</td>';
		if($delete_check_array['total']==0)
		echo '<td width=10% onclick="javascript:do_hover_change(this,1); main_page_delete('.$page_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_trash.gif','Delete').'</td>'; 
		echo '<td width=10% onclick="javascript:do_hover_change(this,1); copy_main_page('.$page_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_copy.gif','Copy').'</td>';
		echo '<td width=10% onclick="javascript:do_hover_change(this,1); move_main_page('.$page_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_move.gif','Move').'</td>';
		?>
		</td>
		<td class="cell_bg_popm_right" width="10">&nbsp;</td>
		</tr>
		</table>
	</td>
	<td width="150" onClick="javascript: close_level1_main_page(<?php echo $page_id ;?>);">&nbsp;</td>
	<td width="65"  align="right" valign="top" nowrap="nowrap"><?php 
	echo '<a id="base_save_operation" style="display:none;">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;';
	echo '<a href="javascript: close_level1_main_page('.$page_id.');">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?>&nbsp;</td>
	</tr>
	<tr><td colspan="3"><br></td></tr>
	<tr>
		<td colspan="3" align="center">
		<div id="preview_details" class="main" style="width:650px; height:100px; overflow:scroll;">
		<?php echo $main_page_details_array['description']; ?>
		</div>
		</td>
	</tr>
	
	<tr><td colspan="3" id="new_level2_page_content" style="display:none" align="center"></td></tr>
	<tr><td id="delete_details" class="main" style="display:none;" colspan="3" align="center"><?php echo TEXT_DELETE_PAGE_INTRO; ?></td></tr>
	<tr>
	<td colspan="3" id="edit_details" style="display:none;">&nbsp;</td>
	</tr>
	<tr>
	<td colspan="5" id="copy_details" style="display:none;">
	<table cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td class="main" align="right"><?php echo TEXT_INFO_COPY_TO_INTRO; ?></td>
	</tr>
	<br/>
	<tr>
	<td class="main" align="right"><?php echo tep_draw_pull_down_menu('copying_parent_id', tep_get_static_pages_tree('','',$page_id), $page_id , ' id="copying_parent_id"'); ?></td>
	</tr>
	</table></td>
	<tr>
	<td colspan="5" id="move_details" style="display:none;;">
	<table cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td class="main" align="right"><?php echo TEXT_INFO_MOVE_TO_INTRO; ?></td></tr>
	<br/>
	<tr>
	<td  class="main" align="right"><?php echo 'menu'.tep_draw_pull_down_menu('move_parent_id', tep_get_static_pages_tree('','',$page_id), $page_id , ' id="move_parent_id"'); ?></td>
	</tr>
	<tr><td colspan="2"><br></td></tr>
	</table></td>
	</tr>
	<tr>
	<td colspan="3" id="level_2page_details"><?php level2_page($page_id); ?></td>
	</tr>
	<tr><td colspan="3"><br></td></tr>
	</table>
	<?php 
	} 
	
	
	function level2_page_fetch_details($page_id){ global $languages_id;
	$main_page_details_query=tep_db_query('select mp.sort_order,mp.parent_id,mp.page_status,mpd.page_name,mpd.description from '.TABLE_MAINPAGE.' mp, '.TABLE_MAINPAGE_DESCRIPTIONS." mpd where mp.page_id=mpd.page_id and mp.page_id='$page_id' ");
	$main_page_details_array=tep_db_fetch_array($main_page_details_query);
	$sort_order=$main_page_details_array['sort_order'];
	?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="openContent">
	<tr class="openContent_top">
	<td class="main"><?php echo (($main_page_details_array['page_status']==1)?'<a href="javascript: page_status('.$page_id.',0);">'.tep_image(DIR_WS_IMAGES . "template/icon_active.gif",'Active').'</a>':'<a href="javascript: page_status('.$page_id.',1);">'.tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','InActive').'</a>').'&nbsp;&nbsp;'.$main_page_details_array['page_name']; 
	echo '&nbsp;&nbsp;<a href="javascript: move_updown(\'level2_page_\','. $page_id .',\'up\','.$sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_up.gif",'Up').'</a>&nbsp;&nbsp;<a href="javascript: move_updown(\'level2_page_\','.$page_id.',\'down\','.$sort_order.')">'.tep_image(DIR_WS_IMAGES."/template/img_arrow_down.gif",'Down').'</a>';
	?></td>			
	<td colspan="5" style="cursor:pointer;" align="center">
		<table style="background:#DEE4F5;" width="100%" border="0" cellpadding="0" id="cms_level2_header_operation" cellspacing="0">
		<tr>
		<td class="cell_bg_popm_left" width="10">&nbsp;</td>
		<?php 
		echo '<td width=10% onclick="javascript:do_hover_change2(this,1); level2_edit_main_page('.$page_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_edit.gif','Edit').'</td>';
		echo '<td width=10% onclick="javascript:do_hover_change2(this,1); level2_main_page_delete('.$page_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_trash.gif','Delete').'</td>'; 
		echo '<td width=10% onclick="javascript:do_hover_change2(this,1); level2_copy_main_page('.$page_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_copy.gif','Copy').'</td>';
		echo '<td width=10% onclick="javascript:do_hover_change2(this,1); level2_move_main_page('.$page_id.');" onMouseOver="javascript:do_hover_change2(this,2);" onMouseOut="javascript:do_hover_change2(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_move.gif','Move').'</td>';
		?>
		<td class="cell_bg_popm_right" width="10">&nbsp;</td>
		</tr>
		</table>
	</td>
	<td width="100"  align="right" nowrap="nowrap"><?php 
	echo '<a id="level2_base_save_operation" style="display:none;">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;';
	echo '<a href="javascript: close_level2_main_page('.$page_id.');">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?>&nbsp;</td>
	</tr>
	<tr><td colspan="3"><br></td></tr>
	<tr>
		<td colspan="3" align="center">
		<div id="level2_preview_details" style="width:550px; height:100px; overflow:scroll;">
		<?php echo $main_page_details_array['description']; ?>
		</div>
		</td>
	</tr>
	<tr><td id="level2_delete_details" class="main" style="display:none;" colspan="3" align="center"><?php echo TEXT_DELETE_PAGE_INTRO; ?></td></tr>
	<tr>
	<td colspan="3" id="level2_edit_details" style="display:none;">&nbsp;</td>
	</tr>
	<tr>
	<td colspan="8" id="level2_copy_details" style="display:none;">
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td class="main" align="left"><?php echo TEXT_INFO_COPY_TO_INTRO; ?></td></tr>
	<tr>
	<td class="main" align="right"><?php echo tep_draw_pull_down_menu('level2_copying_parent_id', tep_get_static_pages_tree('','',$page_id), $page_id , ' id="level2_copying_parent_id"'); ?></td>
	</tr>
	</table></td>
	<tr>
	<td colspan="8" id="level2_move_details" style="display:none;;">
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td class="main" align="left"><?php echo TEXT_INFO_MOVE_TO_INTRO; ?></td></tr>
	<tr>
	<td class="main" align="right"><?php echo 'menu'.tep_draw_pull_down_menu('level2_move_parent_id', tep_get_static_pages_tree('','',$page_id), $page_id , ' id="level2_move_parent_id"'); ?></td>
	</tr>
	<tr><td></td></tr>
	</table></td>
	</tr>
	<!-- <tr>
	<td colspan="3" id="level_2page_details"><?php //level2_page($page_id); ?></td>
	</tr> -->
	<tr><td colspan="3"><br></td></tr>
	</table>
	<?php
	}
		
		
	function level2_page($page_id){
		global $languages_id;
		$sub_page_query=tep_db_query('select page_id from '.TABLE_MAINPAGE." where parent_id='$page_id'");
		if(tep_db_num_rows($sub_page_query)>0){
	?>
	
		<table width="100%" id="level2_page_table" cellpadding="0" cellspacing="0" border="0">
		<?php $cnt=0; while($sub_page_array=tep_db_fetch_array($sub_page_query)){ 
		$class_name=($cnt%2==0)?'subdataTableRowEven':'subdataTableRowEven';
		$sub_page_id=$sub_page_array['page_id'];

		$sub_page_name_query=tep_db_query("select mpd.page_name,mp.page_status from ".TABLE_MAINPAGE_DESCRIPTIONS." mpd, ".TABLE_MAINPAGE." mp where mp.page_id=mpd.page_id and mpd.page_id='$sub_page_id' and mpd.language_id='$languages_id'");
		$sub_page_name_array=tep_db_fetch_array($sub_page_name_query);
		$page_status=$sub_page_name_array['page_status'];
		?>
		<tr id="level2_page_<?php echo $sub_page_id; ?>">
		<td style="padding-left:30px;">
			<div onClick="javascript: level2_fetch_details(<?php echo $page_id.','.$sub_page_id; ?>);" id="main_page_<?php echo $sub_page_id; ?>" class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);">
			<?php echo (($page_status==1)?tep_image(DIR_WS_IMAGES.'template/icon_active.gif','Active'):tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','InActive')).'&nbsp;'.$sub_page_name_array['page_name']; ?>
			</div>
			<div id="ajax_main_page_<?php echo $sub_page_id; ?>">
			</div> 
		</td>
		</tr>
		<?php }  ?>
		</table>
	
	<?php	
		} // Sub page 
	} // level2 page Ends
	
	function level2_page_details(){ global $languages_id;
	$level2_page_query=tep_db_query('select page_id from '.TABLE_MAINPAGE." where parent_id!='0'");
	$cnt=0;
	while($level2_page_array=tep_db_fetch_array($level2_page_query)){
	$class_name=($cnt%2==0)?'dataTableRowOdd':'dataTableRowEven';
	$page_id=$level2_page_array['page_id'];
	$sub_page_name_query=tep_db_query("select mpd.page_name,mp.page_status,mp.page_id from ".TABLE_MAINPAGE_DESCRIPTIONS." mpd, ".TABLE_MAINPAGE." mp where mp.page_id=mpd.page_id and mpd.page_id='$page_id' and mpd.language_id='$languages_id'");
	$sub_page_name_array=tep_db_fetch_array($sub_page_name_query);
	$page_status=$sub_page_name_array['page_status'];
	$sub_page_id=$sub_page_name_array['page_id'];
	?>
	<tr id="level2_page_<?php echo $sub_page_id; ?>">
	<td style="padding-left:30px;">
		<div onClick="javascript: level2_fetch_details(<?php echo $page_id.','.$sub_page_id; ?>);" id="main_page_<?php echo $sub_page_id; ?>" class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);">
		<?php echo (($page_status==1)?tep_image(DIR_WS_IMAGES.'template/icon_active.gif','Active'):tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','InActive')).'&nbsp;'.$sub_page_name_array['page_name']; ?>
		</div>
		<div id="ajax_main_page_<?php echo $sub_page_id; ?>">
		</div> 
	</td>
	</tr>
		
	<?php
		}
	}
	
	function fetch_edit_details($page_id){
	global $languages;
	//$edit_details_query=tep_db_query('select '); 
	echo tep_draw_form('edit_page_form',FILENAME_INFORMATION_PAGES,'','post').tep_draw_hidden_field('page_id',$page_id);
	echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
	for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
		?>
		<tr>
		<td class="main" width="35%" ><?php if ($i == 0) echo TEXT_PAGE_NAME; ?></td>
		<td class="main" width="10%" ><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']);?> </td> 
		<td class="main" width="55%" ><?php echo tep_draw_input_field('page_name[' . $languages[$i]['id'] . ']', (isset($page_name[$languages[$i]['id']]) ? $page_name[$languages[$i]['id']] : tep_get_page_name($page_id, $languages[$i]['id']))); ?>
		</td>

		</tr>
		<?php
		}
		for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
		?>
		<tr>
		<td class="main"  valign="top" width="35%"><?php if ($i == 0) echo TEXT_PAGE_DESCRIPTION; ?></td>
		<!--<td width="70%">
		<table border="0" cellspacing="0" cellpadding="0">
			<tr> -->
				<td class="main" valign="top" width="15%"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
				<td class="main" width="55%"><?php echo tep_draw_textarea_field('page_description[' . $languages[$i]['id'] . ']', 'soft', '80', '24', (isset($page_description[$languages[$i]['id']]) ? $page_description[$languages[$i]['id']] : tep_get_page_description($page_id, $languages[$i]['id'])),'id="page_description[' . $languages[$i]['id'] . ']"'); ?></td>
				
		<!--	</tr>
		</table>
		</td>		-->
		</tr>
	<?php	
		}	
	echo '<tr><td colspan="2"></form></td></tr> </table>';
	}
	function new_static_page(){
	global $languages;
	echo tep_draw_form('new_static_page_form',FILENAME_INFORMATION_PAGES,'','post');
	?>
	<table border="0" cellpadding="5" cellspacing="0" width="100%">
	<tr height="30"></tr>
	<tr>
	<td>
	<table class="openContent_top" width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td style="padding-left:10px;" width="100"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif','Active').'&nbsp;&nbsp;'.TEXT_NEW_PAGE; ?></td>
	<td align="right"><?php echo '<a id="new_page_save_button_id" href="javascript: save_new_level1_page();">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>&nbsp;&nbsp;<a id="close_button" href="javascript: close_new_level1_page();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?></td>
	</tr>
	</table>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<?php for ($i=0, $n=sizeof($languages); $i<$n; $i++) { ?>
	<tr>
	<td class="main" align="right"><?php if ($i == 0) echo TEXT_PAGE_NAME; ?></td>
	<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('new_page_name[' . $languages[$i]['id'] . ']'); ?>
	</td>
	</tr>
	<?php } ?>
	<?php for ($i=0, $n=sizeof($languages); $i<$n; $i++) { ?>
	<tr>
	<td class="main" align="right" valign="top" width="150"><?php if ($i == 0) echo TEXT_PAGE_DESCRIPTION; ?></td>
	<td>
	<table border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
	<td class="main"><?php echo tep_draw_textarea_field('new_page_description[' . $languages[$i]['id'] . ']', 'soft', '80', '24','','id="new_page_description[' . $languages[$i]['id'] . ']"'); ?></td>
	</tr>
	</table>
	</td>
	</tr>
	<?php } ?>
	</table>
	</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	</form>
	<?php } ?>
<!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/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/http.js"></script>
<script language="javascript" type="text/javascript">
	function fn_submit(form){
		var action =form.action;
		var last_index = action.lastIndexOf("=");
		var modified_action = action.substring(0,last_index+1)+document.getElementById("copying_parent_id").value;
		form.action = modified_action;
		form.submit();
	}
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
	<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
	<!-- header_eof //-->
	
	<!-- Ajax Work Starts -->
<?php $level=isset($HTTP_GET_VARS['level'])?$HTTP_GET_VARS['level']:''; ?>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	
<?php if($level==1){ ?>	
	<tr height="30px;">
	<td style="padding-left:5px; padding-top:5px;"><table height="30px;" width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr class="dataTableHeadingRow">
	<td width="350" valign="bottom">
	<?php echo '<a onMouseOver="do_hover_change1(this,2);" onMouseOut="do_hover_change1(this,1);" id="base_header_new_operation" href="javascript: new_static_page();">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','New').'</a>'; ?>
	</td>
	<td align="right" class="dataTableHeadingContent" valign="bottom"><?php echo tep_draw_form('cms_search_form',FILENAME_INFORMATION_PAGES,'','post','onSubmit="javascript: return cms_search_validation();"');?>
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
				<td align="right" class="dataTableHeadingContent" valign="bottom"><?php echo 'Search';?>&nbsp;<?php echo tep_draw_input_field('cms_search') . '&nbsp;&nbsp;<a href="javascript: search_validation();">'.tep_image(DIR_WS_IMAGES.'template/img_search.gif','','','','title="Search" align=absbottom').'</a>';?></td>
			</tr>
		</table>
		</form>
	</td>			
	<td width="230" align="center" class="dataTableHeadingContent" valign="bottom">
	<?php 
	$jump_array=array();
	$go_to_query=tep_db_query("select mpd.page_id,mpd.page_name from ".TABLE_MAINPAGE." mp, ".TABLE_MAINPAGE_DESCRIPTIONS." mpd where mp.page_id=mpd.page_id and mp.parent_id='0' and mpd.language_id='$languages_id'");
	while($go_to_array=tep_db_fetch_array($go_to_query)){
	$jump_array[]=array('id'=>$go_to_array['page_id'],'text'=>$go_to_array['page_name']);
	}
	echo 'Go To '.tep_draw_pull_down_menu('jump',$jump_array,'',' onChange="javascript: main_page_fetch_details(this.value);" ');
	?>
	</td>
	</tr></table></td>
	</tr>
	<tr>
	<td style="padding-left:10px; padding-top:10px;" class="pageHeading"><?php echo HEADING_TITLE; ?></td>
	</tr>
	<tr>
	<td id="load_main_page_id"><?php load_main_page(0); ?></td>
	</tr>
	<tr>
	<td id="new_static_page_content" style="display:none;"></td>
	</tr>
<?php } ?>
	
<?php	if($level==2){ ?>
	<tr>
	<td style="padding-left:10px; padding-top:10px;" class="pageHeading"><?php echo HEADING_TITLE; ?></td>
	</tr>
	<tr>
	<td id="load_main_page_id">
<!--	<table width="100%" id="level2_page_table" cellpadding="0" cellspacing="0" border="0"> -->
	<?php //level2_page_details(); 
	load_main_page(0,'level2');
	?>
<!--	</table> -->
	</td>
	</tr>
<?php } ?>	
	</table>

	<!-- Ajax Work Ends -->
	
	<!-- footer //-->
	<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
	<!-- footer_eof //-->

</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var ajax_image_load='<?php echo tep_image(DIR_WS_IMAGES.'24-1.gif'); ?>',previous_page_id='',previous_level2_page_id='';
var parent_href="";	
<?php
	$level=isset($HTTP_GET_VARS['level'])?$HTTP_GET_VARS['level']:'';
	if($level==1){
	$page_id=isset($HTTP_GET_VARS['page_id'])?$HTTP_GET_VARS['page_id']:'';
		if($page_id!=''){
?>
			main_page_fetch_details(<?php echo $page_id; ?>);
<?php
			}
	}elseif($level==2){
	$page_id=isset($HTTP_GET_VARS['page_id'])?$HTTP_GET_VARS['page_id']:'';
		if($page!=''){
?>	
		main_page_fetch_details(<?php echo $page_id; ?>);
<?php 
		}
	}
?>
	function cms_search_validation(){
	var cms_search=document.getElementById('cms_search').value;
		if(cms_search!=''){
		do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=search&cms_search='); ?>'+cms_search);
		}
	document.getElementById('load_main_page_id').innerHTML=ajax_image_load;
	return false;
	}
	function search_validation(){
	var cms_search=document.getElementById('cms_search').value;
		if(cms_search!=''){
		do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=search&cms_search='); ?>'+cms_search);
		document.getElementById('load_main_page_id').innerHTML=ajax_image_load;
		}
	}
	function reset_search(){
	document.getElementById('cms_search').value='';
	document.getElementById('load_main_page_id').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=reset_search'); ?>');
	}
	function main_page_fetch_details(page_id){
		if(previous_page_id!='')
			close_level1_main_page(previous_page_id);
	if(document.getElementById('ajax_main_page_'+page_id)){
	document.getElementById('ajax_main_page_'+page_id).style.display='';
	document.getElementById('ajax_main_page_'+page_id).innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=main_page_fetch_details&page_id='); ?>'+page_id);
	
	previous_page_id=page_id;
	close_new_level1_page();
	if(document.getElementById('base_header_new_operation'))
	document.getElementById('base_header_new_operation').href="javascript: new_level2_page("+page_id+")";	
	}
	}
	
	function level2_fetch_details(parent_page_id,page_id){
		if(previous_level2_page_id!='')
			close_level2_main_page(previous_level2_page_id);
	document.getElementById('ajax_main_page_'+page_id).style.display='';
	document.getElementById('ajax_main_page_'+page_id).innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=level2_page_fetch_details&page_id='); ?>'+page_id+'&parent_page_id='+parent_page_id);
	previous_level2_page_id=page_id;
		if(document.getElementById('cms_level_header_operation'))
		document.getElementById('cms_level_header_operation').style.display='none';
	close_all_panel();
	}
	function close_level2_main_page(page_id){
		if(document.getElementById('preview_details'))
			document.getElementById('preview_details').style.display='';
		if(document.getElementById('ajax_main_page_'+page_id) && document.getElementById('main_page_'+page_id)){
		document.getElementById('ajax_main_page_'+page_id).innerHTML='';
		document.getElementById('ajax_main_page_'+page_id).style.display='none';
		document.getElementById('main_page_'+page_id).style.display='';
		}
	document.getElementById('cms_level_header_operation').style.display='';
		if(document.getElementById('new_page_save_button_id'))
		document.getElementById('new_page_save_button_id').href=parent_href;
	}
	
	function new_level2_page(page_id){
	display_flag=0;
	close_all_panel();
	document.getElementById('new_level2_page_content').style.display='';
	document.getElementById('new_level2_page_content').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=new_level2_page&page_id='); ?>'+page_id);
		if(previous_level2_page_id!='')
			close_level2_main_page(previous_level2_page_id);
	}
	
	function edit_main_page(page_id){
	close_all_panel();
	document.getElementById('edit_details').style.display='';
	document.getElementById('edit_details').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=fetch_edit_details&page_id='); ?>'+page_id);
	}
	
	function level2_edit_main_page(page_id){
	close_all_level2_panel();
	document.getElementById('level2_edit_details').style.display='';
	document.getElementById('level2_edit_details').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=level2_fetch_edit_details&page_id='); ?>'+page_id);
	}
	
	function copy_main_page(page_id){
	close_all_panel();
	document.getElementById('base_save_operation').style.display='';
	document.getElementById('copy_details').style.display='';
	document.getElementById('base_save_operation').href="javascript: save_copy_main_page("+page_id+")";
	}
	function level2_copy_main_page(page_id){
	close_all_level2_panel();
	document.getElementById('level2_copy_details').style.display='';
	document.getElementById('level2_base_save_operation').style.display='';
	document.getElementById('level2_base_save_operation').href="javascript: level2_save_copy_main_page("+page_id+")";
	}
	function save_copy_main_page(page_id){
	var copying_parent_id=document.getElementById('copying_parent_id').value;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=copy_main_page&page_id='); ?>'+page_id+'&copying_parent_id='+copying_parent_id);
	}
	function level2_save_copy_main_page(page_id){
	var level2_copying_parent_id=document.getElementById('level2_copying_parent_id').value;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=level2_copy_main_page&page_id='); ?>'+page_id+'&level2_copying_parent_id='+level2_copying_parent_id);
	}
	function move_main_page(page_id){ 
	close_all_panel();
	document.getElementById('move_details').style.display='';
	document.getElementById('base_save_operation').style.display='';
	document.getElementById('base_save_operation').href="javascript: save_move_main_page("+page_id+")";
	}
	function level2_move_main_page(page_id){
	close_all_level2_panel();
	document.getElementById('level2_move_details').style.display='';
	document.getElementById('level2_base_save_operation').style.display='';
	document.getElementById('level2_base_save_operation').href="javascript: level2_save_move_main_page("+page_id+")";
	}
	function save_move_main_page(page_id){
	var move_parent_id=document.getElementById('move_parent_id').value;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=move_main_page&page_id='); ?>'+page_id+'&move_parent_id='+move_parent_id);
	}
	function level2_save_move_main_page(page_id){
	close_all_level2_panel();
	var level2_move_parent_id=document.getElementById('level2_move_parent_id').value;
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=level2_save_move_main_page&page_id='); ?>'+page_id+'&level2_move_parent_id='+level2_move_parent_id);
	}
	function level2_main_page_delete(page_id){
	close_all_level2_panel();
	document.getElementById('level2_delete_details').style.display='';
	document.getElementById('level2_base_save_operation').style.display='';
	document.getElementById('level2_base_save_operation').href="javascript: level2_main_page_delete_confirm("+page_id+")";
	}
	function level2_main_page_delete_confirm(page_id){
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=level2_main_page_delete&page_id='); ?>'+page_id);
	}
	function main_page_delete(page_id){
	close_all_panel();
	document.getElementById('delete_details').style.display='';
	document.getElementById('base_save_operation').style.display='';
	document.getElementById('base_save_operation').href="javascript: main_page_delete_confirm("+page_id+")";
	}
	function main_page_delete_confirm(page_id){
	do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=main_page_delete&page_id='); ?>'+page_id);
	document.getElementById("cms_search").value="";
	}
	
	function close_all_panel(){
	if(document.getElementById('preview_details'))document.getElementById('preview_details').style.display='none';
	if(document.getElementById('edit_details'))document.getElementById('edit_details').innerHTML='';
	if(document.getElementById('edit_details'))document.getElementById('edit_details').style.display='none';
	if(document.getElementById('copy_details'))document.getElementById('copy_details').style.display='none';
	if(document.getElementById('move_details'))document.getElementById('move_details').style.display='none';
	if(document.getElementById('delete_details'))document.getElementById('delete_details').style.display='none';
	if(document.getElementById('base_save_operation'))document.getElementById('base_save_operation').style.display='none';
	if(document.getElementById('new_level2_page_content'))document.getElementById('new_level2_page_content').innerHTML='';
	if(document.getElementById('new_level2_page_content'))document.getElementById('new_level2_page_content').style.display='none';
	if(document.getElementById('base_save_operation'))document.getElementById('base_save_operation').href="#";
	}
	function close_all_level2_panel(){
	document.getElementById('level2_preview_details').style.display='none';
	document.getElementById('level2_edit_details').innerHTML='';
	document.getElementById('level2_edit_details').style.display='none';
	document.getElementById('level2_copy_details').style.display='none';
	document.getElementById('level2_move_details').style.display='none';
	document.getElementById('level2_delete_details').style.display='none';
	document.getElementById('level2_base_save_operation').style.display='none';
	document.getElementById('level2_base_save_operation').href="#";
	}
	
	function close_level1_main_page(page_id){
		if(document.getElementById('ajax_main_page_'+page_id) && document.getElementById('main_page_'+page_id)){
		document.getElementById('ajax_main_page_'+page_id).innerHTML='';
		document.getElementById('ajax_main_page_'+page_id).style.display='none';
		document.getElementById('main_page_'+page_id).style.display='';
		}
	if(document.getElementById('base_header_new_operation'))	
	document.getElementById('base_header_new_operation').href='javascript: new_static_page()';
	}
	function save_edit_page(page_id){
	var error=false; error_message='';
		<?php if (HTML_AREA_WYSIWYG_DISABLE == 'Enable') { ?>
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
		document.getElementById('page_description[<?php echo $languages[$i]['id']; ?>]').value=document.getElementById('if_page_description[<?php echo $languages[$i]['id']; ?>]').contentWindow.document.body.innerHTML;
		<?php } ?>
		<?php } ?>
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
			if(str_trim(document.getElementById('page_name[<?php echo $languages[$i]['id']; ?>]').value)==''){
			error=true; error_message='<?php echo JS_ERROR_PAGE_NAME; ?>';
			}
		<?php } ?>
		if(error==true)
			alert(error_message);
		else
			do_post_command('edit_page_form','<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=save_edit_page'); ?>');
	}
	function new_static_page(){
	display_flag=0;
		document.getElementById('new_static_page_content').style.display='';
		document.getElementById('new_static_page_content').innerHTML=ajax_image_load;
		do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=new_static_page'); ?>');
		if(previous_page_id!='')
			close_level1_main_page(previous_page_id);
	}
	function save_new_level1_page(){
	var error=false,error_message='';
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
			if(str_trim(document.getElementById('new_page_name[<?php echo $languages[$i]['id']; ?>]').value)==''){
			error=true; error_message='<?php echo JS_ERROR_PAGE_NAME; ?>';
			}
		<?php } ?>
		if(error==true)
			alert(error_message);
		else{
			<?php if (HTML_AREA_WYSIWYG_DISABLE == 'Enable') { 
			for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
			document.getElementById('new_page_description[<?php echo $languages[$i]['id']; ?>]').value=document.getElementById('if_new_page_description[<?php echo $languages[$i]['id']; ?>]').contentWindow.document.body.innerHTML;
			<?php } 
				}
			?>
		do_post_command('new_static_page_form','<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=save_new_level1_page'); ?>');
		document.getElementById("cms_search").value='';
		close_new_level1_page();
		}
	}
	function save_new_level2_page(page_id){
	var error=false,error_message='';
		<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
			if(str_trim(document.getElementById('new_page_name[<?php echo $languages[$i]['id']; ?>]').value)==''){
			error=true; error_message='<?php echo JS_ERROR_PAGE_NAME; ?>';
			}
		<?php } ?>
		if(error==true)
			alert(error_message);
		else{
			<?php if (HTML_AREA_WYSIWYG_DISABLE == 'Enable') { 
			for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
			document.getElementById('new_page_description[<?php echo $languages[$i]['id']; ?>]').value=document.getElementById('if_new_page_description[<?php echo $languages[$i]['id']; ?>]').contentWindow.document.body.innerHTML;
			<?php } 
				}
			?>
			do_post_command('new_static_page_form','<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=save_new_level2_page&parent_id='); ?>'+page_id);
			close_new_level2_page();
		 }
	}
	function close_new_level1_page(){
	change_new_image();
		if(document.getElementById('new_static_page_content')){
		document.getElementById('new_static_page_content').innerHTML='';
		document.getElementById('new_static_page_content').style.display='none';
		}
	}
	function change_new_image(){
	if(document.getElementById('base_header_new_operation')){
	display_flag=1;
	document.getElementById('base_header_new_operation').firstChild.src=document.getElementById('base_header_new_operation').firstChild.src.replace('_hover.gif','.gif');
	}
	}
	function close_new_level2_page(){
	change_new_image();
		document.getElementById('new_level2_page_content').innerHTML='';
		document.getElementById('new_level2_page_content').style.display='none';
	}
	function page_status(page_id,status){
		do_get_command('<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=page_status&page_id='); ?>'+page_id+'&status='+status);
	}
	function do_result(result){
	var token=result.split('^');
		switch(token[0]){
		case 'main_page_fetch_details':
		var page_id=token[1];
		document.getElementById('main_page_'+page_id).style.display='none';
		document.getElementById('ajax_main_page_'+page_id).innerHTML=token[2];
		break;
		case 'level2_page_fetch_details':
		var page_id=token[1];
		document.getElementById('main_page_'+page_id).style.display='none';
		document.getElementById('ajax_main_page_'+page_id).innerHTML=token[2];
		break;
		case 'fetch_edit_details':
		var page_id=token[1];
			<?php if (HTML_AREA_WYSIWYG_DISABLE == 'Enable') { ?>
            <?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
          		initEditor('page_description[<?php echo $languages[$i]['id']; ?>]');
     		<?php } } ?>
		document.getElementById('edit_details').innerHTML=token[2];
			
		document.getElementById('base_save_operation').style.display='';
		document.getElementById('base_save_operation').href="javascript: save_edit_page("+page_id+");";
		break;
		case 'level2_fetch_edit_details':
		var page_id=token[1];
			<?php if (HTML_AREA_WYSIWYG_DISABLE == 'Enable') { ?>
            <?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
          		initEditor('page_description[<?php echo $languages[$i]['id']; ?>]');
     		<?php } } ?>
		document.getElementById('level2_edit_details').innerHTML=token[2];
			
		document.getElementById('level2_base_save_operation').style.display='';
		document.getElementById('level2_base_save_operation').href="javascript: save_edit_page("+page_id+");";
		break;
		case 'load_main_page':
		document.getElementById('load_main_page_id').innerHTML=token[1];
		break;
		case 'search':
		document.getElementById('load_main_page_id').innerHTML=token[1];
		break;
		case 'new_static_page':
		document.getElementById('new_static_page_content').style.display='';
		document.getElementById('new_static_page_content').innerHTML=token[1];
			<?php if (HTML_AREA_WYSIWYG_DISABLE == 'Enable') { ?>
            <?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
          		initEditor('new_page_description[<?php echo $languages[$i]['id']; ?>]');
     		<?php } } ?>
		break;
		case 'page_status': 
		var page_id=token[1];
		document.getElementById('main_page_'+page_id).innerHTML=token[2];
		document.getElementById('main_page_'+page_id).style.display='none';
		document.getElementById('ajax_main_page_'+page_id).innerHTML=token[3];
		break;
		case 'new_level2_page':
		var page_id=token[1];
		document.getElementById('new_level2_page_content').innerHTML=token[2];
		document.getElementById('new_page_save_button_id').href="javascript: save_new_level2_page("+page_id+")";
		document.getElementById('close_button').href="javascript: close_new_level2_page();";
			<?php if (HTML_AREA_WYSIWYG_DISABLE == 'Enable') { ?>
            <?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
          		initEditor('new_page_description[<?php echo $languages[$i]['id']; ?>]');
     		<?php } } ?>
		parent_href="javascript: save_new_level2_page("+page_id+")";
		break;
		}
	}
	
	 function do_hover_change(element,eve){ 
		 var span_edit=document.getElementById("edit_details");
		 var span_delete=document.getElementById("delete_details");
		 var span_copy=document.getElementById("copy_details"); 
		 var span_move=document.getElementById("move_details"); 
		
		 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';
			    if(img_get_src.src==img_src+'template/img_copy.gif') {
					if(span_copy && span_copy.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_copy_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_copy_hover.gif' && span_copy && span_copy.style.display=="none") img_get_src.src=img_src+'template/img_copy.gif';
			    if(img_get_src.src==img_src+'template/img_move.gif') {
					if(span_move && span_move.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_move_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_move_hover.gif' && span_move && span_move.style.display=="none") img_get_src.src=img_src+'template/img_move.gif';
		  }
		 }		 
	 }  	

	 function do_hover_change2(element,eve){ 
		 var span_edit=document.getElementById("level2_edit_details");
		 var span_delete=document.getElementById("level2_delete_details");
		 var span_copy=document.getElementById("level2_copy_details"); 
		 var span_move=document.getElementById("level2_move_details"); 
		
		 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';
			    if(img_get_src.src==img_src+'template/img_copy.gif') {
					if(span_copy && span_copy.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_copy_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_copy_hover.gif' && span_copy && span_copy.style.display=="none") img_get_src.src=img_src+'template/img_copy.gif';
			    if(img_get_src.src==img_src+'template/img_move.gif') {
					if(span_move && span_move.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_move_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_move_hover.gif' && span_move && span_move.style.display=="none") img_get_src.src=img_src+'template/img_move.gif';
		  }
		 }		 
	 }  	

	var display_flag=1;
	function do_hover_change1(element,mode){
		if(display_flag==1){
		if (element.mode && mode==element.mode) return;
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
		}
		element.mode=mode;
	}
	
	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,page_id,type,sort_order){ 
					var row=document.getElementById(prefix+page_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=='load_main_page_'){
	var command="<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=main_page_sort_order&page_id='); ?>"+page_id+'&sort_order='+sort_order+'&type='+type;
	do_get_command(command);
	}else{
	var command="<?php echo tep_href_link(FILENAME_INFORMATION_PAGES,'command=level2_sort_order&page_id='); ?>"+page_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>