  function UA()
  {
    var a = navigator.userAgent.toLowerCase(), b = parseInt(navigator.appVersion);
    var g = navigator.appName == "Netscape";
    this.DOM=document.getElementById ? true : false;
    this.opera  = a.indexOf('opera') != -1;
    this.opera5 = a.indexOf("opera 5") > 0 || a.indexOf("opera/5") >= 0;
    this.opera6 = a.indexOf("opera 6") > 0 || a.indexOf("opera/6") >= 0;
    this.opera7 = a.indexOf("opera 7") > 0 || a.indexOf("opera/7") >= 0;
    this.oldOpera = this.opera5 || this.opera6;
    this.ie3down = a.indexOf('msie') != -1 && b < 4 && !this.opera;
    this.ie4up = !this.ie3down&&document.all&&document.all.item&&!this.opera;
    this.ie5up = this.DOM&&this.ie4up;
    this.ie6 = this.ie5up&&a.indexOf('msie 6.')>0;
    this.ie = this.ie4up||this.ie5up;
    this.nn4 = g&&!this.DOM&&!this.opera;
    this.moz = this.nn6up=this.DOM&&g&&!this.opera;
    this.hj = a.indexOf('hotjava')!=-1;
    this.aol = a.indexOf('aol')!=-1;
    this.aol4up = this.aol&&this.ie4up;
    this.supp = this.supported = this.oldOpera||this.opera7||this.ie||this.moz||this.nn4||this.DOM;
  }

  var ua = new UA();

  function CodeThatSetMY(m,y,f,url)
  {
    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 h=window.opener||window;
    if(h&&h.codethatcalendar)
    {
      h.codethatcalendar.date.setYear(y);
      h.codethatcalendar.date.setMonth(m);
    }
    //window.location.reload();
    window.location = url + '?m=' + m + '&y=' + y;
  }

  function CodeThatFind(d,f)
  {
    if(d.getElementById&&d.getElementById(f)!=null)
    {
      return d.getElementById(f);
    }
    else if(ua.ie4up)
    {
      return d.all[f];
    }
    else
    {
      if(d.forms.item)
        for(var j=0;d.forms.item(j)!=null;++j)
        {
          if(d.forms.item(j).namedItem&&d.forms.item(j).namedItem(f))
            return d.forms.item(j).namedItem(f);
          if(d.forms.item(j).elements&&d.forms.item(j).elements[f])
            return d.forms.item(j).elements[f];
        }
        for(var k in d.forms)
          if(d.forms[k].elements&&d.forms[k].elements[f])
            return d.forms[k].elements[f];
    }
    return null;
  }

  function CodeThatAlign(n)
  {
    return n<10?("0"+n):(""+n);
  }

  function CodeThatDateFormat(f,d,m,y)
  {
    var o=f;
    d=d<10?("0"+d):d;
    o=o.replace("dd",d);
    m++;
    m=m<10?("0"+m):m;
    o=o.replace("MM",m);
    o=o.replace("yyyy",y);
    if(CodeThatFind(document,'time'))
    {
      var q=CodeThatFind(document,'time').value;
      var r=parseInt(q.substring(0,2)-0);
      if(r<0||r>23)
      {
        r=r%24;
        r+=(r<0?24:0);
      }

      o=o.replace("HH",CodeThatAlign(r));
      var u=parseInt(q.substring(3,5)-0);
      if(u<0||u>59)
      {
        u=u%60;
        u+=(u<0?60:0);
      }

      o=o.replace("mm",CodeThatAlign(u));
      var x=parseInt(q.substring(6,8)-0);
      if(x<0||x>59)
      {
        x=x%60;
        x+=(x<0?60:0);
      }

      o=o.replace("ss",CodeThatAlign(x));
    }
    return o;
  }

  function CodeThatSetDay(f,d,m,y,i,a)
  {
    if(window.opener&&!i)
    {
        a = 'window.opener.' + a;
    }
    var a1=eval(a);
    if(a1) a1.value=CodeThatDateFormat(f,d,m,y);
  }

  function CodeThatCalendar(def)
  {
    this.def=def;
    this.o1=0;
  }

  {
    var b1=CodeThatCalendar.prototype;

    b1.getCss=function(key,d)
    {
      return this.def[key];
    }

    b1.create=function(d,ctl)
    {
      var c1=false;
      this.i=c1;
      if(!this.date)
        this.date=window.date||new Date();
      var d1=this.def;
      d.write("<table cellspacing=0 cellpadding=0 width="+d1.width+" border="+(d1.border_width||0)+" bordercolor='"+(d1.border_color||'#000000')+"'>");
      d.write("<tr>");
      if(c1)
        this.createButtons(d,c1);
      else
      {
        if(d1.headerstyle.type=="buttons")
          this.createButtons(d,c1);
        else if(d1.headerstyle.type=="comboboxes")
          this.createCombos(d);
      }
      d.write("</tr>");
      var e1=0;
      d.write("<tr>");
      this.createWeekdays(d);
      d.write("</tr>");
      ol=this.createMonth(d);
      if(d1.showtime)
      {
        this.createTime(d);
      }
      d.write("</table>");
      if (this.event==1) return;

      add = 0;
      i=0;
      for(dat in this.events){i++;}
      if (i > 0)
      {
          d.write('<table cellspacing="0" cellpadding="0" border="0"><tr><td style="border-color:#663399;background-color:#663399;"></td></tr><tr><td style="border-color:#663399;background-color:#663399;color:#FFFFFF;font-weight: bold;text-align:left">&nbsp;Key Events:</td></tr>');
          now=new Date();
          for(dat in this.events)
          {
            date = dat.split('/');
            date[0] --;
            d.write('<tr><td style="border-color:#663399;background-color:#663399;text-align:left;color:#FFFFFF;font-weight:bold;border:0px">- <a style="color:#FFFFFF;font-weight:bold;text-decoration: underline;font-family:Verdana,sans-serif;font-size:8pt;" href="#" onClick="CodeThatSetDay(\''+this.def.dtype+'\','+date[1]+','+date[0]+','+(now.getFullYear()+((now.getMonth() > date[0]) ? 1 : 0))+','+this.i+',\''+this.b2+'\');window.opener.setData(\''+this.ini_form+'\');window.close();return false">'+this.events[dat]+'</a></td></tr>');
            add += 13;
          }
          d.write('</table>');
          if (ol > 4)
          {
             this.win.resizeTo(this.def.windoww + 10, this.ini_height + 72 + add);
          }
          else
          {
              this.win.resizeTo(this.def.windoww + 10, this.ini_height + 50 + add);
          }
       }
       else
       {
          if (ol > 4)
          {
             this.win.resizeTo(this.def.windoww + 10, this.ini_height + 42 + add);
          }
          else
          {
              this.win.resizeTo(this.def.windoww + 10, this.ini_height + 20);
          }
       }
    }
    b1.createTime=function(d)
    {
      d.write("<tr><td colspan=7 align=center>"+(ua.nn4?"<form>":"")+"<input "+(ua.nn4?"name":"id")+"='time' type=hidden value='"+CodeThatAlign(this.date.getHours())+":"+CodeThatAlign(this.date.getMinutes())+":"+CodeThatAlign(this.date.getSeconds())+"'>"+(ua.nn4?"</form>":"")+"</td></tr>");
    }

    b1.createMonth=function(d)
    {
      var f1=this.date.getDate();
      var g1=this.date.getMonth();
      var h1=this.date.getYear();
      var i1=this.def;

      var j1=1;
      this.date.setDate(j1);
//      var k1=(this.date.getDay()-i1.firstday);
//    by Shadow
      var k1=(this.date.getDay() - i1.firstday - 1);

      k1+=(k1<0?7:0);
      j1-=k1;
      var l1,m1=false,n1;
      for(var o1=0;o1<6;++o1)
      {
        d.write("<tr>");
        for(var p1=0;p1<7;++p1)
        {
          n1=p1+i1.firstday;
          n1-=(n1<7?0:7);
          n1=n1==0||n1==6;

          this.date.setDate(j1);
          if(this.date.getDate()==1)
          {
            m1=!m1;
          }
          l1=(this.date.getDate()==f1&&m1)?"cd_css":(m1?(n1?"we_css":"wd_css"):(n1?"weom_css":"wdom_css"));
          if (this.event == 1)
          {
              d.write("<td align=center width=14% "+this.getCss(l1)+" style='background-color: #FFFFFF; font-weight: bold;'><A  class='"+this.getCss(l1)+"' href='javascript:CodeThatSetDay(\""+i1.dtype2+"\","+this.date.getDate()+","+this.date.getMonth()+","+this.date.getFullYear()+","+this.i+",\""+this.b2+"\");window.close()'>");
          }
          else
          {
              d.write("<td align=center width=14% "+this.getCss(l1)+" style='background-color: #FFFFFF; font-weight: bold;'><A  class='"+this.getCss(l1)+"' href='javascript:CodeThatSetDay(\""+i1.dtype+"\","+this.date.getDate()+","+this.date.getMonth()+","+this.date.getFullYear()+","+this.i+",\""+this.b2+"\");window.opener.setData(\""+this.ini_form+"\");window.close()'>");
          }
          d.write(this.date.getDate());
          d.write("</A></td>");
          j1=this.date.getDate()+1;
        }
        d.write("</tr>");
        this.date.setDate(j1);
        if(this.date.getDate()<8&&o1>3)
          break;
      }
      this.date.setDate(f1);
      this.date.setMonth(g1);
      this.date.setYear(h1);
      return o1;
    }

    b1.createWeekdays=function(d)
    {
      var q1=this.def;
      var r1;
      for(var s1=0;s1<7;++s1)
      {
        r1=s1+q1.firstday;
        r1-=(r1<7?0:7);
        d.write("<td align=center "+this.getCss("dn_css")+" style='color: #663399; background-color:#E6D9F7'>"+q1.daynames[r1]+"</td>");
      }
    }

    b1.createButtons=function(d,i)
    {
      var today=new Date();
      var t1=9,u1=this.def.headerstyle;
      for(var v1 in u1)
        --t1;
      if(u1.imgprevy&&!i)
        d.write("<td width=14% align=left><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",3,\""+this.url+"\")'><IMG border=0 src='"+u1.imgprevy+"'</IMG></A>");
      if(u1.imgprevm&&!i)
        if (today.getMonth() == this.date.getMonth() && this.event == 0)
            d.write("<td width=14% align=left><IMG border=0 src='"+u1.imgprevm+"'</IMG>");
        else
            d.write("<td width=14% align=left><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",1,\""+this.url+"\")'><IMG border=0 src='"+u1.imgprevm+"'</IMG></A>");
      d.write("<td colspan="+t1+" align=center "+this.getCss("css",u1)+" style='background-color:#663399;color:#FFFFFF; font-weight: bold; height: 27pt'>"+this.def.monthnames[this.date.getMonth()]+"&nbsp;"+this.date.getFullYear()+"</td>");
      if(u1.imgnextm&&!i)
        d.write("<td width=14% align=right><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",0,\""+this.url+"\")'><IMG border=0 src='"+u1.imgnextm+"'</IMG></A></td>");
      if(u1.imgnexty&&!i)
        d.write("<td width=14% align=right><a href='javascript:CodeThatSetMY("+this.date.getMonth()+","+this.date.getFullYear()+",2,\""+this.url+"\")'><IMG border=0 src='"+u1.imgnexty+"'</IMG></A></td>");
    }

    b1.createCombos=function(d,l)
    {
      var w1=this.def.headerstyle;
      d.write("<td colspan=7 "+this.getCss("css",w1)+">");
      if(ua.nn4)
        d.write("<form>");
      d.write("<select align=left "+this.getCss("css",w1)+" "+(ua.nn4?"name":"id")+"='month' onchange='CodeThatSetMY(CodeThatFind(document,\"month\").selectedIndex,"+w1.yearrange[0]+"+CodeThatFind(document,\"year\").selectedIndex,4,\""+this.url+"\");'>");

      var x1=0;
      for(;x1<12;++x1)
        d.write("<option "+(x1==this.date.getMonth()?"selected='selected'":"")+" value='"+x1+"'>"+this.def.monthnames[x1]+"</option>");
      d.write("</select>");
      d.write("<select align=right "+this.getCss("css",w1)+" "+(ua.nn4?"name":"id")+"='year' onchange='CodeThatSetMY(CodeThatFind(document,\"month\").selectedIndex,"+w1.yearrange[0]+"+CodeThatFind(document,\"year\").selectedIndex,4,\""+this.url+"\");'>");

      for(x1=w1.yearrange[0];x1<=w1.yearrange[1];++x1)
        d.write("<option "+(x1==this.date.getFullYear()?"selected='selected'":"")+" value='"+x1+"'>"+x1+"</option>");
      d.write("</select>");

      if(ua.nn4)
        d.write("</form>");
      d.write("</td>");
    }

    b1.parseValue=function(s, y1)
    {
      var z1=this.date;
      var a2;
      if(y1.indexOf("dd")!=-1)
      {
        a2=parseInt(s.substr(y1.indexOf("dd"),2)-0);
        if(!isNaN(a2)&&a2!=undefined)
          z1.setDate(a2);
      }

      if(y1.indexOf("MM")!=-1)
      {
        a2=parseInt(s.substr(y1.indexOf("MM"),2)-1);
        if(!isNaN(a2)&&a2!=undefined)
          z1.setMonth(a2);
      }

      if(y1.indexOf("yyyy")!=-1)
      {
        a2=parseInt(s.substr(y1.indexOf("yyyy"),4)-0);
        if(!isNaN(a2)&&a2!=undefined)
          z1.setYear(a2);
      }

      if(y1.indexOf("HH")!=-1)
      {
        a2=parseInt(s.substr(y1.indexOf("HH"),2)-0);
        if(!isNaN(a2)&&a2!=undefined)
          z1.setHours(a2);
      }

      if(y1.indexOf("mm")!=-1)
      {
        a2=parseInt(s.substr(y1.indexOf("mm"),2)-0);
        if(!isNaN(a2)&&a2!=undefined)
          z1.setMinutes(a2);
      }

      if(y1.indexOf("ss")!=-1)
      {
        a2=parseInt(s.substr(y1.indexOf("ss"),2)-0);

        if(!isNaN(a2)&&a2!=undefined)
          z1.setSeconds(a2);
      }
    }

    b1.popup=function(ctl,form)
    {
      window.codethatcalendar=this;
      this.ctl=ctl;
      this.ini_form=form;
//      var b2=CodeThatFind(document,ctl);
      var b2=eval(form + '.' + ctl);
      this.b2 = form + '.' + ctl;
      this.date=new Date();
      this.event=0;
      this.url=basehref + this.def.url;
      if(b2.value!="")
        this.parseValue(b2.value, this.def.dtype);
      var c2=window.open(this.url + '?d=' + this.date.getDate() + '&m=' + this.date.getMonth() + '&y=' + this.date.getYear(),'','width='+this.def.windoww+',height='+this.def.windowh+',status=no,resizable=no,top=200,left=350,dependent=yes,alwaysRaised=yes');
      this.ini_height = this.def.windowh;
      this.win=c2;
      c2.opener=window;
      c2.focus();
    }
    b1.event_popup=function(ctl,form)
    {
      window.codethatcalendar=this;
      this.ctl=ctl;
      this.ini_form=form;
      var b2=eval(form + '.' + ctl);
      this.b2 = form + '.' + ctl;
      this.date=new Date();
      this.event=1;
      this.url=basehref + this.def.url;
      if(b2.value!='')
        this.parseValue(b2.value, this.def.dtype2);
      var c2=window.open(this.url + '?d=' + this.date.getDate() + '&m=' + this.date.getMonth() + '&y=' + this.date.getYear(),'','width='+this.def.windoww+',height='+this.def.windowh+',status=no,resizable=no,top=200,left=550,dependent=yes,alwaysRaised=yes');
      this.win=c2;
      c2.opener=window;
      c2.focus();
    }
  }

  var c_params = {
    url:'design/calendar.php',
    firstday:6,
    dtype:'MM/dd/yyyy', // dtype:'MM/dd',
    dtype2:'MM/dd',
    width:250,
    windoww:270,
    windowh:230,
    border_width:0,
    border_color:'#0000d3',
    dn_css:'clsDayName',
    cd_css:'clsCurrentDay',
    wd_css:'clsWorkDay',
    we_css:'clsWeekEnd',
    wdom_css:'clsWorkDayOtherMonth',
    weom_css:'clsWeekEndOtherMonth',
    headerstyle: {
        type:"buttons",
        imgnextm:'pic/forward.gif',
        imgprevm:'pic/back.gif',
        css:'clsDayName'
    },
    showtime:true,
    monthnames :["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
    daynames : ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
  }

  var js_calendar = new CodeThatCalendar(c_params);

