(function(){var C=YAHOO.util.Dom;var A=YAHOO.util.Event;var B=YAHOO.util.Element;var E=SODON.util.DateMath;SODON.widget.Calendar=function(H,F,G){this.init.apply(this,arguments)};SODON.widget.Calendar.cfg=function(F){SODON.widget.Calendar.cfg.superclass.constructor.apply(this,arguments)};YAHOO.extend(SODON.widget.Calendar.cfg,SODON.util.Config,{_DEFAULT_CONFIG:{LANGUAGE:"MON",TITLE_MON:"Календарь",TITLE_ENG:"Calendar",YEAR_MON:"жил",YEAR_ENG:"year",MONTH_MON:"сар",MONTH_ENG:"month",DATE_MON:"өдөр",DATE_ENG:"date",CLOSE_MON:"Хаах",CLOSE_ENG:"Close",CANCEL_MON:"Болих",CANCEL_ENG:"Cancel",SELECT_MON:"Сонгох",SELECT_ENG:"Select",CURRENT_FORMAT:null,SELECTED_DATE:null,CURRENT_DATE:null,MIN_DATE:new Date(1920,0,1,0,0,0,0),MAX_DATE:new Date(2020,0,1,0,0,0,0),TODAY:null,SHOW_TITLE:false,SHOW_CLOSEBUTTON:false,SHOW_YEARMONTH:true,SHOW_WEEKDAYS:true,SHOW_DAYS:true,SHOW_SELECTBUTTON:false,SHOW_CANCELBUTTON:false,CLOSEBUTTON_CLICK:null,PREVMONTHBUTTON_CLICK:null,NEXTMONTHBUTTON_CLICK:null,DAY_CLICK:null,SELECTBUTTON_CLICK:null,CANCELBUTTON_CLICK:null,POPUPBUTTON_CLICK:null,TEMPLATE:null,MONTHS_SHORT_MON:["1-р сар","2-р сар","3-р сар","4-р сар","5-р сар","6-р сар","7-р сар","8-р сар","9-р сар","10-р сар","11-р сар","12-р сар"],MONTHS_SHORT_ENG:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],MONTHS_LONG_MON:["Нэгдүгээр сар","Хоёрдугаар сар","Гуравдугаар сар","Дөрөвдүгээр сар","Тавдугаар сар","Зургадугаар сар","Долоодугаар сар","Наймдугаар сар","Есдүгээр сар","Аравдугаар сар","Арваннэгдүгээр сар","Арванхоёрдугаар сар"],MONTHS_LONG_ENG:["January","February","March","April","May","June","July","August","September","October","November","December"],CURRENT_MONTHS:null,WEEKDAYS_1CHAR_MON:["Д","М","Л","П","Б","Б","Н"],WEEKDAYS_1CHAR_ENG:["S","M","T","W","T","F","S"],WEEKDAYS_SHORT_MON:["Да","Мя","Лх","Пү","Ба","Бя","Ня"],WEEKDAYS_SHORT_ENG:["Su","Mo","Tu","We","Th","Fr","Sa"],WEEKDAYS_MEDIUM_MON:["Дав","Мяг","Лха","Пүр","Баа","Бям","Ням"],WEEKDAYS_MEDIUM_ENG:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],WEEKDAYS_LONG_MON:["Даваа","Мягмар","Лхагва","Пүрэв","Баасан","Бямба","Ням"],WEEKDAYS_LONG_ENG:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],CURRENT_WEEKDAYS:null,uniqueId:null,CLASSNAME_ID:null,POPUPBUTTON:null,ISDRAG:true,POSITION:{x:60,y:25},OUTPUT:null},setupConfig:function(){this._DEFAULT_CONFIG.TEMPLATE=D.TEMPLATE_1;this._DEFAULT_CONFIG.CURRENT_FORMAT="FORMAT_MIDDLELINE";this._DEFAULT_CONFIG.CURRENT_DATE=E.clearTime(new Date());this._DEFAULT_CONFIG.TODAY=E.clearTime(new Date());this._DEFAULT_CONFIG.CURRENT_MONTHS="MONTHS_SHORT";this._DEFAULT_CONFIG.CURRENT_WEEKDAYS="WEEKDAYS_SHORT";var F;for(F in this._DEFAULT_CONFIG){this.owner.Config[F]=this._DEFAULT_CONFIG[F]}}});SODON.widget.Calendar.cfg._CONSTANT={FORMAT_MIDDLELINE_MON:"yyyy-mm-dd",FORMAT_MIDDLELINE_ENG:"mm-dd-yyyy",FORMAT_SLASH_MON:"yyyy/mm/dd",FORMAT_SLASH_ENG:"mm/dd/yyyy",FORMAT_SHORT_MON:"mm-dd",FORMAT_SHORT_ENG:"mm/dd",FORMAT_MON_WITHOUT_WEEK:"FORMAT_MON_WITHOUT_WEEK",FORMAT_FULL_MON:"FORMAT_FULL_MON",FORMAT_FULL_ENG:"FORMAT_FULL_ENG",TEMPLATE_1:"TEMPLATE_1",TEMPLATE_2:"TEMPLATE_2"};var D=SODON.widget.Calendar.cfg._CONSTANT;SODON.widget.Calendar.prototype={id:null,oContainer:null,Config:null,STATUS:null,CLICKED_STATUS:null,UNDEFINED:"undefined",SHOW:"show",HIDE:"hide",CONTAINER_CLICKED:"container_clicked",POPUPBUTTON_CLICKED:"popupbutton_clicked",CLICKED_OUTSIDE:"clicked_outside",_parseArgs:function(G){var F={id:null,container:null,config:null};if(G&&G.length&&G.length>0){switch(G.length){case 1:F.id=null;F.container=G[0];F.config=null;break;case 2:if(YAHOO.lang.isObject(G[1])&&!G[1].tagName&&!(G[1] instanceof String)){F.id=null;F.container=G[0];F.config=G[1]}else{F.id=G[0];F.container=G[1];F.config=null}break;default:F.id=G[0];F.container=G[1];F.config=G[2];break}}else{}return F},init:function(I,G,H){var F=this._parseArgs(arguments);I=F.id;G=F.container;H=F.config;this.oContainer=C.get(G);this.id=I;this.Config={};this.cfg=new SODON.widget.Calendar.cfg(this);this.cfg.setupConfig();if(H){this.cfg.setConfig(H)}this.cfg.set("CURRENT_FORMAT",D[this.cfg.get("CURRENT_FORMAT")+"_"+this.cfg.get("LANGUAGE")]);this.cfg.set("CURRENT_MONTHS",this.cfg.get(this.cfg.get("CURRENT_MONTHS")+"_"+this.cfg.get("LANGUAGE")));this.cfg.set("CURRENT_WEEKDAYS",this.cfg.get(this.cfg.get("CURRENT_WEEKDAYS")+"_"+this.cfg.get("LANGUAGE")));C.addClass(this.oContainer,this.getClassNameId()+"cal-container")},render:function(){C.setStyle(this.oContainer,"display","");var F="";if(this.cfg.get("SHOW_TITLE")||this.cfg.get("SHOW_CLOSEBUTTON")){F+='<div id="'+this.getUniqueId()+'head" class="'+this.getClassNameId()+'cal-head">';if(this.cfg.get("SHOW_TITLE")){F+="<h1>"+this.cfg.get("TITLE_"+this.cfg.get("LANGUAGE"))+"</h1>"}if(this.cfg.get("SHOW_CLOSEBUTTON")){F+='<a href="javascript:void(0)" onclick="'+this.id+'.hideCalendar(); return false;"></a>'}F+="</div>"}F+='<div class="'+this.getClassNameId()+'cal-body">';if(this.cfg.get("SHOW_YEARMONTH")){F+=this.renderYearMonth()}if(this.cfg.get("SHOW_WEEKDAYS")){F+=this.renderWeekDays()}if(this.cfg.get("SHOW_DAYS")){F+=this.renderDays()}F+="</div>";if(this.cfg.get("SHOW_SELECTBUTTON")||this.cfg.get("SHOW_CANCELBUTTON")){F+=this.renderFoot()}this.oContainer.innerHTML=F;this.renderAfterInitEvents()},renderYearMonth:function(){var G="";G+='<div class="'+this.getClassNameId()+'cal-yearmonth">';G+='<div class="'+this.getClassNameId()+'cal-yearmonth-content">';if(this.cfg.get("TEMPLATE")==D.TEMPLATE_2){G+='<span id="'+this.getUniqueId()+'month-prev" class="prev"></span>';G+='<span id="'+this.getUniqueId()+'month-next" class="next"></span>';G+="<em>"+this.cfg.get("CURRENT_DATE").getFullYear()+" "+this.cfg.get("YEAR_"+this.cfg.get("LANGUAGE"))+", "+this.cfg.get("CURRENT_MONTHS")[this.cfg.get("CURRENT_DATE").getMonth()]+"</em>"}else{G+='<input id="'+this.getUniqueId()+'year" type="text" value="'+this.cfg.get("CURRENT_DATE").getFullYear()+'" />';G+='<span class="prevnext"><em id="'+this.getUniqueId()+'year-next" class="next"></em><em id="'+this.getUniqueId()+'year-prev" class="prev"></em></span>';G+="<span> "+this.cfg.get("YEAR_"+this.cfg.get("LANGUAGE"))+" </span>";G+='<select id="'+this.getUniqueId()+'month">';for(var F=0;F<12;F++){if(this.cfg.get("CURRENT_DATE").getMonth()==F){G+='<option value="'+F+'" selected="selected">'+this.cfg.get("CURRENT_MONTHS")[F]+"</option>"}else{G+='<option value="'+F+'">'+this.cfg.get("CURRENT_MONTHS")[F]+"</option>"}}G+="</select>";if(this.cfg.get("TEMPLATE")!=D.TEMPLATE_1){this.cfg.get("TEMPLATE")=D.TEMPLATE_1}}G+="</div>";G+="</div>";return G},renderWeekDays:function(){var G="";G+='<div class="'+this.getClassNameId()+'cal-weekdays">';G+='<div class="'+this.getClassNameId()+'cal-weekdays-content">';var F=0;while(F<this.cfg.get("CURRENT_WEEKDAYS").length){G+='<div class="'+this.getClassNameId()+'cal-weekdays-day"><em>'+this.cfg.get("CURRENT_WEEKDAYS")[F]+"</em></div>";F++}G+="</div>";G+="</div>";return G},renderDays:function(){var G="",H,I,J;G+='<div class="'+this.getClassNameId()+'cal-days">';G+='<div class="'+this.getClassNameId()+'cal-days-content">';H=E.findMonthStart(this.cfg.get("CURRENT_DATE"));I=E.findMonthEnd(this.cfg.get("CURRENT_DATE"));J=this.getWorkingDateStart();var F=0;while(F<42){if(E.before(J,H)||E.after(J,I)){G+='<div class="'+this.getClassNameId()+'cal-days-other"><a id="'+this.getUniqueId()+"day-"+J.getMonth()+J.getDate()+'" href="#">'+SODON.util.Math.fixNumber(J.getDate())+"</a></div>"}else{if(E.equals(J,this.cfg.get("TODAY"))){G+='<div class="'+this.getClassNameId()+'cal-days-today"><a id="'+this.getUniqueId()+"day-"+J.getMonth()+J.getDate()+'" href="#">'+SODON.util.Math.fixNumber(J.getDate())+"</a></div>"}else{if(this.cfg.get("SELECTED_DATE")&&E.equals(J,this.cfg.get("SELECTED_DATE"))){G+='<div class="'+this.getClassNameId()+'cal-days-day-s"><a id="'+this.getUniqueId()+"day-"+J.getMonth()+J.getDate()+'" href="#">'+SODON.util.Math.fixNumber(J.getDate())+"</a></div>"}else{G+='<div class="'+this.getClassNameId()+'cal-days-day"><a id="'+this.getUniqueId()+"day-"+J.getMonth()+J.getDate()+'" href="#">'+SODON.util.Math.fixNumber(J.getDate())+"</a></div>"}}}J=E.add(J,E.DAY,1);F++}G+="</div>";G+="</div>";return G},renderFoot:function(){var F="";F+='<div class="'+this.getClassNameId()+'cal-foot">';if(this.cfg.get("SHOW_SELECTBUTTON")){F+='<input id="'+this.getUniqueId()+'cal-selectbutton" type="button" value="'+this.cfg.get("SELECT_"+this.cfg.get("LANGUAGE"))+'" class="'+this.getClassNameId()+'cal-selectbutton" />'}if(this.cfg.get("SHOW_CANCELBUTTON")){F+='<input id="'+this.getUniqueId()+'cal-cancelbutton" type="button" value="'+this.cfg.get("CANCEL_"+this.cfg.get("LANGUAGE"))+'" class="'+this.getClassNameId()+'cal-cancelbutton" />'}F+="</div>";return F},renderAfterInitEvents:function(){var H=this;if(this.cfg.get("SHOW_CLOSEBUTTON")){A.on(this.getUniqueId()+"cal-closebutton","click",function(L){H.hideCalendar()})}if(this.cfg.get("SHOW_YEARMONTH")){A.on(this.getUniqueId()+"year-next","click",function(L){H.nextYear()});A.on(this.getUniqueId()+"year-prev","click",function(L){H.prevYear()});A.on(this.getUniqueId()+"month","change",function(L){H.cfg.get("CURRENT_DATE").setMonth(parseInt(this.value));H.render()});A.on(this.getUniqueId()+"month-prev","click",function(L){H.prevMonth()});A.on(this.getUniqueId()+"month-next","click",function(L){H.nextMonth()})}if(this.cfg.get("SHOW_DAYS")){var K;K=this.getWorkingDateStart();var I=0;while(I<42){var J=function(L){H.selectThisDay(this.date);H.print2Output();if(L.target){L.target.href="javascript:void(0)"}return false};if(this.cfg.get("DAY_CLICK")!=null){J=this.cfg.get("DAY_CLICK")}A.on(this.getUniqueId()+"day-"+K.getMonth()+K.getDate(),"click",J,this,{date:K});K=E.add(K,E.DAY,1);I++}}if(this.cfg.get("SHOW_SELECTBUTTON")){var G=function(L){H.print2Output();H.hideCalendar()};if(this.cfg.get("SELECTBUTTON_CLICK")!=null){G=this.cfg.get("SELECTBUTTON_CLICK")}A.on(this.getUniqueId()+"cal-selectbutton","click",G,this)}if(this.cfg.get("SHOW_CANCELBUTTON")){var F=function(L){H.clearOutput();H.hideCalendar()};if(this.cfg.get("SELECTBUTTON_CLICK")!=null){F=this.cfg.get("CANCELBUTTON_CLICK")}A.on(this.getUniqueId()+"cal-cancelbutton","click",F,this)}},nextYear:function(){var F=E.add(this.cfg.get("CURRENT_DATE"),E.YEAR,1);this.cfg.set("CURRENT_DATE",F);this.render()},prevYear:function(){var F=E.subtract(this.cfg.get("CURRENT_DATE"),E.YEAR,1);this.cfg.set("CURRENT_DATE",F);this.render()},nextMonth:function(){var F=E.add(this.cfg.get("CURRENT_DATE"),E.MONTH,1);this.cfg.set("CURRENT_DATE",F);this.render()},prevMonth:function(){var F=E.subtract(this.cfg.get("CURRENT_DATE"),E.MONTH,1);this.cfg.set("CURRENT_DATE",F);this.render()},selectThisDay:function(F){var J,K,H,I;K=this.getWorkingDateStart();H=E.findMonthStart(this.cfg.get("CURRENT_DATE"));I=E.findMonthEnd(this.cfg.get("CURRENT_DATE"));var G=0;while(G<42){J=C.get(this.getUniqueId()+"day-"+K.getMonth()+K.getDate());if(C.hasClass(J.parentNode,this.getClassNameId()+"cal-days-day-s")){C.removeClass(J.parentNode,this.getClassNameId()+"cal-days-day-s");if(E.before(K,H)||E.after(K,I)){C.addClass(J.parentNode,this.getClassNameId()+"cal-days-other")}else{if(E.equals(K,this.cfg.get("TODAY"))){C.addClass(J.parentNode,this.getClassNameId()+"cal-days-today")}else{C.addClass(J.parentNode,this.getClassNameId()+"cal-days-day")}}}K=E.add(K,E.DAY,1);G++}this.cfg.set("SELECTED_DATE",F);J=C.get(this.getUniqueId()+"day-"+F.getMonth()+F.getDate());C.removeClass(J.parentNode,this.getClassNameId()+"cal-days-day");C.removeClass(J.parentNode,this.getClassNameId()+"cal-days-other");C.removeClass(J.parentNode,this.getClassNameId()+"cal-days-today");C.addClass(J.parentNode,this.getClassNameId()+"cal-days-day-s")},getClassNameId:function(){if(this.cfg.get("CLASSNAME_ID")!=null){return this.cfg.get("CLASSNAME_ID")+"-"}return""},getUniqueId:function(){if(this.cfg.get("uniqueId")!=null){return this.cfg.get("uniqueId")+"-"}else{return this.oContainer.id+"-"}},getDateByFormat:function(F){if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_MIDDLELINE_MON){return F.getFullYear()+"-"+SODON.util.Math.fixNumber((F.getMonth()+1))+"-"+SODON.util.Math.fixNumber((F.getDate()))}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_MIDDLELINE_ENG){return SODON.util.Math.fixNumber((F.getMonth()+1))+"-"+SODON.util.Math.fixNumber((F.getDate()))+"-"+F.getFullYear()}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_SLASH_MON){return F.getFullYear()+"/"+SODON.util.Math.fixNumber((F.getMonth()+1))+"/"+SODON.util.Math.fixNumber((F.getDate()))}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_SLASH_ENG){return SODON.util.Math.fixNumber((F.getMonth()+1))+"/"+SODON.util.Math.fixNumber((F.getDate()))+"/"+F.getFullYear()}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_SHORT_MON){return SODON.util.Math.fixNumber((F.getMonth()+1))+"-"+SODON.util.Math.fixNumber((F.getDate()))}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_SHORT_ENG){return SODON.util.Math.fixNumber((F.getMonth()+1))+"/"+SODON.util.Math.fixNumber((F.getDate()))}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_FULL_MON){return F.getFullYear()+" оны "+SODON.util.Math.fixNumber((F.getMonth()+1))+" сарын "+SODON.util.Math.fixNumber((F.getDate()))+", "+this.cfg.get("WEEKDAYS_LONG_MON")[SODON.util.DateMath.fixWeekday(F.getDay())]+" гараг"}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_FULL_ENG){return this.cfg.get("WEEKDAYS_LONG_ENG")[F.getDay()]+" "+this.cfg.get("MONTHS_LONG_ENG")[F.getMonth()]+" "+SODON.util.Math.fixNumber((F.getDate()))+", "+F.getFullYear()}else{if(this.cfg.get("CURRENT_FORMAT")==D.FORMAT_MON_WITHOUT_WEEK){return F.getFullYear()+" оны "+SODON.util.Math.fixNumber((F.getMonth()+1))+" сарын "+SODON.util.Math.fixNumber((F.getDate()))}}}}}}}}}},closeCalendar:function(){C.setStyle(this.oContainer,"display","none");this.oContainer.innerHTML=""},showCalendar:function(){C.setStyle(this.oContainer,"display","");this.setStatus(this.SHOW)},hideCalendar:function(){C.setStyle(this.oContainer,"display","none");this.setStatus(this.HIDE)},print2Output:function(){if(this.cfg.get("SELECTED_DATE")!=null){var F=C.get(this.cfg.get("OUTPUT"));F.value=this.getDateByFormat(this.cfg.get("SELECTED_DATE"))}},clearOutput:function(){var F=C.get(this.cfg.get("OUTPUT"));F.value=""},getWorkingDateStart:function(){var F,G;F=E.findMonthStart(this.cfg.get("CURRENT_DATE"));G=E.findMonthStart(this.cfg.get("CURRENT_DATE")).getDay();if(G==0){G=7}return E.subtract(F,E.DAY,(G-1))},getStatus:function(){return this.STATUS},getClickedStatus:function(){return this.CLICKED_STATUS},setStatus:function(F){this.STATUS=F},setClickedStatus:function(F){this.CLICKED_STATUS=F}};SODON.widget.CalendarPopup=function(H,F,G){this.init.apply(this,arguments)};YAHOO.extend(SODON.widget.CalendarPopup,SODON.widget.Calendar,{init:function(L,G,I){var H=this;var F=this._parseArgs(arguments);L=F.id;G=F.container;I=F.config;var K=document.createElement("div");K.id=G;C.insertBefore(K,C.getFirstChild(document.getElementsByTagName("body")[0]));this.oContainer=K;this.id=L;this.Config={};this.cfg=new SODON.widget.Calendar.cfg(this);this.cfg.setupConfig();if(I){this.cfg.setConfig(I)}this.cfg.set("CURRENT_FORMAT",D[this.cfg.get("CURRENT_FORMAT")+"_"+this.cfg.get("LANGUAGE")]);this.cfg.set("CURRENT_MONTHS",this.cfg.get(this.cfg.get("CURRENT_MONTHS")+"_"+this.cfg.get("LANGUAGE")));this.cfg.set("CURRENT_WEEKDAYS",this.cfg.get(this.cfg.get("CURRENT_WEEKDAYS")+"_"+this.cfg.get("LANGUAGE")));this.cfg.set("SHOW_TITLE",I.SHOW_TITLE===undefined?true:I.SHOW_TITLE);this.cfg.set("SHOW_CLOSEBUTTON",I.SHOW_CLOSEBUTTON===undefined?true:I.SHOW_TITLE);this.cfg.set("SHOW_SELECTBUTTON",I.SHOW_SELECTBUTTON===undefined?true:I.SHOW_TITLE);this.cfg.set("SHOW_CANCELBUTTON",I.SHOW_CANCELBUTTON===undefined?true:I.SHOW_TITLE);if(this.cfg.get("POPUPBUTTON")==null){this.cfg.set("POPUPBUTTON",this.getUniqueId()+"cal-popupbutton")}var J=C.get(this.cfg.get("POPUPBUTTON"));C.addClass(this.oContainer,this.getClassNameId()+"cal-container");C.addClass(this.oContainer,this.getClassNameId()+"cal-container-popup");C.setStyle(this.oContainer,"display","none");C.setStyle(this.oContainer,"position","absolute");C.setStyle(this.oContainer,"left",(C.getX(J)+this.cfg.get("POSITION")["x"])+"px");C.setStyle(this.oContainer,"top",(C.getY(J)+this.cfg.get("POSITION")["y"])+"px");this.setStatus(this.UNDEFINED);this.setClickedStatus(this.UNDEFINED);this.initEvents()},initEvents:function(){var G=this;var F=this.cfg.get("POPUPBUTTON");var I=this.cfg.get("POPUPBUTTON_CLICK");var H=function(J){if(G.getStatus()==G.UNDEFINED){G.render();G.setDrag();G.setStatus(G.SHOW)}else{G.toggleCalendar()}G.setClickedStatus(G.POPUPBUTTON_CLICKED)};if(I!=null){H=I}A.on(F,"click",H);A.on(this.oContainer,"click",function(J){G.setClickedStatus(G.CONTAINER_CLICKED)});A.on("body","click",function(J){if(G.getClickedStatus()!=G.POPUPBUTTON_CLICKED&&G.getClickedStatus()!=G.CONTAINER_CLICKED){G.setClickedStatus(G.CLICKED_OUTSIDE)}if(G.getStatus()==G.SHOW&&G.getClickedStatus()==G.CLICKED_OUTSIDE){G.hideCalendar()}G.setClickedStatus(G.UNDEFINED)})},setDrag:function(){if(this.cfg.get("ISDRAG")){var G=this.getUniqueId()+"head";var F=new YAHOO.util.DD(this.oContainer);F.setHandleElId(G);C.setStyle(G,"cursor","move")}},toggleCalendar:function(){if(this.getStatus()==this.SHOW){this.hideCalendar()}else{if(this.getStatus()==this.HIDE){this.showCalendar()}}}})})();