var AgatCalendar={window_id:"agat_calendar",animationSpeed:200,show:function(evt1){var evt=evt1.originalEvent;var dateElem=$(evt1.target).prev()[0];var doc=document;var dateFormat=$(dateElem).hasAttribute("tfsFormat")?$(dateElem).attr("tfsFormat").toLowerCase():"dmy";var dateobj=AgatCalendar.parseDate(dateElem.value,dateFormat);if(!dateobj)dateobj=new Date();var x=evt1.pageX;var y=evt1.pageY;if(y+200>doc.body.scrollTop+doc.body.clientHeight){y=doc.body.scrollTop+doc.body.clientHeight-220;}
var popup=doc.getElementById(AgatCalendar.window_id);if(!popup){popup=doc.createElement("div");popup.id=AgatCalendar.window_id;$(popup).hide();AgatCalendar.build(popup);$(popup).appendTo("body");}
$(document).bind("mousedown",AgatCalendar.mouseHandler);popup.style.position="absolute";popup.style.top=y;popup.style.left=x;popup.style.width=220;popup.style.backgroundColor="white";popup.style.zIndex=100;$(popup).show();popup.focus();var lang=AgatEngine.getGeneralAttribute("tfsLanguage").toLowerCase();AgatCalendar.populateByDate(lang,popup,dateobj);var caldata={dateElem:dateElem,dateobj:dateobj,lang:lang,dateFormat:dateFormat,popup:popup};doc._agat_caldata=caldata;},build:function(popup){var files={"*hebrew":"hebrew","*english":"english"};var file=files['*'+AgatEngine.getGeneralAttribute("tfsLanguage").toLowerCase()]||"english";var html=AgatCalendarString[file];$(popup).append(html);$("img[tfssrc]",popup).each(function(){this.src=systemPictures+"/"+$(this).attr("tfsSrc");});popup.style.border="1px #666666 solid";$(popup).bind("click",AgatCalendar.clickHandler);},populateByDate:function(lang,popup,dateobj){var doc=document;var heb_months=['ינואר','פברואר','מרץ','אפריל','מאי','יוני','יולי','אוגוסט','ספטמבר','אוקטובר','נובמבר','דצמבר'];var eng_months=['January','February','March','April','May','June','July','August','September','October','November','December'];var month_names=(lang=="hebrew"?heb_months:eng_months);var month_name=month_names[dateobj.getMonth()];var heb_days=['ראשון','שני','שלישי','רביעי','חמישי','שישי','שבת'];var eng_days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];var weekday_names=(lang=="hebrew"?heb_days:eng_days);var weekday_name=weekday_names[dateobj.getDay()];var today_desc;if(lang=="hebrew"){today_desc="יום "+
weekday_name+" ה-"+
dateobj.getDate()+" ב"+
month_name;}else{today_desc=weekday_name+", "+dateobj.getDate()+" "+month_name.substr(0,3);}
$("#_cal_todayDesc").html(today_desc);$("#_cal_monthValue").hide();$("#_cal_monthValue").html(dateobj.getMonth());$("#_cal_monthCal").html(month_name);$("#_cal_yearCal").html(dateobj.getFullYear());var firstday=new Date(dateobj.getFullYear(),dateobj.getMonth(),1);var weekday1=firstday.getDay();var month_days=AgatCalendar.getMonthDays(dateobj.getMonth(),dateobj.getFullYear());for(var i=1;i<=42;i++){var button=$("#_cal_Button"+i,popup)[0];button.style.width='2em';button.style.margin='3px';button.style.backgroundColor='white';button.style.color='black';button.style.fontWeight='bold';button.style.border='solid 1px gray';button.style.fontSize='12px';button.style.cursor='pointer';var daynum=i-weekday1;if(1<=daynum&&daynum<=month_days){$(button).show();button.value=daynum;button.innerText=daynum;button.disabled=false;}else{$(button).hide();button.value="";button.innerText="";button.disabled=true;}}},getMonthDays:function(month,year){var months_days=[31,28,31,30,31,30,31,31,30,31,30,31];var month_days=months_days[month];if(year%4==0&&month==1){month_days++;}
return month_days;},parseDate:function(datestr,dateFormat){datestr=datestr.replace(/^\s+|\s+$/g);if(!datestr)return null;var ar=datestr.split("/");if(ar.length!=3)return null;var day,month,year;if(dateFormat=="dmy"){day=ar[0];month=ar[1];year=ar[2];}else{month=ar[0];day=ar[1];year=ar[2];}
var dateobj=new Date(year,month-1,day);if(isNaN(dateobj.getTime())){return null;}
return dateobj;},mouseHandler:function(evt1){var evt=evt1.originalEvent;var doc;if(evt.target!=null)doc=evt.target.ownerDocument;else doc=evt.srcElement.ownerDocument;var popup=doc.getElementById(AgatCalendar.window_id);if(!popup||popup.style.display=="none")return;if($(evt1.target).parents("#"+AgatCalendar.window_id).length>0)
return;if(document._agat_caldata!=undefined)
document._agat_caldata.dateElem.focus();AgatCalendar.close(popup);evt1.preventDefault();evt1.stopPropagation();},close:function(popup){$(popup).hide(AgatCalendar.animationSpeed);$(document).unbind("mousedown",AgatCalendar.mouseHandler);document._agat_caldata=undefined;},clickHandler:function(evt){var target;if(evt.target!=null)target=evt.target;else target=evt.srcElement;var doc=target.ownerDocument;var popup=doc.getElementById(AgatCalendar.window_id);var caldata=doc._agat_caldata;if(target.id.match(/^_cal_Button[0-9]+$/)){var dateobj=caldata.dateobj;if(target.value.toString().length==1)
var day='0'+target.value;else
var day=target.value;if((dateobj.getMonth()+1).toString().length==1)
var month="0"+(dateobj.getMonth()+1).toString();else
var month=(dateobj.getMonth()+1).toString();var year=dateobj.getFullYear().toString();var datestr;if(caldata.dateFormat=="dmy"){datestr=day+"/"+month+"/"+year;}else{datestr=month+"/"+day+"/"+year;}
$(caldata.dateElem).tfsValue(datestr);AgatCalendar.close(popup);return;}
if(target.id.match(/^_cal_month([0-9]+)$/)){var month=parseInt(RegExp.$1,10);doc.getElementById("_cal_displayMonth").style.display="none";var dateobj=caldata.dateobj;dateobj.setMonth(month);AgatCalendar.populateByDate(caldata.lang,caldata.popup,dateobj);return;}
if(target.id.match(/^_cal_year([0-9]+)$/)){var year=parseInt(RegExp.$1,10);doc.getElementById("_cal_displayMonth").style.display="none";var dateobj=caldata.dateobj;dateobj.setYear(year);AgatCalendar.populateByDate(caldata.lang,caldata.popup,dateobj);return;}
switch(target.id){case"yearCalDrop":case"_cal_yearCalDrop":AgatCalendar.showYearSelector(caldata);break;case"_cal_monthCalDrop":AgatCalendar.showMonthSelector(caldata);break;case"_cal_prev":AgatCalendar.updateYearSelector(caldata,-10);break;case"_cal_next":AgatCalendar.updateYearSelector(caldata,+10);break;}},showYearSelector:function(caldata){var popup=caldata.popup;var doc=popup.ownerDocument;var div=doc.getElementById("_cal_displayMonth");var thisYear=caldata.dateobj.getFullYear();var begin=Math.max(thisYear,1);var end=begin+10;var html="";html+="<div onmouseover='javascript:this.style.backgroundColor=\"Peachpuff\"' "+"onmouseout='javascript:this.style.backgroundColor=\"PapayaWhip\"' "+"style='cursor:pointer;width:100%' id='_cal_prev'>";html+="-</div>\n";for(var year=begin;year<end;year++){html+="<div onmouseover='javascript:this.style.backgroundColor=\"Peachpuff\"' "+"onmouseout='javascript:this.style.backgroundColor=\"PapayaWhip\"' "+"style='cursor:pointer;width:100%' id='_cal_year"+year+"'>";html+=year.toString()+"</div>\n";}
html+="<div onmouseover='javascript:this.style.backgroundColor=\"Peachpuff\"' "+"onmouseout='javascript:this.style.backgroundColor=\"PapayaWhip\"' "+"style='cursor:pointer;width:100%' id='_cal_next'>";html+="+</div>\n";div.innerHTML=html;var refElem=doc.getElementById("_cal_yearCal").parentNode;div.style.position="absolute";div.style.backgroundColor="PapayaWhip";div.style.border="solid 1px DarkGray";div.style.display="block";div.style.width=refElem.offsetWidth+"px";div.style.height="auto";div.style.dir="ltr";div.style.left=refElem.offsetLeft+"px";div.style.top=refElem.offsetHeight+"px";div.style.align="center";refElem.appendChild(div);},updateYearSelector:function(caldata,inc){var popup=caldata.popup;var doc=document;var div=$("#_cal_displayMonth",popup)[0];var elems=div.childNodes;for(var i=0;i<elems.length;i++){var elem=elems[i];if(!elem.id||!elem.id.match(/^_cal_year([0-9]+)$/))continue;var year=parseInt(RegExp.$1,10);year+=inc;elem.id="_cal_year"+year.toString();$(elem).text(year.toString());}},showMonthSelector:function(caldata){var popup=caldata.popup;var doc=popup.ownerDocument;var div=doc.getElementById("_cal_displayMonth");var html="";var heb_months=['ינואר','פברואר','מרץ','אפריל','מאי','יוני','יולי','אוגוסט','ספטמבר','אוקטובר','נובמבר','דצמבר'];var eng_months=['January','February','March','April','May','June','July','August','September','October','November','December'];var month_names=(caldata.lang=="hebrew"?heb_months:eng_months);for(var i=0;i<month_names.length;i++){html+="<div onmouseover='javascript:this.style.backgroundColor=\"Peachpuff\"' "+"onmouseout='javascript:this.style.backgroundColor=\"PapayaWhip\"' "+"style='cursor: pointer; width: 100%' id='_cal_month"+i+"'>"+
month_names[i]+"</div>\n";}
div.innerHTML=html;var refElem=doc.getElementById("_cal_monthCal").parentNode.parentNode;div.style.position="absolute";div.style.backgroundColor="PapayaWhip";div.style.border="solid 1px DarkGray";div.style.display="block";div.style.width=refElem.offsetWidth+"px";div.style.height="auto";div.style.left=refElem.offsetLeft+"px";div.style.top=refElem.offsetHeight+"px";refElem.appendChild(div);}};