function Calendar(){this.debug=false;this.construct(arguments[0])}Calendar.prototype.constructor=Calendar;Calendar.prototype={msie:false,msie6:false,index:null,type:null,weekStartDay:1,daysPerMonth:new Array(31,28,31,30,31,30,31,31,30,31,30,31),offsetX:0,table:null,opener:null,anchor:null,alertBox:null,timeOutDisplay:false,currentDate:new Date(),selectedDate:new Date(),cssClass:new Array("disabled","promotion","special","current_month","other_month"),construct:function(){var Calendar=this;this.msie=(jQuery.browser.msie)?true:false;this.msie6=(this.msie&&jQuery.browser.version.substr(0,1)=="6")?true:false;if(arguments.length==1&&typeof(arguments[0]=="object")){this.cssClass=arguments[0].cssClass||"";this.weekStartDay=arguments[0].weekStartDay||1;this.offsetX=arguments[0].offsetX||0}if(arguments.length==1&&typeof(arguments[0]=="object")){}this.setHTML();this.setInnerHTML();$(document).bind("click",function(e){Calendar.isClickedOut(e)})},control:function(){return{enabled:true,every:true,text:null,price:null,cssClass:""}},display:function(show){if(show){this.setPosition();this.setInnerHTML();if(this.msie){this.table.style.display="block"}else{$(this.table).show(500)}}else{if(this.msie){$(this.table).css({display:"none"})}else{$(this.table).hide(500)}}},displayAlert:function(priceText,stockText,controlText,cssClass,show){var Calendar=this;if(show&&((typeof(priceText)=="string"&&priceText.length>0)||(typeof(stockText)=="string"&&stockText.length>0)||(typeof(controlText)=="string"&&controlText.length>0))){text="";if(typeof(priceText)=="string"&&priceText!="null"&&priceText.length>0){text+='<span class="price-text">'+priceText+"</span>"}if(typeof(stockText)=="string"&&stockText!="null"&&stockText.length>0){text+='<span class="stock-text">'+stockText+"</span>"}if(typeof(controlText)=="string"&&controlText!="null"&&controlText.length>0){text+='<span class="control-text">'+controlText+"</span>"}this.alertBox.html(text);for(i=0;i<this.cssClass.length;i++){this.alertBox.toggleClass(this.cssClass[i],false)}this.alertBox.toggleClass(cssClass,true);if(this.timeOutDisplay){window.clearTimeout(this.timeOutDisplay);this.timeOutDisplay=false}this.alertBox.css({top:$(this.table).offset().top+($(this.table).height()/2)-(this.alertBox.height()/2),left:$(this.table).offset().left+$(this.table).width()+5});if(this.msie){$(this.alertBox).css({display:"block"})}else{this.alertBox.fadeIn(250)}}else{if(!this.timeOutDisplay&&(typeof(priceText)!="strig"||priceText.length==0)&&(typeof(stockText)!="strig"||stockText.length==0)&&(typeof(controlText)!="strig"||controlText.length==0)){this.timeOutDisplay=window.setTimeout(function(){if(this.msie){$(Calendar.alertBox).css({display:"none"})}else{Calendar.alertBox.fadeOut(250)}window.clearTimeout(Calendar.timeOutDisplay);Calendar.timeOutDisplay=false},250)}}},isClickedOut:function(e){element=e.target;bool=false;while(!bool&&undefined!=element){if(element==this.table||element==this.opener){bool=true;return true}else{if(element.tagName.toLowerCase()=="html"){bool=true;this.display(false);return true}}element=element.parentNode}},setAnchor:function(element){this.anchor=$(element)},setControlFunction:function(fn){this.control=fn},setIndex:function(index){this.index=index},setOpener:function(element,addHandler){var Calendar=this;this.opener=element;if(addHandler){$(this.opener).click(function(e){Calendar.display()})}},setPosition:function(){var Calendar=this;$(this.table).css({top:this.anchor.offset().top+(this.anchor.height()/2)-($(this.table).height()/2),left:this.anchor.offset().left+this.anchor.width()+3+Calendar.offsetX})},setSelectedDate:function(date){this.selectedDate=date},setType:function(type){this.type=type},setUpdateFunction:function(fn){this.update=fn},setHTML:function(){var Calendar=this;alertBox=jQuery('<span class="calendar alert"></span>');$("body").append(alertBox);this.alertBox=alertBox;thd=document.createElement("thead");thd.appendChild(document.createElement("tr"));thd.childNodes[0].appendChild(document.createElement("th"));thd.childNodes[0].appendChild(document.createElement("th"));thd.childNodes[0].appendChild(document.createElement("th"));thd.childNodes[0].childNodes[0].className="previous";thd.childNodes[0].childNodes[1].colSpan="5";thd.childNodes[0].childNodes[1].className="current";thd.childNodes[0].childNodes[2].className="next";thd.appendChild(document.createElement("tr"));thd.childNodes[1].className="day_abbr";for(i=0;i<7;i++){thd.childNodes[1].appendChild(document.createElement("th"));thd.childNodes[1].childNodes[i].setAttribute("title",translation.day[((i-1+Calendar.weekStartDay)%7)]);thd.childNodes[1].childNodes[i].innerHTML=translation.dayAbbr[((i-1+Calendar.weekStartDay)%7)]}tfo=document.createElement("tfoot");tfo.appendChild(document.createElement("tr"));tfo.childNodes[0].appendChild(document.createElement("th"));tfo.childNodes[0].childNodes[0].className="current";tfo.childNodes[0].childNodes[0].innerHTML=translation.dateToday;tfo.childNodes[0].childNodes[0].colSpan="7";tbd=document.createElement("tbody");for(i=0;i<6;i++){tbd.appendChild(document.createElement("tr"));for(j=0;j<7;j++){tbd.childNodes[i].appendChild(document.createElement("td"))}}this.table=document.createElement("table");this.table.className=this.cssClass;this.table.style.display="none";this.table.appendChild(thd);this.table.appendChild(tfo);this.table.appendChild(tbd);this.table.prv=thd.childNodes[0].childNodes[0];this.table.cur=thd.childNodes[0].childNodes[1];this.table.nxt=thd.childNodes[0].childNodes[2];this.table.tdy=tfo.childNodes[0].childNodes[0];this.table.thd=thd;this.table.tbd=tbd;document.body.appendChild(this.table);$(this.table.tbd).find("td").attr({"xml:price":"","xml:stock":"","xml:control":""});$(this.table.tbd).find("td").hover(function(){$(this).addClass("hover");Calendar.displayAlert($(this).attr("xml:price"),$(this).attr("xml:stock"),$(this).attr("xml:control"),$(this).attr("class"),true)},function(){$(this).removeClass("hover");Calendar.displayAlert(null,null,null,null,false)})},setInnerHTML:function(){var Calendar=this;switch(arguments.length){case 2:var y=arguments[1];var m=arguments[0];var d=this.selectedDate.getDate();break;case 3:var y=arguments[0];var m=arguments[1];var d=arguments[2];this.selectedDate=new Date(arguments[0],arguments[1],arguments[2]);break;case 0:default:var y=this.selectedDate.getFullYear();var m=this.selectedDate.getMonth();var d=this.selectedDate.getDate();break}this.daysPerMonth[1]=(((y%4==0)&&(y%100!=0))||(y%400==0))?29:28;var dsp_y=y;var dsp_m=m;var dsp_d=1;var m_first_d=new Date(y,m,1).getDay();var offset=0;offset=(m_first_d>=this.weekStartDay)?m_first_d-this.weekStartDay:7-this.weekStartDay+m_first_d;if(offset>0){dsp_m--;if(dsp_m<0){dsp_m=11;dsp_y--}dsp_d=this.daysPerMonth[dsp_m]-offset+1}var nxt_m=m+1;var nxt_m_y=y;if(nxt_m>11){nxt_m=0;nxt_m_y++}var lst_m=m-1;var lst_m_y=y;if(lst_m<0){lst_m=11;lst_m_y--}this.table.cur.innerHTML=translation.month[m]+" "+y;this.table.prv.onclick=function(){Calendar.setInnerHTML(lst_m,lst_m_y)};this.table.nxt.onclick=function(){Calendar.setInnerHTML(nxt_m,nxt_m_y)};firstMonthDay=new Date(y,m,1);lastMonthDay=new Date(y,m,this.daysPerMonth[m]);for(var i=0;i<7;i++){control=this.control(this.index,this.type,firstMonthDay,lastMonthDay,i,false);txt=(!control.enabled&&control.every)?" - "+translation.dateClosed:"";this.table.thd.childNodes[1].childNodes[i].setAttribute("title",translation.day[(i%7)]+txt);this.table.thd.childNodes[1].childNodes[i].className=(!control.enabled&&control.every)?"disabled":null;$(this.table.thd.childNodes[1].childNodes[i]).hover(function(){Calendar.displayAlert($(this).attr("title"),null,null,this.className,true)},function(){Calendar.displayAlert(null,null,null,null,false)})}delete (i);for(i=0;i<6;i++){for(j=0;j<7;j++){if(dsp_m==this.selectedDate.getMonth()&&dsp_d==this.selectedDate.getDate()&&dsp_y==this.selectedDate.getFullYear()){css_class="current_day"}else{if(dsp_m==m){css_class="current_month"}else{css_class="other_month"}}this.table.tbd.rows[i].cells[j].innerHTML=dsp_d;this.table.tbd.rows[i].cells[j].setAttribute("d",dsp_d);this.table.tbd.rows[i].cells[j].setAttribute("m",dsp_m+1);this.table.tbd.rows[i].cells[j].setAttribute("y",dsp_y);this.table.tbd.rows[i].cells[j].setAttribute("title","");this.table.tbd.rows[i].cells[j].className=css_class;this.table.tbd.rows[i].cells[j].onclick=function(){Calendar.update(Calendar.index,Calendar.type,new Date($(this).attr("y"),$(this).attr("m")-1,$(this).attr("d"),Calendar.selectedDate.getHours(),Calendar.selectedDate.getMinutes()));Calendar.display(false)};var control=this.control(this.index,this.type,new Date(dsp_y,dsp_m,dsp_d,0,0,0));text="";if(typeof(control.priceText)=="string"&&control.priceText.length>0){control.priceText=control.priceText.replace('"',"&quote;");text+=control.priceText+" "}if(typeof(control.stockText)=="string"&&control.stockText.length>0){control.stockText=control.stockText.replace('"',"&quote;");text+=control.stockText+" "}if(typeof(control.controlText)=="string"&&control.controlText.length>0&&!control.timePrice){control.controlText=control.controlText.replace('"',"&quote;");text+="("+control.controlText+")"}if(!control.enabled){if(text.length==0){text=translation.day[j]+" - "+translation.dateClosed}this.table.tbd.rows[i].cells[j].onclick=null}$(this.table.tbd.rows[i].cells[j]).attr({title:text,"xml:price":control.priceText,"xml:stock":control.stockText,"xml:control":control.controlText});if(control.cssClass!=null){this.table.tbd.rows[i].cells[j].className+=" "+control.cssClass}dsp_d++;if(dsp_d>this.daysPerMonth[dsp_m]){dsp_d=1;dsp_m++}if(dsp_m>11){dsp_m=0;dsp_y++}}}delete (i);if(!this.control(this.index,this.type,this.currentDate).enabled){$(this.table.tdy).addClass("disabled");$(this.table.tdy).click(function(){return false})}else{$(this.table.tdy).removeClass("disabled");$(this.table.tdy).click(function(){Calendar.update(Calendar.index,Calendar.type,new Date(Calendar.currentDate.getFullYear(),Calendar.currentDate.getMonth(),Calendar.currentDate.getDate(),Calendar.currentDate.getHours(),Calendar.currentDate.getMinutes()));Calendar.setInnerHTML()})}},update:function(){return false}};
