
var ehs_gamsites = ["ehs.pro.intechopen.intechopen"];

// Get URL
	var ehs_dmn=window.location.href;

if (typeof window.apntag == "undefined") {
var apntag = window.apntag || {};     
apntag.anq = apntag.anq || [];
(function() {
   var d = document, e = d.createElement('script'), p = d.getElementsByTagName('head')[0];
   e.type = 'text/javascript';  e.async = true;
   e.src = '//acdn.adnxs.com/ast/ast.js';
   p.insertBefore(e, p.firstChild);
})();

var ehsAdsObj = window.ehsAdsObj || {};
var ehsAdsLog = window.ehsAdsLog || {};
	
// Load GPT
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
});
(function () {
var gads = document.createElement("script");
gads.async = true;
gads.type = "text/javascript";
var useSSL = "https:" == document.location.protocol;
gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js";
var node = document.getElementsByTagName("script")[0];
node.parentNode.insertBefore(gads, node);
})();

/*(function(w,d,s,m,n,t){
	w[m]=w[m]||{init:function(){(w[m].q=w[m].q||[]).push(arguments);},ready:function(c){if('function'!=typeof c){return;}(w[m].c=w[m].c||[]).push(c);c=w[m].c;
	n.onload=n.onreadystatechange=function(){if(!n.readyState||/loaded|complete/.test(n.readyState)){n.onload=n.onreadystatechange=null;if(t.parentNode&&n.parentNode){t.parentNode.removeChild(n);}
	while(c.length){(c.shift())();}}};}},w[m].d=1*new Date();n=d.createElement(s);t=d.getElementsByTagName(s)[0];n.async=1;n.src='//www.medtargetsystem.com/javascript/beacon.js';
	n.setAttribute("data-aim",m); t.parentNode.insertBefore(n,t);
})(window,document,'script','EHSAIM');

EHSAIM.init('52-500-9E888B4D');*/

(function() {
	var e = document.createElement("iframe");
	e.style.display = "none";
	e.src="https://dmp.tapnative.com/adx-tag-manager/container?id=2d65abf806236849a9c5ac1200bf876c&adx_custom=";
	document.body.appendChild(e);
})();

	// Consent manager
	function setEHSConsent () {
		document.getElementById('ehsConsent').style.display='none';
		var date = new Date();
			date.setTime(date.getTime()+(240*24*60*60*1000));
		document.cookie='ehsconsent=1;expires='+date.toGMTString()+';path=/';
	}
	function getEHSConsent () {
		var re = new RegExp("ehsconsent=([^;]+)");
			var value = re.exec(document.cookie);
			return (value != null) ? unescape(value[1]) : null;
	}
	if (ehs_dmn.includes("diabetesincontrol.com/?ehstest") && getEHSConsent()!="1") {
		var ehsConsentDiv=document.createElement('div');
		ehsConsentDiv.id="ehsConsent";
		ehsConsentDiv.style.backgroundColor="#CCC";
		ehsConsentDiv.style.minHeight="26px";
		ehsConsentDiv.style.fontSize="14px";
		ehsConsentDiv.style.color="#111";
		ehsConsentDiv.style.lineHeight="26px";
		ehsConsentDiv.style.padding="8px 0 8px 30px";
		ehsConsentDiv.style.position="fixed";
		ehsConsentDiv.style.bottom="0";
		ehsConsentDiv.style.left="0";
		ehsConsentDiv.style.right="0";
		ehsConsentDiv.style.zIndex="9999";
		ehsConsentDiv.innerHTML="eHealthcare Solutions (EHS) managed advertising on this website. By continuing, you agree to the use of cookies as per the <a href='http://ehealthcaresolutions.com/privacy-policy/' target='_blank' id='ehsConsentA1'>EHS Privacy Policy</a> <a href='#' onClick='setEHSConsent();return false;' id='ehsConsentA2'>Continue</a>";
		document.body.appendChild(ehsConsentDiv); 
		var ehsConsentElA1=document.getElementById("ehsConsentA1");
		var ehsConsentElA2=document.getElementById("ehsConsentA2");
		ehsConsentElA1.style.color="#4B8EE7";
		ehsConsentElA1.style.textDecoration="none";
		ehsConsentElA2.style.backgroundColor="#22DD22";
		ehsConsentElA2.style.color="#000";
		ehsConsentElA2.style.display="inline-block";
		ehsConsentElA2.style.borderRadius="5px";
		ehsConsentElA2.style.padding="0 20px";
		ehsConsentElA2.style.cursor="pointer";
		ehsConsentElA2.style.float="right";
		ehsConsentElA2.style.margin="0 60px 0 10px";
	}
	
// Quantcast
window._qevents = window._qevents || [];
(function() {
var elem = document.createElement('script');
elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js";
elem.async = true;
elem.type = "text/javascript";
var scpt = document.getElementsByTagName('script')[0];
scpt.parentNode.insertBefore(elem, scpt);
})();
window._qevents.push({
qacct:"p-JvWVMLN-qY9aC",
uid:""
});

// Set config to true
window.ehs_config = true;

}

(function () {
var ehs_kv=[],ehs_adid="intechopen-intechopen-8",ehs_site="ehs.pro.intechopen.intechopen",ehs_zone="",ehs_size="300x250",ehs_vpos="",ehs_hpos="",ehs_puid="";ehs_kv.push("hbid=true;");ehs_kv.push("iprof=md;");ehs_kv.push("r=1589780215811561.5;");
function ehsGetUrlKeywords() {
  var kws = ["psoriasis","dermatitis","melanoma","keratosis","acne"];
  var u = decodeURIComponent((location.href || "").toLowerCase());
  var found = [];
  for (var i = 0; i < kws.length; i++) {
    if (u.indexOf(kws[i]) > -1 && found.indexOf(kws[i]) === -1) {
      found.push(kws[i]);
    }
  }
  return found.length ? "eurlkw=" + found.join(";eurlkw=") + ";" : "";
}

function ehsGetMetaKeywords() {
  var kws = ["psoriasis","dermatitis","melanoma","keratosis","acne"];
  var meta = document.querySelector('meta[name="description"]');
  if (!meta) return "";
  var d = meta.content ? meta.content.toLowerCase() : "";
  var found = [];
  for (var i = 0; i < kws.length; i++) {
    if (d.indexOf(kws[i]) > -1 && found.indexOf(kws[i]) === -1) {
      found.push(kws[i]);
    }
  }
  return found.length ? "emetakw=" + found.join(";emetakw=") + ";" : "";
}

function ehsIsInViewport(id) {
	var el=document.getElementById(id);
    const rect = el.getBoundingClientRect();
    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth) &&
		!document.hidden
    );
}

function refresh(slot) {
  ehsAdsObj[slot.getSlotElementId()].refreshTimer = false;
  window.pbjs.que.push(function () {
    window.pbjs.requestBids({
      timeout: 3000,
      adUnitCodes: [ehs_adid],
      bidsBackHandler: function () {
        window.pbjs.setTargetingForGPTAsync([ehs_adid]);
        googletag.pubads().refresh([slot]);
      }
    });
  });
}

function genKVgam (ehs_kv) {
	// Filter and join all key-values into one string
	ehs_len = ehs_kv.length;
	for (ehs_i = 0; ehs_i < ehs_len; ehs_i++) {
	if (typeof ehs_kv[ehs_i] != "undefined") {
	ehs_kv[ehs_i] = ehs_kv[ehs_i].replace(/[^A-z0-9_\-=;]/g, "_");
	if (ehs_kv[ehs_i].slice(-1) != ";")
	ehs_kv[ehs_i] += ";";
	}
	}
	var ehs_kvstring = ehs_kv.join("");

	// Create array of all eligible (not empty or null) key-values in the format: a[key]="value1,value2,value3,...";
	var ehs_kva = ehs_kvstring.split(";");
	ehs_len = ehs_kva.length;
	var ehs_kvarray = [];
	for (ehs_i = 0; ehs_i < ehs_len; ehs_i++) {
	if (ehs_kva[ehs_i].match(/[a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-]+/g)) {
	var ehs_temp = ehs_kva[ehs_i].split("=");
	if (ehs_kvarray[ehs_temp[0]] === undefined && ehs_temp[1] != "null" && ehs_temp[1] != "")
	ehs_kvarray[ehs_temp[0]] = ehs_temp[1];
	else if (ehs_temp[1] != "null" && ehs_temp[1] != "") {
	if (ehs_kvarray[ehs_temp[0]].indexOf(ehs_temp[1]) == -1)
	ehs_kvarray[ehs_temp[0]] += "," + ehs_temp[1];
	}
	}
	}
	return ehs_kvarray;
}

function displayAdGAM (ehs_kvarray) {
	if (ehs_size == "inter") {
		var googletag = window.googletag || {};
    googletag.cmd = googletag.cmd || [];
		// Start GPT
		googletag.cmd.push(function () {
			googletag.defineOutOfPageSlot(ehs_target, ehs_adid).addService(googletag.pubads());
			for (var ehs_kvkey in ehs_kvarray) {
				if (ehs_kvarray.hasOwnProperty(ehs_kvkey)) {
					var ehs_kvvalue = ehs_kvarray[ehs_kvkey];
					googletag.pubads().setTargeting(ehs_kvkey, ehs_kvvalue);
				}
			}
			googletag.pubads().setTargeting('adid', ehs_adid);
			googletag.pubads().collapseEmptyDivs();
			googletag.enableServices();
		});
		// Display ad
		googletag.cmd.push(function () {
			googletag.display(ehs_adid);
		});
	}
	else {
		var googletag = window.googletag || {};
    googletag.cmd = googletag.cmd || [];

		var pbjs = pbjs || {};
		pbjs.que = pbjs.que || [];
		var prebidSites={"ehs.pro.hiper.dic":[{bidder:'appnexus',params:{placementId:22128823}},{bidder:'ix',params:{siteId:608084}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'773368575'}},{bidder:'sonobi',params:{placement_id:'0c380396f0ddf0f98f8c'}},{bidder:'unruly',params:{siteId:237100}},{bidder:'smartadserver',params:{siteId:428955,pageId:1408913,formatId:105018}},{bidder:'deepintent',params:{tagId:"907"}},{bidder:'gourmetads',params:{placementId:'26773341',usePaymentRule:true}}],"ehs.pro.intechopen.intechopen":[{bidder:'appnexus',params:{placementId:22127074}},{bidder:'ix',params:{siteId:608084}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'107123274'}},{bidder:'sonobi',params:{placement_id:'1c65de51688d95b9734b'}},{bidder:'unruly',params:{siteId:237101}},{bidder:'deepintent',params:{tagId:"1073"}},{bidder:'brightcom',params:{publisherId:20675}},{bidder:'gourmetads',params:{placementId:'26773263',usePaymentRule:true}},{bidder:'ogury',params:{assetKey: 'OGY-243D9F9914F7',adUnitId: 'wd-hb-stdb-intech-eheal-vsufuwkj5qvw'}}],"ehs.pro.behavenet.behavenet":[{bidder:'appnexus',params:{placementId:22653637}},{bidder:'sonobi',params:{placement_id:'25843e78f3f3ecfcf176'}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'343888546'}},{bidder:'deepintent',params:{tagId:"1081"}}],"ehs.con.hw.healingwell":[{bidder:'appnexus',params:{placementId:22801620}},{bidder:'ix',params:{siteId:721943}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'391061224'}},{bidder:'sonobi',params:{placement_id:'ed54a79fafeb0d0fe945'}},{bidder:'smartadserver',params:{siteId:428579,pageId:1408446,formatId:105018}},{bidder:'deepintent',params:{tagId:"1075"}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmeanatomy":[{bidder:'appnexus',params:{placementId:22801634}},{bidder:'ix',params:{siteId:721956}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'479654059'}},{bidder:'smartadserver',params:{siteId:465272,pageId:1472006,formatId:105018}},{bidder:'deepintent',params:{tagId:"1087"}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmesurgery":[{bidder:'appnexus',params:{placementId:23377650}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmephysiology":[{bidder:'appnexus',params:{placementId:23377621}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmeobgyn":[{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmepaed":[{bidder:'brightcom',params:{publisherId:20675}}],"ehs.con.medindia.medindia":[{bidder:'appnexus',params:{placementId:22801618}},{bidder:'ix',params:{siteId:721942}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'513804132'}},{bidder:'sonobi',params:{placement_id:'b65b9d533c92059a7c8e'}},{bidder:'smartadserver',params:{siteId:428579,pageId:1408446,formatId:105018}},{bidder:'deepintent',params:{tagId:"1074"}}],"ehs.con.ehs.pharmamktg":[{bidder:'appnexus',params:{placementId:22801632}},{bidder:'ix',params:{siteId:721945}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'667450268'}},{bidder:'sonobi',params:{placement_id:'5ec558a60a200bf263f4'}},{bidder:'smartadserver',params:{siteId:428961,pageId:1408922,formatId:105018}},{bidder:'deepintent',params:{tagId:"1077"}}],"ehs.con.ehs.diabetesnews":[{bidder:'appnexus',params:{placementId:22778391}},{bidder:'ix',params:{siteId:721951}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'525744048'}},{bidder:'smartadserver',params:{siteId:465268,pageId:1472002,formatId:105018}},{bidder:'deepintent',params:{tagId:"1082"}}],"ehs.con.findadoc.findadoc":[{bidder:'appnexus',params:{placementId:23173334}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'845951061'}},{bidder:'smartadserver',params:{siteId:465271,pageId:1472005,formatId:105018}},{bidder:'deepintent',params:{tagId:"1101"}}],"ehs.pro.caredash.caredash":[{bidder:'appnexus',params:{placementId:27918466}},{bidder:'ix',params:{siteId:907625}},{bidder:'brightcom',params:{publisherId:20675}}]};
		var prebidSizes = '320,50,728,90,728,240,300,250,160,600,300,600';
		var isPrebidEligible = prebidSizes.includes(dim.toString());
		var isSiteEligible = ehs_site in prebidSites;

		if (isPrebidEligible && isSiteEligible) {
			var adUnits = [{
				code: ehs_adid,
				mediaTypes: {
					banner: {
						sizes: dim
					}
				},
				bids: prebidSites[ehs_site]
			}];

			window.pbjs.que.push(function() {
					window.pbjs.addAdUnits(adUnits);
					pbjs.setConfig({
					userSync: {
						userIds: [{
							name: "criteo",
						}]
					},
					"schain": {
						"validation": "relaxed",
						"config": {
						  "ver":"1.0",
						  "complete": 1,
						  "nodes": [
							{
							  "asi":"gourmetads.com",
							  "sid":"12345",
							  "hp":1
							}
						  ]
						}
					  }
					});
			});
		}
		
		// Start GPT
		googletag.cmd.push(function () {
			var slot = googletag.defineSlot(ehs_target, dim, ehs_adid).addService(googletag.pubads());
			for (var ehs_kvkey in ehs_kvarray) {
				if (ehs_kvarray.hasOwnProperty(ehs_kvkey)) {
					var ehs_kvvalue = ehs_kvarray[ehs_kvkey];
					googletag.pubads().setTargeting(ehs_kvkey, ehs_kvvalue);
				}
			}
			var g=window.localStorage.getItem("_pdfps");
			googletag.pubads().setTargeting("permutive",g?JSON.parse(g):[]);
			googletag.pubads().setTargeting('adid', ehs_adid);
			googletag.pubads().setTargeting('vp', ehs_vpos);
			googletag.pubads().setTargeting('hp', ehs_hpos);
			googletag.pubads().collapseEmptyDivs();
			// Lazy loading option
			if (ehs_adid=="intechopen-intechopen-3" || ehs_adid=="intechopen-intechopen-4" || ehs_adid=="hw-healingwell-0" || ehs_adid=="hw-healingwell-1" || ehs_adid=="hw-healingwell-2" || ehs_adid=="hw-healingwell-3") {
				googletag.pubads().enableLazyLoad({fetchMarginPercent: 0, renderMarginPercent: 0});
			}
			if (isPrebidEligible && isSiteEligible) {
				var refreshTime = 30;
				ehsAdsObj[ehs_adid] = {};
				ehsAdsObj[ehs_adid].slot = slot;
				ehsAdsObj[ehs_adid].refreshTimer = false;

				googletag.pubads().addEventListener('impressionViewable', function(event) {
							var slot = event.slot;
							if (ehsAdsObj[slot.getSlotElementId()] && !ehsAdsObj[slot.getSlotElementId()].refreshTimer) {
								ehsAdsObj[slot.getSlotElementId()].refreshTimer = true;
								setTimeout(function() {
									refresh(slot);
								}, refreshTime * 1000);
							}	
						});
			}
			googletag.enableServices();
		});
		// Display ad
		if (isPrebidEligible && isSiteEligible) {
			window.pbjs.que.push(() => {
				window.pbjs.requestBids({
					timeout: 3000,
					adUnitCodes: [ehs_adid],
					bidsBackHandler: function bidsBackHandler() {
						window.pbjs.setTargetingForGPTAsync([ehs_adid]);
						googletag.cmd.push(() => {
							googletag.display(ehs_adid);
						});
					},
				});
			});
		} else {
			googletag.cmd.push(function () {
				googletag.display(ehs_adid);
			});
		}
	}
}

function genKVxandr (ehs_kv) {
	// Filter and join all key-values into one string
	ehs_len = ehs_kv.length;
	for (ehs_i = 0; ehs_i < ehs_len; ehs_i++) {
	if (typeof ehs_kv[ehs_i] != "undefined") {
	ehs_kv[ehs_i] = ehs_kv[ehs_i].replace(/[^A-z0-9_\-=;]/g, "_");
	if (ehs_kv[ehs_i].slice(-1) != ";")
	ehs_kv[ehs_i] += ";";
	}
	}
	var ehs_kvstring = ehs_kv.join("");

	// Create array of all eligible (not empty or null) key-values in the format: a[key]="value1,value2,value3,...";
	var ehs_kva = ehs_kvstring.split(";");
	ehs_len = ehs_kva.length;
	var ehs_kvarray = [];
	for (ehs_i = 0; ehs_i < ehs_len; ehs_i++) {
	if (ehs_kva[ehs_i].match(/[a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-]+/g)) {
	var ehs_temp = ehs_kva[ehs_i].split("=");
	if (ehs_kvarray[ehs_temp[0]] === undefined && ehs_temp[1] != "null" && ehs_temp[1] != "")
	ehs_kvarray[ehs_temp[0]] = ehs_temp[1];
	else if (ehs_temp[1] != "null" && ehs_temp[1] != "") {
	if (ehs_kvarray[ehs_temp[0]].indexOf(ehs_temp[1]) == -1)
	ehs_kvarray[ehs_temp[0]] += "," + ehs_temp[1];
	}
	}
	}
	var ehs_kvs = {};
	for (var ehs_kvkey in ehs_kvarray) {
		if (typeof ehs_kvarray[ehs_kvkey] === 'string' || ehs_kvarray[ehs_kvkey] instanceof String) {
			var ehs_kvvalue = ehs_kvarray[ehs_kvkey].split(",");
			ehs_kvs[ehs_kvkey] = ehs_kvvalue;
		}
	}
	return ehs_kvs;
}

function displayAdXandr (ehs_kvs) {
	// ad counter for lazy Load
	var ehs_adcount=[];
	ehs_adcount[ehs_adid]=0;
	var apntag = window.apntag || {};  
    apntag.anq = apntag.anq || [];
	var pbjs = window.pbjs || {};
	pbjs.que = pbjs.que || [];
	
		var prebidSites={"ehs.pro.hiper.dic":[{bidder:'appnexus',params:{placementId:22128823}},{bidder:'appnexus',params:{placementId:36783343},member:'3659'},{bidder:'ix',params:{siteId:608084}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'773368575'}},{bidder:'unruly',params:{siteId:237100}},{bidder:'smartadserver',params:{siteId:428955,pageId:1408913,formatId:105018}},{bidder:'deepintent',params:{tagId:"907"}},{bidder:'gourmetads',params:{placementId:'26773341',usePaymentRule:true}}],"ehs.pro.intechopen.intechopen":[{bidder:'appnexus',params:{placementId:22127074}},{bidder:'ix',params:{siteId:608084}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'107123274'}},{bidder:'sonobi',params:{placement_id:'1c65de51688d95b9734b'}},{bidder:'unruly',params:{siteId:237101}},{bidder:'deepintent',params:{tagId:"1073"}},{bidder:'brightcom',params:{publisherId:20675}},{bidder:'gourmetads',params:{placementId:'26773263',usePaymentRule:true}}],"ehs.pro.behavenet.behavenet":[{bidder:'appnexus',params:{placementId:22653637}},{bidder:'sonobi',params:{placement_id:'25843e78f3f3ecfcf176'}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'343888546'}},{bidder:'deepintent',params:{tagId:"1081"}}],"ehs.con.hw.healingwell":[{bidder:'appnexus',params:{placementId:22801620}},{bidder:'ix',params:{siteId:721943}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'391061224'}},{bidder:'sonobi',params:{placement_id:'ed54a79fafeb0d0fe945'}},{bidder:'smartadserver',params:{siteId:428579,pageId:1408446,formatId:105018}},{bidder:'deepintent',params:{tagId:"1075"}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmeanatomy":[{bidder:'appnexus',params:{placementId:22801634}},{bidder:'ix',params:{siteId:721956}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'479654059'}},{bidder:'smartadserver',params:{siteId:465272,pageId:1472006,formatId:105018}},{bidder:'deepintent',params:{tagId:"1087"}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmesurgery":[{bidder:'appnexus',params:{placementId:23377650}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmephysiology":[{bidder:'appnexus',params:{placementId:23377621}},{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmeobgyn":[{bidder:'brightcom',params:{publisherId:20675}}],"ehs.pro.teachme.teachmepaed":[{bidder:'brightcom',params:{publisherId:20675}}],"ehs.con.medindia.medindia":[{bidder:'appnexus',params:{placementId:22801618}},{bidder:'ix',params:{siteId:721942}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'513804132'}},{bidder:'sonobi',params:{placement_id:'b65b9d533c92059a7c8e'}},{bidder:'smartadserver',params:{siteId:428579,pageId:1408446,formatId:105018}},{bidder:'deepintent',params:{tagId:"1074"}}],"ehs.con.ehs.pharmamktg":[{bidder:'appnexus',params:{placementId:36783343},member:'3659'},{bidder:'appnexus',params:{placementId:22801632}},{bidder:'ix',params:{siteId:721945}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'667450268'}},{bidder:'sonobi',params:{placement_id:'5ec558a60a200bf263f4'}},{bidder:'smartadserver',params:{siteId:428961,pageId:1408922,formatId:105018}},{bidder:'deepintent',params:{tagId:"1077"}}],"ehs.con.ehs.diabetesnews":[{bidder:'appnexus',params:{placementId:22778391}},{bidder:'ix',params:{siteId:721951}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'525744048'}},{bidder:'smartadserver',params:{siteId:465268,pageId:1472002,formatId:105018}},{bidder:'deepintent',params:{tagId:"1082"}}],"ehs.con.findadoc.findadoc":[{bidder:'appnexus',params:{placementId:23173334}},{bidder:'medianet',params:{cid:'8CUXI52YQ',crid:'845951061'}},{bidder:'smartadserver',params:{siteId:465271,pageId:1472005,formatId:105018}},{bidder:'deepintent',params:{tagId:"1101"}}],"ehs.pro.caredash.caredash":[{bidder:'appnexus',params:{placementId:27918466}},{bidder:'ix',params:{siteId:907625}},{bidder:'brightcom',params:{publisherId:20675}}]};
	var prebidSizes = '320,50,728,90,728,240,300,250,160,600,300,600';
	var isPrebidEligible = prebidSizes.includes(dim.toString());
	var isSiteEligible = ehs_site in prebidSites;
	
	if (isPrebidEligible && isSiteEligible) {
		var adUnits = [{
			code: ehs_adid,
			mediaTypes: {
				banner: {
					sizes: dim
				}
			},
			bids: prebidSites[ehs_site]
		}];

		window.pbjs.que.push(function() {
				window.pbjs.addAdUnits(adUnits);
				pbjs.setConfig({
				userSync: {
					userIds: [{
						name: "criteo",
					}]
				},
				"schain": {
					"validation": "relaxed",
					"config": {
					  "ver":"1.0",
					  "complete": 1,
					  "nodes": [
						{
						  "asi":"gourmetads.com",
						  "sid":"12345",
						  "hp":1
						}
					  ]
					}
				  }
				});
		});
	}
	
    apntag.anq.push(function() {
		var apntag = window.apntag || {};  
		apntag.anq = apntag.anq || [];
        apntag.defineTag({
            member: 3659,
			keywords: ehs_kvs,
			//tagId: ehs_tagid,
			invCode: ehs_site,
            sizes: dim,
            targetId: ehs_adid,
			disablePsa: true,
			consentManagement: {disabled: false,timeout: 100,gpp: {disabled: false}}
        });
		apntag.onEvent('adAvailable', ehs_adid, function(adAvailable, adObj){
        ehsAdsLog[ehs_adid].ad = adAvailable;
		});
        //apntag.loadTags();
		
		// xandr events
		if (ehs_dmn.includes("drugs.com")) {
		//apntag.onEvent('adAvailable', ehs_adid, function(adAvailable, adObj){
        //console.log('callback adAvailable');
        //console.log(adAvailable);
		//});
		apntag.onEvent('adNoBid', ehs_adid, function(adNoBid, adObj){
        console.log('callback adNoBid');
        console.log(adNoBid);
		window.googletag = window.googletag || {cmd: []};
		googletag.cmd.push(function() {
			googletag.defineSlot('/7146/drugs/pro', dim, ehs_adid)
				.addService(googletag.pubads())
				.setTargeting('p', '1');
			googletag.enableServices();
			googletag.display(ehs_adid);
		});
		});
		}
		//end xandr events
    });
	if (isPrebidEligible && isSiteEligible) {
		window.pbjs.que.push(() => {
			window.pbjs.requestBids({
				timeout: 3000,
				adUnitCodes: [ehs_adid],
				bidsBackHandler: function bidsBackHandler() {
					var apntag = window.apntag || {};  
					apntag.anq = apntag.anq || [];
					window.pbjs.setTargetingForAst([ehs_adid]);
					apntag.anq.push(function() {
					apntag.loadTags();
					apntag.showTag(ehs_adid);
				});
				},
			});
		});
	}
	else {
		apntag.anq.push(function() {
			// Lazy load setup
			if ((ehs_dmn.includes("aad1.org")) && ehsIsInViewport(ehs_adid)) {
				apntag.loadTags();
				apntag.showTag(ehs_adid);
				ehs_adcount[ehs_adid]++;
				console.log("********"+ehs_adid+": "+ehs_adcount[ehs_adid]);
			} // non lazy load
			else if (!(ehs_dmn.includes("aad1.org"))) {
				apntag.loadTags();
				apntag.showTag(ehs_adid);
			}
		});
	}
	// add scrolling listener for lazy load
	document.addEventListener('scroll', function () {
		if ((ehs_dmn.includes("aad1.org")) && ehs_adcount[ehs_adid]==0 && ehsIsInViewport(ehs_adid)) {
			apntag.loadTags();
			apntag.showTag(ehs_adid);
			ehs_adcount[ehs_adid]++;
			console.log("********"+ehs_adid+": "+ehs_adcount[ehs_adid]);
		}
	}, {
	passive: true
	});
}

// Initialize all vars
var ehs_zonepat = /^[A-z]{1}[A-z0-9_-]{1,30}$/i,
ehs_kvpat = /^([A-z]{1}[A-z0-9_-]{1,11}=[A-z0-9_-]{1,241})$/i,
ehs_sitea = ehs_site.split("."),
ehs_class = "class=" + ehs_sitea[1] + ";",
ehs_pub = "pub=" + ehs_sitea[2] + ";",
ehs_sn = "sn=" + ehs_sitea[3] + ";",
ehs_zn = "zn=" + ehs_zone + ";",
ehs_path = document.location.pathname,
ehs_patha = ehs_path.split("/"),
ehs_query = document.location.search,
ehs_pgq = ehs_query.replace(/[^A-z0-9_-]/g, "_"),
ehs_i = 0,
cclookup = (typeof cclookup === 'undefined')?"":cclookup,
ehs_contkv = (typeof ehs_contkv === 'undefined')?"":ehs_contkv,
ehs_z3 = (typeof ehs_z3 === 'undefined')?"":ehs_z3,
ehs_id = (typeof ehs_id === 'undefined')?"":ehs_id;
// Get puid from URL if publisher doesn't provide
if (ehs_puid == "" && ehs_query.indexOf("puid=") > -1) {
ehs_puid = ehs_query.substring(ehs_query.indexOf("puid=") + 5);
}
// Check for homepage
if (ehs_path=="/" || ehs_path=="/spectrum" || ehs_path=="/spectrum/" || ehs_path=="/care" || ehs_path=="/care/" || ehs_path=="/clinical" || ehs_path=="/clinical/" || ehs_path=="/diabetes" || ehs_path=="/diabetes/") ehs_zn = "zn=homepage;";

// EHS inventory mapping
//var ehs_inventory={"ehs.pro.hiper.dic":6195372,"ehs.pro.ehs.medgoo":6195372};
var ehs_inventory={"ehs.pro.hiper.dic":6195372,"ehs.pro.ehs.medgoo":23353867,"ehs.test":24256859};
var ehs_tagid=ehs_inventory[ehs_site];

// Start pushing all Key-Values into array
ehs_kv.push("adid="+ehs_adid+";");
ehs_kv.push(cclookup);
ehs_kv.push(ehs_contkv);
ehs_kv.push(ehs_z3);
ehs_kv.push(ehs_class, ehs_pub, ehs_sn, ehs_zn);
ehs_kv.push(ehsGetUrlKeywords());
ehs_kv.push(ehsGetMetaKeywords());

// Run through page path and push page key-values into pgp
var ehs_len = ehs_patha.length;
for (ehs_i = 0; ehs_i < ehs_len; ehs_i++) {
if (ehs_patha[ehs_i] != "") {
ehs_pgp = "pgp=" + ehs_patha[ehs_i].replace(/[^A-z0-9_-]/g, "_") + ";";
ehs_kv.push(ehs_pgp);
}
}

// Push page query key-value into pgq
ehs_pgq = ehs_pgq.length <= 250 ? "pgq=" + ehs_pgq.substring(1) + ";" : "pgq=" + ehs_pgq.substring(1, 250) + ";";
ehs_kv.push(ehs_pgq);

// If spanish add lng=es
if (ehs_dmn.includes("es.familydoctor.org")) {
	ehs_kv.push("lng=es;");
}

// GAM setup

// Add zone to target
if (ehs_site=="ehs.pro.hiper.dic" || ehs_site=="ehs.pro.teachme.teachmeanatomy" || ehs_site=="ehs.pro.teachme.teachmesurgery" || ehs_site=="ehs.pro.teachme.teachmephysiology" || ehs_site=="ehs.con.hw.healingwell" || ehs_site=="ehs.pro.intechopen.intechopen" || ehs_site=="ehs.pro.pdr.pdrnetwork" || ehs_site=="ehs.con.medindia.medindia" || ehs_site=="ehs.con.medindia.medindia" || ehs_site=="ehs.pro.behavenet.behavenet" || ehs_site=="ehs.pro.teachme.teachmeobgyn" || ehs_site=="ehs.pro.teachme.teachmepaed" || ehs_site=="ehs.pro.caredash.caredash" || ehs_site=="ehs.con.skinsight.skinsight" || ehs_site=="ehs.pro.dl.doctorslounge" || ehs_site=="ehs.pro.rxec.rxeconsult" || ehs_site=="ehs.con.ehs.diabetesnews") var ehs_network="/10271103/";
else var ehs_network="/6913/";
var ehs_target = ehs_network + ehs_site;
ehs_target += ehs_zonepat.test(ehs_zone) ? "/" + ehs_zone : "";

// Define size for GPT
if (ehs_size=="inter") {
	var dim=[[0, 0]];
}
else {
	var dima = ehs_size.split(",");
	ehs_len = dima.length;
	var dim = [];
	for (ehs_i = 0; ehs_i < ehs_len; ehs_i++) {
		dima1 = dima[ehs_i].split("x");
		var ehs_width = parseInt(dima1[0]);
		var ehs_height = parseInt(dima1[1]);
		dim.push([ehs_width, ehs_height]);
	}
}

if ((!ehs_gamsites.includes(ehs_site) || document.location.search=="?ehs_test" || ehs_dmn.includes("intechopen.com/chapters/86424")) && document.location.search!="?ehs_gam") {
if (ehs_dmn.includes("diabetesjournals.org1") && typeof AIM_106.ready==="function") {
	AIM_106.ready(function(){
		if (typeof AIM_106.ondetect==="function") {
			AIM_106.ondetect(function(json){
				if (typeof json.identity_type != "undefined") {
					console.log("t="+json.identity_type);
				}
				var ehs_kvs=genKVxandr(ehs_kv);
				displayAdXandr(ehs_kvs);
				if (ehs_dmn.includes("intechopen.com")) {
					console.log(ehs_dmn);
				}
				ehsAdsLog[ehs_adid] = {};
				ehsAdsLog[ehs_adid].site = ehs_site;
				ehsAdsLog[ehs_adid].size = ehs_size;
				ehsAdsLog[ehs_adid].kv = ehs_kvs;
				console.log(JSON.stringify(json, null, 2));
			});
		}
		else {
			var ehs_kvs=genKVxandr(ehs_kv);
			displayAdXandr(ehs_kvs);
			if (ehs_dmn.includes("intechopen.com")) {
				console.log(ehs_dmn);
			}
			ehsAdsLog[ehs_adid] = {};
			ehsAdsLog[ehs_adid].site = ehs_site;
			ehsAdsLog[ehs_adid].size = ehs_size;
			ehsAdsLog[ehs_adid].kv = ehs_kvs;
		}
	});
}
else {
	var ehs_kvs=genKVxandr(ehs_kv);
	displayAdXandr(ehs_kvs);
	if (ehs_dmn.includes("intechopen.com")) {
		console.log(ehs_dmn);
	}
	ehsAdsLog[ehs_adid] = {};
	ehsAdsLog[ehs_adid].site = ehs_site;
	ehsAdsLog[ehs_adid].size = ehs_size;
	ehsAdsLog[ehs_adid].kv = ehs_kvs;
}
}
else {
	var ehs_kvs=genKVgam(ehs_kv);
	displayAdGAM(ehs_kvs);
}

// Xandr Audience Pixels
if (ehs_site=="ehs.con.ada.diabetes") {
	(function() {
	var d = document, e = d.createElement('script'), p = d.getElementsByTagName('head')[0];
	e.type = 'text/javascript';  e.async = true;
	e.src = 'https://secure.adnxs.com/seg?add=31351255&t=1';
	p.insertBefore(e, p.firstChild);
	})();
}
if (ehs_site=="ehs.con.aad.aad") {
	(function() {
	var d = document, e = d.createElement('script'), p = d.getElementsByTagName('head')[0];
	e.type = 'text/javascript';  e.async = true;
	e.src = 'https://secure.adnxs.com/seg?add=37325672&t=1';
	p.insertBefore(e, p.firstChild);
	})();
}
if (ehs_site=="ehs.pro.aad.aad") {
	(function() {
	var d = document, e = d.createElement('script'), p = d.getElementsByTagName('head')[0];
	e.type = 'text/javascript';  e.async = true;
	e.src = 'https://secure.adnxs.com/seg?add=37325669&t=1';
	p.insertBefore(e, p.firstChild);
	})();
}
if (ehs_site.includes("ehs.pro.chest")) {
	(function() {
	var d = document, e = d.createElement('script'), p = d.getElementsByTagName('head')[0];
	e.type = 'text/javascript';  e.async = true;
	e.src = 'https://secure.adnxs.com/seg?add=38520398&t=1';
	p.insertBefore(e, p.firstChild);
	})();
}
if (ehs_site.includes("ehs.pro.ada")) {
	(function() {
	var d = document, e = d.createElement('script'), p = d.getElementsByTagName('head')[0];
	e.type = 'text/javascript';  e.async = true;
	e.src = 'https://secure.adnxs.com/seg?add=38520606&t=1';
	p.insertBefore(e, p.firstChild);
	})();
}
if (ehs_site=="ehs.pro.amga.amga") {
	(function() {
	var d = document, e = d.createElement('script'), p = d.getElementsByTagName('head')[0];
	e.type = 'text/javascript';  e.async = true;
	e.src = 'https://secure.adnxs.com/seg?add=41251395&t=1';
	p.insertBefore(e, p.firstChild);
	})();
}
})();
