// Copyright Levexis Ltd	Tue Feb  9 12:25:07 2010 GMT	1	
if(typeof (LEVU)=="undefined"){
LEVU=(function(){
function _1(_2){
var a=document.getElementsByTagName("body");
if(a.length===0){
a=document.getElementsByTagName("head");
}
a[0].appendChild(_2);
};
p={SQ:function(_3){
var s=this.FS(_3);
if(s){
var i=s.src.indexOf("/"+_3+"?");
if(i>-1){
return s.src.substr(i+_3.length+2);
}
}
return "";
},ES:function(_4){
var s=this.FS(_4);
if(s&&s.innerHTML){
try{
eval(s.innerHTML);
}
catch(error){
LEVU.LE("error with es of [ "+s.innerHTML+" ]","Error");
}
}
},FS:function(_5){
var ss=document.getElementsByTagName("script");
for(var s=(ss.length-1);s>=0;s=s-1){
if(ss[s].src.indexOf("/"+_5)>-1){
return ss[s];
}
}
return "";
},GP:function(_6,_7){
if(_7&&_6){
return LEVU.RX(_6,"[?|&]"+"?"+_7+"=([^&]*)");
}
},SP:function(_8,_9,_a){
var _b=_8.indexOf(_9);
if(_b>0){
var re=new RegExp("[&|?]"+_9+"=[^&]*");
return _8.replace(re,_9+"="+_a);
}else{
if(_b<0){
return _8+"&"+_9+"="+_a;
}else{
var re=new RegExp("^"+_9+"=[^&]*");
return _8.replace(re,_9+"="+_a);
}
}
},AIF:function(_c,_d){
var f=document.createElement("iframe");
if(_d){
f.width="18px";
f.height="18px";
}else{
f.width="0px";
f.height="0px";
}
f.style.position="absolute";
f.style.top="0px";
f.style.left="-999em";
_1(f);
f.src=_c;
},WIF:function(_e,_f){
var id=LEVU.GetCB(5);
var f="<iframe id=\"tmif"+id+"\" src=\"\" style=\"position: absolute; top: 0px; left: -999em \" ";
if(_f){
f+="width = \"18px\" height=\"18px\"";
}else{
f+="width = \"0px\" height=\"0px\"";
}
document.write(f+"></iframe>");
var _10=document.getElementById("tmif"+id);
_10.src=_e;
},AJS:function(_11){
var f=document.createElement("script");
f.type="text/javascript";
_1(f);
f.src=_11;
},CIm:function(_12){
(new Image).src=_12;
},DS:function(_13){
if(!_13){
return 0;
}
var rn=Math.random()*100;
if(_13>=rn){
return 1;
}else{
return 0;
}
},LE:function(_14,_15){
if(!_15){
_15="Error";
}
if(typeof (console)!="undefined"&&LEVU.GC("tmDebug")==1){
console.log("TagMan "+_15+": "+_14);
}
},GetCB:function(_16){
var cb=Math.random()+"";
return cb.substr(2,_16);
},GC:function(_17){
var c=document.cookie;
var _18=c.indexOf(_17+"=");
if(_18>-1){
epos=c.indexOf(";",_18);
if(epos>_18){
return unescape(c.substr(_18+_17.length+1,epos-_18-_17.length-1));
}else{
return unescape(c.substr(_18+_17.length+1));
}
}else{
return "";
}
},SC:function(_19,_1a,_1b,_1c){
var cs=_19+"="+escape(_1a)+";";
if(_1c==1){
cs+=" expires=Tue, 2 Jun 2015 00:00:00 UTC;";
}
if(!_1b){
_1b="/";
}
cs+=" path="+_1b+";";
document.cookie=cs;
},OTQ:function(_1d){
var q=[];
for(var k in _1d){
q.push(escape(k)+"="+escape(_1d[k]));
}
return q.join("&");
},QTO:function(_1e){
var ps=_1e.replace(/^[?&]/,"").split("&");
var o=new Object;
for(var i=0;i<ps.length;i++){
var p=ps[i].split("=");
o[unescape(p[0])]=unescape(p[1]);
}
if(o){
return o;
}else{
return "";
}
},IIF:function(){
if(window.parent.frames.length===0){
return 0;
}else{
return 1;
}
},RX:function(_1f,_20){
if(_1f&&_20){
var re=new RegExp(_20);
var m=re.exec(_1f);
if(m){
m.splice(0,1);
return m.join("");
}
}
return "";
},SS:function(_21,_22,end){
if(_21){
if(end){
return _21.toString().substr(_22,end);
}else{
return _21.toString().substr(_22);
}
}
return "";
},FD:function(_23,_24){
if(_23&&_24){
return _23.indexOf(_24)==-1?0:1;
}
return 0;
},GS:function(it,ps){
if(it&&ps){
var ot="";
ps=","+ps+",";
var pts=it.split("/");
var rp=pts.length*-1;
for(var lp=0;lp<pts.length;lp=lp+1){
if(ps.indexOf(","+lp+",")>-1||ps.indexOf(","+rp+",")>-1){
if(ot){
ot+="/";
}
ot+=pts[lp];
}
rp+=1;
}
return ot;
}
},WJS:function(_25,_26){
var out="<scr"+"ipt type=\"text/javascript\"";
if(_26){
out+=" src=\""+_25+"\">";
}else{
out+=">"+_25;
}
document.write(out+"</scr"+"ipt>");
},ADW:function(_27){
if(typeof (LEVU.djs)=="undefined"){
LEVU.djs="";
}
LEVU.djs+=" "+_27;
},IDW:function(){
if(typeof (LEVU.djs)!="undefined"&&LEVU.djs){
var _28=(("https://"==LEVU.GPR())?"https://sec":"http://res");
LEVU.WJS(_28+".levexis.com/js/LEVU.WDW.xjs",1);
}
},WDW:function(){
if(typeof (LEVU.djs)!="undefined"&&LEVU.djs){
LEVU.WJS(LEVU.djs,0);
LEVU.djs="";
}
},GPR:function(){
return (location.protocol=="https:")?"https://":"http://";
},PR:function(_29){
var _2a="";
for(var key in _29){
_2a+="\t"+key+"=>"+_29[key]+"\n";
}
return (_2a);
}};
return p;
})();
LEVU.ES("lu.js");
var q=LEVU.SQ("lu.js");
if(q){
var u=LEVU.GPR()+q;
LEVU.WJS(u,1);
}
}
// if the staging cookie is set it will now document.write the staging version of the tmap out instead
// it's done here so we can use the LEVU.GC function
if ( LEVU.GC('tmStaging') ) {
    // avoid infinite loop if someone puts live template on staging or is messing around with their dns
    if (typeof(tmIncludedOnce)=='undefined') {
        var stagingMapURL = LEVU.FS('octopustravel.js');
         if (stagingMapURL) {            
            var stagingMapURL = stagingMapURL.src.replace( /(.*?)\/\/(.*?)\.(.*?)\// , '$1//tagstaging.$3/' );
            LEVU.WJS(stagingMapURL,1);
        } else {
            LEVU.LE('Unable to find [octopustravel.js]','FATAL');
        }
        var tmIncludedOnce = 1;
    }
} else {
// not in staging mode proceed as normal
    <!-- No Client JS -->
    
    // reverse compatibility
    if (typeof( tmPageId ) == 'undefined' && typeof( tmContId ) != 'undefined') var tmPageId = tmContId;
    
    if (typeof(tmPageId)!='undefined') LEVU.LE('base tmPageId='+tmPageId,'Debug');
    if (typeof(tmOPV)!='undefined') LEVU.LE('base tmOPV='+tmOPV,'Debug');
    
    // Initialise globals
    var searchRecords = [ LEVU.GS(document.location.toString(), 2) // Stem 2
 ];
    
    if (!searchRecords) {
            LEVU.LE('No mapping rules found','Warning');
    } else {
            LEVU.LE("Mapping Rule Values\n" + LEVU.PR(searchRecords),'Debug');	
    }
    
// These are the libs used by this code the includes have to be at the start of the line


//
// If we have not already, define the TMAN namespace first
//
if (typeof(TMAN) == 'undefined'){ var TMAN = {} }

TMAN.MAP = function() { this.maps = new Array(); };
TMAN.MAP.prototype = {
	//
	// Adds map to TMAN.MAP hash object
	//
	AddMap: function(t) {
		h = new TMAN.MAP.HashMap(t);
		this.maps[h.head.ParentCId()] = h;
	},
	//
	// Adds map to TagMah hash object only if container ID matches
	//
	AddMapIf: function(c,t) {
		var HM = new TMAN.MAP.HashMap(t);
		var d = HM.head.ParentCId();
		if (d == c)
			this.maps[c] = HM;
	},
	//
	// Searches maps for text - hashing first
	//
	Search: function(t) {
		var h = TMAN.MAP.B92SHA1(t);
		for (var i in this.maps) {
			var m = this.maps[i];
			if (m)
				return m.Search(h);
		}
	}
};

TMAN.MAP.Head = function(m) {
	this.ok = true;	this.error = '';
	if (!m || (m.length == 0))
		return;
	this.v = TMAN.B92.desmall(m.substr(0,2));
	if (this.v !=  2) {
		this.ok = false; this.error = 'Version '+this.v+' is unsupported';
		return;
	}
	this.hlen = TMAN.B92.desmall(m.substr(2,1));
	this.clen = TMAN.B92.desmall(m.substr(3,1));
	this.cid  = TMAN.B92.desmall(m.substr(4,2));
	this.olen = TMAN.B92.desmall(m.substr(6,1));
	this.oto  = TMAN.B92.desmall(m.substr(7,2));
	a  = TMAN.B92.desmall(m.substr(9,1));
	this.schema = m.substr(10,a);
	this.maps = m.substr(10+a);
};
TMAN.MAP.Head.prototype = {
	Version:	function() { return this.v; },
	HashLen:	function() { return this.hlen; },
	CIdLen:		function() { return this.clen; },
	ParentCId:	function() { return this.cid; },
	OtherLen:	function() { return this.olen; },
	Maps:		function() { return this.maps; },
	OPVTO:		function() { return this.oto; },
	Schema:		function() { return this.schema; }
};

//
// Returns the sha1 hash of a text message - as a packed array of ints
//
TMAN.MAP.SHA1 = function(msg) {
	// This rotates 32 bit int s bits to left
	function ROL(n,s) { return ( n<<s ) | (n>>>(32-s)); }

	// Remove unichar chars
	function Utf8Encode(s) {
		string = s.replace(/\r\n/g,"\n");
		var u = "";
		for (var n = 0; n < s.length; n++) {
			var c = s.charCodeAt(n);
			if (c < 128)
				u += String.fromCharCode(c);
			else if((c > 127) && (c < 2048)) {
				u += String.fromCharCode((c >> 6) | 192);
				u += String.fromCharCode((c & 63) | 128);
			}
			else {
				u += String.fromCharCode((c >> 12) | 224);
				u += String.fromCharCode(((c >> 6) & 63) | 128);
				u += String.fromCharCode((c & 63) | 128);
			}
 
		}
		return u;
	}
	var blockstart;
	var i, j,k;
	var W = new Array(80);
	var H0 = 0x67452301; var H1 = 0xEFCDAB89; var H2 = 0x98BADCFE;
	var H3 = 0x10325476; var H4 = 0xC3D2E1F0;
	var A, B, C, D, E;
	var temp;
	//msg = Utf8Encode(msg);
	var msg_len = msg.length;
	var word_array = new Array();
	for( i=0; i<msg_len-3; i+=4 ) {
		j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
		word_array.push( j );
	}
	switch( msg_len % 4 ) {
		case 0:
			i = 0x080000000;
		break;
		case 1:
			i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
		break;
 
		case 2:
			i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
		break;
 
		case 3:
			i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
		break;
	}
	word_array.push( i );
	while( (word_array.length % 16)!= 14) word_array.push(0);
	word_array.push( msg_len>>>29 );
	word_array.push( (msg_len<<3)&0x0ffffffff );
	for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
		for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
		for( i=16; i<80; i++ ) W[i] = ROL(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
                A = H0; B = H1; C = H2; D = H3; E = H4;
		for (i=0;i<80;i++) {
			k = W[i];
			if (i<20)
				temp = (ROL(A,5) + ((B&C) | (~B&D)) + E + k + 0x5A827999) & 0x0ffffffff;
			else	if (i<40)
					temp = (ROL(A,5) + (B ^ C ^ D) + E + k + 0x6ED9EBA1) & 0x0ffffffff;
				else	if (i<60)
						temp = (ROL(A,5) + ((B&C) | (B&D) | (C&D)) + E + k + 0x8F1BBCDC) & 0x0ffffffff;
					else
						temp = (ROL(A,5) + (B ^ C ^ D) + E + k + 0xCA62C1D6) & 0x0ffffffff;
                        E = D; D = C; C = ROL(B,30); B = A; A = temp;
                }
		H0 = (H0 + A) & 0xffffffff; H1 = (H1 + B) & 0xffffffff; H2 = (H2 + C) & 0xffffffff; H3 = (H3 + D) & 0xffffffff; H4 = (H4 + E) & 0xffffffff;
	}
	return [ H0, H1 , H2, H3, H4 ];
};
//
// Given a string returns the b92 encoded sha hash as a string of 25 chars.
//
TMAN.MAP.B92SHA1 = function(text) { return TMAN.B92.encode(TMAN.MAP.SHA1(text),25); };

//
// A specific Map now...
//
TMAN.MAP.Map = function(m,h) {
	if (!m || !h)
		return;
	this.head = h;
	this.hash = m.substr(0,h.HashLen());
	this.Cid   = TMAN.B92.desmall(m.substr(h.HashLen(),h.CIdLen()));
	this.Other = TMAN.B92.desmall(m.substr(h.HashLen()+h.CIdLen(),h.OtherLen()));
};
TMAN.MAP.Map.prototype = {
	Hash:		function() { return this.hash; },
	ContainerId:	function() { return this.Cid; },
	Header:		function() { return this.head; },
	OncePerVisit:	function() { return ((this.Other & 1)==1)?true:false; }
};

TMAN.MAP.HashMap = function(t) {
	this.text = t;
	this.head = new TMAN.MAP.Head(this.text);
};
TMAN.MAP.HashMap.prototype.Search = function(m) {
	var h = this.head;
	//
	// Extract hashlen and entire map len
	//
	var hl = h.HashLen();
	var ml = hl + h.CIdLen() + h.OtherLen();
	//
	// Get the least most hashlen bytes
	//
	m = m.substr(m.length-hl);
	var t = h.Maps(); var i = 0; var j=0;
	while (i != -1) {
	    j = t.indexOf(m,i);
	    //
	    // If a match found, but not on a boundary then try to find next one...
	    //
	    if ((j % ml) == 0)
	        return new TMAN.MAP.Map(t.substr(j,ml),h);
	    if (j==i) // e.i. we havn't moved on!
	        i = j + 1;
	    else
	        i = j;
	}  
	return;
};
if(typeof(TMAN)=="undefined"){var TMAN={}}TMAN.B92={};TMAN.B92.div=function(f){var a=f.length;var h=new Array(a*2);var g=0;var d=0;var e=0;for(e=0;e<a*2;e++){g<<=16;if((e%2)==0){h[e]=((f[d]>>16)&65535)|g}else{h[e]=(f[d++]&65535)|g}g=h[e]%92;h[e]=h[e]/92|0}var b=new Array(a);for(e=0;e<a;e++){b[e]=(h[e*2]<<16)|(h[e*2+1])}TMAN.B92.rem=g;return b};TMAN.B92.encode=function(e,a){var f=e.length;var g=new Array(f);var b=new Array(a);var d=0;TMAN.B92.rem=0;for(d=0;d<f;d++){g[d]=e[d]}for(d=0;d<a;d++){g=TMAN.B92.div(g);b[d]=TMAN.B92.rem}var c="";while(a>0){d=b[--a];if(d>58){c+=String.fromCharCode(d+34)}else{if(d>1){c+=String.fromCharCode(d+33)}else{c+=String.fromCharCode(d+32)}}}return c};TMAN.B92.decode=function(l,f){var h=l.length>>1;if((f*2)>h){h=f*2}var a=new Array(h);var b=0;var d=0;for(b=0;b<h;b++){a[b]=0}for(d=0;d<l.length;d++){for(b=0;b<h;b++){a[b]*=92;if(b==0){var g=l.charCodeAt(d);if(g>92){a[0]+=g-34}else{if(g>34){a[0]+=g-33}else{a[0]+=g-32}}}}for(b=0;b<h-1;b++){var e=a[b]>>16;if(e){a[b+1]+=e;a[b]&=65535}}}var k=new Array(f);for(d=0;d<f;d++){b=f-(d+1);k[b]=a[(d*2)+1]<<16;k[b]+=a[d*2]}return k};TMAN.B92.desmall=function(c){var b=TMAN.B92.decode(c,1);return b[0]};
    
    // These are the maps...
    TMAN.MapStrings = [ " #!! #!  .octopustravelV) " ];
    
    if (!TMAN.MapStrings) {
            LEVU.LE('No mappings for this container','Warning');
    } else {
            LEVU.LE("Mapping string\n" + LEVU.PR(TMAN.MapStrings),'Debug');	
    }
    
    var TH = new TMAN.MAP;
    var i = 0;
    // only search the map for the base container that matches the pageId
    for (var i=0;i<TMAN.MapStrings.length;i++) TH.AddMapIf(tmPageId,TMAN.MapStrings[i]);
    // Now look for the container on the extract rules, one at a time
    var container;
    i = searchRecords.length;
    while (i > 0 && !container) {
            i--;
            // watch out for errors if expression not found
            if(typeof(searchRecords[i])!='undefined') container = TH.Search(i+searchRecords[i].toString());
    }
    // update pageId and ContainerId if matched
    if (container) {
            var sourcePageId =  tmPageId;
      if (container.OncePerVisit()) {
            tmOPV=container.Header().OPVTO();
      } else {
            tmOPV=0;
      }
      tmPageId = container.ContainerId();
    }
}