(function(a){a.extend(a.jgrid,{showModal:function(b){b.w.show()},closeModal:function(b){b.w.hide().attr("aria-hidden","true");if(b.o){b.o.remove()}},hideModal:function(d,c){c=a.extend({jqm:true,gb:""},c||{});if(c.onClose){var b=c.onClose(d);if(typeof b=="boolean"&&!b){return}}if(a.fn.jqm&&c.jqm===true){a(d).attr("aria-hidden","true").jqmHide()}else{if(c.gb!==""){try{a(".jqgrid-overlay:first",c.gb).hide()}catch(f){}}a(d).hide().attr("aria-hidden","true")}},findPos:function(d){var b=0,c=0;if(d.offsetParent){do{b+=d.offsetLeft;c+=d.offsetTop}while(d=d.offsetParent)}return[b,c]},createModal:function(b,c,f,v,g,m,t){var s=document.createElement("div"),h,u=this;t=a.extend({},t||{});h=a(f.gbox).attr("dir")=="rtl"?true:false;s.className="ui-widget ui-widget-content ui-corner-all ui-jqdialog";s.id=b.themodal;var d=document.createElement("div");d.className="ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";d.id=b.modalhead;a(d).append("<span class='ui-jqdialog-title'>"+f.caption+"</span>");var q=a("<a href='javascript:void(0)' class='ui-jqdialog-titlebar-close ui-corner-all'></a>").hover(function(){q.addClass("ui-state-hover")},function(){q.removeClass("ui-state-hover")}).append("<span class='ui-icon ui-icon-closethick'></span>");a(d).append(q);if(h){s.dir="rtl";a(".ui-jqdialog-title",d).css("float","right");a(".ui-jqdialog-titlebar-close",d).css("left",0.3+"em")}else{s.dir="ltr";a(".ui-jqdialog-title",d).css("float","left");a(".ui-jqdialog-titlebar-close",d).css("right",0.3+"em")}var j=document.createElement("div");a(j).addClass("ui-jqdialog-content ui-widget-content").attr("id",b.modalcontent);a(j).append(c);s.appendChild(j);a(s).prepend(d);if(m===true){a("body").append(s)}else{if(typeof m=="string"){a(m).append(s)}else{a(s).insertBefore(v)}}a(s).css(t);if(typeof f.jqModal==="undefined"){f.jqModal=true}var k={};if(a.fn.jqm&&f.jqModal===true){if(f.left===0&&f.top===0&&f.overlay){var w=[];w=this.findPos(g);f.left=w[0]+4;f.top=w[1]+4}k.top=f.top+"px";k.left=f.left}else{if(f.left!==0||f.top!==0){k.left=f.left;k.top=f.top+"px"}}a("a.ui-jqdialog-titlebar-close",d).click(function(x){var p=a("#"+b.themodal).data("onClose")||f.onClose;var r=a("#"+b.themodal).data("gbox")||f.gbox;u.hideModal("#"+b.themodal,{gb:r,jqm:f.jqModal,onClose:p});return false});if(f.width===0||!f.width){f.width=300}if(f.height===0||!f.height){f.height=200}if(!f.zIndex){var l=a(v).parents("*[role=dialog]").filter(":first").css("z-index");if(l){f.zIndex=parseInt(l,10)+1}else{f.zIndex=950}}var n=0;if(h&&k.left&&!m){n=a(f.gbox).width()-(!isNaN(f.width)?parseInt(f.width,10):0)-8;k.left=parseInt(k.left,10)+parseInt(n,10)}if(k.left){k.left+="px"}a(s).css(a.extend({width:isNaN(f.width)?"auto":f.width+"px",height:isNaN(f.height)?"auto":f.height+"px",zIndex:f.zIndex,overflow:"hidden"},k)).attr({tabIndex:"-1",role:"dialog","aria-labelledby":b.modalhead,"aria-hidden":"true"});if(typeof f.drag=="undefined"){f.drag=true}if(typeof f.resize=="undefined"){f.resize=true}if(f.drag){a(d).css("cursor","move");if(a.fn.jqDrag){a(s).jqDrag(d)}else{try{a(s).draggable({handle:a("#"+d.id)})}catch(o){}}}if(f.resize){if(a.fn.jqResize){a(s).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se ui-icon-grip-diagonal-se'></div>");a("#"+b.themodal).jqResize(".jqResize",b.scrollelm?"#"+b.scrollelm:false)}else{try{a(s).resizable({handles:"se, sw",alsoResize:b.scrollelm?"#"+b.scrollelm:false})}catch(i){}}}if(f.closeOnEscape===true){a(s).keydown(function(r){if(r.which==27){var p=a("#"+b.themodal).data("onClose")||f.onClose;u.hideModal(this,{gb:f.gbox,jqm:f.jqModal,onClose:p})}})}},viewModal:function(c,b){b=a.extend({toTop:true,overlay:10,modal:false,overlayClass:"ui-widget-overlay",onShow:this.showModal,onHide:this.closeModal,gbox:"",jqm:true,jqM:true},b||{});if(a.fn.jqm&&b.jqm===true){if(b.jqM){a(c).attr("aria-hidden","false").jqm(b).jqmShow()}else{a(c).attr("aria-hidden","false").jqmShow()}}else{if(b.gbox!==""){a(".jqgrid-overlay:first",b.gbox).show();a(c).data("gbox",b.gbox)}a(c).show().attr("aria-hidden","false");try{a(":input:visible",c)[0].focus()}catch(d){}}},info_dialog:function(h,f,o,c){var j={width:290,height:"auto",dataheight:"auto",drag:true,resize:false,caption:"<b>"+h+"</b>",left:250,top:170,zIndex:1000,jqModal:true,modal:false,closeOnEscape:true,align:"center",buttonalign:"center",buttons:[]};a.extend(j,c||{});var r=j.jqModal,q=this;if(a.fn.jqm&&!r){r=false}var l="";if(j.buttons.length>0){for(var b=0;b<j.buttons.length;b++){if(typeof j.buttons[b].id=="undefined"){j.buttons[b].id="info_button_"+b}l+="<a href='javascript:void(0)' id='"+j.buttons[b].id+"' class='fm-button ui-state-default ui-corner-all'>"+j.buttons[b].text+"</a>"}}var p=isNaN(j.dataheight)?j.dataheight:j.dataheight+"px",d="text-align:"+j.align+";";var k="<div id='info_id'>";k+="<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+p+";"+d+"'>"+f+"</div>";k+=o?"<div class='ui-widget-content ui-helper-clearfix' style='text-align:"+j.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'><a href='javascript:void(0)' id='closedialog' class='fm-button ui-state-default ui-corner-all'>"+o+"</a>"+l+"</div>":l!==""?"<div class='ui-widget-content ui-helper-clearfix' style='text-align:"+j.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'>"+l+"</div>":"";k+="</div>";try{if(a("#info_dialog").attr("aria-hidden")=="false"){this.hideModal("#info_dialog",{jqm:r})}a("#info_dialog").remove()}catch(g){}this.createModal({themodal:"info_dialog",modalhead:"info_head",modalcontent:"info_content",scrollelm:"infocnt"},k,j,"","",true);if(l){a.each(j.buttons,function(e){a("#"+this.id,"#info_id").bind("click",function(){j.buttons[e].onClick.call(a("#info_dialog"));return false})})}a("#closedialog","#info_id").click(function(i){q.hideModal("#info_dialog",{jqm:r});return false});a(".fm-button","#info_dialog").hover(function(){a(this).addClass("ui-state-hover")},function(){a(this).removeClass("ui-state-hover")});if(a.isFunction(j.beforeOpen)){j.beforeOpen()}this.viewModal("#info_dialog",{onHide:function(e){e.w.hide().remove();if(e.o){e.o.remove()}},modal:j.modal,jqm:r});if(a.isFunction(j.afterOpen)){j.afterOpen()}try{a("#info_dialog").focus()}catch(n){}},createEl:function(x,j,n,u,s){var b="";function t(e,i){if(a.isFunction(i.dataInit)){i.dataInit(e)}if(i.dataEvents){a.each(i.dataEvents,function(){if(this.data!==undefined){a(e).bind(this.type,this.data,this.fn)}else{a(e).bind(this.type,this.fn)}})}return i}function c(e,z,y){var i=["dataInit","dataEvents","dataUrl","buildSelect","sopt","searchhidden","defaultValue","attr"];if(typeof(y)!="undefined"&&a.isArray(y)){i=a.extend(i,y)}a.each(z,function(B,A){if(a.inArray(B,i)===-1){a(e).attr(B,A)}});if(!z.hasOwnProperty("id")){a(e).attr("id",a.jgrid.randId())}}switch(x){case"textarea":b=document.createElement("textarea");if(u){if(!j.cols){a(b).css({width:"98%"})}}else{if(!j.cols){j.cols=20}}if(!j.rows){j.rows=2}if(n=="&nbsp;"||n=="&#160;"||(n.length==1&&n.charCodeAt(0)==160)){n=""}b.value=n;c(b,j);j=t(b,j);a(b).attr({role:"textbox",multiline:"true"});break;case"checkbox":b=document.createElement("input");b.type="checkbox";if(!j.value){var o=n.toLowerCase();if(o.search(/(false|0|no|off|undefined)/i)<0&&o!==""){b.checked=true;b.defaultChecked=true;b.value=n}else{b.value="on"}a(b).attr("offval","off")}else{var r=j.value.split(":");if(n===r[0]){b.checked=true;b.defaultChecked=true}b.value=r[0];a(b).attr("offval",r[1])}c(b,j,["value"]);j=t(b,j);a(b).attr("role","checkbox");break;case"select":b=document.createElement("select");b.setAttribute("role","select");var d,v=[];if(j.multiple===true){d=true;b.multiple="multiple";a(b).attr("aria-multiselectable","true")}else{d=false}if(typeof(j.dataUrl)!="undefined"){a.ajax(a.extend({url:j.dataUrl,type:"GET",dataType:"html",context:{elem:b,options:j,vl:n},success:function(B,z){var A,y=[],D=this.elem,C=this.vl,e=a.extend({},this.options),i=e.multiple===true;if(typeof(e.buildSelect)!="undefined"){var E=e.buildSelect(B);A=a(E).html()}else{A=a(B).html()}if(A){a(D).append(A);c(D,e);e=t(D,e);if(typeof e.size==="undefined"){e.size=i?3:1}if(i){y=C.split(",");y=a.map(y,function(F){return a.trim(F)})}else{y[0]=a.trim(C)}setTimeout(function(){a("option",D).each(function(F){a(this).attr("role","option");if(a.inArray(a.trim(a(this).text()),y)>-1||a.inArray(a.trim(a(this).val()),y)>-1){this.selected="selected"}})},0)}}},s||{}))}else{if(j.value){var h;if(d){v=n.split(",");v=a.map(v,function(e){return a.trim(e)});if(typeof j.size==="undefined"){j.size=3}}else{j.size=1}if(typeof j.value==="function"){j.value=j.value()}var p,g,k;if(typeof j.value==="string"){p=j.value.split(";");for(h=0;h<p.length;h++){g=p[h].split(":");if(g.length>2){g[1]=a.map(g,function(e,y){if(y>0){return e}}).join(":")}k=document.createElement("option");k.setAttribute("role","option");k.value=g[0];k.innerHTML=g[1];if(!d&&(a.trim(g[0])==a.trim(n)||a.trim(g[1])==a.trim(n))){k.selected="selected"}if(d&&(a.inArray(a.trim(g[1]),v)>-1||a.inArray(a.trim(g[0]),v)>-1)){k.selected="selected"}b.appendChild(k)}}else{if(typeof j.value==="object"){var f=j.value;for(var w in f){if(f.hasOwnProperty(w)){k=document.createElement("option");k.setAttribute("role","option");k.value=w;k.innerHTML=f[w];if(!d&&(a.trim(w)==a.trim(n)||a.trim(f[w])==a.trim(n))){k.selected="selected"}if(d&&(a.inArray(a.trim(f[w]),v)>-1||a.inArray(a.trim(w),v)>-1)){k.selected="selected"}b.appendChild(k)}}}}c(b,j,["value"]);j=t(b,j)}}break;case"text":case"password":case"button":var l;if(x=="button"){l="button"}else{l="textbox"}b=document.createElement("input");b.type=x;b.value=n;c(b,j);j=t(b,j);if(x!="button"){if(u){if(!j.size){a(b).css({width:"98%"})}}else{if(!j.size){j.size=20}}}a(b).attr("role",l);break;case"image":case"file":b=document.createElement("input");b.type=x;c(b,j);j=t(b,j);break;case"custom":b=document.createElement("span");try{if(a.isFunction(j.custom_element)){var m=j.custom_element.call(this,n,j);if(m){m=a(m).addClass("customelement").attr({id:j.id,name:j.name});a(b).empty().append(m)}else{throw"e2"}}else{throw"e1"}}catch(q){if(q=="e1"){this.info_dialog(a.jgrid.errors.errcap,"function 'custom_element' "+a.jgrid.edit.msg.nodefined,a.jgrid.edit.bClose)}if(q=="e2"){this.info_dialog(a.jgrid.errors.errcap,"function 'custom_element' "+a.jgrid.edit.msg.novalue,a.jgrid.edit.bClose)}else{this.info_dialog(a.jgrid.errors.errcap,typeof(q)==="string"?q:q.message,a.jgrid.edit.bClose)}}break}return b},checkDate:function(n,e){var g=function(i){return(((i%4===0)&&(i%100!==0||(i%400===0)))?29:28)},l=function(j){for(var r=1;r<=j;r++){this[r]=31;if(r==4||r==6||r==9||r==11){this[r]=30}if(r==2){this[r]=29}}return this};var h={},q;n=n.toLowerCase();if(n.indexOf("/")!=-1){q="/"}else{if(n.indexOf("-")!=-1){q="-"}else{if(n.indexOf(".")!=-1){q="."}else{q="/"}}}n=n.split(q);e=e.split(q);if(e.length!=3){return false}var c=-1,o,d=-1,f=-1;for(var b=0;b<n.length;b++){var p=isNaN(e[b])?0:parseInt(e[b],10);h[n[b]]=p;o=n[b];if(o.indexOf("y")!=-1){c=b}if(o.indexOf("m")!=-1){f=b}if(o.indexOf("d")!=-1){d=b}}if(n[c]=="y"||n[c]=="yyyy"){o=4}else{if(n[c]=="yy"){o=2}else{o=-1}}var m=l(12),k;if(c===-1){return false}else{k=h[n[c]].toString();if(o==2&&k.length==1){o=1}if(k.length!=o||(h[n[c]]===0&&e[c]!="00")){return false}}if(f===-1){return false}else{k=h[n[f]].toString();if(k.length<1||h[n[f]]<1||h[n[f]]>12){return false}}if(d===-1){return false}else{k=h[n[d]].toString();if(k.length<1||h[n[d]]<1||h[n[d]]>31||(h[n[f]]==2&&h[n[d]]>g(h[n[c]]))||h[n[d]]>m[h[n[f]]]){return false}}return true},isEmpty:function(b){if(b.match(/^\s+$/)||b===""){return true}else{return false}},checkTime:function(c){var d=/^(\d{1,2}):(\d{2})([ap]m)?$/,b;if(!this.isEmpty(c)){b=c.match(d);if(b){if(b[3]){if(b[1]<1||b[1]>12){return false}}else{if(b[1]>23){return false}}if(b[2]>59){return false}}else{return false}}return true},checkValues:function(j,h,o,r,m){var c,b,n,l,q;if(typeof(r)==="undefined"){if(typeof(h)=="string"){for(b=0,q=o.p.colModel.length;b<q;b++){if(o.p.colModel[b].name==h){c=o.p.colModel[b].editrules;h=b;try{n=o.p.colModel[b].formoptions.label}catch(d){}break}}}else{if(h>=0){c=o.p.colModel[h].editrules}}}else{c=r;n=m===undefined?"_":m}if(c){if(!n){n=o.p.colNames[h]}if(c.required===true){if(this.isEmpty(j)){return[false,n+": "+a.jgrid.edit.msg.required,""]}}var p=c.required===false?false:true;if(c.number===true){if(!(p===false&&this.isEmpty(j))){if(isNaN(j)){return[false,n+": "+a.jgrid.edit.msg.number,""]}}}if(typeof c.minValue!="undefined"&&!isNaN(c.minValue)){if(parseFloat(j)<parseFloat(c.minValue)){return[false,n+": "+a.jgrid.edit.msg.minValue+" "+c.minValue,""]}}if(typeof c.maxValue!="undefined"&&!isNaN(c.maxValue)){if(parseFloat(j)>parseFloat(c.maxValue)){return[false,n+": "+a.jgrid.edit.msg.maxValue+" "+c.maxValue,""]}}var f;if(c.email===true){if(!(p===false&&this.isEmpty(j))){f=/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;if(!f.test(j)){return[false,n+": "+a.jgrid.edit.msg.email,""]}}}if(c.integer===true){if(!(p===false&&this.isEmpty(j))){if(isNaN(j)){return[false,n+": "+a.jgrid.edit.msg.integer,""]}if((j%1!==0)||(j.indexOf(".")!=-1)){return[false,n+": "+a.jgrid.edit.msg.integer,""]}}}if(c.date===true){if(!(p===false&&this.isEmpty(j))){if(o.p.colModel[h].formatoptions&&o.p.colModel[h].formatoptions.newformat){l=o.p.colModel[h].formatoptions.newformat}else{l=o.p.colModel[h].datefmt||"Y-m-d"}if(!this.checkDate(l,j)){return[false,n+": "+a.jgrid.edit.msg.date+" - "+l,""]}}}if(c.time===true){if(!(p===false&&this.isEmpty(j))){if(!this.checkTime(j)){return[false,n+": "+a.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]}}}if(c.url===true){if(!(p===false&&this.isEmpty(j))){f=/^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;if(!f.test(j)){return[false,n+": "+a.jgrid.edit.msg.url,""]}}}if(c.custom===true){if(!(p===false&&this.isEmpty(j))){if(a.isFunction(c.custom_func)){var k=c.custom_func.call(o,j,n);if(a.isArray(k)){return k}else{return[false,a.jgrid.edit.msg.customarray,""]}}else{return[false,a.jgrid.edit.msg.customfcheck,""]}}}}return[true,"",""]}})})(jQuery);
