// CodeThatCalendar PRO


function getndx(D,M,Y)
{
  return Y*400+M*32+D;
}


function UA()
{
    var t=this,nv=navigator,n=nv.userAgent.toLowerCase();
    t.win=n.indexOf('win')>=0;
    t.mac=n.indexOf('mac')>=0;
    t.DOM=document.getElementById?true:false;
    t.dynDOM=document.createElement&&document.addEventListener;
    t.khtml=nv.vendor=='KDE';
    var idx=n.indexOf('opera');
    t.opera=idx!=-1;
    if(t.opera)
    {
        t.vers=parseFloat(n.substr(idx+6));
        t.major=Math.floor(t.vers);
        t.opera5=t.major==5;
        t.opera6=t.major==6;
        t.opera7=t.major==7;
        t.opera7up=t.vers>=7;
    }
    t.oldOpera=t.opera5||t.opera6;
    idx=n.indexOf('msie');
    if(idx>=0&&!t.opera&&!t.khtml)
    {
        t.vers=parseFloat(n.substr(idx+5));
        t.ie3down=t.vers<4;
        t.ie=t.ie4up=document.all&&document.all.item&&!t.ie3down;
        t.ie5up=t.ie&&t.DOM;
        t.ie55up=t.ie&&t.vers>=5.5;
        t.ie6up=t.ie&&t.vers>=6
    }
    t.cm=document.compatMode;
    t.css1cm=t.cm=='CSS1Compat';
    t.nn4=nv.appName=="Netscape"&&!t.DOM&&!t.opera;
    if(t.nn4)t.vers=parseFloat(nv.appVersion);
    t.moz=t.nn6up=t.gecko=n.indexOf('gecko')!=-1;
    if(t.gecko)t.vers=parseFloat(n.substr(n.indexOf('rv:')+3));
    t.nn7up=t.gecko&&t.vers>1;
    t.hj=n.indexOf('hotjava')!=-1;
    t.aol=n.indexOf('aol')!=-1;
    t.aol4up=t.aol&&t.ie4up;
    t.major=Math.floor(t.vers);
    t.supp=t.supported=t.oldOpera||t.opera7up||t.ie||t.moz||t.nn4||t.DOM
};
function Undef(o)
{
    return typeof(o)=='undefined'||o===''||o==null
};
function Def(o)
{
    return!Undef(o)
};
var ua=new UA();
function CodeThatSetMY(m,y,f,id)
{
    switch(f)
    {
        case 0:
        {
            ++m;
            if(m==12)
            {
                m=0;
                y++;
            }
            break;
        }
        case 1:
        {
            --m;
            if(m==-1)
            {
                m=11;
                y--;
            }
            break;
        }
        case 2:
        {
            ++y;
            break;
        }
        case 3:
        {
            --y;
            break;
        }
        case 4:
        {
            break;
        }
    }
    var c;
    if(!window.opener)window.opener=window.parent;
    if(ua.moz&&ua.vers>=1.4)
    {
        if(this.opener)c=this.opener.codethatcalendar;
        else c=this.parent.codethatcalendar;
        window.opener=this.parent;
    }
    else if(window.opener)c=window.opener.codethatcalendar;
    if(c)
    {
        c[id].date.setFullYear(y);
        c[id].date.setMonth(m);
        c[id].created=false;
    }
    location.reload();
};
function CodeThatFind(d,f)
{
    if(d.getElementById&&Def(d.getElementById(f)))
    {
        return d.getElementById(f);
    }
    else if(ua.ie4up)
    {
        return d.all[f];
    }
    else
    {
        if(d.forms.item)for(var i=0;
        d.forms.item(i)!=null;
        ++i)
        {
            if(d.forms.item(i).namedItem&&d.forms.item(i).namedItem(f))
            return d.forms.item(i).namedItem(f);
            if(d.forms.item(i).elements&&d.forms.item(i).elements[f])
            return d.forms.item(i).elements[f];
        }
        for(var form in d.forms)if(d.forms[form].elements&&d.forms[form].elements[f])
        return d.forms[form].elements[f];
    }
    return null;
};
function GetObjectByFlag(w)
{
    t=w.codethatcalendar;
    for(i=0;i<t.length;i++)
    {
        if(!t[i].created)
        return t[i];
    }
};
function CodeThatAlign(n)
{
    return n<10?("0"+n):(""+n);;
};
function CodeThatDateFormat(doc,f,d,m,y)
{
    if(doc==null)doc=document;
    var s=f;
    d=d<10?("0"+d):d;
    s=s.replace("dd",d);
    m++;
    m=m<10?("0"+m):m;
    s=s.replace("MM",m);
    s=s.replace("yyyy",y);
    s=s.replace("yy",String(y).substr(2));
    if(CodeThatFind(doc,'time'))
    {
        var t=CodeThatFind(doc,'time').value;
        var hours=parseInt(t.substring(0,2)-0);
        if(hours<0||hours>23)
        {
            hours=hours%24;
            hours+=(hours<0?24:0);
        }
        s=s.replace("HH",CodeThatAlign(hours));
        var minutes=parseInt(t.substring(3,5)-0);
        if(minutes<0||minutes>59)
        {
            minutes=minutes%60;
            minutes+=(minutes<0?60:0);
        }
        s=s.replace("mm",CodeThatAlign(minutes));
        var seconds=parseInt(t.substring(6,8)-0);
        if(seconds<0||seconds>59)
        {
            seconds=seconds%60;
            seconds+=(seconds<0?60:0);
        }
        s=s.replace("ss",CodeThatAlign(seconds));
    }
    return s;
};
function CodeThatClose(c,f,i,ifr,id)
{
    var t=window.parent.codethatcalendar[id];
    if(Undef(t))
    return;
    var doc;
    var w=ifr==''?window.opener||window.parent:window.parent||window.opener;
    if(w&&!i)doc=w.document;
    else doc=document;
    var e=CodeThatFind(doc,c);
    if(Def(e))
    {
        var v='';
        for(j=0;j<t.dates.length;j++)v+=(j?t.spr:'')+CodeThatDateFormat(null,f,t.dates[j].getDate(),t.dates[j].getMonth(),t.dates[j].getFullYear());
        e.value=v;
        if(e.fireEvent)e.fireEvent("onchange");
        else
        {
            if(e.onchange)e.onchange();
        }
    }
    if(w&&!i)
    {
        if(Def(w)&&Def(ifr))
        {
            var iframe=CodeThatFind(doc,ifr);
            if(Def(iframe))iframe.style.visibility='hidden';
            if(ua.opera6)
            {
                var d=CodeThatFind(doc,"calendar_div");
                if(Def(d))d.style.visibility='hidden';
            }
        }
        else
        {
            window.close();
        }
    }
};
var ctsd=0;
function ctsdClear()
{
    clearTimeout(ctsd);
    ctsd=0;
};
function CodeThatSetDay(c,f,d,m,y,i,ifr,id)
{
    if(ctsd)
    {
        ctsdClear();
        return;
    }
    ctsd=setTimeout('ctsdClear()',100);
    var t=window.parent.codethatcalendar[id];
    if(Undef(t))
    return;
    if(t.multi)
    {
        for(j=0;j<t.dates.length;j++)if(t.dates[j].getFullYear()==y&&t.dates[j].getMonth()==m&&t.dates[j].getDate()==d)
        {
            t.dates.splice(j,1);
            return;
        }
    }
    var nd=new Date();
    nd.setDate(d);
    nd.setMonth(m);
    nd.setFullYear(y);
    if(t.multi)t.dates.push(nd);
    else
    {
        for(k=0;k<t.dates.length;k++)for(r=0;
        r<=t.ptr.mw;
        r++)for(cl=0;
        cl<7;
        cl++)
        {
            var a=r*7+cl;
            if(t.ptr.l[a][0]==t.dates[k].getDate()&&t.ptr.l[a][1]==t.dates[k].getMonth()&&t.ptr.l[a][2]==t.dates[k].getFullYear())
            {
                var td=CodeThatFind(t.d,'1'+r+cl);
                var href=CodeThatFind(t.d,'1'+r+cl+'a');
                var css_class=t.getCssValue(t.ptr.s[a]);
                if(ua.ie)
                {
                    td.className=css_class;
                    href.className=css_class;
                }
                else
                {
                    td.setAttribute("class",css_class);
                    href.setAttribute("class",css_class);
                }
                r=t.ptr.mw;
                break;
            }
        }
        t.dates=new Array(nd);
        t.date.setDate(d);
        t.date.setMonth(m);
        t.date.setFullYear(y);
        CodeThatClose(c,f,i,ifr,id);
    }
};
function RegisterObject(obj)
{
    var exist_flag=false;
    if(!window.codethatcalendar)
    {
        window.codethatcalendar=new Array();
        window.codethatcalendar[0]=obj;
        obj.id=0;
    }
    else
    {
        for(i=0;i<window.codethatcalendar.length;i++)
        {
            if(window.codethatcalendar[i].id==obj.id)exist_flag=true;
            break;
        }
        if(!exist_flag)
        {
            window.codethatcalendar[window.codethatcalendar.length]=obj;
            obj.id=window.codethatcalendar.length-1;
        }
    };
};
function CodeThatCalendar(def)
{
    this.def=def;
    this.links=
    {
    };
    this.styles=
    {
    };
    this.hideifr=true;
    if(Undef(def.txt))this.def.txt=["Previous year","Previous month","Next month","Next year","Apply"];
    if(Undef(def.multi))this.def.multi=false;
    if(Undef(def.imgapply))this.def.imgapply='apply.gif';
    if(Undef(def.spr))this.def.spr="\n";
    if(Undef(def.wecd_css))this.def.wecd_css=def.cd_css;
    if(Undef(def.wecw_css))this.def.wecw_css=def.tw_css;
    if(Undef(def.wdomcw_css))this.def.wdomcw_css=def.tw_css;
    if(Undef(def.weomcw_css))this.def.weomcw_css=def.tw_css;
    if(typeof(this.def.img_path)!="undefined")
    {
        if(this.def.img_path.lastIndexOf("\/")!=this.def.img_path.length-1)this.def.img_path=this.def.img_path+"\/";
    }
    if(typeof(this.def.template_path)!="undefined")
    {
        if(this.def.template_path.lastIndexOf("/")!=this.def.template_path.length-1)this.def.template_path=this.def.template_path+"/";
        if(this.def.template_path.indexOf("\/")!=0)if(typeof(this.def.img_path)!="undefined"&&this.def.img_path.indexOf("\/")!=0)
        {
            s=this.def.template_path;
            a=s.split("/");
            if(a.length)a.length=a.length-1;
            t="";
            for(i=0;i<a.length;i++)
            {
                t=t+"../";
            }
            this.img_path=t+this.def.img_path;
        }
    }
};
{
    var CTc=CodeThatCalendar.prototype;
    CTc.getCss=function(key,d)
    {
        if(this.getStyle())
        return "class='"+this.getStyle()+"'";
        if(!d)d=this.def;
        if(d[key])
        {
            return "class='"+d[key]+"'";
        }
        return "";
    };
    CTc.getCssValue=function(key,d)
    {
        if(this.getStyle())
        return this.getStyle();
        if(!d)d=this.def;
        if(d[key])
        {
            return d[key];
        }
        return "";
    };
    CTc.hide=function()
    {
        if(window.parent&&this.hideifr&&this.ifr)
        {
            var iframe=CodeThatFind(window.parent.document,this.ifr);
            if(iframe)iframe.style.visibility='hidden';
        }
        clearEventHandler('keypress');
        clearEventHandler('keydown');
    };
    CTc.create=function(d,ctl)
    {
        this.created=true;
        var i=false;
        if(ctl)
        {
            this.ctl=ctl;
            RegisterObject(this);
            i=true;
        }
        this.i=i;
        if(!this.date)this.date=window.date||new Date();
        if(!this.dates)this.dates=new Array();
        this.ptr=
        {
            w:0,d:0,mw:0,l:new Array(),s:new Array()
        };
        
        
        var def=this.def;
        var acts='';
        if(this.ifr&&def.headerstyle.type!="comboboxes")
        {
            acts='onMouseOver="window.parent.codethatcalendar['+this.id+'].hideifr=false;"';
            acts+=" onMouseOut=\"window.parent.codethatcalendar["+this.id+"].hideifr=true;setTimeout('window.parent.codethatcalendar["+this.id+"].hide();',1000);\""
        }
        d.write("<table "+(Def(this.ifr)?"align=\"center\"":"")+" cellspacing="+(def.border_width||0)+" cellpadding=0 "+acts+" width="+def.width+" border=0 bgcolor='"+(def.border_color||'#ffffff')+"'>");
        d.write("<tr>");
        if(def.headerstyle.type=="buttons")this.createButtons(d);
        else if(def.headerstyle.type=="comboboxes")this.createCombos(d);
        d.write("</tr>");
        var day=0;
        d.write("<tr>");
        this.createWeekdays(d);
        d.write("</tr>");
        var w=this.createMonth(d);
        if(def.showtime)
        {
            this.createTime(d);
        }
        if(def.preview)
        {
            this.createPreview(d);
        }
        if(def.multi)
        {
            this.createApply(d);
        }
        if(ua.opera&&w==4)
        {
            d.write("<tr><td colspan=7>&nbsp;<td></tr>");
        }
        d.write("</table>");
        this.d=d;
    };
    CTc.createTime=function(d)
    {
        time=CodeThatAlign(this.date.getHours())+":"+CodeThatAlign(this.date.getMinutes())+":"+CodeThatAlign(this.date.getSeconds());
        d.write("<tr><td align=center colspan=7>"+(ua.nn4?"<form>":"")+"<input size="+(String(time).length+3)+" "+(ua.nn4?"name":"id")+"='time' style=\"border:0\" value='"+time+"' "+this.getCss('time_css')+"'>"+(ua.nn4?"</form>":"")+"</td></tr>");
    };
    CTc.createPreview=function(d)
    {
        d.write("<tr><td colspan=7 align=center>"+(ua.nn4?"<form>":"")+"<input size="+(String(this.dtype).length+5)+" id=\"preview_area\""+this.getCss('preview_css')+"style=\"border:0\">"+(ua.nn4?"</form>":"")+"</td>");
    };
    CTc.createApply=function(d)
    {
        d.write("<tr><td colspan=7 align=center>"+"<a href='javascript:CodeThatClose(\""+this.ctl+"\",\""+this.def.dtype+"\","+this.i+",\""+(Def(this.ifr)?this.ifr:"")+"\",\""+this.id+"\")'"+" onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[4]+"\")'><img border=0 src='"+(typeof(this.def.img_path)=="undefined"?'':this.img_path)+this.imgapply+"'></a></td></tr>");
    };
    CTc.createMonth=function(d)
    {
        var dt=new Date();
        var cd=dt.getDate();
        var cm=dt.getMonth();
        var cy=dt.getFullYear();
        var ci=getndx(cd,cm,cy);
        //d.write("<td> ",cd," ",cm," ",cy," </td>");
        var cday=this.date.getDay();
        var def=this.def;
        var cur_day=1;
        this.date.setDate(cur_day);
        var thisweek=false;
        var start=(this.date.getDay()-def.firstday);
        start+=(start<0?7:0);
        cur_day-=start;
        var css,thismonth=false,weekend,thisday,highlight;
        var w,month;
        for(w=0;w<6;++w)
        {
            this.ptr.mw=w;
            d.write("<tr>");
            for(var day=0;day<7;++day)
            {
                
                weekend=day+def.firstday;
                weekend-=(weekend<7?0:7);
                weekend=weekend==0||weekend==6;
                this.date.setDate(cur_day);
                if(this.date.getDate()==1)
                {
                    thismonth=!thismonth;
                    if(thismonth)month=this.date.getMonth();
                }
                if(day==0)
                {
                    var dd=this.date.getDate();
                    var mm=this.date.getMonth();
                    var yy=this.date.getFullYear();
                    var wsi=getndx(dd,mm,yy);
                    this.date.setDate(this.date.getDate()+6);
                    var wse=getndx(this.date.getDate(),this.date.getMonth(),this.date.getFullYear());
                    this.date.setFullYear(yy);
                    this.date.setMonth(mm);
                    this.date.setDate(dd);
                    
                    
                    if ((wsi<=ci)&&(wse>=ci)) thisweek=true;
                    else thisweek=false;
                    //d.write("<td>"+thisweek+" "+ci+" "+wsi+" "+wse+"</rd>");
                    /*if(w!=0)
                    {
                        thisweek=cd-this.date.getDate();
                        if(thisweek<7&&thisweek>=0)thisweek=true;
                        else thisweek=false;
                    }
                    else thisweek=(start+cd)<8;*/
                    //if(this.date.getMonth()-month==1)break;
                }
                if(day==7&&thisweek)thisweek=false;
                thisday=this.date.getDate()==cd&&thismonth&&thisweek; //libor !! &&thisweek
                if(thisday)
                {
                    this.ptr.w=w;
                    this.ptr.d=day;
                }
                pr_date="'"+this.def.dtype+"',"+this.date.getDate()+","+this.date.getMonth()+","+this.date.getFullYear();
                highlight=false;
                if(thismonth)
                {
                    this.tmn=this.date.getMonth();
                    for(i=0;i<this.dates.length;i++)if(this.dates[i].getDate()==this.date.getDate()&&this.dates[i].getMonth()==this.date.getMonth()&&this.dates[i].getFullYear()==this.date.getFullYear())
                    {
                        highlight=true;
                        break;
                    }
                }

                //d.write("<td>"+cd+"-"+cm+"-"+cy+"  "+cur_day+"</td>\n"); //LIBOR!!!
                var ccm=this.date.getMonth()+1;
                var datestr="|"+this.date.getDate()+"-"+ccm+"-"+this.date.getFullYear();
                weekend=true;
                //if (def.terms.indexOf(datestr)!=-1&&getndx(this.date.getDate(),this.date.getMonth(),this.date.getFullYear())>ci) weekend=true;
                //else weekend=false;
                //d.write("<td>"+datestr+" "+weekend+"</td>\n"); //LIBOR!!!
                //d.write("<td>"+getndx(this.date.getDate(),this.date.getMonth(),this.date.getFullYear())+" "+thisday+" "+thisweek+" "+thismonth+"</td>\n"); //LIBOR!!!
                
                css=thisday?(weekend?'wecd_css':'cd_css'):(thisweek?(thismonth?(weekend?'wecw_css':'tw_css'):(weekend?'weomcw_css':'wdomcw_css')):(thismonth?(weekend?'we_css':'wd_css'):(weekend?'weom_css':'wdom_css')));
                span_id='1'+w+day;
                act='onmouseover="window.parent.codethatcalendar['+this.id+'].highlightDate('+w+','+day+');"';
                d.write("<td align=center width=14% id=\""+span_id+"\" "+act+" "+this.getCss(highlight?'highlight_css':css)+">");
                if (weekend) d.write("<A "+this.getCss(highlight?'highlight_css':css)+"id=\""+span_id+"a\" "+this.getRef()+">"); //!!LIBOR if() ...
                else d.write("<A "+this.getCss(highlight?'highlight_css':css)+"id=\""+span_id+"a\" >");
                d.write(this.date.getDate());
                d.write("</A></td>");
                this.ptr.l[w*7+day]=[this.date.getDate(),this.date.getMonth(),this.date.getFullYear()];
                this.ptr.s[w*7+day]=css;
                cur_day=this.date.getDate()+1;
            }
            d.write("</tr>");
            this.date.setDate(cur_day);
            if((this.date.getDate()<8&&w>3))break;
        }
        this.date.setDate(cd);
        this.date.setMonth(cm);
        this.date.setFullYear(cy);
        return w;
    };
    CTc.setLink=function(s,l)
    {
        this.links[s]=l;
    };
    CTc.setStyle=function(s,l)
    {
        this.styles[s]=l;
    };
    CTc.getStyle=function()
    {
        var c;
        if(this.i)
        {
            var fd=CodeThatDateFormat(null,this.def.dtype,this.date.getDate(),this.date.getMonth(),this.date.getFullYear());
            if(this.styles[fd])c=this.styles[fd];
        }
        return c;
    };
    CTc.getRef=function()
    {
        var ref;
        if(this.i)
        {
            var fd=CodeThatDateFormat(null,this.def.dtype,this.date.getDate(),this.date.getMonth(),this.date.getFullYear());
            if(this.links[fd])ref=" href='"+this.links[fd]+"'";
        }
        ref=ref||(" href='javascript:CodeThatSetDay(\""+this.ctl+"\",\""+this.def.dtype+"\","+this.date.getDate()+","+this.date.getMonth()+","+this.date.getFullYear()+","+this.i+",\""+(Def(this.ifr)?this.ifr:"")+"\",\""+this.id+"\")'");
        return ref;
    };
    CTc.createWeekdays=function(d)
    {
        var def=this.def;
        var weekend;
        for(var day=0;day<7;++day)
        {
            weekend=day+def.firstday;
            weekend-=(weekend<7?0:7);
            d.write("<td align=center "+this.getCss("dn_css")+">"+def.daynames[weekend]+"</td>");
        }
    };
    CTc.createButtons=function(d)
    {
        var dh=this.def.headerstyle;
        var w=100-(dh.imgprevy?14:0)-(dh.imgprevm?14:0)-(dh.imgnextm?14:0)-(dh.imgnexty?14:0);
        d.write('<td colspan=7><table width=100% border=0 cellpadding=0 cellspacing=0><tr>');
        if(typeof(this.def.img_path)!="undefined")
        {
            if(dh.imgprevy)d.write("<td width=14% align=left bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",3,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[0]+"\")'><img border=0 src='"+this.img_path+dh.imgprevy+"'></a></td>");
            if(dh.imgprevm)d.write("<td width=14% align=left bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",1,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[1]+"\")'><img border=0 src='"+this.img_path+dh.imgprevm+"'></a></td>");
            d.write("<td width="+w+"% align=center "+this.getCss("css",dh)+">"+this.def.monthnames[this.date.getMonth()]+"&nbsp;"+this.date.getFullYear()+"</td>");
            if(dh.imgnextm)d.write("<td width=14% align=right bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",0,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[2]+"\")'><img border=0 src='"+this.img_path+dh.imgnextm+"'></a></td>");
            if(dh.imgnexty)d.write("<td width=14% align=right bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",2,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[3]+"\")'><img border=0 src='"+this.img_path+dh.imgnexty+"'></a></td>");
        }
        else
        {
            if(dh.imgprevy)d.write("<td width=14% align=left bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",3,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[0]+"\")'><img border=0 src='"+dh.imgprevy+"'></a>");
            if(dh.imgprevm)d.write("<td width=14% align=left bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",1,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[1]+"\")'><img border=0 src='"+dh.imgprevm+"'></a>");
            d.write("<td width="+w+"% align=center "+this.getCss("css",dh)+">"+this.def.monthnames[this.date.getMonth()]+"&nbsp;"+this.date.getFullYear()+"</td>");
            if(dh.imgnextm)d.write("<td width=14% align=right bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",0,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[2]+"\")'><img border=0 src='"+dh.imgnextm+"'></a></td>");
            if(dh.imgnexty)d.write("<td width=14% align=right bgcolor=#ffffff><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",2,"+this.id+")' onmouseover='window.parent.codethatcalendar["+this.id+"]."+"setStatus(\""+this.def.txt[3]+"\")'><img border=0 src='"+dh.imgnexty+"'></a></td>");
        }
        d.write('<\/tr><\/table><\/td>');
    };
    CTc.createCombos=function(d,l)
    {
        var dh=this.def.headerstyle;
        d.write('<td colspan=7><table width=100% border=0 cellpadding=0 cellspacing=0><tr>');
        d.write("<td align=left "+this.getCss("css",dh)+">");
        if(ua.nn4)d.write("<form>");
        d.write("<select align=left "+this.getCss("css",dh)+" "+(ua.nn4?"name":"id")+"='month' onchange='CodeThatSetMY(CodeThatFind(document,\"month\").selectedIndex,"+dh.yearrange[0]+"+CodeThatFind(document,\"year\").selectedIndex,4,"+this.id+");'>");
        var i=0;
        for(;i<12;++i)d.write("<option "+(i==this.date.getMonth()?"selected='selected'":"")+" value='"+i+"'>"+this.def.monthnames[i]+"</option>");
        d.write("</select>");
        d.write("</td><td align=right>");
        d.write("<select align=right "+this.getCss("css",dh)+" "+(ua.nn4?"name":"id")+"='year' onchange='CodeThatSetMY(CodeThatFind(document,\"month\").selectedIndex,"+dh.yearrange[0]+"+CodeThatFind(document,\"year\").selectedIndex,4,"+this.id+");'>");
        for(i=dh.yearrange[0];i<=dh.yearrange[1];++i)d.write("<option "+(i==this.date.getFullYear()?"selected='selected'":"")+" value='"+i+"'>"+i+"</option>");
        d.write("</select>");
        if(ua.nn4)d.write("</form>");
        d.write("</td>");
        d.write('<\/tr><\/table><\/td>');
    };
    CTc.parseValue=function(s)
    {
        var f=this.def.dtype,d=new Date();
        var t;
        if(f.indexOf("yyyy")!=-1)
        {
            t=parseInt(s.substr(f.indexOf("yyyy"),4)-0);
            if(!isNaN(t)&&typeof(t)!="undefined")d.setFullYear(t);
        }
        if(f.indexOf("MM")!=-1)
        {
            t=parseInt(s.substr(f.indexOf("MM"),2)-1);
            if(!isNaN(t)&&typeof(t)!='undefined')d.setMonth(t);
        }
        if(f.indexOf("dd")!=-1)
        {
            t=parseInt(s.substr(f.indexOf("dd"),2)-0);
            if(!isNaN(t)&&typeof(t)!='undefined')d.setDate(t);
        }
        if(f.indexOf("HH")!=-1)
        {
            t=parseInt(s.substr(f.indexOf("HH"),2)-0);
            if(!isNaN(t)&&typeof(t)!='undefined')d.setHours(t);
        }
        if(f.indexOf("mm")!=-1)
        {
            t=parseInt(s.substr(f.indexOf("mm"),2)-0);
            if(!isNaN(t)&&typeof(t)!='undefined')d.setMinutes(t);
        }
        if(f.indexOf("ss")!=-1)
        {
            t=parseInt(s.substr(f.indexOf("ss"),2)-0);
            if(!isNaN(t)&&typeof(t)!='undefined')d.setSeconds(t);
        }
        return d
    };
    CTc.parseMulti=function(s)
    {
        this.multi=this.def.multi;
        this.spr=this.def.spr;
        this.imgapply=this.def.imgapply;
        if(s=='')
        return;
        var e=s.split(this.spr);
        this.dates=new Array();
        for(i=0;i<e.length;i++)
        {
            this.dates.push(this.parseValue(e[i]));
        }
    };
    CTc.popup=function(ctl)
    {
        this.created=false;
        RegisterObject(this);
        this.ctl=ctl;
        var e=CodeThatFind(document,ctl);
        this.date=new Date();
        this.parseMulti(e.value);
        if(typeof(this.def.template_path)!="undefined")
        {
            var w=window.open(this.def.template_path+"codethatcalendar.html?"+this.id,this.id,'width='+this.def.windoww+',height='+this.def.windowh+',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes');
        }
        else var w=window.open("/codethatcalendar.html?"+this.id,this.id,'width='+this.def.windoww+',height='+this.def.windowh+',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes');
        w.opener=window;
        w.focus();
    };
    CTc.innerpopup=function(ctl,ifr)
    {
        RegisterObject(this);
        this.created=false;
        this.ctl=ctl;
        this.ifr=ifr;
        this.hideifr=false;
        var e=CodeThatFind(document,ctl);
        this.date=new Date();
        this.parseMulti(e.value);
        var w=CodeThatFind(document,ifr);
        if(ua.oldOpera)
        {
            w=document.frames[ifr];
            w.location.reload();
            var d=CodeThatFind(document,"calendar_div");
            d.style.visibility='visible';
        }
        else
        {
            if(typeof(this.def.template_path)!="undefined")
            {
                w.src=this.def.template_path+"codethatcalendar.html?"+this.id;
            }
            else w.src="codethatcalendar.html?"+this.id;
            w.style.visibility='visible';
        }
        w.opener=window;
        w.height=this.def.windowh;
        w.width=this.def.windoww;
        if(!ua.moz)
        {
            w.focus();
        }
    };
    CTc.inline_create=function(d,ctl)
    {
        if((ua.moz&&ua.vers<1.4)||ua.oldOpera)
        {
            this.create(d,ctl);
            return;
        }
        RegisterObject(this);
        this.created=false;
        var pos="relative";
        var offx=0;
        var offy=0;
        if((typeof this.def.position)!="undefined")
        {
            if(this.def.position.absolute==true)pos="absolute";
            else pos="relative";
            if((typeof this.def.position.y)!="undefined")offy=this.def.position.y;
            if((typeof this.def.position.x)!="undefined")offx=this.def.position.x;
        }
        var opacity=100;
        if((typeof this.def.opacity)!="undefined")opacity=this.def.opacity;
        this.ctl=ctl;
        d.write('<iframe id="c_frame'+this.id+'" frameborder="0" name="c_frame" scrolling="no" STYLE="filter:Alpha(Opacity='+opacity+'); position:'+pos+'; top:'+offy+'; left:'+offx+'; " >');
        d.write('</iframe>');
        var e=CodeThatFind(document,ctl);
        this.date=new Date();
        this.parseMulti(e.value);
        var w=CodeThatFind(d,"c_frame"+this.id);
        if(typeof(this.def.template_path)!="undefined")
        {
            w.src=this.def.template_path+"codethatcalendar.html?"+this.id;
        }
        else w.src="codethatcalendar.html?"+this.id;
        w.style.visibility='visible';
        w.opener=window;
        w.height=this.def.windowh;
        w.width=this.def.windoww;
        if(!ua.moz)w.focus();
    };
    CTc.highlightDate=function(w,d)
    {
        var o=this.ptr.l[this.ptr.w*7+this.ptr.d],m=true;
        for(j=0;j<this.dates.length;j++)if(o[1]==this.tmn&&this.dates[j].getDate()==o[0]&&this.dates[j].getMonth()==o[1]&&this.dates[j].getFullYear()==o[2])
        {
            m=false;
            break;
        }
        if(m)this.changeCSS(this.ptr.s[this.ptr.w*7+this.ptr.d]);
        this.ptr.w=w;
        this.ptr.d=d;
        var o=this.ptr.l[w*7+d];
        this.setStatus(CodeThatDateFormat(this.d,this.def.dtype,o[0],o[1],o[2]));
        this.changeCSS('highlight_css');
    };
    CTc.changeCSS=function(css)
    {
        var td=CodeThatFind(this.d,'1'+this.ptr.w+this.ptr.d);
        var href=CodeThatFind(this.d,'1'+this.ptr.w+this.ptr.d+'a');
        var css_class=this.getCssValue(css);
        if(ua.ie)
        {
            td.className=css_class;
            href.className=css_class;
        }
        else
        {
            td.setAttribute("class",css_class);
            href.setAttribute("class",css_class);
        }
    };
    CTc.setStatus=function(s)
    {
        pr=CodeThatFind(this.d,'preview_area');
        if(pr!=null)
        {
            pr.size=String(s).length+2;
            pr.value=s;
        }
    };
function keyNav(id,k,s)
{
    var c=window.parent.codethatcalendar[id];
    if(Undef(k))
    return;
    if(s)switch(k)
    {
        case 13:if(!c.multi)
        return;
        var o=c.ptr.l[c.ptr.w*7+c.ptr.d];
        CodeThatClose(c.ctl,c.def.dtype,c.i,(Def(c.ifr)?c.ifr:""),id);
        return;
        case 37:var m=c.date.getMonth()-1;
        if(m==-1)
        {
            m=11;
            c.date.setFullYear(c.date.getFullYear()-1);
        }
        c.date.setMonth(m);
        break;
        case 38:c.date.setFullYear(c.date.getFullYear()+1);
        break;
        case 39:var m=1+c.date.getMonth();
        if(m==12)
        {
            m=0;
            c.date.setFullYear(1+c.date.getFullYear());
        }
        c.date.setMonth(m);
        break;
        case 40:c.date.setFullYear(c.date.getFullYear()-1);
        break;
        default:
        return;
    }
    else switch(k)
    {
        case 13:var o=c.ptr.l[c.ptr.w*7+c.ptr.d];
        CodeThatSetDay(c.ctl,c.def.dtype,o[0],o[1],o[2],c.i,(Def(c.ifr)?c.ifr:""),id);
        return;
        case 32:var td=new Date();
        c.date.setFullYear(td.getFullYear());
        c.date.setMonth(td.getMonth());
        c.date.setDate(td.getDate());
        break;
        case 37:var cc=c.ptr.w*7+c.ptr.d-1;
        if(!c.ptr.w&&(cc<0||c.ptr.l[cc+1][1]!=c.ptr.l[cc][1]))keyNav(id,37,true);
        else c.highlightDate(c.ptr.d==0?c.ptr.w-1:c.ptr.w,c.ptr.d==0?6:c.ptr.d-1);
        return;
        case 38:if(!c.ptr.w&&c.ptr.d==6)keyNav(id,39,true);
        else c.highlightDate(c.ptr.w?c.ptr.w-1:c.ptr.mw,c.ptr.w?c.ptr.d:c.ptr.d+1);
        return;
        case 39:var cc=c.ptr.w*7+c.ptr.d+1;
        if(c.ptr.w&&(cc==c.ptr.l.length||c.ptr.l[cc-1][1]!=c.ptr.l[cc][1]))keyNav(id,39,true);
        else c.highlightDate(c.ptr.d==6?c.ptr.w+1:c.ptr.w,c.ptr.d==6?0:c.ptr.d+1);
        return;
        case 40:if(c.ptr.w==c.ptr.mw&&!c.ptr.d)keyNav(id,37,true);
        else c.highlightDate(c.ptr.w==c.ptr.mw?0:c.ptr.w+1,c.ptr.w==c.ptr.mw?c.ptr.d-1:c.ptr.d);
        return;
        default:
        return;
    }
    c.created=false;
    location.reload();
};
function regEventHandler(e,h,obj)
{
    if(Undef(obj))obj=document;
    e=e.toLowerCase();
    if(ua.nn4)
    {
        var name=e.toUpperCase();
        obj.captureEvents(Event[name]);
    }
    var f=typeof(h)=="function"?function(e)
    {
        var ev=ua.ie?window.event:e;
        if(Def(ev))ev=new CEvent(ev);
        return h(ev)
    }
:typeof(h)=="string"?new Function("e","var ev=ua.ie?window.event:e;if (Def(ev)) ev=new CEvent(ev);"+h):null;
obj["on"+e]=f
};
function clearEventHandler(e,obj)
{
    if(Undef(obj))obj=document;
    e=e.toLowerCase();
    if(ua.nn4)
    {
        var name=e.toUpperCase();
        obj.releaseEvents(Event[name]);
    }
    obj["on"+e]=null
};
function CEvent(e)
{
    var t=this;
    t._e=e;
    t.x=ua.nn4||ua.moz?e.pageX:ua.oldOpera?e.clientX:e.clientX+document.body.scrollLeft;
    t.y=ua.nn4||ua.moz?e.pageY:ua.oldOpera?e.clientY:e.clientY+document.body.scrollTop;
    t.offsetX=ua.nn4||ua.moz?e.layerX:e.offsetX;
    t.offsetY=ua.nn4||ua.moz?e.layerY:e.offsetY;
    t.screenX=e.screenX;
    t.screenY=e.screenY;
    t.target=ua.ie?e.srcElement:e.target;
    t.key=ua.nn4||ua.moz?e.which:e.keyCode;
    t.alt=ua.nn4?e.modifiers&Event.ALT_MASK:e.altKey;
    t.ctrl=ua.nn4?e.modifiers&Event.CONTROL_MASK:e.ctrlKey;
    t.shift=ua.nn4?e.modifiers&Event.SHIFT_MASK:e.shiftKey;
    t.spec=t.alt||t.ctrl||t.shift;
    var b=ua.nn4||ua.moz?e.which:e.button;
    t.b_left=b==1;
    t.b_mid=ua.nn4||ua.moz?b==2:b==4;
    t.b_right=ua.nn4||ua.moz?b==3:b==2
};
function initCalendar()
{
    var w=(Undef(window.opener)||Undef(window.opener.codethatcalendar))?window.parent:window.opener;
    if(ua.opera)window.opener.codethatcalendar=w.codethatcalendar;
    window.parent.codethatcalendar=w.codethatcalendar;
    var c=GetObjectByFlag(w);
    if(c)
    {
        document.write("<div class='clsBody'>");
        c.create(document);
        document.write("</div>")
    }
    var l=window.location.search;
    if(l.indexOf('?')==0)l=l.substr(1);
    regEventHandler('keypress','keyNav("'+l+'",ev.key,ev.spec)');
    regEventHandler('keydown','keyNav("'+l+'",ev.key,ev.spec)');
    if(window.focus)window.focus();
};
}
