function Args() {
    var caller = this._findCaller();
    if (!caller) {
        this._isHttps = window.location.href.match("^https") == "https";
        this._queryString = "no_match_script";
    }
    else {
        this._isHttps = caller.src.match("^https") == "https";
        var qString = caller.src.replace(/^[^\?]+\??/, '');
        if (qString) { this._queryString = qString + "&"; }
    }
}

function createIframe() {
    var iframe;
    if (document.createElement && (iframe = document.createElement('iframe'))) {
        iframe.name = iframe.id = Math.floor((Math.random() + "") * 1000000000000).toString();
        iframe.width = 0;
        iframe.height = 0;
        iframe.style.display = 'none';
        iframe.src = 'about:blank';
    }

    return iframe;
}

if (!Args._SeenScriptCache) Args._SeenScriptCache = new Array();
Args.prototype._findCaller = function () {
    var scripts = document.getElementsByTagName('script');
    for (var i = scripts.length - 1; i >= 0; i--) {
        var src = scripts[i].src;

        if (src.match(/^[^\?]+\?/) && src.match(/doubleverify\.com/) && !Args._SeenScriptCache[i]) {
            if (src.match('ncript18.js')) {
                Args._SeenScriptCache[i] = 1;
                return scripts[i];
            }
        }
        else {
            Args._SeenScriptCache[i] = 1;
        }
    }
    return null;
}

try {
    window.parentIsPermitted = false;
    window.DVCurWin = window;

    try {
        for (i = 0; i <= 10; i++) {
            if ((window.DVCurWin.parent != null) && (window.DVCurWin.parent != window.DVCurWin)) {
                var loc = window.DVCurWin.parent.location.toString();
                var x = loc.length;
                if (x > 0) {
                    window.DVCurWin = window.DVCurWin.parent;
                    window.parentIsPermitted = true;
                }
                else {
                    window.parentIsPermitted = false;
                    break;
                }
            }
            else {
                if (i == 0) {
                    window.parentIsPermitted = true;
                }
                break;
            }
        }
    }
    catch (e)
    { window.parentIsPermitted = false; }

    if (window.DVCurWin.document.referrer.length == 0) {
        window.DVURL = window.DVCurWin.location;
    }
    else {
        if (window.parentIsPermitted) {
            window.DVURL = window.DVCurWin.location;
        }
        else {
            window.DVURL = window.DVCurWin.document.referrer;
        }
    }

    			var serverName = 'tps31.doubleverify.com';		
		
    var qPageID = null;
    var cUrl = null;
    if (window.external != null) {
        qPageID = window.external.QueuePageID != undefined ? window.external.QueuePageID : null;
        cUrl = window.external.CrawlerUrl != undefined ? window.external.CrawlerUrl : null;
    }

    var args = new Args();	
			if (!args._isHttps) {
			var iframe = createIframe();
			document.body.insertBefore(iframe,document.body.firstChild);

			var iframeDocument = (iframe.contentDocument || iframe.contentWindow.document || window.frames[iframe.name].document);
			var src = 'http://' + serverName + '/visit.js?' + args._queryString.replace("agnc=", "ctx=") + '&num=1018&srcurl=' + encodeURIComponent(DVURL) + '&curl=' + (cUrl == null ? '' : encodeURIComponent(cUrl)) + '&qpgid=' + (qPageID == null ? '' : qPageID);
			var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
			if (isChrome) {
				src += '&referrer=' + encodeURIComponent(iframeDocument.referrer);
			}		
			iframeDocument.open();
			iframeDocument.write('<html><head><\/head><body><scr' + 'ipt type="text/javascript" src="' + src + '"><\/scr' + 'ipt><scr' + 'ipt type="text/javascript">var script = document.getElementsByTagName("script")[0]; if (script.readyState) { script.onreadystatechange = function() { if (script.readyState == "complete") document.close(); } } else document.close();<\/scr' + 'ipt><\/body><\/html>');
		}
	
}
catch (ex) { } 


