window.onerror=_winError;
var adURL,playOn,timeBetweenAds,codebase,archive,fqCapDur,fqCapDaily,exitOnClick,trackSite,debugLevel;
var playURL,clickURL,publisherPlayURL,publisherClickURL,advertiserPlayURL,advertiserClickURL;
var u_referrerURL=document.referrer;
var u_ol=u_iframe=u_P=false;
var Unicast=true;
String.prototype.contains = function(s) {return (this.toLowerCase().indexOf(s)!=-1);};
var u_agt=navigator.userAgent.toLowerCase();
var u_OPERA=(u_agt.contains("opera"));
var u_MSIE=(u_agt.contains("msie") && !u_OPERA);
var u_NTSC=(u_agt.contains("mozilla") && !u_agt.contains("spoofer") && !u_agt.contains("compatible")  && !u_OPERA);
var u_WIN=(u_agt.contains("win"));
var u_MAC=(u_agt.contains("mac"));
var u_ver=u_MSIE ? parseFloat(u_agt.replace(/[\w\W]*\smsie\s/,'')) : parseFloat(navigator.appVersion);
var u_mVer=(navigator.appMinorVersion && navigator.appMinorVersion!=0) ? navigator.appMinorVersion.slice(1,-1) : 0;
var u_jar="ARCHIVE=adcontroller.jar";
var u_TS="TransitionSensor";
var noTS="notReady";
var hfs=false;
var u_rc=u_flash=u_director=0;
var u_color;
var _wol, _wul, _wbul;

if (!navigator.unicastdebug) navigator.unicastdebug="0";
if (_writeTag()) {
 _wol = window.onload
 window.onload = _ol;
 if (document.bgColor) u_color=document.bgColor.slice(1);
 if (!u_iframe) u_referrerURL=document.URL;
 if (fqCapDur=="") fqCapDur="0";
 if (fqCapDaily=="") fqCapDaily="0";
 if (!_isEmpty(publisherPlayURL)) playURL=publisherPlayURL;
 if (!_isEmpty(publisherClickURL)) clickURL=publisherClickURL;
 if (_isEmpty(exitOnClick)) exitOnClick="false";
 if (archive=="no") u_jar="";
 if (_isEmpty(codebase)) codebase="http://adcontroller.unicast.com/java32/classes/";
 _dw('<APPLET CODE="com.unicast.adcontroller.tools.TransitionSensor" CODEBASE='+codebase+' NAME='+u_TS+' WIDTH=1 HEIGHT=1 ALIGN=baseline '+u_jar+'>');
 _dw('<PARAM NAME=referrer VALUE='+u_referrerURL+'>');
 _dw('<PARAM NAME=exitOnClick VALUE='+exitOnClick+'>');
 if (!_isEmpty(debugLevel)) _dw('<PARAM NAME=debugLevel VALUE='+debugLevel+'>');
 if (!_isEmpty(playURL)) _dw('<PARAM NAME=amsPlayURL VALUE='+playURL+'>');
 if (!_isEmpty(clickURL)) _dw('<PARAM NAME=amsClickURL VALUE='+clickURL+'>');
 if (!_isEmpty(advertiserPlayURL)) _dw('<PARAM NAME=advertiserPlayURL VALUE='+advertiserPlayURL+'>');
 if (!_isEmpty(advertiserClickURL)) _dw('<PARAM NAME=advertiserClickURL VALUE='+advertiserClickURL+'>');
 if (!_isEmpty(u_color)) _dw('<PARAM NAME=color VALUE='+u_color+'>');
 if (fqCapDur) _dw('<PARAM NAME=fqCap VALUE='+fqCapDur+'>');
 if (fqCapDaily) _dw('<PARAM NAME=fqCapDaily VALUE='+fqCapDaily+'>');
 if (!_isEmpty(timeBetweenAds)) _dw('<PARAM NAME=timeBetweenAds VALUE='+timeBetweenAds+'>');
 if (!_isEmpty(adURL)) _dw('<PARAM NAME=adURL VALUE='+adURL+'>');
 if (!_isEmpty(playOn)) _dw('<PARAM NAME=playOn VALUE='+playOn+'>');
 if (!_isEmpty(trackSite)) _dw('<PARAM NAME=trackSite VALUE='+trackSite+'>');
 _dw('</APPLET>');
 _dw('<APPLET CODE="com.unicast.adcontroller.tools.JSProxy" CODEBASE='+codebase+' NAME=JSProxy WIDTH=1 HEIGHT=1 ALIGN=baseline MAYSCRIPT '+u_jar+'>');
 if (!_isEmpty(u_color)) _dw('<PARAM NAME=color VALUE='+u_color+'>');
 if (!_isEmpty(debugLevel)) {_dw('<PARAM NAME=debugLevel VALUE='+debugLevel+'>'); navigator.unicastdebug=debugLevel;}
 _dw('</APPLET>');
}
function _writeTag() {
 if (!u_WIN && !u_MAC) return _fail(1);
 if (!u_NTSC && !u_MSIE) return _fail(2);
 if (u_MSIE && u_MAC) return _fail(3);
 if (u_ver<4) return _fail(4);
 if (u_NTSC && u_ver<=4.05) return _fail(5);
 if (u_NTSC && u_ver==4.6) return _fail(6);
 if (u_MAC && u_NTSC && u_ver<4.5) return _fail(7);
 if (u_NTSC && u_ver>=5) return _fail(8);
 if (u_MSIE && u_ver>6) return _fail(9);
 if (u_MSIE && u_ver==4.01 && u_mVer.contains("sp1a")) return _fail(9);
 if (_hiFrameSecurity()) return _fail(10);
 if (!_detectPlugins()) return _fail(11);
 if (_tagDetected()) return _fail(12);
 return true;
}
function ts_nbp() {
document.applets[u_TS].nbp();
}
function ts_getPlayURL() {
return document.applets[u_TS].getPlayURL();
}
function ssopen(sswin) {
return sswin.closed;
}
function _tagDetected() {
if (u_NTSC) {
 var netscapeFlag=window.U
 window.U=true;
 return netscapeFlag;
}
var flag=navigator.Unicast;
navigator.Unicast=true;
 if (u_MSIE){
  var cnt=0; 
  if (u_ver<5){
   for (var i=0;i<parent.frames.length;i++)
    if (parent.frames[i].Unicast) cnt++;
  }
  else {
   if (u_ver>=5.5 && !flag) {
     _wbul = window.onbeforeunload;
     window.onbeforeunload=_bul;
   }
   cnt=_execJS("for (var i=cnt=0;i<parent.frames.length;i++) {try {if (parent.frames[i].Unicast)cnt++;}catch(e){}} return cnt;");
  }
  u_iframe=(cnt>=1);
  if (u_iframe && u_ver<5.5) flag=(cnt>1);
 }
 return flag;
}
function _hiFrameSecurity() {
 if (u_MSIE && u_ver>=5)
  return _execJS('try{if (parent.frames.length!=0) return (parent.frames[0]==null);}catch(e){return true}');
 if (u_MSIE && u_ver<5)
  return _execVB('If parent.frames.length<>0 then hfs=IsNull(parent.frames(0)): If Err.Number<>0 then hfs=true: End If', 'hfs');
}
function _detectPlugins() {
 u_flash = _sniffPlugin("Shockwave Flash", "ShockwaveFlash", [5,4,3]);
 return (u_flash>=4);
}
function _sniffPlugin(ntsc, msie, ver) {
 var version=0;
 if (u_NTSC && (navigator.plugins[ntsc]))
  version = parseInt(navigator.plugins[ntsc].description.replace(/[\D]*/,''));
 if (u_MSIE){
  for (var i=0; i<ver.length; i++){
   if (_pluginMSIE(msie, ver[i])){
    version=ver[i];
    break;
   }
  }
 }
 return version;
}
function _pluginMSIE(name, ver) {
 var plug = name+"."+name+"."+ver;
 if (u_ver>=5)
  return _execJS('try{return new ActiveXObject("'+plug+'");}catch(e){return false}');
 if (u_ver<5)
  return _execVB('u_P=IsObject(CreateObject("'+plug+'"))', 'u_P');
}
function _u() {}
function _p(url) {
    var uniqueNum = (new Date()).getTime();
    pos = url.lastIndexOf("http");
    if ( pos == 0){
	   url = url + uniqueNum;
       u_i=new Image();
       u_i.src = url; 
    } else {
       url1=url.substring(0,pos) + uniqueNum;
       url2=url.substring(pos) + uniqueNum;
       u_i=new Image();
       u_i.src=url1;
       u_i=new Image();
       u_i.src=url2;
    }
}
//function _gp() {return _TS() ? document.applets[u_TS].gp(Object) : noTS;}
function _gc() {return _TS() ? document.applets[u_TS].gc(Object) : noTS;}
function _gt() {return (_TS() && _gts()) ? u_TS : null;}
function _gts() {
 if (u_NTSC || (u_MSIE && u_ver<5)) return typeof document.applets[u_TS].gt(Object)!="undefined";
 else return _execJS("try {return typeof document.applets[u_TS].gt(Object)!='undefined';}catch(e){return false;}");
}
function _playNextTrans() {return _TS() ? document.applets[u_TS].playNextTrans() : "false";}
function _getAdType() {return _TS() ? document.applets[u_TS].adType() : null;}
function _ready() {return document.applets[u_TS].ready();}
function _notifyTS() {return _TS() ? document.applets[u_TS].notifyTS() : false;}
function _TS() {
 if (u_MSIE && u_ver>=5)
  return _execJS('try{return ((typeof document.applets[u_TS] != "undefined") && document.applets[u_TS].isActive());}catch(e){return false}');
 else 
  return (typeof document.applets[u_TS]!="undefined" && document.applets[u_TS].isActive());
}
function _getPlayerType() {return document.applets[u_TS].playerType();}
function _isHTMLPlayer() {return document.applets[u_TS].isHTMLPlayer();}
function _dw(string) {document.write(string);}
function _execVB(vb, rc) {execScript("On error resume next:" + vb, "VBScript"); return window[rc];}
function _execJS(js) {var func = new Function(js); return func();}
function _fail(rc) {u_rc=rc; return false;}
function _ol() {u_ol=true; if (_wol) _wol(); if ( _TS()) _onload();}
function _onload() {if (u_ol) document.applets[u_TS].onload();}
function _bul() {if (_wbul) _wbul(); navigator.Unicast=false;}
function _winError() {return true;}
function _isEmpty(data) {if ((!data || data==null) || (typeof data == "string" && (data == "null" || data == "undefined" || data.replace(/\s*/,"")==""))) return true; else return false;}

