<?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 Zac Inc 
		
		Released under the GNU General Public License
	*/
	// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
	$server_date = getServerDate();
	require('includes/classes/split_page_results_event.php');
	require(DIR_WS_CLASSES . 'currencies.php');
	$currencies = new currencies();	
	$page=isset($HTTP_GET_VARS['page'])?$HTTP_GET_VARS['page']:1;	
	$action=isset($HTTP_GET_VARS['action'])?$HTTP_GET_VARS['action']:'';
	$fID=isset($HTTP_GET_VARS['fID'])?$HTTP_GET_VARS['fID']:$HTTP_POST_VARS['featured_id'];
	if($action!=""){		
		if($action=='get_details'){
			echo_get_details();	
		}else if($action=='page_navigation'){ 
			echo 'page_navigation';
			table_write();	 	
		}else if($action=='edit'){ 
			$product=array('products_name'=>'','expires_date'=>$server_date);
			if($fID>0){				
				$product_query = tep_db_query("select p.products_id, pd.products_name,s.expires_date from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_FEATURED . " s where p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = s.products_id and s.featured_id = '" . $fID . "' order by pd.products_name");
      			$product = tep_db_fetch_array($product_query);
			}  
      	    $sInfo = new objectInfo($product);      	          	    
			$featured_array = array();
      		$featured_query = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p, " . TABLE_FEATURED . " s where s.products_id = p.products_id");
      		while ($featured = tep_db_fetch_array($featured_query)) {
        		$featured_array[] = $featured['products_id'];
      		}      		
      		if($fID>0)echo 'edit';	      		
			else echo 'new';
		?>
		  <table border="0" cellspacing="0" cellpadding="3" width="100%">
          <?php if(!$fID>0) {?>
		  <tr class="openContent_top" style="cursor:pointer;cursor:hand;">
		   <td colspan="2">
		     <table border="0" cellpadding="0" cellspacing="0" width="100%">
			   <tr>
			     <td  width="90%" onClick="javascript:expand_new('close');">&nbsp;</td>
		  		 <td align="right" ><input type="image" src="images/template/img_savel.gif" alt="save" title="save" border="0">&nbsp;&nbsp;<a href="javascript:expand_new('close');"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a></td>
			   </tr>
			 </table>
		   </td>			
		  </tr><?php } ?>
		  <tr>
            <td class="main" width="30"><?php echo TEXT_FEATURED_PRODUCT; ?>&nbsp;</td>
            <td class="main" width="85%"><?php echo ($sInfo->products_name) ? $sInfo->products_name :tep_draw_products_pull_down('products_id', 'style="font-size:10px"', $featured_array); ?></td>
		 </tr>
          <tr>
            <td class="main" width="100" nowrap="nowrap"><?php echo TEXT_FEATURED_EXPIRES_DATE; ?>&nbsp;</td>            
            <td class="main" align="left" width="25%"><?php echo tep_draw_input_field("expire_date",isset($sInfo->expires_date)?format_date($sInfo->expires_date):format_date($server_date));
            	  $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
            	  <a href="javascript:show_calendar('frm_feature.expire_date',null,null,'<?php echo $date_format;?>');"
							onmouseover="window.status='Date Picker';return true;"
							onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/ >  
		   </a></td>
          </tr>
		  <tr><td colspan="2"><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></td></tr>
        </table>
  <?php	}else if($action=='setflag'){
  			tep_set_featured_status($fID, $HTTP_GET_VARS['flag']);
  		}else if($action=='update'){
  			$expires_date = '';
			$expires_date =isset($HTTP_POST_VARS['expire_date'])?tep_convert_date_raw($HTTP_POST_VARS['expire_date']):'000-00-00';
  			if(!$HTTP_GET_VARS['fID']){  															
				tep_db_query("insert into " . TABLE_FEATURED . " (products_id, featured_date_added, expires_date, status) values ('" . $HTTP_POST_VARS['products_id'] . "','" . $server_date . "', '" . $expires_date . "', '1')");
				echo 'new_featured';			
  			}else if($HTTP_GET_VARS['fID'])  			
				tep_db_query("update " . TABLE_FEATURED . " set featured_last_modified = '" . $server_date ."', expires_date = '" . $expires_date . "' where featured_id = '" . $HTTP_POST_VARS['featured_id'] . "'");		  			
  				echo_get_details();  			
  		}else if($action=='delete'){	  		
	  		/*$featured = 'delete';
			$featured.="<table border='0' cellspacing='2' cellpadding='1' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
				$featured.='<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_DELETE_FEATURED . '</td></tr>';
				$featured.='<tr><td></td><td width="500" align="left" class="main">'.TEXT_INFO_DELETE_INTRO. '</td></tr>';
				$featured.='<tr><td></td><td  width="500" align="left" class="main"><b>'.$sInfo->products_name. '</b></td></tr>';	  		
			echo $featured.='</table>';*/
  		}else if($action=='delete_confirm'){  					 
			tep_db_query("delete from " . TABLE_FEATURED . " where featured_id = '" . tep_db_input($fID) . "'");
			echo 'delete_success';
  		}
		exit;
	}		
	function tep_set_featured_status($featured_id, $status) {		 
		 global $server_date;
		 if ($status == '1') 
			return tep_db_query("update " . TABLE_FEATURED . " set status = '1' where featured_id = '" . $featured_id . "'");
		 elseif ($status == '0') 
			return tep_db_query("update " . TABLE_FEATURED . " set status = '0', date_status_change = '" . $server_date . "' where featured_id = '" . $featured_id . "'");
		 else 
			return -1;		
	}
	function echo_get_details(){
   	 global $languages_id,$fID;
   	   $str_vals="";		
	  $product_query = tep_db_query("select s.featured_id,pd.products_name,date_format(s.featured_date_added,'%Y-%m-%d') as featured_date_added,date_format(s.featured_last_modified,'%Y-%m-%d') as featured_last_modified,p.products_image_1,p.products_title_1,date_format(s.expires_date,'%Y-%m-%d') as expires_date,date_format(s.date_status_change,'%Y-%m-%d') as date_status_change,s.status  from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_FEATURED . " s where p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = s.products_id and s.featured_id = '" . $fID . "'");		 
	   if(tep_db_num_rows($product_query)>0){
		  $featured = tep_db_fetch_array($product_query);
		  while(list($key,$vals)=each($featured)){									 	 			 
			if($key=='expires_date' || $key=='featured_date_added' || $key=='featured_last_modified' || $key=='date_status_change')
				$vals=format_date($vals);			 		
			$str_vals.=$vals.'||';
		 }
	  }else $str_vals="No Record Found";
		echo 'get_details'.$str_vals;
  }
function table_write(){
	global $page,$languages_id;
	echo '<table border="0" width="100%" cellspacing="0" cellpadding="0">';
	$featured_query_raw = "select p.products_id, pd.products_name, s.featured_id, s.featured_date_added, s.featured_last_modified, s.expires_date, s.date_status_change, s.status from " . TABLE_PRODUCTS . " p, " . TABLE_FEATURED . " s, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = s.products_id order by s.featured_id desc";
	$featured_split = new splitPageResultsEvent($page, MAX_DISPLAY_FEATURED_PRODUCTS_LISTING, $featured_query_raw, $featured_query_numrows);
	$featured_query = tep_db_query($featured_query_raw);
	$i=0;
	if(tep_db_num_rows($featured_query)>0){
	while ($featured = tep_db_fetch_array($featured_query)) {
		if ( ((!$HTTP_GET_VARS['sID']) || ($HTTP_GET_VARS['sID'] == $featured['featured_id'])) && (!$sInfo) ) {		
			$products_query = tep_db_query("select products_image_1,products_title_1 from " . TABLE_PRODUCTS . " where products_id = '" . $featured['products_id'] . "'");
			$products = tep_db_fetch_array($products_query);
			$sInfo_array = array_merge($featured, $products);
			$sInfo = new objectInfo($sInfo_array);
		}
		
		$class="dataTableRowEven";
		if($i%2==0) $class="dataTableRowOdd";
		$i++;	      
		echo '<tr height="20" class="'.$class.'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$featured['featured_id'].'\').style.display==\'none\') expand_category(' . $featured['featured_id'] . ',3);">' . "\n";    
?>
			<td colspan="2">
			 <div id="data_<?php echo $featured['featured_id'];?>">
			  <table border="0" cellspacing="0" cellpadding="3" width="100%">
			   <tr>
				<td  class="dataTableContent">
				<?php 
					if ($featured['status'] == '1')
						echo tep_image(DIR_WS_IMAGES . 'template/icon_active.gif', IMAGE_ICON_STATUS_GREEN, 10, 10);
					else
						echo tep_image(DIR_WS_IMAGES . 'template/icon_inactive.gif', IMAGE_ICON_STATUS_RED, 10, 10);
					echo tep_draw_separator('pixel_trans.gif','10','10');
					echo $featured['products_name'];
				?>
				 </td>
			    </tr>
			    </table>
			    </div>
			   <div style="display:none" class="openContent" id="head_<?php echo $featured['featured_id'];?>"></div> 
			   </td>		 		  	 	  	
       		   </tr>            
<?php 		
	}
	
	} else { echo '<tr><td class=main id="no_record" align=center>No Records Found </td></tr>'; } 
	
	//if(tep_db_num_rows($featured_query)<=0) ?>
	<tr><td class="main"  align="center"><?php //echo TEXT_NO_RECORDS_FOUND; ?></td></tr>
	<tr>
       <td class="smallText" valign="top"><?php echo $featured_split->display_count($featured_query_numrows, MAX_DISPLAY_FEATURED_PRODUCTS_LISTING, $page, TEXT_DISPLAY_NUMBER_OF_FEATURED); ?></td>
       <td class="smallText" align="right"><?php echo $featured_split->display_script_links($featured_query_numrows, MAX_DISPLAY_FEATURED_PRODUCTS_LISTING, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','1'); ?></td>        
    </tr>
    </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/date-picker.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript" src="includes/http.js"></script>
<?php require('includes/date_format_js.php');?>
<script languages="javascript">
var max_display="<?php echo MAX_DISPLAY_FEATURED_PRODUCTS_LISTING;?>";
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var server_date="<?php echo getServerDate();?>";
 function ValidateForm(){
	var id=0;
	var frm=document.frm_feature;
	if(frm && frm.featured_id) id=frm.featured_id.value;
	if(document.getElementById("span_details")) var span_details=document.getElementById("span_details");
	if(document.getElementById("span_edit")) var span_edit=document.getElementById("span_edit");
	if(document.getElementById("span_delete")) var span_delete=document.getElementById("span_delete");
	if(document.getElementById("loading")) var loadings=document.getElementById("loading");
	if(document.getElementById("prd_new")) var prd_new = document.getElementById("prd_new");
	var error_result=command="";
	if(frm.action_type) var action_type=frm.action_type.value;
	if(span_details && span_details.style.display!="" && span_edit.style.display=='' && prd_new.style.display=='none'){
			if(server_date) var server_date_obj=date_format(server_date,'y-m-d','y-m-d',true).getTime();
	  	    if(frm.expire_date && frm.expire_date.value) var expire_date_obj=date_format(frm.expire_date.value,'','y-m-d',true).getTime();	  	    	  	    	  	    	  	    	  	   
	  	    if(frm.expire_date && frm.expire_date.value=="")
				error_result="<?php echo ERR_EXPIRY_DATE;?>\n";	  	    	
	  	    else if(server_date_obj>=expire_date_obj)
	  	    	error_result="<?php echo ERR_EXPIRE_DATE_LESSTHAN;?>\n";	  	    														
			if(error_result!=""){
				alert(error_result);
				return false;
			}else if(span_edit.style.display==''){
				span_details.innerHTML=span_delete.innerHTML="";
		  		var ids="";
		  		if(action_type=='edit') ids="&fID="+id;
				command="<?php echo tep_href_link(FILENAME_FEATURED,'action=update');?>"+ids;
				if(loadings) loadings.style.display="";
				if(span_edit) span_edit.style.display="none";
			}
	}else if(document.getElementById("span_delete") && span_delete.style.display==''){
		if(span_delete.style.display==""){
			span_details.innerHTML=span_edit.innerHTML="";
			command="<?php echo tep_href_link(FILENAME_FEATURED,'action=delete_confirm');?>&fID="+id;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
		}
	}else if(prd_new.style.display!='none'){
		if(server_date) var server_date_obj=date_format(server_date,'y-m-d','y-m-d',true).getTime();
	  	    if(frm.expire_date && frm.expire_date.value) var expire_date_obj=date_format(frm.expire_date.value,'','y-m-d',true).getTime();	  	    	  	    	  	    	  	    	  	   
	  	    if(frm.expire_date && frm.expire_date.value=="")
				error_result="<?php echo ERR_EXPIRY_DATE;?>\n";	  	    	
	  	    else if(server_date_obj>=expire_date_obj)
	  	    	error_result="<?php echo ERR_EXPIRE_DATE_LESSTHAN;?>\n";	  	    														
			if(error_result!=""){
				alert(error_result);
				return false;
			}else {
				command="<?php echo tep_href_link(FILENAME_FEATURED,'action=update');?>";
				change_new_image();
		}
	}
	if(command!="") do_post_command('frm_feature',command);		
	return false;
}
function expand_new(perform){
	if(document.getElementById("featured_id")) f_id=document.getElementById("featured_id").value;
	if(f_id && document.getElementById("head_"+f_id)){
		document.getElementById("head_"+f_id).style.display="none";
		document.getElementById("data_"+f_id).style.display="";		
	}
	switch(perform){	
	case 'add_new':
 	if(document.getElementById('no_record'))
		document.getElementById('no_record').style.display='none';
		display_flag=0;
		if(document.getElementById("span_edit")) document.getElementById("span_edit").innerHTML="";
		document.getElementById("prd_new").style.display='';
		document.getElementById('prd_new').innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
		command="<?php echo tep_href_link(FILENAME_FEATURED,'action=edit');?>";
		do_get_command(command);
	break;
	case 'close':
 		if(document.getElementById('no_record'))
			document.getElementById('no_record').style.display='';
		change_new_image();	
		document.getElementById("prd_new").style.display='none';
	break;
	}
}
function change_new_image(){
	document.getElementById('header_new_operation').firstChild.src=document.getElementById('header_new_operation').firstChild.src.replace('_hover.gif','.gif');
	display_flag=1;
}
var previous_id='';
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=""; 	 	
 	 	if(category==3 && document.getElementById("prd_new").style.display=="") {
 	 		document.getElementById("prd_new").innerHTML="";
 	 		document.getElementById("prd_new").style.display="none";	
 	 	}
 	 	var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
 	 	 if(category!=1 && document.frm_feature && document.frm_feature.featured_id && document.frm_feature.featured_id.value>0)  {
			var old_ids=document.frm_feature.featured_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(document.frm_feature.featured_id && id>0 && document.frm_feature.featured_id.value>0 && document.frm_feature.featured_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_feature.featured_id.value=id;			   
			}
		if(id>0 && category!=1 && document.frm_feature && document.frm_feature.featured_id) document.frm_feature.featured_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_FEATURED,'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_feature.action_type) document.frm_feature.action_type.value='new';
 	 					command="<?php echo tep_href_link(FILENAME_FEATURED,'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_edit_hover.gif')	
 	 			   	  			tr_obj.childNodes[1].childNodes[0].src=img_src+'template/img_edit.gif';
 	 			   	  		if(tr_obj.childNodes[2].childNodes[0].src==img_src+'template/img_trash_hover.gif')	
 	 			   	  			tr_obj.childNodes[2].childNodes[0].src=img_src+'template/img_trash.gif';	 	 			   	  			
 	 			   	  	}	 			   	  	  	 			   	  	 	 			   	  	
 	 			   	  }	 	 			    			   	   	 			   
 	 			 }else { 	
				 	if(previous_id!='')
						if(document.getElementById('head_'+previous_id))
							document.getElementById('head_'+previous_id).innerHTML=''; 			 	 	 			 	
 	 			 	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_FEATURED,'action=get_details');?>&fID="+id; 	 			 	 	 			 	
					previous_id=id;
 	 			 }
				change_new_image();
 	 			break; 	 			 	 			
 	 			case 4:
 	 					span_edit.style.display="";
 	 					span_delete.style.display=span_details.style.display="none";
 	 					span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					if(document.frm_feature.action_type) document.frm_feature.action_type.value='edit';
 	 					command="<?php echo tep_href_link(FILENAME_FEATURED,'action=edit');?>&fID="+id;
 	 			break; 	 	 		
 	 			case 5:
 	 					span_delete.style.display="";
 	 					span_edit.style.display=span_details.style.display="none";
 	 					span_delete.innerHTML='<table border="0" cellspacing="2" cellpadding="1" width="100%"><tr><td width="17" align="center"><?php echo tep_image('images/template/img_trash.gif')?></td>'+
											  '<td width="500" align="left" class="inner_title"><?php echo TEXT_INFO_HEADING_DELETE_FEATURED;?></td></tr>'+
											  '<tr><td></td><td width="500" align="left" class="main"><?php echo TEXT_INFO_DELETE_INTRO;?></td></tr>'+
											  '<tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif',50,10);?></td></tr></table>';
 	 					if(img_save) img_save.style.display="";
 	 			break;
 	 			case 6:
 	 				if(img_src && id && document.frm_feature.featured_id){
 	 					var featured_id=document.frm_feature.featured_id.value;
 	 					var data_id=document.getElementById("data_"+featured_id);
 	 					if(data_id) var img=data_id.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
 	 					if(img_src+"template/icon_active.gif"==id.src){
 	 						img.src=id.src=img_src+"template/icon_inactive.gif"; 	 						 	 						
 	 						command="<?php echo tep_href_link(FILENAME_FEATURED,'action=setflag');?>&fID="+featured_id+"&flag=0";
 	 					}else if(img_src+"template/icon_inactive.gif"==id.src){
 	 						img.src=id.src=img_src+"template/icon_active.gif";
 	 						command="<?php echo tep_href_link(FILENAME_FEATURED,'action=setflag');?>&fID="+featured_id+"&flag=1";
 	 					}
 	 				}
 	 			break;
				case 7:
				 if(head && data_id){
		 	 			  	head.style.display="none";
		 	 			  	head.innerHTML="";
		 	 			  	data_id.style.display="";	
		 	 			  } 
		 	 			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,5)=='close') print_details('close',result.substr(5));	
   	    else if(result.substr(0,14)=='delete_success') print_details('delete_success',result.substr(14)); 		 				 						
   	    else if(result.substr(0,6)=='delete') print_details('delete',result.substr(6));
		else if(result.substr(0,15)=='page_navigation') print_details('page_navigation',result.substr(15));
		else if(result.substr(0,12)=='new_featured') print_details('new_featured',result.substr(23));	
		else if(result.substr(0,3)=='new') print_details('new',result.substr(3));							 	 			 	 			 	 				 	 											   	
   	  }
   }
      
   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  featured_id="";
			var  product_name="";
			var  featured_date_added="";						
			var  featured_last_modified="";
			var  products_image_1="";
			var  products_title_1="";
			var  expires_date="";
			var  date_status_change="";
			var  products_status="";
 	 		featured_id=splt_str[0];
			product_name=splt_str[1];
			featured_date_added=splt_str[2];						
			featured_last_modified=splt_str[3];
			products_image_1=splt_str[4];
			products_title_1=splt_str[5];
			expires_date=splt_str[6];
			date_status_change=splt_str[7];
			products_status=splt_str[8];
 	 	}	  	 		 	 	 	 	  	 		 	  	 
 		if(document.frm_feature && document.frm_feature.featured_id) var id=document.frm_feature.featured_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="100%">'+
						          '<tbody><tr>'+						         	 
					  			 	'<td class="dataTableContent" align="left"><img src="images/template/'+((products_status==0)?'icon_inactive.gif':'icon_active.gif')+'" alt="Active" title=" Active " border="0" height="10" width="10">&nbsp;&nbsp;&nbsp;'+product_name+'</td>'+
						         '</tr>'+
						      	'</tbody></table>';
	 	 		}		 	 		
	 	 		include="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+
				  "<td width='450' nowrap='nowrap' class='main' valign='middle' onclick='javascript:expand_category("+featured_id+",7);'>&nbsp;<img onclick='javascript:expand_category(this,6);' src='images/template/"+((products_status==0)?'icon_inactive.gif':'icon_active.gif')+"' border='0' height='10' width='10'>"+				  							  				  
				  "&nbsp;&nbsp;"+product_name+"</td>"+
				  "<td width='25' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='width:80;height:30px;display:inline;position:relative;'>"+
				  	    "<tr class='img_move' id='img_ids'>"+
				  	  		"<td class='cell_bg_popm_left' width='5'>&nbsp;</td>"+				  	  	
				  	    	//"<td width='10%' onclick='javascript:change_class(this,1);expand_category("+featured_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='5' onclick='javascript:change_class(this,1);expand_category("+featured_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='5' onclick='javascript:change_class(this,1);expand_category("+featured_id+",5);' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='delet' title='delete' src='images/template/img_trash.gif'></td>"+				  	    				  	    
				  	    	"<td class='cell_bg_popm_right' width='5'>&nbsp;</td>"+
						"</tr>"+
					 "</table>"+
				  "</td><td  width='350' style='cursor:pointer;cursor:hand;' onclick='javascript:expand_category("+featured_id+",7);'>&nbsp;</td>"+
				 "<td width='80' align='right'>&nbsp;<span 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("+featured_id+",3);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</span></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='5' class='main'><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='10' align='left'>&nbsp;&nbsp;<img src='../images/small/"+products_image_1+"' alt='"+products_title_1+"' width='100' height='100' title='"+products_title_1+"'></td>"+				  							  			
							"<td width='600' valign='top'>"+				  							  			
				  				"<table width='50%' border='0' cellspacing='0' cellpadding='3' class='main'>";
				  					if(featured_date_added!=""){
				  						include+="<tr>"+
					  						"<td align='left' width='20%' valign='top'><b><?php echo TEXT_INFO_DATE_ADDED;?></b></td>"+
					  						"<td align='left' width='30%' valign='top'>"+featured_date_added+"</td>"+
				  						"</tr>";
				  					}	
				  					if(featured_last_modified!=""){		  					
					  					include+="<tr>"+
					  						"<td align='left' width='20%'><b><?php echo TEXT_INFO_LAST_MODIFIED;?></b></td>"+
					  						"<td align='left' width='30%'>"+featured_last_modified+"</td>"+
					  					"</tr>";						
				  					}							  					
				  					if(expires_date!=""){		  					
					  					include+="<tr>"+
					  						"<td align='left' width='20%'><b><?php echo TEXT_INFO_EXPIRES_DATE;?></b></td>"+
					  						"<td align='left' width='30%'>"+expires_date+"</td>"+
					  					"</tr>";						
				  					}
				  					if(date_status_change>0){		  					
					  					include+="<tr>"+
					  						"<td align='left' width='20%'><b><?php echo TEXT_INFO_STATUS_CHANGE;?></b></td>"+
					  						"<td align='left' width='30%'>"+date_status_change+"</td>"+
										"</tr><tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></td></tr>";
				  					}				  									  			  						  							
					include+="<tr><td>&nbsp;</td></tr></span>"+
				  "</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';
 	 		}									         														
 	 	break; 	 		
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
 	 	break;
 	 	case 'delete':
 	 		if(span_delete) span_delete.style.display="";			
 	 		if(span_delete && span_details){ 	 			 	 			
 	 			span_delete.innerHTML=result; 	 			
 	 			span_details.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_FEATURED_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 	var obj=document.getElementById("page_1");
 	    	 	var len=1;
 	    	 	if(obj) len=parseInt(obj.options[obj.selectedIndex].value); 	    	 							 	    	 	 	
 	    	 	command="<?php echo tep_href_link(FILENAME_FEATURED,'action=page_navigation');?>&page="+len;    	 	 	    	 	
 	    	 }			 
 	    	 if(command!="") do_get_command(command);
 	 	break;
		case 'new':
				document.getElementById('prd_new').innerHTML=result;
				document.getElementById('prd_new').style.display='';
		break;
 	 	case 'new_featured':
				//var obj=document.getElementById("page_1");
				var len=1;
				document.getElementById('prd_new').style.display='none';
				/*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 product_name=result_splt[1];							
						var products_status=result_splt[8];
						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_'+id+'">'+
						       '<table border="0" cellpadding="3" cellspacing="0" width="100%">'+
						          '<tbody><tr>'+						         	 
					  			 	'<td class="dataTableContent" align="left"><img src="images/template/'+((products_status==0)?'icon_inactive.gif':'icon_active.gif')+'" alt="Active" title=" Active " border="0" height="10" width="10">&nbsp;&nbsp;&nbsp;'+product_name+'</td>'+
						         '</tr>'+
						      	'</tbody></table>'+
						      '</div>'+
						      '<div style="display: none;" class="openContent" id="head_'+id+'"></div>';
						    var rows_cnt=tbl_obj.rows.length-2;
    						var tbl=tbl_obj.rows[rows_cnt];
    						tbl.onclick=function () {expand_category(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_FEATURED_INSERT_SUCCESS;?>";
				 	    	 	res_display.style.display=""; 	    	 	
 	    	 				} 
						}     					
					}											
				}else if(obj && obj.options.length>0 || tbl_obj_rows==max_display){
				 	if(obj) len=1;				 						 	 				 	
				 	if(!obj && tbl_obj_rows==max_display) len=1; 				 					 
				}*/	
				command="<?php echo tep_href_link(FILENAME_FEATURED,'action=page_navigation');?>&page="+len;
				if(command!="") 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';		    		    		     		   	
		  }
		 }		 
	  }	
	  var display_flag=1;
	   function do_hover_change(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>
<?php
	if ( ($HTTP_GET_VARS['action'] == 'new') || ($HTTP_GET_VARS['action'] == 'edit') ) {
?>
<link rel="stylesheet" type="text/css" href="includes/javascript/calendar.css">
<script language="JavaScript" src="includes/javascript/calendarcode.js"></script>
<?php
	}
?>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<div id="popupcalendar" class="text"></div>
<!-- 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="2">            
          	<tr><td id="res_display" class="main" style="display:none"></td></tr>
          	<tr>
            	<td valign="top">
            	<?php echo tep_draw_form('frm_feature',FILENAME_FEATURED,'','post','onsubmit="javascript:return ValidateForm();"'); ?>
	            	<table border="0" width="100%" cellspacing="0" cellpadding="2">
	              		<tr class="dataTableHeadingRow" style="height:26px">	              		
							<td valign="middle"><?php echo '<a id="header_new_operation" href="javascript: expand_new(\'add_new\');" onMouseOut="javascript:do_hover_change(this,1);" onMouseOver="javascript:do_hover_change(this,2);">'.tep_image(DIR_WS_IMAGES.'template/img_new.gif','New','22','22').'</a>'; ?></td>
						</tr>
						<tr><td colspan="3"><?php  echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>
						<tr class="dataTableHeadingRow">
	                		<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
	              		</tr>
	              		<tr>
	              			<td id="ajax_details"> <?php  table_write(); ?></td>    		
	          	 		</tr>	              
						<tr>
							<td id="prd_new" class="openContent" style="display:none" ></td>
						</tr>
	            	</table>
	            	<input type="hidden" name="featured_id" id="featured_id">            	
	            	<input type="hidden" name="action_type" id="action_type">
          		</form>
           </td>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_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'); ?> 
