
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';}}

window.CXDbGuiEntry=function(){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CXDbGuiEntryStaticData=function(){this.ShowImage=new Image();this.ShowImage.src="/image/misc/arrow-down.gif";this.HideImage=new Image();this.HideImage.src="/image/misc/arrow-right.gif";}
s_CXDbGuiEntryStaticData=new CXDbGuiEntryStaticData();CXDbGuiEntry.prototype.Init=function(RecordId,Data,Parent){this.Parent=Parent;this.Data=Data;this.RecordId=RecordId;this.prototype={};this.prototype.ToInfoPanel=null;this.ReInit();}
CXDbGuiEntry.prototype.ReInit=function(){this.ExtendedInfo=null;this.InfoPanel=null;this.Form=null;this.LoadingPanel=null;}
CXDbGuiEntry.prototype._GetExtendedInfo=function(){if(this.ExtendedInfo)return this.ExtendedInfo;var Id='ExtendedInfo'+this.RecordId;this.ExtendedInfo=document.getElementById(Id);if(this.ExtendedInfo)return this.ExtendedInfo;this.ExtendedInfo=document.createElement('span');this.ExtendedInfo.id='ExtendedInfo'+this.RecordId;this.ExtendedInfo.className='EntryExtendedInfo';this.ExtendedInfo.style.display='none';return this.ExtendedInfo;}
CXDbGuiEntry.prototype._GetExpansionControlHtml=function(){return['<a class="ExtendedInfoIndicatorRegion EntrySummaryRegion"',' onclick="javascript:',this.Parent.Id,'.ToggleEntryExtendedInfo(',this.RecordId,')"','>','<img',' id="ExtendedInfoIndicator',this.RecordId,'"',' src="',s_CXDbGuiEntryStaticData.HideImage.src,'"',' alt="Show/Hide details"',' style="width:16;border:none">','</a>'].join('');}
CXDbGuiEntry.prototype.ToggleEntryExtendedInfo=function(){var PanelName='ExtendedInfo'+this.RecordId;var oPanel=document.getElementById(PanelName);if(!oPanel)return;if(oPanel.style.display=='none'){this.ShowEntryExtendedInfo();}else{this.HideEntryExtendedInfo();}}
CXDbGuiEntry.prototype.ShowEntryExtendedInfo=function(){if(!this.Cancel())return;var PanelName='ExtendedInfo'+this.RecordId;var ImageName='ExtendedInfoIndicator'+this.RecordId;var oPanel=document.getElementById(PanelName);if(!oPanel)return;var oImage=document.getElementById(ImageName);if(!oImage)return;if(oPanel.style.display=='none'){$(oPanel).show("slow");oImage.src=s_CXDbGuiEntryStaticData.ShowImage.src;}}
CXDbGuiEntry.prototype.HideEntryExtendedInfo=function(){if(!this.Cancel())return;var PanelName='ExtendedInfo'+this.RecordId;var ImageName='ExtendedInfoIndicator'+this.RecordId;var oPanel=document.getElementById(PanelName);if(!oPanel)return;var oImage=document.getElementById(ImageName);if(!oImage)return;if(oPanel.style.display==''||oPanel.style.display=='block'){$(oPanel).hide("slow");oImage.src=s_CXDbGuiEntryStaticData.HideImage.src;}}
CXDbGuiEntry.prototype.InsertInto=function(Table,Index){if(!Table)return;this._InsertSummaryInto(Table,Index);if(this.ToInfoPanel){var RowElementId='ExtendedInfoRow'+this.RecordId;var Row=document.getElementById(RowElementId);if(Row){Index=Row.rowIndex;var t=Row.parentNode;while(t.nodeName!='TABLE')t=t.parentNode;t.deleteRow(Row.rowIndex);}else{if(Index){Index=Index+1;}else{Index=-1;}}
var Row=Table.insertRow(Index);Row.id=RowElementId;var Cell=Row.insertCell(-1);var SummaryRow=document.getElementById('Row'+this.RecordId);Cell.colSpan=SummaryRow.cells.length;Cell.appendChild(this._GetExtendedInfo());this.HideLoadingPanel();}}
CXDbGuiEntry.prototype._InsertSummaryInto=function(Table,Index){if(!Table)return;var RowElementId='Row'+this.RecordId;var Row=document.getElementById(RowElementId);if(Row){Index=Row.rowIndex;var t=Row.parentNode;while(t.nodeName!='TABLE')t=t.parentNode;t.deleteRow(Row.rowIndex);}else{if(!Index)Index=-1}
var Row=Table.insertRow(Index);Row.id='Row'+this.RecordId;Row.className="EntrySummaryInfo";var iRowsPerEntry=(this.ToInfoPanel?2:1);if(Math.floor(Table.rows.length/iRowsPerEntry)%2){Row.style.backgroundColor="#EEEEEE";}
{var e=Row.insertCell(-1);e.className="EntrySummaryActions EntrySummaryRegion";if(this.ToInfoPanel){e.innerHTML=this._GetExpansionControlHtml();}else{if(this.Parent.HeaderRows==-1){this.Parent.HeaderRows=Row.rowIndex-1;}
e.innerHTML=Row.rowIndex-this.Parent.HeaderRows;}
for(var iIndex in this.Parent.aResultInputs){var e=Row.insertCell(-1);e.innerHTML=this.Parent.aResultInputs[iIndex].ToHtml(this.Parent,this.RecordId,'',this.Data);}
for(var iIndex in this.Parent.aResultActions){var e=Row.insertCell(-1);e.innerHTML=this.Parent.aResultActions[iIndex].ToHtml(this.Parent,this.RecordId,'',this.Data);}}
this.InsertSummaryIntoRow(Row);}
CXDbGuiEntry.prototype.InsertSummaryIntoRow=function(Row){for(var iIndex=0;iIndex<this.Parent.aDisplayColumns.length;iIndex++){var Name=this.Parent.aDisplayColumns[iIndex];var e=Row.insertCell(-1);if(this.Data[Name]){e.innerHTML=htmlspecialchars(this.Data[Name]);}else{e.innerHTML='';}}
return;}
CXDbGuiEntry.prototype.InsertIntoElement=function(Container,Index){if(!Container)return;var Id='Entry'+this.RecordId;var r=document.getElementById(Id);if(r){r.innerHTML='';}else{r=document.createElement('span');r.style.display='block';r.style.width='100%';r.style.marginBottom='5px';r.id=Id;Container.appendChild(r);}
if(!Index)Index=Container.childNodes.length;r.appendChild(this._SummaryToElement(Index));r.appendChild(this._GetExtendedInfo());}
CXDbGuiEntry.prototype._SummaryToElement=function(Index){var r=document.createElement('span');r.className="EntrySummaryInfo";if(Index%2){r.style.backgroundColor="#EEEEEE";}
{var e=document.createElement('span');e.className="EntrySummaryActions EntrySummaryRegion";var aContents=[this._GetExpansionControlHtml()];for(var iIndex in this.Parent.aResultActions){aContents.push(this.Parent.aResultActions[iIndex].ToHtml(this.Parent,this.RecordId));}
e.innerHTML=aContents.join('');r.appendChild(e);}
this.InsertSummaryIntoElement(r);return r;}
CXDbGuiEntry.prototype.InsertSummaryIntoElement=function(r){return;}
CXDbGuiEntry.prototype.ShowLoadingPanel=function(){if(this.InfoPanel){this.InfoPanel.style.display='none';}
if(this.Form){this.Form.style.display='none';}
if(this.LoadingPanel){this.LoadingPanel.style.display='';}else{this.LoadingPanel=document.createElement('div');this.LoadingPanel.style.textAlign="center";this.LoadingPanel.innerHTML=['<div>','<span class="loadingitempanel">','<span style="padding:20px;display:block;">','Loading... <img src="',this.Parent.ImagesPath,'progress.gif"/>','</span>','</span>','</div>'].join('');this.ExtendedInfo.appendChild(this.LoadingPanel);}
this.Parent.HidePanel('ConfirmDeletePanel'+this.RecordId);}
CXDbGuiEntry.prototype.HideLoadingPanel=function(){if(this.LoadingPanel){this.LoadingPanel.style.display='none';}
if(this.Form){this.Form.style.display='none';}
if(this.InfoPanel){this.InfoPanel.style.display='';}}
CXDbGuiEntry.prototype.Cancel=function(){if(this.Form){if(!confirm('Are you sure you want to abandon your changes?  This action is not reversible!')){return false;}
this.Form.parentNode.removeChild(this.Form);this.Form=null;}
if(this.LoadingPanel){this.LoadingPanel.style.display='none';}
if(this.InfoPanel){this.InfoPanel.style.display='';}else if(this.ToInfoPanel){this.ExtendedInfo.appendChild(this.ToInfoPanel());}
return true;}
CXDbGuiEntry.prototype.Edit=function(){if(this.LoadingPanel){this.LoadingPanel.style.display='none';}
if(this.InfoPanel){this.InfoPanel.style.display='none';}
if(this.Form){this.Form.style.display='';}else{this.ExtendedInfo.appendChild(this.ToEditForm());}}
CXDbGuiEntry.prototype.ToInfoPanel=function(){if(this.InfoPanel)return this.InfoPanel;var e=document.createElement('span');e.id='InfoPanel'+this.RecordId;{var aContents=[];for(var Name in this.Data){var Field=new CField(this.Parent.DisplayName(Name),this.Data[Name]);aContents.push(Field.ToHtml());}
aContents.push(['<span class="inputgroup">','<span class="inputcontrol">','<input class="ActionButton" type="button" value="Delete" ',' onclick="',this.Parent.Id,'.ShowPanel(\'ConfirmDeletePanel',this.RecordId,'\')"/>','<input class="ActionButton" type="button" value="Edit" ',' onclick="',this.Parent.Id,'.Edit(\'',this.RecordId,'\')"/>','</span>','</span>','<div class="confirmpanel" id="ConfirmDeletePanel',this.RecordId,'" style="display:none">','<p>Are you sure you want to delete this entry?  Note this action is not reversible.</p>','<input type="button" value=" No " onclick="',this.Parent.Id,'.HidePanel(\'ConfirmDeletePanel',this.RecordId,'\')">','<input type="button" name="Confirm" value="Yes" onclick="',this.Parent.Id,'.Delete(',this.RecordId,')">','</div>',].join(''));e.innerHTML=aContents.join('');}
this.InfoPanel=e;return e;}
CXDbGuiEntry.prototype.ToEditForm=function(){if(this.Form)return this.Form;this.Form=document.createElement('form');this.Form.action=['javascript:',this.Parent.Id,'.Apply(\'',this.RecordId,'\')'].join('');this.Form.id="EditForm"+this.RecordId;{var aContents=[];for(var Name in this.Parent.Schema){var Schema=this.Parent.Schema[Name];var FieldValue=new CField(Name,this.Data[Name]);var FieldValueHtml='';var Attributes=new CXDb.CAttributes();Attributes.id=[FieldValue,this.RecordId].join('-');if(Schema.multiline||Schema.length>100){var ColumnCount=60;var iLineCount=0;if(this.Data[Name]){var Value=new String(this.Data[Name]);iLineCount=Value.search("/\n/");iLineCount+=Math.ceil(Value.length/ColumnCount);}
var iTextAreaLines=iLineCount+2;if(iTextAreaLines>25)iTextAreaLines=25;if(iTextAreaLines<3)iTextAreaLines=3;Attributes.cols=ColumnCount;Attributes.rows=iTextAreaLines;FieldValueHtml=FieldValue.ToTextArea(Attributes.ToHtml());}else{Attributes.size=Schema.length;FieldValueHtml=FieldValue.ToInputControl(Attributes.ToHtml());}
var Field=new CField(this.Parent.DisplayName(Name),FieldValueHtml,false);aContents.push(Field.ToHtml());}
this.Form.innerHTML=aContents.join('');}
{var aContents=['<span class="inputcontrol">','<input type="submit" value="',this.RecordId?'Modify':'Create','">'];if(this.RecordId){aContents.push(['<button onclick="',this.Parent.Id,'.Cancel(\'',this.RecordId,'\');return false;">','Cancel</button>',''].join(''));}else{aContents.push(['<button onclick="',this.Parent.Id,'.ClearForm(this);return false;">','Clear</button>',''].join(''));}
aContents.push('</span>');var b=document.createElement('span');b.className='inputgroup';b.innerHTML=aContents.join('');this.Form.appendChild(b);}
{var e=document.createElement('span');e.innerHTML=['<input type="hidden" name="Action" value="Modify Record">','<input type="hidden" name="RecordId" value="',this.RecordId,'">'].join('');this.Form.appendChild(e);}
return this.Form;}
CXDbGuiEntry.prototype.Apply=function(){this.ShowLoadingPanel();var oRequest=new AjaxCallback(this,'_ModifyComplete');oRequest.RecordId=this.RecordId;var PostData=this.Parent.BuildPostData(this.Form,'Js');oRequest.Send(this.Parent.Page,PostData);}
CXDbGuiEntry.prototype._ModifyComplete=function(oRequest){var SearchResults=eval(oRequest.responseText);if(typeof(SearchResults)!='object'){this.Edit();return;}
if(!SearchResults.Results)return;if(this.RecordId==0){this.Parent.HidePanel('AddPanel');this.Form.parentNode.removeChild(this.Form);this.LoadingPanel.parentNode.removeChild(this.LoadingPanel);this.Parent.AddFormEntry=null;this.Parent._SearchComplete(oRequest);}else if(SearchResults.Results[this.RecordId]){this.Init(this.RecordId,SearchResults.Results[this.RecordId],this.Parent);var Table=document.getElementById('SearchResults');this.InsertInto(Table);this.ToggleEntryExtendedInfo();this.Parent.RaiseEvent(this.Parent.Events.onSearchComplete,[]);}}

window.CResultAction=function(Name,DisplayName,Link,Tooltip){this.Name=Name;this.DisplayName=DisplayName;this.Link=Link;this.Tooltip=Tooltip;}
CResultAction.prototype.ToHtml=function(Parent,RecordId,Attributes,Data){var aResults=['<button',' id="',Parent.Id,this.Name,RecordId,'"',' onclick="',htmlspecialchars(eval(this.Link)),'"',' type="button"',];if(this.Tooltip){aResults.push(' title="',this.Tooltip,'"');}
if(Attributes)aResults.push(Attributes);aResults.push('>');aResults.push(htmlspecialchars(this.DisplayName));aResults.push('</button>');return aResults.join('');}
window.CResultInput=function(Name,Type,Attributes){this.Name=Name;this.Type=Type;this.Attributes=Attributes;}
CResultInput.prototype.ToHtml=function(Parent,RecordId){var aResults=['<input',' id="',Parent.Id,this.Name,RecordId,'"',' type="',this.Type,'"',' name="',htmlspecialchars(this.Name),RecordId,'"'];if(this.Attributes)aResults.push(this.Attributes);aResults.push('>');return aResults.join('');}
window.CXDbGui=function(Page){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CXDbGui.prototype=new CPage();CXDbGui.prototype.constructor=CXDbGui;CXDbGui.superclass=CPage.prototype;CXDbGui.prototype.Init=function(Page){CXDbGui.superclass.Init.apply(this,arguments);this.ActionPanelNames.push('AddPanel');this.ActionPanelNames.push('SearchPanel');this.SortByField='';this.SortReversed=false;this.aDisplayNames=[];this.aDisplayColumns=null;this.aResultActions=[];this.aResultInputs=[];this.HeaderRows=-1;this.AddFormEntry=null;this.StaticRequestVars=[];this.Events.onSearchComplete="onSearchComplete";this.AddEventHandler(this.Events.onSearchComplete,this,this.onSearchComplete);this.Data=null;}
CXDbGui.prototype._GetData=function(RecordId){if(RecordId==0)return this.AddFormEntry;var iIndex=this._GetDataIndex(RecordId);if(iIndex<0)return null;return this.Data['Results'][iIndex];}
CXDbGui.prototype._GetDataIndex=function(RecordId){if(!this.Data.Results)return-1;var aResults=this.Data.Results;for(var iIndex in aResults){var Result=aResults[iIndex];if(Result.RecordId==RecordId){return iIndex;}}
return-1;}
CXDbGui.prototype._NewDataEntry=function(RecordId,Data){return new CXDbGuiEntry(RecordId,Data,this);}
CXDbGui.prototype.CallbackThisForm=function(Form,ResultFormat){if(!ResultFormat)ResultFormat='Html';if(ResultFormat=='Html'){this.ShowLoadingPanel();}
var oRequest=new AjaxCallback(this,'CallbackThisFormComplete'+ResultFormat);var PostData=this.BuildPostData(Form,ResultFormat);oRequest.Send(this.Page,PostData);}
CXDbGui.prototype.BuildSingleActionPostData=function(Form,ResultFormat,Action){var aDisabledControls=[];for(iIndex=0;iIndex<Form.elements.length;iIndex++){var element=Form.elements[iIndex];if(element.name!='Action')continue
if(element.disabled)continue;element.disabled=true;aDisabledControls.push(iIndex);}
var PostData=this.BuildPostData(Form,ResultFormat);for(iIndex=0;iIndex<aDisabledControls.length;iIndex++){if(Form.elements[iIndex].name=='Action'){Form.elements[iIndex].disabled=false;}}
return PostData+'&Action='+Action;}
CXDbGui.prototype.CallbackThisFormCompleteHtml=function(oRequest){var oPanel=document.getElementById('CallbackResponsePanel');if(!oPanel){alert("Can't find the CallbackResponsePanel.  The results are shown here instead:"+oRequest.responseText);}else{oPanel.style.display='';oPanel.innerHTML=oRequest.responseText;window.location.href="#CallbackResponsePanel";}}
CXDbGui.prototype.CallbackThisFormCompleteJs=function(oRequest){alert(oRequest.responseText);}
CXDbGui.prototype.ToggleEntryExtendedInfo=function(RecordId){var Result=this._GetData(RecordId);if(!Result)return;Result.ToggleEntryExtendedInfo();}
CXDbGui.prototype.ShowActionPanel=function(){CXDbGui.superclass.ShowActionPanel.apply(this,arguments);var p=document.getElementById('AddPanel');if(!p)return;if(p.style.display=='none')return;if(!this.Id)return;if(!this.AddFormEntry){this.AddFormEntry=this._NewDataEntry(0,{});}
this.AddFormEntry.ExtendedInfo=p;this.AddFormEntry.Edit();}
CXDbGui.prototype.ShowErrorPanel=function(Input,ErrorMessage){if(!Input.id)return;var ErrorPanelId=Input.id+'ErrorPanel';var Panel=document.getElementById(ErrorPanelId);if(!Panel){Panel=document.createElement('span');Panel.id=ErrorPanelId;Panel.className='inputerror';Input.parentNode.appendChild(Panel);}else{Panel.style.display='';}
Panel.innerHTML=ErrorMessage;}
CXDbGui.prototype.HideErrorPanel=function(Input){if(!Input.id)return;var ErrorPanelId=Input.id+'ErrorPanel';var Panel=document.getElementById(ErrorPanelId);if(!Panel)return;Panel.style.display='none';}
CXDbGui.prototype.DisplayName=function(FieldName){var DisplayName=FieldName;for(var iIndex in this.aDisplayNames){if(this.aDisplayNames[iIndex].Name==FieldName){DisplayName=this.aDisplayNames[iIndex].Value;break;}}
return DisplayName;}
CXDbGui.prototype.FieldSortLink=function(FieldName,Attributes){var aResult=new Array();aResult.push('<span style="white-space: nowrap" ');aResult.push(Attributes);aResult.push('>');{aResult.push('<a href="javascript:');aResult.push(this.Id+'.SortAndRender(\''+FieldName+'\')');aResult.push('" title="Sort by this column">');aResult.push(htmlspecialchars(this.DisplayName(FieldName)));aResult.push('</a>');if(this.SortByField==FieldName)
if(this.SortReversed){aResult.push('&nbsp;<img src="'+this.ImagesPath+'arrow-up.gif" alt="">');}else{aResult.push('&nbsp;<img src="'+this.ImagesPath+'arrow-down.gif" alt="">');}}
aResult.push('</span>');return aResult.join('');}
CXDbGui.prototype.Sort=function(FieldName){if(FieldName){if(FieldName==this.SortByField){this.SortReversed=!this.SortReversed;}else{this.SortByField=FieldName;for(var i in this.Data['Results']){this.Data['Results'][i].SortKey=null;}}}
if(!this.SortByField)return;var SortByField=this.SortByField;var Reversed=this.SortReversed?-1:1;var f=function(a,b){if(!a.SortKey){a.SortKey=eval('a.Data.'+SortByField);if(!a.SortKey)a.SortKey=a.RecordId;}
if(!b.SortKey){b.SortKey=eval('b.Data.'+SortByField);if(!b.SortKey)b.SortKey=b.RecordId;}
if(a.SortKey>b.SortKey)return 1*Reversed;if(a.SortKey<b.SortKey)return-1*Reversed;return 0;}
this.Data['Results'].sort(f);}
CXDbGui.prototype.RenderHeaders=function(eTable){var eSortControls=eTable.insertRow(-1);eSortControls.className="SortControls listheader";{Element=eSortControls.insertCell(-1);Element.className='EntrySummaryActions';var iColspan=this.aResultActions.length+this.aResultInputs.length;Element.colSpan=iColspan+1;Element.innerHTML='<span class="ExtendedInfoIndicatorRegion EntrySummaryRegion"></span>'
+'<span class="EntrySummaryRegion"></span>';if(this.Data['Results'].length){if(!this.aDisplayColumns){this.aDisplayColumns=[];for(var Name in this.Data['Results'][0].Data){this.aDisplayColumns.push(Name);}}
for(var iIndex=0;iIndex<this.aDisplayColumns.length;iIndex++){var Name=this.aDisplayColumns[iIndex];Element=eSortControls.insertCell(-1);Element.className='EntrySummaryName';Element.innerHTML=this.FieldSortLink(htmlspecialchars(Name),' class="EntrySummaryRegion"');}}}}
CXDbGui.prototype.Render=function(){var Container=document.getElementById('ActionContent');Container.style.display="none";Container.innerHTML='';var Element=document.createElement('span');var aContents=new Array();aContents.push("<b>Results:</b> "+this.Data['Results'].length);Element.innerHTML=aContents.join('');Container.appendChild(Element);var Message=this.Data['Message'];if(Message){Element=document.createElement('p');Element.innerHTML=Message;Container.appendChild(Element);}
var Form=document.createElement('form');Form.id='SearchResultsForm';Form.action='';Container.appendChild(Form);Form.innerHTML=this.HiddenFormInputsToHtml();if(this.Data['Results'].length){var eTable=document.createElement('table');eTable.id='SearchResults';eTable.className='SearchResults';this.RenderHeaders(eTable);Form.appendChild(eTable);{var aResults=this.Data['Results'];for(var iIndex in aResults){var Result=aResults[iIndex];Result.InsertInto(eTable);}}
var SearchResultActions=document.createElement('span');SearchResultActions.id="SearchResultsActions";SearchResultActions.innerHTML=this.ActionButtonsToHtml(XMLDBGUI_ACTION_STYLE_SEARCH_LIST);Form.appendChild(SearchResultActions);}
Container.style.display="";}
CXDbGui.prototype.SortAndRender=function(FieldName){this.ShowResultMessage(null);this.Sort(FieldName);this.Render();}
CXDbGui.prototype.GenericSearch=function(){var Form=document.getElementById('SearchForm');this.SetActionTitle("Searching the database");var Element=document.getElementById('ActionContent');Element.innerHTML='';this.HidePanel('SearchPanel');this.ShowLoadingPanel();this.ShowResultMessage(null);var oRequest=new AjaxCallback(this,'_SearchComplete');var PostData=this.BuildPostData(Form,'Js');oRequest.Send(this.Page,PostData);}
CXDbGui.prototype.Search=function(XPathSearch){this.SetActionTitle("Searching the database");var Element=document.getElementById('ActionContent');Element.innerHTML='';this.ShowLoadingPanel();this.ShowResultMessage(null);var oRequest=new AjaxCallback(this,'_SearchComplete');var PostData=[this.StaticRequestVars.join('&'),'ContentType=AjaxJs','Action=Search','Search='+escape(Utf8.encode(XPathSearch))].join('&');oRequest.Send(this.Page,PostData);}
CXDbGui.prototype._SearchComplete=function(oRequest){this.HideLoadingPanel();this.SetActionTitle("Search results");var SearchResults=oRequest.responseText;if(typeof(SearchResults)=='object'){if(!SearchResults.Results)return;this.Data=SearchResults;}else{SearchResults=eval(oRequest.responseText);if(typeof(SearchResults)=='object'){this.Data=SearchResults;}}
if(this.Data&&this.Data.Results){var aResults=this.Data.Results;var aEntries=new Array();for(var iIndex in aResults){var Result=aResults[iIndex];aEntries.push(this._NewDataEntry(iIndex,Result));}
this.Data.Results=aEntries;}
this.RaiseEvent(this.Events.onSearchComplete,[]);}
CXDbGui.prototype.onSearchComplete=function(){this.Sort();this.Render();}
CXDbGui.prototype.Edit=function(RecordId){var Entry=this._GetData(RecordId);if(!Entry)return;Entry.Edit();}
CXDbGui.prototype.Apply=function(RecordId){var Entry=null;if(RecordId==0){Entry=this.AddFormEntry;}else{Entry=this._GetData(RecordId);}
if(!Entry)return;Entry.Apply();}
CXDbGui.prototype.Cancel=function(RecordId){var Entry=this._GetData(RecordId);if(!Entry)return;Entry.Cancel();}
CXDbGui.prototype.DeleteSelected=function(Form){if(!confirm('Are you sure you want to delete these items?  This action is not reversible!')){return false;}
this.ShowLoadingPanel();var oRequest=new AjaxCallback(this,'_DeleteComplete');var PostData=this.BuildSingleActionPostData(Form,'Js','Delete Record');oRequest.Send(this.Page,PostData);}
CXDbGui.prototype.Delete=function(RecordId){var Entry=this._GetData(RecordId);if(!Entry)return;Entry.ShowLoadingPanel();var oRequest=new AjaxCallback(this,'_DeleteComplete');var PostData=['ContentType=AjaxJs','Action=Delete Record','Select'+RecordId+'=on'].join('&');oRequest.Send(this.Page,PostData);}
CXDbGui.prototype._DeleteComplete=function(oRequest){this.HideLoadingPanel();this.HidePanel('AddPanel');var Result=eval(oRequest.responseText);if(typeof(Result)!='object'||!Result.DeletedRecordIds){this.Render();return;}
this.ShowResultMessage(Result);var Table=document.getElementById('SearchResults');for(iIndex=0;iIndex<Result.DeletedRecordIds.length;iIndex++){var RecordId=Result.DeletedRecordIds[iIndex];var iDataIndex=this._GetDataIndex(RecordId);if(iDataIndex<0)continue;this.Data['Results'].splice(iDataIndex,1);}
this.Render();}
CXDbGui.prototype.ExpandAll=function(){var aResults=this.Data['Results'];for(var iIndex in aResults){var Result=aResults[iIndex];Result.ShowEntryExtendedInfo();}}
CXDbGui.prototype.CollapseAll=function(){var aResults=this.Data['Results'];for(var iIndex in aResults){var Result=aResults[iIndex];Result.HideEntryExtendedInfo();}}

window.CMinistriesDbGuiEntry=function(Data){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CMinistriesDbGuiEntry.prototype=new CXDbGuiEntry();CMinistriesDbGuiEntry.prototype.constructor=CMinistriesDbGuiEntry;CMinistriesDbGuiEntry.superclass=CXDbGuiEntry.prototype;CMinistriesDbGuiEntry.prototype.Init=function(UserId,Data,Parent){CMinistriesDbGuiEntry.superclass.Init.apply(this,arguments);this.FieldName=this.Data.FieldName;}
CMinistriesDbGuiEntry.prototype.ToInfoPanel=function(){if(this.InfoPanel)return this.InfoPanel;var e=document.createElement('span');e.id='InfoPanel'+this.RecordId;{var aContents=[];if(this.Data['extendedinformation']){aContents.push([this.Data['extendedinformation']].join(''));}
if(this.Parent.bAdministrator){aContents.push(['<span class="inputgroup">','<span class="inputcontrol">','<input class="ActionButton" type="button" value="Delete" ',' onclick="',this.Parent.Id,'.ShowPanel(\'ConfirmDeletePanel',this.RecordId,'\')"/>','<input class="ActionButton" type="button" value="Edit" ',' onclick="',this.Parent.Id,'.Edit(\'',this.RecordId,'\')"/>','</span>','</span>','<div class="confirmpanel" id="ConfirmDeletePanel',this.RecordId,'" style="display:none">','<p>Are you sure you want to delete this entry?  Note this action is not reversible.</p>','<input type="button" value=" No " onclick="',this.Parent.Id,'.HidePanel(\'ConfirmDeletePanel',this.RecordId,'\')">','<input type="button" name="Confirm" value="Yes" onclick="',this.Parent.Id,'.Delete(',this.RecordId,')">','</div>',].join(''));}else if(this.Data['canedit']==1){aContents.push(['<span class="inputgroup">','<span class="inputcontrol">','<input class="ActionButton" type="button" value="Edit" ',' onclick="',this.Parent.Id,'.Edit(\'',this.RecordId,'\')"/>','</span>','</span>',].join(''));}
aContents.push('<hr>');e.innerHTML=aContents.join('');}
this.InfoPanel=e;return e;}
CMinistriesDbGuiEntry.prototype.ToEditForm=function(){if(this.Form)return this.Form;this.Form=document.createElement('form');this.Form.action=['javascript:',this.Parent.Id,'.Apply(\'',this.RecordId,'\')'].join('');this.Form.id="EditForm"+this.RecordId;{var aContents=[];for(var Name in this.Parent.Schema){var Schema=this.Parent.Schema[Name];var FieldValue=new CField(Name,this.Data[Name]);var FieldValueHtml='';if(Schema.multiline||Schema.length>100){var ColumnCount=60;var iLineCount=0;if(this.Data[Name]){var Value=new String(this.Data[Name]);iLineCount=Value.search("/\n/");iLineCount+=Math.ceil(Value.length/ColumnCount);}
var iTextAreaLines=iLineCount+2;if(iTextAreaLines>25)iTextAreaLines=25;if(iTextAreaLines<10)iTextAreaLines=10;FieldValueHtml=FieldValue.ToTextArea(['rows="',iTextAreaLines,'" cols="',ColumnCount,'"'].join(''));}else{FieldValueHtml=FieldValue.ToInputControl('size="'+Schema.length+'"');}
var Field=new CField(this.Parent.DisplayName(Name),FieldValueHtml,false);aContents.push(Field.ToHtml());}
this.Form.innerHTML=aContents.join('');}
{var aContents=['<span class="inputcontrol">','<input type="submit" value="',this.RecordId?'Modify':'Create','">'];if(this.RecordId){aContents.push(['<button onclick="',this.Parent.Id,'.Cancel(\'',this.RecordId,'\');return false;">','Cancel</button>',''].join(''));}else{aContents.push(['<button onclick="',this.Parent.Id,'.ClearForm(this);return false;">','Clear</button>',''].join(''));}
aContents.push('</span>');aContents.push('<hr>');var b=document.createElement('span');b.className='inputgroup';b.innerHTML=aContents.join('');this.Form.appendChild(b);}
{var e=document.createElement('span');e.innerHTML=['<input type="hidden" name="Action" value="Modify Record">','<input type="hidden" name="RecordId" value="',this.RecordId,'">'].join('');this.Form.appendChild(e);}
this.Form.elements.namedItem('information').rows=10;this.Form.elements.namedItem('information').id=this.Form.id+'information';this.Form.elements.namedItem('extendedinformation').rows=20;this.Form.elements.namedItem('extendedinformation').id=this.Form.id+'extendedinformation';this.Form.elements.namedItem('webpage').rows=30;this.Form.elements.namedItem('webpage').id=this.Form.id+'webpage';this.Form.action=['javascript: tinyMCE.execCommand(\"mceRemoveControl\", true, \'EditForm',this.RecordId,'information\');','javascript: tinyMCE.execCommand(\"mceRemoveControl\", true, \'EditForm',this.RecordId,'extendedinformation\');','javascript: tinyMCE.execCommand(\"mceRemoveControl\", true, \'EditForm',this.RecordId,'webpage\');','javascript: if(document.getElementById(\'',this.Parent.Id,'EditButton',this.RecordId,'\')){document.getElementById(\'',this.Parent.Id,'EditButton',this.RecordId,'\').style.display = \'\';}','javascript: ',this.Parent.Id,'.Apply(\'',this.RecordId,'\')'].join('');if(document.getElementById(this.Parent.Id+'EditButton'+this.RecordId)){document.getElementById(this.Parent.Id+'EditButton'+this.RecordId).style.display='none';}
if(this.Data['href']){this.Form.elements.namedItem('webpage').parentNode.parentNode.style.visibility='hidden';this.Form.elements.namedItem('webpage').parentNode.parentNode.style.height='1px'}
return this.Form;}
window.CMinistriesDbGui=function(Page){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CMinistriesDbGui.prototype=new CXDbGui();CMinistriesDbGui.prototype.constructor=CMinistriesDbGui;CMinistriesDbGui.superclass=CXDbGui.prototype;CMinistriesDbGui.prototype.Init=function(Page){CMinistriesDbGui.superclass.Init.apply(this,arguments);this.SortByField='ministry';this.aDisplayColumns=null;this.StaticRequestVars=[];}
CMinistriesDbGui.prototype._NewDataEntry=function(RecordId,Data){return new CMinistriesDbGuiEntry(RecordId,Data,this);}
CMinistriesDbGui.prototype.CategoryList=function(Category){this.SetActionTitle("Searching the database");var Element=document.getElementById('ActionContent');Element.innerHTML='';this.ShowLoadingPanel();this.ShowResultMessage(null);var oRequest=new AjaxCallback(this,'_SearchComplete');var PostData=[this.StaticRequestVars.join('&'),'ContentType=AjaxJs','Action=Search','MatchType=Contains','category='+escape(Utf8.encode(Category))].join('&');oRequest.Send(this.Page,PostData);}
CMinistriesDbGui.prototype.Render=function(){var Container=document.getElementById('ActionContent');Container.innerHTML='';var Element=document.createElement('span');var aContents=new Array();aContents.push("<b>Results: </b> "+this.Data['Results'].length);Element.innerHTML=aContents.join('');Container.appendChild(Element);var Message=this.Data['Message'];if(Message){Element=document.createElement('p');Element.innerHTML=Message;Container.appendChild(Element);}
var Form=document.createElement('form');Form.id='SearchResultsForm';Form.action='';Container.appendChild(Form);Form.innerHTML=this.HiddenFormInputsToHtml();if(this.Data['Results'].length){var eTable=document.createElement('table');eTable.id='SearchResults';eTable.className='SearchResults';this.RenderHeaders(eTable);Form.appendChild(eTable);{var aResults=this.Data['Results'];for(var iIndex in aResults){var Result=aResults[iIndex];Result.InsertInto(eTable);}}
var SearchResultActions=document.createElement('span');SearchResultActions.id="SearchResultsActions";Form.appendChild(SearchResultActions);}
if(this.Data['Results'].length==1){var aResults=this.Data['Results'];for(var iIndex in aResults){var Result=aResults[iIndex];Result.ToggleEntryExtendedInfo();}}}
CMinistriesDbGui.prototype.RenderHeaders=function(eTable){}
CMinistriesDbGuiEntry.prototype.InsertInto=function(Table,Index){if(!Table)return;this._InsertSummaryInto(Table,Index);if(this.ToInfoPanel){var RowElementId='ExtendedInfoRow'+this.RecordId;var Row=document.getElementById(RowElementId);if(Row){Index=Row.rowIndex;var t=Row.parentNode;while(t.nodeName!='TABLE')t=t.parentNode;t.deleteRow(Row.rowIndex);}else{if(Index){Index=Index+1;}else{Index=-1;}}
var Row=Table.insertRow(Index);Row.id=RowElementId;var Cell=Row.insertCell(-1);var SummaryRow=document.getElementById('Row'+this.RecordId);Cell.colSpan=SummaryRow.cells.length;Cell.appendChild(this._GetExtendedInfo());this.HideLoadingPanel();}}
CMinistriesDbGuiEntry.prototype._InsertSummaryInto=function(Table,Index){if(!Table)return;var RowElementId='Row'+this.RecordId;var Row=document.getElementById(RowElementId);if(Row){Index=Row.rowIndex;var t=Row.parentNode;while(t.nodeName!='TABLE')t=t.parentNode;t.deleteRow(Row.rowIndex);}else{if(!Index)Index=-1}
var Row=Table.insertRow(Index);Row.id='Row'+this.RecordId;Row.className="EntrySummaryInfo";var iRowsPerEntry=(this.ToInfoPanel?2:1);if(Math.floor(Table.rows.length/iRowsPerEntry)%2){}
{var e=Row.insertCell(-1);e.className="EntrySummaryActions EntrySummaryRegion";if(this.ToInfoPanel){if(MinistriesDbGui.bAdministrator||this.Data['canedit']==1){e.innerHTML=this._GetExpansionControlHtml();}}else{if(this.Parent.HeaderRows==-1){this.Parent.HeaderRows=Row.rowIndex-1;}
e.innerHTML=Row.rowIndex-this.Parent.HeaderRows;}
for(var iIndex in this.Parent.aResultInputs){var e=Row.insertCell(-1);e.innerHTML=this.Parent.aResultInputs[iIndex].ToHtml(this.Parent,this.RecordId,'',this.Data);}
for(var iIndex in this.Parent.aResultActions){var e=Row.insertCell(-1);if(MinistriesDbGui.bAdministrator||this.Data['canedit']==1){e.innerHTML=['<input class="ActionButton" type="button" value="Edit" ',' id="',this.Parent.Id,'EditButton',this.RecordId,'"',' onclick="',this.Parent.Id,'.Edit(\'',this.RecordId,'\')"/>',].join('');}}}
this.InsertSummaryIntoRow(Row);}
CMinistriesDbGuiEntry.prototype.InsertSummaryIntoRow=function(Row){var e=Row.insertCell(-1);aContents=[];aContents.push("<img style='float: left; margin-top: 18px; margin-right: 10px;' height='140px' width='140px' src='/image/ministries/");if(this.Data['icon']){aContents.push("buttons/"+this.Data['image']);}else{aContents.push("default.jpg")}
aContents.push("' alt='");aContents.push(htmlspecialchars(this.Data['ministry']));aContents.push("'>");aContents.push("<div style='margin-left: 150px;'>");aContents.push("<h3><a href='/ministries/summary/"+this.RecordId+"/'>");aContents.push(htmlspecialchars(this.Data['ministry']));aContents.push("</a></h3>");if(this.Data['director']){aContents.push("<p><strong>Ministry Leader: ");}else{aContents.push("<p><strong>Organizer: ");}
aContents.push(htmlspecialchars(this.Data['leader']));aContents.push("</strong><br/>");if(this.Data['director']){aContents.push("<strong>Director Responsible: ");aContents.push(htmlspecialchars(this.Data['director']));aContents.push("</strong><br/>");}
aContents.push(htmlspecialchars(this.Data['information']));aContents.push("</p>");aContents.push("<p>Contact: ");if(this.Data['email']){aContents.push("<a href='mailto:");aContents.push(htmlspecialchars(this.Data['email']));aContents.push("'>");aContents.push(htmlspecialchars(this.Data['email']));aContents.push("</a>");}else if(this.Data['mailname']){aContents.push("<a href='mailto:");aContents.push(htmlspecialchars(this.Data['mailname']));aContents.push("@leaders.carrubbers.org");aContents.push("'>");aContents.push(htmlspecialchars(this.Data['mailname']));aContents.push("@leaders.carrubbers.org");aContents.push("</a>");}else{aContents.push("<a href='mailto:office@carrubbers.org'>");aContents.push("office@carrubbers.org</a>");}
aContents.push("</p>");if(this.Data['extendedinformation']||this.Data['webpage']){aContents.push("<p>");}
if(this.Data['extendedinformation']){aContents.push("<a id='ExtendedInfoLink"+this.RecordId+"' href='javascript:");aContents.push(this.Parent.Id+".ToggleEntryExtendedInfo("+this.RecordId+")");aContents.push("'>more information...</a><br/>");}
if(this.Data['href']){aContents.push("<a href='"+this.Data['href']+"'>view ministry webpages...</a><br/>");}else if(this.Data['webpage']){aContents.push("<a href='/ministries/detail/"+this.RecordId+"/'>view ministry webpage...</a><br/>");}
if(this.Data['extendedinformation']||this.Data['webpage']){aContents.push("</p>");}
aContents.push("</div>");e.innerHTML=aContents.join('');return;}
CMinistriesDbGuiEntry.prototype.ToggleEntryExtendedInfo=function(){var PanelName='ExtendedInfo'+this.RecordId;var oPanel=document.getElementById(PanelName);if(!oPanel)return;if(oPanel.style.display=='none'){this.ShowEntryExtendedInfo();}else{this.HideEntryExtendedInfo();}}
CMinistriesDbGuiEntry.prototype.ShowEntryExtendedInfo=function(){if(!this.Cancel())return;var PanelName='ExtendedInfo'+this.RecordId;var ImageName='ExtendedInfoIndicator'+this.RecordId;var LinkName='ExtendedInfoLink'+this.RecordId;var oPanel=document.getElementById(PanelName);if(!oPanel)return;var oImage=document.getElementById(ImageName);var oLink=document.getElementById(LinkName);if(oPanel.style.display=='none'){oPanel.style.display='';if(oLink){oLink.innerHTML="hide additional information...";}
if(oImage){oImage.src=s_CXDbGuiEntryStaticData.ShowImage.src;}}}
CMinistriesDbGuiEntry.prototype.HideEntryExtendedInfo=function(){if(!this.Cancel())return;var PanelName='ExtendedInfo'+this.RecordId;var ImageName='ExtendedInfoIndicator'+this.RecordId;var LinkName='ExtendedInfoLink'+this.RecordId;var oPanel=document.getElementById(PanelName);if(!oPanel)return;var oImage=document.getElementById(ImageName);var oLink=document.getElementById(LinkName);if(oPanel.style.display==''){if(oLink){oLink.innerHTML="more information...";}
oPanel.style.display='none';if(oImage){oImage.src=s_CXDbGuiEntryStaticData.HideImage.src;}}}
CMinistriesDbGuiEntry.prototype.Edit=function(){this.ShowEntryExtendedInfo();if(this.LoadingPanel){this.LoadingPanel.style.display='none';}
if(this.InfoPanel){this.InfoPanel.style.display='none';}
if(this.Form){this.Form.style.display='';}else{this.ExtendedInfo.appendChild(this.ToEditForm());}
tinyMCE.execCommand("mceAddControl",true,this.Form.id+'information');tinyMCE.execCommand("mceAddControl",true,this.Form.id+'extendedinformation');tinyMCE.execCommand("mceAddControl",true,this.Form.id+'webpage');}
CMinistriesDbGuiEntry.prototype.Cancel=function(){if(this.Form){if(!confirm('Are you sure you want to abandon your changes?  This action is not reversible!')){return false;}
tinyMCE.execCommand("mceRemoveControl",true,this.Form.id+'information');tinyMCE.execCommand("mceRemoveControl",true,this.Form.id+'extendedinformation');tinyMCE.execCommand("mceRemoveControl",true,this.Form.id+'webpage');if(document.getElementById(this.Parent.Id+'EditButton'+this.RecordId)){document.getElementById(this.Parent.Id+'EditButton'+this.RecordId).style.display='';}
this.Form.parentNode.removeChild(this.Form);this.Form=null;}
if(this.LoadingPanel){this.LoadingPanel.style.display='none';}
if(this.InfoPanel){this.InfoPanel.style.display='';}else if(this.ToInfoPanel){this.ExtendedInfo.appendChild(this.ToInfoPanel());}
return true;}
CMinistriesDbGui.prototype.ShowActionPanel=function(){CXDbGui.superclass.ShowActionPanel.apply(this,arguments);var p=document.getElementById('AddPanel');if(!p)return;if(p.style.display=='none'){tinyMCE.execCommand("mceRemoveControl",true,'EditForm0information');tinyMCE.execCommand("mceRemoveControl",true,'EditForm0extendedinformation');tinyMCE.execCommand("mceRemoveControl",true,'EditForm0webpage');this.AddFormEntry.Form.parentNode.removeChild(this.AddFormEntry.Form);this.AddFormEntry.Form=null;return;}
if(!this.Id)return;if(!this.AddFormEntry){this.AddFormEntry=this._NewDataEntry(0,{});}
this.AddFormEntry.ExtendedInfo=p;this.AddFormEntry.Edit();}
