var periodi; var monthName = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); var month; var year; var selectedDate; var fromDate; var toDate; var targetElement; var dockElement; function getCoordsInTopWindow(o){ return getCoords(o); var x = 0; var y = 0; var win; if(o.ownerDocument.defaultView) win = o.ownerDocument.defaultView; else win = o.ownerDocument.parentWindow; if(win.frameElement){ var parentFrameCoords = getCoordsInTopWindow(win.frameElement); x += parentFrameCoords.x; y += parentFrameCoords.y; } while(o.tagName!="BODY"){ x += o.offsetLeft; y += o.offsetTop; o=o.offsetParent; } var r = new Object(); r.x = x; r.y = y; return r; } function getCoords(o){ var x = 0; var y = 0; while(o && o.tagName!="BODY"){ x += o.offsetLeft; y += o.offsetTop; o=o.offsetParent; } var r = new Object(); r.x = x; r.y = y; return r; } function calendarCloseIE(){ if(window.frames.calendar.event.clientX<0 || window.frames.calendar.event.clientX>158 || window.frames.calendar.event.clientY<0 || window.frames.calendar.event.clientY>153 ){ window.document.getElementById("calendarDiv").style.visibility = "hidden"; targetElement.focus(); } } function calendarClose(){ window.document.getElementById("calendarDiv").style.visibility = "hidden"; targetElement.focus(); } function calendarPick(pdockElement, ptargetElement, pfromDate, ptoDate, pperiodi){ if(ptargetElement.disabled) return; periodi = pperiodi; var pselectedDate = stringToDate(ptargetElement.value); /* var pselectedDay = ptargetElement.value; var pselectedMonth = ptargetElement.previousSibling.value-1; var pselectedYear = ptargetElement.previousSibling.previousSibling.value; var pselectedDate = new Date(pselectedDay, pselectedMonth, pselectedYear); //var pselectedDate = stringToDate(ptargetElement.previousSibling.previousSibling.value+"."+ptargetElement.previousSibling.value +"."+ptargetElement.value); */ /* if(pselectedDate){ if(dateToString(pselectedDate)!=ptargetElement.value){ pselectedDate = false; } } */ dockElement = pdockElement; targetElement = ptargetElement; var now = new Date(); //alert(dockElement.id); //alert(targetElement.id); var coords = getCoordsInTopWindow(dockElement); coords.x += dockElement.offsetWidth+2; var div; div = window.document.getElementById("calendarDiv"); if(!div){ alert("Calendar not loaded yet!"); return; } else{ if(window.innerHeight){ if(coords.x + div.offsetWidth + 2 > window.innerWidth + window.pageXOffset){ coords.x -= div.offsetWidth + 2; } if(coords.y + div.offsetHeight + 2 > window.innerHeight + window.pageYOffset){ coords.y -= div.offsetHeight + 2; } } else{ if(coords.x + div.offsetWidth + 2 > document.body.clientWidth + document.body.scrollLeft){ coords.x -= div.offsetWidth + 2; } if(coords.y + div.offsetHeight + 2 > document.body.clientHeight + document.body.scrollTop){ coords.y -= div.offsetHeight + 2; } } div.style.left = coords.x+"px"; div.style.top = coords.y+"px"; div.style.visibility = "visible"; } if(pselectedDate){ month = pselectedDate.getMonth(); year = pselectedDate.getUTCFullYear(); } else if(pfromDate){ month = pfromDate.getMonth(); year = pfromDate.getUTCFullYear(); } else{ month = now.getMonth(); year = now.getUTCFullYear(); } selectedDate = pselectedDate; if(pfromDate){ fromDate = pfromDate; } else{ fromDate = now; } if(ptoDate){ toDate = ptoDate; } else{ toDate = new Date(now.getUTCFullYear()+2, now.getMonth(), now.getDay()); } calendarRewrite(); if (navigator.appName == "Microsoft Internet Explorer") { window.frames.calendar.document.onfocusout = calendarCloseIE; } else { window.frames.calendar.onblur = calendarClose; } //window.document.getElementById("calendar").onblur=calendarClose; setTimeout("window.frames.calendar.focus()", 50); } /* function closeWithTimeout() { parent.calendarClose(); parent.frames.calendar.focus(); } */ function calendarMonthDec(){ month--; if(month<0) { month=11; year--; } calendarRewrite(); return false; } function calendarMonthInc(){ month++; if(month>11){ month=0; year++; } calendarRewrite(); return false; } function calendarMonthSet(){ month = this.month; calendarRewrite(); return false; } function calendarYearSet(){ year = this.year; calendarRewrite(); return false; } function calendarMonthSelectShow(e){ window.frames.calendar.document.getElementById("monthSelect").style.display="block"; window.frames.calendar.document.getElementById("yearSelect").style.display="none"; if(month>=3){ window.setTimeout('window.frames.calendar.document.getElementById("monthSelect").scrollTop = window.frames.calendar.document.getElementById("monthSelect").getElementsByTagName("a")[month-3].offsetTop', 10); } if(!e) e = window.frames.calendar.event; if(e.stopPropagating) e.stopPropagating(); else e.cancelBubble=true; } function calendarYearSelectShow(e){ window.frames.calendar.document.getElementById("monthSelect").style.display="none"; window.frames.calendar.document.getElementById("yearSelect").style.display="block"; if(!e) e = window.frames.calendar.event; if(e.stopPropagating) e.stopPropagating(); else e.cancelBubble=true; } function dateToString(d){ return d.getDate()+"."+(d.getMonth()+1)+"."+d.getUTCFullYear(); } function stringToDate(s){ try{ var a = s.split("."); if(!parseInt(a[2]) && !parseInt(a[1]) && !parseInt(a[0])) return false; return new Date(parseInt(a[2]), parseInt(a[1])-1, parseInt(a[0]), 12); } catch(ex){ return false; } } function calendarDateSelect(){ targetElement.value = dateToString(this.date); /* targetElement.value = this.date.getUTCFullYear(); targetElement.previousSibling.value = this.date.getMonth()+1; targetElement.previousSibling.previousSibling.value = this.date.getDate(); */ calendarClose(); return false; } function calendarRewrite(){ var doc = window.frames.calendar.document; var html; html = ""; html += ""; html += ""; html += ""; html += "
<"+monthName[month]+">"+year+"
"; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += "
MoTuWeThFrSaSu
       
       
       
       
       
       
"; html += ""; html += ""; doc.body.innerHTML = html; doc.getElementById('monthDec').onclick=doc.getElementById('monthDec').touchstart=calendarMonthDec; doc.getElementById('monthInc').onclick=doc.getElementById('monthInc').touchstart=calendarMonthInc; var monthNameCoords = getCoords(doc.getElementById("monthName")); var monthSelect = doc.getElementById("monthSelect"); monthSelect.style.left = monthNameCoords.x; monthSelect.style.top = monthNameCoords.y + doc.getElementById("monthName").offsetHeight - 1; monthSelect.style.width = doc.getElementById("monthName").offsetWidth; monthSelect.onblur = function(){ this.display="none" } for(i=0;i<12;i++){ var monthLink = doc.createElement("a"); monthLink.innerHTML = "  "+monthName[i]; monthLink.href = "javascript:;"; monthLink.month = i; monthLink.onclick = monthLink.touchstart = calendarMonthSet; monthSelect.appendChild(monthLink); if(i==month) { monthLink.className = "selected"; } } doc.getElementById("monthName").onclick = doc.getElementById("monthName").touchstart = calendarMonthSelectShow; var yearNameCoords = getCoords(doc.getElementById("yearName")); var yearSelect = doc.getElementById("yearSelect"); yearSelect.style.left = yearNameCoords.x; yearSelect.style.top = yearNameCoords.y + doc.getElementById("yearName").offsetHeight - 1; yearSelect.style.width = doc.getElementById("yearName").offsetWidth; var now = new Date(); for(i=fromDate.getUTCFullYear();i<=toDate.getUTCFullYear();i++){ var yearLink = doc.createElement("a"); yearLink.innerHTML = i; yearLink.href = "javascript:;"; yearLink.year = i; yearLink.onclick = yearLink.touchstart = calendarYearSet; yearSelect.appendChild(yearLink); if(i==year){ yearLink.className = "selected"; } } doc.getElementById("yearName").onclick = doc.getElementById("yearName").touchstart = calendarYearSelectShow var day = 1; var dayMili = 1000*60*60*24; var d = new Date(year, month, day, 12) var m = d.getMonth(); var firstX = -1; while(d.getMonth()==m) { var x = d.getDay()-1; if(x==-1) x = 6; var y = parseInt((d.getDate()-1) / 7); if(x=fromDate || !fromDate) && (d<=toDate || !toDate)) { if(periodi){ pronadjeno = false; for(var i=0;i=periodi[i].Od && d<=periodi[i].Do ){ var link = doc.createElement("a"); link.href="javascript:;"; link.onclick=link.touchstart=calendarDateSelect; link.date=d; link.innerHTML=d.getDate(); cell.appendChild(link); cell.className="RR"; pronadjeno = true; break; } } if(!pronadjeno){ cell.innerHTML = d.getDate(); } } else{ var link = doc.createElement("a"); link.href="javascript:;"; link.onclick=link.touchstart=calendarDateSelect; link.date=d; link.innerHTML=d.getDate(); cell.appendChild(link); } } else{ cell.innerHTML = d.getDate(); } if(selectedDate && d.getTime()==selectedDate.getTime()){ cell.className+="selected"; } d = new Date(d.getTime()+dayMili); if(firstX==-1) firstX = x; } } function calendarInit(){ var div; div = window.document.getElementById("calendarDiv"); if(!div){ div = window.document.createElement("div"); div.style.visibility = "hidden"; div.style.position = "absolute"; div.style.left = "0px"; div.style.top = "0px"; div.style.zIndex = "1000"; div.id = "calendarDiv"; window.document.body.appendChild(div); div.innerHTML = ""; div2 = window.document.createElement("div"); div2.style.display = "none"; div2.style.position = "absolute"; div2.style.left = "0px"; div2.style.right = "0px"; div2.style.width = "100%"; div2.style.height = "100%"; /* doc = window.frames.calendar.document; doc.open(); doc.write(""); doc.write(""); doc.write(""); doc.write(" "); doc.write(""); doc.write(""); doc.write(""); doc.close(); */ /* window.frames.calendar.onblur=calendarClose; window.document.getElementById("calendar").onblur=calendarClose; */ } } window.onload=calendarInit;