var monthName = new Array('sij', 'vlj', 'ožu', 'tra', 'svi', 'lip', 'srp', 'kol', 'ruj', 'lis', 'stu', 'pro');
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.tagName!="BODY"){
x += o.offsetLeft;
y += o.offsetTop;
o=o.offsetParent;
}
var r = new Object();
r.x = x;
r.y = y;
return r;
}
function calendarClose(){
window.document.getElementById("calendarDiv").style.visibility = "hidden";
targetElement.focus();
}
function calendarPick(pdockElement, ptargetElement, pfromDate, ptoDate){
if(ptargetElement.disabled) return;
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();
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(coords.x + div.offsetWidth + 2 > window.document.body.offsetWidth){
coords.x = window.document.body.offsetWidth - div.offsetWidth - 2;
}
if(coords.y + div.offsetHeight + 2 > window.document.body.offsetHeight){
coords.y = window.document.body.offsetHeight - 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();
setTimeout("window.frames.calendar.focus()", 10);
}
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]));
}
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 += "| < | "+monthName[month]+" | > | "+year+" | ";
html += "
";
html += "
";
html += "";
html += "";
html += "| po | ";
html += "ut | ";
html += "sr | ";
html += "če | ";
html += "pe | ";
html += "su | ";
html += "ne | ";
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 += "
";
doc.body.innerHTML = html;
doc.getElementById('monthDec').onclick=calendarMonthDec;
doc.getElementById('monthInc').onclick=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 = calendarMonthSet;
monthSelect.appendChild(monthLink);
if(i==month) {
monthLink.className = "selected";
}
}
doc.getElementById("monthName").onclick = 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 = calendarYearSet;
yearSelect.appendChild(yearLink);
if(i==year){
yearLink.className = "selected";
}
}
doc.getElementById("yearName").onclick = calendarYearSelectShow
var day = 1;
var dayMili = 1000*60*60*24;
var d = new Date(year, month, day)
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)){
var link = doc.createElement("a");
link.href="javascript:;";
link.onclick=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.id = "calendarDiv";
window.document.body.appendChild(div);
div.innerHTML = "";
/*
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;