var curLang;
var cook = null;
var showAll;

function hsshowLanguageBox(){

	hsHideBoxes();

	var button = window.event.srcElement;

	window.event.returnValue = false;
	window.event.cancelBubble = true;

	var div = documentElement("hslanguagemenu");
	if (div && button) {
		div.style.pixelLeft = 0;
		div.style.pixelTop = button.offsetTop + button.offsetHeight;
		div.style.visibility = "visible";
	}
}

function setLanguageFilter(language){

	var lang;

	hsHideBoxes();

	window.event.returnValue = false;
	window.event.cancelBubble = true;

	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 updateLanguageElements(){

	if (!curLang) return;
	
	var pres = document.getElementsByTagName("DIV");
	var pre;
	var name;

	if (pres) {
		for (var iPre = 0; iPre < pres.length; iPre++) {
			pre = pres[iPre];
			name = pre.name;
			if (!name)
			{
				name = pre.Name;
			}
			if (name && pre.className) {
				if (pre.className == "LanguageSpecific") {
					if (name.toUpperCase().indexOf(curLang.toUpperCase()) != -1 || curLang == "All") {
						pre.style.display = "block";
					}
					else {
						pre.style.display = "none";
					};
				}
			};
		}
	}

}

function hsLanguageFilteredBodyLoad() {

	var cLang;
	var i;
	var b;
	var l;
	var e;
	var obj;
	var lang;

	// 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;
					}
				}
			}
		}
		window.onerror = null;
	}	

	if (curLang != null)
		showAll = false;
				
	updateLanguageElements();
	
	hsBodyLoad();

}