if(!window.ie){ var el = $('kir_cal_ie_iframe'); el.parentNode.removeChild(el); } var kir_calendars = new Array(); var test = ''; var prev_selected = 0; getCal = function(el_name){ calendar_num = el_name; el = $(el_name); if(!$defined(kir_calendars[el_name])) kir_calendars[el_name] = new cal(el); var obj = kir_calendars[el_name]; var coord = el.getCoordinates(); var x = coord.left; var y = coord.top-(-coord.height)-(-2); if($('kir_calendar').style.display == '' && $('kir_calendar').getStyle('top').toInt() == y && $('kir_calendar').getStyle('left').toInt() == x){ $('kir_calendar').style.display = 'none'; return false; } obj.setCoord(x, y); obj.date = obj.initDate(el.value); obj.reDraw(); return false; } cal = function(el){ this.box = el; this.monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31); this.year_div = document.getElementById('cal_year'); this.month_div = document.getElementById('cal_month'); this.month_out = document.getElementById('cal_month_out'); this.div = $('kir_calendar'); this.init(); } cal.prototype.initDate = function(string){ var date = parse_date_to_object(string); this.year = date.getFullYear(); this.month = date.getMonth()+1; this.day = date.getDate(); return date; } cal.prototype.init = function(string){ if(document.getElementById('cal_hidden')){ var hidden = document.getElementById('cal_hidden'); var hidden_box = document.getElementById('empty_day'); var clone = false; for(var i=0;i<6;i++){ clone = hidden.cloneNode(true); clone.id = 'cal_hidden_'+i; hidden_box.appendChild(clone); } hidden_box.removeChild(hidden); var day = document.getElementById('cal_day'); var day_box = document.getElementById('normal_day'); for(var i=1;i<32;i++){ clone = day.cloneNode(true); clone.innerHTML = i; clone.id = 'cal_day_'+i; day_box.appendChild(clone); } day_box.removeChild(day); } } cal.prototype.setFormat = function(string){ this.format = string; } cal.prototype.getLastDay = function(){ var add = 0; if(this.month == 2 && this.year % 4 == 0) add = 1; return this.monthLength[this.month-1]-(-add); } cal.prototype.changeYear = function(add){ this.year = this.year-(-add); this.date.setFullYear(this.year); this.reDraw(); } cal.prototype.setCoord = function(x, y){ this.x = x; this.y = y; document.getElementById('kir_calendar').style.top = y+'px'; document.getElementById('kir_calendar').style.left = x+'px'; } cal.prototype.changeMonth = function(add){ this.month = this.month-(-add); if(this.month ==13){ this.month = 1; this.year++; } if(this.month == 0){ this.month = 12; this.year--; } this.date.setDate(1); this.date.setMonth(this.month-1); this.date.setFullYear(this.year); this.reDraw(); } cal.prototype.showDebug = function(){ alert('|'+this.date.getFullYear()+'-'+this.date.getMonth()+'-'+this.date.getDate()+'-'+this.year+'-'+this.month+'-'+this.day); } cal.prototype.showFirstBlocks = function(){ this.date.setDate(1); var week = this.date.getDay(); week = (week+6) % 7; this.date.setDate(this.day); var last = this.getLastDay(); for(var i=0;i 24 || min >= 60 || hour < 0 || min < 0) need_default = 1; } if (need_default) { if (default_option == -1) return null; if (default_option == 0 || default_option == null) hour = min = 0; if (default_option == 1) { var now = new Date(); hour = now.getHours(); min = now.getMinutes(); } } return {0: hour, 1: min}; } function format_date_string(year, month, day) { calDate = new Date(year, month-1, day); // SET THE DATE RETURNED TO THE USER day = calDate.getDate(); month = calDate.getMonth()+1; year = calDate.getFullYear(); var monthString = month_names[calDate.getMonth()]; var ofMonthString = of_month_names[calDate.getMonth()]; var monthAbbrev = monthString.substring(0,3); var weekday = weekdayList[calDate.getDay()]; var weekdayAbbrev = weekday.substring(0,3); outDate = calDateFormat; regexp = /\\(.)/g; //new RegExp(v); outDate = outDate.replace(regexp, function (str,ch) {return ("@" + String.fromCharCode(ch.charCodeAt(0)+128)); } ); // RETURN TWO DIGIT DAY if (calDateFormat.indexOf("d") != -1) { day = makeTwoDigit(day); outDate = jsReplace(outDate, "d", day); } // RETURN ONE OR TWO DIGIT DAY WITH SUFFIX else if (calDateFormat.indexOf("jS") != -1) { suffix = day % 10; if (suffix == 1) suffix = 'st' else if (suffix == 2) suffix = 'nd' else if (suffix == 3) suffix = 'rd' else suffix = 'th'; outDate = jsReplace(outDate, "jS", day+suffix); } // RETURN ONE OR TWO DIGIT DAY else if (calDateFormat.indexOf("j") != -1) { outDate = jsReplace(outDate, "j", day); } // RETURN TWO DIGIT MONTH if (calDateFormat.indexOf("m") != -1) { month = makeTwoDigit(month); outDate = jsReplace(outDate, "m", month); } // RETURN ONE OR TWO DIGIT MONTH else if (calDateFormat.indexOf("n") != -1) { outDate = jsReplace(outDate, "n", month); } // RETURN FOUR-DIGIT YEAR if (calDateFormat.indexOf("Y") != -1) { outDate = jsReplace(outDate, "Y", year); } // RETURN TWO-DIGIT YEAR else if (calDateFormat.indexOf("y") != -1) { var yearString = "" + year; var yearString = yearString.substring(2,4); outDate = jsReplace(outDate, "y", yearString); } // RETURN FOUR-DIGIT YEAR else if (calDateFormat.indexOf("Y") != -1) { outDate = jsReplace(outDate, "Y", year); } // RETURN DAY OF MONTH (Initial Caps) if (calDateFormat.indexOf("F") != -1) { outDate = jsReplace(outDate, "F", monthString); } if (calDateFormat.indexOf("f") != -1) { outDate = jsReplace(outDate, "f", ofMonthString); } // RETURN DAY OF MONTH 3-DAY ABBREVIATION (Initial Caps) if (calDateFormat.indexOf("M") != -1) { outDate = jsReplace(outDate, "M", monthAbbrev); } // RETURN WEEKDAY (Initial Caps) if (calDateFormat.indexOf("l") != -1) { outDate = jsReplace(outDate, "l", weekday); } // RETURN WEEKDAY 3-DAY ABBREVIATION (Initial Caps) if (calDateFormat.indexOf("D") != -1) { outDate = jsReplace(outDate, "D", weekdayAbbrev); } regexp = /@(.)/g; outDate = outDate.replace(regexp, function (str,ch) { return ("\\" + String.fromCharCode(ch.charCodeAt(0)-128)); } ); return outDate; } // ENSURE THAT VALUE IS TWO DIGITS IN LENGTH function makeTwoDigit(inValue, isOneDigit) { var numVal = parseInt(inValue, 10); // VALUE IS LESS THAN TWO DIGITS IN LENGTH if (numVal < 10 && !isOneDigit) { // ADD A LEADING ZERO TO THE VALUE AND RETURN IT return("0" + numVal); } else { return numVal; } } // REPLACE ALL INSTANCES OF find WITH replace // inString: the string you want to convert // find: the value to search for // replace: the value to substitute // // usage: jsReplace(inString, find, replace); // example: jsReplace("To be or not to be", "be", "ski"); // result: "To ski or not to ski" // function jsReplace(inString, find, replace) { var outString = ""; if (!inString) { return ""; } // REPLACE ALL INSTANCES OF find WITH replace if (inString.indexOf(find) != -1) { // SEPARATE THE STRING INTO AN ARRAY OF STRINGS USING THE VALUE IN find t = inString.split(find); // JOIN ALL ELEMENTS OF THE ARRAY, SEPARATED BY THE VALUE IN replace return (t.join(replace)); } else { return inString; } }