//-- DidIt's tman_iframe.js file
//-- Cached by iStockphoto on 01 May 2010
//-- This is here in case the javascript memcaching failes - we still will try to serve the file

if(!window.LEV){
LEV={};
}
if(!LEV.String){
LEV.String=function(_1){
this.value=new String(_1);
};
LEV.String.prototype={match:function(_2,as){
var _3=this.value.match(_2);
if(!_3){
this.value="";
return this;
}
var _4=_3[0];
if(!as){
this.value=_4;
return this;
}
if(_4){
this.value=_4.replace(_2,as);
}
return this;
},replace:function(_5,as){
this.value=this.value.replace(_5,as);
return this;
},toString:function(){
return this.value;
}};
}
LEV.STG={getCookie:function(_6){
if(document.cookie.length>0){
c_start=document.cookie.indexOf(_6+"=");
if(c_start!=-1){
c_start=c_start+_6.length+1;
c_end=document.cookie.indexOf(";",c_start);
if(c_end==-1){
c_end=document.cookie.length;
}
return unescape(document.cookie.substring(c_start,c_end));
}
}
return null;
}};
LEV.LOG=function(_7){
if(LEV.STG.getCookie("tmDebug")&&typeof (console)!="undefined"&&console&&console.log){
console.log(_7);
}
};
if(!LEV.DOMQ){
LEV.DOMQ=function(el){
this.el=el||document;
};
LEV.DOMQ.factory=function(_8){
var _9=[];
for(var i=0;i<_8.length;i++){
_9[i]=new LEV.DOMQ(_8[i]);
}
return _9;
};
LEV.DOMQ.prototype={id:function(id){
if(!this.el){
return this;
}
this.el=this.el.getElementById(id);
return this;
},tag:function(_a,_b){
if(!this.el){
return this;
}
if(!_b){
_b=0;
}
this.el=this.el.getElementsByTagName(_a)[_b];
return this;
},name:function(_c,_d){
if(!this.el){
return this;
}
if(!_d){
_d=0;
}
this.el=this.getElementsByName(_c)[_d];
return this;
},className:function(_e,_f){
if(!this.el){
return this;
}
if(!_f){
_f=0;
}
this.el=this.getElementsByClassName(_e)[_f];
return this;
},isAncestor:function(_10){
var el=this.el;
if(!el){
return;
}
while(_10){
if(_10==el){
return true;
}
_10=_10.parentNode;
}
},getElementsByName:function(_11){
if(!this.el){
return [];
}
var all=document.getElementsByName(_11);
if(this.el==document){
return all;
}
var _12=[];
for(var i=0;i<all.length;i++){
if(this.isAncestor(all[i])){
_12.push(all[i]);
}
}
return _12;
},getElementsByClassName:function(_13){
if(!this.el){
return [];
}
var e=this.el;
var _14=(e.all)?e.all:e.getElementsByTagName("*");
_13=_13.replace(/\-/g,"\\-");
var reg=new RegExp("(^|\\s)"+_13+"(\\s|$)");
var _15=[];
for(var i=0;i<_14.length;i++){
if(reg.test(_14[i].className)){
_15.push(_14[i]);
}
}
return _15;
},match:function(r,as){
return new LEV.String(this.toString()).match(r,as);
},replace:function(r,as){
return new LEV.String(this.toString()).replace(r,as);
},toString:function(){
if(!this.el){
return "";
}
var s=(this.el==document)?this.el.documentElement.innerHTML:(this.el.value)?this.el.value:this.el.innerHTML;
return s;
}};
LEV.DT=function(){
var P={html:function(){
return new LEV.DOMQ();
},id:function(id){
return P.html().id(id);
},tag:function(tag,_16){
return P.html().tag(tag,_16);
},name:function(_17,_18){
return P.html().name(_17,_18);
},className:function(_19,_1a){
return P.html().className(_19,_1a);
},head:function(){
return P.tag("head");
},body:function(){
return P.tag("body");
}};
var DT=function(_1b){
if(!window.tmParam){
window.tmParam={};
}
for(var _1c in _1b){
var cmd=_1b[_1c];
var s="";
if(typeof cmd=="string"){
s=P.id(cmd);
}else{
if(cmd instanceof RegExp){
s=P.html().match(cmd,"$1");
}else{
if(cmd instanceof Array){
s=P.id(cmd[0]).match(cmd[1],"$1");
}else{
if(typeof cmd=="function"){
s=cmd(P)||"";
}
}
}
}
window.tmParam[_1c]=s.toString();
}
};
if(window.LEV_DT){
DT(window.LEV_DT);
}
return DT;
}();
}
if(!LEV.onDOM){
LEV.onDOM=function(){
var _1d=false;
var _1e=[];
var _1f=function(_20){
if(_1d){
_20();
}else{
_1e.push(_20);
}
};
_1f.isReady=function(){
return _1d;
};
function _21(){
if(_1d){
return;
}
_1d=true;
LEV.extend(tmParam,{tmdom:1});
for(var i=0;i<_1e.length;i++){
_1e[i]();
}
};
var u=navigator.userAgent.toLowerCase();
if(/webkit/.test(u)){
timeout=setTimeout(function(){
if(document.readyState=="loaded"||document.readyState=="complete"){
_21();
}else{
setTimeout(arguments.callee,10);
}
},10);
}else{
if((/mozilla/.test(u)&&!/(compatible)/.test(u))||(/opera/.test(u))){
document.addEventListener("DOMContentLoaded",_21,false);
}else{
if(/msie/.test(u)&&window==top){
var ri=setInterval(function(){
try{
document.documentElement.doScroll("left");
}
catch(e){
return;
}
clearInterval(ri);
ri=null;
_21();
},10);
}else{
var old=window.onload;
window.onload=function(){
_21();
if(old){
old();
}
};
}
}
}
return _1f;
}();
}
LEV.extend=function(o1,o2){
for(var key in o2){
o1[key]=o2[key];
}
return o1;
};
if(typeof (tmPageId)=="undefined"){
if(typeof (tmContId)=="undefined"){
LEV.LOG("tmContId or tmPageId not defined for TagMan container, it's compulsary");
}else{
var tmPageId=tmContId;
}
}
var tmDoc=document;
var tmLoc=tmDoc.location;
var tmPageTitle=DoubleLescape(tmDoc.title,100);
var tmHost=DoubleLescape(tmLoc.hostName);
var tmHash=DoubleLescape(tmLoc.hash);
var tmPath=DoubleLescape(tmLoc.pathname);
var tmSearch=DoubleLescape(tmLoc.search);
var levref=DoubleLescape(tmDoc.referrer,150);
var gooTrans;
if(tmDoc.getElementById){
gooTrans=tmDoc.getElementById("utmtrans");
}else{
if(tmDoc.utmform&&tmDoc.utmform.utmtrans){
gooTrans=tmDoc.utmform.utmtrans;
}
}
if(gooTrans){
gooTrans=DoubleLescape(gooTrans);
}
if(typeof (tmBaseUrl)=="undefined"||typeof (tmPageId)=="undefined"){
LEV.LOG("tmBaseUrl not defined for TagMan, it's compulsary");
}else{
if(window.tmAlreadyRun){
}else{
var tagStr;
var tmStagingUrl=LEV.STG.getCookie("tmStaging");
if(tmStagingUrl===null){
tagStr=tmBaseUrl;
}else{
tagStr=tmBaseUrl.replace(/(.*?)\/\/(.*?)\.(.*)/,"$1//tagstaging.$3");
}
tagStr=tagStr+"/tmpageid="+tmPageId;
window.tmAlreadyRun=1;
tagStr+="&levyouruid="+Math.random();
(function(){
function _22(_23,_24){
if(_24){
var re=new RegExp("[?|&]"+_24+"=([^&]*)");
var m=re.exec(_23);
if(m){
return (m[1]);
}
}
};
var _25=document.location.search;
if(_25){
if(_22(_25,"tmredirect")){
return;
}
var _26=_22(_25,"tmcampid");
if(_26){
LEV.extend(tmParam,{tmcampid:_26,tmad:_22(_25,"tmad"),tmplaceref:_22(_25,"tmplaceref"),tmclickref:_22(_25,"tmclickref")});
}
}
}());
if(window.tmDisableJs){
LEV_TMIFCB();
}else{
var scriptStr=tagStr+LEV_TMIFPS();
document.write("<scr"+"ipt type=\"text/javascript\" src=\""+scriptStr+"&tmtag=js\"></scr"+"ipt>");
}
var loadBookmarklet=LEV.STG.getCookie("tmBookmarklet");
if(loadBookmarklet!==null){
LEV.BMK.loadCoreBm();
}
}
}
function LEV_TMIFPS(){
var _27="";
if(typeof (tmParam)!="undefined"){
for(var _28 in tmParam){
var _29=tmParam[_28];
var _2a=typeof (_29);
if(_28&&_29&&(_2a=="number"||_2a=="string"||_2a=="boolean")){
_27+="&"+_28+"="+DoubleLescape(_29);
}
}
}
return _27;
};
function LEV_TMTCB(){
window.tmTrack=undefined;
if(window.tmTrackWaiting){
LEV_TMIFCB();
}
};
LEV_TMIFCB=function(){
var _2b=function(){
if(window.tmTrack){
window.tmTrackWaiting=1;
return;
}
if(window.tmImmediate){
_2c();
}else{
LEV.onDOM(_2c);
}
};
function _2c(){
if(window.LEV_DT){
LEV.DT(window.LEV_DT);
}
if(window.LEV_DTD){
for(var i=0;i<LEV_DTD.length;i++){
LEV_DTD[i]();
}
}
_2d();
};
function _2e(){
var a=arguments;
var r="";
for(var i=0;i<a.length;i+=2){
var p=a[i];
var v=a[i+1];
r+=(v&&v!="undefined")?"&"+p+"="+v:"";
}
return r;
};
function _2d(){
tagStr+=LEV_TMIFPS();
if(location.hash=="#tmtest"){
parent.location=document.referrer+"#"+tagStr;
}
if(typeof (console)!="undefined"){
try{
LEV.LOG("referrer="+document.referrer);
if(typeof (tmParam)=="object"){
var _2f="";
for(var key in tmParam){
if(typeof (tmParam[key])!="undefined"){
_2f+="\t"+key+"=>"+tmParam[key]+"\n";
}
}
if(!_2f){
_2f="<empty>";
}
}
LEV.LOG("tmParam Contents\n"+_2f);
if(typeof (tmOPV)!="undefined"){
LEV.LOG("tmOPV="+tmOPV);
}
LEV.LOG("tmBaseURL="+tmBaseUrl);
LEV.LOG("tmPageId="+tmPageId);
}
catch(err){
LEV.LOG("logging error on of tmPageId or tmBaseURL probably does not exits");
}
}
if(window.tmCaptureData){
tagStr+=_2e("levref",levref,"tmpagetitle",tmPageTitle,"tmpagehost",tmHost,"tmpagehash",tmHash,"tmpagepath",tmPath,"tmsearch",tmSearch,"tmhost",tmHost);
}
if(window.tmDisableIframe&&!(tmParam.tmad||tmParam.levrev||tmParam.levresdes||tmParam.levordref)){
return;
}
var s=tagStr+"&tmtag=iframe";
if(LEV.onDOM.isReady()){
var _30=document.createElement("iframe");
_30.src=s;
_30.style.width="0px";
_30.style.height="0px";
_30.style.border="0px";
document.getElementsByTagName("body")[0].appendChild(_30);
}else{
document.write("<iframe src=\""+s+"\" width=\"0\" height=\"0\" border=\"0\"></iframe>");
}
LEV.LOG("Iframe written: "+s);
};
return _2b;
}();
function Lescape(_31){
return escape(_31).replace(/\//g,"%2F");
};
function DoubleLescape(_32,lim){
var out=Lescape(Lescape(_32));
if(!lim){
return out;
}
var ind=out.lastIndexOf("%",lim);
var _33=0;
if(ind>lim-3){
_33=ind;
}else{
ind=out.lastIndexOf("%25",lim);
if(ind>lim-5){
_33=ind;
}
}
if(_33>0){
lim=lim-(lim-_33);
}
return out.substr(0,lim);
};
