
if(typeof($fc)=='undefined'){var $fc={};}
$fc.watchedfields={};$fc.watchingfields={};$fc.watchingtracker={};$fc.watchloading=0;function addWatch(prefix,property,opts){$fc.watchedfields[prefix]=$fc.watchedfields[prefix]||{};$fc.watchingfields[prefix]=$fc.watchingfields[prefix]||{};$fc.watchingtracker[prefix]=$fc.watchingtracker[prefix]||{};$fc.watchingtracker[prefix][property]=$fc.watchingtracker[prefix][property]||{};$j("select[name="+prefix+property+"], input[name="+prefix+property+"][type=text], input[name="+prefix+property+"][type=password]").live("change",{prefix:prefix,property:property},ajaxUpdate);$j("input[name="+prefix+property+"][type=checkbox], input[name="+prefix+property+"][type=radio]").live("click",{prefix:prefix,property:property},ajaxUpdate);var el=$j("input[name="+prefix+property+"][type=hidden]");if(el.size()){var lastvalue=el.val();setInterval(function(){var el=$j("input[name="+prefix+property+"][type=hidden]");if(el.val()!==lastvalue){lastvalue=el.val();var ev={data:{prefix:prefix,property:property}};ajaxUpdate.call(el[0],ev);}},100);};if($fc.watchingtracker[prefix][property][opts.property]===undefined){$fc.watchedfields[prefix][property]=$fc.watchedfields[prefix][property]||[];$fc.watchedfields[prefix][property].push(opts);$fc.watchingfields[prefix][opts.property]=$fc.watchingfields[prefix][opts.property]||[];$fc.watchingfields[prefix][opts.property].push(opts);$fc.watchingtracker[prefix][property][opts.property]='';}};function getValueData(base,prefix){base=base||{};var property="";for(var property in base){var inputs=$j('input[name='+prefix+property+'],select[name='+prefix+property+'],textarea[name='+prefix+property+']');if(inputs.size()){base[property]=[];inputs.each(function(){var self=$j(this);if((!(self.is("[type=radio]")||self.is("[type=radio]"))||self.is(":checked"))&&self.val()!=="")base[property].push(self.val());});base[property]=base[property].join();}}
return base;};function ajaxUpdate(event){var values={};var reenable=[];if($fc.watchloading==0){for(var i=0;i<$fc.watchedfields[event.data.prefix][event.data.property].length;i++){watcher=$fc.watchedfields[event.data.prefix][event.data.property][i];values[watcher.property]="";for(var j=0;j<$fc.watchingfields[event.data.prefix][watcher.property].length;j++)
values[$fc.watchingfields[event.data.prefix][watcher.property][j].watchedproperty]="";}
values=getValueData(values,event.data.prefix);for(var i=0;i<$fc.watchedfields[event.data.prefix][event.data.property].length;i++){$fc.watchloading++;(function(watcher){$j("#"+watcher.prefix+watcher.property+"ajaxdiv").html(watcher.ftLoaderHTML).load('/webtop/facade/ftajax.cfm?ajaxmode=1&formtool='+watcher.formtool+'&typename='+watcher.typename+'&fieldname='+watcher.fieldname+'&property='+watcher.property+'&objectid='+watcher.objectid,values,function(response){$j("#"+watcher.fieldname+"ajaxdiv").html(response.responseText);if($fc.watchedfields[watcher.prefix]&&$fc.watchedfields[watcher.prefix][watcher.property]&&$fc.watchedfields[watcher.prefix][watcher.property].length){$j("select[name="+watcher.prefix+watcher.property+"], input[name="+watcher.prefix+watcher.property+"][type=text], input[name="+watcher.prefix+watcher.property+"][type=password]").bind("change",{prefix:watcher.prefix,property:watcher.property},ajaxUpdate);$j("input[name="+watcher.prefix+watcher.property+"][type=checkbox], input[name="+watcher.prefix+watcher.property+"][type=radio]").bind("click",{prefix:watcher.prefix,property:watcher.property},ajaxUpdate);reenable.push("select[name="+watcher.prefix+watcher.property+"], input[name="+watcher.prefix+watcher.property+"][type=text], input[name="+watcher.prefix+watcher.property+"][type=password]");reenable.push("input[name="+watcher.prefix+watcher.property+"][type=checkbox], input[name="+watcher.prefix+watcher.property+"][type=radio]");}
$fc.watchloading--;if($fc.watchloading)$j(reenable.join()).attr("disabled",false);});})($fc.watchedfields[event.data.prefix][event.data.property][i]);}}};function ajaxClear(){var values={};var prefix="";var property="";var thisproperty="";var reenable=$j([]);for(prefix in $fc.watchedfields);for(property in $fc.watchedfields[prefix]);if($fc.watchloading==0){for(var i=0;i<$fc.watchedfields[prefix][property].length;i++){watcher=$fc.watchedfields[prefix][property][i];values[watcher.property]="";for(var j=0;j<$fc.watchingfields[prefix][watcher.property].length;j++)
values[$fc.watchingfields[prefix][watcher.property][j].watchedproperty]="";}
for(var thisproperty in values){if($j('#'+prefix+thisproperty).val()){values[thisproperty]=$j('#'+prefix+thisproperty).val();if(values[thisproperty].join)values[thisproperty]=values[thisproperty].join();}}
for(var i=0;i<$fc.watchedfields[prefix][property].length;i++){$fc.watchloading++;(function(watcher){$j("#"+watcher.prefix+watcher.property+"ajaxdiv").html(watcher.ftLoaderHTML).load('/webtop/facade/ftajax.cfm?ajaxmode=1&formtool='+watcher.formtool+'&typename='+watcher.typename+'&fieldname='+watcher.fieldname+'&property='+watcher.property+'&objectid='+watcher.objectid,values,function(response){$j("#"+watcher.fieldname+"ajaxdiv").html(response.responseText);if($fc.watchedfields[watcher.prefix]&&$fc.watchedfields[watcher.prefix][watcher.property]&&$fc.watchedfields[watcher.prefix][watcher.property].length){$j("select[name="+watcher.prefix+watcher.property+"], input[name="+watcher.prefix+watcher.property+"][type=text], input[name="+watcher.prefix+watcher.property+"]:not([type]), input[name="+watcher.prefix+watcher.property+"][type=password]").bind("change",{prefix:watcher.prefix,property:watcher.property},ajaxUpdate).disable();$j("input[name="+watcher.prefix+watcher.property+"][type=checkbox], input[name="+watcher.prefix+watcher.property+"][type=radio]").bind("click",{prefix:watcher.prefix,property:watcher.property},ajaxUpdate).disable();}
$fc.watchloading--;});})($fc.watchedfields[prefix][property][i]);}}};function farcryButtonURL(id,url,target){if(target=='undefined'||target=='_self'){location.href=url;return false;}else{win=window.open('',target);win.location=url;win.focus;return false;}}
function selectObjectID(objectid){$j('.fc-selected-object-id').attr('value',objectid);}
function createFormtoolTree(fieldname,rootID,dataURL,rootNodeText,selectedIDs,iconCls){var Tree=Ext.tree;var checkRoot=false;tree=new Tree.TreePanel({animate:true,loader:new Tree.TreeLoader({dataUrl:dataURL,baseAttrs:{checked:false,iconCls:'categoryIconCls'},baseParams:{selectedObjectIDs:selectedIDs}}),enableDD:true,containerScroll:true,border:false});tree.on('checkchange',function(n,c){var newList="";var currentTreeList=Ext.getDom(fieldname).value;if(c){if(currentTreeList.length){currentTreeList=currentTreeList+','}
Ext.getDom(fieldname).value=currentTreeList+n.id}else{var valueArray=currentTreeList.split(",");for(var i=0;i<valueArray.length;i++){if(n.id!=valueArray[i]){if(newList.length){newList=newList+',';}
newList=newList+valueArray[i]}}
Ext.getDom(fieldname).value=newList;}});if(selectedIDs.match(rootID)){checkRoot=true;}
var root=new Tree.AsyncTreeNode({text:rootNodeText,draggable:false,id:rootID,iconCls:iconCls,checked:checkRoot});tree.setRootNode(root);tree.render(fieldname+'-tree-div');root.expand();}
function selectedObjectID(objectid){$j('.fc-selected-object-id').attr('value',objectid);}
function validateBtnClick(formName){var btnValidation=new Validation(formName,{onSubmit:false});if(btnValidation.validate()){return true}else{return false};}
function btnURL(url,target){if(target=='undefined'||target=='_self'){location.href=url;return false;}else{win=window.open('',target);win.location=url;win.focus;return false;}}
function btnClick(formName,value){$j('.fc-button-clicked').attr('value',value);}
function btnTurnOnServerSideValidation(){$j('.fc-server-side-validation').attr('value',1);}function btnTurnOffServerSideValidation(){$j('.fc-server-side-validation').attr('value',0);}
function btnSubmit(formName,value){btnClick(formName,value);if(formName!=''){$j('#'+formName).submit();}}
function farcryForm_ajaxSubmission(formname,action,maskMsg,maskCls,ajaxTimeout,ajaxTarget){var a=action?action:$j('#'+formname).attr('action');if(maskMsg==undefined){var maskMsg='Form Submitting, please wait...'};if(maskCls==undefined){var maskCls='mask-ajax-submission'};if(ajaxTimeout==undefined){var ajaxTimeout=30};if(ajaxTarget==undefined){var ajaxTarget="#"+formname+"formwrap";};if(ajaxTimeout>0){ajaxTimeout=ajaxTimeout*1000;}
if(maskMsg.length){$j("#"+formname).mask(maskMsg);}
$j.ajax({type:"POST",url:a,data:$j("#"+formname).serialize(),dataType:"html",cache:false,timeout:ajaxTimeout,success:function(msg){if(maskMsg.length){$j(ajaxTarget).unmask();}
$j(ajaxTarget).html(msg);}});}
function checkUncheckAll(theElement){var theForm=theElement.form,z=0;for(z=0;z<theForm.length;z++){if(theForm[z].type=='checkbox'&&theForm[z].name!='checkall'){theForm[z].checked=theElement.checked;setRowBackground(theForm[z]);}}}
function setRowBackground(childCheckbox){var row=childCheckbox.parentNode;while(row&&row.tagName.toLowerCase()!='tr'){row=row.parentNode;}
if(row&&row.style){if(childCheckbox.checked){row.style.backgroundColor='#F9E6D4';}
else{row.style.backgroundColor='';}}}
$fc.openDialog=function(title,url,width,height){var fcDialog=$j("<div></div>")
w=width?width:600;h=height?height:$j(window).height()-50;$j("body").prepend(fcDialog);$j(fcDialog).dialog({bgiframe:true,modal:true,title:title,width:w,height:h,close:function(event,ui){$j(fcDialog).dialog('destroy');$j(fcDialog).remove();}});$j(fcDialog).dialog('open');$j.ajax({type:"POST",cache:false,url:url,complete:function(data){$j(fcDialog).html(data.responseText);},data:{},dataType:"html"});};$fc.openDialogIFrame=function(title,url,width,height){var w=width?width:600;var h=height?height:$j(window).height()-50;var fcDialog=$j("<div id='fc-dialog-iframe' style='padding:20px;'><iframe style='width:99%;height:99%;border-width:0px;' frameborder='0'></iframe></div>")
$j("body").prepend(fcDialog);$j(fcDialog).dialog({bgiframe:true,modal:true,title:title,width:w,height:h,close:function(event,ui){$j(fcDialog).dialog('destroy');$j(fcDialog).remove();}});$j(fcDialog).dialog('open');$j('iframe',$j(fcDialog)).attr('src',url);return fcDialog;};var fcForm={};fcForm.openLibrarySelect=function(typename,objectid,property,id,urlparameters){urlparameters=urlparameters?urlparameters:'';var yPos=$j("html").scrollTop();var newDialogDiv=$j("<div><iframe style='width:99%;height:99%;border-width:0px;' frameborder='0'></iframe></div>");$j("body").prepend(newDialogDiv);$j("html").css('overflow','hidden');$j(newDialogDiv).dialog({bgiframe:true,modal:true,title:'Library',draggable:false,resizable:false,position:['left','top'],width:"99%",height:$j(window).height()-15,buttons:{Ok:function(){$j(this).dialog('close');}},close:function(event,ui){$j("html").css('overflow','auto');fcForm.refreshProperty(typename,objectid,property,id);$j(newDialogDiv).dialog('destroy');$j(newDialogDiv).remove();$j("html").scrollTop(yPos);}});$j(newDialogDiv).dialog('open');$j('iframe',$j(newDialogDiv)).attr('src','/index.cfm?type='+typename+'&objectid='+objectid+'&view=displayLibraryTabs'+'&property='+property+'&fieldname='+id+'&'+urlparameters);};fcForm.openLibraryAdd=function(typename,objectid,property,id){var newDialogDiv=$j("<div id='"+typename+objectid+property+"'><iframe style='width:100%;height:100%;border-width:0px;' frameborder='0'></iframe></div>")
var filterTypename=$j('#'+id+'-add-type').val();$j("body").prepend(newDialogDiv);$j("html").css('overflow','hidden');$j(newDialogDiv).dialog({bgiframe:true,title:'Add New',closeOnEscape:false,draggable:false,resizable:false,position:['left','top'],width:"99%",height:$j(window).height()-15,close:function(event,ui){$j("html").css('overflow','auto');fcForm.refreshProperty(typename,objectid,property,id);$j(newDialogDiv).dialog('destroy');$j(newDialogDiv).remove();}});$j(newDialogDiv).dialog('open');$j('iframe',$j(newDialogDiv)).attr('src','/index.cfm?type='+typename+'&objectid='+objectid+'&view=displayLibraryAdd'+'&property='+property+'&filterTypename='+filterTypename);};fcForm.openLibraryEdit=function(typename,objectid,property,id,editid){var newDialogDiv=$j("<div id='"+typename+objectid+property+"'><iframe style='width:100%;height:100%;border-width:0px;' frameborder='0'></iframe></div>")
$j("body").prepend(newDialogDiv);$j("html").css('overflow','hidden');$j(newDialogDiv).dialog({bgiframe:true,modal:true,title:'Edit',closeOnEscape:false,draggable:false,resizable:false,position:['left','top'],width:"99%",height:$j(window).height()-15,close:function(event,ui){$j("html").css('overflow','auto');fcForm.refreshProperty(typename,objectid,property,id);$j(newDialogDiv).dialog('destroy');$j(newDialogDiv).remove();}});$j(newDialogDiv).dialog('open');$j('iframe',$j(newDialogDiv)).attr('src','/index.cfm?type='+typename+'&objectid='+objectid+'&view=displayLibraryEdit'+'&property='+property+'&editid='+editid);};fcForm.deleteLibraryItem=function(typename,objectid,property,formfieldname,itemids){$j.ajax({cache:false,type:"POST",url:'/index.cfm?ajaxmode=1&type='+typename+'&objectid='+objectid+'&view=displayAjaxUpdateJoin'+'&property='+property,data:{deleteID:itemids},dataType:"html",complete:function(data){$j('#join-item-'+itemids).hide('blind',{},500);$j('#join-item-'+itemids).remove();$j('#'+formfieldname).attr('value','');var aItems=$j('#'+formfieldname+'-library-wrapper').sortable('toArray',{'attribute':'serialize'});if($j.isArray(aItems)){$j('#'+formfieldname).val(aItems.join(","));}else{$j('#'+formfieldname).val('');}}});}
fcForm.deleteAllLibraryItems=function(typename,objectid,property,formfieldname,itemids){$j.ajax({cache:false,type:"POST",url:'/index.cfm?ajaxmode=1&type='+typename+'&objectid='+objectid+'&view=displayAjaxUpdateJoin'+'&property='+property,data:{deleteID:itemids},dataType:"html",complete:function(data){$j('#'+formfieldname).attr('value','');$j('#join-'+objectid+'-'+property).hide('blind',{},500);$j('#join-'+objectid+'-'+property).remove();}});}
fcForm.detachLibraryItem=function(typename,objectid,property,formfieldname,itemids){$j('#join-item-'+itemids).hide('blind',{},500);$j('#join-item-'+itemids).remove();$j('#'+formfieldname).attr('value','');var aItems=$j('#'+formfieldname+'-library-wrapper').sortable('toArray',{'attribute':'serialize'});if($j.isArray(aItems)){$j('#'+formfieldname).val(aItems.join(","));}else{$j('#'+formfieldname).val('');}}
fcForm.detachAllLibraryItems=function(typename,objectid,property,formfieldname,itemids){$j('#'+formfieldname).attr('value','');$j('#join-'+objectid+'-'+property).hide('blind',{},500);$j('#join-'+objectid+'-'+property).remove();}
fcForm.initLibrary=function(typename,objectid,property,urlParams){fcForm.initLibrarySummary(typename,objectid,property,urlParams);$j('tr.selector-wrap').filter(':has(input:checked)').addClass('rowselected').end().click(function(event){if(event.target.type!=='checkbox'&&event.target.type!=='radio'){$j('input',this).attr('checked',function(){$j(this).attr('checked',!this.checked);$j(this).trigger('click');if(this.type=='checkbox'){return!this.checked;}});};});$j("input.checker").click(function(e){if(e.target.type=='radio'){$j('tr.selector-wrap').removeClass('rowselected');$j(this).parents('tr.selector-wrap').addClass('rowselected');}else{$j(this).parents('tr.selector-wrap').toggleClass('rowselected');};});$j("input.checkall").click(function(e){if($j(e.target).attr('checked')){$j("input.checker").attr('checked','checked');}else{$j("input.checker").attr('checked','checked');};});};fcForm.initLibrarySummary=function(typename,objectid,property,urlParams){}
fcForm.refreshProperty=function(typename,objectid,property,id){var propertydata={propertyValue:$j('#'+id).val()};$j("select[name^="+id+"],input[name^="+id+"]").each(function(){if(this.name!=id)propertydata[this.name.slice(id.length)]=$j(this).val();});var prefix=id.slice(0,id.length-property.length);$j.ajax({type:"POST",cache:false,url:'/index.cfm?ajaxmode=1&type='+typename+'&objectid='+objectid+'&view=displayAjaxRefreshJoinProperty'+'&property='+property+'&prefix='+prefix,success:function(msg){$j("#"+id+'-library-wrapper').html(msg);fcForm.initSortable(typename,objectid,property,id);},data:propertydata,dataType:"html"});}
fcForm.initSortable=function(typename,objectid,property,id){$j('#'+id+'-library-wrapper').sortable({items:'li.sort',axis:'y',update:function(event,ui){$j('#'+id).val($j('#'+id+'-library-wrapper').sortable('toArray',{'attribute':'serialize'}).join(","));}});}
$j.extend({dimScreen:function(speed,opacity,callback){if(jQuery('#__dimScreen').size()>0)return;if(typeof speed=='function'){callback=speed;speed=null;}
if(typeof opacity=='function'){callback=opacity;opacity=null;}
if(speed<1){var placeholder=opacity;opacity=speed;speed=placeholder;}
if(opacity>=1){var placeholder=speed;speed=opacity;opacity=placeholder;}
speed=(speed>0)?speed:500;opacity=(opacity>0)?opacity:0.5;return jQuery('<div></div>').attr({id:'__dimScreen',fade_opacity:opacity,speed:speed}).css({background:'#000',height:jQuery(document).height()+'px',left:'0px',opacity:0,position:'absolute',top:'0px',width:jQuery(document).width()+'px',zIndex:999}).appendTo(document.body).fadeTo(speed,opacity,callback);},dimScreenStop:function(callback){var x=jQuery('#__dimScreen');var opacity=x.attr('fade_opacity');var speed=x.attr('speed');x.fadeOut(speed,function(){x.remove();if(typeof callback=='function')callback();});}});$fc.objectAdminAction=function(title,url){if($fc.objectAdminActionDiv===undefined){$fc.objectAdminActionDiv=$j("<div><iframe style='width:100%;height:99%;' frameborder='0'></iframe></div>");$j("body").prepend($fc.objectAdminActionDiv);$j("html").css('overflow','hidden');$j($fc.objectAdminActionDiv).dialog({bgiframe:true,modal:true,title:title,draggable:false,resizable:false,position:['left','top'],width:"99%",height:$j(window).height()-15,close:function(event,ui){$j("html").css('overflow','auto');window.location=window.location.href.split("#")[0];}});}
$j($fc.objectAdminActionDiv).dialog('open');$j('iframe',$j($fc.objectAdminActionDiv)).attr('src',url);};var userselection=[];var inputField;fcForm.selections={init:function(aTypename,aProperty,aId){typename=aTypename;property=aProperty;id=aId;inputField=$j('#'+aId,parent.document);if(inputField.val().length){userselection=inputField.val().split(',');}
fcForm.selections.statusupdate(property);$j("tr.selector-wrap input[name='selected']").live('click',function(e){var el=$(this);if(el.is(':radio')){userselection=[el.val()];}else if(el.is(':checked')){fcForm.selections.add(el.val());}else{fcForm.selections.remove(el.val());}
inputField.val(userselection.toString());fcForm.selections.statusupdate(property);});},add:function(objID){if($j.inArray(objID,userselection)==-1){userselection.push(objID);}},remove:function(objID){var arrPos=$j.inArray(objID,userselection);if(arrPos>=0){userselection.splice(arrPos,1);}},statusupdate:function(property){var nbrSelections=userselection.length;var statusText='<div id="OKMsg">'+nbrSelections+' items selected.</div>';if(nbrSelections==0){statusText='<div id="errorMsg">No items have been selected.</div>';}
$j('#librarySummary-'+typename+'-'+property).html(statusText);},reinitpage:function(){$j('tr.selector-wrap').removeClass('rowselected');$j("tr.selector-wrap input[name='selected']").attr('checked',false);$j.each(userselection,function(){$j("tr.selector-wrap input[value='"+this+"']").attr('checked',true).parents('tr.selector-wrap').addClass('rowselected');});}};$j("form input, form select").live('keypress',function(e){if($j(this).parents('form').find('.defaultAction').length<=0)
return true;if((e.which&&e.which==13)||(e.keyCode&&e.keyCode==13)){$j(this).parents('form').find('.defaultAction').click();return false;}else{return true;}});(function(a){a.fn.mask=function(c){this.unmask();if(this.css("position")=="static"){this.addClass("masked-relative")}this.addClass("masked");var f=a('<div class="loadmask"></div>');var d=navigator.userAgent.toLowerCase();var h=document.compatMode=="CSS1Compat";var e=d.indexOf("msie")>-1;var g=d.indexOf("msie 7");if(e&&!(g&&h)&&this.css("height")=="auto"){f.height(this.height());f.width(this.width())}this.append(f);if(typeof c=="string"){var b=a('<div class="loadmask-msg" style="display:none;"></div>');b.append("<div>"+c+"</div>");this.append(b);b.css("top",Math.round(this.height()/2-b.height()/2)+"px");b.css("left",Math.round(this.width()/2-b.width()/2)+"px");b.show()}};a.fn.unmask=function(b){this.find(".loadmask-msg,.loadmask").remove();this.removeClass("masked");this.removeClass("masked-relative")}})(jQuery);(function($){$.fn.uniform=function(settings){settings=$.extend({valid_class:'valid',invalid_class:'invalid',focused_class:'focused',holder_class:'ctrlHolder',field_selector:'input, select, textarea'},settings);return this.each(function(){var form=$(this);var focusControlHolder=function(element){$j(element).parents("."+settings.holder_class).addClass(settings.focused_class);};form.find(settings.field_selector).each(function(){if($(this).hasClass("focus")){$(this).focus();focusControlHolder($(this));}});form.find(settings.field_selector).focus(function(){form.find('.'+settings.focused_class).removeClass(settings.focused_class);focusControlHolder($(this));});form.find(settings.field_selector).blur(function(){form.find('.'+settings.focused_class).removeClass(settings.focused_class);});});};})(jQuery);;(function($){$.extend($.fn,{swapClass:function(c1,c2){var c1Elements=this.filter('.'+c1);this.filter('.'+c2).removeClass(c2).addClass(c1);c1Elements.removeClass(c1).addClass(c2);return this;},replaceClass:function(c1,c2){return this.filter('.'+c1).removeClass(c1).addClass(c2).end();},hoverClass:function(className){className=className||"hover";return this.hover(function(){$(this).addClass(className);},function(){$(this).removeClass(className);});},heightToggle:function(animated,callback){animated?this.animate({height:"toggle"},animated,callback):this.each(function(){jQuery(this)[jQuery(this).is(":hidden")?"show":"hide"]();if(callback)
callback.apply(this,arguments);});},heightHide:function(animated,callback){if(animated){this.animate({height:"hide"},animated,callback);}else{this.hide();if(callback)
this.each(callback);}},prepareBranches:function(settings){if(!settings.prerendered){this.filter(":last-child:not(ul)").addClass(CLASSES.last);this.filter((settings.collapsed?"":"."+CLASSES.closed)+":not(."+CLASSES.open+")").find(">ul").hide();}
return this.filter(":has(>ul)");},applyClasses:function(settings,toggler){this.filter(":has(>ul):not(:has(>a))").click(function(event){toggler.apply($(this).next());}).add($("a",this)).hoverClass();if(!settings.prerendered){this.filter(":has(>ul:hidden)").addClass(CLASSES.expandable).replaceClass(CLASSES.last,CLASSES.lastExpandable);this.not(":has(>ul:hidden)").addClass(CLASSES.collapsable).replaceClass(CLASSES.last,CLASSES.lastCollapsable);this.prepend("<div class=\""+CLASSES.hitarea+"\"/>").find("div."+CLASSES.hitarea).each(function(){var classes="";$.each($(this).parent().attr("class").split(" "),function(){classes+=this+"-hitarea ";});$(this).addClass(classes);});}
this.find("div."+CLASSES.hitarea).click(toggler);},treeview:function(settings){settings=$.extend({cookieId:"treeview"},settings);if(settings.add){return this.trigger("add",[settings.add]);}
if(settings.toggle){var callback=settings.toggle;settings.toggle=function(){return callback.apply($(this).parent()[0],arguments);};}
function treeController(tree,control){function handler(filter){return function(){toggler.apply($("div."+CLASSES.hitarea,tree).filter(function(){return filter?$(this).parent("."+filter).length:true;}));return false;};}
$("a:eq(0)",control).click(handler(CLASSES.collapsable));$("a:eq(1)",control).click(handler(CLASSES.expandable));$("a:eq(2)",control).click(handler());}
function toggler(){$(this).parent().find(">.hitarea").swapClass(CLASSES.collapsableHitarea,CLASSES.expandableHitarea).swapClass(CLASSES.lastCollapsableHitarea,CLASSES.lastExpandableHitarea).end().swapClass(CLASSES.collapsable,CLASSES.expandable).swapClass(CLASSES.lastCollapsable,CLASSES.lastExpandable).find(">ul").heightToggle(settings.animated,settings.toggle);if(settings.unique){$(this).parent().siblings().find(">.hitarea").replaceClass(CLASSES.collapsableHitarea,CLASSES.expandableHitarea).replaceClass(CLASSES.lastCollapsableHitarea,CLASSES.lastExpandableHitarea).end().replaceClass(CLASSES.collapsable,CLASSES.expandable).replaceClass(CLASSES.lastCollapsable,CLASSES.lastExpandable).find(">ul").heightHide(settings.animated,settings.toggle);}}
function serialize(){function binary(arg){return arg?1:0;}
var data=[];branches.each(function(i,e){data[i]=$(e).is(":has(>ul:visible)")?1:0;});$.cookie(settings.cookieId,data.join(""));}
function deserialize(){var stored=$.cookie(settings.cookieId);if(stored){var data=stored.split("");branches.each(function(i,e){$(e).find(">ul")[parseInt(data[i])?"show":"hide"]();});}}
this.addClass("treeview");var branches=this.find("li").prepareBranches(settings);switch(settings.persist){case"cookie":var toggleCallback=settings.toggle;settings.toggle=function(){serialize();if(toggleCallback){toggleCallback.apply(this,arguments);}};deserialize();break;case"location":var current=this.find("a").filter(function(){return this.href.toLowerCase()==location.href.toLowerCase();});if(current.length){current.addClass("selected").parents("ul, li").add(current.next()).show();}
break;}
branches.applyClasses(settings,toggler);if(settings.control){treeController(this,settings.control);$(settings.control).show();}
return this.bind("add",function(event,branches){$(branches).prev().removeClass(CLASSES.last).removeClass(CLASSES.lastCollapsable).removeClass(CLASSES.lastExpandable).find(">.hitarea").removeClass(CLASSES.lastCollapsableHitarea).removeClass(CLASSES.lastExpandableHitarea);$(branches).find("li").andSelf().prepareBranches(settings).applyClasses(settings,toggler);});}});var CLASSES=$.fn.treeview.classes={open:"open",closed:"closed",expandable:"expandable",expandableHitarea:"expandable-hitarea",lastExpandableHitarea:"lastExpandable-hitarea",collapsable:"collapsable",collapsableHitarea:"collapsable-hitarea",lastCollapsableHitarea:"lastCollapsable-hitarea",lastCollapsable:"lastCollapsable",lastExpandable:"lastExpandable",last:"last",hitarea:"hitarea"};$.fn.Treeview=$.fn.treeview;})(jQuery);;(function($){function load(settings,root,child,container){$.getJSON(settings.url,{root:root},function(response){function createNode(parent){var current=$("<li/>").attr("id",this.id||"").html("<span>"+this.text+"</span>").appendTo(parent);if(this.classes){current.children("span").addClass(this.classes);}
if(this.expanded){current.addClass("open");}
if(this.hasChildren||this.children&&this.children.length){var branch=$("<ul/>").appendTo(current);if(this.hasChildren){current.addClass("hasChildren");createNode.call({text:"placeholder",id:"placeholder",children:[]},branch);}
if(this.children&&this.children.length){$.each(this.children,createNode,[branch])}}}
$.each(response,createNode,[child]);$(container).treeview({add:child});});}
var proxied=$.fn.treeview;$.fn.treeview=function(settings){if(!settings.url){return proxied.apply(this,arguments);}
var container=this;load(settings,"source",this,container);var userToggle=settings.toggle;return proxied.call(this,$.extend({},settings,{collapsed:true,toggle:function(){var $this=$(this);if($this.hasClass("hasChildren")){var childList=$this.removeClass("hasChildren").find("ul");childList.empty();load(settings,this.id,childList,container);}
if(userToggle){userToggle.apply(this,arguments);}}}));};})(jQuery);
