<?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');
  tep_get_last_access_file();     
  require('includes/classes/split_page_results_event.php');                                                                      
  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');  
  $manufacturers_id= (isset($HTTP_GET_VARS['mID']) ? $HTTP_GET_VARS['mID'] : $HTTP_POST_VARS['manufacture_id']);
  $page = (isset($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] : 1);
  $manufacturer_products=array('products_count'>0);
  $server_date = getServerDate(true);
  if($action!=""){
  	if($HTTP_GET_VARS['mID']){
  		$manufacturers_query_raw = tep_db_query("select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, m.date_added, m.last_modified from " . TABLE_MANUFACTURERS . " m,".TABLE_MANUFACTURERS_INFO." mi where  m.manufacturers_id=mi.manufacturers_id and mi.languages_id='".(int)$languages_id."' and m.manufacturers_id='".(int)$manufacturers_id."' order by m.manufacturers_name asc");
  		if(tep_db_num_rows($manufacturers_query_raw)>0){
  			$manufacturers=tep_db_fetch_array($manufacturers_query_raw);
  			$manufacturer_products_query = tep_db_query("select count(*) as products_count from " . TABLE_PRODUCTS . " where manufacturers_id = '" . (int)$manufacturers['manufacturers_id'] . "'");
      		if(tep_db_num_rows($manufacturer_products_query)>0)
      		   		$manufacturer_products = tep_db_fetch_array($manufacturer_products_query);      	
      		$mInfo_array = array_merge($manufacturers, $manufacturer_products);
      		$mInfo = new objectInfo($mInfo_array);
  		}  					  		
  	}
  	if($action=='get_details'){
  		echo_get_details();
  	}else if($action=='page_navigation'){
  		echo 'page_navigation';
		table_write();
  	}else if($action=='file_upload'){              
       	if ($manufacturers_image = new upload('manufacturers_image', DIR_FS_CATALOG_IMAGES)){        	        	
        	$sql_array=array();
        	$sql_array=array('manufacturers_image'=>$manufacturers_image->filename);
        	if($HTTP_POST_VARS['action_type']=='new'){	        	
	        	$sql_array=array('manufacturers_image'=>$manufacturers_image->filename,'date_added'=>$server_date);	        	
	        	tep_db_perform(TABLE_MANUFACTURERS,$sql_array);
	        	$id=tep_db_insert_id();
	        	$languages = tep_get_languages();
	        	for ($i=0, $n=sizeof($languages); $i<$n; $i++) {	          
		          $language_id = $languages[$i]['id'];	          
		          $insert_sql_data = array('manufacturers_id' => $id,
		                                   'languages_id' => $language_id);            
		          tep_db_perform(TABLE_MANUFACTURERS_INFO, $insert_sql_data);                                          
	        	}        	                     
	          echo $id;
        	}else if($HTTP_POST_VARS['action_type']=='edit')
				tep_db_perform(TABLE_MANUFACTURERS, $sql_array, 'update', "manufacturers_id = '" . (int)$manufacturers_id . "'");	        		        	                 
       	}
  	}else if($action=='edit'){  		  		  		  		
  		if(!$HTTP_GET_VARS['mID']) echo "new"; 
  		else if($HTTP_GET_VARS['mID']) echo 'edit';
  		tep_create_manufact();
  	}else if($action=='update'){
        $manufacturers_name = tep_db_prepare_input($HTTP_POST_VARS['manufacturers_name']);
        $sql_data_array = array('manufacturers_name' => $manufacturers_name);
        if(!$HTTP_GET_VARS['mID']){
          $insert_sql_data = array('date_added' => $server_date);
          $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
          tep_db_perform(TABLE_MANUFACTURERS, $sql_data_array);
          $manufacturers_id = tep_db_insert_id();
          $action='insert';        	
        }else  if ($HTTP_GET_VARS['mID']) {
          $update_sql_data = array('last_modified' => $server_date);
          $sql_data_array = array_merge($sql_data_array, $update_sql_data);
          tep_db_perform(TABLE_MANUFACTURERS, $sql_data_array, 'update', "manufacturers_id = '" . (int)$manufacturers_id . "'");
          $action='save';          
        }        
        $languages = tep_get_languages();
        for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
          $manufacturers_url_array = $HTTP_POST_VARS['manufacturers_url'];
          $language_id = $languages[$i]['id'];
          $sql_data_array = array('manufacturers_url' => tep_db_prepare_input($manufacturers_url_array[$language_id]));
          if ($action == 'insert') {
            $insert_sql_data = array('manufacturers_id' => $manufacturers_id,
                                     'languages_id' => $language_id);
            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
            tep_db_perform(TABLE_MANUFACTURERS_INFO, $sql_data_array);
          } elseif ($action == 'save')         
            tep_db_perform(TABLE_MANUFACTURERS_INFO, $sql_data_array, 'update', "manufacturers_id = '" . (int)$manufacturers_id . "' and languages_id = '" . (int)$language_id . "'");                                                      
        }  
        if($HTTP_POST_VARS['action_type']=='new')          	
          		echo 'new_manufacture'.$manufacturers_id.'||'.$manufacturers_name;
        else if($HTTP_POST_VARS['action_type']=='edit') 
           		echo_get_details();		
  	}else if($action=='delete'){
  	  $manu='delete';  	  
  	  $manu.="<table border='0' cellspacing='2' cellpadding='1' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
	  $manu.='<td width="500" align="left" class="inner_title">'.TEXT_HEADING_DELETE_MANUFACTURER . '</td></tr>';
	  $manu.='<tr><td></td><td width="500" align="left" class="main">'.TEXT_DELETE_INTRO. '</td></tr>';
	  $manu.='<tr><td></td><td  width="500" align="left" class="main"><b>'.$mInfo->manufacturers_name. '</b></td></tr>';
	  $manu.='<tr><td></td><td  width="500" align="left" class="main"><b>'.tep_draw_checkbox_field('delete_image', '1', true) . ' ' . TEXT_DELETE_IMAGE. '</b></td></tr>';  	        
      if ($mInfo->products_count > 0) {
        $manu.='<tr><td></td><td  width="500" align="left" class="main"><b>'.tep_draw_checkbox_field('delete_products') . ' ' . TEXT_DELETE_PRODUCTS. '</b></td></tr>';
        $manu.='<tr><td></td><td  width="500" align="left" class="main"><b>'.sprintf(TEXT_DELETE_WARNING_PRODUCTS, $mInfo->products_count). '</b></td></tr>';         
      }   
      $manu.='<tr><td colspan="2">'.tep_draw_separator("pixel_trans.gif",5,10).'</td></tr></table>';
      echo $manu; 
  	}else if($action=='delete_confirm'){
  		if ($HTTP_POST_VARS['delete_image']==1) {
          $manufacturer_query = tep_db_query("select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$manufacturers_id . "'");
          $manufacturer = tep_db_fetch_array($manufacturer_query);
          $image_location = DIR_FS_DOCUMENT_ROOT . DIR_WS_CATALOG_IMAGES . $manufacturer['manufacturers_image'];
          if (file_exists($image_location)) @unlink($image_location);
        }
        tep_db_query("delete from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$manufacturers_id . "'");
        tep_db_query("delete from " . TABLE_MANUFACTURERS_INFO . " where manufacturers_id = '" . (int)$manufacturers_id . "'");
        if ($HTTP_POST_VARS['delete_products']>0) {
          $products_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " where manufacturers_id = '" . (int)$manufacturers_id . "'");
          while ($products = tep_db_fetch_array($products_query)) {
            tep_remove_product($products['products_id']);
          }
        }else 
          tep_db_query("update " . TABLE_PRODUCTS . " set manufacturers_id = '0' where manufacturers_id = '" . (int)$manufacturers_id . "'");
          echo 'delete_success';          		
  	}
  	exit;
  }  
  function echo_get_details(){
  	global $mID,$languages_id;
	//echo "select m.manufacturers_id, m.manufacturers_name,m.manufacturers_image,m.date_added,m.last_modified from " . TABLE_MANUFACTURERS . " m,".TABLE_MANUFACTURERS_INFO." mi where m.manufacturers_id=mi.manufacturers_id and m.manufacturers_id='".(int)$mID."' and mi.languages_id='".(int)$languages_id."' order by m.manufacturers_name asc";
  	$manufacturers_query_raw = tep_db_query("select m.manufacturers_id, m.manufacturers_name,m.manufacturers_image,m.date_added,m.last_modified,mi.manufacturers_url from " . TABLE_MANUFACTURERS . " m,".TABLE_MANUFACTURERS_INFO." mi where m.manufacturers_id=mi.manufacturers_id and m.manufacturers_id='".(int)$mID."' and mi.languages_id='".(int)$languages_id."' order by m.manufacturers_name asc");
  	if(tep_db_num_rows($manufacturers_query_raw)>0){
  		$manufacturers=tep_db_fetch_array($manufacturers_query_raw);
  		while(list($key,$vals)=each($manufacturers)){						
			 	if($key=='date_added' || $key=='last_modified')
			 		$vals=format_date($vals);					
			 										 		
				$str_vals.=$vals."||";	
			}
		}else $str_vals="No Record Found";	
		echo 'get_details'.$str_vals;  	
  }
  function tep_create_manufact(){
   global $HTTP_GET_VARS,$languages_id,$languages_id,$manufacturers_id; 
   $mInfo=array();
   if($HTTP_GET_VARS['mID']){
  		$manufacturers_query_raw = tep_db_query("select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, m.date_added, m.last_modified from " . TABLE_MANUFACTURERS . " m,".TABLE_MANUFACTURERS_INFO." mi where  m.manufacturers_id=mi.manufacturers_id and mi.languages_id='".(int)$languages_id."' and m.manufacturers_id='".(int)$manufacturers_id."' order by m.manufacturers_name asc");
  		if(tep_db_num_rows($manufacturers_query_raw)>0){
  			$manufacturers=tep_db_fetch_array($manufacturers_query_raw);
  			$manufacturer_products_query = tep_db_query("select count(*) as products_count from " . TABLE_PRODUCTS . " where manufacturers_id = '" . (int)$manufacturers['manufacturers_id'] . "'");
      		if(tep_db_num_rows($manufacturer_products_query)>0)
      		   		$manufacturer_products = tep_db_fetch_array($manufacturer_products_query);      	
      		$mInfo_array = array_merge($manufacturers, $manufacturer_products);
      		$mInfo = new objectInfo($mInfo_array);
  		}  					  		
  	}	
   ?>
  	<table border="0" cellspacing="0" cellpadding="3" width="100%">
  			<?php if(!$HTTP_GET_VARS['mID']){ ?>
  			<tr class="openContent_top">
	      	 <td colspan="2">
	      	 	 <table cellpadding="0" cellspacing="0" border="0" width="100%">	  	
		   	 		<tr align="right" style="cursor:pointer;cursor:hand;">
		   	 			<td  width="500" onclick='javascript:expand_category(0,1);'><td>
		   	 			<td width="80" align='right'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category(<?php echo (($HTTP_GET_VARS['itID'])?$HTTP_GET_VARS['itID'].',3':'0,1');?>);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>
		   			</tr>
		         </table>
		     </td>
  	  		</tr>
  	  	<?php } ?>
  			<tr>
  			  <td  colspan="2" class='inner_title'><?php echo ((!$HTTP_GET_VARS['mID'])?TEXT_HEADING_NEW_MANUFACTURER:TEXT_HEADING_EDIT_MANUFACTURER);?></td>
  			</tr>
  			<tr>
  			  <td colspan="2" class='main'><?php echo TEXT_EDIT_INTRO;?></td>
  			</tr>
  			<tr>
  			  <td class='main' width='25%'><?php echo TEXT_MANUFACTURERS_NAME;?></td>
  			  <td class='main' align='left' width='75%'><?php echo tep_draw_input_field('manufacturers_name', $mInfo->manufacturers_name);?></td>
  			</tr>
  			<tr>
  			  <td class='main' width='25%'><?php echo TEXT_MANUFACTURERS_IMAGE;?></td>
  			  <td class='main' width='75%'><?php echo tep_draw_file_field('manufacturers_image') .tep_draw_hidden_field('manufacturers_image'). '<br>' . $mInfo->manufacturers_image;?></td>
  			</tr>
  	  <?php 	  		                                       
      $languages = tep_get_languages();
      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {        
        $edit.= '<tr><td class="main" width="25%">'.TEXT_MANUFACTURERS_URL.'</td><td class="main" width="75%">' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('manufacturers_url[' . $languages[$i]['id'] . ']', tep_get_manufacturer_url($mInfo->manufacturers_id, $languages[$i]['id'])).'</td></tr>';        
      }	         
      echo $edit;?>      
  	  <tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>
	  </table> 
<?php }
  function table_write(){
  global $page,$languages_id;?>
  <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 
		  $manufacturers_query_raw = "select m.manufacturers_id, m.manufacturers_name,mi.manufacturers_url from " . TABLE_MANUFACTURERS . " m,".TABLE_MANUFACTURERS_INFO." mi where m.manufacturers_id=mi.manufacturers_id and mi.languages_id='".(int)$languages_id."' order by m.manufacturers_id desc";		  
		  $manufacturers_split = new splitPageResultsEvent($page, MAX_DISPLAY_MANUFACTURERS_IN_A_LIST, $manufacturers_query_raw, $manufacturers_query_numrows);
		  $manufacturers_query = tep_db_query($manufacturers_query_raw);
		  $i=0;
		 
		  while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
		      $class="dataTableRowEven";
			  if($i%2==0) $class="dataTableRowOdd";
			  $i++;      
		      echo '<tr class="'.$class.'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$manufacturers['manufacturers_id'].'\').style.display==\'none\') expand_category(' . $manufacturers['manufacturers_id'] . ',3);">' . "\n";    
		  ?>
  			<td>
			   <div id="data_<?php echo $manufacturers['manufacturers_id'];?>">
			     <table border="0" cellspacing="0" cellpadding="3" width="80%">
			    <tr>
                	<td class="dataTableContent"><?php echo $manufacturers['manufacturers_name']; ?></td>
                	</tr>
              	</table>
                </div>
                <div style="display:none" class="openContent" id="head_<?php echo $manufacturers['manufacturers_id'];?>"></div>
             </td>
            </tr>                               	
<?php }
 if(!tep_db_num_rows($manufacturers_query)){ ?>
	<tr><td class="main" id="no_record"  align="center"><?php echo TEXT_NO_RECORDS_FOUND; ?></td></tr>
<?php } ?>	
  <tr id="new_manufact" style="display:none" class="openContent">
			<td colspan="5" class="openContent_top">	
				<table cellpadding="1" cellspacing="0" border="0" width="100%">
					<tr>
						<td class="inner_title"><?php echo 'New Products Manufacturers';?></td>
						<td width='240' align='right' ><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:drop_new_manufact();'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>
					</tr>
					<tr><td colspan='5' ><div id="span_new" style="display:none"></div></td></tr>
				</table>
			</td>
		</tr>
              <tr>
                <td colspan="2" align="right"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php  echo $manufacturers_split->display_count($manufacturers_query_numrows, MAX_DISPLAY_MANUFACTURERS_IN_A_LIST, $page, TEXT_DISPLAY_NUMBER_OF_MANUFACTURERS); ?></td>
                    <td class="smallText" align="right"><?php echo $manufacturers_split->display_script_links($manufacturers_query_numrows, MAX_DISPLAY_MANUFACTURERS_IN_A_LIST, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','1'); ?></td>                     
                  </tr>
                </table></td>
              </tr>
             </table> 
  			</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/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript" src="includes/aim.js"></script>
<script language="javascript" type="text/javascript">
	var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
	var max_display="<?php echo MAX_DISPLAY_MANUFACTURERS_IN_A_LIST;?>";		
	var lang=Array();
	<?php	 
	 $languages = tep_get_languages();
	 for($i=0;$i<sizeof($languages);$i++){?>
	  		lang[<?php echo $i;?>]="<?php echo $languages[$i]['id'];?>";	
<?php } ?>  	
    function startCallback_manufacture() {	  	  	  	 	  
	  var span_edit=document.getElementById("span_edit");
	  if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){
	  	if(document.getElementById("manufacturers_image") && document.getElementById("manufacturers_image").value!="")
	  		return validate_image();
	  	else if(document.getElementById("manufacturers_image") && document.getElementById("manufacturers_image").value==""){
	  		 ValidateForm();
	  		 return false;
	  	}
	  }	else if(span_delete && span_delete.style.display==""){
	  	ValidateForm();
	  	return false;
	  }  							 
  	}    
  	function completeCallback_manufacture(response) {  	  		  		  		
  		ValidateForm(response);
  	}
	function ValidateForm(m_id){
		var frm = document.frm_manufact;
		var error = "";		
		if(frm.action_type) var action_type=frm.action_type.value;
		//alert (action_type);
		if(frm && frm.manufacture_id) id=frm.manufacture_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");
		var ids="";				
		if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){
			if(frm.manufacturers_name && ((frm.manufacturers_name.value=="") || (str_trim(frm.manufacturers_name.value)=="") ))
				error+="<?php echo ERR_MANUFACTURE_NAME;?>";
			else if(frm.elements["manufacturers_url[]"] && error==""){
				var obj=frm.elements["manufacturers_url[]"];
				for(i=0;i<lang.length;i++){
					if(obj[i].value=="") error="<?php echo ERR_MANUFACTURER_URL_SHOULD_NOT_EMPTY;?>";
				}							
			}										
			if(error!=""){
				alert(error);
				return false;
			}else if (span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display=="") {										
				if(frm.action_type && frm.action_type.value=='edit')  ids="&mID="+id;
				if(m_id>0) ids="&mID="+m_id;													
				command="<?php echo tep_href_link(FILENAME_MANUFACTURERS,'action=update');?>"+ids;
				if(loadings) loadings.style.display=""; 					
				if(span_edit) span_edit.style.display="none";
				if(document.getElementById("new_create") && document.getElementById("new_create").style.display=="") {
					if(span_edit) span_edit.innerHTML="";
					document.getElementById("new_create").style.display="none";	
					new_image_change();
				}					
			}								 
		}else if(span_delete && span_delete.style.display==""){								
				span_details.innerHTML=span_edit.innerHTML="";
				command="<?php echo tep_href_link(FILENAME_MANUFACTURERS,'action=delete_confirm');?>&mID="+id;						
				if(loadings) loadings.style.display=""; 					
				if(span_delete) span_delete.style.display="none";			
	 	} 
	 	do_post_command('frm_manufact',command);
	 	return false;		
	}
	function validate_image(){
		var image_types=Array(".png",".jpg",".jpeg",".gif");
		var frm = document.frm_manufact;
		var error = "";		
		if (document.getElementById("manufacturers_image") && document.getElementById("manufacturers_image").value!="" && !check_mime_type(document.getElementById("manufacturers_image"),image_types))
			error="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
		if(error!=""){
			alert(error);
			return false;
		}
		return true;
	}	
	function new_image_change(){
		document.getElementById('img_new').firstChild.src=img_src+"template/img_new.gif";
		//document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
		display_flag=1;
	}
var previous_id='';
function expand_category(id,category,r_type,sta){
	if(id==0 && category==2){
	display_flag=0;
	document.getElementById('img_new').firstChild.src=img_src+"template/img_new_hover.gif";
	//document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('.gif','_hover.gif');
 	if(document.getElementById('no_record'))
		document.getElementById('no_record').style.display='none';
		
		
	}if(id==0 && category==1)
 	if(document.getElementById('no_record'))
		document.getElementById('no_record').style.display='';
		new_image_change();
		var span_edit=document.getElementById("span_edit");
		if(category==3 && document.getElementById('head_'+id) && document.getElementById('head_'+id).style.display!='none' && document.getElementById("span_edit") && document.getElementById("span_edit").style.display=='none' && document.getElementById("span_delete") && document.getElementById("span_delete").style.display=='none') return;
		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==1 && document.getElementById("new_create").style.display==""){  	 		
 	 		document.getElementById("new_create").style.display="none";
 	 		document.getElementById("new_create").innerHTML="";
 	 	}
 	 	if(category==2 && id==0 && document.frm_manufact.manufacture_id && document.frm_manufact.manufacture_id.value>0 && document.getElementById("head_"+document.frm_manufact.manufacture_id.value) && document.getElementById("data_"+document.frm_manufact.manufacture_id.value)){
			if(span_edit) span_edit.innerHTML="";
			document.getElementById("head_"+document.frm_manufact.manufacture_id.value).style.display="none";
			document.getElementById("data_"+document.frm_manufact.manufacture_id.value).style.display="";
			if(document.getElementById("new_create")) document.getElementById("new_create").style.display="";						
 	 	}
 	 	var res_display=document.getElementById("res_display");
 	 	if(res_display) res_display.style.display="none";
 	 	 if(category!=1 && document.frm_manufact && document.frm_manufact.manufacture_id && document.frm_manufact.manufacture_id.value>0)  {
			var old_ids=document.frm_manufact.manufacture_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_manufact.manufacture_id.value>0 && document.frm_manufact.manufacture_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_manufact.manufacture_id.value=id;			   
		}	
		if(id>0 && category!=1 && document.frm_manufact && document.frm_manufact.manufacture_id) document.frm_manufact.manufacture_id.value=id; 														 								 	 	 	
 	 	if(category){
 	 		var span_details=document.getElementById("span_details"); 	 					
			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 ser="";
 	 			       var page="";
 	 			       if(document.getElementById("search") && document.getElementById("search").value!="" && sta=="" && !r_type) {
					   	ser="&search="+document.getElementById("search").value;
						id="";
					   }else if(document.getElementById("search") && document.getElementById("search").value=="" && sta=="" && !r_type) return;
					    else if(document.getElementById("search") && document.getElementById("search").value=="" && sta=="" && r_type=='reset') id=1;
 	 			       if(id!="") page="&page="+id;
 	 			       command="<?php echo tep_href_link(FILENAME_MANUFACTURERS,'action=page_navigation');?>"+page+ser;
 	 			   	   if(document.getElementById("ajax_details")) document.getElementById("ajax_details").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 			break;
 	 			case 2:
					document.getElementById('img_new').firstChild.src=img_src+"template/img_new_hover.gif";
					//document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('.gif','_hover.gif');
 	 				 if(span_edit) span_edit.innerHTML="";
 	 				 if(document.frm_manufact.action_type) document.frm_manufact.action_type.value='new';
 	 				 document.getElementById("new_create").style.display="";
					 document.getElementById("new_create").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 				 command="<?php echo tep_href_link(FILENAME_MANUFACTURERS,'action=edit');?>";
 	 			break;
 	 			case 3:
 	 			   if(document.getElementById("new_create")){ 	 			   
 	 			   		document.getElementById("new_create").style.display="none"; 	 			   
 	 			   		document.getElementById("new_create").innerHTML="";
				   		new_image_change();
				   }
 	 			   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.diaplay="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_MANUFACTURERS,'action=get_details');?>&mID="+id; 	 			 	 	 			 	
					previous_id=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_manufact.action_type) document.frm_manufact.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_MANUFACTURERS,'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_MANUFACTURERS,'action=delete');?>&mID="+id; 	 	 	 					 	 					 	 			
 	 			break; 	 
				case 6:
		 	 			  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,15)=='new_manufacture') print_details('new_manufacture',result.substr(15));
		else if(result.substr(0,3)=='new') {
			display_flag=0;
			document.getElementById("new_create").style.display="";
			document.getElementById("new_create").innerHTML=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  manufacture_id="";
			var  manufacture_name="";
			var  manufacture_image="";	
			var man_url="";		
			var  manufacture_date_added="";
			var  manufacture_last_modified="";			
 	 		manufacture_id=splt_str[0];
 	 		manufacture_name=splt_str[1];
 	 		manufacture_image=splt_str[2];
			manufacture_date_added=splt_str[3];
 	 		manufacture_last_modified=splt_str[4];
			man_url=splt_str[5];
 	 	}	  	 		 	 	 	 	  	 		 	  	 
 		if(document.frm_manufact && document.frm_manufact.manufacture_id) var id=document.frm_manufact.manufacture_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(document.getElementById('content')) document.getElementById('content').innerHTML=' '; 		 	 		 	 	 		 	 		
 	 		if(head  && no_result!="")
				head.innerHTML=no_result; 	 			 	 		
 	 		else if(head && no_result==""){
	 	 		if(data_id){ 
	 	 			data_id.innerHTML='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						          '<tbody><tr style="height:20">'+						         	
						         	'<td align="left" class="dataTableContent" width="200">'+manufacture_name+'</td>'+			         						  			 	 
						         '</tr>'+
						      	'</tbody></table>';
	 	 		}	
	 	 		include="<tr>"+
				"<div id='content'><table width='100%' border='0' cellspacing='0' cellpadding='0' class='openContent_top'>"+
				"<tr height='40' valign='top'  >"+
				"<td align='left' valign='middle' width='400' class='main' onclick='javascript:expand_category("+manufacture_id+",6);'>&nbsp;&nbsp;&nbsp;"+manufacture_name+"</td>"+
				  "<td width='100' align='left' class='main' valign='top'> "+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='height:30px;display:inline;position:relative;'>"+
				  	  "<tr class='img_move' id='img_ids'>"+
				  	  	"<td class='cell_bg_popm_left' width='10' >&nbsp;</td>"+				  	  	
				  	    "<td width='10' onclick='javascript:change_class(this,1);expand_category("+manufacture_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("+manufacture_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='400' style='cursor:pointer;cursor:hand;' onclick='javascript:expand_category("+manufacture_id+",6);'>&nbsp;</td>"+
				 "<td width='90' nowrap='nowrap' 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("+manufacture_id+",6);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a></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='8' 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'></td><td width='10' align='center'><img width='100' height='80' src='../images/"+manufacture_image+"'></td>"+				  							  							  			
							"<td width='600'>"+				  							  			
				  				"<table width='50%' border='0' cellspacing='0' cellpadding='3' class='main'>";
								if(man_url!=""){
				  						include+="<tr>"+
					  						"<td align='left' width='17%' valign='top'><?php echo TEXT_URL;?></td>"+
					  						"<td align='left' width='30%' valign='top'>"+man_url+"</td>"+
				  						"</tr>";
				  					}	
				  					if(manufacture_date_added!=""){
				  						include+="<tr>"+
					  						"<td align='left' width='17%' valign='top'><?php echo TEXT_DATE_ADDED;?></td>"+
					  						"<td align='left' width='30%' valign='top'>"+manufacture_date_added+"</td>"+
				  						"</tr>";
				  					}	
				  					if(manufacture_last_modified!=""){		  					
					  					include+="<tr>"+
					  						"<td align='left' width='17%'><?php echo TEXT_LAST_MODIFIED;?></td>"+
					  						"<td align='left' width='30%'>"+manufacture_last_modified+"</td>"+
					  					"</tr>";						
				  					}							  									  			  			  						
					include+="</table><tr><td colspan='8'><img src='images/pixel_trans.gif' border='0' alt='' width='100%' height='20'></td></tr></span>"+
				  "</td>"+
				"</tr>"+
			"</table></div>";
			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 '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':			 
 	    	 var len=1;
 	    	 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_MANUFACTURE_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 	var obj=document.getElementById("page_1");
 	    	 	if(obj) len=obj.options[obj.selectedIndex].value; 	    	 		 	    	 	 	    	 	
 	    	 	command="<?php echo tep_href_link(FILENAME_MANUFACTURERS,'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_manufacture':														
				command="<?php echo tep_href_link(FILENAME_MANUFACTURERS,'action=page_navigation');?>&page=1";
				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_new.gif'){				   		
			   		if(eve==1 || eve==2) img_get_src.src=img_src+'template/img_new_hover.gif';					
			   }else if(eve==3 && img_get_src.src==img_src+'template/img_new_hover.gif') 
			    	img_get_src.src=img_src+'template/img_new.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;
	}
	
	 function open_close(id){
	 var head=document.getElementById("head_"+id);	
	 var data_id=document.getElementById("data_"+id);
	 if(head && head.style.display=="" && data_id ) {
				 head.style.display="none";
					 data_id.style.display="";
					// document.getElementById('content').innerHTML=' ';
					head.innerHTML='';
					 }
	// data_id.style.display="";
	// head.style.display="none" ;

	 }

</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- 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><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr  style="height:23px" class="dataTableHeadingRow">           
            <td class="pageHeading" align="left" valign="bottom"><a alt="New" title="New" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);"  id="img_new" href="javascript:expand_category(0,2);"><?php echo tep_image('images/template/img_new.gif');?></a></td>            		
          </tr>
          <tr><td><?php  echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>	
          <tr>
            <td valign="top" colspan="3">
            	<?php echo tep_draw_form('frm_manufact',FILENAME_MANUFACTURERS, 'action=file_upload', 'post', ' onSubmit="javascript:return AIM.submit(document.frm_manufact, {\'onStart\' : startCallback_manufacture, \'onComplete\' : completeCallback_manufacture});" enctype="multipart/form-data" '); ?> 	
            	<table border="0" width="100%" cellspacing="0" cellpadding="2">
	              <tr><td id="res_display" class="main" style="display:none"></td></tr>		
	              <tr class="dataTableHeadingRow">
	                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_MANUFACTURERS; ?></td>    
	              </tr>
	              <tr>
	               <td>
	                <?php table_write();?>
	               </td>
	              </tr>
	              <tr><td colspan="3" style="display:none" class="openContent" id="new_create"></td></tr>
                </table>
               	<input type="hidden" name="action_type" id="action_type">
               	<input type="hidden" name="manufacture_id" id="manufacture_id">
              </form>
              </td>
          </tr>
        </table></td>
      </tr>
    </table>
   </td>
   </tr>
   </table>
<!-- 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'); ?>
