var req;var hist=new Array;var nhist=0;    // Obsolete but needed cause outside referencesvar layel,basetag,formnm,finalcod;var hashHist=false;var priLayid='';    // Primary layer// compatMode: BackCompat if no DOCTYPE, o/w CSS1Compat// IE requires DOCTYPE to use onhashchangeif ('onhashchange' in window &&    (navigator.appName != 'Microsoft Internet Explorer' ||     document.compatMode!="BackCompat")) {    window.onhashchange=ax_hashChg;    hashHist=true;    }else {    hashCurrent=document.location.hash;    hashInterval=window.setInterval('ax_chkHashChg()',500);    hashHist=true;    }function ax_chkHashChg() {    if (document.location.hash!==hashCurrent) {        hashCurrent=document.location.hash;        ax_hashChg();        }    }function ax_getHTML(layid,url,par,act,finfnc,ax,wnd) {    // 04/22/11: Does NOT support history - use ax_getPage()    if (wnd)        var layel=wnd.document.getElementById(layid);    else        var layel=document.getElementById(layid);    var req,finalcod;    if (!layel) {        alert('Unable to find ID '+layid);        return;        }    if (window.XMLHttpRequest) {        req=new XMLHttpRequest();        }    else if (window.ActiveXObject) {        req=new ActiveXObject("Microsoft.XMLHTTP");        }    if (finfnc) {        finalcod=finfnc;        }    else {        finalcod='';        }    if (req) {       req.onreadystatechange = function () {            if (req.readyState == 4 && req.status == 200) {                if (layel) {                    layel.innerHTML=req.responseText;                    if (ax) { // Execute script                        axscriptx(layel);                        }                    if (finalcod.length>0) {                        eval(finalcod);                        }                    }                }            }        if (act) {            req.open(act,url);            }        else {            req.open("GET",url);            }        if (par) {            req.send(par);            }        else {            req.send('');            }        }    }function ax_getPage(layid,url,par,act,finfnc,expw,wnd) {    // 04/22/11: Same as ax_getHTML but keeps history    //           Back/forward arrows supported    //           Default YES to executing script    //           Calls expwrap() if there    if (wnd)        var layel=wnd.document.getElementById(layid);    else        var layel=document.getElementById(layid);    var req,finalcod;    if (!layel) {        alert('Unable to find ID '+layid);        return;        }    expw=expw && expw==true?true:false;    if (priLayid=='') priLayid=layid;    if (!hist[layid]) { // Initialize        hist[layid]=new Array(-1,0,new Array,new Array);        if (layel.innerHTML.length>0) {            hist[layid][0] +=1;            hist[layid][1] +=1;            hist[layid][2][0]=layel.innerHTML;            hist[layid][3][0]='';            if (priLayid==layid && hashHist==true)                window.location.hash=layid+'_'+hist[layid][0];            }        }    if (window.XMLHttpRequest) {        req=new XMLHttpRequest();        }    else if (window.ActiveXObject) {        req=new ActiveXObject("Microsoft.XMLHTTP");        }    if (finfnc) {        finalcod=finfnc;        }    else {        finalcod='';        }    if (req) {       req.onreadystatechange = function () {            if (req.readyState == 4 && req.status == 200) {                if (layel) {                    layel.innerHTML=req.responseText;               if (hist[layid] &&                 (hist[layid][0]==-1 || hist[layid][3][hist[layid][0]]!=url)) {                        hist[layid][0] +=1;                        hist[layid][1]=hist[layid][0]+1;                        hist[layid][2][hist[layid][0]]=layel.innerHTML;                        hist[layid][3][hist[layid][0]]=url;                        }                 // 10/25/10: swap axscript/finalcod order                 //           finalcod was executing first                 //   if (ax) { // Execute script                 // 01/25/12: Check for axscript: creates mess                    if (finalcod.length==0 || finalcod.indexOf('axscript')==-1)                        axscriptx(layel);                 //       }                    if (finalcod.length>0) {                        eval(finalcod);                        }                    window.scrollTo(0,0);                    if (expw==true && typeof expwrap=='function') expwrap();                    if (priLayid==layid && hashHist==true)                        window.location.hash=layid+'_'+hist[layid][0];                    showhist();                    }                }            }        if (act) {            req.open(act,url);            }        else {            req.open("GET",url);            }        if (req.overrideMimeType) { // NOT IE//12/23/09: Removed cause breaks French characters that need UTF-8//          But I bet some of those weird " characters will now be broken//            req.overrideMimeType('text/html; charset=windows-1252');            }// MAC does not like these headers//     req.setRequestHeader('User-Agent',navigator.userAgent+' Merlin_AX/1.0');        if (par) {            req.send(par);            }        else {            req.send('');            }        }    }function ax_go(layid,k) { // k<0: go back that #pages (def -1)                      // k>0: go forward    if (priLayid==layid && hashHist==true) {        if (k) {            history.go(k);            }        else {            history.go(-1);            }        }    else {    el=document.getElementById(layid);    if (el) {        if (k) {         if (k<0 && hist[layid][0]+k >=0 && hist[layid][0]+k<hist[layid][1]) {                hist[layid][0]=hist[layid][0]+k;                el.innerHTML = hist[layid][2][hist[layid][0]];                }            else if (k>0 && hist[layid][0]+k<hist[layid][1]) {                hist[layid][0]=hist[layid][0]+k;                el.innerHTML = hist[layid][2][hist[layid][0]];                }            else if (hist[layid][1]==0) {                hist[layid][0]=-1;                history.go(-1);                }            }        else if (hist[layid][1]>0 && hist[layid][0]>0) {            hist[layid][0] -= 1;            el.innerHTML = hist[layid][2][hist[layid][0]];            }        else if (hist[layid][1]==0) {            hist[layid][0]=-1;            history.go(-1);            }        }      }    showhist();    }function ax_addHist(layid) { // Add current to history                             // Call when first ax page is "include", not ajax/*    var layel=document.getElementById(layid);    hist[layid][0] +=1;    hist[curHist]=layel.innerHTML;    histEl[curHist]=layel;    histUrl[curHist]='';    hist[layid][1]=hist[layid][0]+1;    if (hashHist==true)        window.location.hash=curHist;*/    }function ax_hashChg() { // Ajax container has onhashchange="hashChg(event)"    var hash=window.location.hash;    var layid=hash.substr(1);    if (layid=='') {history.go(-1); return;}    hash=Number(layid.substr(layid.lastIndexOf('_')+1));    layid=layid.substr(0,layid.lastIndexOf('_'));//alert('hashChg: '+layid+':'+hash);    if (hash != hist[layid][0] && hash>=0 && hash<hist[layid][1] ) {        document.getElementById(layid).innerHTML=hist[layid][2][hash];        hist[layid][0]=hash;        if (typeof expwrap=='function') expwrap();        }    showhist();    }function ax_getFields(fname,url,act,par,btag,finfnc,errfnc) { /* fname:  Form name in HTML page containing fields            If null: assign values to js memvars instead of fields    url:    URL of page to return XML data    act:    GET/POST - default GET    par:    For POST only: body data, GET: include ?field=value in URL    btag:   Base tag name in return XML data - default 'fields'    finfnc: Call this optional function at the end    errfnc: Call this optional function if an error */    var formnm=fname;    if (btag)        var basetag=btag;    else        var basetag="fields";    if (finfnc)        var finalcod=finfnc;    else        var finalcod='';    if (errfnc)        var finalerr=errfnc;    else        var finalerr='';    if (window.XMLHttpRequest) {        req=new XMLHttpRequest();        }    else if (window.ActiveXObject) {        req=new ActiveXObject("Microsoft.XMLHTTP");        }    if (req) {        req.onreadystatechange = function ax_processFields() {            if (req.readyState == 4 && req.status == 200) {            if (!req.responseXML) {                alert('XML error: '+req.responseText);                if (finalerr.length>0) {                    eval(finalerr);                    }                return;                }            oel = req.responseXML.getElementsByTagName('error');            if (oel && oel.length>0) { //error                alert(oel[0].firstChild.nodeValue);                if (finalerr.length>0) {                    eval(finalerr);                    }                return;                }            oel = req.responseXML.getElementsByTagName('confirm');            if (oel && oel.length>0) { //03/05/08 confirm                ok=confirm(oel[0].firstChild.nodeValue);                if (finalcod.length>0) {                    eval(finalcod);                    }                return;                }          // 03/11/09: VDS needs array            elarray=req.responseXML.getElementsByTagName('array');            if (elarray && elarray.length>0) {                elarn=elarray.length;                }            else {                elarn=0;                oFields = req.responseXML.getElementsByTagName(basetag);                if (oFields && oFields.length>0) {                   oFld = oFields[0].firstChild;                   while (oFld) {                    if (oFld.nodeType==1) { // Element: Field name                        fld = oFld.nodeName;                        oVal=oFld.firstChild;                        if (oVal && (oVal.nodeType==3 || oVal.nodeType==4)) {                            val = oVal.nodeValue;                            }                        else {                            val = "";                            }                        if (fld=='jscript') { //10/17/11: Execute script                            eval(val);                            }                        else if (formnm) {                            ffld = eval('document.'+formnm+'.'+fld);                            if (ffld) {                                if (ffld.length && ffld[0].type=='radio') {                                    for (i=0;i<ffld.length;i++) {                                        if (ffld[i].value==val) {                                            ffld[i].checked=true;                                            break;                                            }                                        }                                    }                                else {                                    ffld.value = val;                                    }                                }                            }                        else {                            if (fld.substr(0,3)=='ID-') { // 06/03/11                                var f=document.getElementById(fld.substr(3));                                if (f) f.innerHTML=val;                                }                            else { //05/06/11: opt quotes around val                                try {                                    eval(fld+'='+val+';');                                    }                                catch (err) {                                    eval(fld+'="'+val+'";');                                    }                                }                            }                        }                    oFld=oFld.nextSibling;                    }                  }                }            if (finalcod.length>0) {                eval(finalcod);                }            }        }// * End fnc        if (act) {            req.open(act,url);            }        else {            req.open("GET",url);            }//     req.setRequestHeader('User-Agent',navigator.userAgent+' Merlin_AX/1.0');        if (par) {            req.send(par);            }        else {            req.send('');            }        }  // End "if (req)"    }function ax_makeflds(frm) { // Make query string of fields in form    var qs="";    for (i=0;i<frm.elements.length;i++) {        ok=true;       if (frm.elements[i].type=="radio" || frm.elements[i].type=="checkbox") {            ok=frm.elements[i].checked;            }        else if (frm.elements[i].type=="select-multiple") {            for (var j=0;j<frm.elements[i].options.length;j++) {                if (frm.elements[i].options[j].selected) {                    qs += frm.elements[i].name+                       '='+fldenc(frm.elements[i].options[j].value)+'&';                    }                }            ok=false;            }        if (ok && frm.elements[i].name) {            qs += frm.elements[i].name+'='+fldenc(frm.elements[i].value)+'&';            }        }    return qs;    }function fldenc(v) { // encode string    v=v.replace(/\%/g,'%25');    v=v.replace(/\&/g,'%26');    v=v.replace(/\=/g,'%3D');    v=v.replace(/\+/g,'%2B');    return v;    }function axscriptx(el) { //Execute scripts    var jsc = document.getElementsByName('_myscript');    if (jsc.length==0)        jsc=document.getElementsByTagName('script');    for (var iaxx=0;iaxx<jsc.length;iaxx++) {        js=jsc[iaxx];      // 05/19/10: el must be a parent node        var me=js;        while (me.parentNode && me.parentNode != el) me=me.parentNode;        if (me.parentNode) {            if (js && js.innerHTML) {                var u=js.innerHTML.replace(/\&amp\;/g,'&');                u=u.replace(/\&lt\;/g,'<');                u=u.replace(/\&gt\;/g,'>');                try {eval(u);} catch(err) {alert(err);}                }            }        }    }function showhist() {return;    if (document.getElementById('debug')) {        var htm='priLayid:'+priLayid+'<br><table border=1 cellspacing=0><th>Section</th><th>Current</th><th>Max</th>'+            '<th>URL</th></tr>'        for (i in hist) {            htm+='<tr><td>'+i+'</td><td>'+hist[i][0]+'</td><td>'+hist[i][1]+                '</td>'            for (j=0;j<hist[i][1];j++) {                htm+='<td>'+hist[i][3][j]+'</td>'+                    '</tr><tr><td colspan=3></td>'                }            htm+='</tr>'            }        htm+='</table>'        document.getElementById('debug').innerHTML=htm;        }    }function ax_insert(sec,url,typ) { // Insert page thru ax or iframe    typ=typ || 'A';    if (typ=='A') { // A:ajax (default)        if (url.indexOf('?')>-1)            url +='&ax=Y';        else url +='?ax=Y';        if (typeof expwrap == 'function')          ax_getPage(sec,url,'GET','','expwrap()',true);        else          ax_getPage(sec,url,'GET','','',true);        }    else { // I:iframe        var el=document.getElementById(sec);        el.innerHTML='<iframe src="'+url+'" frameborder="0" framemargin="0" width="100%" height="100%"></iframe>';        }    }/*** General link functions, supporting session storage and helper ***//*function lnkIt(url,sessfld) {    if (sessfld) url=appendUrl(url,sessfld,sessionStorage.getItem(sessfld));    return url;    }function lnkGo(url,sessfld) {    if (sessfld) url=appendUrl(url,sessfld,sessionStorage.getItem(sessfld));    document.location=url;    }*/function lnkPop(temp,url,ttl,loadob,blank,js) { //   if (sessfld) url=appendUrl(url,sessfld,sessionStorage.getItem(sessfld));    ttl=ttl || '';    js=js || "lnkPopfin('"+temp+"');";    loadob=loadob || '';    blank=blank || false;    var hlp=eval('pop_'+temp);    if (hlp) {        hlp.get(url,ttl,null,js,'',loadob,blank);        }    }function lnkAx(divid,url,data,loadob,js,expw) {    js=js || '';    data=data || '';    expw=expw && expw==true?true:false;    if (loadob) {        lnkLoadOn(loadob);        }    js="lnkLoadOff('"+divid+"');_refresh=true;"+js;    var el=document.getElementById(divid);    if (el) {        if (url.substr(0,2)!='/!' && sessionStorage.getItem('_ident'))            url='/!'+sessionStorage.getItem('_ident')+url;        var pre=el.getAttribute('data-plug'); // parent url        if (pre) url=pre+url;        // el.setAttribute('data-plugpg',url); // Builder        el.pg=url; // Builder        ax_getPage(divid,url,data,data?'POST':'GET',js,expw);        }    }/*function lnkWin(url,sessfld,wid,hgt,win) {    wid=wid || 800;    hgt=hgt || 600;    win=win || sessfld;    if (sessfld) url=appendUrl(url,sessfld,sessionStorage.getItem(sessfld));    window.open(url,win,'toolbar=0,width='+wid+',height='+hgt+',scrollbars=1,resizable=1');    }*/function lnkPopForm(frm,temp,url,ttl,loadob,blank,js) {    var qs=ax_makeflds(frm);    var s=frm.getAttributeNode("method");    if (s && s.value.toUpperCase() == "POST")        post=qs;    else {        post=''        if (url.indexOf('?')>=0) {            if (url.substr(url.length-1,1)=='&') url += qs;            else url+='&'+qs;            }        else url+='?'+qs;        }//    if (sessfld) url=appendUrl(url,sessfld,sessionStorage.getItem(sessfld));    ttl=ttl || '';    js=js || "lnkPopfin('"+temp+"');";    loadob=loadob || '';    blank=blank || false;    var hlp=eval('pop_'+temp);    if (hlp) {        hlp.get(url,ttl,null,js,post,loadob,blank);        }    }function lnkPopfin(temp) {    var hob=eval('pop_'+temp);    if (hob && document.getElementById('goback_bop')) {        if (hob.helpNum>0)            document.getElementById('goback_bop').style.visibility="visible";        if (hob.helpNum<hob.helpMax-1)            document.getElementById('goforth_bop').style.visibility="visible";        }    }function appendUrl(url,fld,val) {    if (url.indexOf('?')>=0) {        if (url.substr(url.length-1,1) != '&')            url += '&';        url += fld+'='+val;        }    else url += '?'+fld+'='+val;    return url;    }function lnkLoadOn(loadob,gif) { // Turn loader gif on    if (!document.getElementById("LoaderObj")) {        var ob=document.createElement('img');        ob.id='LoaderObj';        gif=gif || "/backoffice/images/loading.gif";        ob.src=gif;        ob.style.position="absolute";        ob.style.zIndex="99999";        ob.style.display="none";        document.body.appendChild(ob);        }    else        var ob=document.getElementById("LoaderObj");    var x=loadob.offsetLeft;    var y=loadob.offsetTop;    while (loadob.offsetParent) {        loadob=loadob.offsetParent;        x+=loadob.offsetLeft;        y+=loadob.offsetTop;        }    if (document.documentElement) {        x+=document.documentElement.scrollLeft;        y+=document.documentElement.scrollTop;        }    else {        x+=document.body.scrollLeft;        y+=document.body.scrollTop;        }    ob.style.top=y+'px';    ob.style.left=x+'px';    ob.style.display="block";    }function lnkLoadOff(divid) {    var ob=document.getElementById("LoaderObj");    if (ob) ob.style.display="none";    if (divid)        itmr=window.setInterval("lnkChkImgs('"+divid+"')",200);    }function lnkChkImgs(divid) {    var el=document.getElementById(divid);    if (el) {        var imgs=el.getElementsByTagName('img');        for (var i=0;i<imgs.length;i++) {            if (imgs[i].complete==false) return;            }        }    window.clearInterval(itmr);    expwrap();    }
