///********Powered By Sadhenshie********///
///***https://www.facebook.com/Sadhenshie***///
var divHit;
var DivDropDownHeight;
var httpRequest;
var debugOn = true;
var BASE_TKO="lde";
var BASEPATH = window.location.protocol+'//'+window.location.hostname;
if (window.location.port) BASEPATH+=':'+window.location.port;
    BASEPATH+='/';
var PREFIX = window.location;PREFIX=PREFIX.pathname.split("/");PREFIX=PREFIX[1]+'/';
var BaseReload=true;
var BaseErMsg="We detect a mistake, Press Ok to reload the page.";

//BASEPATH="http://localhost:225/";
//Attributes
//id - object ID
//data-aUrl - link where data to be submitted
//data-rspLoc - location -> response to be place after submission
//data-dPosition - Response -> Position its either top,bottom or overwrite
//data-xFunc - function to handle basic JSON response if not "data-xFunc" is not define then automatically use AJAX
//data-jFunc - custom function to handle JSON response if not "data-jFunc" is not define then automatically use AJAX
//data-data to be submitted if "data" not define it will use getformvalues for form element but for other need to be defined
//data-dLoader - format [data-dLoader="class or id,then loader class"] if attribute "data-dLoader" is not define then it will automatically used the default loader
//data-aUrl="" data-data="" data-dLoader="" data-rspLoc="" data-dPosition="" data-jFunc=""

//Confirm
//data-jConfirm -Confirm
//data-jCTitle -Confirm Title
//data-jCMsg -Confirm Msg
//data-jCYbtn -Confirm Yes Button
//data-jCNbtn -Confirm  No Button
//Confirm

//Extras
//J=XJAct
//XJACmsg
//jObject.jConfirm
//jObject.jUpdatePage
//class=#AJXJS//

//{"iFunc",XJAStatus,dLoader:"custom_loader",rspLoc:"records",dPosition:"top",jFunc:,xFunc:};
//document.onkeydown = function(evt) {
//    evt = evt || window.event;
//    if (evt.keyCode == 13  && document.getElementById("xalertText")) {
//       rmChild("xwrapper");rmChild("xalertText");
//       xConfirmButton(0);
//       return false;
//    }
//};


//Explore
/*
var e = jQuery.Event("keyup");
 e.which = 13; // # Some key code value
 $("#header-search").trigger(e);
*/
//Explore

window.onbeforeunload = confirmExit;
function confirmExit()
{
    if (!BaseReload){ return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
    }else{return null;}
}
function newFormPost(e,t,n){var r=document.createElement("form");r.name="_newForm";r.action=e?e:"";r.method="post";if(t)r.target=t;document.body.appendChild(r);if(n){var i=n.split("&");for(var s=0;s<i.length;s++){var o=i[s].split("=");if(o.length==2)addFormValues(r,unescape(o[0]),unescape(o[1]))}}r.submit()}function postAsNewForm(e){newFormPost(e.action,e.target,getFormValuesA(e))}function getElementFields(e){var t="";if(typeof e=="string"){var n=document.getElementById(e);if(n){if(!n.elements){t=getElementsByTagNames("input,select,textarea",n)}else{t=n.elements}}}else{if(!e.elements){t=getElementsByTagNames("input,select,textarea",e)}else{t=e.elements}}return t}function getElementsByTagNames(e,t){if(!t)t=document;var n=e.split(",");var r=new Array;for(var i=0;i<n.length;i++){var s=t.getElementsByTagName(n[i]);for(var o=0;o<s.length;o++){r.push(s[o])}}return r}function rmChild(e){var t=e;if(typeof e=="string")var t=document.getElementById(e);if(t){zbox=t.parentNode;if(zbox){zbox.removeChild(t)}return true}return false}function createWrapper(e,t){if(e){xalertCSS=e}var n=screen.availWidth;var r=screen.availHeight;if(t!=1){var i=document.createElement("div");i.id="xwrapper";i.setAttribute("style","margin:0px auto; position:fixed; top: 0; left:0; background-color: #000; opacity: 0.50; width:100%; height:100%; ");i.setAttribute("onclick","xConfirmButton(0) ");appendX(i,"xwrapper")}var s=document.createElement("div");s.id="xalertText";if(xalertCSS==""){/*s.style.border="solid 6px #848383";*/s.style.padding="4px 7px"; s.style.boxShadow="0px 0px 20px rgba(50, 50, 50, 0.75)";s.style.backgroundColor="#fff";/*s.style.borderRadius="10px"*/}else{s.style.cssText=xalertCSS}s.style.margin="0px auto";s.style.top=0;s.style.left=0;r=parseInt(r/4);n=parseInt(n/3);s.style.position="fixed";s.style.top="30%";s.style.left="39%";var o=document.createElement("div");o.setAttribute("onclick","xConfirmButton(0) ");o.setAttribute("class","dgclose");o.setAttribute("title","Close");o.src=BASEPATH+"public/img/close.png";o.setAttribute("style","cursor:pointer; float:right;");try{o.setAttribute("onerror","rmChild(this)");o.style.behavior="url(iepngfix.htc)"}catch(u){}s.appendChild(o);return s}function xConfirmButton(button){if(ConfirmObjects!=""&&button==1){eval(ConfirmObjects)}if(NoConfirmObjects!=""&&button==0){eval(NoConfirmObjects)}rmChild("xwrapper");rmChild("xalertText");showSelectDiv()}function xalert(e,t,n){hideSelectBox(document.body);if(!n){n=""}NoConfirmObjects=n;divTag=createWrapper();var r=document.body.offsetWidth;var i=screen.availHeight;divTag.innerHTML=divTag.innerHTML+"<strong style='color:#000;margin:0;border-bottom:1px solid #848383;padding-top:2px;display: block;padding-bottom: 2px;padding-left: 2px;'>"+e+"</strong><blockquote align='center' id='xblock' style='margin: 12px 40px;border:none !important;padding: 10px;border:none !important;color: #000000;min-width: 150px;/*max-height:"+(i-300)+"px; max-width: "+(r-200)+"px;*/ overflow:auto;' >"+t+"</blockquote>";divTag.style.display="inline";appendX(divTag,"xalertText");repoXAlert()}function repoXAlert(){var e=document.body.offsetWidth;var t=screen.availHeight;var n=document.getElementById("xalertText");n.style.left=parseInt((e-n.offsetWidth)/2)+"px";n.style.top=parseInt((t-n.offsetHeight)/3)+"px"}function xalertCss(e,t,n,r){try{xalert(e,t)}catch(i){}var s=document.getElementById("xalertText");s.innerHTML=t;if(n){s.style.border=n}else{s.style.border="none"}if(r){s.style.background=r}else{s.style.background="transparent"}s.style.left=parseInt((x-divTag.offsetWidth)/2)+"px";s.style.top=parseInt((y-divTag.offsetHeight)/2)+"px";return s}function appendX(e,t){lastAppend=document.getElementById(t);if(lastAppend){e.style.zIndex=lastAppend.style.zIndex+2;document.body.insertBefore(e,lastAppend)}else{e.style.zIndex=16e6;document.body.appendChild(e)}}function xConfirm(e,t,n,r,i,s){if(!s){s=""}if(!i){i=""}ConfirmObjects=i;NoConfirmObjects=s;divTag=createWrapper();divTag.innerHTML=divTag.innerHTML+"<strong style='color:#000;border-bottom:1px solid #848383;display: block;padding-bottom: 2px;padding-top:2px;padding-left: 2px;'>"+e+"</strong><blockquote  style='padding: 10px;margin: 12px 40px 4px;border:none !important' align='center'>"+t+"</blockquote>";divTag.innerHTML=divTag.innerHTML+"<center><button class='xCbY' style='width: 80px;border: 1px solid #E5E5E5;box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);outline: 0 none;cursor: pointer;border-radius: 3px;margin: 5px 5px 18px;' name='yes' onclick='xConfirmButton(1)'>"+n+"</button><button class='xCbN' style='width: 80px;border: 1px solid #E5E5E5;box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);outline: 0 none;cursor: pointer;border-radius: 3px;margin: 5px 5px 18px;' onclick='xConfirmButton(0)'>"+r+"</button></center>";appendX(divTag,"xalertText");getObj(divTag,"yes","button").focus()}function ajaxerror(e){response="";try{response=resolveajax(e)}catch(t){}return response}function execJS(node,useEVAL){if(!node)return;var bSaf=navigator.userAgent.indexOf("Safari")!=-1;var bOpera=navigator.userAgent.indexOf("Opera")!=-1;var bMoz=navigator.appName=="Netscape";var st=node.getElementsByTagName("SCRIPT");var strExec;for(var i=0;i<st.length;i++){if(bSaf){strExec=st[i].innerHTML;st[i].innerHTML=""}else if(bOpera){strExec=st[i].text;st[i].text=""}else if(bMoz){strExec=st[i].textContent;st[i].textContent=""}else{strExec=st[i].text;st[i].text=""}if(debugOn)alert(strExec);try{if(useEVAL){eval(strExec)}else{var x=document.createElement("script");x.type="text/javascript";if(bSaf||bOpera||bMoz)x.innerHTML=strExec;else x.text=strExec;document.getElementsByTagName("head")[0].appendChild(x)}}catch(e){alert(e)}}}function getObj(e,t,n){if(typeof e=="string")e=document.getElementById(e);if(e){var r=e.getElementsByTagName(n);if(!t||t=="")if(r.length)return r[0];for(var i=0;i<r.length;i++){var s=r[i];if(s.id==t||s.name==t)return s}}}function getFormValuesA(e){var t="";var n=getElementFields(e);for(var r=0;r<n.length;r++){var i=n[r];if(i.disabled)continue;if(i.type=="hidden"&&i.name!=""){try{var s=FCKeditorAPI.GetInstance(i.name);if(s){var o=s.GetXHTML(true);if(o!=""){i.value=o}}}catch(u){}}switch(i.type){case"checkbox":if(i.checked)t+=i.name+"="+1+"&";else t+=i.name+"="+0+"&";break;case"radio":if(i.checked)t+=i.name+"="+escape(i.value)+"&";break;case"submit":t+=i.name+"="+escape(i.value)+"&";break;case"textarea":t+=i.name+"="+escape(i.value)+"&";break;case"hidden":t+=i.name+"="+escape(i.value)+"&";break;case"text":t+=i.name+"="+escape(i.value)+"&";break;case"email":t+=i.name+"="+escape(i.value)+"&";break;case"password":t+=i.name+"="+escape(i.value)+"&";break;case"select-one":if(i.options.length&&i.selectedIndex>-1)t+=i.name+"="+i.options[i.selectedIndex].value+"&";break;case"select-multiple":t+=i.name+"=";var a="";for(j=0;j<i.options.length;j++){if(i.options[j].selected){a+=i.options[j].value+","}}a=rtrim(a,",");t+=a+"&";break}}t=t.replace(/\+/g,"%2B");t=t.substr(0,t.length-1);t=t.replace(/&=&/g,"&");return t}function addFormValues(fObj,fName,fValue){if(typeof fObj=="string"){fObj=document.getElementById(fObj)}var tempA=eval("fObj."+fName);if(typeof tempA!="object"&&typeof tempA!="undefined"){if(!tempA.value)tempA=null}if(typeof tempA=="undefined"||!tempA){var XnewXinput=document.createElement("input");XnewXinput.name=fName+"";XnewXinput.type="hidden";XnewXinput.value=fValue;XnewXinput.setAttribute("alt","dynamic");fObj.appendChild(XnewXinput)}else{changeValue(tempA,fValue)}}function changeValue(fObj,fValue){var oldValue="";if(typeof fObj=="string"){fObj=document.getElementById(fObj)}if(fObj){oldValue=fObj.value;if(oldValue!=fValue){fObj.value=fValue;var onchangeEvent=fObj.getAttribute("onchange");if(onchangeEvent){try{eval(onchangeEvent)}catch(e){}}}else{fObj.value=fValue}}}function lettersOnly(e){var t;document.all?t=e.keyCode:t=e.which;return t>64&&t<91||t>96&&t<123||t==8}function numberOnly(e){var t;document.all?t=e.keyCode:t=e.which;return t>47&&t<60||t==8||t==46}function addslashes(e){e=e.replace(/\\/g,"\\\\");e=e.replace(/\'/g,"\\'");e=e.replace(/\"/g,'\\"');e=e.replace(/\0/g,"\\0");return e}function trim(e,t){if(!t){t=" ";e=e.replace(/^\s+|\s+$/g,"")}return ltrim(rtrim(e,t),t)}function ltrim(e,t){t=t||"\\s";return e.replace(new RegExp("^["+t+"]+","g"),"")}function rtrim(e,t){t=t||"\\s";return e.replace(new RegExp("["+t+"]+$","g"),"")}function httpBuildJSQuery(e,t){var n="";if(!e){e=window.location.href}if(e.indexOf(".php?")>-1){var r=e.substr(e.indexOf("?")+1)}else{r=e}var i=r.split("&");for(var s=0;s<i.length;s++){if(!(t&&i[s].indexOf(t.toLowerCase()+"=")>-1)){n+="&"+i[s]}}return unescape(n)}function removeHTMLTags(e){e=e.replace(/&(lt|gt);/g,function(e,t){return t=="lt"?"<":">"});var t=e.replace(/<\/?[^>]+(>|$)/g,"");return t}function showSelect(){return false;while(obj=document.getElementById("zbox-replacement"))obj.parentNode.removeChild(obj);var e=document.getElementsByTagName("select").length;if(e>0){var t=document.getElementsByTagName("select");for(i=0;i<e;i++){var n=t[i];n.style.display="inline"}}}function hideSelectBox(){return false;var e=document.getElementsByTagName("select").length;if(e>0){var t=document.getElementsByTagName("select");for(i=0;i<e;i++){var n=t[i];if(n.style.display!="none"){n.style.display="none";var r=document.createElement("input");r.setAttribute("type","text");r.setAttribute("id","zbox-divdropdown-replacement");if(n.options.length>0)r.value=n.options[n.selectedIndex>0?n.selectedIndex:0].text;if(n.style.width)r.style.width=n.style.width;else r.style.width=n.offsetWidth;n.parentNode.appendChild(r)}}}}function hideSelectDiv(e){return false;if(e.hasChildNodes()){var t=e.childNodes;for(var n=0;n<t.length;n++){if(t[n].nodeType==1){if(t[n].id=="myHTTPDivDropDown"){divHit=1}else if(t[n].nodeName=="SELECT"&&divHit==1){if(t[n].offsetTop<DivDropDownHeight){var r=t[n];var i=document.createElement("input");i.setAttribute("type","text");i.setAttribute("id","zbox-divdropdown-replacement");if(r.options.length>0)i.value=r.options[r.selectedIndex>0?r.selectedIndex:0].text;if(r.style.width)i.style.width=r.style.width;else i.style.width=r.offsetWidth;r.parentNode.appendChild(i);r.style.display="none"}}else{DivDropDownHeight=t[n].offsetTop+t[n].offsetHeight;hideSelectDiv(t[n])}}}}}function showSelectDiv(){return false;while(obj=document.getElementById("zbox-divdropdown-replacement"))obj.parentNode.removeChild(obj);var e=document.getElementsByTagName("select").length;if(e>0){var t=document.getElementsByTagName("select");for(i=0;i<e;i++){var n=t[i];obj=n.parentNode;while(obj.nodeName!="BODY"&&obj.nodeName!="DIV")obj=obj.parentNode;if(obj.nodeName=="DIV")n.style.display="inline"}}}var xalertCSS="";var ConfirmObjects;var NoConfirmObjects;loadNoticeMsg='<div class="loaderFx"><div class="sk-fading-circle"><div class="sk-circle1 sk-circle"></div><div class="sk-circle2 sk-circle"></div><div class="sk-circle3 sk-circle"></div><div class="sk-circle4 sk-circle"></div><div class="sk-circle5 sk-circle"></div><div class="sk-circle6 sk-circle"></div><div class="sk-circle7 sk-circle"></div><div class="sk-circle8 sk-circle"></div><div class="sk-circle9 sk-circle"></div><div class="sk-circle10 sk-circle"></div><div class="sk-circle11 sk-circle"></div><div class="sk-circle12 sk-circle"></div></div></div>';//<div class="loaderFx"><div class="spinner"><div class="cube1"></div><div class="cube2"></div></div></div>

window.onload = function (){
	binder();
    $(document).bind("contextmenu",function(e) {
        if(!e.toElement.href && !e.toElement.parentElement.href && e.target.tagName!="INPUT" && !debugOn){
            return false;
        }
    });
};

function i_getObj(obj){
    return document.getElementById(obj);
}

function keeper(item) {
    item.setAttribute("listened","Yes");
    item.data_aUrl=item.getAttribute("data-aUrl");
    item.data_rspLoc=item.getAttribute("data-rspLoc");
    item.data_jFunc=item.getAttribute("data-jFunc");
    item.data_dLoader=item.getAttribute("data-dLoader");
    item.data_dPosition=item.getAttribute("data-dPosition");
    item.removeAttribute("data-aUrl");
    item.removeAttribute("data-rspLoc");
    item.removeAttribute("data-jFunc");
    item.removeAttribute("data-dLoader");
    item.removeAttribute("data-dPosition");
}
function binder(){
	var dIsBlApSf = document.getElementsByClassName('#AJXJS');
	var i=0;var item=null;
	    for (i = 0; i < dIsBlApSf.length; ++i) {
		item = dIsBlApSf[i];
        item.data=item.getAttribute("data");
        item.removeAttribute("data");
            if (!item.getAttribute("listened")) {
                keeper(item);
                if (item.tagName=="FORM") {
                    item.jSource=(item.getAttribute("jSource")||0);
                    item.removeAttribute("jSource");
                    if (item.id && item.id=="B_FormFx") {
                        if(typeof aTtRib_jCont === "function"){
                            var jUrl=item.data_aUrl.split("/");
                            var data="jSource="+item.jSource;
                            XMLajxJsn(null, jUrl[0]+"/"+jUrl[1]+"/attribs", data,{jFunc:aTtRib_jCont})
                        }
                    }
                    if (item.jSource==0 || i_getObj("saveIXD")) {
                        i_getObj("saveIXD").jOnclick=i_getObj("saveIXD").getAttribute("onclick");
                        if(i_getObj("saveIXD").jOnclick)i_getObj("saveIXD").addEventListener("click", function(){eval(i_getObj("saveIXD").jOnclick);return false;}, false);
                        i_getObj("saveIXD").removeAttribute("onclick");
                        item.onsubmit=function(){XJAct(this);return false;}
                        item.onkeydown=function(evt){evt=evt|| window.event;if(evt.keyCode==13)return false;}
                    }
                }
                else if (item.tagName=="INPUT" && item.type=="text") {
                    item.onkeyup=function(){XJAct(this);return false;}
                }
                else if (item.tagName=="SELECT") {
                    item.onchange=function(){XJAct(this);return false;}
                }
                else{
                    item.addEventListener("click", function(){XJAct(this);return false;}, false);
                }
            }
	    }
	///For Top Button///
	var sRecords = document.getElementsByClassName('#rSearchAJXS');
	    for (i = 0; i < sRecords.length; ++i) {
            item = sRecords[i];
            keeper(item);
            item.data_page=item.getAttribute("data-page");
            item.data_order=item.getAttribute("data-order");
            item.data_direct=item.getAttribute("data-direct");
            item.removeAttribute("data-page");
            item.removeAttribute("data-order");
            item.removeAttribute("data-direct");
            if (item.tagName=="INPUT" && item.type=="text") {
                item.onkeyup=function(e){
                    var charCode;
                    if(e && e.which){charCode = e.which;}
                    else if(window.event){e = window.event;charCode = e.keyCode;}
                    if(charCode == 13)		
                        rPagiAct(this);
                    return false;
                }
            }else if (item.tagName=="SELECT") {
                item.onchange=function(e){
                    rPagiAct(this);return false;
                }
            }else if (item.tagName!="DIV"){
                item.addEventListener("click", function(){rPagiAct(this);return false;}, false);
            }
	    }
	var eRecords = document.getElementsByClassName('#eRecordsAJXS');
	for (i = 0; i < eRecords.length; ++i) {
		item = eRecords[i];
        keeper(item);
		item.addEventListener("click", function(){eRecordsAJX(this); return false;}, false);
	}
	var dRecords = document.getElementsByClassName('#dRecordsAJXS');
	for (i = 0; i < dRecords.length; ++i) {
		item = dRecords[i];
        keeper(item);
		item.addEventListener("click", function(){dRecordsAJX(this); return false;}, false);
	}
    
    /*RPT Printing*/
	var dRecords = document.getElementsByClassName('#AJXSRPT');
	for (i = 0; i < dRecords.length; ++i) {
		item = dRecords[i];
        item.rptModule=item.getAttribute("rpt-Module");
        item.rptXtype=item.getAttribute("rpt-Xtype");
        item.removeAttribute("rpt-Module");
        item.removeAttribute("rpt-Xtype");
        item.addEventListener("click", function(){c_Print(this); return false;}, false);
	}
}

function tableHeaderBinder(show_url){
	var i=0;var item=null;
	var records = document.getElementsByClassName('#rTableAJXS');
	    for (i = 0; i < records.length; ++i) {
		item = records[i];
        keeper(item);
        item.data_page=item.getAttribute("data-page");
        item.data_order=item.getAttribute("data-order");
        item.data_direct=item.getAttribute("data-direct");
        item.removeAttribute("data-page");
        item.removeAttribute("data-order");
        item.removeAttribute("data-direct");
		item.addEventListener("click", function(){rPagiAct(this);return false;}, false);
	    }
	var sRecords = document.getElementsByClassName('#rTablePagerAJXS');
	    for (i = 0; i < sRecords.length; ++i) {
		item = sRecords[i];
        keeper(item);
		item.onkeyup=function(e){
			var charCode;
			if(e && e.which){
			    charCode = e.which;
			}else if(window.event){
			    e = window.event;
			    charCode = e.keyCode;
			}
			if(charCode == 13 && item.value.length>0)		
			rPagiAct(this);return false;
		}
	    }
	var ochange = document.getElementsByClassName('#pgChangeAJXS');
	    for (i = 0; i < ochange.length; ++i) {
		item = ochange[i];  
        keeper(item);
		item.onchange=function(){rPagiAct(this);return false;}
	    }
}
	///For Pagination///
function fireRPT(obj){
    obj.disabled = true;
    var rptmsg="";
    if (!obj.rptModule) {
       rptmsg+="RPT Module Attribute not Found.\n"; 
    }
    if (!obj.rptFire) {
       rptmsg+="RPT Fire Attribute not Found.\n"; 
    }
    if (!obj.rptBurn) {
       rptmsg+="RPT Burn Attribute not Found.\n"; 
    }
    if (!obj.rptXtype) {
       rptmsg+="RPT XType Attribute not Found.\n"; 
    }
    if (rptmsg) {
        xalert("Information",rptmsg);
    }else{
        XMLajxRPT(obj,"module="+obj.rptModule+"&fire="+obj.rptFire+"&burn="+obj.rptBurn+"&xtype="+obj.rptXtype);
    }
}

function rPagiAct(obj){
var aUrl="";var attribs = {};var page=1;var msg="";
		if (obj.data_aUrl && obj.data_aUrl.trim().length>0) {
			aUrl=obj.data_aUrl;
		}else{
			msg+='Html Form Attribute "data-aUrl" not defined.\n';
		}
		if (obj.data_dLoader && obj.data_dLoader.trim().length>0) {
			attribs.dLoader=data_dLoader;	
		}
		if (obj.data_rspLoc && obj.data_rspLoc.trim().length>0) {
			attribs.rspLoc=obj.data_rspLoc;	
		}
		if (obj.data_dPosition && obj.data_dPosition.trim().length>0) {
			attribs.dPosition=obj.data_dPosition;	
		}
		if (obj.data_page && obj.data_page.trim().length>0) {
			page=obj.data_page;
			if (page=='this.value') {
				page=obj.value;
			}
		}
		if (obj.data_order && obj.data_order.trim().length>0) {
			if(aUrl.indexOf("?") > -1)aUrl+='&daefffb93e6c3be7136ba40edae4f2='+obj.data_order;
			else aUrl+='?daefffb93e6c3be7136ba40edae4f2='+obj.data_order;
			if (obj.data_direct) {
				aUrl+='&b4688aaaaf17fad03225929fe56ago='+obj.data_direct;
			}else{
				aUrl+='&b4688aaaaf17fad03225929fe56ago=asc';
			}
		}else{
            var tbhd=document.getElementsByClassName("sorting_asc")[0];
            if (!tbhd) {
                tbhd=document.getElementsByClassName("sorting_desc")[0];
            }if (!tbhd) {
                tbhd=document.getElementsByClassName("sorting")[0];
            }
            if (tbhd) {
                var dir=tbhd.data_direct;
                if (dir=='asc')dir='desc';else dir='asc';
                if(aUrl.indexOf("?") > -1)aUrl+='&daefffb93e6c3be7136ba40edae4f2='+tbhd.data_order;
                else aUrl+='?daefffb93e6c3be7136ba40edae4f2='+tbhd.data_order;
				aUrl+='&b4688aaaaf17fad03225929fe56ago='+dir;
            }
        }
        if (i_getObj("branch_xyz")) {
            aUrl+="&brxid="+i_getObj("branch_xyz").value;
        }
		if (obj.data_jFunc && obj.data_jFunc.trim().length>0) {
			attribs.jFunc=obj.data_jFunc;
			fn = window[attribs.jFunc];attribs.jFunc=fn;
			fnExists = typeof fn === 'function';
			if(!fnExists){
                msg+='Html Form Attribute "data-jFunc" Function not defined.\n';
			}
		}
	if (msg){
        SweetInfo("",msg,"warning");
	}else{
		sRecordsAJXS(aUrl,page,0,attribs);
	}
}

function XJAct(obj){
var aUrl="";var data="";var attribs = {};var msg="";
        if (obj.tagName=="FORM" && !i_getObj("saveIXD")){
            SweetInfo("","Can't bind Event, Missing ID 'saveIXD'.","warning");
        return false;
        }else if(obj.tagName=="FORM"){
            i_getObj("saveIXD").setAttribute("style", "display:none");
            i_getObj("saveIXD").disabled = true;
        }
		if (obj.data_aUrl && obj.data_aUrl.trim().length>0) {
			aUrl=obj.data_aUrl;
		}else{
			msg+='Html Form Attribute "data-aUrl" not defined.\n';
		}
		if (obj.data && obj.data.trim().length>0) {
			data=obj.data;	
		}else{
			if (obj.tagName=="FORM") {
				data=getFormValuesA(obj);
			}else if(obj.name){
				data=obj.name+"="+obj.value;
			}
		}
		if (obj.data_dLoader && obj.data_dLoader.trim().length>0) {
			attribs.dLoader=obj.data_dLoader;	
		}if (obj.data_rspLoc && obj.data_rspLoc.trim().length>0) {
			attribs.rspLoc=obj.data_rspLoc;	
		}if (obj.data_dPosition && obj.data_dPosition.trim().length>0) {
			attribs.dPosition=obj.data_dPosition;	
		}if (obj.data_jFunc && obj.data_jFunc.trim().length>0) {
			attribs.jFunc=obj.data_jFunc;
			fn = window[attribs.jFunc];attribs.jFunc=fn;
			fnExists = typeof fn === 'function';
			if(!fnExists){
                msg+='Html Form Attribute "data-jFunc" Function not defined.\n';
			}
		}
	if (msg){
	    if (!i_getObj("xalertText"))
        SweetInfo("",msg,"warning");
	}else{
		if (obj.getAttribute("data-jConfirm")) {
			if (obj.getAttribute("data-jConfirm")=='true') {
				var title="Confirm";
				var msg="Do you want to continue ? ";
				var ybtn="Yes";
				var ntbn="No";
				if (obj.getAttribute("data-jCTitle") && obj.getAttribute("data-jCTitle").trim().length>0) {
						title=obj.getAttribute("data-jCTitle");	
				}
				if (obj.getAttribute("data-jCMsg") && obj.getAttribute("data-jCMsg").trim().length>0) {
						msg=obj.getAttribute("data-jCMsg");	
				}
				if (obj.getAttribute("data-jCYbtn") && obj.getAttribute("data-jCYbtn").trim().length>0) {
						ybtn=obj.getAttribute("data-jCYbtn");	
				}
				if (obj.getAttribute("data-jCNbtn") && obj.getAttribute("data-jCNbtn").trim().length>0) {
						ntbn=obj.getAttribute("data-jCNbtn");	
				}
				if(!jFunc)jFunc=null;
				xConfirm(title,msg,ybtn,ntbn,"XMLajxJsn('"+this+"','"+aUrl+"','"+data+"',"+XJAStatus+",'"+dLoader+"','"+rspLoc+"','"+dPosition+"',"+jFunc+")");
				
			}else{
				XMLajxJsn(obj, aUrl, data, attribs);
			}
		}else{
			XMLajxJsn(obj, aUrl, data, attribs);
		}
	}
}

function XJACleaner() {
    rmChild('xalertText');
    rmChild('xwrapper');
}

function SweetInfo(s_title,s_content,s_icon,s_action) { 
    swal.resetDefaults();
    swal({
      title: s_title,
      text: s_content,
      type: s_icon,
      showCancelButton: false,
      confirmButtonText: 'OK',
    }).then(function() { // Option Action when ok is click
        if (s_action) {
            eval(s_action);
        }
    }, function(dismiss) {// dismiss can be 'cancel', 'overlay', 'close', 'timer'
        if (s_action) {
            eval(s_action);
        }
    });
}

function SweetConfirm(s_title,s_content,s_icon,y_text,n_text,y_action,n_action,jPage,rspLoc) {
    swal.resetDefaults();
    swal({
      title: s_title,
      text: s_content,
      type: s_icon,
      showCancelButton: true,
      reverseButtons: true,
      padding: 17,
      confirmButtonText: y_text,
      cancelButtonText: n_text,
    }).then(function() {
        if (jPage && i_getObj(rspLoc)) {
            i_getObj(rspLoc).innerHTML=jPage;
            binder();
        }
        if(y_action){eval(y_action);}
    }, function(dismiss) {// dismiss can be 'cancel', 'overlay', 'close', 'timer'
       if (n_action){eval(n_action);}
    });
}

function XJACmsg(obj,response,attribs) {
	var icon="info";
    var jPage=null;
    var rm_cuva=true;
    var Eval=null;
    try
	{
		var jObject = JSON.parse(response);
		if (jObject.jEval) {
            Eval=jObject.jEval;
		}
		if (jObject.jMsg) {
                if (jObject.jMsg.icon) {     
                    if (jObject.jMsg.icon=="good") {if(!jObject.jMsg.title){jObject.jMsg.title="Well Done!";}if(!jObject.jMsg.content){jObject.jMsg.content="Selected record has been <span class='hlr'>Updated</span>.";}icon = "success";}
                    else if (jObject.jMsg.icon=="deleted"){
                        rPagiAct(i_getObj("header-search"));
                        if(!jObject.jMsg.title){jObject.jMsg.title="Deleted!";}if(!jObject.jMsg.content){jObject.jMsg.content="Selected record(s) has been <span class='hlr'>Deleted</span>.";}icon = "success";
                        }
                    else if (jObject.jMsg.icon=="hkr") {if(!jObject.jMsg.title){jObject.jMsg.title="Security Warning!";}if(!jObject.jMsg.content){jObject.jMsg.content="Someone's trying to <span class='hlr'>Interrupt</span> your work.\nYou will be redirected to default listing.";}icon = "warning";}
                    else if (jObject.jMsg.icon=="print") {icon = "info";
                        if (jObject.jAction) {jObject.jAction="location.href='"+jObject.jAction+"'";}
                    }
                    else {icon = jObject.jMsg.icon;}
                }
                SweetInfo((jObject.jMsg.title || ""),jObject.jMsg.content,icon,(jObject.jAction || null));
		}else if (jObject.jAction){
		    location.href = BASEPATH+jObject.jAction;
		}else if (jObject.jConfirm){
            if (jObject.jConfirm.icon) {
                if (jObject.jConfirm.icon=="dconfirm") {
                    jObject.jConfirm.title="Are you sure?";
                    jObject.jConfirm.content="You will not be able to recover these selected record(s)!";
                    jObject.jButtonY="Yes, Drop it!";
                    jObject.jButtonN="Cancel";
                    icon = "warning";
                }else if (jObject.jConfirm.icon=="renew") {
                    jObject.jConfirm.title="Good Job!";
                    jObject.jConfirm.content="Data has been Added Successfully.<br/>Would you like to <span class='hlr'>Create New</span>?";
                    jObject.jButtonY="Yes, Create";
                    jObject.jButtonN="Close";
                    icon = "success";
                    if (jObject.jUpdatePage){
                        jPage = jObject.jUpdatePage.content;
                        if (jObject.jUpdatePage.jEval) {
                                jObject.jButtonYa=jObject.jUpdatePage.jEval;
                        }
                    }
                }else if (jObject.jConfirm.icon=="reprint") {
                    jObject.jConfirm.icon="success";
                    rm_cuva=false;
                }else{
                    icon = jObject.jConfirm.icon;
                }
            }
            SweetConfirm(jObject.jConfirm.title,jObject.jConfirm.content,icon,jObject.jButtonY,jObject.jButtonN,(jObject.jButtonYa || null),(jObject.jButtonNa || null),jPage,(attribs.rspLoc|| null)); 
		}else if (jObject.jUpdatePage){
			if(attribs.rspLoc && i_getObj(attribs.rspLoc)){
				i_getObj(attribs.rspLoc).innerHTML=jObject.jUpdatePage.content;
				binder();
			}
			if (jObject.jUpdatePage.jEval) {
					eval(jObject.jUpdatePage.jEval);
			}
			if (jObject.jUpdatePage.jAction) {
                window.history.pushState({"html":"","pageTitle":document.title},"", jObject.jUpdatePage.jAction);
			}
		}
		else if (jObject.jUpdateC){
			if(attribs.rspLoc && i_getObj(attribs.rspLoc)){
				i_getObj(attribs.rspLoc).innerHTML=jObject.jUpdateC.content;
			}
		}
        if (attribs.jFunc) {
            attribs.jFunc(obj,jObject,attribs);
        }
        if (Eval && !jObject.showUrl) {
			eval(Eval);
        }
	}
	catch(e)
	{
            if(debugOn)
		console.log(e);
		
	    if(attribs.rspLoc && i_getObj(attribs.rspLoc)) {
		    i_getObj(attribs.rspLoc).innerHTML=response;	
	    }else{
		SweetInfo("XHTTP","Json/Http Response not valid","error","location.reload();");
	    }
	}
    if (obj){
        obj.disabled = false;
        obj=i_getObj("saveIXD");
        if (obj) {
            obj.removeAttribute("style");
            obj.disabled = false;
            if ((icon=="success" || icon=="renew") && rm_cuva) {
                obj.parentNode.removeChild(obj);
                obj=i_getObj("B_FormFx");
                if (obj) {
                    obj.removeAttribute("data-aUrl");
                }
            }
        }
    }
    BaseReload=true;
}

function update_cntrl_selection(opt,id)
	{
        var ids=i_getObj('e51e320dea32e3831f428b7fa62efa8c');
        if(opt<0)ids.value="";
        else if(opt==1)
            {
                if(!ids.value.length>0)
                    {
                        ids.value=id;
                    }
                else if (check_value(ids.value,',',id)==0)
                    {
                        ids.value=ids.value+','+id;
                    }
                    else
                    {
                        ids.value=remove_value(ids.value,',',id);
                    }
            }
        else if(opt==0)
            {
                if (check_value(ids.value,',',id)==1)
                {
                    ids.value=remove_value(ids.value,',',id);
                }
                else
                {
                    if(ids.value.length>0)
                        {
                            ids.value=ids.value+','+id;
                        }
                    else
                        {
                            ids.value=id;				
                        }
                }
            }
	}
	
function toBuildTable(obj,jObject,attribs){
    if (jObject.sTv_Records) {
        var rx=jObject.array.records;
        var i=jObject.start;
        var tv_rs=[];
        while(i<rx.length){ tv_rs.push(rx[i]);i++;}
        window[jObject.sTv_Records]=tv_rs;
    }
    if (jObject.sTx_Records) {
        window[jObject.sTx_Records]=jObject.array.records;
    }   
        
	buildAJX((attribs.rspLoc || null),jObject.array,jObject.showUrl,jObject.perpage,jObject.curpage,jObject.count,jObject.start,jObject.end,jObject.order,jObject.direct,( jObject.onclick || null ),( jObject.ondblclick || null ),jObject.multiselect);
    if (jObject.jEval) {
			eval(jObject.jEval);
	}
    if(i_getObj("lde-table-context")){
        $('#lde-table').bootstrapTable({
            contextMenu: '#lde-table-context',
            contextMenuTrigger: 'both',
            contextMenuButton: '.lde-table-button',
            contextMenuAutoClickRow: true,
            onClickRow: function(row, $el, e){
                if(row._id){
                var rmv=false;
                if($el.hasClass("success")){rmv=true;}
                if(jObject.multiselect){
                    if(!e){
                        $('#lde-table').find('.success').removeClass('success');update_cntrl_selection(-1,row._id.replace("tr",""));
                    }
                    if(rmv && e){
                         $el.removeClass('success');
                         update_cntrl_selection(0,row._id.replace("tr",""));
                    }else{
                         $el.addClass('success');
                         update_cntrl_selection(1,row._id.replace("tr",""));
                    }
                }else{
                     $('#lde-table').find('.success').removeClass('success');
                     update_cntrl_selection(-1,row._id.replace("tr",""));
                     if(!rmv || !e){
                          $el.addClass('success');
                         update_cntrl_selection(1,row._id.replace("tr",""));
                     }
                }}
            },
            beforeContextMenuRow: function(e, row) {
                if(row._id){
                    $("#lde-table-context li a").each(function() {
                        var hrf=$(this).attr('href');
                        var expr=$(this).attr('data-expr');
                        if(hrf){
                            hrf=hrf.split("/");
                            hrf[hrf.length-1]=row._id.replace("tr","");
                            hrf=hrf.join("/");
                            this.href=hrf;
                        }
                        if(expr){
                            var target=$(this).attr('data-target');
                            var def=$(this).attr('data-def');
                            var ttype=$(this).attr('data-type');
                            def= def ? def : 0;
                            var val=0;
                            if(ttype!='string'){
                                val=parseFloat(row[target].replace(",",""));
                            }else{
                                val=row[target];
                            }
                            val= val ? val : def;
                            if(eval(expr.replace(/col/g,val))){
                                this.parentNode.style.display="none";
                            }else {this.parentNode.style.display="block";}
                        }
                    });
                }else{
                    return false;
                }
            },
            onContextMenuItem: function(row, $el){
                var ev=$el.data("click");
                if(ev){
                    ev=ev.replace("this","'"+row._id+"'");
                    eval(ev);
                }
            }
        });
        $(document).trigger("enhance.tablesaw");
    }
    tableHeaderBinder();
    
    var whp=(BASEPATH.substr(0, BASEPATH.length-1))+window.location.pathname;
    var dtax="";
    if (jObject.curpage)dtax+="?cur="+jObject.curpage;
    if (jObject.perpage)dtax+="&per="+jObject.perpage;
    if (jObject.xtype)dtax+="&xtype="+jObject.xtype;
    if (jObject.order)dtax+="&srt="+jObject.order;
    if (jObject.direct)dtax+="&drt="+jObject.direct;
    if (jObject.d_at)dtax+="&d_at="+jObject.d_at;
    if (jObject.d_to)dtax+="&d_to="+jObject.d_to;
    if (jObject.str)dtax+="&str="+jObject.str;
    if (jObject.brxid)dtax+="&brxid="+jObject.brxid;
    if (jObject.upd_showUrl)i_getObj("header-search").data_aUrl=jObject.showUrl;
	window.history.pushState({"html":"","pageTitle":document.title},"", whp+dtax);
}
//{"iFunc",XJAStatus,dLoader:"custom_loader",rspLoc:"records",dPosition:"top",jFunc:,xFunc:};
//XMLajxJsn(obj, url, dataToPost, XJAStatus, dLoader, rspLoc ,dPosition , XJACmsg, toBuildTable)
//function XMLajxJsn(obj, url, dataToPost, returnfunc, funcParam1, funcParam2, funcParam3, funcParam4, funcParam5){
function XMLajxJsn(obj, url, dataToPost, attribs){
	    var AjaxRequest = initMultiHttpRequestAjX(obj,attribs);
        if (!attribs) {attribs={};}
        if (!attribs.xFunc) {attribs.xFunc=XJACmsg;}
		if (AjaxRequest){
			   AjaxRequest.onreadystatechange=function(){checkReadyStateAjX(obj, AjaxRequest, attribs);}
			   if( BASEPATH && BASEPATH!="" )
			   {
				   AjaxRequest.open('POST', BASEPATH + url, true);
                   AjaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			   }else{
				   AjaxRequest.open('POST', url, true);
                   AjaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			   }
			AjaxRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			AjaxRequest.send(dataToPost+"&_token="+BASE_TKO);
		}else {
            SweetInfo("XMLHTTP","Your browser does not support XMLHTTP.","error");
		}
	}
//RPT
//function XMLajxRPT(obj, dataToPost, returnfunc, funcParam1, funcParam2, funcParam3, funcParam4, funcParam5){
function XMLajxRPT(obj, dataToPost, attribs){
		var AjaxRequest = initMultiHttpRequestAjX(obj,null);
        if (!attribs) { attribs={}; }
        if (!attribs.xFunc) {attribs.xFunc=XJACmsg;}
        attribs.PrintControl=true;
		if (AjaxRequest){
                AjaxRequest.onreadystatechange=function(){checkReadyStateAjX(obj, AjaxRequest, attribs);}
                AjaxRequest.open('POST', window.location.protocol+'//'+'localhost:225/', true);
                AjaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			AjaxRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			AjaxRequest.send(dataToPost);
		}else {
            SweetInfo("XMLHTTP","Your browser does not support XMLHTTP.","error");
		}
}
function initMultiHttpRequestAjX(obj,attribs){
	var AjaxRequest=null;
	if (typeof ActiveXObject != 'undefined') {
	    AjaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
	}else if (typeof XMLHttpRequest != 'undefined') {
	    AjaxRequest = new XMLHttpRequest();
	}if (attribs && attribs.dLoader) {
	    var idclass=attribs.dLoader.split(',');
	    if (idclass.length>1 && idclass[0].trim().length>0) {
            if (i_getObj(idclass[0])) {
                if(!i_getObj(idclass[0]).getAttribute("class")){
                    i_getObj(idclass[0]).setAttribute("class",idclass[1]);
                }else{
                    i_getObj(idclass[0]).classList.add(idclass[1]);
                }
            }else if(document.getElementsByClassName(idclass[0])){
                var classes=document.getElementsByClassName(idclass[0]);
                classes[0].classList.add(idclass[1]);
            }
	    }else if(obj){
            if (!obj.getAttribute("class")) {
                obj.setAttribute("class",idclass[0]);
            }else{
                obj.classList.add(idclass[0]);
            }
	    }
	}else{
	    loadNotice();
	}return AjaxRequest;
}

function loadNotice(e) {
    if(!e){e=loadNoticeMsg}if(e==""){e=" Working ... "}rmChild("loadNotice");var t=document.createElement("div");t.style.width="100%";t.style.textAlign="center";t.style.position="fixed";t.style.top="60%";t.style.left=0;t.style.opacity="0.70";t.id="loadNotice";t.innerHTML=e;document.body.appendChild(t);
}

function checkReadyStateAjX(mobj, AjaxRequest, attribs){
	obj = AjaxRequest;
	if(AjaxRequest)
	{   if(obj.readyState == 4)
		{   if (attribs && attribs.dLoader) {
				var idclass=attribs.dLoader.split(',');
				if (idclass.length>1 && idclass[0].trim().length>0) {
				    if (i_getObj(idclass[0])) {
					    i_getObj(idclass[0]).classList.remove(idclass[1]);
				    }else if(document.getElementsByClassName(idclass[0])){
					    var classes=document.getElementsByClassName(idclass[0]);
					    classes[0].classList.remove(idclass[1]);
				    }
				}else{
				    if (!mobj.getAttribute("class")) {
					    mobj.setAttribute("class",idclass[0]);
				    }else{
                        mobj.setAttribute("class",mobj.getAttribute("class").replace(attribs.dLoader,""));
				    }
				}			
			}else{
				setTimeout('rmChild("loadNotice")',0);
			}if(obj.status == 200)
			{   if (attribs.iFunc) {
                    var tempFunc=function() { attribs.iFunc(mobj, AjaxRequest, attribs); }
                }else{
                    var tempFunc=function() { XJAStatus(mobj, AjaxRequest, attribs); }
                }
			  return tempFunc();
			  AjaxRequest = null;
			}else{
				if (obj.status == 404 ) {
                    SweetInfo("",BaseErMsg,"info","location.reload();");//ajaxerror(404);
				}else if (obj.status == 500 ) {
                    SweetInfo("",BaseErMsg,"info","location.reload();");
				}else if (obj.status == 0 ) {
                    if (attribs.PrintControl) {
                        SweetInfo("Printer Action Control","Open Printer Service and Print your Data Again.","info","ajaxerror(0);");
                    }else{
                        SweetInfo("",BaseErMsg,"info","location.reload();");
                    }
				}
				AjaxRequest = null;
			}
		}
	}
	return false;	
}
	
//function XJAStatus(obj, AjaxRequest, funcParam1, funcParam2, funcParam3, funcParam4){
function XJAStatus(obj, AjaxRequest, attribs){	
	if(!AjaxRequest){
	    AjaxRequest = httpRequest;	
	}
    if(AjaxRequest.readyState==4 && AjaxRequest.status==200){
        var dv = AjaxRequest.responseXML;
            if (attribs.xFunc) {
                return attribs.xFunc(obj,AjaxRequest.responseText,attribs);
            }
            else if ((!dv)){
                if (!attribs.rspLoc){
                    var dv = document.createElement('pre'); // create dynamically div tag
                    dv.setAttribute('id',"xmlDebugLine");       //give id to it
                    dv.innerHTML=AjaxRequest.responseText;
                    execJS(dv,1);
                }else{
                    if(i_getObj(attribs.rspLoc)) {
                        obj=i_getObj(attribs.rspLoc);
                    }
                    if (attribs.dPosition && attribs.dPosition.toLowerCase()=='top') {
                       obj.innerHTML=AjaxRequest.responseText+obj.innerHTML;	
                    }else if(attribs.dPosition && attribs.dPosition.toLowerCase()=='bottom'){
                       obj.innerHTML+=AjaxRequest.responseText;
                    }else{
                       obj.innerHTML=AjaxRequest.responseText;	
                    }
                   binder();
                }
            }else{
                dv=dv.documentElement;
                for (j=0;j<dv.childNodes.length;j++) {
                    if (dv.childNodes[j].nodeName=='script'){
                        eval(dv.childNodes[j].firstChild.nodeValue);
                    }
                }
            }	
    }
	return false;
}

function buildAJX(obj,array,show_url,perpage,curpage,count,start,end,order,direct,onclick,ondblclick,multiselect){
	curpage=parseInt(curpage);
	perpage=parseInt(perpage);
	devElement="<table id=\"lde-table\" class=\"tablesaw table-striped table-bordered table-hover\" cellspacing=\"0\" data-tablesaw-mode=\"columntoggle\" data-tablesaw-mode-switch data-tablesaw-minimap><thead><tr><th class=\"align-center bright bleft tablesaw-priority-"+(array['fields'].length+1)+"\" width=\"3\" data-tablesaw-priority=\""+(array['fields'].length+1)+"\">#</th>";
	/*if (multiselect) {//width=\"3%\"
		devElement+="<th class=\"align-center np bright\" ><input type=\"checkbox\" id=\"chk_parent\" name=\"chk_parent\" onclick=\"change_all_tr_bg()\"/></th>";
	}*/i=0;
	while(i<array['fields'].length){
	    devElement+="<th data-tablesaw-priority=\""+(i+1)+"\" ";//persist
	    if(array['sortable'].indexOf(array['fields'][i])>-1){
			devElement+="class='#rTableAJXS";
			devElement+=' sorting';
	    }else devElement+=' sorting';
	    if(order==array['fields'][i] && direct=='asc'){devElement+=' sorting_desc';}
	    if(order==array['fields'][i] && direct=='desc'){devElement+=' sorting_asc';}
        if(array["alignment"] && array["alignment"][i]){devElement+=' '+array["alignment"][i];}
            //width='"+array['width'][i]+"%' 
            devElement+="' data-aUrl='"+show_url+"' data-rspLoc='records' data-jFunc='toBuildTable'";
        if(array['sortable'].indexOf(array['fields'][i])>-1){
            if(direct=='asc')devElement+=' data-direct="desc"';
            else devElement+=' data-direct="asc"';
                devElement+=' data-order="'+array['fields'][i]+'"';
	    }
	    devElement+=">"+array['titles'][i]+"</th>";
        i++;
	}
    //width="15"
	if (array["button"])
	devElement+='<th class="np"></th>';
	devElement+='</tr></thead><tbody id="lde-table-body">';
	cnt=cnter=0;
	all_id=null;i=0;
        if(array['records']){
	while(i<array['records'].length)
		{
		if(cnt>=start && cnt<end){
			if(all_id)all_id+=','+array['records'][i]['xid'];else all_id=array['records'][i]['xid'];
			devElement+='<tr ';
			if(cnt%2==0){devElement+='class="odd"';}
			devElement+='id="tr'+array['records'][i]['xid']+'"';
			
            /*if (ondblclick!=null) {
                devElement+=' ondblclick="'+ondblclick+'(\''+array['records'][i]['xid']+'\')"';
            }*/
            
			devElement+="><td class=\"align-center bleft\">"+(cnt+1)+"</td>";
            
			/*if(multiselect){
				devElement+="<td class=\"align-center np\"><input type=\"checkbox\" ";
                if(multiselect || onclick){
                    devElement+=' onclick="'+onclick+'(\''+array['records'][i]['xid']+'\')"';
                }
                devElement+="id=\""+array['records'][i]['xid']+"\" name=\"chk\" /></td>";
			} */
			ii=0;
			while(ii<array['fields'].length){
				if (parseFloat(array['records'][i][array['fields'][ii]])!=0) {
					devElement+="<td class='t-l tablesaw-priority-"+(ii+1);
                    if(array["alignment"] && array["alignment"][ii]){devElement+=" "+array["alignment"][ii]+"'";}
					devElement+="'>"+stripslashes(array['records'][i][array['fields'][ii]])+"</td>";
				}else{
				devElement+="<td class='t-l tablesaw-priority-"+(ii+1)+"' title=\"\"></td>";
				}
				ii++;
			}
			if (array["button"]) {
			    devElement+="<td class=\"np btn-tbl\" title=\"\">"+'<div class="btn-group btn-grid" ';
			    if (array['btnminw']) {
                    devElement+=" style='min-width:"+array['btnminw']+"px;'";
			    }
			    devElement+='>';
			    if(array["eval1"])
                    eval(array["eval1"]);
			    if (array["eval2"]) {//code
                    devElement+='<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"><span class="caret"></span><span class="sr-only">Toggle Dropdown</span></button>';
                    devElement+='<ul class="dropdown-menu" role="menu">';
                    eval(array["eval2"]);
				devElement+='</ul>';	
			    }
			    devElement+='</div>';
			    devElement+="</td>";
			}
			devElement+="</tr>";
			}
		cnt++;
		i++;
		}
	}
	if (array["Footer"]) {
	    devElement+=array["Footer"];
	}
        devElement+='</tbody></table><input type="hidden" id="d023d77a133b04056ef144d2184" value="'+all_id+'" size="50" /><input type="hidden" id="e51e320dea32e3831f428b7fa62efa8c" value="" size="50"/>';
	if(!all_id)devElement+="<div class=\"empty-record\" style=\"display: block;	height: 35px;margin-bottom: 5px;\">No matching records found.</div>";
                    
                page=parseInt(count/perpage);
                if((count/perpage)>page){
                        page+=1;
                }
                if((count/perpage)==page){
                         cnter=1;
                    //if(count>1)page+=1
                }
		devElement+="<div class=\"row-lg np\">"
			devElement+="<div class=\"col-lg-6 col-md-6\">";
				devElement+="<div class=\"dataTables_paginate paging_bootstrap\">";
					devElement+="<ul class=\"pagination\">";
					if (curpage>1) {
						       devElement+="<li><a class=\"#rTableAJXS\" data-jFunc=\"toBuildTable\" data-aUrl=\""+show_url+"\" data-rspLoc=\"records\" data-page=\""+(curpage-1)+"\">&#x21d0; Previous</a></li>";
					}else{
						devElement+="<li class=\"prev disabled\"><a>&#x21d0; Previous</a></li>";
					}
						view=cnt;
						i=cnt=1;limit=6;
						if (curpage>1)cnt=curpage;
						topage=page-curpage;
						if (topage<limit) {
							tolimit=((limit-1)-topage);
							cnt=curpage-tolimit;
							if (cnt<=0)cnt=1;
						}
						
						while(cnt<=page && i<=limit)
						{
						    if(curpage==cnt){devElement+="<li class=\"active\"><a>"+cnt+"</a></li><input type=\"hidden\" id=\"selected_page\" value=\""+cnt+"\"/>";}
						    else {
						       devElement+="<li><a class=\"#rTableAJXS\" data-jFunc=\"toBuildTable\" data-aUrl=\""+show_url+"\" data-rspLoc=\"records\" data-page=\""+cnt+"\">"+cnt+"</a></li>";
						    }
						    cnt++;
						    i++;
						}
						
					if(cnter==1){maxPage=cnt}else{maxPage=cnt-1;}
					if ((curpage+1)<=maxPage && page>0) {
						devElement+="<li><a class=\"#rTableAJXS next\" data-jFunc=\"toBuildTable\" data-aUrl=\""+show_url+"\" data-rspLoc=\"records\" data-page=\""+(curpage+1)+"\">&nbsp;&nbsp;Next &nbsp;&#x21d2;</a></li>";
					}else{
						devElement+="<li class=\"next disabled\"><a>&nbsp;&nbsp;Next &nbsp;&#x21d2;</a></li>";
					}
					devElement+="<li id='lde-table-np'><input type='text' value='"+(curpage)+"' class=\"#rTablePagerAJXS\" data-page=\"this.value\"data-aUrl=\""+show_url+"\" data-rspLoc=\"records\" data-jFunc=\"toBuildTable\"  style='width:40px;text-align:center;padding: 2px;margin: 3px;'/>/ "+(page)+"</li>"
					devElement+="</ul>";
				devElement+="</div>";
			devElement+="</div>";
			devElement+="<div class=\"col-lg-6 col-md-6\">";
			showingTo=(curpage*perpage)//
			showingFrom=((curpage-1)*perpage)+1;
			if (showingTo>count)showingTo=count;
			if (showingFrom<=0)showingFrom=1;
				devElement+="<div class=\"dataTables_info\" id=\"recordsx_info\"><span>Showing "+(showingFrom)+" to "+(showingTo)+" of "+(count)+" entries &nbsp;";
				
					devElement+=" By: </span>";
							devElement+="<select data-jFunc=\"toBuildTable\" data-aUrl=\""+show_url+"\" data-rspLoc=\"records\" name=\"page_cnt\" class=\"#pgChangeAJXS input-short align-center form-control\" id=\"page_cnt\" >";
		i=0;
		while(i<array['pager'].length){
						devElement+="<option "; if(perpage==array['pager'][i]){ devElement+= " Selected";}
						devElement+='>'+array['pager'][i].toString()+"</option>";
		    i++;    
		    }
					devElement+="</select><div class=\"clear\"></div>";
				devElement+="</div>";//table info
			devElement+="</div>";//col six
			devElement+="<input type=\"hidden\" id=\"max_page\" value='"+(maxPage)+"' /> ";
		devElement+="</div>";//row
		
		//devElement+="</div></div>";
		if (i_getObj(obj)) {
			i_getObj(obj).innerHTML=devElement;
            i_getObj("d023d77a133b04056ef144d2184").jXval=i_getObj("d023d77a133b04056ef144d2184").value;
            i_getObj("d023d77a133b04056ef144d2184").removeAttribute("value");
		}else{
		    //if (!i_getObj("xalertText"))
			//xalert("Information","Html Attribute 'data-rspLoc' Not Found");
            SweetInfo("","Html Attribute 'data-rspLoc' Not Found.","error");
		}
	}

function toBuildTablePreview(obj,jObject,attribs){
    try{
        if(jObject.jEval)
        {
            buildAJXPreview(obj,jObject.array);
        }else{
            printToPDF(jObject.array);
        }
    }catch(e){
        //document.body.innerHTML+=response;
    }
}
function buildAJXPreview(obj,array){
	devElement="<table class=\"table-bordered\" cellspacing=\"0\"><thead><tr><th width=\"3\">#</th>";
	i=0;
	while(i<array['fields'].length){
	    devElement+="<th width='"+array['width'][i]+"%' ";
	    devElement+=">"+array['titles'][i]+"</th>";
        i++;
	}
	devElement+='</tr></thead><tbody>';
	cnt=cnter=0;i=0;
        if(array['records']){
	while(i<array['records'].length)
		{
			devElement+="<tr><td>"+(cnt+1)+"</td>";
			ii=0;
			while(ii<array['fields'].length){
				if (array['records'][i][array['fields'][ii]]) {
					devElement+="<td ";
					devElement+=">"+stripslashes(array['records'][i][array['fields'][ii]])+"</td>";
				}else{
				devElement+="<td title=\"\"></td>";
				}
				ii++;
			}
			devElement+="</tr>";
		cnt++;
		i++;
		}
	}
    devElement+='</tbody></table>';
	if(i==0)devElement+="<div class=\"row\"><div class=\"col-xs-12\"><div class=\"empty-record\" style=\"display: block;	height: 35px;\">Empty Record!</div></div></div>";
                
		document.body.innerHTML+=devElement;
        rmChild("loadNotice");
        window.print();
	}

function sRecordsAJXS(url,curpage,perpage,attribs)
	{
        if (!attribs) {attribs={rspLoc:"records",jFunc:toBuildTable};}
        var xtype="";var addSt="";
		if(i_getObj('page_cnt') && i_getObj('page_cnt').value && perpage==0)
		{ perpage=i_getObj('page_cnt').value; }
        if (i_getObj("searchType")){
            xtype = i_getObj('searchType').value;
        }
		var dataToPost="curpage="+curpage+"&perpage="+perpage+"&type="+( xtype|| null);
		if (i_getObj('date_atx')) {
		    addSt="&date_at="+i_getObj('date_atx').value;
		}
		if (i_getObj('date_tox')) {
		    addSt+="&date_to="+i_getObj('date_tox').value;
		}
		dataToPost+=addSt;
		if (i_getObj("valx1"))
		    dataToPost+="&valx1="+i_getObj("valx1").value;
		if (i_getObj("valx2"))
		    dataToPost+="&valx2="+i_getObj("valx2").value;
		if(i_getObj('header-search') && i_getObj('header-search').value){
		    dataToPost+="&srch_str="+i_getObj('header-search').value;	
		}
        if (i_getObj("branch_xyz")) {
            dataToPost+="&brxid="+i_getObj("branch_xyz").value;
        }
		if(i_getObj('daefffb93e6c3be7136ba40edae4f2') && i_getObj('daefffb93e6c3be7136ba40edae4f2').value){
		    if(i_getObj('header-search') && i_getObj('header-search').value){
		    url+='&'+"b4688aaaaf17fad03225929fe56ago="+i_getObj('b4688aaaaf17fad03225929fe56ago').value+"&daefffb93e6c3be7136ba40edae4f2="+i_getObj('daefffb93e6c3be7136ba40edae4f2').value;
		    }
		    else{
		    url=url+'/?'+"b4688aaaaf17fad03225929fe56ago="+i_getObj('b4688aaaaf17fad03225929fe56ago').value+"&daefffb93e6c3be7136ba40edae4f2="+i_getObj('daefffb93e6c3be7136ba40edae4f2').value;		
		    }
		}
		XMLajxJsn(null, url, dataToPost, attribs);
	}
function eRecordsAJX(obj)
	{
		var aUrl="";var data="";attribs={};var msg="";
		var id=i_getObj("e51e320dea32e3831f428b7fa62efa8c").value;
		var data="b80bb779b4ca7bb18575505eb94="+id+"&e135d843bb085929e88e997f38b="+(getFirstElement(id,',') || '');
		
				if (obj.data_aUrl && obj.data_aUrl.trim().length>0) {
					aUrl=obj.data_aUrl;
				}else{
					msg+='Html Form Attribute "data-aUrl" not defined.\n';
				}
				if (obj.data_dLoader && obj.data_dLoader.trim().length>0) {
					attribs.dLoader=obj.data_dLoader;	
				}
				if (obj.data_rspLoc && obj.data_rspLoc.trim().length>0) {
					attribs.rspLoc=obj.data_rspLoc;	
				}
				if (obj.data_dPosition && obj.data_dPosition.trim().length>0) {
					attribs.dPosition=obj.data_dPosition;	
				}
				if (obj.data_jFunc && obj.data_jFunc.trim().length>0) {
					attribs.jFunc=obj.data_jFunc;
					fn = window[attribs.jFunc];attribs.jFunc=fn;
					fnExists = typeof fn === 'function';
					if(!fnExists){
					msg+='Html Form Attribute "data-jFunc" Function not defined.\n';
					}
				}
		if (msg){
            SweetInfo("",msg,"error");
		}else{
			XMLajxJsn(obj, aUrl, data, attribs)
		}
	}

function eBtnAJX(obj,url)
	{
		obj=obj.replace("tr",'');
		var data="e135d843bb085929e88e997f38b="+obj;
		XMLajxJsn(null, url, data)
	}

function dBtnAJX(obj,url)
	{
		obj=obj.replace("tr",'');
		var data="b80bb779b4ca7bb18575505eb94="+obj+"&d2bcc286168bf8e040885c5cb7b6=0";
		XMLajxJsn(null, url, data)
	}

function crTbill(obj,url)
    {
		location.href=BASEPATH+url+"/"+obj;
    }

function dRecordsAJX(obj)
	{
		var aUrl="";var data="";var attribs={};var msg="";
		var data="b80bb779b4ca7bb18575505eb94="+i_getObj("e51e320dea32e3831f428b7fa62efa8c").value+"&d2bcc286168bf8e040885c5cb7b6=0";
				if (obj.data_aUrl && obj.data_aUrl.trim().length>0) {
					aUrl=obj.data_aUrl;
				}else{
					msg+='Html Form Attribute "data-aUrl" not defined.\n';
				}
				if (obj.data_dLoader && obj.data_dLoader.trim().length>0) {
					attribs.dLoader=obj.data_dLoader;	
				}
				if (obj.data_rspLoc && obj.data_rspLoc.trim().length>0) {
					attribs.rspLoc=obj.data_rspLoc;	
				}
				if (obj.data_dPosition && obj.data_dPosition.trim().length>0) {
					attribs.dPosition=data_dPosition;	
				}
				if (obj.data_jFunc && obj.data_jFunc.trim().length>0) {
					attribs.jFunc=obj.data_jFunc;
					fn = window[attribs.jFunc];attribs.jFunc=fn;
					fnExists = typeof fn === 'function';
					if(!fnExists){
                        msg+='Html Form Attribute "data-jFunc" Function not defined.\n';
					}
				}
		if (msg){
            SweetInfo("",msg,"error");
		}else{
			XMLajxJsn(obj, aUrl, data, attribs)
		}
	}
function tdRecordsAJX(aUrl)
	{
		var data="b80bb779b4ca7bb18575505eb94="+i_getObj("e51e320dea32e3831f428b7fa62efa8c").value+"&d2bcc286168bf8e040885c5cb7b6=1";
		XMLajxJsn(null, aUrl, data)
	}	

function tdRecordsAJXOne(aUrl,valx)
	{
		var data="b80bb779b4ca7bb18575505eb94="+valx+"&d2bcc286168bf8e040885c5cb7b6=1";
		XMLajxJsn(null, aUrl, data)
	}
function processAjaxData(response, urlPath){
		i_getObj("content").innerHTML = response.html;
		document.title = response.pageTitle;
		window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
	}
	
function chng_page(url,tp)
	{
		var id=i_getObj("e51e320dea32e3831f428b7fa62efa8c").value;
		var datastring="b80bb779b4ca7bb18575505eb94="+id+"&rcrdtp="+tp+"&e135d843bb085929e88e997f38b="+getFirstElement(id,',');
		XMLajxJsn(null, url, datastring)
	}

function chng_rcrd(url,responseId)
	{
		var datastring="rcrdtp=3";
		xmlXsend(url,datastring,responseId);
		return false;
	}
	
function cur(url,responseId)
	{
		var datastring;
		xmlXsend(url,datastring,responseId);
		return false;
	}
	
function change_tr_bg(id)
	{
        var ids=i_getObj('e51e320dea32e3831f428b7fa62efa8c');
		if(i_getObj('chk_parent'))
            i_getObj('chk_parent').checked=false;
        if (i_getObj(id)) {
            if(i_getObj(id).checked==true)
                {
                    if(!ids.value.length>0)
                        {
                            ids.value=id;
                        }
                    else if (check_value(ids.value,',',id)==0)
                        {
                            ids.value=ids.value+','+id;
                        }
                        else
                        {
                            i_getObj(id).checked=false;
                            ids.value=remove_value(ids.value,',',id);
                        }
                }
            else if(i_getObj(id).checked==false)
                {
                    if (check_value(ids.value,',',id)==1)
                    {
                        ids.value=remove_value(ids.value,',',id);
                    }
                    else
                    {
                        i_getObj(id).checked=true;
                        if(ids.value.length>0)
                            {
                                ids.value=ids.value+','+id;
                            }
                        else
                            {
                                ids.value=id;				
                            }
                    }
                }
                
            }
	}
function change_all_tr_bg()
	{
		i_getObj('e51e320dea32e3831f428b7fa62efa8c').value='';
		var value=i_getObj('d023d77a133b04056ef144d2184').jXval;
		var ind=',';
		if(i_getObj('chk_parent').checked==true)
		{
		var iii=0;
		for(ii=0;ii<=value.length;ii++)
		{
		if(value[ii]==ind || ii==value.length)
			{
			var to='';
			for(iii;iii<ii;iii++)
				{
				to=to+value[iii];
				}
			if (i_getObj(to)) {
                i_getObj(to).checked=true;
            }
			if(i_getObj('e51e320dea32e3831f428b7fa62efa8c').value.length>0)
				{
					i_getObj('e51e320dea32e3831f428b7fa62efa8c').value=i_getObj('e51e320dea32e3831f428b7fa62efa8c').value+','+to;
				}
			else
				{
					i_getObj('e51e320dea32e3831f428b7fa62efa8c').value=to;				
				}
				iii++;
			}
		}
		}
		else if(i_getObj('chk_parent').checked==false)
		{
		var iii=0;
		for(ii=0;ii<=value.length;ii++)
		{
		if(value[ii]==ind || ii==value.length)
			{
			var to='';
			for(iii;iii<ii;iii++)
				{
				to=to+value[iii];
				}
				if (i_getObj(to)) {
                    i_getObj(to).checked=false;
                }
				iii++;
			}
		}	
		}
	}
	
function refresh_selected(value,ind)
	{
		value=i_getObj('e51e320dea32e3831f428b7fa62efa8c').value;
		var iii=0;
		var i=0;
		for(ii=0;ii<=value.length;ii++)
		{
		if(value[ii]==ind || ii==value.length)
			{
			var to='';
			for(iii;iii<ii;iii++)
				{
				to=to+value[iii];
				}
				
				i_getObj('tr'+to).style.backgroundColor="#357000";
				i_getObj(to).checked=false;
				if (i==0)
					{
					i++;
					i_getObj('e51e320dea32e3831f428b7fa62efa8c').value=to;				
					}
				else if(i_getObj('e51e320dea32e3831f428b7fa62efa8c').value.length>0)
					{
					i_getObj('e51e320dea32e3831f428b7fa62efa8c').value=i_getObj('e51e320dea32e3831f428b7fa62efa8c').value+','+to;
					}
				else
					{
					i_getObj('e51e320dea32e3831f428b7fa62efa8c').value=to;				
					}
				iii++;
			}
		}
		return true;
	}
	
//functions-if not using built-in functions
function return_array(value,ind)
	{
		if(value!=null)
		{
		var pass_value=[];
		var up=0;
		var iii=0;
		for(ii=0;ii<=value.length;ii++)
		{
		if(value[ii]==ind || ii==value.length)
			{
			var to='';
			for(iii;iii<ii;iii++)
				{
				to=to+value[iii];
				}
				iii++;
				pass_value[up]=to;		
				up++;
			}
		}
		return pass_value;
		}
		else
		{
		return null;	
		}
	}
	
function remove_value(value,ind,to_remove)
	{	
		var pass_value=return_array(value,ind);
		var cntrl=0;
		var to_return;
		for(ii=0;ii<pass_value.length;ii++)
		       {
			if(to_remove==pass_value[ii])
			       {
			       }
			else
			       {
			       if(cntrl==0)
				{
				to_return=pass_value[ii];
				cntrl=1;			
				}
				else
				{
				to_return+=','+pass_value[ii];	
				}
			       }
			}
		if((ii-1)==0)
		{
		return null;	
		}
		else
		{
		return to_return;
		}       
	}
	
function check_value(value,ind,to_check)
	{	
		var pass_value=return_array(value,ind);
		var cntrl;
		for(ii=0;ii<pass_value.length;ii++)
		       {
			if(to_check==pass_value[ii])
			       {
				cntrl=1;
				return cntrl;
			       }
			else
			       {
				cntrl=0;
			       }
		       }
		return cntrl;
	}
	
function getNextElement(value,ind,cur_element)
	{	
		var pass_value=return_array(value,ind);
		if(pass_value!=null)
		{
		var to_return=null;
		for(ii=0;ii<pass_value.length;ii++)
		       {
			if(cur_element==pass_value[ii] && (ii+1)<pass_value.length)
			       {
				 to_return=pass_value[ii+1];
			       }
		       }
		return to_return;
		}
		else
		{
		return null;
		}
	}
	
function getPreviousElement(value,ind,cur_element)
	{	
		var pass_value=return_array(value,ind);
		if(pass_value!=null)
		{
		var to_return=null;
		for(ii=0;ii<pass_value.length;ii++)
		       {
			if(cur_element==pass_value[ii] && (ii-1)>=0)
			       {
				 to_return=pass_value[ii-1];
			       }
		       }
		return to_return;
		}
		else
		{
		return null;
		}
	}
	
function count_array(value,ind)
	{
		var cnt=0;
		if(value.length>0)
		{
		for(ii=0;ii<=value.length;ii++)
		{
		if(value[ii]==ind || ii==value.length)
			{
			cnt++;
			}
		}
		return cnt;
		}
		else
		{
		return 0;	
		}
	
	}
	
function getFirstElement(value,ind)
	{
		if(value!=null)
		{
		var pass_value=[];
		var up=0;
		var iii=0;
		var cntrl=0;
		for(ii=0;ii<=value.length && cntrl!=1;ii++)
		{
		if(value[ii]==ind || ii==value.length)
			{
			var to='';
			for(iii;iii<ii;iii++)
				{
				to=to+value[iii];
				cntrl=1;
				}
				
			}
		}
		if(cntrl==1)
		{ return to; }
		else
		{ return null;}
		}
		else
		{
		return null;	
		}
	}
	
function replacethis(value,ind,rep)
	{
	var passvalue='';
	for(i=0;i<value.length;i++)
		{
		if(value[i]==ind)
			{
			passvalue=passvalue+rep;
			}
		else
			{
			passvalue=passvalue+value[i];	
			}
		}
	return passvalue;
	}
function addslashesx(str) {
    str = str.replace(/\\/g, '\\\\');
    str = str.replace(/\'/g, '\\\'');
    str = str.replace(/\"/g, '\\"');
    str = str.replace(/\0/g, '\\0');
    return str;
}
 
function stripslashes(str) {
    if(typeof str != "string"){
        if (str==null) {
            str="";
        }else{
            str=str.toString();
        }
    }
    str = str.replace(/\\'/g, '\'');
    str = str.replace(/\\"/g, '"');
    str = str.replace(/\\0/g, '\0');
    str = str.replace(/\\\\/g, '\\');
    return str;
}

function str_pad(input, pad_length, pad_string, pad_type) {
            var half = '',
              pad_to_go;
          
            var str_pad_repeater = function(s, len) {
              var collect = '',
                i;
          
              while (collect.length < len) {
                collect += s;
              }
              collect = collect.substr(0, len);
          
              return collect;
            };
          
            input += '';
            pad_string = pad_string !== undefined ? pad_string : ' ';
          
            if (pad_type !== 'STR_PAD_LEFT' && pad_type !== 'STR_PAD_RIGHT' && pad_type !== 'STR_PAD_BOTH') {
              pad_type = 'STR_PAD_RIGHT';
            }
            if ((pad_to_go = pad_length - input.length) > 0) {
              if (pad_type === 'STR_PAD_LEFT') {
                input = str_pad_repeater(pad_string, pad_to_go) + input;
              } else if (pad_type === 'STR_PAD_RIGHT') {
                input = input + str_pad_repeater(pad_string, pad_to_go);
              } else if (pad_type === 'STR_PAD_BOTH') {
                half = str_pad_repeater(pad_string, Math.ceil(pad_to_go / 2));
                input = half + input + half;
                input = input.substr(0, pad_length);
              }
            }
          
    return input;
}
function dsblekeys(evt) {
        var e = window.event || evt; // for trans-browser compatibility  
        var charCode = e.which || e.keyCode;
        if(charCode==9){
                return true;
        }
    e.preventDefault();
	return false;
}

function dsbleEnter(evt) {
        var e = window.event || evt; // for trans-browser compatibility  
        var charCode = e.which || e.keyCode;
	if(charCode==13){
            e.preventDefault();
            return false; 
	}
	return true;
}
function isfloat(evt,obj)
    {
        var dec = obj.value.split(".")[1];
        if (dec) {
            dec=dec.length;
        }else{
            dec=0;
        }
        var startPos = obj.selectionStart;
        var e = window.event || evt; // for trans-browser compatibility  
        var charCode = e.which || e.keyCode;
        if (((charCode > 45 && charCode < 58) || (charCode >= 96 && charCode <= 105)) || (charCode == 8 || charCode == 190 || charCode == 110)){
            //obj.value.replace(/[^.]/g, "").length>0
            if (obj.value.indexOf('.') != -1 && (charCode==190 || charCode==110)){


            }else{
                if ((dec>9 && charCode!=8) && startPos>=obj.value.length-10) {
                }else{
                    return true;
                }
            }
        }else if(charCode==9 || charCode==37 || charCode==39){
               return true;
        }
        return false;  
    }
function isNumber(evt)
    {
        var e = window.event || evt; // for trans-browser compatibility  
        var charCode = e.which || e.keyCode;
         if (((charCode > 46 && charCode < 58) || (charCode >= 96 && charCode <= 105)) || charCode == 8){  
            return true;  
        }else if(charCode==9 || charCode==37 || charCode==39){
            return true; 
        }
         return false;
    }
function isCtrl(evt)
    {
        var e = window.event || evt; // for trans-browser compatibility  
        var charCode = e.which || e.keyCode;
        if((charCode==107 || charCode==109) && e.location==3){
            return false; 
        }
        return true;
    }
    
function FCurx(num){
    num = parseFloat(num);
    if (!isNaN(num))
        return num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
    else return "0.00";
}

function FCurxy(num,dc){
    num = parseFloat(num);
    if (!isNaN(num))
        return num.toFixed(dc).replace(/\d(?=(\d{3})+\.)/g, '$&,');
    else return "0.00";
}
function FCurx5(num){
    num = parseFloat(num);
    if (!isNaN(num))
        return num.toFixed(5).replace(/\d(?=(\d{3})+\.)/g, '$&,');
    else return "0.00";
}
function FCurx10(num){
    num = parseFloat(num);
    if (!isNaN(num))
        return num.toFixed(10).replace(/\d(?=(\d{3})+\.)/g, '$&,');
    else return "0.00";
}

function redirectX(jAction) {
    location.href = BASEPATH+jAction
}

function isInArray(array, value) {
    return array.indexOf(value) > -1;
}
function fire() {
    i_getObj('sidebarX').style.display='none';
    i_getObj('wrapperX').style.cssText='margin-left:0 !important;border-left: none !important;'; 
}
function burn() {
    i_getObj('sidebarX').style.display='block';
    i_getObj('wrapperX').style.cssText='0 !important;border-left: 1px solid #d2d6de;'; 
}
//functions-if not using built-in functions
//Additional Utils
function scrollObj(obj) {
            $('html, body').animate({scrollTop: $(obj).offset().top-150}, 250);
    }
function utils_sTz(selector,value_F,def_v,woptField,remoteL,urlx,filter){
        if (i_getObj(selector.replace("#",""))){
            $stz = $(selector).selectize({
                    valueField: value_F || 'idx',
                    labelField: 'text',
                    optionField: woptField || false,
                    remoteLoad: remoteL || false,
                    searchField: ['text','caption'],
                    options: def_v,
                    sortField : 'text',
                    render: {
                            item: function(item, escape) {
                                    var name = $.trim((item.text || ''));
                                    return '<div>' +
                                            (name ? '<span class="name">' + escape(name) + '</span>' : '') +
                                    '</div>';
                            },
                            option: function(item, escape) {
                                    var name = $.trim((item.text || ''));
                                    var label = name || item.caption;
                                    var caption = name ? item.caption : null;
                                    return '<div>' +
                                            '<span class="label">'  + escape(label) + '</span>' +
                                            (caption ? '<span class="caption">' + escape(caption) + '</span>' : '') +
                                    '</div>';
                            }
                    },load: function(query, callback) {
                            if (query.length<1) return callback();
                                $.ajax({
                                    url: BASEPATH + PREFIX +(urlx || '')+'/q_i/' + encodeURIComponent(query),
                                    type: 'POST',
                                    data: "datax_TableI="+JSON.stringify(filter || null),
                                    error: function() {
                                        callback();
                                },
                                success: function(res){
                                    callback(JSON.parse(res));
                                }
                            });
                    }
                    });
            return $stz[0].selectize;
        }
    return false;
    }
//Additional Utils

//grid printing
function p_Preview() {
        xConfirm("Confirm","Open new tab for print preview.","Continue","Cancel","p_P_aY();");
}
function p_P_aY() {
    var obj=document.getElementsByClassName("sorting_asc")[0];
    if (!obj) {
        obj=document.getElementsByClassName("sorting_desc")[0];
    }if (!obj) {
        obj=document.getElementsByClassName("sorting")[0];
    }
    if (obj) {
        var dir=obj.data_direct;
        var dtf="";
        var dtt="";
        if (dir=='asc')dir='desc';else dir='asc';
        if (i_getObj("date_atx")) {
            dtf=i_getObj('date_atx').value;
        }
        if (i_getObj("date_atx")) {
            dtf=i_getObj('date_tox').value
        }
        sRecordsAJXS(obj.data_aUrl+"_p_preview/1?str="+i_getObj("header-search").value+"&xtype="+i_getObj("searchType").value+"&odr="+obj.data_order+"&dr="+dir+"&date_at="+dtf+"&date_to="+dtt,1,0,{jFunc:toBuildTablePreview});
    }else{
        //xalert("Error!","No object and location to get!.");
        SweetInfo("","No object and location to get.","error");
    }
}