var DraggedItem=null;var ShortcodeNextSave=0;var ShortcodeTimeOut=null;var ShortcodeString="";var Autosave=false;var PageObsolete=false;var PageUpdating=false;var CheckObsolescenceTimeOut=5E3;var wfu_transfers_observer_interval=100;var wfu_allops_freeze_events=false;var wfu_PD_bank={};
jQuery(document).ready(function($){$(".wfu_color_field").wpColorPicker({change:function(event,ui){event.target.value=ui.color.toString();if(event.target.name=="wfu_text_elements")wfu_update_text_value(event);else if(event.target.name=="wfu_triplecolor_elements")wfu_update_triplecolor_value(event)}})});
function wfu_admin_activate_tab(key){var tabs=document.getElementById("wfu_tab_container");var tab,tabkey;for(var i=0;i<tabs.childNodes.length;i++){tab=tabs.childNodes[i];if(tab.nodeType===1){tabkey=tab.id.substr(8);if(tab.className.indexOf("nav-tab-active")>-1){tab.className="nav-tab";document.getElementById("wfu_container_"+tabkey).style.display="none"}}}document.getElementById("wfu_tab_"+key).className="nav-tab nav-tab-active";document.getElementById("wfu_container_"+key).style.display="block"}
function wfu_admin_onoff_clicked(key){var onoff=document.getElementById("wfu_attribute_"+key);var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key);var shadows_inv=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key+"_inv");var status=onoff.className.substr(onoff.className.length-2)=="on";status=!status;if(status){document.getElementById("wfu_attribute_value_"+key).value="true";onoff.className="wfu_onoff_container_on";for(var i=0;i<shadows.length;i++)shadows[i].style.display=
"none";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="block"}else{document.getElementById("wfu_attribute_value_"+key).value="false";onoff.className="wfu_onoff_container_off";for(var i=0;i<shadows.length;i++)shadows[i].style.display="block";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="none"}wfu_generate_shortcode();if(key=="userdata"||key=="formdata")wfu_update_formfield_variables()}
function wfu_admin_radio_clicked(key){var radios=document.getElementsByName("wfu_radioattribute_"+key);var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key);var shadows_inv=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key+"_inv");var val="";for(i=0;i<radios.length;i++)if(radios[i].checked)val=radios[i].value;var status=val.substr(0,1)=="*";if(status){val=val.substr(1);for(var i=0;i<shadows.length;i++)shadows[i].style.display="none";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display=
"block"}else{for(var i=0;i<shadows.length;i++)shadows[i].style.display="block";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="none"}document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}function wfu_set_checkbox_status(check,status){if(status==0){check.checked=false;check.indeterminate=true;check.classList.add("indeterminate")}else{check.indeterminate=false;check.classList.remove("indeterminate");check.checked=status==1}}
function wfu_addEventHandler(obj,evt,handler){if(obj.addEventListener)obj.addEventListener(evt,handler,false);else if(obj.attachEvent)obj.attachEvent("on"+evt,handler);else obj["on"+evt]=handler}
function wfu_attach_separator_dragdrop_events(){var container=document.getElementById("wfu_placements_container");var item;for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_separator_hor"||item.className=="wfu_component_separator_ver"){wfu_addEventHandler(item,"dragenter",wfu_separator_dragenter);wfu_addEventHandler(item,"dragover",wfu_default_dragover);wfu_addEventHandler(item,"dragleave",wfu_separator_dragleave);wfu_addEventHandler(item,
"drop",wfu_separator_drop)}}}
function wfu_Attach_Admin_DragDrop_Events(){if(window.FileReader){var container=document.getElementById("wfu_placements_container");if(container){var available_container=document.getElementById("wfu_componentlist_container");var item;for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_box"){wfu_addEventHandler(item,"dragstart",wfu_component_dragstart);wfu_addEventHandler(item,"dragend",wfu_component_dragend)}}for(var i=0;i<available_container.childNodes.length;i++){item=
available_container.childNodes[i];if(item.className=="wfu_component_box_container")for(var ii=0;ii<item.childNodes.length;ii++)if(item.childNodes[ii].className=="wfu_component_box wfu_inbase"){wfu_addEventHandler(item.childNodes[ii],"dragstart",wfu_component_dragstart);wfu_addEventHandler(item.childNodes[ii],"dragend",wfu_component_dragend)}}item=document.getElementById("wfu_componentlist_dragdrop");wfu_addEventHandler(item,"dragenter",wfu_componentlist_dragenter);wfu_addEventHandler(item,"dragover",
wfu_default_dragover);wfu_addEventHandler(item,"dragleave",wfu_componentlist_dragleave);wfu_addEventHandler(item,"drop",wfu_componentlist_drop);wfu_attach_separator_dragdrop_events()}}}
function wfu_componentlist_dragenter(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;var item=document.getElementById("wfu_componentlist_dragdrop");if(item.className.indexOf("wfu_componentlist_dragdrop_dragover")==-1)item.className+=" wfu_componentlist_dragdrop_dragover";return false}
function wfu_componentlist_dragleave(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;var item=document.getElementById("wfu_componentlist_dragdrop");item.className=item.className.replace(" wfu_componentlist_dragdrop_dragover","");return false}
function wfu_componentlist_drop(e){e=e||window.event;if(e.preventDefault)e.preventDefault();var component_raw=e.dataTransfer.getData("Component");if(!component_raw)return false;var parts=component_raw.split("_");var component=parts[0];var multi_index=parseInt(parts[1]);var item=document.getElementById("wfu_component_box_"+component+"_"+multi_index);if(multi_index==0){item.className="wfu_component_box wfu_inbase";item.style.display="block";document.getElementById("wfu_component_box_container_"+component).appendChild(item)}else item.parentNode.removeChild(item);
var placements=wfu_admin_recreate_placements_text(null,"");wfu_admin_recreate_placements_panel(placements);document.getElementById("wfu_attribute_value_placements").value=placements;wfu_update_multiplacement_attributes();wfu_generate_shortcode();return false}
function wfu_separator_dragenter(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;if(e.target.className=="wfu_component_separator_hor"){var bar=document.getElementById("wfu_component_bar_hor");bar.style.top=e.target.offsetTop+"px";bar.style.display="block"}else if(e.target.className=="wfu_component_separator_ver"){var bar=document.getElementById("wfu_component_bar_ver");bar.style.top=e.target.offsetTop+"px";bar.style.left=e.target.offsetLeft+"px";bar.style.display=
"block"}return false}function wfu_default_dragover(e){e=e||window.event;if(e.preventDefault)e.preventDefault();return false}
function wfu_separator_dragleave(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;if(e.target.className=="wfu_component_separator_hor"){var bar=document.getElementById("wfu_component_bar_hor");bar.style.display="none"}else if(e.target.className=="wfu_component_separator_ver"){var bar=document.getElementById("wfu_component_bar_ver");bar.style.display="none"}return false}
function wfu_separator_drop(e){e=e||window.event;if(e.preventDefault)e.preventDefault();var component_raw=e.dataTransfer.getData("Component");if(!component_raw)return false;var parts=component_raw.split("_");var component=parts[0];var multi_index=parseInt(parts[1]);var item=document.getElementById("wfu_component_box_"+component+"_"+multi_index);item.style.display="none";item.className="wfu_component_box wfu_inbase";document.getElementById("wfu_component_box_container_"+component).appendChild(item);
var placements=wfu_admin_recreate_placements_text(e.target,component);wfu_admin_recreate_placements_panel(placements);document.getElementById("wfu_attribute_value_placements").value=placements;wfu_update_multiplacement_attributes();wfu_generate_shortcode();return false}
function wfu_component_dragstart(e){e=e||window.event;e.dataTransfer.setData("Component",e.target.id.replace("wfu_component_box_",""));if(e.target.className.indexOf("wfu_component_box_dragged")==-1){e.target.className+=" wfu_component_box_dragged";DraggedItem=e.target}e.target.style.zIndex=3;var item=document.getElementById("wfu_componentlist_dragdrop");item.className="wfu_componentlist_dragdrop wfu_componentlist_dragdrop_dragover";item.style.display="block";return false}
function wfu_component_dragend(e){e=e||window.event;DraggedItem=null;e.target.style.zIndex=1;var item=document.getElementById("wfu_componentlist_dragdrop");item.style.display="none";item.className="wfu_componentlist_dragdrop";e.target.className=e.target.className.replace(" wfu_component_box_dragged","");document.getElementById("wfu_component_bar_ver").style.display="none";document.getElementById("wfu_component_bar_hor").style.display="none";return false}
function wfu_admin_recreate_placements_text(place,new_component){function add_item(component){if(placements!="")placements+=delim;placements+=component;delim=""}var container=document.getElementById("wfu_placements_container");var delim="";var placements="";var component="";for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_separator_ver"){if(delim=="")delim="+";if(item==place){add_item(new_component);delim="+"}}else if(item.className=="wfu_component_separator_hor"){delim=
"/";if(item==place){add_item(new_component);delim="/"}}else if(item.className=="wfu_component_box")add_item(item.id.replace("wfu_component_box_","").replace(/_.*$/,""))}return placements}
function wfu_admin_recreate_placements_panel(placements_text){var container=document.getElementById("wfu_placements_container");var item,placements,sections,itemname_raw,parts,multi_index,index_item;var itemname="";for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_box"){itemname_raw=item.id.replace("wfu_component_box_","");parts=itemname_raw.split("_");itemname=parts[0];multi_index=parseInt(parts[1]);if(multi_index==0){item.style.display=
"inline-block";item.className="wfu_component_box wfu_inbase";document.getElementById("wfu_component_box_container_"+itemname).appendChild(item)}else item.parentNode.removeChild(item)}}var box_containers=document.querySelectorAll("div.wfu_component_box_container");var component_used={};for(var i=0;i<box_containers.length;i++){itemname=box_containers[i].id.replace("wfu_component_box_container_","");component_used[itemname]=0;index_item=document.querySelector("div#"+box_containers[i].id+" div.wfu_component_box_index");
if(index_item)index_item.innerHTML="1"}container.innerHTML="";placements=placements_text.split("/");for(var i=0;i<placements.length;i++){item=document.createElement("DIV");item.className="wfu_component_separator_hor";item.setAttribute("draggable",true);container.appendChild(item);item=document.createElement("DIV");item.className="wfu_component_separator_ver";item.setAttribute("draggable",true);container.appendChild(item);sections=placements[i].split("+");for(var ii=0;ii<sections.length;ii++){item=
document.querySelector("div#wfu_component_box_container_"+sections[ii]+" div.wfu_component_box.wfu_inbase");if(item){itemname_raw=item.id.replace("wfu_component_box_","");parts=itemname_raw.split("_");itemname=parts[0];multi_index=parseInt(parts[1]);if(multi_index==0)container.appendChild(item);else{component_used[itemname]++;item.id="wfu_component_box_"+itemname+"_"+(component_used[itemname]+1).toString();item.style.display="block";index_item=document.querySelector("div#"+item.id+" div.wfu_component_box_index");
index_item.innerHTML=(component_used[itemname]+1).toString();item=item.cloneNode(true);container.appendChild(item);item.id="wfu_component_box_"+itemname+"_"+component_used[itemname].toString();index_item=document.querySelector("div#"+item.id+" div.wfu_component_box_index");index_item.innerHTML=component_used[itemname].toString();wfu_addEventHandler(item,"dragstart",wfu_component_dragstart);wfu_addEventHandler(item,"dragend",wfu_component_dragend)}item.className="wfu_component_box";item.style.display=
"inline-block";item=document.createElement("DIV");item.className="wfu_component_separator_ver";item.setAttribute("draggable",true);container.appendChild(item)}}}item=document.createElement("DIV");item.className="wfu_component_separator_hor";item.setAttribute("draggable",true);container.appendChild(item);item=document.createElement("DIV");item.id="wfu_component_bar_hor";item.className="wfu_component_bar_hor";container.appendChild(item);item=document.createElement("DIV");item.id="wfu_component_bar_ver";
item.className="wfu_component_bar_ver";container.appendChild(item);wfu_attach_separator_dragdrop_events()}
function wfu_update_multiplacement_attributes(){var box_containers=document.querySelectorAll("div.wfu_component_box_container");for(var i=0;i<box_containers.length;i++){itemname=box_containers[i].id.replace("wfu_component_box_container_","");var index_item=document.querySelector("div#"+box_containers[i].id+" div.wfu_component_box_index");if(index_item){var occurrences=Math.max(1,parseInt(index_item.innerHTML)-1);var dependencies=document.getElementsByName("wfu_attribute_governor_"+itemname);for(var j=
0;j<dependencies.length;j++)wfu_update_multiplacement_attribute(dependencies[j].value,occurrences)}}}
function wfu_update_multiplacement_attribute(attribute,occurrencies){if(attribute=="userdatalabel"){var attributes=document.querySelectorAll("div.wfu_formdata_container");var current=attributes.length;if(current<1)return;var base=attributes[0],tr0,tr;var i=2;while(i<=Math.max(current,occurrencies)){if(i>current){var new_attribute=attribute+i.toString();tr0=base.parentNode;while(tr0!=null&&tr0.tagName!="TR")tr0=tr0.parentNode;if(tr0==null||tr0.tagName!="TR")return;tr=tr0.cloneNode(true);tr.id="tr_"+
wfu_randomString(4);tr0.parentNode.appendChild(tr);var elem=document.querySelector("tr#"+tr.id+' label[for="wfu_attribute_'+attribute+'"]');elem.setAttribute("for","wfu_attribute_"+new_attribute);elem.innerHTML+=" ("+i.toString()+")";elem=document.querySelector("tr#"+tr.id+" input.wfu_attribute_governor");elem.setAttribute("name","wfu_attribute_governor_independent");elem.value=new_attribute;elem=document.querySelector("tr#"+tr.id+" div.wfu_formdata_container");elem.id+=i.toString();var def=document.getElementById("wfu_attribute_default_"+
new_attribute);if(!def){def=document.createElement("INPUT");def.id="wfu_attribute_default_"+new_attribute;def.type="hidden";def.value=document.getElementById("wfu_attribute_default_"+attribute).value;document.getElementById("wfu_attribute_defaults").appendChild(def)}var shortcode_value=document.getElementById("wfu_attribute_value_"+new_attribute);if(!shortcode_value){shortcode_value=document.createElement("INPUT");shortcode_value.id="wfu_attribute_value_"+new_attribute;shortcode_value.type="hidden";
shortcode_value.value=def.value;document.getElementById("wfu_attribute_values").appendChild(shortcode_value)}window["wfu_attribute_"+new_attribute+"_formtemplate"]=window["wfu_attribute_"+attribute+"_formtemplate"];window["wfu_attribute_"+new_attribute+"_typeprops"]=window["wfu_attribute_"+attribute+"_typeprops"];wfu_apply_value(new_attribute,"formfields",shortcode_value.value)}else if(i>occurrencies){tr=attributes[i-1].parentNode;while(tr!=null&&tr.tagName!="TR")tr=tr.parentNode;if(tr==null||tr.tagName!=
"TR")return;tr.parentNode.removeChild(tr);wfu_update_formfield_variables()}i++}attributes=document.querySelectorAll("div.wfu_formdata_container");var names=[];for(var i=0;i<attributes.length;i++)names.push(attributes[i].id.replace(/^wfu_attribute_/,""));var all_attributes=document.querySelectorAll(".wfu_formdata_all_attributes");for(var i=0;i<all_attributes.length;i++)all_attributes[i].value=names.join(",");wfu_formdata_update_all_updown_buttons(attribute)}}
function wfu_subfolders_input_changed(e){e=e||window.event;var item=e.target;var key=item.id.replace("wfu_subfolders_path_","");key=key.replace("wfu_subfolders_label_","");var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var old_path_value,old_label_value;var isnewitem=
document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";if(isnewitem){old_path_value="";old_label_value=""}else{var items=list.data;item=items[list.selectedIndex];old_path_value=item.path;old_label_value=item.label}if(tools_path.value==old_path_value&&tools_label.value==old_label_value){tools_ok.disabled=true;if(!isnewitem)wfu_subfolders_update_nav(key)}else{tools_ok.disabled=false;var navs=document.getElementsByName("wfu_subfolder_nav_"+key);for(var i=0;i<navs.length;i++)navs[i].disabled=
true}}
function wfu_subfolders_auto_changed(key){var list=document.getElementById("wfu_attribute_"+key);var auto=document.getElementById("wfu_subfolders_auto_"+key);var editable=document.getElementById("wfu_subfolders_editable_"+key);var manualtext=document.getElementById("wfu_subfolders_manualtext_"+key);if(auto.checked){var manualvalue=document.getElementById("wfu_attribute_value_"+key).value;if(manualvalue.substr(0,4)!="auto")manualtext.value=manualvalue;editable.parentNode.style.display="inline";wfu_apply_value(key,
"folderlist","auto"+(editable.checked?"+":""));list.disabled=true}else{list.disabled=false;editable.parentNode.style.display="none";wfu_apply_value(key,"folderlist",manualtext.value)}}
function wfu_subfolders_up_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var prevind=item.index-1;if(prevind<0)return;var prevpos=-1;var curind=list.selectedIndex-1;while(curind>=0)if(items[curind].level==item.level&&items[curind].index==prevind){prevpos=curind;break}else curind--;if(prevpos==-1)return;var children_count=0;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>
item.level){children_count++;curind++}else break;items[prevpos].index=item.index;item.index=prevind;list.data=items.slice(0,prevpos).concat(items.slice(list.selectedIndex,list.selectedIndex+1+children_count)).concat(items.slice(prevpos,list.selectedIndex)).concat(items.slice(list.selectedIndex+1+children_count));var val=wfu_update_subfolder_list(key);list.selectedIndex=prevpos;wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
key).value=val;wfu_generate_shortcode()}}
function wfu_subfolders_down_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var nextind=item.index+1;var nextpos=-1;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level==item.level){nextpos=curind;break}else if(items[curind].level<item.level)break;else curind++;if(nextpos==-1)return;var next_children_count=0;curind=nextpos+1;while(curind<items.length)if(items[curind].level>
item.level){next_children_count++;curind++}else break;items[nextpos].index=item.index;item.index=nextind;list.data=items.slice(0,list.selectedIndex).concat(items.slice(nextpos,nextpos+1+next_children_count)).concat(items.slice(list.selectedIndex,nextpos)).concat(items.slice(nextpos+1+next_children_count));var val=wfu_update_subfolder_list(key);list.selectedIndex=list.selectedIndex+next_children_count+1;wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
key).value=val;wfu_generate_shortcode()}}
function wfu_subfolders_left_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){items[curind].level--;curind++}else break;item.level--;var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
key).value=val;wfu_generate_shortcode()}}
function wfu_subfolders_right_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){items[curind].level++;curind++}else break;item.level++;var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
key).value=val;wfu_generate_shortcode()}}
function wfu_subfolders_def_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];if(item["default"])item["default"]=false;else{for(var i=0;i<items.length;i++)items[i]["default"]=false;item["default"]=true}var val=wfu_update_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
function wfu_subfolders_ok_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);if(tools_path.value==""||tools_label.value==""){alert("Path or label cannot be empty!");return}var items=list.data;var isnewitem=document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";if(isnewitem){var newlevel=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+
key).value);var newitem={label:tools_label.value,path:tools_path.value,level:newlevel,"default":false};var newpos=parseInt(document.getElementById("wfu_subfolders_newitemindex_"+key).value);if(newpos>=items.length)items.push(newitem);else items.splice(newpos,0,newitem)}else{item=items[list.selectedIndex];item.path=tools_path.value;item.label=tools_label.value}var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=
val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
function wfu_subfolders_del_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var children_count=0;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){children_count++;curind++}else break;if(children_count>0)if(!confirm("Children items will be deleted as well. Proceed?"))return;items.splice(list.selectedIndex,1+children_count);var val=wfu_update_subfolder_list(key);
list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
function wfu_subfolders_add_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;var curpos=list.selectedIndex;item=items[curpos];var opts=list.options;var opt=document.createElement("option");opt.value="";opt.innerHTML="";opts.add(opt,curpos);list.selectedIndex=curpos;var tools_container=document.getElementById("wfu_subfolder_tools_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+
key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var tools_browse=document.getElementById("wfu_subfolders_browse_"+key);tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;document.getElementById("wfu_subfolders_isnewitem_"+key).value="1";document.getElementById("wfu_subfolders_newitemindex_"+key).value=curpos;document.getElementById("wfu_subfolders_newitemlevel_"+key).value=item.level;document.getElementById("wfu_subfolders_newitemlevel2_"+
key).value="";tools_path.disabled=item.level==0;tools_browse.disabled=item.level==0;if(item.level==0){tools_path.value="{root}";tools_label.value="{upload folder}"}else{tools_path.value="";tools_label.value=""}var navs=document.getElementsByName("wfu_subfolder_nav_"+key);for(var i=0;i<navs.length;i++)navs[i].disabled=true}
function wfu_subfolders_browse_clicked(key){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var fd=null;try{var fd=new FormData}catch(e){}if(fd==null)return;var container=document.getElementById("wfu_global_dialog_container");var dialog=document.getElementById("wfu_subfolders_browser_"+key);var btn=document.getElementById("wfu_subfolders_browse_"+key);var shadow=document.getElementById("wfu_subfolders_inner_shadow_"+key);var msgcont=document.getElementById("wfu_subfolders_browser_msgcont_"+
key);var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);var list=document.getElementById("wfu_subfolders_browser_list_"+key);while(list.options.length>0)list.options.remove(0);ok.disabled=true;ok.onclick=function(){wfu_folder_browser_cancel_clicked(key)};msg.innerHTML="loading folder contents...";img.style.display="inline";msgcont.style.display="block";
container.style.display="block";dialog.style.display="block";dialog.style.left=btn.offsetLeft+btn.offsetWidth-dialog.offsetWidth+"px";dialog.style.top=btn.offsetTop+btn.offsetHeight-dialog.offsetHeight+"px";shadow.style.display="block";container.onclick=function(){wfu_folder_browser_cancel_clicked(key)};var path=document.getElementById("wfu_attribute_uploadpath").value;if(path.substr(path.length-1)=="/")path=path.substr(0,path.length-1);var paths=wfu_get_relative_path(key).split(",");var path1=path+
paths[0];if(path1.substr(0)!="/")path1="/"+path1;var path2="";if(paths.length==2)path2=paths[1];fd.append("action","wfu_ajax_action_read_subfolders");fd.append("folder1",wfu_plugin_encode_string(path1));fd.append("folder2",wfu_plugin_encode_string(path2));xhr.key=key;xhr.addEventListener("load",wfu_readfolderComplete,false);xhr.addEventListener("error",wfu_readfolderFailed,false);xhr.addEventListener("abort",wfu_readfolderCanceled,false);xhr.open("POST",AdminParams.wfu_ajax_url);xhr.send(fd)}
function wfu_readfolderComplete(evt){var key=evt.target.key;var msgcont=document.getElementById("wfu_subfolders_browser_msgcont_"+key);var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var list=document.getElementById("wfu_subfolders_browser_list_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+
key);var txt=evt.target.responseText;if(txt!=-1){var start_text="wfu_read_subfolders:";var pos=evt.target.responseText.indexOf(start_text);if(pos==-1)pos=evt.target.responseText.length;var messages=evt.target.responseText.substr(0,pos);var response=evt.target.responseText.substr(pos+start_text.length,evt.target.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){var filelist=
wfu_plugin_decode_string(txt_value);var flist=filelist.split(",");var fcount=0;var opt;for(var i=0;i<flist.length;i++)if(flist[i]!=""){opt=document.createElement("option");opt.value=flist[i];opt.innerHTML=flist[i].replace("*","&nbsp;&nbsp;&nbsp;");list.add(opt);fcount++}if(fcount==0){opt=document.createElement("option");opt.value="";opt.innerHTML="{empty}";opt.disabled=true;list.add(opt)}list.selectedIndex=-1;ok.onclick=function(){var val=list.options[list.selectedIndex].value;var level=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+
key).value);if(val.substr(0,1)=="*"||level==0){document.getElementById("wfu_subfolders_newitemlevel_"+key).value=level+1;if(level>0)val=val.substr(1)}tools_path.value=val;tools_label.value=val;wfu_folder_browser_cancel_clicked(key);wfu_subfolders_ok_clicked(key)};msgcont.style.display="none"}else if(txt_header=="error"){msg.innerHTML=txt_value;img.style.display="none";ok.disabled=false}else{msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}}}
function wfu_readfolderFailed(evt){var key=evt.target.key;var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}
function wfu_readfolderCanceled(evt){var key=evt.target.key;var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}
function wfu_subfolders_browser_list_changed(key){var list=document.getElementById("wfu_subfolders_browser_list_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);ok.disabled=list.selectedIndex<0}
function wfu_folder_browser_cancel_clicked(key){var container=document.getElementById("wfu_global_dialog_container");var dialog=document.getElementById("wfu_subfolders_browser_"+key);var btn=document.getElementById("wfu_subfolders_browse_"+key);var shadow=document.getElementById("wfu_subfolders_inner_shadow_"+key);container.onclick=null;shadow.style.display="none";dialog.style.display="none";container.style.display="none"}
function wfu_get_relative_path(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;var isnewitem=document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";var level;if(isnewitem)level=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+key).value);else level=items[list.selectedIndex].level;var relpath="/";var curpos=list.selectedIndex-1;var curlevel=level;while(curpos>=0&&curlevel>1){if(items[curpos].level<curlevel){relpath=
"/"+items[curpos].path+relpath;curlevel=items[curpos].level}curpos--}if(isnewitem&&document.getElementById("wfu_subfolders_newitemlevel2_"+key).value=="1"&&level>0&&list.selectedIndex>0)relpath+=","+items[list.selectedIndex-1].path;return relpath}function wfu_subfolders_changed(key){wfu_update_subfolder_list(key);wfu_subfolders_update_toolnav(key)}
function wfu_subfolders_update_toolnav(key){var list=document.getElementById("wfu_attribute_"+key);var items,item,ind,nextind,prevlevel;var tools_container=document.getElementById("wfu_subfolder_tools_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var tools_browse=document.getElementById("wfu_subfolders_browse_"+key);var auto=document.getElementById("wfu_subfolders_auto_"+
key);document.getElementById("wfu_subfolders_isnewitem_"+key).value="";document.getElementById("wfu_subfolders_newitemindex_"+key).value="";document.getElementById("wfu_subfolders_newitemlevel_"+key).value="";document.getElementById("wfu_subfolders_newitemlevel2_"+key).value="";if(list.data==null){items=wfu_decode_subfolder_list(key);list.data=items}else items=list.data;if(list.data.length===0){list.className="wfu_select_folders wfu_select_folders_empty";list.options[0].innerHTML=auto.checked?"":
"press here"}else list.className="wfu_select_folders";if(list.selectedIndex<0){tools_container.className="wfu_subfolder_tools_container wfu_subfolder_tools_disabled";tools_path.disabled=true;tools_label.disabled=true;tools_ok.disabled=true;tools_browse.disabled=true;tools_label.value="";tools_path.value=""}else if(list.selectedIndex>=list.options.length-1){tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;document.getElementById("wfu_subfolders_isnewitem_"+
key).value="1";document.getElementById("wfu_subfolders_newitemindex_"+key).value=items.length;var level;if(items.length==0)level=0;else if(items[items.length-1].level==0)level=1;else level=items[items.length-1].level;document.getElementById("wfu_subfolders_newitemlevel_"+key).value=level;document.getElementById("wfu_subfolders_newitemlevel2_"+key).value="1";tools_path.disabled=level==0;tools_browse.disabled=false;if(level==0){tools_path.value="{root}";tools_label.value="{upload folder}"}else{tools_path.value=
"";tools_label.value=""}}else{tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;item=items[list.selectedIndex];tools_path.disabled=item.level==0;tools_browse.disabled=item.level==0;tools_label.value=item.label;tools_path.value=item.path}var navs=document.getElementsByName("wfu_subfolder_nav_"+key);if(list.selectedIndex<0||list.selectedIndex>=list.options.length-1)for(var i=0;i<navs.length;i++)navs[i].disabled=true;else wfu_subfolders_update_nav(key)}
function wfu_subfolders_update_nav(key){var list=document.getElementById("wfu_attribute_"+key);var navs_up=document.getElementById("wfu_subfolders_up_"+key);var navs_down=document.getElementById("wfu_subfolders_down_"+key);var navs_left=document.getElementById("wfu_subfolders_left_"+key);var navs_right=document.getElementById("wfu_subfolders_right_"+key);var navs_add=document.getElementById("wfu_subfolders_add_"+key);var navs_def=document.getElementById("wfu_subfolders_def_"+key);var navs_del=document.getElementById("wfu_subfolders_del_"+
key);var items=list.data;var item=items[list.selectedIndex];navs_up.disabled=item.index<=0;ind=list.selectedIndex+1;nextind=0;while(ind<items.length)if(items[ind].level==item.level){nextind=items[ind].index;break}else if(items[ind].level<item.level)break;else ind++;navs_down.disabled=item.level==0||nextind==0;navs_left.disabled=list.selectedIndex==0&&item.level<1||list.selectedIndex>0&&item.level<=1;if(list.selectedIndex>=1)prevlevel=items[list.selectedIndex-1].level;else prevlevel=0;navs_right.disabled=
item.level-prevlevel>0;navs_add.disabled=item.level==0;navs_def.disabled=false;navs_def.className="button"+(item["default"]?" wfu_subfolder_nav_pressed":"");navs_del.disabled=false}
function wfu_decode_subfolder(data){var ret={label:"",path:"",level:0,"default":false};data=data.trim();var star_count=0;var is_default=false;while(star_count<data.length)if(data.substr(star_count,1)=="*")star_count++;else break;data=data.substr(star_count,data.length-star_count);if(data.substr(0,1)=="&"){data=data.substr(1);is_default=true}ret.level=star_count;ret["default"]=is_default;var data_raw=data.split("/");if(data_raw.length==1){ret.path=data_raw[0];ret.label=data_raw[0]}else if(data_raw.length>
1){ret.path=data_raw[0];ret.label=data_raw[1]}if(star_count==0){ret.path="{root}";if(ret.label=="")ret.label="{upload folder}"}return ret}
function wfu_decode_subfolder_list(key){var opts=document.getElementById("wfu_attribute_"+key).options;var list=Array();var dir_levels=["root"];var last_index=[0];var subfolder_path;var prev_level=-1;for(var i=0;i<opts.length-1;i++){list.push(wfu_decode_subfolder(wfu_plugin_decode_string(opts[i].value)));if(dir_levels.length>list[i].level)dir_levels[list[i].level]=list[i].path;else dir_levels.push(list[i].path);subfolder_path="";for(j=1;j<=list[i].level;j++)subfolder_path+=dir_levels[j]+"/";list[i].fullpath=
subfolder_path;if(last_index.length<=list[i].level)last_index.push(0);if(list[i].level>prev_level)list[i].index=0;else list[i].index=last_index[list[i].level]+1;last_index[list[i].level]=list[i].index;prev_level=list[i].level}return list}
function wfu_update_subfolder_list(key){var opts=document.getElementById("wfu_attribute_"+key).options;var list=document.getElementById("wfu_attribute_"+key);var items=list.data;if(items==null)return;var value_raw,text_raw;var global_raw="";opts.length=items.length+1;for(var i=0;i<items.length;i++){value_raw="";text_raw="";for(j=0;j<items[i].level;j++){value_raw+="*";text_raw+="&nbsp;&nbsp;&nbsp;"}if(items[i]["default"]){value_raw+="&";opts[i].className="wfu_select_folders_option_default"}else opts[i].className=
"";value_raw+=items[i].path+"/"+items[i].label;text_raw+=items[i].label;opts[i].value=wfu_plugin_encode_string(value_raw);opts[i].innerHTML=text_raw;if(global_raw!="")global_raw+=",";global_raw+=value_raw}opts[items.length].value="";opts[items.length].innerHTML="";return global_raw}
function wfu_userdata_edit_field(line,label,required){var item;for(var i=0;i<line.childNodes.length;i++){item=line.childNodes[i];if(item.tagName=="INPUT")if(item.type=="text"){item.value=label;wfu_attach_element_handlers(item,wfu_update_userfield_value)}else{if(item.type=="checkbox")item.checked=required}else if(item.tagName=="DIV")item.className="wfu_userdata_action"}}function wfu_formdata_edit_field(line,label,required){}
function wfu_formdata_get_field_props(key){var key_parts=key.split("_");var attribute=key_parts[0];var a="wfu_formfield_"+key;var fielddef=window["wfu_attribute_"+attribute+"_typeprops"][document.getElementById(a+"_type").value];var field={type:document.getElementById(a+"_type").value,label:document.getElementById(a+"_label").value,labelposition:document.getElementById(a+"_labelposition").value,required:fielddef.required.substr(0,4)=="show"&&document.getElementById(a+"_required")?document.getElementById(a+
"_required").checked:fielddef.required.substr(5)=="true",donotautocomplete:fielddef.donotautocomplete.substr(0,4)=="show"&&document.getElementById(a+"_donotautocomplete")?document.getElementById(a+"_donotautocomplete").checked:fielddef.donotautocomplete.substr(5)=="true",validate:fielddef.validate.substr(0,4)=="show"&&document.getElementById(a+"_validate")?document.getElementById(a+"_validate").checked:fielddef.validate.substr(5)=="true",typehook:fielddef.typehook.substr(0,4)=="show"&&document.getElementById(a+
"_typehook")?document.getElementById(a+"_typehook").checked:fielddef.typehook.substr(5)=="true",hintposition:fielddef.hintposition.substr(0,4)=="show"&&document.getElementById(a+"_hintposition")?document.getElementById(a+"_hintposition").value:fielddef.hintposition.substr(5),"default":fielddef["default"].substr(0,4)=="show"&&document.getElementById(a+"_default")?document.getElementById(a+"_default").value:fielddef["default"].substr(5),data:fielddef.data.substr(0,4)=="show"&&document.getElementById(a+
"_data")?document.getElementById(a+"_data").value:fielddef.data.substr(5),group:fielddef.group.substr(0,4)=="show"&&document.getElementById(a+"_group")?document.getElementById(a+"_group").value:fielddef.group.substr(5),format:fielddef.format.substr(0,4)=="show"&&document.getElementById(a+"_format")?document.getElementById(a+"_format").value:fielddef.format.substr(5)};return field}
function wfu_formdata_type_changed(key){var key_parts=key.split("_");var attribute=key_parts[0];var a="wfu_formfield_"+key;var line_container=document.getElementById(a+"_container");var field=wfu_formdata_get_field_props(key);var template=wfu_formdata_prepare_template(attribute,field,key);line_container.innerHTML=template;var formfield_elements=document.querySelectorAll("div#"+a+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
wfu_update_formfield_value);wfu_formdata_update_buttons(key);wfu_update_formfield_value({target:line_container})}function wfu_userdata_add_field(obj){var line=obj.parentNode;var newline=line.cloneNode(true);wfu_userdata_edit_field(newline,"",false);line.parentNode.insertBefore(newline,line.nextSibling)}
function wfu_formdata_add_field(key){var key_parts=key.split("_");var attribute=key_parts[0];var ind=key_parts[1];var container=document.getElementById("wfu_attribute_"+attribute);var prev=document.getElementById("wfu_formfield_"+key+"_container");var new_line_container=document.createElement("DIV");var new_key=attribute+"_"+wfu_randomString(4);new_line_container.id="wfu_formfield_"+new_key+"_container";new_line_container.className="wfu_formdata_line_container";container.insertBefore(new_line_container,
prev.nextSibling);var field={type:"text",label:"",labelposition:"left",required:false,donotautocomplete:false,validate:false,"default":"",data:"",group:"",format:"",hintposition:"right",typehook:false};var template=wfu_formdata_prepare_template(attribute,field,new_key);new_line_container.innerHTML=template;var formfield_elements=document.querySelectorAll("div#wfu_formfield_"+new_key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
wfu_update_formfield_value);wfu_formdata_update_buttons(key);wfu_formdata_update_buttons(new_key);wfu_update_formfield_value({target:new_line_container})}
function wfu_formdata_prepare_template(attribute,field,key){var template=wfu_plugin_decode_string(window["wfu_attribute_"+attribute+"_formtemplate"]);var fielddef=window["wfu_attribute_"+attribute+"_typeprops"][field.type];var fielddef_array=window["wfu_attribute_"+attribute+"_typeprops"][0].split(",");var fieldprops_basic=["required","donotautocomplete","validate","typehook","labelposition","hintposition","default","data","group","format"];var labelpositions=["none","top","right","bottom","left",
"placeholder"];var hintpositions=["none","inline","top","right","bottom","left"];template=template.replace(/\[\[key\]\]/g,key).replace(/\[\[t\]\]/g,field.type).replace(/\[\[label\]\]/g,field.label).replace(/\[\[s\]\]/g,field.labelposition).replace(/\[\[d\]\]/g,field["default"]).replace(/\[\[l\]\]/g,field.data).replace(/\[\[data_label\]\]/g,fielddef.data_label).replace(/\[\[g\]\]/g,field.group).replace(/\[\[f\]\]/g,field.format).replace(/\[\[p\]\]/g,field.hintposition);for(var i=0;i<fieldprops_basic.length;i++)template=
template.replace(new RegExp("\\[\\["+fieldprops_basic[i]+"_hint\\]\\]","g"),fielddef[fieldprops_basic[i]+"_hint"]);for(var i=0;i<fielddef_array.length;i++)template=template.replace("[[type_"+fielddef_array[i]+"_selected]]",fielddef_array[i]==field.type?' selected="selected"':"");for(var i=0;i<labelpositions.length;i++)template=template.replace("[[labelposition_"+labelpositions[i]+"_selected]]",labelpositions[i]==field.labelposition?' selected="selected"':"");for(var i=0;i<hintpositions.length;i++)template=
template.replace("[[hintposition_"+hintpositions[i]+"_selected]]",hintpositions[i]==field.hintposition?' selected="selected"':"");template=template.replace("[[remove_disabled]]","");template=template.replace("[[up_disabled]]","");template=template.replace("[[down_disabled]]","");template=field.required?template.replace(/\[\[r\->\]\]|\[\[<\-r\]\]/g,""):template.replace(/\[\[r\->\]\].*\[\[<\-r\]\]/g,"");template=field.donotautocomplete?template.replace(/\[\[a\->\]\]|\[\[<\-a\]\]/g,""):template.replace(/\[\[a\->\]\].*\[\[<\-a\]\]/g,
"");template=field.validate?template.replace(/\[\[v\->\]\]|\[\[<\-v\]\]/g,""):template.replace(/\[\[v\->\]\].*\[\[<\-v\]\]/g,"");template=field.typehook?template.replace(/\[\[h\->\]\]|\[\[<\-h\]\]/g,""):template.replace(/\[\[h\->\]\].*\[\[<\-h\]\]/g,"");template=fielddef.required.substr(0,4)=="show"?template.replace(/\[\[R\->\]\]|\[\[<\-R\]\]/g,""):template.replace(/\[\[R\->\]\][^]*\[\[<\-R\]\]/g,"");template=fielddef.donotautocomplete.substr(0,4)=="show"?template.replace(/\[\[A\->\]\]|\[\[<\-A\]\]/g,
""):template.replace(/\[\[A\->\]\][^]*\[\[<\-A\]\]/g,"");template=fielddef.validate.substr(0,4)=="show"?template.replace(/\[\[V\->\]\]|\[\[<\-V\]\]/g,""):template.replace(/\[\[V\->\]\][^]*\[\[<\-V\]\]/g,"");template=fielddef.hintposition.substr(0,4)=="show"?template.replace(/\[\[P\->\]\]|\[\[<\-P\]\]/g,""):template.replace(/\[\[P\->\]\][^]*\[\[<\-P\]\]/g,"");template=fielddef.typehook.substr(0,4)=="show"?template.replace(/\[\[H\->\]\]|\[\[<\-H\]\]/g,""):template.replace(/\[\[H\->\]\][^]*\[\[<\-H\]\]/g,
"");template=fielddef["default"].substr(0,4)=="show"?template.replace(/\[\[D\->\]\]|\[\[<\-D\]\]/g,""):template.replace(/\[\[D\->\]\][^]*\[\[<\-D\]\]/g,"");template=fielddef.data.substr(0,4)=="show"?template.replace(/\[\[L\->\]\]|\[\[<\-L\]\]/g,""):template.replace(/\[\[L\->\]\][^]*\[\[<\-L\]\]/g,"");template=fielddef.group.substr(0,4)=="show"?template.replace(/\[\[G\->\]\]|\[\[<\-G\]\]/g,""):template.replace(/\[\[G\->\]\][^]*\[\[<\-G\]\]/g,"");template=fielddef.format.substr(0,4)=="show"?template.replace(/\[\[F\->\]\]|\[\[<\-F\]\]/g,
""):template.replace(/\[\[F\->\]\][^]*\[\[<\-F\]\]/g,"");return template}function wfu_userdata_remove_field(obj){var line=obj.parentNode;var container=line.parentNode;var first=null;for(var i=0;i<container.childNodes.length;i++)if(container.childNodes[i].nodeType===1){first=container.childNodes[i];break}if(line!=first){line.parentNode.removeChild(line);for(var i=0;i<first.childNodes.length;i++)if(first.childNodes[i].nodeType===1){wfu_update_userfield_value({target:first.childNodes[i]});break}}}
function wfu_formdata_remove_field(key){var key_parts=key.split("_");var attribute=key_parts[0];var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");if(containers.length<2)return;var container=document.getElementById("wfu_attribute_"+attribute);var line_container=document.getElementById("wfu_formfield_"+key+"_container");var line_container_index=0;for(var i=0;i<containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}container.removeChild(line_container);
containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");if(line_container_index>containers.length)line_container_index=containers.length;line_container=containers[line_container_index-1];var prev_key=line_container.id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");wfu_formdata_update_buttons(prev_key);wfu_update_formfield_value({target:line_container})}
function wfu_formdata_move_field(key,direction){var key_parts=key.split("_");var attribute=key_parts[0];var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");var attr_occur_index=all_attributes.indexOf(attribute)+1;var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var container=document.getElementById("wfu_attribute_"+attribute);var line_container=document.getElementById("wfu_formfield_"+
key+"_container");var line_container_index=0;for(var i=0;i<containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}if(direction=="up"&&attr_occur_index==1&&line_container_index==1||direction=="down"&&attr_occur_index==all_attributes.length&&line_container_index==containers.length)return;var field=wfu_formdata_get_field_props(key);var other_attribute=attribute;var other_line_container=line_container;if(direction=="up")if(line_container_index>1)other_line_container=containers[line_container_index-
2];else{other_attribute=all_attributes[attr_occur_index-2];var other_containers=document.querySelectorAll("div#wfu_attribute_"+other_attribute+" .wfu_formdata_line_container");other_line_container=other_containers[other_containers.length-1]}else if(line_container_index<containers.length)other_line_container=containers[line_container_index];else{other_attribute=all_attributes[attr_occur_index];var other_containers=document.querySelectorAll("div#wfu_attribute_"+other_attribute+" .wfu_formdata_line_container");
other_line_container=other_containers[0]}var other_key=other_line_container.id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");if(other_attribute==attribute)if(direction=="up")container.insertBefore(line_container,other_line_container);else container.insertBefore(other_line_container,line_container);else{var other_field=wfu_formdata_get_field_props(other_key);var template=wfu_formdata_prepare_template(other_attribute,field,other_key);other_line_container.innerHTML=template;var formfield_elements=
document.querySelectorAll("div#wfu_formfield_"+other_key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);template=wfu_formdata_prepare_template(attribute,other_field,key);line_container.innerHTML=template;formfield_elements=document.querySelectorAll("div#wfu_formfield_"+key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
wfu_update_formfield_value)}wfu_formdata_update_buttons(key);wfu_formdata_update_buttons(other_key);wfu_update_formfield_value({target:line_container});if(other_attribute!=attribute)wfu_update_formfield_value({target:other_line_container})}
function wfu_formdata_update_buttons(key){var key_parts=key.split("_");var attribute=key_parts[0];var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");var attr_occur_index=all_attributes.indexOf(attribute)+1;var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var line_container=document.getElementById("wfu_formfield_"+key+"_container");var line_container_index=0;for(var i=0;i<
containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}var up_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_up");var down_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_down");var remove_elements=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_action_remove");up_element.className="wfu_formdata_action wfu_formdata_action_up"+
(attr_occur_index==1&&line_container_index==1?" wfu_formdata_action_disabled":"");down_element.className="wfu_formdata_action wfu_formdata_action_down"+(attr_occur_index==all_attributes.length&&line_container_index==containers.length?" wfu_formdata_action_disabled":"");for(var i=0;i<remove_elements.length;i++)remove_elements[i].className="wfu_formdata_action wfu_formdata_action_remove"+(remove_elements.length>1?"":" wfu_formdata_action_disabled")}
function wfu_formdata_update_all_updown_buttons(attribute){var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");for(var i=0;i<all_attributes.length;i++){var ii=i+1;var containers=document.querySelectorAll("div#wfu_attribute_"+all_attributes[i]+" .wfu_formdata_line_container");for(var j=0;j<containers.length;j++){var jj=j+1;var key=containers[j].id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");var up_element=document.querySelector("div#wfu_formfield_"+
key+"_container .wfu_formdata_action.wfu_formdata_action_up");var down_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_down");up_element.className="wfu_formdata_action wfu_formdata_action_up"+(ii==1&&jj==1?" wfu_formdata_action_disabled":"");down_element.className="wfu_formdata_action wfu_formdata_action_down"+(ii==all_attributes.length&&jj==containers.length?" wfu_formdata_action_disabled":"")}}}
function wfu_generate_shortcode(){var shortcode_tag=document.getElementById("wfu_shortcode_tag").value;var defaults=document.getElementById("wfu_attribute_defaults");var values=document.getElementById("wfu_attribute_values");var item;var attribute="";var value="";var shortcode_full="["+shortcode_tag;var shortcode="";for(var i=0;i<defaults.childNodes.length;i++){item=defaults.childNodes[i];if(item.nodeType===1){attribute=item.id.replace("wfu_attribute_default_","");value=document.getElementById("wfu_attribute_value_"+
attribute).value;if(item.value!=value)shortcode+=" "+attribute+'="'+value+'"'}}shortcode_full+=shortcode+"]";document.getElementById("wfu_shortcode").value=shortcode_full;ShortcodeString=shortcode.substr(1);if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode").disabled=wfu_plugin_encode_string(shortcode_full)==document.getElementById("wfu_shortcode_original_enc").value;if(Autosave)wfu_schedule_save_shortcode()}
function wfu_update_text_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;val=val.replace(/(\r\n|\n|\r)/gm,"%n%");val=val.replace(/"/gm,"%dq%");val=val.replace(/\[/gm,"%brl%");val=val.replace(/\]/gm,"%brr%");if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
function wfu_update_date_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
function wfu_update_stringmatch_textvalue(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.replace("_matchfield","").replace("_matchvalue","");wfu_update_stringmatch_value(attribute)}
function wfu_update_triplecolor_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.replace("_color","");attribute=attribute.replace("_bgcolor","");attribute=attribute.replace("_borcolor","");item=document.getElementById("wfu_attribute_"+attribute+"_color");var val=item.value+","+document.getElementById("wfu_attribute_"+attribute+"_bgcolor").value+","+document.getElementById("wfu_attribute_"+attribute+"_borcolor").value;if(val!==item.oldVal){item.oldVal=
val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
function wfu_update_dimension_value(e){e=e||window.event;var item=e.target;var attribute=item.name.replace("wfu_dimension_elements_","");var group=document.getElementsByName(item.name);item=group[0];var val="";var dimname="";for(var i=0;i<group.length;i++){dimname=group[i].id.replace("wfu_attribute_"+attribute+"_","");if(val!=""&&group[i].value!="")val+=", ";if(group[i].value!="")val+=dimname+":"+group[i].value}if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=
val;wfu_generate_shortcode()}}function wfu_update_ptext_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.substr(2);var singular=document.getElementById("wfu_attribute_s_"+attribute).value;var plural=document.getElementById("wfu_attribute_p_"+attribute).value;var val=singular+"/"+plural;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val}wfu_generate_shortcode()}
function wfu_update_mchecklist_value(attribute){var value="";var mchecklist=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(checkall.checked){jQuery("#wfu_attribute_"+attribute+" input").prop("disabled",true);jQuery("#wfu_attribute_"+attribute+" input").prop("checked",true);value="all"}else{jQuery("#wfu_attribute_"+attribute+" input").prop("disabled",false);jQuery("#wfu_attribute_"+attribute+" input").each(function(){if(jQuery(this).prop("checked"))value+=
","+jQuery(this).next().html()});value=value.substr(1)}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
function wfu_update_rolelist_value(attribute){var value="";var rolelist=document.getElementById("wfu_attribute_"+attribute);var guests=document.getElementById("wfu_attribute_"+attribute+"_guests");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(checkall.checked){rolelist.disabled=true;value="all"}else{rolelist.disabled=false;var options=rolelist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}if(guests.checked){if(value!=
"")value+=",";value+="guests"}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
function wfu_update_userlist_value(attribute){var value="";var userlist=document.getElementById("wfu_attribute_"+attribute);var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");var guests=document.getElementById("wfu_attribute_"+attribute+"_guests");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(only_current&&only_current.checked){userlist.disabled=true;checkall.disabled=true;guests.disabled=true;value="current"}else{checkall.disabled=false;guests.disabled=
false;if(checkall.checked){userlist.disabled=true;value="all"}else{userlist.disabled=false;var options=userlist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}if(guests.checked){if(value!="")value+=",";value+="guests"}}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
function wfu_update_postlist_value(attribute){var value="";var userlist=Array();var checkall=Array();var postlist=document.getElementById("wfu_attribute_"+attribute+"_postlist").value.split(",");for(var i=0;i<postlist.length;i++){userlist.push(document.getElementById("wfu_attribute_"+attribute+"_"+postlist[i]));checkall.push(document.getElementById("wfu_attribute_"+attribute+"_all_"+postlist[i]))}var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&only_current.checked){for(var i=
0;i<postlist.length;i++){userlist[i].disabled=true;checkall[i].disabled=true}value="current"}else{var allchecked=true;value="";for(var i=0;i<postlist.length;i++){checkall[i].disabled=false;if(checkall[i].checked){userlist[i].disabled=true;if(value!="")value+=",";value+="all"+postlist[i]}else{userlist[i].disabled=false;allchecked=false;var options=userlist[i].options;for(var j=0;j<options.length;j++)if(options[j].selected){if(value!="")value+=",";value+=options[j].value}}}if(allchecked)value="all"}document.getElementById("wfu_attribute_value_"+
attribute).value=value;wfu_generate_shortcode()}
function wfu_update_bloglist_value(attribute){var value="";var bloglist=document.getElementById("wfu_attribute_"+attribute);var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(only_current&&only_current.checked){bloglist.disabled=true;checkall.disabled=true;value="current"}else{checkall.disabled=false;if(checkall.checked){bloglist.disabled=true;value="all"}else{bloglist.disabled=false;var options=
bloglist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
function wfu_update_stringmatch_value(attribute){var matchfield=document.getElementById("wfu_attribute_"+attribute+"_matchfield").value;var matchcriterion=document.getElementById("wfu_attribute_"+attribute+"_matchcriterion").value;var matchvalue=document.getElementById("wfu_attribute_"+attribute+"_matchvalue").value;matchfield=matchfield.replace(";","");if(matchfield.trim()=="")document.getElementById("wfu_attribute_value_"+attribute).value="";else document.getElementById("wfu_attribute_value_"+attribute).value=
"field:"+matchfield+";criterion:"+matchcriterion+";value:"+matchvalue;wfu_generate_shortcode()}
function wfu_update_userfield_value(e){e=e||window.event;var item=e.target;var line=item.parentNode;var container=line.parentNode;var fieldval="";var fieldreq=false;var val="";for(var i=0;i<container.childNodes.length;i++){line=container.childNodes[i];if(line.tagName==="DIV"){for(var j=0;j<line.childNodes.length;j++)if(line.childNodes[j].tagName=="INPUT")if(line.childNodes[j].type=="text"){fieldval=line.childNodes[j].value;if(i==0)item=line.childNodes[j]}else if(line.childNodes[j].type=="checkbox")fieldreq=
line.childNodes[j].checked;if(val!=""&&fieldval!="")val+="/";if(fieldval!=""&&fieldreq)val+="*";if(fieldval!="")val+=fieldval}}if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_userdatalabel").value=val;wfu_generate_shortcode();wfu_update_formfield_variables()}}
function wfu_update_formfield_value(e){e=e||window.event;var item=e.target;var attribute=item.id.match(/^wfu_formfield_(.*?)_/)[1];var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var val="";for(var i=0;i<containers.length;i++){var part="";var ind=containers[i].id.match(/^wfu_formfield_.*?_(.*?)_/)[1];var key=attribute+"_"+ind;var label=document.getElementById("wfu_formfield_"+key+"_label").value;if(label.trim()!=""){part=label.trim();var type=
document.getElementById("wfu_formfield_"+key+"_type").value;var typeprops=window["wfu_attribute_"+attribute+"_typeprops"];part+="|t:"+type;part+="|s:"+document.getElementById("wfu_formfield_"+key+"_labelposition").value;if(typeprops[type].required.substr(0,4)=="show")part+="|r:"+(document.getElementById("wfu_formfield_"+key+"_required").checked?"1":"0");if(typeprops[type].donotautocomplete.substr(0,4)=="show")part+="|a:"+(document.getElementById("wfu_formfield_"+key+"_donotautocomplete").checked?
"1":"0");if(typeprops[type].validate.substr(0,4)=="show")part+="|v:"+(document.getElementById("wfu_formfield_"+key+"_validate").checked?"1":"0");if(typeprops[type].typehook.substr(0,4)=="show")part+="|h:"+(document.getElementById("wfu_formfield_"+key+"_typehook").checked?"1":"0");if(typeprops[type].hintposition.substr(0,4)=="show")part+="|p:"+document.getElementById("wfu_formfield_"+key+"_hintposition").value;if(typeprops[type]["default"].substr(0,4)=="show")part+="|d:"+document.getElementById("wfu_formfield_"+
key+"_default").value;if(typeprops[type].data.substr(0,4)=="show")part+="|l:"+document.getElementById("wfu_formfield_"+key+"_data").value;if(typeprops[type].group.substr(0,4)=="show")part+="|g:"+document.getElementById("wfu_formfield_"+key+"_group").value;if(typeprops[type].format.substr(0,4)=="show")part+="|f:"+document.getElementById("wfu_formfield_"+key+"_format").value}if(part!=""){if(val!="")val+="/";val+=part}}if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
attribute).value=val;wfu_generate_shortcode();wfu_update_formfield_variables()}}
function wfu_update_formfield_variables(){var userdata=document.getElementById("wfu_attribute_value_userdatalabel");if(!userdata)return;var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_userdata");var selects=document.getElementsByName("wfu_formfield_select");for(var i=0;i<selects.length;i++)selects[i].style.display="none";if(shadows.length==0)return;if(shadows[0].style.display=="block")return;var options_str='<option style="display:none;">%userdataXXX%</option>';var userfields=userdata.value.replace(/\//g,
"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");var ind=2;while(document.getElementById("wfu_attribute_userdatalabel"+ind)){var userfields2=document.getElementById("wfu_attribute_value_userdatalabel"+ind).value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");userfields=userfields.concat(userfields2);ind++}var field="";var pos=0;ind=1;for(var i=0;i<userfields.length;i++){field=userfields[i];if(field[0]=="*")field=field.substr(1);
pos=field.indexOf("|");if(pos>-1)field=field.substr(0,pos);if(field.trim()!=""){options_str+='<option value="%userdata'+ind+'%">'+ind+": "+field.trim()+"</option>";ind++}}for(var i=0;i<selects.length;i++){selects[i].innerHTML=options_str;selects[i].style.display="inline-block"}}
function wfu_attach_element_handlers(item,handler){var elem_events=["DOMAttrModified","textInput","input","change","keypress","paste","focus","propertychange"];for(var i=0;i<elem_events.length;i++)wfu_addEventHandler(item,elem_events[i],handler)}
function wfu_Attach_Admin_Events(autosave_shortcode){Autosave=autosave_shortcode;wfu_generate_shortcode();wfu_update_formfield_variables();wfu_Attach_Admin_DragDrop_Events();var text_elements=document.getElementsByName("wfu_text_elements");for(var i=0;i<text_elements.length;i++)wfu_attach_element_handlers(text_elements[i],wfu_update_text_value);var ptext_elements=document.getElementsByName("wfu_ptext_elements");for(var i=0;i<ptext_elements.length;i++)wfu_attach_element_handlers(ptext_elements[i],
wfu_update_ptext_value);var stringmatch_elements=document.getElementsByName("wfu_stringmatch_elements");for(var i=0;i<stringmatch_elements.length;i++)wfu_attach_element_handlers(stringmatch_elements[i],wfu_update_stringmatch_textvalue);var triplecolor_elements=document.getElementsByName("wfu_triplecolor_elements");for(var i=0;i<triplecolor_elements.length;i++)wfu_attach_element_handlers(triplecolor_elements[i],wfu_update_triplecolor_value);var dimension_elements=document.getElementsByName("wfu_dimension_elements_widths");
for(var i=0;i<dimension_elements.length;i++)wfu_attach_element_handlers(dimension_elements[i],wfu_update_dimension_value);dimension_elements=document.getElementsByName("wfu_dimension_elements_heights");for(var i=0;i<dimension_elements.length;i++)wfu_attach_element_handlers(dimension_elements[i],wfu_update_dimension_value);var userfield_elements=document.getElementsByName("wfu_userfield_elements");for(var i=0;i<userfield_elements.length;i++)wfu_attach_element_handlers(userfield_elements[i],wfu_update_userfield_value);
var formfield_elements=document.getElementsByName("wfu_formfield_elements");for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);var subfolder_input_elements=document.getElementsByName("wfu_subfolder_tools_input");for(var i=0;i<subfolder_input_elements.length;i++)wfu_attach_element_handlers(subfolder_input_elements[i],wfu_subfolders_input_changed);var wfu_columnprops_elements=document.getElementsByName("wfu_columnprops_elements");
for(var i=0;i<wfu_columnprops_elements.length;i++)wfu_attach_element_handlers(wfu_columnprops_elements[i],wfu_columnprops_element_changed);if(document.getElementById("wfu_shortcode_postid").value!="")setTimeout(function(){wfu_check_page_obsolescence()},CheckObsolescenceTimeOut)}
function wfu_insert_variable(obj){var attr=obj.className.replace("wfu_variable wfu_variable_","");var inp=document.getElementById("wfu_attribute_"+attr);var pos=inp.selectionStart;var prevval=inp.value;inp.value=prevval.substr(0,pos)+obj.innerHTML+prevval.substr(pos);wfu_update_text_value({target:inp})}
function wfu_insert_userfield_variable(obj){var attr=obj.className.replace("wfu_variable wfu_variable_","");var inp=document.getElementById("wfu_attribute_"+attr);var pos=inp.selectionStart;var prevval=inp.value;inp.value=prevval.substr(0,pos)+obj.value+prevval.substr(pos);obj.value="%userdataXXX%";wfu_update_text_value({target:inp})}
function wfu_columns_itemclicked(obj,attribute){var select=obj.parentNode;if(select.tagName!="SELECT")return;for(var i=0;i<select.options.length;i++)select.options[i].selected=select.options[i]==obj;wfu_update_column_props(attribute)}
function wfu_columns_buttonaction(attribute,action){var source=document.getElementById("wfu_attribute_"+attribute+"_sourcelist");var target=document.getElementById("wfu_attribute_"+attribute);if(action=="add")for(var i=0;i<source.options.length;i++){if(source.options[i].selected||source.options[i].className=="wfu_columns_item_required"){var found=false;var sou=source.options[i].value.replace(/:.*/,"");for(var j=0;j<target.options.length;j++){var tar=target.options[j].value.replace(/:.*/,"");if(tar==
sou){found=true;break}}if(!found){var parts=source.options[i].value.match(/(.*?):(.*?)\/(.*)/);var item_name=parts[1];var sorttype=item_name=="custom"?"+-"+(parts[2]==""?"s":parts[2]):parts[2]!=""?"-+"+parts[2]:"";var title=parts[3];if(item_name=="custom")item_name="custom1";var opt=document.createElement("OPTION");opt.value=item_name+":"+sorttype+"/"+source.options[i].innerHTML+"/"+title;opt.innerHTML=source.options[i].innerHTML+(title!=""&&title!=source.options[i].innerHTML?" ("+title+")":"");opt.className=
source.options[i].className;opt.onclick=source.options[i].onclick;target.appendChild(opt);target.selectedIndex=target.options.length-1}}}else if(action=="del"){var i=0;while(i<target.options.length)if(target.options[i].selected&&target.options[i].className!="wfu_columns_item_required")target.options.remove(i);else i++}else if(action=="up"||action=="down"){var ind=-1;for(var i=0;i<target.options.length;i++)if(target.options[i].selected&&ind==-1)ind=i;else if(target.options[i].selected&&ind>-1)target.options[i].selected=
false;if(action=="up"&&ind>0)target.insertBefore(target.options[ind],target.options[ind-1]);else if(action=="down"&&ind<target.options.length-1)target.insertBefore(target.options[ind+1],target.options[ind])}wfu_update_column_props(attribute);wfu_update_columns(attribute)}
function wfu_update_column_props(attribute){var target=document.getElementById("wfu_attribute_"+attribute);var props_table=document.getElementById("wfu_attribute_"+attribute+"_columnprops_container");var props_title=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title");var props_title_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title_label");var props_id=document.getElementById("wfu_attribute_"+attribute+"_columnprops_id");var props_id_label=document.getElementById("wfu_attribute_"+
attribute+"_columnprops_id_label");var props_sort=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort");var props_sort_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort_label");var props_sorttype=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sorttype");var props_sorttype_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sorttype_label");var index=target.selectedIndex;if(props_sorttype.options[0].value=="")props_sorttype.options.remove(0);
if(index==-1){props_table.className="wfu_columnprops_container wfu_columnprops_container_disabled";props_title.value="";props_title.disabled=true;props_id.value="";props_id.disabled=true;props_sort.checked=false;props_sort.disabled=true;props_sorttype.selectedIndex=-1;props_sorttype.disabled=true}else{var parts=target.options[index].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var item_name=parts[1];var fieldid_enabled=item_name.substr(0,6)=="custom";var fieldid_value=fieldid_enabled?item_name.substr(6):
"";var sortable_enabled=parts[2]!="";var sortable=sortable_enabled&&parts[2].substr(1,1)=="+";var sorttype_enabled=sortable&&parts[2].substr(0,1)=="+";var sorttype=sortable?parts[2].substr(2):"";var title=parts[4];props_table.className="wfu_columnprops_container";props_title.value=title;props_title.disabled=false;props_id_label.className=fieldid_enabled?"":"wfu_columnprops_label_disabled";props_id.value=fieldid_value;props_id.disabled=!fieldid_enabled;props_sort_label.className=sortable_enabled?"":
"wfu_columnprops_label_disabled";props_sort.checked=sortable;props_sort.disabled=!sortable_enabled;props_sorttype_label.className=sorttype_enabled?"":"wfu_columnprops_label_disabled";props_sorttype.value=sorttype;props_sorttype.disabled=!sorttype_enabled}}
function wfu_columnprops_element_changed(e){e=e||window.event;var item=e.target;var attribute=item.id.match(/^wfu_attribute_(.*?)_columnprops_/)[1];var target=document.getElementById("wfu_attribute_"+attribute);var props_title=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title");var props_id=document.getElementById("wfu_attribute_"+attribute+"_columnprops_id");var props_sort=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort");var props_sorttype=document.getElementById("wfu_attribute_"+
attribute+"_columnprops_sorttype");var index=target.selectedIndex;if(index==-1)return;var parts=target.options[index].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var item_name=parts[1];var flat_name=item_name.substr(0,6)=="custom"?"custom":item_name;var fieldid_enabled=flat_name=="custom";var fieldid_value=fieldid_enabled?parseInt(props_id.value)>=1?props_id.value:"1":"";var sort=parts[2]!=""?parts[2].substr(0,1)+(props_sort.checked?"+":"-")+(props_sorttype.value!=""?props_sorttype.value:parts[2].substr(2)!=
""?parts[2].substr(2):"s"):"";var label=parts[3];var title=props_title.value!=""?props_title.value:label;target.options[index].value=flat_name+fieldid_value+":"+sort+"/"+label+"/"+title;target.options[index].innerHTML=label+(title!=label?" ("+title+")":"");wfu_update_column_props(attribute);wfu_update_columns(attribute)}
function wfu_update_columns(attribute){var target=document.getElementById("wfu_attribute_"+attribute);var columns="";for(var i=0;i<target.options.length;i++){var parts=target.options[i].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var col=parts[1]+":"+(parts[2].substr(1,1)=="+"?parts[2].substr(2):"")+"/"+parts[4];if(columns!="")columns+=",";columns+=col}document.getElementById("wfu_attribute_value_"+attribute).value=columns;wfu_generate_shortcode()}
function wfu_GetHttpRequestObject(){var xhr=null;try{xhr=new XMLHttpRequest}catch(e$0){try{xhr=new ActiveXObject("Msxml2.XMLHTTP")}catch(e2){try{xhr=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}if(xhr==null&&window.createRequest)try{xmlhttp=window.createRequest()}catch(e$1){}return xhr}
function wfu_plugin_encode_string(str){var i=0;var newstr="";var num;var hex="";for(i=0;i<str.length;i++){num=str.charCodeAt(i);if(num>=2048)num=((num&16773120|917504)<<4)+((num&4032|8192)<<2)+(num&63|128);else if(num>=128)num=((num&65472|12288)<<2)+(num&63|128);hex=num.toString(16);if(hex.length==1||hex.length==3||hex.length==5)hex="0"+hex;newstr+=hex}return newstr}
function wfu_plugin_decode_string(str){var i=0;var newstr="";var num,val;while(i<str.length){num=parseInt(str.substr(i,2),16);if(num<128)val=num;else if(num<224)val=((num&31)<<6)+(parseInt(str.substr(i+=2,2),16)&63);else val=((num&15)<<12)+((parseInt(str.substr(i+=2,2),16)&63)<<6)+(parseInt(str.substr(i+=2,2),16)&63);newstr+=String.fromCharCode(val);i+=2}return newstr}
function wfu_randomString(len){var chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";var string_length=len;var randomstring="";for(var i=0;i<string_length;i++){var rnum=Math.floor(Math.random()*chars.length);randomstring+=chars.substring(rnum,rnum+1)}return randomstring}
function wfu_schedule_save_shortcode(){var d=new Date;var dt=ShortcodeNextSave-d.getTime();if(ShortcodeTimeOut!=null){clearTimeout(ShortcodeTimeOut);ShortcodeTimeOut=null}if(dt<=0)wfu_save_shortcode();else ShortcodeTimeOut=setTimeout(function(){wfu_save_shortcode()},dt)}function wfu_check_page_obsolescence(){if(PageObsolete||PageUpdating||document.getElementById("wfu_shortcode_postid").value=="")return}
function wfu_save_shortcode(){if(PageObsolete)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;PageUpdating=true;document.getElementById("wfu_update_failed_message").style.display="none";var url=AdminParams.wfu_ajax_url;params=new Array(8);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_save_shortcode";params[1]=new Array(2);params[1][0]="shortcode";params[1][1]=wfu_plugin_encode_string(ShortcodeString);params[2]=new Array(2);params[2][0]="shortcode_original";
params[2][1]=document.getElementById("wfu_shortcode_original_enc").value;params[3]=new Array(2);params[3][0]="post_id";params[3][1]=document.getElementById("wfu_shortcode_postid").value;params[4]=new Array(2);params[4][0]="post_hash";params[4][1]=document.getElementById("wfu_shortcode_posthash").value;params[5]=new Array(2);params[5][0]="shortcode_position";params[5][1]=document.getElementById("wfu_shortcode_position").value;params[6]=new Array(2);params[6][0]="shortcode_tag";params[6][1]=document.getElementById("wfu_shortcode_tag").value;
params[7]=new Array(2);params[7][0]="widget_id";params[7][1]=document.getElementById("wfu_shortcode_widgetid").value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);var d=new Date;if(Autosave)ShortcodeNextSave=d.getTime()+5E3;else if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode_wait").style.display="inline";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){PageUpdating=false;var start_text="wfu_save_shortcode:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){if(Autosave){document.getElementById("wfu_save_label").innerHTML=
"saved";document.getElementById("wfu_save_label").className="wfu_save_label";document.getElementById("wfu_save_label").style.opacity=1;wfu_fadeout_element(300);ShortcodeNextSave=d.getTime()+1E3;if(ShortcodeTimeOut!=null)wfu_schedule_save_shortcode()}else if(document.getElementById("wfu_update_shortcode")){document.getElementById("wfu_update_shortcode_wait").style.display="none";document.getElementById("wfu_update_shortcode").disabled=true;if(window.plugin_window)window.plugin_window.location.reload(true)}if(document.getElementById("wfu_shortcode_postid").value!=
""){var shortcode_tag=document.getElementById("wfu_shortcode_tag").value;document.getElementById("wfu_shortcode_original_enc").value=wfu_plugin_encode_string("["+shortcode_tag+" "+ShortcodeString+"]");document.getElementById("wfu_shortcode_posthash").value=txt_value;setTimeout(function(){wfu_check_page_obsolescence()},CheckObsolescenceTimeOut)}}else{if(Autosave){document.getElementById("wfu_save_label").innerHTML="not saved";document.getElementById("wfu_save_label").className="wfu_save_label_fail";
document.getElementById("wfu_save_label").style.opacity=1;wfu_fadeout_element(300)}if(txt_header=="fail")if(txt_value=="post_modified"){PageObsolete=true;if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode").disabled=true;document.getElementById("wfu_update_rejected_message").style.display="block"}else document.getElementById("wfu_update_failed_message").style.display="block"}}};xhr.send(parameters)}
function wfu_adjust_opacity(opacity){document.getElementById("wfu_save_label").style.opacity=opacity}function wfu_fadeout_element(interval){var reps=20;var op=0;for(var i=0;i<reps;i++){op=1-i/reps;setTimeout('wfu_adjust_opacity("'+op.toString()+'")',i*interval/reps)}setTimeout('wfu_adjust_opacity("0.0")',i*interval/reps)}
function wfu_apply_value(attribute,type,value){if(type=="onoff"){document.getElementById("wfu_attribute_"+attribute).className="wfu_onoff_container_"+(value!="true"?"on":"off");wfu_admin_onoff_clicked(attribute)}else if(type=="text"||type=="ltext"||type=="integer"||type=="float"||type=="mtext"||type=="color"){var item=document.getElementById("wfu_attribute_"+attribute);value=value.replace(/%n%/gm,"\n");value=value.replace(/%dq%/gm,'"');value=value.replace(/%brl%/gm,"[");value=value.replace(/%brr%/gm,
"]");if(type=="color"){var rgb=colourNameToHex(value);if(!rgb)rgb=value;jQuery("#wfu_attribute_"+attribute).wpColorPicker("color",rgb)}item.value=value;wfu_update_text_value({target:item})}else if(type=="date"){var item=document.getElementById("wfu_attribute_"+attribute);item.value=value;wfu_update_date_value({target:item})}else if(type=="placements"){wfu_admin_recreate_placements_panel(value);document.getElementById("wfu_attribute_value_placements").value=value;wfu_generate_shortcode()}else if(type==
"radio"){var radios=document.getElementsByName("wfu_radioattribute_"+attribute);for(var i=0;i<radios.length;i++)radios[i].checked=radios[i].value==value||"*"+radios[i].value==value;wfu_admin_radio_clicked(attribute)}else if(type=="ptext"){value=value.replace(/%n%/gm,"\n");value=value.replace(/%dq%/gm,'"');value=value.replace(/%brl%/gm,"[");value=value.replace(/%brr%/gm,"]");var parts=value.split("/");var singular=parts.length<1?"":parts[0];var plural=parts.length<2?singular:parts[1];var item1=document.getElementById("wfu_attribute_s_"+
attribute);item1.value=singular;var item2=document.getElementById("wfu_attribute_p_"+attribute);item2.value=plural;wfu_update_ptext_value({target:item1});wfu_update_ptext_value({target:item2})}else if(type=="mchecklist"){value=value.toLowerCase();if(value=="all")document.getElementById("wfu_attribute_"+attribute+"_all").checked=true;else{document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;var items=value.split(",");for(var i=0;i<items.length;i++)items[i]=items[i].trim();jQuery("#wfu_attribute_"+
attribute+" input").each(function(){jQuery(this).prop("checked",items.indexOf(jQuery(this).next().html())>-1)})}wfu_update_mchecklist_value(attribute)}else if(type=="rolelist"){var item=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");var default_administrator=checkall.className.indexOf("wfu_default_administrator")>-1;var roles=value.split(",");if(roles.indexOf("all")>-1){checkall.checked=true;for(var i=0;i<item.options.length;i++)item.options[i].selected=
default_administrator&&item.options[i].value=="administrator"}else{checkall.checked=false;for(var i=0;i<roles.length;i++)roles[i]=roles[i].trim();for(var i=0;i<item.options.length;i++)item.options[i].selected=roles.indexOf(item.options[i].value)>-1}document.getElementById("wfu_attribute_"+attribute+"_guests").checked=roles.indexOf("guests")>-1;wfu_update_rolelist_value(attribute)}else if(type=="userlist"){var item=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+
attribute+"_all");var default_0=checkall.className.indexOf("wfu_default_0")>-1;var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=true;checkall.checked=false;document.getElementById("wfu_attribute_"+attribute+"_guests").checked=false;for(var i=0;i<item.options.length;i++)item.options[i].selected=default_0&&i<1}else{if(only_current)only_current.checked=false;var users=value.split(",");if(users.indexOf("all")>-1){checkall.checked=
true;for(var i=0;i<item.options.length;i++)item.options[i].selected=default_0&&i<1}else{checkall.checked=false;for(var i=0;i<users.length;i++)users[i]=users[i].trim();for(var i=0;i<item.options.length;i++)item.options[i].selected=users.indexOf(item.options[i].value)>-1}document.getElementById("wfu_attribute_"+attribute+"_guests").checked=users.indexOf("guests")>-1}wfu_update_userlist_value(attribute)}else if(type=="postlist"){var userlist=Array();var checkall=Array();var postlist=document.getElementById("wfu_attribute_"+
attribute+"_postlist").value.split(",");for(var i=0;i<postlist.length;i++){userlist.push(document.getElementById("wfu_attribute_"+attribute+"_"+postlist[i]));checkall.push(document.getElementById("wfu_attribute_"+attribute+"_all_"+postlist[i]))}var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=true;for(var i=0;i<postlist.length;i++){checkall[i].checked=false;for(var j=0;j<userlist[i].options.length;j++)userlist[i].options[j].selected=
false}}else{if(only_current)only_current.checked=false;var ids=value.split(",");for(var i=0;i<postlist.length;i++){if(value=="all"||ids.indexOf("all"+postlist[i])>-1)checkall[i].checked=true;for(var j=0;j<userlist[i].options.length;j++)userlist[i].options[j].selected=ids.indexOf(userlist[i].options[j].value)>-1}}wfu_update_postlist_value(attribute)}else if(type=="bloglist"){var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=
true;document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;var item=document.getElementById("wfu_attribute_"+attribute);for(var i=0;i<item.options.length;i++)item.options[i].selected=false}else{if(only_current)only_current.checked=false;var blogs=value.split(",");if(value=="all")document.getElementById("wfu_attribute_"+attribute+"_all").checked=true;else{document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;for(var i=0;i<blogs.length;i++)blogs[i]=blogs[i].trim();
var item=document.getElementById("wfu_attribute_"+attribute);for(var i=0;i<item.options.length;i++)item.options[i].selected=blogs.indexOf(item.options[i].value)>-1}}wfu_update_bloglist_value(attribute)}else if(type=="stringmatch"){var matchfield="";var matchcriterion="equal to";var matchvalue="";var matches=value.match(/^field:(.*?);\s*criterion:(.*?)\s*;\s*value:(.*)$/);if(matches&&matches.length==4){matchfield=matches[1];matchcriterion=matches[2];matchvalue=matches[3]}document.getElementById("wfu_attribute_"+
attribute+"_matchfield").value=matchfield;document.getElementById("wfu_attribute_"+attribute+"_matchcriterion").value=matchcriterion;document.getElementById("wfu_attribute_"+attribute+"_matchvalue").value=matchvalue;wfu_update_stringmatch_value(attribute)}else if(type=="columns"){var source=document.getElementById("wfu_attribute_"+attribute+"_sourcelist");var target=document.getElementById("wfu_attribute_"+attribute);target.innerHTML="";var columns_flat=value.replace(/(:|\/).*?(,|$)/g,"$2").split(",");
for(var i=0;i<source.options.length;i++){var parts=source.options[i].value.match(/(.*?):(.*?)\/(.*)/);var item_name=parts[1];if(source.options[i].className=="wfu_columns_item_required"&&columns_flat.indexOf(item_name)==-1){var sorttype=item_name=="custom"?"+-"+(parts[2]==""?"s":parts[2]):parts[2]!=""?"-+"+parts[2]:"";var title=parts[3];if(item_name=="custom")item_name="custom1";var opt=document.createElement("OPTION");opt.value=item_name+":"+sorttype+"/"+source.options[i].innerHTML+"/"+title;opt.innerHTML=
source.options[i].innerHTML+(title!=""&&title!=source.options[i].innerHTML?" ("+title+")":"");opt.className=source.options[i].className;opt.onclick=source.options[i].onclick;target.appendChild(opt)}}var columns=value.split(",");for(var i=0;i<columns.length;i++){var item_parts=columns[i].split("/",2);var item_name=item_parts[0];var item_title="";if(item_parts.length>1)item_title=item_parts[1];item_parts=item_name.split(":",2);item_name=item_parts[0];var flat_name=item_name.replace(/custom[0-9]+$/,
"custom");var ind=-1;for(var j=0;j<source.options.length;j++){var sou=source.options[j].value.replace(/:.*/,"");if(sou==flat_name){ind=j;break}}var already_exists=false;for(var j=0;j<target.options.length;j++){var tar=target.options[j].value.replace(/:.*/,"");if(tar==item_name){already_exists=true;break}}if(item_name!="custom"&&ind>-1&&!already_exists){var parts=source.options[ind].value.match(/(.*?):(.*?)\/(.*)/);var sortable=flat_name=="custom"||parts[2]!="";var sorttype=parts[2];var label=source.options[ind].innerHTML;
var title=parts[3];var item_sort="";if(item_parts.length==1)item_sort=flat_name=="custom"?"+-s":sortable?"-+"+sorttype:"";else if(flat_name=="custom")item_sort="+"+(item_parts[1]==""?"-s":"+"+item_parts[1]);else item_sort=sortable?"-"+(item_parts[1]==""?"-":"+")+sorttype:"";if(item_title=="")item_title=title;var opt=document.createElement("OPTION");opt.value=item_name+":"+item_sort+"/"+label+"/"+item_title;opt.innerHTML=label+(title!=label?" ("+title+")":"");opt.className=source.options[ind].className;
opt.onclick=source.options[i].onclick;target.appendChild(opt)}}wfu_update_column_props(attribute);wfu_update_columns(attribute)}else if(type=="dimensions"){var dims=value.split(",");var details,nam,val,item;var group=document.getElementsByName("wfu_dimension_elements_"+attribute);for(var i=0;i<group.length;i++)group[i].value="";for(var i=0;i<dims.length;i++){details=dims[i].split(":",2);nam=details.length<1?"":details[0];val=details.length<2?nam:details[1];item=document.getElementById("wfu_attribute_"+
attribute+"_"+nam.trim());if(item)item.value=val.trim()}item=group[0];wfu_update_dimension_value({target:item})}else if(type=="userfields"){var fields_arr=value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");var is_req;var fields=Array();for(var i=0;i<fields_arr.length;i++){is_req=fields_arr[i].substr(0,1)=="*";if(is_req)fields_arr[i]=fields_arr[i].substr(1);if(fields_arr[i]!="")fields.push({name:fields_arr[i],required:is_req})}var container=document.getElementById("wfu_attribute_"+
attribute);var first=null;var remove_array=Array();for(var i=0;i<container.childNodes.length;i++)if(container.childNodes[i].nodeType===1)if(first==null)first=container.childNodes[i];else remove_array.push(container.childNodes[i]);for(var i=0;i<remove_array.length;i++)container.removeChild(remove_array[i]);wfu_userdata_edit_field(first,"",false);var newline;var prevline=first;for(var i=0;i<fields.length;i++)if(i==0)wfu_userdata_edit_field(first,fields[i].name,fields[i].required);else{newline=prevline.cloneNode(true);
wfu_userdata_edit_field(newline,fields[i].name,fields[i].required);container.insertBefore(newline,prevline.nextSibling);prevline=newline}var item;for(var i=0;i<first.childNodes.length;i++){item=first.childNodes[i];if(item.tagName=="INPUT")break}wfu_update_userfield_value({target:item})}else if(type=="formfields"){var fields=Array();var fielddefs=window["wfu_attribute_"+attribute+"_typeprops"];var fielddef_array=fielddefs[0].split(",");var defaults={};for(var i=0;i<fielddef_array.length;i++){var fielddef=
fielddefs[fielddef_array[i]];var def={};def.type=fielddef_array[i];def.label="";def.labelposition=fielddef.labelposition.substr(5);def.required=fielddef.required.substr(5)=="true";def.donotautocomplete=fielddef.donotautocomplete.substr(5)=="true";def.validate=fielddef.validate.substr(5)=="true";def.typehook=fielddef.typehook.substr(5)=="true";def.hintposition=fielddef.hintposition.substr(5);def["default"]=fielddef["default"].substr(5);def.data=fielddef.data.substr(5);def.group=fielddef.group.substr(5);
def.format=fielddef.format.substr(5);defaults[fielddef_array[i]]=def}var fields_arr=value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");for(var i=0;i<fields_arr.length;i++){var field_raw=fields_arr[i].trim();var fieldprops={};for(prop in defaults["text"])fieldprops[prop]=defaults["text"][prop];if(field_raw.substr(0,1)=="*"){fieldprops.required=true;field_raw=field_raw.substr(1)}var field_parts=field_raw.split("|");if(field_parts[0].trim()!=""){var type_key=
-1;var new_type="";for(var j=0;j<field_parts.length;j++){var part=field_parts[j].replace(/^\s+/gm,"");var flag=part.substr(0,2);var val=part.substr(2);if(flag=="t:"&&j>0&&fielddef_array.indexOf(val)>-1){new_type=val;type_key=j;break}}if(new_type!=""){for(prop in defaults[new_type])fieldprops[prop]=defaults[new_type][prop];field_parts.splice(type_key,1)}fieldprops.label=field_parts[0].trim();field_parts.splice(0,1);for(var j=0;j<field_parts.length;j++){var part=field_parts[j].replace(/^\s+/gm,"");
var flag=part.substr(0,2);var val=part.substr(2);if(flag=="s:")fieldprops.labelposition=val;else if(flag=="r:")fieldprops.required=val=="1";else if(flag=="a:")fieldprops.donotautocomplete=val=="1";else if(flag=="v:")fieldprops.validate=val=="1";else if(flag=="d:")fieldprops["default"]=val;else if(flag=="l:")fieldprops.data=val;else if(flag=="g:")fieldprops.group=val;else if(flag=="f:")fieldprops.format=val;else if(flag=="p:")fieldprops.hintposition=val;else if(flag=="h:")fieldprops.typehook=val==
"1"}fields.push(fieldprops)}}if(fields.length==0)fields.push(fieldprops_default);var container=document.getElementById("wfu_attribute_"+attribute);var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");for(var i=1;i<containers.length;i++)container.removeChild(containers[i]);var new_line_container=containers[0];for(var i=0;i<fields.length;i++){var new_key=attribute+"_"+wfu_randomString(4);var template=wfu_formdata_prepare_template(attribute,fields[i],
new_key);if(i>0)new_line_container=document.createElement("DIV");new_line_container.id="wfu_formfield_"+new_key+"_container";new_line_container.className="wfu_formdata_line_container";if(i>0)container.insertBefore(new_line_container,null);new_line_container.innerHTML=template;wfu_formdata_update_buttons(new_key)}var formfield_elements=document.querySelectorAll("div#wfu_attribute_"+attribute+' input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
wfu_update_formfield_value);wfu_update_formfield_value({target:containers[0]})}else if(type=="color-triplet"){var colors=value.split(",");for(var i=0;i<colors.length;i++)colors[i]=colors[i].trim();if(colors.length==2)colors=[colors[0],colors[1],"#000000"];else if(colors.length==1)colors=[colors[0],"#FFFFFF","#000000"];else if(colors.length<3)colors=["#000000","#FFFFFF","#000000"];var rgb=colourNameToHex(colors[0]);if(!rgb)rgb=colors[0];jQuery("#wfu_attribute_"+attribute+"_color").wpColorPicker("color",
rgb);var item=document.getElementById("wfu_attribute_"+attribute+"_color");item.value=colors[0];rgb=colourNameToHex(colors[1]);if(!rgb)rgb=colors[1];jQuery("#wfu_attribute_"+attribute+"_bgcolor").wpColorPicker("color",rgb);document.getElementById("wfu_attribute_"+attribute+"_bgcolor").value=colors[1];rgb=colourNameToHex(colors[2]);if(!rgb)rgb=colors[2];jQuery("#wfu_attribute_"+attribute+"_borcolor").wpColorPicker("color",rgb);document.getElementById("wfu_attribute_"+attribute+"_borcolor").value=colors[2];
wfu_update_triplecolor_value({target:item})}else if(type=="folderlist"){var items=wfu_parse_folderlist_js(value);var opts=document.getElementById("wfu_attribute_"+attribute).options;while(opts.length>0)opts.remove(0);var opt,subfolder,subfolder_raw,text,stars,subvalue;for(var i=0;i<items.path.length;i++){subfolder=items.path[i];if(subfolder.substr(subfolder.length,1)=="/")subfolder=subfolder.substr(0,subfolder.length-1);subfolder_raw=subfolder.split("/");subfolder=subfolder_raw[subfolder_raw.length-
1];stars=parseInt(items.level[i]);text="";subvalue="";for(var j=0;j<stars;j++){text+="&nbsp;&nbsp;&nbsp;";subvalue+="*"}text+=items.label[i];if(items["default"][i])subvalue+="&";if(subfolder=="")subvalue+="{root}/"+items.label[i];else subvalue+=subfolder+items.label[i];opt=document.createElement("option");if(items["default"][i])opt.className="wfu_select_folders_option_default";else opt.className="";opt.value=wfu_plugin_encode_string(subvalue);opt.innerHTML=text;opts.add(opt)}opt=document.createElement("option");
opt.value="";opt.innerHTML="";opts.add(opt);var list=document.getElementById("wfu_attribute_"+attribute);list.data=wfu_decode_subfolder_list(attribute);wfu_subfolders_update_toolnav(attribute);item=list;if(value!==item.oldVal){item.oldVal=value;document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}}}
function wfu_parse_folderlist_js(list){var ret=Object();ret.path=Array();ret.label=Array();ret.level=Array();ret["default"]=Array();if(list.substr(0,4)=="auto")return ret;var subfolders=list.split(",");if(subfolders.length==0)return ret;if(subfolders.length==1&&subfolders[0].trim()=="")return ret;var dir_levels=["root"];var prev_level=0;var level0_count=0;var _default=-1;var subfolder,star_count,start_spaces,is_default,subfolder_dir,subfolder_label,subfolder_path;for(var i=0;i<subfolders.length;i++){subfolder=
subfolders[i].trim();star_count=0;start_spaces="";is_default=false;while(star_count<subfolder.length)if(subfolder.substr(star_count,1)=="*"){star_count++;start_spaces+="&nbsp;&nbsp;&nbsp;"}else break;if(star_count-prev_level<=1&&(star_count>0||level0_count==0)){subfolder=subfolder.substr(star_count,subfolder.length-star_count);if(subfolder.substr(0,1)=="&"){subfolder=subfolder.substr(1);is_default=true}subfolder_items=subfolder.split("/");if(subfolder_items.length<2)subfolder_items.push("");if(subfolder_items[1]!=
""){subfolder_dir=subfolder_items[0];subfolder_label=subfolder_items[1]}else{subfolder_dir=subfolder;subfolder_label=subfolder}if(subfolder_dir!=""){if(is_default&&_default==-1)_default=ret.path.length;else is_default=false;if(star_count==0)level0_count=1;if(dir_levels.length>star_count)dir_levels[star_count]=subfolder_dir;else dir_levels.push(subfolder_dir);subfolder_path="";for(var i_count=1;i_count<=star_count;i_count++)subfolder_path+=dir_levels[i_count]+"/";ret.path.push(subfolder_path);ret.label.push(subfolder_label);
ret.level.push(star_count);ret["default"].push(is_default);prev_level=star_count}}}return ret}
function colourNameToHex(colour){var colours={"aliceblue":"#f0f8ff","antiquewhite":"#faebd7","aqua":"#00ffff","aquamarine":"#7fffd4","azure":"#f0ffff","beige":"#f5f5dc","bisque":"#ffe4c4","black":"#000000","blanchedalmond":"#ffebcd","blue":"#0000ff","blueviolet":"#8a2be2","brown":"#a52a2a","burlywood":"#deb887","cadetblue":"#5f9ea0","chartreuse":"#7fff00","chocolate":"#d2691e","coral":"#ff7f50","cornflowerblue":"#6495ed","cornsilk":"#fff8dc","crimson":"#dc143c","cyan":"#00ffff","darkblue":"#00008b",
"darkcyan":"#008b8b","darkgoldenrod":"#b8860b","darkgray":"#a9a9a9","darkgreen":"#006400","darkkhaki":"#bdb76b","darkmagenta":"#8b008b","darkolivegreen":"#556b2f","darkorange":"#ff8c00","darkorchid":"#9932cc","darkred":"#8b0000","darksalmon":"#e9967a","darkseagreen":"#8fbc8f","darkslateblue":"#483d8b","darkslategray":"#2f4f4f","darkturquoise":"#00ced1","darkviolet":"#9400d3","deeppink":"#ff1493","deepskyblue":"#00bfff","dimgray":"#696969","dodgerblue":"#1e90ff","firebrick":"#b22222","floralwhite":"#fffaf0",
"forestgreen":"#228b22","fuchsia":"#ff00ff","gainsboro":"#dcdcdc","ghostwhite":"#f8f8ff","gold":"#ffd700","goldenrod":"#daa520","gray":"#808080","green":"#008000","greenyellow":"#adff2f","honeydew":"#f0fff0","hotpink":"#ff69b4","indianred ":"#cd5c5c","indigo ":"#4b0082","ivory":"#fffff0","khaki":"#f0e68c","lavender":"#e6e6fa","lavenderblush":"#fff0f5","lawngreen":"#7cfc00","lemonchiffon":"#fffacd","lightblue":"#add8e6","lightcoral":"#f08080","lightcyan":"#e0ffff","lightgoldenrodyellow":"#fafad2",
"lightgrey":"#d3d3d3","lightgreen":"#90ee90","lightpink":"#ffb6c1","lightsalmon":"#ffa07a","lightseagreen":"#20b2aa","lightskyblue":"#87cefa","lightslategray":"#778899","lightsteelblue":"#b0c4de","lightyellow":"#ffffe0","lime":"#00ff00","limegreen":"#32cd32","linen":"#faf0e6","magenta":"#ff00ff","maroon":"#800000","mediumaquamarine":"#66cdaa","mediumblue":"#0000cd","mediumorchid":"#ba55d3","mediumpurple":"#9370d8","mediumseagreen":"#3cb371","mediumslateblue":"#7b68ee","mediumspringgreen":"#00fa9a",
"mediumturquoise":"#48d1cc","mediumvioletred":"#c71585","midnightblue":"#191970","mintcream":"#f5fffa","mistyrose":"#ffe4e1","moccasin":"#ffe4b5","navajowhite":"#ffdead","navy":"#000080","oldlace":"#fdf5e6","olive":"#808000","olivedrab":"#6b8e23","orange":"#ffa500","orangered":"#ff4500","orchid":"#da70d6","palegoldenrod":"#eee8aa","palegreen":"#98fb98","paleturquoise":"#afeeee","palevioletred":"#d87093","papayawhip":"#ffefd5","peachpuff":"#ffdab9","peru":"#cd853f","pink":"#ffc0cb","plum":"#dda0dd",
"powderblue":"#b0e0e6","purple":"#800080","red":"#ff0000","rosybrown":"#bc8f8f","royalblue":"#4169e1","saddlebrown":"#8b4513","salmon":"#fa8072","sandybrown":"#f4a460","seagreen":"#2e8b57","seashell":"#fff5ee","sienna":"#a0522d","silver":"#c0c0c0","skyblue":"#87ceeb","slateblue":"#6a5acd","slategray":"#708090","snow":"#fffafa","springgreen":"#00ff7f","steelblue":"#4682b4","tan":"#d2b48c","teal":"#008080","thistle":"#d8bfd8","tomato":"#ff6347","turquoise":"#40e0d0","violet":"#ee82ee","wheat":"#f5deb3",
"white":"#ffffff","whitesmoke":"#f5f5f5","yellow":"#ffff00","yellowgreen":"#9acd32"};if(typeof colours[colour.toLowerCase()]!="undefined")return colours[colour.toLowerCase()];return false}
function wfu_download_file(filepath_enc,ii){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var nonce="";var nonce_elem=document.getElementById("wfu_download_file_nonce");if(nonce_elem)nonce=nonce_elem.value;if(nonce=="")return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_download_file_invoker";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="nonce";params[2][1]=
nonce;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="wfu_ajax_action_download_file_invoker:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+
start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header.substr(0,16)=="wfu_download_id;"){var download_id=txt_header.substr(16);var container=document.getElementById("wfu_file_download_container_"+ii);container.innerHTML=txt_value;setTimeout("wfu_download_file_monitor('"+filepath_enc+"', "+ii+", '"+download_id+"')",100)}}};xhr.send(parameters)}
function wfu_download_file_monitor(filepath_enc,ii,id){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_download_file_monitor";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="id";params[2][1]=id;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);
xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="wfu_ajax_action_download_file_monitor:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=
response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header!="repeat"){var container=document.getElementById("wfu_file_download_container_"+ii);container.innerHTML=""}else if(txt_header=="repeat")setTimeout("wfu_download_file_monitor('"+filepath_enc+"', "+ii+", '"+txt_value+"')",100)}};xhr.send(parameters)}
function wfu_filedetails_changed(e){var userdata_elements=document.getElementsByName("wfu_filedetails_userdata");var def,subm;var changed=false,changed2=false;for(var i=0;i<userdata_elements.length;i++){def=document.getElementById(userdata_elements[i].id.replace("wfu_filedetails_userdata_value_","wfu_filedetails_userdata_default_"));subm=document.getElementById(userdata_elements[i].id.replace("wfu_filedetails_userdata_value_","wfu_filedetails_userdata_"));subm.value=userdata_elements[i].value;if(userdata_elements[i].value!=
def.value){changed=true;break}}if(document.getElementById("wfu_filedetails_userid"))changed2=document.getElementById("wfu_filedetails_userid").value!=document.getElementById("wfu_filedetails_userid_default").value;document.getElementById("dp_filedetails_submit_fields").disabled=!changed&&!changed2}
function wfu_Attach_FileDetails_Admin_Events(){var userdata_elements=document.getElementsByName("wfu_filedetails_userdata");for(var i=0;i<userdata_elements.length;i++)wfu_attach_element_handlers(userdata_elements[i],wfu_filedetails_changed)}
function wfu_update_browserpermission_option(type,id,immediate){var users=document.getElementById("wfu_fbperm_users");var roles=document.getElementById("wfu_fbperm_roles");var view=document.getElementById("wfu_fbperm_"+type+"_"+id+"_view");var dl=document.getElementById("wfu_fbperm_"+type+"_"+id+"_dl");var edit=document.getElementById("wfu_fbperm_"+type+"_"+id+"_edit");var del=document.getElementById("wfu_fbperm_"+type+"_"+id+"_del");if(type=="role"){if(id=="0"){dl.checked=view.checked&&dl.checked;
edit.checked=view.checked&&edit.checked;del.checked=view.checked&&del.checked;dl.disabled=!view.checked;edit.disabled=!view.checked;del.disabled=!view.checked;var roles_tr=document.querySelectorAll("tr.wfu_fbperm_role_tr");for(var i=0;i<roles_tr.length;i++){var rolename=roles_tr[i].id.substr(16,roles_tr[i].id.length-20);wfu_update_browserpermission_option("role",rolename,false)}if(immediate){var props=(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":"");roles.value=
roles.value.replace(/^0\[\w*\]/,"0["+props+"]")}}else if(id!="administrator"){var row=document.getElementById("wfu_fbperm_role_"+id+"_row");var def=document.getElementById("wfu_fbperm_role_"+id+"_def");var view_def=document.getElementById("wfu_fbperm_role_0_view");var dl_def=document.getElementById("wfu_fbperm_role_0_dl");var edit_def=document.getElementById("wfu_fbperm_role_0_edit");var del_def=document.getElementById("wfu_fbperm_role_0_del");view.checked=def.checked?view_def.checked:view.checked;
row.style.fontWeight=def.checked?"":"bold";dl.checked=def.checked?dl_def.checked:view.checked&&dl.checked;edit.checked=def.checked?edit_def.checked:view.checked&&edit.checked;del.checked=def.checked?del_def.checked:view.checked&&del.checked;view.disabled=def.checked;dl.disabled=def.checked||!view.checked;edit.disabled=def.checked||!view.checked;del.disabled=def.checked||!view.checked;if(immediate){var props=def.checked?"":"D"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?
"l":"");roles.value=roles.value.replace(new RegExp(","+id+"\\[\\w*\\]"),","+id+"["+props+"]")}}var users_tr=document.querySelectorAll("tr.wfu_fbperm_user_tr");for(var i=0;i<users_tr.length;i++){var username=users_tr[i].id.substr(16,users_tr[i].id.length-20);wfu_update_browserpermission_option("user",username,false)}}else if(type=="user"){var role=document.getElementById("wfu_fbperm_user_"+id+"_role");if(id=="0"){view.checked=role.checked?false:view.checked;dl.checked=role.checked?false:view.checked&&
dl.checked;edit.checked=role.checked?false:view.checked&&edit.checked;del.checked=role.checked?false:view.checked&&del.checked;view.disabled=role.checked;dl.disabled=role.checked||!view.checked;edit.disabled=role.checked||!view.checked;del.disabled=role.checked||!view.checked;view.indeterminate=role.checked;dl.indeterminate=role.checked;edit.indeterminate=role.checked;del.indeterminate=role.checked;var users_tr=document.querySelectorAll("tr.wfu_fbperm_user_tr");for(var i=0;i<users_tr.length;i++){var username=
users_tr[i].id.substr(16,users_tr[i].id.length-20);wfu_update_browserpermission_option("user",username,false)}if(immediate){var props=role.checked?"":"R"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":"");users.value=users.value.replace(/^0\[\w*\],?/,"");users.value="0["+props+"]"+(users.value==""?"":","+users.value)}}else{var user_roles=document.getElementById("wfu_fbperm_user_"+id+"_roles").value.split(",");if(user_roles.length==1&&user_roles[0]=="")user_roles=
Array();if(user_roles.indexOf("administrator")<0){var row=document.getElementById("wfu_fbperm_user_"+id+"_row");var def=document.getElementById("wfu_fbperm_user_"+id+"_def");var role_def=document.getElementById("wfu_fbperm_user_0_role");var view_def=document.getElementById("wfu_fbperm_user_0_view");var dl_def=document.getElementById("wfu_fbperm_user_0_dl");var edit_def=document.getElementById("wfu_fbperm_user_0_edit");var del_def=document.getElementById("wfu_fbperm_user_0_del");if(user_roles.length>
0){var $view_from_roles=false;var $dl_from_roles=false;var $edit_from_roles=false;var $del_from_roles=false;for(var i=0;i<user_roles.length;i++){$view_from_roles=$view_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_view").checked;$dl_from_roles=$view_from_roles&&($dl_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_dl").checked);$edit_from_roles=$view_from_roles&&($edit_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_edit").checked);
$del_from_roles=$view_from_roles&&($del_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_del").checked)}}else{var $view_from_roles=document.getElementById("wfu_fbperm_role_0_view");var $dl_from_roles=document.getElementById("wfu_fbperm_role_0_dl");var $edit_from_roles=document.getElementById("wfu_fbperm_role_0_edit");var $del_from_roles=document.getElementById("wfu_fbperm_role_0_del")}row.style.fontWeight=def.checked?"":"bold";role.checked=def.checked?role_def.checked:role.checked;
view.checked=def.checked?role_def.checked?$view_from_roles:view_def.checked:role.checked?$view_from_roles:view.checked;dl.checked=def.checked?role_def.checked?$dl_from_roles:dl_def.checked:role.checked?$dl_from_roles:view.checked&&dl.checked;edit.checked=def.checked?role_def.checked?$edit_from_roles:edit_def.checked:role.checked?$edit_from_roles:view.checked&&edit.checked;del.checked=def.checked?role_def.checked?$del_from_roles:del_def.checked:role.checked?$del_from_roles:view.checked&&del.checked;
role.disabled=def.checked;view.disabled=def.checked||role.checked;dl.disabled=def.checked||role.checked||!view.checked;edit.disabled=def.checked||role.checked||!view.checked;del.disabled=def.checked||role.checked||!view.checked;if(immediate){var props=def.checked?"":"D"+(role.checked?"":"R"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":""));users.value=users.value.replace(new RegExp(","+id+"\\[\\w*\\]|"+id+"\\[\\w*\\],|"+id+"\\[\\w*\\]"),"");users.value+=(users.value==
""?"":",")+id+"["+props+"]"}}}}}
function wfu_goto_historylog_page(token,go_to){var sel=document.getElementById("wfu_historylog_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);
params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_historylog_page";params[1]=new Array(2);params[1][0]="token";params[1][1]=token;params[2]=new Array(2);params[2][0]="page";params[2][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_historylog_overlay").style.display="block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_historylog_overlay").style.display="none";var start_text="wfu_historylog_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);if(response!=""){var t=document.getElementById("wfu_historylog_table");t.tBodies[0].innerHTML=
wfu_plugin_decode_string(response);sel.selectedIndex=newpage-1;document.getElementById("wfu_historylog_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_historylog_prev_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_historylog_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_historylog_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_historylog_last_disabled").style.display=
newpage==sel.options.length?"inline":"none";document.getElementById("wfu_historylog_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_historylog_last").style.display=newpage==sel.options.length?"none":"inline";document.getElementById("wfu_historylog_next").style.display=newpage==sel.options.length?"none":"inline"}}};xhr.send(parameters)}
function wfu_attach_uploadedfiles_events(){function _wfu_hightlight_property(obj){var id=obj.id.replace(/^p_([0-9]+)_[0-9]+$/,"$1");document.querySelector("tr.wfu_row-"+id+" .wfu-remarks-container").innerHTML=wfu_plugin_decode_string(obj.firstChild.value)}function _wfu_unhightlight_property(obj){var id=obj.id.replace(/^p_([0-9]+)_[0-9]+$/,"$1");obj.classList.remove("wfu-clicked");document.querySelector("tr.wfu_row-"+id+" .wfu-remarks-container").innerHTML=""}window.wfu_last_shown_remark=null;var props=
document.querySelectorAll(".wfu-properties:not(.wfu-dashicons-hidden)");for(var i=0;i<props.length;i++)if(typeof props[i].hashover=="undefined"||props[i].hashover!=true){jQuery(props[i]).hover(function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_hightlight_property(this);window.wfu_last_shown_remark=this},function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_unhightlight_property(this);window.wfu_last_shown_remark=
null});jQuery(props[i]).click(function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_hightlight_property(this);this.classList.add("wfu-clicked");window.wfu_last_shown_remark=this});this.hashover=true}}
function wfu_update_uploadedfiles_bubble(count){var bubble_container=document.querySelector("#toplevel_page_wfu_uploaded_files .update-plugins");var bubble_text=document.querySelector("#toplevel_page_wfu_uploaded_files .plugin-count");if(bubble_container&&bubble_text){bubble_container.className="update-plugins count-"+count;var text=count;if(count>99)text="99+";bubble_text.innerHTML=text}}
function wfu_goto_uploadedfiles_page(token,go_to){var sel=document.getElementById("wfu_uploadedfiles_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);
params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_uploadedfiles_page";params[1]=new Array(2);params[1][0]="token";params[1][1]=token;params[2]=new Array(2);params[2][0]="page";params[2][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_uploadedfiles_overlay").style.display="block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_uploadedfiles_overlay").style.display="none";var start_text="wfu_uploadedfiles_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);if(response!=""){var t=document.getElementById("wfu_uploadedfiles_table");
var html=wfu_plugin_decode_string(response);var unread_files_count=0;var unread_files_count_raw=html.match(/wfu_uploadedfiles_unread\[(.*?)\]/);if(unread_files_count_raw&&unread_files_count_raw[1])unread_files_count=parseInt(unread_files_count_raw[1]);if(isNaN(unread_files_count))unread_files_count=0;t.tBodies[0].innerHTML=html;sel.selectedIndex=newpage-1;document.getElementById("wfu_uploadedfiles_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_uploadedfiles_prev_disabled").style.display=
newpage==1?"inline":"none";document.getElementById("wfu_uploadedfiles_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_uploadedfiles_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_uploadedfiles_last_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_uploadedfiles_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_uploadedfiles_last").style.display=
newpage==sel.options.length?"none":"inline";document.getElementById("wfu_uploadedfiles_next").style.display=newpage==sel.options.length?"none":"inline";wfu_attach_uploadedfiles_events();wfu_update_uploadedfiles_bubble(unread_files_count)}}};xhr.send(parameters)}
function wfu_include_file(filepath_enc,ii){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var nonce="";var nonce_elem=document.getElementById("wfu_include_file_nonce");if(nonce_elem)nonce=nonce_elem.value;if(nonce=="")return;var url=AdminParams.wfu_ajax_url;params=new Array(2);params[0]=new Array(3);params[0][0]="action";params[0][1]="wfu_ajax_action_include_file";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="nonce";params[2][1]=
nonce;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_include_file_"+ii+"_a").href="javascript: void(0)";document.getElementById("wfu_include_file_"+ii+"_img").style.display="inline";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4){document.getElementById("wfu_include_file_"+ii+"_img").style.display=
"none";if(xhr.status==200){var start_text="wfu_include_file:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){document.getElementById("wfu_file_flat_"+ii).style.display="none";
document.getElementById("wfu_file_link_"+ii).style.display="inline";document.getElementById("wfu_file_can_be_included_actions_"+ii).style.display="none";document.getElementById("wfu_file_is_included_actions_"+ii).style.display="block"}else document.getElementById("wfu_include_file_"+ii+"_a").innerHTML=document.getElementById("wfu_include_file_"+ii+"_inpfail").value}}};xhr.send(parameters)}
function wfu_adminbrowser_select_all_visible_changed(){var status=document.getElementById("wfu_select_all_visible").checked;var selectors=document.querySelectorAll(".wfu_selectors");for(var i=0;i<selectors.length;i++)selectors[i].checked=status}
function wfu_adminbrowser_selector_changed(obj){var selectors_count=document.querySelectorAll(".wfu_selectors").length;var selected_count=document.querySelectorAll(".wfu_selectors:checked").length;var all_visible=document.getElementById("wfu_select_all_visible");all_visible.style.webkitAppearance="";all_visible.style.webkitAppearance="checkbox";all_visible.checked=selected_count>0;all_visible.indeterminate=selected_count>0&&selected_count<selectors_count}
function wfu_apply_adminbrowser_bulkaction(){var actionselector=document.getElementById("wfu_adminbrowser_bulkactions");if(actionselector.selectedIndex<1)return;var action=actionselector.options[actionselector.selectedIndex].value;var selected=document.querySelectorAll(".wfu_selectors:checked");if(selected.length==0)return;var codes=[];var codes_included=0,codes_not_included=0;for(var i=0;i<selected.length;i++){var file_code=selected[i].className.replace(/.*?wfu_selcode_/,"");if(file_code!=""){var included=
selected[i].className.indexOf("wfu_included")>-1;if(included)codes_included++;else codes_not_included++;if(action=="delete"&&!included||action=="include"&&included)selected[i].checked=false;else codes.push(file_code)}}if(action=="delete"&&codes_not_included>0)alert("Notice! Files that were not uploaded using the plugin cannot be deleted and have been deselected.");else if(action=="include"&&codes_included>0)alert("Notice! Files already included in the plugin have been deselected.");if(codes.length==
0)return;var url=document.getElementById("wfu_adminbrowser_action_url").value;var referer=document.getElementById("wfu_adminbrowser_referer").value;if(action=="delete"||action=="include"){var form=document.createElement("FORM");form.method="POST";form.action=url;form.style.display="none";var field1=document.createElement("INPUT");field1.type="hidden";field1.name="action";field1.value=action+"_file";form.appendChild(field1);var field2=document.createElement("INPUT");field2.type="hidden";field2.name=
"file";field2.value="list:"+codes.join();form.appendChild(field2);var field3=document.createElement("INPUT");field3.type="hidden";field3.name="referer";field3.value=referer;form.appendChild(field3);document.body.appendChild(form);form.submit()}}
function wfu_goto_adminbrowser_page(token,go_to){var sel=document.getElementById("wfu_adminbrowser_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(4);
params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_adminbrowser_page";params[1]=new Array(2);params[1][0]="code";params[1][1]=document.getElementById("wfu_adminbrowser_code").value;params[2]=new Array(2);params[2][0]="token";params[2][1]=token;params[3]=new Array(2);params[3][0]="page";params[3][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_adminbrowser_overlay").style.display=
"block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_adminbrowser_overlay").style.display="none";var start_text="wfu_adminbrowser_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-
pos-start_text.length);if(response!=""){response=wfu_plugin_decode_string(response);var t=document.getElementById("wfu_adminbrowser_table");t.tBodies[0].innerHTML=response;document.getElementById("wfu_select_all_visible").checked=false;wfu_adminbrowser_select_all_visible_changed();sel.selectedIndex=newpage-1;document.getElementById("wfu_adminbrowser_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_adminbrowser_prev_disabled").style.display=newpage==1?"inline":
"none";document.getElementById("wfu_adminbrowser_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_adminbrowser_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_adminbrowser_last_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_adminbrowser_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_adminbrowser_last").style.display=newpage==sel.options.length?
"none":"inline";document.getElementById("wfu_adminbrowser_next").style.display=newpage==sel.options.length?"none":"inline"}}};xhr.send(parameters)}
function wfu_focus_table_on_highlighted_file(tableID){var tr=document.querySelector("#"+tableID+" tr.wfu-highlighted");if(tr){var adminbar=document.getElementById("wpadminbar");if(adminbar)adminbar=jQuery(adminbar).is(":visible")?adminbar:null;jQuery("html, body").animate({scrollTop:jQuery(tr).offset().top-(adminbar?jQuery(adminbar).height():0)+"px"},"fast")}}
function wfu_cleanlog_initialize_elements(){jQuery("#wfu_cleanlog_dateold").datepicker({dateFormat:"yy-mm-dd",beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});jQuery("#wfu_cleanlog_datefrom").datepicker({dateFormat:"yy-mm-dd",beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});jQuery("#wfu_cleanlog_dateto").datepicker({dateFormat:"yy-mm-dd",
beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});wfu_attach_element_handlers(document.getElementById("wfu_cleanlog_periodold"),wfu_cleanlog_element_handler);wfu_attach_element_handlers(document.getElementById("wfu_cleanlog_periodtype"),wfu_cleanlog_element_handler)}function wfu_cleanlog_element_handler(e){document.querySelector(".wfu_cleanlog_error").classList.add("hidden")}
function wfu_cleanlog_period_changed(){var sel=document.getElementById("wfu_cleanlog_period");if(sel.selectedIndex==0){document.querySelector(".wfu_selectdate_container").style.display="block";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="none";document.getElementById("wfu_cleanlog_dateold").value="";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==
1){document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display="block";document.querySelector(".wfu_selectdates_container").style.display="none";document.getElementById("wfu_cleanlog_periodold").value="1";document.getElementById("wfu_cleanlog_periodtype").selectedIndex=1;document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==2){document.querySelector(".wfu_selectdate_container").style.display=
"none";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="block";document.getElementById("wfu_cleanlog_datefrom").value="";document.getElementById("wfu_cleanlog_dateto").value="";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==3){document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display=
"none";document.querySelector(".wfu_selectdates_container").style.display="none";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else{document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="none";document.querySelector(".wfu_cleanlog_proceed").classList.add("disabled")}document.querySelector(".wfu_cleanlog_error").classList.add("hidden")}
function wfu_cleanlog_selector_toggle(show){if(show){document.getElementById("wfu_cleanlog_period").selectedIndex=-1;wfu_cleanlog_period_changed();document.querySelector(".wfu_cleanlog_tr").style.display="table-row"}else document.querySelector(".wfu_cleanlog_tr").style.display="none"}
function wfu_cleanlog_selector_validate(){var ret={error:"",param:""};var sel=document.getElementById("wfu_cleanlog_period");if(sel.selectedIndex==-1)ret.error="Invalid clean-up period selected";else if(sel.selectedIndex==0){var date=jQuery("#wfu_cleanlog_dateold").datepicker("getDate");if(date==null)ret.error="Invalid or empty date";else{var today=new Date;if(date>today)ret.error="Date must be older than today";else{var timelimit=jQuery.datepicker.formatDate("yymmdd",date);ret.param="0:"+timelimit.toString()}}}else if(sel.selectedIndex==
1){var inp=document.getElementById("wfu_cleanlog_periodold");var sel2=document.getElementById("wfu_cleanlog_periodtype");if(parseInt(inp.value)<=0)ret.error="Invalid period";else if(sel2.selectedIndex<0||sel2.selectedIndex>2)ret.error="Invalid period interval";else ret.param="1:"+inp.value.toString()+":"+sel2.value.substr(0,1)}else if(sel.selectedIndex==2){var datefrom=jQuery("#wfu_cleanlog_datefrom").datepicker("getDate");var dateto=jQuery("#wfu_cleanlog_dateto").datepicker("getDate");if(datefrom==
null)ret.error="Invalid or empty starting date";else if(dateto==null)ret.error="Invalid or empty ending date";else{var today=new Date;if(datefrom>today)ret.error="Starting date must be older than today";else if(dateto>datefrom)ret.error="Ending date must be older or equal to starting date";else{var fromlimit=jQuery.datepicker.formatDate("yymmdd",datefrom);var tolimit=jQuery.datepicker.formatDate("yymmdd",dateto);ret.param="2:"+fromlimit.toString()+":"+tolimit.toString()}}}else if(sel.selectedIndex==
3)ret.param="3";return ret}function wfu_cleanlog_selector_checkproceed(){var ret=wfu_cleanlog_selector_validate();if(ret.error!=""){document.querySelector(".wfu_cleanlog_error").innerHTML=ret.error;document.querySelector(".wfu_cleanlog_error").classList.remove("hidden");return false}document.querySelector(".wfu_cleanlog_error").classList.add("hidden");document.querySelector(".wfu_cleanlog_proceed").href=document.getElementById("wfu_cleanlog_href").value+"&data="+ret.param;return true}
function wfu_initialize_consent_policy(params){wfu_PD_bank.params=params;wfu_adjust_pdops_levels();wfu_adjust_permissions_levels();wfu_adjust_logactions_levels();wfu_attach_pdheaders_events();wfu_attach_pdops_events();wfu_attach_conops_events();wfu_pdops_update(true);wfu_allops_freeze_events=true;wfu_conops_update();wfu_consent_question_optable_recreate();wfu_update_consent_questions();wfu_consent_question_operations_reassign();wfu_update_consent_question_itemprops(0,-1);wfu_permissions_update(true);
wfu_logactions_update(true);wfu_pdusers_update();wfu_allops_freeze_events=false}function wfu_get_consent_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_consent_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}function wfu_get_permissions_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_permissions_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}
function wfu_get_logactions_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_logactions_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}function wfu_get_pd_users(){var pd_users_str=wfu_plugin_decode_string(document.getElementById("wfu_assigned_users").value);var pd_users=null;try{pd_users=JSON.parse(pd_users_str)}catch(e){}return pd_users}
function wfu_set_consent_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_consent_policy").value=wfu_plugin_encode_string(policy_str)}function wfu_set_logactions_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_logactions_policy").value=wfu_plugin_encode_string(policy_str)}
function wfu_set_permissions_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_permissions_policy").value=wfu_plugin_encode_string(policy_str)}
function wfu_adjust_pdops_levels(){function _wfu_force_pdop_update_nested(item){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_pdop_update_nested(item.children[j]);else policy.operations[id].Allowed=true}function _wfu_nested_adjust_pdops_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_pdops_levels(item.children[j],level+1);var id=item.ID;if(wfu_PD_bank.allowedstatus[id]==0&&level==wfu_PD_bank.params.oplevels){_wfu_force_pdop_update_nested(item);
wfu_PD_bank.allowedstatus[id]=1;policy_needs_update=true}}wfu_pdops_update(false);var policy=wfu_get_consent_policy();if(policy){console.log(policy);var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_pdops_levels(policy.structure[i],1);if(policy_needs_update)wfu_set_consent_policy(policy)}}
function wfu_attach_pdheaders_events(){var acc=document.querySelectorAll(".wfu_pdheader_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=null;if(this.classList.contains("wfu_pdop_header_button"))panel=document.querySelector(".wfu_plugin_operations");else if(this.classList.contains("wfu_conop_header_button"))panel=document.querySelector(".wfu_consent_operations");else if(this.classList.contains("wfu_conquestion_header_button"))panel=
document.querySelector(".wfu_consent_questions");else if(this.classList.contains("wfu_permissions_header_button"))panel=document.querySelector(".wfu_consent_permissions");else if(this.classList.contains("wfu_logactions_header_button"))panel=document.querySelector(".wfu_consent_logactions");else if(this.classList.contains("wfu_pdusers_header_button"))panel=document.querySelector(".wfu_consent_users");if(panel)if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display=
"none"})}function wfu_attach_pdops_events(){var acc=document.querySelectorAll(".wfu_pdop_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=this.parentElement.nextElementSibling;if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display="none"})}
function wfu_attach_conops_events(){var acc=document.querySelectorAll(".wfu_conop_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=this.parentElement.nextElementSibling;if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display="none"})}
function wfu_pdop_toggle(obj){if(wfu_allops_freeze_events)return;if(obj.id.indexOf("wfu_pdop_")==-1)return;var id=obj.id.replace("wfu_pdop_","");var policy=wfu_get_consent_policy();if(policy){if(typeof policy.operations[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");if(policy.children_index[id].length>0){var level=1;
var parid=id;while((parid=policy.operations[parid].Parent)>0)level++;if((wfu_PD_bank.params.oplevels<1||level<wfu_PD_bank.params.oplevels)&&!confirm("This will set all children operations to "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==0)policy.operations[id2].Allowed=
new_status}}else policy.operations[id].Allowed=new_status;wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_pdops_update(true);wfu_conops_update();wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_optable_recreate();wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_allops_freeze_events=false}}
function wfu_conop_toggle(obj){if(wfu_allops_freeze_events)return;if(obj.id.indexOf("wfu_conop_")==-1)return;var id=obj.id.replace("wfu_conop_","");var policy=wfu_get_consent_policy();if(policy){if(typeof policy.operations[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)check.classList.remove("indeterminate");if(policy.children_index[id].length>0){var level=
1;var parid=id;while((parid=policy.operations[parid].Parent)>0)level++;if((wfu_PD_bank.params.oplevels<1||level<wfu_PD_bank.params.oplevels)&&!confirm("This will make all children operations "+(new_status?"require":"not require")+" consent. Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==0)policy.operations[id2].NeedsConsent=
new_status}}else policy.operations[id].NeedsConsent=new_status;wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_conops_update();wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_optable_recreate();wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_allops_freeze_events=false}}
function wfu_pdops_update(updatehtml){function _wfu_atomic_pdop_update(id){var allowed=policy.operations[id].Allowed;policy.operations[id].allowedstatus={};for(var k=0;k<policy.operations[id].Datatypes.length;k++){var type=policy.operations[id].Datatypes[k];policy.operations[id].allowedstatus[type]=allowed?1:-1}var condition=policy.operations[id].Condition;if(condition=="")policy.operations[id].pdvisible=true;else{var negative=false;if(condition.substr(0,1)=="!"){negative=true;condition=condition.replace("!",
"")}var allowedstatus2=policy.operations[parseInt(condition)].allowedstatus;var enabled=false;for(var type in allowedstatus2)if(allowedstatus2.hasOwnProperty(type))if(allowedstatus2[type]>-1){enabled=true;break}policy.operations[id].pdvisible=negative?!enabled:enabled}}function _wfu_nested_pdops_update(item,level){var id=item.ID;if(item.children.length>0){policy.operations[id].allowedstatus={};policy.operations[id].pdvisible=false;for(var j=0;j<item.children.length;j++){_wfu_nested_pdops_update(item.children[j],
level+1);var id2=item.children[j].ID;if(policy.operations[id2].pdvisible){var allowed=policy.operations[id2].Allowed;for(var type in policy.operations[id2].allowedstatus)if(policy.operations[id2].allowedstatus.hasOwnProperty(type)){var allowedstatus2=policy.operations[id2].allowedstatus[type];if(typeof policy.operations[id].allowedstatus[type]=="undefined")policy.operations[id].allowedstatus[type]=allowedstatus2;else if(policy.operations[id].allowedstatus[type]*allowedstatus2<1)policy.operations[id].allowedstatus[type]=
0}if(!policy.operations[id].pdvisible)policy.operations[id].pdvisible=policy.operations[id2].pdvisible}}}else _wfu_atomic_pdop_update(id);var allowedstatus=-2;for(var type in policy.operations[id].allowedstatus)if(policy.operations[id].allowedstatus.hasOwnProperty(type)){var allowedstatus2=policy.operations[id].allowedstatus[type];if(allowedstatus==-2)allowedstatus=allowedstatus2;else if(allowedstatus*allowedstatus2<1){allowedstatus=0;break}}if(typeof wfu_PD_bank.allowedstatus=="undefined")wfu_PD_bank.allowedstatus=
{};wfu_PD_bank.allowedstatus[id]=allowedstatus;if(typeof wfu_PD_bank.level=="undefined")wfu_PD_bank.level={};wfu_PD_bank.level[id]=level;if(updatehtml){var check=document.getElementById("wfu_pdop_"+id);wfu_set_checkbox_status(check,allowedstatus);var container=document.getElementById("wfu_pdop_container_"+id);if(container)container.style.display=policy.operations[id].pdvisible&&(wfu_PD_bank.params.oplevels<1||level<=wfu_PD_bank.params.oplevels)?"block":"none"}}var policy=wfu_get_consent_policy();
if(policy){wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_pdops_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
function wfu_conops_update(){function _wfu_atomic_conop_update(id){policy.operations[id].needsconsentstatus=policy.operations[id].Allowed&&policy.operations[id].NeedsConsent?1:-1;var condition=policy.operations[id].Condition;if(condition=="")policy.operations[id].convisible=true;else{var negative=false;if(condition.substr(0,1)=="!"){negative=true;condition=condition.replace("!","")}var enabled=wfu_PD_bank.allowedstatus[parseInt(condition)]>-1;policy.operations[id].convisible=negative?!enabled:enabled}policy.operations[id].convisible=
policy.operations[id].convisible&&policy.operations[id].Allowed}function _wfu_nested_conops_update(item,level){var id=item.ID;if(item.children.length>0){policy.operations[id].needsconsentstatus=-2;policy.operations[id].convisible=false;for(var j=0;j<item.children.length;j++){_wfu_nested_conops_update(item.children[j],level+1);var id2=item.children[j].ID;if(policy.operations[id2].convisible){var needsconsentstatus2=policy.operations[id2].needsconsentstatus;if(policy.operations[id].needsconsentstatus==
-2)policy.operations[id].needsconsentstatus=needsconsentstatus2;else if(policy.operations[id].needsconsentstatus*needsconsentstatus2<1)policy.operations[id].needsconsentstatus=0;if(!policy.operations[id].convisible)policy.operations[id].convisible=policy.operations[id2].convisible}}}else _wfu_atomic_conop_update(id);if(typeof wfu_PD_bank.visible=="undefined")wfu_PD_bank.visible={};wfu_PD_bank.visible[id]=policy.operations[id].convisible;if(typeof wfu_PD_bank.needsconsentstatus=="undefined")wfu_PD_bank.needsconsentstatus=
{};wfu_PD_bank.needsconsentstatus[id]=policy.operations[id].needsconsentstatus;var check=document.getElementById("wfu_conop_"+id);wfu_set_checkbox_status(check,policy.operations[id].needsconsentstatus);var container=document.getElementById("wfu_conop_container_"+id);if(container)container.style.display=policy.operations[id].convisible&&(wfu_PD_bank.params.oplevels<1||level<=wfu_PD_bank.params.oplevels)?"block":"none"}var policy=wfu_get_consent_policy();if(policy){wfu_allops_freeze_events=true;for(var i=
0;i<policy.structure.length;i++)_wfu_nested_conops_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
function wfu_update_consent_questions(){var policy=wfu_get_consent_policy();if(policy){var maincontainer=document.getElementById("wfu_conquestions_container");wfu_allops_freeze_events=true;for(var i=0;i<policy.questions.length;i++){var container=wfu_render_consent_question(i);if(container){maincontainer.appendChild(container);wfu_update_consent_question(i,true)}}wfu_update_conquestion_header();wfu_allops_freeze_events=false}}
function wfu_render_consent_question(index){var policy=wfu_get_consent_policy();if(!policy)return null;var question=policy.questions[index];var i=index+1;var container=document.createElement("DIV");container.className="wfu_conquestion_container";container.id="wfu_conquestion_container_"+i;var header=document.createElement("DIV");header.className="wfu_conquestion_header";var headerlabel=document.createElement("LABEL");headerlabel.className="wfu_conquestion_headerlabel";headerlabel.innerHTML="Question "+
i;header.appendChild(headerlabel);var tools=document.createElement("DIV");tools.className="wfu_conquestion_tools";var add_btn=document.getElementById("wfu_conquestion_add").cloneNode(true);add_btn.removeAttribute("id");wfu_addEventHandler(add_btn,"click",wfu_conquestion_tools_handler);var remove_btn=document.getElementById("wfu_conquestion_remove").cloneNode(true);remove_btn.removeAttribute("id");wfu_addEventHandler(remove_btn,"click",wfu_conquestion_tools_handler);var up_btn=document.getElementById("wfu_conquestion_up").cloneNode(true);
up_btn.removeAttribute("id");wfu_addEventHandler(up_btn,"click",wfu_conquestion_tools_handler);var down_btn=document.getElementById("wfu_conquestion_down").cloneNode(true);down_btn.removeAttribute("id");wfu_addEventHandler(down_btn,"click",wfu_conquestion_tools_handler);tools.appendChild(add_btn);tools.appendChild(remove_btn);tools.appendChild(up_btn);tools.appendChild(down_btn);header.appendChild(tools);var subcontainer=document.createElement("DIV");subcontainer.className="wfu_conquestion_subcontainer";
var mainprops=document.createElement("DIV");mainprops.className="wfu_conquestion_mainprops";var mainpropstitle=document.createElement("LABEL");mainpropstitle.className="wfu_conquestion_mainpropstitle";mainpropstitle.innerHTML="Main Properties";var titlelabel=document.createElement("LABEL");titlelabel.className="wfu_conquestion_titlelabel";titlelabel.innerHTML="Title";var titletext=document.createElement("INPUT");titletext.className="wfu_conquestion_titletext";titletext.value=question.title;wfu_attach_element_handlers(titletext,
wfu_conquestion_mainprops_handler);var titlelocationlabel=document.createElement("LABEL");titlelocationlabel.className="wfu_conquestion_titlelocationlabel";titlelocationlabel.innerHTML="Title Location";var titlelocationlist=document.createElement("SELECT");titlelocationlist.className="wfu_conquestion_titlelocationlist";var opt=document.createElement("OPTION");opt.value="top";opt.innerHTML="Top";opt.selected=question.location=="top";titlelocationlist.add(opt);var opt=document.createElement("OPTION");
opt.value="bottom";opt.innerHTML="Bottom";opt.selected=question.location=="bottom";titlelocationlist.add(opt);wfu_addEventHandler(titlelocationlist,"change",wfu_conquestion_mainprops_handler);var matrixlabel=document.createElement("LABEL");matrixlabel.className="wfu_conquestion_matrixlabel";matrixlabel.innerHTML="Number of Items";var matrix_x=document.createElement("INPUT");matrix_x.className="wfu_conquestion_matrix_x";matrix_x.type="number";matrix_x.min=1;var qx=parseInt(question.x);if(qx<=0)qx=
1;question.x=qx;matrix_x.value=qx;wfu_attach_element_handlers(matrix_x,wfu_conquestion_mainprops_handler);var matrixsep=document.createElement("LABEL");matrixsep.className="wfu_conquestion_matrixsep";matrixsep.innerHTML="x";var matrix_y=document.createElement("INPUT");matrix_y.className="wfu_conquestion_matrix_y";matrix_y.type="number";matrix_y.min=1;var qy=parseInt(question.y);if(qy<=0)qy=1;question.y=qy;matrix_y.value=qy;wfu_attach_element_handlers(matrix_y,wfu_conquestion_mainprops_handler);var groupedlabel=
document.createElement("LABEL");groupedlabel.className="wfu_conquestion_groupedlabel";groupedlabel.innerHTML="Grouped";var groupedbox=document.createElement("INPUT");groupedbox.className="wfu_conquestion_groupedbox";groupedbox.type="checkbox";groupedbox.checked=question.grouped==1;wfu_addEventHandler(groupedbox,"change",wfu_conquestion_mainprops_handler);var typelabel=document.createElement("LABEL");typelabel.className="wfu_conquestion_typelabel";typelabel.innerHTML="Type";var typelist=document.createElement("SELECT");
typelist.className="wfu_conquestion_typelist";var opt=document.createElement("OPTION");opt.value="checkbox";opt.innerHTML="Checkbox";opt.selected=question.type=="checkbox";typelist.add(opt);var opt=document.createElement("OPTION");opt.value="radio";opt.innerHTML="Radio";opt.selected=question.type=="radio";typelist.add(opt);var opt=document.createElement("OPTION");opt.value="prompt";opt.innerHTML="Prompt";opt.selected=question.type=="prompt";typelist.add(opt);wfu_addEventHandler(typelist,"change",
wfu_conquestion_mainprops_handler);mainprops.appendChild(mainpropstitle);mainprops.appendChild(matrixlabel);mainprops.appendChild(matrix_x);mainprops.appendChild(matrixsep);mainprops.appendChild(matrix_y);mainprops.appendChild(titlelabel);mainprops.appendChild(titletext);mainprops.appendChild(titlelocationlabel);mainprops.appendChild(titlelocationlist);mainprops.appendChild(groupedlabel);mainprops.appendChild(groupedbox);mainprops.appendChild(typelabel);mainprops.appendChild(typelist);var itemspreview=
document.createElement("DIV");itemspreview.className="wfu_conquestion_itemspreview";var itemspreviewtitle=document.createElement("LABEL");itemspreviewtitle.className="wfu_conquestion_itemspreviewtitle";itemspreviewtitle.innerHTML="Items";var displayedtitle=document.createElement("LABEL");displayedtitle.className="wfu_conquestion_displayedtitle";displayedtitle.innerHTML=question.title;var itemtable=document.createElement("TABLE");itemtable.className="wfu_conquestion_itemtable";itemspreview.appendChild(itemspreviewtitle);
if(question.location!="bottom")itemspreview.appendChild(displayedtitle);itemspreview.appendChild(itemtable);if(question.location=="bottom")itemspreview.appendChild(displayedtitle);wfu_addEventHandler(itemspreview,"click",wfu_conquestion_itempreviewer_handler);var itemprops=document.createElement("DIV");itemprops.className="wfu_conquestion_itemprops";var itempropstitle=document.createElement("LABEL");itempropstitle.className="wfu_conquestion_itempropstitle";itempropstitle.innerHTML="Item Properties";
var labellabel=document.createElement("LABEL");labellabel.className="wfu_conquestion_labellabel";labellabel.innerHTML="Label";var labeltext=document.createElement("INPUT");labeltext.className="wfu_conquestion_labeltext";labeltext.value="";wfu_attach_element_handlers(labeltext,wfu_conquestion_mainprops_handler);var labellocationlabel=document.createElement("LABEL");labellocationlabel.className="wfu_conquestion_labellocationlabel";labellocationlabel.innerHTML="Label Location";var labellocationlist=
document.createElement("SELECT");labellocationlist.className="wfu_conquestion_labellocationlist";var opt=document.createElement("OPTION");opt.value="top";opt.innerHTML="Top";opt.selected=false;labellocationlist.add(opt);var opt=document.createElement("OPTION");opt.value="left";opt.innerHTML="Left";opt.selected=false;labellocationlist.add(opt);var opt=document.createElement("OPTION");opt.value="right";opt.innerHTML="Right";opt.selected=true;labellocationlist.add(opt);var opt=document.createElement("OPTION");
opt.value="bottom";opt.innerHTML="Bottom";opt.selected=false;labellocationlist.add(opt);wfu_addEventHandler(labellocationlist,"change",wfu_conquestion_mainprops_handler);var preselectedlabel=document.createElement("LABEL");preselectedlabel.className="wfu_conquestion_preselectedlabel";preselectedlabel.innerHTML="Preselected";var preselectedbox=document.createElement("INPUT");preselectedbox.className="wfu_conquestion_preselectedbox";preselectedbox.type="checkbox";preselectedbox.checked=false;wfu_addEventHandler(preselectedbox,
"change",wfu_conquestion_mainprops_handler);var visiblelabel=document.createElement("LABEL");visiblelabel.className="wfu_conquestion_visiblelabel";visiblelabel.innerHTML="Visible";var visiblebox=document.createElement("INPUT");visiblebox.className="wfu_conquestion_visiblebox";visiblebox.type="checkbox";visiblebox.checked=true;wfu_addEventHandler(visiblebox,"change",wfu_conquestion_mainprops_handler);itemprops.appendChild(itempropstitle);itemprops.appendChild(labellabel);itemprops.appendChild(labeltext);
itemprops.appendChild(labellocationlabel);itemprops.appendChild(labellocationlist);itemprops.appendChild(preselectedlabel);itemprops.appendChild(preselectedbox);itemprops.appendChild(visiblelabel);itemprops.appendChild(visiblebox);subcontainer.appendChild(mainprops);subcontainer.appendChild(itemspreview);subcontainer.appendChild(itemprops);container.appendChild(header);container.appendChild(subcontainer);return container}
function wfu_consent_question_action(action,index){var policy=wfu_get_consent_policy();if(!policy)return;var maincontainer=document.getElementById("wfu_conquestions_container");var qcount=document.querySelectorAll(".wfu_conquestion_container").length;if(action=="add"){var question={title:"",location:"top",x:1,y:1,grouped:0,type:"checkbox",items:[{index:1,label:"I agree to allow the plugin to use my personal data",location:"right",preselect:0,visible:true,operations:{}}]};policy.questions.splice(index+
1,0,question);wfu_set_consent_policy(policy);var container=wfu_render_consent_question(index+1);if(container){for(var j=index+2;j<=qcount;j++)document.getElementById("wfu_conquestion_container_"+j).id="wfu_conquestion_container_"+(j+1);maincontainer.insertBefore(container,document.getElementById("wfu_conquestion_container_"+(index+3)));wfu_update_consent_question(index+1,true);wfu_update_consent_question_itemprops(index+1,-1)}}else if(action=="remove"){if(qcount<=1)return;policy.questions.splice(index,
1);wfu_set_consent_policy(policy);maincontainer.removeChild(document.getElementById("wfu_conquestion_container_"+(index+1)));for(var j=index+2;j<=qcount;j++)document.getElementById("wfu_conquestion_container_"+j).id="wfu_conquestion_container_"+(j-1)}else if(action=="up"){if(index<=0)return;var tempq=policy.questions[index];policy.questions[index]=policy.questions[index-1];policy.questions[index-1]=tempq;wfu_set_consent_policy(policy);var container1=document.getElementById("wfu_conquestion_container_"+
(index+1));var container2=document.getElementById("wfu_conquestion_container_"+index);container1.id="wfu_conquestion_container_"+index+"_temp";container2.id="wfu_conquestion_container_"+(index+1);container1.id="wfu_conquestion_container_"+index;maincontainer.insertBefore(container1,container2)}else if(action=="down"){if(index>=qcount-1)return;var tempq=policy.questions[index];policy.questions[index]=policy.questions[index+1];policy.questions[index+1]=tempq;wfu_set_consent_policy(policy);var container1=
document.getElementById("wfu_conquestion_container_"+(index+2));var container2=document.getElementById("wfu_conquestion_container_"+(index+1));container1.id="wfu_conquestion_container_"+(index+1)+"_temp";container2.id="wfu_conquestion_container_"+(index+2);container1.id="wfu_conquestion_container_"+(index+1);maincontainer.insertBefore(container1,container2)}}
function wfu_update_consent_question(index,recreate){var policy=wfu_get_consent_policy();if(!policy)return;var question=policy.questions[index];var i=index+1;var itemspreview=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemspreview");var itemtable=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemtable");var displayedtitle=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_displayedtitle");if(!itemspreview)return;if(recreate){var matrix_x=
document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_matrix_x");var matrix_y=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_matrix_y");var titletext=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_titletext");var titlelocationlist=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_titlelocationlist");var groupedbox=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_groupedbox");
matrix_x.value=question.x;matrix_y.value=question.y;titletext.value=question.title;titlelocationlist.value=question.location;groupedbox.checked=question.grouped==1;matrix_x.disabled=question.type=="prompt";matrix_y.disabled=question.type=="prompt";titletext.disabled=question.type=="prompt";titlelocationlist.disabled=question.type=="prompt";groupedbox.disabled=question.type=="prompt";displayedtitle.style.display=question.type=="prompt"?"none":"block";while(itemtable.rows.length>0)itemtable.deleteRow(0)}var qnum=
question.x*question.y;var qitems=[];for(var j=0;j<qnum;j++)qitems.push({label:"",location:"right",preselect:false,visible:true,operations:{}});for(var j=0;j<question.items.length;j++)if(typeof question.items[j].visible=="undefined")question.items[j].visible=1;for(var j=0;j<question.items.length;j++){var ind=question.items[j].index-1;if(ind>=0&&ind<qnum){qitems[ind].label=question.items[j].label;qitems[ind].location=question.items[j].location;qitems[ind].preselect=question.items[j].preselect==1;qitems[ind].visible=
typeof question.items[j].visible=="undefined"||question.items[j].visible==1;qitems[ind].operations=question.items[j].operations}}var j=0;for(var k=0;k<question.x;k++){var row;if(recreate)row=itemtable.insertRow(k);else row=itemtable.rows[k];for(var l=0;l<question.y;l++){var cell;if(recreate){cell=row.insertCell(l);cell.classList.add("wfu_conquestion_itemcontainer")}else cell=row.cells[l];while(cell.childNodes.length>0)cell.removeChild(cell.childNodes[0]);if(qitems[j].visible)cell.classList.add("wfu_item_visible");
else cell.classList.remove("wfu_item_visible");var itemlabel=document.createElement("LABEL");itemlabel.className="wfu_conquestion_itemlabel";if(qitems[j].label==""){itemlabel.classList.add("wfu_empty_label");itemlabel.innerHTML="{no label}"}else{itemlabel.classList.remove("wfu_empty_label");itemlabel.innerHTML=qitems[j].label}if(question.type=="prompt")cell.appendChild(itemlabel);else{var itembox=document.createElement("INPUT");itembox.className="wfu_conquestion_itembox wfu_frozen";itembox.type=question.type;
itembox.checked=qitems[j].preselect;if(qitems[j].location=="top"){cell.appendChild(itemlabel);cell.appendChild(document.createElement("BR"));cell.appendChild(itembox)}else if(qitems[j].location=="left"){cell.appendChild(itemlabel);cell.appendChild(itembox)}else if(qitems[j].location=="bottom"){cell.appendChild(itembox);cell.appendChild(document.createElement("BR"));cell.appendChild(itemlabel)}else{cell.appendChild(itembox);cell.appendChild(itemlabel)}}j++}}if(question.title==""){displayedtitle.classList.add("wfu_empty_label");
displayedtitle.innerHTML="{no title}"}else{displayedtitle.classList.remove("wfu_empty_label");displayedtitle.innerHTML=question.title}if(question.location!="bottom")itemspreview.insertBefore(displayedtitle,itemtable);else itemspreview.insertBefore(displayedtitle,null)}
function wfu_conquestion_mainprops_handler(e){if(wfu_allops_freeze_events)return;var policy=wfu_get_consent_policy();if(!policy)return;e=e||window.event;var item=par=e.target;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var i=parseInt(par.id.replace("wfu_conquestion_container_",""));var index=i-1;var question=policy.questions[index];var recreate=true;var is_mainprop=true;var update_optable=false;if(item.classList.contains("wfu_conquestion_titletext"))question.title=
item.value;else if(item.classList.contains("wfu_conquestion_matrix_x"))question.x=item.value;else if(item.classList.contains("wfu_conquestion_matrix_y"))question.y=item.value;else if(item.classList.contains("wfu_conquestion_titlelocationlist"))question.location=item.value;else if(item.classList.contains("wfu_conquestion_groupedbox")){question.grouped=item.checked?1:0;if(question.grouped==1){var qpreselect_count=0;for(var j=0;j<question.items.length;j++)if(qpreselect_count==1)question.items[j].preselect=
0;else if(question.items[j].preselect==1)qpreselect_count++}}else if(item.classList.contains("wfu_conquestion_typelist")){question.type=item.value;if(question.type=="prompt"){question.x=1;question.y=1;question.title="";question.location="top";question.grouped=0}}else{var itemcontainers=document.querySelectorAll("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemcontainer.wfu_item_selected");if(itemcontainers.length==0)return;var itemindex=itemcontainers[0].parentNode.rowIndex*itemcontainers[0].parentNode.cells.length+
itemcontainers[0].cellIndex+1;var qitem=null;var qindex=question.items.length;for(var j=0;j<question.items.length;j++)if(question.items[j].index==itemindex){qitem=question.items[j];break}else if(question.items[j].index>itemindex){qindex=j;break}if(!qitem){qitem={index:itemindex,label:"",location:"right",preselect:false,visible:1,operations:{}};question.items.splice(qindex,0,qitem)}if(item.classList.contains("wfu_conquestion_labeltext"))qitem.label=item.value;else if(item.classList.contains("wfu_conquestion_labellocationlist"))qitem.location=
item.value;else if(item.classList.contains("wfu_conquestion_preselectedbox")){if(item.checked&&question.grouped==1)for(var j=0;j<question.items.length;j++)question.items[j].preselect=0;qitem.preselect=item.checked?1:0}else if(item.classList.contains("wfu_conquestion_visiblebox")){qitem.visible=item.checked?1:0;update_optable=true}recreate=false;is_mainprop=false}wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_update_consent_question(index,recreate);if(is_mainprop){wfu_update_consent_question_itemprops(index,
-1);wfu_consent_question_operations_reassign()}if(update_optable){wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(i,itemindex)}wfu_allops_freeze_events=false}
function wfu_conquestion_itempreviewer_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=par=e.target;var qcount=document.querySelectorAll(".wfu_conquestion_container").length;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var i=parseInt(par.id.replace("wfu_conquestion_container_",""));var index=i-1;if(!item.classList.contains("wfu_conquestion_itemcontainer"))item=item.parentNode;var itemindex=-1;if(item.classList.contains("wfu_conquestion_itemcontainer"))itemindex=
item.parentNode.rowIndex*item.parentNode.cells.length+item.cellIndex+1;wfu_allops_freeze_events=true;for(var j=0;j<qcount;j++)wfu_update_consent_question_itemprops(j,-1);wfu_update_consent_question_itemprops(index,itemindex);wfu_allops_freeze_events=false}
function wfu_update_consent_question_itemprops(index,itemindex){var policy=wfu_get_consent_policy();if(!policy)return;var question=policy.questions[index];var i=index+1;var itemcontainers=document.querySelectorAll("#wfu_conquestions_container .wfu_conquestion_itemcontainer");var itemcontainer=null;var contindex=0;var contitemindex=1;for(var j=0;j<itemcontainers.length;j++){itemcontainers[j].classList.remove("wfu_item_selected");var par=itemcontainers[j];while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));
if(parseInt(par.id.replace("wfu_conquestion_container_",""))>contindex){contindex++;contitemindex=1}if(contindex==i&&contitemindex==itemindex)itemcontainer=itemcontainers[j];contitemindex++}if(itemcontainer)itemcontainer.classList.add("wfu_item_selected");var labeltext=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_labeltext");var labellocationlist=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_labellocationlist");var preselectedbox=document.querySelector("#wfu_conquestion_container_"+
i+" .wfu_conquestion_preselectedbox");var visiblebox=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_visiblebox");var qindex=-1;for(var j=0;j<question.items.length;j++)if(question.items[j].index==itemindex){qindex=j;break}if(qindex<0){labeltext.value="";labeltext.disabled=itemindex<1;labellocationlist.value="right";labellocationlist.disabled=itemindex<1;preselectedbox.checked=false;preselectedbox.disabled=itemindex<1;visiblebox.checked=true;visiblebox.disabled=itemindex<
1}else{labeltext.disabled=false;labeltext.value=question.items[qindex].label;labellocationlist.disabled=question.type=="prompt";labellocationlist.value=question.type=="prompt"?"":question.items[qindex].location;preselectedbox.disabled=question.type=="prompt";preselectedbox.checked=question.type=="prompt"?false:question.items[qindex].preselect==1;visiblebox.disabled=question.type=="prompt"?true:index==0&&itemindex==1;visiblebox.checked=question.type=="prompt"?true:typeof question.items[qindex].visible==
"undefined"||question.items[qindex].visible==1}wfu_consent_question_optable_update(i,itemindex)}
function wfu_consent_question_optable_recreate(){var oplist=[];var policy=wfu_get_consent_policy();if(policy){if(typeof wfu_PD_bank.conops!="undefined")for(var id in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(id))wfu_PD_bank.conops[id].active=false;var optable=document.getElementById("wfu_conquestions_optable");var body=optable.tBodies[0];while(body.rows.length>0)optable.rows[0].remove();var i=0;for(var id in wfu_PD_bank.allowedstatus)if(wfu_PD_bank.allowedstatus.hasOwnProperty(id)){var included=
true;included=included&&(policy.children_index[id].length==0&&(wfu_PD_bank.params.oplevels<1||wfu_PD_bank.level[id]<=wfu_PD_bank.params.oplevels)||policy.children_index[id].length>0&&wfu_PD_bank.level[id]==wfu_PD_bank.params.oplevels);included=included&&wfu_PD_bank.needsconsentstatus[id]==1;included=included&&wfu_PD_bank.visible[id];if(included){if(typeof wfu_PD_bank.conops=="undefined")wfu_PD_bank.conops={};wfu_PD_bank.conops[id]={active:true,qindex:[1],itemindex:[1],inverse:[false],unassigned:true,
nonevisible:false};var row=body.insertRow(i);row.id="wfu_conquestions_oprow_"+id;var cell=row.insertCell(0);var name=policy.operations[id].Name;var parid=id;while((parid=policy.operations[parid].Parent)>0)name=policy.operations[parid].Name+"/"+name;cell.innerHTML=name;var cell=row.insertCell(1);var selbox=document.createElement("INPUT");selbox.type="radio";selbox.className="wfu_conquestions_opsel wfu_frozen";wfu_addEventHandler(selbox,"click",wfu_conquestion_optable_handler);cell.appendChild(selbox);
var cell=row.insertCell(2);var invbox=document.createElement("INPUT");invbox.type="checkbox";invbox.className="wfu_conquestions_opinv wfu_frozen";invbox.disabled=true;wfu_addEventHandler(invbox,"change",wfu_conquestion_optable_handler);cell.appendChild(invbox);i++}}}}
function wfu_consent_question_operations_reassign(){var policy=wfu_get_consent_policy();if(policy){for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)){wfu_PD_bank.conops[opid].qindex=[];wfu_PD_bank.conops[opid].itemindex=[];wfu_PD_bank.conops[opid].inverse=[];wfu_PD_bank.conops[opid].unassigned=true;wfu_PD_bank.conops[opid].nonevisible=true}for(var i=0;i<policy.questions.length;i++){var question=policy.questions[i];for(var j=0;j<question.items.length;j++){var qitem=question.items[j];
for(var opid in qitem.operations)if(qitem.operations.hasOwnProperty(opid))if(typeof wfu_PD_bank.conops[opid]!="undefined")if(wfu_PD_bank.params.multi_op_assignments||wfu_PD_bank.conops[opid].qindex.length==0){wfu_PD_bank.conops[opid].qindex.push(i+1);wfu_PD_bank.conops[opid].itemindex.push(j+1);wfu_PD_bank.conops[opid].inverse.push(qitem.operations[opid]==-1);wfu_PD_bank.conops[opid].unassigned=false}else delete qitem.operations[opid]}}for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)){var j=
0;while(j<wfu_PD_bank.conops[opid].qindex.length){var qindex=wfu_PD_bank.conops[opid].qindex[j];var itemindex=wfu_PD_bank.conops[opid].itemindex[j];var remove=false;if(qindex<1||qindex>policy.questions.length)remove=true;else{var question=policy.questions[qindex-1];var qnum=question.x*question.y;if(itemindex<1||itemindex>qnum)remove=true}if(remove){wfu_PD_bank.conops[opid].qindex.splice(j,1);wfu_PD_bank.conops[opid].itemindex.splice(j,1);wfu_PD_bank.conops[opid].inverse.splice(j,1)}else{var qitem=
policy.questions[qindex-1].items[itemindex-1];if(typeof qitem.visible=="undefined"||qitem.visible)wfu_PD_bank.conops[opid].nonevisible=false;j++}}if(wfu_PD_bank.conops[opid].nonevisible){wfu_PD_bank.conops[opid].unassigned=wfu_PD_bank.conops[opid].qindex.length==0;wfu_PD_bank.conops[opid].qindex.splice(0,0,1);wfu_PD_bank.conops[opid].itemindex.splice(0,0,1);wfu_PD_bank.conops[opid].inverse.splice(0,0,false)}}wfu_set_consent_policy(policy);wfu_update_consent_question_item_assignments()}}
function wfu_update_consent_question_item_assignments(){var containers=document.querySelectorAll("#wfu_conquestions_container .wfu_conquestion_itemcontainer");for(var i=0;i<containers.length;i++)containers[i].classList.remove("wfu_item_assigned");for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)&&wfu_PD_bank.conops[opid].active)for(var j=0;j<wfu_PD_bank.conops[opid].qindex.length;j++){var qindex=wfu_PD_bank.conops[opid].qindex[j];var itemindex=wfu_PD_bank.conops[opid].itemindex[j];
var itemtable=document.querySelector("#wfu_conquestion_container_"+qindex+" .wfu_conquestion_itemtable");var x=itemtable.rows[0].cells.length;var rowindex=Math.floor((itemindex-1)/x);var cellindex=(itemindex-1)%x;itemtable.rows[rowindex].cells[cellindex].classList.add("wfu_item_assigned")}}
function wfu_conquestion_conop_bankpos(opid,index,itemindex){var pos=-1;for(var i=0;i<wfu_PD_bank.conops[opid].qindex.length;i++)if(wfu_PD_bank.conops[opid].qindex[i]==index&&wfu_PD_bank.conops[opid].itemindex[i]==itemindex){pos=i;break}return pos}
function wfu_consent_question_optable_update(index,itemindex){var freeze=index<1||itemindex<1;for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)&&wfu_PD_bank.conops[opid].active){var oprow=document.getElementById("wfu_conquestions_oprow_"+opid);var selbox=document.querySelector("#wfu_conquestions_oprow_"+opid+" .wfu_conquestions_opsel");var invbox=document.querySelector("#wfu_conquestions_oprow_"+opid+" .wfu_conquestions_opinv");if(wfu_PD_bank.conops[opid].unassigned||wfu_PD_bank.conops[opid].nonevisible)oprow.classList.add("wfu_op_unassigned");
else oprow.classList.remove("wfu_op_unassigned");var pos=wfu_conquestion_conop_bankpos(opid,index,itemindex);selbox.checked=!freeze&&pos>-1;if(!freeze&&pos>-1&&(wfu_PD_bank.conops[opid].unassigned||wfu_PD_bank.conops[opid].nonevisible)&&index==1&&itemindex==1)selbox.classList.add("wfu_forced_selection");else selbox.classList.remove("wfu_forced_selection");invbox.checked=!freeze&&pos>-1&&wfu_PD_bank.conops[opid].inverse[pos];invbox.disabled=!(!freeze&&pos>-1);if(freeze){selbox.classList.add("wfu_frozen");
invbox.classList.add("wfu_frozen")}else{selbox.classList.remove("wfu_frozen");invbox.classList.remove("wfu_frozen")}}}
function wfu_conquestion_optable_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;var itemcontainer=document.querySelector("#wfu_conquestions_container .wfu_conquestion_itemcontainer.wfu_item_selected");if(!itemcontainer)return;var par=itemcontainer;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var index=parseInt(par.id.replace("wfu_conquestion_container_",""));var itemcontainers=document.querySelectorAll("#wfu_conquestion_container_"+
index+" .wfu_conquestion_itemcontainer");var itemindex=-1;for(var j=0;j<itemcontainers.length;j++)if(itemcontainers[j]==itemcontainer){itemindex=j+1;break}var policy=wfu_get_consent_policy();if(!policy)return;if(!item.classList.contains("wfu_conquestions_opsel")&&!item.classList.contains("wfu_conquestions_opinv"))return;var opid=parseInt(item.parentNode.parentNode.id.replace("wfu_conquestions_oprow_",""));var opas=wfu_PD_bank.conops[opid];var pos=wfu_conquestion_conop_bankpos(opid,index,itemindex);
if(pos<0||opas.unassigned){if(!wfu_PD_bank.params.multi_op_assignments||opas.unassigned){var question=policy.questions[opas.qindex[0]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[0]){if(typeof question.items[j].operations[opid]!="undefined")delete question.items[j].operations[opid];break}opas.qindex.splice(0,1);opas.itemindex.splice(0,1);opas.inverse.splice(0,1)}opas.qindex.push(index);opas.itemindex.push(itemindex);opas.inverse.push(document.querySelector("#wfu_conquestions_oprow_"+
opid+" .wfu_conquestions_opinv").checked);opas.unassigned=false;pos=opas.qindex.length-1;var question=policy.questions[opas.qindex[pos]-1];var qitem=null;var qindex=question.items.length;for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[pos]){qitem=question.items[j];qitem.operations[opid]=opas.inverse[pos]?-1:1;break}else if(question.items[j].index>itemindex){qindex=j;break}if(!qitem){qitem={index:opas.itemindex[pos],label:"",location:"right",preselect:false,operations:{}};
qitem.operations[opid]=opas.inverse[pos]?-1:1;question.items.splice(qindex,0,qitem)}wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(index,itemindex);wfu_update_consent_question_item_assignments();wfu_allops_freeze_events=false}else if(item.classList.contains("wfu_conquestions_opsel")&&pos>=0){var question=policy.questions[opas.qindex[pos]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==
opas.itemindex[pos]){if(typeof question.items[j].operations[opid]!="undefined")delete question.items[j].operations[opid];break}opas.qindex.splice(pos,1);opas.itemindex.splice(pos,1);opas.inverse.splice(pos,1);wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;item.checked=false;wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(index,itemindex);wfu_update_consent_question_item_assignments();wfu_allops_freeze_events=false}else if(item.classList.contains("wfu_conquestions_opinv")){opas.inverse[pos]=
item.checked;var question=policy.questions[opas.qindex[pos]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[pos]){question.items[j].operations[opid]=opas.inverse[pos]?-1:1;break}wfu_set_consent_policy(policy)}}
function wfu_conquestion_tools_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;var qcount=document.querySelectorAll(".wfu_conquestion_container").length;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var index=parseInt(par.id.replace("wfu_conquestion_container_",""))-1;wfu_allops_freeze_events=true;var action="";if(item.classList.contains("wfu_conquestion_add"))action="add";else if(item.classList.contains("wfu_conquestion_remove")&&
qcount>1)action="remove";else if(item.classList.contains("wfu_conquestion_up")&&index>0)action="up";else if(item.classList.contains("wfu_conquestion_down")&&index<qcount-1)action="down";if(action!=""){wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_action(action,index);wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_update_conquestion_header()}wfu_allops_freeze_events=false}
function wfu_update_conquestion_header(){var labels=document.querySelectorAll(".wfu_conquestion_headerlabel");var add_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_add");var remove_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_remove");var up_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_up");var down_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_down");
for(var i=0;i<labels.length;i++){labels[i].innerHTML="Question "+(i+1);if(labels.length>1)remove_btns[i].classList.remove("wfu_tool_disabled");else remove_btns[i].classList.add("wfu_tool_disabled");if(i>0)up_btns[i].classList.remove("wfu_tool_disabled");else up_btns[i].classList.add("wfu_tool_disabled");if(i<labels.length-1)down_btns[i].classList.remove("wfu_tool_disabled");else down_btns[i].classList.add("wfu_tool_disabled")}}
function wfu_permissions_update(updatehtml){function _wfu_nested_perms_update(item,level){var id=item.ID;if(item.children.length>0){policy.permissions[id].allowedstatus={};for(var j=0;j<item.children.length;j++){_wfu_nested_perms_update(item.children[j],level+1);var id2=item.children[j].ID;for(var locid in policy.permissions[id2].allowedstatus)if(policy.permissions[id2].allowedstatus.hasOwnProperty(locid)){var allowedstatus2=policy.permissions[id2].allowedstatus[locid];if(typeof policy.permissions[id].allowedstatus[locid]==
"undefined")policy.permissions[id].allowedstatus[locid]=allowedstatus2;else if(policy.permissions[id].allowedstatus[locid]*allowedstatus2<1)policy.permissions[id].allowedstatus[locid]=0}}}else{var allowed=policy.permissions[id].Allowed;policy.permissions[id].allowedstatus={};for(var k=0;k<policy.permissions[id].Locations.length;k++){var locid=policy.permissions[id].Locations[k];policy.permissions[id].allowedstatus[locid]=allowed.indexOf(locid)>-1?1:-1}}if(typeof wfu_PD_bank.perallowedstatus=="undefined")wfu_PD_bank.perallowedstatus=
{};wfu_PD_bank.perallowedstatus[id]=policy.permissions[id].allowedstatus;if(updatehtml){var row=document.getElementById("wfu_perm_row_"+id);for(var locid in policy.permissions[id].allowedstatus)if(policy.permissions[id].allowedstatus.hasOwnProperty(locid)){var check=document.querySelector("#wfu_perm_row_"+id+" .wfu_location_cell:nth-child("+(parseInt(locid)+1)+") input");wfu_set_checkbox_status(check,policy.permissions[id].allowedstatus[locid])}}}var policy=wfu_get_permissions_policy();if(policy){console.log(policy);
wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_perms_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
function wfu_adjust_permissions_levels(){function _wfu_force_permission_update_nested(item,locid){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_permission_update_nested(item.children[j],locid);else if(policy.permissions[id].Allowed.indexOf(locid)==-1&&policy.permissions[id].Locations.indexOf(locid)>-1)policy.permissions[id].Allowed.push(locid)}function _wfu_nested_adjust_permissions_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_permissions_levels(item.children[j],
level+1);var id=item.ID;for(var locid in wfu_PD_bank.perallowedstatus[id])if(wfu_PD_bank.perallowedstatus[id].hasOwnProperty(locid))if(wfu_PD_bank.perallowedstatus[id][locid]==0&&level==wfu_PD_bank.params.perlevels){_wfu_force_permission_update_nested(item,parseInt(locid));wfu_PD_bank.perallowedstatus[id][locid]=1;policy_needs_update=true}}wfu_permissions_update(false);var policy=wfu_get_permissions_policy();if(policy){var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_permissions_levels(policy.structure[i],
1);if(policy_needs_update)wfu_set_permissions_policy(policy)}}
function wfu_perm_toggle(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_location_selector"))return;var id=obj.parentNode.parentNode.id.replace("wfu_perm_row_","");var locid=obj.parentNode.cellIndex;var policy=wfu_get_permissions_policy();if(policy){if(typeof policy.permissions[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");
if(policy.children_index[id].length>0){var level=1;var parid=id;while((parid=policy.permissions[parid].Parent)>0)level++;if((wfu_PD_bank.params.perlevels<1||level<wfu_PD_bank.params.perlevels)&&!confirm("This will make all children permissions "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==
0){var locindex2=policy.permissions[id2].Allowed.indexOf(locid);if(new_status&&locindex2==-1&&policy.permissions[id2].Locations.indexOf(locid)>-1)policy.permissions[id2].Allowed.push(locid);else if(!new_status&&locindex2>-1)policy.permissions[id2].Allowed.splice(locindex2,1)}}}else{var locindex=policy.permissions[id].Allowed.indexOf(locid);if(new_status&&locindex==-1&&policy.permissions[id].Locations.indexOf(locid)>-1)policy.permissions[id].Allowed.push(locid);else if(!new_status&&locindex>-1)policy.permissions[id].Allowed.splice(locindex,
1)}wfu_set_permissions_policy(policy);wfu_allops_freeze_events=true;wfu_permissions_update(true);wfu_allops_freeze_events=false}}
function wfu_perm_button_action(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_perm_button"))return;var policy=wfu_get_permissions_policy();if(policy){var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_perm_row"));var id=parseInt(par.id.replace("wfu_perm_row_",""));obj.classList.toggle("expanded");for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];var parid=id2;var visible=true;while((parid=policy.permissions[parid].Parent)>
0)visible=visible&&document.querySelector("#wfu_perm_row_"+parid+" .wfu_perm_button")&&document.querySelector("#wfu_perm_row_"+parid+" .wfu_perm_button").classList.contains("expanded");document.getElementById("wfu_perm_row_"+id2).style.display=visible?"table-row":"none"}}}
function wfu_logactions_update(updatehtml){function _wfu_nested_logactions_update(item,level){var id=item.ID;if(item.children.length>0){policy.logactions[id].allowedstatus={};for(var j=0;j<item.children.length;j++){_wfu_nested_logactions_update(item.children[j],level+1);var id2=item.children[j].ID;for(var entid in policy.logactions[id2].allowedstatus)if(policy.logactions[id2].allowedstatus.hasOwnProperty(entid)){var allowedstatus2=policy.logactions[id2].allowedstatus[entid];if(typeof policy.logactions[id].allowedstatus[entid]==
"undefined")policy.logactions[id].allowedstatus[entid]=allowedstatus2;else if(policy.logactions[id].allowedstatus[entid]*allowedstatus2<1)policy.logactions[id].allowedstatus[entid]=0}}}else{var allowed=policy.logactions[id].Allowed;policy.logactions[id].allowedstatus={};for(var k=0;k<policy.logactions[id].Entities.length;k++){var entid=policy.logactions[id].Entities[k];policy.logactions[id].allowedstatus[entid]=allowed.indexOf(entid)>-1?1:-1}}if(typeof wfu_PD_bank.logallowedstatus=="undefined")wfu_PD_bank.logallowedstatus=
{};wfu_PD_bank.logallowedstatus[id]=policy.logactions[id].allowedstatus;if(updatehtml){var row=document.getElementById("wfu_log_row_"+id);for(var entid in policy.logactions[id].allowedstatus)if(policy.logactions[id].allowedstatus.hasOwnProperty(entid)){var check=document.querySelector("#wfu_log_row_"+id+" .wfu_entity_cell:nth-child("+(parseInt(entid)+1)+") input");wfu_set_checkbox_status(check,policy.logactions[id].allowedstatus[entid])}}}var policy=wfu_get_logactions_policy();if(policy){console.log(policy);
wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_logactions_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
function wfu_adjust_logactions_levels(){function _wfu_force_logaction_update_nested(item,entid){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_logaction_update_nested(item.children[j],entid);else if(policy.logactions[id].Allowed.indexOf(entid)==-1&&policy.logactions[id].Entities.indexOf(entid)>-1)policy.logactions[id].Allowed.push(entid)}function _wfu_nested_adjust_logactions_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_logactions_levels(item.children[j],
level+1);var id=item.ID;for(var entid in wfu_PD_bank.logallowedstatus[id])if(wfu_PD_bank.logallowedstatus[id].hasOwnProperty(entid))if(wfu_PD_bank.logallowedstatus[id][entid]==0&&level==wfu_PD_bank.params.loglevels){_wfu_force_logaction_update_nested(item,parseInt(entid));wfu_PD_bank.logallowedstatus[id][entid]=1;policy_needs_update=true}}wfu_logactions_update(false);var policy=wfu_get_logactions_policy();if(policy){var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_logactions_levels(policy.structure[i],
1);if(policy_needs_update)wfu_set_logactions_policy(policy)}}
function wfu_log_toggle(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_entity_selector"))return;var id=obj.parentNode.parentNode.id.replace("wfu_log_row_","");var entid=obj.parentNode.cellIndex;var policy=wfu_get_logactions_policy();if(policy){if(typeof policy.logactions[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");
if(policy.children_index[id].length>0){var level=1;var parid=id;while((parid=policy.logactions[parid].Parent)>0)level++;if((wfu_PD_bank.params.loglevels<1||level<wfu_PD_bank.params.loglevels)&&!confirm("This will make all children log actions "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==
0){var entindex2=policy.logactions[id2].Allowed.indexOf(entid);if(new_status&&entindex2==-1&&policy.logactions[id2].Entities.indexOf(entid)>-1)policy.logactions[id2].Allowed.push(entid);else if(!new_status&&entindex2>-1)policy.logactions[id2].Allowed.splice(entindex2,1)}}}else{var entindex=policy.logactions[id].Allowed.indexOf(entid);if(new_status&&entindex==-1&&policy.logactions[id].Entities.indexOf(entid)>-1)policy.logactions[id].Allowed.push(entid);else if(!new_status&&entindex>-1)policy.logactions[id].Allowed.splice(entindex,
1)}wfu_set_logactions_policy(policy);wfu_allops_freeze_events=true;wfu_logactions_update(true);wfu_allops_freeze_events=false}}
function wfu_log_button_action(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_log_button"))return;var policy=wfu_get_logactions_policy();if(policy){var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_log_row"));var id=parseInt(par.id.replace("wfu_log_row_",""));obj.classList.toggle("expanded");for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];var parid=id2;var visible=true;while((parid=policy.logactions[parid].Parent)>
0)visible=visible&&document.querySelector("#wfu_log_row_"+parid+" .wfu_log_button")&&document.querySelector("#wfu_log_row_"+parid+" .wfu_log_button").classList.contains("expanded");document.getElementById("wfu_log_row_"+id2).style.display=visible?"table-row":"none"}}}
function wfu_pdusers_addrole_handler(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_pdusers_roles_add"))return;var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_roles_container"));var type=par.id.replace(/^wfu_pdusers_roles_(in|out)_container$/,"$1");var roles=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_list");var names=[];for(var i=0;i<roles.options.length;i++)if(roles.options[i].selected)names.push(roles.options[i].value);
wfu_allops_freeze_events=true;wfu_pdusers_add_roles(type,names);wfu_allops_freeze_events=false}
function wfu_pdusers_add_roles(type,names){var show=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_show");var roles=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_list");var selected=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel .wfu_pdusers_roles_role");var source=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]').checked?"in":"out";var btype=type=="in"?
"included":"excluded";var count=selected.length;for(var i=0;i<names.length;i++){var title="";if(names[i]=="all")title="All";else for(var j=0;j<roles.options.length;j++)if(roles.options[j].value==names[i]){title=roles.options[j].innerHTML;break}if(title!=""){var already_in=false;for(var j=0;j<selected.length;j++)if(selected[j].roleName==names[i]){already_in=true;break}if(!already_in){var pos=wfu_PD_bank.pdusers.rolestates[source][btype].indexOf(names[i]);if(pos==-1)wfu_PD_bank.pdusers.rolestates[source][btype].push(names[i]);
if(count>0)show.appendChild(document.createElement("BR"));var role=document.createElement("DIV");role.classList.add("wfu_pdusers_roles_role");role.roleName=names[i];role.innerHTML=title;if(names[i]=="all")role.classList.add("wfu_pdusers_roles_all");else{var delbtn=document.createElement("SPAN");wfu_addEventHandler(delbtn,"click",wfu_pdusers_removerole_handler);role.appendChild(delbtn)}show.appendChild(role);count++}}}}
function wfu_pdusers_clear_roles(type){var show=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_show");var selected=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel .wfu_pdusers_roles_role");var brs=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel br");for(var i=0;i<selected.length;i++)show.removeChild(selected[i]);for(var i=0;i<brs.length;i++)show.removeChild(brs[i])}
function wfu_pdusers_removerole_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_roles_role"))return;var role=item.parentNode.roleName;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_roles_container"));var type=par.id.replace(/^wfu_pdusers_roles_(in|out)_container$/,"$1");var source=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]').checked?"in":"out";var btype=
type=="in"?"included":"excluded";var pos=wfu_PD_bank.pdusers.rolestates[source][btype].indexOf(role);if(pos>-1)wfu_PD_bank.pdusers.rolestates[source][btype].splice(pos,1);var br1=item.parentNode.previousSibling;var br2=item.parentNode.nextSibling;var show=document.querySelector("#"+par.id+" .wfu_pdusers_roles_show");wfu_allops_freeze_events=true;show.removeChild(item.parentNode);if(br1&&br1.tagName&&br1.tagName=="BR")show.removeChild(br1);else if(br2&&br2.tagName&&br2.tagName=="BR")show.removeChild(br2);
wfu_allops_freeze_events=false}
function wfu_pdusers_update(){var pd_users=wfu_get_pd_users();if(pd_users){console.log(pd_users);wfu_PD_bank.pdusers={rolestates:{"in":{included:[],excluded:[]},out:{included:["all"],excluded:[]}}};var userin_input=document.querySelector('#wfu_pdusers_users_in_container .wfu_pdusers_users_leftpanel input[type="text"]');wfu_attach_element_handlers(userin_input,wfu_pdusers_get_users);var userout_input=document.querySelector('#wfu_pdusers_users_out_container .wfu_pdusers_users_leftpanel input[type="text"]');wfu_attach_element_handlers(userout_input,
wfu_pdusers_get_users);wfu_PD_bank.pdusers.userinput={"in":{prev_value:""},out:{prev_value:""},xhr:null};var radioin=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]');var rolein_list=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_list");var rolein_back=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_back");var radioout=document.querySelector('#wfu_pdusers_roles_out_container input[type="radio"]');var roleout_list=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_list");
var roleout_back=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_back");if(pd_users.roles_included.length>0&&pd_users.roles_included[0]!="all"||pd_users.roles_excluded.length==1&&pd_users.roles_excluded[0]=="all"||pd_users.roles_included.length==0&&pd_users.roles_excluded.length==0){wfu_PD_bank.pdusers.rolestates["in"].included=pd_users.roles_included;rolein_list.disabled=false;rolein_back.classList.add("active");roleout_list.disabled=true;roleout_back.classList.remove("active");
radioin.checked=true;wfu_pdusers_add_roles("in",pd_users.roles_included);wfu_pdusers_add_roles("out",[])}else{wfu_PD_bank.pdusers.rolestates.out.excluded=pd_users.roles_excluded;rolein_list.disabled=true;rolein_back.classList.remove("active");roleout_list.disabled=false;roleout_back.classList.add("active");radioout.checked=true;wfu_pdusers_add_roles("in",["all"]);wfu_pdusers_add_roles("out",pd_users.roles_excluded)}}}
function wfu_pdusers_roletype_handler(obj){if(wfu_allops_freeze_events)return;if(obj.name!="wfu_pdusers_roletypes")return;var radioin=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]');var rolein_list=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_list");var rolein_back=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_back");var radioout=document.querySelector('#wfu_pdusers_roles_out_container input[type="radio"]');var roleout_list=
document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_list");var roleout_back=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_back");wfu_allops_freeze_events=true;wfu_pdusers_clear_roles("in");wfu_pdusers_clear_roles("out");if(obj.value=="include"){rolein_list.disabled=false;rolein_back.classList.add("active");roleout_list.disabled=true;roleout_back.classList.remove("active");radioin.checked=true;wfu_pdusers_add_roles("in",wfu_PD_bank.pdusers.rolestates["in"].included);
wfu_pdusers_add_roles("out",wfu_PD_bank.pdusers.rolestates["in"].excluded)}else{rolein_list.disabled=true;rolein_back.classList.remove("active");roleout_list.disabled=false;roleout_back.classList.add("active");radioout.checked=true;wfu_pdusers_add_roles("in",wfu_PD_bank.pdusers.rolestates.out.included);wfu_pdusers_add_roles("out",wfu_PD_bank.pdusers.rolestates.out.excluded)}wfu_allops_freeze_events=false}
function wfu_pdusers_adduser_handler(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_pdusers_users_add"))return;var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");var users=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");var names=[];for(var i=0;i<users.options.length;i++)if(users.options[i].selected)names.push(users.options[i].value);
wfu_allops_freeze_events=true;wfu_pdusers_add_users(type,names);wfu_allops_freeze_events=false}
function wfu_pdusers_add_users(type,names){var show=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_show");var users=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");var selected=document.querySelectorAll("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_rightpanel .wfu_pdusers_users_user");var otherselected=document.querySelectorAll("#wfu_pdusers_users_"+(type=="in"?"out":"in")+"_container .wfu_pdusers_users_rightpanel .wfu_pdusers_users_user");
var count=selected.length;for(var i=0;i<names.length;i++){var title="";for(var j=0;j<users.options.length;j++)if(users.options[j].value==names[i]){title=users.options[j].innerHTML;break}if(title!=""){var already_in=false;for(var j=0;j<selected.length;j++)if(selected[j].userName==names[i]){already_in=true;break}if(!already_in){if(count>0)show.appendChild(document.createElement("BR"));for(var j=0;j<otherselected.length;j++)if(otherselected[j].userName==names[i]){var prev_wfu_allops_freeze_events=wfu_allops_freeze_events;
wfu_allops_freeze_events=false;wfu_pdusers_removeuser_handler({target:otherselected[j].children[0]});wfu_allops_freeze_events=prev_wfu_allops_freeze_events;break}var user=document.createElement("DIV");user.classList.add("wfu_pdusers_users_user");user.userName=names[i];user.innerHTML=title;var delbtn=document.createElement("SPAN");wfu_addEventHandler(delbtn,"click",wfu_pdusers_removeuser_handler);user.appendChild(delbtn);show.appendChild(user);count++}}}}
function wfu_pdusers_removeuser_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_users_user"))return;var user=item.parentNode.userName;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");var br1=item.parentNode.previousSibling;var br2=item.parentNode.nextSibling;var show=document.querySelector("#"+
par.id+" .wfu_pdusers_users_show");wfu_allops_freeze_events=true;show.removeChild(item.parentNode);if(br1&&br1.tagName&&br1.tagName=="BR")show.removeChild(br1);else if(br2&&br2.tagName&&br2.tagName=="BR")show.removeChild(br2);wfu_allops_freeze_events=false}
function wfu_pdusers_get_users(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_users_leftpanel"))return;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");if(item.value==wfu_PD_bank.pdusers.userinput[type].prev_value)return;wfu_PD_bank.pdusers.userinput[type].prev_value=item.value;if(wfu_PD_bank.pdusers.xhr!=
null){wfu_PD_bank.pdusers.xhr.abort();wfu_PD_bank.pdusers.xhr=null}var userlist=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");if(item.value==""){var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;return}var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_pdusers_get_users";params[1]=new Array(2);params[1][0]=
"nonce";params[1][1]=document.getElementById("_wpnonce").value;params[2]=new Array(2);params[2][0]="query";params[2][1]=item.value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="pdusers_get_users:";var pos=xhr.responseText.indexOf(start_text);
if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);var users_str=wfu_plugin_decode_string(response);var users=null;try{users=JSON.parse(users_str)}catch(e$2){}var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[i]=null;for(i=0;i<users.length;i++){var opt=document.createElement("OPTION");opt.value=users[i].user_login;opt.innerHTML=users[i].display_name+
" ("+users[i].user_login+")";userlist.options.add(opt)}}};wfu_PD_bank.pdusers.xhr=xhr;xhr.send(parameters)}function wfu_initialize_consent_policy_basic(){wfu_PD_bank.userinput={prev_value:"",xhr:null,prev_select:-1};wfu_attach_element_handlers(document.getElementById("wfu_pd_user_box0"),wfu_pd_get_users_basic)}
function wfu_pd_get_users_basic(e){e=e||window.event;var item=e.target;if(!item.classList.contains("wfu_pd_user_box0"))return;if(item.value==wfu_PD_bank.userinput)return;var userlist=document.getElementById("wfu_pd_user_select0");wfu_PD_bank.userinput=item.value;if(wfu_PD_bank.userinput.xhr!=null){wfu_PD_bank.userinput.xhr.abort();wfu_PD_bank.userinput.xhr=null}if(item.value==""){var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;return}var xhr=wfu_GetHttpRequestObject();
if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_pdusers_get_users";params[1]=new Array(2);params[1][0]="nonce";params[1][1]=document.getElementById("_wpnonce").value;params[2]=new Array(2);params[2][0]="query";params[2][1]=item.value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="pdusers_get_users:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);var users_str=wfu_plugin_decode_string(response);var users=null;try{users=JSON.parse(users_str)}catch(e$3){}var length=
userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;for(i=0;i<users.length;i++){var opt=document.createElement("OPTION");opt.value=users[i].user_login;opt.innerHTML=users[i].display_name+" ("+users[i].user_login+")";userlist.options.add(opt)}}};wfu_PD_bank.userinput.xhr=xhr;xhr.send(parameters)}
function wfu_export_user_data(){var userlist=document.getElementById("wfu_pd_user_select0");if(userlist.selectedIndex<0){alert("No user has been selected!");return}var params={username:userlist.options[userlist.selectedIndex].value};var params_str=JSON.stringify(params);wfu_download_file("exportdata:"+params_str,1)}
function wfu_erase_user_data_check(){var userlist=document.getElementById("wfu_pd_user_select0");var anchor=document.getElementById("wfu_erase_userdata0");if(userlist.selectedIndex<0){alert("No user has been selected!");return false}else{anchor.href=anchor.href.replace(/action=erase_userdata_ask.*$/,"action=erase_userdata_ask&username="+userlist.options[userlist.selectedIndex].value);return true}}
function wfu_pd_pre_save_actions(){var wfu_PD_bank_str=JSON.stringify(wfu_PD_bank);document.getElementById("wfu_PD_bank").value=wfu_plugin_encode_string(wfu_PD_bank_str)};
