String.prototype.toDate = function()
{
 var date_temp=false
 if(this=="null" || this=="")
  return null
 var d=new Date()
 var s=this.split(" ")
 t=s[0].split(".")
 d.setFullYear(t[0])
 d.setMonth(t[1]-1)
 d.setDate(t[2])
 if(s.length>1)
 {
  t=s[1].split(":")
  d.setHours(t[0])
  d.setMinutes(t[1])
  d.setSeconds(t[2])
 }
 else
 {
  d.setHours(0)
  d.setMinutes(0)
  d.setSeconds(0)
 }
 return d
}

function oDTP()
{
 Date.prototype.toDateString = function()
 {
  var s=String(this.getFullYear())
  s+="."+("0"+String(this.getMonth()+1)).substr(("0"+String(this.getMonth()+1)).length-2,2)
  s+="."+("0"+String(this.getDate())).substr(("0"+String(this.getDate())).length-2,2)
  return s
 }
 
 this.updateDTP=function()
 {
  with(this)
  {
   ev=date.getFullYear()
   ho=date.getMonth()
   popup.document.getElementById("dtpYear").innerText=ev
   popup.document.getElementById("dtpMonth").innerText=honapok[ho]
   popup.document.getElementById("dtpPrevYear").onclick=function() { setMonth(-12) }
   popup.document.getElementById("dtpNextYear").onclick=function() { setMonth(12) }
   popup.document.getElementById("dtpPrevMonth").onclick=function() { setMonth(-1) }
   popup.document.getElementById("dtpNextMonth").onclick=function() { setMonth(1) }
   
   ma=new Date()
   mai_ho=(ev==ma.getFullYear() && ho==ma.getMonth() ? true : false)
   mai_nap=ma.getDate()
   
   date.setDate(1)
   hetielsonap=date.getDay()-1
   if(hetielsonap<0)
   hetielsonap=6
   date.setMonth(date.getMonth()+1)
   date.setDate(0)
   utolsonap=date.getDate()
  
   dtpweeks=popup.document.getElementById("dtpDays").rows
   for(d=1,j=0;j<6;j++,hetielsonap=0)
    for(i=0;i<napok.length;i++)
     with(dtpweeks(j+1).cells(i))
     {
      if(i<hetielsonap || d>utolsonap)
      {
       innerHTML="&nbsp;"
       className="dtpDay"
//       onclick=null
      }
      else
      {
       innerHTML=d.toString()
       className="dtpDay"
       if(mai_ho && d==mai_nap)
        className+="Today"
       if(i>4)
        className+="Weekend"
       d++
      }
      onclick=function() { setDay(this.innerText) }
      onmouseover=this.cellOver
      onmouseout=this.cellOut
     }
  }
 }
 this.setMonth=function(offset)
 {
  with(this.date)
  {
   month=getMonth()+offset%12
   year=getFullYear()+parseInt(offset/12)
   if(month<0 || month>11)
   {
    month-=12*offset/Math.floor(offset)
    year+=offset/Math.abs(offset)
   }
   setDate(1)
   setMonth(month)
   setFullYear(year)
  }
  this.updateDTP()
 }
 this.setDay=function(day)
 {
  if(parseInt(day)>0)
  {
   this.date.setDate(day)
   this.target.value=this.date.toDateString()
  }
  else
   this.target.value=""
  this.popup.hide()
 }
 this.getDate=function(keep)
 {
  this.target=event.srcElement//.previousSibling
  dtemp=this.target.value.toDate()
  if(keep && dtemp)
   this.date=dtemp
  else
   this.date=new Date()
  this.updateDTP()
  this.popup.show(-62, 20, 144, 125, this.target)
 }
 this.cellOver=function() { oldclass=this.className;this.className="dtpDayHigh" }
 this.cellOut=function() { this.className=oldclass }
 this.oldclass
 this.honapok=Array("január","február","március","április","május","június","július","augusztus","szeptember","október","november","december")
 this.napok=Array("H","K","Sz","Cs","P","Sz","V")
 this.target=new Object()
 this.popup=window.createPopup()
 with(this.popup.document)
 { createStyleSheet("_include/dtp.css")
  body.className="dtp"
  oDiv=body.appendChild(createElement("<div id=DTP></div>"))
  oTable=oDiv.appendChild(createElement("<table></table>"))
  oRow=oTable.insertRow()
  oTD=oRow.appendChild(createElement("<td id=dtpPrevYear class=dtpNav></td>"))
  oTD.innerHTML="&darr;"
  oTD=oRow.appendChild(createElement("<td id=dtpNextYear class=dtpNav></td>"))
  oTD.innerHTML="&uarr;"
  oTD=oRow.appendChild(createElement("<td id=dtpYear class=dtpYear nowrap></td>"))
  oTD=oRow.appendChild(createElement("<td id=dtpMonth class=dtpMonth nowrap></td>"))
  oTD=oRow.appendChild(createElement("<td id=dtpPrevMonth class=dtpNav></td>"))
  oTD.innerHTML="&darr;"
  oTD=oRow.appendChild(createElement("<td id=dtpNextMonth class=dtpNav></td>"))
  oTD.innerHTML="&uarr;"
  oTable=oDiv.appendChild(createElement("<table class=dtp id=dtpDays cellpadding=0 cellspacing=0></table>"))
  oTR=oTable.insertRow()
  for(i=0;i<this.napok.length;i++)
  {
   oTD=oTR.appendChild(createElement("<td class=dtpLabel></td>"))
   oTD.innerHTML=this.napok[i]
   if(i>4)
    oTD.className="dtpLabelWeekend"
  }
  for(j=0;j<6;j++)
  {
   oTR=oTable.insertRow()
   for(i=0;i<this.napok.length;i++)
    oTD=oTR.appendChild(createElement("<td></td>"))
  }
 }
}

