<?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'] : '');
  $type=($HTTP_GET_VARS['type'])?$HTTP_GET_VARS['type'] : '';
  $options_id=(isset($HTTP_GET_VARS['oID'])?(int)$HTTP_GET_VARS['oID']:'');
  $page = (isset($HTTP_GET_VARS['page']) ? (int)$HTTP_GET_VARS['page'] :1);
	if($action!=""){
   	  if($action=='get_details'){
   	  	  echo_get_details();
     }else if($action=='edit_options'){
		    $options_info=array('options_id'=>0,
		                        'options_name'=>'',
								'options_type'=>$type
					 			);					 			  
		     if($options_id){
		        $options_info_query=tep_db_query("SELECT * from " . TABLE_CUSTOMER_OPTIONS . " where options_id='" . (int)$options_id . "' and options_type='" . $type . "'");
			 	$options_info=tep_db_fetch_array($options_info_query);	
				$cnt=tep_db_num_rows($options_info_query);
			}
		    $oInfo=new objectInfo($options_info);		
		    echo 'edit';
		?>
	  <table border="0" cellspacing="2" cellpadding="4" width="100%">
	   <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>
			<tr valign="top">
			<td class="main" width="35%" align="right"><?php echo (($type=='I')?TABLE_HEADING_CUSTOMER_OPTIONS:TABLE_HEADING_CUSTOMER_OCCUPATIONS);?></td>
			<td class="main" width="65%" align="left"><?php echo tep_draw_input_field('options_name',$oInfo->options_name,'size=50 maxlength=70');?></td>
			</tr>
	   <tr height="30"><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>
	  </table>
	 <?php 
   }else if($action=='update_options'){
			$options_name=(isset($HTTP_POST_VARS['options_name'])?$HTTP_POST_VARS['options_name']:'');
			$sql_data = array('options_name' => $options_name,
				   			  'options_type' => $type
							 );
		if ($options_id>0 && $HTTP_POST_VARS['action_type']=='edit')  { 
			tep_db_perform(TABLE_CUSTOMER_OPTIONS, $sql_data, 'update', "options_id = '" . (int)$options_id . "'");
		}					
		else  if($HTTP_POST_VARS['action_type']=='new'){
			tep_db_perform(TABLE_CUSTOMER_OPTIONS, $sql_data);
			$options_id = tep_db_insert_id();
			echo 'new_location';				
		}				  		
		echo_get_details();
	}else if($action=='page_navigation'){ 
	   echo $action;
	   table_write();
	}else if($action=='delete_options'){
			$options_string = 'delete';
		 	$options_string .="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='5%' align='right'>".tep_image('images/template/img_trash.gif').'</td>';
		 	$options_string .='<td width="350" align="left" class="inner_title">'. (($type=='I')?TEXT_HEADING_DELETE_CUSTOMER_INTEREST:TEXT_HEADING_DELETE_CUSTOMER_OCCUPATION) . '</td></tr>';
		 	$options_string .='<tr><td></td><td width="350" align="left" class="main">'. (($type=='I')?TEXT_DELETE_INTRO_INTEREST:TEXT_DELETE_INTRO_OCCUPATION) . '<br></td></tr>';									   
			$options_string .='<tr><td><img src="images/pixel_trans.gif" border="0" alt="" width="5" height="15"></td></tr></table>';
		 	echo $options_string;
	}else if($action=='delete_confirm'){   	    
        tep_db_query("delete from " . TABLE_CUSTOMER_OPTIONS . " where options_id = '" . (int)$options_id . "'");
		echo "delete_success";
	}		  			    	  	  	  		    
 	exit;
 }	
?>
<?php
  function table_write(){
  global $page, $type,$HTTP_GET_VARS;
  ?>	       	   		
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
	 <?php
  	   $sources_query_raw = "select options_id, options_name from " . TABLE_CUSTOMER_OPTIONS . " where options_type='" . $HTTP_GET_VARS['type'] . "'  order by options_id desc";
	   //echo $sources_query_raw;
	   $sources_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $sources_query_raw, $sources_query_numrows);
  	   $sources_query = tep_db_query($sources_query_raw);
	   if(tep_db_num_rows($sources_query)>0){ 
		while ($sources = tep_db_fetch_array($sources_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_'.$sources['options_id'].'\').style.display==\'none\') expand_category(' . $sources['options_id'] . ',3);">' . "\n"; 
		   ?>  			      
			  <td colspan="4" width="100%">
				<div id="data_<?php echo $sources['options_id'];?>">
				 <table border="0" cellspacing="0" cellpadding="0" width="100%">
					<tr>
						<td class='dataTableContent' width="150" align="left"><?php echo $sources['options_name']; ?></td>
					</tr>
				 </table>
			    </div>
				<div class="openContent" id="head_<?php echo $sources['options_id'];?>" style="display:none"></div>
			 </td>					      
			</tr>
      	<?php }
			 }else echo '<tr><td class="smallText" class="main" id="no_options" align="center">'.TEXT_EMPTY_OPTIONS.'</td></tr>'; ?>
			 
			 <tr id="new_class" style="display:none">
			<td colspan="5">	
				<table cellpadding="1" cellspacing="0" class="openContent" border="0" width="100%">
					<tr class="openContent_top">
						<td class="inner_title"><?php echo (($type=='I')?'New Customer Intrest':'New Customer Occupation');//echo 'New Tax Class';?></td>
						<td width='40%' align='right' class="openContent_top" ><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:drop_new_class();'><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>
			 
		</table>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr>			  
		         <td class="smallText" valign="top"><?php echo $sources_split->display_count($sources_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page,(($type=='I')?TEXT_DISPLAY_NUMBER_OF_CUSTOMERS_OPTIONS_INTEREST:TEXT_DISPLAY_NUMBER_OF_CUSTOMERS_OPTIONS_OCCUPATION)); ?></td>
		    	 <td class="smallText" align="right"><?php echo $sources_split->display_script_links($sources_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','\'\''); ?></td>
		    </tr>
	   </table>
<?php  }  
  function echo_get_details(){
  	global $options_id, $type; 
	  $fetch_query=tep_db_query("select options_id, options_name from " . TABLE_CUSTOMER_OPTIONS . " where options_id='" . (int)$options_id . "' and options_type='" . $type . "' order by options_id desc");
	  if (tep_db_num_rows($fetch_query)>0){
		  $fetch_result=tep_db_fetch_array($fetch_query);
		  $name=$fetch_result["options_name"];
		  $options_id = $fetch_result["options_id"]; 
		  $str_vals.= $name . "||" . $options_id;	
     }else $str_vals = 'No Record Found';
   echo 'get_details'.$str_vals; 	
  }
?>
<!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 language="javascript" src="includes/menu.js"></script>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";	
var max_display="<?php echo MAX_DISPLAY_SPECIAL_PRODUCTS;?>";
var server_date="<?php echo getServerDate();?>";
  function validateForm(ofrm){
      var error_result="";
	  if(ofrm && ofrm.options_id) id=ofrm.options_id.value;
	  var span_details=document.getElementById("span_details");
	  var span_edit=document.getElementById("span_edit");				
	  var span_delete=document.getElementById("span_delete");
	  var loadings=document.getElementById("loading");
	  if(ofrm.action_type) var action_type=ofrm.action_type.value;
	  var ids="";	
	  var tt="<?php echo (($type=='I')?'Customer Intrest':'Customer Occupation');?>";
	  if(span_edit)
	  details=span_edit;	
	  else details=span_new;  	  	
	 // if(span_details && span_details.style.display!="" && details.style.display==""){	    	
	  //  span_details.innerHTML=span_delete.innerHTML="";
	  if(details.style.display==""){   
	  obj=ofrm.options_name.value; 
	 	 if (obj=="" || str_trim(obj)=='') 
				error_result+=tt +( " should not be empty ");	
		 //if (tt=="Customer Intrest" && isNaN(obj)){
		 	//	error_result+=tt +( " should be a Numeric Value ");				      
	 	 if (error_result!=""){
    	    alert(error_result);
	 		 return false;
	     }else{      							
			if(ofrm.action_type && ofrm.action_type.value=='edit')  ids="&oID="+id;
			command="<?php echo tep_href_link(FILENAME_CUSTOMER_OPTIONS,'action=update_options&type='.$type);?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_edit) span_edit.style.display="none";
		    if(document.getElementById("new_class")){document.getElementById("new_class").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="&oID="+id;
			command="<?php echo tep_href_link(FILENAME_CUSTOMER_OPTIONS,'action=delete_confirm&type='.$type);?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
     }
	do_post_command('customer_options',command);
    return false;
   } 
var previous_id='';
   function expand_category(id,category,r_type,sta){ 
   	if(id==0 && category==2){
	//	if(document.getElementById('no_options'))
		//		document.getElementById('no_options').style.display='none';
		display_flag=0;
	}
	if(id==0 && category==1){
	//	if(document.getElementById('no_options'))
	//			document.getElementById('no_options').style.display='';
		document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
		display_flag=1;
	}	
		drop_new_class();
		//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;
		var sta;
		if(!sta) sta="";
		var frm=document.customer_options;
		if(category=='1' && document.getElementById("page_''") && sta!=""){
 	 		id=parseInt(document.getElementById("page_''").options[document.getElementById("page_''").selectedIndex].value);
 	 		if(sta=='next' && document.getElementById("page_''")) {
 	 			if(document.getElementById("page_''").length==document.getElementById("page_''").selectedIndex+1) return;
 	 			id+=1;
 	 		}else if(sta=='prev') {
 	 			if(document.getElementById("page_''").selectedIndex==0) return;
 	 			id-=1;
 	 		}
 	 		if(id<=1) id=1;
 	 	}else if(category=='1' && sta=="") id="";
 	 	var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
 	 	 if(frm && frm.options_id && frm.options_id.value>0)  {
			var old_ids=frm.options_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 && frm.options_id.value>0 && frm.options_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.options_id.value=id;			   
			}							
		if(category!=1 && frm && frm.options_id && frm.options_id.value=="") frm.options_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_CUSTOMER_OPTIONS,'action=page_navigation&type='.$type);?>"+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(frm.action_type) frm.action_type.value='new'; 	 					
 	 				 command="<?php echo tep_href_link(FILENAME_CUSTOMER_OPTIONS,'action=edit_options&type='.$type);?>"; 	 				  	 					 	 					 	 					 	 				 	 		
 	 			break; 	 			
 	 			case 3:
				  if(document.getElementById("new_class")){ document.getElementById("new_class").style.display="none"; 	 			   
				  document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
					display_flag=1;
					}
 	 			   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_CUSTOMER_OPTIONS,'action=get_details&type='.$type);?>&oID="+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(frm.action_type) frm.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_CUSTOMER_OPTIONS,'action=edit_options&type='.$type);?>&oID="+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_CUSTOMER_OPTIONS,'action=delete_options&type='.$type);?>&oID="+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_options;
   	  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,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,6)=='delete') print_details('delete',result.substr(6));		
   	  }
   }
   function print_details(category,result){ 
 	 	var no_result="";
 	 	var frm=document.customer_options;
		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 name="";
 	 		name=splt_str[0];
 	 	}	  	 		  	 		 	 	 	  	 		 	  	 
 		if(frm && frm.options_id) var id=frm.options_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': 
 	 		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="150" align="left">'+name+'</td>'+
						         '</tr>'+
						      '</tbody></table>';	
	 	 		}		 	 

	 	 		include ="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+				  				  							  
				  "<td align='left' valign='middle' width='350' class='inner_title' onclick='javascript:expand_category("+id+",6);'>"+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("+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("+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='360' onclick='javascript:expand_category("+id+",6);'>&nbsp;</td>"+
				 "<td width='80' 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("+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='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='40'>&nbsp;</td>"+				  							  			
							"<td width='100%'>"+				  							  			
				  				"<table width='100%' border='0' cellspacing='0' cellpadding='2' class='main'>";				  														
									include+="<tr>"+
											"<td align='left' width='10%'></td>"+
											"<td align='right' width='40%'><b><?php echo (($type=='I')?TABLE_HEADING_CUSTOMER_OPTIONS:TABLE_HEADING_CUSTOMER_OCCUPATIONS) . "&nbsp;&nbsp;" . ":";?></b></td>"+
											"<td align='left' width='40%'>"+name+"</td>"+
											"<td align='left' width='10%'></td>"+
										"</tr>";
									include+="<tr height='20'>"+
											"<td align='left' width='10'></b></td>"+
											"<td align='left' width='150'></td>"+
										"</tr>";
				  			  include+="</table></td></tr>"+
									   "<tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></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';
 	 		}									  
 	 	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 (($type=='I')?TEXT_INTERESTS_DELETE_SUCCESS:TEXT_OCCUPATIONS_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_CUSTOMER_OPTIONS,'action=page_navigation&type='.$type);?>&page="+len;
					do_get_command(command); 
			 } 	    	  	    	 			 			 			
 	 	break;	
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
 	 	break;	 	 	
		case 'new_location':
				var len=1;
				if(result!=""){
					/*result_splt=result.split('||');
					if(result_splt[0]>0){						
						var id=result_splt[1];
						var options_name=result_splt[0];	
						//if(head) {  
    						var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;    						
    						var row_obj=tbl_obj.insertRow(tbl_obj.rows.length);
    						var row_cell=row_obj.insertCell(0);
    						row_cell.innerHTML='<div id="data_'+id+'">'+
						       '<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						         '<tbody><tr>'+
						         	'<td class="dataTableContent" width="150" align="left">'+options_name+'</td>'+
						         '</tr>'+
						      '</tbody></table>'+
						      '</div>'+
						      '<div style="display:none;" class="openContent" id="head_'+id+'"></div>';						    						      
    						var rows_cnt=tbl_obj.rows.length-1;
    						var tbl=tbl_obj.rows[rows_cnt];
    						tbl.onclick=function () {((document.getElementById("head_"+id) && document.getElementById("head_"+id).style.display=='none')?expand_category(id,3):'')};
    						tbl.style.height="25px"; 
    						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 (($type=='I')?TEXT_INTERESTS_INSERT_SUCCESS:TEXT_OCCUPATIONS_INSERT_SUCCESS);?>";
					 res_display.style.display=""; 	    	 	
					}*/
				 command="<?php echo tep_href_link(FILENAME_CUSTOMER_OPTIONS,'action=page_navigation&type='.$type);?>&page="+len;
				 do_get_command(command);	
				}																			 						
		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_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';		    		    		     		   	
		  }
		 }		 
	  }	
	  
	  function new_class(){
	 display_flag=0;
	   var frm=document.customer_options; 
	   id=frm.options_id.value;
	   
	   if(frm && frm.options_id && frm.options_id.value>0)  {
			var old_ids=frm.options_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( pre_head && pre_head.innerHTML!='') pre_head.innerHTML="";									
		 }		 	 
			if(id>0 && frm.options_id.value>0 && frm.options_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.options_id.value=id;			   
			}
	
	  document.getElementById('span_new').style.display="";
	 if(document.getElementById('no_options'))
	 	document.getElementById('no_options').style.display="none";
	 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.getElementById('span_new').innerHTML="";
	  document.getElementById('new_class').style.display="";
	  if(frm.action_type) frm.action_type.value='new'; 
	  
	  document.getElementById('span_new').innerHTML=' <table border="0" cellspacing="2" cellpadding="4" width="100%"> '+
	  ' <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr> '+
	   '<tr valign="top"> '+
		'<td class="main" width="35%" align="right"><?php echo (($type=='I')?TABLE_HEADING_CUSTOMER_OPTIONS:TABLE_HEADING_CUSTOMER_OCCUPATIONS);?></td>'+
		'<td class="main" width="65%" align="left"><?php echo tep_draw_input_field('options_name','','size=50 maxlength=70');?></td>'+
		'</tr>'+
	   ' <tr height="30"><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>'+
	  ' </table>';
	  
	  }
	  
	  function drop_new_class(){
	  change_new_image(document.getElementById('img_new'));
	   document.getElementById('new_class').style.display="none"
	  if(document.getElementById('no_options'))
	 	document.getElementById('no_options').style.display="";
	  }
</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" cellspacing="0" cellpadding="0" width=100%>
	 <tr><td>
      <?php echo tep_draw_form('customer_options',FILENAME_CUSTOMER_OPTIONS, '' ,'post','onsubmit="javascript:return validateForm(this);"');?>
	 <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr><td id="res_display" class="main" style="display:none"></td></tr>
			  	 <tr><td> <div id="new_class_button" align="left">
				<?php echo '<a href="javascript:void new_class();" id="img_new"  onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);">' . tep_image('images/template/img_new.gif','New','22','22') . '</a>'; ?>
			</div></td></tr>
			  <tr class="dataTableHeadingRow" height="20" valign="top">
                <td class="dataTableHeadingContent"><?php echo (($type=='I')?TABLE_HEADING_CUSTOMER_OPTIONS:TABLE_HEADING_CUSTOMER_OCCUPATIONS); ?></td>
              </tr>
               <tr>
                  <td colspan="3" id="ajax_details">
	       	   			 <?php table_write(); ?>	       	   		
		   		   </td>
		 	   </tr>  
       		<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>	
      </table>
        <input type="hidden" name="options_id" id="options_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></td>
  </tr>
  </table>
<!-- body_eof //-->

<!-- 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;
	}
	function change_new_image(element){
	display_flag=1;
	element.firstChild.src=element.firstChild.src.replace('_hover.gif','.gif');
	}
</script>
