<?php
/*
  osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License 

*/  
// Set flag that this is a parent file
	define( '_FEXEC', 1 ); 
  require('includes/application_top.php');
  set_time_limit(0);
  require(DIR_WS_FUNCTIONS . 'events_sessions.php');
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
  // get getvars and postvars values
  	$event_id=(int)$HTTP_GET_VARS['eID'];
  	$session_id=(int)$HTTP_GET_VARS['sID'];
  	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  	$actions=isset($HTTP_POST_VARS['actions'])?$HTTP_POST_VARS['actions']:'';
  // get getvars and postvars values
  //action starts here
  switch($actions){
  case 'update_session'://update the given session
  $action=$actions;
  $insert_error="";
  $insert_array=array();
  $select_event_id=(isset($HTTP_POST_VARS['event_selected'])) ? (int)tep_db_prepare_input($HTTP_POST_VARS['event_selected']):$event_id;
  $select_session_type=tep_db_prepare_input($HTTP_POST_VARS['select_session_type']);
  $sessions_start_date = tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['sessions_start_date']));
	if ($select_session_type=='R') {
		$sessions_end_date = tep_db_prepare_input($HTTP_POST_VARS['sessions_end_date']);
		if ($HTTP_POST_VARS['weekly_check']=='Y'){
			$HTTP_POST_VARS['sessions_type_option']='WW';
			$weekdays=array('1'=>'0','2'=>'0','3'=>'0','4'=>'0','5'=>'0','6'=>'0','7'=>'0');
			$weekselected=$HTTP_POST_VARS['sessions_type_weekly_days'];
			for($i=0,$n=sizeof($weekselected);$i<$n;$i++)
				$weekdays[$weekselected[$i]]='1';
			$weekstring=implode('',$weekdays);
			$insert_array=array('sessions_type_weekly_weeks'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_weekly_weeks']),
								'sessions_type_weekly_days'=>$weekstring);
		}
		$sessions_end_date=tep_convert_date_raw($sessions_end_date);
		if ($sessions_start_date=='' || $sessions_end_date==''){
			$insert_error=TEXT_ERR_EMPTY_DATES;
			$action='new_session';
			break;
		}
		if ($sessions_start_date>$sessions_end_date){
			$insert_error=TEXT_ERR_DATE_INVERT;
			$action='new_session';
			break;
		}
		if (tep_check_dates_collide($sessions_start_date,$sessions_end_date,$session_id,$select_event_id)){
			$insert_error=TEXT_ERR_DATES_COLLIDE;					
			$action='new_session';
			break;
		}
		if($HTTP_POST_VARS['daily_check']=='Y')  $HTTP_POST_VARS['sessions_type_option']='DD';
				$sql_data_array = array('events_id' => $select_event_id,
										'sessions_type'=> 'R',
										'sessions_start_date' => $sessions_start_date,
										'sessions_end_date' => $sessions_end_date,
										'sessions_type_option' => tep_db_prepare_input($HTTP_POST_VARS['sessions_type_option']));		  		
				if ($HTTP_POST_VARS['daily_check']=='Y') 
					$insert_array=array('sessions_type_daily_days'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_daily_days']));
				elseif ($HTTP_POST_VARS['sessions_type_option']=='MD') 
					$insert_array=array('sessions_type_monthly_days'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_monthly_days']),
										'sessions_type_monthly_months'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_monthly_months']));
				elseif ($HTTP_POST_VARS['sessions_type_option']=='MM') 
					$insert_array=array('sessions_type_monthly_weeks'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_monthly_weeks']),
										'sessions_type_monthly_weekdays'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_monthly_weekdays']),
										'sessions_type_monthly_weekmonths'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_monthly_weekmonths']));
				elseif ($HTTP_POST_VARS['sessions_type_option']=='YM') 
					$insert_array=array('sessions_type_yearly_months'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_yearly_months']),
										'sessions_type_yearly_monthdays'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_yearly_monthdays']));
				elseif ($HTTP_POST_VARS['sessions_type_option']=='YY') 
					$insert_array=array('sessions_type_yearly_weeks'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_yearly_weeks']),
										'sessions_type_yearly_weekdays'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_yearly_weekdays']),
										'sessions_type_yearly_weekmonths'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_type_yearly_weekmonths']));
				$sql_data_array = array_merge($sql_data_array, $insert_array);
				if ($action=='update_session'){
					$insert_error=tep_change_event_valid($select_event_id,$event_id);
					if($insert_error!="") $action='new_session';
				}
				if ($action == 'update_session') tep_delete_multiple_sessions($session_id);
				if (!$HTTP_GET_VARS['sID']) {
					tep_db_perform(TABLE_RECURSIVE_SESSIONS, $sql_data_array);
					$session_id=tep_db_insert_id();
				} elseif ($action == 'update_session') tep_db_perform(TABLE_RECURSIVE_SESSIONS, $sql_data_array, 'update', "recursive_sessions_id = '" . (int)$session_id . "'");
				$HTTP_POST_VARS['sessions_start_date']=tep_convert_date_raw($HTTP_POST_VARS['sessions_start_date']);
				$HTTP_POST_VARS['sessions_end_date']=tep_convert_date_raw($HTTP_POST_VARS['sessions_end_date']);
				$sInfo=new objectInfo($HTTP_POST_VARS);
				$sInfo->sessions_type_weekly_days=$weekstring;
				if($HTTP_POST_VARS['sessions_type_option']=='DD')
					$result_dates=date_range($HTTP_POST_VARS['sessions_start_date'],$HTTP_POST_VARS['sessions_end_date'],$sInfo->sessions_type_daily_days);
				else
					$result_dates=get_dates_array($sInfo,$HTTP_POST_VARS['sessions_type_option']);
				$value_data=""; $insert_flag=0;
				for($icnt=0;$icnt<sizeof($result_dates);$icnt++){
					$status="";
					$sql_data_array = array('events_id' => $select_event_id,
											'recursive_sessions_id'=>$session_id,
											'start_date' => $result_dates[$icnt],
											'sessions_type' => 'R');
					$status=tep_add_multiple_session($sql_data_array);
				}
				$sql_data_array=array('sessions_date_count'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_date_count']),
										'sessions_select_interval'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_select_interval']),
										'sessions_select_count'=>tep_db_prepare_input($HTTP_POST_VARS['sessions_select_count'])); 
				 tep_db_perform(TABLE_EVENTS,$sql_data_array,'update',"events_id='" . (int)$select_event_id . "'");				
			} else { 	
				if ($sessions_start_date==''){
					$insert_error=TEXT_ERR_START_DATE;
					$action='new_session';
					break;
				}
				$sql_data_array = array('events_id' => $select_event_id,
										'start_date' => $sessions_start_date,
										'sessions_type' => 'S');
				$insert_error=tep_change_event_valid($select_event_id,$event_id);
				if ($insert_error!='') $action='new_session';			
				if (!$HTTP_GET_VARS['sID']){
					tep_add_single_session($sql_data_array);
					$session_id=tep_db_insert_id();
				}else if ($HTTP_GET_VARS['sID']) tep_db_perform(TABLE_EVENTS_SESSIONS, $sql_data_array, 'update', "sessions_id = '" . (int)$session_id . "'");
	     }
		if ($insert_error==''){
			tep_set_event_limit_dates($event_id);
		}
  }
  $session_type=tep_get_session_type($event_id);
  if (tep_not_null($action)&& $action!='update_session' && $action!='new_session') {
     switch ($action) {
	  case 'edit_session':
	  	if(!$HTTP_GET_VARS['sID'] ) echo 'new^';
		if($HTTP_GET_VARS['sID']>0) echo 'edit^';
	  	session_new_edit();
	  break;
	  case 'search':
	  case 'reset':
		echo 'search^';
		table_write();
   	  break;
  	  case 'get_details':
  	 	echo_get_details();
  	  break;
      // delete session after deletion
      case 'delete_confirm':
		$delete_id=(int)$HTTP_GET_VARS['sID'];
        if ($delete_id!=0) {
		    if ($session_type=='R'){
		       tep_delete_recursive_session($delete_id);
	    	   tep_delete_multiple_sessions($delete_id);
		    } else tep_delete_single_session($delete_id);	    	        
			tep_set_event_limit_dates($event_id);
			echo 'delete_success^';
		}
      break;
    }
    exit;
  }
  function echo_get_details(){
  	 global $event_id,$HTTP_POST_VARS,$session_type,$session_id;
  	if ($session_type=='R')
        $session_query=tep_db_query("SELECT r.recursive_sessions_id as sessions_id, date_format(r.sessions_start_date, '%Y-%m-%d') as min_date,date_format(r.sessions_end_date, '%Y-%m-%d') as max_date,r.sessions_type from " . TABLE_RECURSIVE_SESSIONS . " r where r.recursive_sessions_id=" . (int)$session_id . " and r.events_id='".(int)$event_id."' order by r.sessions_start_date");        		
    else
        $session_query=tep_db_query("SELECT s.sessions_id,min(date_format(s.start_date,'%Y-%m-%d')) as min_date,max(date_format(s.start_date,'%Y-%m-%d')) as max_date,s.sessions_type from " . TABLE_EVENTS_SESSIONS . " s where s.sessions_id=" . (int)$session_id . " and s.events_id='".(int)$event_id."' and  s.sessions_type='S' group by s.events_id");
                  	
		if(tep_db_num_rows($session_query)>0){
			$session=tep_db_fetch_array($session_query);
			while(list($key,$vals)=each($session)){
			 	if($key=='sessions_type'){
			 		if($vals=='R') $vals=TEXT_TYPE_RECURSIVE;
					else $vals=TEXT_TYPE_SINGLE;
			 	}
				if($key=='min_date' || $key=='max_date') $vals = format_date($vals);
				$str_vals.=$vals."{}";
			}
	    }else $str_vals="No Record Found";
		echo (($HTTP_POST_VARS['action_type'] == 'new') ? '' : 'get_details^') . $str_vals;
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var event_id="<?php echo $event_id;?>";
  if(document.getElementById("action_type")) var action_type=document.getElementById("action_type").value;
  /*
      var error_result="";
      if(document.getElementById("action_type")) var action_type=document.getElementById("action_type").value;
	  if(document.getElementById("location_id")) id=document.getElementById("location_id").value;
	  var span_details=document.getElementById("span_details");
	  var span_edit=document.getElementById("span_edit");				
	  var span_delete=document.getElementById("span_delete");
	  var loadings=document.getElementById("loading");
	  var ids="";	  	
	  if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){		  		  
			  if (document.getElementById("service_location_name").value=="") 
				   error_result+="<?php echo tep_output_string(ERR_EMPTY_LOCATION_NAME); ?>\n";		      
			  if (document.getElementById("service_location_seats").value=="" || document.getElementById("service_location_seats").value<=0) 
				   error_result+="<?php echo tep_output_string(ERR_INVALID_LOCATION_SEATS); ?>\n";		       		  
			  if (document.getElementById("service_location_equipment") && document.getElementById("service_location_equipment").selectedIndex<=0)
				   error_result+="<?php echo tep_output_string(ERR_EMPTY_EQUIPMENT_NAME); ?>\n";		  	  
      if (error_result!=""){
         alert(error_result);
	 	 return false;
      }else if(span_edit && span_edit.style.display=="" || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){      							
			if(action_type=='edit')  ids="&lID="+id;
			command="<?php echo tep_href_link(FILENAME_SERVICES_LOCATIONS,'action=update_location');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_edit) span_edit.style.display="none";
			if(document.getElementById("new_create")){ document.getElementById("new_create").style.display="none";
			document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
			display_flag=1;
			}
      }
	}else if(span_delete.style.display==""){      							
			ids="&sID="+id;
			command="<?php echo tep_href_link(FILENAME_SERVICES_LOCATIONS,'action=delete_confirm');?>"+ids;
			if(loadings) loadings.style.display="";			
     }
	do_post_command('service_location_detail',command);	
    return false;
   */

var mPath='<?php echo $HTTP_GET_VARS['mPath']; ?>'; 
var cPath='<?php echo $HTTP_GET_VARS['cPath']; ?>';
var eID='<?php echo $HTTP_GET_VARS['eID']; ?>';
 
  function ValidateForm(){
     var session_option;
     var submit_result;
     var error_result;
     var icnt;
	 var sdate;
	 var edate;
     error_result="";
     var session_type;
     if(document.getElementById("action_type")) var action_type=document.getElementById("action_type").value;
	  if(document.getElementById("session_id")) id=document.getElementById("session_id").value;
	 var ids="&eID="+event_id;
  if(action_type!='delete'){	 	 
   while(true){
    if(document.sessions.sessions_start_date && document.sessions.sessions_start_date.value==""){
    	error_result="<?php echo tep_db_input(TEXT_ERR_START_DATE_EMPTY); ?>";
		break;
    }
    if(document.sessions.sessions_end_date && document.sessions.sessions_end_date.value==""){
    	error_result="<?php echo tep_db_input(TEXT_ERR_END_DATE_EMPTY); ?>";
		break;
    }
    if (document.sessions.event_selected.selectedIndex<0){
        error_result="<?php echo tep_db_input(TEXT_ERR_SELECT_EVENT); ?>";
		break;
	}
	if(document.sessions.sessions_start_date)
		sdate=date_format(document.sessions.sessions_start_date.value,'<?php echo EVENTS_DATE_FORMAT;?>','Y-m-d');
	if(document.sessions.sessions_end_date	)
		edate=date_format(document.sessions.sessions_end_date.value,'<?php echo EVENTS_DATE_FORMAT;?>','Y-m-d');
		
	if(document.sessions.sessions_start_date && document.sessions.sessions_end_date && (sdate > edate)){
		error_result="<?php echo tep_db_input(TEXT_ERR_DATE_INVERT); ?>";
		break;
	}
     if (document.sessions.session_type_count && document.sessions.session_type_count.value==1){
         if (document.sessions.select_session_type.checked==false){
	         error_result="<?php echo tep_db_input(TEXT_ERR_NO_TYPE_OPTION); ?>";
             break;
         }
		session_type=document.sessions.select_session_type.value;
      }else{
         if (document.sessions.select_session_type && document.sessions.select_session_type[0] && document.sessions.select_session_type[0].checked==false && document.sessions.select_session_type[1] && document.sessions.select_session_type[1].checked==false){
            error_result="<?php echo tep_db_input(TEXT_ERR_NO_TYPE_OPTION); ?>";
            break;	
         }
	 if (document.sessions.select_session_type && document.sessions.select_session_type[0] && document.sessions.select_session_type[0].checked==true)
	    session_type=document.sessions.select_session_type[0].value;
	 else if(document.sessions.select_session_type && document.sessions.select_session_type[1])
	    session_type=document.sessions.select_session_type[1].value;
     }

     if (session_type!="R") break;
        if (isNaN(parseInt(document.sessions.sessions_date_count.value))==true){
	    	error_result="<?php echo tep_db_input(TEXT_ERR_DATE_COUNT); ?>";
	    	break;
	    }
        if (parseInt(document.sessions.sessions_date_count.value)<=0){
 	    	error_result="<?php echo tep_db_input(TEXT_ERR_DATE_COUNT_VALUE); ?>";
 	    	break;
 	    }	    
        if (isNaN(parseInt(document.sessions.sessions_select_interval.value))==true){
	    	error_result="<?php echo tep_db_input(TEXT_ERR_SELECT_INTERVAL); ?>";
	    	break;
	    }
        if (parseInt(document.sessions.sessions_select_interval.value)<=0){
 	    	error_result="<?php echo tep_db_input(TEXT_ERR_SELECT_INTERVAL_VALUE); ?>";
 	    	break;
 	    }

        if (isNaN(parseInt(document.sessions.sessions_select_count.value))==true){
	    	error_result="<?php echo tep_db_input(TEXT_ERR_SELECT_COUNT); ?>";
	    	break;
	    }
        if (parseInt(document.sessions.sessions_select_count.value)<=0){
 	    	error_result="<?php echo tep_db_input(TEXT_ERR_SELECT_COUNT_VALUE); ?>";
 	    	break;
 	    }

	 for(icnt=0;icnt<document.sessions.sessions_type_option.length;icnt++){
	    if (document.sessions.sessions_type_option[icnt].checked==true){
	     session_option=document.sessions.sessions_type_option[icnt].value;
	     break;}}
	 if (session_option==""){
	    error_result="<?php echo tep_db_input(TEXT_ERR_NO_RECURSIVE_OPTION); ?>";
	    break;}
	 if (document.getElementById("daily_check") && document.getElementById("daily_check").checked){
	    if (isNaN(parseInt(document.sessions.sessions_type_daily_days.value))==true){
	      error_result="<?php echo tep_db_input(TEXT_ERR_DAILY_DAYS); ?>";break;}
	 }
	 if (document.getElementById("weekly_check") && document.getElementById("weekly_check").checked){
	    if (isNaN(parseInt(document.sessions.sessions_type_weekly_weeks.value))==true){
	      error_result="<?php echo tep_db_input(TEXT_ERR_WEEKLY_WEEKS); ?>";break;}
	    for(icnt=0;icnt<document.getElementsByName("sessions_type_weekly_days[]").length;icnt++){
	       if (document.getElementsByName("sessions_type_weekly_days[]")[icnt].checked==true) break;
	    }
	    if (icnt>=document.getElementsByName("sessions_type_weekly_days[]").length)
	       error_result="<?php echo tep_db_input(TEXT_ERR_WEEKLY_DAYS); ?>";
	       break;
	 }
	 if (session_option=="MD"){
	    if (isNaN(parseInt(document.sessions.sessions_type_monthly_days.value))==true){
	      error_result="<?php echo tep_db_input(TEXT_ERR_MONTHLY_DAYS); ?>";break;}
	    if (isNaN(parseInt(document.sessions.sessions_type_monthly_months.value))==true){
	      error_result="<?php echo tep_db_input(TEXT_ERR_MONTHLY_MONTHS); ?>";break;}
	 }
	 if (session_option=="MM"){
	    if (isNaN(parseInt(document.sessions.sessions_type_monthly_weekmonths.value))==true){
	      error_result="<?php echo tep_db_input(TEXT_ERR_MONTHLY_WEEKMONTHS); ?>";break;}
         }
	 if (session_option=="YM"){
	    if (isNaN(parseInt(document.sessions.sessions_type_yearly_monthdays.value))==true){
	      error_result="<?php echo tep_db_input(TEXT_ERR_YEARLY_MONTHDAYS); ?>";break;}
         }
    break;
    }
  }
  if (error_result!=""){
        alert(error_result);
        return false;
  }else if(document.getElementById("new_create") && document.getElementById("new_create").style.display==""){      							
		if(action_type=='edit')  ids+="&sID="+id;
		command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=update_session');?>"+ids;
		
		if(document.getElementById("new_create")){ document.getElementById("new_create").style.display="none";
			document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
			display_flag=1;
		}     
		document.sessions.actions.value="update_session";
		document.sessions.action="<?php echo tep_href_link(FILENAME_SESSIONS,'mPath=') ?>"+mPath+"&cPath="+cPath+"&eID="+eID;
		if(action_type=='edit')
			document.sessions.action="<?php echo tep_href_link(FILENAME_SESSIONS,'mPath=') ?>"+mPath+"&cPath="+cPath+"&eID="+eID+"&sID="+id;;
		return true;
  }else if(action_type=='edit'){ 
		ids+="&sID="+id;
		document.sessions.actions.value="update_session";
		command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=update_session');?>"+ids;
		document.sessions.action="<?php echo tep_href_link(FILENAME_SESSIONS,'mPath=') ?>"+mPath+"&cPath="+cPath+"&eID="+eID+"&sID="+id;
		return true;
		if(document.getElementById('image_type')) document.getElementById('image_type').value="true";
  }else if(action_type=="delete"){      							
		ids+="&sID="+id+"&eID="+event_id;
		command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=delete_confirm');?>"+ids;
  }
	document.getElementById('loading').style.display='';
	document.getElementById('span_details').style.display='none';
    do_post_command('sessions',command);	
    return false;     
  }
  var previous_id='';
 function expand_category(id,category,r_type,sta_type){ 
  	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("new_create").innerHTML="";
	}
	if(document.getElementById("image_type")) document.getElementById("image_type").value='';		
	var res_display=document.getElementById("res_display");
	var frm=document.sessions;
	if(document.sessions && document.sessions.session_id){
			var old_ids=document.sessions.session_id.value;			
			var pre_data_id=document.getElementById("data_"+old_ids);
			var pre_head=document.getElementById("head_"+old_ids);
			var loadings=document.getElementById("loading");
			if(loadings) loadings.style.display="none";
			if(category==1 && pre_head && pre_head.innerHTML!='') pre_head.innerHTML="";									
	}
	if(id==0 && category==1){
		if((r_type=='') && category==1 && document.getElementById("new_create").style.display==""){	 	 		
		  document.getElementById("new_create").style.display="none";
		return;		
	}
	}if(category==2 && id==0 && frm && frm.session_id.value>0 && document.getElementById("head_"+frm.session_id.value) && document.getElementById("data_"+frm.session_id.value)){
			if(span_details) span_details.innerHTML="";
			document.getElementById("head_"+frm.session_id.value).style.display="none";
			document.getElementById("data_"+frm.session_id.value).style.display="";
 	}
	if(id>0 && document.sessions && document.sessions.session_id && document.sessions.session_id.value=="") document.sessions.session_id.value=id;
		if(id>0 && document.sessions.session_id.value>0 && document.sessions.session_id.value!=id){
			var head=document.getElementById("head_"+id);
			if(head && head.style.display=="") head.style.display="none";
			if(category!=12 &&  category!=13 && pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";
			document.sessions.session_id.value=id;
		}		
 	 	if(category){
 	 		var span_details=document.getElementById("span_details");
			var data_id=document.getElementById("data_"+id);
			var head=document.getElementById("head_"+id);
			var action_type=document.getElementById("action_type");
			var img_save=document.getElementById("img_save");
			var img_new=document.getElementById("img_new");
			document.getElementById("back").style.display="";
			var command="";
 	 		switch(category){
 	 			case 1:
			 	  var ser="";
 	 			  var page=""; 	 
 	 			  if(r_type=='search' || r_type=='reset'){ 
					  if(document.getElementById("search_date") && document.getElementById("search_date").value!="" && r_type=='search' || r_type=='reset') {
						command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=search&eID='.$event_id);?>";
							if(r_type=='reset') { 
								if(document.getElementById("search_date")) document.getElementById("search_date").value='';
							command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=reset&eID='.$event_id);?>";
							}if(document.getElementById("ajax_details")) document.getElementById("ajax_details").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
				  	  }else return false;
				  }   
				break; 
 	 			case 2:
					 if(span_details) span_details.style.display="none";
 	 				 if(id){
					 	 if(frm.action_type) frm.action_type.value='edit';
						 if(document.getElementById("new_create")) document.getElementById("new_create").innerHTML="";
						 // document.getElementById("new_create").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
						 command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=edit_session');?>&sID="+id+"&eID="+event_id;
					 }else {
						 if(frm.action_type) frm.action_type.value='new';
						 document.getElementById("new_create").style.display="";
						 if(document.getElementById("span_details")) document.getElementById("span_details").innerHTML="";
						 document.getElementById("new_create").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
						 command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=edit_session');?>&eID="+event_id; 
					 }
 	 			break; 	 			
				case 3:
					if(document.getElementById('image_type')) document.getElementById('image_type').value="true";
					var tr1=document.getElementById("img_ids");
					var imgsrc;
					var node;
					if(tr1)
					for(var j=0;j<tr1.cells.length;j++){
						td=tr1.cells[j];
						imgsrc='';
						for(var i=0;i<td.childNodes.length;i++){
							node=td.childNodes[i];
							if(node.tagName=='IMG'){
								imgsrc=node.src;
								if(imgsrc==img_src+'template/img_edit_hover.gif')
								   td.childNodes[i].src = img_src+'template/img_edit.gif';
								else if(imgsrc==img_src+'template/img_trash_hover.gif')
								   td.childNodes[i].src = img_src+'template/img_trash.gif';
								break;
							}
						}
					}
				  if(document.getElementById("new_create")){ document.getElementById("new_create").style.display="none"; 	 			   
				    document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
					display_flag=1;
				  }

				 if(head && head.style.display==""){
 	 			   	  if(span_details.style.display==""){
 	 			   	    head.style.display="none"; 	 			   	    
 	 			   	  	data_id.style.display=""; 	 			   	  	
 	 			   	  }else { 	 			   	  	 	 			   	  	 	 			   	  	
 	 			   	  	span_details.style.display="";
 	 			   	  	if(img_save) img_save.style.display="none"; 
 	 			   	  }	 	 			    			   	   	 			   
 	 			 }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_SESSIONS,'action=get_details');?>&sID="+id+"&eID=<?php echo $event_id;?>";					 			 	
					previous_id=id;						
 	 			 }
				break;
 	 			case 6:
 	 					if(action_type) action_type.value='new'; 	 					
 						command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=edit_product');?>&eID="+id; 	
						document.getElementById('loading').style.display=''; 	 	 					 	 			
 	 			break;
 	 			case 7:
 	 					if(action_type) action_type.value='edit';
 	 					command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=edit_product');?>&eID="+id; 	 	 	 					 	 			
 	 			break;
 	 			case 8:
 	 					if(action_type) action_type.value='delete'; 	 					
 	 					span_details.style.display="";			 	 		 	 				
 	 					span_details.innerHTML='<table border="0" cellspacing="2" cellpadding="1" width="100%"><tr><td width="17" align="center"><?php echo tep_image('images/template/img_trash.gif')?></td>'+
											  '<td width="500" align="left" class="inner_title"><?php echo TEXT_INFO_HEADING_DELETE_SESSION;?></td></tr>'+
											  '<tr><td></td><td width="500" align="left" class="main"><?php echo TEXT_DELETE_SESSION_INTRO;?></td></tr>'+											  				      					       
											  '<tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif',50,10);?></td></tr></table>'; 	 					
 	 					if(img_save) img_save.style.display="";
 	 			break;
 	 		}
 	 		if(r_type=='search') {
			document.getElementById("back").style.display="none";
 	 			do_post_command('search',command);
 	 			return false;
 	 		}else if(command!="") do_get_command(command);
 	 	}
	  }
	  function print_details(category,result){
 	 	var no_result="";
 	 	if(result.substr(0,15)=='No Record Found'){
 	 		no_result="No Record Found";
 	 	}else if(result!='' && result.length>0 && category!='edit' && result.substr(0,15)!='No Record Found'){
			splt_str=result.split("{}");
 	 		var  session_id="";
			var  session_date="";
			var  session_type="";
																
 	 		session_id=splt_str[0];			
			session_date=splt_str[1] + '&nbsp; to &nbsp;'+ splt_str[2];
			session_type=splt_str[3];
 	 	}
 		if(document.sessions && document.sessions.session_id) var id=document.sessions.session_id.value;
 		var span_details=document.getElementById("span_details");
 		var head=document.getElementById("head_"+id);
 		var data_id=document.getElementById("data_"+id);
 		var res_display=document.getElementById("res_display");
		var img_save=document.getElementById("img_save");
 	 	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="45%"><img src="images/icons/preview.gif" alt="Preview" title=" Preview " border="0">&nbsp;'+session_date+'</td>'+
                					'<td class="dataTableContent" align="center">'+session_type+'</td>'+
						         '</tr>'+
						      '</tbody></table>';	
	 	 		}
				head.innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0' class='openContent'>"+
				"<tr heigth='40' class='openContent_top'>"+
				  "<td width='10'></td>"+				  
				  "<td align='left' valign='middle' width='350' class='main'></td>"+
				  "<td width='470' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='height:30px;display:inline;position:relative;'>"+
				  	 "<tr class='img_move' id='img_ids'>"+
						 "<td class='cell_bg_popm_left' width='10'>&nbsp;</td>"+
						 "<td width='10%' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);' onclick='javascript:change_class(this,1);expand_category("+session_id+",2);'><img alt='Edit session' title='Edit session' src='images/template/img_edit.gif'></td>"+
						 "<td width='10%' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);' onclick='javascript:change_class(this,1);expand_category("+session_id+",8);'><img alt='Delete session' title='Delete session' src='images/template/img_trash.gif'></td>"+
						 "<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
				  	 "</tr>"+
				  	"</table>"+
				  "</td>"+
				  "<td width='240' 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("+session_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 id='span_details'>"+
				  	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
				  			"<td width='50'>&nbsp;</td>"+
				  			"<td width='450' valign='top'>"+
				  				"<table width='450' border='0' cellspacing='5' cellpadding='0' class='main'>"+
				  					"<tr>"+
				  						"<td align='left' width='110' valign='top' class='main'><?php echo TEXT_SESSION_DATES;?>: </td>"+
				  						"<td align='left' width='290' valign='top' class='main'>"+session_date+"</td>"+
				  					"</tr>"+
				  					"<tr>"+
				  						"<td align='left' width='110' class='main'><?php echo TEXT_SESSION_TYPE;?>: </td>"+
				  						"<td align='left' width='290' class='main'>"+session_type+"</td>"+
				  					"</tr>"+	
				  				"</table>"+
				  			"</td>"+
				  		"</tr><tr><td colspan='8'><img src='images/pixel_trans.gif' border='0' alt='' width='100%' height='20'></td></tr>"+
				  	"</table></span>"+			  			  		
				  "</td>"+
			"</table>";			
 	 				
 	 		} 	 	
 	 	break;
		case 'edit':
		span_details.innerHTML = result;
		span_details.style.display='';
		document.getElementById("img_save").style.display='';
		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_SESSION_DELETED_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 }
 	 	break;				 	 	
		case 'new_session':									
 			command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=reset');?>&page=1&eID="+event_id;
			do_get_command(command);	
		break;
		case 'error':
			if(head) head.style.display="none";
			if(data_id) data_id.style.display="";
			if(res_display){
		    	res_display.innerHTML="<span class='errorText'>"+result+"</span>";
	 	    	res_display.style.display=""; 	    	 	
 			}				
		break;
		case 'delete_success':			 
 	    	 var len=1;
 	    	 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 				 			
			 }
			 if(res_display){
	    	 	res_display.innerHTML="<?php echo TEXT_SESSION_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 	var obj=document.getElementById("page_''");
 	    	 	if(obj) len=obj.options[obj.selectedIndex].value;
 	    	 	command="<?php echo tep_href_link(FILENAME_SESSIONS,'action=page_navigation');?>&page="+len;
				do_get_command(command); 	    	 	 	    	 
 	    	 } 	    	  	    	 			 			 			
 	 	break;
 	 	}
		if(res_display && res_display.style.display=="") setTimeout("res_display.style.display='none'",2000); 	 	 	 	
 	 	clearTimeout();		
	  }
   function do_result(result){
   	  var frm=document.sessions;
	  var splt="";
	  var res=result;
   	  if(result!=""){
	  	res_split=result.split("^");
	 	splt=res_split[0];
		res=res_split[1];
		if(splt=='get_details' && res=='No Record Found') splt='new_session'; 								
		print_details(splt,res);
		if(splt=='new' && document.getElementById("new_create"))
			document.getElementById("new_create").innerHTML=res;
		else if(splt=='search' && document.getElementById("ajax_details")) 
			document.getElementById("ajax_details").innerHTML=res;
		toggle_panel('Session_Intervals','false','','0');
		if(splt == 'new' || splt == 'edit') clear_intervals(res_split[2]);
   	  }
   }
  function change_class(obj,eve){ 		
		 	var action_type=""; 
			var img_get_src=obj.childNodes[0];					
		 	var img_type="";
			if(document.getElementById("action_type")) action_type=document.getElementById("action_type").value;		 			 		   		    		    
		    if(document.getElementById("image_type").value=='true'){
			action_type='';
			}			
			if(img_get_src){			    				 
				if(img_get_src.src==img_src+'template/img_edit.gif') { 
					if((action_type=="edit") && 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'){ 	
					if(action_type=="edit") return;
					else img_get_src.src=img_src+'template/img_edit.gif';
				}
				if(img_get_src.src==img_src+'template/img_trash.gif') {
					if((action_type=="delete") && 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'){ 				
					if(action_type=="delete") return;
					else img_get_src.src=img_src+'template/img_trash.gif';
				}				
		  }		 		 
	  }	
	  
  var display_flag=1;
  function do_hover_change(element,mode){ 
	if(display_flag==1){
		if (element.mode && mode==element.mode) return;
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
	}
	element.mode=mode;
	} 
	
</script>
<?php
	// WebMakers.com Added: Java Scripts
	include(DIR_WS_INCLUDES . 'javascript/' . 'webmakers_added_js.php');
	include(DIR_WS_INCLUDES . 'date_format_js.php');
?>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
	<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
	<table border="0" width="100%" cellspacing="2" cellpadding="3">
  	<tr> 
		<!-- body_text //-->
    <td width="100%" valign="top">		
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
          	<td align="right">
          	  <table border="0" width="100%" cellspacing="0" cellpadding="0">
               <tr class="dataTableHeadingRow">
                <td align="left"><a alt="New Session" title="New Session" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);" id="img_new" href="javascript:expand_category(0,2);"><?php echo tep_image('images/template/img_new.gif','New Session','22','22',' align="absmiddle"');?></a></td>
                <td>
				<?php echo tep_draw_form('search', FILENAME_SESSIONS, '', 'post','onsubmit="javascript:return expand_category(1,1,\'search\');"');?>
				   <table border="0" cellpadding="0" cellspacing="0" width="100%">					
					<tr>
					 <td class="smallText" align="right" valign="middle" style="color:#CC0000" align="absbottom">
						<?php // echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search').'&nbsp;';?><?php //echo tep_image('images/template/img_search.gif','Search','','',' align=absmiddle');?>
						<?php //echo tep_draw_form('search_form',FILENAME_SESSIONS,'','post',' onSubmit="javascript:return expand_category(1,1,\'search\');" ').'&nbsp;&nbsp;&nbsp;(<font color=#CC0000>Give Date in Y-M-D format</font>)' . '&nbsp;&nbsp;<font color=#000000>'.HEADING_TITLE_SEARCH.'</font>'.tep_draw_input_field('search').'&nbsp;';?>
						<?php //echo tep_draw_form('search_form',FILENAME_SESSIONS,'','post',' onSubmit="javascript:return expand_category(1,1,\'search\');"');?>
							
							<!--<table border="0" width="100%" cellpadding="0" cellspacing="0" align="right">
							<tr>
							<td valign="middle" align="right" width="100%">
							<table width="100%" border="0" cellpadding="0" cellspacing="0" align="right">
								
							<tr>
							<td align="right">
							
							<table border="0" cellpadding="0" cellspacing="0" width="85%">
							<tr><?php //$_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
								<td class="main" nowrap="nowrap" valign="middle" align="right"><?php //echo "Search &nbsp;"; ?><small><?php echo '(' . $date_format . ')&nbsp;'; ?></small></td>
								<td class="main" valign="middle" width="100px"><?php //echo tep_draw_input_field("sessions_start_date",(tep_not_null($sInfo->sessions_start_date)?format_date($sInfo->sessions_start_date):format_date($current_date)),"size=10",false,'text',false);
								//echo tep_draw_input_field("search_date",$sInfo->sessions_start_date,"size=10",false,'text',false);
								?>
								<a onClick="javascript:call_calendar('search.search_date',null,null,'<?php //echo $date_format;?>');if(!show)show=true;"
							      onmouseover="window.status='Date Picker';return true;"
							      onmouseout="window.status='';return true;"><img border="none" style="vertical-align:bottom; cursor:pointer;" src="images/icon_calendar.gif"/>  
							    </a></td><td align="left" style="width:30px;">
								<input type="image" align="absbottom" src="<?php //echo DIR_WS_IMAGES.'template/img_search.gif';?>" alt="Search" title="Search"></form>
								</td></tr></table></td></tr></table>											
							</td>
							</tr>
							</table>-->	
					 </td>
					 
					</tr>
				  </table>	
				 </form>
                </td>                
               </tr>
              </table>
            </td>
          </tr>
		  <tr><td colspan="2" class="main" style="color:red;display:none;" id="error_tag"></td></tr>
          <tr>
	        <td class="pageHeading"><?php echo sprintf(HEADING_SESSION_TITLE ,tep_get_events_name($event_id)); ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>            
          </tr>
        </table>
       </td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr><td id="res_display" class="main" style="display:none"></td></tr>
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent" width="43%"><?php echo TABLE_HEADING_SESSIONS; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_TYPE; ?></td>
               <!-- <td class="dataTableHeadingContent" align="right"><?php //echo TABLE_HEADING_ACTION; ?>&nbsp;</td>-->
              </tr>
              <tr>
              <td colspan="3">
			  <?php echo tep_draw_form('sessions',FILENAME_SESSIONS, tep_get_all_get_params() ,'post','onsubmit="javascript:return ValidateForm(this);"');

			  ?>                            
	              <table border="0" cellspacing="0" cellpadding="0" width="100%">
	              <tr>
	              	<td>              		              			
						 <div id="ajax_details">
						 <?php table_write();?>
						 </div>
						 <div id="new_create"></div>
						 <input type="hidden" name="session_id"	 id="session_id">
		    			 <input type="hidden" name="action_type" id="action_type">
						 <input type="hidden" name="image_type" id="image_type">
						 <input type="hidden" name="actions">
	              	</td>
	              </tr> 
	              </table>
               </form>
              </td></tr>   
            </table></td>		 
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100', '10'); ?></td>
      </tr>	
      <tr>
        <td colspan="3">
          <table border="0" width="100%" cellspacing="0" cellpadding="2">
          	<tr>            	
            	<td align="right" class="smallText" id="back" style="visibility:visible"><?php echo '<a href="' . tep_href_link(FILENAME_EVENTS_MAINPAGE,tep_get_all_get_params(array('cPath','eID','action','page'))) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>&nbsp;';?>&nbsp;</td>
          	</tr>
          </table>
       </td>
      </tr>
    </table>
    </td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php');
 
function table_write(){
	global $HTTP_GET_VARS,$event_id,$session_type,$action,$HTTP_POST_VARS;
	$search='';	

	if($HTTP_POST_VARS['search_date']!="") {
		$search=" and r.sessions_start_date='" . tep_convert_date_raw(tep_db_input($HTTP_POST_VARS['search_date'])) . "'";
		if($session_type!='R') $search=" and s.start_date='" . tep_convert_date_raw(tep_db_input($HTTP_POST_VARS['search_date'])) . "'";	
	}
	echo "<table border='0' cellspacing='0' cellpadding='0' width='100%'>";
	$sessions_count = 0;
    if ($session_type=='R')
        $sessions_query=tep_db_query("SELECT r.recursive_sessions_id as sessions_id, date_format(r.sessions_start_date, '%Y-%m-%d') as sessions_start_date,date_format(r.sessions_end_date, '%Y-%m-%d') as sessions_end_date from " . TABLE_RECURSIVE_SESSIONS . " r where r.events_id=" . (int)$event_id . $search ." order by r.sessions_start_date");        		
    else
        $sessions_query=tep_db_query("SELECT s.sessions_id,date_format(s.start_date,'%Y-%m-%d') as sessions_start_date from " . TABLE_EVENTS_SESSIONS . " s where s.events_id=" . (int)$event_id . " and s.sessions_type='S' " . $search  ." order by s.start_date");
			
  if(tep_db_num_rows($sessions_query)>0){
    while ($sessions = tep_db_fetch_array($sessions_query)) {
      $sessions_count++;
      $class="dataTableRowEven";
  	  if($rows%2==0) $class="dataTableRowOdd";
      $rows++;
	  // Get categories_id for session if search
      if ((!isset($HTTP_GET_VARS['sID']) && !isset($sInfo)) || ($HTTP_GET_VARS['sID'] == $sessions['sessions_id'] && !isset($sInfo) && substr($action, 0, 3) != 'new')) {
        $sInfo_array = $sessions;
        $sInfo = new objectInfo($sInfo_array);
      }
	  echo '  <tr style="height:25" class="'.$class.'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'head_'.$sessions['sessions_id'].'\').style.display==\'none\') expand_category(' . $sessions['sessions_id'] . ',3);">' . "\n";            
	?>
		<td colspan="4" width="100%">
		   	<div id="data_<?php echo $sessions['sessions_id'];?>">
		   	  <table border="0" cellspacing="0" cellpadding="0" width="100%">
		   		<tr>
                	<td class="dataTableContent" width="45%"><?php echo tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '&nbsp;' . format_date($sessions['sessions_start_date']) . ($session_type=='R'?TEXT_SESSIONS_TO . format_date($sessions['sessions_end_date']):''); ?></td>
                	<td class="dataTableContent" align="center" ><?php   if ($session_type=='R') echo TEXT_TYPE_RECURSIVE; else echo TEXT_TYPE_SINGLE;?></td>
                </tr>
              </table>
          </div>
          <div class="openContent" id="head_<?php echo $sessions['sessions_id'];?>" style="display:none"></div>
        </td>     	
     </tr>
 <?php } 
   }else if(!tep_db_num_rows($sessions_query)){ ?>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr height="5">&nbsp;
			</tr>		
 			<tr>
				<td class="main" align="center"><b><?php echo TEXT_EMPTY_SESSION;?></b></td>
			</tr>
		</table>
<?php } if($action=='search'){ ?>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">	
		<tr><td>&nbsp;</td></tr>		
			<tr>
				<td align="right" id="reset"><a href="javascript:expand_category(1,1,'reset');"><?php echo tep_image_button('button_reset.gif', IMAGE_RESET,'style="cursor:hand;cursor:pointer;" ');?></a>&nbsp;&nbsp;</td>
			</tr>
		</table>		      	
  <?php }?>
	</table>
<?php } 

function session_new_edit(){
	global $HTTP_GET_VARS,$HTTP_POST_VARS,$session_type,$session_id,$event_id,$languages_id,$action;
		$parameters = array('sessions_start_date' =>format_date(getServerDate()),
								'sessions_end_date' => format_date(getServerDate()),
								'event_id'=> '',
								'recursive_sessions_id' => '',
								'sessions_type_option' => 'DD',
								'sessions_type_daily_days' => '1',
								'sessions_type_weekly_weeks' => '1',
								'sessions_type_monthly_days' => '1',
								'sessions_type_monthly_months' => '1',
								'sessions_type_monthly_weeks' => '1',
								'sessions_type_monthly_weekdays' => '1',
								'sessions_type_monthly_weekmonths' => '1',
								'sessions_type_yearly_months' => '1',
								'sessions_type_yearly_monthdays' => '1',
								'sessions_type_yearly_weeks' => '1',
								'sessions_type_yearly_weekdays' => '1',
								'sessions_type_yearly_weekmonths' => '1',
								'sessions_date_count'=>'1',
								'sessions_select_interval' =>'1',
								'sessions_select_count'=>'1');

    		$sInfo = new objectInfo($parameters);
    		//check for session_type

			if (isset($HTTP_GET_VARS['sID']) && empty($HTTP_POST_VARS)) {			
				if ($session_type=='R'){
					$session_query = tep_db_query("SELECT date_format(r.sessions_start_date, '%Y-%m-%d') as sessions_start_date,date_format(r.sessions_end_date, '%Y-%m-%d') as sessions_end_date,r.sessions_type,r.sessions_type_option,
													r.events_id,r.recursive_sessions_id, r.sessions_type_daily_days, r.sessions_type_weekly_weeks, r.sessions_type_weekly_days, r.sessions_type_monthly_days,
													r.sessions_type_monthly_months,r.sessions_type_monthly_weeks,r.sessions_type_monthly_weekdays,r.sessions_type_monthly_weekmonths,
													r.sessions_type_yearly_months,r.sessions_type_yearly_monthdays,r.sessions_type_yearly_weeks,r.sessions_type_yearly_weekdays,
													r.sessions_type_yearly_weekmonths from " . TABLE_RECURSIVE_SESSIONS . " r " .
													" where r.recursive_sessions_id = '" . (int)$session_id . "'");
					$session = tep_db_fetch_array($session_query);
					$session['sessions_start_date'] = format_date($session['sessions_start_date']);
					$session['sessions_end_date'] = format_date($session['sessions_end_date']);
					
					$sInfo->objectInfo($session);
				} else {
					$session_query=tep_db_query("SELECT date_format(s.start_date, '%Y-%m-%d') as sessions_start_date,s.events_id from " . TABLE_EVENTS_SESSIONS . " s where s.sessions_id='" . (int)$session_id . "'");
					$session = tep_db_fetch_array($session_query);	
					$session['sessions_start_date'] = format_date($session['sessions_start_date']);
					$session['sessions_end_date'] = format_date($session['sessions_end_date']);
					$sInfo->objectInfo($session);
				}
			} else if (tep_not_null($HTTP_POST_VARS)) {
				$sInfo->objectInfo($HTTP_POST_VARS);
				$sInfo->sessions_type_weekly_days=$weekstring;
				$session_type=$select_session_type;
			} else if ($session_type=='R' && isset($HTTP_GET_VARS['sID'])){				
				$previous_query = tep_db_query(	"SELECT r.sessions_type,r.sessions_type_option,r.sessions_type_daily_days, r.sessions_type_weekly_weeks, r.sessions_type_weekly_days, r.sessions_type_monthly_days,
												r.sessions_type_monthly_months,r.sessions_type_monthly_weeks,r.sessions_type_monthly_weekdays,r.sessions_type_monthly_weekmonths,
												r.sessions_type_yearly_months,r.sessions_type_yearly_monthdays,r.sessions_type_yearly_weeks,r.sessions_type_yearly_weekdays,
												r.sessions_type_yearly_weekmonths from " . TABLE_RECURSIVE_SESSIONS . " r " .
												" where r.events_id = '" . (int)$event_id . "' order by r.sessions_end_date desc limit 1");												
				if (tep_db_num_rows($previous_query)>0){
					$previous_result=tep_db_fetch_array($previous_query);
					$sInfo->objectInfo($previous_result);
				}
			}
			$eventSelected=$event_id==0? $sInfo->events_id: $event_id;
			if ($session_type=='R'){
				$event_common_query=tep_db_query("SELECT sessions_date_count,sessions_select_count,sessions_select_interval from " . TABLE_EVENTS . " where events_id='" . (int)$eventSelected . "'");
				if ($event_common_result=tep_db_fetch_array($event_common_query)){
					$sInfo->sessions_select_count=$event_common_result['sessions_select_count'];
					$sInfo->sessions_select_interval=$event_common_result['sessions_select_interval'];
					$sInfo->sessions_date_count=$event_common_result['sessions_date_count'];
				}
			}
			$daysselect=isset($sInfo->sessions_type_weekly_days)?$sInfo->sessions_type_weekly_days:'0000000';
			$sessions_type_weekly_days=array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');
			$sessions_weeks_checkstring='<table border="0" cellspacing="0" cellpadding="0" class="formArea"><tr>';
			for ($i = 0, $n = sizeof($sessions_type_weekly_days); $i < $n; $i++) {
				$temp='<td class="main"';
				if ($i%2==0) $temp.=' bgcolor="#ebebff" ';
				$temp.='>';
				$temp .= tep_draw_checkbox_field('sessions_type_weekly_days[]', $i+1, (substr($daysselect,$i,1)=='1'?true:false),'','id=sessions_type_weekly_days[]') . '&nbsp;' . $sessions_type_weekly_days[$i] . '&nbsp;';
				$temp .='</td>';
				$sessions_weeks_checkstring.=$temp;
			}
			$sessions_weeks_checkstring.="</tr></table>";
  		?>
				<table border="0" width="100%" cellspacing="3" cellpadding="2" class="openContent">
				<?php if(!$HTTP_GET_VARS['sID']) { ?><tr class="openContent_top"><td colspan="2" width='1100' align='right' id='img_save'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category(0,1);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td></tr><?php } ?>
				<?php if ($insert_error!='') { ?>
					<tr>
						<td>
							<table border="0" width="100%" cellspacing='2' cellpadding="2" class='formArea'>
								<tr>
									<td class="pageHeading"><?php echo TEXT_ERROR; ?></td>
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '1'); ?></td>
								</tr>
								<tr><td class="main"><?php echo $insert_error; ?>
							</table>
						</td>
					</tr>
				<?php } ?>
				
				<?php if(!$HTTP_GET_VARS['sID']){ ?>
				
				<tr>
					<td>
						<table border="0" width="100%" cellspacing="0" cellpadding="0">
							<tr>
								<td class="pageHeading"><?php echo sprintf(TEXT_NEW_SESSION, tep_get_events_name($event_id));?></td>
								<td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
							</tr>
						</table>
					</td>
				</tr>
				
			   <?php } ?>	
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="2" width="100%">
							<?php echo tep_draw_hidden_field('event_selected',$HTTP_GET_VARS['eID']);?>		  
							<tr height="30" valign="top">
								<td class="main" colspan="2"><?php echo "<b>Session Details</b>"; ?></td>
							</tr>
							<tr><td colspan="4">
							<?php if($session_type=='' || $session_type=='R'){?><table border="0" cellpadding="0" cellspacing="0" width="50%"><?php }else{?><table border="0" cellpadding="0" cellspacing="0" width="100%"><?php }?>
							<tr><?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
								<td class="main" nowrap="nowrap" width="100" valign="top"><?php echo TEXT_SESSIONS_START_DATE; ?><br><small><?php echo '(' . $date_format . ')'; ?></small></td>
								<?php if($session_type=='' || $session_type=='R'){?><td class="main" width="25%" valign="top"><?php }else{?><td class="main" valign="top" width="90%"><?php }?><?php //echo tep_draw_input_field("sessions_start_date",(tep_not_null($sInfo->sessions_start_date)?format_date($sInfo->sessions_start_date):format_date($current_date)),"size=10",false,'text',false);
								echo tep_draw_input_field("sessions_start_date",$sInfo->sessions_start_date,"size=10",false,'text',false);
								?>
								<a onClick="javascript:call_calendar('sessions.sessions_start_date',null,null,'<?php echo $date_format;?>');if(!show)show=true;"
							      onmouseover="window.status='Date Picker';return true;"
							      onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
							    </a></td>
							<?php if($session_type=='' || $session_type=='R'){ 
							 		$_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
									<td class="main" nowrap="nowrap" width="100" valign="top"><?php echo TEXT_SESSIONS_END_DATE; ?><br><small><?php echo '(' . $date_format . ')'; ?></small></td>
									<td class="main" width="25%" valign="top"><?php //echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' ;
									echo tep_draw_input_field("sessions_end_date",$sInfo->sessions_end_date,"size=10",false,'text',false);?>
									<a onClick="javascript:call_calendar('sessions.sessions_end_date',null,null,'<?php echo $date_format;?>');if(!show)show=true;"
									  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 colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main" colspan="2"><?php echo TEXT_SESSIONS_TYPE; ?></td>
									<td class="main" colspan="2">
																		
									<?php
									$session_type_count=0;
									if ($session_type=='' || $session_type=='S'){
										echo tep_draw_radio_field('select_session_type', 'S', ($session_type=='S'?true:false)) . '&nbsp;' . TEXT_SESSIONS_TYPE_SINGLE . '&nbsp;';
										$session_type_count++;
									}
									if ($session_type=='' || $session_type=='R'){
										echo tep_draw_radio_field('select_session_type', 'R', true) . '&nbsp;' . TEXT_SESSIONS_TYPE_RECUR; 
										$session_type_count++;
									}
									echo tep_draw_hidden_field('session_type_count',$session_type_count);
									?>
									
									</td>
								</tr>
								<tr>
									<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main" colspan="2"><?php echo TEXT_SESSIONS_SELECT_INTERVAL; ?></td>
									<td class="main" colspan="2">
									<?php echo tep_draw_input_field('sessions_select_interval',$sInfo->sessions_select_interval,'maxlength=3 size=5'); ?></td>
								</tr>
								<tr>
									<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main" colspan="2"><?php echo TEXT_SESSIONS_DATE_COUNT; ?></td>
									<td class="main" colspan="2">
									<?php echo tep_draw_input_field('sessions_date_count',$sInfo->sessions_date_count,'maxlength=3 size=5'); ?></td>
								</tr>
								<tr>
									<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main" colspan="2"><?php echo TEXT_SESSIONS_SELECT_COUNT; ?></td>
									<td class="main" colspan="2">
									<?php echo tep_draw_input_field('sessions_select_count',$sInfo->sessions_select_count,'maxlength=3 size=5'); ?></td>
								</tr>
								</table></td></tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr height="30" valign="top">
									<td class="main" colspan="2"><?php echo "<b>Session Intervals</b>"; ?></td>
								</tr>
								<tr>
								<td colspan="2"><table width="400" cellpadding="0" cellspacing="0" border="0">
								<tr>
								<td width="100" class="main"><label for="daily_check"><?php echo tep_draw_checkbox_field('daily_check','Y',(($sInfo->sessions_type_option=='DD')?true:false),'','onClick="javascript: do_open_session(\'D\');"'); ?>&nbsp;Daily</label></td>
								<td width="100" class="main"><label for="weekly_check"><?php echo tep_draw_checkbox_field('weekly_check','Y',(($sInfo->sessions_type_option=='WW')?true:false),'','onClick="javascript: do_open_session(\'W\');"'); ?>&nbsp;Weekly</label></td>
								<td width="100" class="main"><label for="monthly_check"><?php echo tep_draw_checkbox_field('monthly_check','Y',(($sInfo->sessions_type_option=='MD' || $sInfo->sessions_type_option=='MM')?true:false),'','onClick="javascript: do_open_session(\'M\');"'); ?>&nbsp;Monthly</label></td>
								<td width="100" class="main"><label for="yearly_check"><?php echo tep_draw_checkbox_field('yearly_check','Y',(($sInfo->sessions_type_option=='YM' || $sInfo->sessions_type_option=='YY')?true:false),'','onClick="javascript: do_open_session(\'Y\');"'); ?>&nbsp;Yearly</label></td>
								</tr>
								</table></td>
								</tr>
								<tr>
								<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr <?php echo ( ($sInfo->sessions_type_option=='DD')?'style="display:;"':'style="display:none"'); ?> id="session_daily">
									<td class="main">
									<table cellpadding="0" cellspacing="0">
									<tr>
									<td class="main"><?php echo '&nbsp;Every&nbsp;'.  tep_draw_input_field('sessions_type_daily_days', $sInfo->sessions_type_daily_days,'size=5 maxlength=2'); ?></td>
									<td><img src="images/spin_up.gif" onClick="javascript:do_increment(document.sessions.sessions_type_daily_days,'d');" /><br /><img src="images/spin_down.gif" onClick="javascript:do_decrement(document.sessions.sessions_type_daily_days);" /></td>
									<td class="main">&nbsp;Day(s)</td>
									</tr>
									</table>
									</td>
								</tr>
								<tr <?php echo (($sInfo->sessions_type_option=='WW')?'style="display:;"':'style="display:none"'); ?> id="session_weekly">									
									<td class="main">
										<table border="0" cellpadding="0" cellspacing="0">
										<tr>
										<td class="main" align="left"><?php echo '&nbsp;Every&nbsp;'. tep_draw_input_field('sessions_type_weekly_weeks', $sInfo->sessions_type_weekly_weeks,'size=5 maxlength=2');?></td>
										<td><img src="images/spin_up.gif" onClick="javascript:do_increment(document.sessions.sessions_type_weekly_weeks,'w');" /><br /><img src="images/spin_down.gif" onClick="javascript:do_decrement(document.sessions.sessions_type_weekly_weeks);" /></td>
										<td class="main">&nbsp;weeks(s) on&nbsp;</td>
										<td><?php echo $sessions_weeks_checkstring; ?>
										</td></tr></table>
										
									</td>
								</tr>
								<tr <?php echo (($sInfo->sessions_type_option=='MD' || $sInfo->sessions_type_option=='MM') ? 'style="display:;"' : 'style="display:none;"'); ?> id="session_monthly">
									<td class="main">									
									<table cellpadding="0" cellspacing="0" style="border:solid 1px #7b9ebd;"> 
									<tr>
										<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
									</tr>
									<tr>
										<td width="100" align="right" class="main"><?php echo tep_draw_radio_field('sessions_type_option', 'MD', ($sInfo->sessions_type_option=='MD'?true:false),'','onClick="clear_intervals(this.value)"').'&nbsp;Day&nbsp;'.tep_draw_input_field('sessions_type_monthly_days', $sInfo->sessions_type_monthly_days,'size=5 maxlength=2'); ?></td>
										<td width="20" align="left"><img src="images/spin_up.gif" onClick="javascript:do_increment(document.sessions.sessions_type_monthly_days,'d');" /><br /><img src="images/spin_down.gif" onClick="javascript:do_decrement(document.sessions.sessions_type_monthly_days);" /></td>
										<td align="left" class="main">&nbsp;Every&nbsp;<?php echo tep_draw_input_field('sessions_type_monthly_months', $sInfo->sessions_type_monthly_months,'size=5 maxlength=2'); ?></td>
										<td width="10"><img src="images/spin_up.gif" onClick="javascript:do_increment(document.sessions.sessions_type_monthly_months,'m');" /><br /><img src="images/spin_down.gif" onClick="javascript:do_decrement(document.sessions.sessions_type_monthly_months);" /></td>
										<td class="main" width="470">&nbsp;&nbsp;month(s)</td>
									</tr>
									<tr style="height:50">
										<td colspan="5"><table cellpadding="0" cellspacing="0">
										<tr>
											<td class="main"><?php echo  tep_draw_radio_field('sessions_type_option', 'MM', ($sInfo->sessions_type_option=='MM'?true:false),'','onClick="clear_intervals(this.value)"') .'&nbsp;The&nbsp;'.  tep_draw_combo_select('weeks','sessions_type_monthly_weeks',$sInfo->sessions_type_monthly_weeks) . '&nbsp;' . tep_draw_combo_select('days',"sessions_type_monthly_weekdays",$sInfo->sessions_type_monthly_weekdays) .'&nbsp;of every&nbsp;'. tep_draw_input_field('sessions_type_monthly_weekmonths', $sInfo->sessions_type_monthly_weekmonths,'size=5 maxlength=2'); ?></td>
											<td><img src="images/spin_up.gif" onClick="javascript:do_increment(document.sessions.sessions_type_monthly_weekmonths,'m');" /><br /><img src="images/spin_down.gif" onClick="javascript:do_decrement(document.sessions.sessions_type_monthly_weekmonths);" /></td>
											<td class="main">&nbsp;&nbsp;month(s)</td>
										</tr>
									  </table>
									</td>
									</tr>
									</table>									
									</td>
								</tr>
								<tr <?php echo ( ($sInfo->sessions_type_option=='YM' || $sInfo->sessions_type_option=='YY' ) ? 'style="display:;"' : 'style="display:none;"'); ?> id="session_yearly">
									<td class="main">
									<table border="0" cellspacing="0" cellpadding="0" style="border:solid 1px #7b9ebd;">
									<tr>
										<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
									</tr>
									<tr>
									<td class="main"><?php echo tep_draw_radio_field('sessions_type_option', 'YM', ($sInfo->sessions_type_option=='YM'?true:false),'','onClick="clear_intervals(this.value)"') . sprintf(TEXT_SESSIONS_TYPE_YEARS_DISPLAY1, tep_draw_combo_select('months','sessions_type_yearly_months',$sInfo->sessions_type_yearly_months) . '&nbsp;' . tep_draw_input_field('sessions_type_yearly_monthdays', $sInfo->sessions_type_yearly_monthdays,'size=5 maxlength=2 height=5'));?></td>
									<td width="209"><img src="images/spin_up.gif" onClick="javascript:do_increment(document.sessions.sessions_type_yearly_monthdays,'d');" /><br /><img src="images/spin_down.gif" onClick="javascript:do_decrement(document.sessions.sessions_type_yearly_monthdays);" /></td>
									</tr>
									<tr style="height:50"><td class="main" colspan="2"><?php echo tep_draw_radio_field('sessions_type_option', 'YY', ($sInfo->sessions_type_option=='YY'?true:false),'','onClick="clear_intervals(this.value)"') . sprintf(TEXT_SESSIONS_TYPE_YEARS_DISPLAY2, tep_draw_combo_select('weeks','sessions_type_yearly_weeks',$sInfo->sessions_type_yearly_weeks) . '&nbsp;' . tep_draw_combo_select('days',"sessions_type_yearly_weekdays",$sInfo->sessions_type_yearly_weekdays), tep_draw_combo_select('months',"sessions_type_yearly_weekmonths",$sInfo->sessions_type_yearly_weekmonths));?></td></tr>
									</table>
									</td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
							<?php } 
							if(!$HTTP_GET_VARS['sID']) { ?><tr><td colspan="2" width='1110' align='right' id='img_save'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category(0,1);'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td></tr><?php } ?>
							<tr>
								<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
							</tr>
						</table>
					</td>
				</tr>	  
    		</table> 
	<?php 
		echo "^" . $sInfo->sessions_type_option;
		} ?>
	<script language="javascript">
		function do_open_session(mode){
			document.getElementById('session_daily').style.display='none';
			document.getElementById('session_weekly').style.display='none';
			document.getElementById('session_monthly').style.display='none';
			document.getElementById('session_yearly').style.display='none';
			document.getElementById('daily_check').checked=false;
			document.getElementById('weekly_check').checked=false;
			document.getElementById('monthly_check').checked=false;
			document.getElementById('yearly_check').checked=false;
			var session_type_obj=document.sessions.elements["sessions_type_option"];			
			if(mode=='D' || mode=='W') for(i=0;i<session_type_obj.length;i++) if(session_type_obj[i]) session_type_obj[i].checked=false;			
			switch(mode){
				case 'D':
					document.getElementById('session_daily').style.display='';
					document.getElementById('daily_check').checked=true;					
					break;
				case 'W':
					document.getElementById('session_weekly').style.display='';
					document.getElementById('weekly_check').checked=true;
					break;
				case 'M':
					document.getElementById('session_monthly').style.display='';
					document.getElementById('monthly_check').checked=true;
					if(session_type_obj[0]) session_type_obj[0].checked=true;
					clear_intervals('MD');
					break;
				case 'Y':
					document.getElementById('session_yearly').style.display='';
					document.getElementById('yearly_check').checked=true;					
					if(session_type_obj[2]) session_type_obj[2].checked=true;
					clear_intervals('YM');
					break;
			}
		}
	
		function clear_intervals(value){
			if(value.toLowerCase() != 'dd'){
				if(document.getElementById('sessions_type_daily_days'))document.getElementById('sessions_type_daily_days').value = '';
			}
			if(value.toLowerCase() != 'ww'){
				if(document.getElementById('sessions_type_weekly_weeks'))document.getElementById('sessions_type_weekly_weeks').value = '';
				if(document.getElementsByName('sessions_type_weekly_days'))
					for(i=0;i<document.getElementsByName('sessions_type_weekly_days[]').length;i++)document.getElementsByName('sessions_type_weekly_days[]')[i].checked = false;
			}
			if(value.toLowerCase() != 'md'){
				if(document.getElementById('sessions_type_monthly_days')){
				  document.getElementById('sessions_type_monthly_days').value = '';
				  document.getElementById('sessions_type_monthly_days').disabled=true;				  	
				}				
				if(document.getElementById('sessions_type_monthly_months')) {
				  document.getElementById('sessions_type_monthly_months').value = '';
				  document.getElementById('sessions_type_monthly_months').disabled=true;
				}
				if(document.getElementById('sessions_type_monthly_weeks')) document.getElementById('sessions_type_monthly_weeks').disabled=false;
				if(document.getElementById('sessions_type_monthly_weekdays')) document.getElementById('sessions_type_monthly_weekdays').disabled=false;
				if(document.getElementById('sessions_type_monthly_weekmonths'))document.getElementById('sessions_type_monthly_weekmonths').disabled=false;							
			}
			if(value.toLowerCase() != 'mm'){
				if(document.getElementById('sessions_type_monthly_weeks')) {
				  document.getElementById('sessions_type_monthly_weeks').selectedIndex = 0;				  
				  document.getElementById('sessions_type_monthly_weeks').disabled=true;
				}
				if(document.getElementById('sessions_type_monthly_weekdays')) {
				 document.getElementById('sessions_type_monthly_weekdays').selectedIndex = 0;				 
				 document.getElementById('sessions_type_monthly_weekdays').disabled=true;
				}
				if(document.getElementById('sessions_type_monthly_weekmonths')) {
				 document.getElementById('sessions_type_monthly_weekmonths').value = '';	
				 document.getElementById('sessions_type_monthly_weekmonths').disabled=true;
				}
				if(document.getElementById('sessions_type_monthly_days')) document.getElementById('sessions_type_monthly_days').disabled=false;				
				if(document.getElementById('sessions_type_monthly_months'))  document.getElementById('sessions_type_monthly_months').disabled=false;
			}
			if(value.toLowerCase() != 'ym'){
				if(document.getElementById('sessions_type_yearly_months')) {
					document.getElementById('sessions_type_yearly_months').selectedIndex = 0;
					document.getElementById('sessions_type_yearly_months').disabled=true;	
				}				
				if(document.getElementById('sessions_type_yearly_monthdays')) {
					document.getElementById('sessions_type_yearly_monthdays').value = '';	
					document.getElementById('sessions_type_yearly_monthdays').disabled=true;
				}
				if(document.getElementById('sessions_type_yearly_weeks')) document.getElementById('sessions_type_yearly_weeks').disabled=false;
				if(document.getElementById('sessions_type_yearly_weekdays'))document.getElementById('sessions_type_yearly_weekdays').disabled=false;
				if(document.getElementById('sessions_type_yearly_weekmonths'))document.getElementById('sessions_type_yearly_weekmonths').disabled=false;				
			}
			if(value.toLowerCase() != 'yy'){
				if(document.getElementById('sessions_type_yearly_weeks')) {
					document.getElementById('sessions_type_yearly_weeks').selectedIndex = 0;
					document.getElementById('sessions_type_yearly_weeks').disabled=true;
				}
				if(document.getElementById('sessions_type_yearly_weekdays')){
					document.getElementById('sessions_type_yearly_weekdays').selectedIndex = 0;	
					document.getElementById('sessions_type_yearly_weekdays').disabled=true;
				}
				if(document.getElementById('sessions_type_yearly_weekmonths')) {
				  document.getElementById('sessions_type_yearly_weekmonths').selectedIndex = 0;
				  document.getElementById('sessions_type_yearly_weekmonths').disabled=true;	
				}
				if(document.getElementById('sessions_type_yearly_months')) document.getElementById('sessions_type_yearly_months').disabled=false; 
				if(document.getElementById('sessions_type_yearly_monthdays')) document.getElementById('sessions_type_yearly_monthdays').disabled=false; 
			}
		}
		show = true;
		function call_calendar(obj,obj1,obj2,format){
			if(show){
				show = false;
				show_calendar(obj,obj1,obj2,format);
			}
		}
		
	<?php if(isset($insert_error) && $insert_error!=""){ ?>
	document.getElementById('error_tag').innerHTML='<?php echo $insert_error; ?>';
	document.getElementById('error_tag').style.display='';
	function error_display(){
 	document.getElementById("error_tag").style.display='none';
	}
	setTimeout("error_display()",2000);
	clearTimeout();
	<?php } ?>
	
	
	  function check_key(e){
     var kc=0;
   	  if (window.event)
	    kc=window.event.keyCode;
	  else if (e)
	 	kc=e.which;
	  else
		kc=0;
	  if(kc==13) expand_category(1,'1','search');
   }
	function do_increment(frm,mode) {
	if(mode!="") {
		if(mode=='d')
			var t_value=31;
		else if(mode=='m')
			var t_value=12;
		else if(mode=='w')
			var t_value=7;	
			
		if(frm.value!="" && parseInt(frm.value)<t_value && frm.disabled!=true) {
			var day_value=frm.value;
			frm.value=parseInt(day_value)+1;
		} else if(frm.disabled!=true)
			frm.value=1;
	}	
	}
	function do_decrement(frm) {
	if(frm.value!="" && parseInt(frm.value)>1) {
		var day_value=frm.value;
		frm.value=parseInt(day_value)-1;
	}
	else
		frm.value=1;
	}
	</script>
	
	<?php
	function date_range($sd,$ed,$session_type_daily_days)
	{
	$tmp = array();
	$sdu = strtotime($sd);
	$edu = strtotime($ed);
		while ($sdu <= $edu) {
		$tmp[] = date('Y-m-d',$sdu);
		$sdu = strtotime('+'.$session_type_daily_days.' day',$sdu);
		}
	return ($tmp);
	}
	?>