
var Utf8={encode:function(string){if(!string)return'';string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}
else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}
else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}
return utftext;},decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}
else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}
else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return string;}}

window.AjaxCallback=function(oParent,Callback){this.oParent=oParent;this.Callback=Callback;this.xmlhttp=false;if(navigator.userAgent.indexOf(" Firefox/")<0){try{this.xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e1){try{this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e2){this.xmlhttp=false;}}}
if(!this.xmlhttp&&typeof XMLHttpRequest!='undefined'){try{this.xmlhttp=new XMLHttpRequest();}catch(e){this.xmlhttp=false;}}}
AjaxCallback.prototype.Send=function(Page,Data){if(this.oParent.ZendProfile){Page+='?'+Data+'&start_debug=1&debug_port=10000&start_profile=1';Data='';}
var oCallback=this;this.xmlhttp.onreadystatechange=function(){if(oCallback.xmlhttp.readyState==4){if(oCallback.xmlhttp.status==200){oCallback.Complete();}else{oCallback.Error();}}}
this.xmlhttp.open("POST",Page);this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');this.xmlhttp.send(Data);}
AjaxCallback.prototype.Error=function(){alert("Error while processing callback");}
AjaxCallback.prototype.Complete=function(){eval('this.oParent.'+this.Callback+'(this.xmlhttp);');}

window.HtmlSpecialChars=function(Source){var Target=String(Source);Target=Target.replace(/&/g,'&amp;');Target=Target.replace(/</g,'&lt;');Target=Target.replace(/>/g,'&gt;');Target=Target.replace(/\"/g,'&quot;');Target=Target.replace(/\'/g,'&#039;');return Target;}
window.MarkupParagraphs=function(PlainTextString){if(!PlainTextString){return"";}
var MarkedUpString=PlainTextString.replace(/\n\n/g,"</p><p>");if(MarkedUpString!=PlainTextString){MarkedUpString="<p>"+MarkedUpString+"</p>";}
MarkedUpString=MarkedUpString.replace(/\n/g,"<br>\n");return MarkedUpString;}
window.VerticalText=function(Text,FontSize,FontFamily,Colour,Background){if(!FontSize){FontSize=14;}
if(!FontFamily){FontFamily='Helvetica';}
if(!Colour){Colour='#000000';}
if(!Background){Background='#FFFFFF';}
var SvgEnabled=true;if(getInternetExplorerVersion()!=-1&&getInternetExplorerVersion()<9){SvgEnabled=false;}
if(SvgEnabled){var Content=new String(HtmlSpecialChars(Text));var e=document.createElement('span');e.style.whiteSpace="nowrap";e.innerHTML=Content;e.style.fontSize=FontSize+"px";e.style.fontFamily=FontFamily;document.body.appendChild(e);var SvgHeight=e.offsetWidth;var SvgWidth=e.offsetHeight;document.body.removeChild(e);var aUrl=[];aUrl.push('FontFamily='+FontFamily);aUrl.push('Size='+FontSize);aUrl.push('Text='+Content);aUrl.push('Colour='+encodeURIComponent(Colour));aUrl.push('Background='+encodeURIComponent(Background));var aAttributes=[];aAttributes.push('data="/lib/utils/verticaltext.php?'+aUrl.join('&')+'"');aAttributes.push('width="'+SvgWidth+'"');aAttributes.push('height="'+SvgHeight+'"');aAttributes.push('type="image/svg+xml"');return['<object ',aAttributes.join(' '),'></object>'].join('');}else{return['<span class="verticaltext" style="font-family:',FontFamily,';color:',Colour,';font-size:',FontSize,'px;">',HtmlSpecialChars(Text),'</span>'].join('');}}

window.htmlspecialchars=function(Source){Target=new String(Source)
Target=Target.replace(/&/g,'&amp;');Target=Target.replace(/</g,'&lt;');Target=Target.replace(/>/g,'&gt;');Target=Target.replace(/\"/g,'&quot;');Target=Target.replace(/\'/g,'&#039;');return Target;}
if(typeof(CXDb)=='undefined')CXDb={};CXDb.CAttributes=function(){}
CXDb.CAttributes.prototype.ToHtml=function(){var aResults=[];for(var Key in this){if(typeof(this[Key])=="function")continue;aResults.push([Key,'="',this[Key],'"'].join(''));}
return aResults.join(' ');}
window.CField=function(Name,Value,EncodeValue){if(arguments.length<=0)return;if(arguments.length<3){this.Init(Name,Value,true);}else{this.Init(Name,Value,EncodeValue);}}
CField.prototype.Init=function(Name,Value,EncodeValue){this.Name=Name;this.Value=Value;if(typeof(EncodeValue)=='undefined')EncodeValue=true;this.EncodeValue=EncodeValue;}
CField.prototype.ToReadOnlyElement=function(){var e=document.createElement('span');e.className='inputgroup';e.innerHTML=this._ToInnerHtml();return e;}
CField.prototype._ToInnerHtml=function(){var aContent=new Array();aContent.push('<span class="inputlabel">'+htmlspecialchars(this.Name)+':</span>');aContent.push('<span class="inputcontrol">');if(this.EncodeValue){aContent.push(htmlspecialchars(this.Value));}else{aContent.push(this.Value);}
aContent.push('</span>');return aContent.join('');}
CField.prototype.ToHtml=function(Attributes){var aContents=[];aContents.push('<div class="inputgroup" ');if(Attributes){aContents.push(Attributes);}
aContents.push('>');aContents.push(this._ToInnerHtml());aContents.push('</div>');return aContents.join('');}
CField.prototype.ToInputControl=function(Attributes){if(!Attributes)Attributes='';var aContent=new Array();aContent.push('<input name="'+this.Name+'" '+Attributes+' value="');if(this.Value){if(this.EncodeValue){aContent.push(htmlspecialchars(this.Value));}else{aContent.push(this.Value);}}
aContent.push('">');return aContent.join('');}
CField.prototype.ToInput=function(DisplayName,Attributes){var Field=new CField(DisplayName,this.ToInputControl(Attributes),false);return Field.ToHtml();}
CField.prototype.ToCheckboxControl=function(Attributes){if(!Attributes)Attributes='';var aContent=new Array();aContent.push('<input name="'+this.Name+'" '+Attributes+' type="checkbox"');if(this.Value&&this.Value!='0'){aContent.push(' checked');}
aContent.push('">');return aContent.join('');}
CField.prototype.ToTextArea=function(Attributes){if(!Attributes)Attributes='';Result=['<textarea name="',this.Name,'" ',Attributes,'>',this.Value?htmlspecialchars(this.Value):'','</textarea>'].join('');return Result;}
CField.prototype.ToSelectInput=function(aOptions,Attributes){var Result=['<select Name="',this.Name,'" ',Attributes,'>"'];var bFound=false;for(var iIndex=0;iIndex<aOptions.length;iIndex++){var Option=aOptions[iIndex];if(this.Value==Option)bFound=true;Result.push(['<option',this.Value==Option?' selected':'',,'>',htmlspecialchars(Option),'</option>'].join(''));}
if(!bFound){Result.push(['<option selected>',this.EncodeValue?htmlspecialchars(this.Value):this.Value,'</option>'].join(''));}
Result.push("</select>");return Result.join('');}
CField.prototype.ToAssocSelectInput=function(aOptions,Attributes){var Result=['<select Name="',this.Name,'" ',Attributes,'>"'];for(var Option in aOptions){var Display=aOptions[Option];Result.push(['<option value="',htmlspecialchars(Option),'"',Option==this.Value?' selected':'','>',htmlspecialchars(Display),'</option>'].join(''));}
if(this.Value){if(!aOptions[this.Value]){Result.push(["<option selected>",this.EncodeValue?htmlspecialchars(this.Value):this.Value,"</option>"].join(''));}}
Result.push("</select>");return Result.join('');}
CField.prototype.ToDateAndTimeControls=function(){var Result=[];var testDate=new Date();var valueDate=this.Value?new Date(this.Value*1000):new Date();var aOptions={};aOptions[-1]='HH';for(var iHour=0;iHour<24;iHour++){testDate.setHours(iHour);aOptions[iHour]=testDate.format('HH');}
Result.push(new CField(this.Name+"Hours",valueDate.getHours()).ToAssocSelectInput(aOptions));var aOptions={};for(var iMinute=0;iMinute<60;iMinute=iMinute+5){testDate.setMinutes(iMinute);aOptions[iMinute]=testDate.format('mm');}
Result.push(new CField(this.Name+"Minutes",valueDate.getMinutes()).ToAssocSelectInput(aOptions));var aOptions={};aOptions[-1]=['DD'];testDate.setMonth(0);for(var iDay=1;iDay<=31;iDay++){testDate.setDate(iDay);aOptions[iDay]=testDate.format('dd');}
Result.push(new CField(this.Name+"Day",valueDate.getDate()).ToAssocSelectInput(aOptions));var aOptions={};aOptions[-1]='Month';testDate.setDate(1);for(var iMonth=0;iMonth<12;iMonth++){testDate.setMonth(iMonth);aOptions[iMonth]=testDate.format('MMM');}
Result.push(new CField(this.Name+"Month",valueDate.getMonth()).ToAssocSelectInput(aOptions));var aOptions={};aOptions[-1]='YYYY';var iYear=testDate.getFullYear();for(var iYearOffset=0;iYearOffset<40;iYearOffset++){testDate.setFullYear(iYear+iYearOffset-10);var d=testDate.format('yyyy');aOptions[d]=d;}
Result.push(new CField(this.Name+"Year",valueDate.getFullYear()).ToAssocSelectInput(aOptions));return Result.join('');}
CField.prototype.FromDateAndTimeControls=function(Form){var Result=new Date();Result.setSeconds(0);Result.setMilliseconds(0);Result.setDate(1);var aInputNames=['Hours','Minutes','Year','Month','Day'];for(iIndex=0;iIndex<aInputNames.length;iIndex++){var Component=aInputNames[iIndex];var Element=Form.elements.namedItem(this.Name+Component);if(!Element)continue;switch(Component){case"Hours":Result.setHours(Element.value);break;case"Minutes":Result.setMinutes(Element.value);break;case"Day":Result.setDate(Element.value);break;case"Month":Result.setMonth(Element.value);break;case"Year":Result.setFullYear(Element.value);break;}}
return Math.floor(Result.getTime()/1000);}
window.CAutoCompletionControl=function(Element){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CAutoCompletionControl.prototype.Init=function(Element,Options){this.Element=Element;this.Options=Options?Options:[];}
CAutoCompletionControl.prototype.OnKeyPress=function(oEvent){if(this.Element.nodeName!="INPUT"&&this.Element.nodeName!='TEXTAREA')return true;if(!this.Element.ReplaceSelection){this.Element.ReplaceSelection=function(Text){if(navigator.userAgent.indexOf("IE")==-1){var iStart=this.selectionStart;this.value=this.value.substring(0,iStart)+Text+this.value.substring(this.selectionEnd,this.value.length);this.setSelectionRange(iStart+Text.length,iStart+Text.length);}else{var oRange=document.selection.createRange();oRange.text=Text;oRange.collapse(true);oRange.select();}
this.focus();};}
if(!this.Element.GetSelection){this.Element.GetSelection=function(){if(navigator.userAgent.indexOf("IE")==-1){return{Start:this.selectionStart,Value:this.value.substring(this.selectionStart,this.selectionEnd-this.selectionStart),End:this.selectionEnd};}else{var Marker=Math.random();while(this.value.indexOf(Marker)!=-1){Marker+=Math.random();}
var OriginalText=new String(this.value);var oRange=document.selection.createRange();oRange.text=[Marker,oRange.text,Marker].join('');var aArray=this.value.split(Marker);var Result={};Result.Start=aArray[0].length;Result.Value=aArray[1];Result.End=aArray[0].length+aArray[1].length;this.value=OriginalText;this.Select(Result.Start,Result.End);return Result;}}}
if(!this.Element.Select){this.Element.Select=function(iStart,iEnd){switch(arguments.length){case 0:this.select();break;case 1:iEnd=this.value.length;case 2:if(navigator.userAgent.indexOf("IE")==-1){this.setSelectionRange(iStart,iEnd);}else{var oRange=this.createTextRange();var aLines=this.value.split('\n');var iRunner=0;iEnd+=aLines.length-1;while(iRunner<=iEnd){iRunner+=aLines.shift().length;iRunner+=1;if(iRunner<=iStart)iStart--;if(iRunner<=iEnd)iEnd--;}
oRange.moveStart("character",iStart);oRange.moveEnd("character",-(this.value.length-iEnd));oRange.select();}}
this.focus();}}
var CharCode=0;if(window.event){CharCode=window.event.keyCode;}else if(oEvent.which){CharCode=oEvent.which;}
switch(CharCode){case 0:case 38:case 40:case 37:case 39:case 33:case 34:case 36:case 35:case 9:case 27:case 16:case 17:case 18:case 20:case 8:case 46:return true;case 13:if(this.Element.nodeName=='TEXTAREA')return true;var Selection=this.Element.GetSelection();if(Selection.Start==Selection.End){return true;}else{var iLen=this.Element.value.length;this.Element.Select(iLen,iLen);return false;}
default:this.OnAutoComplete(CharCode);}
return false;}
CAutoCompletionControl.prototype.OnAutoComplete=function(CharCode){var Selection=this.Element.GetSelection();var SkipAutocompletion=(Selection.End<this.Element.value.length);this.Element.ReplaceSelection(String.fromCharCode(CharCode));if(SkipAutocompletion)return;var CurrentValue=new String(this.Element.value);var FixedContent='';if(this.Element.nodeName=='TEXTAREA'){var LastEOL=CurrentValue.lastIndexOf('\n');if(LastEOL>0){FixedContent=CurrentValue.substring(0,LastEOL+1);CurrentValue=CurrentValue.substring(LastEOL+1);}}
CurrentValue=CurrentValue.replace(/([\.\\\+\*\?\[\^\]\(\$\)])/g,"\\$1");var SearchRegExp=new RegExp("^"+CurrentValue,"i");for(var OptionIndex in this.Options){var Option=this.Options[OptionIndex];if(Option.search(SearchRegExp)!=-1){var iLen=this.Element.value.length;var aNewValue=[FixedContent,Option];this.Element.value=aNewValue.join('');this.Element.Select(iLen,this.Element.value.length);return;}}}

window.CPage=function(Page){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CPage.prototype.Init=function(Page){this.Page=Page;this.Id='';this.ActionPanelNames=new Array('HelpPanel');this.ImagesPath='';this.MailDomain='';this.ZendProfile=false;this.aActions={};this.bGuiSecureMode=true;this.Events={};}
CPage.prototype.AddEventHandler=function(EventName,ContextObject,Method){if(!this.EventHandlers)this.EventHandlers={};if(!this.EventHandlers[EventName])this.EventHandlers[EventName]=[];this.EventHandlers[EventName].push({"Context":ContextObject,"Method":Method});}
CPage.prototype.RaiseEvent=function(EventName,EventArgs){if(!this.EventHandlers)return;if(!this.EventHandlers[EventName])return;var aHandlers=this.EventHandlers[EventName];for(var iIndex=0;iIndex<aHandlers.length;iIndex++){var Handler=aHandlers[iIndex];Handler.Method.apply(Handler.Context,EventArgs);}}
CPage.prototype.RemoveEventHandler=function(EventName,ContextObject,Method){if(!this.EventHandlers)return;if(!this.EventHandlers[EventName])return;var EventHandlers=this.EventHandlers[EventName];for(var iIndex=0;iIndex<EventHandlers.length;iIndex++){if(EventHandlers[iIndex].Context!=ContextObject)continue;if(EventHandlers[iIndex].Method.toString()!=Method.toString())continue;EventHandlers.splice(iIndex,1);break;}}
CPage.prototype.ClearForm=function(Element){if(!Element)return;var oForm=(Element.form?Element.form:Element);if(!oForm)return;if(!oForm.elements)return;for(i=0;i<oForm.length;i++){var oInputControl=oForm.elements[i];if(!oInputControl)continue;if(oInputControl.type=='text')oInputControl.value='';if(oInputControl.type=='textarea')oInputControl.value='';}}
CPage.prototype.BuildPostData=function(Form,ResultFormat){if(!ResultFormat)ResultFormat='Html';var aPostData=['ContentType=Ajax'+ResultFormat];for(iIndex=0;iIndex<Form.elements.length;iIndex++){var element=Form.elements[iIndex];if(element.name=='')continue;if(element.disabled)continue;if(element.type=='checkbox'){if(!element.checked)continue;}
if(element.type=='radio'){if(!element.checked)continue;}
if(element.type=='select-one'){if(element.value==''){if(element.selectedIndex==-1)continue;var value=element.options[element.selectedIndex].text;aPostData.push('&'+element.name+'='+escape(value));continue;}}
aPostData.push('&'+element.name+'=');if(element.value){aPostData.push(escape(Utf8.encode(element.value)));}}
return aPostData.join('');}
CPage.prototype.ShowPanel=function(PanelName){var oPanel=document.getElementById(PanelName);if(!oPanel)return;oPanel.style.display='';}
CPage.prototype.HidePanel=function(PanelName){var oPanel=document.getElementById(PanelName);if(!oPanel)return;oPanel.style.display='none';}
CPage.prototype.TogglePanel=function(PanelName){var oPanel=document.getElementById(PanelName);if(!oPanel)return;if(oPanel.style.display=='none'){oPanel.style.display='';}else{oPanel.style.display='none';}}
CPage.prototype.ShowActionPanel=function(PanelName){for(var iIndex in this.ActionPanelNames){if(PanelName!=this.ActionPanelNames[iIndex]){this.HidePanel(this.ActionPanelNames[iIndex]);}}
if(PanelName)this.TogglePanel(PanelName);this.ShowResultMessage(null);}
CPage.prototype.ShowLoadingPanel=function(){var oLoadingPanel=document.getElementById('CallbackLoadingPanel');if(oLoadingPanel){var oPanel=document.getElementById('CallbackResponsePanel');if(oPanel){oPanel.style.display='';oPanel.innerHTML=oLoadingPanel.innerHTML;}}}
CPage.prototype.HideLoadingPanel=function(){var oPanel=document.getElementById('CallbackResponsePanel');if(oPanel){oPanel.style.display='none';oPanel.innerHTML='';}}
CPage.prototype.SetActionTitle=function(NewTitle){var ActionTitle=document.getElementById('ActionTitle');if(ActionTitle){if(!ActionTitle.firstChild){ActionTitle.appendChild(document.createTextNode(''));}
ActionTitle.firstChild.nodeValue=NewTitle;}}
CPage.prototype.ShowResultMessage=function(Result){var p=document.getElementById('ActionResult');if(!p)return;if(typeof(Result)!=='undefined'&&Result&&Result.Message){p.innerHTML=Result.Message;p.style.display='';}else{p.innerHTML='';p.style.display='none';}}
CPage.prototype.HiddenFormInputsToHtml=function(){return'';}
CPage.prototype.ActionButtonToHtml=function(aAction){var aResult=['<input name="Action" value="',htmlspecialchars(aAction.Name),'" '];if(aAction.Tooltip){aResult.push(' title="',aAction.Tooltip,'"');}
if(aAction.Attributes){aResult.push(aAction.Attributes);var s=new String(aAction.Attributes);if(s.indexOf('type=')==-1){aResult.push('type="submit" ');}}else{aResult.push('type="submit" ');}
aResult.push(">");return aResult.join('');}
CPage.prototype.ActionButtonsToHtml=function(Mask){var aResult=[];for(var ActionName in this.aActions){var aValue=this.aActions[ActionName];var bPermitted=this.bGuiSecureMode;switch(aValue.Permissions){case XMLDB_PERMISSION_ENABLE:bPermitted=true;break;case XMLDB_PERMISSION_DISABLE:bPermitted=false;break;case XMLDB_PERMISSION_INHERIT:default:break;}
if(!bPermitted)continue;if(Mask){if(typeof(aValue.Style)!='undefined'){if(!(aValue.Style&Mask))continue;}}
aResult.push(this.ActionButtonToHtml(aValue));}
return aResult.join('');}
CPage.prototype.CheckboxToHtml=function(FieldName,Data,Attributes){if(!Attributes)Attributes='';var aResult=['<input type="checkbox" Name="',FieldName,'" ',Attributes];if(Data[FieldName]){if(Data[FieldName]=='1'){aResult.push(' checked');}}
aResult.push(">");return aResult.join('');}
CPage.prototype.RadioButtonToHtml=function(Id,FieldName,Option,Data,Label,Attributes){if(!Attributes)Attributes='';var aResult=['<span ',Attributes,'>','<input type="radio"',' Name="',FieldName,'"',' Value="',Option,'"',' Id="',Id,'"'];if(Data[FieldName]){if(Data[FieldName]==Option){aResult.push(' checked');}}
aResult.push('>');if(Label){aResult.push(['<label for="',Id,'">',Label,'</label>'].join(''));}
aResult.push('</span>');return aResult.join('');}
CPage.prototype.ForEachCheckbox=function(FormId,Callback){var oForm=document.forms.namedItem(FormId);if(!oForm)return;var oInputList=oForm.elements;if(!oInputList)return;for(i=0;i<oInputList.length;i++){var oInputElement=oInputList.item(i);if(!oInputElement)continue;if(oInputElement.type!='checkbox')continue;var oInputName=new String(oInputElement.name);if(oInputName.substring(0,6)!='Select')continue;Callback(oInputElement);}}
CPage.prototype.PopulateTableOfContents=function(ContentId,TableOfContentsId){var Toc=document.getElementById(TableOfContentsId);if(!Toc)return;var Current=document.getElementById(ContentId);if(!Current)return;var aCurrent=new Array();aCurrent.push(Current);var aToc=new Array();aToc.push(Toc);var iNextId='1';while(aCurrent.length>0){var Current=aCurrent.pop();if(Current.nodeType!=1)continue;var Regex=new RegExp("^H(\\d*)$","i");var Matches=Regex.exec(Current.nodeName);if(Matches){var ThisLevel=Matches[1];while(ThisLevel<aToc.length){aToc.pop();}
if(ThisLevel>aToc.length){var Item=document.createElement('ul');aToc[aToc.length-1].appendChild(Item);aToc.push(Item);}
var Item=document.createElement('li');var Id;if(Current.id){Id=Current.id;}else{Id=['TOCEntry',this.Id,iNextId++].join('');Current.id=Id;}
Item.innerHTML=['<a href="#',Id,'">',Current.innerHTML,'</a>'].join('');aToc[aToc.length-1].appendChild(Item);}
for(var iIndex=Current.childNodes.length-1;iIndex>=0;iIndex--){var ThisNode=Current.childNodes.item(iIndex);if(ThisNode.nodeType!=1)continue;aCurrent.push(Current.childNodes.item(iIndex));}}}
CPage.prototype.RemoveWatermark=function(Control){if(Control.className!='Watermark')return;if(!Control.WatermarkValue){Control.WatermarkValue=Control.value;}
if(Control.value==Control.WatermarkValue){Control.value='';}
Control.className='';}
CPage.prototype.AddWatermark=function(Control){if(!Control.WatermarkValue)return;if(!Control.value){Control.value=Control.WatermarkValue;}
if(Control.WatermarkValue==Control.value){Control.className='Watermark';}}
