
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.CAddressLinesControl=function(AddressLines){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CAddressLinesControl.prototype=new Object();CAddressLinesControl.prototype.constructor=CAddressLinesControl;CAddressLinesControl.superclass=Object.prototype;CAddressLinesControl.prototype.Init=function(AddressLines){this.Data=AddressLines;this.Children=null;this.IdsByAddressLine=null;}
CAddressLinesControl.prototype.GetChildren=function(){if(this.Children)return this.Children;this.Children=new Array();for(var AddressLineId in this.Data){var aAddress=this.Data[AddressLineId];if(!aAddress.parentid)continue;var parentid=aAddress.parentid;if(!this.Children[parentid]){this.Children[parentid]=new Array();}
this.Children[parentid].push(AddressLineId);}
return this.Children;}
CAddressLinesControl.prototype.GetIdsByAddressLine=function(){if(this.IdsByAddressLine)return;this.IdsByAddressLine=new Array();for(var AddressLineId in this.Data){var aAddress=this.Data[AddressLineId];if(!this.IdsByAddressLine[aAddress.line])
this.IdsByAddressLine[aAddress.line]=[];this.IdsByAddressLine[aAddress.line].push(AddressLineId);}
return this.IdsByAddressLine;}
CAddressLinesControl.prototype.UpdateAddressLines=function(Deleted,Added){if(Deleted){for(var iIndex in Deleted){var AddressLineId=Deleted[iIndex];delete this.Data[AddressLineId];}
this.Children=null;this.IdsByAddressLine=null;}
if(Added){for(var AddressLineId in Added){this.Data[AddressLineId]=Added[AddressLineId];}
this.Children=null;this.IdsByAddressLine=null;}}
CAddressLinesControl.prototype.GetAddressLines=function(AddressLineId){var aAddressLines=new Array();LineId=AddressLineId;while(LineId){var Line=this.Data[LineId];if(!Line)break;aAddressLines.push(Line.line);LineId=Line.parentid;}
return aAddressLines;}
CAddressLinesControl.prototype.CompactAddressLines=function(Form,AddressLinesInput,ParentIdInput){this.GetIdsByAddressLine();var aAddressLines=Form.elements[AddressLinesInput].value.split('\n');{var aCleanedAddressLines=[];for(var iAddressLine=0;iAddressLine<aAddressLines.length;iAddressLine++){var AddressLine=aAddressLines[iAddressLine];var CleanedAddressLine=AddressLine.replace(/^\s*(.*[^\s,])[\s,]*$/,"$1");if(CleanedAddressLine=='')continue;aCleanedAddressLines.push(CleanedAddressLine);}
aAddressLines=aCleanedAddressLines;}
var ParentAddressLineId=null;while(aAddressLines.length){var AddressLine=aAddressLines[aAddressLines.length-1];AddressLine=AddressLine.replace(/^\s*(.*[^\s,])[\s,]*$/,"$1");var aAddressLineIds=this.IdsByAddressLine[AddressLine];if(!aAddressLineIds)break;var AddressLineId=null
for(var iAddressLineIndex=0;iAddressLineIndex<aAddressLineIds.length;iAddressLineIndex++){if(this.Data[aAddressLineIds[iAddressLineIndex]].parentid==ParentAddressLineId){AddressLineId=aAddressLineIds[iAddressLineIndex];break;}}
if(!AddressLineId)break;aAddressLines.pop();ParentAddressLineId=AddressLineId;}
if(ParentAddressLineId==null)ParentAddressLineId='';Form.elements[AddressLinesInput].value=aAddressLines.join('\n');Form.elements[ParentIdInput].value=ParentAddressLineId;}
CAddressLinesControl.prototype.ExpandAddressLines=function(Form,AddressLinesInput,ParentIdInput){var aAddressLines=new Array();if(Form.elements[AddressLinesInput].value!=''){aAddressLines.push(Form.elements[AddressLinesInput].value);}
ParentAddressLineId=Form.elements[ParentIdInput].value;while(ParentAddressLineId){var AddressLine=this.Data[ParentAddressLineId];aAddressLines.push(AddressLine.line);ParentAddressLineId=AddressLine.parentid;}
Form.elements[AddressLinesInput].value=aAddressLines.join('\n');}
CAddressLinesControl.prototype.Search=function(SearchRegExp){var aParentAddressLineIds=new Array();for(var AddressLineId in this.Data){var aAddress=this.Data[AddressLineId];var Line=new String(aAddress.line);if(Line.search(SearchRegExp)!=-1){aParentAddressLineIds.push(AddressLineId);}}
var aAddressLines=new Array();while(aParentAddressLineIds.length){var AddressLineId=aParentAddressLineIds.pop();if(aAddressLines[AddressLineId])continue;aAddressLines[AddressLineId]=AddressLineId;var AddressLineChildren=this.GetChildren()
var aChildren=AddressLineChildren[AddressLineId];for(var iIndex in aChildren){var ChildId=aChildren[iIndex];if(aAddressLines[ChildId])continue;aParentAddressLineIds.push(ChildId);}}
return aAddressLines;}
CAddressLinesControl.prototype.AttributeSearch=function(SearchRegExp,ValueFunc){var aAddressLines=new Array();for(var AddressLineId in this.Data){var aAddressLine=this.Data[AddressLineId];if(!ValueFunc(aAddressLine))continue;var Value=new String(ValueFunc(aAddressLine));Value=Value.replace(/[ \t]/g,"");if(Value.search(SearchRegExp)!=-1){aAddressLines[AddressLineId]=AddressLineId;}}
return aAddressLines;}
CAddressLinesControl.prototype.OnComplete=function(Control,KeyName){var Lines=Control.value.split('\n');var FirstLine=Lines[0].replace(/^\s*([^\s].*[^\s])\s*$/,"$1");for(var AddressLineId in this.Data){var Address=this.Data[AddressLineId];if(Address.line==FirstLine){var AddressId=Control.name.substring(new String(KeyName).length);var Form=Control.form;if(Address.postcode){var PostCodeElement=Form.elements['postcode'+AddressId];if(!PostCodeElement.value.length){PostCodeElement.value=Address.postcode;}}
if(Address.landline){var LandLineElement=Form.elements['landline'+AddressId];if(!LandLineElement.value.length){LandLineElement.value=Address.landline;}}
break;}}}
CAddressLinesControl.prototype.AutoCompleteAddress=function(Control,CharCode){var Selection=Control.GetSelection();var SkipAutocompletion=(Selection.End<Control.value.length);Control.ReplaceSelection(String.fromCharCode(CharCode));if(SkipAutocompletion)return;var CurrentLine=new String(Control.value);var FixedContent='';if(Control.nodeName=='TEXTAREA'){var LastEOL=CurrentLine.lastIndexOf('\n');if(LastEOL>0){FixedContent=CurrentLine.substring(0,LastEOL+1);CurrentLine=CurrentLine.substring(LastEOL+1);}}
CurrentLine=CurrentLine.replace(/([\.\\\+\*\?\[\^\]\(\$\)])/g,"\\$1");var SearchRegExp=new RegExp("^"+CurrentLine,"i");for(var AddressLineId in this.Data){var Address=this.Data[AddressLineId];var AddressLine=new String(Address.line);if(AddressLine.search(SearchRegExp)!=-1){var iLen=Control.value.length;var aNewValue=[FixedContent,Address.line];if(Control.nodeName=='TEXTAREA'){while(Address.parentid){Address=this.Data[Address.parentid];aNewValue.push('\n');aNewValue.push(Address.line);}}
Control.value=aNewValue.join('');Control.Select(iLen,Control.value.length);return;}}}
CAddressLinesControl.prototype.AddAddressLines=function(Form,AddressLinesInput,ParentIdInput,Object,Method){var oRequest=new AjaxCallback(this,'Ignored');var Context=this;oRequest.Complete=function(){var NewAddressLines=eval(this.xmlhttp.responseText);if(typeof(NewAddressLines)!='object')return;Context.UpdateAddressLines(null,NewAddressLines);Context.ExpandAddressLines(Form,AddressLinesInput,ParentIdInput);Method.apply(Object,arguments);}
var AddressLines=Form.elements[AddressLinesInput].value;var ParentId=Form.elements[ParentIdInput].value;var PostData=['ContentType=AjaxJs','Action=AddAddressLines','Address='+escape(Utf8.encode(AddressLines)),'ParentId='+ParentId,].join('&');oRequest.Send('/contacts/index.php',PostData);}

window.CAddressBookAttribute=function(Data){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CAddressBookAttribute.prototype=new Object();CAddressBookAttribute.prototype.constructor=CAddressBookAttribute;CAddressBookAttribute.superclass=Object.prototype;CAddressBookAttribute.prototype.Init=function(Parent,Id,Name,Value){this.Parent=Parent;this.Id=Id;if(Name){this.Name=Name;}else{this.Name="Attribute Name";}
this.Value=Value?Value:'';this.AttributeNameString='AttributeName';this.AttributeIdString='AttributeId';this.AttributeValueString='AttributeValue';this.Key="Public"}
CAddressBookAttribute.prototype.ToInputControl=function(AttributeId){if(this.Id){var FieldId=new CField(this.AttributeIdString+AttributeId,this.Id);var FieldValue=new CField(this.AttributeValueString+AttributeId,this.Value);var Value=[FieldValue.ToInputControl(''),FieldId.ToInputControl(' type="hidden"')].join('');var FieldWithLabel={};FieldWithLabel=new CField(this.Parent.AttributeNames[this.Key][this.Id],Value,false);return FieldWithLabel.ToHtml();}
var ValueNameSelect=[];for(var Id in this.Parent.AttributeNames[this.Key]){var aOption=['<option value="',htmlspecialchars(Id),'">',htmlspecialchars(this.Parent.AttributeNames[this.Key][Id]),'</option>'];ValueNameSelect.push(aOption.join(''));}
var ValueName='';var ValueField='';var IdFieldName='';ValueName=new CField(this.AttributeNameString+AttributeId,this.Name?this.Name:this.Name);ValueField=new CField(this.AttributeValueString+AttributeId,this.Value);return['<span class="inputgroup">','<span class="inputlabel">','<select name="',this.AttributeIdString,AttributeId,'"',' onchange="return AddressBookGui.OnChangeAttributeSelection(this, ',AttributeId,');">',ValueNameSelect.join(''),'<option value="0">Other...</option>','</select>',ValueName.ToInputControl(' style="display:none"'),'</span>','<span class="inputcontrol">',ValueField.ToInputControl(''),'</span>','</span>'].join('');}
window.CPublicAddressBookAttribute=function(Data){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CPublicAddressBookAttribute.prototype=new CAddressBookAttribute();CPublicAddressBookAttribute.prototype.constructor=CPublicAddressBookAttribute;CPublicAddressBookAttribute.superclass=CAddressBookAttribute.prototype;CPublicAddressBookAttribute.prototype.Init=function(Parent,Id,Name,Value){CPublicAddressBookAttribute.superclass.Init.apply(this,arguments);if(Name){this.Name=Name;}else{this.Name="Public Attribute Name";}
this.AttributeNameString='AttributeName';this.AttributeIdString='AttributeId';this.AttributeValueString='AttributeValue';this.Key="Public"}
CPublicAddressBookAttribute.prototype.ToInputControl=function(AttributeId){return CPublicAddressBookAttribute.superclass.ToInputControl.apply(this,arguments);}
window.CPrivateAddressBookAttribute=function(Data){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CPrivateAddressBookAttribute.prototype=new CAddressBookAttribute();CPrivateAddressBookAttribute.prototype.constructor=CPrivateAddressBookAttribute;CPrivateAddressBookAttribute.superclass=CAddressBookAttribute.prototype;CPrivateAddressBookAttribute.prototype.Init=function(Parent,Id,Name,Value){CPrivateAddressBookAttribute.superclass.Init.apply(this,arguments);if(Name){this.Name=Name;}else{this.Name="Admin Attribute Name";}
this.AttributeNameString='AdminAttributeName';this.AttributeIdString='AdminAttributeId';this.AttributeValueString='AdminAttributeValue';this.Key="Private"}
CPrivateAddressBookAttribute.prototype.ToInputControl=function(AttributeId){return CPrivateAddressBookAttribute.superclass.ToInputControl.apply(this,arguments);}
window.CAddressBookEntry=function(Data){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CAddressBookEntry.prototype=new CXDbGuiEntry();CAddressBookEntry.prototype.constructor=CAddressBookEntry;CAddressBookEntry.superclass=CXDbGuiEntry.prototype;CAddressBookEntry.prototype.Init=function(UserId,Data,Parent){CAddressBookEntry.superclass.Init.apply(this,arguments);this.Title='';this.FirstName='';this.LastName='';this.DisplayName='';this.PhoneNumber='';this.Email='';}
CAddressBookEntry.prototype.ToggleEntryExtendedInfo=function(){CAddressBookEntry.superclass.ToggleEntryExtendedInfo.apply(this,arguments);var e=document.getElementById(this.Parent.Id+'Details'+this.RecordId);if(!e)return;if(this.ExtendedInfo.style.display=='none'){e.style.borderStyle='';}else{e.style.borderStyle='inset';}}
CAddressBookEntry.prototype.InsertSummaryIntoRow=function(Row){{var e=Row.insertCell(-1);e.className="EntrySummaryName EntrySummaryRegion";if(this.DisplayName){e.innerHTML=this.DisplayName;}}
{var e=Row.insertCell(-1);e.className="EntrySummaryContactDetails";if(this.PhoneNumber){e.innerHTML='<span class="EntrySummaryRegion">'+htmlspecialchars(this.PhoneNumber)+'</span>';}}
{var e=Row.insertCell(-1);e.className="EntrySummaryContactDetails";e.style.textAlign='right';if(this.Email){e.innerHTML='<a class="EntrySummaryRegion" href="mailto:'+htmlspecialchars(this.Email)+'">'+htmlspecialchars(this.Email)+'</a>';}}}
window.CGroupAddressBookEntry=function(){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CGroupAddressBookEntry.prototype=new CAddressBookEntry();CGroupAddressBookEntry.prototype.constructor=CGroupAddressBookEntry;CGroupAddressBookEntry.superclass=CAddressBookEntry.prototype;CGroupAddressBookEntry.prototype.Init=function(UserId,Data,Parent){CGroupAddressBookEntry.superclass.Init.apply(this,arguments);this.FirstName=this.Data.FirstName;this.LastName=this.Data.LastName;this.DisplayName=this.FirstName+' '+this.LastName;this.Email=this.Data.FirstName+'@'+this.Data.LastName+'.'+this.Parent.MailDomain;this.Desc=this.Data.Desc;}
CGroupAddressBookEntry.prototype.ToInfoPanel=function(){if(this.InfoPanel)return this.InfoPanel;var e=document.createElement('span');e.id='InfoPanel'+this.RecordId;var aContents=new Array();var aFields=[new CField('Name',this.DisplayName),new CField('Description',this.Desc),new CField('Email','<a href="mailto:'+this.Email+'">'+this.Email+'</a>')];for(var iIndex in aFields){var Field=aFields[iIndex];if(!Field.Value)continue;var f=document.createElement('span');f.className='inputgroup';var aContent=new Array();aContent.push('<span class="inputlabel">'+htmlspecialchars(Field.Name)+':</span>');aContent.push('<span class="inputcontrol">'+Field.Value+'</span>');f.innerHTML=aContent.join('');e.appendChild(f);}
this.InfoPanel=e;return e;}
window.CIndividualAddressBookEntry=function(){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CIndividualAddressBookEntry.prototype=new CAddressBookEntry();CIndividualAddressBookEntry.prototype.constructor=CIndividualAddressBookEntry;CIndividualAddressBookEntry.superclass=CAddressBookEntry.prototype;CIndividualAddressBookEntry.prototype.Init=function(UserId,Data,Parent){CIndividualAddressBookEntry.superclass.Init.apply(this,arguments);this.NewAddressCount=0;this.NewAttributeCount=[];this.NewAttributeCount['Public']=0;this.NewAttributeCount['Private']=0;this.Title=this.Data.title||'';this.FirstName=this.Data.FirstName||'';this.LastName=this.Data.LastName||'';var aContents=new Array();aContents.push(this.Data.title);aContents.push(this.Data.FirstName);aContents.push(this.Data.LastName);this.DisplayName=aContents.join(' ');this.Email=this.Data.Email;this.PhoneNumber=this.Data.mphone||(this.Data.landline||'');}
CIndividualAddressBookEntry.prototype._ToAddressElement=function(AddressLineId){var f=document.createElement('span');f.className='inputgroup';var TopLine=this.Parent.AddressLines[AddressLineId];var aContent=new Array();aContent.push('<span class="inputlabel">');if(AddressLineId==this.Data.prefaddresslineid){aContent.push(htmlspecialchars('Preferred '));}
aContent.push(htmlspecialchars('Address'));if(TopLine.postcode){aContent.push(' (<a href="http://maps.google.co.uk/maps?q='+htmlspecialchars(TopLine.postcode)+'">Map</a>)');}
aContent.push(':</span>');aContent.push('<span class="inputcontrol">');aContent.push(this.Parent.AddressLinesControl.GetAddressLines(AddressLineId).join('<br>'));if(TopLine.postcode){aContent.push('<br>');aContent.push(TopLine.postcode);}
aContent.push('</span>');if(TopLine.landline){aContent.push('<span class="inputlabel">'+htmlspecialchars('Landline')+':</span>');aContent.push('<span class="inputcontrol">'+htmlspecialchars(TopLine.landline)+'</span>');}
f.innerHTML=aContent.join('');return f;}
CIndividualAddressBookEntry.prototype.GetAddressIds=function(){if(!this.Form)return new Array();var AddressIds=new Array();var SearchRegExp=/^Address(\d*)$/;for(var iIndex=0;iIndex<this.Form.elements.length;iIndex++){var InputElement=this.Form.elements[iIndex];var Name=new String(InputElement.name);if(Name.search(SearchRegExp)==-1)continue;var AddressId=Name.replace(SearchRegExp,"$1");AddressIds.push(parseInt(AddressId));}
return AddressIds;}
CIndividualAddressBookEntry.prototype._AddAddressEditRow=function(Table,AddressLineId,RowIndex){var AddressId=this.NewAddressCount;this.NewAddressCount++;if(!RowIndex){RowIndex=Table.rows.length;}
var r=Table.insertRow(RowIndex);r.id='AddressIdRow'+AddressId;{var c=r.insertCell(-1);c.style.backgroundColor="#cccccc";c.innerHTML=['<button onclick="',this.Parent.Id,".DeleteAddress(",this.RecordId,",'",AddressId,'\')">','Delete</button>',].join('');}
{var c=r.insertCell(-1);c.className='AddressFormCell';var aContents=new Array();Field=new CField('AddressId'+AddressId,0);aContents.push(Field.ToInputControl('type="hidden"'));var Field=new CField('Address'+AddressId,this.Parent.AddressLinesControl.GetAddressLines(AddressLineId).join('\n'),false);var TextArea=Field.ToTextArea(['rows="5" ','cols="30" ','onkeypress="return AddressBookGui.OnAutoCompleteAddress(this, event);" ','onblur="return AddressBookGui.OnCompleteAddress(this,\'Address\')"'].join(''));var FieldWithLabel=new CField('Address',TextArea,false);aContents.push(FieldWithLabel.ToHtml());var TopLine=new Object();if(AddressLineId){TopLine=this.Parent.AddressLines[AddressLineId];}
Field=new CField('postcode'+AddressId,TopLine.postcode);var FieldWithLabel=new CField('Postcode',Field.ToInputControl(''),false);aContents.push(FieldWithLabel.ToHtml());Field=new CField('landline'+AddressId,TopLine.landline);var FieldWithLabel=new CField('Landline',Field.ToInputControl(''),false);aContents.push(FieldWithLabel.ToHtml());c.innerHTML=aContents.join('');}
{var c=r.insertCell(-1);c.className='AddressFormCell';c.style.width='150px';var id=['Preferred','-',this.RecordId,'-',AddressId].join('');c.innerHTML=['<input type="radio" name="PreferredAddressId" ','id="',id,'" ','value="',AddressId,'" ',this.Data.prefaddresslineid==AddressLineId?'checked ':'','>','<label for="',id,'">Preferred</label>'].join('');}}
CIndividualAddressBookEntry.prototype.AddAddress=function(){var e=document.getElementById('AddAnotherAddressButton'+this.RecordId);if(!e)return;while(e.nodeName!='TR')e=e.parentNode;var r=e;while(e.nodeName!='TABLE')e=e.parentNode;var t=e;this._AddAddressEditRow(t,null,r.rowIndex);}
CIndividualAddressBookEntry.prototype.DeleteAddress=function(AddressId){var t=document.getElementById("EditFormTable"+this.RecordId);if(!t)return;for(var iRowIndex=0;iRowIndex<t.rows.length;iRowIndex++){var r=t.rows[iRowIndex];if(r.id==('AddressIdRow'+AddressId)){t.deleteRow(iRowIndex);return;}}}
CIndividualAddressBookEntry.prototype.AddAttribute=function(e,Admin){while(e.nodeName!='TD')e=e.parentNode;var n=e.lastChild;while(n.nodeName!='SPAN')n=n.previousSibling;if(Admin){var BlankAttribute=new CPrivateAddressBookAttribute(this.Parent,0,"","");n.innerHTML=BlankAttribute.ToInputControl(this.NewAttributeCount['Private']);this.NewAttributeCount['Private']++;}else{var BlankAttribute=new CPublicAddressBookAttribute(this.Parent,0,"","");n.innerHTML=BlankAttribute.ToInputControl(this.NewAttributeCount['Public']);this.NewAttributeCount['Public']++;}
e.appendChild(n);{var n=document.createElement('span');var aValue=['<button onclick="',this.Parent.Id,'.AddAttribute(this,\'',this.RecordId,'\', ',(Admin?'true':'false'),,');return false;">','Add Another...</button>'];if(Admin){var Field=new CField('Admin Attribute',aValue.join(''),false);n.innerHTML=Field.ToHtml(' id="AddAnotherAdminAttributeButton'+this.RecordId+'"');}else{var Field=new CField('Attribute',aValue.join(''),false);n.innerHTML=Field.ToHtml(' id="AddAnotherAttributeButton'+this.RecordId+'"');}
e.appendChild(n);}}
CIndividualAddressBookEntry.prototype._GetSpouseField=function(){if(!this.Data.spouseid)return new CField('Spouse','');var SpouseValue='';var aContents=new Array();aContents.push(this.Parent.Id);aContents.push(".Search('");aContents.push("@RecordId="+this.Data.spouseid);aContents.push("')");var Link=aContents.join('');aContents=new Array();aContents.push('<a href="javascript:');aContents.push(Link);aContents.push('">');aContents.push(htmlspecialchars(this.Data.spousename));aContents.push('</a>');return new CField('Spouse',aContents.join(''),false);}
CIndividualAddressBookEntry.prototype._AttributeLookupComplete=function(oRequest){var Attributes=eval(oRequest.responseText);if(typeof(Attributes)=='object'){this.Data.Attributes=Attributes;this.Cancel();}}
CIndividualAddressBookEntry.prototype.ToInfoPanel=function(){if(this.InfoPanel)return this.InfoPanel;if(typeof(this.Data.Attributes)=='undefined'){var oRequest=new AjaxCallback(this,'_AttributeLookupComplete');var PostData=['ContentType=AjaxJs','Action=AttributeLookup','RecordId='+this.RecordId,'AdminLookup=0',].join('&');this.ShowLoadingPanel();oRequest.Send(this.Parent.Page,PostData);return document.createTextNode(' ');}
var e=document.createElement('span');e.id="InfoPanel"+this.RecordId;{var aContents=new Array();var IdField=new CField('User Id',['<a href="/users/users.php?Action=View Record&RecordId=',this.RecordId,'">',this.RecordId,'</a>'].join(''),false);var aFields=[this.Parent.UserIsAdmin?IdField:{},new CField('Name',[this.Data.title,this.Data.FirstName,this.Data.LastName].join(' ')),new CField('Date of Birth',this.Data.datebirth),this._GetSpouseField(),new CField('Mobile Phone',this.Data.mphone),new CField('Last Modified',this.Data.datemodified)];for(var iIndex in aFields){var Field=aFields[iIndex];if(!Field.Value)continue;aContents.push(Field.ToHtml());}
var f=document.createElement('span');f.innerHTML=aContents.join('');e.appendChild(f);}
{var aContents=[];for(var AttributeId in this.Data.Attributes['Public']){var Name=this.Parent.AttributeNames['Public'][AttributeId];var Value=this.Data.Attributes['Public'][AttributeId];var Field=null;switch(Name){case'Yahoo! Messenger':Value=['<a href="http://profiles.yahoo.com/',htmlspecialchars(Value),'">View Profile</a>'].join('');Field=new CField(Name,Value,false);break;case'Facebook':Value=['<a href="http://www.facebook.com/profile.php?id=',htmlspecialchars(Value),'">View Profile</a>'].join('');Field=new CField(Name,Value,false);break;case'Linked In':Value=['<a href="http://www.linkedin.com/profile?viewProfile=&key=',htmlspecialchars(Value),'">View Profile</a>'].join('');Field=new CField(Name,Value,false);break;default:Field=new CField(Name,Value);}
aContents.push(Field.ToHtml());}
if(aContents.length){var a=document.createElement('span');a.innerHTML=aContents.join('');e.appendChild(a);}}
{var aContents=[];for(var AttributeId in this.Data.Attributes['Private']){var Name=this.Parent.AttributeNames['Private'][AttributeId];var Value=this.Data.Attributes['Private'][AttributeId];var Field=new CField(Name,Value);aContents.push(Field.ToHtml());}
if(aContents.length){var a=document.createElement('span');a.innerHTML=aContents.join('');a.style.borderWidth=3;e.appendChild(a);}}
if(this.Data.prefaddresslineid){var aAddressLineIds=this.Parent.GetAddresses(this.RecordId);for(var iIndex in aAddressLineIds){var AddressInfo=aAddressLineIds[iIndex];var AddressLineId=AddressInfo.addresslineid;e.appendChild(this._ToAddressElement(AddressLineId));}}
if(this.Parent.UserIsAdmin||this.RecordId==this.Parent.UserId){var b=document.createElement('span');b.className='inputgroup';b.innerHTML=['<span class="inputcontrol">','<button onclick="',this.Parent.Id,'.Edit(\'',this.RecordId,'\')">','Edit</button>','</span>',].join('');e.appendChild(b);}
this.InfoPanel=e;return e;}
CIndividualAddressBookEntry.prototype.ToEditForm=function(){if(this.Form)return this.Form;var t=document.createElement('table');t.id="EditFormTable"+this.RecordId;var r=t.insertRow(-1);var c=r.insertCell(-1);c=r.insertCell(-1);c.colSpan=2;{var aContents=new Array();var TitleField=new CField('Title',new CField('title',this.Data.title).ToInputControl(''),false);aContents.push(TitleField.ToHtml());{var Value=[htmlspecialchars(this.Data.FirstName),' ',htmlspecialchars(this.Data.LastName),' ','<span style="font-size:9pt">(<a href="/users/" target="_blank">Edit...</a>)</span>'].join('');var Field=new CField('Name',Value,false);aContents.push(Field.ToHtml());}
{var Value=[this.Parent.RadioButtonToHtml('Male'+this.RecordId,'gender','1',this.Data,'Male'),this.Parent.RadioButtonToHtml('Female'+this.RecordId,'gender','0',this.Data,'Female'),this.Parent.RadioButtonToHtml('UnspecifiedGender'+this.RecordId,'gender','-1',{'gender':!this.Data.gender?-1:''},'Unspecified'),].join('');var Field=new CField('Gender',Value,false);aContents.push(Field.ToHtml());}
{var Control=new CField('Date of Birth',this.Data.datebirth?this.Data.datebirth:"YYYY-MM-DD");var aValue=['<input name="Date of Birth" value="',this.Data.datebirth?this.Data.datebirth:"YYYY-MM-DD",'" onblur="return AddressBookGui.OnCompleteDateOfBirth(this,',this.RecordId,');"','>'];aValue.push(['<span id="Over18',this.RecordId,'"',(this.Data.datebirth?'style="display:none" ':''),'>','<input type="checkbox" name="Over18Checkbox" id="Over18Checkbox',this.RecordId,'" ',(this.Data.userinfoid?'checked ':''),'" onchange="return AddressBookGui.TogglePanel(\'UnderAgeError',this.RecordId,'\');"','>','<label for="Over18Checkbox',this.RecordId,'">',htmlspecialchars(this.Data.FirstName),' is over 18.</label>','</span>'].join(''));aValue.push(['<span id="UnderAgeError',this.RecordId,'" class="FormatWarning" ',(this.Data.userinfoid?'style="display:none"':''),,'>','We will only permit additional information to be added about people who are over 18.</span>','<span id="datebirthformaterror',this.RecordId,'" style="display:none;" class="FormatWarning">','Invalid date format.  Must be YYYY-MM-DD.</span>'].join(''));var Field=new CField('Date of Birth',aValue.join(''),false);aContents.push(Field.ToHtml())}
{var Value=['<input name="spousename" value="',this.Data.spousename,'"',' onblur="return AddressBookGui.OnCompleteSpouse(this,',this.RecordId,');"','>','<input name="spouseid" value="',this.Data.spouseid,'" type="hidden">','<span id="SpouseUnknownError',this.RecordId,'" style="display:none;" class="FormatWarning">','We don\'t know anyone by that name, your spouse must first be added to the address book before we can connect you.</span>','<span id="ChooseSpouseError',this.RecordId,'" style="display:none;" class="FormatWarning">','Please choose from one of the following:','<select name="SpouseChooser" onchange="return AddressBookGui.OnSelectSpouse(this, ',this.RecordId,')"></select>','</span>'].join('');var Field=new CField('Spouse',Value,false);aContents.push(Field.ToHtml())}
var aFields=[new CField('Mobile Phone',this.Data.mphone)];for(var iIndex in aFields){var Field=aFields[iIndex];var FieldWithLabel=new CField(Field.Name,Field.ToInputControl(''),false);aContents.push(FieldWithLabel.ToHtml());}
{var EmailAddress=htmlspecialchars(this.Data.Email);var Value=['<a href="mailto:',EmailAddress,'">',EmailAddress,'</a> ','<span style="font-size:9pt">(<a href="/users/" target="_blank">Edit...</a>)</span>'].join('');var Field=new CField('Email Address',Value,false);aContents.push(Field.ToHtml());}
c.innerHTML=aContents.join('');}
{var aAttributeTypes=new Array("Public","Private");for(var i=0;i<aAttributeTypes.length;i++){Key=aAttributeTypes[i];if(Key=="Private"&&!this.Parent.UserIsAdmin){continue;}
r=t.insertRow(-1);c=r.insertCell(-1);c.className='DarkShadedCell';c=r.insertCell(-1);c.colSpan=2;c.className='AttributeCell';c.id=(Key=="Private"?"AdminAttributes"+this.RecordId:"Attributes"+this.RecordId);admin=(Key=="Private"?true:false);var aContents=[];for(var AttributeId in this.Data.Attributes[Key]){var Number=this.NewAttributeCount[Key];this.NewAttributeCount[Key]++;if(admin){var A=new CPrivateAddressBookAttribute(this.Parent,AttributeId,'',this.Data.Attributes[Key][AttributeId]);}else{var A=new CPublicAddressBookAttribute(this.Parent,AttributeId,'',this.Data.Attributes[Key][AttributeId]);}
aContents.push(A.ToInputControl(Number));}
c.innerHTML=aContents.join('');c.appendChild(document.createElement('span'));this.AddAttribute(c,admin);}}
var aAddressLineIds=this.Parent.GetAddresses(this.RecordId);for(var iIndex in aAddressLineIds){var AddressInfo=aAddressLineIds[iIndex];var AddressLineId=AddressInfo.addresslineid;this._AddAddressEditRow(t,AddressLineId);}
r=t.insertRow(-1);c=r.insertCell(-1);c=r.insertCell(-1);{var aContents=['<button onclick="',this.Parent.Id,'.AddAddress(\'',this.RecordId,'\');return false;">','Add Another...</button>'];var Field=new CField('Address',aContents.join(''),false);var G=Field.ToReadOnlyElement();G.id="AddAnotherAddressButton"+this.RecordId;c.appendChild(G);}
r=t.insertRow(-1);c=r.insertCell(-1);c=r.insertCell(-1);{var b=document.createElement('span');b.className='inputgroup';b.innerHTML=['<span class="inputcontrol">','<button onclick="',this.Parent.Id,'.Apply(\'',this.RecordId,'\');return false;">','Apply</button>','<button onclick="',this.Parent.Id,'.Cancel(\'',this.RecordId,'\');return false;">','Cancel</button>','</span>',''].join('');c.appendChild(b);}
this.Form=document.createElement('form');this.Form.id="EditForm"+this.RecordId;this.Form.appendChild(t);{var e=document.createElement('span');e.innerHTML=['<input type="hidden" name="Action" value="Modify Record">','<input type="hidden" name="RecordId" value="',this.RecordId,'">','<input type="hidden" name="userinfoid" value="',this.Data.userinfoid,'">'].join('');this.Form.appendChild(e);}
return this.Form;}
CIndividualAddressBookEntry.prototype.Apply=function(){var Over18Checkbox=this.Form.elements['Over18Checkbox'];if(!Over18Checkbox.checked){alert(document.getElementById('UnderAgeError'+this.RecordId).innerHTML);Over18Checkbox.focus();return;}
this.ShowLoadingPanel();var AddressIds=this.GetAddressIds();for(var iIndex=0;iIndex<AddressIds.length;iIndex++){var AddressId=AddressIds[iIndex];this.Parent.AddressLinesControl.CompactAddressLines(this.Form,'Address'+AddressId,'AddressId'+AddressId);if(this.Form.elements['Address'+AddressId].value==''){this.Form.elements['Address'+AddressId].disabled=true;var ParentAddressLineId=this.Form.elements['AddressId'+AddressId].value;var AddressLine=this.Parent.AddressLines[ParentAddressLineId];var PostCode=this.Form.elements['postcode'+AddressId].value;if(PostCode==(AddressLine.postcode?AddressLine.postcode:'')){this.Form.elements['postcode'+AddressId].disabled=true;}
var LandLine=this.Form.elements['landline'+AddressId].value;if(LandLine==(AddressLine.landline?AddressLine.landline:'')){this.Form.elements['landline'+AddressId].disabled=true;}}}
if(this.Form.elements['Date of Birth'].value=="YYYY-MM-DD"){this.Form.elements['Date of Birth'].disabled=true;}
this.Form.elements['spousename'].disabled=true;this.Form.elements['SpouseChooser'].disabled=true;var aAttributeTypes=new Array("Public","Private");for(var i=0;i<aAttributeTypes.length;i++){Key=aAttributeTypes[i];sIdString=(Key=="Private"?"AdminAttributeId":"AttributeId");sNameString=(Key=="Private"?"AdminAttributeName":"AttributeName");sValueString=(Key=="Private"?"AdminAttributeValue":"AttributeValue");for(var iIndex=0;iIndex<this.NewAttributeCount[Key];iIndex++){if(this.Form.elements[sValueString+iIndex].value==''){if(this.Form.elements[sNameString+iIndex]){this.Form.elements[sNameString+iIndex].disabled=true;}
this.Form.elements[sIdString+iIndex].disabled=true;this.Form.elements[sValueString+iIndex].disabled=true;continue;}
if(this.Form.elements[sIdString+iIndex].value!=0){if(this.Form.elements[sNameString+iIndex]){this.Form.elements[sNameString+iIndex].disabled=true;}}}}
var oRequest=new AjaxCallback(this,'_ModifyComplete');oRequest.RecordId=this.RecordId;var PostData=this.Parent.BuildPostData(this.Form,'Js');oRequest.Send(this.Parent.Page,PostData);}
CIndividualAddressBookEntry.prototype._ModifyComplete=function(oRequest){var ModifyResults=eval(oRequest.responseText);if(typeof(ModifyResults)!='object'){var AddressIds=this.GetAddressIds();for(var iIndex=0;iIndex<AddressIds.length;iIndex++){var AddressId=AddressIds[iIndex];this.Form.elements['landline'+AddressId].disabled=false;this.Form.elements['postcode'+AddressId].disabled=false;this.Form.elements['Address'+AddressId].disabled=false;this.Parent.AddressLinesControl.ExpandAddressLines(this.Form,'Address'+AddressId,'AddressId'+AddressId);}
this.Form.elements['Date of Birth'].disabled=false;this.Form.elements['spousename'].disabled=false;this.Form.elements['SpouseChooser'].disabled=false;for(var iIndex=0;iIndex<this.NewAttributeCount['Public'];iIndex++){if(this.Form.elements['AttributeName'+iIndex]){this.Form.elements['AttributeName'+iIndex].disabled=false;}
this.Form.elements['AttributeId'+iIndex].disabled=false;this.Form.elements['AttributeValue'+iIndex].disabled=false;}
this.Edit();return;}
this.Parent.UpdateAddressLines(null,ModifyResults.NewAddressLines);this.Parent.UpdateAddressInfo(ModifyResults.DeletedAddressInfoLines,ModifyResults.NewAddressInfoLines);if(ModifyResults.NewAttributeNames){for(var AttributeId in ModifyResults.NewAttributeNames){this.Parent.AttributeNames['Public'][AttributeId]=ModifyResults.NewAttributeNames[AttributeId];}}
if(ModifyResults.NewAdminAttributeNames){for(var AdminAttributeId in ModifyResults.NewAdminAttributeNames){this.Parent.AttributeNames['Private'][AdminAttributeId]=ModifyResults.NewAdminAttributeNames[AdminAttributeId];}}
if(ModifyResults.Results&&ModifyResults.Results[this.RecordId]){this.Parent.Data['Results'][this.RecordId]=ModifyResults.Results[this.RecordId];this.Init(this.RecordId,ModifyResults.Results[this.RecordId],this.Parent);var Table=document.getElementById('SearchResults');this.InsertInto(Table);this.ToggleEntryExtendedInfo();}}

window.CAddressLineEntry=function(Data){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CAddressLineEntry.prototype=new CXDbGuiEntry();CAddressLineEntry.prototype.constructor=CAddressLineEntry;CAddressLineEntry.superclass=CXDbGuiEntry.prototype;CAddressLineEntry.prototype.Init=function(AddressLineId,Parent){CAddressLineEntry.superclass.Init.apply(this,arguments);}
CAddressLineEntry.prototype.ToggleEntryExtendedInfo=function(){CAddressLineEntry.superclass.ToggleEntryExtendedInfo.apply(this,arguments);var e=document.getElementById(this.Parent.Id+'Details'+this.RecordId);if(!e)return;if(this.ExtendedInfo.style.display=='none'){e.style.borderStyle='';}else{e.style.borderStyle='inset';}}
CAddressLineEntry.prototype.InsertSummaryIntoElement=function(Element){{var c=document.createElement('span');c.innerHTML=['<span style="padding-left:3px">','<a href="javascript:',this.Parent.Id,'.AddressSearch(\'',htmlspecialchars(this.Data.line),'\')">',this.Data.line,'</a>','</span>'].join('');Element.appendChild(c);}
if(this.Data.postcode){var c=document.createElement('span');c.innerHTML=['<span style="padding-left:3px">','(<a href="http://maps.google.co.uk/maps?q='+htmlspecialchars(this.Data.postcode)+'">map</a>)','</span>'].join('');Element.appendChild(c);}}
CAddressLineEntry.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){if(this.Parent.aResultActions[iIndex].Name=='Export')continue;aContents.push(this.Parent.aResultActions[iIndex].ToHtml(this.Parent,this.RecordId));}
e.innerHTML=aContents.join('');r.appendChild(e);}
this.InsertSummaryIntoElement(r);return r;}
CAddressLineEntry.prototype.ToInfoPanel=function(){if(this.InfoPanel)return this.InfoPanel;var e=document.createElement('span');e.id='InfoPanel'+this.RecordId;e.style.width='100%';e.style.display='block';var AddressLineChildren=this.Parent.AddressLinesControl.GetChildren();var aChildren=AddressLineChildren[this.RecordId];var aChildEntries=[];for(var iIndex in aChildren){var ChildId=aChildren[iIndex];var AddressLine=this.Parent.AddressLines[ChildId];var NewAddressLineEntry=new CAddressLineEntry(ChildId,AddressLine,this.Parent);aChildEntries.push(NewAddressLineEntry);this.Parent.Data['Results'].push(NewAddressLineEntry);}
{{var s=document.createElement('span');s.className='AddressLineExtendedInfo';var aContents=[];{Field=new CField('Address Line',this.Data.line);aContents.push(Field.ToHtml());var aFullAddress=this.Parent.AddressLinesControl.GetAddressLines(this.Data.parentid);if(this.Data.postcode){aFullAddress.push(this.Data.postcode);}
if(aFullAddress.length){Field=new CField('Located in',aFullAddress.join('<br>\n'),false);aContents.push(Field.ToHtml());}
if(this.Parent.UserIsAdmin){aContents.push(['<span class="inputgroup">','<span class="inputcontrol">','<button onclick="',this.Parent.Id,'.Edit(\'',this.RecordId,'\')">','Edit</button>','</span>','</span>'].join(''));}}
s.innerHTML=aContents.join('');e.appendChild(s);}
var Container=document.createElement('span');e.appendChild(Container);e.style.marginLeft='15px';e.style.borderLeft='thin solid black';e.style.paddingLeft='10px';e.id='SubAddressLines'+this.RecordId;if(aChildEntries.length){for(var iIndex in aChildEntries){var Result=aChildEntries[iIndex];Result.InsertIntoElement(Container);}}}
this.InfoPanel=e;return e;}
CAddressLineEntry.prototype.ToEditForm=function(){if(this.Form)return this.Form;this.Form=document.createElement('form');this.Form.id="EditForm"+this.RecordId;this.Form.className='AddressLineExtendedInfo';{var aContents=[];{var Field=new CField('AddressLineId',this.RecordId);aContents.push(Field.ToInputControl('type="hidden"'));var Field=new CField('line',this.Data.line);var FieldWithLabel=new CField('Address Line',Field.ToInputControl(''),false);aContents.push(FieldWithLabel.ToHtml());Field=new CField('ParentAddressLineId',this.Data.parentid);aContents.push(Field.ToInputControl('type="hidden"'));var Field=new CField('ParentAddressLines',this.Parent.AddressLinesControl.GetAddressLines(this.Data.parentid).join('\n'),false);var TextArea=Field.ToTextArea(['rows="5" ','cols="30" ','onkeypress="return AddressBookGui.OnAutoCompleteAddress(this, event);" '].join(''));var FieldWithLabel=new CField('Located in',TextArea,false);aContents.push(FieldWithLabel.ToHtml());}
var c=document.createElement('span');c.innerHTML=aContents.join('');this.Form.appendChild(c);}
{var b=document.createElement('span');b.className='inputgroup';b.innerHTML=['<input type="hidden" name="Action" value="Modify Address">','<span class="inputcontrol">','<button onclick="',this.Parent.Id,'.Apply(\'',this.RecordId,'\');return false;">','Apply</button>','<button onclick="',this.Parent.Id,'.Cancel(\'',this.RecordId,'\');return false;">','Cancel</button>','</span>',''].join('');this.Form.appendChild(b);}
return this.Form;}
CAddressLineEntry.prototype.Apply=function(){this.Parent.AddressLinesControl.CompactAddressLines(this.Form,'ParentAddressLines','ParentAddressLineId');var ParentId=this.Form.elements['ParentAddressLineId'].value;while(ParentId){if(ParentId==this.RecordId){alert('An Address Line can\'t be located inside itself.');this.Parent.AddressLinesControl.ExpandAddressLines(this.Form,'ParentAddressLines','ParentAddressLineId');return;}
ParentId=this.Parent.AddressLines[ParentId].parentid;}
if(this.Form.elements['ParentAddressLines'].value==''){this.Form.elements['ParentAddressLines'].disabled=true;}
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);}
CAddressLineEntry.prototype._ModifyComplete=function(oRequest){var ModifyResults=eval(oRequest.responseText);if(typeof(ModifyResults)!='object'){this.Form.elements['ParentAddressLines'].disabled=false;this.Parent.AddressLinesControl.ExpandAddressLines(this.Form,'ParentAddressLines','ParentAddressLineId');this.Edit();return;}
this.Parent.UpdateAddressLines(null,ModifyResults.NewAddressLines);{var NewData=ModifyResults.NewAddressLines[this.RecordId];if(NewData.parentid!=this.Data.parentid){this.Parent.AddressTree();}else{var iIndex=this.Parent._GetDataIndex(this.RecordId);this.Parent.Data['Results'][iIndex]=NewData;this.Init(this.RecordId,NewData,this.Parent);var Container=document.getElementById('SubAddressLines'+this.Data.parentid);this.InsertIntoElement(Container);this.ToggleEntryExtendedInfo();}}}

window.CAddressBookGui=function(Page){if(arguments.length<=0)return;this.Init.apply(this,arguments);}
CAddressBookGui.prototype=new CXDbGui();CAddressBookGui.prototype.constructor=CAddressBookGui;CAddressBookGui.superclass=CXDbGui.prototype;CAddressBookGui.prototype.Init=function(Page){CAddressBookGui.superclass.Init.apply(this,arguments);this.UserId='';this.UserIsAdmin=false;this.AddressLines=null;this.AddressLinesControl=null;this.AddressInfo=null;this.AddressInfoByAddressLine=null;this.AddressInfoByUserId=null;this.AttributeNames=null;this.AdminAttributeNames=null;}
CAddressBookGui.prototype._NewDataEntry=function(RecordId,Data){if(Data.GroupId){return new CGroupAddressBookEntry(RecordId,Data,this);}else{return new CIndividualAddressBookEntry(RecordId,Data,this);}}
CAddressBookGui.prototype._GetAddressInfoByAddressLine=function(){if(this.AddressInfoByAddressLine)return;var ArrayFind=function Find(Needle,Haystack){var Length=Haystack.length;for(var Index=0;Index<Length;Index++){if(Haystack[Index]==Needle)return Index}
return-1;}
this.AddressInfoByAddressLine=new Array();for(var AddressInfoId in this.AddressInfo){var aAddressInfo=this.AddressInfo[AddressInfoId];var addresslineid=aAddressInfo.addresslineid;if(!this.AddressInfoByAddressLine[addresslineid]){this.AddressInfoByAddressLine[addresslineid]=new Array();}
if(ArrayFind(aAddressInfo.userid,this.AddressInfoByAddressLine[addresslineid])==-1){this.AddressInfoByAddressLine[addresslineid].push(aAddressInfo.userid);}}}
CAddressBookGui.prototype._GetAddressInfoByUserId=function(){if(this.AddressInfoByUserId)return;this.AddressInfoByUserId=new Array();for(var AddressInfoId in this.AddressInfo){var Address=this.AddressInfo[AddressInfoId];Address.AddressInfoId=AddressInfoId;var Addressses=new Array();if(!this.AddressInfoByUserId[Address.userid]){this.AddressInfoByUserId[Address.userid]=Addressses;}else{Addressses=this.AddressInfoByUserId[Address.userid];}
this.AddressInfoByUserId[Address.userid].push(Address);}}
CAddressBookGui.prototype.UpdateAddressLines=function(Deleted,Added){this.AddressLinesControl.UpdateAddressLines(Deleted,Added);this.AddressLines=this.AddressLinesControl.Data;}
CAddressBookGui.prototype.UpdateAddressInfo=function(Deleted,Added){if(Deleted){for(var iIndex in Deleted){var AddressInfoId=Deleted[iIndex];delete this.AddressInfo[AddressInfoId];}
this.AddressInfoByAddressLine=null;this.AddressInfoByUserId=null;}
if(Added){for(var AddressInfoId in Added){this.AddressInfo[AddressInfoId]=Added[AddressInfoId];}
this.AddressInfoByAddressLine=null;this.AddressInfoByUserId=null;}}
CAddressBookGui.prototype.ViewMe=function(){this.Search('@RecordId='+this.UserId);}
CAddressBookGui.prototype.AddressSearch=function(AddressLine){var Form=document.getElementById('SearchForm');this.ClearForm(Form);Form.elements['address'].value=AddressLine;this.GenericSearch();}
CAddressBookGui.prototype.GenericSearch=function(){var ActionTitle=document.getElementById('ActionTitle');if(ActionTitle){ActionTitle.firstChild.nodeValue="Searching the database";}
var Element=document.getElementById('ActionContent');Element.innerHTML='';this.HidePanel('SearchPanel');this.ShowLoadingPanel();var Form=document.getElementById('SearchForm');{var aAddressSearch=this._AddressSearch();var aPostCodeSearch=this._PostCodeSearch();var aLandLineSearch=this._LandLineSearch();var aAddressLines=null;var Intersect=function(Result,Other){if(!Other)return Result;if(!Result){return Other;}
var Results=new Array();for(var AddressLineId in Result){if(!Other[AddressLineId])continue;Results[AddressLineId]=AddressLineId}
return Results;}
aAddressLines=Intersect(aAddressLines,aAddressSearch);aAddressLines=Intersect(aAddressLines,aPostCodeSearch);aAddressLines=Intersect(aAddressLines,aLandLineSearch);if(aAddressLines){this._GetAddressInfoByAddressLine();var aUsers=new Array();for(AddressLineId in aAddressLines){if(!this.AddressInfoByAddressLine[AddressLineId])continue;var aUsersAtThisAddress=this.AddressInfoByAddressLine[AddressLineId]
for(var iIndex in aUsersAtThisAddress){aUsers.push(aUsersAtThisAddress[iIndex]);}}
if(!aUsers.length){var Result;this.Data=new Array();this.Data['Results']=new Array();this.HideLoadingPanel();this.Render();return;}
var iMaxSearchCount=100;if(aUsers.length>iMaxSearchCount){if(!confirm(["The address components of your search match ",aUsers.length,' entries.  Click OK to search within the first ',iMaxSearchCount,' matches, cancel to refine your search.'].join(''))){this.HideLoadingPanel();this.ShowPanel('SearchPanel');return;}
aUsers.length=iMaxSearchCount;}
Form.elements['recordid'].value=aUsers.join(',');}else{Form.elements['recordid'].value='';}}
var oRequest=new AjaxCallback(this,'_SearchComplete');var PostData=this.BuildPostData(Form,'Js');oRequest.Send(this.Page,PostData);}
CAddressBookGui.prototype._AddressSearch=function(){var Form=document.getElementById('SearchForm');var SearchAddress=Form.elements['address'].value;if(SearchAddress=="")return null;var aUserIds=new Array();{var SearchRegExp=null;{var SearchPattern=new String(SearchAddress);SearchPattern=SearchPattern.replace(/([\.\\\+\*\?\[\^\]\(\$\)])/g,"\\$1");var e=document.getElementById('MatchTypeEquals');if(e&&e.checked){SearchPattern="^"+SearchPattern+"$";}
var SearchFlags="";var e=document.getElementById('CaseSensitiveNo');if(e&&e.checked){SearchFlags="i";}
SearchRegExp=new RegExp(SearchPattern,SearchFlags);}}
return this.AddressLinesControl.Search(SearchRegExp);}
CAddressBookGui.prototype._PostCodeSearch=function(){return this._AddressLineAttributeSearch('postcode',function(Arg){return Arg.postcode;})}
CAddressBookGui.prototype._LandLineSearch=function(){return this._AddressLineAttributeSearch('landline',function(Arg){return Arg.landline;})}
CAddressBookGui.prototype._AddressLineAttributeSearch=function(InputName,ValueFunc){var Form=document.getElementById('SearchForm');var SearchValue=new String(Form.elements[InputName].value);SearchValue=SearchValue.replace(/[ \t]/g,"");if(SearchValue=="")return null;var SearchRegExp=new RegExp(SearchValue,"i");this.AddressLinesControl.AttributeSearch(SearchRegExp,ValueFunc);}
CAddressBookGui.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 eTable=document.createElement('table');eTable.id='SearchResults';eTable.className='SearchResults';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>';Element=eSortControls.insertCell(-1);Element.className='EntrySummaryName';Element.width='200px';var contents=new Array();contents.push(this.FieldSortLink('Title',' class="EntrySummaryRegion"'));contents.push(this.FieldSortLink('FirstName',' class="EntrySummaryRegion"'));contents.push(this.FieldSortLink('LastName',' class="EntrySummaryRegion"'));Element.innerHTML=contents.join(' ');Element=eSortControls.insertCell(-1);Element.className='EntrySummaryContactDetails';Element.innerHTML=this.FieldSortLink('PhoneNumber',' class="EntrySummaryRegion"');Element=eSortControls.insertCell(-1);Element.className='EntrySummaryContactDetails';Element.width='40%';Element.innerHTML=this.FieldSortLink('Email',' style="float:right"');}
Container.appendChild(eTable);{var aResults=this.Data['Results'];for(var iIndex in aResults){var Result=aResults[iIndex];Result.InsertInto(eTable);}}}}
CAddressBookGui.prototype.AddressTree=function(){this.Data={'Results':[]};{var aResults=this.Data['Results'];var aAddressLineEntries=new Array();for(var AddressLineId in this.AddressLines){var aAddress=this.AddressLines[AddressLineId];if(aAddress.parentid)continue;aAddressLineEntries.push(new CAddressLineEntry(AddressLineId,aAddress,this));}
this.Data['Results']=aAddressLineEntries;}
var ActionTitle=document.getElementById('ActionTitle');if(ActionTitle){ActionTitle.firstChild.nodeValue="Search By Address";}
var Container=document.getElementById('ActionContent');Container.innerHTML='';{var aResults=this.Data['Results'];for(var iIndex in aResults){var Result=aResults[iIndex];Result.InsertIntoElement(Container);}}}
CAddressBookGui.prototype.GetAddresses=function(UserId){this._GetAddressInfoByUserId();if(!this.AddressInfoByUserId[UserId])return new Array();return this.AddressInfoByUserId[UserId];}
CAddressBookGui.prototype.ToggleAddressLineExtendedInfo=function(AddressLineId){var Data=new CAddressLineEntry(AddressLineId,this);Data.ToggleEntryExtendedInfo();}
CAddressBookGui.prototype.AddAttribute=function(Element,RecordId,Admin){var Entry=this._GetData(RecordId);if(!Entry)return;Entry.AddAttribute(Element,Admin);}
CAddressBookGui.prototype.AddAddress=function(RecordId){var Entry=this._GetData(RecordId);if(!Entry)return;Entry.AddAddress();}
CAddressBookGui.prototype.DeleteAddress=function(RecordId,AddressId){var Entry=this._GetData(RecordId);if(!Entry)return;Entry.DeleteAddress(AddressId);}
CAddressBookGui.prototype.OnCompleteDateOfBirth=function(Control,RecordId){var e=document.getElementById('datebirthformaterror'+RecordId);if(!e)return;e.style.display='none';if(Control.value=='')Control.value='YYYY-MM-DD';if(Control.value=='YYYY-MM-DD')return true;var BirthDate=null;do{var aMatches=Control.value.match(/^\s*(\d\d\d\d)-(\d\d)-(\d\d)\s*$/);if(!aMatches)break;if(aMatches[1]<=1900)break;if(1>aMatches[2]||aMatches[2]>12)break;if(1>aMatches[3]||aMatches[3]>31)break;BirthDate=new Date(aMatches[1],aMatches[2]-1,aMatches[3]);}while(false);if(!BirthDate){e.style.display='';return false;}
var AgeError=document.getElementById('UnderAgeError'+RecordId);if(!AgeError)return;var Over18Checkbox=document.getElementById('Over18Checkbox'+RecordId);if(!Over18Checkbox)return;var Over18CheckboxPanel=document.getElementById('Over18'+RecordId);if(!Over18CheckboxPanel)return;AgeError.style.display='none';Over18Checkbox.checked=false;Over18CheckboxPanel.style.display='none';{var Now=new Date();var iAge=Now.getFullYear()-BirthDate.getFullYear();Now.setFullYear(BirthDate.getFullYear());if(Now<BirthDate){iAge--;}
if(iAge<18){AgeError.style.display='';Over18CheckboxPanel.style.display='';return false;}}
Over18Checkbox.checked=true;return true;}
CAddressBookGui.prototype.OnCompleteSpouse=function(Control,RecordId){var w=document.getElementById('SpouseUnknownError'+RecordId);if(!w)return;w.style.display='none';var e=document.getElementById('ChooseSpouseError'+RecordId);if(!e)return;e.style.display='none';var Entry=this._GetData(RecordId);if(!Entry)return;if(Entry.Data.spousename==Control.value){Control.form.elements['spouseid']=Entry.Data.spouseid;return;}
Control.form.elements['spouseid'].value='';if(Control.value.match(/^\s*$/))return;var oRequest=new AjaxCallback(this,'_SpouseLookupComplete');var PostData=['ContentType=AjaxJs','Action=SpouseLookup','RecordId='+RecordId,'SpouseName='+escape(Utf8.encode(Control.value)),'LastName='+escape(Utf8.encode(Entry.Data.LastName))].join('&');oRequest.Send(this.Page,PostData);}
CAddressBookGui.prototype._SpouseLookupComplete=function(oRequest){var Results=eval(oRequest.responseText);if(typeof(Results)!='object')return;if(!Results.RecordId)return;var Form=document.getElementById("EditForm"+Results.RecordId);if(!Form)return;if(Form.elements['spousename'].value!=Results.SpouseName)return;var Select=Form.elements['SpouseChooser'];if(!Select)return;{Select.style.display='';Select.innerHTML='';for(var UserId in Results.Options){var e=document.createElement('option');var o=Results.Options[UserId];e.value=parseInt(UserId);e.text=[o.FirstName,o.LastName].join(' ');try{Select.add(e,null);}catch(ex){Select.add(e);}}}
Select.disabled=true;Select.style.display='none';if(!Select.options.length){var w=document.getElementById('SpouseUnknownError'+Results.RecordId);if(!w)return;w.style.display='';return;}
if(Select.options.length==1){Form.elements['spousename'].value=Select.options[0].text;Form.elements['spouseid'].value=Select.options[0].value;return;}
var w=document.getElementById('ChooseSpouseError'+Results.RecordId);if(!w)return;w.style.display='';Select.disabled=false;Select.style.display='';Select.focus();}
CAddressBookGui.prototype.OnSelectSpouse=function(Control,RecordId){var Form=Control.form;var o=Control.options[Control.selectedIndex];Form.elements['spousename'].value=o.text;Form.elements['spouseid'].value=o.value;var w=document.getElementById('ChooseSpouseError'+RecordId);if(!w)return;w.style.display='none';Control.disabled=true;}
CAddressBookGui.prototype.OnChangeAttributeSelection=function(Control,AttributeId){var Form=Control.form;if(Control.name.match("Admin*")){var AttributeString='AdminAttributeName';}else{var AttributeString='AttributeName';}
if(Control.value==0){Form.elements[AttributeString+AttributeId].style.display='';}else{Form.elements[AttributeString+AttributeId].style.display='none';}}
CAddressBookGui.prototype.OnCompleteAddress=function(Control,KeyName){this.AddressLinesControl.OnComplete(Control,KeyName)}
CAddressBookGui.prototype.OnAutoCompleteAddress=function(Control,oEvent){var RichControl=new CAutoCompletionControl(Control);RichControl.Parent=this;RichControl.OnAutoComplete=function(CharCode){return this.Parent.AddressLinesControl.AutoCompleteAddress(this.Element,CharCode);}
return RichControl.OnKeyPress(oEvent);}
CAddressBookGui.prototype.Export=function(RecordId){window.location.href=this.Page+"?ContentType=AjaxvCard&Action=Export&RecordId="+RecordId;}
