text: !function(t){"use strict";var e=function(){function e(e,o){this.settings=t.extend(!0,t.fn.calendarSwitch.defaults,o||{}),this.element=e,this.init()}return e.prototype={init:function(){var e=this;e.selectors=e.settings.selectors,e.sections=e.selectors.sections,e.index=e.settings.index,e.comfire=e.settings.comfireBtn;t(e.sections).append("<div class='headerWrapper'><div class='headerTip'>请选择入住离店日期</div><div class='comfire'>完成</div></div><table class='dateZone'><tr><td class='colo'>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td class='colo'>六</td></tr></table><div class='tbody'></div>"),t(e.sections).find(".headerWrapper").css({height:"50px","line-height":"50px",width:"100%",background:"#fff",position:"fixed","z-index":"9999"}),t(e.sections).find(".headerTip").css({"text-align":"left","line-height":"50px","margin-left":"10px","font-size":"15px"}),t(e.sections).find(e.comfire).css({height:"26px","line-height":"26px",width:"50px",color:"#2EB6A8",position:"absolute",right:"10px","text-align":"center","font-size":"14px",cursor:"pointer",top:"11px",border:"1px solid #2EB6A8","border-radius":"4px"});for(var o=0;o<e.index;o++){var s=o;t(e.sections).find(".tbody").append("<p class='ny1'></p><table class='dateTable'></table>");var n=new Date;n.setMonth(n.getMonth()+s);var i=n.getFullYear(),a=n.getMonth(),r=new Date(i,a,1),c=r.getDay(),l=a+1;l<10?t(e.sections).find(".ny1").eq(s).text(i+"年0"+l+"月"):t(e.sections).find(".ny1").eq(s).text(i+"年"+l+"月");var d=[];d=e._isLeapYear(i)?new Array(31,29,31,30,31,30,31,31,30,31,30,31):new Array(31,28,31,30,31,30,31,31,30,31,30,31);for(var p=c+d[a],f=Math.ceil(p/7),h=0;h<f;h++)t(e.sections).find(".dateTable").eq(s).append("<tr></tr>");t(e.sections).find(".dateTable").eq(s).find("tr").each(function(e,o){for(var s=0;s<7;s++)t(this).append("<td></td>")});for(var u=t(e.sections).find(".dateTable").eq(s).find("td"),v=0;v<d[a];v++)u.eq(c++).text(v+1)}e._initselected(),e.element.on("click",function(t){t.preventDefault(),e._slider(e.sections)}),t(e.comfire).on("click",function(o){o.preventDefault(),t(e.sections).find(".tbody .rz").each(function(o,s){if("离店"==t(this).text()){t(e.sections).find(".tbody .rz").each(function(o,s){if("入住"==t(this).text()){var n=parseInt(t(this).parent().text().replace(/[^0-9]/gi,""));n<10&&(n="0"+n);for(var i=t(this).parents("table").prev("p").text().split(""),a=[],r=[],c="",l="",d=0;d<e.index;d++){var p=d;a.push(i[p])}c=a.join("");for(var d=5;d<7;d++)r.push(i[d]);l=r.join(""),t("#startDate").val(c+"-"+l+"-"+n)}if("离店"==t(this).text()){var n=t(this).parent().text().split("离")[0];n<10&&(n="0"+n);for(var f=t(this).parents("table").prev("p").text().split(""),h=[],u=[],v="",g="",d=0;d<4;d++)h.push(f[d]);v=h.join("");for(var d=5;d<7;d++)u.push(f[d]);if(g=u.join(""),t("#endDate").val(v+"-"+g+"-"+n),parseInt(t("#startDate").val().replace(/[^0-9]/gi,""))==parseInt(t("#endDate").val().replace(/[^0-9]/gi,""))){var x=t("#startDate").val(),b=new Date(x.replace(/-/g,"/")),m=new Date;m=new Date(b.getTime()+864e5);var D=m.getFullYear(),z=m.getMonth()+1,k=m.getDate();t("#endDate").val(D+"-"+z+"-"+k)}}a=[],r=[],h=[],u=[]});var n=t(".lidian_hover").text().replace(/[^0-9]/gi,"");t(".NumDate").text(n);var i=t("#startDate").val();t("#endDate").val();if(i)e._slider(e.sections),e._callback();else{var a=new Date,r=a.getFullYear(),c=a.getMonth()+1,l=a.getDate();t("#startDate").val(r+"-"+c+"-"+l),a=new Date(a.getTime()+864e5);var r=a.getFullYear(),c=a.getMonth()+1,l=a.getDate();t("#endDate").val(r+"-"+c+"-"+l),t(".NumDate").text("1"),e._slider(e.sections),e._callback()}}})})},_isLeapYear:function(t){return t%4==0&&(t%100!=0||t%400==0)},_slider:function(e){var o=this;o.animateFunction=o.settings.animateFunction,"fadeToggle"==o.animateFunction?t(e).fadeToggle():"slideToggle"==o.animateFunction?t(e).slideToggle():"toggle"==o.animateFunction&&t(e).toggle()},_initselected:function(){var e=this;e.comeColor=e.settings.comeColor,e.outColor=e.settings.outColor,e.daysnumber=e.settings.daysnumber;var o=(new Date).getDate(),s=[],n=[];t(e.sections).find(".dateTable").eq(0).find("td").each(function(s,n){t(this).text()==o&&(t(this).append('</br><p class="rz">入住</p>'),""!=t(this).next().text()?t(this).next().append('</br><p class="rz">离店</p>'):t(".dateTable").eq(1).find("td").each(function(e,o){if(""!=t(this).text())return t(this).append('</br><p class="rz">离店</p>'),!1}),e._checkColor(e.comeColor,e.outColor))}),t(e.sections).find(".tbody").find("td").each(function(e,o){""!=t(this).text()&&s.push(o)});for(var i=0;i<o-1;i++)t(s[i]).css("color","#ccc");if(e.daysnumber){for(var i=o-1;i<o+parseInt(e.daysnumber);i++)n.push(s[i]);for(var i=o+parseInt(e.daysnumber);i<t(s).length;i++)t(s[i]).css("color","#ccc")}else for(var i=o-1;i<t(s).length;i++)n.push(s[i]);e._selectDate(n)},_checkColor:function(e,o){for(var s=this,n=t(s.sections).find(".rz"),i=0;i<n.length;i++)"入住"==n.eq(i).text()?n.eq(i).closest("td").css({background:e,color:"#fff"}):n.eq(i).closest("td").css({background:o,color:"#fff"})},_callback:function(){var e=this;e.settings.callback&&"function"===t.type(e.settings.callback)&&e.settings.callback()},_selectDate:function(e){var o=this;o.comeColor=o.settings.comeColor,o.outColor=o.settings.outColor,o.comeoutColor=o.settings.comeoutColor,o.sections=o.selectors.sections;var s,n,i,a=0;t(e).on("click",function(r){if(r.stopPropagation(),0==a)t(o.sections).find(".hover").remove(),t(o.sections).find(".tbody").find("p").remove(".rz"),t(o.sections).find(".tbody").find("br").remove(),t(e).css({background:"#fff",color:"#333333"}),t(this).append('<p class="rz">入住</p>'),s=t(e).index(t(this)),o._checkColor(o.comeColor,o.outColor),a=1,t(o.sections).find(".rz").each(function(e,o){"入住"==t(this).text()&&(t(this).parent("td").append('<span class="hover ruzhu_hover">选择离店日期</span>'),t(this).parent("td").css("position","relative"))}),t(".hover").css({position:"absolute",left:"-17px",top:"0px"}),t(".ruzhu_hover").css({width:"100%",height:"41px",left:"0px",top:"-45px",background:"#434949",color:"#fff","z-index":"9999"});else if(1==a){if(t(o.sections).find(".rz").each(function(e,o){"入住"==t(this).text()&&(t(this).parent("td").find(".ruzhu_hover").remove(),t(this).parent("td").css("position","relative"))}),a=0,i=t(e).index(t(this)),s>=i)return t(o.sections).find(".hover").remove(),t(o.sections).find(".tbody").find("p").remove(".rz"),t(o.sections).find(".tbody").find("br").remove(),t(e).css({background:"#fff",color:"#333333"}),t(this).append('<p class="rz">入住</p>'),s=t(e).index(t(this)),o._checkColor(o.comeColor,o.outColor),a=1,t(o.sections).find(".rz").each(function(e,o){"入住"==t(this).text()&&(t(this).parent("td").append('<span class="hover ruzhu_hover">选择离店日期</span>'),t(this).parent("td").css("position","relative"))}),t(".hover").css({position:"absolute",left:"-17px",top:"0px"}),void t(".ruzhu_hover").css({width:"100%",height:"41px",left:"0px",top:"-45px",background:"#434949",color:"#fff","z-index":"9999"});if(n=Math.abs(i-s),0==n&&(n=1),s<i)for(t(this).append('<p class="rz">离店</p>'),s+=1;s<i;s++)t(e[s]).css({background:o.comeoutColor,color:"#333333"});else if(s==i);else if(s>i)for(t(o.sections).find(".rz").text("离店"),t(this).append('<p class="rz">入住</p>'),i+=1;i<s;i++)t(e[i]).css({background:o.comeoutColor,color:"#333333"});t(o.sections).find(".rz").each(function(e,o){"离店"==t(this).text()&&(t(this).parent("td").append('<span class="hover lidian_hover">共'+n+"晚</span>"),t(this).parent("td").css("position","relative"))}),t(".hover").css({position:"absolute",left:"-17px",top:"0px"}),t(".ruzhu_hover").css({width:"200%",left:"0px",top:"-24px",background:"#434949",color:"#fff","z-index":"9999"}),t(".lidian_hover").css({width:"100%",left:"0px",top:"-24px",background:"#434949",color:"#fff"}),o._slider("firstSelect");var c=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],l=new Date(t("#startDate").val()),d=new Date(t("#endDate").val());t(".week").text(c[l.getDay()]),t(".week1").text(c[d.getDay()]),o._checkColor(o.comeColor,o.outColor)}})}},e}();t.fn.calendarSwitch=function(o){return this.each(function(){var s=t(this),n=s.data("calendarSwitch");if(n||s.data("calendarSwitch",n=new e(s,o)),"string"===t.type(o))return n[o]()})},t.fn.calendarSwitch.defaults={selectors:{sections:"#calendar"},index:4,animateFunction:"toggle",controlDay:!1,daysnumber:"30",comeColor:"blue",outColor:"red",comeoutColor:"#0cf",callback:"",comfireBtn:".comfire"}}(jQuery);