CRLF="\r\n";SPACE="&nbsp;";BR="<br>";UL="<ul>";_UL="</ul>";LI="<li>";_LI="</li>";SERVER_ERROR="ec_";SERVER_ERROR_USER_NOT_LOGGED="ec_usernotlogged";SERVER_ERROR_CAPTCHA="ec_securitycode";SERVER_ERROR_ACCOUNT_EXISTS="ec_accountexists";SERVER_ERROR_REMEMBER_PASSWORD="ec_rememberpassword";SERVER_ERROR_LOGIN="ec_login";CALENDAR_SHORT="short";CALENDAR_LONG="long";function isFunction(obj){return(typeof obj=="function")}
function isError(response,codeError){return(response.substr(0,codeError.length)==codeError)}
function getClassName(obj){if(obj&&obj.constructor&&obj.constructor.toString){var arr=obj.constructor.toString().match(/function\s*(\w+)/);if(arr&&arr.length==2)return arr[1]}}
function validateMail(email){var arr;if(email.length<=0)return false;arr=email.match("^(.+)@(.+)$");if(arr==null)return false;if(arr[1]!=null){var regexp_user=/^\"?[\w-_\.]*\"?$/;if(arr[1].match(regexp_user)==null)return false}
if(arr[2]!=null){var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;if(arr[2].match(regexp_domain)==null){var regexp_ip=/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;if(arr[2].match(regexp_ip)==null)return false}
return true}
return false}
function writeMails(DOMElement,domain){var aDOMItem=DOMElement.select(".writemail");aDOMItem.each(function(DOMItem){var mail=DOMItem.innerHTML+"@"+domain;DOMItem.innerHTML='<a href="mailto:'+mail+'">'+mail+'</a>'})}
function utf8Encode(sData){return unescape(encodeURIComponent(sData))}
function utf8Decode(sData){return decodeURIComponent(escape(sData))}
function readData(Data,DOMData){var DOMDataList=DOMData.select("div");DOMDataList.each(function(DOMData){eval("Data."+DOMData.id+"='"+DOMData.innerHTML+"';")},this)}
function stripDomain(sLink){return sLink.substr(sLink.lastIndexOf("/")+1)}
Array.prototype.ksort=function(){var aKeys=new Array();var aResult=new Array();for(iKey in this){if(isFunction(this[iKey]))continue;aKeys.push(iKey)}
aKeys=aKeys.sort();for(iKey in aKeys){if(isFunction(aKeys[iKey]))continue;aResult[aKeys[iKey]]=this[aKeys[iKey]]}
return aResult}
IDate=function(index){this.setIndex(index)}
IDate.dayNames=['Lunes','Martes','Miércoles','Jueves','Viernes','Sábado','Domingo'];IDate.dayNamesShort=['D','L','M','M','J','V','S'];IDate.monthNames=['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];IDate.monthDays=[31,28,31,30,31,30,31,31,30,31,30,31];IDate.replaceChars={d:function(){return this.day},D:function(){return(this.day<10 ? '0':'')+this.day},w:function(){return IDate.dayNamesShort[this.weekDay]},W:function(){return IDate.dayNames[this.weekDay]},m:function(){return this.month+1},M:function(){return(this.month<9 ? '0':'')+(this.month+1)},N:function(){return IDate.monthNames[this.month]},Y:function(){return this.year},y:function(){return(''+this.year).substr(2)}}
IDate.isLeapYear=function(iYear){return((iYear % 4==0)&&(iYear % 100||!(iYear % 400)))? true:false}
IDate.getIndex=function(year,month,day){return Date.UTC(year,month,day)/86400000}
IDate.unserialize=function(value){if(!value)value="";value=value.replace(/-/g,"/");var D=new Date(value+" 00:00:00");var index=IDate.getIndex(D.getFullYear(),D.getMonth(),D.getDate());var result=new IDate(index);return result}
IDate.prototype.setIndex=function(index){this.index=0;if(!index)return;this.index=index;var D=new Date;D.setTime(index*86400000);this.year=D.getUTCFullYear();this.month=D.getUTCMonth();this.day=D.getUTCDate();this.weekDay=D.getUTCDay()-1;if(this.weekDay<0)this.weekDay=6}
IDate.prototype.setToday=function(){var D=new Date;var index=IDate.getIndex(D.getFullYear(),D.getMonth(),D.getDate());this.setIndex(index)}
IDate.prototype.isSaturday=function(){if(!this.index)return;return(this.weekDay==5)}
IDate.prototype.isSunday=function(){if(!this.index)return;return(this.weekDay==6)}
IDate.prototype.isAugust=function(){if(!this.index)return;return(this.month==7)}
IDate.prototype.toString=function(){if(!this.index)return;return this.day+"/"+(this.month+1)+"/"+this.year}
IDate.prototype.serialize=function(){if(!this.index)return;return this.year+"-"+(this.month+1)+"-"+this.day}
IDate.prototype.format=function(format){if(!this.index)return;var result='';for(var i=0;i<format.length;i++){var c=format.charAt(i);if(IDate.replaceChars[c]){result+=IDate.replaceChars[c].call(this);continue}
if(c=="$"){i++;c=format.charAt(i)}
result+=c}
return result};dtToday=new IDate;dtToday.setToday();CookieManager=new Object;CookieManager.WpCookie=null;CookieManager.init=function(domain){CookieManager.WpCookie=new wp_Cookie({expires:10,expires_unit:"years",domain:domain})}
CookieManager.get=function(sName){return CookieManager.WpCookie.get(sName)}
CookieManager.set=function(sName,sValue){CookieManager.WpCookie.remove(sName);CookieManager.WpCookie.set(sName,sValue)}
CookieManager.remove=function(sName){CookieManager.WpCookie.remove(sName)}
function InternalException(e,data,message){alert(Lang.Exception.Unknown)}
Serializer64=new Object;Serializer64.data=String("tQ0CS4GmaIAO1XVgrqdkinM7$8Y9phNRDj6JczExvUeTWKHL5.2usBlw3fbFyoZP");Serializer64.readInt=function(data){result=0;var i=data.length-1;while(i>=0){var index=this.data.indexOf(data.substr(i,1));result=result*64+index;i--}
return result}
Serializer64.writeInt=function(value,digits){var result="";if(value==0&&(digits==0||digits==null))return this.data.substr(0,1);while(value>0||digits>0){var index=value % 64;var result=result+this.data.substr(index,1);value=parseInt(value/64);digits--}
return result}
Serializer64.readDate=function(data,dateAux){var index=this.readInt(data);if(dateAux)index+=dateAux.index;var date=new IDate(index);return date}
Serializer64.writeDate=function(date,dateAux){var index=date.index;if(dateAux)index=index-dateAux.index;if(dateAux)
return this.writeInt(index,2);else
return this.writeInt(index,3)}
Serializer64.readString=function(data){var result="";for(var i=0;i<data.length;i+=4){var code=this.readInt(data.substr(i,4));result+=String.fromCharCode((code>>16)&0xFF);result+=String.fromCharCode((code>>8)&0xFF);result+=String.fromCharCode(code&0xFF)}
index=result.length;while(index>0&&result[index-1]==' ')index--;result=result.substring(0,index);return result}
Serializer64.writeString=function(value){value=value+Array("","  "," ")[(value.length)% 3];result="";for(var i=0;i<value.length;i+=3){code=(value.charCodeAt(i)<<16)+(value.charCodeAt(i+1)<<8)+value.charCodeAt(i+2);result=result+this.writeInt(code,4)}
return result}
function CGTask(iStepCount){this.iStep=0;this.iStepCount=iStepCount;this.bTerminated=false}
CGTask.prototype.isFirstStep=function(){return(this.iStep==0)}
CGTask.prototype.isLastStep=function(){return(this.iStep==this.iStepCount)}
CGTask.prototype.restart=function(){this.iStep=0;this.execute()}
CGTask.prototype.terminate=function(){this.iStep=this.iStepCount;this.execute()}
CGTask.prototype.step=function(steps){if(steps==null)steps=1;this.iStep+=steps-1;this.execute()}
CGTask.prototype.gotoStep=function(iStep){if(iStep>this.iNumSteps)return false;this.iStep=iStep-2;this.execute()}
CGTask.prototype.execute=function(){if(this.bTerminated)return;if(this.isLastStep()){this.bTerminated=true;if(this.ReturnTask)this.ReturnTask.execute();return}
var Step=this.getNextStep();try{this.method=Step.method;this.method()}
catch(e){InternalException(e)}}
CGTask.prototype.getNextStep=function(){if(this.iStep>this.iStepCount)return false;this.iStep++;var Step={method:this["step_"+this.iStep]};return Step}
CGTask.prototype.onSuccess=function(){this.execute()}
CGTask.prototype.onFailure=function(sFailure){if(this.ReturnTask)
this.ReturnTask.onFailure(sFailure);else
InternalException(sFailure)}
function CGAction(iStepCount){this.iStep=0;this.iStepCount=iStepCount;this.bExecuted=false}
CGAction.prototype=new CGTask;CGAction.constructor=CGAction;CGAction.prototype.execute=function(){if(this.bTerminated)return;if(this.isLastStep()){this.bTerminated=true;if(this.ReturnTask)this.ReturnTask.execute();Desktop.hideMessage();return}
var Step=this.getNextStep();try{this.method=Step.method;this.method()}
catch(e){Desktop.hideMessage();InternalException(Lang.Exceptions.Unknown)}}
CGAction.prototype.onFailure=function(sFailure){Desktop.hideMessage();if(this.ReturnTask)
this.ReturnTask.onFailure(sFailure);else
InternalException(sFailure)}
CommandDispatcher=new Object;CommandDispatcher.History=new Object;CommandDispatcher.dispatch=function(sCommand,DOMItem){if(CommandFactory.useHistory(sCommand))
this.History.addCommand(sCommand);else
this.execute(sCommand,DOMItem)}
CommandDispatcher.execute=function(sCommand,DOMItem){try{var Action=CommandFactory.getAction(sCommand);if(Action==null)return;Action.DOMItem=DOMItem;Action.execute();return false}
catch(e){InternalException(e);return false}}
CommandDispatcher.History.addCommand=function(sCommand){frames[0].window.location=Configuration.PageHistory+"?"+sCommand}
CommandDispatcher.History.executeCommand=function(){if(!Application.running)return;var sLink=frames[0].window.location.href;var iPos=sLink.indexOf("?");if(iPos>0)
var sCommand=sLink.substring(iPos+1);else
var sCommand="showhome()";CommandDispatcher.execute(sCommand)}
CommandFactory=new Object;CommandFactory.aList=new Array();CommandFactory.add=function(ClassAction,aParameters,bUseHistory){if(!ClassAction)return;if(!ClassAction.prototype.constructor)return;var sClassName=this.getClassName(ClassAction);var sOperation=String(sClassName.substring(String("GGAction").length)).toLowerCase();if(aParameters==null)aParameters=new Object;this.aList[sOperation]={ClassAction:ClassAction,aParameters:aParameters,bUseHistory:bUseHistory}}
CommandFactory.getClassName=function(ClassAction){var data=ClassAction.constructor.toString().match(/function\s*(\w+)/);if(data&&data.length==2)return data[1]}
CommandFactory.getAction=function(sCommand){var Command=this.parseCommand(sCommand);var Item=this.aList[Command.sOperation];if(Item==null)return;var Action=new Item.ClassAction;for(var index in Command.aParameters)
Action[index]=Command.aParameters[index];return Action}
CommandFactory.useHistory=function(sCommand){var Command=this.parseCommand(sCommand);var Item=this.aList[Command.sOperation]
if(Item==null)return;return Item.bUseHistory}
CommandFactory.parseCommand=function(sCommand){var Command=new Object;sCommand=sCommand.replace(/%20/g,"");sCommand=sCommand.replace(/%28/g,"(");sCommand=sCommand.replace(/%29/g,")");if(sCommand.indexOf(Configuration.Url)==0){sCommand=sCommand.substr(Configuration.Url.length+1)}
if(sCommand.indexOf("(")==-1){Command.sOperation=sCommand;return Command}
var reg=new RegExp(/(.*)\(([^\)]*)/g);var aResult=reg.exec(sCommand);Command.sOperation=aResult[1];if(aResult[2]!=""){aResult=aResult[2].split(',');var Item=this.aList[Command.sOperation]
Command.aParameters=new Object;for(var key in Item.aParameters){var index=Item.aParameters[key];Command.aParameters[key]=aResult[index]}}
return Command}
CommandListener=new Object;CommandListener.start=function(Dispatcher){this.Dispatcher=Dispatcher}
CommandListener.stop=function(){this.Dispatcher=null}
CommandListener.capture=function(DOMItem){if(!this.Dispatcher)return;var DOMItem=$(DOMItem);if(!DOMItem)return;aDOMCommands=DOMItem.select(".command");aDOMCommands.each(function(DOMCommand){Event.observe(DOMCommand,'click',CommandListener.atCommandClick.bind(CommandListener,DOMCommand))});aDOMCommands=DOMItem.select(".changecommand");aDOMCommands.each(function(DOMCommand){Event.observe(DOMCommand,'change',CommandListener.atCommandChange.bind(CommandListener,DOMCommand))});aDOMCommands=DOMItem.select(".submitcommand");aDOMCommands.each(function(DOMCommand){Event.observe(DOMCommand,'submit',CommandListener.atCommandSubmit.bind(CommandListener,DOMCommand))});if(DOMItem.hasClassName("command")){Event.observe(DOMItem,'click',CommandListener.atCommandClick.bind(CommandListener,DOMItem))}
if(DOMItem.hasClassName("changecommand")){Event.observe(DOMItem,'change',CommandListener.atCommandChange.bind(CommandListener,DOMItem))}}
CommandListener.atCommandClick=function(DOMItem,EventLaunched){var sCommand=null;if(DOMItem.href)sCommand=stripDomain(DOMItem.href);else if(DOMItem.name)sCommand=DOMItem.name;else if(DOMItem.id)sCommand=DOMItem.id;if(!sCommand)return false;this.Dispatcher.dispatch(sCommand,DOMItem);if((EventLaunched)&&(!DOMItem.value))Event.stop(EventLaunched);return false}
CommandListener.atCommandChange=function(DOMItem,EventLaunched){var sCommand=null;if(DOMItem.href)sCommand=DOMItem.href;else if(DOMItem.value)sCommand=DOMItem.value;if(!sCommand)return false;this.Dispatcher.dispatch(sCommand,DOMItem);if((EventLaunched)&&(!DOMItem.value))Event.stop(EventLaunched);return false}
CommandListener.atCommandSubmit=function(DOMItem,EventLaunched){var sCommand=null;if(DOMItem.action)sCommand=DOMItem.action;if(!sCommand)return false;this.Dispatcher.dispatch(sCommand,DOMItem);if((EventLaunched)&&(!DOMItem.value))Event.stop(EventLaunched);return false}
function CGCalendarDay(Data){if(!Data)return;this.dtDate=IDate.unserialize(Data.date);this.sName=Data.name}
function CGPlace(){this.code="";this.sName="";this.aPlaces=new Array();this.aHolidays=new Array();this.hasPlaces=false}
CGPlace.prototype.unserializeJson=function(jsonData){this.code=jsonData.code.replace(new RegExp(Configuration.PlacesSeparatorCode,"g"),"/");this.sName=jsonData.name;this.iDepth=eval(jsonData.depth);this.isOther=(this.code.substr(this.code.length-4,3)=="000");for(iPos in jsonData.Places){if(!jsonData.Places[iPos])continue;if(isFunction(jsonData.Places[iPos]))continue;var Place=new CGPlace();Place.unserializeJson(jsonData.Places[iPos]);this.aPlaces[Place.code]=Place;this.hasPlaces=true}
if(this.hasPlaces){var Place=new CGPlace();Place.code=this.code+"000/";Place.sName=Lang.Label.Other;Place.iDepth=this.iDepth+1;this.aPlaces[Place.code]=Place}
for(iPos in jsonData.Holidays){if(!jsonData.Holidays[iPos])continue;if(isFunction(jsonData.Holidays[iPos]))continue;var Holiday=new CGCalendarDay(jsonData.Holidays[iPos]);var indexDate=Holiday.dtDate.index;this.aHolidays[indexDate]=Holiday}}
CGPlace.prototype.unserialize=function(sData){this.unserializeJson(sData.evalJSON())}
function CGSerializable(){}
CGSerializable.prototype.serialize=function(){result="";for(key in this){if(isFunction(this[key]))continue;result+=',"'+key+'":"'+this[key]+'"'}
return "{"+result.substr(1)+"}"}
function CGResult(dtNotify){this.dtNotify=dtNotify;this.dtDue=null;this.iWorkingDays=0;this.iUnqualifiedDays=0;this.iTotalDays=0;this.sLabel=null;this.sDescription=null;this.sLocation=null}
CGResult.prototype=new CGSerializable;Calendar=new Object;Calendar.isHolidays=true;Calendar.isSunday=true;Calendar.isSaturday=true;Calendar.isAugust=false;Calendar.isAugustSaturday=false;Calendar.isDueOnSaturday=false;Calendar.sCodePlace="";Calendar.Place=null;Calendar.aPlaces=new Array();Calendar.aUserDays=new Array();Calendar.aHolidays=new Array();Calendar.isEmpty=true;Calendar.updateHolidays=function(){this.aHolidays=new Array();this.isUpdated=true;for(var iPos in this.aPlaces){if(isFunction(this.aPlaces[iPos]))continue;var Place=this.aPlaces[iPos];Place.isUpdated=true;if(Place.aHolidays.length==0)continue;Place.isUpdated=false;for(var jPos in Place.aHolidays){if(isFunction(Place.aHolidays[jPos]))continue;var Holiday=Place.aHolidays[jPos];var index=Holiday.dtDate.index;var iYear=Holiday.dtDate.year;this.aHolidays[index]=Holiday;if(iYear<this.iLastYear)continue;Place.isUpdated=true}
if(Place.isUpdated)continue;this.isUpdated=false}
this.aHolidays=this.aHolidays.ksort()}
Calendar.addPlace=function(Place){if(Place.iDepth>0){this.Place=this.aPlaces[Place.iDepth-1];Place.sName=this.Place.aPlaces[Place.code].sName}
else{this.Place=null;Place.sName=""}
this.Place=Place;this.sCodePlace=Place.code;this.removePlacesFromDepth(Place.iDepth);this.aPlaces[Place.iDepth]=Place;this.updateHolidays()}
Calendar.removePlacesFromDepth=function(iDepth){for(var iPos=iDepth;iPos<this.aPlaces.length;iPos++)delete this.aPlaces[iPos];this.aPlaces.length=iDepth}
Calendar.existHoliday=function(index){return(this.aHolidays[index]!=null)}
Calendar.getUserDays=function(){return this.aUserDays}
Calendar.existUserDay=function(index){return(this.aUserDays[index]!=null)}
Calendar.addUserDay=function(index,UserDay){this.aUserDays[index]=UserDay}
Calendar.deleteUserDay=function(index){if(this.aUserDays[index]==null)return true;delete this.aUserDays[index]}
Calendar.serialize=function(){var version=0;var opt=0;opt+=(this.isHolidays<<0);opt+=(this.isSaturday<<1);opt+=(this.isSunday<<2);opt+=(this.isAugust<<3);opt+=(this.isAugustSaturday<<4);opt+=(this.isDueOnSaturday<<5);var result=Serializer64.writeInt(version)+Serializer64.writeInt(opt)+Serializer64.writeInt(this.mode==CALENDAR_SHORT ? 1:0);var sCode=this.sCodePlace;var iCode=0;for(var i=1;i<sCode.length;i+=4){iCode=iCode*100+parseInt(sCode.substr(i,3),10)}
result+=Serializer64.writeInt(iCode);result+=".";var aDays=this.aUserDays.ksort();var PreviousDate=null;for(var iDay in aDays){if(isFunction(aDays[iDay]))continue;result+=Serializer64.writeDate(aDays[iDay].dtDate,PreviousDate);PreviousDate=aDays[iDay].dtDate}
return result}
Calendar.unserialize=function(value){var version=Serializer64.readInt(value.substr(0,1));switch(version){}
var opt=Serializer64.readInt(value.substr(1,1));this.isHolidays=((opt&1)!=0);this.isSaturday=((opt&2)!=0);this.isSunday=((opt&4)!=0);this.isAugust=((opt&8)!=0);this.isAugustSaturday=((opt&16)!=0);this.isDueOnSaturday=((opt&32)!=0);var mode=Serializer64.readInt(value.substr(2,1));this.mode=(mode)? CALENDAR_SHORT:CALENDAR_LONG;var data=value.substring(3,value.indexOf("."));var iCode=Serializer64.readInt(data);var sCode="";while(iCode>0){var aux=String("00"+(iCode % 100));sCode="/"+aux.substr(aux.length-3)+sCode;iCode=parseInt(iCode/100)}
this.sCodePlace=sCode;this.aUserDays=new Array();var data=value.substring(value.indexOf(".")+1,value.length);var index=0;var aDays=new Array();var UserDay=new CGCalendarDay();UserDay.dtDate=Serializer64.readDate(data.substr(i,3),null);index=UserDay.dtDate.index;this.aUserDays[index]=UserDay;LastDate=UserDay.dtDate;for(var i=3;i<data.length;i+=2){var UserDay=new CGCalendarDay();UserDay.dtDate=Serializer64.readDate(data.substr(i,2),LastDate);index=UserDay.dtDate.index;this.aUserDays[index]=UserDay;LastDate=UserDay.dtDate}
Calendar.isEmpty=false}
Calendar.getData=function(iYear,iMonth,iDay,iWeekDay){Data=new Object;Data.sType="";Data.sName="";var dtDate=new IDate(IDate.getIndex(iYear,iMonth,iDay));var index=dtDate.index;var Holiday=this.aHolidays[index];var UserDay=this.aUserDays[index];if(iWeekDay==6&&this.isSunday)Data.sType+=" sunday";if(iWeekDay==5&&this.isSaturday)Data.sType+=" saturday";if(iMonth==7&&this.isAugust)Data.sType+=" august";if(iMonth==7&&iWeekDay==5&&this.isAugustSaturday)Data.sType+=" august saturday";Data.isStatic=(Data.sType!=""||Holiday);if(Holiday){Data.sType+=" holiday";if(Holiday.sName)Data.sName=Holiday.sName;else Data.sName=Lang.Calendar.LocalHoliday}
else if(UserDay){Data.sType+=" userday"}
if(Data.isStatic)Data.sType+=" static";return Data}
Calendar.calculate=function(dtNotify,iDays){var Result=new CGResult(dtNotify);var index=dtNotify.index;var dtCurrentDay=new IDate(index);while(iDays>0){index++;dtCurrentDay.setIndex(index);var Holiday=this.aHolidays[index];var Userday=this.aUserDays[index];Result.iTotalDays++;if(Userday){Result.iUnqualifiedDays++;continue}
if((Holiday)&&(this.isHolidays)){Result.iUnqualifiedDays++;continue}
if(dtCurrentDay.isSunday()&&this.isSunday){Result.iUnqualifiedDays++;continue}
if(dtCurrentDay.isSaturday()&&this.isSaturday){Result.iUnqualifiedDays++;continue}
if(dtCurrentDay.isAugust()&&this.isAugust){Result.iUnqualifiedDays++;continue}
if(dtCurrentDay.isAugust()&&dtCurrentDay.isSaturday()&&this.isAugustSaturday){Result.iUnqualifiedDays++;continue}
Result.iWorkingDays++;iDays--;if(iDays>0)continue;if(dtCurrentDay.isSaturday()&&this.isDueOnSaturday)iDays++}
Result.dtDue=dtCurrentDay;return Result}
Calendar.getCount=function(dtFirst,dtLast){var dtCurrentDay=new IDate;var index=dtFirst.index;var stop=dtLast.index;if(index>stop){index=stop;stop=dtFirst.index}
var iDays=0;while(index<stop){index++;dtCurrentDay.setIndex(index);var Holiday=this.aHolidays[index];var Userday=this.aUserDays[index];if(Userday)continue;if((Holiday)&&(this.isHolidays))continue;if(dtCurrentDay.isSunday()&&this.isSunday)continue;if(dtCurrentDay.isSaturday()&&this.isSaturday)continue;if(dtCurrentDay.isAugust()&&this.isAugust)continue;if(dtCurrentDay.isAugust()&&dtCurrentDay.isSaturday()&&this.isAugustSaturday)continue;iDays++}
return iDays}
Calendar.getWorkingDaysOfMonth=function(iMonth,iYear){var index=IDate.getIndex(iYear,iMonth,0);var iDays=IDate.monthDays[iMonth];return Calendar.getCount(new IDate(index),new IDate(index+iDays))}
function MonthYear(iMonth,iYear){if(iMonth!=null)this.iMonth=iMonth;else this.iMonth=dtToday.month;if(iYear!=null)this.iYear=iYear;else this.iYear=dtToday.year}
MonthYear.prototype.add=function(value){var iMonth=this.iMonth+value;var iYear=this.iYear;while(iMonth>=12){iYear++;iMonth-=12}
while(iMonth<0){iYear--;iMonth+=12}
if(iYear<this.iFirstYear){this.iYear=this.iFirstYear;this.iMonth=0;return false}
else if(iYear>this.iLastYear){return false}
else{this.iYear=iYear;this.iMonth=iMonth;return true}}
MonthYear.prototype.next=function(value){var iMonth=this.iMonth+value;var iYear=this.iYear;if(iMonth>=12){iYear++;iMonth-=12}
if(iYear>this.iLastYear)return false;return new MonthYear(iMonth,iYear)}
Account=new Object;Account.clear=function(){Account.code=null;Account.sFullname=null;Account.sEmail=null;Account.sCalendar=null}
Account.unserialize=function(sData){var Data=sData.evalJSON();Account.code=Data.User.code;Account.sFullname=Data.User.fullname;Account.sEmail=Data.User.email;Account.sCalendar=Data.calendar}
Account.isLogged=function(){return(Account.code!=null)}
Account.clear();function CGTaskLoadPlaces(){this.base=CGTask;this.index=0;this.aPath=null;this.sPath="";this.base(2)}
CGTaskLoadPlaces.prototype=new CGTask;CGTaskLoadPlaces.prototype.step_1=function(){var sFullPath,sPath,aPath;if(!this.aPath)this.aPath=Calendar.sCodePlace.split("/");if(this.index<this.aPath.length){this.sPath+=this.aPath[this.index]+"/";Kernel.loadPlace(this,this.sPath)}}
CGTaskLoadPlaces.prototype.step_2=function(){var Place=new CGPlace();Place.unserialize(this.data);Calendar.addPlace(Place);this.index++;if(this.index<this.aPath.length)
this.restart();else
this.terminate()}
Kernel=new Object;Kernel.init=function(){}
Kernel.loadPlaces=function(Task){var TaskLoadPlaces=new CGTaskLoadPlaces;TaskLoadPlaces.ReturnTask=Task;TaskLoadPlaces.execute()}
Kernel.loadPlace=function(Task,path){if(path.substr(path.length-4,3)=="000"){Task.data='{"code":"'+path+'","depth":"'+((path.length-1)/4)+'","Places":[],"Holidays":[]}';if(Task.onSuccess)Task.onSuccess()}
else{path=path.replace(/\//g,Configuration.PlacesSeparatorCode);Kernel.executeRequest(Task,"loadplace","path="+path)}}
Kernel.loadPage=function(Task,id){Kernel.executeRequest(Task,"loadpage","id="+id)}
Kernel.register=function(Task,data){Kernel.executeRequest(Task,"register","data="+data)}
Kernel.login=function(Task,email,password,captcha){Kernel.executeRequest(Task,"login","email="+email+"&password="+password+"&captcha="+captcha)}
Kernel.logout=function(Task){Kernel.executeRequest(Task,"logout")}
Kernel.loadAccount=function(Task){Kernel.executeRequest(Task,"loadaccount")}
Kernel.saveAccount=function(Task,data){Kernel.executeRequest(Task,"saveaccount","data="+data)}
Kernel.changePassword=function(Task,oldpassword,newpassword){Kernel.executeRequest(Task,"changepassword","oldpassword="+oldpassword+"&newpassword="+newpassword)}
Kernel.rememberPassword=function(Task,email,captcha){Kernel.executeRequest(Task,"rememberpassword","email="+email+"&captcha="+captcha)}
Kernel.downloadDueResult=function(Task,data,format){var parameters="op=downloaddueresult&data="+data+"&format="+format;window.location=Configuration.Api+Kernel.writeRequest(parameters)}
Kernel.isServerError=function(response){return isError(response,SERVER_ERROR)}
Kernel.startRequest=function(){document.body.addClassName('wait')}
Kernel.terminateRequest=function(){document.body.removeClassName('wait')}
Kernel.executeRequest=function(Task,sOperation,sParameters){Kernel.startRequest();new Ajax.Request(Configuration.Api,{parameters:Kernel.writeRequest("op="+sOperation+((sParameters)?("&"+sParameters):"")),onSuccess:function(message){Task.data=Kernel.readResponse(message.responseText);try{if(Kernel.isServerError(Task.data)){Kernel.terminateRequest();if(Task.onFailure)Task.onFailure(Task.data);else InternalException(Task.data)}
else{Kernel.terminateRequest();if(Task.onSuccess)Task.onSuccess()}}
catch(e){Kernel.terminateRequest();InternalException(e)}},onFailure:function(message,options){Kernel.terminateRequest();InternalException(message)},onException:function(message,options){Kernel.terminateRequest();InternalException(message)}})}
Kernel.mode=false;Kernel.readResponse=function(data){if(Kernel.mode)return Serializer64.readString(data);return data}
Kernel.writeRequest=function(data){var result=(Kernel.mode)? "r="+Serializer64.writeString(data):data;return "?"+result}
Desktop=new Object;Desktop.init=function(){this.DOMDisplay=$("Desktop");if(this.DOMDisplay)writeMails(this.DOMDisplay,Configuration.Domain)}
Desktop.show=function(){$("DesktopLoading").style.display="none";this.DOMDisplay.style.display="block"}
Desktop.refresh=function(){if(Calendar.isEmpty)
this.DOMDisplay.addClassName("empty");else
this.DOMDisplay.removeClassName("empty");if(Account.isLogged())
this.DOMDisplay.addClassName("session");else
this.DOMDisplay.removeClassName("session");DOMPlace=$("place");if(DOMPlace&&!Calendar.isEmpty)DOMPlace.innerHTML=Calendar.Place.sName;this.refreshContext()}
Desktop.createDialog=function(DialogClass,Parameters){var Dialog=new DialogClass();for(var index in Parameters)
Dialog[index]=Parameters[index];var DOMContainer=Dialog.DOMDisplay.up(".container");this.showContainer(DOMContainer);Dialog.refresh();Dialog.show()}
Desktop.showContainer=function(DOMContainer){aDOMDialogs=DOMContainer.select(".dialog.hiddenable");for(var index in aDOMDialogs){var DOMDialog=aDOMDialogs[index];if(isFunction(DOMDialog))continue;DOMDialog.style.display="none"}
if(DOMContainer==this.DOMContainer)return;if(this.DOMContainer)this.DOMContainer.style.display="none";this.DOMContainer=DOMContainer;this.DOMContainer.style.display="block"}
Desktop.refreshContext=function(){var Dialog=new CGDialogInfo();if(Dialog.DOMDisplay==null)return;Dialog.refresh();Dialog.show()}
Desktop.showMessage=function(sMessage,mode){var DOMMessage=this.DOMDisplay.select(".message").first();if(!DOMMessage)return;DOMMessage.innerHTML=sMessage;DOMMessage.style.display="block"}
Desktop.hideMessage=function(){var DOMMessage=this.DOMDisplay.select(".message").first();if(!DOMMessage)return;DOMMessage.style.display="none"}
CGDialog=function(){}
CGDialog.prototype.init=function(){this.getElement("head").style.display="block";this.getElement("body").style.display="block";this.getElement("result").style.display="none";this.getElement("message").style.display="none"}
CGDialog.prototype.refresh=function(){}
CGDialog.prototype.showMessage=function(sMessage,mode){var DOMItem=this.getElement("message");DOMItem.style.display="block";DOMItem.className="message";if(mode)DOMItem.addClassName(mode);DOMItem.innerHTML=sMessage;this.show()}
CGDialog.prototype.hideMessage=function(){var DOMItem=this.getElement("message");DOMItem.style.display="none"}
CGDialog.prototype.showResult=function(){this.getElement("result").style.display="block";this.getElement("head").style.display="none";this.getElement("body").style.display="none"}
CGDialog.prototype.getField=function(name){var DOMField=this.getElementField(name);if(DOMField.type=="checkbox")return DOMField.checked;if(DOMField.type=="text")return DOMField.value;if(DOMField.type=="password")return DOMField.value;return DOMField.innerHTML}
CGDialog.prototype.setField=function(name,value){var DOMField=this.getElementField(name);if(DOMField.type=="checkbox")DOMField.checked=value;else
if(DOMField.type=="text")DOMField.value=value;else
if(DOMField.type=="password")DOMField.value=value;else
DOMField.innerHTML=value}
CGDialog.prototype.disableField=function(name,value){var DOMField=this.getElementField(name);var DOMContainer=DOMField.up(".field");DOMField.disabled=value;DOMContainer.className=(value)? "field disabled":"field"}
CGDialog.prototype.setFieldVisible=function(name,value){var DOMField=this.getElementField(name);DOMField.style.display=(value)? "block":"none"}
CGDialog.prototype.setDisplay=function(sDisplay){this.DOMDisplay=$(sDisplay)}
CGDialog.prototype.isVisible=function(){if(!this.DOMDisplay)return false;return((this.DOMDisplay.style.display!="none")&&(this.DOMDisplay.style.display!=""))}
CGDialog.prototype.show=function(){this.DOMDisplay.style.display="block"}
CGDialog.prototype.hide=function(){this.DOMDisplay.style.display="none"}
CGDialog.prototype.getElement=function(sClass){return this.DOMDisplay.select("."+sClass).first()}
CGDialog.prototype.getElementField=function(sName){return this.DOMDisplay.select(".field ."+sName).first()}
CGDialog.prototype.refreshImage=function(DOMImage){if(DOMImage.link==null)DOMImage.link=DOMImage.src;DOMImage.src=DOMImage.link+"?"+Math.random()}
CGDialogCalculate=function(){this.base=CGDialog;this.DOMDisplay=$("DialogCalculate");this.base()}
CGDialogCalculate.prototype=new CGDialog;CGDialogCalculate.prototype.showSelect=function(){this.refreshSelect();var aDOMSelect=this.getElement("select");var aDOMForm=this.getElement("fields");aDOMSelect.style.display="block";aDOMForm.style.display="none"}
CGDialogCalculate.prototype.hideSelect=function(){var DOMSelect=this.getElement("select");var aDOMForm=this.getElement("fields");DOMSelect.style.display="none";aDOMForm.style.display="block"}
CGDialogCalculate.prototype.isSelectVisible=function(){var DOMSelect=this.getElement("select");return(DOMSelect.style.display=="block")}
CGDialogCalculate.prototype.refresh=function(){this.setField("notifydate",State.Calculating.dtNotify.format("D/M/y"));this.setField("days",State.Calculating.iDays);this.hideSelect()}
CGDialogCalculate.prototype.refreshSelect=function(){var Dialog=new CGDialogCalendarMonth();Dialog.mode=CALENDAR_SHORT;Dialog.sOnClickCommand="calculatesetdate";for(var i=1;i<=2;i++){var DOMCalendar=this.getElement("selectdate"+i);if(DOMCalendar==null)continue;Dialog.setDisplay(DOMCalendar);Dialog.clear();var Aux=State.Calculating.SelectMonth.next(i-1);if(Aux==false)continue;Dialog.setMonth(Aux.iMonth,Aux.iYear);Dialog.refresh()}}
CGDialogCount=function(){this.base=CGDialog;this.DOMDisplay=$("DialogCount");this.base();var DOMInput=this.getElementField("firstdate");var DOMField=DOMInput.up(".field");DOMField.DOMInput=DOMInput;DOMField.MonthYear=new MonthYear;DOMField.setDate=function(value){State.Counting.dtFirst=new IDate(value);this.DOMInput.innerHTML=State.Counting.dtFirst.format("D/M/y")}
var DOMInput=this.getElementField("lastdate");var DOMField=DOMInput.up(".field");DOMField.DOMInput=DOMInput;DOMField.MonthYear=new MonthYear;DOMField.setDate=function(value){State.Counting.dtLast=new IDate(value);this.DOMInput.innerHTML=State.Counting.dtLast.format("D/M/y")}}
CGDialogCount.prototype=new CGDialog;CGDialogCount.prototype.refresh=function(){this.refreshSelect("firstdate");this.refreshSelect("lastdate");this.setField("firstdate",State.Counting.dtFirst.format("D/M/y"));this.setField("lastdate",State.Counting.dtLast.format("D/M/y"))}
CGDialogCount.prototype.refreshSelect=function(name){var Dialog=new CGDialogCalendarMonth();Dialog.mode=CALENDAR_SHORT;Dialog.sOnClickCommand="countsetdate";var DOMCalendar=this.getElement("select ."+name);var DOMField=DOMCalendar.up(".field");DOMField.Dialog=Dialog;Dialog.setDisplay(DOMCalendar);Dialog.clear();Dialog.setMonth(DOMField.MonthYear.iMonth,DOMField.MonthYear.iYear);Dialog.refresh()}
CGDialogCount.prototype.refreshCount=function(name){this.setField("count",Calendar.getCount(State.Counting.dtFirst,State.Counting.dtLast)+" días hábiles")}
CGDialogPage=function(){this.base=CGDialog;this.DOMDisplay=$("DialogPage");this.base()}
CGDialogPage.prototype=new CGDialog;CGDialogPage.prototype.refresh=function(){this.DOMDisplay.innerHTML=this.data;CommandListener.capture(this.DOMDisplay);writeMails(this.DOMDisplay,Configuration.Domain)}
CGDialogLogin=function(){this.base=CGDialog;this.DOMDisplay=$("DialogLogin");this.base()}
CGDialogLogin.prototype=new CGDialog;CGDialogLogin.prototype.refresh=function(){this.init();this.setField("email","");this.setField("password","");this.setField("captchacode","");this.refreshCaptcha()}
CGDialogLogin.prototype.refreshCaptcha=function(){this.getElement("captcha").style.display="none";if(Application.iLoginCount<Configuration.MaxLoginCount)return;this.refreshImage(this.getElementField("captchaimage"));this.getElement("captcha").style.display="block"}
CGDialogLogin.prototype.show=function(){this.DOMDisplay.style.display="block";this.getElementField("email").focus()}
CGDialogLogin.prototype.read=function(){var Login=new CGSerializable;Login.email=this.getField("email");Login.password=this.getField("password");Login.captcha=this.getField("captchacode");return Login}
CGDialogRegister=function(){this.base=CGDialog;this.DOMDisplay=$("DialogRegister");this.base()}
CGDialogRegister.prototype=new CGDialog;CGDialogRegister.prototype.refresh=function(){this.init();this.setField("email","");this.setField("fullname","");this.setField("password","");this.setField("repassword","");this.setField("captchacode","")}
CGDialogRegister.prototype.refreshCaptcha=function(){this.refreshImage(this.getElementField("captchaimage"))}
CGDialogRegister.prototype.show=function(){this.DOMDisplay.style.display="block";this.getElementField("fullname").focus()}
CGDialogRegister.prototype.read=function(){var Account=new CGSerializable;Account.email=this.getField("email");Account.fullname=this.getField("fullname");Account.password=this.getField("password");Account.securitycode=this.getField("captchacode");return Account}
CGDialogRememberPassword=function(){this.base=CGDialog;this.DOMDisplay=$("DialogRememberPassword");this.base()}
CGDialogRememberPassword.prototype=new CGDialog;CGDialogRememberPassword.prototype.refresh=function(){this.init();this.setField("email","");this.setField("captchacode","");this.refreshImage(this.getElementField("captchaimage"))}
CGDialogRememberPassword.prototype.refreshCaptcha=function(){this.refreshImage(this.getElementField("captchaimage"))}
CGDialogRememberPassword.prototype.show=function(){this.DOMDisplay.style.display="block";this.getElementField("email").focus()}
CGDialogChangePassword=function(){this.base=CGDialog;this.DOMDisplay=$("DialogChangePassword");this.base()}
CGDialogChangePassword.prototype=new CGDialog;CGDialogChangePassword.prototype.refresh=function(){this.init();this.setField("oldpassword","");this.setField("newpassword","");this.setField("chkpassword","")}
CGDialogChangePassword.prototype.show=function(){this.DOMDisplay.style.display="block";this.getElementField("oldpassword").focus()}
CGDialogCalendarMonth=function(){this.base=CGDialog;this.DOMDisplay=null;this.isReadOnly=false;this.base()}
CGDialogCalendarMonth.prototype=new CGDialog;CGDialogCalendarMonth.prototype.setMonth=function(iMonth,iYear){this.iMonth=iMonth;this.iYear=iYear}
CGDialogCalendarMonth.prototype.setOnClickCommand=function(sCommand){this.sOnClickCommand=sCommand}
CGDialogCalendarMonth.prototype.drawHeader=function(){var sHtml;var sYear=this.iYear;var sMonth=IDate.monthNames[this.iMonth];sHtml='<div class="static">';sHtml+='<div class="header">'+sMonth+' '+sYear+"</div>";sHtml+='<div class="footer">'+Calendar.getWorkingDaysOfMonth(this.iMonth,this.iYear)+Lang.Calendar.WorkingDays+'</div>';sHtml+=this.drawHeaderDays();sHtml+="</div>";return sHtml}
CGDialogCalendarMonth.prototype.drawHeaderDays=function(){var sHtml='<div class="names">';for(var i=1;i<=7;i++){var WeekDay=IDate.dayNamesShort[i%7];sHtml+='<span class="day">'+WeekDay+'</span>'}
sHtml+='</div>';return sHtml}
CGDialogCalendarMonth.prototype.drawDay=function(iDay,iWeekDay,Data){var sHtml;if(Data==null)Data=new Object;if(this.isReadOnly)Data.sCommand=null;if(iDay<0)return '<a class="day">&nbsp;</a>';var sClassName=' class="command day'+Data.sType+((Data.isToday)? " today":"")+'"';var sTitle=' title="'+Data.sName+'"';var sCommand=(Data.sCommand)? ' href="'+Data.sCommand+'"':'';sHtml='<a'+sClassName+sTitle+sCommand+'>'+iDay+'</a>';return sHtml}
CGDialogCalendarMonth.prototype.refresh=function(){var sHtml;var sOnClickCommand=this.sOnClickCommand+"(::PARAMETERS::)";if(!this.DOMDisplay)return;var index=IDate.getIndex(this.iYear,this.iMonth,1);var iDay=1;var iStop=IDate.monthDays[this.iMonth];var bIsCurrentMonth=((this.iYear==dtToday.year)&&(this.iMonth==dtToday.month));var dtFirst=new IDate(index);var iWeekDay=dtFirst.weekDay;if(IDate.isLeapYear(this.iYear))
IDate.monthDays[1]=29;else
IDate.monthDays[1]=28;sHtml='<div class="short">';sHtml+=this.drawHeader();sHtml+='<div>';while(iDay<=iStop){for(var i=0;i<=6;i++){if((iDay==1&&i<iWeekDay)||iDay>iStop){sHtml+=this.drawDay(-1)}
else{var Data=Calendar.getData(this.iYear,this.iMonth,iDay,iWeekDay);Data.isToday=(index==dtToday.index);Data.sCommand=sOnClickCommand.replace("::PARAMETERS::",index);sHtml+=this.drawDay(iDay,iWeekDay,Data);iDay++;index++;iWeekDay++;iWeekDay=iWeekDay % 7}}}
sHtml+='</div>';this.DOMDisplay.innerHTML=sHtml;CommandListener.capture(this.DOMDisplay)}
CGDialogCalendarMonth.prototype.clear=function(){this.DOMDisplay.innerHTML='<div class="short">&nbsp;</div>'}
CGDialogCalendar=function(){this.base=CGDialog;this.DOMDisplay=$("DialogCalendar");this.base()}
CGDialogCalendar.prototype=new CGDialog;CGDialogCalendar.prototype.refresh=function(){if(State.Calendar.needRefresh==false)return;State.Calendar.needRefresh=false;var Dialog=new CGDialogCalendarMonth();Dialog.isReadOnly=(Configuration.Mode=="calendar");Dialog.mode=CALENDAR_SHORT;for(var i=1;i<=12;i++){var Aux=State.Calendar.next(i-1);Dialog.setMonth(Aux.iMonth,Aux.iYear);Dialog.setDisplay("month"+i);Dialog.sOnClickCommand="calendarmarkdate";Dialog.refresh()}
this.setField("places",this.generatePlaces())}
CGDialogCalendar.prototype.generatePlaces=function(){var result="";var aPlaces=Calendar.aPlaces;for(var index=1;index<aPlaces.length;index++){var Place=aPlaces[index];if(Place==null)continue;if(Place.isOther)continue;if(!aPlaces[index-1].aPlaces[Place.code])continue;result=Place.sName+","+" "+result}
if(result=="")return Lang.DialogInfo.NoPlaces;return result.substr(0,result.length-2)}
CGDialogInfo=function(){this.base=CGDialog;this.DOMDisplay=$("DialogInfo");this.base()}
CGDialogInfo.prototype=new CGDialog;CGDialogInfo.prototype.generateOptions=function(){var result="";if(Calendar.isHolidays)result+=Lang.DialogInfo.isHolidays+","+" ";if(Calendar.isSaturday)result+=Lang.DialogInfo.isSaturday+","+" ";if(Calendar.isSunday)result+=Lang.DialogInfo.isSunday+","+" ";if(Calendar.isAugust)result+=Lang.DialogInfo.isAugust+","+" ";if(Calendar.isAugustSaturday)result+=Lang.DialogInfo.isAugustSaturday+","+" ";if(Calendar.isDueOnSaturday)result+=Lang.DialogInfo.isDueOnSaturday+","+" ";if(result=="")return Lang.DialogInfo.NoOptions;return result.substr(0,result.length-2)}
CGDialogInfo.prototype.generatePlaces=function(){var result="";var aPlaces=Calendar.aPlaces;for(var index=1;index<aPlaces.length;index++){var Place=aPlaces[index];if(Place==null)continue;if(Place.isOther)continue;if(!aPlaces[index-1].aPlaces[Place.code])continue;result=Place.sName+","+result}
if(result=="")return Lang.DialogInfo.NoPlaces;return result.substr(0,result.length-1)}
CGDialogInfo.prototype.generateNextHolidays=function(){var iCount=0;var result="";var iToday=dtToday.index;for(var index in Calendar.aHolidays){if(isFunction(Calendar.aHolidays[index]))continue;if(index<iToday)continue;result+=Calendar.aHolidays[index].dtDate.format("d $d$e N")+","+" ";iCount++;if(iCount>=4)break}
if(result=="")return Lang.DialogInfo.NoHolidays;return result.substr(0,result.length-2)}
CGDialogInfo.prototype.refresh=function(){this.setField("options",this.generateOptions());this.setField("places",this.generatePlaces());this.setField("nextholidays",this.generateNextHolidays());this.setFieldVisible("isholidays",!Calendar.isHolidays);this.setField("fullname",Account.sFullname)}
CGDialogInfo.prototype.read=function(){var Account=new CGSerializable;Account.fullname=this.getField("fullname");return Account}
CGDialogSetupPlaces=function(){this.base=CGDialog;this.DOMDisplay=$("DialogSetupPlaces");this.base()}
CGDialogSetupPlaces.prototype=new CGDialog;CGDialogSetupPlaces.prototype.removeDescendantSelectors=function(iDepth){var aDOMSelects=this.DOMDisplay.select(".place");aDOMSelects.each(function(DOMSelect){var iSelectDepth=DOMSelect.id.replace("place","");if(iSelectDepth>iDepth)DOMSelect.replace("")},this);return true}
CGDialogSetupPlaces.prototype.renderPlace=function(Place){var DOMContainer=this.getElementField("selectors");var sPlaceCss=(Place.iDepth!="")? ".place."+Place.iDepth:".place";var sPlaceClass=(Place.iDepth!="")? "place"+" "+Place.iDepth:"place";var DOMSelect,bHasPlaces=false;var PlaceSelected=Calendar.aPlaces[Place.iDepth+1];var sSelectorOptions="<option value='unloadplace("+Place.iDepth+")'>"+Lang.DialogSetupPlaces.SelectPlace+"</option>";for(var iPos in Place.aPlaces){if(isFunction(Place.aPlaces[iPos]))continue;var PlaceAux=Place.aPlaces[iPos];sSelectorOptions+="<option value='loadplace("+PlaceAux.code+")'";sSelectorOptions+=((PlaceSelected!=null)&&(PlaceSelected.code==PlaceAux.code))?" selected ":"";sSelectorOptions+=">"+PlaceAux.sName+"</option>"}
if(Place.hasPlaces){var sHtml="<select id='place"+Place.iDepth+"' class='changecommand "+sPlaceClass+"'>";sHtml+=sSelectorOptions;sHtml+="</select>";DOMContainer.insert(sHtml,"bottom");DOMSelect=DOMContainer.select(sPlaceCss).first();CommandListener.capture(DOMSelect)}
var DOMInput=this.DOMDisplay.select("input.command").first();DOMInput.disabled=Place.hasPlaces;return true}
CGDialogSetupPlaces.prototype.refreshFromDepth=function(iDepth){this.removeDescendantSelectors(iDepth-1);for(var iPos in Calendar.aPlaces){if(isFunction(Calendar.aPlaces[iPos]))continue;if(Calendar.aPlaces[iPos].iDepth<iDepth)continue;this.renderPlace(Calendar.aPlaces[iPos])}}
CGDialogSetupPlaces.prototype.refresh=function(){this.refreshFromDepth(0)}
CGDialogSetupOptions=function(){this.base=CGDialog;this.DOMDisplay=$("DialogSetupOptions");this.base()}
CGDialogSetupOptions.prototype=new CGDialog;CGDialogSetupOptions.prototype.refresh=function(){this.disableField("isdueonsaturday",Calendar.isSaturday);this.disableField("isaugustsaturday",Calendar.isAugust||Calendar.isSaturday);this.setField("isholidays",Calendar.isHolidays);this.setField("issunday",Calendar.isSunday);this.setField("issaturday",Calendar.isSaturday);this.setField("isaugust",Calendar.isAugust);this.setField("isaugustsaturday",Calendar.isAugustSaturday);this.setField("isdueonsaturday",Calendar.isDueOnSaturday)}
CGDialogResult=function(){this.base=CGDialog;this.DOMDisplay=$("DialogResult");this.base()}
CGDialogResult.prototype=new CGDialog;CGDialogResult.prototype.refresh=function(){this.setField("duedate",State.Calculating.Result.dtDue.format("W,d $d$e N $d$e Y"));this.setField("notifydate",State.Calculating.Result.dtNotify.format("W,d $d$e N $d$e Y"));this.setField("totaldays",State.Calculating.Result.iTotalDays);this.setField("workingdays",State.Calculating.Result.iWorkingDays);this.setField("unqualifieddays",State.Calculating.Result.iUnqualifiedDays);this.hideMessage();if(State.Calculating.Result.dtDue.year<Calendar.iLastYear)return;if(Calendar.isUpdated)return;var sPlaces="";for(var iPos in Calendar.aPlaces){if(isFunction(Calendar.aPlaces[iPos]))continue;var Place=Calendar.aPlaces[iPos];if(Place.isUpdated)continue;sPlaces=sPlaces+Place.sName+","}
var sMessage=Lang.Warning.CalendarNotUpdated;sMessage=sMessage.replace('::YEAR::',Calendar.iLastYear);sMessage=sMessage.replace('::PLACES::',sPlaces.substr(0,sPlaces.length-1));this.showMessage(sMessage,"warning")}
CGDialogDownload=function(){this.base=CGDialog;this.DOMDisplay=$("DialogDownloadResult");this.base()}
CGDialogDownload.prototype=new CGDialog;CGDialogDownload.prototype.generateDescription=function(){var sResult="";sResult+=Lang.DialogDownload.DueDate+":"+" "+State.Calculating.Result.dtDue.format("d $d$e N $d$e Y")+CRLF;sResult+=Lang.DialogDownload.NotifyDate+":"+" "+State.Calculating.Result.dtNotify.format("d $d$e N $d$e Y")+CRLF;sResult+=Lang.DialogDownload.TotalDays+":"+" "+State.Calculating.Result.iTotalDays+CRLF;sResult+=Lang.DialogDownload.WorkingDays+":"+" "+State.Calculating.Result.iWorkingDays+CRLF;sResult+=Lang.DialogDownload.UnqualifiedDays+":"+" "+State.Calculating.Result.iUnqualifiedDays+CRLF;return sResult}
CGDialogDownload.prototype.refresh=function(){this.setField("label",Lang.DialogDownload.Due);this.setField("description",this.generateDescription())}
CGDialogLinkCalendar=function(){this.base=CGDialog;this.DOMDisplay=$("DialogLinkCalendar");this.iWidth=0;this.iHeight=0;this.base()}
CGDialogLinkCalendar.prototype=new CGDialog;CGDialogLinkCalendar.prototype.generateURL=function(){switch(State.LinkCalendar.sMode){case "link":
var sURL="<a href='::LINK::' target='_blank' alt='diashabiles.com' title='diashabiles.com'><img src='http://www.diashabiles.com/images/banners/::TYPE::/::THEME::.png' title='diashabiles.com' alt='diashabiles.com' border='0' height='::HEIGHT::' width='::WIDTH::'/>";sURL=sURL.replace('::LINK::',Configuration.Url+"/init?"+Calendar.serialize());sURL=sURL.replace('::TYPE::',State.LinkCalendar.sType);sURL=sURL.replace('::THEME::',State.LinkCalendar.sTheme);return sURL;case "calculator":
var sURL="<iframe border='0' height='350' width='240' style='border:0;' src='::URL::'></iframe>";sURL=sURL.replace('::URL::',Configuration.Url+"/calculator?"+Account.code);return sURL;case "calendar":
var sURL="<iframe border='0' width='550' height='750' style='border:0;' src='::URL::'></iframe>";sURL=sURL.replace('::URL::',Configuration.Url+"/calendar?"+Account.code);return sURL}}
CGDialogLinkCalendar.prototype.refreshOption=function(sOption){var DOMOption=this.getElementField(sOption);if((Account.isLogged()==false)&&DOMOption.hasClassName("logged"))
DOMOption.disabled=true;else
DOMOption.disabled=false;DOMOption.checked=(State.LinkCalendar.sMode==sOption)}
CGDialogLinkCalendar.prototype.refresh=function(){if(Account.isLogged())
this.DOMDisplay.addClassName("logged");else
this.DOMDisplay.removeClassName("logged");var DOMField=this.getElementField("modeinfo");var DOMParent=$(DOMField.parentNode.parentNode);DOMField.innerHTML=(Account.isLogged())? "":Lang.DialogLinkCalendar.InfoLogged;CommandListener.capture(DOMField);this.refreshOption("link");this.refreshOption("calendar");this.refreshOption("calculator");if(State.LinkCalendar.sMode!="link"){this.DOMDisplay.removeClassName("linking");this.setField("url",this.generateURL())}
else{this.DOMDisplay.addClassName("linking");var DOMField=this.getElementField("type");var DOMOption=DOMField.select("."+State.LinkCalendar.sType).first();DOMOption.selected=true;var aResult=State.LinkCalendar.sType.split("x");if(aResult.length>1){this.iWidth=aResult[0];this.iHeight=aResult[1]}
var sURL=this.generateURL();sURL=sURL.replace('::WIDTH::',this.iWidth);sURL=sURL.replace('::HEIGHT::',this.iHeight);this.setField("url",sURL);var DOMPreview=this.getElementField("preview");DOMPreview.update(sURL)}}
function CGActionInit(){this.base=CGAction;this.base(3)}
CGActionInit.prototype=new CGAction;CGActionInit.constructor=CGActionInit;CGActionInit.prototype.step_1=function(){MonthYear.prototype.iFirstYear=Configuration.FirstYear;MonthYear.prototype.iLastYear=Configuration.LastYear;if(oldCookie=CookieManager.get("diashabiles_calendar")){CookieManager.set(Configuration.CookieCalendar,oldCookie);CookieManager.remove("diashabiles_calendar")}
var data=(Configuration.Mode=="application")? CookieManager.get(Configuration.CookieCalendar):Configuration.Calendar;if(Configuration.Command=="")Configuration.Command="showhome";if(data!=null)Calendar.unserialize(data);Calendar.iLastYear=Configuration.LastYear;State=new Object;State.sCommand=Configuration.Command;State.Calendar=new MonthYear(0);State.Calculating=new Object;State.Calculating.dtNotify=dtToday;State.Calculating.iDays=60;State.Calculating.Result=new CGResult;State.Counting=new Object;State.Counting.dtFirst=dtToday;State.Counting.dtLast=dtToday;State.LinkCalendar=new Object;State.LinkCalendar.sMode=null;State.LinkCalendar.sType=null;State.LinkCalendar.sTheme=null;Setup=new Object;Kernel.loadPlaces(this)}
CGActionInit.prototype.step_2=function(){this.code=CookieManager.get("code");if(this.code)
Kernel.loadAccount(this,this.code);else
this.step()}
CGActionInit.prototype.step_3=function(){if(this.code)Account.unserialize(this.data);Desktop.init();Desktop.refresh()
Desktop.show();CommandDispatcher.dispatch(State.sCommand);this.terminate()}
function CGActionShowHome(){}
CGActionShowHome.prototype=new CGAction;CGActionShowHome.constructor=CGActionShowHome;CommandFactory.add(CGActionShowHome,null,true);CGActionShowHome.prototype.execute=function(){State.sCommand="showcalculate";Desktop.createDialog(CGDialogCalculate)}
function CGActionShowSetup(){}
CGActionShowSetup.prototype=new CGAction;CGActionShowSetup.constructor=CGActionShowSetup;CommandFactory.add(CGActionShowSetup,{mode:0},true);CGActionShowSetup.prototype.execute=function(){var DialogClass=null;Setup.sMode=this.mode;if(this.mode=="options")
DialogClass=CGDialogSetupOptions;else if(this.mode=="places")
DialogClass=CGDialogSetupPlaces;if(DialogClass)Desktop.createDialog(DialogClass)}
function CGActionStartSetup(){}
CGActionStartSetup.prototype=new CGAction;CGActionStartSetup.constructor=CGActionStartSetup;CommandFactory.add(CGActionStartSetup,null,false);CGActionStartSetup.prototype.execute=function(){Setup.bFull=true;CommandDispatcher.dispatch("showsetup(places)")}
function CGActionContinueSetup(){}
CGActionContinueSetup.prototype=new CGAction;CGActionContinueSetup.constructor=CGActionContinueSetup;CommandFactory.add(CGActionContinueSetup,null,false);CGActionContinueSetup.prototype.execute=function(){if(Setup.bFull){if(Setup.sMode=="places"){CommandDispatcher.dispatch("showsetup(options)");return}}
Setup.sMode=null;Setup.bFull=false;Calendar.isEmpty=false;State.Calendar.needRefresh=true;CookieManager.set(Configuration.CookieCalendar,Calendar.serialize());Desktop.refresh();var sCommand=State.sCommand+"()";CommandDispatcher.dispatch(sCommand)}
function CGActionSetOption(){}
CGActionSetOption.prototype=new CGAction;CGActionSetOption.constructor=CGActionSetOption;CommandFactory.add(CGActionSetOption,{option:0},false);CGActionSetOption.prototype.execute=function(){if(this.option==null)return;State.Calendar.needRefresh=true;Calendar[this.option]=this.DOMItem.checked;CookieManager.set(Configuration.CookieCalendar,Calendar.serialize());Desktop.refreshContext();setTimeout("Desktop.createDialog(CGDialogSetupOptions)",10)}
function CGActionLoadPlace(){this.base=CGAction;this.base(3)}
CGActionLoadPlace.prototype=new CGAction;CGActionLoadPlace.constructor=CGActionLoadPlace;CommandFactory.add(CGActionLoadPlace,{path:0},false);CGActionLoadPlace.prototype.step_1=function(){Kernel.loadPlace(this,this.path)}
CGActionLoadPlace.prototype.step_2=function(){var Place=new CGPlace();Place.unserialize(this.data);Calendar.addPlace(Place);State.Calendar.needRefresh=true;CookieManager.set(Configuration.CookieCalendar,Calendar.serialize());var Dialog=new CGDialogSetupPlaces();Dialog.refreshFromDepth(Place.iDepth);Desktop.refreshContext();this.terminate()}
function CGActionUnloadPlace(){}
CGActionUnloadPlace.prototype=new CGAction;CGActionUnloadPlace.constructor=CGActionUnloadPlace;CommandFactory.add(CGActionUnloadPlace,{depth:0},false);CGActionUnloadPlace.prototype.execute=function(){var iDepth=parseInt(this.depth)+1;Calendar.removePlacesFromDepth(iDepth);State.Calendar.needRefresh=true;CookieManager.set(Configuration.CookieCalendar,Calendar.serialize());var Dialog=new CGDialogSetupPlaces();Dialog.refreshFromDepth(iDepth);Desktop.refreshContext()}
function CGActionShowPage(){}
CGActionShowPage.prototype=new CGAction;CGActionShowPage.constructor=CGActionShowPage;CommandFactory.add(CGActionShowPage,{page:0},true);CGActionShowPage.prototype.step_1=function(){Kernel.loadPage(this,this.page)}
CGActionShowPage.prototype.step_2=function(){Desktop.createDialog(CGDialogPage,{data:this.data});this.terminate()}
function CGActionShowCalendar(){}
CGActionShowCalendar.prototype=new CGAction;CGActionShowCalendar.constructor=CGActionShowCalendar;CommandFactory.add(CGActionShowCalendar,null,true);CGActionShowCalendar.prototype.execute=function(){State.sCommand="showcalendar";if(Calendar.isEmpty){var Action=new CGActionStartSetup();Action.execute();return}
Desktop.createDialog(CGDialogCalendar)}
function CGActionCalendarAddMonth(){}
CGActionCalendarAddMonth.prototype=new CGAction;CGActionCalendarAddMonth.constructor=CGActionCalendarAddMonth;CommandFactory.add(CGActionCalendarAddMonth,{value:0,display:1},false);CGActionCalendarAddMonth.prototype.execute=function(){this.value=parseInt(this.value);if(State.Calendar.add(this.value)==false)return;State.Calendar.needRefresh=true;Desktop.createDialog(CGDialogCalendar)}
function CGActionCalendarMarkDate(){}
CGActionCalendarMarkDate.prototype=new CGAction;CGActionCalendarMarkDate.constructor=CGActionCalendarMarkDate;CommandFactory.add(CGActionCalendarMarkDate,{index:0},false);CGActionCalendarMarkDate.prototype.execute=function(){var DOMParent=this.DOMItem;if(!DOMParent.hasClassName("day"))DOMParent=DOMParent.up(".day");if(DOMParent.hasClassName("static"))return;if(Calendar.existUserDay(this.index)){Calendar.deleteUserDay(this.index);DOMParent.removeClassName("userday")}
else{CalendarDay=new CGCalendarDay();CalendarDay.dtDate=new IDate(this.index);Calendar.addUserDay(this.index,CalendarDay);DOMParent.addClassName("userday")}
CookieManager.set(Configuration.CookieCalendar,Calendar.serialize())}
function CGActionShowCalculate(){}
CGActionShowCalculate.prototype=new CGAction;CGActionShowCalculate.constructor=CGActionShowCalculate;CommandFactory.add(CGActionShowCalculate,null,true);CGActionShowCalculate.prototype.execute=function(){State.sCommand="showcalculate";Desktop.createDialog(CGDialogCalculate)}
function CGActionCalculate(){}
CGActionCalculate.prototype=new CGAction;CGActionCalculate.constructor=CGActionCalculate;CommandFactory.add(CGActionCalculate,null,false);CGActionCalculate.prototype.execute=function(){State.sCommand="calculate";if(Calendar.isEmpty)
CommandDispatcher.dispatch("startsetup()");else
CommandDispatcher.dispatch("showresult("+State.Calculating.dtNotify.index+","+State.Calculating.iDays+")")}
function CGActionShowResult(){}
CGActionShowResult.prototype=new CGAction;CGActionShowResult.constructor=CGActionShowResult;CommandFactory.add(CGActionShowResult,{date:0,days:1},true);CGActionShowResult.prototype.execute=function(){State.Calculating.dtNotify.setIndex(this.date);State.Calculating.iDays=eval(this.days);State.Calculating.Result=Calendar.calculate(State.Calculating.dtNotify,State.Calculating.iDays);Desktop.createDialog(CGDialogResult)}
function CGActionAddDay(){}
CGActionAddDay.prototype=new CGAction;CGActionAddDay.constructor=CGActionAddDay;CommandFactory.add(CGActionAddDay,{value:0},false);CGActionAddDay.prototype.execute=function(){var Dialog=new CGDialogCalculate();State.Calculating.iDays+=parseInt(this.value);if(State.Calculating.iDays<1)State.Calculating.iDays=1;if(State.Calculating.iDays>300)State.Calculating.iDays=300;Dialog.setField("days",State.Calculating.iDays)}
function CGActionCalculateShowSelect(){}
CGActionCalculateShowSelect.prototype=new CGAction;CGActionCalculateShowSelect.constructor=CGActionCalculateShowSelect;CommandFactory.add(CGActionCalculateShowSelect,null,false);CGActionCalculateShowSelect.prototype.execute=function(){State.Calculating.SelectMonth=new MonthYear;var Dialog=new CGDialogCalculate;if(Dialog.isSelectVisible())
Dialog.hideSelect();else
Dialog.showSelect()}
function CGActionCalculateSetDate(){}
CGActionCalculateSetDate.prototype=new CGAction;CGActionCalculateSetDate.constructor=CGActionCalculateSetDate;CommandFactory.add(CGActionCalculateSetDate,{index:0},false);CGActionCalculateSetDate.prototype.execute=function(){State.Calculating.dtNotify=new IDate(this.index);Dialog=new CGDialogCalculate();Dialog.setField("notifydate",State.Calculating.dtNotify.format("D/M/y"));Dialog.hideSelect()}
function CGActionCalculateAddMonth(){}
CGActionCalculateAddMonth.prototype=new CGAction;CGActionCalculateAddMonth.constructor=CGActionCalculateAddMonth;CommandFactory.add(CGActionCalculateAddMonth,{value:0},false);CGActionCalculateAddMonth.prototype.execute=function(){this.value=parseInt(this.value);State.Calculating.SelectMonth.add(this.value);var Dialog=new CGDialogCalculate();Dialog.refreshSelect()}
function CGActionShowCount(){}
CGActionShowCount.prototype=new CGAction;CGActionShowCount.constructor=CGActionShowCount;CommandFactory.add(CGActionShowCount,null,true);CGActionShowCount.prototype.execute=function(){State.sCommand="showcount";if(Calendar.isEmpty){var Action=new CGActionStartSetup();Action.execute();return}
Desktop.createDialog(CGDialogCount)}
function CGActionCountAddMonth(){}
CGActionCountAddMonth.prototype=new CGAction;CGActionCountAddMonth.constructor=CGActionCountAddMonth;CommandFactory.add(CGActionCountAddMonth,{value:0},false);CGActionCountAddMonth.prototype.execute=function(){var DOMField=this.DOMItem.up(".field");this.value=parseInt(this.value);DOMField.MonthYear.add(this.value);var Dialog=DOMField.Dialog;Dialog.setMonth(DOMField.MonthYear.iMonth,DOMField.MonthYear.iYear);Dialog.refresh()}
function CGActionCountSetDate(){}
CGActionCountSetDate.prototype=new CGAction;CGActionCountSetDate.constructor=CGActionCountSetDate;CommandFactory.add(CGActionCountSetDate,{value:0},false);CGActionCountSetDate.prototype.execute=function(){this.value=parseInt(this.value);var DOMField=this.DOMItem.up(".field");DOMField.setDate(this.value);var Dialog=new CGDialogCount;Dialog.refreshCount()}
function CGActionShowDownload(){}
CGActionShowDownload.prototype=new CGAction;CGActionShowDownload.constructor=CGActionShowDownload;CommandFactory.add(CGActionShowDownload,null,true);CGActionShowDownload.prototype.execute=function(){Desktop.createDialog(CGDialogDownload)}
function CGActionDoDownload(){}
CGActionDoDownload.prototype=new CGAction;CGActionDoDownload.constructor=CGActionDoDownload;CommandFactory.add(CGActionDoDownload,{format:0},false);CGActionDoDownload.prototype.execute=function(){if(!this.format)return;var Dialog=new CGDialogDownload();State.Calculating.Result.label=escape(Dialog.getField("label"));State.Calculating.Result.description=escape(Dialog.getField("description"));State.Calculating.Result.location="";Kernel.downloadDueResult(this,State.Calculating.Result.serialize(),this.format)}
function CGActionShowLink(){}
CGActionShowLink.prototype=new CGAction;CGActionShowLink.constructor=CGActionShowLink;CommandFactory.add(CGActionShowLink,null,true);CGActionShowLink.prototype.execute=function(){State.LinkCalendar.sMode="link";State.LinkCalendar.sType="100x040";State.LinkCalendar.sTheme="001";Desktop.createDialog(CGDialogLinkCalendar)}
function CGActionSetLinkTheme(){}
CGActionSetLinkTheme.prototype=new CGAction;CGActionSetLinkTheme.constructor=CGActionSetLinkTheme;CommandFactory.add(CGActionSetLinkTheme,{theme:0},false);CGActionSetLinkTheme.prototype.execute=function(){State.LinkCalendar.sTheme=this.theme;Desktop.createDialog(CGDialogLinkCalendar)}
function CGActionSetLinkMode(){}
CGActionSetLinkMode.prototype=new CGAction;CGActionSetLinkMode.constructor=CGActionSetLinkMode;CommandFactory.add(CGActionSetLinkMode,{mode:0},false);CGActionSetLinkMode.prototype.execute=function(){State.LinkCalendar.sMode=this.mode;Desktop.createDialog(CGDialogLinkCalendar)}
function CGActionSetLinkType(){}
CGActionSetLinkType.prototype=new CGAction;CGActionSetLinkType.constructor=CGActionSetLinkType;CommandFactory.add(CGActionSetLinkType,{type:0},false);CGActionSetLinkType.prototype.execute=function(){State.LinkCalendar.sType=this.type;Desktop.createDialog(CGDialogLinkCalendar)}
function CGActionShowRegister(){}
CGActionShowRegister.prototype=new CGAction;CGActionShowRegister.constructor=CGActionShowRegister;CommandFactory.add(CGActionShowRegister,null,true);CGActionShowRegister.prototype.execute=function(){Desktop.createDialog(CGDialogRegister)}
function CGActionShowLogin(){}
CGActionShowLogin.prototype=new CGAction;CGActionShowLogin.constructor=CGActionShowLogin;CommandFactory.add(CGActionShowLogin,null,true);CGActionShowLogin.prototype.execute=function(){Desktop.createDialog(CGDialogLogin)}
function CGActionShowRememberPassword(){}
CGActionShowRememberPassword.prototype=new CGAction;CGActionShowRememberPassword.constructor=CGActionShowRememberPassword;CommandFactory.add(CGActionShowRememberPassword,null,true);CGActionShowRememberPassword.prototype.execute=function(){Desktop.createDialog(CGDialogRememberPassword)}
function CGActionShowChangePassword(){}
CGActionShowChangePassword.prototype=new CGAction;CGActionShowChangePassword.constructor=CGActionShowChangePassword;CommandFactory.add(CGActionShowChangePassword,null,true);CGActionShowChangePassword.prototype.execute=function(){Desktop.createDialog(CGDialogChangePassword)}
function CGActionDoRegister(){this.base=CGAction;this.base(3)}
CGActionDoRegister.prototype=new CGAction;CGActionDoRegister.constructor=CGActionDoRegister;CommandFactory.add(CGActionDoRegister,null,false);CGActionDoRegister.prototype.step_1=function(){var Dialog=new CGDialogRegister();this.Account=Dialog.read();this.Account.calendar=Calendar.serialize();if((this.Account.email=="")||(this.Account.name=="")||(this.Account.password=="")||(this.Account.captcha=="")){Dialog.showMessage(Lang.Error.EmptyFields,"error");return}
if(this.Account.password!=Dialog.getField("repassword")){Dialog.showMessage(Lang.Error.PasswordsMismatch,"error");return}
if(validateMail(this.Account.email)==false){Dialog.showMessage(Lang.Error.InvalidEmail,"error");return}
Kernel.register(this,this.Account.serialize())}
CGActionDoRegister.prototype.step_2=function(){var Dialog=new CGDialogRegister();Dialog.showResult();Kernel.login(this,this.Account.email,this.Account.password)}
CGActionDoRegister.prototype.step_3=function(){Account.unserialize(this.data);Desktop.refresh();this.terminate()}
CGActionDoRegister.prototype.onFailure=function(sResponse){var Dialog=new CGDialogRegister();if(sResponse=="")InternalException()
else if(isError(sResponse,SERVER_ERROR_CAPTCHA))Dialog.showMessage(Lang.Error.Captcha,"error");else if(isError(sResponse,SERVER_ERROR_ACCOUNT_EXISTS))Dialog.showMessage(Lang.Error.AccountExists,"error");Dialog.refreshCaptcha();this.terminate()}
function CGActionDoLogin(){this.base=CGAction;this.base(3)}
CGActionDoLogin.prototype=new CGAction;CGActionDoLogin.constructor=CGActionDoLogin;CommandFactory.add(CGActionDoLogin,null,false);CGActionDoLogin.prototype.step_1=function(){var Dialog=new CGDialogLogin();this.Login=Dialog.read();if((this.Login.email=="")||(this.Login.password=="")){Dialog.showMessage(Lang.Error.EmptyFields,"error");return}
if(validateMail(this.Login.email)==false){Dialog.showMessage(Lang.Error.InvalidEmail,"error");return}
Kernel.login(this,this.Login.email,this.Login.password,this.Login.captcha);Desktop.showMessage(Lang.Message.Entering)}
CGActionDoLogin.prototype.step_2=function(){Account.unserialize(this.data);Calendar.unserialize(Account.sCalendar);CookieManager.set("code",Account.code);CookieManager.set(Configuration.CookieCalendar,Account.sCalendar);Kernel.loadPlaces(this)}
CGActionDoLogin.prototype.step_3=function(){Application.iLoginCount=0;CookieManager.set("logcount",0);Desktop.refresh();CommandDispatcher.dispatch("showhome()");this.terminate()}
CGActionDoLogin.prototype.onFailure=function(sResponse){var Dialog=new CGDialogLogin();if(Application.iLoginCount==null)Application.iLoginCount=0;Application.iLoginCount++;CookieManager.set("logcount",Application.iLoginCount);if(sResponse=="")InternalException()
else if(isError(sResponse,SERVER_ERROR_LOGIN))Dialog.showMessage(Lang.Error.Login,"error");else if(isError(sResponse,SERVER_ERROR_CAPTCHA))Dialog.showMessage(Lang.Error.Captcha,"error");Dialog.refreshCaptcha();this.terminate()}
function CGActionDoLogout(){this.base=CGAction;this.base(2)}
CGActionDoLogout.prototype=new CGAction;CGActionDoLogout.constructor=CGActionDoLogout;CommandFactory.add(CGActionDoLogout,null,false);CGActionDoLogout.prototype.step_1=function(){Account.clear();CookieManager.remove("code");Kernel.logout(this);Desktop.showMessage(Lang.Message.Exiting)}
CGActionDoLogout.prototype.step_2=function(){Desktop.refresh();CommandDispatcher.dispatch("showhome()");this.terminate()}
function CGActionDoChangePassword(){this.base=CGAction;this.base(2)}
CGActionDoChangePassword.prototype=new CGAction;CGActionDoChangePassword.constructor=CGActionDoChangePassword;CommandFactory.add(CGActionDoChangePassword,null,false);CGActionDoChangePassword.prototype.step_1=function(){var Dialog=new CGDialogChangePassword();var sOldPassword=Dialog.getField("oldpassword");var sNewPassword=Dialog.getField("newpassword");var sChkPassword=Dialog.getField("chkpassword");if(sOldPassword==""){Dialog.showMessage(Lang.Error.OldPasswordEmpty,"error");return}
if(sNewPassword==""){Dialog.showMessage(Lang.Error.PasswordEmpty,"error");return}
if(sNewPassword!=sChkPassword){Dialog.showMessage(Lang.Error.PasswordsMismatch,"error");return}
Kernel.changePassword(this,sOldPassword,sNewPassword);Desktop.showMessage(Lang.Message.Wait)}
CGActionDoChangePassword.prototype.step_2=function(){var Dialog=new CGDialogChangePassword();Dialog.showResult();this.terminate()}
CGActionDoChangePassword.prototype.onFailure=function(sResponse){var Dialog=new CGDialogChangePassword();if(sResponse=="")InternalException()
else Dialog.showMessage(Lang.Error.ChangePassword,"error");this.terminate()}
function CGActionDoRememberPassword(){this.base=CGAction;this.base(2)}
CGActionDoRememberPassword.prototype=new CGAction;CGActionDoRememberPassword.constructor=CGActionDoRememberPassword;CommandFactory.add(CGActionDoRememberPassword,{display:0},false);CGActionDoRememberPassword.prototype.step_1=function(){var Dialog=new CGDialogRememberPassword();var sEmail=Dialog.getField("email");var sCaptcha=Dialog.getField("captchacode");if((sEmail=="")||(sCaptcha=="")){Dialog.showMessage(Lang.Error.EmptyFields,"error");return}
if(validateMail(sEmail)==false){Dialog.showMessage(Lang.Error.InvalidEmail,"error");return}
Kernel.rememberPassword(this,sEmail,sCaptcha)}
CGActionDoRememberPassword.prototype.step_2=function(){var Dialog=new CGDialogRememberPassword();Dialog.showResult();this.terminate()}
CGActionDoRememberPassword.prototype.onFailure=function(sResponse){var Dialog=new CGDialogRememberPassword();if(sResponse=="")InternalException()
else if(isError(sResponse,SERVER_ERROR_REMEMBER_PASSWORD))Dialog.showMessage(Lang.Error.RememberPassword,"error");else if(isError(sResponse,SERVER_ERROR_CAPTCHA))Dialog.showMessage(Lang.Error.Captcha,"error");Dialog.refreshCaptcha();this.terminate()}
function CGActionDoSaveAccount(){this.base=CGAction;this.base(2)}
CGActionDoSaveAccount.prototype=new CGAction;CGActionDoSaveAccount.constructor=CGActionDoSaveAccount;CommandFactory.add(CGActionDoSaveAccount,null,false);CGActionDoSaveAccount.prototype.step_1=function(){var Dialog=new CGDialogInfo();Desktop.showMessage(Lang.Message.Saving);this.Account=Dialog.read();this.Account.calendar=Calendar.serialize();Kernel.saveAccount(this,this.Account.serialize())}
CGActionDoSaveAccount.prototype.step_2=function(){this.terminate()}
var Application=new Object;var Configuration=new Object;Application.running=false;Application.init=function(){readData(Configuration,$("ApplicationConfiguration"));CookieManager.init(Configuration.Domain);CommandListener.start(CommandDispatcher);CommandListener.capture(document.body);Action=new CGActionInit();Action.execute();Application.iLoginCount=CookieManager.get("logcount");Application.running=true}
window.onload=function(){Application.init()}
