<?php
/*Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd */
/*

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

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
	tep_get_last_access_file();
	require('includes/classes/currencies.php');
	require('includes/classes/split_page_results_event.php');	
	$currencies=new currencies();
	$action=isset($HTTP_GET_VARS["action"])?$HTTP_GET_VARS["action"]:'';
	$found_results=false;
	$mID=isset($HTTP_GET_VARS["mID"])?(int)$HTTP_GET_VARS["mID"]:$HTTP_POST_VARS['message_id'];
	$page = (isset($HTTP_GET_VARS['page']) ? (int)$HTTP_GET_VARS['page'] : 1);
	if($action!=""){		
		//fetch admin users into combo array		
		if($action=='get_details'){
			echo_get_details();			
		}else if($action=='page_navigation'){
  			echo 'page_navigation';
			table_write();
  		}else if($action=='edit'){  		  		  		
  			echo 'edit';  			
			if ($mID>0){				
				tep_db_query("UPDATE " . TABLE_EVENTS_ADMIN_MESSAGES . " set message_unread='N' where message_id='" . (int)$mID . "'");
				$message_query=tep_db_query("SELECT am.message_id,am.message_from,am.message_to,am.message_date,am.message_subject,am.message_text,am.message_unread,concat(a.admin_firstname,' ',a.admin_lastname) as admin_name from " . TABLE_EVENTS_ADMIN_MESSAGES . " am, " . TABLE_ADMIN . " a where message_to='" . $login_email . "' " . $message_filter . " and am.message_from=a.admin_email_address order by am.message_date desc");
				if(tep_db_num_rows($message_query)>0) $message_result=tep_db_fetch_array($message_query);
			}else $action="new_message";
			
			if(!$HTTP_GET_VARS['mID']){			
				$admin_users=array();
				$admin_query=tep_db_query("SELECT admin_id,concat(admin_firstname,' ',admin_lastname) as admin_name,admin_email_address from " . TABLE_ADMIN . " where admin_hide_backend='N' order by admin_name");
				while($admin_result=tep_db_fetch_array($admin_query)){
					$admin_users[]=array('id'=>$admin_result["admin_email_address"],'text'=>$admin_result["admin_name"]);
				}
			}			
  			?>
  		 <table border="0" cellspacing="3" cellpadding="3" width="70%">  		 
  			<?php if($mID>0 && $action!='new_message'){ ?>
  				<tr>
				<td>
				 <table width="100%" border="0" cellspacing="2" cellpadding="2" >
					<tr>
						<td class="tableHeading" width="200"><?php echo TABLE_FROM;?></td>
						<td class="tableHeading" width="200"><?php echo TABLE_SUBJECT;?></td>
						<td class="tableHeading" width="100"><?php echo TABLE_DATE;?></td>
						<td class="tableHeading"><?php echo TABLE_TEXT;?></td>
					</tr>
					<tr class="attributes-odd">
						<td class="main" nowrap valign="top"><?php echo $message_result["admin_name"];?></td>
						<td class="main" nowrap valign="top"><?php echo $message_result["message_subject"];?></td>
						<td class="main" valign="top"><?php echo format_date($message_result["message_date"]);?></td>
						<td class="main" valign="top"><?php echo tep_output_string($message_result["message_text"]);?></td>
					</tr>
				</table>
			</td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>		
  			<?php }	?>
  			<tr>
				<td class="pageHeading"><?php echo ($action!='new_message'?TEXT_REPLY_MESSAGE:TEXT_NEW_MESSAGE); ?></td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
  			<tr> 
			 <td>
				<table border="0" cellspacing="5" cellpadding="2" >
				  <?php if ($action=='new_message'){ ?>
					<tr>
						<td class="main"><?php echo TEXT_MESSAGE_TO; ?></td>
						<td class="main"><?php echo tep_draw_pull_down_menu('message_to',$admin_users); ?></td>
					</tr>
					<?php } else echo '<input type=hidden name="message_to" value="' . $message_result['message_from'] . '">';						   
					?>
					<tr>
						<td class="main"><?php echo TEXT_MESSAGE_SUBJECT; ?></td>
						<td class="main"><?php echo tep_draw_input_field('message_subject','','size=40',true); ?></td>
					</tr>
					<tr>
						<td class="main" valign=top><?php echo TEXT_MESSAGE_TEXT; ?></td>
						<td class="main"><?php echo tep_draw_textarea_field('message_text','soft','80','24',$message_result['message_text'],'id="message_text"');?></td>
					</tr>
					<tr>
						<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif',50,10); ?></td>
					</tr>
				</table>
			</td>
		</tr>
  	  <?php 	  		                                             	        
	  echo '</table>';              		
	}else if($action=='update'){
		if($HTTP_POST_VARS['action_type']=='edit') $HTTP_POST_VARS["message_to"]=$HTTP_POST_VARS["message_to_assign"];
		$sql_array=array('message_from'=>$login_email,
						 'message_to'=>tep_db_prepare_input($HTTP_POST_VARS["message_to"]),
						 'message_date'=>getServerDate(true),
						 'message_subject'=>tep_db_prepare_input($HTTP_POST_VARS["message_subject"]),
						 'message_text'=>tep_db_prepare_input($HTTP_POST_VARS["message_text"]),
						 'message_unread'=>'Y');
		tep_db_perform(TABLE_EVENTS_ADMIN_MESSAGES,$sql_array);		
		$mID=tep_db_insert_id();
		echo 'new_message';					
		echo_get_details();	
	}else if($action=='delete_confirm' && $mID>0){					
		tep_db_query("DELETE from " . TABLE_EVENTS_ADMIN_MESSAGES . " where message_id in(" . $mID . ")");		
		echo 'delete_success';	
	}
		exit;
	} 
		
	function echo_get_details(){
  		global $mID,$login_id;
  		$message_query=tep_db_query("SELECT message_id,message_unread,message_from,message_to,date_format(message_date,'%Y-%m-%d') as message_date,message_subject,message_text from " . TABLE_EVENTS_ADMIN_MESSAGES . " where message_id='".(int)$mID."'");  		
  		if(tep_db_num_rows($message_query)>0){
	  		$message=tep_db_fetch_array($message_query);
  			while(list($key,$vals)=each($message)){						
			 	if($key=='message_date')
			 		$vals=format_date($vals);								 										 		
				$str_vals.=$vals."||";	
			}
			$admin_query=tep_db_query("SELECT concat(admin_firstname,' ',admin_lastname) as admin_name from " . TABLE_ADMIN . " where admin_id=" . $login_id);
			if(tep_db_num_rows($admin_query)>0){
				$admin_result=tep_db_fetch_array($admin_query);
				$str_vals.=$admin_result['admin_name'];			
			}
		}else $str_vals="No Record Found";			
		echo 'get_details'.$str_vals;  	
  }
  function table_write(){  	  
   global $login_email,$message_filter,$page;
   $query="SELECT am.message_id,am.message_from,am.message_to,am.message_date,am.message_subject,am.message_text,am.message_unread,concat(a.admin_firstname,' ',a.admin_lastname) as admin_name from " . TABLE_EVENTS_ADMIN_MESSAGES . " am, " . TABLE_ADMIN . " a where message_to='" . $login_email . "' " . $message_filter . " and am.message_from=a.admin_email_address order by am.message_id";      
   $messages_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $query, $messages_query_numrows);      
   $message_query=tep_db_query($query);
   $cnt=tep_db_num_rows($message_query);
   if ($cnt>0)	$found_results=true;
   if ($found_results) {?>
   <table border="0" width="100%" cellspacing="0" cellpadding="0">  
    <tr>
 	  <td colspan="3" id="ajax_details">
   	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
  <?php $rows=0;$currow=0;	
	while($message_result=tep_db_fetch_array($message_query)) {				
		$class="dataTableRowEven";
		if($row_cnt%2==0) $class="dataTableRowOdd";		
	?>					
		<tr class="<?php echo $class;?>" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)" onClick="javascript:if(document.getElementById('head_<?php echo $message_result['message_id'];?>').style.display=='none') expand_category(<?php echo $message_result["message_id"];?>,3);">
			  <td>
			   <div id="data_<?php echo $message_result['message_id'];?>">
			     <table border="0" cellspacing="0" cellpadding="3" width="80%">
			      <tr>            					
					<td class="main" width="20">
						<?php 	if ($message_result["message_unread"]=="Y") {
									echo tep_image(DIR_WS_ICONS . "unread.gif",IMAGE_UNREAD);
								} else {
									echo tep_image(DIR_WS_ICONS . "read.gif",IMAGE_READ);
								}
						?>
					</td>
					<td width="290" class="main" nowrap><?php echo $message_result["admin_name"];?></td>
					<td class="main" width="350"><?php echo $message_result["message_subject"];?></td>
					<td class="main"><?php echo format_date($message_result["message_date"]) . ' ' . date("H:m:s",strtotime($message_result["message_date"]));?></td>
				</tr>
              	</table>
               </div>
              <div style="display:none" class="openContent" id="head_<?php echo $message_result['message_id']	;?>"></div>
             </td>
            </tr> 		
	   <?php $row_cnt++;
	  	   }  ?>
	  	 	   <tr>
                <td colspan="2" align="right"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php  echo $messages_split->display_count($messages_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_MESSAGES); ?></td>
                    <td class="smallText" align="right"><?php echo $messages_split->display_script_links($messages_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','1'); ?></td>                     
                  </tr>
                </table></td>
              </tr>
             </table> 
  			</td>
  		</tr>		 
  	<?php } else { // found results ?>
		<tr><td class="smallText" colspan="5" align="center"><?php echo NO_RESULTS;?></td></tr>		
	<?php
		  } // check action ?>
	  </table>  	  
<?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 language="javascript" src="includes/general.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">					
	var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";	
	var max_display="<?php echo MAX_DISPLAY_SEARCH_RESULTS;?>";
	function validateForm(frm){ 									
				var id=0;				
				if(frm && frm.message_id) id=frm.message_id.value;								
				var span_details=document.getElementById("span_details");
				var span_edit=document.getElementById("span_edit");				
				var span_delete=document.getElementById("span_delete");					
				var loadings=document.getElementById("loading");
				if(frm.action_type) var action_type=frm.action_type.value; 										
				if(span_details && span_details.style.display=="") return false;
				if(frm && document.getElementById("message_subject") && document.getElementById("message_subject").value==""){					
						alert("<?php echo ERR_SUBJECT;?>");
						return false;															
				}else if(span_edit && span_edit.style.display==""){
					span_details.innerHTML=span_delete.innerHTML="";				
					command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=update');?>";																								
					if(loadings) loadings.style.display=""; 					
					if(span_edit) span_edit.style.display="none";	
				}
				if(command!="") do_post_command('frm_message',command);
				return false;
			}			
	function expand_category(id,category,r_type,sta){ 	 		
		if(!sta) sta="";
		var obj=document.getElementById("page_1");
		if(category=='1' && obj && sta!=""){
 	 		id=parseInt(obj.options[obj.selectedIndex].value);
 	 		if(sta=='next') {
 	 			if(obj.length==obj.selectedIndex+1) return;
 	 			id+=1;
 	 		}else if(sta=='prev') {
 	 			if(obj.selectedIndex==0) return;
 	 			id-=1;
 	 		}
 	 		if(id<=1) id=1;
 	 	}else if(category=='1' && sta=="") id="";
 	 	 var res_display=document.getElementById("res_display");
 	 	 if(res_display) res_display.style.display="none";
 	 	 	if(category!=1 && document.frm_message && document.frm_message.message_id && document.frm_message.message_id.value>0)  {
			var old_ids=document.frm_message.message_id.value;			
			var pre_data_id=document.getElementById("data_"+old_ids);
			var pre_head=document.getElementById("head_"+old_ids);			
			var loadings=document.getElementById("loading");						
			if(loadings) loadings.style.display="none";
			if(category==1 && pre_head && pre_head.innerHTML!='') pre_head.innerHTML="";									
		 }		 		 	 
		if(id>0 && document.frm_message.message_id.value>0 && document.frm_message.message_id.value!=id){			   
			   if(pre_head && pre_head.style.display=="") pre_head.style.display="none";
			   if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";			   			  
			   document.frm_message.message_id.value=id;			   
		}	
		if(category!=1 && document.frm_message && document.frm_message.message_id) document.frm_message.message_id.value=id; 														 								 	 	 	
 	 	if(category){
 	 		var span_details=document.getElementById("span_details");
 	 		var span_edit=document.getElementById("span_edit");			
			var span_delete=document.getElementById("span_delete");								
			var data_id=document.getElementById("data_"+id);						
			var head=document.getElementById("head_"+id);
			var img_save=document.getElementById("img_save");			
			var command="";																		 
 	 		switch(category){ 	 			
 	 			case '1': 	 			       
 	 			       var page=""; 	 			       						    
 	 			       if(id!="") page="&page="+id; 
 	 			       	command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=page_navigation');?>"+page;
 	 			   	   if(document.getElementById("ajax_details")) document.getElementById("ajax_details").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>"; 	 			   	    	 			   					   
 	 			break;
 	 			case 2:
 	 				 span_edit.style.display=""; 	 					 	 				 
 	 				 span_details.style.display=span_delete.style.display="none";
 	 				 span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 				 if(document.frm_message.action_type) document.frm_message.action_type.value='new'; 	 					
 	 				 command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=edit');?>"; 	 				  	 				  	 					 	 					 	 					 	 				 	 	
 	 			break; 	 			
 	 			case 3:
 	 			   if(head && head.style.display==""){
 	 			   	  if(span_details.style.display==""){
 	 			   	    head.style.display="none"; 	 			   	    
 	 			   	  	data_id.style.display=""; 	 			   	  	
 	 			   	  }else {
 	 			   	  	if(span_edit.style.display=="") span_edit.style.display="none";
 	 			   	  	if(span_delete.style.display=="") span_delete.style.display="none"; 	 			   	  	 	 			   	  	
 	 			   	  	span_details.style.display="";
 	 			   	  	if(img_save) img_save.style.display="none"; 
 	 			   	  	if(document.getElementById("img_ids")){
 	 			   	  		var tr_obj=document.getElementById("img_ids");
 	 			   	  		if(tr_obj.childNodes[1].childNodes[0].src==img_src+'template/img_copy_hover.gif')	
 	 			   	  			tr_obj.childNodes[1].childNodes[0].src=img_src+'template/img_copy.gif';
 	 			   	  		if(tr_obj.childNodes[2].childNodes[0].src==img_src+'template/img_edit_hover.gif')	
 	 			   	  			tr_obj.childNodes[2].childNodes[0].src=img_src+'template/img_edit.gif';
 	 			   	  		if(tr_obj.childNodes[3].childNodes[0].src==img_src+'template/img_trash_hover.gif')	
 	 			   	  			tr_obj.childNodes[3].childNodes[0].src=img_src+'template/img_trash.gif';	 	 			   	  			
 	 			   	  	}	 			   	  	  	 			   	  	 	 			   	  	
 	 			   	  }	 	 			    			   	   	 			   
 	 			 }else { 	 			 	 	 			 	
 	 			 	if(data_id && data_id.style.display=="") data_id.style.display="none";
 	 			 	if(pre_head && pre_head.style.display=="") pre_head.style.display="none"; 	 			 	
 	 			 	if(head) {
 	 			 	 	head.style.display=""; 	 			 	 	 	 			 	  	 			
 	 			 		head.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";	 			 		
 	 			 	}
 	 			 	command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=get_details');?>&mID="+id; 	 			 	 	 			 	
 	 			 }
 	 			break;
 	 			case 4:
 	 					span_edit.style.display=""; 	 					
 	 					span_details.style.display=span_delete.style.display="none";
 	 					span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					if(document.frm_message.action_type) document.frm_message.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=edit');?>&mID="+id; 	 		 	 					 	 					 	 				 	 		
 	 			break; 	 			
 	 			case 5:	 	 				 	 				 	 		 	 				
 	 					span_delete.style.display="";
 	 					span_edit.style.display=span_details.style.display="none";
 	 					span_delete.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=delete_confirm');?>&mID="+id; 	 	 	 					 	 					 	 			
 	 			break; 	 	 			
 	 		}
 	 		if(command!="") do_get_command(command);
 	 	}		
 	 }  	
   function do_result(result){
   	  if(result!=""){
   	    if(result.substr(0,11)=='get_details') print_details('get_details',result.substr(11));
   	    else if(result.substr(0,4)=='edit') print_details('edit',result.substr(4));  	 		 				 				
		else if(result.substr(0,14)=='delete_success') print_details('delete_success',result.substr(14));		
		else if(result.substr(0,15)=='page_navigation') print_details('page_navigation',result.substr(15));		
		else if(result.substr(0,11)=='new_message') print_details('new_message',result.substr(22));				   	   
   	  }
   }
   function print_details(category,result){ 	 	 	 	 	 	 	 	 	 	
 	 	var no_result="";
		if(result.substr(0,15)=='No Record Found')
 	 		no_result="No Record Found";
 	 	else if(result!='' && result.length>0 && category!='edit' && result.substr(0,15)!='No Record Found'){
 	 		splt_str=result.split("||"); 	 		 	 		 	 		  	 	
 	 		var  message_id="";
 	 		var  message_unread="";
			var  message_from="";
			var  message_to="";			
			var  message_date="";
			var  message_subject="";
			var  message_text	
			var  admin_name="";		 	 		
 	 		message_id=splt_str[0];
 	 		message_unread=splt_str[1];
			message_from=splt_str[2];
			message_to=splt_str[3];			
			message_date=splt_str[4];
			message_subject=splt_str[5];
			message_text=splt_str[6];	
			admin_name=splt_str[7];
 	 	}	   	 	
 	 	if(document.frm_message.message_to_assign && message_to) document.frm_message.message_to_assign.value=message_to;
 		if(document.frm_message && document.frm_message.message_id) var id=document.frm_message.message_id.value;
 		var span_details=document.getElementById("span_details");
 		var span_edit=document.getElementById("span_edit");
 		var span_delete=document.getElementById("span_delete");
 		var head=document.getElementById("head_"+id);
 		var data_id=document.getElementById("data_"+id);
 		var res_display=document.getElementById("res_display");
 		var img_save=document.getElementById("img_save");
		if(img_save && category!='get_details') img_save.style.display="";			
 	 	switch(category){ 	 		 	 		 	 		 	 		
 	 		case 'get_details': 	 		 	 		 	 	 		 	 		
 	 		if(head  && no_result!="")
				head.innerHTML=no_result; 	 			 	 		
 	 		else if(head && no_result==""){
	 	 		if(data_id){ 
	 	 			data_id.innerHTML='<table border="0" cellpadding="3" cellspacing="0" width="80%">'+
			      					'<tbody><tr>'+            					
										'<td class="main" width="20"><img src="images/icons/'+((message_unread=='N')?'read.gif':'unread.gif')+'" alt="'+((message_unread=='N')?'Read':'Unread')+'" title="'+((message_unread=='N')?'Read':'Unread')+'"  border="0"></td>'+
										'<td class="main" nowrap="nowrap" width="290">'+admin_name+'</td>'+
										'<td class="main" width="350">'+message_subject+'</td>'+
										'<td class="main">'+message_date+'</td>'+
									'</tr>'+
              						'</tbody></table>';	 	 			
	 	 		}	
	 	 		include="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+
				  '<td width="20">&nbsp;<img src="images/icons/'+((message_unread=='N')?'read.gif':'unread.gif')+'" alt="'+((message_unread=='N')?'Read':'Unread')+'" title="'+((message_unread=='N')?'Read':'Unread')+'"  border="0"></td>'+				  							  				  
				  "<td align='left' valign='middle' width='350' class='inner_title'>&nbsp;"+admin_name+"</td>"+
				  "<td width='470' align='left' class='main' valign='top'>"+
				  	"<table border='0' 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>"+
				  	  	"<td width='10%' onclick='javascript:change_class(this,1);expand_category("+message_id+",2);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='New' title='New' src='images/template/img_copy.gif'></td>"+
				  	    "<td width='10%' onclick='javascript:change_class(this,1);expand_category("+message_id+",4);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Edit' title='Edit' src='images/template/img_edit.gif'></td>"+
				  	    "<td width='10%' onclick='javascript:change_class(this,1);expand_category("+message_id+",5);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Delete' title='Delete' src='images/template/img_trash.gif'></td>"+				  	    
				  	    "<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
				  	  "</tr>"+
				  	"</table>"+
				  "</td>"+
				 "<td width='240' align='right' id='img_save' style='display:none'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category("+message_id+",3);'><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='openContent1'><span style='display:none' id='span_edit'></span><span style='display:none' id='span_delete'></span><span id='span_details'>"+	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+				  			
				  			"<td width='60' align='center'></td>"+				  							  
				  			"<td width='600'>"+				  							  			
				  				"<table width='80%' border='0' cellspacing='3' cellpadding='3' class='main'><tr>";				  									  						
				  					if(message_from!=""){				  				
					  					include+="<td align='left' width='10' valign='top'><?php echo TEXT_MESSAGE_FROM;?></td>"+
					  							 "<td align='left' width='170' valign='top'>"+message_from+"</td>";				  						
				  					}	
				  					if(message_to!=""){		  					
					  					include+="<td align='left' width='10'><?php echo TEXT_MESSAGE_TO;?></td>"+
					  							 "<td align='left' width='170'>"+message_to+"</td>";					  										
				  					}	
				  					include+="</tr><tr>";			  								  												  									  			  			  						
				  					if(message_date!=""){		  					
					  					include+="<td align='left' width='10'><?php echo TABLE_DATE;?></td>"+
					  							 "<td align='left' width='170'>"+message_date+"</td>";						
				  					}
				  					if(message_subject!=""){		  					
					  					include+="<td align='left' width='10'><?php echo TEXT_MESSAGE_SUBJECT;?></td>"+
					  							 "<td align='left' width='170'>"+message_subject+"</td>";					  											
				  					}				  								  								
					include+="</tr></span>"+
				  "</td>"+
				"</tr>"+
				"<tr>"+
						'<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif',50,10); ?></td>'+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
 	 		} 	 			 	 		
 	 	break;
 	 	case 'edit': 	 	 	 			 	 		 	 		 	 	
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){ 	 			 	 			
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}						
 	 		initEditor('message_text');			       			
 	 	break;
 	 	case 'delete': 	 				 	 	
 	 		if(span_delete) span_delete.style.display="";
 	 		if(span_delete){ 	 			
 	 			span_delete.innerHTML=result; 	 			
 	 			span_details.style.display=span_edit.style.display='none';
 	 		} 	 								   			   
 	 	break; 	 	
 	 	case 'delete_success':			 
 	    	 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 				 			
			 }
 	    	 if(res_display){	    	 	
 	    	 	res_display.innerHTML="<?php echo TEXT_MESSAGE_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 	var obj=document.getElementById("page_1");
 	    	 	if(obj){  	    	 		
 	    	 		var len=obj.options[obj.selectedIndex].value;
 	    	 		command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=page_navigation');?>&page="+len;
					do_get_command(command);
 	    	 	} 	    	 	
 	    	 } 	    	 			 			 			
 	 	break;	
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
 	 	break;	 	 	
		case 'new_message':			
				var obj=document.getElementById("page_1");
				if(data_id) {
					var tbl_obj=data_id.parentNode.parentNode.parentNode.parentNode;
					var tbl_obj_rows=tbl_obj.rows.length-1; 		
				}				
				if(obj && obj.options.length==obj.selectedIndex || !obj && tbl_obj_rows<max_display){
					result_splt=result.split('||');
					if(result_splt[0]>0){
						var id=result_splt[0];
						var resource_name=result_splt[1];	
						var resource_costs=result_splt[2];
						if(data_id) {    			    						
    						var row_obj=tbl_obj.insertRow(tbl_obj_rows);
    						var row_cell=row_obj.insertCell(0);
    						row_cell.innerHTML='<div id="data_'+message_id+'">'+
						       '<table border="0" cellpadding="3" cellspacing="0" width="100%">'+
			      					'<tbody><tr>'+            					
										'<td class="main" width="20"><img src="images/icons/'+((message_unread=='N')?'read.gif':'unread.gif')+'" alt="'+((message_unread=='N')?'Read':'Unread')+'" title="'+((message_unread=='N')?'Read':'Unread')+'"  border="0"></td>'+
										'<td class="main" nowrap="nowrap" width="290">'+admin_name+'</td>'+
										'<td class="main" width="350">'+message_subject+'</td>'+
										'<td class="main">'+message_date+'</td>'+
									'</tr>'+
              						'</tbody></table>'+
						      	'</div>'+
						        '<div style="display: none;" class="openContent" id="head_'+message_id+'"></div>';
						    var rows_cnt=tbl_obj.rows.length-2;
    						var tbl=tbl_obj.rows[rows_cnt];
    						tbl.onclick=function () { (document.getElementById('head_'+message_id) && document.getElementById('head_'+message_id).style.display!='none')?'':expand_category(message_id,3);};
    						tbl.style.height="18px"; 
    						if(rows_cnt%2==0) tbl.className="dataTableRowOdd";
    						else tbl.className="dataTableRowEven";
    						tbl.onmouseover=function (){rowOverEffect(this)};
    						tbl.onmouseout=function (){rowOutEffect(this)};
    						if(head && data_id){
    							head.style.display="none";
    							data_id.style.display="";
    						}
    						if(res_display){
					    	 res_display.innerHTML="<?php echo TEXT_MESSAGE_INSERT_SUCCESS;?>";
				 	    	 res_display.style.display=""; 	    	 	
 	    	 				} 
						}     					
					}											
				}else if(obj && obj.options.length>0 || tbl_obj_rows==max_display){
				 	if(obj) {
				 		var len=1;	
				 		len=parseInt(obj.options.length);
				 	}
				 	if(!obj && tbl_obj_rows==max_display) len=1; 
				 	command="<?php echo tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'action=page_navigation');?>&page="+len;
				 	do_get_command(command);
				}				 						
		break;
 	 	}
 	 	if(res_display.style.display=="") setTimeout("res_display.style.display='none'",2000); 	 	 	 	
 	 	clearTimeout();
	  }
	  function change_class(obj,eve){ 		 		 	 	
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");				 		 			 
		 if(obj){		   		    		    
		    var img_get_src=obj.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_copy.gif') {
					if(span_edit && span_edit.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_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_copy.gif';
			    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';		    		    		     		   	
		  }
		 }		 
	  }			
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- 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="0">
		<tr><td  class="main" id="res_display"></td></tr>									
		<tr>
		<td>
		<?php echo tep_draw_form('frm_message',FILENAME_EVENTS_ADMIN_MESSAGES,'','post','onSubmit="javascript:return validateForm(this);"');?>
		<table width="100%" border="0" cellspacing="0" cellpadding="2">
			<tr>								
				<td class="tableHeading" width="120" align="left"><?php echo TABLE_FROM;?></td>
				<td class="tableHeading" width="140"><?php echo TABLE_SUBJECT;?></td>
				<td class="tableHeading" width="160"><?php echo TABLE_DATE;?></td>
			</tr>
			<tr>
				<td colspan="3"><?php echo table_write();?></td>
			</tr>
		</table>
		<input type="hidden" name="action_type" id="action_type">
		<input type="hidden" name="message_id" id="message_id">
		<input type="hidden" name="message_to_assign" id="message_to_assign">		
		</form>
		</td>
		</tr>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '15'); ?></td>
		</tr>											
	</table>
	</td>
	<!-- body_eof //-->
	</tr>
</table>
<!-- body_eof //-->
	<!-- footer //-->
	<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
	<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
