<?php
/*

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

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );

  require('includes/application_top.php');
  require('includes/classes/split_page_results_event.php');
  tep_get_last_access_file();           
  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  $command=isset($HTTP_GET_VARS["command"])?$HTTP_GET_VARS["command"]:'';
  $customer_group_id=isset($HTTP_GET_VARS["cID"])?(int)$HTTP_GET_VARS["cID"]:'';
  $page = (isset($HTTP_GET_VARS['page']) ? (int)$HTTP_GET_VARS['page'] :1);
  
   if($action!=""){
   	  if($action=='get_details'){
   	  	  echo_get_details();
	  }else if($action=='page_navigation'){ 
	     echo $action;
		 table_write(); 
	  }else if($action=='edit_groups'){ 
		    $cnt=0;
		    $customers_info=array('customers_groups_id'=>0,
								 'customers_groups_name'=>'',
								 'customers_groups_discount'=>''
					 			);					 			  
		     if($customer_group_id){
			    $customers_info_query=tep_db_query("SELECT * from " . TABLE_CUSTOMERS_GROUPS . " where customers_groups_id='" . (int)$HTTP_GET_VARS['cID'] . "'");
			 	$customers_info=tep_db_fetch_array($customers_info_query);				
				$cnt=tep_db_num_rows($customers_info_query);
			}
		    $lInfo=new objectInfo($customers_info);		    
		    if($customer_group_id) echo 'edit';
		    else echo 'new';		    
			tep_create_location();		        				   					    
		  }else if($action=='delete_groups'){
			$location_string = 'delete';
		 	$location_string .="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
		 	$location_string .='<td width="500" align="left" class="inner_title">'. TEXT_INFO_HEADING_DELETE_GROUP . '</td></tr>';
		 	$location_string .='<tr><td></td><td width="500" align="left" class="main">'.TEXT_DELETE_INTRO. '<br></td></tr>';
			$location_string .='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',60,20).'</td></tr></table>';
		 	echo $location_string;
        }else if($action=='update_groups'){
			$customers_groups_name=(isset($HTTP_POST_VARS['customers_groups_name'])?$HTTP_POST_VARS['customers_groups_name']:'');
			$customers_groups_discount=(isset($HTTP_POST_VARS['customers_groups_discount'])?$HTTP_POST_VARS['customers_groups_discount']:'');
			$customers_groups_discount_sign=(isset($HTTP_POST_VARS['customers_groups_discount_sign'])?$HTTP_POST_VARS['customers_groups_discount_sign']:'');
			
			$field_customers_groups_discount=$customers_groups_discount_sign.$customers_groups_discount;
			
			$sql_data = array(  'customers_groups_name' => $customers_groups_name,
								'customers_groups_discount' =>$field_customers_groups_discount
							 );
			//print_r($sql_data);
		if ($customer_group_id>0 && $HTTP_POST_VARS['action_type']=='edit')  
			tep_db_perform(TABLE_CUSTOMERS_GROUPS, $sql_data, 'update', "customers_groups_id = '" . (int)$customer_group_id . "'");				
		else  if($HTTP_POST_VARS['action_type']=='new'){
			tep_db_perform(TABLE_CUSTOMERS_GROUPS, $sql_data);
			$customer_group_id = tep_db_insert_id();
			echo 'new_location';				
		}				  		
		echo_get_details();  	  	  		    
   	 }else if($action=='delete_confirm'){   	    
		$delete_query=tep_db_query("delete from " . TABLE_CUSTOMERS_GROUPS . " where customers_groups_id='" . (int)$customer_group_id . "'");
	    echo 'delete_success';	     
   	 }
   	 exit;
   }        

   function echo_get_details(){
  	 global $customer_group_id;	
  		
   	    $customers_groups_query_raw = tep_db_query("select customers_groups_id, customers_groups_name, customers_groups_discount from " . TABLE_CUSTOMERS_GROUPS . "  where customers_groups_id='".(int)$customer_group_id."' order by customers_groups_name");
		if(tep_db_num_rows($customers_groups_query_raw)>0){
			$customers_groups=tep_db_fetch_array($customers_groups_query_raw);
			while(list($key,$vals)=each($customers_groups)){						
				$str_vals.=$vals."||";	
			}
		}else $str_vals="No Record Found";	
		echo 'get_details'.$str_vals;
  }
  
  
  function table_write(){
    global $page,$HTTP_GET_VARS;	
   ?>
  	<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<?php
		$search = '';
    	if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search']))  $search = " where (customers_groups_name like '%" . tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']))."%')"; 
	 
        $customers_groups_query_raw = "select customers_groups_id, customers_groups_name, customers_groups_discount from " . TABLE_CUSTOMERS_GROUPS . $search . ' order by customers_groups_id desc';
	 	
		$resource_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $customers_groups_query_raw, $resource_query_numrows);
		$customers_groups_query = tep_db_query($customers_groups_query_raw);		   
		if(tep_db_num_rows($customers_groups_query)>0){ 
		  while ($customers = tep_db_fetch_array($customers_groups_query)) {					 
				 $class="dataTableRowEven";
  				 if($rows%2==0) $class="dataTableRowOdd"; 					
  				 $rows++;
  				 echo '  <tr style="height:25" class="'.$class.'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$customers['customers_groups_id'].'\').style.display==\'none\') expand_category(' . $customers['customers_groups_id'] . ',3);">' . "\n"; 
			   ?>  			      
		   	  <td colspan="4" width="100%">
		   	  	<div id="data_<?php echo $customers['customers_groups_id'];?>">
		   	  	 <table border="0" cellspacing="0" cellpadding="0" width="100%">
		   	  		<tr>
		   	  			<td class='dataTableContent' width="50%" align="left"><?php echo $customers['customers_groups_name']; ?>
		      			<td class='dataTableContent' width="15%" align="right"><?php echo $customers['customers_groups_discount']; ?>%</td>				      			
		      			<td class='dataTableContent' width="35%" align="left"></td>				      			
					</tr>
		   	  	</table>
		   	   </div>
		   	   <div class="openContent" id="head_<?php echo $customers['customers_groups_id'];?>" style="display:none"></div>
		   	  </td>					      
      		</tr>
      	<?php } ?>
		<?php  } else if($HTTP_GET_VARS['search']==""){ ?>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr>
				<td class="main" id="empty_group" align="center"><?php echo TEXT_EMPTY_GROUPS;?></td>
			</tr>
		</table>
<?php }	if($HTTP_GET_VARS['search']!=""){ ?>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<?php if(tep_db_num_rows($customers_groups_query)<=0){  ?>
			<tr>
				<td class="main" align="center"><?php echo N0_SEARCH_RESULT;?></td>
			</tr>
			<?php } ?>
			<tr>
				<td class="main" align="center"><?php echo tep_draw_separator('pixel_trans.gif');?></td>
			</tr>
			<tr>
				<td align="right"><a href="javascript:expand_category(1,'1','reset')"><?php echo tep_image_button('button_reset.gif', IMAGE_RESET);?></a></td>
			</tr>
		</table>		      	
<?php }?>
		</table>
<?php 	if(tep_db_num_rows($customers_groups_query)>0){ ?>	
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr height="10"></tr>
			<tr>				  
		         <td class="smallText" valign="top"><?php echo $resource_split->display_count($resource_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page,TEXT_DISPLAY_NUMBER_OF_CUSTOMERS_GROUPS); ?></td>
		    	 <td class="smallText" align="right"><?php echo $resource_split->display_script_links($resource_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','\'\''); ?></td>
		    </tr>
		</table>
<?php  } 
  }
function tep_create_location(){ 
	global 	$HTTP_GET_VARS;	
    $customers_info=array();
    $customers_info_query=tep_db_query("SELECT * from " . TABLE_CUSTOMERS_GROUPS . " where customers_groups_id='" . (int)$HTTP_GET_VARS['cID'] . "'");
	if(tep_db_num_rows($customers_info_query)>0) $customers_info=tep_db_fetch_array($customers_info_query);
	$lInfo=new objectInfo($customers_info);
?>

	<table border="0" cellspacing="2" cellpadding="4" width="100%">
			   <?php if(!$HTTP_GET_VARS['cID']) { ?>
			   	<tr class="openContent_top">
					<td class="inner_title" width="50%"><?php echo HEADING_NEW_CUSTOMERS_GROUP;?></td>
					<td  width='50%' align='right' id='img_save'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category(0,1);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;
					</td>
				</tr><?php } ?>			   
			    <tr>
				 <td colspan="2" width="100%" align="center">
				  <table border="0" cellspacing="2" cellpadding="4" width="100%">							     
					<tr valign="top">
						<td class="main" align="right" width="20%"><?php echo ENTRY_GROUPS_NAME;?></td>
						<td class="main" align="center" width="25%"><?php echo tep_draw_input_field('customers_groups_name',$lInfo->customers_groups_name,'size=30 maxlength=50');?></td>
				<!--	</tr>
					<tr valign="top">  !-->
						<td align="right" width="20%" class="main"><?php echo ENTRY_DEFAULT_DISCOUNT; ?></td>
						<td align="left" width="35%">&nbsp;
						<select  name="customers_groups_discount_sign"> 
			      		  <option name="minus" value="-" <?php if (strstr($lInfo->customers_groups_discount,"-")) echo "selected=\"selected\"" ?>>-</option>
						  <option name="plus" value="+"  <?php if (substr($lInfo->customers_groups_discount,0,1)!='-') echo "selected=\"selected\"" ?>>+</option>
			   			</select>&nbsp;<?php echo tep_draw_input_field('customers_groups_discount', ((substr($lInfo->customers_groups_discount,0,1)=='-') ? substr($lInfo->customers_groups_discount,1,strlen($lInfo->customers_groups_discount)) : substr($lInfo->customers_groups_discount,0,strlen($lInfo->customers_groups_discount))) , 'size=27 maxlength="20"', false); ?>&nbsp;
						</td>
					<!-- </tr> !-->
				 </table>
			    </td>
		      </tr>			
	  <tr><td colspan='8'><img src='images/pixel_trans.gif' border='0' alt='' width='100%' height='20'></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/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script>
   var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
    function validateForm(lfrm){
      var error_result="";
      if(document.getElementById("action_type")) var action_type=document.getElementById("action_type").value;
	  if(document.getElementById("customer_group_id")) id=document.getElementById("customer_group_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="";	  		 
	  var obj="";
	  var obj1="";
	  
	  if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){		  		  
	  obj=document.getElementById("customers_groups_name").value;
	  obj1=document.getElementById("customers_groups_discount").value;
	  
			  if (obj=="" || str_trim(obj)=='') 
				   error_result+="<?php echo tep_output_string(ERROR_CUSTOMERS_GROUPS_NAME); ?>\n";		      
			  if (obj1=="" || str_trim(obj1)=='') 
				   error_result+="<?php echo tep_output_string(ERROR_CUSTOMERS_DISCOUNT); ?>\n";		       		  
			  if (isNaN(document.getElementById("customers_groups_discount").value)) 
				   error_result+="<?php echo tep_output_string(ERROR_NUMERIC_VALUE); ?>\n";		       		  
	  if (error_result!=""){
	     alert(error_result);
	 	 return false;
      }else if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){      							
			if(action_type=='edit')  ids="&cID="+id;
			command="<?php echo tep_href_link(FILENAME_CUSTOMERS_GROUPS,'action=update_groups');?>"+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="none";
			document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
			display_flag=1;
			}
      }
	}else if(span_delete.style.display==""){      							
			ids="&cID="+id;
			command="<?php echo tep_href_link(FILENAME_CUSTOMERS_GROUPS,'action=delete_confirm');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
     }
	do_post_command('customer_groups',command);	
    return false;
   }
  
   function check_key(e){
     var kc=0;
   	  if (window.event)
	    kc=window.event.keyCode;
	  else if (e)
	 	kc=e.which;
	  else
		kc=0;
	  if(kc==13) expand_category(1,'1','search');
   }
var previous_id='';  
   function expand_category(id,category,r_type,sta_type){ 	 
		if(category==2 && id==0){
			display_flag=0;
			if(document.getElementById('empty_group'))
				document.getElementById('empty_group').style.display='none';
		}
		if(category==1 && id==0){
			if(document.getElementById('empty_group'))
				document.getElementById('empty_group').style.display='';
		display_flag=1;
		document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
		}
			
		var sta_type;
		var span_details=document.getElementById("span_details");
 	 	var span_edit=document.getElementById("span_edit");			
		var span_delete=document.getElementById("span_delete");
		if(!sta_type) sta_type="";
		var frm=document.customer_groups;
		if(category=='1' && document.getElementById("page_''") && sta_type!=""){
			id=parseInt(document.getElementById("page_''").options[document.getElementById("page_''").selectedIndex].value);
 	 		if(sta_type=='next' && document.getElementById("page_''")) {
 	 			if(document.getElementById("page_''").length==document.getElementById("page_''").selectedIndex+1) return;
 	 			id+=1;
 	 		}else if(sta_type=='prev') {
 	 			if(document.getElementById("page_''").selectedIndex==0) return;
 	 			id-=1;
 	 		}
 	 		if(id<=1) id=1;
 	 	}else if(category==1 && sta_type=="") id="";
 	 	
 	 	if(category=='1' && document.getElementById("new_create").style.display=="")	 	 		
 	 		document.getElementById("new_create").style.display="none";	 
 	 	if(category==2 && id==0 && frm && frm.customer_group_id.value>0 && document.getElementById("head_"+frm.customer_group_id.value) && document.getElementById("data_"+frm.customer_group_id.value)){
			if(span_edit) span_edit.innerHTML="";
			document.getElementById("head_"+frm.customer_group_id.value).style.display="none";
			document.getElementById("data_"+frm.customer_group_id.value).style.display="";
 	 	}
		
		var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
 	 	 if(frm && frm.customer_group_id && frm.customer_group_id.value>0)  {
			var old_ids=frm.customer_group_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(id>0 && frm.customer_group_id.value>0 && frm.customer_group_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="";
			   frm.customer_group_id.value=id;			   
			}							
		if(id>0 && category!=1 && frm && frm.customer_group_id) frm.customer_group_id.value=id;		 								 	 	 	 
		if(category){
			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_type=="" && r_type=='search') {
					   	ser="&search="+document.getElementById("search").value;
						id="";
					    }else if(document.getElementById("search") && document.getElementById("search").value!="" && sta_type=="" && r_type=='reset'){
					  	 document.getElementById("search").value="";
						}else if(document.getElementById("search") && document.getElementById("search").value=="" && sta_type=="" && r_type=='search'){
						 display_flag=1;
						 document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
						 return;
						}else if(document.getElementById("search") && document.getElementById("search").value=="" && sta_type=="" && r_type=='reset') id=1;
 	 			        if(id!="") page="&page="+id;
					    command="<?php echo tep_href_link(FILENAME_CUSTOMERS_GROUPS,'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:
					 if(span_edit) span_edit.style.display="none";
					 if(span_details) span_details.style.display="none";
 	 				 if(frm.action_type) frm.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_CUSTOMERS_GROUPS,'action=edit_groups');?>"; 	 				   	 				  	 				  	 				  	 				  	 		
 	 			break; 	 			
 	 			case 3:
 	 			   if(document.getElementById("new_create")){ document.getElementById("new_create").style.display="none"; 	 			   
				   display_flag=1;
					document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
				   }
 	 			   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.visibility="hidden"; 
 	 			   	  	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_CUSTOMERS_GROUPS,'action=get_details');?>&cID="+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...'>";
 	 					document.getElementById("new_create").innerHTML="";
						if(frm.action_type) frm.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_CUSTOMERS_GROUPS,'action=edit_groups');?>&cID="+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_CUSTOMERS_GROUPS,'action=delete_groups');?>&cID="+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){
   	  var frm=document.customer_groups;
   	  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,12)=='new_location') print_details('new_location',result.substr(23));
		else if(result.substr(0,3)=='new' && document.getElementById("new_create"))
			document.getElementById("new_create").innerHTML=result.substr(3);
		else if(result.substr(0,6)=='delete') print_details('delete',result.substr(6));		
   	  }
   }
   function print_details(category,result){ 

 	 	var no_result="";
 	 	var frm=document.customer_groups;
		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  customer_group_id="";
			var  customers_groups_name="";
			var  customers_groups_discount="";						

 	 		customer_group_id=splt_str[0]; 	 		
 	 		customers_groups_name=splt_str[1];
 	 		customers_groups_discount=splt_str[2]; 	 		 	 		 	 								
 	 	}	 		  	 		 	 	 	  	 		 	  	 
 		if(frm && frm.customer_group_id) var id=frm.customer_group_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 equip=document.getElementById("equip");
 		var img_save=document.getElementById("img_save");

		if(img_save && category!='get_details') img_save.style.visibility="visible";		
 	 	switch(category){ 	 		 	 		 	 		 	 		
 	 		case 'get_details':
			head.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>'+
						         	'<td class="dataTableContent" width="50%" align="left">'+customers_groups_name+'</td>'+
					  			 	'<td class="dataTableContent" width="15%" align="right">'+customers_groups_discount+'%</td>'+  
					  			 	'<td class="dataTableContent" width="35%" align="left"></td>'+  
								 '</tr>'+
						      '</tbody></table>';	
	 	 		}		 	 			
	 	 		include ="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr height='40' class='openContent_top'>"+				  				  							  
				  "<td align='left' valign='middle' width='350' class='inner_title' onclick='javascript:expand_category("+customer_group_id+",6);'>"+customers_groups_name+"</td>"+
				  "<td width='60' 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='5'>&nbsp;</td>"+
				  	    "<td width='10%' onclick='javascript:change_class(this,1);expand_category("+customer_group_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("+customer_group_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='5'>&nbsp;</td>"+
				  	  "</tr>"+
				  	"</table>"+
				  "</td>"+"<td style='cursor:pointer;cursor:hand;' onclick='javascript:expand_category("+customer_group_id+",6);'>&nbsp;</td>"+
				 "<td width='65' align='right'><span id='img_save' style='visibility:hidden;'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category("+customer_group_id+",3);'><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='3'><img src='images/24-1.gif' alt='Loading...' title='Loading...'></td></tr>"+				
				"<tr>"+
				  "<td colspan='3' id='span_id' class='main'><span style='display:none' id='span_edit' name='span_edit'></span><span style='display:none' id='span_delete'></span><span id='span_details' name='span_details'>"+	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
				  			"<td width='15%'>&nbsp;</td>"+				  							  			
							"<td width='85%'>"+				  							  			
				  				"<table width='70%' border='0' cellspacing='0' cellpadding='2' class='main'>";				  														
									if(customers_groups_name!=""){
									include+="<tr>"+
											"<td align='left' width='20%'><b><?php echo ENTRY_GROUPS_NAME;?></b></td>"+
											"<td align='left' width='25%'>"+customers_groups_name+"</td>"+
							/*		}
									if(customers_groups_discount!=""){
										include+="<tr>"+  */
											"<td align='left' width='25%'><b><?php echo TEXT_CUSTOMERS_DISCOUNT;?></b></td>"+
											"<td align='left' width='35%'>"+customers_groups_discount+"%</td>"+
										"</tr><tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></td></tr>";
									}
				  			  include+="</table></td></tr></table>"+
					"</span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
 	 		} 	 			 	 		
 	 	break;
 	 	case 'edit':
			if(document.getElementById('img_save')) document.getElementById('img_save').style.visibility='visible';
			if(span_edit) span_edit.style.display="";	
 	 		if(span_edit && span_details){
				span_edit.innerHTML=result; 
 	 			span_details.style.display='none';
 	 		}									  
 	 	toggle_panel('Equipment:_','false','','0');	     					 		  												
 	 	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_GROUP_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
				var obj=document.getElementById("page_''");
 	    	 	if(obj) 
				    len=obj.options[obj.selectedIndex].value;
 	    	 		command="<?php echo tep_href_link(FILENAME_CUSTOMERS_GROUPS,'action=page_navigation');?>&page="+len;
					do_get_command(command); 
			 } 
			if(document.getElementById("search")) document.getElementById("search").value=""; 								   			   
 	 	break;	
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		   document.getElementById("ajax_details").innerHTML=result;
 	 	break;	 	 	
		case 'new_location':
				var len=1;
				 command="<?php echo tep_href_link(FILENAME_CUSTOMERS_GROUPS,'action=page_navigation');?>&page="+len;
				 do_get_command(command);
				 if(document.getElementById("search")) document.getElementById("search").value=""; 								   			   
		break;
 	 	}
 	 	if(res_display && 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_get_src.src.replace('_hover.gif','.gif');
					 	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" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="5">
  <tr> 
<!-- body_text //-->   
             <td valign="top">
              <table border="0" cellspacing="2" cellpadding="0" width=100%>
              <tr class="dataTableHeadingRow">
                 	<td colspan="3">
                 		<table border="0" cellspacing="0" cellpadding="0" width=100%>	
                 			<tr>
                 				<td valign="bottom" class="pageHeading" align="left"><a alt="New Location" title="New Location" onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,1);" id="img_new" href="javascript:expand_category(0,2);"><?php echo tep_image('images/template/img_new.gif','New Group','22','22',' align="absmiddle"');?></a></td>
			                 	<td class="dataTableHeadingContent" align="right" valign="absmiddle"><?php echo '<b>' . HEADING_TITLE_SEARCH . '</b> ' . tep_draw_input_field('search','','onkeyup="javascript:check_key(event)"') . '&nbsp;';?></td>
								<td align="left" valign="absmiddle" width="25"><a alt="Search" title="Search" href="javascript:expand_category(1,'1','search');"><?php echo tep_image('images/template/img_search.gif');?></a></td>	
                 			</tr>
                 		</table>
                 	</td>                 	
               </tr>
               <tr>
                <td>
           <?php echo tep_draw_form('customer_groups',FILENAME_CUSTOMERS_GROUPS, '' ,'post','onsubmit="javascript:return validateForm(this);"');?>
	       		<table border="0" cellspacing="0" cellpadding="0" width=100%>                 
                 <tr><td id="res_display" class="main" style="display:none"></td></tr>
                 <tr class="dataTableHeadingRow" height=20 valign="top">
				     <td class="main" width="50%" align="left"><b><?php echo TABLE_HEADING_NAME; ?></b></td>
				     <td class="main" width="15%" align="right"><b><?php echo TABLE_HEADING_DISCOUNT; ?></b></td>
				     <td class="main" width="35%" align="left"></td>
			     </tr>
                 <tr>
                  	<td colspan="3" id="ajax_details">
						<?php table_write(); ?>
					</td>
		 		 </tr>	
		 		 <tr>
		 		 	<td colspan="3">
		 		 		<table border="0" cellspacing="0" cellpadding="0" width="100%">
		 		 				<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>
							    <tr><td colspan="3" style="display:none" class="openContent" id="new_create"><?php tep_create_location();?></td></tr>
		 		 		</table>
		 		 	</td>
		 		 </tr>	 		                			 		 		 
        </table>
        </td></tr></table>
        <input type="hidden" name="customer_group_id" id="customer_group_id">
	    <input type="hidden" name="action_type" id="action_type">
	    <input type="hidden" name="icnt" id="icnt">
        </form>
        </td>      
<!-- body_text_eof //-->
<!-- body_eof //-->
	</tr>			
  </table>
<!-- footer //-->
			

<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<script language="javascript">
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>                                                                                                                                                         