function initPage()
{Event.observe(document,'click',onClick,true);famundoApplication.adjust_page();famundoApplication.adjust_layout();FamundoMainUtils.addStopTTListner();}
function onClick(e)
{var elem=Event.element(e);var div=Event.findElement(e,'div');if(div==document)
div=false;if(div&&Element.hasClassName(div,'message_board_message_text'))
{toggleMessage(div,'message_board_message_text_height')}
if(div&&Element.hasClassName(div,'message_board_reply_text'))
{toggleMessage(div,'message_board_reply_text_height')}
if(Element.hasClassName(elem,'ec_arrow'))
{famundoApplication.toggleBox(e,'can_be_hidden');famundoApplication.adjust_page();}}
function toggleMessage(elem,visibleClassName)
{if(Element.hasClassName(elem,visibleClassName))
{Element.removeClassName(elem,visibleClassName);Element.addClassName(elem,'height_auto');}
else
{Element.removeClassName(elem,'height_auto');Element.addClassName(elem,visibleClassName);}}
var famundoMessages={setConversationIcon:function(conversation_id,color_id,count)
{(count>1)?famundoMessages._showMultipleMessagesIcon(conversation_id,color_id):famundoMessages._showOneMessageIcon(conversation_id,color_id);},_showMultipleMessagesIcon:function(conversation_id,color_id)
{var icon_id="message_board_message_icon_"+conversation_id;Element.removeClassName($(icon_id),'message_board_message_icon');Element.removeClassName($(icon_id),'bg_mb_message_user'+color_id);Element.addClassName($(icon_id),'message_board_multi_message_icon');Element.addClassName($(icon_id),'bg_mb_multi_message_user'+color_id);},_showOneMessageIcon:function(conversation_id,color_id)
{var icon_id="message_board_message_icon_"+conversation_id;Element.removeClassName($(icon_id),'message_board_multi_message_icon');Element.removeClassName($(icon_id),'bg_mb_multi_message_user'+color_id);Element.addClassName($(icon_id),'message_board_message_icon');Element.addClassName($(icon_id),'bg_mb_message_user'+color_id);}}
function setMessagesBgColor()
{famundoApplication.alternateClasses('message_board_messages','message_board_root_message',['item_background','background_white'],['message_board_message_text','message_board_message_header']);}
function set_reminder_events()
{famundoApplication.alternateClasses('message_board_reminders','message_board_reminder_item',['item_background','background_white']);document.getElementsByClassName('highlight',$('message_board_reminders')).each(function(elem)
{Event.observe($(elem),'mouseover',function(){Element.addClassName(elem,'mouseover_background');});Event.observe($(elem),'mouseout',function(){Element.removeClassName(elem,'mouseover_background');});});}
function set_todo_events()
{famundoApplication.alternateClasses('message_board_todos','message_board_todo_item',['item_background','background_white']);document.getElementsByClassName('highlight',$('message_board_todos')).each(function(elem)
{Event.observe($(elem),'mouseover',function(){Element.addClassName(elem,'mouseover_background');});Event.observe($(elem),'mouseout',function(){Element.removeClassName(elem,'mouseover_background');});});}
function openMBEditForm(id,msg_type)
{switch(msg_type)
{case'todo':var action=famundoMessageUrl.get_edit_todo;break;case'reminder':var action=famundoMessageUrl.get_edit_reminder;break;}
var container=$('form_edit_'+msg_type+'_'+id);if($('form_'+msg_type+'_'+id))
{famundoForms.setFormElements(container);famundoForms.displayInpageForm(container);}
else
{var f=function(){return new Ajax.Updater(container,action,{parameters:"id="+id,evalScripts:true,asynchronous:true,method:'post',onComplete:function(){famundoForms.displayInpageForm(container);}});}
famundoActions.add({func:f,action_type:'ajax',action_id:'edit_'+msg_type,limit:1,limit_type:'remove'});}}
function afterMBEdit(id,msg_type)
{famundoApplication.enableShowOnMouseOver('message_board_'+msg_type+'_actions_'+id);setTimeout("set_"+msg_type+"_events()",400);setTimeout(function(){famundoApplication.afterUpdateEffect('message_board_'+msg_type+'_'+id)},500);afterSubmitInpageForm('form_edit_'+msg_type+'_'+id);if(msg_type=='todo')
famundoApplication.FCKEditor.reset();}
function openDeletePopup(open_for,id,page)
{switch(open_for)
{case'message':var update_elem='messages_content';var url=famundoMessageUrl.get_delete_message+'?id='+id+'&page='+page||1;var caption=famundoMessageText.deleteMessage;var after_delete=function(){};break;case'todo':var update_elem='todos_content';var url=famundoMessageUrl.get_delete_todo+'?id='+id+'&page='+page||1;var caption=famundoMessageText.deleteTodo;var after_delete=function(){famundoApplication.afterDeleteEffect(item_id);};break;case'notice':var update_elem='todos_content';var url=famundoMessageUrl.get_delete_todo+'?id='+id+'&page='+page||1;var caption=famundoMessageText.deleteNotice;var after_delete=function(){famundoApplication.afterDeleteEffect(item_id);};break;case'reminder':var update_elem='reminders_content';var url=famundoMessageUrl.get_delete_reminder+'?id='+id+'&page='+page||1;var caption=famundoMessageText.deleteReminder;var after_delete=function(){famundoApplication.afterDeleteEffect(item_id);};break;}
var del_action=function()
{var myAjax=new Ajax.Request(url,{method:'post',parameters:"",evalScripts:true,onLoading:after_delete});};famundoApplication.openConfirmWindow(caption,famundoGenText.confirm_delete,{'ok_action':del_action});}
function selectUserCallback(user_id,params)
{var f=function(){var params='?selected_user_id='+user_id;var options={asynchronous:true,evalScripts:true,method:'get'};new Ajax.Updater('content_for_msg_board',famundoMessageUrl.get_content_for_msg_board+params,options);}
famundoActions.add({func:f,action_type:'ajax',action_id:'user_messages',limit:2,limit_type:'remove'});famundoActions.add({func:function(){famundoApplication.adjust_page();},action_type:'secvential'});}
function initMessageboard()
{famundoHeaderUserList.setCallBack(selectUserCallback,0);initPage();}
global_initializers.push(function(){initMessageboard();});var famundoDateUtil={oneMinute:60*1000,oneHour:60*1000*60,oneDay:60*1000*60*24,oneWeek:60*1000*60*24*7,shortMonthName:famundoDateUtilTxt.shortMonthName,longMonthName:famundoDateUtilTxt.longMonthName,shortDayName:famundoDateUtilTxt.shortDayName,longDayName:famundoDateUtilTxt.longDayName,leterOfWeekDay:famundoDateUtilTxt.leterOfWeekDay,todayTxt:famundoDateUtilTxt.todayTxt,tomorrowTxt:famundoDateUtilTxt.tomorrowTxt,yesterdayTxt:famundoDateUtilTxt.yesterdayTxt,nextWeekTxt:famundoDateUtilTxt.nextWeekTxt,nextMonthTxt:famundoDateUtilTxt.nextMonthTxt,nextYearTxt:famundoDateUtilTxt.nextYearTxt,lastWeekTxt:famundoDateUtilTxt.lastWeekTxt,lastMonthTxt:famundoDateUtilTxt.lastMonthTxt,lastYearTxt:famundoDateUtilTxt.lastYearTxt,atTxt:famundoDateUtilTxt.atTxt,hourTxt:famundoDateUtilTxt.hourTxt,minutesTxt:famundoDateUtilTxt.minutesTxt,thTxt:famundoDateUtilTxt.thTxt,thOfTxt:famundoDateUtilTxt.thOfTxt,nextTxt:famundoDateUtilTxt.nextTxt,lastTxt:famundoDateUtilTxt.lastTxt,dateSeparator:famundoUserSettings.display.date.separator,parseISO:function(dateStr,noTime)
{var r=dateStr.match(/^\s*(\d\d\d\d)[^\d]*(\d\d)[^\d]*(\d\d)[^\d]*(\d\d)?[^\d]*(\d\d)?[^\d]*(\d\d)?/);if(!r)
return null;function sparseInt(s){return s?parseInt(s,10):0;}
function in_range(n,b,t){return((b<=n)&&(n<=t));}
var year=parseInt(r[1],10);var month=parseInt(r[2],10);if(!in_range(month,1,12))return null;var day=parseInt(r[3],10);if(!in_range(day,1,31))return null;var hour=sparseInt(r[4],10);if(!in_range(hour,0,23))return null;var min=sparseInt(r[5],10);if(!in_range(min,0,59))return null;var sec=sparseInt(r[6],10);if(!in_range(sec,0,59))return null;if(!noTime)
return new Date(year,month-1,day,hour,min,sec);else
return new Date(year,month-1,day);},getShortMonthName:function(month)
{return famundoDateUtil.shortMonthName[month];},getLongMonthName:function(month)
{return famundoDateUtil.longMonthName[month];},getLeterOfWeekDay:function(day)
{return famundoDateUtil.leterOfWeekDay[day];},getFirstDayOfWeek:function()
{return famundoUserSettings.calendar.settings.first_day_of_week;},getFirstWeekDayOfMonth:function(year,month)
{var dt=new Date(year,month,1);return dt.getDay();},getLastDayOfMonth:function(year,month)
{var dt=new Date(year,month,1);dt.setMonth(month+1);dt.setTime(dt.getTime()-famundoDateUtil.oneDay);return dt.getDate();},getMonthFromMonthName:function(monthStr)
{monthStr=monthStr.toUpperCase();for(var i=0;i<12;++i)
{if((monthStr==famundoDateUtil.shortMonthName[i].toUpperCase())||(monthStr==famundoDateUtil.longMonthName[i].toUpperCase()))
return i}
return null;},getDayFromDayName:function(dayStr)
{dayStr=dayStr.toUpperCase();for(var i=0;i<7;++i)
{if((dayStr==famundoDateUtil.shortDayName[i].toUpperCase())||(dayStr==famundoDateUtil.longDayName[i].toUpperCase())||(dayStr==famundoDateUtil.leterOfWeekDay[i].toUpperCase()))
return i}
return null;},getShortWeekDay:function(dn)
{return famundoDateUtil.shortDayName[dn];},getTextAM:function()
{return famundoDateUtilTxt.am;},getTextPM:function()
{return famundoDateUtilTxt.pm;},addDays:function(data,nDays)
{var result=new Date(data.getTime());result.setDate(data.getDate()+nDays);return result;},addMinutes:function(data,nMinutes)
{return(new Date(data.getTime()+(nMinutes*1000*60)));},getDayHours:function(hStart,format,half,h24)
{var rows=new Array();var rown=new Array();var rows24=new Array();var rowz=new Array();var rowz24=new Array();var result=new Array();var ext=(hStart<12)?famundoDateUtil.getTextAM():famundoDateUtil.getTextPM();if(format==null)
format='n';var j=0;for(var i=0;i<24;i++)
{if((hStart+i)<12)
{rows[i]=hStart+i+ext;rows24[i]=hStart+i+ext;rown[i]=hStart+i;rowz[j]=(hStart+i).zTrail(2)+':00 '+ext;rowz24[j]=(hStart+i).zTrail(2)+':00 ';if(half)
{j++;rowz[j]=(hStart+i).zTrail(2)+':30 '+ext;rowz24[j]=(hStart+i).zTrail(2)+':30 ';}
j++;}
else if((hStart+i)==12)
{rows[i]='Noon';rows24[i]='Noon';rown[i]=12;rowz[j]='12:00 '+famundoDateUtil.getTextPM();rowz24[j]='Noon';if(half)
{j++;rowz[j]='12:30 '+famundoDateUtil.getTextPM()
rowz24[j]='12:30 '+famundoDateUtil.getTextPM()}
j++;}
else if((hStart+i)>12&&(hStart+i)<24)
{ext=famundoDateUtil.getTextPM();rows[i]=hStart+i-12+ext;rows24[i]=hStart+i;rown[i]=hStart+i;rowz[j]=(hStart+i-12).zTrail(2)+':00 '+ext;rowz24[j]=(hStart+i).zTrail(2)+':00 ';if(half)
{j++;rowz[j]=(hStart+i-12).zTrail(2)+':30 '+ext;rowz24[j]=(hStart+i).zTrail(2)+':30 ';}
j++;}
else if((hStart+i)==24)
{rows[i]='Midnight';rows24[i]='Midnight';rown[i]=0;ext=famundoDateUtil.getTextAM();rowz[j]='00:00 '+famundoDateUtil.getTextAM();rowz24[j]='Midnight';if(half)
{j++;rowz[j]='00:30 '+famundoDateUtil.getTextAM();rowz24[j]='00:30 ';}
j++;hStart=0;}}
if(!h24)
result[0]=rows;else
result[0]=rowz24;result[1]=rown;if(format=='n')
return result[1];else if(format=='s')
return result[0];else if(format=='z')
if(!h24)
return rowz;else
return rowz24;return result;},parseTime:function(timeStr)
{function validateHourMin(hourStr,minStr,apStr)
{var hour=parseInt(hourStr,10);if(hour==12&&apStr&&(apStr.toLowerCase()=='a'))
hour=0;else if(apStr&&(apStr.toLowerCase()=='p')&&hour!=12)
hour+=12;if((hour<0)||(hour>23))
return null;var min=0;if(minStr)
{min=parseInt(minStr,10);if((min<0)||(min>59))
return null;}
return[hour,min];}
var result=timeStr.match(/^\s*(\d?\d)\s*[:-]?\s*(\d\d)?\s*(p|a)?m?\s*$/i);if(result)
return validateHourMin(result[1],result[2],result[3]);return null;},createDateParserReExpArray:function()
{famundoDateUtil.dateParserReExpArray=[];function matchMonth(monthArray,monthStr)
{for(var i=0;i<monthArray.length;++i)
{if(monthArray[i].toLowerCase()==monthStr.toLowerCase())
return(i+1);}
return null;}
function validateTime(timeStr,parseTime)
{if(parseTime&&timeStr&&!timeStr.match(/^\s*$/))
return famundoDateUtil.parseTime(timeStr);return[0,0];}
function validateMonth(monthStr)
{if(!monthStr)
return null;var month=null;var mm=monthStr.match(/^\s*(\d?\d)\s*$/);if(mm)
{month=parseInt(mm[1],10);return((1<=month)&&(month<=12))?month:null;}
month=matchMonth(famundoDateUtil.shortMonthName,monthStr);if(month)
return month;return matchMonth(famundoDateUtil.longMonthName,monthStr);}
function validateDate(yearStr,monthStr,dayStr,timeStr,parseTime)
{var hour_min=validateTime(timeStr,parseTime);if(!hour_min)
return null;var month=validateMonth(monthStr);if(!month)
return null;var year=parseInt(yearStr,10);if(year<100)
year+=2000;var day=parseInt(dayStr,10);var lastDayOfMonth=famundoDateUtil.getLastDayOfMonth(year,month-1);if((day<1)||(day>lastDayOfMonth))
return null;return new Date(year,month-1,day,hour_min[0],hour_min[1]);}
var usaRe=/^\s*(\w+)[ \/,;.\\]\s*(\d?\d)[ \/,;.\\]\s*((\d\d){1,2})(\s.*)?$/i;function validateDateResultUSA(result,parseTime)
{return validateDate(result[3],result[1],result[2],result[5],parseTime);}
var euRe=/^\s*(\d?\d)[ \/,;.\\]\s*(\w+)[ \/,;.\\]\s*((\d\d){1,2})(\s.*)?$/i;function validateDateResultEU(result,parseTime)
{return validateDate(result[3],result[2],result[1],result[5],parseTime);}
var isoRe=/^\s*((\d\d){1,2})[ \/,;.\\]\s*(\w+)[ \/,;.\\]\s*(\d?\d)(\s.*)?$/i;function validateDateResultISO(result,parseTime)
{return validateDate(result[1],result[3],result[4],result[5],parseTime);}
function txt2RegExpr(txt)
{var rs="^\\s*"+txt+"(\\s.*)?$";rs=rs.replace(/\s+/,"\\s+");return new RegExp(rs,"i");}
function push1(text,regExpr,procedure,paramValue)
{famundoDateUtil.dateParserReExpArray.push({txt:text,regexpr:regExpr,proc:procedure,param:paramValue});}
function pusha(texta,procedure,paramValue)
{$A(texta).each(function(text,i){push1(text,txt2RegExpr(text),procedure,paramValue);});}
function createRemoveAtRegExpr()
{var rs="^\\s*(";for(var i=0;i<famundoDateUtil.atTxt.length;++i)
{rs+='('+famundoDateUtil.atTxt[i]+')';if((i+1)<famundoDateUtil.atTxt.length)
rs+='|';}
rs+=")?(.*)?$";famundoDateUtil.removeAtRegExpr=new RegExp(rs,"i");}
createRemoveAtRegExpr();function removeAtStr(txt)
{var result=txt.match(famundoDateUtil.removeAtRegExpr);if(result)
{return result[famundoDateUtil.atTxt.length+2];}
return txt;}
function addShortcutTime(dt,result,parseTime)
{if(parseTime&&result[1])
{timeStr=removeAtStr(result[1]);if(timeStr)
{var hour_min=validateTime(timeStr,parseTime);if(hour_min)
{dt.setHours(hour_min[0]);dt.setMinutes(hour_min[1]);}}}
else if(!parseTime)
{dt.setHours(0);dt.setMinutes(0);}
return dt;}
function validateToday(result,parseTime)
{return addShortcutTime(new Date(),result,parseTime)}
pusha(famundoDateUtil.todayTxt,validateToday);function validateTomorrow(result,parseTime)
{var dt=new Date();dt.setTime(dt.getTime()+famundoDateUtil.oneDay);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.tomorrowTxt,validateTomorrow);function validateYesterday(result,parseTime)
{var dt=new Date();dt.setTime(dt.getTime()-famundoDateUtil.oneDay);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.yesterdayTxt,validateYesterday);function validateNextWeek(result,parseTime)
{var dt=new Date();dt.setTime(dt.getTime()+7*famundoDateUtil.oneDay);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.nextWeekTxt,validateNextWeek);function validateNextMonth(result,parseTime)
{var dt=new Date();dt.setMonth(dt.getMonth()+1);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.nextMonthTxt,validateNextMonth);function validateNextYear(result,parseTime)
{var dt=new Date();dt.setFullYear(dt.getFullYear()+1);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.nextYearTxt,validateNextYear);function validateLastWeek(result,parseTime)
{var dt=new Date();dt.setTime(dt.getTime()-7*famundoDateUtil.oneDay);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.lastWeekTxt,validateLastWeek);function validateLastMonth(result,parseTime)
{var dt=new Date();dt.setMonth(dt.getMonth()-1);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.lastMonthTxt,validateLastMonth);function validateLastYear(result,parseTime)
{var dt=new Date();dt.setFullYear(dt.getFullYear()-1);return addShortcutTime(dt,result,parseTime)}
pusha(famundoDateUtil.lastYearTxt,validateLastYear);function validateWeekDay(result,parseTime,weekDay)
{var dt=new Date();var daysToMove=(weekDay-dt.getDay()+7)%7;dt.setTime(dt.getTime()+daysToMove*famundoDateUtil.oneDay);return addShortcutTime(dt,result,parseTime)}
for(var weekDay=0;weekDay<7;++weekDay)
{var dayNames=[famundoDateUtil.shortDayName[weekDay],famundoDateUtil.longDayName[weekDay]];pusha(dayNames,validateWeekDay,weekDay);}
switch(famundoUserSettings.display.date.style)
{case'eu':push1("",euRe,validateDateResultEU);break;case'iso':push1("",isoRe,validateDateResultISO);break;default:push1("",usaRe,validateDateResultUSA);break;}
function addReOptions(optionArray,optionArray2,optionArray3)
{var s="(";for(var i=0;i<optionArray.length;++i)
{s+=optionArray[i];if((i+1)!=optionArray.length)
s+="|";}
if(optionArray2)
{s+="|";for(var i=0;i<optionArray2.length;++i)
{s+=optionArray2[i];if((i+1)!=optionArray2.length)
s+="|";}}
if(optionArray3)
{s+="|";for(var i=0;i<optionArray3.length;++i)
{s+=optionArray3[i];if((i+1)!=optionArray3.length)
s+="|";}}
s+=")";return s;}
var monthDayRe="^\\s*"+
addReOptions(famundoDateUtil.longMonthName,famundoDateUtil.shortMonthName)+"\\s*(\\d?\\d)(\\s.*?)?$";function validateMonthDay(result,parseTime,param)
{var dt=new Date();var dayStr=result[2];var day=parseInt(dayStr,10);if((day==null)||(day<1)||(day>31))
return null;var m=famundoDateUtil.getMonthFromMonthName(result[1]);if(m==null)
return null;var monthStr=''+(m+1);var year=dt.getFullYear();if((dt.getMonth()>m)||((dt.getMonth()==m)&&(dt.getDate()>day)))
++year;var yearStr=''+year;var timeStr=result[3];return validateDate(yearStr,monthStr,dayStr,timeStr,parseTime)}
push1("month_day",new RegExp(monthDayRe,"i"),validateMonthDay,null);var thRe="^\\s*(\\d?\\d)\\s*"+
addReOptions(famundoDateUtil.thTxt)+"((\\s+"+famundoDateUtil.thOfTxt+")?\\s+"+
addReOptions(famundoDateUtil.longMonthName,famundoDateUtil.shortMonthName)+")?(\\s+(\\d\\d\\d\\d))?(\\s.*?)?$";function validateTh(result,parseTime,param)
{var dt=new Date();var dayStr=result[1];var monthStr=''+(dt.getMonth()+1);if(result[5])
{var m=famundoDateUtil.getMonthFromMonthName(result[5]);if(m==null)
return null;monthStr=''+(m+1);}
var yearStr=(result[7])?(result[7]):(''+dt.getFullYear());var timeStr=result[8];return validateDate(yearStr,monthStr,dayStr,timeStr,parseTime)}
push1("th",new RegExp(thRe,"i"),validateTh,null);var nextDayNameRe="^\\s*"+famundoDateUtil.nextTxt+"\\s+"+
addReOptions(famundoDateUtil.longDayName,famundoDateUtil.shortDayName,famundoDateUtil.leterOfWeekDay)+"(\\s.*?)?$";function validateNextWeekDay(result,parseTime)
{var weekDay=famundoDateUtil.getDayFromDayName(result[1]);if(null==weekDay)
return null;var dt=new Date();var daysToMove=(weekDay-dt.getDay()+7)%7;dt.setTime(dt.getTime()+daysToMove*famundoDateUtil.oneDay);var yearStr=''+dt.getFullYear();var monthStr=''+(dt.getMonth()+1);var dayStr=''+dt.getDate();var timeStr=result[2];return validateDate(yearStr,monthStr,dayStr,timeStr,parseTime)}
push1("next week day",new RegExp(nextDayNameRe,"i"),validateNextWeekDay,null);var lastDayNameRe="^\\s*"+famundoDateUtil.lastTxt+"\\s+"+
addReOptions(famundoDateUtil.longDayName,famundoDateUtil.shortDayName,famundoDateUtil.leterOfWeekDay)+"(\\s.*?)?$";function validateLastWeekDay(result,parseTime)
{var weekDay=famundoDateUtil.getDayFromDayName(result[1]);if(null==weekDay)
return null;var dt=new Date();var daysToMove=(dt.getDay()-weekDay+7)%7;dt.setTime(dt.getTime()-daysToMove*famundoDateUtil.oneDay);var yearStr=''+dt.getFullYear();var monthStr=''+(dt.getMonth()+1);var dayStr=''+dt.getDate();var timeStr=result[2];return validateDate(yearStr,monthStr,dayStr,timeStr,parseTime)}
push1("last week day",new RegExp(lastDayNameRe,"i"),validateLastWeekDay,null);var endTimeRe="^\\s*(\\d?\\d)\\s*"+
addReOptions(famundoDateUtil.hourTxt)+"\\s*((\\d?\\d)\\s*"+
addReOptions(famundoDateUtil.minutesTxt)+"\\s*)?$";function validateEndTime(result,parseTime,param,getDateTimeProc)
{if(!parseTime||!getDateTimeProc)
return null;var dt=getDateTimeProc();if(!dt)
return null;var hours=parseInt(result[1],10);var min=result[4]?parseInt(result[4],10):0;dt.setMinutes(dt.getMinutes()+min+hours*60);return dt;}
push1("end time",new RegExp(endTimeRe,"i"),validateEndTime,null);var endTimeMinRe="^\\s*(\\d?\\d)\\s*"+
addReOptions(famundoDateUtil.minutesTxt)+"\\s*?$";function validateEndTimeMin(result,parseTime,param,getDateTimeProc)
{if(!parseTime||!getDateTimeProc)
return null;var dt=getDateTimeProc();if(!dt)
return null;var min=parseInt(result[1],10);dt.setMinutes(dt.getMinutes()+min);return dt;}
push1("end time in minutes",new RegExp(endTimeMinRe,"i"),validateEndTimeMin,null);},parseDate:function(dateStr,parseTime,getDateTimeProc)
{if(!famundoDateUtil.dateParserReExpArray)
famundoDateUtil.createDateParserReExpArray();for(var i=0;i<famundoDateUtil.dateParserReExpArray.length;++i)
{var parseInfo=famundoDateUtil.dateParserReExpArray[i];var result=dateStr.match(parseInfo.regexpr);if(result)
return parseInfo.proc(result,parseTime,parseInfo.param,getDateTimeProc);}
return null;},formatTime:function(hours,min,isAmPm)
{if(isAmPm==null)
isAmPm=famundoUserSettings.display.time.is_am_pm;var ampm='';if(isAmPm)
{if(hours>=12)
{ampm=' '+famundoDateUtil.getTextPM();hours-=12;}
else
{ampm=' '+famundoDateUtil.getTextAM();}
if(hours==0)
hours=12;}
return hours.zTrail(2)+':'+min.zTrail(2)+ampm;},formatDate2ISO:function(dt,withTime)
{return dt.strftime(withTime?"%Y-%m-%d %H:%M":"%Y-%m-%d");}};var famundoDayPicker={getSelectedDate:function(id)
{var dayPicElm=$(id);return new Date(dayPicElm.selectedYear,dayPicElm.selectedMonth,dayPicElm.selectedDay,dayPicElm.hour,dayPicElm.minute,0);},getCurrentDate:function(id)
{var dayPicElm=$(id);return new Date(dayPicElm.year,dayPicElm.month,1);},setCurrentDate:function(id,dt)
{var dayPicElm=$(id);dayPicElm.year=dt.getFullYear();dayPicElm.month=dt.getMonth();famundoDayPicker.setCaption(dayPicElm);famundoDayPicker.setMonthDays(dayPicElm);},setSelectedDate:function(id,dt)
{var dayPicElm=$(id);if(dayPicElm.autoSelect)
{famundoDayPicker.setDateAndSelectedDate(id,dt);return;}
dayPicElm.selectedYear=dt.getFullYear();dayPicElm.selectedMonth=dt.getMonth();dayPicElm.selectedDay=dt.getDate();dayPicElm.hour=dt.getHours();dayPicElm.minute=dt.getMinutes();famundoDayPicker.setCaption(dayPicElm);famundoDayPicker.setMonthDays(dayPicElm);famundoDayPicker.displayTime(dayPicElm);},setDateAndSelectedDate:function(id,dt)
{var dayPicElm=$(id);dayPicElm.year=dt.getFullYear();dayPicElm.month=dt.getMonth();dayPicElm.selectedYear=dt.getFullYear();dayPicElm.selectedMonth=dt.getMonth();dayPicElm.selectedDay=dt.getDate();dayPicElm.hour=dt.getHours();dayPicElm.minute=dt.getMinutes();famundoDayPicker.setCaption(dayPicElm);famundoDayPicker.setMonthDays(dayPicElm);famundoDayPicker.displayTime(dayPicElm);},setDateSelectionHandler:function(id,func)
{$(id).selectionHandler=func;},setDateViewChangedHandler:function(id,func)
{$(id).dateViewChangedHandler=func;},setNextMonthHandler:function(id,func)
{$(id).dateNextMonthHandler=func;},setNextYearHandler:function(id,func)
{$(id).dateNextYearHandler=func;},setPreviousMonthHandler:function(id,func)
{$(id).datePreviousMonthHandler=func;},setPreviousYearHandler:function(id,func)
{$(id).datePreviousYearHandler=func;},setTodayHandler:function(id,func)
{$(id).dateTodayHandler=func;},setTimeChangedHandler:function(id,func)
{$(id).timeChangedHandler=func;},setOkHandler:function(id,func)
{$(id).okHandler=func;},setCancelHandler:function(id,func)
{$(id).cancelHandler=func;},isTimeDisplayed:function(id)
{return $(id).pickTime;},markMonthDays:function(id,days2mark)
{var dayPicElm=$(id);dayPicElm.markDaysA=days2mark?$A(days2mark):null;if(dayPicElm.markDaysA)
{dayPicElm.markMonth=dayPicElm.month;dayPicElm.markYear=dayPicElm.year;}
else
{dayPicElm.markMonth=null;dayPicElm.markYear=null;}
famundoDayPicker.setMonthDays(dayPicElm);},onMonthNav:function(e)
{var el=famundoUtils.getEventElement(e,'img');if(el==null)return;var dayPicElm=famundoUtils.ascendDOM(el,'table');var dt=new Date(dayPicElm.year,dayPicElm.month,1);if(el.actionStr=='go_prev_year')
{dt.setYear(dayPicElm.year-1);dayPicElm.navHandler=dayPicElm.datePreviousYearHandler;}
else if(el.actionStr=='go_prev_month')
{var mDiff=dayPicElm.month-1
var yr=mDiff<0?(dayPicElm.year-1):(dayPicElm.year);mDiff=mDiff<0?11:mDiff;dt.setMonth(mDiff);dt.setYear(yr);dayPicElm.navHandler=dayPicElm.datePreviousMonthHandler;}
else if(el.actionStr=='go_today')
{dt=new Date();dayPicElm.selectedDay=dt.getDate();dayPicElm.navHandler=dayPicElm.dateTodayHandler;}
else if(el.actionStr=='go_next_month')
{dt.setMonth(dayPicElm.month+1);dayPicElm.navHandler=dayPicElm.dateNextMonthHandler;}
else if(el.actionStr=='go_next_year')
{dt.setYear(dayPicElm.year+1);dayPicElm.navHandler=dayPicElm.dateNextYearHandler;}
dayPicElm.year=dt.getFullYear();dayPicElm.month=dt.getMonth();if(dayPicElm.autoSelect)
{dayPicElm.selectedYear=dayPicElm.year;dayPicElm.selectedMonth=dayPicElm.month;var lastDayOfMonth=famundoDateUtil.getLastDayOfMonth(dayPicElm.year,dayPicElm.month);if(dayPicElm.selectedDay>lastDayOfMonth)
dayPicElm.selectedDay=lastDayOfMonth;}
famundoDayPicker.setCaption(dayPicElm);famundoDayPicker.setMonthDays(dayPicElm);if(dayPicElm.navHandler)
dayPicElm.navHandler(dayPicElm,dayPicElm.year,dayPicElm.month);if(dayPicElm.dateViewChangedHandler)
dayPicElm.dateViewChangedHandler(dayPicElm,dayPicElm.year,dayPicElm.month);if(dayPicElm.autoSelect&&dayPicElm.selectionHandler)
{dayPicElm.selectionHandler(dayPicElm,famundoDayPicker.getSelectedDate(dayPicElm),true);}},onMouseOverNavElm:function(e)
{var el=famundoUtils.getEventElement(e,'img');if(el==null)return;Element.removeClassName(el,'day_pick_'+el.actionStr);Element.addClassName(el,'day_pick_'+el.actionStr+'_hover');},onMouseOutNavElm:function(e)
{var el=famundoUtils.getEventElement(e,'img');if(el==null)return;Element.removeClassName(el,'day_pick_'+el.actionStr+'_hover');Element.addClassName(el,'day_pick_'+el.actionStr);},onMouseOverCell:function(e)
{var el=famundoUtils.getEventElement(e,'td');if(el==null)return;if(famundoUtils.isOfClass(el,'day_pick_valid_day')&&!famundoUtils.isOfClass(el,'day_pick_selected'))
{Element.addClassName(el,'day_pick_mouseover');}},onMouseOutCell:function(e)
{var el=famundoUtils.getEventElement(e,'td');if(el==null)return;Element.removeClassName(el,'day_pick_mouseover');},selectCellDay:function(cell)
{if(famundoUtils.isOfClass(cell,'day_pick_valid_day'))
{var dayPicElm=famundoUtils.ascendDOM(cell,'table');if(dayPicElm.autoSelect)
{dayPicElm.selectedYear=dayPicElm.year;dayPicElm.selectedMonth=dayPicElm.month;dayPicElm.selectedDay=cell.dayOfMonth;famundoDayPicker.setMonthDays(dayPicElm);}
if(dayPicElm.selectionHandler)
{dayPicElm.selectionHandler(dayPicElm,new Date(dayPicElm.year,dayPicElm.month,cell.dayOfMonth,dayPicElm.hour,dayPicElm.minute,0),false);}}},onMouseDown:function(e)
{var el=famundoUtils.getEventElement(e,'td');if(el==null)return;setTimeout(function(){famundoDayPicker.selectCellDay(el);},100);},onDblClickCell:function(e)
{var el=famundoUtils.getEventElement(e,'td');if(el==null)return;if(!famundoUtils.isOfClass(el,'day_pick_valid_day'))return;if(famundoUtils.isIE||famundoUtils.isSafari)
famundoDayPicker.onOK(e);else
setTimeout(function(){famundoDayPicker.onOK(e);},110);},parseTimeInputText:function(dayPicElm)
{dayPicElm.parseTimeInputTextTimerID=null;var hour_min=famundoDateUtil.parseTime(dayPicElm.timeTextElm.value);if(hour_min)
{dayPicElm.hour=hour_min[0];dayPicElm.minute=hour_min[1];Element.removeClassName(dayPicElm.timeTextElm,'day_pick_time_format_error');}
else
{Element.addClassName(dayPicElm.timeTextElm,'day_pick_time_format_error');}},onTimeTxtKeydown:function(e)
{var dayPicElm=famundoUtils.getEventElement(e,'table');if(dayPicElm==null)return;function getEventKey(evt)
{evt=(evt)?evt:(window.event)?window.event:null;var theKey;if(evt)
theKey=(evt.which)?evt.which:evt.keyCode;return theKey;}
function isEventKeyReturn(evt)
{return(getEventKey(evt)==13);}
if(dayPicElm.parseTimeInputTextTimerID)
clearTimeout(dayPicElm.parseTimeInputTextTimerID);dayPicElm.parseTimeInputTextTimerID=setTimeout(function(){famundoDayPicker.parseTimeInputText(dayPicElm);},500);if(dayPicElm.okHandler&&isEventKeyReturn(e))
setTimeout(function(){famundoDayPicker.onOK(e);},600);},onOK:function(e)
{var dayPicElm=famundoUtils.ascendDOMtoClass(Event.element(e),'day_pick');if(dayPicElm==null)return;if(dayPicElm.okHandler)
dayPicElm.okHandler(dayPicElm,famundoDayPicker.getSelectedDate(dayPicElm));},onCancel:function(e)
{var dayPicElm=famundoUtils.ascendDOMtoClass(Event.element(e),'day_pick');if(dayPicElm==null)return;if(dayPicElm.cancelHandler)
dayPicElm.cancelHandler(dayPicElm);},setCaption:function(dayPicElm)
{dayPicElm.caption.monthElm.innerHTML=famundoDateUtil.getLongMonthName(dayPicElm.month);dayPicElm.caption.yearElm.innerHTML=''+dayPicElm.year;},setWeekDays:function(dayPicElm)
{for(var i=famundoDateUtil.getFirstDayOfWeek();i<famundoDateUtil.getFirstDayOfWeek()+7;i++)
dayPicElm.tHead.rows[0].cells[i-famundoDateUtil.getFirstDayOfWeek()].innerHTML=famundoDateUtil.getLeterOfWeekDay(i%7);},setMonthDays:function(dayPicElm)
{var firstWeekDayOfMonth=famundoDateUtil.getFirstWeekDayOfMonth(dayPicElm.year,dayPicElm.month);var lastDayOfMonth=famundoDateUtil.getLastDayOfMonth(dayPicElm.year,dayPicElm.month);var dayOfMonth=famundoDateUtil.getFirstDayOfWeek()-firstWeekDayOfMonth+1;if(dayOfMonth>1)
dayOfMonth-=7;var today=new Date();var markDays=(dayPicElm.markDaysA&&(dayPicElm.markDaysA.length>0)&&(dayPicElm.markMonth==dayPicElm.month)&&(dayPicElm.markYear=dayPicElm.year));for(var k=0;k<6;k++)
{for(var j=0;j<7;j++)
{var sClass;var sHTML;var day=0;var cell=dayPicElm.tBodies[0].rows[k].cells[j];if((dayOfMonth<1)||(dayOfMonth>lastDayOfMonth))
{sClass='';sHTML='&nbsp;';day=0;}
else
{day=dayOfMonth;sHTML=''+dayOfMonth;sClass='day_pick_valid_day';if(dayPicElm.year==dayPicElm.selectedYear&&dayPicElm.month==dayPicElm.selectedMonth&&dayOfMonth==dayPicElm.selectedDay)
sClass+=' day_pick_selected';if(today.getFullYear()==dayPicElm.year&&today.getMonth()==dayPicElm.month&&today.getDate()==dayOfMonth)
sClass+=' day_pick_today';if(markDays&&dayPicElm.markDaysA.any(function(value,index){return value==dayOfMonth;}))
sClass+=' day_pick_marked_cell';}
cell.innerHTML=sHTML;cell.dayOfMonth=day;cell.className=sClass;dayOfMonth++;}}
if(dayPicElm.hideExtraRow)
{var row=dayPicElm.tBodies[0].rows[5];var cell=row.cells[0];if(Element.hasClassName(cell,'day_pick_valid_day'))
Element.removeClassName(row,'day_pic_hide_row');else
Element.addClassName(row,'day_pic_hide_row');}},createTableElements:function(dayPicElm)
{function appendNavImg(navElm,clsName,title,pname)
{var imgElm=famundoUtils.appendChildElm(navElm,'img','day_pick_'+clsName);imgElm.src=famundoAssetRootURL+'/famundo/utils/images/'+pname+'.gif';imgElm.alt=title;imgElm.title=title;imgElm.actionStr=clsName;return imgElm;}
famundoUtils.removeAllChildren(dayPicElm);dayPicElm.createCaption();dayPicElm.caption.contnavElm=famundoUtils.appendChildElm(dayPicElm.caption,'div','');dayPicElm.caption.navElm=famundoUtils.appendChildElm(dayPicElm.caption.contnavElm,'span','day_pick_nav');if(!dayPicElm.noYearNav)
dayPicElm.caption.goPrevYearElm=appendNavImg(dayPicElm.caption.navElm,'go_prev_year','go prev year','iconPrev');dayPicElm.caption.goPrevMonthElm=appendNavImg(dayPicElm.caption.navElm,'go_prev_month','Previous Month','iconPrev');dayPicElm.caption.goTodayElm=appendNavImg(dayPicElm.caption.navElm,'go_today','Today','iconCurrent');dayPicElm.caption.goNextMonthElm=appendNavImg(dayPicElm.caption.navElm,'go_next_month','Next Month','iconNext');if(!dayPicElm.noYearNav)
dayPicElm.caption.goNextYearElm=appendNavImg(dayPicElm.caption.navElm,'go_next_year','go next year','iconNext');var captionDateElm=famundoUtils.appendChildElm(dayPicElm.caption,'span','date');dayPicElm.caption.monthElm=famundoUtils.appendChildElm(captionDateElm,'span','day_pick_month');if(dayPicElm.drop_instance&&dayPicElm.drop_instance.id)
var uid=dayPicElm.drop_instance.id;else
{var uid=FamundoMainUtils.generateId();dayPicElm.setAttribute('util_id',uid);}
dayPicElm.caption.monthElm.id='month_txt_'+uid;famundoUtils.appendChildTextElm(captionDateElm,' ');dayPicElm.caption.yearElm=famundoUtils.appendChildElm(captionDateElm,'span','day_pick_year');dayPicElm.caption.yearElm.id='year_txt_'+uid;Event.observe(dayPicElm.caption.monthElm,'click',function(e){famundoDayPicker.buildMonthMenu(e,dayPicElm,false);},false);Event.observe(dayPicElm.caption.yearElm,'click',function(e){famundoDayPicker.buildMonthMenu(e,dayPicElm,true);},false);dayPicElm.createTHead();var headTrElm=dayPicElm.tHead.insertRow(-1);for(var i=0;i<7;i++)
famundoUtils.appendChildElm(dayPicElm.tHead.rows[0],'th','');famundoUtils.appendChildElm(dayPicElm,'tbody','');for(var i=0;i<6;i++)
{dayPicElm.tBodies[0].insertRow(-1);for(var j=0;j<7;j++)
dayPicElm.tBodies[0].rows[i].insertCell(-1);}
function add3Event(elm,mousedownProc,mouseoverProc,mouseoutProc)
{Event.observe(elm,'mousedown',mousedownProc,false);Event.observe(elm,'mouseover',mouseoverProc,false);Event.observe(elm,'mouseout',mouseoutProc,false);};for(var k=0;k<6;k++)
{for(var j=0;j<7;j++)
{var cell=dayPicElm.tBodies[0].rows[k].cells[j];Event.observe(cell,'mousedown',famundoDayPicker.onMouseDown,false);Event.observe(cell,'mouseover',famundoDayPicker.onMouseOverCell,false);Event.observe(cell,'mouseout',famundoDayPicker.onMouseOutCell,false);Event.observe(cell,'dblclick',famundoDayPicker.onDblClickCell,false);}}
[dayPicElm.caption.goPrevYearElm,dayPicElm.caption.goPrevMonthElm,dayPicElm.caption.goTodayElm,dayPicElm.caption.goNextMonthElm,dayPicElm.caption.goNextYearElm].each(function(elm)
{if(elm)
{add3Event(elm,famundoDayPicker.onMonthNav,famundoDayPicker.onMouseOverNavElm,famundoDayPicker.onMouseOutNavElm);}});},createTimeElements:function(dayPicElm)
{function appendInput(parentElm,klass,typ,val)
{var elm=famundoUtils.appendChildElm(parentElm,'input',klass,typ);if(elm.value!=val)
{elm.value=val;}
return elm;}
dayPicElm.timeRowElm=dayPicElm.tBodies[0].insertRow(-1);var timeCellElm=dayPicElm.timeRowElm.insertCell(-1);timeCellElm.className='day_pick_time_td_elm';timeCellElm.style.whiteSpace='nowrap';timeCellElm.colSpan=7;dayPicElm.timeTextElm=appendInput(timeCellElm,'form_element day_pick_time_txt','text','');if(dayPicElm.drop_instance&&dayPicElm.drop_instance.id)
dayPicElm.timeTextElm.id="time_text_"+dayPicElm.drop_instance.id;if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
{dayPicElm.dropButton=famundoUtils.appendChildElm(timeCellElm,'button','form_element day_pick_time_drop','button');dayPicElm.dropButton.style.height='9pt';dayPicElm.dropButton.style.width='8pt';dayPicElm.dropButton.style.position='relative';dayPicElm.dropButton.style.top='2px';dayPicElm.timeTextElm.style.padding='1px';}
else
{dayPicElm.dropButton=appendInput(timeCellElm,'form_element day_pick_time_drop','button','');}
dayPicElm.timeRowButElm=dayPicElm.tBodies[0].insertRow(-1);var timeButElm=dayPicElm.timeRowButElm.insertCell(-1);if(dayPicElm.timeWithButtons)
{timeButElm.className='day_pick_time_td_with_buttons';}
timeButElm.colSpan=7;if(dayPicElm.timeWithButtons)
{dayPicElm.timeCancelElm=famundoApplication.famundoButton(famundoGenText.cancel,'',50);dayPicElm.timeOkElm=famundoApplication.famundoButton(famundoGenText.ok,'',50);var tbl=famundoUtils.appendChildElm(timeButElm,'table');tbl.setAttribute('align','center');Element.addClassName(tbl,'form_custom_table');tbl.style.width='140px';var tbr=tbl.insertRow(-1);var tbcok=tbr.insertCell(-1);Element.addClassName(tbcok,'form_nowrap');var tbccancel=tbr.insertCell(-1);tbcok.appendChild(dayPicElm.timeOkElm);tbccancel.appendChild(dayPicElm.timeCancelElm);Element.addClassName(tbccancel,'form_nowrap');}},bindTimeElements:function(dayPicElm)
{if(dayPicElm.timeWithButtons)
{Event.observe(dayPicElm.timeOkElm,'click',famundoDayPicker.onOK,false);Event.observe(dayPicElm.timeCancelElm,'click',famundoDayPicker.onCancel,false);Event.observe(dayPicElm.dropButton,'click',function(e){famundoDayPicker.buildTimeMenu(e,dayPicElm);},false);}
Event.observe(dayPicElm.timeTextElm,'keydown',famundoDayPicker.onTimeTxtKeydown,false);},addTimeDisplay:function(id,hour,minute,withButtons)
{var dayPicElm=$(id);dayPicElm.hour=hour;dayPicElm.minute=minute;dayPicElm.timeWithButtons=withButtons?true:false;if(!dayPicElm.pickTime)
{dayPicElm.pickTime=true;famundoDayPicker.createTimeElements(dayPicElm);famundoDayPicker.displayTime(dayPicElm);famundoDayPicker.bindTimeElements(dayPicElm);}
else
{famundoDayPicker.displayTime(dayPicElm);}},removeTimeDisplay:function(id)
{var dayPicElm=$(id);if(!dayPicElm.pickTime)
return;if(dayPicElm.timeWithButtons)
{Event.stopObserving(dayPicElm.timeOkElm,'click',famundoDayPicker.onOK,false);Event.stopObserving(dayPicElm.timeCancelElm,'click',famundoDayPicker.onCancel,false);}
Event.stopObserving(dayPicElm.timeTextElm,'keydown',famundoDayPicker.onTimeTxtKeydown,false);var rowEl=dayPicElm.timeRowElm;var rowBEl=dayPicElm.timeRowButElm;dayPicElm.pickTime=false;dayPicElm.hour=0;dayPicElm.minute=0;dayPicElm.timeWithButtons=null;dayPicElm.timeRowElm=null;dayPicElm.timeCancelElm=null;dayPicElm.timeOkElm=null;dayPicElm.timeTextElm=null;dayPicElm.dropButton=null;rowEl.parentNode.removeChild(rowEl);rowBEl.parentNode.removeChild(rowBEl);},displayTime:function(dayPicElm)
{if(!dayPicElm.pickTime)
return;dayPicElm.timeTextElm.value=famundoDateUtil.formatTime(dayPicElm.hour,dayPicElm.minute);},initTable:function(day_pic_id_or_element,drop_instance)
{dayPicElm=$(day_pic_id_or_element);dayPicElm.hour=0;dayPicElm.minute=0;dayPicElm.pickTime=false;if(drop_instance)
dayPicElm.drop_instance=$(drop_instance);else
{dayPicElm.drop_instance=null;}
dayPicElm.autoSelect=dayPicElm.getAttribute('auto_select')?true:false;dayPicElm.noYearNav=dayPicElm.getAttribute('no_year_nav')?true:false;dayPicElm.hideExtraRow=dayPicElm.getAttribute('hide_extra_row')?true:false;var selectedDateSplit=dayPicElm.getAttribute('selected_date').split('-');dayPicElm.selectedYear=parseInt(selectedDateSplit[0],10);dayPicElm.selectedMonth=parseInt(selectedDateSplit[1],10)-1;dayPicElm.selectedDay=parseInt(selectedDateSplit[2],10);if(dayPicElm.autoSelect)
{dayPicElm.year=dayPicElm.selectedYear;dayPicElm.month=dayPicElm.selectedMonth;}
else if(dayPicElm.getAttribute('date'))
{var dateSplit=dayPicElm.getAttribute('date').split('-');dayPicElm.year=parseInt(dateSplit[0],10);dayPicElm.month=parseInt(dateSplit[1],10)-1;}
famundoDayPicker.createTableElements(dayPicElm);famundoDayPicker.setCaption(dayPicElm);famundoDayPicker.setWeekDays(dayPicElm);famundoDayPicker.setMonthDays(dayPicElm);var timeStr=dayPicElm.getAttribute('time');if(timeStr)
{var withButtons=dayPicElm.getAttribute('with_buttons')?true:false;var timeSplit=timeStr.split(':');var hour=parseInt(timeSplit[0],10);var minute=parseInt(timeSplit[1],10);famundoDayPicker.addTimeDisplay(dayPicElm,hour,minute,withButtons);}},buildTimeMenu:function(e,obj)
{var id=obj.drop_instance.id;if(!$("div_menu_"+id))
{var j=0;var hrs=new Array();for(var i=0;i<24;i++)
{hrs[j]=famundoDateUtil.formatTime(i,0);j++;hrs[j]=famundoDateUtil.formatTime(i,30);j++;}
var links=new Array();for(var i=0;i<hrs.length;i++)
links[i]={'label':hrs[i],'action':"famundoDayPicker.selectTime(\'"+hrs[i]+"\',\'"+id+"\')",'css':"day_pick_time_drop_cell"};Event.stopObserving(document.getElementsByTagName('body')[0],'mousedown',obj.drop_instance.onBodyMouseDown,false);var scrl=getScrollXY();if(FamundoMainUtils.isIE||famundoUtils.isSafari)
if(famundoUtils.isSafari)
var offs=-8;else
var offs=4;else
var offs=-scrl[1];var scrl=new Array(0,0);if(!FamundoMainUtils.isIE&&!famundoUtils.isSafari)
scrl=getScrollXY();var yPos=Position.cumulativeOffset(obj.timeTextElm)[1]+offs+scrl[1];var xPos=Position.cumulativeOffset(obj.timeTextElm)[0];var pos={'X':xPos,'Y':yPos};FamundoMainUtils.buildTT_menu(e,links,null,'day_pick_time_menu',pos,id);famundoDayPicker.scrollTimeValue(obj,id);famundoDayPicker.hackIE(obj.drop_instance);}
else
{Event.observe(document.getElementsByTagName('body')[0],'mousedown',$(id).onBodyMouseDown,false);}},buildMonthMenu:function(e,obj,isYear)
{if(obj.drop_instance)
{clearmouse=false;var id=obj.drop_instance.id;}
else
{clearmouse=true;var id=obj.getAttribute('util_id');}
if(isYear)
var ext_id='year_'+id;else
var ext_id='month_'+id;if(!$("div_menu_"+ext_id))
{var j=0;if(!isYear)
var mnths=famundoDateUtil.longMonthName;else
{var dt=new Date();var cyear=dt.getFullYear();var mnths=new Array();if(!obj.drop_instance||(!obj.drop_instance.getAttribute('minyear')&&!obj.drop_instance.getAttribute('maxyear')))
{for(var i=0;i<=10;i++)
{mnths[i]=cyear-3+i;}}
else
{var min=obj.drop_instance.getAttribute('minyear')||1900;var max=obj.drop_instance.getAttribute('maxyear')||cyear;min=parseInt(min);max=parseInt(max);for(var i=0;i<=(max-min);i++)
{mnths[i]=min+i;}}}
var links=new Array();for(var i=0;i<mnths.length;i++)
if(!isYear)
links[i]={'label':mnths[i],'action':"famundoDayPicker.selectMonth(\'"+mnths[i]+"\',\'"+id+"\')",'css':"day_pick_month_drop_cell"};else
links[i]={'label':mnths[i],'action':"famundoDayPicker.selectMonth(\'"+mnths[i]+"\',\'"+id+"\',true)",'css':"day_pick_month_drop_cell"};if(obj.drop_instance)
Event.stopObserving(document.getElementsByTagName('body')[0],'mousedown',obj.drop_instance.onBodyMouseDown,false);var offs=0;var hoffs=0;if(famundoUtils.isSafari)
{offs=-6;}
var scrl=getScrollXY();if(!isYear)
{if(clearmouse)
if(!FamundoMainUtils.isIE&&!famundoUtils.isSafari)
{var c=famundoUtils.ascendDOM(obj.caption.monthElm,'caption');}
else
{var c=obj.caption.monthElm;clearmouse=false;if(FamundoMainUtils.isIE)
hoffs=-10;}
else
var c=obj.caption.monthElm;var yPos=Position.cumulativeOffset(c)[1]+offs;var xPos=Position.cumulativeOffset(obj.caption.monthElm)[0]+hoffs;}
else
{if(clearmouse)
if(!FamundoMainUtils.isIE&&!famundoUtils.isSafari)
var c=famundoUtils.ascendDOM(obj.caption.yearElm,'caption');else
{var c=obj.caption.yearElm;clearmouse=false;if(FamundoMainUtils.isIE)
hoffs=-10;}
else
var c=obj.caption.yearElm;var yPos=Position.cumulativeOffset(c)[1]+offs;var xPos=Position.cumulativeOffset(obj.caption.yearElm)[0]+hoffs;}
var pos={'X':xPos,'Y':yPos};FamundoMainUtils.buildTT_menu(e,links,null,'day_pick_month_menu',pos,ext_id,clearmouse);if(FamundoMainUtils.isIE||famundoUtils.isSafari)
{var IEwidth=Element.getDimensions($("table_menu_"+ext_id)).width+18+'px';$("div_menu_"+ext_id).style.width=IEwidth;$(ext_id).style.width=IEwidth;}
if(!isYear)
famundoDayPicker.scrollMonthValue(obj,id);else
famundoDayPicker.scrollMonthValue(obj,id,true);if(obj.drop_instance)
famundoDayPicker.hackIE(obj.drop_instance);}
else if(obj.drop_instance)
{Event.observe(document.getElementsByTagName('body')[0],'mousedown',obj.drop_instance.onBodyMouseDown,false);}},hackIE:function(obj)
{if(FamundoMainUtils.isIE)
{obj.style.border='1px solid red';obj.style.border='0px';}},scrollTimeValue:function(obj,id)
{if(!Element.hasClassName(obj.timeTextElm,'day_pick_time_format_error'))
{var time=famundoDateUtil.parseTime(obj.timeTextElm.value.trim());var tbl=$("table_menu_"+id);var scr=0;for(var i=0;i<tbl.rows.length;i++)
{var row=tbl.rows[i];var cells=row.cells;for(var j=0;j<cells.length;j++)
{var cell=cells[j];var cell_time=famundoDateUtil.parseTime(cell.innerHTML.trim());if(cell_time&&time&&(cell_time[0]==time[0])&&(cell_time[1]==time[1]))
{$("div_menu_"+id).scrollTop=scr;Element.addClassName(cell,'TT_td_menu_hover');setTimeout(function(){abort_flag=false;},100);return true;}}
if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
scr+=Element.getDimensions(cells[0]).height;else
scr+=Element.getDimensions(row).height;}}
return false;},scrollMonthValue:function(obj,id,isYear)
{if(!isYear)
{var month=obj.caption.monthElm.innerHTML;var ext_id='month_'+id;}
else
{var month=obj.caption.yearElm.innerHTML;var ext_id='year_'+id;}
var tbl=$("table_menu_"+ext_id);var scr=0;for(var i=0;i<tbl.rows.length;i++)
{var row=tbl.rows[i];var cells=row.cells;for(var j=0;j<cells.length;j++)
{var cell=cells[j];var cell_month=cell.innerHTML.trim();if(cell_month&&month&&(cell_month==month))
{Element.addClassName(cell,'TT_td_menu_hover');$("div_menu_"+ext_id).scrollTop=scr;setTimeout(function(){abort_flag=false;},100);return true;}}
scr+=Element.getDimensions(row).height;}},selectTime:function(str,id)
{abort_flag=false;$("time_text_"+id).value=str;var dayPickElm=famundoUtils.ascendDOM($("time_text_"+id),'table');if(dayPickElm)
{var str_time=famundoDateUtil.parseTime(str.trim());dayPickElm.hour=str_time[0];dayPickElm.minute=str_time[1];}
Event.observe(document.getElementsByTagName('body')[0],'mousedown',$(id).onBodyMouseDown,false);setTimeout(function(obj){famundoDayPicker.hackIE($(id));},50);},selectMonth:function(str,id,isYear)
{abort_flag=false;if(!isYear)
var ext_id="month_txt_"+id;else
var ext_id="year_txt_"+id;var dayPickElm=famundoUtils.ascendDOM($(ext_id),'table');if(dayPickElm)
{if(!isYear)
var pos=FamundoMainUtils.inArray(famundoDateUtil.longMonthName,str);else
{var pos=str;}
if(!isYear)
{dayPickElm.month=pos;dayPickElm.selectedMonth=pos;}
else
{dayPickElm.year=pos;dayPickElm.selectedYear=pos;}
famundoDayPicker.setCaption(dayPickElm);famundoDayPicker.setMonthDays(dayPickElm);var sd=this.getSelectedDate(dayPickElm)
var current_day=sd.getDate();dayPickElm.selectedDay=current_day;if(dayPickElm.autoSelect&&dayPickElm.selectionHandler)
{dayPickElm.selectionHandler(dayPickElm,famundoDayPicker.getSelectedDate(dayPickElm),false);}}
if(dayPickElm.drop_instance)
{Event.observe(document.getElementsByTagName('body')[0],'mousedown',dayPickElm.drop_instance.onBodyMouseDown,false);setTimeout(function(obj){famundoDayPicker.hackIE($(id));},50);}},initAll:function()
{if(!document.getElementsByTagName||!document.getElementById)
return;var allTables=document.getElementsByTagName('table');for(var i=0;i<allTables.length;i++)
{var tbl=allTables[i];if(Element.hasClassName(tbl,"day_pick"))
{var parent_drop_id=tbl.getAttribute('parent_drop_id');if(!parent_drop_id||!$(parent_drop_id))
{famundoDayPicker.initTable(tbl);}}}}};var famundoDropDates={elements:[],opened:null,add:function(dd_obj)
{if(this.elements.length>0)
for(var i=0;i<this.elements.length;i++)
if(this.elements[i].id==dd_obj.id)
return false;this.elements.push(dd_obj);},find:function(id)
{var drop_date=false;this.elements.each(function(item){if(id==item.id)
drop_date=item;})
return drop_date;},remove:function(id)
{for(var i=0;i<this.elements.length;i++)
{if(!id||this.elements[i].id==id)
{this.removeFromDOM(this.elements[i].id);this.elements.splice(i,1);i=i-1;}}},removeFromDOM:function(id)
{if($(id))
Element.remove($(id));if($(id+'_tblWraper'))
Element.remove($(id+'_tblWraper'));if($(id+'_iframe'))
Element.remove($(id+'_iframe'));},destroyDropDatesOf:function(container)
{var elms=document.getElementsByClassName("date_drop",$(container));for(var i=0;i<elms.length;i++)
this.remove(elms[i].id);},destroyAll:function()
{this.remove();},clear:function()
{this.elements=[];},setOpened:function(dd_obj)
{this.opened=dd_obj;},getOpened:function()
{return this.opened;}}
var famundoDropDate={getCurrentDate:function(id)
{var dropDateElm=$(id);var dt=dropDateElm.dateObj;if(dt==null)
return null;else
return new Date(dt.getFullYear(),dt.getMonth(),dt.getDate(),dt.getHours(),dt.getMinutes(),0);},setCurrentDate:function(id,dt)
{var dropDateElm=$(id);dt=dt||new Date();famundoDropDate.setDate(dropDateElm,dt);},setDateSelectionHandler:function(id,func)
{$(id).selectionHandler=func;},addTimeDisplay:function(id,hour,min,noHandler)
{var dropDateElm=$(id);famundoDayPicker.addTimeDisplay(dropDateElm.dayPickElm,hour,min,true);dropDateElm.pickTime=true;dropDateElm.dateObj.setHours(hour);dropDateElm.dateObj.setMinutes(min);famundoDropDate.displayDate(dropDateElm);famundoDropDate.updateHiddenInput(dropDateElm,noHandler);},removeTimeDisplay:function(id,noHandler)
{var dropDateElm=$(id);famundoDayPicker.removeTimeDisplay(dropDateElm.dayPickElm);dropDateElm.pickTime=false;dropDateElm.dateObj.setHours(0);dropDateElm.dateObj.setMinutes(0);famundoDropDate.displayDate(dropDateElm);famundoDropDate.updateHiddenInput(dropDateElm,noHandler);},markMonthDays:function(id,days2mark)
{var dropDateElm=$(id);famundoDayPicker.setDateAndSelectedDate(dropDateElm.dayPickElm,dropDateElm.dateObj);famundoDayPicker.markMonthDays(dropDateElm.dayPickElm,days2mark);},setStartDropDateElement:function(id,idStartElement)
{var dropDateElm=$(id);if(idStartElement)
{dropDateElm.startDateTimeProc=function(){return famundoDropDate.getCurrentDate(idStartElement);};}
else
{dropDateElm.startDateTimeProc=null;}},showDropDatePicker:function(dropDateElm)
{famundoDropDates.elements.each(function(elem){famundoDropDate.hideDropDatePicker(elem);});this.positionDropDatePicker(dropDateElm);var dt=dropDateElm.dateObj;if(null==dt)
dt=new Date;famundoDayPicker.setDateAndSelectedDate(dropDateElm.dayPickElm,dt);Element.removeClassName(dropDateElm.tblWraperElm,'date_drop_table_wraper_hide');Element.addClassName(dropDateElm.tblWraperElm,'date_drop_table_wraper_show');if(FamundoMainUtils.isIE)
{Position.clone(dropDateElm.tblWraperElm,dropDateElm.iframe);dropDateElm.iframe.style.display='block';}
famundoDropDates.setOpened(dropDateElm);Event.observe(document.getElementsByTagName('body')[0],'mousedown',dropDateElm.onBodyMouseDown,false);},positionDropDatePicker:function(dropDateElm)
{var scrl=getScrollXY();if(famundoUtils.isIE||famundoUtils.isSafari)
{var yPos=Position.cumulativeOffset(dropDateElm)[1]+dropDateElm.offsetHeight+1;}
else
{var yPos=Position.cumulativeOffset(dropDateElm)[1]+dropDateElm.offsetHeight+3;}
var xPos=Position.cumulativeOffset(dropDateElm)[0];dropDateElm.tblWraperElm.style.top=yPos+'px';dropDateElm.tblWraperElm.style.left=xPos+'px';if(FamundoMainUtils.isIE)
{dropDateElm.iframe.style.top=yPos+'px';dropDateElm.iframe.style.left=xPos+'px';}},hideDropDatePicker:function(dropDateElm)
{Event.stopObserving(document.getElementsByTagName('body')[0],'mousedown',dropDateElm.onBodyMouseDown,false);if(FamundoMainUtils.isIE)
{dropDateElm.iframe.style.display='none';}
Element.addClassName(dropDateElm.tblWraperElm,'date_drop_table_wraper_hide');Element.removeClassName(dropDateElm,'date_drop_show');},isClosed:function(dropDateElm)
{return famundoUtils.isOfClass(dropDateElm.tblWraperElm,'date_drop_table_wraper_hide');},clearParseTimer:function(dropDateElm)
{if(dropDateElm.parseTimerID)
{clearTimeout(dropDateElm.parseTimerID);dropDateElm.parseTimerID=null;}},parseInput:function(dropDateElm)
{famundoDropDate.clearParseTimer(dropDateElm);if(dropDateElm.alowNullDate&&(dropDateElm.inputElm.value==null||/^\s*$/.test(dropDateElm.inputElm.value)))
{dropDateElm.dateObj=null;famundoDropDate.updateHiddenInput(dropDateElm);Element.removeClassName(dropDateElm.inputElm,'date_drop_format_error');return true;}
var dt=famundoDateUtil.parseDate(dropDateElm.inputElm.value,dropDateElm.pickTime,dropDateElm.startDateTimeProc);if(dt)
{dropDateElm.dateObj=dt;famundoDropDate.updateHiddenInput(dropDateElm);Element.removeClassName(dropDateElm.inputElm,'date_drop_format_error');return true;}
else
{Element.addClassName(dropDateElm.inputElm,'date_drop_format_error');return false;}},onInputBlur:function(e)
{var el=famundoUtils.getEventElement(e,'input');if(el==null)return;var dropDateElm=famundoUtils.ascendDOMtoClass(el,'date_drop');if(dropDateElm==null)return;famundoDropDate.parseInput(dropDateElm);famundoDropDate.displayDate(dropDateElm);},onInputChange:function(e)
{var el=famundoUtils.getEventElement(e,'input');if(el==null)return;var dropDateElm=famundoUtils.ascendDOMtoClass(el,'date_drop');if(dropDateElm==null)return;famundoDropDate.clearParseTimer(dropDateElm);famundoDropDate.parseInput(dropDateElm);famundoDropDate.displayDate(dropDateElm);},onInputKeydown:function(e)
{var el=famundoUtils.getEventElement(e,'input');if(el==null)return;var dropDateElm=famundoUtils.ascendDOMtoClass(el,'date_drop');if(dropDateElm==null)return;famundoDropDate.clearParseTimer(dropDateElm);famundoDropDate.parseTimerID=setTimeout(function(){famundoDropDate.parseInput(dropDateElm);},500);},onMouseDownDropImg:function(e)
{if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
{var el=famundoUtils.getEventElement(e,'button');}
else
{var el=famundoUtils.getEventElement(e,'input');}
if(el==null)return;if(el==null)return;var dropDateElm=famundoUtils.ascendDOMtoClass(el,'date_drop');if(dropDateElm==null)return;if(famundoUtils.isOfClass(dropDateElm.tblWraperElm,'date_drop_table_wraper_hide'))
famundoDropDate.showDropDatePicker(dropDateElm);else
famundoDropDate.hideDropDatePicker(dropDateElm);Event.stop(e);},onMouseOverDropImg:function(e)
{if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
{var el=famundoUtils.getEventElement(e,'button');}
else
{var el=famundoUtils.getEventElement(e,'input');}
if(el==null)return;Element.addClassName(el,'date_drop_drop_button_hover');},onMouseOutDropImg:function(e)
{if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
{var el=famundoUtils.getEventElement(e,'button');}
else
{var el=famundoUtils.getEventElement(e,'input');}
if(el==null)return;Element.removeClassName(el,'date_drop_drop_button_hover');},onMouseDownAnywere:function(e,dropDateElm)
{var el=famundoUtils.getEventElementAccendText(e);if(el==null)return;if(famundoDropDate.isClosed(dropDateElm))
return;if(dropDateElm.tblWraperElm==famundoUtils.ascendDOMtoClass(el,'date_drop_table_wraper'))
return;if(dropDateElm.dropImgElm==famundoUtils.ascendDOMtoClass(el,'date_drop_img'))
return;famundoDropDate.hideDropDatePicker(dropDateElm);},onDaySelected:function(dayPicElm,selectedDate)
{var dropDateElm=dayPicElm.drop_instance;if(dropDateElm==null)return;if(dropDateElm.pickTime)
{famundoDayPicker.setDateAndSelectedDate(dropDateElm.dayPickElm,selectedDate);}
else
{famundoDropDate.onOK(dayPicElm,selectedDate);}},onOK:function(dayPicElm,selectedDate)
{var dropDateElm=dayPicElm.drop_instance;if(dropDateElm==null)return;famundoDropDate.hideDropDatePicker(dropDateElm);famundoDropDate.setDate(dropDateElm,selectedDate);},updateHiddenInput:function(id,noHandler)
{var dropDateElm=$(id);if(dropDateElm.hiddenInputElm)
{if(dropDateElm.dateObj==null)
dropDateElm.hiddenInputElm.value="";else
dropDateElm.hiddenInputElm.value=famundoDateUtil.formatDate2ISO(dropDateElm.dateObj,dropDateElm.pickTime);}
if(dropDateElm.selectionHandler&&!noHandler)
{dropDateElm.selectionHandler(dropDateElm,famundoDropDate.getCurrentDate(dropDateElm));}},setDate:function(dropDateElm,dt)
{dropDateElm.dateObj=dt;famundoDropDate.updateHiddenInput(dropDateElm);famundoDropDate.displayDate(dropDateElm);},getDate:function(dropDateElm)
{return dropDateElm.dateObj;},formatDate:function(dt,withTime)
{if(dt==null)
return'';return dt.strftime(famundoDateTimeFormats.short_date+(withTime?(' '+famundoDateTimeFormats.time_format):''));},displayDate:function(dropDateElm)
{var new_val=famundoDropDate.formatDate(dropDateElm.dateObj,dropDateElm.pickTime);if(dropDateElm.inputElm.value!=new_val)
{dropDateElm.inputElm.value=new_val;}},createElements:function(dropDateElm)
{var dateElm=famundoUtils.appendChildElm(dropDateElm,'span','date_drop_date');Element.addClassName(dateElm,famundoDropDate.prototype.container_class);dropDateElm.inputElm=famundoUtils.appendChildElm(dateElm,'input',dropDateElm.getAttribute('input_class'),'text');Element.addClassName(dropDateElm.inputElm,famundoDropDate.prototype.input_class);if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
{dropDateElm.dropImgElm=famundoUtils.appendChildElm(dateElm,'button','date_drop_drop_button famundoPopupButton','button');dropDateElm.dropImgElm.style.height='9pt';dropDateElm.dropImgElm.style.width='8pt';dropDateElm.dropImgElm.style.position='relative';dropDateElm.dropImgElm.style.top='3px';}
else
{dropDateElm.dropImgElm=famundoUtils.appendChildElm(dateElm,'input','date_drop_drop_button famundoPopupButton','button');}
var hidden_input_name=dropDateElm.getAttribute('hidden_input_name');if(hidden_input_name)
{dropDateElm.hiddenInputElm=famundoUtils.appendChildElm(dateElm,'input','','hidden');dropDateElm.hiddenInputElm.name=hidden_input_name;dropDateElm.hiddenInputElm.style.display="none";}
var f_create=function(){dropDateElm.tblWraperElm=famundoUtils.appendChildElm(document.getElementsByTagName('body')[0],'span','date_drop_table_wraper date_drop_table_wraper_hide');dropDateElm.tblWraperElm.id=dropDateElm.id+'_tblWraper';if(FamundoMainUtils.isIE)
{dropDateElm.iframe=document.createElement('iframe');dropDateElm.iframe.id=dropDateElm.id+'_iframe';dropDateElm.iframe.src="javascript:false;";document.getElementsByTagName('body')[0].appendChild(dropDateElm.iframe);dropDateElm.iframe.className='calendar_iframe';}
dropDateElm.container=famundoUtils.appendChildElm(dropDateElm.tblWraperElm,'div','day_pick_container');dropDateElm.dayPickElm=famundoUtils.appendChildElm(dropDateElm.container,'table','day_pick');var dateAttrib=dropDateElm.getAttribute('selected_date');dropDateElm.dayPickElm.setAttribute('date',dateAttrib);dropDateElm.dayPickElm.setAttribute('parent_drop_id',dropDateElm.id);dropDateElm.dayPickElm.setAttribute('selected_date',dateAttrib);dropDateElm.dayPickElm.setAttribute('hide_extra_row',"1");['selected_date','time','no_year_nav'].each(function(attrName)
{var val=dropDateElm.getAttribute(attrName);if(val)
dropDateElm.dayPickElm.setAttribute(attrName,val);});dropDateElm.dayPickElm.setAttribute("with_buttons","1");var selDateAttrib=dropDateElm.getAttribute('selected_date');if((selDateAttrib==null)||selDateAttrib.match(/^\s*$/))
{var dateStr=famundoDateUtil.formatDate2ISO(new Date,false);dropDateElm.dayPickElm.setAttribute('selected_date',dateStr);}
var selTimeAttrib=dropDateElm.getAttribute('time');if((selTimeAttrib!=null)&&selTimeAttrib.match(/^\s*$/))
{var timeStr=(new Date).strftime("%H:%M");dropDateElm.dayPickElm.setAttribute('time',timeStr);}
var tabIndex=dropDateElm.getAttribute('tabindex');if(tabIndex!=null)
{dropDateElm.inputElm.tabIndex=tabIndex;dropDateElm.dropImgElm.tabIndex=tabIndex;dropDateElm.removeAttribute('tabindex',false);}};f_create();},initDateDropElemant:function(id_or_element)
{var dropDateElm=$(id_or_element);dropDateElm.startDateTimeProc=null;if(!dropDateElm)
{return false;}
if(!dropDateElm.id)
dropDateElm.id=FamundoMainUtils.generateId();else
{dropDateElm.id=dropDateElm.id+'_'+FamundoMainUtils.generateId();}
var timeStr=dropDateElm.getAttribute('time');if(timeStr!=null)
{dropDateElm.pickTime=true;}
dropDateElm.alowNullDate=false;var alowNullDate=dropDateElm.getAttribute('alow_null_date');if(alowNullDate&&(parseInt(alowNullDate,10)!=0))
{dropDateElm.alowNullDate=true;}
famundoDropDate.createElements(dropDateElm);famundoDayPicker.initTable(dropDateElm.dayPickElm,dropDateElm);dropDateElm.onBodyMouseDown=function(e){famundoDropDate.onMouseDownAnywere(e,dropDateElm);};var selDateAttrib=dropDateElm.getAttribute('selected_date');if((selDateAttrib==null)||selDateAttrib.match(/^\s*$/))
famundoDropDate.setDate(dropDateElm,null);else
famundoDropDate.setDate(dropDateElm,famundoDayPicker.getSelectedDate(dropDateElm.dayPickElm));famundoDropDate.updateHiddenInput(dropDateElm);Event.observe(dropDateElm.dropImgElm,'mousedown',famundoDropDate.onMouseDownDropImg,false);Event.observe(dropDateElm.dropImgElm,'mouseover',famundoDropDate.onMouseOverDropImg,false);Event.observe(dropDateElm.dropImgElm,'mouseout',famundoDropDate.onMouseOutDropImg,false);Event.observe(dropDateElm.inputElm,'change',famundoDropDate.onInputChange,false);Event.observe(dropDateElm.inputElm,'keydown',famundoDropDate.onInputKeydown,false);famundoDayPicker.setDateSelectionHandler(dropDateElm.dayPickElm,famundoDropDate.onDaySelected);famundoDayPicker.setOkHandler(dropDateElm.dayPickElm,famundoDropDate.onOK);famundoDayPicker.setCancelHandler(dropDateElm.dayPickElm,function(dayPickElm){famundoDropDate.hideDropDatePicker(dropDateElm);});famundoDropDates.add(dropDateElm);return dropDateElm;},initAll:function()
{if(!document.getElementsByTagName||!document.getElementById)
return;var elements=document.getElementsByTagName('span');for(var i=0;i<elements.length;i++)
{var el=elements[i];if(famundoUtils.isOfClass(el,"date_drop"))
{famundoDropDate.initDateDropElemant(el);}}}};famundoDropDate.prototype={container_class:'famundoDropDate',input_class:'famundoDropDateInput',isFamundoDropDate:function(elem)
{return Element.hasClassName(elem,famundoDropDate.prototype.container_class);},isFamundoDropDateInput:function(elem)
{return Element.hasClassName(elem,famundoDropDate.prototype.input_class);},getFamundoDropDate:function(elem)
{return famundoUtils.ascendDOMtoClass(elem,famundoDropDate.prototype.container_class);}};var famundoTree=Class.create();famundoTree.prototype={tree_class:'famundoTree',item_class:'famundoTreeItem',item_icon_class:'famundoTreeItemIcon',item_text_class:'famundoTreeItemText',item_checkbox_class:'famundoTreeItemCheckbox',item_indent:20,DnD_enabled:false,onDnDDropItem:Prototype.emptyFunction,onDnDHoverItem:Prototype.emptyFunction,hoverDnDClass:'',initialize:function(treeContainer,treeDef)
{this.root=this.addItem(treeContainer,treeDef);Element.addClassName(this.root,famundoTree.prototype.tree_class);Element.addClassName(famundoTree.prototype.getItemText(this.root),'famundoTreeRootText');Element.addClassName(famundoTree.prototype.getItemIcon(this.root),'famundoTreeRootIcon');},addItem:function(parentNode,item_def)
{var item_obj=new famundoTreeItem(item_def);var item=item_obj.getItem();item_obj.setParentNode(parentNode);var children_def=item_obj.getItemsDef();if(children_def)
{for(var i=0;i<children_def.length;i++)
{this.addItem(item,children_def[i]);}}
return item;},moveItem:function(item,parent)
{var info={};info[item.id]=famundoTree.prototype.isExpandedItem(item);famundoTree.prototype._removeItemIcon(item);famundoTree.prototype.getItems(item).each(function(child)
{info[child.id]=famundoTree.prototype.isExpandedItem(child)?true:false;famundoTree.prototype._removeItemIcon(child);});if(!famundoTree.prototype.isExpandedItem(parent))
{Element.hide(item);}
$(parent).appendChild(item);(info[item.id])?famundoTree.prototype._setItemOpenIcon(item):famundoTree.prototype._setItemCloseIcon(item);famundoTree.prototype.getItems(item).each(function(child)
{(info[child.id])?famundoTree.prototype._setItemOpenIcon(child):famundoTree.prototype._setItemCloseIcon(child);});this._setItemLevel(item);},deleteItem:function(elem)
{var item=famundoTree.prototype.getItem(elem);var root=famundoTree.prototype.getRootItem2(elem);if(item&&root&&(item!=root))
{famundoTree.prototype.getItemParent(item).removeChild(item);return true;}
return false;},getRootItem:function()
{return this.root;},getRootItem2:function(elem)
{while(famundoTree.prototype.isFamundoTreeItem(elem)||famundoTree.prototype.getItemParent(elem))
{if(!famundoTree.prototype.getItemParent(elem))
{return elem;}
else
{elem=famundoTree.prototype.getItemParent(elem);}}
return elem;},deleteAllItems:function(elem)
{var items=famundoTree.prototype.getItems(elem);for(var i=0;i<items.length;i++)
{if($(items[i]))
Element.remove(items[i]);}},getItems:function(item,level)
{var items=new Array();if(!item)
{elem=this.getRootItem();items.push(elem);}
else
{elem=$(item);}
document.getElementsByClassName(this.item_class,elem).each(function(child)
{if(level)
{if((famundoTree.prototype.getItemLevel(elem)+level)>=famundoTree.prototype.getItemLevel(child))
{items.push(child);}}
else
{items.push(child);}});return items;},getItem:function(elem)
{return famundoUtils.ascendDOMtoClass($(elem),famundoTree.prototype.item_class);},getItemParent:function(item)
{return famundoUtils.ascendDOMtoClass($(item).parentNode,famundoTree.prototype.item_class);},getItemLevel:function(item)
{return parseInt($(item).getAttribute('item_level'));},getItemCheckbox:function(item)
{return $($(item).getAttribute('id')+'_'+famundoTree.prototype.item_checkbox_class);},getItemText:function(item)
{return $($(item).getAttribute('id')+'_'+famundoTree.prototype.item_text_class);},updateItemText:function(item,text)
{var item_text=famundoTree.prototype.getItemText(item);var cn=item_text.childNodes;for(var i=0;i<cn.length;i++)
{item_text.removeChild(cn[i]);}
return item_text.appendChild(document.createTextNode(text));},getItemIcon:function(item)
{return $($(item).getAttribute('id')+'_'+famundoTree.prototype.item_icon_class);},getItemIconClass:function(item,type)
{var attr=(type=='open')?'famundoTree_open_icon_class':'famundoTree_close_icon_class';while(famundoTree.prototype.isFamundoTreeItem(item))
{if($(item).getAttribute(attr))
{return $(item).getAttribute(attr);}
item=famundoTree.prototype.getItemParent(item);}
return false;},getItemOpenIconClass:function(item)
{return famundoTree.prototype.getItemIconClass(item,'open');},getItemCloseIconClass:function(item)
{return famundoTree.prototype.getItemIconClass(item,'close');},_setItemLevel:function(item)
{if(!this.getItemLevel(item))
{var item_level=(this.getItemLevel(this.getItemParent(item)||item)+1)||'0';$(item).setAttribute('item_level',item_level);famundoTree.prototype.setItemIndent(item);}
else
{var offset=this.getItemLevel(this.getItemParent(item))-this.getItemLevel(item)+1;$(item).setAttribute('item_level',parseInt(this.getItemLevel(item)+offset));this.getItems(item).each(function(child)
{$(child).setAttribute('item_level',parseInt(famundoTree.prototype.getItemLevel(child)+offset));famundoTree.prototype.setItemIndent(child);});}},setItemIndent:function(item,indent)
{if($(item).getAttribute('item_level')&&famundoTree.prototype.getItemLevel(item)>1)
{$(item).style.marginLeft=(indent||this.item_indent)+'px';}},isFamundoTreeRoot:function(elem)
{return Element.hasClassName(famundoTree.prototype.getItem(elem),famundoTree.prototype.tree_class);},isFamundoTreeItem:function(elem)
{return Element.hasClassName(elem,famundoTree.prototype.item_class);},isFamundoTreeItemIcon:function(elem)
{return Element.hasClassName(elem,famundoTree.prototype.item_icon_class);},isExpandedItem:function(item)
{var icon=famundoTree.prototype.getItemIcon(item);vb=true;famundoTree.prototype.getItemOpenIconClass(item).split(' ').each(function(cls)
{if(!Element.hasClassName(icon,cls))
{vb=false;}});return vb;},collapseAll:function()
{this._setDisplay(this.getRootItem(),'none');},expandAll:function(item)
{this._setDisplay(item||this.getRootItem(),'block');},expandToLevel:function(level)
{this.getItems().each(function(item)
{(famundoTree.prototype.getItemLevel(item)<level)?famundoTree.prototype.openItem(item):famundoTree.prototype.closeItem(item);});},toggleItem:function(e)
{famundoTree.prototype._setDisplay(famundoTree.prototype.getItemParent(Event.element(e)),'toggle');famundoTree.prototype.setSelectedItem(Event.element(e),'toggle');},openItem:function(item,level)
{this._setDisplay(item,'block',level||1);},closeItem:function(item)
{this._setDisplay(item,'none',1);},clickItemText:function(e)
{famundoTree.prototype.setSelectedItem(Event.element(e),'toggle');},_setDisplay:function(item,display,level)
{switch(display)
{case"block":famundoTree.prototype._setItemOpenIcon(item);document.getElementsByClassName(famundoTree.prototype.item_class,$(item)).each(function(child)
{var max_level=famundoTree.prototype.getItemLevel(item)+(level||famundoTree.prototype.getItemLevel(child))+1;if(max_level>=famundoTree.prototype.getItemLevel(child))
{Element.show(child);if(famundoTree.prototype.getItemLevel(child)<max_level)
{famundoTree.prototype._setItemOpenIcon(child);}}});break;case"none":famundoTree.prototype._setItemCloseIcon(item);famundoTree.prototype.getItems(item).each(function(child)
{Element.hide(child);famundoTree.prototype._setItemCloseIcon(child);});break;case"toggle":var children=famundoTree.prototype.getItems(item,1);children.each(function(child)
{Element.toggle(child);});(famundoTree.prototype.isExpandedItem(item))?famundoTree.prototype._setItemCloseIcon(item):famundoTree.prototype._setItemOpenIcon(item);}},_setItemOpenIcon:function(item)
{famundoTree.prototype._removeItemIcon(item);famundoTree.prototype._addItemIcon(item,'open');},_setItemCloseIcon:function(item)
{famundoTree.prototype._removeItemIcon(item);famundoTree.prototype._addItemIcon(item,'close');},_removeItemIcon:function(item)
{if(famundoTree.prototype.isExpandedItem(item))
{var cls=famundoTree.prototype.getItemOpenIconClass(item).split(' ');}
else
{var cls=famundoTree.prototype.getItemCloseIconClass(item).split(' ');}
cls.each(function(c)
{Element.removeClassName(famundoTree.prototype.getItemIcon(item),c);});},_addItemIcon:function(item,icon_type)
{if(icon_type=='open')
{var cls=famundoTree.prototype.getItemOpenIconClass(item).split(' ');}
else
{var cls=famundoTree.prototype.getItemCloseIconClass(item).split(' ');}
cls.each(function(c)
{Element.addClassName(famundoTree.prototype.getItemIcon(item),c);});},setSelectedItem:function(item,scroll)
{var root=famundoTree.prototype.getRootItem2(item);famundoTree.prototype.getItems(root).each(function(child)
{Element.removeClassName(child,'famundoTreeSelectedItem');});if(!famundoTree.prototype.isFamundoTreeItem(item))
{item=famundoTree.prototype.getItemParent(item);}
Element.addClassName(item,'famundoTreeSelectedItem');if(scroll)
{famundoApplication.scrollToElement($(root),$(item));}},getSelectedItem:function(root)
{return document.getElementsByClassName('famundoTreeSelectedItem',root)[0]||false;},enableDragAndDrop:function(options)
{this.scroll=new famundoScroll(this.root.id);this.DnD_enabled=true;Position.includeScrollOffsets=true;this.onDnDDropItem=(options&&options['onDrop'])||Prototype.emptyFunction;this.onDnDHoverItem=(options&&options['onHover'])||Prototype.emptyFunction;this.hoverDnDClass=(options&&options['hoverClass'])||'';this._setDnDItems(this.getItems());Event.observe(document,'mouseup',famundoScroll.prototype._stopScrolling);},disableDragAndDrop:function()
{},isDragAndDropEnabled:function()
{return this.DnD_enabled;},isDraggableItem:function(item)
{var vb=false;Draggables.drags.each(function(drag)
{if(drag.element==$(item))
{vb=true;}});return vb;},isDroppableItem:function(item)
{var vb=false;Droppables.drops.each(function(drop)
{if(drop.element==$(item))
{vb=true;}});return vb;},setItemAsDraggable:function(item)
{if(!famundoTree.prototype.isDraggableItem(item))
{new famundoTreeDraggable($(item).id,{revert:true,handle:famundoTree.prototype.item_icon_class+" "+famundoTree.prototype.item_text_class,ghosting:true,reverteffect:function(element,top_offset,left_offset){var dur=0;element._revert=new Effect.Move(element,{x:-left_offset,y:-top_offset,duration:dur});}});this._setDnDCursorStyle(this.getItemText(item));this._setDnDCursorStyle(this.getItemIcon(item));}},setItemAsDroppable:function(item)
{Droppables.add($(item).id,{accept:famundoTree.prototype._getItemDropAccept(item).replace(' ','').split(',')||'',hoverclass:this.hoverDnDClass,onDrop:function(draggable,droppable,event)
{draggable.style.top='0px';draggable.style.left='0px';draggable.style.position='static';famundoTree.prototype.moveItem(draggable,droppable);famundoTree.prototype._sortDroppables();famundoTree.prototype.onDnDDropItem(draggable,droppable,event);},onHover:function(draggable,droppable)
{famundoTree.prototype.onDnDHoverItem(draggable,droppable);}});},_getItemDropAccept:function(item)
{return $(item).getAttribute('famundoTree_drop_accept_class');},_setDnDItems:function(items)
{for(var i=items.length-1;i>=0;i--)
{if(items[i].getAttribute('famundoTree_draggable')!=='false')
{this.setItemAsDraggable(items[i]);}
if(items[i].getAttribute('famundoTree_droppable')!=='false')
{this.setItemAsDroppable(items[i],this.hoverDnDClass);}}},_sortDroppables:function()
{var trees=document.getElementsByClassName(famundoTree.prototype.tree_class);trees.reverse();trees.each(function(tree)
{var tmp=new Array();var max=0;var items=document.getElementsByClassName(famundoTree.prototype.item_class,tree);items.unshift(tree);items.each(function(item)
{var item_level=famundoTree.prototype.getItemLevel(item);max=Math.max(max,item_level);if(!tmp[item_level])
{tmp[item_level]=new Array();}
if(Droppables.getDroppableFamundo(item))
{tmp[item_level].push(Droppables.getDroppableFamundo(item));}
Droppables.remove(item);});for(var i=max;i>=0;i--)
{for(var j=0;tmp[i]&&tmp[i].length&&j<tmp[i].length;j++)
{Droppables.add(tmp[i][j].element.id,tmp[i][j]);}}});},_setDnDCursorStyle:function(elem)
{$(elem).style.cursor="move";},setItemAsChecked:function(item)
{var checkbox=famundoTree.prototype.getItemCheckbox(item);Element.removeClassName(checkbox,'famundoTreeUncheckedItem');Element.removeClassName(checkbox,'famundoTreePCheckedItem');Element.addClassName(checkbox,'famundoTreeCheckedItem');},setItemAsUnchecked:function(item)
{var checkbox=famundoTree.prototype.getItemCheckbox(item);Element.removeClassName(checkbox,'famundoTreeCheckedItem');Element.removeClassName(checkbox,'famundoTreePCheckedItem');Element.addClassName(checkbox,'famundoTreeUncheckedItem');},setItemAsPartialChecked:function(item)
{var checkbox=famundoTree.prototype.getItemCheckbox(item);Element.removeClassName(checkbox,'famundoTreeCheckedItem');Element.removeClassName(checkbox,'famundoTreeUncheckedItem');Element.addClassName(checkbox,'famundoTreePCheckedItem');},isCheckedItem:function(item)
{return Element.hasClassName(famundoTree.prototype.getItemCheckbox(item),'famundoTreeCheckedItem');},isUncheckedItem:function(item)
{return Element.hasClassName(famundoTree.prototype.getItemCheckbox(item),'famundoTreeUncheckedItem');},isPartialCheckedItem:function(item)
{return Element.hasClassName(famundoTree.prototype.getItemCheckbox(item),'famundoTreePCheckedItem');},checkItem:function(item)
{famundoTree.prototype.setItemAsChecked(item);var children=famundoTree.prototype.getItems(item);for(var i=0;i<children.length;i++)
{famundoTree.prototype.setItemAsChecked(children[i]);}
item=famundoTree.prototype.getItemParent(item);while(item)
{var all_checked=true;var c=famundoTree.prototype.getItems(item,1);for(var i=0;i<c.length;i++)
{if(famundoTree.prototype.isUncheckedItem(c[i])||famundoTree.prototype.isPartialCheckedItem(c[i]))
{all_checked=false;break;}}
if(all_checked)
{famundoTree.prototype.setItemAsChecked(item);item=famundoTree.prototype.getItemParent(item);}
else
{famundoTree.prototype._setPartialCheckedItems(item);break;}}},uncheckItem:function(item)
{famundoTree.prototype.setItemAsUnchecked(item);var children=famundoTree.prototype.getItems(item);for(var i=0;i<children.length;i++)
{famundoTree.prototype.setItemAsUnchecked(children[i]);}
item=famundoTree.prototype.getItemParent(item);while(item)
{var all_unchecked=true;var c=famundoTree.prototype.getItems(item,1);for(var i=0;i<c.length;i++)
{if(famundoTree.prototype.isCheckedItem(c[i])||famundoTree.prototype.isPartialCheckedItem(c[i]))
{all_unchecked=false;break;}}
if(all_unchecked)
{famundoTree.prototype.setItemAsUnchecked(item);item=famundoTree.prototype.getItemParent(item);}
else
{famundoTree.prototype._setPartialCheckedItems(item);break;}}},onClickCheckbox:function(e)
{var item=famundoTree.prototype.getItem(Event.element(e));(famundoTree.prototype.isUncheckedItem(item))?famundoTree.prototype.checkItem(item):famundoTree.prototype.uncheckItem(item);},_setPartialCheckedItems:function(item)
{while(item)
{famundoTree.prototype.setItemAsPartialChecked(item);item=famundoTree.prototype.getItemParent(item);}},getCheckedItems:function(tree)
{var items=famundoTree.prototype.getItems($(tree));var checked_items=new Array();for(var i=0;i<items.length;i++)
{if(famundoTree.prototype.isCheckedItem(items[i]))
{checked_items.push(items[i]);}}
return checked_items;}}
var famundoTreeItem=Class.create();famundoTreeItem.prototype={initialize:function(item_def)
{item_def['text']=Object.extend({'value':''},item_def['text']);item_def['attributes']=Object.extend({'id':famundoUtils.generateId()},item_def['attributes']);this.item_def=item_def;this.eventClickIcon=famundoTree.prototype.toggleItem;this.eventClickText=famundoTree.prototype.clickItemText;this._createMainDiv(item_def['attributes']);this._createIcon();if(item_def['settings']&&item_def['settings']['checkbox'])
this._createCheckbox();this._createText(item_def['text']);if(item_def['extra_elements'])
this.createExtraElements(item_def['extra_elements']);this._makeSettings(item_def['settings']);},getItem:function()
{return this.item_element;},getItemText:function()
{return this.item_text;},getItemIcon:function()
{return this.item_icon;},getItemsDef:function()
{return(this.item_def['items']&&this.item_def['items'].length>0)?this.item_def['items']:false;},_createMainDiv:function(attr)
{this.item_element=document.createElement('div');Element.addClassName(this.item_element,famundoTree.prototype.item_class);for(var prop in attr)
{if(prop=='class')
{Element.addClassName(this.item_element,attr[prop]);}
else
{this.item_element.setAttribute(prop,attr[prop]);}}},_createText:function(text_def)
{this.item_text=document.createElement('span');this.item_text.setAttribute('id',this.item_element.getAttribute('id')+'_'+famundoTree.prototype.item_text_class);var text=document.createTextNode(text_def['value']);Element.addClassName(this.item_text,famundoTree.prototype.item_text_class);Element.addClassName(this.item_text,'cursor_hand');Event.observe(this.item_text,'mousedown',this.eventClickText);if(text_def['url'])
{var a=document.createElement('a');(text_def['url'])?a.setAttribute('href',text_def['url']):'';(text_def['target'])?a.setAttribute('target',text_def['target']):'';a.appendChild(text);this.item_text.appendChild(a);}
else
{this.item_text.appendChild(text);}
if(text_def['js'])
{(a)?eval("famundoUtils.addEvent(a,'click',"+text_def['js']+",false)"):eval("famundoUtils.addEvent(this.item_text,'click',"+text_def['js']+",false)");}
this.item_element.appendChild(this.item_text);},_createIcon:function()
{this.item_icon=document.createElement('div');this.item_icon.setAttribute('id',this.item_element.getAttribute('id')+'_'+famundoTree.prototype.item_icon_class);Element.addClassName(this.item_icon,famundoTree.prototype.item_icon_class);Event.observe(this.item_icon,'click',this.eventClickIcon);this.item_element.appendChild(this.item_icon);if(this.item_def['attributes']['icon_class'])
Element.addClassName(this.item_icon,this.item_def['attributes']['icon_class']);},_createCheckbox:function()
{this.checkbox=document.createElement('div');this.item_element.appendChild(this.checkbox);Element.addClassName(this.checkbox,famundoTree.prototype.item_checkbox_class);Element.addClassName(this.checkbox,'float_left');Element.addClassName(this.checkbox,'famundoTreeUncheckedItem');this.checkbox.id=this.item_element.id+'_'+famundoTree.prototype.item_checkbox_class;var me=this;Event.observe(this.checkbox,'click',function(event){if(me.item_def['settings']&&me.item_def['settings']['onCheckboxClick'])
{me.item_def['settings']['onCheckboxClick'](me.item_element);}
famundoTree.prototype.onClickCheckbox(event);});},_makeSettings:function(settings_def)
{for(var prop in settings_def)
{this.item_element.setAttribute('famundoTree_'+prop,settings_def[prop]);}},setParentNode:function(parentNode)
{$(parentNode).appendChild(this.item_element);famundoTree.prototype._setItemLevel(this.item_element);Element.addClassName(this.item_icon,famundoTree.prototype.getItemOpenIconClass(this.item_element));},createExtraElements:function(elems)
{for(var i=0;i<elems.length;i++)
{this.addExtraElement(elems[i]);}},addExtraElement:function(options)
{if(options['src'])
{var elem=new Image();elem.src=options['src'];}
else
var elem=document.createElement('div');if(options['id'])
elem.id=options['id'];if(options['class'])
Element.addClassName(elem,options['class']);var position=options['position']||'after_text';if(options['tooltip_text'])
elem.title=options['tooltip_text'];switch(position)
{case'after_text':this.item_element.appendChild(elem);break;case'before_text':this.item_element.insertBefore(elem,this.item_text);break;}}}
Object.extend(Droppables,{getDroppableFamundo:function(elem)
{var drop=false;this.drops.each(function(d)
{if(d.element==elem)
{drop=d;}});return drop;}});var famundoTreeDraggable=Class.create();Object.extend(famundoTreeDraggable.prototype,Draggable.prototype);Object.extend(famundoTreeDraggable.prototype,{initDrag:function(event){if(Event.isLeftClick(event)){var src=Event.element(event);if(src.tagName&&(src.tagName=='INPUT'||src.tagName=='SELECT'||src.tagName=='BUTTON'||src.tagName=='TEXTAREA'))return;if(this.element._revert){this.element._revert.cancel();this.element._revert=null;}
var pointer=[Event.pointerX(event),Event.pointerY(event)];var pos=Position.page(this.element);var page_scroll=[document.documentElement.scrollLeft,document.documentElement.scrollTop];this.offset=[0,1].map(function(i){return(pointer[i]-pos[i]-page_scroll[i])});Draggables.activate(this);Event.stop(event);}},startDrag:function(event){this.dragging=true;if(this.options.zindex){this.originalZ=parseInt(Element.getStyle(this.element,'z-index')||0);this.element.style.zIndex=this.options.zindex;}
if(this.options.ghosting){this._clone=this.element.cloneNode(true);var clone_id=famundoUtils.generateId();this._clone.setAttribute('id',clone_id);Position.absolutize(this.element);this.element.parentNode.insertBefore(this._clone,this.element);this.element.setAttribute('clone_id',clone_id);if(!this.element.parentNode.id)
this.element.parentNode.id=famundoUtils.generateId();this.element.setAttribute('parent_id',this.element.parentNode.id);document.body.appendChild(this.element);}
Draggables.notify('onStart',this,event);if(this.options.starteffect)this.options.starteffect(this.element);},updateDrag:function(event,pointer){if(!this.dragging)this.startDrag(event);Position.prepare();Droppables.show(pointer,this.element,event);Draggables.notify('onDrag',this,event);this.draw(pointer);if(this.options.change)this.options.change(this);if(navigator.appVersion.indexOf('AppleWebKit')>0)window.scrollBy(0,0);Event.stop(event);},finishDrag:function(event,success){this.dragging=false;if(this.options.ghosting){Position.relativize(this.element);$(this.element.getAttribute('parent_id')).insertBefore(this.element,this._clone);Element.remove(this._clone);this._clone=null;}
if(success)Droppables.fire(event,this.element);Draggables.notify('onEnd',this,event);var revert=this.options.revert;if(revert&&typeof revert=='function')revert=revert(this.element);var d=this.currentDelta();if(revert&&this.options.reverteffect){this.options.reverteffect(this.element,d[1]-this.delta[1],d[0]-this.delta[0]);}else{this.delta=d;}
if(this.options.zindex)
this.element.style.zIndex=this.originalZ;if(this.options.endeffect)
this.options.endeffect(this.element);Draggables.deactivate(this);Droppables.reset();},show:function(point,element)
{if(!this.drops.length)
{return;}
if(this.last_active)
{this.deactivate(this.last_active);}
this.drops.each(function(drop)
{if(Droppables.isAffected(point,element,drop))
{if(drop.onHover)
{drop.onHover(element,drop.element,Position.overlap(drop.overlap,drop.element));}
if(drop.greedy)
{Droppables.activate(drop);}
throw $break;}});}});var doing_attach_docs=false;function onClickAttachDocument(item)
{id=item.getAttribute('id').substr(17);value=famundoTree.prototype.getItemText(item).innerHTML;check=famundoTree.prototype.isUncheckedItem(item)
uncheck=famundoTree.prototype.isCheckedItem(item)
updateAttachedDocs(check,id,value);}
function createAttachTree(id)
{var container_id=id;var root={'text':{'value':'root'},'attributes':{'id':container_id+'_root','class':'attach_file_tree_root'},'settings':{'open_icon_class':'arrow_down','close_icon_class':'arrow_right','draggable':'false','drop_accept_class':"file_item, photo_item"}}
doing_attach_docs=true;tree=new famundoTree($(container_id),root);}
function loadAttachFileTree(e,tree_prefix)
{var elem=(e?Event.element(e):$('document_user_id'));var user=elem.value;root_item=tree_prefix+'_root';famundoTree.prototype.deleteAllItems($(root_item));var params=user+'?tree_prefix='+tree_prefix
new Ajax.Request('/library/files/load_user_files/'+params,{method:'get',asynchronous:true,evalScripts:true});}
function loadAttachedDocs(names_id,docs_id)
{var doc_names=$(names_id).value;var doc_ids=$(docs_id).value;doc_names=doc_names.match(/.+/g);doc_ids=doc_ids.match(/\d+/g);if(doc_ids&&doc_ids.length>0)
{for(var i=0;i<doc_ids.length;i++)
updateAttachedDocs(true,doc_ids[i],doc_names[i]);setSelectionFromAttachedDocs('attach_file_tree_root');}}
function updateAttachedDocs(check,id,value)
{var ulElem=$('attached_docs');var found=false;var nodeFound=null;for(var i=0;i<ulElem.childNodes.length;i++)
{found=(ulElem.childNodes[i].childNodes[0].id.substr(13)==id);if(found)
{nodeFound=ulElem.childNodes[i];break;}}
if((check&&found)||(!check&&!found))
{return false;}
if(check)
{var li=document.createElement('li');Element.addClassName(li,'li_attached_doc');Element.addClassName(li,'clear_both');var li_id='attached_doc_'+id;li.innerHTML="<div id='"+li_id+"' class='visibility_hidden attached_doc_delete_icon cursor_hand trashcan'></div>"+value;ulElem.appendChild(li);Event.observe($(li_id),'click',function(){Element.remove(li);if($('attach_file_tree_'+id))
famundoTree.prototype.uncheckItem('attach_file_tree_'+id);});Event.observe(li,'mouseover',function(){Element.removeClassName($(li_id),'visibility_hidden');});Event.observe(li,'mouseout',function(){Element.addClassName($(li_id),'visibility_hidden');});}
else if(nodeFound)
{ulElem.removeChild(ulElem.childNodes[i]);}
return true;}
function setSelectionFromAttachedDocs(tree_root)
{var ulElem=$('attached_docs');for(var i=0;i<ulElem.childNodes.length;i++)
{var id=ulElem.childNodes[i].childNodes[0].id.substr(13);var elem=$('attach_file_tree_'+id);if(elem)
{var item=famundoTree.prototype.getItem(elem);famundoTree.prototype.checkItem(item);}}
return true;}
function saveAttachedDocs(update_link_id,f)
{var ids_a=[];var names='';var ulElem=$('attached_docs');for(var i=0;i<ulElem.childNodes.length;i++)
{ids_a.push(ulElem.childNodes[i].childNodes[0].id.substr(13));names+=ulElem.childNodes[i].childNodes[1].data+"\n";}
ids=ids_a.join("\n");var hidden_names=$('hidden_attached_doc_names_'+update_link_id);var hidden_ids=$('hidden_attached_doc_ids_'+update_link_id);hidden_names.value=names;hidden_ids.value=ids;var updateElem=$(update_link_id);var value=(ulElem.childNodes.length>0?ulElem.childNodes.length+' documents attached':'Attach documents');updateElem.innerHTML=value;if(f)
f(ids_a.join(","));}
function reset_attach_docs_flag()
{doing_attach_docs=false;}