
if(typeof FT==="undefined"){FT={};}
FT.PIP={XHR:null,url:'',replaceId:null,intervalTime:100,timeoutTime:2000,optimostModuleKey:null,responseXML:null,postSuccessActions:function(){var rTargetNode=document.getElementById(FT.PIP.replaceId);optimost.displayModule(FT.PIP.optimostModuleKey);FT.PIP.setVisibility(true,rTargetNode);FT.Optimise.log("SUCCESS!");FT.Optimise.log(" Optimost ready?    "+FT.PIP.isOptimostReady(FT.PIP.optimostModuleKey));FT.Optimise.log(" Ajax prices ready? "+FT.PIP.isAsyncPricesFetchReady());FT.Optimise.log(" Element found?     "+(document.getElementById(FT.PIP.replaceId)?"true":"false"));},postFailureActions:function(){FT.Optimise.log("TIMEOUT after "+FT.PIP.timeoutTime+"ms");FT.Optimise.log(" Optimost ready?    "+FT.PIP.isOptimostReady(FT.PIP.optimostModuleKey));FT.Optimise.log(" Ajax prices ready? "+FT.PIP.isAsyncPricesFetchReady());FT.Optimise.log(" Element found?     "+(document.getElementById(FT.PIP.replaceId)?"true":"false"));var failureActionPoller=new FT.PIP.ConditionCheckerWithTimeout(function(){return document.getElementById(FT.PIP.replaceId);},function(){FT.Optimise.log(" Element found?     "+(document.getElementById(FT.PIP.replaceId)?"true":"false"));var rTargetNode=document.getElementById(FT.PIP.replaceId);FT.PIP.setVisibility(true,rTargetNode);},50,function(){FT.Optimise.log("ERROR: The id '"+FT.PIP.replaceId+"' was not found on the page.  Unrecoverable!");},10000);failureActionPoller.start();}};FT.PIP.getNewHTTPObject=function(){var rXHRLocal;try{if(window.XMLHttpRequest){rXHRLocal=new XMLHttpRequest();}else if(window.ActiveXObject){try{rXHRLocal=new ActiveXObject("Msxml2.XMLHTTP");}catch(err){rXHRLocal=new ActiveXObject("Microsoft.XMLHTTP");}}}
catch(err2){rXHRLocal=false;}
return rXHRLocal;};FT.PIP.doAsyncPricesFetch=function(){if(FT.PIP.XHR){try{if(window.XMLHttpRequest){FT.PIP.XHR.open('GET',FT.PIP.url,true);FT.PIP.XHR.onreadystatechange=FT.PIP.asyncPricesFetchCallback;FT.PIP.XHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded');FT.PIP.XHR.send(null);}else if(window.ActiveXObject){FT.PIP.XHR.open('GET',FT.PIP.url,true);FT.PIP.XHR.onreadystatechange=FT.PIP.asyncPricesFetchCallback;FT.PIP.XHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded');FT.PIP.XHR.send();}}
catch(err){FT.PIP.XHR=false;}}};FT.PIP.asyncPricesFetchCallback=function(){if(FT.PIP.XHR.readyState!==4){return;}
var result=FT.PIP.XHR.responseText;if(result===null||result===""||FT.PIP.XHR.status!==200){FT.Optimise.log("Couldn't get prices Ajax: url="+FT.PIP.url+" status="+FT.PIP.XHR.status);FT.PIP.poller.timeoutNow();}else{FT.PIP.responseXML=FT.PIP.XHR.responseXML;}};FT.PIP.isOptimostReady=function(key){return(typeof optimost!=='undefined'&&typeof optimost.M!=='undefined'&&typeof optimost.M[key]==="function"&&typeof optimost.displayModule!=='undefined');};FT.PIP.isAsyncPricesFetchReady=function(){return FT.PIP.responseXML!=null;}
FT.PIP.getDataFromNode=function(nodeName){if(!FT.PIP.responseXML||!nodeName){return"";}
var nl=FT.PIP.responseXML.getElementsByTagName(nodeName);if(nl.length>0&&nl[0].firstChild&&nl[0].firstChild.data){return nl[0].firstChild.data;}
return"";}
FT.PIP.setVisibility=function(bVisible,rNode){rNode.style.visibility=bVisible?'visible':'hidden';}
FT.PIP.ConditionCheckerWithTimeout=function(conditionCallback,successCallback,intervalMs,timeoutCallback,timeoutMs){this.conditionCallback=conditionCallback;this.intervalMs=intervalMs;this.timeoutCallback=timeoutCallback;this.successCallback=successCallback;this.timeoutMs=timeoutMs;this.intervalId=-1;this.timeoutId=-1;this.stopped=false;this.start=function(){if(this.stopped){FT.Optimise.log("Can't restart a stopped poller");return;}
FT.Optimise.log("Poller started...");FT.Optimise.log(" interval = "+this.intervalMs);FT.Optimise.log(" timeout  = "+this.timeoutMs);this.checkNow();if(this.stopped){return;}
var me=this;this.intervalId=setInterval(function(){me.checkNow();},this.intervalMs);this.timeoutId=setTimeout(function(){me.timeoutNow();},this.timeoutMs);}
this.stop=function(){this.stopped=true;clearInterval(this.intervalId);clearTimeout(this.timeoutId);}
this.timeoutNow=function(){if(this.stopped){return;}
this.stop();this.timeoutCallback();}
this.checkNow=function(){if(this.stopped){return;}
if(this.conditionCallback()){this.stop();this.successCallback();}}}
FT.PIP.init=function(queryString,elementToReplaceId,moduleName){if(FT.Optimise.isActive()){FT.PIP.doInit(queryString,elementToReplaceId,moduleName);}else{FT.Optimise.log("Not active due to QA cookie");document.write("<"+"style> #"+elementToReplaceId+"{visibility:visible !important}</style>");}}
FT.PIP.doInit=function(queryString,elementToReplaceId,moduleName){FT.PIP.replaceId=elementToReplaceId;FT.PIP.optimostModuleKey=moduleName;FT.PIP.timeoutTime=FT.Optimise.timeoutTime;FT.PIP.intervalTime=FT.Optimise.intervalTime;var successCondition=function(){return FT.PIP.isOptimostReady(FT.PIP.optimostModuleKey)&&FT.PIP.isAsyncPricesFetchReady()&&document.getElementById(FT.PIP.replaceId);}
FT.PIP.poller=new FT.PIP.ConditionCheckerWithTimeout(successCondition,FT.PIP.postSuccessActions,FT.PIP.intervalTime,FT.PIP.postFailureActions,FT.PIP.timeoutTime);FT.PIP.poller.start();var urlStem='/regb/psp';var serverAddress=window.location.protocol+'//'+window.location.hostname;FT.PIP.url=serverAddress+urlStem+queryString;FT.PIP.XHR=FT.PIP.getNewHTTPObject();FT.PIP.doAsyncPricesFetch();}