<?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 );
	set_time_limit(100);

   require('includes/application_top.php');

   require('includes/classes/split_page_results_event.php');
   require('includes/functions/services_tree.php');

   tep_get_last_access_file();// get input entries to find type of entry
   $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
   $action_value = (isset($HTTP_GET_VARS['action_value']) ? $HTTP_GET_VARS['action_value'] : '');
   $discount_id=(isset($HTTP_GET_VARS['discount_id'])?(int)$HTTP_GET_VARS['discount_id']:'');
   $service_id=(isset($HTTP_GET_VARS['service_id'])?(int)$HTTP_GET_VARS['service_id']:'');
   $page = (isset($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] :1);
   $position=isset($HTTP_GET_VARS['position'])?$HTTP_GET_VARS['position']:1;
   $select_id=(isset($HTTP_POST_VARS['select_id']) ?(int)$HTTP_POST_VARS['select_id'] : 0);
  
  $dsID=(isset($HTTP_GET_VARS['dsID'])?$HTTP_GET_VARS['dsID']:0);
  $services_array=tep_get_service_array_single();
  $service_found=true;
  if (sizeof($services_array)<=0){
    $service_found=false;
  }else {
	if ($select_id!=0 && $select_id!=$service_id){
		$service_id=$select_id;
		}
	else if ($select_id==0 && $service_id==0){
		$service_id=$services_array[0]['id']; }
   }
   $booking_type="H";
   $service_query=tep_db_query("SELECT booking_type,service_costs from " . TABLE_SERVICES ." where service_id='" . $service_id . "'");
   if (tep_db_num_rows($service_query)<=0){
   		$service_result=tep_db_fetch_array($service_query);
   		$booking_type=$service_result['booking_type'];
   }      
   if($action!=""){
   	  if($action=='get_details'){
   	  	  echo_get_details();
   	  }else if($action=='page_navigation'){
   	  		echo $action;
   	  		table_write();
   	  }else if($action=='edit'){
		    $cnt=0;
			$discount_query = tep_db_query("SELECT * from " . TABLE_SERVICES_DISCOUNTS . " where discount_id='" . $discount_id ."'  order by discount_start_date");
			$discount_result=tep_db_fetch_array($discount_query);
			echo 'edit';
		?>        				   		
			<table border="0" cellspacing="2" cellpadding="4" width="100%" align="center">			  
			  <tr><?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
						<td width="15%"></td>
						<td class="main" width=100><?php echo TEXT_DISCOUNT_SDATE; ?><br><small>(<?php echo $date_format;?>)</small></td>
						<td class="main"><?php echo tep_draw_input_field("discount_start_date",format_date($discount_result['discount_start_date']),"size=10",false,'text',false);?>
						<a href="javascript:show_calendar('select_service.discount_start_date',null,null,'<?php echo $date_format;?>');"
						  onmouseover="window.status='Date Picker';return true;"
						  onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
					    </a></td>					   
					    	<td align="left" class="main"><?php echo TEXT_DISCOUNT_STIME;?>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo tep_draw_time_field('s_time',$discount_result['discount_start_time']);?></td>					   
				</tr>
				<tr>	    
						<td width="15%"></td>
						<td class="main" width=100><?php echo TEXT_DISCOUNT_EDATE; ?><br><small>(<?php echo $date_format;?>)</small></td>
						<td class="main"><?php echo tep_draw_input_field("discount_end_date",format_date($discount_result['discount_end_date']),"size=10",false,'text',false);?>
						<a href="javascript:show_calendar('select_service.discount_end_date',null,null,'<?php echo $date_format;?>');"
						  onmouseover="window.status='Date Picker';return true;"
						  onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
						</a>
						</td>						
					    	<td align="left" class="main"><?php echo TEXT_DISCOUNT_ETIME;?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo tep_draw_time_field('e_time',$discount_result['discount_end_time']);?></td>					    
						</tr>
						<tr>
						<td></td>
							<td class="main" width=100><?php echo TEXT_DISCOUNT_VALUE; ?></td>
							<td class="main"><?php echo tep_draw_input_field('discount_value',$discount_result['discount_value'],'size=10 maxlength=10'); ?></td>
							<td class="main" valign=center><?php echo TEXT_DISCOUNT_TYPE; ?>
							<?php 
								echo tep_draw_radio_field('discount_type','A',($discount_result['discount_type']=='A'?true:false)) . '&nbsp;' . TEXT_TYPE_AMOUNT . '&nbsp;';
								echo tep_draw_radio_field('discount_type','P',($discount_result['discount_type']=='P'?true:false)) . '&nbsp;' . TEXT_TYPE_PERCENTAGE . '&nbsp;';
							?>
							</td>
						</tr>
						<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>
				 
					</table>
				</td>
			</tr>
			<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>		
 		 </table>      
<?php   }else if($action=='pos_down' || $action=='pos_up'){


  }else if($action=='delete'){
		 
			$lang_class_string='delete';
			$lang_class_string.="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
			$lang_class_string.='<td width="500" align="left" class="inner_title">'. TEXT_INFO_HEADING_DELETE  .'</td></tr>';
			$lang_class_string.='<tr><td></td><td width="500" align="left" class="main">' . TEXT_INFO_DELETE_INTRO .'<br></td></tr>';
			$lang_class_string.='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',60,20).'</td></tr></table>';
			echo $lang_class_string;
			
        }else if($action=='update'){ 	 
		
		   $start_date = (getServerDate() < tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['discount_start_date']))) ? tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['discount_start_date'])) : getServerDate(); 
		   $end_date=(getServerDate() < tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['discount_end_date']))) ? tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['discount_end_date'])) : getServerDate();
		   $start_time="00:00:00";
		   $end_time="00:00:00";
		   if($HTTP_POST_VARS['s_time_h']!="") $start_time = (($HTTP_POST_VARS['s_time_d']=='PM' && $HTTP_POST_VARS['s_time_h']!="")?$HTTP_POST_VARS['s_time_h']+12:$HTTP_POST_VARS['s_time_h']).':'.$HTTP_POST_VARS['s_time_m'].':00'; 
		   if($HTTP_POST_VARS['e_time_h']!="") $end_time = (($HTTP_POST_VARS['e_time_d']=='PM' && $HTTP_POST_VARS['e_time_h']!="")?$HTTP_POST_VARS['e_time_h']+12:$HTTP_POST_VARS['e_time_h']).':'.$HTTP_POST_VARS['e_time_m'].':00';
				$sql_array=array('discount_start_date'=>$start_date,
						'discount_end_date'=>$end_date,
						'discount_start_time'=>$start_time,
						'discount_end_time'=>$end_time,
						'discount_value'=>tep_db_prepare_input($HTTP_POST_VARS['discount_value']),
						'discount_type'=>tep_db_prepare_input($HTTP_POST_VARS['discount_type']));
						
							  
		if ($HTTP_POST_VARS['dsID']>0 && $HTTP_POST_VARS['action_type']=='edit')   {
		if (isset($HTTP_POST_VARS['dsID'])){
			$update_id=$HTTP_POST_VARS['dsID'];
			tep_db_perform(TABLE_SERVICES_DISCOUNTS,$sql_array,'update',"discount_id='" . $update_id . "'");
		}		  			
		}else  if($HTTP_POST_VARS['action_type']=='new'){
		   if($HTTP_POST_VARS['s_time_h']!="") $start_time = (($HTTP_POST_VARS['s_time_d']=='PM' && $HTTP_POST_VARS['s_time_h']!="")?$HTTP_POST_VARS['s_time_d']+12:$HTTP_POST_VARS['s_time_h']).':'.$HTTP_POST_VARS['s_time_m'].':00'; 
		   if($HTTP_POST_VARS['e_time_h']!="") $end_time = (($HTTP_POST_VARS['e_time_d']=='PM' && $HTTP_POST_VARS['e_time_h']!="")?$HTTP_POST_VARS['e_time_d']+12:$HTTP_POST_VARS['e_time_h']).':'.$HTTP_POST_VARS['e_time_m'].':00';
			$sql_array=array('discount_start_date'=>tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['discount_start_date'])),
						'discount_end_date'=>tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['discount_end_date'])),
						'discount_start_time'=>$start_time,
						'discount_end_time'=>$end_time,
						'service_id'=>$service_id,
						'discount_value'=>tep_db_prepare_input($HTTP_POST_VARS['discount_value']),
						'discount_type'=>tep_db_prepare_input($HTTP_POST_VARS['discount_type'])
						);
			tep_db_perform(TABLE_SERVICES_DISCOUNTS,$sql_array);
			$insert_id=tep_db_insert_id();
			echo "new_discount";
		}
		echo_get_details();
   	 }else if($action=='delete_confirm'){
	    tep_db_query("DELETE from " . TABLE_SERVICES_DISCOUNTS . " where  discount_id='" . $HTTP_POST_VARS['dsID'] . "'");
	    echo 'delete_success';	     
	 }
   	 exit;
   }        
   function echo_get_details(){
  	 global $discount_id,$service_id;
  		  
  		$time_format=(defined('TIME_FORMAT'))?TIME_FORMAT:'';
  		$discount_query = tep_db_query("SELECT * from " . TABLE_SERVICES_DISCOUNTS . " where discount_id='" . (int)$discount_id ."'  order by discount_start_date");		
		$lang_class=tep_db_fetch_array($discount_query);
		$start_time=date('h:i A',strtotime($lang_class['discount_start_time']));
		$end_time=date('h:i A',strtotime($lang_class['discount_end_time']));
		if($time_format=='24') {
			$start_time=date('H:i',strtotime($lang_class['discount_start_time']));
			$end_time=date('H:i',strtotime($lang_class['discount_end_time']));
		}
		$str_vals.=$lang_class['discount_id']."||".format_date($lang_class['discount_start_date'])."||".format_date($lang_class['discount_end_date'])."||".$start_time."||".$end_time."||".$lang_class['discount_value']."||".$lang_class['discount_type']."||".$lang_class['service_id'];
		echo 'get_details'.$str_vals;
   } 

   function table_write(){
    global $page,$service_id,$HTTP_GET_VARS,$booking_type;
   ?>
   	 
  	<table border="0" cellpadding="0" cellspacing="0" width="100%" id="discount_table">
			
			<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>
	<tr class="dataTableHeadingRow" height=20 valign="top">
				  	 <td class="main" align="center" width="20%" nowrap="nowrap"><b><?php echo TEXT_DISCOUNT_SDATE; ?></b></td>				  	 
				  	 <td class="main" align="center" width="20%" nowrap="nowrap"><b><?php echo TEXT_DISCOUNT_STIME; ?></b></td>				  	
               		 <td class="main" align="center" width="20%"><b><?php echo TEXT_DISCOUNT_EDATE; ?></b></td>               		 
				  	 <td class="main" align="center" width="20%" nowrap="nowrap"><b><?php echo TEXT_DISCOUNT_ETIME; ?></b></td>				  	 
					 <td class="main" align="center" width="10%"><b><?php echo TEXT_DISCOUNT_VALUE; ?></b></td>
					 <td class="main" align="center" width="10%"><b><?php echo TEXT_DISCOUNT_TYPE; ?></b></td>
               	 </tr>
	<?php   
	if($service_id==-1) $discount_query_raw = "SELECT * from " . TABLE_SERVICES_DISCOUNTS . " order by discount_start_date";		 
	else $discount_query_raw = "SELECT * from " . TABLE_SERVICES_DISCOUNTS . "  where service_id='" . $service_id ."'  order by discount_start_date";	
	
 		   $dis_query = tep_db_query($discount_query_raw);		   
		   if(tep_db_num_rows($dis_query)>0){ 
		    while ($discount = tep_db_fetch_array($dis_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_'.$discount['discount_id'].'\').style.display==\'none\') expand_category(' . $discount['discount_id'] . ',3);">' . "\n";
  				 $time_format=(defined('TIME_FORMAT'))?TIME_FORMAT:'';
  				 $start_time=date('h:i A',strtotime($discount['discount_start_time']));  				 
				 $end_time=date('h:i A',strtotime($discount['discount_end_time']));
				if($time_format=='24') {
					$start_time=date('H:i',strtotime($discount['discount_start_time']));
					$end_time=date('H:i',strtotime($discount['discount_end_time']));
				} 
			   ?>  			      
		   	  <td colspan="6" width="100%" >
		   	  	<div id="data_<?php echo $discount['discount_id'];?>">
		   	  	 <table border="0" cellspacing="0" cellpadding="0" width="100%">
		   	  		<tr>
                   		<td class="dataTableContent" width="20%" align="center"  nowrap="nowrap" id="lname_<?php echo $discount['discount_id'];?>"><?php echo format_date($discount['discount_start_date']); ?></td>                   		
                   		<td  class="dataTableContent" width="20%" align="center" nowrap="nowrap"><?php echo $start_time; ?></td>
             	   		<td  class="dataTableContent" width="20%" align="center" nowrap="nowrap"><?php echo format_date($discount['discount_end_date']); ?></td>
             	   		<td  class="dataTableContent" width="20%" align="center" nowrap="nowrap"><?php echo $end_time; ?></td>
				   		<td class="dataTableContent" width="10%"  align="center" nowrap="nowrap" ><?php echo $discount['discount_value']; ?></td>
				   		<td  class="dataTableContent" width="10%" align="center" nowrap="nowrap" ><?php echo $discount['discount_type']=='A'?'$':'%'; ?></td>
             		</tr>
		   	  	</table>
		   	   </div>
		   	   <div class="openContent" id="head_<?php echo $discount['discount_id'];?>" style="display:none"></div>
		   	  </td>					      
      		</tr>
			
      	<?php }
			 }else echo '<tr height="20"></tr><tr><td class="main" colspan="6" width="100%" align="center"> No discount found </td></tr>
			 			 ';
			  ?>
			  
			  
			  <tr id="new_discount" style="display:none" class="openContent">
			<td colspan="6" class="openContent_top">	
				<table cellpadding="1" cellspacing="0" border="0" width="100%">
					<tr>
						<td class="inner_title"><?php echo 'New Discount';?></td>
						<td width='400' align='right' ><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:drop_new_discount();'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>
					</tr>
					<tr><td colspan='6'><div id="span_new" style="display:none"></div></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/service_select.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/menu.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<?php  require('includes/date_format_js.php'); ?>
<script language="javascript" src="includes/http.js"></script>
<script language=javascript>
   var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
   var selected="<?php echo $service_id;?>";
   function validateForm(lfrm){
      var error_result="";
      if(lfrm.action_type) var action_type=lfrm.action_type.value;
	  if(lfrm && lfrm.dsID) id=lfrm.dsID.value;
	  var span_details=document.getElementById("span_details");
	  var span_new=document.getElementById("span_new");
	  var span_edit=document.getElementById("span_edit");		
	  var details;		
	  var span_delete=document.getElementById("span_delete");
	  var loadings=document.getElementById("loading");
	  var ids="";
	  if(span_edit)
	  details=span_edit;	
	  else details=span_new;  	 
	   if(details.style.display==""){	
	   
	    if ( (lfrm.discount_start_date.value=="") || (str_trim(lfrm.discount_start_date.value)=="") )
			  		error_result+="Start Date Required\n";
			  if ( (lfrm.discount_end_date.value=="") || (str_trim(lfrm.discount_end_date.value)=="") )
			  		error_result+="End Date Required\n";
			  if( (lfrm.discount_value.value=="") || (str_trim(lfrm.discount_value.value)=="") )
			 		error_result+="Discount Value Required\n";	
			  if (isNaN(lfrm.discount_value.value))
			     	error_result+="Discount Value should be a Number\n";			
			  if ( (!(lfrm.discount_type[0].checked)) && (!(lfrm.discount_type[1].checked)) )
			 		error_result+="Discount Type required\n";
			  
			  
			  
			
		var st_date=date_format(lfrm.discount_start_date.value,'<?php echo EVENTS_DATE_FORMAT;?>','Y-m-d');
		var end_date=date_format(lfrm.discount_end_date.value,'<?php echo EVENTS_DATE_FORMAT;?>','Y-m-d');
		if(st_date>end_date) 
			error_result=error_result + '* <?php echo ERR_START_DATE;?>\n';
		
													   	       		  
	 	 if (error_result!=""){
    	    alert(error_result);
	 		 return false;
	     }else{      							
			if(lfrm.action_type && lfrm.action_type.value=='edit')  ids="&discount_id="+id;
			document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
			display_flag=1;
			command="<?php echo tep_href_link(FILENAME_SERVICES_DISCOUNTS,'action=update');?>"+ids+"&service_id="+selected;
			if(loadings) loadings.style.display="";
			if(span_edit) span_edit.style.display="none";
			if(document.getElementById("new_discount")){document.getElementById("new_discount").style.display="none";
			}
			
	      }
	}else if(span_delete.style.display==""){      							
			ids="&discount_id="+id + "&service_id="+selected;
			command="<?php echo tep_href_link(FILENAME_SERVICES_DISCOUNTS,'action=delete_confirm');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
     }
	do_post_command('select_service',command);
    return false;
   }
  var previous_id='';   
  function expand_category(id,category,r_type,sta){
    if(id==0 && category==2) display_flag=0;	
	if(id==0 && category==1){
		document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
		display_flag=1;
	} 
    document.getElementById('span_new').style.display="none";
  	document.getElementById('new_discount').style.display="none";
	document.getElementById('span_new').innerHTML='';
	if( document.getElementById('new_customer_button'))
    document.getElementById('new_customer_button').style.display='';
			
		//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.select_service;
		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.dsID && frm.dsID.value>0)  {
			var old_ids=frm.dsID.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.dsID.value>0 && frm.dsID.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.dsID.value=id;			   
			}							
		if(category!=1 && frm && frm.dsID && frm.dsID.value=="") frm.dsID.value=id;	
 	 	if(category){
 	 		var span_details=document.getElementById("span_details");
			var span_new=document.getElementById("span_new");
 	 		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=""; 
					   var ser="";
					    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_SERVICES_DISCOUNTS,'action=page_navigation');?>"+page+"&service_id="+selected;
					   //alert(command);
 	 			   	   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'; 	//alert(frm.action_type.value); 					
 	 				 command="<?php echo tep_href_link(FILENAME_SERVICES_DISCOUNTS,'action=edit');?>"; 	
					// alert(command)
				break; 	 			
 	 			case 3:
				if(document.getElementById("new_discount")){ document.getElementById("new_discount").style.display="none"; 	 			   
				    if(document.getElementById('img_new')) 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_new.style.display=="") span_new.style.display="none";
 	 			   	  	if(span_edit.style.display=="") span_edit.style.display="none";
 	 			   	  	if(span_delete.style.display=="") span_delete.style.display="none"; 	 			   	  	 	 			   	  	
 	 			   	  	span_details.style.display="";
 	 			   	  	if(img_save) img_save.style.display="none"; 
 	 			   	  	if(document.getElementById("img_ids")){
 	 			   	  		var tr_obj=document.getElementById("img_ids");
 	 			   	  		if(tr_obj.childNodes[1].childNodes[0].src==img_src+'template/img_edit_hover.gif')	
 	 			   	  			tr_obj.childNodes[1].childNodes[0].src=img_src+'template/img_edit.gif';
 	 			   	  		if(tr_obj.childNodes[2].childNodes[0].src==img_src+'template/img_trash_hover.gif')	
 	 			   	  			tr_obj.childNodes[2].childNodes[0].src=img_src+'template/img_trash.gif';	 	 			   	  			
 	 			   	  	}	 			   	  	  	 			   	  	 	 			   	  	
 	 			   	  }	 	 			    			   	   	 			   
 	 			 }else { 	 			 	 	 			 	
					 if(previous_id!='') 
						 if(document.getElementById('head_'+previous_id))
							document.getElementById('head_'+previous_id).innerHTML='';
					
					if(data_id && data_id.style.display=="") data_id.style.display="none";
 	 			 	if(pre_head && pre_head.style.display=="") pre_head.style.display="none"; 	 			 	
 	 			 	if(head) {
 	 			 	 	head.style.display=""; 	 			 	 	 	 			 	  	 			
 	 			 		head.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";	 			 		
 	 			 	}
					
					
 	 			 	command="<?php echo tep_href_link(FILENAME_SERVICES_DISCOUNTS,'action=get_details');?>&discount_id="+id+"&service_id="+selected; 
					//alert(command);
					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_SERVICES_DISCOUNTS,'action=edit');?>&discount_id="+id+"&service_id="+selected; 	
						//alert(command);
 	 			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_SERVICES_DISCOUNTS,'action=delete');?>&discount_id="+id+"&service_id="+selected; 	 	 	 					 	 					 	 			
						//alert(command);
 	 			break;
				case 6:				 																
				case 7:
					var s_order=frm.sort_order;															
					if(head) var tbl_tr_obj=head.parentNode.parentNode;																									
					var pos_cnt=0;																																	
					pos="pos_up";
					if(category==7) pos="pos_down";
					command="<?php echo tep_href_link(FILENAME_SERVICES_DISCOUNTS);?>?tid="+id+"&pos="+r_type+"&action="+pos;					
					if(s_order) s_order.value=pos;					
					var tpl_cnt=tbl_tr_obj.parentNode.rows.length;
					tpl_cnt=tpl_cnt-2;										
					if(tbl_tr_obj && (tbl_tr_obj.rowIndex==0 && pos=='pos_up' || tpl_cnt==tbl_tr_obj.rowIndex && pos=='pos_down')) return;
				break;		
				
				case 8:
				
				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){
//alert(result);
   	  var frm=document.select_service;
   	  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,5)=='close') print_details('close',result.substr(5));	
		else if(result.substr(0,15)=='page_navigation') print_details('page_navigation',result.substr(15));
		else if(result.substr(0,16)=='sort_order_error') print_details('sort_order_error',result.substr(16));
		else if(result.substr(0,18)=='sort_order_success') print_details('sort_order_success',result.substr(18));
		else if(result.substr(0,12)=='new_discount') print_details('new_discount',result.substr(12));
		else if(result.substr(0,6)=='delete') print_details('delete',result.substr(6));		
   	  }
   }
   function print_details(category,result){ 	 	 	 	 	 	 	 	 	 	
 	 	var no_result="";
	 	var frm=document.select_service;
		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 service_id=""; 		  	 		
 	 		var start_date="";
			var end_date="";
			var start_time="";
			var end_time="";
			var discount_value="";
			var discount_type="";			
			
 	 		discount_id=splt_str[0]; 	 	
 	 		start_date=splt_str[1];
 	 		end_date=splt_str[2]; 	 
 	 		start_time=splt_str[3];
 	 		end_time=splt_str[4];
			discount_value=splt_str[5]; 
			discount_type=splt_str[6]; 
			service_id=splt_str[7]; 
			
			if(discount_type=='A'){
			discount_type='$';
			}else{
			discount_type='%';
		     }
 	 	}	  	 		  	 		 	 	 	  	 		 	  	 
 		if(frm && frm.dsID) var id=frm.dsID.value; 	
	
 		var span_details=document.getElementById("span_details");	
		var span_new=document.getElementById("span_new"); 	 
 		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.display="";		
 	 	switch(category){ 	 		 	 		 	 		 	 		
 	 		case 'get_details': 
				
	 		if(head  && no_result!="")
				head.innerHTML=no_result; 	 			 	 		
 	 		else if(head && no_result==""){	 	 		
	 	 		if(data_id){		 	 		
		 	 		data_id.innerHTML='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						         '<tbody><tr>'+
						         	'<td class="dataTableContent" width="20%" align="center" id="lname_'+discount_id+'" >'+start_date+'</td>'+
						         	'<td class="dataTableContent" width="20%" align="center">'+start_time+'</td>'+
									'<td class="dataTableContent" width="20%" align="center">'+end_date+'</td>'+
									'<td class="dataTableContent" width="20%" align="center">'+end_time+'</td>'+
									'<td class="dataTableContent" width="10%" align="center">'+discount_value+'</td>'+
									'<td class="dataTableContent" width="10%" align="center">'+discount_type+'</td>'+
							    '</tr>'+
								
						      '</tbody></table>';	
	 	 		}		 	 			
	 	 		include ="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+				  				  							  
				  "<td width='40' valign='top' align='center' onclick='javascript:expand_category("+discount_id+",8);'>&nbsp;</td>"+
				  "<td align='left' valign='middle' width='350' class='inner_title' onclick='javascript:expand_category("+discount_id+",8);'></td>"+
				  "<td width='100' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='width:100;height:30px;display:inline;position:relative;'>"+
				  	  "<tr class='img_move' id='img_ids'>"+
				  	  	"<td class='cell_bg_popm_left' width='5'>&nbsp;</td>"+
				  	    "<td width='10%' onclick='javascript:change_class(this,1);expand_category("+discount_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("+discount_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 width='240' onclick='javascript:expand_category("+discount_id+",8);'>&nbsp;</td>"+
				 "<td width='80' align='right' id='img_save' style='display:none'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category("+discount_id+",3);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>"+
				"</tr>"+
				"<tr style='height:10'><td id='loading' style='display:none' colspan='6'><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 >"+				  							  			
				  				"<table width='100%' border='0' cellspacing='0' cellpadding='2' class='main'>"+

								"<tr>"+
								"<td  nowrap='nowrap' width='10%'><b></b></td>"+
											"<td align='left' nowrap='nowrap' width='10%'><b><?php echo 'Discount Start Date:';?></b></td>"+
											"<td nowrap='nowrap'  align='left'  width='15%'>"+start_date+"</td>"+											
											"<td align='left'  nowrap='nowrap' width='10%'><b><?php echo 'Discount End Date:';?></b></td>"+
											"<td nowrap='nowrap' align='left' width='15%'>"+end_date+"</td>"+
										"</tr>"+										
										"<tr>"+
										"<td  nowrap='nowrap' width='10%'><b></b></td>"+
											"<td align='left' nowrap='nowrap' width='10%'><b><?php echo 'Discount Value:';?></b></td>"+
											"<td nowrap='nowrap' align='left' width='15%'>"+discount_value+"</td>"+
											"<td align='left'  nowrap='nowrap' width='10%'><b><?php echo 'Discount Type:';?></b></td>"+
											"<td nowrap='nowrap' align='left' width='15%'>"+discount_type+"</td>"+
										"</tr>"+
										"<tr>"+										
											"<td  nowrap='nowrap' width='10%'><b></b></td>"+
											"<td align='left' nowrap='nowrap' width='10%'><b><?php echo 'Discount Start Time:';?></b></td>"+
											"<td nowrap='nowrap'  align='left'  width='15%'>"+start_time+"</td>"+
											"<td align='left' nowrap='nowrap' width='10%'><b><?php echo 'Discount End Time:';?></b></td>"+
											"<td nowrap='nowrap'  align='left'  width='15%'>"+end_time+"</td>"+
										"</tr>";
						 include+="</table></td></tr><tr><td>&nbsp;</td></tr>"+
					"</span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
			
 	 		} 	 			 	 		
 	 	break;
 	 	case 'edit': 	
		   	
		 		 	 		 	 		 	 		
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){ 	 			 	 			
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}									  
 	 	break;
 	 	case 'delete': 	 				 	 	
 	 		if(span_delete) span_delete.style.display="";
 	 		if(span_delete){ 	 			
 	 			span_delete.innerHTML=result; 	 			
 	 			span_details.style.display=span_edit.style.display='none';
 	 		} 	 								   			   
 	 	break; 	 	
 	 	case 'delete_success':			 
 	    	 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 				 			
			 }
 	    	 if(res_display){
	    	 	res_display.innerHTML="<?php echo TEXT_DELETE_SERVICE;?>";
 	    	 	res_display.style.display="";
				var obj=document.getElementById("page_''");
 	    	 	if(obj){  	    	 		
 	    	 		var len=obj.options[obj.selectedIndex].value;
				}	
					command="<?php echo tep_href_link(FILENAME_SERVICES_DISCOUNTS,'action=page_navigation');?>&page="+len+"&service_id="+selected;
					//alert(command +"&service_id="+selected);
					do_get_command(command);
 	    	} 	    	 			 			 			
 	 	break;	
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
			 if(document.getElementById('img_new')) document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
			 display_flag=1;
 	 	break;	 	
		case 'sort_order_success':
		case 'sort_order_error':
			if(frm.sort_order) var s_order=frm.sort_order.value;															
			if(category=='sort_order_success'){			  			   
			   if(head)  {
				var tbl_obj=head.parentNode.parentNode;
				var up_href=head.childNodes[0].childNodes[0].childNodes[0].childNodes[2].childNodes[0];
			    var down_href=head.childNodes[0].childNodes[0].childNodes[0].childNodes[2].childNodes[2];			    
			    var new_pos=result.substr(result.indexOf('sort_order_success'));			    
			    if(up_href && down_href && new_pos){
					up_href.href="javascript:expand_category("+id+",6,"+new_pos+")";
					down_href.href="javascript:expand_category("+id+",7,"+new_pos+")";
			    }
				var x=1;
				if(s_order && s_order!="" && s_order=="pos_up") x=-1;								
				var row=tbl_obj;
				var index=row.rowIndex;
				var count=tbl_obj.parentNode.rows.length;				
				if (x==-1 && index==0) return;
				if (x==1 && index==count-1) return;
				if (x==-1){
				   row.parentNode.insertBefore(row,row.parentNode.rows[index-1]);
				} else {
					if (index==row.parentNode.rows.length-2)
						row.parentNode.appendChild(row);
					else
						row.parentNode.insertBefore(row,row.parentNode.rows[index+2]);
				}																 							
  		      }			   			   					            	            	      		               	      	    	 	 			  
			}else if(category=='sort_order_error'){
				res_display.style.display=""; 	    	 	
			    res_display.innerHTML="<?php echo 'Error in DB Please Try Again';?>"; 	    	 	 	    	 	 	    	 	 	    	 	 
			}
		break; 	
		case 'new_discount':
		 //alert('fdds');
		 display_flag=0;
				var len=1;
				if(result!=""){
					result_splt=result.split('||');
					if(result_splt[0]>0){						
						var id=result_splt[0];
						var tax_class_title=result_splt[1];	
						var tax_class_description=result_splt[2];						
						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">'+'sdf'+'</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 'insert success';?>";
				 	    	 res_display.style.display=""; 	    	 	
 	    	 				}
						}    					
					}
					command="<?php echo tep_href_link(FILENAME_SERVICES_DISCOUNTS,'action=page_navigation');?>&page="+len+"&service_id="+selected;
					
					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_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_discount(){
	  display_flag=0;
	  var frm=document.select_service;
	  id=frm.dsID.value;
	  if(frm && frm.dsID && frm.dsID.value>0)  {
			var old_ids=frm.dsID.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.dsID.value>0 && frm.dsID.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.dsID.value=id;			   
			}
	
	  document.getElementById('span_new').style.display="";
	 // document.getElementById('img_save').style.display="";
	 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_discount').style.display="";
	  if(frm.action_type) frm.action_type.value='new'; 
	  
	 var booking_type="<?php echo $booking_type;?>";
	 document.getElementById('span_new').innerHTML='<table border="0" cellpadding="2" cellspacing="2" width="100%" align="center" class="openContent">'+
	 '  <tr><td width="15%"></td><td  align="left" class="main"><?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?><?php echo TEXT_DISCOUNT_SDATE; ?><br><small>(<?php echo $date_format;?>)</small>'  +
	 '</td><td align="left" class="main">' +
	 '<?php echo tep_draw_input_field("discount_start_date",'',"size=10",false,'text',false); ?>&nbsp;&nbsp;' + 
	 '<a href="javascript:show_calendar(\'select_service.discount_start_date\',null,null,\'<?php echo $date_format;?>\');"  onmouseover="window.status=\'Date Picker\';return true;"  onmouseout="window.status=\'\';return true;">' +
	'<img border="none" src="images/icon_calendar.gif"/>  ' +
	'</a></td>' +
	'<td align="left" class="main"><?php echo TEXT_DISCOUNT_STIME; ?></td><td align="left" class="main"><?php echo tep_draw_time_field('s_time');?></td></tr>'+
	'<tr><td width="15%"></td><td align="left" class="main"><?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?><?php echo TEXT_DISCOUNT_EDATE; ?><br><small>(<?php echo $date_format;?>)</small></td><td> '+
	'<?php echo tep_draw_input_field("discount_end_date",'',"size=10",false,'text',false); ?>&nbsp;&nbsp;'+
	 '<a href="javascript:show_calendar(\'select_service.discount_end_date\',null,null,\'<?php echo $date_format;?>\');"  onmouseover="window.status=\'Date Picker\';return true;"  onmouseout="window.status=\'\';return true;">' +
	'<img border="none" src="images/icon_calendar.gif"/>  ' +
	'</a></td>' +
	'<td align="left" class="main"><?php echo TEXT_DISCOUNT_ETIME; ?></td><td align="left" class="main"><?php echo tep_draw_time_field('e_time');?></td></tr>'+
	'<tr><td width="15%"></td><td align="left" class="main"><?php echo TEXT_DISCOUNT_VALUE; ?></td><td class="main"><?php echo tep_draw_input_field('discount_value','','size=10 maxlength=10'); ?></td>' +  
	'<td align="left" class="main"><?php echo TEXT_DISCOUNT_TYPE;  ?></td><td nowrap="nowrap" class="main"><?php echo tep_draw_radio_field('discount_type','A','') . TEXT_TYPE_AMOUNT . '&nbsp;'; ?>' +  
	'<?php echo tep_draw_radio_field('discount_type','P','') . '&nbsp;' . TEXT_TYPE_PERCENTAGE  . '&nbsp;'; ?></td></tr><tr><td><img src="images/pixel_trans.gif" border="0" alt="" width="5" height="15"></td></tr>' +  
	'</table>';
	//document.getElementById('new_customer_button').style.display='none';
	  }
	  
	  function drop_new_discount(){
	 // document.getElementById('img_save').style.display="none";
	  change_new_image(document.getElementById('img_new'));
	  document.getElementById('new_discount').style.display="none"
	  document.getElementById('new_customer_button').style.display='';
	
	if(document.getElementById('new_customers_row_id')){
	customer_row_index=document.getElementById('new_customers_row_id').rowIndex;
	ajax_row_index=document.getElementById('new_ajax_row_id').rowIndex;
		var r1=document.getElementById('discount_table').deleteRow(customer_row_index);
		var r2=document.getElementById('discount_table').deleteRow(ajax_row_index-1);
	}
	}
	
	function cc(){
	selected=document.select_service.select_id.options[document.select_service.select_id.selectedIndex].value;
	}
	 
	 
</script>
<?php  // WebMakers.com Added: Java Scripts   
      include(DIR_WS_INCLUDES . 'javascript/' . 'webmakers_added_js.php')
?>
</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 valign="top">
             <?php echo tep_draw_form('select_service',FILENAME_SERVICES_DISCOUNTS, '' ,'post','onSubmit="return validateForm(this);"');?>
	       	<table border="0" cellspacing="0" cellpadding="0" width=100%>
                 <tr><td id="res_display" class="main" style="display:none"></td></tr>
				
				 <?php  if($service_id!=-1){?>
				<tr ><td align="left" class="dataTableHeadingRow"  valign="middle">
			 <div id="new_customer_button" align="left">
				<?php echo '<a href="javascript:void new_discount();" 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 Discount','22','22') . '</a>'; ?>
			</div> 
			</td></tr>
			<?php } ?>
			 <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>	
				 <tr  height=20 valign="bottom" class="dataTableHeadingRow" ><td>Discount Prices For Service</td></tr>
				 <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>	
				 <tr><td>&nbsp;</td></tr>
				 <tr><td>
				 <div id="service_list"  style="position:absolute;left:247px;top:175px;display:none;width:400px;">
						<?php echo tep_draw_service_select_menu('select_id',$services_array,$service_id,'size=10 onClick="javascript:setListboxText(0);toggleList(0);document.select_service.submit();" onFocus="javascript:toggleList(1);" onChange="javascript:cc();" onBlur="javascript:toggleList(0);" class="customerSelect"');?>
					</div>
				 <table border="0" cellspacing="0" cellpadding="2">
					
					<tr height=20>
						<td class="main" width="100" nowrap="nowrap"><?php echo TEXT_SELECT_SERVICE;?></td>
						<td class="main"><?php echo tep_draw_input_field('select_text',$selected_name,'onFocus="javascript:toggleText(1);" onBlur="javascript:toggleText(0);" style="width:400px"');?></td>
						<td class="main" valign=center><?php //echo tep_image_submit('button_select.gif',IMAGE_SELECT,'align=absmiddle size=');?></td>
					</tr>
		</table> 
		</td></tr>
		<tr><td>
				
		<table border="0" cellspacing="0" cellpadding="2">
			<tr><td><?php echo tep_draw_separator('pixel_trans.gif','1','20'); ?></td></tr>
			<tr>
			<?php  if($service_id==-1){?>
			<td class="pageHeading" nowrap="nowrap"><?php echo sprintf(TEXT_HEADING_TITLE,'All services'); } else{ ?></td>  
			
			
				<td class="pageHeading" nowrap="nowrap"><?php echo sprintf(TEXT_HEADING_TITLE,tep_get_service_name($service_id)); }?></td>  
			</tr>
			<tr><td><?php echo tep_draw_separator('pixel_trans.gif','1','10'); ?></td></tr>
	  	</table>
		</td></tr>
                 <tr>
                	  <td colspan="6" id="ajax_details">

	       	   			 <?php echo table_write(); ?>	  
		  			 </td>
				 </tr>        
       			<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>	
		
      	  </table>
        <input type="hidden" name="service_id" id="service_id">
		<input type="hidden" name="dsID" id="dsID">
	    <input type="hidden" name="action_type" id="action_type">
	    <input type="hidden" name="icnt" id="icnt">
		<input type="hidden" id="sort_order">
        </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){
	//alert (element.firstChild.src);
	if(display_flag==1){
	if (element.mode && mode==element.mode) return;
	if (mode==2){
	//alert ('hi');
		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>
		<script language="JavaScript">
					if(na6) document.select_service.select_text.addEventListener("keyup",selectList,true);
					if(iex) document.select_service.select_text.onkeyup=selectList;
					if(na6) document.select_service.select_text.addEventListener("keydown",scrollList,true);
					if(iex) document.select_service.select_text.onkeydown=scrollList;
				</script>
				<script language="JavaScript">
		function resize(){
			document.getElementById('service_list').style.visibility="hidden";
			document.select_service.select_text.blur();
		}
		var iex=(document.all);//ie
		var na6=(window.sidebar);//netscape 6.2
		var lastposition=0;
		var currentField="";
		var intervalId;
			function checkdropDown(){
				if (currentField==""){
					clearInterval(intervalId);
					hideList();
					intervalId="";
				}
			}
			function toggleText(mode){
				if (mode==1) {
					currentField="Text";
					showList();
					if (intervalId) clearInterval(intervalId);
					intervalId=setInterval("checkdropDown()",300);
				} else {
					currentField="";
				}
			}
			function toggleList(mode){
				if (mode==1){
					currentField="drop";
				} else {
					currentField="";
				}
			}
			function showList(){
				var listbox=document.getElementById("service_list");
				var textbox=document.select_service.select_text;
				listbox.style.visibility="visible";
				listbox.style.display="";
				// formtable && holetable are in Header page
			/*	if(iex){
					if(window.scrollMaxX >0)listbox.style.left=formtable.offsetLeft+62;
					else listbox.style.left=formtable.offsetLeft+107;
					listbox.style.top=holetable.offsetTop+53;
				}else{
					if(window.scrollMaxX >0)listbox.style.left=formtable.offsetLeft+117;
					else listbox.style.left=formtable.offsetLeft+110;
					listbox.style.top=holetable.offsetTop+105;
				}
			*/
			
				if(window.scrollMaxX >0)listbox.style.left=document.getElementById('formtable').offsetLeft+75;
				else listbox.style.left=document.getElementById('formtable').offsetLeft+110;
				listbox.style.top=document.getElementById('holetable').offsetTop+134;
			}
			function hideList(){
				var listbox=document.getElementById("service_list");
				var textbox=document.select_service.select_text;
				setListboxText(1);
				listbox.style.display="none";
			}
			function scrollList(e){
				var listbox=document.select_service.select_id;

				if (iex) keyCode=window.service.keyCode;
				if (na6) keyCode=e.which;

				if (keyCode==40 || keyCode==38){
					if (keyCode==40 && listbox.selectedIndex>=0 && listbox.selectedIndex<listbox.options.length-1){
						listbox.selectedIndex+=1;
					} else if (keyCode==38 && listbox.selectedIndex>0 && listbox.selectedIndex<=listbox.options.length-1){
						listbox.selectedIndex-=1;
					}

					setListboxText(0);
					if (iex) window.service.returnValue=0;
					if (na6) e.returnValue=0;
					return;

				}
			}
			function selectList(e){
				var listbox=document.select_service.select_id;
				var search_word=document.select_service.select_text.value;
				var text_length;
				var found=-1;
				var listbox_word;
				var serviceObject;
				var keyCode=0;
				var fromPos=0;
				var toPos=0;
	
				if (!listbox.options || listbox.options.length<=0) return;

				if (search_word!="") {
					search_word=search_word.toLowerCase();
					found=binaryFind(listbox,search_word,0,listbox.options.length-1);
					if (found>=0)
						listbox.selectedIndex=found;
				}

			}
			function setListboxText(mode){
				var listbox=document.select_service.select_id;
				if (!listbox.options || listbox.options.length<=0 || listbox.selectedIndex<=-1) return;
				var textbox_name=document.select_service.select_text;
				if (textbox_name.value=="" && mode==1) return "";
				textbox_name.value=listbox.options[listbox.selectedIndex].innerHTML;
				//document.select_service.submit();
			}
			function binaryFind(listBox,fWord,sPos,ePos){
				var listElement;
				var tWord;
				var mPos;
				if (sPos>ePos) return -1;
				mPos=sPos+Math.ceil((ePos-sPos)/2);
				
				if (mPos<0 || mPos>=listBox.options.length) return -1;
				listElement=listBox.options[mPos].innerHTML.toLowerCase();
				tWord=listElement.substr(0,fWord.length);

				if (tWord==fWord) return mPos;
				if (mPos<=0 || mPos>=listBox.options.length) return -1;
				
				if (fWord<tWord) return binaryFind(listBox,fWord,mPos+1,ePos);
				else return binaryFind(listBox,fWord,sPos,mPos-1);
			}
		</script>
