var livecal_dir = '/js/calendar/' var week_begins = 1; var thismonth = 06; var thisyear = 2007; var min_month = 5; var min_year = 2006; var has_fp = false; var siteurl = 'http://www.heliomag.com'; var firstpost = ''; var permastruct = '#home/calendar/date_%year%%monthnum%%day%'; var m_permastruct= '#home/calendar/date_%year%%monthnum%'; var spinner_img = '/js/calendar/wait1.gif'; var dateDayDisp = new Array('S', 'M', 'T', 'W', 'T', 'F', 'S'); var dateMon = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var dateMonShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); var archives = 'Archives:'; var viewpostsfor_= 'View posts for %1$s %2$s'; // extra fiddly bits of needed code before getting to the meat function viewpostsfor(year,month) { return viewpostsfor_.replace("%1\$s",dateMon[month]).replace("%2\$s",year); } var unixmonth = new Date(thisyear,thismonth-1,1); unixmonth.setYear(thisyear); // to be sure it's a 4 digit value. var entries_cache=new Array(); var tocall; if (navigator.userAgent.indexOf('KHTML')>0) { setTimeout('kcalendar_refresh()',2000); } else { Event.observe(window, 'load', kcalendar_refresh, false); } // let's create the calendar table array function kcalendar_build(year,month,day) { var cal_today=new Date; shownDate=new Date(year,month,day); calh=document.createElement('table'); calh.border=0; calh.cellPadding=0; calh.cellSpacing=0; calh.id="cal-calendar_head"; // draw navigation row month cal_head = document.createElement('THEAD'); calh.appendChild(cal_head); cal_row=cal_head.insertRow(0); cal_row.className='cal_head_row'; // create previous month nav if we have a post from then cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.id = 'prev'; cal_cell.className = 'pad'; // blank space cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.appendChild(document.createTextNode(' ')); cal_cell.width='50%'; // create spinner element cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.className = 'pad'; spinner = document.createElement("span"); spinner.id="calendar_spin"; spinner.className="hgh"; spinner.appendChild(document.createTextNode('Loading...')); cal_cell.appendChild(spinner); // draw month name caption=document.createElement('span'); caption.appendChild(document.createTextNode(dateMon[shownDate.getMonth()].toUpperCase()+',\xA0'+shownDate.getFullYear())); caption.id="cal-calendar_caption"; // caption.style.position='absolute'; caption.style.visibility='hidden'; cal_cell.appendChild(caption); // blank space cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.width='50%'; // create next month nav if we have a post from then cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.id="next"; cal_cell.className='pad'; // More one row to fill bottom color cal_row=cal_head.insertRow(1); cal_row.className='cal_head_fill_row'; // create previous month bottom color cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.className = 'cal_bottom'; // blank space cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.className='cal_head_blank'; // create spinner bottom color cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.className = 'cal_bottom'; // blank space cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.className='cal_head_blank'; // create next month bottom color cal_cell = document.createElement('TH'); cal_row.appendChild(cal_cell); cal_cell.className = 'cal_bottom'; // Create new table cal=document.createElement('table'); cal.border=0; cal.cellPadding=0; cal.cellSpacing=0; cal.id="cal-calendar"; // create calendar body cal_body = document.createElement('TBODY'); cal.appendChild(cal_body); // get date of first cell firstcelldate=new Date(shownDate.getFullYear(),shownDate.getMonth(),1); cellDate=1-firstcelldate.getDay()+week_begins; if (cellDate>1)cellDate-=7; cellDate=1; // draw rest of month days_in_last_month=kcalendar_daysInMonth(shownDate.getFullYear(),shownDate.getMonth()-1); for (i=0;i<5;i++) { cal_row=cal_body.insertRow(i); for(j=0;j<7;j++) { cal_cell=cal_row.insertCell(j); class_to_show=''; if (cellDate<1) { class_to_show='pad'; num_to_show='';//days_in_last_month+cellDate } else if (cellDate>kcalendar_daysInMonth(shownDate.getFullYear(),shownDate.getMonth())) { class_to_show='pad'; num_to_show='';//cellDate-kcalendar_daysInMonth(shownDate.getFullYear(),shownDate.getMonth()); } else { num_to_show=cellDate; class_to_show=''; if (shownDate.getFullYear()==cal_today.getFullYear() && shownDate.getMonth()==cal_today.getMonth() && cellDate==cal_today.getDate()) { cal_cell.id='cal_today'; class_to_show+=" cal_today" } } cal_cell.appendChild(document.createTextNode(num_to_show)); cal_cell.className=class_to_show; if( cal_cell.id != 'cal_today' ) cal_cell.id="kcalendar_"+shownDate.getFullYear()+"_"+(shownDate.getMonth()+1)+"_"+cellDate; cellDate++; } } tocall='kcalendar_'+(shownDate.getFullYear())+"_"+(shownDate.getMonth()); div=document.createElement('div'); div.id="calendar_block"; div.appendChild(calh); div.appendChild(cal); return div; } // identify posts for dates listed function kcalendar_create_links(arr, shown_year,shown_month) { // add prev month/year links if necessary split = arr[0].split(/: /); if (split[1] != 'none') { prev_date = split[1].split(/,/); cell = document.getElementById('prev'); // kill the kid. if (cell.childNodes.length>0) cell.removeChild(cell.childNodes[0]); // create a new one. img = document.createElement('img'); img.src=siteurl + livecal_dir + 'prev_month.png'; img.alt=String.fromCharCode(171) +" " + dateMonShort[prev_date[1]-1]; img.title=String.fromCharCode(171) +" " + dateMonShort[prev_date[1]-1]; link = document.createElement('a'); link.appendChild(img); // document.createTextNode(String.fromCharCode(171)) +" " + dateMonShort[prev_date[1]-1]) link.href="javascript:kcalendar_refresh("+prev_date[0]+","+prev_date[1]+");"; link.title = viewpostsfor(prev_date[0],prev_date[1]-1) cell.appendChild(link); cell.abbr=dateMonShort[prev_date[1]-1]; cell.className = ''; } else { cell = document.getElementById('prev'); img = document.createElement('img'); img.src=siteurl + livecal_dir + 'prev_month_disable.png'; cell.appendChild(img); } // add next month/year links if necessary split = arr[1].split(/: /); if (split[1] != 'none') { cell = document.getElementById('next'); next_date = split[1].split(/,/); // kill the kid. if (cell.childNodes.length>0) cell.removeChild(cell.childNodes[0]); // create a new one. img = document.createElement('img'); img.src=siteurl + livecal_dir + 'next_month.png'; img.alt=dateMonShort[next_date[1]-1]+ " " + String.fromCharCode(187); img.title=dateMonShort[next_date[1]-1]+ " " + String.fromCharCode(187); link = document.createElement('a'); link.appendChild(img); link.href="javascript:kcalendar_refresh("+next_date[0]+","+next_date[1]+");"; link.title = viewpostsfor(next_date[0],next_date[1]-1) cell.appendChild(link); cell.abbr=dateMonShort[next_date[1]-1]; cell.className = ''; } else { cell = document.getElementById('next'); img = document.createElement('img'); img.src=siteurl + livecal_dir + 'next_month_disable.png'; cell.appendChild(img); } // don't do anything if we don't have any links // this should only happen when someone jumps years if (arr[2] == '') return; // now create links for each post for (i=2;i2) { split=arr[2].split(/: /); if (el && split.length>1) { split=split[0].split(/-/); text=el.childNodes[0]; el2=document.createElement('a'); el2.title= archives+' '+dateMon[split[1]-1]+' '+split[0]; el2.appendChild(text); el2.href = m_permastruct; el2.href = el2.href.replace(/%year%/,split[0] ); el2.href = el2.href.replace(/%monthnum%/,split[1] ); el2.href = el2.href.replace(/%25year%25/,split[0] ); el2.href = el2.href.replace(/%25monthnum%25/,split[1] ); el2.onclick = function () {var href=this.href; actual_click=href.substr(href.indexOf('#')+1); dhtmlHistory.add(href.substr(href.indexOf('#')+1), ''); central_category_post_list('',href.substring(href.indexOf('date_')+5)); return false;} // create fancy tooltips if the plugin is enabled if ( has_fp == true ) FancyTooltips.autoCreation(); el.appendChild(el2); } } } function kcalendar_daysInMonth(year,month) { if (month<0) { month+=12;year--; } if (month==3||month==5||month==8||month==10)return 30; if (month!=1)return 31; if (!(year%4))return 29; return 28; } function kcalendar_refresh(year,month) { if (isNaN(year)) { year=unixmonth.getFullYear(); month=unixmonth.getMonth(); } else { month--; } while (month<0 ) { month+=12;year--; } while (month>11) { month-=12;year++; } el=document.getElementById('calendar'); if (!el) { el2=document.getElementById('cal-calendar'); if (el2) { el=document.createElement('div'); el.id='calendar'; el3=el2.parentNode; el3.insertBefore(el,el2); el3.removeChild(el2); el.appendChild(el2); } } if (!el) return; els=el.childNodes; for (i=el.childNodes.length-1;i>-1;i--)el.removeChild(els[i]); cal=kcalendar_build(year,month,1); el.appendChild(cal); // apply link to post dates if (entries_cache[tocall]) { kcalendar_create_links(entries_cache[tocall],year,month); finalize_http(); } else { if (cal_first_execute) cal_first_execute=false; else { Effect.Fade('cal-calendar',{from:1.0, to:0.3}); cal_execute_appear=true; } global_year=year; global_month=year; var url = '.' + livecal_dir + 'kcalendar.php'; var pars = 'year='+shownDate.getFullYear()+'&month='+(shownDate.getMonth()+1)+'&min_year='+min_year+'&min_month='+min_month; var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: execute_http }); } } var global_year; var global_month; var cal_first_execute=true; var cal_execute_appear=false; function execute_http(req) { el=$('calendar'); entries_cache[tocall]=(req.responseText)? req.responseText.split(/\n/): []; kcalendar_create_links(entries_cache[tocall],global_year,global_month); finalize_http(); } function finalize_http() { if (cal_execute_appear) { Effect.Appear('cal-calendar'); cal_execute_appear=false; } el=$('calendar_spin'); if(el) el.parentNode.removeChild(el); e2=$('cal-calendar_caption'); e2.style.position='relative'; e2.style.visibility='visible'; }