/* Wire up the bodyload handler (set here rather than in the body element
    in order to avoid a HTML Help viewer bug with printing multiple topics) */
window.onload = bodyLoad;

// Current language
var curLang;
var showAll;
var cook = null;

// To prevent 'access denied' errors in the authoring environment
function dxErrorHandler(msg,url,line) {
	if(url=="about:blank")
	{
		return true;
	}
}
if (window.location.href == 'about:blank')
{
	window.onerror = dxErrorHandler;
}

function documentElement(id){
	return document.getElementById(id);
}

function sourceElement(e){
	if (window.event)
		e = window.event;
	return e.srcElement? e.srcElement : e.target;
}

function cancelEvent(e){
	e.returnValue = false;
	e.cancelBubble = true;
	if (e.stopPropagation) { 
		e.stopPropagation(); 
		e.preventDefault();
	} 	
}

function getElementPosition(e){ 
	var offsetLeft = 0; 
	var offsetTop = 0; 
	while (e){ 
		// Allow for the scrolling body region in IE
		if (msieversion() > 4) {
			offsetLeft += (e.offsetLeft - e.scrollLeft); 
			offsetTop += (e.offsetTop - e.scrollTop); 
		}
		else
		{
			offsetLeft += e.offsetLeft ; 
			offsetTop += e.offsetTop; 		
		}
		e = e.offsetParent; 
	} 
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){ 
		offsetLeft += document.body.leftMargin; 
		offsetTop += document.body.topMargin; 
	} 
	return {left:offsetLeft,top:offsetTop}; 
} 

function dxBeforePrint(){

	var i;
	var allElements;

	if (window.text) document.all.text.style.height = "auto";
	
	allElements = document.getElementsByTagName("*");
			
	for (i=0; i < allElements.length; i++){
		if (allElements[i].tagName == "BODY") {
			allElements[i].scroll = "yes";
			}
		if (allElements[i].id == "pagetop") {
			allElements[i].style.margin = "0px 0px 0px 0px";
			allElements[i].style.width = "100%";
			}
		if (allElements[i].id == "pagebody") {
			allElements[i].style.overflow = "visible";
			allElements[i].style.top = "5px";
			allElements[i].style.width = "100%";
			allElements[i].style.padding = "0px 10px 0px 30px";
			}
		if (allElements[i].id == "seealsobutton" || allElements[i].id == "languagesbutton" || allElements[i].id == "requirementsbutton") {
			allElements[i].style.display = "none";
			}
		if (allElements[i].className == "LanguageSpecific") {
			allElements[i].style.display = "block";
			}
		}
}

function dxAfterPrint(){

	 document.location.reload();

}

function showSeeAlsoBox(e){

	if (window.event)
		e = window.event;

	hideAllBoxes();

	var button = sourceElement(e);

	cancelEvent(e);

	var div = documentElement("dxseealsomenu");
	if (div && button) {	
		div.style.height = "";
		div.style.left = 3 + "px";
		div.style.top = button.offsetTop + button.offsetHeight + "px";
		div.style.visibility = "visible";
	}

	return false;
	
}

function showParamBox(e){

	if (window.event)
		e = window.event;

	hideAllBoxes();

	var button = sourceElement(e);
	var documentWidth;
	var documentHeight;
	var boxWidth;
	var pixelLeft;
	var pixelTop;
	var boxHeigt;
	var boxWidth;

	cancelEvent(e);

	var div = documentElement(button.id + "_box");
	if (div && button) {

		// Have the browser size the box
		div.style.height = "";
		div.style.width = "";
		
		// Clear any tooltip so it doesn't appear above the popup
		button.title = "";
	
		pixelTop = getElementPosition(button).top + 14;
		
		// Check if the box would go off the bottom of the visible area
		documentHeight = document.body.clientHeight;
		boxHeight = div.clientHeight;
		if (pixelTop + boxHeight > documentHeight) 
		{
			// If the box won't fit both above and below the link
			//  using the default width then make the box wider
			if (boxHeight >= pixelTop)
				div.style.width = "80%";
			else			
				pixelTop = pixelTop - 14 - boxHeight;
		}
		div.style.top = pixelTop + "px";
		
		documentWidth = document.body.clientWidth;
		boxWidth = div.clientWidth;
		pixelLeft = button.offsetLeft;

		// Check if the box would go off the edge of the visible area		
		if (pixelLeft + boxWidth > documentWidth)
		{
			pixelLeft = documentWidth - boxWidth - 5;
		}
		div.style.left = pixelLeft + "px";		
		
		// Show the box
		div.style.visibility = "visible";
	}

}

function hideAllBoxes(){
	dxHideBoxes();
}

function showRequirementsBox(e){

	if (window.event)
		e = window.event;

	hideAllBoxes();

	var button = sourceElement(e);

	cancelEvent(e);

	var div = documentElement("dxrequirementsmenu");
	if (div && button) {
		div.style.height = "";
		div.style.left = "3px";
		div.style.top = button.offsetTop + button.offsetHeight + "px";
		div.style.visibility = "visible";
	}
	
}

function showLanguageBox(e){

	if (window.event)
		e = window.event;

	hideAllBoxes();

	var button = sourceElement(e);

	cancelEvent(e);

	var div = documentElement("dxlanguagemenu");
	if (div && button) {
		div.style.height = "";
		div.style.left = "3px";
		div.style.top = button.offsetTop + button.offsetHeight + "px";
		div.style.visibility = "visible";
	}
}

function setLanguageFilter(language,e){

	var lang;
	
	if (window.event)
		e = window.event;

	hideAllBoxes();

	cancelEvent(e);
	
	curLang = language;
	updateLanguageElements();
	
	if (cook)
	{
		lang = language;
		if (lang == 'VB')
		{
			lang = 'Visual Basic';		
		}
		if (lang == 'CS')
		{
			lang = 'C#';
		}
		if (lang != 'All')
		{
			cook.putValue('lang', lang);
			cook.putValue('lang.all', '');
		}
		else
		{
			cook.putValue('lang.all', '1');
		}
	}	
}

function bodyLoad(){

	var cLang;
	var i;
	var b;
	var l;
	var e;
	var obj;
	var lang;

	resizeBan();
	document.body.onclick = bodyClick;
	document.body.onresize = bodyResize;
	
	// Check the context window for current language.
	var cLang;
	try{
		for (i=1; i< window.external.ContextAttributes.Count; i++){
			if(window.external.ContextAttributes(i).Name.toUpperCase()=="DEVLANG"){
				var b = window.external.ContextAttributes(i).Values.toArray();
				cLang = b[0].toUpperCase();
			}
		}
	}
	catch(e){}
	
	if (cLang != null){
		if (cLang.indexOf("VB")!=-1) curLang = "VB";
		if (cLang.indexOf("VC")!=-1) curLang = "VC";
		if (cLang.indexOf("CSHARP")!=-1) curLang = "CS";
		if (cLang.indexOf("JSCRIPT")!=-1) curLang = "JScript";
	}

	if (curLang == null){
		var l = "";
		var multipleLang = false;
		// Check to see what the help filter is set to.
		try {l = window.external.Help.FilterQuery.toUpperCase();}
		catch(e){}
		if (l.indexOf("VB")!=-1){
			cLang = "VB";
			}
		if (l.indexOf("VC")!=-1){
			if (cLang!=null) multipleLang = true;
			cLang = "VC";
			}
		if (l.indexOf("C#")!=-1){
			if (cLang!=null) multipleLang = true;
			cLang = "CS";
			}
		if (l.indexOf("CSHARP")!=-1){
			if (cLang!=null) multipleLang = true;
			cLang = "CS";
			}
		if (l.indexOf("JSCRIPT")!=-1){
			if (cLang!=null) multipleLang = true;
			cLang = "JScript";
			}
		if (multipleLang==false) curLang = cLang;		
	}
	
	// If no context attribute available, use the cookie value
	if (curLang == null){
		var obj = documentElement("obj_cook");
		window.onerror = function (err) { return true; }
		if (obj && obj.object) {
			cook = obj;
			if (obj.getValue("lang.all") != "1") {
				var lang = obj.getValue("lang");
				if (lang != null)
				{
					if (lang == 'Visual Basic')
					{
						lang = 'VB';
					}
					if (lang == 'C#')
					{
						lang = 'CS';
					}
					if (lang == 'CS' || lang == 'JScript' || lang == 'VB')
					{
						curLang = lang;
					}
				}
			}
		}
		if (window.location.href == 'about:blank')
		{
			window.onerror = dxErrorHandler;
		}	
		else
		{
			window.onerror = null;
		}
	}		

	if (curLang != null)
		showAll = false;
				
	updateLanguageElements();
	
	window.onbeforeprint = dxBeforePrint;
	window.onafterprint = dxAfterPrint;
	
}

function updateLanguageElements(){

	if (!curLang) return;

	var pres = document.getElementsByTagName("DIV");
	var pre;

	if (pres) {
		for (var iPre = 0; iPre < pres.length; iPre++) {
			pre = pres[iPre];
			if (pre.id && pre.className) {
				if (pre.className == "LanguageSpecific") {
					if (pre.id.toUpperCase().indexOf(curLang.toUpperCase()) != -1 || curLang == "All") {
						pre.style.display = "block";				
					}
					else {
						pre.style.display = "none";
					};
				}
			};
		}
	}
	
}

function bodyResize(){
	resizeBan();
}

function bodyClick(){
	hideAllBoxes();
	resizeBan();
}

function hideSeeAlso(){
	if (documentElement("dxseealsomenu")) {
		documentElement("dxseealsomenu").style.visibility = "hidden";
	};
}


function hideLanguage(){
	if (documentElement("dxlanguagemenu")) {
		documentElement("dxlanguagemenu").style.visibility = "hidden";
	};
}

function hideRequirements(){
	if (documentElement("dxrequirementsmenu")) {
		documentElement("dxrequirementsmenu").style.visibility = "hidden";
	};
}

function dxHideBoxes(){
	var pres = document.getElementsByTagName("DIV");
	var pre;

	if (pres) {
		for (var iPre = 0; iPre < pres.length; iPre++) {
			pre = pres[iPre];
			if (pre.className) {
				if (pre.className == "dxpopupbubble" || pre.className == "popupbubble") {
					pre.style.visibility = "hidden";
				}
			};
		}
	}
}

function resizeBan(){

	if (msieversion() > 4)
	{
		try
		{	

			if (document.body.clientWidth==0) return;
			var oBanner= documentElement("pagetop");
			var oText= documentElement("pagebody");
			if (oText == null) return;
			var oBannerrow1 = documentElement("projectnamebanner");
			var oTitleRow = documentElement("pagetitlebanner");
			if (oBannerrow1 != null){
				var iScrollWidth = dxBody.scrollWidth;
				oBannerrow1.style.marginRight = 0 - iScrollWidth;
			}
			if (oTitleRow != null){
				oTitleRow.style.padding = "0px 10px 0px 22px; ";
			}
			if (oBanner != null){
				document.body.scroll = "no"
				oText.style.overflow= "auto";
				oBanner.style.width= document.body.offsetWidth-2;
				oText.style.paddingRight = "20px"; // Width issue code
				oText.style.width= document.body.offsetWidth-4;
				oText.style.top=0;  
				if (document.body.offsetHeight > oBanner.offsetHeight)
					oText.style.height= document.body.offsetHeight - (oBanner.offsetHeight+4) 
				else oText.style.height=0
			}	
			try{nstext.setActive();} //allows scrolling from keyboard as soon as page is loaded. Only works in IE 5.5 and above.
			catch(e){}

		}
		catch(e){}
	}
} 

function msieversion()
// Return Microsoft Internet Explorer (major) version number, or 0 for others.
// This function works by finding the "MSIE " string and extracting the version number
// following the space, up to the decimal point for the minor version, which is ignored.
{
    var ua = window.navigator.userAgent
    var msie = ua.indexOf ( "MSIE " )

    if ( msie > 0 )        // is Microsoft Internet Explorer; return version number
        return parseInt ( ua.substring ( msie+5, ua.indexOf ( ".", msie ) ) )
    else
        return 0    // is other browser
}

/* XML expand / collapse */

// Detect and switch the display of CDATA and comments from an inline view
//  to a block view if the comment or CDATA is multi-line.
function f(e)
{
	// if this element is an inline comment, and contains more than a single
	//  line, turn it into a block comment.
	if (e.className == "ci") {
		if (e.children(0).innerText.indexOf("\n") > 0)
			fix(e, "cb");
	}

	// if this element is an inline cdata, and contains more than a single
	//  line, turn it into a block cdata.
	if (e.className == "di") {
		if (e.children(0).innerText.indexOf("\n") > 0)
			fix(e, "db");
	}

	// remove the id since we only used it for cleanup
	e.id = "";
}

// Fix up the element as a "block" display and enable expand/collapse on it
function fix(e, cl)
{
	// change the class name and display value
	e.className = cl;
	e.style.display = "block";

	// mark the comment or cdata display as a expandable container
	j = e.parentElement.children(0);
	j.className = "c";

	// find the +/- symbol and make it visible - the dummy link enables tabbing
	k = j.children(0);
	k.style.visibility = "visible";
	k.href = "#";
}

// Change the +/- symbol and hide the children.  This function works on "element"
//  displays
function ch(e)
{
	// find the +/- symbol
	mark = e.children(0).children(0);

	// if it is already collapsed, expand it by showing the children
	if (mark.innerText == "+")
	{
		mark.innerText = "-";
		for (var i = 1; i < e.children.length; i++)
			e.children(i).style.display = "block";
	}
	// if it is expanded, collapse it by hiding the children
	else if (mark.innerText == "-")
	{
		mark.innerText = "+";
		for (var i = 1; i < e.children.length; i++)
			e.children(i).style.display="none";
	}
}

// Change the +/- symbol and hide the children.  This function work on "comment"
//  and "cdata" displays
function ch2(e)
{
	// find the +/- symbol, and the "PRE" element that contains the content
	mark = e.children(0).children(0);
	contents = e.children(1);

	// if it is already collapsed, expand it by showing the children
	if (mark.innerText == "+")
	{
		mark.innerText = "-";
		// restore the correct "block"/"inline" display type to the PRE
		if (contents.className == "db" || contents.className == "cb")
			contents.style.display = "block";
		else 
			contents.style.display = "inline";
	}
	// if it is expanded, collapse it by hiding the children
	else 
		if (mark.innerText == "-")
		{
		mark.innerText = "+";
		contents.style.display = "none";
		}
}

// Handle a mouse click
function cl()
{
	e = window.event.srcElement;

	// make sure we are handling clicks upon expandable container elements
	if (e.className != "c")
	{
		e = e.parentElement;
		if (e.className != "c")
			return;
	}
	e = e.parentElement;

	// call the correct funtion to change the collapse/expand state and display
	if (e.className == "e")
		ch(e);
	if (e.className == "k")
		ch2(e);
}

// Dummy function for expand/collapse link navigation - trap onclick events instead
function ex() 
{}

// Erase bogus link info from the status window
function h()
{
	window.status=" ";
}

/* End XML Expand / Collapse */

/* .NET Framework Help Topic Resolution */

// This function is Copyright 2006 Innovasys Limited. No reproduction or usage
//  allowed other than in documentation generated by Innovasys Document! X v5
function resolveHelp2Keyword(Keyword,OnlineKeyword)
{

	var URL="";

	try
	{
		// Try the likely namespaces first, most recent first
		URL = findHelp2Keyword("MS.VSCC.v80",Keyword);
		if (URL == "")
		{
			URL = findHelp2Keyword("MS.VSCC.2003",Keyword);
			if (URL == "")
			{
				URL = findHelp2Keyword("MS.VSCC",Keyword);
			}
		}

		// URL found in one of the known VSCC namespaces
		if (URL != "")
		{
			return URL;
		}
		// For future proofing, try other VSCC namespaces
		else
		{
			var RegistryWalker = new ActiveXObject("HxDs.HxRegistryWalker");
			var Namespaces = RegistryWalker.RegisteredNamespaceList("MS.VSCC");
			var Namespace,NamespaceName,Session,Topics,Topic;

			if (Namespaces.Count > 0)
			{
				for (n=1;n<=Namespaces.Count;n++)
				{
					Namespace = Namespaces.Item(n);
					NamespaceName = Namespace.Name;
					if (NamespaceName.substring(0,7) == "MS.VSCC")
					{
						switch(NamespaceName)
						{
							case "MS.VSCC.v80":
								break;
							case "MS.VSCC.2003":
								break;
							case "MS.VSCC":
								break;
							default:
								URL = findHelp2Keyword(NamespaceName);
								if (URL != "")
								{
									return Topics(1).URL;
								}
						}
					}
				}
			}
		}
	}
	catch(e) {}

	// No match found in any VSCC namespace
	return "http://msdn2.microsoft.com/en-us/library(d=ide)/" + OnlineKeyword + ".aspx"
}

function findHelp2Keyword(NamespaceName,Keyword)
{
	var Session,Topics;

	try
	{
		Session = new ActiveXObject("HxDs.HxSession");
		Session.Initialize("ms-help://" + NamespaceName, 0);
		Topics = Session.Query(Keyword, "!DefaultAssociativeIndex", 0, "");
		if (Topics.Count > 0)
		{
			return Topics(1).URL;
		}
	}
	catch(e) {}
	return "";
}

function navigateToHelp2Keyword(Keyword,OnlineKeyword,ReplacePage)
{
	window.status="Resolving link to the .NET Framework documentation. Please wait a moment...";
	var URL=resolveHelp2Keyword(Keyword,OnlineKeyword);
	window.status="";
	if (ReplacePage == true)
	{
		location.replace(URL);
	}
	else
	{
		location.href=URL;
	}
}

/* End .NET Framework Help Topic Resolution */