<?php
/*
osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
  require('includes/application_top.php');
  require('includes/classes/split_page_results_event.php');
  $command=isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'';
  $newsletters_id=isset($HTTP_GET_VARS['newsletters_id'])?(int)$HTTP_GET_VARS['newsletters_id']:'';
  if($command!=''){
  	switch($command){
	case 'page_navigation_option':
		echo 'page_navigation_option^';
		global $page;
		$page=isset($HTTP_GET_VARS['page'])?(int)$HTTP_GET_VARS['page']:'';
		load_news_letter();
		break;
	case 'load_details':
		echo 'load_details^'.$newsletters_id.'^';
		load_details($newsletters_id);
		break;
	case 'lock':
		//$newsletters_id=isset($HTTP_GET_VARS['newsletters_id'])?$HTTP_GET_VARS['newsletters_id']:'' ;
		$lock_status=isset($HTTP_GET_VARS['lock_status'])?$HTTP_GET_VARS['lock_status']:'';
		tep_db_query("update ".TABLE_NEWSLETTERS." set locked='$lock_status' where newsletters_id='$newsletters_id'");
		echo 'lock^'.$newsletters_id.'^';
		load_details($newsletters_id);
		$newsletters_query=tep_db_query("select title from ".TABLE_NEWSLETTERS." where newsletters_id='$newsletters_id'");
		$newsletters_array=tep_db_fetch_array($newsletters_query);
		$title=$newsletters_array['title'];
		echo '^';
			if($lock_status==0)
				echo tep_image(DIR_WS_IMAGES.'icons/unlocked.gif','UnLock');
			else 
				echo tep_image(DIR_WS_IMAGES.'icons/locked.gif','Lock');
		echo '&nbsp;&nbsp;'.$title;
		break;
	case 'load_edit_details':
		echo 'load_edit_details^';
		//$newsletters_id=isset($HTTP_GET_VARS['newsletters_id'])?$HTTP_GET_VARS['newsletters_id']:'';
		load_edit_details($newsletters_id);
		break;
	case 'save_newsletters':
		$edit_modules=isset($HTTP_POST_VARS['edit_modules'])?$HTTP_POST_VARS['edit_modules']:'';
		$edit_content=isset($HTTP_POST_VARS['edit_content'])?tep_db_prepare_input($HTTP_POST_VARS['edit_content']):'';
		$edit_title=isset($HTTP_POST_VARS['edit_title'])?tep_db_prepare_input($HTTP_POST_VARS['edit_title']):'';
		tep_db_query("update ".TABLE_NEWSLETTERS." set module='$edit_modules',content='$edit_content',title='$edit_title' where newsletters_id='$newsletters_id'");
		echo 'edit_details^'.$newsletters_id.'^';
		load_details($newsletters_id);
		$newsletters_query=tep_db_query("select title,locked from ".TABLE_NEWSLETTERS." where newsletters_id='$newsletters_id'");
		$newsletters_array=tep_db_fetch_array($newsletters_query);
		$title=$newsletters_array['title'];
		echo '^';
			if($newsletters_array['locked']==0)
				echo tep_image(DIR_WS_IMAGES.'icons/unlocked.gif','UnLock');
			else 
				echo tep_image(DIR_WS_IMAGES.'icons/locked.gif','Lock');
		echo '&nbsp;&nbsp;'.$title;
		break;
	case 'delete':
		tep_db_query("delete from ".TABLE_NEWSLETTERS." where newsletters_id='$newsletters_id'");
		echo 'page_navigation_option^';
		load_news_letter();
		break;
	case 'mailsend':
		echo 'mail_send^'.$newsletters_id.'^';
		$newsletter_query = tep_db_query("select title, content, module from " . TABLE_NEWSLETTERS . " where newsletters_id = '" . (int)$newsletters_id . "'");
    $newsletter = tep_db_fetch_array($newsletter_query);

    $nInfo = new objectInfo($newsletter);
    include(DIR_WS_LANGUAGES . $language . '/modules/newsletters/' . $nInfo->module . substr(FILENAME_NEWSLETTERS, strrpos(FILENAME_NEWSLETTERS, '.')));
    include(DIR_WS_MODULES . 'newsletters/' . $nInfo->module . substr(FILENAME_NEWSLETTERS, strrpos(FILENAME_NEWSLETTERS, '.')));
    $module_name = $nInfo->module;
    $module = new $module_name($nInfo->title, $nInfo->content);
	if ($module->show_choose_audience) { echo $module->choose_audience('ajax'); } else { echo $module->confirm('ajax'); }
	break;
	case 'confirm_mail_send': 
	global $PHP_SELF;
	echo 'confirm_mail_send^';
	$newsletter_query = tep_db_query("select newsletters_id, title, content, module from " . TABLE_NEWSLETTERS . " where newsletters_id = '" . (int)$newsletters_id . "'");
    $newsletter = tep_db_fetch_array($newsletter_query);
    $nInfo = new objectInfo($newsletter);
    include(DIR_WS_LANGUAGES . $language . '/modules/newsletters/' . $nInfo->module . substr($PHP_SELF, strrpos($PHP_SELF, '.')));
    include(DIR_WS_MODULES . 'newsletters/' . $nInfo->module . substr($PHP_SELF, strrpos($PHP_SELF, '.')));
    $module_name = $nInfo->module;
    $module = new $module_name($nInfo->title, $nInfo->content);
	tep_set_time_limit(0);
  	flush();
  	$module->send($nInfo->newsletters_id);
	?>
	<table border="0" cellspacing="0" cellpadding="2">
    <tr>
    <td class="main" valign="middle"><?php echo TEXT_FINISHED_SENDING_EMAILS; ?></td>
    </tr>
    </table>
	<?php
	break;
	case 'save_new_newsletters':
	global $page;
	$new_module=isset($HTTP_POST_VARS['new_module'])?$HTTP_POST_VARS['new_module']:'';
	$new_title=isset($HTTP_POST_VARS['new_title'])?tep_db_prepare_input($HTTP_POST_VARS['new_title']):'';
	$cur_date=getServerDate(true);
	$new_newsletters_content=isset($HTTP_POST_VARS['new_newsletters_content'])?tep_db_prepare_input($HTTP_POST_VARS['new_newsletters_content']):'';
	tep_db_query('insert into '.TABLE_NEWSLETTERS." (module,title,content,date_added) values('$new_module','$new_title','$new_newsletters_content','$cur_date')");
	echo 'page_navigation_option^';
	load_news_letter();
	break;
	}
  exit;
  }
  
  tep_get_last_access_file();                                        
  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  $server_date = getServerDate(true);
?>

<?php
	function load_news_letter(){ global $page;
	$newsletters_query_raw="select newsletters_id,title,content,module,date_added,date_sent,status,locked from ".TABLE_NEWSLETTERS." order by title";
	$newsletters_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $newsletters_query_raw, $newsletters_numrows);	    
    $newsletters_query = tep_db_query($newsletters_query_raw);
	$class_name='dataTableRowOdd';
	echo '<table width="100%" cellpadding="2" cellspacing="2" border="0">';
	while($newsletters_array=tep_db_fetch_array($newsletters_query)){
	$class_name=($class_name=='dataTableRowOdd')?'dataTableRowEven':'dataTableRowOdd';
?>
	<tr id="newsletters_row_<?php echo $newsletters_array['newsletters_id']; ?>">
	<td>
	<div onClick="javascript: newsletters_row_focus(<?php echo $newsletters_array['newsletters_id']; ?>);" id="newsletters_<?php echo $newsletters_array['newsletters_id']; ?>" class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);">
	<?php  if($newsletters_array['locked']==1) echo tep_image(DIR_WS_IMAGES.'icons/locked.gif','Lock');
			else echo tep_image(DIR_WS_IMAGES.'icons/unlocked.gif','UnLock');
	echo '&nbsp;&nbsp;'.$newsletters_array['title']; ?>
	</div>
	<div id="ajax_newsletters_<?php echo $newsletters_array['newsletters_id']; ?>" style="display:none;">
	</div>
	</td>
	</tr>
<?php	
	}
	if(tep_db_num_rows($newsletters_query)<=0)
		echo '<tr><td align="center" id="no_result" style="color:#FF0000;" class="main">No Result Found</td></tr>';
	echo '<tr><td align="right" class="smallText">'.$newsletters_split->display_count($newsletters_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_NEWSLETTERS).
	$newsletters_split->display_script_links($newsletters_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'page_navigation(\'\'','1').'</td></tr>';
	echo '</table>';
	} // function end
?>
<?php
	function load_details($newsletters_id){
	$newsletters_query=tep_db_query("select newsletters_id,title,content,module,date_added,date_sent,status,locked from ".TABLE_NEWSLETTERS." where newsletters_id='$newsletters_id'");
	$newsletters_array=tep_db_fetch_array($newsletters_query);
?>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="openContent">
	<tr heigth="40" bgcolor="#EDF1FE" class="openContent_top">
	<td width="10" valign="top" align="center">&nbsp;</td>
	<td align="left" valign="middle" width="350" class="inner_title"><?php 
	if($newsletters_array['locked']==1) echo '<a href="javascript: lock('.$newsletters_id.',0)">'.tep_image(DIR_WS_IMAGES.'icons/locked.gif','Lock').'</a>'; else echo '<a href="javascript: lock('.$newsletters_id.',1)">'.tep_image(DIR_WS_IMAGES.'icons/unlocked.gif','UnLock').'</a>';
	echo '&nbsp;&nbsp;'.$newsletters_array['title']; ?></td>
	<td width="100" align="left" style="cursor:pointer;" class="main" valign="top">
		<table border="0" id="header_operation" cellspacing="0" cellpadding="0" style="width:100;height:30px;display:inline;position:relative;">
		<tr class="img_move" id="img_ids">
		<td class="cell_bg_popm_left" width="10">&nbsp;</td>
		<?php if($newsletters_array['locked']==1){ 
		echo '<td width="10%" onclick="javascript:do_hover_change(this,1);edit_newsletters('.$newsletters_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>'; 
		echo '<td width="10%" onclick="javascript:do_hover_change(this,1);delete_newsletters(' . $newsletters_id . ');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Delete;" title="Delete" src="images/template/img_trash.gif"></td>'; ?> 
		<td width="10"><?php echo '<a href="javascript: lock('.$newsletters_id.',0)">'.tep_image(DIR_WS_IMAGES.'icons/locked.gif','Lock').'</a>'; ?></td>
		<td width="10"><?php echo '<a href="javascript: mailsend('.$newsletters_id.')">'.tep_image(DIR_WS_IMAGES.'icons/mail.gif','Mail').'</a>'; ?></td>
		<?php } else { ?>
		<td width="10"><?php echo '<a href="javascript: lock('.$newsletters_id.',1)">'.tep_image(DIR_WS_IMAGES.'icons/unlocked.gif','UnLock').'</a>'; ?></td>
		<?php } ?>
		<td class="cell_bg_popm_right" width="10">&nbsp;</td>
		</tr>
		</table>
	</td>
	 <?php $style=''; if($newsletters_array['locked']==0){  $style=' style="visibility:hidden;" ';  } ?>
	<td width="400" align="right"><span><?php echo '<span '.$style.' id="main_operation"><a id="header_edit_operation" href="javascript: save_newsletters('.$newsletters_id.')">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a></span>'; 
	echo '&nbsp;&nbsp;<a href="javascript:void close_newsletters('.$newsletters_id.')">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a>'; ?></td>
	</tr>
	<tr>
	<td colspan="4" id="edit_details" style="display:none;"> </td>
	<td colspan="4" id="delete_details" style="display:none;"> </td>
	</tr>	
	<tr>
	<td colspan="4" id="preview_details">
		<table width="90%" cellpadding="2" class="main" cellspacing="2" border="0">
		<tr>
		<td width="100" align="right"><?php echo TEXT_NEWSLETTER_MODULE; ?></td>
		<td align="left"><?php echo $newsletters_array['module']; ?></td>
		<td width="100" align="right"><?php echo TEXT_NEWSLETTER_DATE_ADDED; ?></td>
		<td width="100"><?php echo format_date($newsletters_array['date_added']); ?></td>
		<td width="100" align="right"><?php echo TABLE_HEADING_SENT; ?>:</td>
		<td width="100"><?php if($newsletters_array['status']==1) echo tep_image(DIR_WS_IMAGES.'icons/tick.gif'); else echo tep_image(DIR_WS_ICONS . 'cross.gif', ICON_CROSS); ?></td>
		</tr>
		<tr>
		<td align="right"><?php echo TEXT_NEWSLETTER_CONTENT; ?></td>
		<td colspan="5"><?php echo $newsletters_array['content']; ?></td>
		</tr>
		</table>
	</td>
	</tr>
	<tr>
		<td colspan="4" align="center" id="mail_details" style="display:none;"></td>
	</tr>
	<tr>
		<td colspan="4" id="new_content" style="display:none;">
		<?php new_content_function(); ?>
		</td>
	</tr>	
	<tr>
	<td colspan="4"><br></td>
	</tr>
	</table>
<?php
	}
	function new_content_function(){
	global $PHP_SELF;

		$file_extension = substr(FILENAME_NEWSLETTERS, strrpos(FILENAME_NEWSLETTERS, '.')); 
		$directory_array = array(); 
		if ($dir = dir(DIR_WS_MODULES . 'newsletters/')) {
		  while ($file = $dir->read()) { 
			if (!is_dir(DIR_WS_MODULES . 'newsletters/' . $file)) {
			  if (substr($file, strrpos($file, '.')) == $file_extension) { 
				$directory_array[] = $file;
			  }
			}
		  } 
		  sort($directory_array);
		  $dir->close();
		}
	
		for ($i=0, $n=sizeof($directory_array); $i<$n; $i++) {
		  $modules_array[] = array('id' => substr($directory_array[$i], 0, strrpos($directory_array[$i], '.')), 'text' => substr($directory_array[$i], 0, strrpos($directory_array[$i], '.')));
		}
	echo tep_draw_form('save_new_newsletters',FILENAME_NEWSLETTERS,'','post');
?>
	<table width="100%" cellpadding="2" cellspacing="2" border="0">
		<tr>
		<td width="200" class="main" align="right"><?php echo TEXT_NEWSLETTER_MODULE; ?></td>
		<td><?php echo tep_draw_pull_down_menu('new_module',$modules_array);  ?></td>
		<td width="500">&nbsp;</td>
		</tr>
		<tr>
		<td class="main" align="right"><?php echo TEXT_NEWSLETTER_TITLE; ?></td>
		<td><?php echo tep_draw_input_field('new_title','','',true); ?></td>
		<td></td>
		</tr>
		<tr>
		<td class="main" align="right"><?php echo TEXT_NEWSLETTER_CONTENT; ?></td>
		<td><?php echo tep_draw_textarea_field('new_newsletters_content', 'soft', '80', '24', '','id="new_newsletters_content"'); ?></td>
		<td></td>
		</tr>
		</table>
	</form>
<?php 
	} // new_content_function end
	
	function load_edit_details($newsletters_id){ 
	$newsletters_edit_query=tep_db_query("select title,content,module from ".TABLE_NEWSLETTERS." where newsletters_id='$newsletters_id'");
	$newsletters_edit_array=tep_db_fetch_array($newsletters_edit_query);
	
	$nInfo=new ObjectInfo($newsletters_edit_array);
		$file_extension = substr(FILENAME_NEWSLETTERS, strrpos(FILENAME_NEWSLETTERS, '.')); 
		$directory_array = array(); 
		if ($dir = dir(DIR_WS_MODULES . 'newsletters/')) {
		  while ($file = $dir->read()) { 
			if (!is_dir(DIR_WS_MODULES . 'newsletters/' . $file)) {
			  if (substr($file, strrpos($file, '.')) == $file_extension) { 
				$directory_array[] = $file;
			  }
			}
		  } 
		  sort($directory_array);
		  $dir->close();
		}
	
		for ($i=0, $n=sizeof($directory_array); $i<$n; $i++) {
		  $modules_array[] = array('id' => substr($directory_array[$i], 0, strrpos($directory_array[$i], '.')), 'text' => substr($directory_array[$i], 0, strrpos($directory_array[$i], '.')));
		}
		echo tep_draw_form('save_newsletters',FILENAME_NEWSLETTERS,'','post');
?>
		
		<table width="100%" class="main" cellpadding="2" cellspacing="2" border="0">
		<tr>
		<td width="200" align="right"><?php echo TEXT_NEWSLETTER_MODULE; ?></td>
		<td><?php echo tep_draw_pull_down_menu('edit_modules',$modules_array,$nInfo->module);  ?></td>
		<td width="500">&nbsp;</td>
		</tr>
		<tr>
		<td align="right"><?php echo TEXT_NEWSLETTER_TITLE; ?></td>
		<td><?php echo tep_draw_input_field('edit_title',$nInfo->title,'',true); ?></td>
		<td></td>
		</tr>
		<tr>
		<td align="right"><?php echo TEXT_NEWSLETTER_CONTENT; ?></td>
		<td><?php echo tep_draw_textarea_field('edit_content', 'soft', '80', '24', $nInfo->content,'id="edit_content"'); ?></td>
		<Td></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/menu.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/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="bottom" class="dataTableHeadingRow" style="height:25px;">
<td colspan="2" style="padding-top:3px;height:23px">&nbsp;&nbsp;<?php echo '<a id="img_new" onMouseOver="do_hover_change1(this,2);" onMouseOut="do_hover_change1(this,1);" href="javascript: new_marketing_newsletters();">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','New','22','22').'</a>'; ?></td>
</tr>
<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>
<tr>
<td colspan="2" class="dataTableHeadingRow">&nbsp;&nbsp;<?php echo HEADING_TITLE; ?></td>
</tr>
<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>
<tr>
<td width="10">&nbsp;</td>
<td id="newsletters_table">
	<?php load_news_letter(); ?>
</td>
</tr>
</table>

<table width="100%" class="openContent" id="new_marketing_newsletters_content" style="display:none;" cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td width="100"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;&nbsp;'.TABLE_HEADING_NEWSLETTERS; ?></td>
	<td align="right"><?php echo '<a href="javascript: save_new_newsletters();">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','').'</a>&nbsp;&nbsp;<a href="javascript: close_new_marketing_newsletters();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','').'</a>'; ?></td>
	</tr>
	<tr>
	<td colspan="2" align="center"><?php new_content_function(); ?></td>
	
	</tr>
</table>

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<div id="ajax_image_load" style="display:none;"><?php echo tep_image(DIR_WS_IMAGES.'24-1.gif'); ?></div>
</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 previous_newsletters_id='';
var html_area_flag=0;
	function new_marketing_newsletters(){
		if(document.getElementById('no_result'))
			document.getElementById('no_result').style.display='none';
	display_flag=0;
	document.getElementById('new_marketing_newsletters_content').style.display='';
		<?php if (HTML_AREA_WYSIWYG_DISABLE_NEWSLETTER == 'Enable') { ?>
			if(html_area_flag==0)
           		initEditor('new_newsletters_content');
		   html_area_flag=1;
	<?php } ?>
	if(previous_newsletters_id!='')
			close_newsletters(previous_newsletters_id);
	}
	function change_new_image(element){
	element.firstChild.src=element.firstChild.src.replace('_hover.gif','.gif');
	}
	function close_new_marketing_newsletters(){
		if(document.getElementById('no_result'))
			document.getElementById('no_result').style.display='';
	display_flag=1;
	change_new_image(document.getElementById('img_new'));
	document.getElementById('new_marketing_newsletters_content').style.display='none';
	document.getElementById('new_title').value='';
	if(document.getElementById('if_new_newsletters_content'))
	document.getElementById('if_new_newsletters_content').contentWindow.document.body.innerHTML='';
	}

	function newsletters_row_focus(newsletters_id){
		if(previous_newsletters_id!='')
			close_newsletters(previous_newsletters_id);
	document.getElementById('ajax_newsletters_'+newsletters_id).style.display='';
	document.getElementById('ajax_newsletters_'+newsletters_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;
	var command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=load_details&newsletters_id='); ?>"+newsletters_id;
	previous_newsletters_id=newsletters_id;
	do_get_command(command);
	close_new_marketing_newsletters();
	}
	
	function close_newsletters(newsletters_id){
		if(document.getElementById('ajax_newsletters_'+newsletters_id) && document.getElementById('newsletters_'+newsletters_id)){
		document.getElementById('ajax_newsletters_'+newsletters_id).innerHTML='';
		document.getElementById('ajax_newsletters_'+newsletters_id).style.display='none';
		document.getElementById('newsletters_'+newsletters_id).style.display='';
		}
	
	}
	function delete_newsletters(newsletters_id){
		document.getElementById('delete_details').style.display='';
		document.getElementById('edit_details').style.display='none';
		if(confirm('<?php echo TEXT_INFO_DELETE_INTRO; ?>')){
		var command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=delete&newsletters_id='); ?>"+newsletters_id;	
		do_get_command(command);
		}else{
		close_newsletters(newsletters_id);
		}
	}
	function page_navigation(arg1,agr2,agr3,agr4){
		var page_no=1;
		if(agr2==1) var obj=document.getElementById("page_1");
		else if(agr2==2) var obj=document.getElementById("page_2");
		if(agr2 && agr4){
			if(obj){
 	 			page_no=parseInt(obj.options[obj.selectedIndex].value);
 	 			if(agr4=='next') {
 	 				if(obj.length==obj.selectedIndex+1) return;
 	 				page_no+=1;
 	 			}else if(agr4=='prev') {
	 	 			if(obj.selectedIndex==0) return;
 		 			page_no-=1;
 	 			}
 	 			if(page_no<=1) page_no=1;
 	 		} 	 		
		}				
		if(agr2==1) command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=page_navigation_option'); ?>&page="+page_no;
		else if(agr2==2) command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=page_navigation_attribute'); ?>&page="+page_no;		
		if(command!="") do_get_command(command);
	}
	function lock(newsletters_id,lock_status){
	var command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=lock&newsletters_id='); ?>"+newsletters_id+'&lock_status='+lock_status;
	do_get_command(command);
	}
	function edit_newsletters(newsletters_id){ close_all();
	document.getElementById('edit_details').style.display='';
	document.getElementById('delete_details').style.display='none';
	document.getElementById('edit_details').innerHTML=document.getElementById('ajax_image_load').innerHTML;
	document.getElementById('preview_details').style.display='none';
	document.getElementById('header_edit_operation').href="javascript: save_newsletters("+newsletters_id+");";
	document.getElementById('mail_details').style.display='none';
	var command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=load_edit_details&newsletters_id='); ?>"+newsletters_id;
	do_get_command(command);

	}
	function save_newsletters(newsletters_id){
		if(document.getElementById('edit_title')){
			if(document.getElementById('edit_title').value=='' || (str_trim(document.getElementById('edit_title').value)=='') ){
			alert("<?php echo ERROR_NEWSLETTER_TITLE; ?>");
			}else {
			document.getElementById('edit_content').value=document.getElementById('if_edit_content').contentWindow.document.body.innerHTML;
			do_post_command('save_newsletters','<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=save_newsletters&newsletters_id='); ?>'+newsletters_id);
			}
		}	
	}
	function new_newsletters(){
	close_all();
	display_flag=1;
	change_new_image(document.getElementById('img_new'));
	document.getElementById('new_content').style.display='';
		<?php if (HTML_AREA_WYSIWYG_DISABLE_NEWSLETTER == 'Enable') { ?>
			if(document.getElementById('new_newsletters_content'))
				initEditor('new_newsletters_content')
		<?php } ?>
	document.getElementById('main_operation').style.visibility='visible';
	document.getElementById('header_edit_operation').href='javascript: save_new_newsletters();';
	}
	function save_new_newsletters(){
	obj=document.getElementById('new_title').value;
		if(obj=='' || str_trim(obj)=='')
			alert('<?php echo ERROR_NEWSLETTER_TITLE; ?>');
		else{
		document.getElementById('new_newsletters_content').value=document.getElementById('if_new_newsletters_content').contentWindow.document.body.innerHTML;
		do_post_command('save_new_newsletters','<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=save_new_newsletters'); ?>');
		}
	
	}
	function close_all(){
		document.getElementById('preview_details').style.display='none';
		document.getElementById('edit_details').style.display='none';
		document.getElementById('delete_details').style.display='none';
		document.getElementById('mail_details').style.display='none';
		document.getElementById('new_content').style.display='none';
	}
	function mailsend(newsletters_id){
	document.getElementById('edit_details').style.display='none';
	document.getElementById('preview_details').style.display='none';
	document.getElementById('delete_details').style.display='none';
	document.getElementById('mail_details').style.display='';
	document.getElementById('mail_details').innerHTML=document.getElementById('ajax_image_load').innerHTML;
	var command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=mailsend&newsletters_id='); ?>"+newsletters_id;
	do_get_command(command);
	}
	function do_result(result){  close_new_marketing_newsletters();
		/*if(document.getElementById('base_new_content')&&document.getElementById('base_new_header')){
			document.getElementById('base_new_content').innerHTML='';
			document.getElementById('base_new_header').innerHTML='';
		}*/
	var token=result.split('^');
	switch(token[0]){
		case 'page_navigation_option':
		document.getElementById('newsletters_table').innerHTML=token[1];
		break;
		case 'load_details': 
		var newsletters_id=token[1];
		document.getElementById('ajax_newsletters_'+newsletters_id).innerHTML=token[2];
		document.getElementById('newsletters_'+newsletters_id).style.display='none';
		document.getElementById('main_operation').style.visibility='hidden';	
		break;
		case 'load_edit_details':
		document.getElementById('edit_details').innerHTML=token[1];
		document.getElementById('main_operation').style.visibility='visible';
		<?php if (HTML_AREA_WYSIWYG_DISABLE_NEWSLETTER == 'Enable') { ?>
			if(document.getElementById('edit_content'))
				initEditor('edit_content')
		<?php } ?>
		break;
		case 'lock':
		var newsletters_id=token[1];
		document.getElementById('ajax_newsletters_'+newsletters_id).innerHTML=token[2];
		document.getElementById('newsletters_'+newsletters_id).innerHTML=token[3];
		if(document.getElementById('main_operation'))
			document.getElementById('main_operation').style.visibility='hidden';	
		break;
		case 'edit_details':
		var newsletters_id=token[1]; 
		document.getElementById('ajax_newsletters_'+newsletters_id).innerHTML=token[2];
		document.getElementById('newsletters_'+newsletters_id).innerHTML=token[3];
		document.getElementById('main_operation').style.visibility='hidden';	
		break;
		case 'mail_send':
		var newsletters_id=token[1];
		document.getElementById('main_operation').style.visibility='visible';
		document.getElementById('header_edit_operation').href="javascript:void mail_confirm_send("+newsletters_id+");";
		document.getElementById('mail_details').innerHTML=token[2];
		break;
		case 'confirm_mail_send':
		document.getElementById('mail_details').innerHTML=token[1];
		
		break;
	}
	}
	function mail_confirm_send(newsletters_id){
	//var command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=confirm_mail_send&newsletters_id='); ?>"+newsletters_id;
	//do_get_command(command);
	if(document.forms['notification'])
		do_post_command('notifications','<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=confirm_mail_send&newsletters_id='); ?>'+newsletters_id);
	else{
		var chosen_array=new Array(); 
			for(i=0;i<document.getElementsByName('chosen[]').length;i++){
			chosen_array[i]=document.getElementById('chosen[]')[i].value;
			}
		var command="<?php echo tep_href_link(FILENAME_NEWSLETTERS,'command=confirm_mail_send&newsletters_id='); ?>"+newsletters_id+'&chosen='+chosen_array;
		do_get_command(command);
	}
	}

	 function do_hover_change(element,eve){ 
		 var span_edit=document.getElementById("edit_details");
		 var span_delete=document.getElementById("delete_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';
		  }
		 }		 
	 }  	

function mover(move) {
  if (move == 'remove') {
    for (x=0; x<(document.notifications.products.length); x++) {
      if (document.notifications.products.options[x].selected) {
        with(document.notifications.elements['chosen[]']) {
          options[options.length] = new Option(document.notifications.products.options[x].text,document.notifications.products.options[x].value);
        }
        document.notifications.products.options[x] = null;
        x = -1;
      }
    }
  }
  if (move == 'add') {
    for (x=0; x<(document.notifications.elements['chosen[]'].length); x++) {
      if (document.notifications.elements['chosen[]'].options[x].selected) {
        with(document.notifications.products) {
          options[options.length] = new Option(document.notifications.elements['chosen[]'].options[x].text,document.notifications.elements['chosen[]'].options[x].value);
        }
        document.notifications.elements['chosen[]'].options[x] = null;
        x = -1;
      }
    }
  }
  return true;
}

function selectAll(FormName, SelectBox) {
  temp = "document." + FormName + ".elements['" + SelectBox + "']";
  Source = eval(temp);

  for (x=0; x<(Source.length); x++) {
    Source.options[x].selected = "true";
  }

  if (x<1) {
    alert('<?php JS_PLEASE_SELECT_PRODUCTS ?>');
    return false;
  } else {
    return true;
  }
}
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;
	} 
</script>
