<?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');
   require('includes/functions/events_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'] : '');
   $events_id=(isset($HTTP_GET_VARS['events_id'])?(int)$HTTP_GET_VARS['events_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);
  $events_array=tep_get_events_array_single();
  $event_found=true;
  if (sizeof($events_array)<=0){
    $event_found=false;
  }else {
	if ($select_id!=0 && $select_id!=$events_id){
		$events_id=$select_id;
		}
	else if ($select_id==0 && $events_id==0){
		$events_id=$events_array[0]['id']; }
 }  
	$event_query=tep_db_query("SELECT events_fees from " . TABLE_EVENTS ." where events_id='" . $events_id . "'");
	if (tep_db_num_rows($event_query)<=0)
		//$event_found=false;
  
  $event_result=tep_db_fetch_array($event_query);
  
  
   if($action!=""){
   	  if($action=='get_details'){
   	  	  echo_get_details();
   	  }else if($action=='page_navigation'){
   	  		echo $action;
   	  		table_write();
   	  }else if($action=='edit'){
		    $cnt=0;
			//echo "SELECT * from " . TABLE_EVENTS_DISCOUNTS . " where discount_id='" . $discount_id ."'  order by discount_start_date";
			$discount_query = tep_db_query("SELECT * from " . TABLE_EVENTS_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="left">
			  
			  <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_event.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 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_event.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>
						</tr>
						<tr>
						    <td width="15%"></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; ?></td>
							<td class="main" valign=center>
							<?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(); 

				$sql_array=array('discount_start_date'=>$start_date,
						'discount_end_date'=>$end_date,
						'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_EVENTS_DISCOUNTS,$sql_array,'update',"discount_id='" . $update_id . "'");
		}
		  
			/*if ($dsID>0 && $action=='edit'){
			//echo "SELECT * from " . TABLE_EVENTS_DISCOUNTS . " where  discount_id='" . $dsID . "'";
				$discount_query=tep_db_query("SELECT * from " . TABLE_EVENTS_DISCOUNTS . " where  discount_id='" . $dsID . "'");
				if ($discount_result=tep_db_fetch_array($discount_query)){
					$discount=new objectInfo($discount_result);
				}
			}*/
		}	
		else  if($HTTP_POST_VARS['action_type']=='new'){
		$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'])),
						'events_id'=>$events_id,
						'discount_value'=>tep_db_prepare_input($HTTP_POST_VARS['discount_value']),
						'discount_type'=>tep_db_prepare_input($HTTP_POST_VARS['discount_type']));
		
		//print_r($sql_data_array);
		tep_db_perform(TABLE_EVENTS_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_EVENTS_DISCOUNTS . " where  discount_id='" . $HTTP_POST_VARS['dsID'] . "'");
	    echo 'delete_success';	     
	 }
   	 exit;
   }        
   function echo_get_details(){
  	 global $discount_id,$events_id;	
  		$discount_query = tep_db_query("SELECT * from " . TABLE_EVENTS_DISCOUNTS . " where discount_id='" . $discount_id ."'  order by discount_start_date");
		//if(tep_db_num_rows($discount_query)>0){
			$lang_class=tep_db_fetch_array($discount_query);
			$str_vals.=$lang_class['discount_id']."||".format_date($lang_class['discount_start_date'])."||".format_date($lang_class['discount_end_date'])."||".$lang_class['discount_value']."||".$lang_class['discount_type']."||".$lang_class['events_id'];
		//}else $str_vals="No Record Found";	
		//}
		echo 'get_details'.$str_vals;
  } 
   function table_write(){
    global $page,$events_id,$HTTP_GET_VARS;	
	 //print_r($HTTP_GET_VARS);
   ?>
   	 
  	<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="100" nowrap="nowrap"><b><?php echo TEXT_DISCOUNT_SDATE; ?></b></td>
               		 <td class="main" align="center" width="100"><b><?php echo TEXT_DISCOUNT_EDATE; ?></b></td>
					 <td class="main" align="center" width="150"><b><?php echo TEXT_DISCOUNT_VALUE; ?></b></td>
					 <td class="main" align="center" width="200"><b><?php echo TEXT_DISCOUNT_TYPE; ?></b></td>
               	 </tr>
	<?php   
	if($events_id==-1){
	$discount_query_raw = "SELECT * from " . TABLE_EVENTS_DISCOUNTS . " order by discount_start_date";
	
	 //echo 'No Events Found to display';
	}else{
	$discount_query_raw = "SELECT * from " . TABLE_EVENTS_DISCOUNTS . "  where events_id='" . $events_id ."'  order by discount_start_date";
	}
	
 		   // $discount_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $discount_query_raw, $dis_query_numrows);
 		    $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"; 
			   ?>  			      
		   	  <td colspan="4" width="100%" >
		   	  	<div id="data_<?php echo $discount['discount_id'];?>">
		   	  	 <table border="0" cellspacing="0" cellpadding="0" width="100%">
		   	  		<tr>
                   <td class="dataTableContent" width="100" align="center"  nowrap="nowrap" id="lname_<?php echo $discount['discount_id'];?>"><?php echo format_date($discount['discount_start_date']); ?></td>
             	   <td  class="dataTableContent" width="100" align="center" nowrap="nowrap"><?php echo format_date($discount['discount_end_date']); ?></td>
				    <td class="dataTableContent" width="150"  align="center" nowrap="nowrap" ><?php echo $discount['discount_value']; ?></td>
					 <td  class="dataTableContent" width="200" 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="4" width="100%" align="center" id="no_discount"> No discount found </td></tr>
			 			';
			  ?>
			  
			  
			  <tr id="new_discount" style="display:none" class="openContent">
			<td colspan="5" class="openContent_top">	
				<table cellpadding="1" cellspacing="0" border="0" width="100%">
					<tr>
						<td class="inner_title"><?php echo 'New 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='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 $discount_split->display_count($dis_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page,TEXT_DISPLAY_NUMBER_OF_DISCOUNT); ?></td>
		    	 <td class="smallText" align="right"><?php //echo $discount_split->display_script_links($dis_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'expand_category(\'\'','\'\''); ?></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/event_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 $events_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";
			
					
	/*	if(lfrm.discount_start_date.value!=''){
		if(((lfrm.discount_start_date.value).indexOf("-")!=-1)){
			date_error=isValidDate(date_format(lfrm.discount_start_date.value,'','YYYY-mm-dd')); 
			} else{
			 date_error=false;	
				error_message=error_message+'<?php echo ERR_INVALID_START_DATE?>\n';
			 }
		}
			if(lfrm.discount_end_date.value!='') {
		if(((lfrm.discount_end_date.value).indexOf("-")!=-1)){
			date_error=isValidDate(date_format(lfrm.discount_end_date.value,'','YYYY-mm-dd'));
			} else{
				error_message=error_message+'<?php echo ERR_INVALID_END_DATE?>\n';
			 date_error=false;	
			 }
			} */
			
		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';
		
			/*
			
			validations
			 */
													   	       		  
	 	 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_EVENTS_DISCOUNTS,'action=update');?>"+ids+"&events_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 + "&events_id="+selected;
			command="<?php echo tep_href_link(FILENAME_EVENTS_DISCOUNTS,'action=delete_confirm');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
     }
	do_post_command('select_event',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_event;
		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_EVENTS_DISCOUNTS,'action=page_navigation');?>"+page+"&events_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_EVENTS_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_EVENTS_DISCOUNTS,'action=get_details');?>&discount_id="+id+"&events_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_EVENTS_DISCOUNTS,'action=edit');?>&discount_id="+id+"&events_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_EVENTS_DISCOUNTS,'action=delete');?>&discount_id="+id+"&events_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_EVENTS_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_event;
   	  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_event;
		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 events_id=""; 		  	 		
 	 		var start_date="";
			var end_date="";
			var discount_value="";
			var discount_type="";
			
			
 	 		discount_id=splt_str[0]; 	 	
 	 		start_date=splt_str[1];
 	 		end_date=splt_str[2]; 	 
			discount_value=splt_str[3]; 
			discount_type=splt_str[4]; 
			events_id=splt_str[5]; 
			
			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="100" align="center" id="lname_'+discount_id+'" >'+start_date+'</td>'+
									'<td class="dataTableContent" width="100" align="center">'+end_date+'</td>'+
									'<td class="dataTableContent" width="150" align="center">'+discount_value+'</td>'+
									'<td class="dataTableContent" width="200" 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='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 >"+				  							  			
				  				"<table width='100%' border='0' cellspacing='0' cellpadding='2' class='main' align='center'>"+
								"<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>"+
										
										
										"<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>";
						 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_EVENT;?>";
 	    	 	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_EVENTS_DISCOUNTS,'action=page_navigation');?>&page="+len+"&events_id="+selected;
					//alert(command +"&events_id="+selected);
					do_get_command(command);
 	    	} 	    	 			 			 			
 	 	break;	
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
			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_EVENTS_DISCOUNTS,'action=page_navigation');?>&page="+len+"&events_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_event;
	  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;			   
			}
	  if(document.getElementById('no_discount'))
			document.getElementById('no_discount').style.display='none';
	  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'; 
	  
	
	 document.getElementById('span_new').innerHTML='<table border="0" cellpadding="2" cellspacing="2" width="100%" align="center" class="openContent"><tr><td ></td></tr><tr><td colspan="5" align="right" class="main"> '+
	 '  <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">' +
	'&nbsp;&nbsp;<?php echo tep_draw_input_field("discount_start_date",'',"size=10",false,'text',false); ?> &nbsp;&nbsp;' + 
	 '<a href="javascript:show_calendar(\'select_event.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 $_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> '+
	'&nbsp;&nbsp;<?php echo tep_draw_input_field("discount_end_date",'',"size=10",false,'text',false); ?>&nbsp;&nbsp;'+
	 '<a href="javascript:show_calendar(\'select_event.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>' +
	'<tr><td width="15%"></td><td align="left" class="main"><?php echo TEXT_DISCOUNT_VALUE; ?></td><td class="main">&nbsp;&nbsp;<?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">&nbsp;&nbsp;<?php echo tep_draw_radio_field('discount_type','A','') . '&nbsp;' . TEXT_TYPE_AMOUNT . '&nbsp;'; ?>' +  
	'&nbsp;&nbsp;<?php echo tep_draw_radio_field('discount_type','P','') . '&nbsp;' . TEXT_TYPE_PERCENTAGE  . '&nbsp;'; ?></td></tr><tr><td ></td></tr><tr><td>&nbsp;</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('no_discount'))
			document.getElementById('no_discount').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_event.select_id.options[document.select_event.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_event',FILENAME_EVENTS_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($events_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 Events</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="event_list"  style="position:absolute;left:247px;top:175px;display:none;width:400px;">
						<?php echo tep_draw_event_select_menu('select_id',$events_array,$events_id,'size=10 onClick="javascript:setListboxText(0);toggleList(0);document.select_event.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_EVENT;?></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($events_id==-1){?>
			<td class="pageHeading" nowrap="nowrap"><?php echo sprintf(TEXT_HEADING_TITLE,'All Events'); } else{ ?></td>  
			
			
				<td class="pageHeading" nowrap="nowrap"><?php echo sprintf(TEXT_HEADING_TITLE,tep_get_events_name($events_id)); }?></td>  
			</tr>
			<tr><td><?php echo tep_draw_separator('pixel_trans.gif','1','10'); ?></td></tr>
	  	</table>
		</td></tr>
                 <tr>
                	  <td colspan="4" 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="events_id" id="events_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>
		<script language="JavaScript">
					if(na6) document.select_event.select_text.addEventListener("keyup",selectList,true);
					if(iex) document.select_event.select_text.onkeyup=selectList;
					if(na6) document.select_event.select_text.addEventListener("keydown",scrollList,true);
					if(iex) document.select_event.select_text.onkeydown=scrollList;
				</script>
				<script language="JavaScript">
		function resize(){
			document.getElementById('event_list').style.visibility="hidden";
			document.select_event.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("event_list");
				var textbox=document.select_event.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+115;
				}*/
				/*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+106;
			   */
				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+133;
			}
			function hideList(){
				var listbox=document.getElementById("event_list");
				var textbox=document.select_event.select_text;
				setListboxText(1);
				listbox.style.display="none";
			}
			function scrollList(e){
				var listbox=document.select_event.select_id;

				if (iex) keyCode=window.event.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.event.returnValue=0;
					if (na6) e.returnValue=0;
					return;

				}
			}
			function selectList(e){
				var listbox=document.select_event.select_id;
				var search_word=document.select_event.select_text.value;
				var text_length;
				var found=-1;
				var listbox_word;
				var eventObject;
				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_event.select_id;
				if (!listbox.options || listbox.options.length<=0 || listbox.selectedIndex<=-1) return;
				var textbox_name=document.select_event.select_text;
				if (textbox_name.value=="" && mode==1) return "";
				textbox_name.value=listbox.options[listbox.selectedIndex].innerHTML;
				//document.select_event.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;
				alert ('hi');
				if (fWord<tWord) return binaryFind(listBox,fWord,mPos+1,ePos);
				else return binaryFind(listBox,fWord,sPos,mPos-1);
			}
		</script>
        </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>