function AjaxManager()
{var GVersion='?v=63';var BEVersion=1000;var ana=this;var cache={};var pendingJSTRequests={};var pendingJSRequests={};var RETRYCOUNT=3;var MAX_REQ_TIME=2*60;var TOO_BUSY_LIMIT=4;var MAX_GET_RESPONSE_RETRIALS=10;this.requests={};this.flush=[];this.active=0;this.sessionExpired=false;this.requestOfSessionExpired=null;this.requestId=1;this.lastRequest='';this.tooBusy=function()
{return ana.active>=TOO_BUSY_LIMIT;};this.determineRequestObject=function()
{var constr=null;try{constr='new ActiveXObject("Msxml2.XMLHTTP")';eval(constr);}catch(e){try{constr='new ActiveXObject("Microsoft.XMLHTTP")';eval(constr);}catch(E){constr=null;};};if(!constr&&typeof XMLHttpRequest!='undefined'){constr='new XMLHttpRequest()';};return constr;};this.requestConstructor=this.determineRequestObject();this.createRequestObject=function()
{return eval(this.requestConstructor);};this.resourceExists=function(url,callback)
{var onLoad=function(found)
{cache[url+"_"]=found;if(callback)callback(found);};if(cache[url+"_"]!=undefined)
onLoad(cache[url+"_"]);else try
{var req=this.createRequestObject();req.onreadystatechange=function()
{if(req.readyState==4)
onLoad(req.status==200);};req.open('HEAD',url+GVersion,true);req.send(null);}
catch(e)
{onLoad(false);};};var fatalError=function(url){window.location=controller.errorPage+"?errorCode=InternalError";}
this.loadJS=function(url,callback,async,count)
{if(!count)
var count=1;else
count++;if(count>RETRYCOUNT)return fatalError(url);var onLoad=function(url,response)
{var clients=pendingJSRequests[url];pendingJSRequests[url]=null;var cilentsCount=clients.length;var headTag=document.getElementsByTagName('head')[0];var setJS=document.createElement('script');setJS.setAttribute('type','text/javascript');headTag.appendChild(setJS);setJS.text=response;for(var i=0;i<cilentsCount;i++)
{var client=clients[i];if(client.callback)
setTimeout(function(){client.callback(url);},10);};};var onResponse=function(status,response)
{if(!pendingJSRequests[url])return;if(status==200)
{onLoad(url,response);cache[url]=true;}
else
{ana.loadJS(url,callback,async,count);};};if(cache[url])
{if(callback)callback();return;}
else if(pendingJSRequests[url]&&count==1)
{pendingJSRequests[url].push({callback:callback});}
else try
{pendingJSRequests[url]=[{callback:callback}];var req=ana.createRequestObject();req.onreadystatechange=function()
{if(req.readyState==4)
{onResponse(req.status,req.responseText);};};req.open('GET',url+GVersion,async);req.send(null);if(!async)
{onResponse(req.status,req.responseText);};}
catch(e)
{ana.loadJS(url,callback,async,count);};};this.loadJST=function(url,element,context,callback,async,downloadOnly,count)
{if(!count)
var count=1;else
count++;if(count>RETRYCOUNT)return fatalError(url);var onLoad=function(url)
{var clients=pendingJSTRequests[url];pendingJSTRequests[url]=null;var cilentsCount=clients.length;for(var i=0;i<cilentsCount;i++)
{var client=clients[i];if(!client.downloadOnly)
{if(!cache[url].parsed)
{cache[url]={parsed:true,data:TrimPath.parseTemplate(cache[url].data)};}
var parsed=cache[url].data;if(!client.context._MODIFIERS)
client.context._MODIFIERS=tt;var processedResponse=parsed.process(client.context);if(client.element)
{client.element.innerHTML=processedResponse;client.element.setAttribute('loaded',true);};};if(client.callback)client.callback(client.element,url);};};var onResponse=function(status,response)
{if(!pendingJSTRequests[url])return;if(status==200)
{cache[url]={parsed:false,data:response};onLoad(url);}
else
{ana.loadJST(url,element,context,callback,async,downloadOnly,count);};};if(cache[url])
{if(downloadOnly)
{if(callback)callback(element,url);return;}
pendingJSTRequests[url]=[{element:element,context:context,callback:callback}];onLoad(url);}
else if(pendingJSTRequests[url]&&count==1)
{pendingJSTRequests[url].push({element:element,context:context,callback:callback,downloadOnly:downloadOnly});}
else try
{pendingJSTRequests[url]=[{element:element,context:context,callback:callback,downloadOnly:downloadOnly}];var req=ana.createRequestObject();req.onreadystatechange=function()
{if(req.readyState==4)
{onResponse(req.status,req.responseText);};};req.open('GET',url+GVersion,async);req.send(null);if(!async)
{onResponse(req.status,req.responseText);};}
catch(e)
{ana.loadJST(url,element,context,callback,async,downloadOnly,count);};};this.loadCSS=function(url,callback,async,themeCSS,count)
{if(!count)
var count=1;else
count++;if(count>RETRYCOUNT)return fatalError(url);var onLoad=function(response,removeThemeStylesheet)
{if(themeCSS)
{if(ana.themeCSSLoadedBefore)
{var styleElement=$('theme_stylesheet_tag');if(styleElement)
{removeChildSafely(styleElement);}
else
{var s=document.styleSheets[0];if(s)s.disabled=true;};};ana.themeCSSLoadedBefore=true;};if(document.createStyleSheet)
{if(themeCSS)
document.createStyleSheet('',0).cssText=response;else
document.createStyleSheet().cssText=response;}
else if(info.isSafari)
{var headTag=document.getElementsByTagName('HEAD')[0];var cssTag=document.createElement('link');cssTag.setAttribute('rel','stylesheet');cssTag.setAttribute('href',url);if(themeCSS)
cssTag.setAttribute('id','theme_stylesheet_tag');headTag.appendChild(cssTag);}
else
{var headTag=document.getElementsByTagName('HEAD')[0];var cssTag=document.createElement('style');cssTag.setAttribute('type','text/css');if(themeCSS)
cssTag.setAttribute('id','theme_stylesheet_tag');headTag.appendChild(cssTag);cssTag.innerHTML=response;}
if(callback)callback(url);};var onResponse=function(status,response)
{if(status==200)
{onLoad(response,false);cache[url]=response;}
else
{ana.loadCSS(url,callback,async,themeCSS,count);};};if(info.isSafari)
onLoad();else if(cache[url])
{if(themeCSS)
onLoad(cache[url],true);else if(callback)callback();}
else try
{var req=ana.createRequestObject();req.onreadystatechange=function()
{if(req.readyState==4)
{if(req.status==200)
{cache[url]=req.responseText;onLoad(cache[url],false);}
else
{ana.loadCSS(url,callback,async,themeCSS,count);};};};req.open('GET',url+GVersion,async);req.send(null);if(!async)
{onResponse(req.status,req.responseText);};}
catch(e)
{ana.loadCSS(url,callback,async,themeCSS,count);};};this.loadPage=function(url,elementId,callback,count)
{if(!count)
var count=1;else
count++;if(count>RETRYCOUNT)return fatalError(url);var onLoad=function(response)
{var element=$(elementId);setInnerHTMLSafely(element,response);if(callback)callback();};if(cache[url])
onLoad(cache[url]);else try
{var req=ana.createRequestObject();req.onreadystatechange=function()
{if(req.readyState==4)
{if(req.status==200)
{cache[url]=req.responseText;onLoad(cache[url]);}
else
{ana.loadPage(url,elementId,callback,count);};};};req.open('GET',url+GVersion,true);req.send(null);}
catch(e)
{ana.loadPage(url,elementId,callback,count);};};this.loadJSON=function(url,callback,async,noCache,method,count)
{if(!count)
var count=1;else
count++;if(count>RETRYCOUNT)return fatalError(url);if(!method)
var method='GET';var tmp;var onLoad=function(responseJSON)
{if(callback)callback(responseJSON);return responseJSON;};var onResponse=function(status,response)
{if(status==200)
{eval("tmp = "+response);if(!noCache)
cache[url]=tmp;return onLoad(tmp);}
else
{ana.loadJSON(url,callback,async,noCache,method,count);};};if(cache[url])
return onLoad(cache[url]);else try
{var req=ana.createRequestObject();req.onreadystatechange=function()
{if(req.readyState==4)
{return onResponse(req.status,req.responseText);};};req.open(method,url+GVersion,async);req.send(null);if(!async)
{return onResponse(req.status,req.responseText);};}
catch(e)
{ana.loadJSON(url,callback,async,noCache,method,count);};};this.broadcast=function(module,action,paramsJSON,response)
{var activeSniffer=null;{var callSniffer=function(sniffer)
{if(typeof controller.sniffers[sniffer]=='function')
{activeSniffer=sniffer;controller.sniffers[sniffer](module,action,paramsJSON,response?response:{errorCode:'OK'});};};for(var sniffer in controller.sniffers)
{if(sniffer.indexOf('box_')==0)
{callSniffer(sniffer);};};}};this.showLoading=function(){var loadingDiv=$("ajax_loading");if(loadingDiv){loadingDiv.innerHTML='Un momento por favor...'.replace(/\s/g,"&nbsp;");if(document.all){loadingDiv.className="loadingIE"}
else{loadingDiv.className="loading"}
loadingDiv.style.display='';}}
this.purgeRequest=function(requestId,tooLong)
{var req=ana.requests[requestId];if(req)
{try
{ana.backFromServer(requestId,tooLong,true);return true;}catch(e)
{e=e.description?e.description:e;window.onerror('In purgRequest, requestId = '+requestId+': '+e,'N/A','N/A');return false;}}
else
return false;};this.getServerResponse=function(iframeDoc,req,requestId,tooLong,purge,callback)
{if(typeof req.fetchRetrials=='undefined')
req.fetchRetrials=0;else
req.fetchRetrials++;if(req.fetchRetrials>MAX_GET_RESPONSE_RETRIALS)
return;var process=function()
{try
{var res=iframeDoc.getElementById('response').value;var response;try
{eval('response = '+res);}catch(e){e=e.description?e.description:e;window.onerror('Bad response from server\n'+'response='+res+',\nerror='+e,'N/A','N/A');response={errorCode:'NetworkError'};}}
catch(e){return ana.getServerResponse(iframeDoc,req,requestId,tooLong,purge,callback);}
if(callback)callback(req,requestId,tooLong,purge,response);}
if(info.isSafari)
setTimeout(process,500);else
process();};this.applyServerResponse=function(req,requestId,tooLong,purge,response)
{var iframe=$(req.iframe);var endTime=new Date();response.clientTime=endTime.getTime()-req.startTime.getTime();switch(response.errorCode)
{case'OK':{}break;case'SessionExpired':{ana.sessionExpired=true;disablePage();var dialogHTML=T('ajx.Sexpire1')+'.<br>'+T('ajx.Sexpire2')
+'<form onsubmit="return controller.relogin($(\'_relogin_password\').value)"><div>'+T('_.Pswrd')+':<input type="password" id="_relogin_password"></div>'
+'<div align="center"><input type="submit" value="'+T('_.Ok')+'"></div></form>';showDialog(T('ajx.SExpTtl'),dialogHTML);$('_relogin_password').focus();ana.requestOfSessionExpired={module:req.module,action:req.action,params:req.params,callback:req.callback,broadcast:req.broadcast,requestId:requestId};}break;};if(req.callback)req.callback(response,req.params);if(req.broadcast)
ana.broadcast(req.module,req.action,req.params,response);var form=$('_request_form_'+requestId);if(form)removeChildSafely(form);if(iframe)iframe.onload=null;delete ana.requests[requestId];ana.active--;var loadingDiv=$('ajax_loading');if(ana.active==0){if(loadingDiv)loadingDiv.style.display='none';};setTimeout("removeChildSafely($('"+req.iframe+"'))",100);iframe=null;iframeDoc=null;};this.backFromServer=function(requestId,tooLong,purge,iframe)
{var req=ana.requests[requestId];if(!req)
{alert('No such request! ('+requestId+')');return;}
if(!iframe)var iframe=document.getElementById(req.iframe);var iframeDoc=null;try{iframeDoc=iframe.contentWindow.document||iframe.contentDocument.document;}catch(e){};var response;if(purge){if(tooLong)
response={errorCode:'NetworkError'};else
response={errorCode:'RequestPurged'};this.applyServerResponse(response);}
else if(!iframeDoc){this.applyServerResponse(response={errorCode:'NetworkError'});}
else{this.getServerResponse(iframeDoc,req,requestId,tooLong,purge,this.applyServerResponse);}};this.convertParamsJSONToString=function(paramsJSON,returnLogEntry,eachItem,requestId)
{var line=null;if(returnLogEntry)
{line='>>['+new Date().toUTCString()+'] Sent request #'+requestId+' ['+paramsJSON._module+', '+paramsJSON._action+', "';var isfirst=true;}
for(var item in paramsJSON)
{if(paramsJSON[item]==null||paramsJSON[item]==undefined||typeof paramsJSON[item]=='string'&&paramsJSON[item]=='')continue;if(typeof paramsJSON[item]=='string'||(typeof paramsJSON[item]=='number'&&isFinite(paramsJSON[item])))
{eachItem(item,paramsJSON[item]);}
else if(typeof paramsJSON[item]=='object')
{var escapeComma=paramsJSON[item].constructor==Array;var arrayVals='';comma=false;for(var subitem in paramsJSON[item])
{if(typeof paramsJSON[item][subitem]=='string')
{arrayVals+=(comma?',':'')+(escapeComma?paramsJSON[item][subitem].replace(/,/g,',,'):paramsJSON[item][subitem]);comma=true;}
else if(typeof paramsJSON[item][subitem]=='number'&&isFinite(paramsJSON[item][subitem]))
{arrayVals+=(comma?',':'')+paramsJSON[item][subitem];comma=true;};};if(arrayVals!='')
{eachItem(item,arrayVals);};};if(item=='_module'||item=='_action'||item=='_callback'||item=='_onFailure'||item=='_address'||item=='_requestId')
continue;if(returnLogEntry)
{if(typeof paramsJSON[item]!='function')
{if(!isfirst)line+=', ';line+=item+'='+(item=='password'?'********':(item=='body'||item=='htmlBody'?'__BODY__':paramsJSON[item]));isfirst=false;}}};line+='"]';return line;};var getBackendHandler=function()
{if(!ana.backend)
ana.backend="http://"+window.location.host+"/php/controller.php";return ana.backend;}
this.requestInvisible=function(module,action,paramsJSON,callback,method,broadcast,immediateResponse,requestId)
{if(!paramsJSON)var paramsJSON={};paramsJSON['_module']=module;paramsJSON['_action']=action;paramsJSON['plain']=1;var url=getBackendHandler()+"?";ana.convertParamsJSONToString(paramsJSON,false,function(item,val){url+=encodeURIComponent(item)+"="+encodeURIComponent(val)+"&";});var myCallback=function(response)
{if(callback!=null)
callback(response,paramsJSON);if(broadcast)
{ana.broadcast(module,action,paramsJSON,response);}}
return ana.loadJSON(url,myCallback,true,method!='GET',method);};this.requestInvisibleGet=function(module,action,paramsJSON,callback,immediateResponse)
{return this.requestInvisible(module,action,paramsJSON,callback,"GET",true,immediateResponse);};this.requestInvisiblePost=function(module,action,paramsJSON,callback,immediateResponse)
{return this.requestInvisible(module,action,paramsJSON,callback,"POST",true,immediateResponse);};this.request=function(module,action,paramsJSON,callback,method,broadcast,immediateResponse,requestId)
{var response=null;if(ana.sessionExpired&&action!='relogin'){response={errorCode:'SessionExpired'};}
else if(ana.active>=15){response={errorCode:'TooManyRequests'};}
if(response){if(callback)callback(response);if(broadcast)
ana.broadcast(module,action,paramsJSON,response);return;}
if(immediateResponse)
{if(callback)callback({errorCode:'OK'},paramsJSON,true);ana.broadcast('clientRequest',immediateResponse,paramsJSON,null);}
ana.active++;if(broadcast)ajax.showLoading();if(!requestId)
var requestId=++ana.requestId;var iframe;if(info.isIE)
iframe=document.createElement('<iframe name="_request_tunnel_'+requestId+'" id="_request_tunnel_'+requestId+'" style="display:none" onload="ajax.backFromServer('+requestId+')" >');else{iframe=document.createElement('iframe');iframe.style.width="0px";iframe.style.height="0px";iframe.style.border="0px";iframe.name='_request_tunnel_name_'+requestId;iframe.setAttribute('id','_request_tunnel_'+requestId);iframe.onload=function(){ana.backFromServer(requestId,null,null,iframe);};};ana.requests[requestId]={iframe:'_request_tunnel_'+requestId,startTime:new Date(),module:module,action:action,params:paramsJSON,callback:callback,broadcast:broadcast};document.body.appendChild(iframe);if(!paramsJSON)paramsJSON={};paramsJSON['_module']=module;paramsJSON['_action']=action;paramsJSON['_address']=controller.address;if(!ana.requestEncoding)
{var e=$('encodingMetaTag').getAttribute('CONTENT');ana.requestEncoding=e.substr(e.indexOf("charset=")+"charset=".length);}
paramsJSON['_requestEncoding']=ana.requestEncoding;ana.backend=getBackendHandler();if(method=="POST")
{var form;if(info.isIE)
form=document.createElement("<form id='_request_form_"+requestId+"' name='_request_form_"+requestId+"' method='"+method
+"' target='"+iframe.name+"' action='"+ana.backend+"' >");else{form=document.createElement('form');form.name=form.id='_request_form_'+requestId;form.method=method;form.target=iframe.name;form.action=ana.backend;};var i;var line=ana.convertParamsJSONToString(paramsJSON,true,function(item,val){i=document.createElement('input');i.type='hidden';i.name=item;i.value=val;form.appendChild(i);},requestId);document.body.appendChild(form);form.submit();}
else
{var str=ana.backend+"?";var line=ana.convertParamsJSONToString(paramsJSON,true,function(item,val){str+=item+"="+escape(val)+"&";},requestId);iframe.src=str;}
paramsJSON['_requestId']=requestId;if(method=='POST')
setTimeout(function(){ana.purgeRequest(requestId,true)},MAX_REQ_TIME*1000);if($('_request_log_textArea'))$('_request_log_textArea').value+=line+'\n';if(controller.feedback)
controller.feedback.logRequest(line);return requestId;};this.requestGet=function(module,action,paramsJSON,callback,immediateResponse)
{return this.request(module,action,paramsJSON,callback,"GET",true,immediateResponse);};this.requestPost=function(module,action,paramsJSON,callback,immediateResponse)
{return this.request(module,action,paramsJSON,callback,"POST",true,immediateResponse);};this.requestSilentPost=function(module,action,json,callback,immediateResponse)
{return this.requestInvisible(module,action,json,callback,"POST",false,immediateResponse);};this.alert=function(msg)
{ajax.broadcast('clientRequest','alert',{'type':'alert','message':msg},null);}
this.info=function(msg)
{ajax.broadcast('clientRequest','alert',{'type':'info','message':msg},null);}
this.error=function(msg)
{ajax.broadcast('clientRequest','alert',{'type':'error','message':msg},null);}
this.clear=function()
{ajax.broadcast('clientRequest','alert',{'type':'alert','message':''},null);}
this.log=function(msg)
{}};ajax=new AjaxManager();
