var datepicker="";datepicker={monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],daysInMonth:[31,28,31,30,31,30,31,31,30,31,30,31],cal:new Object(),insert:function(b,l){if(!$(b)){if(this.cal[b]){alert("error object with this id already exists in script");return}if(!l.relativeTo){alert("error - no relativeTo specified");return}if(!$(l.relativeTo)){alert("error cannot find relativeTo element");return}if(!l.inputFunc||typeof(l.inputFunc)!="function"){alert("error inputFunc must be a function that returns an array [dayVal,monthVal,yearVal]");return}if(!l.outputFunc||typeof(l.outputFunc)!="function"){alert("error outputFunc must be a function");return}this.cal[b]=new Object();this.cal[b].inputFunc=l.inputFunc;this.cal[b].outputFunc=l.outputFunc;if(l.node){if(!$(l.node)){alert("error - node not found");return}$(l.node).insert(this.calHTML.replace(/{ID_REPLACE}/g,b))}else{$(l.relativeTo).parentNode.insert(this.calHTML.replace(/{ID_REPLACE}/g,b))}}else{alert("ID("+b+") already in document");return}this.cal[b].selected=[null,null,null];var d=this.cal[b].inputFunc();if(!d.length||d.length!=3){alert("error - must define a 0,1,2 day,month and year in inputFunc (length 3)");return}var a;for(var e=2;e>=0;e--){a=parseInt(d[e]);if(d[e]!=a){this.cal[b].selected[e]=null;continue}if(a<=0&&e!=1){this.cal[b].selected[e]=null;continue}if(e==2){if(a<1000||a>9999){this.cal[b].selected=null;continue}}else{if(e==1){a--;if(a>11){this.cal[b].selected=null;continue}}else{if(e==0){if(d[1]==1&&d[2]%4==0){this.daysInMonth[1]=29}else{this.daysInMonth[1]=28}if(a>this.daysInMonth[a]){this.cal[b].selected=null;continue}}}}this.cal[b].selected[e]=a}this.cal[b].defaultSelectToday=l.defaultSelectToday;if(!this.cal[b].selected){this.cal[b].selected=[null,null,null]}var k=2;if(l.initState){k=2}this.cal[b].state=k;this.setupContent(b,2);if(l.position&&l.relativeTo){var f=$(l.relativeTo).getDimensions();var c=$(l.relativeTo).positionedOffset();var j=null;var h=null;switch(l.position){case"topright":j=c.left+f.width;h=c.top;break;case"bottomleft":j=c.left;h=c.top+f.height;break;case"bottomright":j=c.left+f.width;h=c.top+f.height;break;default:alert("invalid options.position set");return}if(j!=null&&h!=null){if(l.positionAdjust){if(l.positionAdjust.left){j+=l.positionAdjust.left}if(l.positionAdjust.top){h+=l.positionAdjust.top}}$(b).setStyle({left:j+"px",top:h+"px"})}else{alert("newLeft and or newTop is null");return}}else{alert("error - must define position and relativeto");return}this.cal[b].blurClick=function(i){if(datepicker.cal[b].animEffect.state!="finished"){datepicker.cal[b].animEffect.cancel()}if(i){var m=Event.element(i);var n=$(m).up("div");if(n){if(n.id){if(n.id==b||n.id==b+"_tCont"){return}}}}datepicker.cal[b].animEffect=new Effect.Fade(b,{duration:0.5,afterFinish:function(){delete datepicker.cal[b];$(b).remove()}});Event.stopObserving(document.body,"mousedown",datepicker.cal[b].blurClick)};Event.observe(document.body,"mousedown",this.cal[b].blurClick);$(b).setStyle({visibility:"hidden"});$(b).show();var g=$(b).getDimensions();g.height-=5;$(b).hide();$(b).setStyle({visibility:"visible"});this.cal[b].animEffect=new Effect.Parallel([new Effect.Appear(b),new Effect.Scale(b,100,{scaleFrom:25,scaleContent:false,scaleMode:{originalWidth:g.width,originalHeight:g.height}})],{duration:0.5,afterFinish:function(){datepicker.cal[b].curHeight=$(b).getHeight()-5;$(b).setStyle({height:datepicker.cal[b].curHeight+"px"})}})},setupContent:function(h,d){if(!this.cal[h]){alert("Error - ID("+h+") was not initiated");return}var b=new Date();if(typeof(ipb.vars.datepicker_compToBoardOffset)=="number"){var f=b.getTimezoneOffset()*60+ipb.vars.datepicker_compToBoardOffset;b.setTime(b.getTime()+f*1000)}var q=[b.getDate(),b.getMonth(),b.getFullYear()];var o=true;if(typeof(this.cal[h].selected[2])!="number"&&typeof(this.cal[h].selected[1])!="number"&&typeof(this.cal[h].selected[0])!="number"){o=this.cal[h].defaultSelectToday}else{if(typeof(this.cal[h].selected[2])=="number"){q[2]=this.cal[h].selected[2]}else{if(this.cal[h].state==0){o=false}}if(typeof(this.cal[h].selected[1])=="number"){q[1]=this.cal[h].selected[1]}else{if(this.cal[h].state==1){o=false}}if(typeof(this.cal[h].selected[0])=="number"){q[0]=this.cal[h].selected[0]}else{if(this.cal[h].state==2){o=false}}}var k;if($(h+"_newTable")){$(h+"_newTable").setAttribute("id",h+"_oldTable");$(h+"_oldTable").setAttribute("style","position:absolute");k=new Element("table",{id:h+"_newTable",style:"display:none"})}else{k=new Element("table",{id:h+"_newTable"})}if(d==2){k.setAttribute("class","cipb_datepicker_calendar");var e=new Date();e.setFullYear(q[2],q[1],1);var l=e.getDay();var j="background-color:#9BB2C8; color:#363636; border:1px solid #2B4F74;";var n=1;var c=false;var r=false;for(var a=0;a<7;a++){k.insert("<tr></tr>");if(a==0){k.getElementsByTagName("tr")[a].insert("<th>Su</th><th>Mo</th><th>Tu</th><th>We</th><th>Th</th><th>Fr</th><th>Sa</th>");continue}if(r){k.getElementsByTagName("tr")[a].setAttribute("style","display:none")}else{k.getElementsByTagName("tr")[a].setAttribute("style","")}k.getElementsByTagName("tr")[a].insert("<td></td><td></td><td></td><td></td><td></td><td></td><td></td>");for(var g=0;g<7;g++){if(!c){if(g!=l){k.getElementsByTagName("td")[g+((a-1)*7)].innerHTML=""}else{k.getElementsByTagName("td")[g+((a-1)*7)].innerHTML='<a href="#" onclick="datepicker.select(\''+h+"',["+n+","+q[1]+","+q[2]+'],2); this.blur(); return false;">'+n+"</a>";if(o&&n==q[0]){k.getElementsByTagName("td")[g+((a-1)*7)].getElementsByTagName("a")[0].setAttribute("style",j)}n++;c=true}}else{if(r){k.getElementsByTagName("td")[g+((a-1)*7)].innerHTML=""}if(n<=this.daysInMonth[q[1]]){k.getElementsByTagName("td")[g+((a-1)*7)].innerHTML='<a href="#" onclick="datepicker.select(\''+h+"',["+n+","+q[1]+","+q[2]+'],2); this.blur(); return false;">'+n+"</a>"}if(o&&n==q[0]){k.getElementsByTagName("td")[g+((a-1)*7)].getElementsByTagName("a")[0].setAttribute("style",j)}if(n==this.daysInMonth[q[1]]){r=true}n++}}}$(h+"_tCont").insert({before:k});$(h).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="datepicker.transition(\''+h+"',-1); this.blur(); return false;\">"+this.monthLabels[q[1]]+" "+q[2]+"</a>"}else{if(d==1){k.setAttribute("class","cipb_datepicker_calendar_other");var m;var t=-1;if(o){t=q[1]}for(m=0;m<12;m++){if(m%3==0){k.insert('<tr><td colspan="2"></td><td colspan="2"></td><td colspan="2"></td><td colspan="2"></td></tr>')}k.getElementsByTagName("td")[m].innerHTML='<a href="#" onclick="datepicker.select(\''+h+"',[-1,"+m+',911],1); this.blur(); return false;">'+this.monthLabels[m].substr(0,3)+"</a>";if(m==t){k.getElementsByTagName("td")[m].getElementsByTagName("a")[0].setAttribute("style","border:1px dotted #CCCCCC;")}else{k.getElementsByTagName("td")[m].getElementsByTagName("a")[0].setAttribute("style","")}}$(h+"_tCont").insert({before:k});$(h).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="datepicker.transition(\''+h+"',-1); this.blur(); return false;\">"+q[2]+"</a>"}else{if(d==0){k.setAttribute("class","cipb_datepicker_calendar_other");var s=new Array();var p=q[2];while(p%10!=0){p--}p--;for(var m=0;m<12;m++){s[m]=p;if(m%3==0){k.insert('<tr><td colspan="2"></td><td colspan="2"></td><td colspan="2"></td><td colspan="2"></td></tr>')}k.getElementsByTagName("td")[m].innerHTML='<a href="#" onclick="datepicker.select(\''+h+"',[-1,-1,"+p+'],1); this.blur(); return false;">'+p+"</a>";if(p==q[2]){k.getElementsByTagName("td")[m].getElementsByTagName("a")[0].setAttribute("style","border:1px dotted #CCCCCC;")}else{k.getElementsByTagName("td")[m].getElementsByTagName("a")[0].setAttribute("style","")}if(m==0||m==11){k.getElementsByTagName("td")[m].getElementsByTagName("a")[0].setAttribute("style","color:#999999;")}p++}$(h+"_tCont").insert({before:k});$(h).getElementsByClassName("cipb_datepicker_title")[0].innerHTML=s[1]+" - "+s[10]}}}},transition:function(g,c,b){if(!this.cal[g]){alert("Error - ID("+g+") was not initiated");return}if(this.cal[g].dpae&&this.cal[g].dpae.state=="running"){return}if(!this.cal[g]){alert("Error - ID("+g+") was not initiated");return}var f=this.cal[g].state;this.cal[g].state+=c;if(this.cal[g].state<0||this.cal[g].state>2){alert("error cannot transition to non-existant state:"+this.cal[g].state);this.cal[g].state-=c}this.setupContent(g,this.cal[g].state);var a=$(g+"_oldTable").getHeight();var e=$(g+"_newTable").getHeight();if(a<e){hDiff=(e-a)}else{hDiff=((a-e)*-1)}if(a!=e&&f!=this.cal[g].state){if(a<e){hDiff+=2}else{hDiff-=2}}this.cal[g].curHeight=this.cal[g].curHeight+hDiff;if(!b||b==0){this.cal[g].dpae=new Effect.Parallel([new Effect.Morph(g,{sync:true,style:"height:"+datepicker.cal[g].curHeight+"px;"}),new Effect.Fade(g+"_oldTable",{sync:true}),new Effect.Appear(g+"_newTable",{sync:true})],{duration:0.5,afterFinish:function(){$(g+"_oldTable").remove()}})}else{if(b==1){var d=$(g+"_oldTable").getWidth();$(g+"_newTable").setStyle({left:d+"px",display:""});this.cal[g].dpae=new Effect.Parallel([new Effect.Morph(g,{sync:true,style:"height:"+datepicker.cal[g].curHeight+"px;"}),new Effect.Move(g+"_oldTable",{sync:true,x:-1*d,y:0,mode:"relative"}),new Effect.Move(g+"_newTable",{sync:true,x:-1*d,y:0,mode:"relative"})],{duration:0.5,afterFinish:function(){$(g+"_oldTable").remove()}})}else{if(b==2){var d=$(g+"_oldTable").getWidth();$(g+"_newTable").setStyle({left:-1*d+"px",display:""});this.cal[g].dpae=new Effect.Parallel([new Effect.Morph(g,{sync:true,style:"height:"+datepicker.cal[g].curHeight+"px;"}),new Effect.Move(g+"_oldTable",{sync:true,x:d,y:0,mode:"relative"}),new Effect.Move(g+"_newTable",{sync:true,x:d,y:0,mode:"relative"})],{duration:0.5,afterFinish:function(){$(g+"_oldTable").remove()}})}}}},slide:function(e,d){if(!this.cal[e]){alert("Error - ID("+e+") was not initiated");return}if(this.cal[e].dpae&&this.cal[e].dpae.state=="running"){return}var a=new Date();var c=[a.getDate(),a.getMonth(),a.getFullYear()];if(typeof(this.cal[e].selected[2])!="number"){this.cal[e].selected[2]=c[2]}if(typeof(this.cal[e].selected[1])!="number"){this.cal[e].selected[1]=c[1]}switch(d){case -1:if(this.cal[e].state==2){this.select(e,[-2,this.cal[e].selected[1]+1,911]);if(this.cal[e].selected[1]==12){this.select(e,[-2,0,this.cal[e].selected[2]+1])}$(e).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="datepicker.transition(\''+e+"',-1); this.blur(); return false;\">"+this.monthLabels[this.cal[e].selected[1]]+" "+this.cal[e].selected[2]+"</a>"}else{if(this.cal[e].state==1){this.select(e,[-2,-2,this.cal[e].selected[2]+1]);$(e).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="this.blur(); return false;">'+this.cal[e].selected[2]+"</a>"}else{if(this.cal[e].state==0){this.select(e,[-2,-2,this.cal[e].selected[2]+10]);$(e).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="this.blur(); return false;">'+this.cal[e].selected[2]+"</a>"}}}this.transition(e,0,1);break;case 1:if(this.cal[e].state==2){var b=this.cal[e].selected[1];this.select(e,[-2,this.cal[e].selected[1]-1,911]);if(b==0){this.select(e,[-2,11,this.cal[e].selected[2]-1])}$(e).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="datepicker.transition(\''+e+"',-1); this.blur(); return false;\">"+this.monthLabels[this.cal[e].selected[1]]+" "+this.cal[e].selected[2]+"</a>"}else{if(this.cal[e].state==1){this.select(e,[-2,-2,this.cal[e].selected[2]-1]);$(e).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="this.blur(); return false;">'+this.cal[e].selected[2]+"</a>"}else{if(this.cal[e].state==0){this.select(e,[-2,-2,this.cal[e].selected[2]-10]);$(e).getElementsByClassName("cipb_datepicker_title")[0].innerHTML='<a href="#" onclick="this.blur(); return false;">'+this.cal[e].selected[2]+"</a>"}}}this.transition(e,0,2);break}},select:function(g,c,f){if(!this.cal[g]){alert("Error - ID("+g+") was not initiated");return}if(this.cal[g].animEffect.state!="finished"){return}var b=this.cal[g].selected.slice();if(c instanceof Array){if(c[0]!=911){if(c[0]==-1){if(c[1]==911||this.cal[g].selected[1]==c[1]){c[0]=this.cal[g].selected[0]}}this.cal[g].selected[0]=c[0]}if(c[1]!=911){if(c[1]==-1){if(c[2]==911||this.cal[g].selected[2]==c[2]){c[1]=this.cal[g].selected[1]}}this.cal[g].selected[1]=c[1]}if(c[2]!=911){this.cal[g].selected[2]=c[2]}}else{alert("error detail must me array - selection not made")}if(!f){return}else{switch(this.cal[g].state){case 2:if(this.cal[g].selected[0]!=b[0]){var a="background-color:#9BB2C8; color:#363636; border:1px solid #2B4F74;";for(var d=0;d<6;d++){for(var e=0;e<7;e++){if($$("#"+g+" .cipb_datepicker_calendar td")[e+(d*7)].getElementsByTagName("a").length>0){if($$("#"+g+" .cipb_datepicker_calendar td")[e+(d*7)].getElementsByTagName("a")[0].innerHTML!=this.cal[g].selected[0]){$$("#"+g+" .cipb_datepicker_calendar td")[e+(d*7)].getElementsByTagName("a")[0].setAttribute("style","")}else{$$("#"+g+" .cipb_datepicker_calendar td")[e+(d*7)].getElementsByTagName("a")[0].setAttribute("style",a)}}}}}this.cal[g].selected[1]++;this.cal[g].outputFunc(this.cal[g].selected);this.cal[g].selected[1]--;this.cal[g].blurClick();break;case 1:if(this.cal[g].selected[1]!=b[1]){var a="border:1px dotted #CCCCCC;";for(var e=0;e<12;e++){if(e!=this.cal[g].selected[1]){$$("#"+g+" .cipb_datepicker_calendar_other td")[e].getElementsByTagName("a")[0].setAttribute("style","")}else{$$("#"+g+" .cipb_datepicker_calendar_other td")[e].getElementsByTagName("a")[0].setAttribute("style",a)}}}this.transition(g,f);break;case 0:if(this.cal[g].selected[2]!=b[2]){var a="border:1px dotted #CCCCCC;";for(var e=0;e<12;e++){if($$("#"+g+" .cipb_datepicker_calendar_other td")[e].getElementsByTagName("a")[0].innerHTML!=this.cal[g].selected[2]){$$("#"+g+" .cipb_datepicker_calendar_other td")[e].getElementsByTagName("a")[0].setAttribute("style","")}else{$$("#"+g+" .cipb_datepicker_calendar_other td")[e].getElementsByTagName("a")[0].setAttribute("style",a)}}}this.transition(g,f);break}}},calHTML:'<div id="{ID_REPLACE}"style="position:absolute; display:none;"class="cipb_datepicker"><span class="cipb_datepicker_head"><a class="cipb_datepicker_prev_a" onclick="datepicker.slide(\'{ID_REPLACE}\',1); this.blur(); return false;" href="#"><span class="cipb_datepicker_prev_span"></span></a><a class="cipb_datepicker_next_a" onclick="datepicker.slide(\'{ID_REPLACE}\',-1); this.blur(); return false;" href="#"><span class="cipb_datepicker_next_span"></span></a><span class="cipb_datepicker_title"></span></span><div id="{ID_REPLACE}_tCont"></div></div>'};
