//IsParentAccessible
//   This function checks to see if we can access the parent of the WIP.
//   If we can, then the document.domain must match the parent's.
//   If we can't, then the scoping bar must have come in and wacked
//   the domain, in which case, we need to set it up to match
function IsParentAccessible()
{
    try
    {
        var x = parent.document.domain;
        return true;
    }
    catch(ex)
    {
        return false;
    }
}


//SetLiveDomain
//   This function will look at the current domain and will put the page in the Live domain
//   if necessary to prevent cross-domain scripting errors.
function SetLiveDomain()
{
    //only do this if the scoping bar is actually present
    if (!IsParentAccessible())
    {
	    var liveDomain = "live.com";
	    var liveDomainIndex = document.domain.indexOf(liveDomain);

	    if (liveDomainIndex == -1)
	    {
		    liveDomain = "live-int.com";
		    liveDomainIndex = document.domain.indexOf(liveDomain);
	    }
    	
	    if ((liveDomainIndex > -1) && ((liveDomainIndex + liveDomain.length) == document.domain.length))
	    {
		    document.domain = liveDomain;
	    }
    }
}

function DoHeader() 
{
    SetLiveDomain();
	var a = window.parent.HelpHistory[window.parent.HelpHistory.length-1];
	if (a != null)
	{
	document.write('<a HREF="javascript:goback()">Back</a>');
	document.write('&nbsp;|&nbsp;');
	}
	document.write('<a href="help.htm">Help topics</a>');
}
function DoFooter()
{
    SetLiveDomain();
	var s = document.location.toString();
	var i = s.indexOf('/help/');
	var page = s.substring(i+6);
	
	var link = "'mailto:maphelp@microsoft.com?subject=Windows Live Local Help Feedback (" + page + ")'";
	if (page=="Help.htm")
	{
	document.write('<a href="http://support.live.com/default.aspx?productkey=wllocal&locale=en-us" target=_blank>Contact us</A>');
	document.write('&nbsp;|&nbsp;');
	document.write('<a HREF='+link+'>Send feedback about this topic</A>');
	}
	else
	{
		var footTable = '<TABLE WIDTH="100%" ID="Table1" style="font-size:8pt"><TR class="columnar">';
		var a = window.parent.HelpHistory[window.parent.HelpHistory.length-1];
		if (a != null)
		{
			footTable+='<TD style="text-align: left" width=20><a HREF="javascript:goback()">Back</A></TD>';
		}
						
			footTable += '<TD style="text-align: left"><a href="help.htm">Help topics</a></TD>'+
					'<TD style="text-align: right"><a href="http://support.live.com/default.aspx?productkey=wllocal&locale=en-us" target=_blank>Contact us</A></TD>'+
					'<TD style="text-align: left" width=90><a HREF='+link+'>Send feedback about this topic</A></TD></TR></TABLE>';
			document.write(footTable);
		}
}
function DisableRight(e)
{
    SetLiveDomain();
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) return false;
	else return true;
}
function DoTracking()
{
    SetLiveDomain();
	var s = document.location.toString();
	var i = s.indexOf('/help/');
	var page = s.substring(i+6);
}
function SetHistory() //also serves as an onLoad for help topics
{
    SetLiveDomain();
	window.parent.HelpHistory.push(window.location.href);
	
	//disable right-click on help topics
	document.onmousedown=DisableRight;
	document.onmouseup=DisableRight;
	if (document.layers) window.captureEvents(Event.MOUSEDOWN);
	if (document.layers) window.captureEvents(Event.MOUSEUP);
	window.onmousedown=DisableRight;
	window.onmouseup=DisableRight;

	//track page usage
	DoTracking();
}
function GetHistory()
{
	
}
function goback()
{
    SetLiveDomain();
	window.parent.HelpHistory.splice(window.parent.HelpHistory.length, 1);
	window.parent.HelpHistory.pop();
	var loc = window.parent.HelpHistory.pop();
	if (loc!=null)
	{
		parent.VE_Help.Open('Help',loc);
	}
}
function getOblique(sceneID)
{	
    SetLiveDomain();
	var view = Msn.VE.MapView();
	view.SetMapStyle('o', sceneId); 
	view.SetZoomLevel(1);
	SetView(view);
}

function HideDiv(id) 
{ 
    SetLiveDomain();
	if (document.getElementsByTagName('div').className = 'expando') 
	{ // DOM3 = IE5, NS6 
		document.getElementsByTagName('div').className = 'expando'.style.display = 'none'; 
	} 
	else if (document.layers) 
	{ // Netscape 4 
		document.hideshow.visibility = 'hidden'; 
	} 
	else 
	{ // IE 4 
		document.all.hideshow.style.display = 'block'; 
	} 
} 
function HideAll()
{
    SetLiveDomain();
	for( var i = 0; i < document.getElementsByTagName('div').length; i++ ) 
	{
		if(document.getElementsByTagName('div')[i].className = 'expando')
		{
		document.getElementsByTagName('div')[i].style.display = 'none';
		}
	}
}
function ShowDiv(id) 
{ 
    SetLiveDomain();
	HideAll();
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6 
	document.getElementById(id).style.display = 'block'; 
	} 
	else if (document.layers) 
	{ // Netscape 4 
		document.hideshow.visibility = 'visible'; 
	}
	else 
	{ // IE 4 
		document.all.hideshow.style.display = 'block'; 
	} 
}

//required by FF to switch to Bird's Eye from hyperlink
function ShowScene(id, dir)
    {
      SetLiveDomain();
      parent.window.setTimeout("map.SetMapStyle('o',"+id+",'"+dir+"')", 1);
    }

//required by FF to show a collection
function launchCollection(_collectionId,_locale)
{
    SetLiveDomain();
	var parent = top;
	if (parent && typeof parent != 'undefined')
	{
		collectionsManager = parent.window.VE_CollectionsManager;
		if (collectionsManager && typeof collectionsManager != 'undefined')
			{ 
				parent.window.setTimeout("VE_CollectionsManager.RetrieveCollectionDetails('" + _collectionId + "','" + _locale + "')",1);
			}
	}
	
	// Unconditionally return false to prevent the default action
	return false;
}

// Opens an url in help.live.com
function OpenLiveHelp(project, querytype, query)
{
    SetLiveDomain();
    var helpWinName = "_live_help";
	var winWidth = 550;
	var winHeight = 575;
	var winLeft = (screen.availWidth - winWidth) * 0.5;
	var winTop = (screen.availHeight - winHeight) * 0.5;
	var winFeatures = "resizable=yes,top="+winTop+",width="+winWidth+",height="+winHeight+",left="+winLeft;
          
	// project name is baked into the g-link      
	var url = liveHelpUrl + "?querytype=" + querytype + "&query=" + query;
    var win = window.open(url, helpWinName, winFeatures); //floating portal
	
	if (win != null && typeof win == 'object') 
	    win.focus(); //no hidden window
}


