DOM=function(){} DOM.c=function(controller,tagName,attributes,appendTo,contents){var E=document.createElement(tagName);try{if(attributes){for(var prop in attributes){E.setAttribute(prop,attributes[prop]);}}}catch(e){alert("failed to set attributes");} if(controller){try{E.Controller=controller;}catch(e){alert("failed to set controller");}} if(contents){switch(typeof contents){case"string":E.appendChild(document.createTextNode(contents));break;default:try{E.appendChild(contents);}catch(e){} break;}} if(E.tagName.toLowerCase()=="table"){TableClass(E);} if(E.tagName.toLowerCase()=="input"){InputClass(E);} if(E.tagName.toLowerCase()=="select"){SelectClass(E);} if(E.tagName.toLowerCase()=="form"){FormClass(E);} if(E.tagName.toLowerCase()=="textarea"){TextAreaClass(E);} if(appendTo){try{E.Parent=appendTo;appendTo.appendChild(E);}catch(e){console.dir(e);alert(e);}} return E;} DOM.get=function(identifier){return document.getElementById(identifier);} DOM.select=function(controller,id,name,className,appendTo,disabled,isMultiple,rows,data){var E=document.createElement("select");if((typeof name=="string")&&(name!=null)){E.name=name;} if((typeof id=="string")&&(id!=null)){E.id=id;} if(typeof className=="string"){E.className=className;} E.disabled=disabled;if(isMultiple==true){E.setAttribute("multiple","true");}else{E.removeAttribute("multiple");} try{E.setAttribute("size",rows);}catch(e){} try{E.Controller=controller;}catch(e){} try{E.Parent=appendTo;appendTo.appendChild(E);}catch(e){} E.options=[];E.AddItem=function(value,caption,selected){var o=new Option;o.value=value;o.text=caption;o.selected=selected;this.options[this.options.length]=o;} E.AddItemsFromJSONString=function(data){if(typeof data!="string"){return false;} var Data=JSON.parse(data);for(var i=0;i=0;i--){if(this.options[i].selected){this.RemoveItemAtIndex(i);}}} E.GetItemsAsJSONString=function(){var v="";for(var i=0;ib.text){return 1;}else if(b.text>a.text){return-1;}else{return 0;}});this.options.length=0;for(var i=0;ib.value){return 1;}else if(b.value>a.value){return-1;}else{return 0;}});this.options.length=0;for(var i=0;i=0;i--){if(A[i]==className){A.splice(i,1);}} E.className=A.join(" ");} DOM.width=function(E){try{return E.offsetWidth;}catch(e){return 0;}} DOM.height=function(E){try{return E.offsetHeight;}catch(e){return 0;}} DOM.remove=function(E){E.parentNode.removeChild(E);} DOM.removeAllChildren=function(E){while(E.firstChild){E.removeChild(E.firstChild);}} DOM.scrollTo=function(E){try{E.scrollIntoView({"behavior":"smooth"});}catch(e){alert(e);}} DOM.hide=function(E){DOM.addClass(E,"hide");} DOM.unhide=function(E){DOM.removeClass(E,"hide");} DOM.clicked=function(event,element){if(!event.type){return false;} if(event.type!="click"){return false;} if(!event.path){if(!event.target){return false;} var _target=event.target;while(_target!=element){if(_target==document){return false;} _target=_target.parentNode;} return true;} for(var item in event.path){if(event.path[item]==element){return true;}} return false;} DOM.mouseovered=function(event,element){if(!event.type){return false;} if(event.type!="mouseover"){return false;} if(!event.path){return false;} for(var item in event.path){if(event.path[item]==element){return true;}} return false;} DOM.clone=function(source,isDeep){return source.cloneNode(isDeep);} DOM.supportsWebP=function(){var E=document.createElement('canvas');if(!!(E.getContext&&E.getContext('2d'))){return E.toDataURL('image/webp').indexOf('data:image/webp')==0;} return false;} DOM.get=function(elementId){if(!DOM.exists(elementId)){return false;} return document.getElementById(elementId);} DOM.exists=function(elementId){return!!document.getElementById(elementId);} DOM.lazyLoadImages=function(tagName,classname,sourceAttr,targetAttr){var E=document.getElementsByTagName(tagName);for(var i=0;i0&&now-ref<=86400000){return"Yesterday";} if(ref-now>0&&ref-now<=86400000){return"Tomorrow";} return DateHelper.dayOfWeekAtIndex(ref.getDay());} DateHelper.toFormattedCaption=function(d,format){d=DateHelper.toDate(d);var min="0"+d.getMinutes().toString();var dat="0"+d.getDate().toString();var mon="0"+(d.getMonth()+1).toString();format=format.replace("YYYY",d.getFullYear().toString());format=format.replace("YY",d.getFullYear().toString().substring(2));format=format.replace("MM",mon.substring(mon.length-2));format=format.replace("MilH",d.getHours());format=format.replace("DD",dat.substring(dat.length-2));format=format.replace("dd",dat.replace("0",""));format=format.replace("NN",min.substring(min.length-2));format=format.replace("DayOfWeekRelative",DateHelper.toRelativeDayOfWeekCaption(d));format=format.replace("DayOfWeek",DateHelper.dayOfWeekAtIndex(d.getDay()));format=format.replace("MonthName",DateHelper.monthNameAtIndex(d.getMonth()));format=format.replace("MonName",DateHelper.monNameAtIndex(d.getMonth()));if(d.getHours("en-US",{"hours":"numeric"})>12){format=format.replace("HH",(d.getHours()-12).toString());format=format.replace("AM|PM","PM");}else if(d.getHours("en-US",{"hours":"numeric"})==12){format=format.replace("HH",d.getHours().toString());format=format.replace("AM|PM","PM");}else{format=format.replace("HH",d.getHours().toString());format=format.replace("AM|PM","AM");} return format;} DateHelper.toSequenceString=function(d){return DateHelper.toSequenceNum().toString();} DateHelper.toSequenceNum=function(d){d=DateHelper.toDate(d);return d.getTime();} DateHelper.dayOfWeekAtIndex=function(i){var a=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];return a[i];} DateHelper.monthNameAtIndex=function(i){var a=["January","February","March","April","May","June","July","August","September","October","November","December"];return a[i];} DateHelper.monNameAtIndex=function(i){var a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return a[i];} DateHelper.dayOfYear=function(d){return(Date.UTC(d.getFullYear(),d.getMonth(),d.getDate())-Date.UTC(d.getFullYear(),0,0))/ 24 / 60 / 60 / 1000;} FormHelper=function(){} FormHelper.DoErrors=function(A,M){for(var i=A.length-1;i>=0;i--){console.log("FormControl: "+A[i].RootElement.id);for(var j=M.length-1;j>=0;j--){if(A[i].RootElement.id==M[j].identifier){A[i].AddError(M[j].text);M.splice(j,1);}}} return;} FormHelper.PushData=function(A,M){for(var p in M){for(var i=0;i=10&&num<20){return n+"th";} switch(n.substring(n,n.length-1)){case"1":return n+"st";break;case"2":return n+"nd";break;case"3":return n+"rd";break;default:return n+"th";break;}} PageOverlay=function(){} PageOverlay.On=function(){DOM.addClass(DOM.get("page-inner"),"blur");DOM.addClass(DOM.get("pageoverlay"),"on");} PageOverlay.Off=function(){DOM.removeClass(DOM.get("page-inner"),"blur");DOM.removeClass(DOM.get("pageoverlay"),"on");} TimeframeHelper=function(){} TimeframeHelper.diff=function(d1,d2){return DateHelper.toDate(d1)-DateHelper.toDate(d2);} TimeframeHelper.minutesToTimeframe=function(m){return parseInt(m)*60000;} TimeframeHelper.days=function(tf){return parseInt(tf / 86400000);} TimeframeHelper.hours=function(tf){return parseInt(tf / 3600000);} TimeframeHelper.minutes=function(tf){return parseInt(tf / 60000);} TimeframeHelper.seconds=function(tf){return parseInt(tf / 1000);} TimeframeHelper.numToString=function(n,len){var nn="";for(var i=0;i0){for(var j=0;j1){if(!obj[xml.childNodes[i].nodeName]){obj[xml.childNodes[i].nodeName]=[];} obj[xml.childNodes[i].nodeName].push(XMLHelper.XMLtoJSON(xml.childNodes[i],O));}else{obj[xml.childNodes[i].nodeName]=XMLHelper.XMLtoJSON(xml.childNodes[i],O);}}}} return obj;} XMLHelper.StringToXML=function(str){if(window.ActiveXObject){var oXML=new ActiveXObject("Microsoft.XMLDOM");oXML.loadXML(str);return oXML;}else{return(new DOMParser()).parseFromString(str,"text/xml");}} XMLHelper.GetImmediateChildElementsByTagName=function(xml,tagName){var a=xml.getElementsByTagName(tagName);for(var i=a.length-1;i>=0;i--){if(a[i].parentNode!=xml){a[i].remove();}} return a;} YouTube=function(){} YouTube.GetPlayer=function(link_code){this.RootElement=DOM.c(this,"DIV",{"class":"video-container"});this.YouTube=DOM.c(this,"IFRAME",{"class":"live-stream-youtube","src":"https://www.youtube.com/embed/"+link_code+"?autoplay=1&modestbranding=1","width":560,"height":315,"frameborder":0,"allow":"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture","allowfullscreen":true,"modestbranding":"1"},this.RootElement);return this.RootElement;} InputClass=function(htmlInput){this.ObjectType="InputClass";this.Input=htmlInput;this.Input.SectionControl=null;if(!htmlInput.getAttribute("type")){htmlInput.setAttribute("type","text");} this.Input.GetValue=function(){if(this.disabled){return null;} if(this.getAttribute("nodataout")=="true"){return null;} switch(this.getAttribute("type")){case"text":case"button":case"submit":case"hidden":case"password":return(this.value)?this.value:"";break;case"radio":case"checkbox":return(this.checked)?this.getAttribute("value"):null;break;}} this.Input.SetValue=function(value){switch(this.getAttribute("type")){case"text":case"button":case"submit":case"hidden":case"password":this.value=(value)?value:"";break;case"radio":case"checkbox":break;}} this.Input.AddError=function(s){if(this.getAttribute("noerrors")=="true"){return true;} var o=this.FindSectionControl();try{return o.AddError(s);}catch(e){}} this.Input.ClearErrors=function(){if(this.getAttribute("noerrors")=="true"){return true;} var o=this.FindSectionControl();try{return o.ClearErrors();}catch(e){}} this.Input.FindSectionControl=function(){if(this.SectionControl){return this.SectionControl;} var p=this.parentElement;var sc=null;if(p==document){return null;} try{sc=p.Controller.ObjectType;}catch(e){} while(sc!="SectionControl"){p=p.parentElement;if(p==document){return null;} try{sc=p.Controller.ObjectType;}catch(e){}} this.SectionControl=p.Controller.RootElement;return this.SectionControl;}} TableClass=function(htmlTable){this.ObjectType="TableClass";this.Table=htmlTable;this.Table.NotShown=[];this.Table.IsAscending=true;this.RootElement=this.Table;DOM.addClass(this.RootElement,"table-control");this.Table.SELECTMODES={SINGLE:0,MULTIPLE:1};this.Table.SelectMode=this.Table.SELECTMODES.SINGLE;this.Table.STATES={READY:0,WORKING:1};this.Table.THead=DOM.c(this,"thead",null,this.Table);this.Table.TBody=DOM.c(this,"tbody",null,this.Table);this.Table.TNone=DOM.c(this,"tbody",{"class":"grid-body-none"});this.Table.TWorking=DOM.c(this,"tbody",{"class":"working"},null,DOM.c(null,"td"));this.Table.AppendRow=function(row){if(row.tagName!="TR"){alert("Element must be type \"TR\"");return false;} if(this.OnBeforeRowAdd()!=true){return false;} this.InitializeRow(row);this.TBody.appendChild(row);this.UpdateRowCounter(row,this.RowCount());this.OnAfterRowAdd();} this.Table.SelectRow=function(row){if(!DOM.hasClass(row,"selectable")){return false;} if(!row.IsSelected){if(this.SelectMode==this.SELECTMODES.SINGLE){if(this.DeselectAllRows()==false){return false;}} if(!row.OnBeforeSelect()){return false;} DOM.addClass(row,"selected");row.IsSelected=true;row.dispatchEvent(new CustomEvent("selected"));}} this.Table.DeselectRow=function(row){if(row.IsSelected){if(!row.OnBeforeDeselect()){return false;} DOM.removeClass(row,"selected");row.IsSelected=false;row.dispatchEvent(new CustomEvent("deselected"));}} this.Table.DeselectAllRows=function(){for(var i=0;i=this.RowCount()){this.AppendRow(row);return true;} if(this.OnBeforeRowAdd()!=true){return false;} this.TBody.insertBefore(row,this.RowAtIndex(index));this.InitializeRow(row);this.DoNoneRow();this.SortByColumn(this.SortedColumn,this.IsAscending);this.UpdateRowCounters();this.OnAfterRowAdd();} this.Table.OnBeforeRowAdd=function(){return true;} this.Table.OnAfterRowAdd=function(){} this.Table.OnAfterRowRemove=function(){} this.Table.RemoveAllRows=function(){while(this.TBody.childNodes.length>0){this.TBody.removeChild(this.TBody.childNodes[0]);}} this.Table.RemoveRowAtIndex=function(index){this.TBody.removeChild(this.RowAtIndex(index));this.DoNoneRow();this.UpdateRowCounters();} this.Table.RemoveRowsWithIdentifiers=function(str){var a=str.split(",");for(var i=0;i=0;i--){this.IncludeRowAtIndex(i);}} this.Table.ExcludeRow=function(row){this.NotShown.push(row);this.TBody.removeChild(row);this.DoNoneRow();} this.Table.IncludeRowAtIndex=function(index){var row=this.NotShown[index];this.TBody.appendChild(row);this.NotShown.splice(index,1);this.UpdateRowCounter(row,this.RowCount());this.DoNoneRow();} this.Table.ClickSort=function(index){if(this.SortedColumn==index){this.SortByColumn(index,!this.IsAscending);}else{this.SortByColumn(index,true);}} this.Table.SortByColumn=function(index,isAscending){if(index==null){return true;} var sortArray=new Array();DOM.addClass(this.THead.getElementsByTagName("th")[index],"working");for(var i=0;ib[0].toLowerCase())?i=1:(b[0].toLowerCase()>a[0].toLowerCase())?i=-1:i=0;return i;});}else{sortArray.sort(function grid_sort_descending(a,b){(a[0].toLowerCase()>b[0].toLowerCase())?i=-1:(b[0].toLowerCase()>a[0].toLowerCase())?i=1:i=0;return i;});} this.SortedColumn=index;this.IsAscending=isAscending;var addSortClass=(this.IsAscending)?"sorted-asc":"sorted-desc";var removeSortClass=(this.IsAscending)?"sorted-desc":"sorted-asc";for(var i=0;i0){s[j].removeChild(s[j].childNodes[0]);} s[j].appendChild(DOM.text(val+". "));}}} this.Table.SetState=function(state){switch(state){case this.STATES.WORKING:DOM.addClass(this,"working");break;default:DOM.removeClass(this,"working");break;}} this.Table.InitializeRow=function(row){row.Table=this;if(!row.OnRowClick){if(DOM.hasClass(row,"selectable")){row.OnRowClick=function(e){this.Table.SelectRow(this);} row.onclick=row.OnRowClick;}} if(!row.OnBeforeSelect){row.OnBeforeSelect=function(){return true;}} if(!row.OnBeforeDeselect){row.OnBeforeDeselect=function(){return true;}} if(!row.CellAtIndex){row.CellAtIndex=function(idx){return this.getElementsByTagName("td")[idx];}}}} SelectClass=function(htmlSelect){this.ObjectType="SelectClass";this.Select=htmlSelect;this.RootElement=this.Select;this.Select.SectionControl=null;this.Select.AddOption=function(opt){this.options[this.options.length]=opt;} this.Select.RemoveOption=function(opt){for(var i=0;i=0;i--){if(this.options[i].selected){this.RemoveItemAtIndex(i);}}} this.Select.GetItemsAsJSONString=function(){var v="";for(var i=0;ib.text){return 1;}else if(b.text>a.text){return-1;}else{return 0;}});this.options.length=0;for(var i=0;ib.value){return 1;}else if(b.value>a.value){return-1;}else{return 0;}});this.options.length=0;for(var i=0;i";s+=this.D[i];s+="";} break;default:s+="{";for(var i in this.D){if(!first){s+=",";} s+="\""+i+"\":\""+this.D[i]+"\"";first=false;} s+="}";break;} this.Data=s;return JSON.parse(s);} this.Form.DispatchEventAndExecute=function(e,func){this.dispatchEvent(e);if(!func){return true;} this.Scoped=func;return this.Scoped(e.detail);}} TextAreaClass=function(htmlTextArea){this.ObjectType="TextAreaClass";this.TextArea=htmlTextArea;this.RootElement=this.TextArea;this.TextArea.SectionControl=null;this.TextArea.GetValue=function(){if(this.disabled){return null;} if(this.getAttribute("nodataout")=="true"){return null;} return this.value;} this.TextArea.SetValue=function(value){if(this.disabled){return null;} if(this.getAttribute("nodatain")=="true"){return null;} this.value=value;} this.TextArea.AddError=function(s){if(this.getAttribute("noerrors")=="true"){return true;} var o=this.FindSectionControl();try{return o.AddError(s);}catch(e){}} this.TextArea.ClearErrors=function(){if(this.getAttribute("noerrors")=="true"){return true;} var o=this.FindSectionControl();try{return o.ClearErrors();}catch(e){}} this.TextArea.FindSectionControl=function(){if(this.SectionControl){return this.SectionControl;} var p=this.parentElement;var sc=null;if(p==document){return null;} try{sc=p.Controller.ObjectType;}catch(e){} while(sc!="SectionControl"){p=p.parentElement;if(p==document){return null;} try{sc=p.Controller.ObjectType;}catch(e){}} this.SectionControl=p.Controller.RootElement;return this.SectionControl;}}