// Current language
var curLang;
var showAll;

function hsHideBoxes(){
	var pres = document.all.tags("DIV");
	var pre;

	if (pres) {
		for (var iPre = 0; iPre < pres.length; iPre++) {
			pre = pres[iPre];
			if (pre.className) {
				if (pre.className == "hspopupbubble") {
					pre.style.visibility = "hidden";
				}
			};
		}
	}
}

function hsBeforePrint(){

	var i;

	if (window.text) document.all.text.style.height = "auto";
			
	for (i=0; i < document.all.length; i++){
		if (document.all[i].tagName == "BODY") {
			document.all[i].scroll = "yes";
			}
		if (document.all[i].id == "hspagetop") {
			document.all[i].style.margin = "0px 0px 0px 0px";
			document.all[i].style.width = "100%";
			}
		if (document.all[i].id == "hspagebody") {
			document.all[i].style.overflow = "visible";
			document.all[i].style.top = "5px";
			document.all[i].style.width = "100%";
			document.all[i].style.padding = "0px 10px 0px 30px";
			}
		if (document.all[i].id == "hsseealsobutton" || document.all[i].id == "hslanguagesbutton") {
			document.all[i].style.display = "none";
			}
		if (document.all[i].className == "LanguageSpecific") {
			document.all[i].style.display = "block";
			}
		}
}

function hsAfterPrint(){

	 document.location.reload();

}

function hsShowSeeAlsoBox(){

	hsHideSeeAlso();
	hsHideLanguage();

	var button = window.event.srcElement

	window.event.returnValue = false;
	window.event.cancelBubble = true;

	var div = document.all.hsseealsomenu;
	if (div && button) {
		div.style.pixelLeft = 3;
		div.style.pixelTop = button.offsetTop + button.offsetHeight;
		div.style.visibility = "visible";
	}
}



function hsShowGlossaryItemBox(term,definition){

	hsHideBoxes();

	var button = window.event.srcElement;
	var documentWidth;
	var documentHeight;
	var boxWidth;
	var pixelLeft;
	var pixelTop;
	var boxHeigt;
	var boxWidth;
	
	window.event.returnValue = false;
	window.event.cancelBubble = true;

	var div = document.all["hsglossaryitembox"]
	if (div && button) {

		div.innerHTML = "<p><strong>" + term + "</strong><br>" + definition + "</p>"

		// Check if the document width is < 500 pixels. If it is, make the box a static 250 pixels wide
		documentWidth = document.body.clientWidth;
		if (documentWidth < 500) 
		{
			if (documentWidth < 250)
			{
				div.style.width = documentWidth - 50 + "px"
				boxWidth = documentWidth - 50;
			}
			else
			{
				div.style.width = "250px"
				boxWidth = 250;
			}
		}	
		else
		{
			div.style.width = "30%";
			boxWidth = documentWidth * 0.3;
		}
	
		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.pixelLeft = pixelLeft;
		
		pixelTop = window.event.clientY+7;
		// Check if the box would go off the bottom of the visible area
		documentHeight = document.body.clientHeight;
		boxHeight = div.clientHeight;
		if (pixelTop + boxHeight > documentHeight) 
		{
			pixelTop = window.event.clientY - 7 - boxHeight;
		}
		div.style.pixelTop = pixelTop;
		
		// Show the box
		div.style.visibility = "visible";
	}

}

function hsShowLanguageBox(){

	hsHideSeeAlso();
	hsHideLanguage();

	var button = window.event.srcElement

	window.event.returnValue = false;
	window.event.cancelBubble = true;

	var div = document.all.hslanguagemenu;
	if (div && button) {
		div.style.pixelLeft = 0;
		div.style.pixelTop = button.offsetTop + button.offsetHeight;
		div.style.visibility = "visible";
	}
}

function hsSetLanguageFilter(language){

	hsHideSeeAlso();
	hsHideLanguage();

	window.event.returnValue = false;
	window.event.cancelBubble = true;
	
	curLang = language;
	hsUpdateLanguageElements();
	
}

function hsBodyLoad(){

	var cLang;
	var i;
	var b;
	var l;
	var e;

	hsResizeBan();
	document.body.onclick = hsBodyClick;
	document.body.onresize = hsBodyResize;
	
	// 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("C#")!=-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("JSCRIPT")!=-1){
			if (cLang!=null) multipleLang = true;
			cLang = "JScript";
			}
		if (multipleLang==false) curLang = cLang;
	}

	if (curLang != null)
		showAll = false;
		
	hsUpdateLanguageElements();	
	
	window.onbeforeprint = hsBeforePrint;
	window.onafterprint = hsAfterPrint;	
	
}

function hsUpdateLanguageElements(){

	if (!curLang) return;

	var pres = document.all.tags("DIV");
	var pre;

	if (pres) {
		for (var iPre = 0; iPre < pres.length; iPre++) {
			pre = pres[iPre];
			if (pre.Name && pre.className) {
				if (pre.className == "LanguageSpecific") {
					if (pre.Name.indexOf(curLang) != -1 || curLang == "All") {
						pre.style.display = "block";				
					}
					else {
						pre.style.display = "none";
					};
				}
			};
		}
	}
	
}

function hsBodyResize(){
	hsResizeBan();
}

function hsBodyClick(){
	hsHideBoxes();
	hsResizeBan();
}

function hsHideSeeAlso(){
	if (document.all.dxseealsomenu) {
		document.all.hsseealsomenu.style.visibility = "hidden";
	};
}


function hsHideLanguage(){
	if (document.all.dxlanguagemenu) {
		document.all.hslanguagemenu.style.visibility = "hidden";
	};
}

function hsResizeBan(){

	if (hsmsieversion() > 4)
	{
		try
		{

			if (document.body.clientWidth==0) return;
			var oBanner= document.all.item("hspagetop");
			var oText= document.all.item("hspagebody");
			if (oText == null) return;
			var oBannerrow1 = document.all.item("hsprojectnamebanner");
			var oTitleRow = document.all.item("hspagetitlebanner");
			if (oBannerrow1 != null){
				var iScrollWidth = hsbody.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 hsmsieversion()
// 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
}
