var Library = (function(){var Element = (function(){function isValidElement(element){var isValid = false;if(element.nodeType && element.nodeType == 1 && element.nodeName){ isValid = true; }return isValid;}function isValidTag(tag){var isValid = false;var tags = ["a","div","fieldset","form","h1","h2","h3","h4","h5","h6","input","label","li","legend","option","optgroup","p","select","span","table","tbody","textarea","td","tfoot","th","thead","tr","ul","ol"];tags.foreach(function(element){if(element == tag){ isValid = true; return; }});return isValid;}function initDOMElement(element){if(isValidElement(element)){if(element.extend){element.extend(Library.HTMLExtension.Methods).extend(Library.HTMLExtension.Properties);switch(element.nodeName.toLowerCase()){case "a": element.extend(Library.AnchorExtension.Methods).extend(Library.AnchorExtension.Properties); break;case "input": element.extend(Library.InputExtension.Methods).extend(Library.InputExtension.Properties); break;case "select": element.extend(Library.SelectExtension.Methods).extend(Library.SelectExtension.Properties); break;case "table": element.extend(Library.TableExtension.Methods).extend(Library.TableExtension.Properties); element.initTable(); break;default: break;}}}return element;}function create(element,options){if(Library.isString(element) && isValidTag(element)){element = document.createElement(element);element.extend = Library.extendMe;initDOMElement(element);if(Library.isObject(options)){ element.extend(options); }return element;}return;}function initialise(element,options){if(Library.isObject(element) && isValidElement(element)){element.extend = Library.extendMe;initDOMElement(element);if(Library.isObject(options)){ element.extend(options); }return element;}return;}function get(element,options){if(Library.isString(element)){element = element.trim();if(element.length > 1 && element.substr(0,1) == "#"){var eid = element.substr(1,element.length);if(document.getElementById(eid)){element = document.getElementById(eid);if(!element.extend){ initialise(element); }if(Library.isObject(options)){ element.extend(options); }return element;}}}}return {isValidElement: isValidElement,isValidTag: isValidTag,create: create,initialise: initialise,get: get};})();function getCursorPosition(e){function getPosition(eventObject){if(!eventObject){ eventObject = window.event; }if(eventObject){var MouseX = eventObject.clientX;var MouseY = eventObject.clientY;var ScrollOffsetsXY = getScrollXY();var ScrollX = ScrollOffsetsXY[0];var ScrollY = ScrollOffsetsXY[1];var cursorTop = (MouseY + ScrollY);var cursorLeft = (MouseX + ScrollX);return [cursorLeft, cursorTop];}return;}function getScrollXY(){var scrOfX = 0, scrOfY = 0;if(typeof(window.pageYOffset) == "number") {scrOfY = window.pageYOffset;scrOfX = window.pageXOffset;}else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {scrOfY = document.body.scrollTop;scrOfX = document.body.scrollLeft;}else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {scrOfY = document.documentElement.scrollTop;scrOfX = document.documentElement.scrollLeft;}return [scrOfX, scrOfY];}return getPosition(e);}function isNumber(num){ return (!isNaN(num) && !(num == "")); };function isString(str){ return (typeof(str) == "string"); };function isFunction(fn){ return (fn && typeof(fn) == "function"); };function isObject(obj){ return (obj && typeof(obj) == "object"); };function isBoolean(bool){ return (typeof(bool) == "boolean" && (bool == true || bool == false)); };function isNull(variable){ return (variable == null); };function jQueryLoaded(){ return (typeof jQuery !== "undefined"); };function showObjectSchema(obj){if(isObject(obj)){var str = "";for( var p in obj ){ str = str+""+ p+" = "+obj[p]+"\n"; }window.alert(str);} else{ window.alert("Not an Object"); }}function extend(target,object){if(Library.isObject(target) && Library.isObject(object)){for(p in object){ target[p] = object[p]; }}return target;}function extendMe(obj){ return extend(this,obj); }function disableBubbling(e){if(e && e.stopPropagation){ e.stopPropagation(); }else { event.cancelBubble = true; }}function getCurrentFileName(){ return window.location.toString().substr((window.location.toString().lastIndexOf("/") + 1), (window.location.toString().length - window.location.toString().lastIndexOf("/"))); }function preload(arr,dir){dir = dir.trim();arr.foreach(function(element){var img = new Image();if(dir !== ""){ img.src = dir+"/"+element; }else{ img.src = element; }});}function initialiseLibrary(){Array.prototype.extend = extendMe;Array.prototype.extend(Library.ArrayExtension.Methods).extend(Library.ArrayExtension.Properties);Date.prototype.extend = extendMe;Date.prototype.extend(Library.DateExtension.Methods).extend(Library.DateExtension.Properties);Number.prototype.extend = extendMe;Number.prototype.extend(Library.NumberExtension.Methods).extend(Library.NumberExtension.Properties);String.prototype.extend = extendMe;String.prototype.extend(Library.StringExtension.Methods).extend(Library.StringExtension.Properties);window.Library = window.$lib = Library;}return {Element: Element,createElement: Element.create,initElement: Element.initialise,getElement: Element.get,isNumber: isNumber,isString: isString,isFunction: isFunction,isObject: isObject,isBoolean: isBoolean,isNull: isNull,isValidElement: Element.isValidElement,isValidTag: Element.isValidTag,jQueryLoaded: jQueryLoaded,showObjectSchema: showObjectSchema,extend: extend,extendMe: extendMe,disableBubbling: disableBubbling,getCursorPosition: getCursorPosition,getCurrentFileName: getCurrentFileName,preload: preload,initialise: initialiseLibrary};})();Library.ArrayExtension = (function(){function foreach(action){if(Library.isFunction(action)){for(var i=0; i<this.length; i++){ action( this[i] , i , this ); }}}function inArray(val,insensitive){var isin = false;this.foreach(function(element){if(insensitive && insensitive == true){ element = element.toLowerCase(); val = val.toLowerCase(); }if(element == val){ isin = true; return; }});return isin;}function merge(arr){var parentArray = this;if(arr.foreach){ arr.foreach(function(element){ parentArray.push(element); }); }return parentArray;}var methods = {foreach: foreach,inArray: inArray,merge: merge};var properties = {  };return { Methods: methods , Properties: properties };})();Library.DateExtension = (function(){function getAmPm(){ if(this.getHours() > 11){ return "pm"; } else{ return "am"; } }function getDayName(){ return this.days[this.getDay()]; }function getDayShortName(){ return this.getDayName().slice(0,3); }function getDaySuffix(){ return this.suffixes[this.getDate()-1]; }function getMonthName(){ return this.months[this.getMonth()]; }function getMonthShortName(){ return this.getMonthName().slice(0,3); }function getDaysInMonth(){ var d = new Date(this.getFullYear(), this.getMonth() + 1, 0); return d.getDate(); }function getFirstWeekday(){ var d = new Date(this.getFullYear(), this.getMonth(), 1); return d.getDay(); }function getWeeksInMonth(){ var d = new Date(this.getFullYear(), this.getMonth(), 1); return Math.ceil(6 - (42 - (d.getDay() + d.getDaysInMonth())) / 7); }function getHour(){ var t = this.getHours(); if(t < 10){ return "0"+t; } else{ return ""+t+""; } } function getMinute(){ var t = this.getMinutes(); if(t < 10){ return "0"+t; } else{ return ""+t+""; } } function getSecond(){ var t = this.getSeconds(); if(t < 10){ return "0"+t; } else{ return ""+t+""; } } function getMillisecond(){ var t = this.getMilliseconds(); if(t < 10){ return "00"+t; } else{ return ""+t+""; } } function getNextDate(period){ return this.get_next_or_previous_date(period,1); }function getPreviousDate(period){ return this.get_next_or_previous_date(period,-1); }function get_next_or_previous_date(period,interval){switch(period.toLowerCase()){case "day": return new Date(this.getFullYear(), this.getMonth(), this.getDate()+interval, this.getHours(), this.getMinutes(), this.getSeconds()); break;case "month": return new Date(this.getFullYear(), this.getMonth()+interval, this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()); break;case "year": return new Date(this.getFullYear()+interval, this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()); break;case "hour": return new Date(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours()+interval, this.getMinutes(), this.getSeconds()); break;case "minute": return new Date(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes()+interval, this.getSeconds()); break;case "second": return new Date(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()+interval); break;default: return null;}}function copy(){ return new Date(this.getTime()); }function isLeapYear(){var d = new Date(this.getFullYear(), 1, 29);if(d.getMonth() == 1){ return true; }else{ return false; }}function format(str){switch(str){case "dd/mm/yyyy": return this.getDate() +"/"+ (this.getMonth()+1) +"/"+ this.getFullYear(); break;case "yyyy/mm/dd": return this.getFullYear() +"/"+ (this.getMonth()+1) +"/"+ this.getDate(); break;case "mm/dd/yyyy": return this.getMonth() +"/"+ this.getDate() +"/"+ this.getFullYear(); break;case "h:m ampm": return this.getHour() +":"+ this.getMinute() +" "+ this.getAmPm(); break;default: return this.getDayName() +" "+ this.getDate() +""+ this.getDaySuffix() +" "+ this.getMonthName() +" "+ this.getFullYear() +" "+ this.getHour() +":"+ this.getMinute() +":"+ this.getSecond() +" "+ this.getAmPm(); break;}}function getCalendarArray(){var calDays = new Array(41); for(i=1; i<=this.getDaysInMonth(); i++){ calDays[(i)+this.getFirstWeekday()-1] = i; }return calDays;}var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];var suffixes = ["st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st"];var methods = {copy: copy,isLeapYear: isLeapYear,getAmPm: getAmPm,getDayName: getDayName,getDayShortName: getDayShortName,getDaySuffix: getDaySuffix,getMonthName: getMonthName,getMonthShortName: getMonthShortName,getDaysInMonth: getDaysInMonth,getFirstWeekday: getFirstWeekday,getWeeksInMonth: getWeeksInMonth,getHour: getHour,getMinute: getMinute,getSecond: getSecond,getMillisecond: getMillisecond,getNextDate: getNextDate,getPreviousDate: getPreviousDate,get_next_or_previous_date: get_next_or_previous_date,getCalendarArray: getCalendarArray,format: format};var properties = {days: days,months: months,suffixes: suffixes};return { Methods: methods , Properties: properties };})();Library.NumberExtension = (function(){function isEven(){ return (this%2 == 0); }function isOdd(){ return (!this.isEven()); }var methods = {isEven: isEven,isOdd: isOdd};var properties = {  };return { Methods: methods , Properties: properties };})();Library.StringExtension = (function(){function changeToCamelCase(){if(this.trim().length && this.trim().length > 0){if(this.trim().indexOf(" ")){var words = this.split(" ");if(words.length && words.length > 0){var tempStr = "";for(var i=0; i<words.length; i++){tempStr += words[i].substr(0,1).toUpperCase() +""+ words[i].substr(1,words[i].length).toLowerCase()+" ";}return tempStr.trim();}}else{ return this.substr(0,1).toUpperCase() +""+ this.substr(1,this.length).toLowerCase(); }}return;}function getJSONObject(){return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(this.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + this + ')');}function isDate(){function getDaysInMonth(mth,yr){ if(isValidMonth(mth) && isValidYear(yr)){ mth--; var d = new Date(yr, mth+1, 0); return d.getDate(); } return; }function isValidDay(dy,mth,yr){ if(dy > 0 && dy <= getDaysInMonth(mth,yr)){ return true; } else{ return false; } }function isValidMonth(mth){ if(mth > 0 && mth < 13){ return true; } else{ return false; } }function isValidYear(yr){ if(yr >=minYear && yr <= maxYear){ return true; } else{ return false; } }var minYear = 1900;var maxYear = 2100;if(this.indexOf("/") > 0){var dateParts = this.split("/");if(dateParts.length == 3){var day = dateParts[0]*1; var month = dateParts[1]*1; var year = dateParts[2]*1;if(Library.isNumber(day) && Library.isNumber(month) && Library.isNumber(year)){if(isValidDay(day,month,year)){ return true; }}}}return false;}function changeToDate(){if(this.isDate && this.isDate()){var dateParts = this.split("/");if(dateParts.length == 3){var day = dateParts[0]*1; var month = dateParts[1]*1; var year = dateParts[2]*1;if(Library.isNumber(day) && Library.isNumber(month) && Library.isNumber(year)){return new Date(month+"/"+day+"/"+year);}}}return;}function changeToBoolean(){var str = this.trim();return (str == "true" || str == "1" || str == "yes" || str == "on");}function trim(str){return str.leftTrim().rightTrim();}function leftTrim(str){return str.replace(/^\s\s*/, "");}function rightTrim(str){var i = str.length;while(/\s/.test(str.charAt(--i)));return str.slice(0, i + 1);}var methods = {toCamelCase: changeToCamelCase,getJSONObject: getJSONObject,toJSON: getJSONObject,isDate: isDate,toDate: changeToDate,trim: function(){ return trim(this); },leftTrim: function(){ return leftTrim(this); },rightTrim: function(){ return rightTrim(this); },toBoolean: changeToBoolean};var properties = {  };return { Methods: methods , Properties: properties };})();Library.HTMLExtension = (function(){function addClass(classStr){if(Library.isString(classStr) && classStr.trim() !== "" && !this.hasClass(classStr)){var arr = this.getClassArray();arr.push(classStr);this.className = getClassString(arr);}return this;}function removeClass(classStr){if(Library.isString(classStr) && classStr.trim() !== "" && this.hasClass(classStr)){var arr = this.getClassArray();arr.foreach(function(element,index){if(classStr == element){ arr.splice(index,1); }});this.className = getClassString(arr);}return this;}function hasClass(classStr){if(Library.isString(classStr) && classStr.trim() !== ""){if(this.getClassArray().inArray(classStr)){ return true; }}return false;}function getClassArray(){var arr = new Array();if(this.className.trim() !== ""){if(this.className.trim().indexOf(" ")){var parts = this.className.split(" ");parts.foreach(function(element){ arr.push(element); });}else{ arr.push(this.className); }}return arr;}function getClassString(arr){var str = "";arr.foreach(function(element){ str += element +" "; });return str.trim();}function append(obj){if(Library.isObject(obj)){ this.appendChild(obj); return this; }if(Library.isString(obj) || Library.isNumber(obj) || Library.isBoolean(obj)){ this.appendChild(document.createTextNode(""+obj.toString()+"")); return this; }}function appendTo(obj){if(Library.isObject(this) && Library.isObject(obj)){ obj.appendChild(this); return this; }}function removeChildNodes(){if(this.hasChildNodes()){while(this.hasChildNodes()){ this.removeChild(this.firstChild); }}return this;}function getNextChild(){ var n = this; do{ n = n.nextSibling; } while (n && n.nodeType != 1);  return n; }function getPreviousChild(){ var p = this; do{ p = p.previousSibling; } while(p && p.nodeType != 1); return p; }function setHTML(html,append){if($lib.isString(html) && html.trim() !== ""){if(append && append == true){ this.innerHTML += html }else{ this.innerHTML = html; }}return this;}function appendHTML(html){this.setHTML(html,true);return this;}function setStyle(styles){if($lib.isObject(styles)){$lib.extend(this.style,styles);}return this;};function isElementInDocument(){if(!this.parentNode || this.parentNode.nodeType == 11){ return false; }return true;}function removeMe(){if(this.inDocument()){if(this.parentNode){ this.parentNode.removeChild(this); }}}function hasOverflow(){var curOverflow = this.style.overflow;if( !curOverflow || curOverflow === "visible" ) { this.style.overflow = "hidden"; }var isOverflowing = this.clientWidth < this.scrollWidth || this.clientHeight < this.scrollHeight;this.style.overflow = curOverflow;return isOverflowing;}var methods = {addClass: addClass,hasClass: hasClass,getClassArray: getClassArray,removeClass: removeClass,append: append,appendTo: appendTo,removeChildNodes: removeChildNodes,nextChild: getNextChild,previousChild: getPreviousChild,setHTML: setHTML,appendHTML: appendHTML,setStyle: setStyle,inDocument: isElementInDocument,remove: removeMe,hasOverflow: hasOverflow};var properties = {  };return { Methods: methods , Properties: properties };})();Library.AnchorExtension = (function(){function openNewWindow(){if(this.getProtocol() == "http" || this.getProtocol() == "https"){ window.open(this.href); return false; }}function getProtocol(){var protocol = "unknown";if(this.href && this.href != ""){if(this.href.indexOf(":")){ protocol = this.href.substr(0,this.href.indexOf(":")); }}return protocol;}var methods = {openNewWindow: openNewWindow,getProtocol: getProtocol};var properties = {  };return { Methods: methods , Properties: properties };})();Library.InputExtension = (function(){function hasText(){if(this.value !== ""){ return true; }return false;}var methods = {hasText: hasText};var properties = {  };return { Methods: methods , Properties: properties };})();Library.SelectExtension = (function(){function addOption(val,txt){Library.Element.create("option" , { value: val, title: txt }).append(txt).appendTo(this);return this;}function selectOption(val){for(i=0; i<this.options.length; i++){if(this.options[i].value == val){ this.options[i].selected = true; }else{ this.options[i].selected = false; }}return this;}function isValidSelection(){if(this.selectedIndex > 0){ return true; } else{ return false; }}function getSelectedOptionText(){return this.options[this.options.selectedIndex].innerHTML;}var methods = {addOption: addOption,selectOption: selectOption,isValidSelection: isValidSelection,getSelectedOptionText: getSelectedOptionText};var properties = {  };return { Methods: methods , Properties: properties };})();Library.TableExtension = (function(){function initTable(){this.thead = Library.createElement("thead");this.append(this.thead);this.tfoot = Library.createElement("tfoot");this.append(this.tfoot);this.tbody = Library.createElement("tbody");this.append(this.tbody);this.cellPadding = 0;this.cellSpacing = 0;}function setCaption(caption){if(isString(caption) && caption != ""){if(!this.caption){ this.createCaption(); }this.caption.innerHTML = caption;}else{ this.deleteCaption(); }}function getSection(tSection){if(tSection && tSection != ""){switch(tSection){case "head": return this.thead; break;case "foot": return this.tfoot; break;default: return this.tbody; break;}}return this.tbody;}function insertRow(tSection,opts){var row = Library.createElement("tr",opts);row.getNextRow = function(){var r = this.nextChild();if(r && r.nodeName && r.nodeName.toLowerCase() == "tr"){ return r; }return;};row.getPreviousRow = function(){var r = this.previousChild();if(r && r.nodeName && r.nodeName.toLowerCase() == "tr"){ return r; }return;};row.addCell = function(content,opts){var row = this;var tag = "td";if(this.parentNode.nodeName.toLowerCase() == "thead"){ tag = "th"; }var cell = Library.createElement(tag,opts);cell.getNextCell = function(){var c = this.nextChild();if(c && c.nodeName && c.nodeName.toLowerCase() == "td"){ return c; }return;};cell.getPreviousCell = function(){var c = this.previousChild();if(c && c.nodeName && c.nodeName.toLowerCase() == "td"){ return c; }return;};if(content){ cell.append(content); }this.append(cell);return row;};row.getCell = function(index){ if(index > 0){ return this.getCells()[index-1]; } return; };row.getCells = function (){var row = this;if(row && row.nodeName && row.nodeName.toLowerCase() == "tr"){ return row.cells; }return;};row.getCellCount = function(){ return this.getCells().length; };row.getFirstCell = function(){ return this.getCell(1); };row.getLastCell = function(){ return this.getCell(this.getCellCount()); };var tSection = this.getSection(tSection);tSection.append(row);return row;}function getRow(index,tSection){ if(index > 0){ return this.getRows(tSection)[index-1]; } return; }function getRows(tSection){var rows = this.getSection(""+tSection+"").rows;Library.extend(rows,Library.ArrayExtension.Methods);return rows;}function getRowCount(tSection){ return this.getRows(tSection).length; }function getFirstRow(tSection){ return this.getRow(1,""+tSection+""); }function getLastRow(tSection){ return this.getRow(this.getRowCount(tSection),""+tSection+""); }var methods = {initTable: initTable,setCaption: setCaption,getSection: getSection,insertRow: insertRow,getRow: getRow,getRows: getRows,getRowCount: getRowCount,getFirstRow: getFirstRow,getLastRow: getLastRow};var properties = {  };return { Methods: methods , Properties: properties };})();Library.Calendar = function(options){function isValidMonth(mth){if(Library.isNumber(mth)){if(mth > 0 && mth <=12){ return true; } else { return false; }}else{ return false; }}function isValidYear(yr){if(Library.isNumber(yr)){if(yr.toString().length == 4){if(yr >= this.minyear && yr <= this.maxyear){ return true; } else { return false; }}else { return false; }}else { return false; }}function getCalendarDate(mth,yr){var d = new Date(); d.setDate(1);if(this.isValidMonth(mth) && this.isValidYear(yr)){d.setMonth(mth-1); d.setYear(yr);}return d;}function getCalendarTable(mth,yr){var d = this.getCalendarDate(mth,yr);var calArr = d.getCalendarArray();var table = Library.createElement("table").addClass("calendar");table.insertRow("head").addCell(d.getMonthName() +" "+ d.getFullYear(),{ colSpan: 7 });table.getLastRow("head").getLastCell().addClass("period");table.insertRow("head");d.days.foreach(function(element){table.getLastRow("head").addCell(element.substr(0,1).toUpperCase());});var today = new Date();for(r=1; r<=d.getWeeksInMonth(); r++){table.insertRow();for(c=0; c<7; c++){if(Library.isNumber(calArr[(r-1) * 7 + c])){var day = calArr[(r-1) * 7 + c];var dayDate = new Date( d.getFullYear(), d.getMonth(), day );table.getLastRow().addCell(day,{id: "day"+day,date: dayDate,setInputField: setInputField,calendar: this,title: (function(){ return (new Date( d.getFullYear(), d.getMonth(), day )).format(); })(),onmouseover: function() { this.addClass("over"); },onmouseout: function() { this.removeClass("over"); },onclick: (function(calObj){if(Library.isFunction(calObj.dayClick)) { return calObj.dayClick; }})(this)});table.getLastRow().getLastCell().addClass("day");if(dayDate.format("dd/mm/yyyy") == today.format("dd/mm/yyyy")){table.getLastRow().getLastCell().addClass("today");}}else {table.getLastRow().addCell(" ").getLastCell().addClass("empty");}}}var mSelect = this.getMonthSelect(d.getMonth()+1);var ySelect = this.getYearSelect(d.getFullYear());table.insertRow("foot").addCell( Library.createElement("div").append(mSelect).append(ySelect).addClass("calendar-select") , { colSpan: 7 } );if(!(today.getMonth() == (d.getMonth()) && today.getFullYear() == d.getFullYear()) && ($lib.isBoolean(options.showReset) && options.showReset == true)){table.insertRow("foot").addCell(Library.createElement("a",{href: "javascript:;",title: "Reset Calendar",calendar: this,onclick: function(){ this.calendar.update(); }}).append("Reset Calendar").addClass("calendar-reset"),{ colSpan: 7 });}return table;}function getCloseCalendarButton(){return Library.createElement("a",{href: "javascript:;",title: "Close",calendar: this,onclick: function(){ this.calendar.remove(); }}).addClass("calendar-close").appendHTML("<span>x</span>");}function displayCalendar(mth,yr){this.remove();this.removeChildNodes();this.getCloseCalendarButton().appendTo(this);this.append(this.getCalendarTable(mth,yr)).appendTo(this.container);}function displayCalendarAtCursor(e,mth,yr){var topPos = 0; var leftPos = 0;var coords = Library.getCursorPosition(e);if(coords && coords.length == 2){ topPos = coords[1]; leftPos = coords[0]; }this.setStyle({position: "absolute",top: topPos+"px",left: leftPos+"px"}).show(mth,yr);}function updateCalendar(opts){this.removeChildNodes();this.getCloseCalendarButton().appendTo(this);this.append(this.getCalendarTable(opts.month,opts.year)).appendTo(this.container);if($lib.isFunction(this.onUpdate)){ this.onUpdate(opts); }}function setInputField(input,format,remove){if(Library.isString(input)){ input = Library.getElement("#"+ input); }if(input && input.nodeName && input.nodeName.toLowerCase() == "input"){ input.value = this.date.format(format); }if(remove == true){ this.calendar.remove(); }}function getMonthSelect(mth){var mSelect = Library.createElement("select",{ id: "calendar-month" , calendar: this , onchange: calendarSelect_onChange }).addClass("calendar-month");Date.prototype.months.foreach(function(element,index){ mSelect.addOption(index+1, element); });mSelect.selectOption(mth);return mSelect;}function getYearSelect(yr){var ySelect = Library.createElement("select",{ id: "calendar-year" , calendar: this , onchange: calendarSelect_onChange }).addClass("calendar-year");for(var y=this.minyear; y<=this.maxyear; y++){ ySelect.addOption(y,y); }ySelect.selectOption(yr);return ySelect;}function calendarSelect_onChange(){var mth; var yr;if(this.id == "calendar-month"){mth = this.value;yr = Library.getElement("#calendar-year").value;}if(this.id == "calendar-year"){mth = Library.getElement("#calendar-month").value;yr = this.value;}this.calendar.update({ month: mth , year: yr });}var defaults = {container: document.body,id: "calendar-container",minyear: (new Date()).getFullYear()-4,maxyear: (new Date()).getFullYear()+4,dayClick: function(){ window.alert("You selected: "+ this.date.format("dd/mm/yyyy")); this.calendar.remove(); }};if(Library.isObject(options)){ Library.extend(defaults,options); }var Methods = {dayClick: defaults.dayClick,getCloseCalendarButton: getCloseCalendarButton,getCalendarDate: getCalendarDate,getCalendarTable: getCalendarTable,getMonthSelect: getMonthSelect,getYearSelect: getYearSelect,isValidMonth: isValidMonth,isValidYear: isValidYear,show: displayCalendar,showAtCursor: displayCalendarAtCursor,update: updateCalendar,onUpdate: defaults.onUpdate};var Properties = {container: defaults.container,maxyear: defaults.maxyear,minyear: defaults.minyear};return Library.createElement("div",{ id: defaults.id }).addClass("calendar").extend(Methods).extend(Properties);};Library.PopupBox = function(defaults){var container = $lib.initElement(document.body);function showPopupBox(){if( ($lib.isBoolean(defaults.cover) && defaults.cover) || ($lib.isObject(defaults.cover) && $lib.isBoolean(defaults.cover.show) && defaults.cover.show) ){this.cover.enable();}container.append(this);return this;}function removePopupBox(){if(this.inDocument()){ container.removeChild(this); }if( ($lib.isBoolean(defaults.cover) && defaults.cover) || ($lib.isObject(defaults.cover) && $lib.isBoolean(defaults.cover.show) && defaults.cover.show) ){if(this.cover.active == true){ this.cover.disable(); }}return this;}function getHeadSection(defs){var h = $lib.createElement("div").addClass("head");h.closeButton = $lib.createElement("a",{href: "javascript:;",title: "Close",onclick: function(){popup.remove();if($lib.isFunction(defs.close)){ defs.close(); }}}).appendHTML("<span>X</span>");h.setTitle = function(txt){this.removeChildNodes().append( $lib.createElement("h3").append(txt) ).append(this.closeButton);};h.setTitle(defs.title);return h;}function getContentSection(defs){var c = $lib.createElement("div").addClass("content");if($lib.isString(defs.content) && defs.content.trim() !== ""){ c.appendHTML(defs.content); } else if($lib.isObject(defs.content) && $lib.isValidElement(defs.content)){ c.append(defs.content); } return c;}function getFootSection(defs){var f = $lib.createElement("div").addClass("foot");var popupType = defs.type;if(defs.type == "alert" || defs.type == "error" || defs.type == "success"){ popupType = "information"; }switch(popupType){case "information":if($lib.isFunction(defs.dismiss)){ defs.dismiss.text = "Dismiss"; defs.dismiss.click = defs.dismiss; defs.dismiss.remove = true; }else if($lib.isObject(defs.dismiss)){if(!$lib.isString(defs.dismiss.text) || defs.dismiss.text.trim() == ""){ defs.dismiss.text = "Dismiss"; }if(!$lib.isBoolean(defs.dismiss.remove)){ defs.dismiss.remove = true; }}f.dismissButton = getButton({ text: defs.dismiss.text , click: defs.dismiss.click , id: "btnDismiss" , remove: defs.dismiss.remove }).addClass("button").addClass("dismiss");f.dismissButton.appendTo(f);break;case "confirmation":if($lib.isFunction(defs.confirm)){ defs.confirm.text = "Yes"; defs.dismiss.click = defs.confirm; defs.confirm.remove = true; }else if($lib.isObject(defs.confirm)){if(!$lib.isString(defs.confirm.text) || defs.confirm.text.trim() == ""){ defs.confirm.text = "Yes"; }if(!$lib.isBoolean(defs.confirm.remove)){ defs.confirm.remove = true; }}f.confirmButton = getButton({ text: defs.confirm.text , click: defs.confirm.click , id: "btnConfirm" , remove:  defs.confirm.remove }).addClass("button").addClass("confirm");f.confirmButton.appendTo(f);if($lib.isFunction(defs.cancel)){ defs.cancel.text = "No"; defs.cancel.click = defs.cancel; defs.cancel.remove = true; }else if($lib.isObject(defs.cancel)){if(!$lib.isString(defs.cancel.text) || defs.cancel.text.trim() == ""){ defs.cancel.text = "No"; }if(!$lib.isBoolean(defs.cancel.remove)){ defs.cancel.remove = true; }}f.cancelButton = getButton({ text: defs.cancel.text , click: defs.cancel.click , id: "btnCancel" , remove:  defs.cancel.remove }).addClass("button").addClass("cancel");f.cancelButton.appendTo(f);break;}return f;}function getButton(opts){if(!$lib.isString(opts.text) || opts.text.trim() == ""){ opts.text = "[-No Text-]"; }if(!$lib.isString(opts.type) || opts.type.trim() == ""){ opts.type = "button"; }var button = $lib.createElement("input",{type: opts.type,value: opts.text,id: opts.id,popup: popup,onclick: function(){if($lib.isBoolean(opts.remove) && opts.remove){ popup.remove(); }if($lib.isFunction(opts.click)){ opts.click(); }}});return button;}if(!$lib.isString(defaults.type) || defaults.type.trim() == ""){ defaults.type = ""; }if(!$lib.isString(defaults.title) || defaults.title.trim() == ""){ defaults.title = "Alert Box"; }var headSection = getHeadSection(defaults);var contentSection = getContentSection(defaults);var footSection = getFootSection(defaults);var popup = $lib.createElement("div",{ type: defaults.type }).addClass("popupbox").append(headSection).append(contentSection).append(footSection);if($lib.isString(defaults.type) && defaults.type.trim() !== ""){ popup.addClass(defaults.type); }var PageCover = (function(defs){function displayCover(){ container.append(this); this.active = true; return this; }function removeCover(){if(this.active == true && this.inDocument()){container.removeChild(cover);this.active = false;}return this;}var coverID = "page-cover";var cover = $lib.createElement("div",{ id: coverID , active: false }).setStyle({margin: "0",width: "100%",height: "100%",position: "fixed",top: "0",left: "0",zIndex: "2",backgroundColor: "#000",filter: "alpha(opacity=40)",opacity: ".40"});if($lib.isObject(defs.cover) && $lib.isFunction(defs.cover.click)){ cover.extend({ onclick: defs.cover.click }); }return cover.extend({enable: displayCover,disable: removeCover,popup: popup});})(defaults);var Methods = {show: showPopupBox,remove: removePopupBox,button: getButton};var Properties = {head: headSection,content: contentSection,foot: footSection,cover: PageCover};return popup.extend(Methods).extend(Properties);};if(Library && Library.isObject(Library) && Library.initialise){Library.initialise();}
