<?php if ( !defined('CPABC_AUTH_INCLUDE') ) { echo 'Direct access not allowed.'; exit; } ?>
<?php

  wp_enqueue_script( "jquery" );
  wp_enqueue_script( "jquery-ui-core" );
  wp_enqueue_script( "jquery-ui-datepicker" );

?>
</p> <!-- this p tag fixes a IE bug -->
<link rel="stylesheet" type="text/css" href="<?php echo plugins_url('TDE_AppCalendar/'.cpabc_get_option('calendar_theme','').'all-css.css', __FILE__); ?>" />
<script>
var pathCalendar = "<?php echo cpabc_appointment_get_site_url(); ?>";
var cpabc_global_date_format = '<?php echo cpabc_get_option('calendar_dateformat', CPABC_APPOINTMENTS_DEFAULT_CALENDAR_DATEFORMAT); ?>';
var cpabc_global_military_time = '<?php echo cpabc_get_option('calendar_militarytime', CPABC_APPOINTMENTS_DEFAULT_CALENDAR_MILITARYTIME); ?>';
var cpabc_global_start_weekday = '<?php echo cpabc_get_option('calendar_weekday', CPABC_APPOINTMENTS_DEFAULT_CALENDAR_WEEKDAY); ?>';
var cpabc_global_mindate = '<?php $value = cpabc_get_option('calendar_mindate', CPABC_APPOINTMENTS_DEFAULT_CALENDAR_MINDATE); if ($value != '') echo date("n/j/Y", strtotime($value)); ?>';
var cpabc_global_maxdate = '<?php $value = cpabc_get_option('calendar_maxdate', CPABC_APPOINTMENTS_DEFAULT_CALENDAR_MAXDATE); if ($value != '') echo date("n/j/Y",strtotime($value)); ?>';
var cpabc_global_gmt_enabled = <?php $value = cpabc_get_option('gmt_enabled', 'no'); if ($value == 'yes' && CPABC_APPOINTMENTS_TZONE) echo 'true'; else echo 'false'; ?>;
var cpabc_global_gmt = <?php $value = cpabc_get_option('gmt_diff', '0'); if ($value != '') echo intval($value); else echo '0'; ?>;
var cpabc_global_close_on_select = <?php $value = cpabc_get_option('close_fpanel', 'yes'); if ($value == '' || $value == 'yes') echo 'true'; else echo 'false'; ?>;
var cpabc_global_cancel_text = '<?php _e("Cancel"); ?>';
var cpabc_global_pagedate = '<?php
    $sm = cpabc_get_option('calendar_startmonth', date("n"));
    $sy = cpabc_get_option('calendar_startyear', date("Y"));
    if ($sm=='0' || $sm=='') $sm = date("n");
    if ($sy=='0' || $sy=='') $sy = date("Y");
    echo $sm."/".$sy;
?>';
</script>
<script type="text/javascript" src="<?php echo plugins_url('TDE_AppCalendar/all-scripts.js', __FILE__); ?>"></script>
<script type="text/javascript">
 var cpabc_current_calendar_item;
 var abc_last_date = '';
 var abc_cost = '';
 function apc_clear_date()
 {
    document.getElementById("selDaycal"+cpabc_current_calendar_item ).value = "";   
    cpabc_updateItem();
 }
 function cpabc_updateItem()
 {
    document.getElementById("calarea_"+cpabc_current_calendar_item).style.display = "none";
    var i = document.FormEdit.cpabc_item.options.selectedIndex;
    var selecteditem = document.FormEdit.cpabc_item.options[i].value;
    cpabc_do_init(selecteditem);
 }
 var cpabc_first_load = true;
 function cpabc_do_init(id)
 {                                                      
    cpabc_current_calendar_item = id;
    document.getElementById("calarea_"+cpabc_current_calendar_item).style.display = "";
    cpabc_global_date_format = document.getElementById("ccpabc_global_date_format"+id).value;
    cpabc_global_military_time = document.getElementById("ccpabc_global_military_time"+id).value;
    cpabc_global_start_weekday = document.getElementById("ccpabc_global_start_weekday"+id).value;
    cpabc_global_mindate = document.getElementById("cmintime"+id).value;
    cpabc_global_maxdate = document.getElementById("cmaxtime"+id).value;
    if (document.getElementById("ccpabc_global_gmt_enabled"+id).value == 'true') 
        cpabc_global_gmt_enabled = true;
    else
        cpabc_global_gmt_enabled = false;    
    cpabc_global_gmt = document.getElementById("ccpabc_global_gmt"+id).value;
    if (document.getElementById("ccpabc_global_close_on_select"+id).value == 'true') 
        cpabc_global_close_on_select = true;
    else
        cpabc_global_close_on_select = false;    
    cpabc_global_pagedate = document.getElementById("ccpabc_global_pagedate"+id).value;    
    initAppCalendar("cal"+cpabc_current_calendar_item,document.getElementById("ccpages"+id).value,2,document.getElementById("cclanguage"+id).value,{m1:"<?php if (!$readonly) _e('Please select the appointment time.','cpabc'); ?>"});
<?php if (get_option('CPABC_APPOINTMENTS_DEFAULT_USE_EDITOR',"1") != "1" && CPABC_APPOINTMENTS_RELOAD_FORM_STRUCTURE) { ?>
    if (cpabc_first_load) {
        cpabc_first_load = false;    
        return;        
    }
<?php } ?>    
 }
 </script>
<form class="cpp_form" id="cp_abcform_pform" name="FormEdit" action="<?php get_site_url(); ?>" method="post" onsubmit="return doValidate(this);">
<input name="cpabc_appointments_post_update" type="hidden" value="<?php echo CP_CALENDAR_ID; ?>" />
<input name="cpabc_edit_item" type="hidden" value="<?php echo $_POST["cpabc_edit_item"]; ?>" />
<?php echo $quant_buffer; ?>
<div <?php if (count($myrows) < 2) echo 'style="display:none"'; ?>>
  <?php _e("Calendar",'cpabc').":"; ?><br />
  <select name="cpabc_item" id="cpabc_item" onchange="cpabc_updateItem()"><?php echo $calendar_items; ?></select><br /><br />
</div>
<?php
  if (!$readonly) _e("Select date and time",'cpabc').":";
  foreach ($myrows as $item)
  {
      echo '<div id="calarea_'.$item->id.'" style="display:none"><input name="tzonelistcal'.$item->id.'" type="hidden" id="tzonelistcal'.$item->id.'" /><input name="selDaycal'.$item->id.'" type="hidden" id="selDaycal'.$item->id.'" /><input name="selMonthcal'.$item->id.'" type="hidden" id="selMonthcal'.$item->id.'" /><input name="selYearcal'.$item->id.'" type="hidden" id="selYearcal'.$item->id.'" /><input name="selHourcal'.$item->id.'" type="hidden" id="selHourcal'.$item->id.'" /><input name="selMinutecal'.$item->id.'" type="hidden" id="selMinutecal'.$item->id.'" /><div class="appContainer"><div style="z-index:1000;" class="appContainer2"><div id="cal'.$item->id.'Container"></div></div></div> <div style="clear:both;"></div><div '.($readonly?'style="display:none;"':'').' id="listcal'.$item->id.'"></div></div>';
?><input name="cclanguage<?php echo $item->id; ?>" type="hidden" id="cclanguage<?php echo $item->id; ?>" value="<?php echo $item->calendar_language; ?>" /><input name="ccpages<?php echo $item->id; ?>" type="hidden" id="ccpages<?php echo $item->id; ?>" value="<?php echo ($item->calendar_pages?$item->calendar_pages:'2'); ?>" /><input name="ccpabc_global_date_format<?php echo $item->id; ?>" type="hidden" id="ccpabc_global_date_format<?php echo $item->id; ?>" value="<?php echo $item->calendar_dateformat; ?>" /><input name="ccpabc_global_military_time<?php echo $item->id; ?>" type="hidden" id="ccpabc_global_military_time<?php echo $item->id; ?>" value="<?php echo $item->calendar_militarytime; ?>" /><input name="ccpabc_global_start_weekday<?php echo $item->id; ?>" type="hidden" id="ccpabc_global_start_weekday<?php echo $item->id; ?>" value="<?php echo $item->calendar_weekday; ?>" /><input name="cmintime<?php echo $item->id; ?>" type="hidden" id="cmintime<?php echo $item->id; ?>" value="<?php if ($item->calendar_mindate != '') echo date("n/j/Y", strtotime($item->calendar_mindate));?>" /><input name="cmaxtime<?php echo $item->id; ?>" type="hidden" id="cmaxtime<?php echo $item->id; ?>" value="<?php if ($item->calendar_maxdate != '') echo date("n/j/Y", strtotime($item->calendar_maxdate));?>" />            <input name="ccpabc_global_gmt_enabled<?php echo $item->id; ?>" type="hidden" id="ccpabc_global_gmt_enabled<?php echo $item->id; ?>" value="<?php if ($item->gmt_enabled == 'yes' && CPABC_APPOINTMENTS_TZONE) echo 'true'; else echo 'false'; ?>" /><input name="ccpabc_global_gmt<?php echo $item->id; ?>" type="hidden" id="ccpabc_global_gmt<?php echo $item->id; ?>" value="<?php if ($item->gmt_diff != '') echo intval($item->gmt_diff); else echo '0'; ?>" /><input name="ccpabc_global_close_on_select<?php echo $item->id; ?>" type="hidden" id="ccpabc_global_close_on_select<?php echo $item->id; ?>" value="<?php if ($item->close_fpanel == '' || $item->close_fpanel == 'yes') echo 'true'; else echo 'false'; ?>" /><input name="ccpabc_global_pagedate<?php echo $item->id; ?>" type="hidden" id="ccpabc_global_pagedate<?php echo $item->id; ?>" value="<?php
                                                                                                                                                  $sm = $item->calendar_startmonth;
                                                                                                                                                  $sy = $item->calendar_startyear;
                                                                                                                                                  if ($sm=='0' || $sm=='') $sm = date("n");
                                                                                                                                                  if ($sy=='0' || $sy=='') $sy = date("Y");
                                                                                                                                                  echo $sm."/".$sy;
                                                                                                                                              ?>" /><?php      
  }
?>
<script type="text/javascript">
 cpabc_do_init(<?php echo $myrows[0]->id; ?>);
 function doValidate(form)
 {
    var selst = ""+document.getElementById("selDaycal"+cpabc_current_calendar_item).value;    
    if (selst == '')
    {
        alert('<?php echo str_replace("'","\'",__('Please select date and time','cpabc')); ?>.');
        return false;
    }
    selst = selst.match(/;/g);selst = selst.length;
    if (selst > <?php $opt = 1; if ($opt == '') $opt = '1'; echo $opt; ?>)
    {
        var almsg = '<?php echo str_replace("'","\'",__('Please select a maximum of %1 time-slots. Currently selected: %2 time-slots.','cpabc')); ?>';
        almsg = almsg.replace('%1','<?php echo $opt; ?>');
        almsg = almsg.replace('%2',selst);
        alert(almsg);
        return false;
    } 
    return true;    
 }
</script><div id="abccost" style="display:none"></div>

<input type="submit" name="subbtn" class="cp_subbtn" value="<?php _e('Update date','cpabc'); ?>">

</form>


