var _____WB$wombat$assign$function_____=function(name){return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name))||self[name];};if(!self.__WB_pmw){self.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opens = _____WB$wombat$assign$function_____("opens");
function getCookie(cookieName) {
	if (cookieName === "JSESSIONID") {
		return getSessionId();
	}
}

function getSessionId() {
	var sessionId = sessionStorage.getItem("sessionId")
	if (sessionId) {
		return sessionId;
	}
	sessionId = Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2);
	sessionStorage.setItem("sessionId", sessionId);
	return sessionId;
}

function getUrlVars() {
	var vars = [],
		hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for (var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}


var originalWriteFunction = document.write;
document.write = function (content) {
	if (typeof content === 'string') {
		content = content.replace("qqhlc9-bqzpr.ybsitecenter.com?", "dh-static-files.s3.amazonaws.com/dev/test/ybsitecenter_map.html?session="+getSessionId()+"&");
	}
	originalWriteFunction.call(document, content);
}


$(document).ready(function () {
	var styles = document.querySelectorAll("style");
	for (var i = 0; i < styles.length; i++) {
		var element = styles[i];
		var content = element.textContent;
		if (content.contains("<style")) {
			element.innerText = content.replace(/<style[^>]*>/g, "");
		}
	}
	var url = location.href;
	var anchors = document.querySelectorAll("a");
	var isMobile =  (screen.width <= 640) ||  (window.matchMedia && window.matchMedia('only screen and (max-width: 640px)').matches);
	for (var j = 0; j < anchors.length; j++) {
		var a = anchors[j];
		var href = a.href;
		var mapIndex = href.indexOf("maps.google.co");
		if (mapIndex>0){
			a.href = "//"+href.substring(mapIndex);

		}

		
		var isPreview = url.indexOf("/site/") && url.contains("preview");
		if (!isMobile && !isPreview) {
			// we dont want to see this query params in not mobile devices.
			a.href = a.href.replace("?dm_device=desktop", "");
			if (a.href.indexOf("&") == a.href.indexOf("&preview=true")){
				a.href = a.href.replace("&preview=true","?preview=true");
			}
			
		}
	}


	
	if (isPreview && window["oCMenu"]) {
		for (var property in oCMenu.m) {
			if (oCMenu.m && oCMenu.m.hasOwnProperty(property)) {
				var link = oCMenu.m[property].lnk;
				if (link && link.indexOf("/") == 0) {
					oCMenu.m[property].lnk = "/site/" + Parameters.SiteAlias + link + "?preview=true";
				}
			}
		}
	}
});

}