function tdialog_start(id,callback){$.fn.modal.Constructor.prototype.enforceFocus=function(){};$(id).modal({backdrop:true,keyboard:true});if(typeof callback!="undefined"){$(id).on("hidden.bs.modal",function(){callback();tdialog_close(id.substring(1))})}else{$(id).on("hidden.bs.modal",function(){tdialog_close(id.substring(1))})}}function tdialog_close(id){$(".modal-backdrop").last().remove();$("#"+id).modal("hide");$("body").removeClass("modal-open");setTimeout(function(){$("#"+id).remove()},300)}function tjquerydialog_start(id,modal,draggable,resizable,width,height,top,left,zIndex,actions){$(id).dialog({modal:modal,stack:false,zIndex:2e3,draggable:draggable,resizable:resizable,height:height,width:width,close:function(ev,ui){$(this).remove()},buttons:actions});$(id).closest(".ui-dialog").css({zIndex:zIndex});$(".ui-widget-overlay").css({zIndex:100});if(top>0){$(id).closest(".ui-dialog").css({top:top+"px"})}if(left>0){$(id).closest(".ui-dialog").css({left:left+"px"})}}function tform_send_data(form_name,field,value,fire_events){try{var single_field=$("form[name="+form_name+"] [name='"+field+"']");var array_field=$("form[name="+form_name+"] [name='"+field+"[]']");if(single_field.length||array_field.length){if(typeof Adianti.formEventsCounter=="undefined"){Adianti.formEventsCounter=0}if(Adianti.formEventsCounter==0){if(single_field.length){if(single_field.attr("widget")=="thtmleditor"){single_field.summernote("code",value)}else if(single_field.attr("role")=="tcombosearch"){single_field.select2().val(value).trigger("change")}else if(single_field.attr("component")=="multisearch"){if(value){single_field.select2().val(value).trigger("change")}}else if(single_field.attr("type")=="radio"){if(value){var radio_input=single_field.filter("[value="+value+"]").prop("checked",true);if(radio_input.parent().prop("tagName")=="LABEL"){radio_input.parent().parent().find("label").removeClass("active");radio_input.parent().toggleClass("active")}}}else{single_field.val(value)}if(fire_events){if(single_field.attr("exitaction")){tform_events_hang_exec(single_field.attr("exitaction"))}if(single_field.attr("changeaction")){tform_events_hang_exec(single_field.attr("changeaction"))}}}else if(array_field.length){if(array_field.attr("type")=="checkbox"){array_field.prop("checked",false);if(value){array_field.parent().parent().find("label").removeClass("active");var checkeds=value.split(",");$.each(checkeds,function(key,checkvalue){var check_input=array_field.filter("[value="+checkvalue+"]").prop("checked",true);if(check_input.parent().prop("tagName")=="LABEL"){check_input.parent().toggleClass("active")}})}}else if(array_field.attr("component")=="multientry"){if(value){array_field.empty();var values=value.split(",");$.each(values,function(key,value){array_field.append($("<option/>").val(value).text(value))});array_field.val(values).trigger("change")}}else if(array_field.attr("component")=="multisearch"){if(value){var values=value.split(",");array_field.select2().val(values).trigger("change")}}else if(array_field.length){if(value){var checkeds=value.split(",");$(array_field).find("option").prop("selected",false);$.each(checkeds,function(key,checkvalue){$(array_field).find("option").filter("[value="+checkvalue+"]").prop("selected",true)})}}if(fire_events){if(array_field.attr("exitaction")){tform_events_hang_exec(array_field.attr("exitaction"))}if(array_field.attr("changeaction")){tform_events_hang_exec(array_field.attr("changeaction"))}}}}else{tform_events_queue_push(function(){tform_send_data(form_name,field,value,fire_events)})}}}catch(e){console.log(e)}}function tform_send_data_by_id(form_name,field,value,fire_events){try{if($("form[name="+form_name+"] [id="+field+"]").length){if(typeof Adianti.formEventsCounter=="undefined"){Adianti.formEventsCounter=0}if(Adianti.formEventsCounter==0){$("form[name="+form_name+"] [id="+field+"]").val(value);if(fire_events){if($("form[name="+form_name+"] [id="+field+"]").attr("exitaction")){tform_events_hang_exec($("form[name="+form_name+"] [id="+field+"]").attr("exitaction"))}if($("form[name="+form_name+"] [id="+field+"]").attr("changeaction")){tform_events_hang_exec($("form[name="+form_name+"] [id="+field+"]").attr("changeaction"))}}}else{tform_events_queue_push(function(){tform_send_data_by_id(form_name,field,value,fire_events)})}}}catch(e){console.log(e)}}function tform_events_hang_exec(string_callback){Adianti.formEventsCounter++;string_callback=string_callback.replace("'callback'","tform_decrease_events_counter");Function(string_callback)()}function tform_events_queue_push(callback){if(typeof Adianti.formEventsQueue=="undefined"){Adianti.formEventsQueue=new Array}Adianti.formEventsQueue.push(callback);setTimeout(tform_process_events_queue,100)}function tform_process_events_queue(){if(Adianti.formEventsCounter==0&&Adianti.formEventsQueue.length>0){next=Adianti.formEventsQueue.shift();next()}if(Adianti.formEventsQueue.length>0){setTimeout(tform_process_events_queue,100)}}function tform_decrease_events_counter(){Adianti.formEventsCounter--}function tform_send_data_aggregate(form_name,field,value,fire_events){try{if($("form[name="+form_name+"] [name="+field+"]").val()==""){tform_send_data(form_name,field,value,fire_events)}else{current_value=$("form[name="+form_name+"] [name="+field+"]").val();$("form[name="+form_name+"] [name="+field+"]").val(current_value+", "+value)}}catch(e){console.log(e)}}function tform_fire_field_actions(form_name,field){if($("form[name="+form_name+"] [name="+field+"]").attr("exitaction")){tform_events_hang_exec($("form[name="+form_name+"] [name="+field+"]").attr("exitaction"))}if($("form[name="+form_name+"] [name="+field+"]").attr("changeaction")){tform_events_hang_exec($("form[name="+form_name+"] [name="+field+"]").attr("changeaction"))}}function tform_hide_field(form,field){$("#"+form+' [name="'+field+'"]').closest(".tformrow").hide("fast")}function tform_show_field(form,field){$("#"+form+' [name="'+field+'"]').closest(".tformrow").show("fast")}function ttable_clone_previous_row(element){var table=$(element).closest("table");var last_row=table.find("tbody tr:last");var insert=last_row.clone();ttable_reset_fields(insert,true);table.find("tbody").append(insert);ttable_reset_counter(table)}function ttable_reset_counter(table){var count=0;var rows=$(table).find("tr").each(function(index,row){var fields=$(row).find("input,select");$(row).data("row",count);if(fields.length>0){$.each(fields,function(findex,field){$(field).data("row",count)});count++}})}function ttable_remove_row(element){var table=$(element).closest("table");var rows=table.find("tbody").find("tr:visible").length;tr=$(element).closest("tr");if(rows==1){var insert=tr.clone();ttable_reset_fields(insert,true);tr.after($(insert));tr.remove()}else{tr.remove()}ttable_reset_counter(table)}function ttable_reset_fields(row,clear_fields){var fields=$(row).find("input,select");var uniqid=parseInt(Math.random()*1e8);var newids=[];$.each(fields,function(index,field){var field_id=$(field).attr("id");var field_component=$(field).attr("widget");var field_role=$(field).attr("role");if(typeof field_id!=="undefined"){var field_id_parts=field_id.split("_");field_id_parts.pop();var field_prefix=field_id_parts.join("_");var new_id=field_prefix+"_"+uniqid;var parent=$(field).parent();if(newids.indexOf(new_id)>=0){var new_id=field_prefix+parseInt(Math.random()*100)+"_"+uniqid}newids.push(new_id);if(field_component=="tdate"){$(field).attr("id",new_id);if(clear_fields){$(field).val("")}if(typeof $(field).attr("exitaction")!=="undefined"){$(field).attr("exitaction",$(field).attr("exitaction").replace(field_id,new_id))}if(typeof $(field).attr("onblur")!=="undefined"){$(field).attr("onblur",$(field).attr("onblur").replace(field_id,new_id))}grandparent=$(parent).parent();field=$(field).detach();$(parent).remove();grandparent.append(field);var re=new RegExp(field_id,"g");ttable_execute_scripts(grandparent,"tdate",function(script_content){script_content=script_content.replace(re,new_id);return script_content})}else if(field_component=="tentry"){$(field).attr("id",new_id);if(clear_fields){$(field).val("")}if(typeof $(field).attr("exitaction")!=="undefined"){$(field).attr("exitaction",$(field).attr("exitaction").replace(field_id,new_id))}if(typeof $(field).attr("onblur")!=="undefined"){$(field).attr("onblur",$(field).attr("onblur").replace(field_id,new_id))}var re=new RegExp(field_id,"g");ttable_execute_scripts(parent,"tentry",function(script_content){script_content=script_content.replace(re,new_id);return script_content})}else if(field_component=="tcolor"){$(field).attr("id",new_id);if(clear_fields){$(field).val("")}if(typeof $(field).attr("exitaction")!=="undefined"){$(field).attr("exitaction",$(field).attr("exitaction").replace(field_id,new_id))}if(typeof $(field).attr("onblur")!=="undefined"){$(field).attr("onblur",$(field).attr("onblur").replace(field_id,new_id))}grandparent=$(parent).parent();var re=new RegExp(field_id,"g");ttable_execute_scripts(grandparent,"tcolor",function(script_content){script_content=script_content.replace(re,new_id);return script_content})}else if(field_component=="thidden"){$(field).attr("id",new_id);if(clear_fields){$(field).val("")}var re=new RegExp(field_id,"g");ttable_execute_scripts(parent,"thidden",function(script_content){script_content=script_content.replace(re,new_id);return script_content})}else if(field_component=="tdbmultisearch"||field_component=="tdbuniquesearch"){$(field).attr("id",new_id);$(parent).find(".select2-container").remove();var re=new RegExp(field_id,"g");ttable_execute_scripts(parent,"tdbmultisearch",function(script_content){script_content=script_content.replace(re,new_id);return script_content});if(clear_fields){setTimeout(function(){$(field).val("").trigger("change")},10)}}else if(field_component=="tmultisearch"||field_component=="tuniquesearch"){$(field).attr("id",new_id);$(parent).find(".select2-container").remove();var re=new RegExp(field_id,"g");ttable_execute_scripts(parent,"tmultisearch",function(script_content){script_content=script_content.replace(re,new_id);return script_content});if(clear_fields){setTimeout(function(){$(field).val("").trigger("change")},10)}}else if(field_component=="tcombo"){$(field).attr("id",new_id);if(clear_fields){$(field).val("")}if(field_role=="tcombosearch"){$(parent).find(".select2-container").remove()}if(typeof $(field).attr("changeaction")!=="undefined"){$(field).attr("changeaction",$(field).attr("changeaction").replace(field_id,new_id))}if(typeof $(field).attr("onchange")!=="undefined"){$(field).attr("onchange",$(field).attr("onchange").replace(field_id,new_id))}var re=new RegExp(field_id,"g");ttable_execute_scripts(parent,"tcombo",function(script_content){script_content=script_content.replace(re,new_id);return script_content})}}if(field_component=="tradiobutton"){$(field).parent().removeClass("active")}else if(field_component=="tcheckbutton"){$(field).parent().removeClass("active")}})}function ttable_show_row(table,rowid){$("#"+table).find("tr#"+rowid).show()}function ttable_hide_row(table,rowid){$("#"+table).find("tr#"+rowid).hide()}function ttable_execute_scripts(container,filter,callback){var scripts=$(container).find("script");$.each(scripts,function(sindex,script){var text=$(script).text();text=callback(text);if(text.trim().split("_")[0]==filter){$(script).text(text);setTimeout(function(){new Function(text)()},10)}})}function ttable_sortable_rows(id,handle,callback){$(document).ready(function(){$("#"+id+" tbody").sortable({handle:handle,deactivate:callback})})}function ttable_get_column_values(id,column){return $("#"+id+" tbody").find("tr").find("td:nth-child("+column+")").map(function(){return this.innerText}).get().join(",")}function tdatagrid_inlineedit(querystring){$(function(){$(".inlineediting").editInPlace({callback:function(unused,enteredText){__adianti_load_page($(this).attr("action")+querystring+"&key="+$(this).attr("key")+"&"+$(this).attr("pkey")+"="+$(this).attr("key")+"&field="+$(this).attr("field")+"&value="+encodeURIComponent(enteredText));return enteredText},show_buttons:false,text_size:20,params:column=name})})}function tdatagrid_add_serialized_row(datagrid,row){$("#"+datagrid+" > tbody:last-child").append(row)}function tdatagrid_enable_groups(){$("[id^=tdatagrid_] tr[level]").not("[x=1]").css("cursor","pointer").attr("x","1").click(function(){if(!$(this).data("child-visible")){$(this).data("child-visible",false)}$(this).data("child-visible",!$(this).data("child-visible"));if($(this).data("child-visible")){$(this).siblings('[childof^="'+$(this).attr("level")+'"]').hide("fast")}else{$(this).siblings('[childof^="'+$(this).attr("level")+'"]').show("fast")}})}function tbutton_enable_field(form_name,field){setTimeout(function(){$("button[name="+field+"]").removeAttr("disabled");$("button[name=btn_"+field+"]").removeAttr("disabled")},1)}function tbutton_disable_field(form_name,field){setTimeout(function(){$("button[name="+field+"]").attr("disabled",true);$("button[name=btn_"+field+"]").attr("disabled",true)},1)}function tcheckgroup_enable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [checkgroup="+field+"]").removeAttr("disabled");$("form[name="+form_name+"] [checkgroup="+field+"]").parent().removeAttr("disabled")},1)}function tcheckgroup_disable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [checkgroup="+field+"]").attr("disabled","");$("form[name="+form_name+"] [checkgroup="+field+"]").parent().attr("disabled","")},1)}function tcheckgroup_clear_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [checkgroup="+field+"]").attr("checked",false)},1)}function tcolor_enable_field(form_name,field){try{setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").closest(".color-div").colorpicker("enable");$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield_disabled")},1)}catch(e){console.log(e)}}function tcolor_disable_field(form_name,field){try{setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").closest(".color-div").colorpicker("disable");$("form[name="+form_name+"] [name="+field+"]").addClass("tfield_disabled")},1)}catch(e){console.log(e)}}function tcolor_start(id,size,change_function){var last_tcolor_change_time=0;if(typeof change_function!="undefined"){$("#"+id).closest(".color-div").colorpicker().on("changeColor",function(e){if(e.timeStamp-last_tcolor_change_time>500){change_function(e.color);last_tcolor_change_time=e.timeStamp}});$("#"+id).click(function(){$("#"+id).closest(".color-div").colorpicker("show")})}else{$("#"+id).closest(".color-div").colorpicker()}if(size!=="undefined"){$("#"+id).closest(".color-div").width(size)}$(".colorpicker").css("z-index",1e6)}function ticon_enable_field(form_name,field){try{setTimeout(function(){$("form[name="+form_name+'] div[name="block_'+field+'"]').remove()},1)}catch(e){console.log(e)}}function ticon_disable_field(form_name,field){try{input=$("form[name="+form_name+"] [name="+field+"]").closest(".input-group");setTimeout(function(){$("form[name="+form_name+'] div[name="block_'+field+'"]').remove()},19);setTimeout(function(){input.prepend('<div name="block_'+field+'" style="position:absolute; width:'+input.width()+"px; height:"+input.height()+'px; background: #c0c0c0; opacity:0.5;"></div>')},20)}catch(e){console.log(e)}}function ticon_start(id,func){if(func){$("#"+id).iconpicker().on("iconpickerUpdated",function(e){func($(this).val())})}else{$("#"+id).iconpicker()}}function tcombo_enable_field(form_name,field){if(typeof form_name!="undefined"&&form_name!=""){form_name='form[name="'+form_name+'"] '}else{form_name=""}var selector='[name="'+field+'"]';if(field.indexOf("[")==-1&&$("#"+field).length>0){var selector="#"+field}try{$(form_name+selector).attr("onclick",null);$(form_name+selector).css("pointer-events","auto");$(form_name+selector).removeClass("tcombo_disabled").addClass("tcombo")}catch(e){console.log(e)}}function tcombo_disable_field(form_name,field){if(typeof form_name!="undefined"&&form_name!=""){form_name='form[name="'+form_name+'"] '}else{form_name=""}var selector='[name="'+field+'"]';if(field.indexOf("[")==-1&&$("#"+field).length>0){var selector="#"+field}try{$(form_name+selector).attr("onclick","return false");$(form_name+selector).css("pointer-events","none");$(form_name+selector).removeClass("tcombo").addClass("tcombo_disabled")}catch(e){console.log(e)}}function tcombo_add_option(form_name,field,key,value){if(typeof form_name!="undefined"&&form_name!=""){form_name='form[name="'+form_name+'"] '}else{form_name=""}var selector='select[name="'+field+'"]';if(field.indexOf("[")==-1&&$("#"+field).length>0){var selector="#"+field}var optgroups=$(form_name+selector).find("optgroup");if(optgroups.length>0){$('<option value="'+key+'">'+value+"</option>").appendTo(optgroups.last())}else{$('<option value="'+key+'">'+value+"</option>").appendTo(form_name+selector)}}function tcombo_create_opt_group(form_name,field,label){if(typeof form_name!="undefined"&&form_name!=""){form_name='form[name="'+form_name+'"] '}else{form_name=""}var selector='[name="'+field+'"]';if($("#"+field).length>0){var selector="#"+field}$('<optgroup label="'+label+'"></optgroup>').appendTo(form_name+selector)}function tcombo_clear(form_name,field){if(typeof form_name!="undefined"&&form_name!=""){form_name='form[name="'+form_name+'"] '}else{form_name=""}if($(form_name+'[name="'+field+'"]').attr("role")=="tcombosearch"){if($(form_name+'[name="'+field+'"]').find("option:not(:disabled)").length>0){$(form_name+'[name="'+field+'"]').val("");$(form_name+'[name="'+field+'"]').empty();$(form_name+'[name="'+field+'"]').change()}}else{$(form_name+'[name="'+field+'"]').val(false);$(form_name+'[name="'+field+'"]').html("")}}function tcombo_enable_search(field,placeholder){$(field).select2({allowClear:true,placeholder:placeholder})}function tcombocombined_enable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("disabled",false)}catch(e){}try{$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield_disabled").addClass("tfield")}catch(e){}try{$("form[name="+form_name+"] [name="+field+"]").next().attr("disabled",false)}catch(e){}try{$("form[name="+form_name+"] [name="+field+"]").next().removeClass("tcombo_disabled").addClass("tcombo")}catch(e){}}function tcombocombined_disable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("disabled",true)}catch(e){}try{$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield").addClass("tfield_disabled")}catch(e){}try{$("form[name="+form_name+"] [name="+field+"]").next().attr("disabled",true)}catch(e){}try{$("form[name="+form_name+"] [name="+field+"]").next().removeClass("tcombo").addClass("tcombo_disabled")}catch(e){}}function tcombocombined_clear_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").val("")}catch(e){}try{$("form[name="+form_name+"] [name="+field+"]").next().val("")}catch(e){}}function tdate_enable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("disabled",false);$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield_disabled").addClass("tfield");$("form[name="+form_name+"] [name="+field+"]").css("border-right","0")}catch(e){console.log(e)}setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").next().show()},1)}function tdate_disable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("disabled",true);$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield").addClass("tfield_disabled");$("form[name="+form_name+"] [name="+field+"]").css("border-right","1px solid gray")}catch(e){console.log(e)}setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").next().hide()},1)}function tdate_start(id,mask,language,size,options){$(id).wrap('<div class="tdate-group date">');$(id).after('<span class="btn btn-default tdate-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>');atributes={format:mask,todayBtn:"linked",language:language,calendarWeeks:false,autoclose:true,todayHighlight:true,orientation:"bottom auto"};options=Object.assign(atributes,JSON.parse(options));$(id).closest(".tdate-group").datepicker(options).on("changeDate",function(e){if($(id).attr("exitaction")){new Function($(id).attr("exitaction"))()}}).on("show",function(){$(".datepicker").on("click",function(e){e.stopPropagation()})});if(size!=="undefined"){$(id).closest(".tdate-group").width(size)}}function tdatetime_start(id,mask,language,size,options){$(id).wrap('<div class="tdate-group tdatetimepicker input-append date">');$(id).after('<span class="add-on btn btn-default tdate-group-addon"><i class="fa fa-clock-o icon-th"></i></span>');atributes={autoclose:true,todayBtn:true,todayHighlight:true,format:mask,language:language};options=Object.assign(atributes,JSON.parse(options));$(id).closest(".tdate-group").datetimepicker(options).on("change.dp",function(e){if($(id).attr("exitaction")){new Function($(id).attr("exitaction"))()}}).on("show",function(){$(".datepicker").on("click",function(e){e.stopPropagation()})});if(size!=="undefined"){$(id).closest(".tdate-group").width(size)}}function tdbentry_start(field_name,url,min){$('input[name="'+field_name+'"]').autocomplete({serviceUrl:url,minChars:min})}function tentry_mask(field,event,mask){var value,i,character,returnString,tamCampo,maskLength;value=field.value;if(typeof value=="undefined"){return true}if($(field).attr("forceupper")=="1"){value=value.toUpperCase()}if($(field).attr("forcelower")=="1"){value=value.toLowerCase()}if(document.all){keyCode=event.keyCode}else if(document.layers){keyCode=event.which}else{keyCode=event.which}if(keyCode==8||event.keyCode==9||event.keyCode==13){return true}returnString="";var n=0;if(mask.charAt(1)=="!"){maskLength=field.value.length+1}else{maskLength=mask.length}for(i=0;i<maskLength-1;i++){maskChar=mask.charAt(i);valueChar=value.charAt(n);if(i<=value.length){if((maskChar=="-"||maskChar=="_"||maskChar=="."||maskChar=="/"||maskChar=="\\"||maskChar==":"||maskChar=="|"||maskChar=="("||maskChar==")"||maskChar=="["||maskChar=="]"||maskChar=="{"||maskChar=="}")&maskChar!==valueChar){returnString+=maskChar}else{returnString+=valueChar;n++}}}field.value=returnString;tamCampo=field.value.length;if(mask.charAt(1)=="!"){maskChar=mask.charAt(0)}else{maskChar=mask.charAt(tamCampo)}switch(maskChar){case"A":case"a":return keyCode>47&&keyCode<58||keyCode>64&&keyCode<91||keyCode>96&&keyCode<123;break;case"S":case"s":return keyCode>64&&keyCode<91||keyCode>96&&keyCode<123;break;case"9":return keyCode>47&&keyCode<58;break}return true}function tentry_upper(field){if(typeof field.value!=="undefined"){field.value=field.value.toUpperCase()}}function tentry_lower(field){if(typeof field.value!=="undefined"){field.value=field.value.toLowerCase()}}function tentry_autocomplete(field,options){var selecteds;var selector='input[name="'+field+'"]';if($("#"+field).length>0){var selector="#"+field}$(selector).autocomplete({lookup:options,onSelect:function(){var oldv=$(this).data("val");var newv=$(this).val();$(this).data("val",newv);$(selector).removeAttr("onblur");if(oldv!==newv){if($(selector).attr("exitaction")){string_callback=$(selector).attr("exitaction");Function(string_callback)()}}}})}function tentry_numeric_mask(field,decimals,decimal_sep,thousand_sep){var selector='input[name="'+field+'"]';if($("#"+field).length>0){var selector="#"+field}$(selector).iMask({type:"number",decDigits:decimals,decSymbol:decimal_sep,groupSymbol:thousand_sep});if($(selector).prop("readonly")==true){$(selector).off("keydown")}}function texpander_start(){$(".texpander-container").click(function(e){e.stopPropagation()})}function tfield_enable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("readonly",false);$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield_disabled").addClass("tfield")}catch(e){console.log(e)}}function tfield_disable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("readonly",true);$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield").addClass("tfield_disabled")}catch(e){console.log(e)}}function tfield_clear_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").val("")}catch(e){console.log(e)}}function tfield_transfer_value(source,target,delimiter){if($(source).attr("type")=="checkbox"){var value=$(source).attr("value");var current_val=$(source).closest(delimiter).find(target).val();if($(source).is(":checked")){current_val=current_val+value+","}else{current_val=current_val.replace(value+",","")}$(source).closest(delimiter).find(target).val(current_val)}else{var current_val=$(source).val();$(source).closest(delimiter).find(target).val(current_val)}}function ttreeview_start(id,collapsed){$(id).treeview({persist:"location",animated:"fast",collapsed:collapsed})}function TFileAjaxUpload(idFile,action,divParent,completeAction,fileHandling){var idFile=idFile;var action=action;var divParent=$("#"+divParent);var completeAction=completeAction;var fileHandling=fileHandling;TFileAjaxUpload.prototype.supportAjaxUploadWithProgress=function(){return this.supportFileAPI()&&this.supportAjaxUploadProgressEvents()&&this.supportFormData()};TFileAjaxUpload.prototype.supportFileAPI=function(){var fi=document.createElement("INPUT");fi.type="file";return"files"in fi};TFileAjaxUpload.prototype.supportAjaxUploadProgressEvents=function(){var xhr=new XMLHttpRequest;return!!(xhr&&"upload"in xhr&&"onprogress"in xhr.upload)};TFileAjaxUpload.prototype.supportFormData=function(){return!!window.FormData};TFileAjaxUpload.prototype.initFileAjaxUpload=function(){if(this.supportAjaxUploadWithProgress()){var formData=new FormData;var fileInput=document.getElementById(idFile);var file=fileInput.files[0];formData.append("fileName",file);this.sendXHRequest(formData,action)}};TFileAjaxUpload.prototype.sendXHRequest=function(formData,uri){var xhr=new XMLHttpRequest;xhr.upload.addEventListener("loadstart",this.onloadstartHandler,false);xhr.upload.addEventListener("progress",this.onprogressHandler,false);xhr.upload.addEventListener("load",this.onloadHandler,false);xhr.addEventListener("readystatechange",this.onreadystatechangeHandler,false);xhr.open("POST",uri,true);xhr.send(formData)};TFileAjaxUpload.prototype.onloadstartHandler=function(evt){if($(divParent).children("img").length==0)$(divParent).prepend($("<img>"));$(divParent).children("img").attr({src:"lib/adianti/images/tfile_loader.gif",title:"...",style:"float:left; padding:2px"})};TFileAjaxUpload.prototype.onloadHandler=function(evt){};TFileAjaxUpload.prototype.onprogressHandler=function(evt){};TFileAjaxUpload.prototype.onreadystatechangeHandler=function(evt){var status=null;try{status=evt.target.status}catch(e){return}if(status=="200"&&evt.target.responseText){var response=JSON.parse(evt.target.responseText);if(response.type=="success"){$(divParent).children("img").attr({src:"lib/adianti/images/ico_ok.png",title:"Sucesso"});if(this.readyState==4){var hiddenFile=$(divParent).children("input[type=hidden]");if(fileHandling){var dados=tfile_getData(hiddenFile);if(dados.fileName)dados.delFile=dados.fileName;dados.newFile=response.fileName;dados.fileName=response.fileName;tfile_setData(hiddenFile,dados);tfile_show_file(divParent,response.fileName,false,fileHandling)}else{$(hiddenFile).val(response.fileName)}if(typeof completeAction=="function")completeAction()}}else{$(divParent).children("img").attr({src:"lib/adianti/images/ico_error.png",title:response.msg})}}}}function tfile_getData(hidden){var dados=decodeURIComponent($(hidden).val());var dados_json="";try{dados_json=dados?JSON.parse(dados):{}}catch(e){dados_json={}}return dados_json}function tfile_setData(hidden,data){if(data)$(hidden).val(encodeURIComponent(JSON.stringify(data)));else $(hidden).val("")}function tfile_show_file(divParent,filename,link,fileHandling){var divLinhaFile=$("<div />",{"class":"div_filename"});var divBox=$("<div />",{style:"float:left;width:90%;border:1px solid #ddd;overflow:auto;"});var spanDel=$("<span />",{"class":"glyphicon glyphicon-trash red",title:"Remover",style:"cursor: pointer; float:left; margin-left: 3px; margin-top: 4px;"});var hiddenFile=$(divParent).children("input[type=hidden]");var dados=tfile_getData(hiddenFile);var filename=filename;if(fileHandling){filename=dados.fileName}if(filename){if(link){var linkFile=$("<a />",{href:"download.php?file="+filename,target:"_blank"});$(linkFile).append(filename);$(divBox).append(linkFile)}else{$(divBox).append(filename)}$(divParent).children(".div_filename").remove();$(divParent).append(divLinhaFile);$(divLinhaFile).append(divBox,spanDel);$(spanDel).click(function(){$(divLinhaFile).remove();$(divParent).children("img").attr({src:"",title:""});dados.delFile=filename;if(dados.delFile==dados.newFile)dados="";tfile_setData(hiddenFile,dados)})}}function tfile_start(id,service,containerID,completeAction,fileHandling){$("#"+id).change(function(){var tfile=new TFileAjaxUpload(id,service,containerID,completeAction,fileHandling);tfile.initFileAjaxUpload()});if($("#"+containerID).children("input[type=hidden]").val())tfile_show_file($("#"+containerID),$("#"+id).val(),true,fileHandling)}function tfile_enable_field(form_name,field){try{$("form[name="+form_name+"] [name=file_"+field+"]").removeAttr("disabled");$("form[name="+form_name+"] [name=file_"+field+"]").removeClass("tfield_disabled").addClass("tfield")}catch(e){console.log(e)}}function tfile_disable_field(form_name,field){try{$("form[name="+form_name+"] [name=file_"+field+"]").attr("disabled",true);$("form[name="+form_name+"] [name=file_"+field+"]").removeClass("tfield").addClass("tfield_disabled")}catch(e){console.log(e)}}function tfile_clear_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").val("");$("form[name="+form_name+"] [name=file_"+field+"]").val("")}catch(e){console.log(e)}}function tfile_update_download_link(name){if($("#view_"+name).length){value=$("[name="+name+"]").val();$("#view_"+name).attr("href","download.php?file=tmp/"+value);$("#view_"+name).html("tmp/"+value)}}function TMultiFileAjaxUpload(fieldName,objFile,action,divParent,completeAction,fileHandling){var objFile=objFile;var action=action;var divParent=$("#"+divParent);var divContainerFile=$("<div />",{style:"width:100%"});var lbFile=$("<span />");var divLinhaParcial=$("<div />");var divBoxParcial=$("<div />",{style:"float:left;width:90%;border:1px solid gray;overflow:auto;"});var divParcialFile=$("<div />",{"class":"progress-bar"});var statusImage=$("<img />");var spanDel=$("<span />",{"class":"glyphicon glyphicon-trash red",title:"Remover",style:"cursor: pointer; margin-left: 3px; margin-top: 4px;"});var hiddenFile=$("<input />",{type:"hidden",name:fieldName+"[]"});var completeAction=completeAction;var fileHandling=fileHandling;$(lbFile).html(objFile.name);$(divBoxParcial).append(divParcialFile);$(divLinhaParcial).append(divBoxParcial,spanDel);$(divContainerFile).append(hiddenFile,lbFile,statusImage,divLinhaParcial);$(divParent).append(divContainerFile);$(spanDel).click(function(){$(divContainerFile).remove()});TMultiFileAjaxUpload.prototype.supportAjaxUploadWithProgress=function(){return this.supportFileAPI()&&this.supportAjaxUploadProgressEvents()&&this.supportFormData()};TMultiFileAjaxUpload.prototype.supportFileAPI=function(){var fi=document.createElement("INPUT");fi.type="file";return"files"in fi};TMultiFileAjaxUpload.prototype.supportAjaxUploadProgressEvents=function(){var xhr=new XMLHttpRequest;return!!(xhr&&"upload"in xhr&&"onprogress"in xhr.upload)};TMultiFileAjaxUpload.prototype.supportFormData=function(){return!!window.FormData};TMultiFileAjaxUpload.prototype.initFileAjaxUpload=function(){if(this.supportAjaxUploadWithProgress()){var formData=new FormData;var file=objFile;formData.append("fileName",file);this.sendXHRequest(formData,action)}};TMultiFileAjaxUpload.prototype.sendXHRequest=function(formData,uri){var xhr=new XMLHttpRequest;
xhr.upload.addEventListener("loadstart",this.onloadstartHandler,false);xhr.upload.addEventListener("progress",this.onprogressHandler,false);xhr.upload.addEventListener("load",this.onloadHandler,false);xhr.addEventListener("readystatechange",this.onreadystatechangeHandler.bind(this),false);xhr.open("POST",uri,true);xhr.send(formData)};TMultiFileAjaxUpload.prototype.onloadstartHandler=function(evt){};TMultiFileAjaxUpload.prototype.onloadHandler=function(evt){};TMultiFileAjaxUpload.prototype.onprogressHandler=function(evt){if(evt.lengthComputable){var percent=Math.round(evt.loaded*100/evt.total);$(divParcialFile).css("width",percent+"%").html(percent+"%")}};TMultiFileAjaxUpload.prototype.onreadystatechangeHandler=function(evt){var status=null;try{status=evt.target.status}catch(e){return}if(status=="200"&&evt.target.readyState=="4"&&evt.target.responseText){var response=JSON.parse(evt.target.responseText);if(fileHandling){var dados=tmultifile_getData(hiddenFile);dados.newFile=response.fileName;dados.fileName=response.fileName;tmultifile_setData(hiddenFile,dados)}else{$(hiddenFile).val(response.fileName)}if(response.type=="success"){$(divParcialFile).attr({title:"Sucesso"});$(divParcialFile).addClass("progress-bar-success");if(this.readyState==4&&typeof completeAction=="function"){completeAction()}}else{$(divParcialFile).attr({title:"Ocorreu um erro: "+response.msg});$(divParcialFile).addClass("progress-bar-danger")}}}}function tmultifile_getData(hidden){var dados=decodeURIComponent($(hidden).val());var dados_json="";try{dados_json=dados?JSON.parse(dados):{}}catch(e){dados_json={}}return dados_json}function tmultifile_setData(hidden,data){$(hidden).val(encodeURIComponent(JSON.stringify(data)))}function tmultifile_show_files(id,fieldName,containerID,fileHandling){var divParent=$("#"+containerID);if(fileHandling){$("#"+id).parent().children("input[type=hidden]").each(function(index,inp_hd){var dados=tmultifile_getData(inp_hd);var divContainerFile=$("<div />",{style:"width:100%"});var divFile=$("<div />",{style:"float:left;width:90%;border:1px solid #ddd;overflow:auto;"});if(dados.idFile)var linkFile=$("<a />",{href:"download.php?file="+dados.fileName,target:"_blank"});else var linkFile=$("<span />");var spanDel=$("<span />",{"class":"glyphicon glyphicon-trash red",title:"Remover",style:"cursor: pointer; margin-left: 3px; margin-top: 4px;"});if(!dados.delFile){$(divFile).append(linkFile);$(linkFile).html(dados.fileName);$(divContainerFile).append(divFile,spanDel);$(divParent).append(divContainerFile);$(spanDel).click(function(){$(divContainerFile).remove();dados.delFile=true;tmultifile_setData(inp_hd,dados)})}})}}function tmultifile_start(id,service,containerID,completeAction,fileHandling){$(document).ready(function(){var receiver=$("#"+id).attr("receiver");$("#"+id).change(function(){$.each($(this).prop("files"),function(index,file){var tfile=new TMultiFileAjaxUpload(receiver,file,service,containerID,completeAction,fileHandling);tfile.initFileAjaxUpload()})});tmultifile_show_files(id,receiver,containerID,fileHandling)})}function tmultifile_enable_field(form_name,field){try{$("form[name="+form_name+"] [name='file_"+field+"[]']").removeAttr("disabled");$("form[name="+form_name+"] [name='file_"+field+"[]']").removeClass("tfield_disabled").addClass("tfield")}catch(e){console.log(e)}}function tmultifile_disable_field(form_name,field){try{$("form[name="+form_name+"] [name='file_"+field+"[]']").attr("disabled",true);$("form[name="+form_name+"] [name='file_"+field+"[]']").removeClass("tfield").addClass("tfield_disabled")}catch(e){console.log(e)}}function tmultifile_clear_field(form_name,field){try{$("form[name="+form_name+"] [name='"+field+"[]']").val("");$("form[name="+form_name+"] [name='file_"+field+"[]']").val("")}catch(e){console.log(e)}}function thtmleditor_enable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").next().find(".note-editable").attr("contenteditable",true)},1)}function thtmleditor_disable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").next().find(".note-editable").attr("contenteditable",false)},1)}function thtmleditor_clear_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").code("")},1)}function thtmleditor_start(objectId,width,height,lang){$("#"+objectId).summernote({width:width,height:height,lang:lang});if(typeof $("#"+objectId).next(".note-editor")[0]!=="undefined"){var container=$("#"+objectId).next(".note-editor")[0];$(container).css("margin",$("#"+objectId).css("margin"))}}function tmenubar_start(){$(document).ready(function(){$(".dropdown-toggle").dropdown()})}function MultiField(objId,width,height){this.formFieldsName=Array();this.formFieldsMandatory=Array();this.formFieldsAlias=Array();this.formPostFields=Array();this.storeButton=null;this.deleteButton=null;this.cancelButton=null;this.inputResult=null;this.addEndCol=function(obj){if(document.all)return;var rows=obj.getElementsByTagName("THEAD")[0].getElementsByTagName("TR");for(var no=0;no<rows.length;no++){var cell=rows[no].insertCell(-1);cell.innerHTML="&nbsp;";cell.setAttribute("data","");cell.style.width="13px";cell.width="13";cell.className="multifield_header"}};this.initmultifield=function(objId,width,height){width=width+"";height=height+"";var obj=document.getElementById(objId);if(obj){this.mtf=obj;var self=this;if(navigator.userAgent.indexOf("MSIE")>=0){obj.parentNode.style.overflowY="auto"}if(width.indexOf("%")>=0){obj.style.width=width;obj.parentNode.style.width=width}else{obj.style.width=width+"px";obj.parentNode.style.width=width+"px"}if(height.indexOf("%")>=0){obj.parentNode.style.height=height}else{obj.parentNode.style.height=height+"px"}this.addEndCol(obj);obj.cellSpacing=0;obj.cellPadding=0;var tHead=obj.getElementsByTagName("THEAD")[0];var tBody=obj.getElementsByTagName("TBODY")[0];for(no=0;no<tBody.rows.length;no++){tBody.rows[no].onmousedown=function(){self.highlightSelectedRow(this);return false};tBody.rows[no].onmouseup=function(){return false};tBody.rows[no].onselectstart=function(){return false};var row=tBody.rows[no];for(i=0;i<row.cells.length;i++){row.cells[i].className="multifieldtd"}}for(var no=1;no<obj.rows.length;no++){obj.rows[no].onmouseover=this.highlightDataRow;obj.rows[no].onmouseout=this.deHighlightDataRow}}};this.highlightDataRow=function(){this.className="tmultifield_over";if(document.all){var divObj=this.parentNode.parentNode.parentNode;var tHead=divObj.getElementsByTagName("TR")[0];tHead.style.top=divObj.scrollTop+"px"}};this.deHighlightDataRow=function(){this.className=null;if(document.all){var divObj=this.parentNode.parentNode.parentNode;var tHead=divObj.getElementsByTagName("TR")[0];tHead.style.top=divObj.scrollTop+"px"}};this.highlightSelectedRow=function(row){if(this.selectedRow!=null){this.selectedRow.style.backgroundColor=""}row.style.backgroundColor="#88FF88";this.selectedRow=row;var x;for(x=0;x<this.formFieldsName.length;x++){var field=document.getElementsByName(this.formFieldsName[x])[0];var new_value=row.cells[x].innerHTML;if(field.getAttribute("auxiliar")!="1"){if(field.type=="radio"){$("input[type=radio][name="+field.name+"][value="+new_value+"]").click()}else if(field.getAttribute("component")=="multisearch"){objectId=field.getAttribute("id");$("#"+objectId).select2("val","");if(row.cells[x].getAttribute("data")){try{$("#"+objectId).select2("data",JSON.parse(row.cells[x].getAttribute("data")))}catch(e){}}}else{field.value=new_value}}if(typeof field.onchange=="function")field.onchange()}var self=this;if(this.storeButton){this.storeButton.onclick=function(){self.updateRowValuesFromFormFields(row);self.unselectRow();if(self.cancelButton)self.cancelButton.setAttribute("disabled","1");if(self.deleteButton)self.deleteButton.setAttribute("disabled","1");this.onclick=function(){self.addRowFromFormFields()}}}if(this.deleteButton){this.deleteButton.removeAttribute("disabled");this.deleteButton.onclick=function(){self.deleteRow();if(self.cancelButton)self.cancelButton.setAttribute("disabled","1");if(self.deleteButton)self.deleteButton.setAttribute("disabled","1");if(self.storeButton){self.storeButton.onclick=function(){self.addRowFromFormFields()}}}}if(this.cancelButton){this.cancelButton.removeAttribute("disabled");this.cancelButton.onclick=function(){self.unselectRow();if(self.cancelButton)self.cancelButton.setAttribute("disabled","1");if(self.deleteButton)self.deleteButton.setAttribute("disabled","1");if(self.storeButton){self.storeButton.onclick=function(){self.addRowFromFormFields()}}}}};this.addRowFromFormFields=function(){var row=document.createElement("TR");var self=this;row.onmousedown=function(){self.highlightSelectedRow(this);return false};row.onmouseup=function(){return false};row.onmouseover=this.highlightDataRow;row.onmouseout=this.deHighlightDataRow;for(var x=0;x<this.formFieldsName.length;x++){var cell=document.createElement("TD");cell.width=this.mtf.getElementsByTagName("THEAD")[0].getElementsByTagName("TR")[0].getElementsByTagName("TD")[x].width;cell.innerHTML=this.getFieldValue(this.formFieldsName[x]);cell.setAttribute("data",this.getFieldData(this.formFieldsName[x]));if(cell.innerHTML.trim()==""&&this.formFieldsMandatory[x]){alert(this.mandatoryMessage.replace("^1",this.mtf.tHead.rows[0].cells[x].innerHTML));document.getElementsByName(this.formFieldsName[x])[0].focus();return false}row.appendChild(cell)}this.mtf.tBodies[0].appendChild(row);if(!document.all)row.insertCell(-1);this.clearFormFields();return true};this.updateRowValuesFromFormFields=function(row){var x;for(x=0;x<this.formFieldsName.length;x++){var v=this.getFieldValue(this.formFieldsName[x]);if(v.trim()==""&&this.formFieldsMandatory[x]){alert(this.mandatoryMessage.replace("^1",this.mtf.tHead.rows[0].cells[x].innerHTML));document.getElementsByName(this.formFieldsName[x])[0].focus();return false}row.cells[x].innerHTML=v;row.cells[x].setAttribute("data",this.getFieldData(this.formFieldsName[x]))}this.clearFormFields();return true};this.unselectRow=function(){if(this.selectedRow){this.selectedRow.onmouseout();this.selectedRow.style.backgroundColor="";this.clearFormFields();this.selectedRow=null}};this.deleteRow=function(){if(this.selectedRow){var row=this.selectedRow;this.unselectRow();this.mtf.tBodies[0].removeChild(row)}};this.clearFormFields=function(){for(x=0;x<this.formFieldsName.length;x++){var inputs=document.getElementsByName(this.formFieldsName[x]);switch(inputs[0].type){case"text":inputs[0].value="";break;case"textarea":inputs[0].value="";break;case"hidden":if(inputs[0].getAttribute("component")=="multisearch"){objectId=inputs[0].getAttribute("id");return $("#"+objectId).select2("val","")}break;case"radio":for(var y=0;y<inputs.length;y++){inputs[y].checked=false}break;case"select-one":inputs[0].selectedIndex=-1;try{inputs[0].value=0}catch(e){}break;case"select-multiple":for(var y=0;y<inputs[0].options.length;y++){inputs[0].options[y].selected=false}break;case"checkbox":inputs[0].checked=false;break}}};this.getFieldData=function(field){var inputs=document.getElementsByName(field);if(inputs[0].getAttribute("component")=="multisearch"){return JSON.stringify($("#"+objectId).select2("data"))}else{return this.getFieldValue(field)}};this.getFieldValue=function(field){var inputs=document.getElementsByName(field);if(inputs){switch(inputs[0].type){case"text":return inputs[0].value;break;case"textarea":return inputs[0].value;break;case"hidden":if(inputs[0].getAttribute("component")=="multisearch"){objectId=inputs[0].getAttribute("id");return $("#"+objectId).select2("val").toString()}break;case"radio":for(var y=0;y<inputs.length;y++){if(inputs[y].checked)return inputs[y].value}break;case"select-one":if(inputs[0].getAttribute("auxiliar")=="1"){if(inputs[0].selectedIndex>-1){if(inputs[0].options[inputs[0].selectedIndex].value=="0"){return""}else{return inputs[0].options[inputs[0].selectedIndex].text}}}else{if(inputs[0].selectedIndex>-1){if(inputs[0].options[inputs[0].selectedIndex].value=="0"){return""}else{return inputs[0].options[inputs[0].selectedIndex].value}}}break;case"select-multiple":for(var y=0;y<inputs[0].options.length;y++){if(inputs[0].options[y].selected){v+=","+inputs[0].options[y].value}}v=v.substr(1);if(v){return v};break;case"checkbox":return inputs[0].checked?"Sim":"N�o";break}}return""};this.parseTableToJSON=function(){var tbody=this.mtf.tBodies[0];var head=this.mtf.tHead.rows[0].cells;var result="[";for(var row=0;row<tbody.rows.length;row++){result+="{";var objRow=tbody.rows[row];var max=objRow.cells.length;if(!document.all)max=objRow.cells.length-1;var values="";for(var col=0;col<=max;col++){var objCell=objRow.cells[col];var content=objCell.getAttribute("data");if(this.formFieldsAlias[col])colname=this.formFieldsAlias[col];else colname=head[col].innerHTML;if(this.formPostFields[colname]){if(values.length>0)values+=",";values+='"'+escape(colname)+'":"'+escape(content)+'"'}}if(objRow.getAttribute("dbId")){result+='"id":"'+objRow.getAttribute("dbId")+'"';if(values.length>0)result+=","+values}else{result+=values}result+="}";if(row<tbody.rows.length-1)result+=","}result+="]";if(this.inputResult)this.inputResult.value=result;return result};this.selectedRow=null;this.initmultifield(objId,width,height)}function tmultifield_start(objid,fields,mandatories,width,height){if(typeof multifields=="undefined"){multifields=new Object}var name=$("#"+objid).attr("name").split("_").slice(1).join("_");multifields[objid]=new MultiField(objid,width,height);multifields[objid].formFieldsAlias=fields;multifields[objid].formFieldsName=Array();multifields[objid].formPostFields=Array();for(key in fields){col=fields[key];multifields[objid].formPostFields[col]=1;multifields[objid].formFieldsName.push(name+"_"+col)}multifields[objid].formFieldsMandatory=mandatories;multifields[objid].mandatoryMessage="The field ^1 is required";multifields[objid].storeButton=document.getElementsByName(objid+"btnStore")[0];multifields[objid].deleteButton=document.getElementsByName(objid+"btnDelete")[0];multifields[objid].cancelButton=document.getElementsByName(objid+"btnCancel")[0];multifields[objid].inputResult=document.getElementsByName(name)[0]}function tmultifield_enable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+'] div[mtf_name="block_'+field+'"]').remove()},20)}function tmultifield_disable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+'] div[mtf_name="block_'+field+'"]').remove()},19);setTimeout(function(){$("form[name="+form_name+'] div[mtf_name="'+field+'"]').css("position","relative").prepend('<div mtf_name="block_'+field+'" style="position:absolute; width:'+$('div[mtf_name="'+field+'"]').width()+"px; height:"+$('div[mtf_name="'+field+'"]').height()+'px; background: #c0c0c0; opacity:0.5;"></div>')},20)}function tmultifield_clear_field(form_name,field){$("#"+field+"mfTable .tmultifield_scrolling").html("")}function tmultisearch_start(id,minlen,maxsize,placeholder,multiple,width,height,allowclear,allowsearch,callback){var options={minimumInputLength:minlen,maximumSelectionLength:maxsize,allowClear:allowclear,placeholder:placeholder,multiple:multiple,minimumResultsForSearch:allowsearch,id:function(e){return e.id+"::"+e.text},templateResult:function(d){if(/<[a-z][\s\S]*>/i.test(d.text)){return $(d.text)}else{return d.text}},templateSelection:function(d){if(/<[a-z][\s\S]*>/i.test(d.text)){return $(d.text)}else{return d.text}}};if(multiple!=="1"){delete options.maximumSelectionLength}$("#"+id).select2(options);if(typeof callback!="undefined"){$("#"+id).on("change",function(e){callback()})}if(parseInt(maxsize)!==1){$("#"+id).parent().find(".select2-selection").height(height);$("#"+id).parent().find(".select2-selection").find(".select2-selection__rendered").height(height);$("#"+id).parent().find(".select2-selection").find(".select2-selection__rendered").css("overflow-y","auto")}}function tmultisearch_clear_field(form_name,field){try{$("form[name="+form_name+'] [name="'+field+'[]"]').val("").trigger("change");$("form[name="+form_name+'] [name="'+field+'"]').val("").trigger("change")}catch(e){console.log(e)}}function tmultisearch_enable_field(form_name,field){try{$("form[name="+form_name+'] [name="'+field+'[]"]').attr("disabled",false);$("form[name="+form_name+'] [name="'+field+'"]').attr("disabled",false)}catch(e){console.log(e)}}function tmultisearch_disable_field(form_name,field){try{$("form[name="+form_name+'] [name="'+field+'[]"]').attr("disabled",true);$("form[name="+form_name+'] [name="'+field+'"]').attr("disabled",true)}catch(e){console.log(e)}}$.fn.select2.amd.require(["select2/selection/search"],function(Search){var oldRemoveChoice=Search.prototype.searchRemoveChoice;Search.prototype.searchRemoveChoice=function(){oldRemoveChoice.apply(this,arguments);this.$search.val("")}});function tmultientry_start(id,maxsize,width,height,callback){var options={tags:true,maximumSelectionLength:maxsize,width:width,tokenSeparators:[",",";"]};if(typeof callback!="undefined"){$("#"+id).on("change",function(e){callback()})}var element=$("#"+id).select2(options)}function tdbmultisearch_start(id,minlen,maxsize,placeholder,multiple,service,width,height,hash,callback){var options={minimumInputLength:minlen,maximumSelectionLength:maxsize,allowClear:true,placeholder:placeholder,multiple:multiple,id:function(e){return e.id+"::"+e.text},templateResult:function(d){if(/<[a-z][\s\S]*>/i.test(d.text)){return $(d.text)}else{return d.text}},templateSelection:function(d){if(/<[a-z][\s\S]*>/i.test(d.text)){return $(d.text)}else{return d.text}},ajax:{url:service,dataType:"json",quietMillis:100,data:function(value,page){return{value:value.term,hash:hash}},processResults:function(data,page){var aa=[];$(data.result).each(function(i){var item=this.split("::");aa.push({id:item[0],text:item[1]})});return{results:aa}}}};if(multiple!=="1"){delete options.maximumSelectionLength}$("#"+id).select2(options);if(typeof callback!="undefined"){$("#"+id).on("change",function(e){callback()})}if(parseInt(maxsize)!==1){$("#"+id).parent().find(".select2-selection").height(height);$("#"+id).parent().find(".select2-selection").find(".select2-selection__rendered").height(height);$("#"+id).parent().find(".select2-selection").find(".select2-selection__rendered").css("overflow-y","auto")}}function tradiogroup_enable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").removeAttr("disabled");$("form[name="+form_name+"] [name="+field+"]").parent().removeAttr("disabled")},1)}function tradiogroup_disable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").attr("disabled","");$("form[name="+form_name+"] [name="+field+"]").parent().attr("disabled","")},1)}function tradiogroup_clear_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").attr("checked",false)},1)}function tseekbutton_enable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("disabled",false);$("form[name="+form_name+"] [name="+field+"]").removeClass("tfield_disabled").addClass("tseekentry")}catch(e){console.log(e)}setTimeout(function(){$("form[name="+form_name+"] [name=_"+field+"_link]").show()},1)}function tseekbutton_disable_field(form_name,field){try{$("form[name="+form_name+"] [name="+field+"]").attr("disabled",true);$("form[name="+form_name+"] [name="+field+"]").addClass("tfield_disabled").removeClass("tseekentry")}catch(e){console.log(e)}setTimeout(function(){$("form[name="+form_name+"] [name=_"+field+"_link]").hide()},1)}function tselect_enable_field(form_name,field){try{$("form[name="+form_name+'] [name="'+field+'[]"]').attr("disabled",false);$("form[name="+form_name+'] [name="'+field+'[]"]').removeClass("tcombo_disabled").addClass("tcombo")}catch(e){console.log(e)}}function tselect_disable_field(form_name,field){try{$("form[name="+form_name+'] [name="'+field+'[]"]').attr("disabled",true);$("form[name="+form_name+'] [name="'+field+'[]"]').removeClass("tcombo").addClass("tcombo_disabled")}catch(e){console.log(e)}}function tselect_clear_field(form_name,field){try{$("form[name="+form_name+'] [name="'+field+'[]"]').val("")}catch(e){console.log(e)}}function tselect_add_option(form_name,field,key,value){$('<option value="'+key+'">'+value+"</option>").appendTo('form[name="'+form_name+'"] select[name="'+field+'[]"]')}function tselect_clear(form_name,field){$('form[name="'+form_name+'"] select[name="'+field+'[]"]').html("")}function tslider_start(id,value,min,max,step){$(id+"_div").slider({value:value,min:min,max:max,step:step,slide:function(event,ui){$(id).val(ui.value)}})}function tslider_enable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").attr("readonly",false)},1);setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").next().show()},1)}function tslider_disable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").attr("readonly",true)},1);setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").next().hide()},1)}function tsortlist_start(id,connect,change_action,limit){$(id).sortable({connectWith:connect,tolerance:"pointer",start:function(event,ui){ui.item.data("index",ui.item.index());ui.item.data("parenta",this.id)},receive:function(event,ui){if(limit>0){if($(this).children().length>limit){$(ui.sender).sortable("cancel");return}}var sourceList=ui.sender;var targetList=$(this);targetListName=this.getAttribute("itemname");document.getElementById(ui.item.attr("id")+"_input").name=targetListName+"[]";if(ui.item.css("display")!==targetList.attr("itemdisplay")){ui.item.css("display",targetList.attr("itemdisplay"));detached=ui.item.detach();$(targetList).append(detached)}},deactivate:change_action}).disableSelection()}function tsortlist_enable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [itemname="+field+"]").sortable("enable")},1)}function tsortlist_disable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [itemname="+field+"]").sortable("disable")},1)}function tsortlist_clear_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [itemname="+field+"]").empty()},1)}function tspinner_start(id,value,min,max,step,callback){$(id).spinner({step:step,numberFormat:"n",spin:function(event,ui){if(ui.value>max){$(this).spinner("value",min);return false}else if(ui.value<min){$(this).spinner("value",max);return false}},stop:callback});relwidth=$(id).attr("relwidth");if(typeof relwidth!=="undefined"){$(id).width("100%");$(id).parent().width(relwidth)}}function tspinner_enable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").spinner("enable");$("form[name="+form_name+"] [name="+field+"]").removeAttr("readonly")},1)}function tspinner_disable_field(form_name,field){setTimeout(function(){$("form[name="+form_name+"] [name="+field+"]").spinner("disable");$("form[name="+form_name+"] [name="+field+"]").removeAttr("disabled");$("form[name="+form_name+"] [name="+field+"]").attr("readonly",true)},1)}function tfullcalendar_start(id,editable,defaultView,currentDate,language,events,day_click_action,event_click_action,event_update_action,min_time,max_time,hidden_days){var drag_status=0;var resize_status=0;$("#"+id).fullCalendar({header:{left:"prev,next today",center:"title",right:"month,agendaWeek,agendaDay"},hiddenDays:hidden_days,defaultDate:currentDate,defaultView:defaultView,allDaySlot:false,viewRender:function(view,element){setTimeout(function(){__adianti_process_popover(),100})},minTime:min_time,maxTime:max_time,slotLabelFormat:"HH:mm",lang:language,editable:editable,eventLimit:true,events:events,eventRender:function(event,element){element.find(".fc-title").html(event.title)},dayClick:function(date,jsEvent,view){if(day_click_action!==""&&drag_status==0&&resize_status==0){__adianti_load_page(day_click_action+"&date="+date.format()+"&view="+view.name)}},eventClick:function(calEvent,jsEvent,view){if(event_click_action!==""&&drag_status==0&&resize_status==0){__adianti_load_page(event_click_action+"&id="+calEvent.id+"&key="+calEvent.id+"&view="+view.name)}},eventDragStart:function(calEvent,jsEvent,ui,view){drag_status=1},eventDragStop:function(calEvent,jsEvent,ui,view){drag_status=0},eventDrop:function(calEvent,jsEvent,ui,view){if(event_update_action!==""){__adianti_ajax_exec(event_update_action+"&id="+calEvent.id+"&key="+calEvent.id+"&start_time="+calEvent.start.format()+"&end_time="+calEvent.end.format())}},eventResizeStart:function(calEvent,jsEvent,ui,view){resize_status=1},eventResizeStop:function(calEvent,jsEvent,ui,view){resize_status=0},eventResize:function(calEvent,jsEvent,ui,view){if(event_update_action!==""){__adianti_ajax_exec(event_update_action+"&id="+calEvent.id+"&key="+calEvent.id+"&start_time="+calEvent.start.format()+"&end_time="+calEvent.end.format())}}})}