var mouse_x = 0;
var mouse_y = 0;
var mouse_window_x = 0;
var mouse_window_y = 0;
var help_text = '';
var Temp = new Object;
var plans_options = new Array();
var active_event_id = "";
var active_series_id = "";
var active_day_timestamp = "";
var current_calendar_id = "";
var dialog_box = null;
var info_window = new Object;
var info_window_width = 400;
var info_window_height = 400;
var plans_url = '';
var theme_url = '';
var css_path = '';
var page_width = 0;
var page_height = 0;
var event_target = null;
var browser_type = null;
var cal_password = '';
var logged_in = false;
var calendars = new Array();
var events = new Array();
var pending_events = new Array();
var users = new Array();
var current_user = null;
var success = false;
var messages = "";
addLoadEvent(plans_page_loaded);
// always called when the calendar page is done loading.
function plans_page_loaded() {
if (document.attachEvent) {
document.attachEvent("onmousemove", mousemove);
document.attachEvent("onclick", hide_contextmenus);
}
if (document.addEventListener) {
document.addEventListener("mousemove", mousemove, true);
document.addEventListener("click", hide_contextmenus, true);
}
xmlhttp_init();
update_login();
do_on_load();
if (messages != null && messages != '') update_messages(messages);
format_messages();
}
// this should always be called by
Warning: ');
text = text.replace(/\[error\]/, 'Error: ');
document.getElementById("plans_messages").innerHTML = text;
}
function update_login() {
if (!document.getElementById('login_logout')) return;
if (!plans_options['sessions']) {
document.getElementById('login_logout').parentNode.removeChild(document.getElementById('login_logout'));
return;
}
if (logged_in) {
document.getElementById('login_logout').innerHTML = ""+get_lang('logout')+" ";
}
else {
var text = "";
text += "Password: ";
text += " "+get_lang('submit')+" "
text += " "
text += ""+get_lang('login')+" ";
text += " ";
document.getElementById('login_logout').innerHTML = text;
}
}
function login_logout(logout) {
var url = plans_url+"?cal_id="+current_calendar_id+"&js_login=1";
if (logout)
url += "&logout=1";
else if (document.getElementById("login_password")) {
var pwd = document.getElementById("login_password").value;
url += "&cal_password="+pwd;
}
try {
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
eval(xmlhttp.responseText);
update_messages(messages);
update_login();
}
}
xmlhttp.send(null)
} catch (e) {} // do nothing
}
function login() {
update_messages("logging in...");
login_logout(false);
}
function logout() {
update_messages("logging out...");
login_logout(true);
}
function show_help() {
info_window = this.open("", "info_window", "resizable=yes,status=yes,scrollbars=yes,top="+info_window_y+",left="+info_window_x+",width="+info_window_width+",height="+info_window_height);
doc = info_window.document;
doc.open('text/html');
doc.write('');
doc.write('');
doc.write(''+get_lang('help_box_title')+' ');
doc.write(' ');
// including plans.js in the info window makes IE freeze for unknown reason.
//doc.write('');
//doc.write('');
doc.write('');
doc.write('');
doc.write(help_text);
doc.write('');
doc.close();
info_window.focus();
}
function add_edit_user(user_id) {
//alert("(add_user)");
var current_user = null;
var return_text = "";
var temp = "";
if (users[user_id])
current_user = users[user_id];
else
current_user = new User();
Temp.user_id = user_id;
return_text += "";
return_text += "
"+plans_lang['add_user_name']+":
";
return_text += "
";
return_text += "
"+plans_lang['user_password']+":
";
return_text += "
";
if (users[user_id]) {
return_text += "
"+plans_lang['user_new_password']+":
";
return_text += "
";
return_text += "
"+plans_lang['repeat_new_password']+":
";
return_text += "
";
}
else {
return_text += "
"+plans_lang['repeat_password']+":
";
return_text += "
";
}
if (!logged_in) {
return_text += "
"+plans_lang['calendar_password']+":
";
return_text += "
";
}
temp = (users[user_id]) ? plans_lang['update_user'] : plans_lang['add_user']
return_text += "
";
if (users[user_id])
return_text += "
";
return_text += "
";
/*
return_text += "";
$lang{permissions_edit_events}
$lang{permissions_edit_calendar}
*/
dialog_box_init();
dialog_box.reset();
temp = (users[user_id]) ? plans_lang['edit_user'] : plans_lang['add_user']
dialog_box.setTitle(temp);
dialog_box.element.style.display = "block";
if (users[user_id]) {
dialog_box.anchor(document.getElementById(user_id+'_edit_user_link'))
} else {
dialog_box.anchor(document.getElementById('add_user_link'))
}
dialog_box.setContents(return_text);
}
function add_edit_user_submit(delete_flag) {
var user_id =(Temp.user_id) ? Temp.user_id : '';
var name = document.getElementById('user_name').value;
var password = document.getElementById('user_password').value;
var new_password = (document.getElementById('user_new_password')) ? document.getElementById('user_new_password').value : "";
var repeat_password = document.getElementById('user_repeat_password').value;
var delete_user = (delete_flag)? 1 : "";
var url = plans_url+"?add_edit_user=1&cal_id="+current_calendar_id+"&user_id="+user_id+"&delete="+delete_user+"&name="+name+"&password="+password+"&new_password="+new_password+"&repeat_password="+repeat_password;
if (document.getElementById('cal_password'))
url+= '&cal_password='+document.getElementById('user_cal_password').value;
//alert("url: "+url);
try {
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
//alert(xmlhttp.responseText);
eval(xmlhttp.responseText);
if (success) list_users();
update_messages(messages);
}
}
xmlhttp.send(null)
} catch (e) {} // do nothing
dialog_box.close();
}
function fade_preview()
{
document.getElementById("bg_preview_e1").style.background = fade("#ffffcc", (1+parseInt(document.update_cal_form.background_events_fade_factor.value)));
document.getElementById("bg_preview_e2").style.background = fade("#ccffff", (1+parseInt(document.update_cal_form.background_events_fade_factor.value)));
}
function fade(color, fade_factor)
{
if (!color.match(/#([0-9]|[A-F]){6}/i)) // valid hex #color?
return false;
var rgb = hex2rgb(color.substring(1,7));
var hsv = rgb2hsv(rgb);
hsv[1] = hsv[1] / fade_factor;
var new_rgb = hsv2rgb(hsv);
return "rgb("+new_rgb[0]+","+new_rgb[1]+","+new_rgb[2]+")";
}
function add_new_ical() {
dialog_box_init();
dialog_box.reset();
var text = ''
text += '
'+plans_lang['ical_url']+':
';
text += '
';
if (plans_options['sessions'] == 0) {
text += '
'+plans_lang['password']+':
';
text += '
';
}
text += '
'+plans_lang['add_ical']+' ';
dialog_box_init();
dialog_box.reset();
dialog_box.setTitle("Add New iCal calendar!");
dialog_box.setContents(text);
dialog_box.element.style.display = "block";
dialog_box.anchor(document.getElementById('add_new_ical_link'));
}
function add_new_ical_submit() {
var ical_url = document.getElementById('ical_url').value;
var ical_url_escaped = escape(escape(escape(ical_url)));
var cal_password = '';
if ( document.getElementById('cal_password'))
cal_password = document.getElementById('cal_password').value;
try {
xmlhttp.open("GET", plans_url+'?add_new_ical=1&ical_url='+ical_url_escaped+'&cal_password='+cal_password,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
//alert(xmlhttp.responseText);
eval(xmlhttp.responseText);
update_messages(messages);
if (success) dialog_box.close();
}
}
xmlhttp.send(null)
} catch (e) {} // do nothing
}
function validate_event() {
var url = plans_url;
var postdata = 'validate_event=1';
postdata +='&evt_title='+document.getElementById('evt_title').value;
postdata +='&evt_start_date='+document.getElementById('evt_start_date').value;
postdata +='&evt_days='+document.getElementById('evt_days').value;
postdata +='&all_day_event='+document.getElementById('all_day_event').value;
postdata +='&evt_start_time='+document.getElementById('evt_start_time').value;
postdata +='&evt_end_time='+document.getElementById('evt_end_time').value;
xmlhttp.open("POST", url, false);
xmlhttp.send(postdata);
//alert(xmlhttp.responseText);
eval(xmlhttp.responseText);
update_messages(messages);
return success;
}
function validate_calendar() {
if (document.getElementById('as'));
document.getElementById('as').value = document.getElementById('rt').innerHTML;
return true;
}
function dialog_box_init() {
if (!dialog_box)
{
dialog_box = new DialogBox({'id':'dialog_box','element_id':'plans_dialog_box','images_url':(theme_url+'/graphics/')});
}
}
function list_users() {
if (!users || users.length == 0) return;
var results = "";
//for (i=0;i
('+get_lang('edit')+') ';
}
if (document.getElementById('select_users'))
document.getElementById('select_users').innerHTML = results;
}
function tab_show(tab_num)
{
if (tab_num == null) return;
var elList, i;
i=0;
// update all tabs.
while (document.getElementById("tab"+i) && i<100)
{
if (i == tab_num)
{
// If the tab is the new active tab, activate it.
document.getElementById("tab"+i).className += " active";
document.getElementById("tab_area"+i).style.display=""
document.getElementById("tab"+i).blur();
}
else
{
// Otherwise, make sure the tab is deactivated.
removename (document.getElementById("tab"+i),"active");
document.getElementById("tab_area"+i).style.display="none"
}
i++;
}
}
function toggle_visible(elname)
{
if (document.getElementById(elname) == null) return;
el = document.getElementById(elname);
if (el.style.display == "none")
el.style.display = ""
else
el.style.display = "none"
}
function toggle_login(elname)
{
toggle_visible(elname);
if ((document.getElementById('login_switch').innerHTML == '[x]'))
{
document.getElementById('login_switch').innerHTML = 'login';
document.getElementById('login_switch').style.top = '0';
document.getElementById('login_switch').style.left = '0';
}
else {
document.getElementById('login_switch').innerHTML = '[x]';
document.getElementById('login_switch').style.top = '-10px';
document.getElementById('login_switch').style.left = '5px';
}
}
function recur_toggle() {
if (document.add_event_form.recurring_event.checked)
{
document.add_event_form.recurrence_type[0].disabled=false;
document.add_event_form.recurrence_type[1].disabled=false;
document.add_event_form.recurrence_type[2].disabled=false;
document.add_event_form.recurrence_type[3].disabled=false;
document.add_event_form.weekday_of_month_type.disabled=false;
document.add_event_form.custom_months.disabled=false;
document.add_event_form.year_fit_type[0].disabled=false;
document.add_event_form.year_fit_type[1].disabled=false;
document.add_event_form.custom_months.disabled=false;
if (!document.add_event_form.recurrence_type[1].checked)
document.add_event_form.weekday_of_month_type.disabled=true;
if (document.add_event_form.year_fit_type[0].checked)
document.add_event_form.custom_months.disabled=true;
document.add_event_form.recur_end_date.disabled=false;
}
else
{
document.add_event_form.recurrence_type[0].disabled=true;
document.add_event_form.recurrence_type[1].disabled=true;
document.add_event_form.recurrence_type[2].disabled=true;
document.add_event_form.recurrence_type[3].disabled=true;
setTimeout("document.add_event_form.every_x_days.disabled=true",100);
setTimeout("document.add_event_form.every_x_weeks.disabled=true",100);
setTimeout("document.add_event_form.weekday_of_month_type.disabled=true",100);
setTimeout("document.add_event_form.custom_months.disabled=true",100);
document.add_event_form.year_fit_type[0].disabled=true;
document.add_event_form.year_fit_type[1].disabled=true;
document.add_event_form.custom_months.disabled=true;
document.add_event_form.recur_end_date.disabled=true;
}
recurrence_type_update();
//alert(document.add_event_form.recurring_event.checked);
}
function recurrence_type_update(last)
{
document.add_event_form.weekday_of_month_type.disabled=true;
document.add_event_form.every_x_days.disabled=true;
document.add_event_form.every_x_weeks.disabled=true;
if (document.add_event_form.recurrence_type[1].checked && !document.add_event_form.recurrence_type[1].disabled)
{
document.add_event_form.weekday_of_month_type.disabled=false;
}
if (document.add_event_form.recurrence_type[2].checked && !document.add_event_form.recurrence_type[2].disabled)
{
document.add_event_form.every_x_days.disabled=false;
}
if (document.add_event_form.recurrence_type[3].checked && !document.add_event_form.recurrence_type[3].disabled)
{
document.add_event_form.every_x_weeks.disabled=false;
}
if (!last) setTimeout("recurrence_type_update(true)",100);
}
function update_remote_calendar_requests()
{
if (!document.update_cal_form || !document.update_cal_form.allow_remote_calendar_requests)
return;
if (document.update_cal_form.allow_remote_calendar_requests.checked)
{
document.update_cal_form.remote_calendar_requests_require_password.disabled = false;
if (document.update_cal_form.remote_calendar_requests_require_password.checked)
document.update_cal_form.remote_calendar_requests_password.disabled = false;
}
}
function show_event_contextmenu(e, event_id, menu_bgcolor, series_id)
{
if (e.ctrlKey || plans_options['right_click_menus_enabled'] != 1) return true;
active_event_id = event_id;
active_series_id = series_id;
var themenu = document.getElementById("contextmenu")
var event_contextmenu_text = "";
themenu.innerHTML = event_contextmenu_text;
document.getElementById("contextmenu_innerbox").style.borderStyle = "solid";
document.getElementById("contextmenu_innerbox").style.borderWidth = "1px";
document.getElementById("contextmenu_innerbox").style.borderTopColor = menu_bgcolor;
document.getElementById("contextmenu_innerbox").style.borderLeftColor = menu_bgcolor;
show_contextmenu(themenu, e);
return false;
}
function show_day_contextmenu(e, day_timestamp)
{
if (e.ctrlKey || plans_options['right_click_menus_enabled'] != 1) return true;
get_page_boundaries();
active_day_timestamp = day_timestamp;
var themenu = document.getElementById("contextmenu")
var day_contextmenu_text = "";
day_contextmenu_text += "";
themenu.innerHTML = day_contextmenu_text;
document.getElementById("contextmenu_innerbox").style.borderStyle = "solid";
document.getElementById("contextmenu_innerbox").style.borderWidth = "1px";
document.getElementById("contextmenu_innerbox").style.borderTopColor = "#ffffff";
document.getElementById("contextmenu_innerbox").style.borderLeftColor = "#ffffff";
show_contextmenu(themenu, e);
return false;
}
function show_contextmenu(contextmenu, event) {
get_page_boundaries();
contextmenu.style.left = mouse_x+"px";
contextmenu.style.top = mouse_y+"px";
contextmenu.style.zIndex = 100000;
contextmenu.style.visibility = "visible";
// adjust menu if near window edge
if (browser_type != "IE")
{
if (distance_to_right_edge < contextmenu.offsetWidth)
contextmenu.style.left = 2+mouse_x - contextmenu.offsetWidth+"px";
if (distance_to_bottom < contextmenu.offsetHeight)
contextmenu.style.top = 2+mouse_y - contextmenu.offsetHeight+"px";
}
// prevent default right-click menu from appearing.
//if (browser_type == "IE")
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
if (event.preventDefault) event.preventDefault();
}
function hide_contextmenus()
{
if (!document.getElementById("contextmenu")) return;
document.getElementById("contextmenu").style.visibility = "hidden";
}
function context_menuitem_highlight(element, color)
{
element.className = "context_menuitem_highlight";
}
function context_menuitem_unhighlight(element)
{
element.className = "context_menuitem";
}
function get_page_boundaries()
{
if (document.body.clientWidth) {
distance_to_right_edge = document.body.clientWidth-mouse_window_x;
distance_to_bottom = document.body.clientHeight-mouse_window_y;
} else if (window.innerWidth) {
distance_to_right_edge = window.innerWidth-mouse_x
distance_to_bottom = window.innerHeight-mouse_y;
}
}
function edit_event()
{
window.location.href = plans_url + "?active_tab=1&add_edit_event=edit&evt_id=" + active_event_id + "";
}
function clone_event()
{
window.location.href = plans_url + "?active_tab=1&add_edit_event=add&evt_id=" + active_event_id + "";
}
function add_event_on_day()
{
window.location.href = plans_url + "?active_tab=1&cal_id="+current_calendar_id+"&add_edit_event=add&add_date_timestamp=" + active_day_timestamp;
}
function delete_event()
{
dialog_box_init();
dialog_box.reset();
var text = ''
if (logged_in || plans_options['disable_passwords'] == 1) {
if (active_series_id) {
text += ''+plans_lang['recurring_event_delete_all1']+'
';
text += '';
} else {
text += ''+plans_lang['event_delete1']+'
';
text += '';
}
} else {
text += ''+plans_lang['password']+':
';
text += '
';
if (active_series_id) {
text += ''+plans_lang['recurring_event_delete_all1']+'
';
text += '';
} else {
text += ''+plans_lang['event_delete1']+':
';
text += ''+get_lang('event_delete2')+' ';
}
}
dialog_box.setTitle(get_lang('delete_event'));
dialog_box.setContents(text);
dialog_box.element.style.display = "block";
dialog_box.anchor();
if (document.getElementById('delete_event_cal_password'))
document.getElementById('delete_event_cal_password').select();
}
function delete_event_submit(all_in_series) {
var cal_password = (document.getElementById('delete_event_cal_password')) ? document.getElementById('delete_event_cal_password').value : '';
var url = plans_url+'?api_command=delete_event&output_format=javascript&evt_id='+active_event_id;
if (cal_password != '')
url += "&cal_password="+cal_password;
if (all_in_series && active_series_id != '')
url += "&all_in_series=1&series_id="+active_series_id;
//alert(url);
try {
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
//alert(xmlhttp.responseText);
eval(xmlhttp.responseText);
}
}
xmlhttp.send(null)
} catch (e) {} // do nothing
}
function pending_events_toggle_events(mode) {
for (var pending_events_id in pending_events) {
if (mode == 1) {
if (!document.getElementById('pending_event_approve_'+pending_events_id).checked && !document.getElementById('pending_event_delete_'+pending_events_id).checked)
document.getElementById('pending_event_approve_'+pending_events_id).checked = true;
else if (document.getElementById('pending_event_approve_'+pending_events_id).checked && !document.getElementById('pending_event_delete_'+pending_events_id).checked)
document.getElementById('pending_event_approve_'+pending_events_id).checked = false;
} else if (mode == 2) {
if (!document.getElementById('pending_event_approve_'+pending_events_id).checked && !document.getElementById('pending_event_delete_'+pending_events_id).checked)
document.getElementById('pending_event_delete_'+pending_events_id).checked = true;
else if (document.getElementById('pending_event_delete_'+pending_events_id).checked && !document.getElementById('pending_event_approve_'+pending_events_id).checked)
document.getElementById('pending_event_delete_'+pending_events_id).checked = false;
}
}
}
function approve_pending_events_toggle() {
var results = '';
if (document.getElementById('pending_events').style.display == 'block') {
document.getElementById('pending_events').style.display = 'none';
return;
}
results += ' '
/*
pending_events.sort(function(a, b) {
if (a.timestamp > b.timestamp) return 1;
if (a.timestamp < b.timestamp) return -1;
return 0;
});
*/
for (var pending_events_id in pending_events) {
results += generate_pending_event(pending_events[pending_events_id]);
}
results += " ";
results += ""+get_lang('email_reminder_text5')+" ";
results += " ";
document.getElementById('pending_events').innerHTML = results;
document.getElementById('pending_events').style.display = 'block';
}
function approve_pending_events_submit() {
var events_to_approve = new Array();
var events_to_delete = new Array();
// get approved events
for (pending_event_id in pending_events)
{
var approve_el = document.getElementById("pending_event_approve_"+pending_event_id);
var delete_el = document.getElementById("pending_event_delete_"+pending_event_id);
if (approve_el && approve_el.checked)
events_to_approve.push(pending_event_id);
if (delete_el && delete_el.checked)
events_to_delete.push(pending_event_id);
}
if (events_to_approve.length == 0 && events_to_delete.length == 0) {
alert(get_lang('no_pending_events_checked'));
return;
}
if (!logged_in && cal_password == '') {
var text = ''
text += ''+plans_lang['calendar_password']+':
';
text += '
';
text += 'ok ';
dialog_box_init();
dialog_box.reset();
dialog_box.setTitle("Password Needed");
dialog_box.setContents(text);
dialog_box.element.style.display = "block";
dialog_box.anchor(document.getElementById('tab_menu'))
return;
}
var url = plans_url+"?manage_pending_events=1&approve="+events_to_approve+"&delete="+events_to_delete;
if (cal_password != '')
url += "&cal_password="+cal_password;
try {
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
//alert(xmlhttp.responseText);
eval(xmlhttp.responseText);
update_messages(messages);
}
}
xmlhttp.send(null)
} catch (e) {} // do nothing
//alert("events_to_approve: "+ events_to_approve + "\nevents_to_delete: "+ events_to_delete);
}
function do_onresize()
{
if (document.body.clientWidth) {
opener.info_window_width = document.body.clientWidth;
opener.info_window_height = document.body.clientHeight;
} else if (this.outerWidth) {
opener.info_window_width = this.outerWidth;
opener.info_window_height = this.outerHeight;
}
}
function display_event(evt_id)
{
var info_window_x = window_x()-info_window_width;
var info_window_y = window_y();
if (evt_id.match(/^r/)) // remote event
{
var URL_string = remote_event_details[evt_id].url;
info_window = this.open(URL_string, "info_window", "resizable=yes,status=yes,scrollbars=yes,top="+info_window_y+",left="+info_window_x+",width="+info_window_width+",height="+info_window_height);
}
else // local event
{
var URL_string = plans_url+"?view_event=1&evt_id="+evt_id;
info_window = this.open(URL_string, "info_window", "resizable=yes,status=yes,scrollbars=yes,top="+info_window_y+",left="+info_window_x+",width="+info_window_width+",height="+info_window_height);
}
info_window.focus();
}
function display_pending_event(pending_event_id)
{
var info_window_x = window_x()-info_window_width;
var info_window_y = window_y();
var URL_string = plans_url+"?view_pending_event=1&pending_event_id="+pending_event_id;
info_window = this.open(URL_string, "info_window", "resizable=yes,status=yes,scrollbars=yes,top="+info_window_y+",left="+info_window_x+",width="+info_window_width+",height="+info_window_height);
info_window.focus();
}
function generate_pending_event(event) {
var results = "";
results += "";
results += generate_list_event(event, "javascript:display_pending_event("+event.id+")");
results +="
"
return results;
}
function generate_list_event(event, link) {
var results = "";
var date_string;
var weekday_string;
//var start_date = new Date(event.start*1000);
//date_string = plans_lang[] $months_abv[$event_start_timestamp_array[4]] $event_start_timestamp_array[3]";
//weekday_string = $day_names_abv[$event_start_timestamp_array[6]]
var nice_start_date = nice_date(event.start, event.end);
results += ""+nice_start_date;
// else #multi-day event
// {
// @event_end_timestamp_array = gmtime $event{end};
// if ($event_start_timestamp_array[4] eq $event_end_timestamp_array[4])
// {
// $date_string="$months_abv[$event_start_timestamp_array[4]] $event_start_timestamp_array[3]-$event_end_timestamp_array[3]";
// }
// else
// {
//// $date_string="$months_abv[$event_start_timestamp_array[4]] $event_start_timestamp_array[3] - $months_abv[$event_end_timestamp_array[4]] $event_end_timestamp_array[3]";
// }
// $weekday_string = "$day_names_abv[$event_start_timestamp_array[6]]-$day_names_abv[$event_end_timestamp_array[6]]";
// }
if (event.icon && event.icon != "blank") results += " ";
results += ""+event.title+" ";
results += " "
return results;
}
function nice_date(start, end, abbreviate_months, include_year) {
start = new Date(start*1000);
end = new Date(end*1000);
var results = "";
var separator_string = " - ";
var start_display_year = (include_year || start.getUTCFullYear() != rightnow.getUTCFullYear()) ? ', '+start.getUTCFullYear() : '';
var end_display_year = (include_year || end.getUTCFullYear() != rightnow.getUTCFullYear()) ? ', '+end.getUTCFullYear() : '';
var start_display_month = (abbreviate_months) ? plans_lang['months_abv'][start.getUTCMonth()] : plans_lang['months'][start.getUTCMonth()];
var end_display_month = (abbreviate_months) ? plans_lang['months_abv'][end.getUTCMonth()] : plans_lang['months'][end.getUTCMonth()];
if (date_format == 'dd/mm/yy')
{
if (start.getUTCMonth() == end.getUTCMonth() && start.getUTCFullYear() == end.getUTCFullYear() && start.getUTCDate() == end.getUTCDate())
{ //same year, same month, same day
results = start.getUTCDate()+' '+start_display_month+start_display_year;
}
else if (start.getUTCMonth() == end.getUTCMonth() && start.getUTCFullYear() == end.getUTCFullYear())
{ //same year, same month
results = start.getUTCDate()+separator_string+end.getUTCDate()+' '+start_display_month+start_display_year;
}
else if (start.getUTCFullYear() != end.getUTCFullYear())
{ //different year
results = start.getUTCDate()+start_display_month+start_display_year+separator_string+end.getUTCDate()+end_display_month+end_display_year;
}
else
{ //same year, different months
results = start.getUTCDate()+start_display_month+separator_string+end.getUTCDate()+end_display_month+end_display_year;
}
}
else
{
if (start.getUTCMonth() == end.getUTCMonth() && start.getUTCFullYear() == end.getUTCFullYear() && start.getUTCDate() == end.getUTCDate())
{ //same year, same month, same day
results = start_display_month+' '+start.getUTCDate()+start_display_year;
}
else if (start.getUTCMonth() == end.getUTCMonth() && start.getUTCFullYear() == end.getUTCFullYear())
{ //same year, same month
results = start_display_month+''+start.getUTCDate()+separator_string+end.getUTCDate()+start_display_year;
}
else if (start.getUTCFullYear() != end.getUTCFullYear())
{ //different year
results = start_display_month+' '+start.getUTCDate()+start_display_year+separator_string+end_display_month+' '+end.getUTCDate()+end_display_year;
}
else
{ //same year, different months
results = start_display_month+' '+start.getUTCDate()+separator_string+end_display_month+' '+end.getUTCDate()+end_display_year;
}
}
return results;
}
function nice_time(start, end, days) {
var start_date = new Date(start*1000);
var end_date = new Date(end*1000);
var temp = (start_date.getUTCDay() == end_date.getUTCDay()) ? '':'dna ';
var results = '';
results = formatDate(start_date,temp+"sh:mm ampm")+" - "+formatDate(end_date,temp+"sh:mm ampm");
// if times are the same, remove the second one.
if (end - start <=1)
{
results = results.replace(/s*-.+/,'');
return results;
}
// if both times are am or pm, remove the first one (it's redundant!)
//$results =~ s/(.*) $lang{am}(.*$lang{am}.*)/$1$2/;
//$results =~ s/(.*) $lang{pm}(.*$lang{pm}.*)/$1$2/;
var reg1 = new RegExp('(.*) am(.*am.*)');
var reg2 = new RegExp('(.*) pm(.*pm.*)');
results = results.replace(reg1,'$1$2');
results = results.replace(reg2,'$1$2');
results = results.replace(/am/,plans_lang['am']);
results = results.replace(/pm/,plans_lang['pm']);
return results;
}
function addZero(vNumber){
return ((vNumber < 10) ? "0" : "") + vNumber
}
function formatDate(vDate, vFormat){
var vDay = addZero(vDate.getUTCDate());
var vMonth = addZero(vDate.getUTCMonth()+1);
var vMonthName = plans_lang['months'][vDate.getUTCMonth()];
var vMonthNameAbv = plans_lang['months_abv'][vDate.getUTCMonth()];
var vDayName = plans_lang['day_names'][vDate.getUTCDay()];
var vDayNameAbv = plans_lang['day_names_abv'][vDate.getUTCDay()];
var vYearLong = addZero(vDate.getFullYear());
var vYearShort = addZero(vDate.getFullYear().toString().substring(3,4));
var vYear = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort)
var vHour = addZero(vDate.getUTCHours());
var ampm = (vHour < 12) ? 'am': 'pm';
var vShortHour = vHour;
if (vHour > 12)
vShortHour -= 12;
if (vShortHour == 0)
vShortHour = 12;
var vMinute = addZero(vDate.getUTCMinutes());
var vSecond = addZero(vDate.getUTCSeconds());
var vDateString = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/MNA/g, vMonthNameAbv).replace(/MN/g, vMonthName).replace(/y{1,4}/g, vYear);
vDateString = vDateString.replace(/hh/g, vHour).replace(/sh/g, vShortHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond).replace(/ampm/g, ampm);
vDateString = vDateString.replace(/dna/g, vDayNameAbv).replace(/dn/g, vDayName);
return vDateString
}
function xmlhttp_init() {
//alert(" (xmlhttp_init) start");
//if (xmlhttp) return;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
xmlhttp = new XMLHttpRequest();
//alert(" (xmlhttp_init) done");
}
function get_lang(key)
{
if (plans_lang[key]) return plans_lang[key];
return '';
}
// classes
function User(i, n) {
this.id = (i) ? i : null; // id must be unique among users
this.name = (n) ? n : "";
}
function Calendar(properties) {
this.id = get_property(properties,'id',null); // id must be unique among calendars
this.title = get_property(properties,'title','');
this.local_background_calendars_string = get_property(properties,'local_background_calendars','');
this.local_background_calendars = this.local_background_calendars_string.split(',');
if (!this.local_background_calendars) this.local_background_calendars = new Array();
}
function Event(properties) {
this.id = get_property(properties,'id',null); // id must be unique among events
this.title = get_property(properties,'title','');
this.details = get_property(properties,'details','');
this.details_url = get_property(properties,'details_url',false);
this.icon = get_property(properties,'icon','');
this.bgcolor = get_property(properties,'bgcolor','');
this.unit_number = get_property(properties,'unit_number','');
this.start = get_property(properties,'start','');
this.end = get_property(properties,'end','');
this.timestamp = get_property(properties,'timestamp',0);
this.days = get_property(properties,'days',1);
this.all_day_event = get_property(properties,'all_day_event',false);
this.no_end_time = get_property(properties,'no_end_time',false);
this.cal_ids_string = get_property(properties,'cal_ids','');
this.cal_ids = this.cal_ids_string.split(',');
}