// for compatible MochiKit 1.4.1
computedStyle = MochiKit.Style.getStyle

var UI={};
UI.version="0.5.3";
UI.Lang={};
UI.Lang.Language=function(_1,_2){
bindMethods(this);
this.code=_1;
this.messages=_2;
};
UI.Lang.Language.prototype={"translate":function(_3){
return this.messages[_3];
}};
UI.Lang.C=new UI.Lang.Language("C",{});
UI.Lang.es=new UI.Lang.Language("es",{"The value must be a number":"El valor debe ser num\xe9rico","The field is required":"Debe ingresar un valor en este campo","The field is not valid":"El valor ingresado no es v\xe1lido","The value must contain only letters":"El valor debe contener solo letras","The value must be a valid email address":"El valor debe contener una direcci\xf3n de correo v\xe1lida"});
UI.Lang.setLanguage=function(_4){
if(typeof (_4)!="undefined"&&typeof (UI.Lang[_4])!="undefined"){
UI.Lang.current=UI.Lang[_4];
}else{
// logWarning("UI.Lang has no translations for language "+_4);
UI.Lang.current=UI.Lang.C;
}
};
if(typeof (LANG)!="undefined"){
UI.Lang.setLanguage(LANG);
}else{
var _detectedLang=navigator.userLanguage||navigator.browserLanguage||navigator.language;
if(_detectedLang.length>=2){
UI.Lang.setLanguage(_detectedLang.substring(0,2));
}else{
logWarning("UI.Lang: Can't autodetect language. (Browser says: "+_detectedLang+")");
UI.Lang.setLanguage("C");
}
_detectedLang=null;
}
function _(_5){
return UI.Lang.current.translate(_5)||_5;
}
UI.Widget=function(_6){
bindMethods(this);
this.element=$(_6);
this.cssClass="uiwidget";
this.register();
};
UI.Widget.get=function(_7){
return $(_7)._widget;
};
var w$=UI.Widget.get;
UI.Widget.prototype={"register":function(){
if(this.element){
this.element._widget=this;
addElementClass(this.element,this.cssClass);
}
},"hide":function(){
hideElement(this.element);
},"show":function(_8){
showElement(this.element,_8);
},"toDOM":function(_9){
return this.element;
},"__dom__":function(_10){
return this.element;
}};
UI.TableModel=function(){
bindMethods(this);
};
UI.TableModel.prototype={"getNumCols":function(){
return 0;
},"getNumRows":function(){
return 0;
},"getCell":function(_11,_12){
return null;
},"getHeader":function(_13){
return null;
},"getFooter":function(_14){
return null;
},"getColType":function(_15){
return null;
},"hasHeader":function(){
return false;
},"hasFooter":function(){
return false;
},"getRow":function(_16){
return map(partial(this.getCell,_16),range(0,this.getNumCols()));
},"getRows":function(){
return map(this.getRow,range(0,this.getNumRows()));
},"getHeaders":function(){
return map(this.getHeader,range(0,this.getNumCols()));
},"getFooters":function(){
return map(this.getFooter,range(0,this.getNumCols()));
},"getColTypes":function(){
return map(this.getColType,range(0,this.getNumCols()));
}};
UI.ArrayTableModel=function(_17,_18,_19,_20,_21){
bindMethods(this);
this.objects=_17||[];
this.fields=_18||this._autoDetectFields();
this.headers=_20||this._autoDetectHeaders();
this.types=_19;
this.footers=_21;
};
UI.ArrayTableModel.prototype=update(new UI.TableModel(),{"getNumCols":function(){
return this.fields?this.fields.length:0;
},"getNumRows":function(){
return this.objects?this.objects.length:0;
},"getCell":function(_22,_23){
var val;
try{
val=this.objects[_22][this.fields[_23]];
if(val==null||typeof (val)=="undefined"){
val="";
}
}
catch(e){
val="";
}
return val;
},"getHeader":function(_25){
try{
return this.headers[_25];
}
catch(e){
return "";
}
},"getFooter":function(_26){
try{
return this.footers[_26];
}
catch(e){
return "";
}
},"getColType":function(_27){
try{
return this.types[_27];
}
catch(e){
return "string";
}
},"_autoDetectFields":function(){
if(this.objects&&this.objects.length>=1){
var _28=[];
for(field in this.objects[0]){
_28.push(field);
}
return _28;
}else{
return [];
}
},"_autoDetectHeaders":function(){
var _29=[];
for(var i=0;i<this.getNumCols();i++){
_29.push(this.fields[i]);
}
return _29;
},"hasHeader":function(){
return !(!this.headers);
},"hasFooter":function(){
return !(!this.footers);
},"changed":function(){
signal(this,"changed");
}});
UI.AsyncArrayTableModel=function(_31,_32,_33,_34){
bindMethods(this);
this.objects=[];
this.fields=_31;
this.headers=_33;
this.types=_32;
this.footers=_34;
};
UI.AsyncArrayTableModel.prototype=update(new UI.ArrayTableModel(),{"retrieveData":function(url,_36){
var _36=_36||"GET";
var d=loadJSONDoc(url);
d.addCallback(this._receiveData);
return d;
},"_receiveData":function(_38){
this.objects=_38;
if(!this.fields){
this._autoDetectFields();
}
if(!this.headers){
this._autoDetectHeaders();
}
this.changed();
}});
UI.HTMLTableModel=function(_39,_40){
bindMethods(this);
this._htmlTable=_39;
this._colTypes=_40;
};
UI.HTMLTableModel.prototype=update(new UI.TableModel(),{"getNumCols":function(){
try{
return this._htmlTable.tBodies[0].rows[0].cells.length;
}
catch(e){
return 0;
}
},"getNumRows":function(){
try{
return this._htmlTable.tBodies[0].rows.length;
}
catch(e){
return 0;
}
},"getCell":function(_41,_42){
try{
return this._htmlTable.tBodies[0].rows[_41].cells[_42].childNodes;
}
catch(e){
return "";
}
},"getHeader":function(_43){
try{
return this._htmlTable.tHead.rows[0].cells[_43].childNodes;
}
catch(e){
return "";
}
},"getFooter":function(_44){
try{
return this._htmlTable.tFoot.rows[0].cells[_44].childNodes;
}
catch(e){
return "";
}
},"getColType":function(_45){
try{
if(this._colTypes){
return this._colTypes[_45];
}else{
return "string";
}
}
catch(e){
return "string";
}
},"hasHeader":function(){
return !(!this._htmlTable.tHead);
},"hasFooter":function(){
return !(!this._htmlTable.tFoot);
}});
UI.ListModel=function(){
bindMethods(this);
};
UI.ListModel.prototype={"getLabel":function(_46){
return "";
},"getValue":function(_47){
return "";
},"getLength":function(){
return 0;
}};
UI.ArrayListModel=function(_48,_49,_50){
bindMethods(this);
this.objects=_48;
this.labelField=_49;
this.valueField=_50;
};
UI.ArrayListModel.prototype=update(new UI.ListModel(),{"getLabel":function(_51){
return this.labelField?this.objects[_51][this.labelField]:""+this.objects[_51];
},"getValue":function(_52){
return this.valueField?this.objects[_52][this.valueField]:this.getLabel(_52);
},"getLength":function(){
return this.objects.length;
},"changed":function(){
signal(this,"changed");
}});
UI.AsyncArrayListModel=function(_53,_54){
bindMethods(this);
this.objects=[];
this.labelField=_53;
this.valueField=_54;
};
UI.AsyncArrayListModel.prototype=update(new UI.ArrayListModel(),{"retrieveData":function(url,_55){
var _55=_55||"GET";
var d=loadJSONDoc(url);
d.addCallback(this._receiveData);
return d;
},"_receiveData":function(_56){
this.objects=_56;
this.changed();
return _56;
}});
UI.HTMLSelectListModel=function(_57){
this._options=_57.getElementsByTagName("option");
};
UI.HTMLSelectListModel.prototype=update(new UI.ListModel(),{"getLabel":function(_58){
return scrapeText(this._options[_58]);
},"getValue":function(_59){
return this._options[_59].value;
},"getLength":function(){
try{
return this._options.length;
}
catch(e){
return 0;
}
}});
UI.Window=function(_60){
bindMethods(this);
if(_60){
this.element=$(_60);
}else{
this.element=DIV({style:{"height":"400px","width":"400px","left":"0px","top":"0px","position":"absolute"}});
}
this.titleBar=null;
this.content=null;
this.draggableTitle=null;
var _61=this.element.getElementsByTagName("h1");
var _62=null;
if(_61.length==0){
this.setTitleBar(UI.Window.standardTitleBar("Untitled Window"));
}else{
this.setTitleBar(_61[0]);
}
var _63=getElementsByTagAndClassName("div","uicontent",this.element);
if(_63.length==0){
var div=DIV({"class":"uicontent"});
var _65=filter(function(el){
return el.className!="uititlebar";
},this.element.childNodes);
map(partial(appendChildNodes,div),_65);
this.setContent(div);
}else{
this.setContent(_63[0]);
}
this.resize(elementDimensions(this.element));
this.visible=computedStyle(this.element,"display")!="none";
this.cssClass="uiwindow";
this.register();
this.NAME=this.element.id+" (UI.Window)";
};
UI.Window.prototype=update(new UI.Widget(),{"show":function(_67){
showElement(this.element);
signal(this,"shown");
if(_67){
this.moveTo(_67);
}
},"hide":function(){
hideElement(this.element);
signal(this,"hidden");
},"close":function(){
removeElement(this.element);
this.draggableTitle.disable();
this.draggableTitle=null;
signal(this,"closed");
},"moveTo":function(_68){
setElementPosition(this.element,_68);
signal(this,"moved",_68);
},"resize":function(_69){
setElementDimensions(this.element,_69);
},"_adjustSize":function(){
setElementDimensions(this.content,{"w":this.element.clientWidth-4,"h":this.element.clientHeight-elementDimensions(this.titleBar).h-4});
},"include":function(url){
var el=DIV();
this.setContent(el);
var d=doSimpleXMLHttpRequest(url);
d.addCallback(function(req){
removeElementClass(el,"uierror");
el.innerHTML=req.responseText;
return req;
});
d.addErrback(function(req){
addElementClass(el,"uierror");
if(req){
el.innerHTML=req.responseText;
}else{
el.innerHTML=_("Error loading")+" "+url;
}
});
return d;
},"setTitleBar":function(_71){
if(this.titleBar){
removeElement(this.titleBar);
this.draggableTitle.disable();
}
addElementClass(_71,"uititlebar");
if(this.element.firstChild){
this.element.insertBefore(_71,this.element.firstChild);
}else{
this.element.appendChild(_71);
}
this.titleBar=_71;
this.draggableTitle=new UI.Draggable(this.titleBar);
this.draggableTitle.elementToMove=this.element;
},"setContent":function(_72){
if(this.content){
removeElement(this.content);
}
addElementClass(_72,"uicontent");
this.content=_72;
appendChildNodes(this.element,this.content);
setElementDimensions(this.content,{"w":this.element.clientWidth-4,"h":this.element.clientHeight-elementDimensions(this.titleBar).h-4});
}});
UI.Window._fromElement=function(_73){
var win=new UI.Window(_73);
var _75=getNodeAttribute("ui:draggable")||"true";
if(_75=="false"){
win.draggableTitle.disable();
}
};
UI.Window.standardTitleBar=function(_76){
return H1({"class":"uititlebar"},_76);
};
UI.Draggable=function(_77,_78,_79,_80){
bindMethods(this);
if(_77){
this.element=$(_77);
}else{
this.element=DIV();
}
this.element=$(_77);
this.elementToMove=$(_77);
this.flags=arguments.length>=2?_78:UI.Draggable.DRAG_X|UI.Draggable.DRAG_Y;
this.leftLimits=_79;
this.topLimits=_80;
this._dragXStart=-1;
this._dragYStart=-1;
this._leftStart=-1;
this._topStart=-1;
this._installMouseDown();
this._disabled=false;
this.NAME=repr(_77)+" (Draggable)";
};
UI.Draggable.DRAG_X=1;
UI.Draggable.DRAG_Y=2;
UI.Draggable._oldonmousemove=document.onmousemove;
UI.Draggable._oldonmouseup=document.onmouseup;
UI.Draggable._draggable=null;
UI.Draggable.prototype={"startFromEvent":function(e){
var e=e||window.event;
var x=e.screenX;
var y=e.screenY;
this.start(x,y);
},"start":function(_84,_85){
if(this._disabled){
return;
}
if(UI.Draggable._draggable){
// logError("Can't drag "+repr(this.element)+" as "+repr(UI.Draggable._draggable.element)+" is being already dragged");
return;
}
UI.Draggable._draggable=this;
this.elementToMove.style.zIndex=1;
this._dragXStart=_84;
this._dragYStart=_85;
this._leftStart=parseInt(computedStyle(this.elementToMove,"left"),10);
this._topStart=parseInt(computedStyle(this.elementToMove,"top"),10);
if((isNaN(this._leftStart)||isNaN(this._topStart))){
logger.error("Can't start the drag for "+repr(this)+" "+"Either the left or the top of the dragged element is not a number "+"left: "+this._leftStart+" top: "+this._topStart);
return;
}
signal(this,"dragStarted");
},"move":function(_86,_87){
if(this._disabled){
return;
}
if((this.flags&UI.Draggable.DRAG_X)>0){
var _88=(this._leftStart+_86-this._dragXStart);
if(this.leftLimits){
if(_88<this.leftLimits[0]){
_88=this.leftLimits[0];
}
if(_88>this.leftLimits[1]){
_88=this.leftLimits[1];
}
}
if(!isNaN(_88)){
this.elementToMove.style.left=_88+"px";
}else{
logger.error("Draggable.move: newLeft isNaN");
}
}
if((this.flags&UI.Draggable.DRAG_Y)>0){
var _89=(this._topStart+_87-this._dragYStart);
if(this.topLimits){
if(_89<this.topLimits[0]){
_89=this.topLimits[0];
}
if(_89>this.topLimits[1]){
_89=this.topLimits[1];
}
}
if(!isNaN(_89)){
this.elementToMove.style.top=_89+"px";
}else{
logger.error("Draggable.move: newTop isNaN");
}
}
signal(this,"dragging");
},"stop":function(){
var e=e||window.event;
UI.Draggable._draggable=null;
signal(this,"dragFinished");
},"_installMouseDown":function(){
var _90=this.element.onmousedown;
var _91=this;
this.element.onmousedown=function(e){
var e=e||window.event;
_91.startFromEvent(e);
if(_90){
_90.apply(this.element,arguments);
}
};
},"enable":function(){
this._disabled=false;
},"disable":function(){
this._disabled=true;
}};
document.onmousemove=function(e){
var e=e||window.event;
var x=e.screenX;
var y=e.screenY;
if(UI.Draggable._draggable){
UI.Draggable._draggable.move(x,y);
}
if(UI.Draggable._oldonmousemove){
_oldmousemove.apply(document,arguments);
}
};
document.onmouseup=function(e){
if(UI.Draggable._draggable){
UI.Draggable._draggable.stop(e);
}
if(UI.Draggable._oldonmouseup){
_oldonmouseup.apply(document,arguments);
}
};
UI.Table=function(_92,_93){
bindMethods(this);
if(_92){
this.element=$(_92);
}else{
this.element=DIV();
}
this.selectedRow=-1;
this._modelRowIndexes=[];
this._bodyRowIndexes=[];
this._selectedTR=null;
this._highlightedTR=null;
this._sortCol=-1;
this._arrow=SPAN(null);
this._model=null;
this.cssClass="uitable";
this.register();
if(_93){
this.setModel(_93);
}
this.NAME=this.element.id+"(UI.Table)";
};
UI.Table._NO_ARROW="&nbsp;&nbsp;&nbsp;";
UI.Table._DOWN_ARROW="&nbsp;&nbsp;&darr;";
UI.Table._UP_ARROW="&nbsp;&nbsp;&uarr;";
UI.Table.prototype=update(new UI.Widget(),{"setModel":function(_94){
this._model=_94;
connect(_94,"changed",this,"render");
this.render();
},"model":function(){
return this._model;
},"render":function(){
if(!this._model){
logError("Can't render a table without model");
return;
}
var _95=this.getTableElement();
if(_95){
swapDOM(_95,null);
}
var _96=[];
if(this._model.hasHeader()){
_96.push(THEAD(null,TR(null,map(this._makeTH,this._model.getHeaders(),range(0,this._model.getNumCols())))));
}
if(this._model.hasFooter()){
_96.push(TFOOT(null,TR(null,map(partial(TD,null),this._model.getFooters()))));
}
var _97=TABLE(null,_96,TBODY(null,map(this._makeTR,this._model.getRows(),range(0,this._model.getNumRows()))));
this.element.appendChild(_97);
this._initIndexesMaps();
},"_initIndexesMaps":function(){
this._bodyRowIndexes=[];
this._modelRowIndexes=[];
for(var i=0;i<this._model.getNumRows();i++){
this._bodyRowIndexes.push(i);
this._modelRowIndexes.push(i);
}
},"getTableElement":function(){
return this.element.getElementsByTagName("table")[0];
},"_makeTH":function(_98,_99){
var th=TH(null,_98);
addElementClass(th,"col_"+_99);
var _101=this;
th.onclick=function(e){
_101.clickHeader(_99,e||window.event);
};
return th;
},"_makeTR":function(row,_103){
var tr=TR(null,map(this._makeTD,row,this._model.getColTypes()));
addElementClass(tr,"row_"+_103);
addElementClass(tr,(_103%2)==0?"even":"odd");
var _105=this;
tr.onclick=function(e){
_105.clickRow(_105.modelRowIndex(tr.sectionRowIndex),e||window.event);
};
tr.onmouseover=function(e){
_105.mouseOverRow(_105.modelRowIndex(tr.sectionRowIndex),e||window.event);
};
tr.onmouseout=function(e){
_105.mouseOutRow(_105.modelRowIndex(tr.sectionRowIndex),e||window.event);
};
signal(this,"rowAdded",tr,_103);
return tr;
},"_makeTD":function(cell,type){
switch(type){
case "rawhtml":
var td=TD(null);
td.innerHTML=cell;
return td;
default:
return TD(null,cell);
}
},"clickRow":function(_109,_110){
this.selectRow(_109);
signal(this,"rowClicked",_109,_110);
},"clickHeader":function(_111,_112){
var _113=this.getTH(_111);
var _114=_113.getAttribute("_order")||"asc";
var _115=_114=="asc"?"desc":"asc";
_113.setAttribute("_order",_115);
this.sort(_111,_115=="desc");
if(_115=="asc"){
this._arrow.innerHTML=UI.Table._DOWN_ARROW;
}else{
this._arrow.innerHTML=UI.Table._UP_ARROW;
}
_113.appendChild(this._arrow);
signal(this,"headerClicked",_111,_112);
},"mouseOverRow":function(_116,_117){
this.highlightRow(_116);
signal(this,"rowMouseOver",_116,_117);
},"mouseOutRow":function(_118,_119){
this.highlightRow(-1);
signal(this,"rowMouseOut",_118,_119);
},"selectRow":function(_120){
if(this._selectedTR){
removeElementClass(this._selectedTR,"ui_active");
}
var _121=this.getTR(_120);
if(_121){
addElementClass(_121,"ui_active");
this._selectedTR=_121;
}else{
this._selectedTR=null;
}
this.selectedRow=_120;
signal(this,"rowSelected",_120);
},"highlightRow":function(_122){
if(this._highlightedTR){
removeElementClass(this._highlightedTR,"ui_hover");
}
var _123=this.getTR(_122);
if(_123){
addElementClass(_123,"ui_hover");
this._highlightedTR=_123;
}
},"modelRowIndex":function(_124){
return this._modelRowIndexes[_124];
},"bodyRowIndex":function(_125){
return this._bodyRowIndexes[_125];
},"getTR":function(_126){
var _127=this.bodyRowIndex(_126);
if(_127>=0){
return this.getTableElement().tBodies[0].rows[_127];
}else{
return null;
}
},"getTH":function(_128){
if(_128>=0){
return this.getTableElement().tHead.rows[0].cells[_128];
}else{
return null;
}
},"_sortDate":function(a,b){
aa=scrapeText(a.cells[this.sortCol]);
bb=scrapeText(b.cells[this.sortCol]);
if(aa.length==10){
dt1=aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
}else{
yr=aa.substr(6,2);
if(parseInt(yr)<50){
yr="20"+yr;
}else{
yr="19"+yr;
}
dt1=yr+aa.substr(3,2)+aa.substr(0,2);
}
if(bb.length==10){
dt2=bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
}else{
yr=bb.substr(6,2);
if(parseInt(yr)<50){
yr="20"+yr;
}else{
yr="19"+yr;
}
dt2=yr+bb.substr(3,2)+bb.substr(0,2);
}
if(dt1==dt2){
return 0;
}
if(dt1<dt2){
return -1;
}
return 1;
},"_sortCurrency":function(a,b){
aa=scrapeText(a.cells[this.sortCol]).replace(/[^0-9.]/g,"");
bb=scrapeText(b.cells[this.sortCol]).replace(/[^0-9.]/g,"");
return parseFloat(aa)-parseFloat(bb);
},"_sortNumeric":function(a,b){
aa=parseFloat(scrapeText(a.cells[this.sortCol]));
if(isNaN(aa)){
aa=0;
}
bb=parseFloat(scrapeText(b.cells[this.sortCol]));
if(isNaN(bb)){
bb=0;
}
return aa-bb;
},"_sortString":function(a,b){
var aa=scrapeText(a.cells[this.sortCol]).toLowerCase();
var bb=scrapeText(b.cells[this.sortCol]).toLowerCase();
if(aa==bb){
return 0;
}
if(aa<bb){
return -1;
}
return 1;
},"_sortStringCaseSensitive":function(a,b){
aa=scrapeText(a.cells[this.sortCol]);
bb=scrapeText(b.cells[this.sortCol]);
if(aa==bb){
return 0;
}
if(aa<bb){
return -1;
}
return 1;
},"sort":function(_133,_134){
_133=_133||0;
_134=_134||false;
this.sortCol=_133;
var _135=this._model.getColType(_133)||"string";
var _136="_sort"+_135.charAt(0).toUpperCase()+_135.substring(1);
if(!this[_136]){
logError("UI.Table.sort: Type "+_135+" unrecognized");
return;
}
var _137=this.getTableElement();
var _138=new Array();
for(var i=0;i<_137.tBodies[0].rows.length;i++){
_138[i]=_137.tBodies[0].rows[i];
_138[i]._modelIndex=this.modelRowIndex(i);
}
_138.sort(this[_136]);
for(var i=0;i<_138.length;i++){
if(!_134){
_137.tBodies[0].appendChild(_138[i]);
}else{
_137.tBodies[0].appendChild(_138[_138.length-1-i]);
}
this._modelRowIndexes[i]=_138[i]._modelIndex;
this._bodyRowIndexes[_138[i]._modelIndex]=i;
try{
delete _138[i]._modelIndex;
}
catch(e){
_138[i]._modelIndex=null;
}
}
}});
UI.Table._fromElement=function(_139){
var _140=new UI.Table(_139.id||_139.getAttribute("id"));
var _141=_139.getAttribute("ui:model");
if(!_141){
var _142=_139.getElementsByTagName("table");
if(_142&&_142.length>0){
_140.setModel(new UI.HTMLTableModel(_142[0]));
}
return;
}else{
_140.setModel(eval("("+_141+")"));
return;
}
};
UI.Slider=function(_143,_144,_145,_146){
bindMethods(this);
if(_143){
this.element=$(_143);
}else{
this.element=DIV({"style":{"width":"100px"}});
}
this.minValue=_144||0;
this.maxValue=_145||100;
this.value=_144;
this.linkedInput=null;
var _147=this.element.getElementsByTagName("div");
if(!_147||_147.length==0){
this.element.appendChild(DIV(null," "));
_147=this.element.getElementsByTagName("div");
}
var _148=_147[0];
this._draggableWidth=parseInt(computedStyle(_148,"width"),10);
this._maxLeft=parseInt(computedStyle(this.element,"width"),10)-this._draggableWidth;
this.draggable=new UI.Draggable(_148,UI.Draggable.DRAG_X,[0,this._maxLeft]);
connect(this.draggable,"dragging",this,"_updateValue");
this._connectWithClicks();
//this.cssClass="uislider";
this.register();
this._updateValue();
if(_146){
this.linkWithInput(_146);
_146.value=this.value;
}
this.NAME=this.element.id+"(UI.Slider)";
};
UI.Slider.prototype=update(new UI.Widget(),{"_updateValue":function(left, n){
var _150=this.value;
if(arguments.length==0){
left=parseInt(computedStyle(this.draggable.element,"left"),10);
}
this.value=Math.round((left/this._maxLeft)*(this.maxValue-this.minValue)+this.minValue);
if(this.value!=_150 && !n){
signal(this,"valueChanged",this.value);
if(this.linkedInput){
this.linkedInput.value=this.value;
}
}
},"_click":function(_151,_152){
var _153=elementPosition(this.element).x;
var _154=(_151-_153-this._draggableWidth/2);
this.setValue(parseFloat((_154/this._maxLeft)*(this.maxValue-this.minValue))+this.minValue);
},"setValue":function(_155, n){
var _156=this.value;
if(_155>this.maxValue){
_155=this.maxValue;
}
if(_155<this.minValue){
_155=this.minValue;
}
var left=Math.round(((_155-this.minValue)/(this.maxValue-this.minValue))*this._maxLeft);
this.draggable.element.style.left=left+"px";
this._updateValue(left, n);
},"_connectWithClicks":function(){
var _157=this;
connect(this.element,"onclick",function(e){
var _158=e.mouse();
_157._click(_158.page.x,_158.page.y);
});
connect(this.draggable.element,"onclick",function(e){
e.stop();
return false;
});
},"linkWithInput":function(_159){
this.linkedInput=_159;
this.linkedInput.value=this.value;
var _160=this;
connect(_159,"onchange",function(e){
var val=parseInt(_159.value,10);
if(!isNaN(val)){
_160.setValue(val);
}
});
}});
UI.Slider._fromElement=function(_161){
var _162=getNodeAttribute(_161,"ui:minvalue")||0;
var _163=getNodeAttribute(_161,"ui:maxvalue")||0;
var _164=getNodeAttribute(_161,"ui:input");
var _165=new UI.Slider(_161,parseInt(_162,10),parseInt(_163,10));
if(_164){
_165.linkWithInput($(_164));
}
};
UI.Form=function(_166,_167,_168){
bindMethods(this);
_166=_166||FORM();
this.element=$(_166);
this.items=_167||[];
this.validators=_168||[];
this.cssClass="uiform";
this._invalidInputs=[];
this.register();
this.NAME=this.element.id+"(UI.Form)";
var _169=_166.onsubmit;
var form=this;
_166.onsubmit=function(){
if(!form.validate()){
return false;
}
if(!_169){
return true;
}else{
return _169();
}
};
};
UI.Form.VALIDATION_PASSED="";
UI.Form.Messages={"REQUIRED":_("The field is required"),"NOT_VALID":_("The field value is not valid"),"NUMBER":_("The value must be a number"),"ALPHA":_("The value must contain only letters"),"ALPHANUM":_("The value must contain only letters and numbers"),"ALPHASPACES":_("The value must contain only letters and spaces"),"ALPHANUMSPACES":_("The value must contain only letters, numbers and spaces"),"EMAIL":_("The value must be a valid email address")};
UI.Form.prototype=update(new UI.Widget(),{"render":function(){
this.element.appendChild(TABLE(null,TBODY(null,map(function(i){
return i.render();
},this.items))));
},"validate":function(){
this._invalidInputs=[];
var _171=true;
for(var i=0;i<this.items.length;i++){
if(this.items[i].inputs){
for(var j=0;j<this.items[i].inputs.length;j++){
if(this.items[i].inputs[j]){
this.items[i].inputs[j].validate();
if(!this.items[i].inputs[j].valid){
this._invalidInputs.push(this.items[i].inputs[j].element);
_171=false;
}
}
}
}
}
for(var i=0;i<this.validators.length;i++){
var errs=this.validators[i](this.element);
var form=this;
if(errs&&errs.length){
_171=false;
forEach(errs,function(err){
var _175=err.fields;
var msg=err.message;
forEach(_175,function(_177){
form._invalidInputs.push(_177);
});
});
}
}
if(_171){
signal(this,"validationPassed");
}else{
signal(this,"validationFailed");
}
return _171;
},"submitAsync":function(url,_178,_179,_180){
if(!this.validate()){
return null;
}
signal(this,"submitted");
var _178=_178||[];
var _179=_179||[];
var _180=_180||"GET";
var url=url||this.element.action;
if(url){
var _181=formContents(this.element);
var _182=_181[0];
var _183=_181[1];
extend(_182,_178);
extend(_183,_179);
var d=doSimpleXMLHttpRequest(url,_182,_183);
signal(this,"sent",_182,_183);
return d;
}
return fail("UI.Form.submitAsync: No url given and url autodetection failed");
},"invalidInputs":function(){
return this._invalidInputs;
}});
UI.Form.Error=function(msg){
this.message=msg;
this.fields=extend([],arguments,1);
};
UI.FormItem=function(_184,_185,_186,flow){
bindMethods(this);
if(_184){
this.element=$(_184);
}else{
this.element=SPAN(null,_186);
}
this.label=_185||"";
this.inputs=_186||[];
this.flow=flow||"horizontal";
};
UI.FormItem.prototype={"render":function(){
var _188=filter(function(el){
return el.nodeType>0;
},this.element.childNodes);
if(_188&&_188.length){
var _189={"class":"noborderspace"};
if(this.flow=="horizontal"){
this.element.appendChild(TABLE(_189,TBODY(null,TR(_189,map(partial(TD,_189),_188)))));
}else{
this.element.appendChild(TABLE(_189,TBODY(null,map(function(el){
return TR(_189,TD(_189,el));
},_188))));
}
}
return TR(null,TD({"align":"right"},LABEL(null,this.label!=""?this.label+":":"")),TD(null,this.element));
}};
UI.FormInput=function(_190,_191){
bindMethods(this);
if(_190){
this.element=$(_190);
}else{
this.element=INPUT();
}
this.validators=_191;
this.cssClass="uiforminput";
this.valid=true;
this.tip=null;
this.register();
this._connectEvents();
};
UI.FormInput.prototype=update(new UI.Widget(),{"validate":function(){
var _192=this.element;
this.unmarkError();
this.valid=true;
if(!this.validators){
return;
}
for(var i=0;i<this.validators.length;i++){
var msg=this.validators[i](this.element);
if(msg&&(msg!=UI.Form.VALIDATION_PASSED)){
this.markError(msg);
return false;
}
}
return true;
},"markError":function(msg){
addElementClass(this.element,"uierror");
var _193=elementPosition(this.element);
var _194=elementDimensions(this.element);
if(typeof (_193.x)!="undefined"&&typeof (_194.w)!="undefined"){
this.tip=DIV({"class":"uitip"},DIV({"class":"uiarrow"}),DIV({"class":"uimsg"},msg));
this.tip.style.left=(_193.x+_194.w)+"px";
this.tip.style.top=(_193.y)+"px";
hideElement(this.tip);
document.getElementsByTagName("body")[0].appendChild(this.tip);
connect(this.element,"onmouseover",this,"showTip");
connect(this.element,"onmouseout",this,"hideTip");
}else{
logWarning("FormInput.markError: Can't get element position and/or dimensions");
}
this.valid=false;
},"showTip":function(){
showElement(this.tip);
},"hideTip":function(){
hideElement(this.tip);
},"unmarkError":function(){
removeElementClass(this.element,"uierror");
if(this.tip){
disconnect(this.element,"onmouseover",this,"showTip");
disconnect(this.element,"onmouseout",this,"hideTip");
removeElement(this.tip);
this.tip=null;
this.element.onmouseover=null;
this.element.onmouseout=null;
}
},"_connectEvents":function(){
if(!this.element){
return;
}
var _195=this.element.onblur;
var _196=this.element.onfocus;
var _197=this;
this.element.onblur=function(){
_197.validate();
if(_195){
_195.apply(this.element,arguments);
}
};
this.element.onfocus=function(){
_197.unmarkError();
if(_196){
_196.apply(this.element,arguments);
}
};
}});
UI.SelectFormInput=function(_198,_199,_200){
bindMethods(this);
this._model=null;
if(_198){
this.element=_198;
}else{
this.element=SELECT();
}
this.element=$(_198);
this.cssClass="uiselectforminput";
this.register();
this.setModel(_200);
};
UI.SelectFormInput.prototype=update(new UI.FormInput(),{"setModel":function(_201){
disconnect(this.model,"changed",this,"render");
this._model=_201;
this.render();
connect(_201,"changed",this,"render");
},"model":function(){
return this._model;
},"render":function(){
replaceChildNodes(this.element,[]);
for(var i=0;i<this._model.getLength();i++){
this.element.appendChild(OPTION({"value":this._model.getValue(i)},this._model.getLabel(i)));
}
}});
UI.Form.Validators={};
UI.Form.Validators.required=function(el){
return el.value.match(/^\s*$/)?UI.Form.Messages.REQUIRED:UI.Form.VALIDATION_PASSED;
};
UI.Form.Validators.regexp=function(re,msg){
return function(el){
return el.value.match(re)?UI.Form.VALIDATION_PASSED:msg||UI.Form.Messages.NOT_VALID;
};
};
UI.Form.Validators.numeric=function(el){
var val=el.value.replace(/,/,"").replace(/\./,"");
return (isNaN(val))?UI.Form.Messages.NUMBER:UI.Form.VALIDATION_PASSED;
};
UI.Form.Validators.alpha=UI.Form.Validators.regexp(/^[A-Za-záéíóúñ]*$/,UI.Form.Messages.ALPHA);
UI.Form.Validators.alphaspaces=UI.Form.Validators.regexp(/^[A-Za-záéíóúñ\s]*$/,UI.Form.Messages.ALPHASPACES);
UI.Form.Validators.alphanum=UI.Form.Validators.regexp(/^[0-9A-Za-áéíóúñ]*$/,UI.Form.Messages.ALPHANUM);
UI.Form.Validators.alphanumspaces=UI.Form.Validators.regexp(/^[0-9A-Za-záéíóúñ\s]*$/,UI.Form.Messages.ALPHANUMSPACES);
UI.Form.Validators.email=UI.Form.Validators.regexp(/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[A-Za-z]{2,4}$/,UI.Form.Messages.EMAIL);
UI.FormInput._getValidators=function(el){
var _203=el.getAttribute("ui:validators");
if(_203){
with(UI.Form.Validators){
_203=eval("("+_203+")");
}
}else{
_203=[];
}
return _203;
};
UI.FormInput._fromElement=function(el){
return new UI.FormInput(el,UI.FormInput._getValidators(el));
};
UI.SelectFormInput._fromElement=function(el){
var _204=el.getAttribute("ui:model");
if(_204){
_204=eval("("+_204+")");
return new UI.SelectFormInput(el,UI.FormInput._getValidators(el),_204);
}else{
_204=new UI.HTMLSelectListModel(el.cloneNode(true));
var _205=new UI.SelectFormInput(el,UI.FormInput._getValidators(el),_204);
_205.render();
return _205;
}
};
UI.FormItem._fromElement=function(el){
var _206=getNodeAttribute(el,"ui:label");
var _207=[];
if(el.tagName.toLowerCase()=="input"){
_207.push(UI.FormInput._fromElement(el));
}else{
if(el.tagName.toLowerCase()=="select"){
_207.push(UI.SelectFormInput._fromElement(el));
}else{
if(el.tagName.toLowerCase()=="textarea"){
_207.push(UI.FormInput._fromElement(el));
}
}
}
var _208=el.getElementsByTagName("input");
if(_208&&_208.length){
_207=_207.concat(map(UI.FormInput._fromElement,_208));
}
var _209=el.getElementsByTagName("textarea");
if(_209&&_209.length){
_207=_207.concat(map(UI.FormInput._fromElement,_209));
}
var _210=el.getElementsByTagName("select");
if(_210&&_210.length){
_207=_207.concat(map(function(_211){
s=UI.SelectFormInput._fromElement(_211);
},_210));
}
return new UI.FormItem(el,_206,_207);
};
UI.Form._fromElement=function(el){
var _212=getNodeAttribute(el,"ui:keeplayout");
_212=(_212&&(_212=="true"));
var _213=getNodeAttribute(el,"ui:validators");
if(_213){
with(UI.Form.Validators){
_213=eval("("+_213+")");
}
}else{
_213=[];
}
var _214=filter(function(el){
return el.nodeType==1;
},el.childNodes);
var form=new UI.Form(el,map(UI.FormItem._fromElement,_214),_213);
if(!_212){
form.render();
}
return form;
};
UI.Accordion=function(_215,_216){
bindMethods(this);
_215=_215||this._defaultElement();
if(_216==null||typeof (_216)=="undefined"){
_216=false;
}
if(_215){
this.element=$(_215);
}else{
this.element=this._defaultElement();
}
this.element=$(_215);
this.multipleExpansion=_216;
this.elements=filter(this._elementNode,iter(this.element.childNodes));
var _217=this._elementNode;
forEach(this.elements,function(el){
addElementClass(el,"uiaccordiontitle");
var _218=filter(_217,el.childNodes);
addElementClass(_218[0],"uiaccordiontitlebar");
_218.splice(0,1);
forEach(_218,function(_219){
addElementClass(_219,"uiaccordioncontent");
hideElement(_219);
});
});
this._installOnClicks();
this.activeElements=[];
this.cssClass="uiaccordion";
this.collapseAll();
this.register();
this.NAME=this.element.id+"(UI.Accordion)";
};
UI.Accordion.prototype=update(new UI.Widget(),{"setMultipleExpansion":function(_220){
this.multipleExpansion=_220;
if(!_220&&this.activeElements.length>1){
this.collapseAll();
}
},"expand":function(_221){
var _222=filter(this._elementNode,_221.childNodes);
addElementClass(_222[0],"uiexpanded");
_222.splice(0,1);
forEach(_222,showElement);
var _223=findIdentical(this.activeElements,_221);
if(_223==-1){
this.activeElements.push(_221);
}
if(!this.multipleExpansion&&this.activeElements.length>1){
this.collapse(this.activeElements[0]);
}
},"expandAll":function(){
if(!this.multipleExpansion){
logError("UI.Accordion.expandAll: Can't expand all elements if not in multipleExpansion mode");
return;
}
forEach(this.elements,this.expand);
},"collapse":function(_224){
var _225=filter(this._elementNode,_224.childNodes);
removeElementClass(_225[0],"uiexpanded");
_225.splice(0,1);
forEach(_225,hideElement);
var _226=findIdentical(this.activeElements,_224);
if(_226!=-1){
this.activeElements.splice(_226,1);
}else{
logWarning("UI.Accordion.collapse: collapsing a non-expanded element!?");
}
},"collapseAll":function(){
forEach(extend(null,this.activeElements),this.collapse);
},"_defaultElement":function(){
return DIV({"class":"uiaccordion"});
},"_installOnClicks":function(){
var _227=this;
forEach(this._titleBars(),function(_228){
connect(_228,"onclick",function(e){
var _229=findIdentical(_227.activeElements,_228.parentNode);
if(_229==-1){
_227.expand(_228.parentNode);
}else{
_227.collapse(_228.parentNode);
}
});
});
},"_elementNode":function(el){
return el.nodeType==1;
},"_firstChildElement":function(el){
return filter(this._elementNode,el.childNodes)[0];
},"_titleBars":function(){
return map(this._firstChildElement,this.elements);
}});
UI.Accordion._fromElement=function(el){
var _230=(getNodeAttribute(el,"ui:multiple")=="true");
new UI.Accordion(el,_230);
};
addLoadEvent(function(){
var _231=getElementsByTagAndClassName("div","uislider");
map(UI.Slider._fromElement,_231);
var _232=getElementsByTagAndClassName("div","uitable");
map(UI.Table._fromElement,_232);
var _233=getElementsByTagAndClassName("form","uiform");
map(UI.Form._fromElement,_233);
var _234=getElementsByTagAndClassName("div","uiwindow");
map(UI.Window._fromElement,_234);
var _235=getElementsByTagAndClassName("div","uiaccordion");
map(UI.Accordion._fromElement,_235);
});

