var ExpirationDate=GetExpirationDate();
var TodaysDateAsString=GetTodaysDateAsString();
function $(id){
	return document.getElementById(id);}
function SizeWindow(minWidth, minHeight, maxWidth, maxHeight){
	var win = new Object();
	var scrollbarsize=0, winframebordersize=5;
	var wintitlebarsize=25;
	win.Scrollbars="no";
	var screenAvailWidth=screen.availWidth -(2*winframebordersize);
	var screenAvailHeight=screen.availHeight-(2*winframebordersize);
	if(maxWidth > screenAvailWidth || maxHeight > screenAvailHeight){
		scrollbarsize=20;
		win.Scrollbars="yes";
		maxWidth=screenAvailWidth-scrollbarsize;
		maxHeight=screenAvailHeight-scrollbarsize;}
	win.Width=Math.min(minWidth, maxWidth);
	win.Height=Math.min(minHeight, maxHeight);
	//center window
	win.Left=(screenAvailWidth - win.Width - scrollbarsize)/2;
	if(win.Left<0){
		win.Left=0;}
	win.Top=(screenAvailHeight - win.Height - scrollbarsize - wintitlebarsize)/2;
	if(win.Top<0){
		win.Top=0;}
	return win;}
function OpenWindow(strURL,winType,winName,winWidth,winHeight){
	try
	{
		var objWindow,resizeable="no",winMaxWidth,winMaxHeight;
		switch(winType)
		{
			case "scanner":
				winWidth=500,winHeight=550,winMaxWidth=500,winMaxHeight=700;
				resizeable="yes";
 				break;
			case "help":
				winWidth=550,winHeight=575,winMaxWidth=550,winMaxHeight=575;
				resizeable="yes";
				break;
			default:
				objWindow=window.open(strURL);
				return;
		}
		var win = SizeWindow(winWidth, winHeight, winMaxWidth, winMaxHeight);
		objWindow=window.open(strURL,winName,'width='+win.Width+',height='+win.Height+',left=' + win.Left+ ',top=' + win.Top + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+win.Scrollbars+',resizable=' + resizeable + ',copyhistory=no');
		if (objWindow != null) {objWindow.focus();}
	}
	catch(e){}
	}
function TestForOpener(){}
function ManageWindows(strURL, useWinParent, closeWinCurrent, useNewWindow){
	if(useWinParent=="true" || useWinParent){
		var navDone=false;
		if(typeof(window.opener)=="object"){
			try{
				window.opener.TestForOpener();
				WindowProperties.SetOpenerLocation(strURL);
				window.opener.focus();
				navDone=true;}
			catch(e){
			  /* .TestForOpener failed so must launch new window*/}}
		if(!navDone){
			OpenWindow(strURL, "", "", "", "");}
	}else if(useNewWindow=="true" || useNewWindow){
		OpenWindow(strURL, "", "", "", "");}
	else{
		DocumentProperties.SetLocationHREF(strURL);}
	if(closeWinCurrent=="true"||closeWinCurrent){
		try{
			window.opener.TestForOpener();
			window.close();
			}
		catch(e){}}}
function GetExpirationDate(){
	var expires=new Date();
	expires.setFullYear(expires.getFullYear()+10);
	return expires;}
function GetTodaysDateAsString(){
	var date=new Date();
	var sDate=(date.getMonth()+1)+"/";
	sDate+=date.getDate()+"/";
	sDate+=date.getFullYear();
	return sDate;}
function SetLanguage(url){
	var expires=new Date();
	expires.setMonth(expires.getMonth()+1);
	SetCookie("mkt",url.split('/')[2],expires,null,DocumentProperties.GetLocationHost(),false);
	DocumentProperties.SetLocationHREF(url);
	event.returnValue=false;}
function GetDomainFromURL(strURL){
	strURL=UnwindStr(strURL);
	if(HasXSSChars(strURL)) return "";
	var hostNameExp = /^(http:\/\/|https:\/\/)([A-Za-z0-9\.\-]+)/
	if(strURL.match(hostNameExp)) return RegExp.$2;
	else if(strURL.indexOf("/")==0) return DocumentProperties.GetLocationHost();
	else return "";}
function GetReferringURL(){
	var cookieValue=null;
	cookieValue=GetSubkey("SessionData","ReferringURL");
	return cookieValue;}
function SetReferringURL(){
	var referringURL=GetReferringURL();
	if((referringURL=='')||(referringURL==null)){
		var referrerURL=DocumentProperties.GetReferrer();
		if(referrerURL=='')
		SetNoEscapeSubkey("SessionData","ReferringURL",escape("NOREFERRER"),"","/",gCookieDomain,"");
		else{
			referrerURL=UnwindStr(referrerURL);
			//validate the referrerURL
			var r, re;					 
			//only allow loweralpha, upperalpha, numeric, _, .,+,?,%,&,\040,=,:,/,# (100 chars max) NOTE:  \040 is space
			re=new RegExp("^[a-zA-Z0-9_\.+?%&\040=:/#]{1,100}$","i");  
			r=referrerURL.match(re);			   
			if(r!=null){
				SetNoEscapeSubkey("SessionData","ReferringURL", escape(referrerURL),"","/",gCookieDomain,"");}}}};
function ShowHelp(queryValue) {
   var url = g_MapHelpServerURL + "?mkt=" + g_LangMark + "&project=WL_Safety&format=b1&querytype=keyword&query=" + queryValue;
   OpenWindow(url,"help","_help",null,null);
   return false;}
function ShowHelpOC(queryValue) {
   var url = "/standard/" + g_LangMark.toLowerCase() + "/support/default.htm";
   DocumentProperties.SetLocationHREF(url);}
function NavToOneCare(obj, strTrackingCode, returnUrl){
	// Used only by scanner: Convert or remove with v3
	// NavToOneCare: event10
	var url = "/standard/" + g_LangMark.toLowerCase() + "/default.htm";
	url=(typeof(g_LiveTracking)!="undefined")?s_NavOffsite(obj,url,strTrackingCode,strTrackingCode,"event10"):url;
	if (returnUrl==true) return url;
	DocumentProperties.SetLocationHREF(url);}
function ResizeScanner(large){
	var style=Utils.FindStyle('StyleMarketOverrides','.DivScanAdContainer','display');
	if (!style){
		style=Utils.FindStyle('StyleAd','.DivScanAdContainer','display');}
	if (style!='none'){
		if(window.opener){
			var w=500;
			var h=(large?650:500);
			var win=SizeWindow(w,h,w,h);
 			window.resizeTo(win.Width,win.Height);
			window.moveTo(win.Left,win.Top);}}}
function RedirectTo(url){
	if (window.opener){
		WindowProperties.SetOpenerLocation(url);
		window.close();}
	else{
		DocumentProperties.SetLocationHREF(url);}}
function SizePage(){
	var CMSConsole=$("CMSConsole");
	if(CMSConsole){
		var w = (document.body.offsetWidth - 774)/2 + 774;
		CMSConsole.style.left=w;
		CMSConsole.style.display="block";}
	var TdRightBottom=$("ctl00_TdRightBottom");
	if(TdRightBottom){
		var TdBottom=$("TdBottom");
		var TdNav=$("TdNav");
		//ff
		TdRightBottom.height=TdBottom.offsetTop-TdNav.offsetTop-275;
		//ie 6
		TdRightBottom.style.height=TdBottom.offsetTop-TdNav.offsetTop-290;}
	if($("TdNav")&&$("TdNav").offsetHeight<400){
		$("TdNav").height=400;}}
function PositionDivLabel(){
	var label=$("DivLabel");
	label.style.pixelLeft=document.body.offsetWidth-label.offsetWidth-20;
	label.style.pixelTop=30-label.offsetHeight/2;
	label.style.visibility='visible';}
function SetDialogScroll(){
	var maxHeight;
	var style=Utils.FindStyle('StyleMarketOverrides','.DivScanAdContainer','display');
	if (!style){
		style=Utils.FindStyle('StyleAd','.DivScanAdContainer','display');}
	maxHeight=(style=='none')?500:600;
	if(document.body.offsetHeight>maxHeight)
		document.body.scroll='yes';}
			
var g_IncompleteWarning=false;
function AreMarketSettingsComplete()
{
	if(g_IncompleteWarning==true)
		return;
	else
		alert("NOTE: Market settings are not final.");
	g_IncompleteWarning=true;
}

function CreateScanner(container,object){
	var objectData=Utils.ObjectToString(object);
	$(container).innerHTML=objectData;}

function IsArray(obj)
{
	return !(typeof(obj)==='undefined')&&!(obj.propertyIsEnumerable('length'))&&typeof(obj)==='object'&&typeof(obj.length)==='number';
}

Utils = new function(){
	this.Tracking = new function()
	{
		this.GetImg = function(src)
		{
			if (src == '') return;
			if (src.indexOf('mrtwxp') != -1)
			{
				src = src.replace(/switch.atdmt.com/g, 'view.atdmt.com');
			}
			var img = document.createElement("img");
				img.width = 1;
				img.height = 1;
				img.border = 0;
				img.src = src;
			document.body.appendChild(img);
		}	
		this.GetJsSrc = function(src)
		{
			if (src == '') return;
			if (src.indexOf('mrtwxp') != -1)
			{
				src = src.replace(/switch.atdmt.com/g, 'view.atdmt.com');
			}
			var scriptTag = document.createElement("script");
				scriptTag.setAttribute("type", "text/javascript");
				scriptTag.setAttribute("src", src);
			document.body.appendChild(scriptTag);

		}
		this.DoClickOmniture = function(code)
		{
			var clickElement = window.event.srcElement;
			if (code == '') return;
			s.linkTrackVars = 'events';
			s.linkTrackEvents = code;
			s.events = code;
			s.tl(clickElement,'o');
		}
		this.DoClickOmniturePreV3 = function(code)
		{
			if (code == '') return;
			s_SetEvent(code);
			s_Send();
		}
		function SetValues(events,vars,values)
		{
			// Used only by scanner: Convert or remove with v3
			// SetValues: prop1
			var linkTrackVars="prop1"; // always track events, and prop1 (language-region)
			if(events!='') // if there are events, track them
			{
				linkTrackVars="events,"+linkTrackVars;
				s.linkTrackEvents=events;
				s.events=events;
			}
			if (IsArray(vars)&&IsArray(values))
			{
				for(var i=0;i<vars.length&&i<values.length;i++)
				{
					linkTrackVars+=","+vars[i];
					s[vars[i]]=values[i];
				}
			}
			s.linkTrackVars=linkTrackVars;
		}
		this.SendOmniture=function(events,vars,values)
		{
			// Used only by scanner: Convert or remove with v3
			// SendOmniture
			if(typeof(g_LiveTracking)==="undefined") return;
			SetValues(events,vars,values);
			s_Send();
		}
		this.LinkTrackOmniture=function(obj,eventName,events,vars,values)
		{
			// Used only by scanner: Convert or remove with v3
			// LinkTrackOmniture
			if(typeof(g_LiveTracking)==="undefined") return;
			SetValues(events,vars,values);
			var lt=obj.href!=null?s.lt(obj.href):"";
			if (lt=="")s.tl(obj,'o',eventName);
		}
	}
			
	//Start - General
	this.UrlEncode=function(val){
		return escape(val).replace(/\//g, '%2F');}
	this.GetGlobalPath=function(){
		var path;
		var href=DocumentProperties.GetLocationHREF();
		if (href.indexOf('NRMODE') > -1 && href.indexOf('NRORIGINALURL') > -1){
			var start = href.indexOf('NRORIGINALURL')+14;
			path = unescape(href.substring(start, href.indexOf('&', start)));}
		else
			path = DocumentProperties.GetLocationPathName();
		var index=-1;
		var count=0;
		for(var i=0;i<3;i++){
			index=path.indexOf("/", index+1);
			if(index<0){
				throw "URL does not conform to global path pattern";}}
		return path.substring(0,index);}
	this.GetGlobalPathFullWithQuery=function(){
		var path;
		var href=DocumentProperties.GetLocationHREF();
		if (href.indexOf('NRMODE') > -1 && href.indexOf('NRORIGINALURL') > -1){
			var start = href.indexOf('NRORIGINALURL')+14;
			path = unescape(href.substring(start, href.indexOf('&', start)));}
		else{
			path=href;}
		return path;}
	this.FindStyle=function(sheet,item, style){
		var stylesheet=document.styleSheets[sheet];
		if (!stylesheet)
			return;
		for (r=0;r<stylesheet.rules.length;r++){
			if(stylesheet.rules[r].selectorText==item)
				return stylesheet.rules[r].style[style];}
		return;}
	this.HtmlEncode=function(htmlString){
		return htmlString.replace(/</g, "&lt;").replace(/>/g, "&gt;");}
	this.IsValid=function(keyCode){
		var validKeys=[9,13,32,37,38,39,40];
		for(var i=0;i<validKeys.length;i++)
			if (validKeys[i]==keyCode)
				return true;
		return false;}
	this.GetScannerType=function(){
		var type='';
		if (Browser.OS=='Vista' || Browser.OS=='Win7')
			type='sandbox';
		return type;}
	this.ResetScannerControl=function(){
		$('ObjControl').outerHTML='<object id="ObjControl"></object>';}
	this.ObjectToString=function(object){
		var output='<object';
		if(object.Id)
			output+=' id="'+object.Id+'"';
		if(object.ClassId)
			output+=' classid="'+object.ClassId+'"';
		if(object.CodeBase)
			output+=' codebase="'+object.CodeBase+'"';
		if(object.OnError)
			output+=' onerror="'+object.OnError+'"';
		if(object.OnReadyState)
			output+=' onreadystatechange="'+object.OnReadyState+'"';
		output+='>';
		if(object.Params)
			for(var i=0;i<object.Params.length;i++)
				output+='<param name="'+object.Params[i].Name+'" value="'+object.Params[i].Value+'" />';
		return output+'</object>';}
	this.GetQuerystringParam = function(querystring, key)
	{
		if (querystring == null)
			return null;

		// Strip out the ? character
		querystring = querystring.substring(1, querystring.length);
		var rgParams = querystring.split('&');
		for (var iParam = 0; iParam < rgParams.length; iParam++)
		{
			var param = rgParams[iParam].split('=');
			if (param.length == 2 && param[0] == key)
				return param[1];
		}
		return null;
	}
	// Chains OnLoad handlers for the window.onload event
	this.addOnLoadHandler = function(newHandler) 
	{
		var oldHandler = window.onload;
		if (typeof window.onload != 'function') 
		{
			window.onload = newHandler;
		} 
		else 
		{
			window.onload = function() 
			{
				if (oldHandler)
					oldHandler();
				newHandler();
			}
		}
	}	
	var m_OldSafetyCenterRootDomain;
	// Stores the OldSafetyCenterRootDomain
	this.SetOldSafetyCenterRootDomain = function(oldDomain)
	{
		m_OldSafetyCenterRootDomain = oldDomain;
	}
	this.GetOldSafetyCenterRootDomain = function()
	{
		return m_OldSafetyCenterRootDomain; 
	}
	//End - General
	
	
	//Start - Browser object
	var m_UserAgent=window.navigator.userAgent;
	var m_AppName=window.navigator.appName;
	var m_OS;
	var m_Browser;
	var m_BrowserVersion;
	this.GetOS=function(){
		if (!m_OS){
			if (m_UserAgent.indexOf("Windows NT 5.0")>-1)
				m_OS="Win2K";
			else if (m_UserAgent.indexOf("Windows NT 5.1")>-1)
				m_OS="WinXP";
			else if (m_UserAgent.indexOf("Windows NT 5.2")>-1)
				m_OS="Win2K3";
			else if (m_UserAgent.indexOf("Windows NT 6.0")>-1)
				m_OS="Vista";
			else if (m_UserAgent.indexOf("Windows NT 6.1")>-1)
				m_OS="Win7";
			else
				m_OS="Unsupported";}
		return m_OS;}	
	this.GetBrowser=function(){
		if (!m_Browser){
			if (m_AppName=="Microsoft Internet Explorer")
				m_Browser="IE";
			else if (m_AppName=="Netscape"&&m_UserAgent.indexOf("Firefox")>-1)
				m_Browser="Firefox";
			else 
				m_Browser=m_AppName;}
		return m_Browser;}
	this.GetBrowserVersion=function(){
		if (!m_BrowserVersion){
			var b=this.GetBrowser();
			var start;
			if (b=="IE"){
				start=m_UserAgent.indexOf("MSIE");
				var end=m_UserAgent.indexOf(";",start);
				m_BrowserVersion=m_UserAgent.substring(start+5,end);}
			else if (b=="Firefox"||b=="Netscape"){
				start=m_UserAgent.indexOf(b);
				m_BrowserVersion=m_UserAgent.substring(start+(b=="Firefox"?8:9));}
			else 
				m_BrowserVersion=window.navigator.appVersion;}
		return m_BrowserVersion;}
	this.GetActiveX=function(){
		if(!!window.ActiveXObject){
			try{
				var temp=new ActiveXObject("Microsoft.XMLHTTP");
				temp=null;
				return true;}
			catch(e){
				return false;}}
		else{
			return false;}}
	//End - Browser object
	this.AlertMissingLocContentSettings=function(){
		alert("Need to add to LocContentSettings.xml for this locale");
		return}
	this.RedirRelativeToCurrentMarket=function(url){
		path = DocumentProperties.GetLocationPathName();
		var index=-1;
		var count=0;
		for(var i=0;i<3;i++){
			index=path.indexOf("/", index+1);
			if(index<0){
				throw "URL does not conform to global path pattern";}}
		
		path = path.substring(0,index+1)
		DocumentProperties.SetLocationHREF(path + url );
		return}
}

function AutoSelectCurrentPage(selectid)
{
	var thisRelPage = document.location.pathname + document.location.search;
	var oElement = document.all(selectid);
	for (var i=0; i<oElement.options.length; i++)
	{
		if (oElement.options(i).value == thisRelPage)
		{
			oElement.options(i).selected = true;
		}
	}
}

// This object tells information about the web browser
var Browser={
	OS:Utils.GetOS(),
	Type:Utils.GetBrowser(),
	Version:Utils.GetBrowserVersion(),
	Cookies:window.navigator.cookieEnabled,
	ActiveX:Utils.GetActiveX()}
	
