var MsG={dateFormat:"",message:[],set:function(a,b){this.message[a]=b},get:function(a){return this.message[a]},setDateFormat:function(a){this.dateFormat=a},getDateFormat:function(){return this.dateFormat}},PopUp=Class.create();
PopUp.prototype={message:null,content:null,hasOverlay:true,timeOut:null,closeFC:null,initialize:function(a,b){this.message=a;this.setContent(b)},setMessages:function(a){this.message=a},open:function(){this.removeNode();var a=$$("body")[0];if(this.hasOverlay){a.appendChild(Builder.node("div",{id:"ppoverlay"}));$("ppoverlay").setStyle({display:"none"})}var b=this.message.mainText!=null?new Array(Builder.node("p",this.message.mainText),this.content):this.content;a.appendChild(Builder.node("div",{id:"popup"},
[Builder.node("h3",this.message.title),Builder.node("div",b),Builder.node("div",{id:"close"},[Builder.node("a",{id:"popupclose",href:"#",title:this.message.closeTitle},this.message.closeTitle)])]));this.message.popClass&&$("popup").addClassName(this.message.popClass);$("popup").setStyle({display:"none"});$$("select","object","embed").each(function(c){c.style.visibility="hidden"});a=this.getPageSize();if(this.hasOverlay){$("ppoverlay").setStyle({width:a[0]+"px",height:a[1]+"px"});new Effect.Appear("ppoverlay",
{duration:0.2,from:0,to:0.3,queue:"end"})}a=this.getPosition(a);$("popup").setStyle({top:a[1]+"px",left:a[0]+"px"});new Effect.Appear("popup",{duration:0.05,queue:"end"});$("popupclose").observe("click",function(c){c.stop();this.close()}.bind(this));setTimeout(this.center.bind(this),100)},getPosition:function(a){var b=document.viewport.getScrollOffsets();return[parseInt(b[0]+a[0]/2-$("popup").getWidth()/2),parseInt(b[1]+document.viewport.getHeight()/10)]},setContent:function(a){this.content=Builder.node("div",
[a])},setContentText:function(a){this.content=Builder.node("div",a)},close:function(){$$("select","object","embed").each(function(a){a.style.visibility="visible"});this.removeNode();this.closeFC!=null&&this.closeFC()},removeNode:function(){var a=$("popup"),b=$("ppoverlay");if(a!=null){a.timeOut!=null&&clearTimeout(a.timeOut);a.parentNode.removeChild(a)}b!=null&&this.hasOverlay&&b.parentNode.removeChild(b)},center:function(){var a=this.getPageSize(),b=document.viewport.getScrollOffsets();new Effect.Move($("popup"),
{x:parseInt(b[0]+a[0]/2-$("popup").getWidth()/2),y:b[1]+document.viewport.getHeight()/10,mode:"absolute",queue:"end",duration:0.2})},getPageSize:function(){var a,b;if(window.innerHeight&&window.scrollMaxY){a=window.innerWidth+window.scrollMaxX;b=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){a=document.body.scrollWidth;b=document.body.scrollHeight}else{a=document.body.offsetWidth;b=document.body.offsetHeight}var c,e;if(self.innerHeight){c=document.documentElement.clientWidth?
document.documentElement.clientWidth:self.innerWidth;e=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){c=document.documentElement.clientWidth;e=document.documentElement.clientHeight}else if(document.body){c=document.body.clientWidth;e=document.body.clientHeight}pageHeight=b<e?e:b;pageWidth=a<c?a:c;return[pageWidth,pageHeight]},setOnClose:function(a){this.closeFC=a}};var ErrorPopUp=function(a,b){this.message=a;this.setContent(b);this.open()};
ErrorPopUp.prototype=new PopUp;ErrorPopUp.prototype.constructor=ErrorPopUp;ErrorPopUp.prototype.setContent=function(a){this.content=Builder.node("ul");this.content.className="errors";for(var b=0;b<a.length;b++){var c=Builder.node("li");c.className="error";a[b].item!=""&&c.appendChild(Builder.node("b",a[b].item));c.appendChild(Builder._text(" "+a[b].error));a[b].suffix!=null&&a[b].suffix!=""&&c.appendChild(Builder._text(" "+a[b].suffix));this.content.appendChild(c)}};
var InfoPopUp=function(a,b,c){this.message=a;this.itemID=c;this.setContent(b);this.open()};InfoPopUp.prototype=new PopUp;InfoPopUp.prototype.constructor=InfoPopUp;InfoPopUp.prototype.setContent=function(a){this.content=Builder.node("ul",{className:"info"});for(var b=0;b<a.length;b++){var c=Builder.node("b",a[b].item);this.content.appendChild(Builder.node("li",c))}};var NoticePopUp=function(a,b){this.hasOverlay=false;this.message=a;this.setContent(b);this.open()};NoticePopUp.prototype=new PopUp;
NoticePopUp.prototype.constructor=NoticePopUp;NoticePopUp.prototype.getPosition=function(a){var b=document.viewport.getScrollOffsets();return[parseInt(b[0]+a[0]/2-$("popup").getWidth()/2),b[1]+a[1]/2-$("popup").getHeight()]};NoticePopUp.prototype.setContent=function(a){this.content=Builder.node("ul",{className:"notice"});for(var b=0;b<a.length;b++)this.content.appendChild(Builder.node("li",a[b]))};
NoticePopUp.prototype.open=function(){PopUp.prototype.open.call(this);var a=this;$("popup").timeOut=self.setTimeout(function(){new Effect.Fade("popup",{afterFinish:function(){PopUp.prototype.close.call(a)}})},3E3)};AjaxInfoPopUp=function(a,b){var c=this;c.message=a;new Ajax.Request(b,{onSuccess:function(e){if(e.responseText!=""){var g=Builder.node("div");g.innerHTML=e.responseText;c.setContent(g);c.open()}}})};AjaxInfoPopUp.prototype=new PopUp;AjaxInfoPopUp.prototype.constructor=AjaxInfoPopUp;
TimeCounter={time:1200,limit:180,msg:null,el:null,init:function(a,b,c,e,g){this.el=$(g);this.msg=b;this.mainMsg=a;this.limit=e;this.time=c;this.interval=1;this.timer=window.setInterval("TimeCounter.change()",parseInt(this.interval*1E3));this.placeTime()},change:function(){this.time-=this.interval;if(this.time==this.limit){var a=new PopUp(this.mainMsg,[Builder.node("p",this.msg.warning.replace(/%time%/,this.getStrTime()))]);a.open()}if(this.time<=0){clearTimeout(this.timer);a=new PopUp(this.mainMsg,
[Builder.node("p",this.msg.logout)]);a.open();a.setOnClose(function(){window.location.reload()})}this.placeTime()},placeTime:function(){if(this.el!=null)this.el.innerHTML=this.getStrTime()},getStrTime:function(){var a="";if(this.time>3600)a+=parseInt(this.time/3600)+"h ";a+=parseInt(this.time/60)+"m ";if(this.time%60!=0)a+=parseInt(this.time%60)+"s";return a}};function inArray(a,b){for(var c=0;c<=a.length;c++)if(a[c]==b)return true;return false}
Calendar={date:new Date,pDruh:["y","d","m"],encode:function(a){if(a==""||a==null)return null;for(var b="^",c=1,e={},g=0,h="",f=MsG.getDateFormat(),j=0;j<f.length;j++){if(j!=0&&h!=f.charAt(j)&&g!=0){b+="(\\d{"+g+(g==1&&(h=="d"||h=="m")?",2":"")+"})";e[h]=c++;h="";g=0}if(inArray(this.pDruh,f.charAt(j))){g++;h=f.charAt(j)}else b+=f.charAt(j)=="."?"\\.":f.charAt(j)}if(g!=0){b+="(\\d{"+g+(g==1&&(h=="d"||h=="m")?",2":"")+"})";e[h]=c++}a=a.match(new RegExp(b+"$"));if(a!=null){for(j in e)a[e[j]]=parseInt(a[e[j]].replace(/^[0]*/,
""));if(this.checkDate(a[e.y],a[e.m],a[e.d]))return[a[e.y],a[e.m]-1,a[e.d]]}return null},decode:function(){for(var a="",b=0,c="",e=MsG.getDateFormat(),g=0,h=0;h<e.length;h++){if(h!=0&&c!=e.charAt(h)&&b!=0){var f=1;switch(c){case "d":f=this.date.getDate();break;case "m":f=this.date.getMonth()+1;break;case "y":f=this.date.getFullYear();break}g=b-Math.floor(Math.log(parseInt(f))/Math.log(10))-1;for(b=0;b<g;b++)a+="0";a+=f;c="";b=0}if(inArray(this.pDruh,e.charAt(h))){b++;c=e.charAt(h)}else a+=e.charAt(h)}if(b!=
0){f=1;switch(c){case "d":f=this.date.getDate();break;case "m":f=this.date.getMonth()+1;break;case "y":f=this.date.getFullYear();break}g=b-Math.floor(Math.log(parseInt(f))/Math.log(10))-1;for(b=0;b<g;b++)a+="0";a+=f}return a},checkDate:function(a,b,c){var e=false;if(a>1980&&a<2100&&b>0&&b<=12){a=this.getNrDays(a,b);e=c>0&&c<=a}return e},setDate:function(a){if(a!=null)this.date.setFullYear(a[0],a[1],a[2]);else this.date=new Date},getDate:function(){return this.date},getNrDays:function(a,b){if(a==null)a=
this.date.getFullYear();if(b==null)b=this.date.getMonth()+1;switch(b){case 4:case 6:case 9:case 11:return 30;case 2:return a%4==0?29:28;default:return 31}},getDay:function(){var a=this.date.getDay();return a==0?6:a-1},compare:function(a){var b=[this.date.getFullYear(),this.date.getMonth(),this.date.getDate()];a=[a.getFullYear(),a.getMonth(),a.getDate()];for(var c=0;c<b.length;c++){if(b[c]<a[c])return-1;if(b[c]>a[c])return 1}return 0}};var FormValidation={rClass:"",vClassPrefix:"",errorsMsg:"",rc:null,setup:function(a,b,c){this.rClass=a;this.vClassPrefix=b;this.errorsMsg=c;this.rc=new RegExp(a,"g")},validate:function(a){a=$(a);if(a!=null){for(var b=[],c=[],e=[],g=[],h=[],f=new Array("input","textarea"),j=new String,l=0;l<f.length;l++)for(var k=a.getElementsByTagName(f[l]),d=0;d<k.length;d++){j=new RegExp(this.vClassPrefix+"_([a-z_]+)","g");if(k[d].className.match(j)!=null){b[b.length]=k[d];j=new String(k[d].className.match(j));
c[c.length]=j.substr(j.indexOf("_")+1);e[e.length]=k[d].className.match(this.rc)!=null}}k=a.getElementsByTagName("label");for(d=0;d<k.length;d++)for(l=0;l<b.length;l++)if(k[d].htmlFor==b[l].id){g[l]=k[d].innerHTML.replace(/:/g,"");h[l]=k[d]}f=[];k={};l={};for(d=0;d<b.length;d++)if(!b[d].disabled){j=b[d].value;if(c[d]=="empty"&&j=="")f[f.length]=this.makeError("empty",g[d],b[d],h[d]);else if(c[d]=="numeric"&&this.vNumeric(j,d,e[d]))f[f.length]=this.makeError("numeric",g[d],b[d],h[d]);else if(c[d]==
"integer"&&this.vInteger(j,d,e[d]))f[f.length]=this.makeError("integer",g[d],b[d],h[d]);else if(c[d]=="date"&&this.vDate(j,d,e[d]))f[f.length]=this.makeError("date",g[d],b[d],h[d]);else if(c[d]=="email"&&this.vEmail(j,d,e[d]))f[f.length]=this.makeError("email",g[d],b[d],h[d]);else if(c[d]=="empty_array"){if(k[b[d].name]==null){k[b[d].name]=[];k[b[d].name+"_label"]=[]}k[b[d].name].push(b[d]);k[b[d].name+"_label"].push(g[d])}else if(c[d]=="checked"){if(l[b[d].name]==null){l[b[d].name]=[];l[b[d].name+
"_label"]=[]}l[b[d].name].push(b[d]);l[b[d].name+"_label"].push(g[d])}}for(var m in k)if(m.indexOf("label")==-1){b=false;for(d=0;d<k[m].length;d++)if(k[m][d].checked){b=true;break}b||(f[f.length]=this.makeError("empty_array","",null,null,k[m+"_label"].toString(", ")))}for(m in l)if(m.indexOf("label")==-1){b=false;for(d=0;d<l[m].length;d++)if(l[m][d].checked){b=true;break}b||(f[f.length]=this.makeError("checked","",null,null,l[m+"_label"].toString(", ")))}if(f.length>0){k=a.getElementsByTagName("button");
for(d=0;d<k.length;d++)k[d].blur()}return f}},vNumeric:function(a,b,c){return c&&a==""||a!=""&&a.match(/^[\-]*\d+(\.\d+)*$/)==null},vInteger:function(a,b,c){return c&&a==""||a!=""&&a.match(/^[\-]*\d+$/)==null},vEmail:function(a,b,c){return(c||a!="")&&!a.match(/^[-_\.a-zA-Z0-9]+@[-a-zA-Z0-9.]+\.[a-zA-Z]{2,4}$/g)},vDate:function(a,b,c){return(c||a!="")&&Calendar.encode(a)==null},makeError:function(a,b,c,e,g){return{item:b,error:this.errorsMsg[a],elem:c,label:e,suffix:g}}},ValidateForm=Class.create();
ValidateForm.prototype={formClass:"validate",initialize:function(){var a=new RegExp(this.formClass,"g"),b=$$("body")[0].getElementsByTagName("form");for(i=0;i<b.length;i++)b[i].className.match(a)!=null&&Event.observe(b[i],"submit",function(c){this.validate(c)}.bind(this))},validate:function(a){var b=Event.element(a);$$("#"+b.id+" label").each(function(c){c.removeClassName("red")});b=FormValidation.validate(b.id);if(b.length>0){Array.from(b).each(function(c){c.label!=null&&$(c.label).addClassName("red")});
a.stop();new ErrorPopUp(FormValidation.errorsMsg,b);return false}return true}};

